summaryrefslogtreecommitdiffstats
path: root/src/com/android/mail/ui/ViewMode.java
diff options
context:
space:
mode:
authorVikram Aggarwal <viki@google.com>2012-02-02 13:56:22 -0800
committerVikram Aggarwal <viki@google.com>2012-02-02 13:56:22 -0800
commitfa131a2ff399fd1d544f759b063268fb4e8a3e70 (patch)
tree5242e380a31326613b067f73e32d29a444194c94 /src/com/android/mail/ui/ViewMode.java
parentc43bc0a606e41144a780c4f873b5450e0ede0c91 (diff)
downloadandroid_packages_apps_UnifiedEmail-fa131a2ff399fd1d544f759b063268fb4e8a3e70.tar.gz
android_packages_apps_UnifiedEmail-fa131a2ff399fd1d544f759b063268fb4e8a3e70.tar.bz2
android_packages_apps_UnifiedEmail-fa131a2ff399fd1d544f759b063268fb4e8a3e70.zip
Make ViewMode focussed and small.
1. ViewMode is no longer aware of tablet versus phone UI. This is the responsibility of the ActivityController now. 2. onViewModeChange receives the new mode as an integer rather than the ViewMode object. 3. Rather than a plethora of isXMode() isYMode() methods, client classes need to manually check getMode() against ViewMode.X ViewMode.Y constants. Change-Id: Ib06196671ad49328c40cc9237667c0a1daf328f7
Diffstat (limited to 'src/com/android/mail/ui/ViewMode.java')
-rw-r--r--src/com/android/mail/ui/ViewMode.java101
1 files changed, 47 insertions, 54 deletions
diff --git a/src/com/android/mail/ui/ViewMode.java b/src/com/android/mail/ui/ViewMode.java
index 82159f7bc..96c42bd91 100644
--- a/src/com/android/mail/ui/ViewMode.java
+++ b/src/com/android/mail/ui/ViewMode.java
@@ -22,8 +22,6 @@ import com.google.common.collect.Lists;
import android.content.Context;
import android.os.Bundle;
-import com.android.mail.utils.Utils;
-
import java.util.ArrayList;
/**
@@ -33,13 +31,15 @@ import java.util.ArrayList;
*/
public class ViewMode {
/**
- * A listener for changes on a ViewMode.
+ * A listener for changes on a ViewMode. To listen to mode changes, implement this
+ * interface and register your object with the single ViewMode held by the ActivityController
+ * instance. On mode changes, the onViewModeChanged method will be called with the new mode.
*/
public interface ModeChangeListener {
/**
- * Handles a mode change.
+ * Called when the mode has changed.
*/
- void onViewModeChanged(ViewMode mode);
+ void onViewModeChanged(int newMode);
}
/**
@@ -66,11 +66,14 @@ public class ViewMode {
// Key used to save this {@link ViewMode}.
private static final String VIEW_MODE_KEY = "view-mode";
private final ArrayList<ModeChangeListener> mListeners = Lists.newArrayList();
+ /**
+ * The actual mode the activity is in. We start out with an UNKNOWN mode, and require entering
+ * a valid mode after the object has been created.
+ */
private int mMode = UNKNOWN;
- private boolean mTwoPane;
public ViewMode(Context context) {
- mTwoPane = Utils.useTabletUI(context);
+ // Do nothing
}
/**
@@ -85,45 +88,60 @@ public class ViewMode {
* Dispatches a change event for the mode.
* Always happens in the UI thread.
*/
- private void dispatchModeChange() {
+ private void dispatchModeChange(int newMode) {
+ mMode = newMode;
ArrayList<ModeChangeListener> list = new ArrayList<ModeChangeListener>(mListeners);
for (ModeChangeListener listener : list) {
- listener.onViewModeChanged(this);
+ listener.onViewModeChanged(newMode);
}
}
/**
- * @return The current mode.
+ * Requests a transition of the mode to show the conversation list as the prominent view.
+ * @return Whether or not a change occurred.
*/
- public int getMode() {
- return mMode;
- }
-
- public void handleRestore(Bundle inState) {
- mMode = inState.getInt(VIEW_MODE_KEY);
+ public boolean enterConversationListMode() {
+ return setModeInternal(CONVERSATION_LIST);
}
- public void handleSaveInstanceState(Bundle outState) {
- outState.putInt(VIEW_MODE_KEY, mMode);
+ /**
+ * Requests a transition of the mode to show a conversation as the prominent view.
+ * @return Whether or not a change occurred.
+ */
+ public boolean enterConversationMode() {
+ return setModeInternal(CONVERSATION);
}
- public boolean isConversationListMode() {
- return mMode == CONVERSATION_LIST;
+ /**
+ * Requests a transition of the mode to show the folder list as the prominent view.
+ * @return Whether or not a change occurred.
+ */
+ public boolean enterFolderListMode() {
+ return setModeInternal(FOLDER_LIST);
}
- public boolean isConversationMode() {
- return mMode == CONVERSATION;
+ /**
+ * @return The current mode.
+ */
+ public int getMode() {
+ return mMode;
}
- public boolean isFolderListMode() {
- return mMode == FOLDER_LIST;
+ /**
+ * Restoring from a saved state restores only the mode. It does not restore the listeners of
+ * this object.
+ * @param inState
+ */
+ public void handleRestore(Bundle inState) {
+ mMode = inState.getInt(VIEW_MODE_KEY);
}
/**
- * @return Whether or not to display 2 pane.
+ * Save the existing mode only. Does not save the existing listeners.
+ * @param outState
*/
- public boolean isTwoPane() {
- return mTwoPane;
+ public void handleSaveInstanceState(Bundle outState) {
+ outState.putInt(VIEW_MODE_KEY, mMode);
}
/**
@@ -136,38 +154,13 @@ public class ViewMode {
/**
* Sets the internal mode.
- * @return Whether or not a change occured.
+ * @return Whether or not a change occurred.
*/
private boolean setModeInternal(int mode) {
if (mMode == mode) {
return false;
}
- mMode = mode;
- dispatchModeChange();
+ dispatchModeChange(mode);
return true;
}
-
- /**
- * Requests a transition of the mode to show the conversation list as the prominent view.
- * @return Whether or not a change occured.
- */
- public boolean transitionToConversationListMode() {
- return setModeInternal(CONVERSATION_LIST);
- }
-
- /**
- * Requests a transition of the mode to show a conversation as the prominent view.
- * @return Whether or not a change occured.
- */
- public boolean transitionToConversationMode() {
- return setModeInternal(CONVERSATION);
- }
-
- /**
- * Requests a transition of the mode to show the folder list as the prominent view.
- * @return Whether or not a change occured.
- */
- public boolean transitionToFolderListMode() {
- return setModeInternal(FOLDER_LIST);
- }
}