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

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

Merge "Fix b/5032231: Allow share in Photo Editor."

parents 26e87940 915d5837
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -44,9 +44,22 @@
            android:id="@+id/redo_button"
            style="@style/ImageActionButton"
            android:src="@drawable/photoeditor_redo"/>

        <ViewSwitcher
            android:id="@+id/save_share_buttons"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <Button
                android:id="@+id/save_button"
                style="@style/TextActionButton"
                android:layout_width="fill_parent"
                android:text="@string/save"/>
            <ImageButton
                android:id="@+id/share_button"
                style="@style/ImageActionButton"
                android:layout_width="fill_parent"
                android:src="@drawable/ic_menu_share_holo_light"/>
        </ViewSwitcher>

    </LinearLayout>
</com.android.gallery3d.photoeditor.ActionBar>
+13 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.ViewSwitcher;

import com.android.gallery3d.R;

@@ -104,8 +105,19 @@ public class ActionBar extends RelativeLayout {
        View button = findViewById(buttonId);
        button.setEnabled(enabled);
        button.setAlpha(enabled ? ENABLED_ALPHA : DISABLED_ALPHA);

        // Track buttons whose enabled status has been updated.
        changedButtons.add(buttonId);

        if (buttonId == R.id.save_button) {
            // Show share-button only after photo is edited and saved; otherwise, show save-button.
            // TODO: Fix the assumption of undo enabled status must be updated before reaching here.
            boolean showShare = findViewById(R.id.undo_button).isEnabled() && !enabled;
            ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.save_share_buttons);
            int next = switcher.getNextView().getId();
            if ((showShare && (next == R.id.share_button))
                    || (!showShare && (next == R.id.save_button))) {
                switcher.showNext();
            }
        }
    }
}
+31 −4
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@ import com.android.gallery3d.R;
 */
public class PhotoEditor extends Activity {

    private Uri uri;
    private Uri sourceUri;
    private Uri saveUri;
    private FilterStack filterStack;
    private ActionBar actionBar;

@@ -43,7 +44,9 @@ public class PhotoEditor extends Activity {
        setContentView(R.layout.photoeditor_main);

        Intent intent = getIntent();
        uri = Intent.ACTION_EDIT.equalsIgnoreCase(intent.getAction()) ? intent.getData() : null;
        if (Intent.ACTION_EDIT.equalsIgnoreCase(intent.getAction())) {
            sourceUri = intent.getData();
        }

        actionBar = (ActionBar) findViewById(R.id.action_bar);
        filterStack = new FilterStack((PhotoView) findViewById(R.id.photo_view),
@@ -63,6 +66,7 @@ public class PhotoEditor extends Activity {
        actionBar.setRunnable(R.id.undo_button, createUndoRedoRunnable(true, effectsBar));
        actionBar.setRunnable(R.id.redo_button, createUndoRedoRunnable(false, effectsBar));
        actionBar.setRunnable(R.id.save_button, createSaveRunnable(effectsBar));
        actionBar.setRunnable(R.id.share_button, createShareRunnable(effectsBar));
        actionBar.setRunnable(R.id.action_bar_back, createBackRunnable(effectsBar));
    }

@@ -106,7 +110,7 @@ public class PhotoEditor extends Activity {
                });
            }
        };
        new LoadScreennailTask(this, callback).execute(uri);
        new LoadScreennailTask(this, callback).execute(sourceUri);
    }

    private Runnable createUndoRedoRunnable(final boolean undo, final EffectsBar effectsBar) {
@@ -157,12 +161,35 @@ public class PhotoEditor extends Activity {
                                    public void onComplete(Uri result) {
                                        progressDialog.dismiss();
                                        actionBar.enableButton(R.id.save_button, (result == null));
                                        saveUri = result;
                                    }
                                };
                                new SaveCopyTask(PhotoEditor.this, uri, callback).execute(bitmap);
                                new SaveCopyTask(PhotoEditor.this, sourceUri, callback).execute(
                                        bitmap);
                            }
                        });
                    }
                });
            }
        };
    }

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

            @Override
            public void run() {
                effectsBar.exit(new Runnable() {

                    @Override
                    public void run() {
                        if (saveUri != null) {
                            Intent intent = new Intent(Intent.ACTION_SEND);
                            intent.putExtra(Intent.EXTRA_STREAM, saveUri);
                            intent.setType("image/*");
                            startActivity(intent);
                        }
                    }
                });
            }
        };