summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Sandler <dsandler@android.com>2011-11-29 18:19:16 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-11-29 18:19:16 -0800
commitcdbaba43954012a317119cc20183eb4de5220e58 (patch)
tree9ad803d01e6300e3efc770fd9af90083fe78ea13
parentecc9ab9e13cce49715b7c1acd3dcc6eb015c3f0f (diff)
parentb4a1da9f32d61cf9347617a382291e488428a744 (diff)
downloadandroid_packages_apps_Snap-cdbaba43954012a317119cc20183eb4de5220e58.tar.gz
android_packages_apps_Snap-cdbaba43954012a317119cc20183eb4de5220e58.tar.bz2
android_packages_apps_Snap-cdbaba43954012a317119cc20183eb4de5220e58.zip
Merge "Improve screen on/off logic in slideshow." into ics-mr1
-rw-r--r--src/com/android/gallery3d/app/ActivityState.java58
-rw-r--r--src/com/android/gallery3d/app/SlideshowPage.java12
2 files changed, 55 insertions, 15 deletions
diff --git a/src/com/android/gallery3d/app/ActivityState.java b/src/com/android/gallery3d/app/ActivityState.java
index 519eaff58..1ef93a4bc 100644
--- a/src/com/android/gallery3d/app/ActivityState.java
+++ b/src/com/android/gallery3d/app/ActivityState.java
@@ -20,17 +20,30 @@ import com.android.gallery3d.ui.GLView;
import android.app.ActionBar;
import android.app.Activity;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
import android.content.Intent;
import android.content.res.Configuration;
+import android.os.BatteryManager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
+import android.view.Window;
import android.view.WindowManager;
abstract public class ActivityState {
public static final int FLAG_HIDE_ACTION_BAR = 1;
public static final int FLAG_HIDE_STATUS_BAR = 2;
+ public static final int FLAG_SCREEN_ON = 3;
+
+ private static final int SCREEN_ON_FLAGS = (
+ WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
+ | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
+ | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
+ );
protected GalleryActivity mActivity;
protected Bundle mData;
@@ -47,6 +60,7 @@ abstract public class ActivityState {
}
private boolean mDestroyed = false;
+ private boolean mPlugged = false;
protected ActivityState() {
}
@@ -86,7 +100,34 @@ abstract public class ActivityState {
protected void onCreate(Bundle data, Bundle storedState) {
}
+ BroadcastReceiver mPowerIntentReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final String action = intent.getAction();
+ if (Intent.ACTION_BATTERY_CHANGED.equals(action)) {
+ boolean plugged = (0 != intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, 0));
+
+ if (plugged != mPlugged) {
+ mPlugged = plugged;
+ final Window win = ((Activity) mActivity).getWindow();
+ final WindowManager.LayoutParams params = win.getAttributes();
+ setScreenOnFlags(params);
+ win.setAttributes(params);
+ }
+ }
+ }
+ };
+
+ void setScreenOnFlags(WindowManager.LayoutParams params) {
+ if (mPlugged && 0 != (mFlags & FLAG_SCREEN_ON)) {
+ params.flags |= SCREEN_ON_FLAGS;
+ } else {
+ params.flags &= ~SCREEN_ON_FLAGS;
+ }
+ }
+
protected void onPause() {
+ ((Activity) mActivity).unregisterReceiver(mPowerIntentReceiver);
}
// should only be called by StateManager
@@ -108,21 +149,30 @@ abstract public class ActivityState {
activity.invalidateOptionsMenu();
+ final Window win = activity.getWindow();
+ final WindowManager.LayoutParams params = win.getAttributes();
+
if ((mFlags & FLAG_HIDE_STATUS_BAR) != 0) {
- WindowManager.LayoutParams params = ((Activity) mActivity).getWindow().getAttributes();
params.systemUiVisibility = View.SYSTEM_UI_FLAG_LOW_PROFILE;
- ((Activity) mActivity).getWindow().setAttributes(params);
} else {
- WindowManager.LayoutParams params = ((Activity) mActivity).getWindow().getAttributes();
params.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE;
- ((Activity) mActivity).getWindow().setAttributes(params);
}
+ setScreenOnFlags(params);
+ win.setAttributes(params);
+
ResultEntry entry = mReceivedResults;
if (entry != null) {
mReceivedResults = null;
onStateResult(entry.requestCode, entry.resultCode, entry.resultData);
}
+
+ if (0 != (mFlags & FLAG_SCREEN_ON)) {
+ // we need to know whether the device is plugged in to do this correctly
+ final IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_BATTERY_CHANGED);
+ activity.registerReceiver(mPowerIntentReceiver, filter);
+ }
onResume();
}
diff --git a/src/com/android/gallery3d/app/SlideshowPage.java b/src/com/android/gallery3d/app/SlideshowPage.java
index 938785e9e..86976292a 100644
--- a/src/com/android/gallery3d/app/SlideshowPage.java
+++ b/src/com/android/gallery3d/app/SlideshowPage.java
@@ -23,8 +23,6 @@ import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
-import android.os.PowerManager;
-import android.os.PowerManager.WakeLock;
import android.view.MotionEvent;
import com.android.gallery3d.common.Utils;
@@ -83,7 +81,6 @@ public class SlideshowPage extends ActivityState {
private Slide mPendingSlide = null;
private boolean mIsActive = false;
- private WakeLock mWakeLock;
private final Intent mResultIntent = new Intent();
private final GLView mRootPane = new GLView() {
@@ -108,12 +105,7 @@ public class SlideshowPage extends ActivityState {
@Override
public void onCreate(Bundle data, Bundle restoreState) {
- mFlags |= (FLAG_HIDE_ACTION_BAR | FLAG_HIDE_STATUS_BAR);
-
- PowerManager pm = (PowerManager) mActivity.getAndroidContext().getSystemService(
- Context.POWER_SERVICE);
- mWakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
- | PowerManager.ON_AFTER_RELEASE, TAG);
+ mFlags |= (FLAG_HIDE_ACTION_BAR | FLAG_HIDE_STATUS_BAR | FLAG_SCREEN_ON);
mHandler = new SynchronizedHandler(mActivity.getGLRoot()) {
@Override
@@ -165,7 +157,6 @@ public class SlideshowPage extends ActivityState {
@Override
public void onPause() {
super.onPause();
- mWakeLock.release();
mIsActive = false;
mModel.pause();
mSlideshowView.release();
@@ -177,7 +168,6 @@ public class SlideshowPage extends ActivityState {
@Override
public void onResume() {
super.onResume();
- mWakeLock.acquire();
mIsActive = true;
mModel.resume();