summaryrefslogtreecommitdiffstats
path: root/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'photoviewer/src/com/android/ex/photo/PhotoViewActivity.java')
-rw-r--r--photoviewer/src/com/android/ex/photo/PhotoViewActivity.java59
1 files changed, 52 insertions, 7 deletions
diff --git a/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java b/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java
index 5231ca1..30017da 100644
--- a/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java
+++ b/photoviewer/src/com/android/ex/photo/PhotoViewActivity.java
@@ -31,6 +31,8 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.ViewPager.OnPageChangeListener;
+import android.text.TextUtils;
+import android.view.MenuItem;
import android.view.View;
import com.android.ex.photo.PhotoViewPager.InterceptType;
@@ -111,6 +113,8 @@ public class PhotoViewActivity extends Activity implements
/** The URI of the photos we're viewing; may be {@code null} */
private String mPhotosUri;
+ /** The URI of the photo currently viewed photo */
+ private String mInitialPhotoUri;
/** The index of the currently viewed photo */
private int mPhotoIndex;
/** The query projection to use; may be {@code null} */
@@ -133,6 +137,8 @@ public class PhotoViewActivity extends Activity implements
private boolean mRestartLoader;
/** Whether or not this activity is paused */
private boolean mIsPaused = true;
+ /** The maximum scale factor applied to images when they are initially displayed */
+ private float mMaxInitialScale;
private final Handler mHandler = new Handler();
// TODO Find a better way to do this. We basically want the activity to display the
// "loading..." progress until the fragment takes over and shows it's own "loading..."
@@ -176,12 +182,19 @@ public class PhotoViewActivity extends Activity implements
if (mIntent.hasExtra(Intents.EXTRA_PHOTO_INDEX) && currentItem < 0) {
currentItem = mIntent.getIntExtra(Intents.EXTRA_PHOTO_INDEX, -1);
}
+ if (mIntent.hasExtra(Intents.EXTRA_INITIAL_PHOTO_URI) && currentItem < 0) {
+ mInitialPhotoUri = mIntent.getStringExtra(Intents.EXTRA_INITIAL_PHOTO_URI);
+ }
+
+ // Set the max initial scale, defaulting to 1x
+ mMaxInitialScale = mIntent.getFloatExtra(Intents.EXTRA_MAX_INITIAL_SCALE, 1.0f);
+
mPhotoIndex = currentItem;
setContentView(R.layout.photo_activity_view);
// Create the adapter and add the view pager
- mAdapter = new PhotoPagerAdapter(this, getFragmentManager(), null);
+ mAdapter = new PhotoPagerAdapter(this, getFragmentManager(), null, mMaxInitialScale);
mViewPager = (PhotoViewPager) findViewById(R.id.photo_view_pager);
mViewPager.setAdapter(mAdapter);
@@ -236,6 +249,16 @@ public class PhotoViewActivity extends Activity implements
outState.putBoolean(STATE_FULLSCREEN_KEY, mFullScreen);
}
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ finish();
+ default:
+ return super.onOptionsItemSelected(item);
+ }
+ }
+
public void addScreenListener(OnScreenListener listener) {
mScreenListeners.add(listener);
}
@@ -296,6 +319,20 @@ public class PhotoViewActivity extends Activity implements
} else {
mAlbumCount = data.getCount();
+ if (mInitialPhotoUri != null) {
+ int index = 0;
+ int uriIndex = data.getColumnIndex(PhotoContract.PhotoViewColumns.URI);
+ while (data.moveToNext()) {
+ String uri = data.getString(uriIndex);
+ if (TextUtils.equals(uri, mInitialPhotoUri)) {
+ mInitialPhotoUri = null;
+ mPhotoIndex = index;
+ break;
+ }
+ index++;
+ }
+ }
+
// We're paused; don't do anything now, we'll get re-invoked
// when the activity becomes active again
// TODO(pwestbro): This shouldn't be necessary, as the loader manager should
@@ -306,6 +343,9 @@ public class PhotoViewActivity extends Activity implements
}
mIsEmpty = false;
+ mAdapter.swapCursor(data);
+ notifyCursorListeners(data);
+
// set the selected photo
int itemIndex = mPhotoIndex;
@@ -314,9 +354,6 @@ public class PhotoViewActivity extends Activity implements
itemIndex = 0;
}
- mAdapter.swapCursor(data);
- notifyCursorListeners(data);
-
mViewPager.setCurrentItem(itemIndex, false);
setViewActivated();
}
@@ -398,7 +435,7 @@ public class PhotoViewActivity extends Activity implements
/**
* Updates the title bar according to the value of {@link #mFullScreen}.
*/
- private void setFullScreen(boolean fullScreen, boolean setDelayedRunnable) {
+ protected void setFullScreen(boolean fullScreen, boolean setDelayedRunnable) {
final boolean fullScreenChanged = (fullScreen != mFullScreen);
mFullScreen = fullScreen;
@@ -428,7 +465,7 @@ public class PhotoViewActivity extends Activity implements
mHandler.removeCallbacks(mActionBarHideRunnable);
}
- private void setLightsOutMode(boolean enabled) {
+ protected void setLightsOutMode(boolean enabled) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
int flags = enabled
? View.SYSTEM_UI_FLAG_LOW_PROFILE
@@ -457,7 +494,7 @@ public class PhotoViewActivity extends Activity implements
private Runnable mActionBarHideRunnable = new Runnable() {
@Override
public void run() {
- PhotoViewActivity.this.setLightsOutMode(true);
+ setFullScreen(true, true);
}
};
@@ -532,4 +569,12 @@ public class PhotoViewActivity extends Activity implements
postActionBarHideRunnableWithDelay();
}
}
+
+ protected boolean isFullScreen() {
+ return mFullScreen;
+ }
+
+ protected void setPhotoIndex(int index) {
+ mPhotoIndex = index;
+ }
}