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

Commit e193bc40 authored by Yuli Huang's avatar Yuli Huang Committed by Android (Google) Code Review
Browse files

Merge "Fix b/5518211 by disabling effects when photo cannot be loaded." into ics-mr1

parents b86c6aa0 f963bc2a
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -67,8 +67,6 @@ public class EffectsBar extends LinearLayout {
                return select;
            }
        });

        setEnabled(false);
    }

    private void createEffectsGallery(int effectsId) {
+14 −10
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ public class PhotoEditor extends Activity {
    private Uri saveUri;
    private FilterStack filterStack;
    private ActionBar actionBar;
    private EffectsBar effectsBar;

    @Override
    public void onCreate(Bundle savedInstanceState) {
@@ -61,14 +62,16 @@ public class PhotoEditor extends Activity {
            actionBar.updateSave(saveUri == null);
        }

        EffectsBar effectsBar = (EffectsBar) findViewById(R.id.effects_bar);
        // Effects-bar is initially disabled until photo is successfully loaded.
        effectsBar = (EffectsBar) findViewById(R.id.effects_bar);
        effectsBar.initialize(filterStack);
        effectsBar.setEnabled(false);

        actionBar.setClickRunnable(R.id.undo_button, createUndoRedoRunnable(true, effectsBar));
        actionBar.setClickRunnable(R.id.redo_button, createUndoRedoRunnable(false, effectsBar));
        actionBar.setClickRunnable(R.id.save_button, createSaveRunnable(effectsBar));
        actionBar.setClickRunnable(R.id.share_button, createShareRunnable(effectsBar));
        actionBar.setClickRunnable(R.id.action_bar_back, createBackRunnable(effectsBar));
        actionBar.setClickRunnable(R.id.undo_button, createUndoRedoRunnable(true));
        actionBar.setClickRunnable(R.id.redo_button, createUndoRedoRunnable(false));
        actionBar.setClickRunnable(R.id.save_button, createSaveRunnable());
        actionBar.setClickRunnable(R.id.share_button, createShareRunnable());
        actionBar.setClickRunnable(R.id.action_bar_back, createBackRunnable());
    }

    private SpinnerProgressDialog createProgressDialog() {
@@ -86,6 +89,7 @@ public class PhotoEditor extends Activity {
                    @Override
                    public void onDone() {
                        progressDialog.dismiss();
                        effectsBar.setEnabled(result != null);
                    }
                });
            }
@@ -93,7 +97,7 @@ public class PhotoEditor extends Activity {
        new LoadScreennailTask(this, callback).execute(sourceUri);
    }

    private Runnable createUndoRedoRunnable(final boolean undo, final EffectsBar effectsBar) {
    private Runnable createUndoRedoRunnable(final boolean undo) {
        return new Runnable() {

            @Override
@@ -121,7 +125,7 @@ public class PhotoEditor extends Activity {
        };
    }

    private Runnable createSaveRunnable(final EffectsBar effectsBar) {
    private Runnable createSaveRunnable() {
        return new Runnable() {

            @Override
@@ -154,7 +158,7 @@ public class PhotoEditor extends Activity {
        };
    }

    private Runnable createShareRunnable(final EffectsBar effectsBar) {
    private Runnable createShareRunnable() {
        return new Runnable() {

            @Override
@@ -175,7 +179,7 @@ public class PhotoEditor extends Activity {
        };
    }

    private Runnable createBackRunnable(final EffectsBar effectsBar) {
    private Runnable createBackRunnable() {
        return new Runnable() {

            @Override
+24 −18
Original line number Diff line number Diff line
@@ -18,55 +18,61 @@ package com.android.gallery3d.photoeditor;

import android.app.Dialog;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ProgressBar;

import com.android.gallery3d.R;

import java.util.ArrayList;

/**
 * Spinner model progress dialog that disables all tools for user interaction after it shows up and
 * and re-enables them after it dismisses.
 */
public class SpinnerProgressDialog extends Dialog {

    private final ViewGroup tools;
    private final ViewGroup toolbar;
    private final ArrayList<View> enabledTools = new ArrayList<View>();

    public static SpinnerProgressDialog show(ViewGroup tools) {
        SpinnerProgressDialog dialog = new SpinnerProgressDialog(tools);
    public static SpinnerProgressDialog show(ViewGroup toolbar) {
        SpinnerProgressDialog dialog = new SpinnerProgressDialog(toolbar);
        dialog.setCancelable(false);
        dialog.show();
        return dialog;
    }

    private SpinnerProgressDialog(ViewGroup tools) {
        super(tools.getContext(), R.style.SpinnerProgressDialog);
    private SpinnerProgressDialog(ViewGroup toolbar) {
        super(toolbar.getContext(), R.style.SpinnerProgressDialog);

        addContentView(new ProgressBar(tools.getContext()), new LayoutParams(
        addContentView(new ProgressBar(toolbar.getContext()), new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

        this.tools = tools;
        enableTools(false);
        // Disable enabled tools when showing spinner progress dialog.
        for (int i = 0; i < toolbar.getChildCount(); i++) {
            View view = toolbar.getChildAt(i);
            if (view.isEnabled()) {
                enabledTools.add(view);
                view.setEnabled(false);
            }
        }
        this.toolbar = toolbar;
    }

    @Override
    public void dismiss() {
        super.dismiss();

        enableTools(true);
        // Enable tools that were disabled by this spinner progress dialog.
        for (View view : enabledTools) {
            view.setEnabled(true);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        super.onTouchEvent(event);

        // Pass touch events to tools for killing idle even when the progress dialog is shown.
        return tools.dispatchTouchEvent(event);
    }

    private void enableTools(boolean enabled) {
        for (int i = 0; i < tools.getChildCount(); i++) {
            tools.getChildAt(i).setEnabled(enabled);
        }
        return toolbar.dispatchTouchEvent(event);
    }
}