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

Commit 272122ca authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Close photo selection activity on config change

This activity doesn't handle orientation changes right.  Let's just close it
on any configuration changes.   This activity is kinda like a popup, so it
should be okay.

Now this activity handles all config changes by itself, so we can remove a lot
of things, such as onSaveInstanceState and PendingPhotoResult.

Bug 6236774

Change-Id: Ib7037a66d092c8d9a285224ea4cf70e7da8ff1b5
parent b8353e22
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -551,11 +551,16 @@
            </intent-filter>
        </activity>

        <!-- Internal photo selection activity -->
        <!--
            Internal photo selection activity.  This activity handles all configuration changes by
            itself.
        -->
        <activity android:name=".activities.PhotoSelectionActivity"
            android:theme="@style/Theme.PhotoSelector"
            android:launchMode="singleTop"
            android:windowSoftInputMode="stateUnchanged">
            android:windowSoftInputMode="stateUnchanged"
            android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|screenLayout|fontScale|uiMode|orientation|screenSize|smallestScreenSize"
            >
        </activity>

        <!-- Interstitial activity that shows a phone disambig dialog -->
+40 −61
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.animation.PropertyValuesHolder;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.net.Uri;
@@ -59,10 +60,6 @@ public class PhotoSelectionActivity extends Activity {
    /** Number of ms for the animation to hide the backdrop on finish. */
    private static final int BACKDROP_FADEOUT_DURATION = 100;

    private static final String KEY_CURRENT_PHOTO_FILE = "currentphotofile";

    private static final String KEY_SUB_ACTIVITY_IN_PROGRESS = "subinprogress";

    /** Intent extra to get the photo URI. */
    public static final String PHOTO_URI = "photo_uri";

@@ -132,10 +129,7 @@ public class PhotoSelectionActivity extends Activity {
    /** Whether a sub-activity is currently in progress. */
    private boolean mSubActivityInProgress;

    /**
     * A photo result received by the activity, persisted across activity lifecycle.
     */
    private PendingPhotoResult mPendingPhotoResult;
    private boolean mCloseActivityWhenCameBackFromSubActivity;

    /**
     * The photo file being interacted with, if any.  Saved/restored between activity instances.
@@ -146,13 +140,6 @@ public class PhotoSelectionActivity extends Activity {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.photoselection_activity);
        if (savedInstanceState != null) {
            String fileName = savedInstanceState.getString(KEY_CURRENT_PHOTO_FILE);
            if (fileName != null) {
                mCurrentPhotoFile = new File(fileName);
            }
            mSubActivityInProgress = savedInstanceState.getBoolean(KEY_SUB_ACTIVITY_IN_PROGRESS);
        }

        // Pull data out of the intent.
        final Intent intent = getIntent();
@@ -186,12 +173,27 @@ public class PhotoSelectionActivity extends Activity {
        });
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // The current look may not seem right on the new configuration, so let's just close self.

        if (!mSubActivityInProgress) {
            finishImmediatelyWithNoAnimation();
        } else {
            // A sub-activity is in progress, so don't close it yet, but close it when we come back
            // to this activity.
            mCloseActivityWhenCameBackFromSubActivity = true;
        }
    }

    @Override
    public void finish() {
        if (!mSubActivityInProgress) {
            closePhotoAndFinish();
        } else {
            activityFinish();
            finishImmediatelyWithNoAnimation();
        }
    }

@@ -227,7 +229,7 @@ public class PhotoSelectionActivity extends Activity {
        return intent;
    }

    private void activityFinish() {
    private void finishImmediatelyWithNoAnimation() {
        super.finish();
    }

@@ -360,15 +362,13 @@ public class PhotoSelectionActivity extends Activity {
                anim.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        activityFinish();
                        finishImmediatelyWithNoAnimation();
                    }
                });
                anim.start();
            }
        };

        // TODO: This won't animate in the right way if the rotation has changed since the activity
        // was first started.
        animatePhoto(mPhotoStartParams);
        animateAwayBackground();
    }
@@ -394,29 +394,24 @@ public class PhotoSelectionActivity extends Activity {
                BACKDROP_FADEOUT_DURATION).start();
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (mCurrentPhotoFile != null) {
            outState.putString(KEY_CURRENT_PHOTO_FILE, mCurrentPhotoFile.toString());
        }
        outState.putBoolean(KEY_SUB_ACTIVITY_IN_PROGRESS, mSubActivityInProgress);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (mPhotoHandler != null) {
            mSubActivityInProgress = false;
            if (mPhotoHandler.handlePhotoActivityResult(requestCode, resultCode, data)) {
                // Clear out any pending photo result.
                mPendingPhotoResult = null;
                // Result was handled.  We'll get a callback later.
            } else {
                // User cancelled the sub-activity and returning to the photo selection activity.
                if (mCloseActivityWhenCameBackFromSubActivity) {
                    finishImmediatelyWithNoAnimation();
                } else {
                // User returning to the photo selection activity.  Re-display options.
                    // Re-display options.
                    mPhotoHandler.onClick(mPhotoView);
                }
            }
        } else {
            // Create a pending photo result to be handled when the photo handler is created.
            mPendingPhotoResult = new PendingPhotoResult(requestCode, resultCode, data);
            // The result comes back before we prepare the handler?  This activity won't get
            // re-created for orientation changes, so this shouldn't happen.
        }
    }

@@ -432,11 +427,7 @@ public class PhotoSelectionActivity extends Activity {
        mode &= ~PhotoActionPopup.Flags.REMOVE_PHOTO;

        mPhotoHandler = new PhotoHandler(this, mPhotoView, mode, mState);
        if (mPendingPhotoResult != null) {
            mPhotoHandler.handlePhotoActivityResult(mPendingPhotoResult.mRequestCode,
                    mPendingPhotoResult.mResultCode, mPendingPhotoResult.mData);
            mPendingPhotoResult = null;
        } else {

        // Setting the photo in displayPhoto() resulted in a relayout
        // request... to avoid jank, wait until this layout has happened.
        SchedulingUtils.doAfterLayout(mBackdrop, new Runnable() {
@@ -446,10 +437,9 @@ public class PhotoSelectionActivity extends Activity {
            }
        });
    }
    }

    private final class PhotoHandler extends PhotoSelectionHandler {
        private PhotoActionListener mListener;
        private final PhotoActionListener mListener;

        private PhotoHandler(
                Context context, View photoView, int photoMode, EntityDeltaList state) {
@@ -496,15 +486,4 @@ public class PhotoSelectionActivity extends Activity {
            }
        }
    }

    private static class PendingPhotoResult {
        private int mRequestCode;
        private int mResultCode;
        private Intent mData;
        private PendingPhotoResult(int requestCode, int resultCode, Intent data) {
            mRequestCode = requestCode;
            mResultCode = resultCode;
            mData = data;
        }
    }
}