Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed60979e authored by nicolasroard's avatar nicolasroard
Browse files

ImagePreset cleanup

Get rid of remaining ivars related to history

Change-Id: Ic106ef6a96f4727c6dd46d7be3d059bdc42e5a2a
parent 2d0eaf53
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -427,7 +427,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
        ImagePreset oldPreset = MasterImage.getImage().getPreset();
        ImagePreset copy = new ImagePreset(oldPreset);
        copy.removeFilter(filterRepresentation);
        MasterImage.getImage().setPreset(copy, true);
        MasterImage.getImage().setPreset(copy, copy.getLastRepresentation(), true);
        if (MasterImage.getImage().getCurrentFilterRepresentation() == filterRepresentation) {
            FilterRepresentation lastRepresentation = copy.getLastRepresentation();
            MasterImage.getImage().setCurrentFilterRepresentation(lastRepresentation);
@@ -449,12 +449,11 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
        } else {
            if (filterRepresentation.allowsSingleInstanceOnly()) {
                representation.updateTempParametersFrom(filterRepresentation);
                copy.setHistoryName(filterRepresentation.getName());
                representation.synchronizeRepresentation();
            }
            filterRepresentation = representation;
        }
        MasterImage.getImage().setPreset(copy, true);
        MasterImage.getImage().setPreset(copy, filterRepresentation, true);
        MasterImage.getImage().setCurrentFilterRepresentation(filterRepresentation);
    }

@@ -558,7 +557,8 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
            mLoadBitmapTask = null;

            if (mOriginalPreset != null) {
                MasterImage.getImage().setPreset(mOriginalPreset, true);
                MasterImage.getImage().setPreset(mOriginalPreset,
                        mOriginalPreset.getLastRepresentation(), true);
                mOriginalPreset = null;
            }

@@ -822,10 +822,10 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL

    public void setDefaultPreset() {
        // Default preset (original)
        ImagePreset preset = new ImagePreset(getString(R.string.history_original)); // empty
        ImagePreset preset = new ImagePreset(); // empty
        preset.setImageLoader(mImageLoader);

        mMasterImage.setPreset(preset, true);
        mMasterImage.setPreset(preset, preset.getLastRepresentation(), true);
    }

    // //////////////////////////////////////////////////////////////////////////////
@@ -905,8 +905,9 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
    void resetHistory() {
        HistoryAdapter adapter = mMasterImage.getHistory();
        adapter.reset();
        ImagePreset original = new ImagePreset(adapter.getItem(0));
        mMasterImage.setPreset(original, true);
        HistoryItem historyItem = adapter.getItem(0);
        ImagePreset original = new ImagePreset(historyItem.getImagePreset());
        mMasterImage.setPreset(original, historyItem.getFilterRepresentation(), true);
        invalidateViews();
        backToMain();
    }
+12 −11
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ import com.android.gallery3d.filtershow.presets.ImagePreset;

import java.util.Vector;

public class HistoryAdapter extends ArrayAdapter<ImagePreset> {
public class HistoryAdapter extends ArrayAdapter<HistoryItem> {
    private static final String LOGTAG = "HistoryAdapter";
    private int mCurrentPresetPosition = 0;
    private String mBorders = null;
@@ -115,33 +115,33 @@ public class HistoryAdapter extends ArrayAdapter<ImagePreset> {
        if (getCount() == 0) {
            return;
        }
        ImagePreset first = getItem(getCount() - 1);
        HistoryItem first = getItem(getCount() - 1);
        clear();
        addHistoryItem(first);
        updateMenuItems();
    }

