Remove PhotoViewFragment's dependency on PhotoViewActivity
Now, there is a interface called PhotoViewCallbacks
that PhotoViewFragment depends upon. This way other
users can use PhotoViewFragment without using
PhotoViewActivity.
Change-Id: Ibbda93d2e0226bcc993ef98be1de7cf3a323f41a
diff --git a/src/com/android/ex/photo/PhotoViewActivity.java b/src/com/android/ex/photo/PhotoViewActivity.java
index ed4576d..5229375 100644
--- a/src/com/android/ex/photo/PhotoViewActivity.java
+++ b/src/com/android/ex/photo/PhotoViewActivity.java
@@ -50,51 +50,7 @@
*/
public class PhotoViewActivity extends FragmentActivity implements
LoaderManager.LoaderCallbacks<Cursor>, OnPageChangeListener, OnInterceptTouchListener,
- OnMenuVisibilityListener {
-
- /**
- * Listener to be invoked for screen events.
- */
- public static interface OnScreenListener {
-
- /**
- * The full screen state has changed.
- */
- public void onFullScreenChanged(boolean fullScreen);
-
- /**
- * A new view has been activated and the previous view de-activated.
- */
- public void onViewActivated();
-
- /**
- * Called when a right-to-left touch move intercept is about to occur.
- *
- * @param origX the raw x coordinate of the initial touch
- * @param origY the raw y coordinate of the initial touch
- * @return {@code true} if the touch should be intercepted.
- */
- public boolean onInterceptMoveLeft(float origX, float origY);
-
- /**
- * Called when a left-to-right touch move intercept is about to occur.
- *
- * @param origX the raw x coordinate of the initial touch
- * @param origY the raw y coordinate of the initial touch
- * @return {@code true} if the touch should be intercepted.
- */
- public boolean onInterceptMoveRight(float origX, float origY);
- }
-
- public static interface CursorChangedListener {
- /**
- * Called when the cursor that contains the photo list data
- * is updated. Note that there is no guarantee that the cursor
- * will be at the proper position.
- * @param cursor the cursor containing the photo list data
- */
- public void onCursorChanged(Cursor cursor);
- }
+ OnMenuVisibilityListener, PhotoViewCallbacks {
private final static String STATE_ITEM_KEY =
"com.google.android.apps.plus.PhotoViewFragment.ITEM";
@@ -254,22 +210,27 @@
}
}
+ @Override
public void addScreenListener(OnScreenListener listener) {
mScreenListeners.add(listener);
}
+ @Override
public void removeScreenListener(OnScreenListener listener) {
mScreenListeners.remove(listener);
}
+ @Override
public synchronized void addCursorListener(CursorChangedListener listener) {
mCursorListeners.add(listener);
}
+ @Override
public synchronized void removeCursorListener(CursorChangedListener listener) {
mCursorListeners.remove(listener);
}
+ @Override
public boolean isFragmentFullScreen(Fragment fragment) {
if (mViewPager == null || mAdapter == null || mAdapter.getCount() == 0) {
return mFullScreen;
@@ -277,6 +238,7 @@
return mFullScreen || (mViewPager.getCurrentItem() != mAdapter.getItemPosition(fragment));
}
+ @Override
public void toggleFullScreen() {
setFullScreen(!mFullScreen, true);
}
@@ -376,6 +338,7 @@
public void onPageScrollStateChanged(int state) {
}
+ @Override
public boolean isFragmentActive(Fragment fragment) {
if (mViewPager == null || mAdapter == null) {
return false;
@@ -479,6 +442,7 @@
}
};
+ @Override
public void setViewActivated() {
for (OnScreenListener listener : mScreenListeners) {
listener.onViewActivated();
diff --git a/src/com/android/ex/photo/PhotoViewCallbacks.java b/src/com/android/ex/photo/PhotoViewCallbacks.java
new file mode 100644
index 0000000..2d4e84a
--- /dev/null
+++ b/src/com/android/ex/photo/PhotoViewCallbacks.java
@@ -0,0 +1,70 @@
+package com.android.ex.photo;
+
+import android.database.Cursor;
+import android.support.v4.app.Fragment;
+
+import com.android.ex.photo.fragments.PhotoViewFragment;
+
+public interface PhotoViewCallbacks {
+ /**
+ * Listener to be invoked for screen events.
+ */
+ public static interface OnScreenListener {
+
+ /**
+ * The full screen state has changed.
+ */
+ public void onFullScreenChanged(boolean fullScreen);
+
+ /**
+ * A new view has been activated and the previous view de-activated.
+ */
+ public void onViewActivated();
+
+ /**
+ * Called when a right-to-left touch move intercept is about to occur.
+ *
+ * @param origX the raw x coordinate of the initial touch
+ * @param origY the raw y coordinate of the initial touch
+ * @return {@code true} if the touch should be intercepted.
+ */
+ public boolean onInterceptMoveLeft(float origX, float origY);
+
+ /**
+ * Called when a left-to-right touch move intercept is about to occur.
+ *
+ * @param origX the raw x coordinate of the initial touch
+ * @param origY the raw y coordinate of the initial touch
+ * @return {@code true} if the touch should be intercepted.
+ */
+ public boolean onInterceptMoveRight(float origX, float origY);
+ }
+
+ public static interface CursorChangedListener {
+ /**
+ * Called when the cursor that contains the photo list data
+ * is updated. Note that there is no guarantee that the cursor
+ * will be at the proper position.
+ * @param cursor the cursor containing the photo list data
+ */
+ public void onCursorChanged(Cursor cursor);
+ }
+
+ public void addScreenListener(OnScreenListener listener);
+
+ public void removeScreenListener(OnScreenListener listener);
+
+ public void addCursorListener(CursorChangedListener listener);
+
+ public void removeCursorListener(CursorChangedListener listener);
+
+ public void setViewActivated();
+
+ public void toggleFullScreen();
+
+ public boolean isFragmentActive(Fragment fragment);
+
+ public void onFragmentVisible(PhotoViewFragment fragment);
+
+ public boolean isFragmentFullScreen(Fragment fragment);
+}
diff --git a/src/com/android/ex/photo/fragments/PhotoViewFragment.java b/src/com/android/ex/photo/fragments/PhotoViewFragment.java
index bb6496a..efa9404 100644
--- a/src/com/android/ex/photo/fragments/PhotoViewFragment.java
+++ b/src/com/android/ex/photo/fragments/PhotoViewFragment.java
@@ -37,9 +37,9 @@
import android.widget.TextView;
import com.android.ex.photo.Intents;
-import com.android.ex.photo.PhotoViewActivity;
-import com.android.ex.photo.PhotoViewActivity.CursorChangedListener;
-import com.android.ex.photo.PhotoViewActivity.OnScreenListener;
+import com.android.ex.photo.PhotoViewCallbacks;
+import com.android.ex.photo.PhotoViewCallbacks.CursorChangedListener;
+import com.android.ex.photo.PhotoViewCallbacks.OnScreenListener;
import com.android.ex.photo.R;
import com.android.ex.photo.adapters.PhotoPagerAdapter;
import com.android.ex.photo.loaders.PhotoBitmapLoader;
@@ -91,7 +91,7 @@
private String mThumbnailUri;
/** The intent we were launched with */
private Intent mIntent;
- private PhotoViewActivity mCallback;
+ private PhotoViewCallbacks mCallback;
private PhotoPagerAdapter mAdapter;
private PhotoView mPhotoView;
@@ -131,7 +131,7 @@
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
- mCallback = (PhotoViewActivity) activity;
+ mCallback = (PhotoViewCallbacks) activity;
if (mCallback == null) {
throw new IllegalArgumentException(
"Activity must be a derived class of PhotoViewActivity");