diff options
author | zhuw <zhuw@codeaurora.org> | 2018-11-02 13:48:27 +0800 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2018-11-01 22:50:47 -0700 |
commit | 41de1355ef13aa6ed7793415ee6cb40cd8386f4e (patch) | |
tree | f1085588d6e71d3fdcb56b4d920bfd1a86efb63a | |
parent | f1ccb05dbefb19f87d6a6e3abc5db40feb4462b5 (diff) | |
download | android_packages_apps_Gallery2-41de1355ef13aa6ed7793415ee6cb40cd8386f4e.tar.gz android_packages_apps_Gallery2-41de1355ef13aa6ed7793415ee6cb40cd8386f4e.tar.bz2 android_packages_apps_Gallery2-41de1355ef13aa6ed7793415ee6cb40cd8386f4e.zip |
change Home button function in timelinepage
finish activity state when Gallery is in timeline page
Change-Id: I2b322430449d47d423f74143ad4e46b9dc90de80
-rwxr-xr-x | src/com/android/gallery3d/app/GalleryActivity.java | 17 | ||||
-rwxr-xr-x | src/com/android/gallery3d/app/TimeLinePage.java | 29 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/com/android/gallery3d/app/GalleryActivity.java b/src/com/android/gallery3d/app/GalleryActivity.java index 16920b942..c4b9564d1 100755 --- a/src/com/android/gallery3d/app/GalleryActivity.java +++ b/src/com/android/gallery3d/app/GalleryActivity.java @@ -25,6 +25,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnCancelListener; import android.content.Intent; +import android.content.IntentFilter; import android.content.UriMatcher; import android.content.pm.PackageManager; import android.graphics.Color; @@ -618,4 +619,20 @@ public final class GalleryActivity extends AbstractGalleryActivity implements On } return super.onGenericMotionEvent(event); } + + public void registerHomeButtonReceiver(TimeLinePage.HomeIconActionReceiver receiver) { + IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); + registerReceiver(receiver, filter); + } + + public void unregisterHomeButtonReceiver(TimeLinePage.HomeIconActionReceiver receiver) { + if (receiver == null) { + return; + } + try { + unregisterReceiver(receiver); + } catch (Exception e) { + Log.w(TAG, "unregister HomeIconActionReceiver failed"); + } + } } diff --git a/src/com/android/gallery3d/app/TimeLinePage.java b/src/com/android/gallery3d/app/TimeLinePage.java index c3c08650b..dad1ef265 100755 --- a/src/com/android/gallery3d/app/TimeLinePage.java +++ b/src/com/android/gallery3d/app/TimeLinePage.java @@ -20,8 +20,10 @@ package com.android.gallery3d.app; import android.app.Activity; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.content.res.Configuration; import android.graphics.Color; import android.graphics.Rect; @@ -124,6 +126,7 @@ public class TimeLinePage extends ActivityState implements private int mSyncResult; private boolean mLoadingFailed; private RelativePosition mOpenCenter = new RelativePosition(); + private HomeIconActionReceiver mHomeIconActionReceiver; private Handler mHandler; private static final int MSG_PICK_PHOTO = 0; @@ -433,6 +436,7 @@ public class TimeLinePage extends ActivityState implements } } }; + registerHomeReceiver(); } @Override @@ -499,6 +503,7 @@ public class TimeLinePage extends ActivityState implements mAlbumDataAdapter.setLoadingListener(null); } mActionModeHandler.destroy(); + ((GalleryActivity) mActivity).unregisterHomeButtonReceiver(mHomeIconActionReceiver); } private void initializeViews() { @@ -896,4 +901,28 @@ public class TimeLinePage extends ActivityState implements tvEmptyAlbum.setVisibility(View.GONE); } } + + public class HomeIconActionReceiver extends BroadcastReceiver { + private static final String SYSTEM_DIALOG_REASON_KEY = "reason"; + private static final String SYSTEM_DIALOG_REASON_HOME_KEY = "homekey"; + + @Override + public void onReceive(Context context, Intent intent) { + if (TextUtils.equals(intent.getAction(), Intent.ACTION_CLOSE_SYSTEM_DIALOGS)) { + String reasonHomeKey = intent.getStringExtra(SYSTEM_DIALOG_REASON_KEY); + if (TextUtils.equals(SYSTEM_DIALOG_REASON_HOME_KEY, reasonHomeKey)) { + StateManager manager = mActivity.getStateManager(); + int stateCount = manager.getStateCount(); + if (stateCount == 1 && manager.getTopState() instanceof TimeLinePage) { + manager.finishState(manager.getTopState()); + } + } + } + } + } + + private void registerHomeReceiver() { + mHomeIconActionReceiver = new HomeIconActionReceiver(); + ((GalleryActivity) mActivity).registerHomeButtonReceiver(mHomeIconActionReceiver); + } } |