    public ImagePreset getLast() {
    public HistoryItem getLast() {
        if (getCount() == 0) {
            return null;
        }
        return getItem(0);
    }

    public ImagePreset getCurrent() {
    public HistoryItem getCurrent() {
        return getItem(mCurrentPresetPosition);
    }

    public void addHistoryItem(ImagePreset preset) {
    public void addHistoryItem(HistoryItem preset) {
        insert(preset, 0);
        updateMenuItems();
    }

    @Override
    public void insert(ImagePreset preset, int position) {
    public void insert(HistoryItem preset, int position) {
        if (mCurrentPresetPosition != 0) {
            // in this case, let's discount the presets before the current one
            Vector<ImagePreset> oldItems = new Vector<ImagePreset>();
            Vector<HistoryItem> oldItems = new Vector<HistoryItem>();
            for (int i = mCurrentPresetPosition; i < getCount(); i++) {
                oldItems.add(getItem(i));
            }
@@ -186,14 +186,15 @@ public class HistoryAdapter extends ArrayAdapter<ImagePreset> {
            view = inflater.inflate(R.layout.filtershow_history_operation_row, null);
        }

        ImagePreset item = getItem(position);
        HistoryItem historyItem = getItem(position);
        ImagePreset item = historyItem.getImagePreset();
        if (item != null) {
            TextView itemView = (TextView) view.findViewById(R.id.rowTextView);
            if (itemView != null) {
                itemView.setText(item.historyName());
            if (itemView != null && historyItem.getFilterRepresentation() != null) {
                itemView.setText(historyItem.getFilterRepresentation().getName());
            }
            ImageView preview = (ImageView) view.findViewById(R.id.preview);
            Bitmap bmp = item.getPreviewImage();
            Bitmap bmp = historyItem.getPreviewImage();
            if (position == getCount()-1 && mOriginalBitmap != null) {
                bmp = mOriginalBitmap;
            }
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2013 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.gallery3d.filtershow;

import android.graphics.Bitmap;
import android.util.Log;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
import com.android.gallery3d.filtershow.presets.ImagePreset;

public class HistoryItem {
    private static final String LOGTAG = "HistoryItem";
    private ImagePreset mImagePreset;
    private FilterRepresentation mFilterRepresentation;
    private Bitmap mPreviewImage;

    public HistoryItem(ImagePreset preset, FilterRepresentation representation) {
        mImagePreset = new ImagePreset(preset);
        try {
            if (representation != null) {
                mFilterRepresentation = representation.clone();
            }
        } catch (CloneNotSupportedException e) {
            Log.e(LOGTAG, "clone not supported", e);
        }
    }

    public ImagePreset getImagePreset() {
        return mImagePreset;
    }

    public FilterRepresentation getFilterRepresentation() {
        return mFilterRepresentation;
    }

    public Bitmap getPreviewImage() {
        return mPreviewImage;
    }

    public void setPreviewImage(Bitmap previewImage) {
        mPreviewImage = previewImage;
    }

}
+0 −2
Original line number Diff line number Diff line
@@ -287,8 +287,6 @@ public class CachingPipeline implements PipelineInterface {

                if (request.getType() == RenderingRequest.ICON_RENDERING) {
                    mEnvironment.setQuality(FilterEnvironment.QUALITY_ICON);
                } else  if (request.getType() == RenderingRequest.STYLE_ICON_RENDERING) {
                    mEnvironment.setQuality(ImagePreset.STYLE_ICON);
                } else {
                    mEnvironment.setQuality(FilterEnvironment.QUALITY_PREVIEW);
                }
+2 −12
Original line number Diff line number Diff line
@@ -67,19 +67,9 @@ public class CategoryAdapter extends ArrayAdapter<Action> {

    public void initializeSelection(int category) {
        mCategory = category;
        if (category == MainPanel.LOOKS || category == MainPanel.BORDERS) {
            ImagePreset preset = MasterImage.getImage().getPreset();
            if (preset != null) {
                for (int i = 0; i < getCount(); i++) {
                    if (preset.historyName().equals(getItem(i).getRepresentation().getName())) {
                        mSelectedPosition = i;
                    }
                }
            }
        } else {
        // TODO: fix this
        mSelectedPosition = -1;
    }
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
Loading