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

Commit d2e9ea0c authored by ztenghui's avatar ztenghui
Browse files

Save button now behaves correctly for filter changes.

Basically, save the original filter from the file's XMP.
Compare the current filter against original one to decide whether or not the
file has been modified and needed to be saved.

At the same time, make sure we don't save "None" filter in the ImagePreset.

bug:9468909

Change-Id: I5b86ab95556b6b010367c9577b02c0bb42ffb824
parent 5180e681
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -36,8 +36,8 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
@@ -450,10 +450,12 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
            copy.addFilter(filterRepresentation);
        } else {
            if (filterRepresentation.allowsSingleInstanceOnly()) {
                representation.updateTempParametersFrom(filterRepresentation);
                representation.synchronizeRepresentation();
                // Don't just update the filter representation. Centralize the
                // logic in the addFilter(), such that we can keep "None" as
                // null.
                copy.removeFilter(representation);
                copy.addFilter(filterRepresentation);
            }
            filterRepresentation = representation;
        }
        MasterImage.getImage().setPreset(copy, filterRepresentation, true);
        MasterImage.getImage().setCurrentFilterRepresentation(filterRepresentation);
@@ -565,6 +567,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
            mLoadBitmapTask = null;

            if (mOriginalPreset != null) {
                MasterImage.getImage().setLoadedPreset(mOriginalPreset);
                MasterImage.getImage().setPreset(mOriginalPreset,
                        mOriginalPreset.getLastRepresentation(), true);
                mOriginalPreset = null;
+3 −1
Original line number Diff line number Diff line
@@ -82,7 +82,9 @@ public class FilterRepresentation implements Cloneable {
        if (representation.mFilterClass == mFilterClass
                && representation.mName.equalsIgnoreCase(mName)
                && representation.mPriority == mPriority
                && representation.mSupportsPartialRendering == mSupportsPartialRendering
                // TODO: After we enable partial rendering, we can switch back
                // to use member variable here.
                && representation.supportsPartialRendering() == supportsPartialRendering()
                && representation.mTextId == mTextId
                && representation.mEditorId == mEditorId
                && representation.mButtonId == mButtonId
+3 −6
Original line number Diff line number Diff line
@@ -99,10 +99,7 @@ public class ImageShow extends View implements OnGestureListener,
    }

    public boolean hasModifications() {
        if (getImagePreset() == null) {
            return false;
        }
        return getImagePreset().hasModifications();
        return MasterImage.getImage().hasModifications();
    }

    public void resetParameter() {
@@ -321,9 +318,9 @@ public class ImageShow extends View implements OnGestureListener,
            int py = 0;
            if (mShowOriginalDirection == UNVEIL_VERTICAL) {
                px = mImageBounds.width();
                py = (int) (mTouch.y - mImageBounds.top);
                py = mTouch.y - mImageBounds.top;
            } else {
                px = (int) (mTouch.x - mImageBounds.left);
                px = mTouch.x - mImageBounds.left;
                py = mImageBounds.height();
                if (showsOriginal) {
                    px = mImageBounds.width();
+24 −5
Original line number Diff line number Diff line
@@ -16,15 +16,22 @@

package com.android.gallery3d.filtershow.imageshow;

import android.graphics.*;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Message;

import android.util.Log;
import com.android.gallery3d.filtershow.FilterShowActivity;
import com.android.gallery3d.filtershow.history.HistoryAdapter;
import com.android.gallery3d.filtershow.history.HistoryItem;
import com.android.gallery3d.filtershow.cache.*;
import com.android.gallery3d.filtershow.cache.FilteringPipeline;
import com.android.gallery3d.filtershow.cache.ImageLoader;
import com.android.gallery3d.filtershow.cache.RenderingRequest;
import com.android.gallery3d.filtershow.cache.RenderingRequestCaller;
import com.android.gallery3d.filtershow.cache.TripleBufferBitmap;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
import com.android.gallery3d.filtershow.filters.ImageFilter;
import com.android.gallery3d.filtershow.presets.ImagePreset;
@@ -45,6 +52,7 @@ public class MasterImage implements RenderingRequestCaller {

    private ImageFilter mCurrentFilter = null;
    private ImagePreset mPreset = null;
    private ImagePreset mLoadedPreset = null;
    private ImagePreset mGeometryOnlyPreset = null;
    private ImagePreset mFiltersOnlyPreset = null;

@@ -224,9 +232,12 @@ public class MasterImage implements RenderingRequestCaller {

    public synchronized boolean hasModifications() {
        if (mPreset == null) {
            return false;
            return getLoadedPreset() != null;
        } else {
            // TODO: same() is quite strict check here. We should be only
            // checking for functionality parity.
            return !mPreset.same(getLoadedPreset());
        }
        return mPreset.hasModifications();
    }

    public TripleBufferBitmap getDoubleBuffer() {
@@ -512,4 +523,12 @@ public class MasterImage implements RenderingRequestCaller {
    public boolean showsOriginal() {
        return mShowsOriginal;
    }

    public void setLoadedPreset(ImagePreset preset) {
        mLoadedPreset = preset;
    }

    public ImagePreset getLoadedPreset() {
        return mLoadedPreset;
    }
}
+28 −23
Original line number Diff line number Diff line
@@ -18,20 +18,19 @@ package com.android.gallery3d.filtershow.presets;

import android.graphics.Bitmap;
import android.graphics.Rect;
import android.net.Uri;
import android.support.v8.renderscript.Allocation;
import android.util.JsonReader;
import android.util.JsonWriter;
import android.util.Log;

import com.adobe.xmp.XMPException;
import com.adobe.xmp.XMPMeta;
import com.adobe.xmp.options.PropertyOptions;
import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.cache.CachingPipeline;
import com.android.gallery3d.filtershow.cache.ImageLoader;
import com.android.gallery3d.filtershow.filters.BaseFiltersManager;
import com.android.gallery3d.filtershow.filters.FiltersManager;
import com.android.gallery3d.filtershow.filters.FilterFxRepresentation;
import com.android.gallery3d.filtershow.filters.FilterImageBorderRepresentation;
import com.android.gallery3d.filtershow.filters.FilterRepresentation;
import com.android.gallery3d.filtershow.filters.FiltersManager;
import com.android.gallery3d.filtershow.filters.ImageFilter;
import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
import com.android.gallery3d.filtershow.imageshow.MasterImage;
@@ -53,6 +52,8 @@ public class ImagePreset {

    private Vector<FilterRepresentation> mFilters = new Vector<FilterRepresentation>();

    protected boolean mIsFxPreset = false;

    private boolean mDoApplyGeometry = true;
    private boolean mDoApplyFilters = true;

@@ -185,21 +186,6 @@ public class ImagePreset {
        return geo;
    }

    public boolean hasModifications() {
        for (int i = 0; i < mFilters.size(); i++) {
            FilterRepresentation filter = mFilters.elementAt(i);
            if (filter instanceof GeometryMetadata) {
                if (((GeometryMetadata) filter).hasModifications()) {
                    return true;
                }
            }
            if (!filter.isNil() && !filter.getName().equalsIgnoreCase("none")) {
                return true;
            }
        }
        return false;
    }

    public boolean isPanoramaSafe() {
        for (FilterRepresentation representation : mFilters) {
            if (representation instanceof GeometryMetadata) {
@@ -353,14 +339,19 @@ public class ImagePreset {
        }
    }

    // If the filter is an "None" effect or border, then just don't add this
    // filter.
    public void addFilter(FilterRepresentation representation) {
        if (representation instanceof GeometryMetadata) {
            setGeometry((GeometryMetadata) representation);
            return;
        }

        if (representation.getFilterType() == FilterRepresentation.TYPE_BORDER) {
            removeFilter(representation);
            if (!isNoneBorderFilter(representation)) {
                mFilters.add(representation);
            }
        } else if (representation.getFilterType() == FilterRepresentation.TYPE_FX) {
            boolean found = false;
            for (int i = 0; i < mFilters.size(); i++) {
@@ -373,18 +364,32 @@ public class ImagePreset {
                }
                if (type == FilterRepresentation.TYPE_FX) {
                    mFilters.remove(i);
                    if (!isNoneFxFilter(representation)) {
                        mFilters.add(i, representation);
                    }
                    found = true;
                }
            }
            if (!found) {
                if (!isNoneFxFilter(representation)) {
                    mFilters.add(representation);
                }
            }
        } else {
            mFilters.add(representation);
        }
    }

    private boolean isNoneBorderFilter(FilterRepresentation representation) {
        return representation instanceof FilterImageBorderRepresentation &&
                ((FilterImageBorderRepresentation) representation).getDrawableResource() == 0;
    }

    private boolean isNoneFxFilter(FilterRepresentation representation) {
        return representation instanceof FilterFxRepresentation &&
                ((FilterFxRepresentation)representation).getNameResource() == R.string.none;
    }

    public FilterRepresentation getRepresentation(FilterRepresentation filterRepresentation) {
        for (int i = 0; i < mFilters.size(); i++) {
            FilterRepresentation representation = mFilters.elementAt(i);