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

Commit e0e9fff3 authored by Ruben Brunk's avatar Ruben Brunk Committed by Android (Google) Code Review
Browse files

Merge "Added "discard unsaved changes" behavior for exiting." into gb-ub-photos-bryce

parents fe2aa4ba a3dbbd7d
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -50,6 +50,17 @@
    <!--  Name for the overflow menu item for settings [CHAR LIMIT=20] -->
    <string name="menu_settings">Settings</string>

    <!--  Exit Dialog -->

    <!--  String displayed when exiting with unsaved changes [CHAR LIMIT=NONE] -->
    <string name="unsaved">There are unsaved changes to this image.</string>
    <!--  String displayed when exiting with unsaved changes [CHAR LIMIT=NONE] -->
    <string name="save_before_exit">Do you want to save before exiting?</string>
    <!--  String displayed when saving and exiting editor [CHAR LIMIT=NONE] -->
    <string name="save_and_exit">Save and Exit</string>
    <!--  String displayed when exiting editor[CHAR LIMIT=NONE] -->
    <string name="exit">Exit</string>

    <!--  History Panel -->

    <!--  Text for the history panel title [CHAR LIMIT=50] -->
+47 −15
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@ package com.android.gallery3d.filtershow;

import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.WallpaperManager;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -972,8 +974,31 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
    @Override
    public void onBackPressed() {
        if (mPanelController.onBackPressed()) {
            if (detectSpecialExitCases()) {
                saveImage();
            } else if(!mImageShow.hasModifications()) {
                done();
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage(R.string.unsaved).setTitle(R.string.save_before_exit);
                builder.setPositiveButton(R.string.save_and_exit, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        saveImage();
                    }
                });
                builder.setNeutralButton(R.string.exit, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        done();
                    }
                });
                builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                    }
                });

                AlertDialog dialog = builder.show();
            }
        }
    }

    public PanelController getPanelController() {
@@ -1026,6 +1051,27 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
    private boolean mOutputted = false;

    public void saveImage() {
        handleSpecialExitCases();
        if (!mOutputted) {
            if (mImageShow.hasModifications()) {
                // Get the name of the album, to which the image will be saved
                File saveDir = SaveCopyTask.getFinalSaveDirectory(this, mImageLoader.getUri());
                int bucketId = GalleryUtils.getBucketId(saveDir.getPath());
                String albumName = LocalAlbum.getLocalizedName(getResources(), bucketId, null);
                showSavingProgress(albumName);
                mImageShow.saveImage(this, null);
            } else {
                done();
            }
        }
    }

    public boolean detectSpecialExitCases() {
        return mCropExtras != null && (mCropExtras.getExtraOutput() != null
                || mCropExtras.getSetAsWallpaper() || mCropExtras.getReturnData());
    }

    public void handleSpecialExitCases() {
        if (mCropExtras != null) {
            if (mCropExtras.getExtraOutput() != null) {
                mSaveToExtraUri = true;
@@ -1036,29 +1082,15 @@ public class FilterShowActivity extends Activity implements OnItemClickListener,
                mOutputted = true;
            }
            if (mCropExtras.getReturnData()) {

                mReturnAsExtra = true;
                mOutputted = true;
            }

            if (mOutputted) {
                mImageShow.getImagePreset().mGeoData.setUseCropExtrasFlag(true);
                showSavingProgress(null);
                mImageShow.returnFilteredResult(this);
            }
        }
        if (!mOutputted) {
            if (mImageShow.hasModifications()) {
                // Get the name of the album, to which the image will be saved
                File saveDir = SaveCopyTask.getFinalSaveDirectory(this, mImageLoader.getUri());
                int bucketId = GalleryUtils.getBucketId(saveDir.getPath());
                String albumName = LocalAlbum.getLocalizedName(getResources(), bucketId, null);
                showSavingProgress(albumName);
                mImageShow.saveImage(this, null);
            } else {
                done();
            }
        }
    }

    public void onFilteredResult(Bitmap filtered) {