summaryrefslogtreecommitdiffstats
path: root/src/com/android/mail/ui/ViewMode.java
diff options
context:
space:
mode:
authorVikram Aggarwal <viki@google.com>2012-01-30 14:02:31 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-01-30 14:02:31 -0800
commit28fed29538b1a9384d4ec4f22cdf7e3e2ee18275 (patch)
treee16f3a969e903ac17c5d559537a42260d7345503 /src/com/android/mail/ui/ViewMode.java
parent545f0ec8b094f243258f106d5a350bf02893c01e (diff)
parentb9e1a353c6a173a2885642dbcc1939f3281f29f7 (diff)
downloadandroid_packages_apps_UnifiedEmail-28fed29538b1a9384d4ec4f22cdf7e3e2ee18275.tar.gz
android_packages_apps_UnifiedEmail-28fed29538b1a9384d4ec4f22cdf7e3e2ee18275.tar.bz2
android_packages_apps_UnifiedEmail-28fed29538b1a9384d4ec4f22cdf7e3e2ee18275.zip
Merge "Create ConversationListFragment"
Diffstat (limited to 'src/com/android/mail/ui/ViewMode.java')
-rw-r--r--src/com/android/mail/ui/ViewMode.java166
1 files changed, 82 insertions, 84 deletions
diff --git a/src/com/android/mail/ui/ViewMode.java b/src/com/android/mail/ui/ViewMode.java
index 01b10be82..154822ce5 100644
--- a/src/com/android/mail/ui/ViewMode.java
+++ b/src/com/android/mail/ui/ViewMode.java
@@ -17,12 +17,13 @@
package com.android.mail.ui;
-import com.android.mail.utils.Utils;
import com.google.common.collect.Lists;
import android.content.Context;
import android.os.Bundle;
+import com.android.mail.utils.Utils;
+
import java.util.ArrayList;
@@ -32,103 +33,92 @@ import java.util.ArrayList;
* dependent on the mode should listen to changes on this object.
*/
public class ViewMode {
- // Key used to save this {@link ViewMode}.
- private static final String VIEW_MODE_KEY = "view-mode";
-
// Do not change the order of the values in the enum. The ordinal position is used in a
// saved instance bundle. When adding values, add them to the end of the enum.
/**
* All possible modes that a Mail activity can be in.
*/
public static enum Mode {
- /**
- * Uncertain mode. The mode has not been initialized.
- */
- MODE_UNKNOWN,
- /**
- * Mode when showing a list of folders.
+ /** Mode when showing a single conversation.
*/
- MODE_FOLDER_LIST,
+ MODE_CONVERSATION,
/**
* Mode when showing a list of conversations
*/
MODE_CONVERSATION_LIST,
/**
- * Mode when showing a single conversation.
+ * Mode when showing a list of folders.
*/
- MODE_CONVERSATION,
+ MODE_FOLDER_LIST,
/**
* Mode when showing results from user search.
*/
MODE_SEARCH_RESULTS,
+ /**
+ * Uncertain mode. The mode has not been initialized.
+ */
+ MODE_UNKNOWN,
}
- // Handy names for external users of this class.
/**
- * Uncertain mode. The mode has not been initialized.
+ * A listener for changes on a ViewMode.
*/
- public static Mode UNKNOWN = Mode.MODE_UNKNOWN;
+ public interface ModeChangeListener {
+ /**
+ * Handles a mode change.
+ */
+ void onViewModeChanged(ViewMode mode);
+ }
+
/**
- * Mode when showing a list of folders.
+ * Mode when showing a single conversation.
*/
- public static Mode FOLDER_LIST = Mode.MODE_FOLDER_LIST;
+ public static Mode CONVERSATION = Mode.MODE_CONVERSATION;
/**
* Mode when showing a list of conversations
*/
public static Mode CONVERSATION_LIST = Mode.MODE_CONVERSATION_LIST;
/**
- * Mode when showing a single conversation.
+ * Mode when showing a list of folders.
*/
- public static Mode CONVERSATION = Mode.MODE_CONVERSATION;
+ public static Mode FOLDER_LIST = Mode.MODE_FOLDER_LIST;
/**
* Mode when showing results from user search.
*/
public static Mode SEARCH_RESULTS = Mode.MODE_SEARCH_RESULTS;
+ // Handy names for external users of this class.
+ /**
+ * Uncertain mode. The mode has not been initialized.
+ */
+ public static Mode UNKNOWN = Mode.MODE_UNKNOWN;
- private Mode mMode = UNKNOWN;
- private final boolean mTwoPane;
+ // Key used to save this {@link ViewMode}.
+ private static final String VIEW_MODE_KEY = "view-mode";
private final ArrayList<ModeChangeListener> mListeners = Lists.newArrayList();
+ private Mode mMode = UNKNOWN;
+ private boolean mTwoPane;
public ViewMode(Context context) {
mTwoPane = Utils.useTabletUI(context);
}
/**
- * 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 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 the folder list as the prominent view.
- * @return Whether or not a change occured.
+ * Adds a listener from this view mode.
+ * Must happen in the UI thread.
*/
- public boolean transitionToFolderListMode() {
- return setModeInternal(FOLDER_LIST);
+ public void addListener(ModeChangeListener listener) {
+ mListeners.add(listener);
}
/**
- * Sets the internal mode.
- * @return Whether or not a change occured.
+ * Dispatches a change event for the mode.
+ * Always happens in the UI thread.
*/
- private boolean setModeInternal(Mode mode) {
- if (mMode == mode) {
- return false;
+ private void dispatchModeChange() {
+ ArrayList<ModeChangeListener> list = new ArrayList<ModeChangeListener>(mListeners);
+ for (ModeChangeListener listener : list) {
+ listener.onViewModeChanged(this);
}
-
- mMode = mode;
- dispatchModeChange();
- return true;
}
/**
@@ -138,68 +128,76 @@ public class ViewMode {
return mMode;
}
- /**
- * @return Whether or not to display 2 pane.
- */
- public boolean isTwoPane() {
- return mTwoPane;
+ public void handleRestore(Bundle inState) {
+ Mode mode = Mode.values()[inState.getInt(VIEW_MODE_KEY, UNKNOWN.ordinal())];
+ setModeInternal(mode);
}
- public boolean isConversationMode() {
- return mMode == CONVERSATION;
+ public void handleSaveInstanceState(Bundle outState) {
+ outState.putInt(VIEW_MODE_KEY, mMode.ordinal());
}
public boolean isConversationListMode() {
return mMode == CONVERSATION_LIST;
}
+ public boolean isConversationMode() {
+ return mMode == CONVERSATION;
+ }
+
public boolean isFolderListMode() {
return mMode == FOLDER_LIST;
}
- public void handleSaveInstanceState(Bundle outState) {
- outState.putInt(VIEW_MODE_KEY, mMode.ordinal());
+ /**
+ * @return Whether or not to display 2 pane.
+ */
+ public boolean isTwoPane() {
+ return mTwoPane;
}
- public void handleRestore(Bundle inState) {
- Mode mode = Mode.values()[inState.getInt(VIEW_MODE_KEY, UNKNOWN.ordinal())];
- setModeInternal(mode);
+ /**
+ * Removes a listener from this view mode.
+ * Must happen in the UI thread.
+ */
+ public void removeListener(ModeChangeListener listener) {
+ mListeners.remove(listener);
}
/**
- * A listener for changes on a ViewMode.
+ * Sets the internal mode.
+ * @return Whether or not a change occured.
*/
- public interface ModeChangeListener {
- /**
- * Handles a mode change.
- */
- void onViewModeChanged(ViewMode mode);
+ private boolean setModeInternal(Mode mode) {
+ if (mMode == mode) {
+ return false;
+ }
+ mMode = mode;
+ dispatchModeChange();
+ return true;
}
/**
- * Adds a listener from this view mode.
- * Must happen in the UI thread.
+ * Requests a transition of the mode to show the conversation list as the prominent view.
+ * @return Whether or not a change occured.
*/
- public void addListener(ModeChangeListener listener) {
- mListeners.add(listener);
+ public boolean transitionToConversationListMode() {
+ return setModeInternal(CONVERSATION_LIST);
}
/**
- * Removes a listener from this view mode.
- * Must happen in the UI thread.
+ * Requests a transition of the mode to show a conversation as the prominent view.
+ * @return Whether or not a change occured.
*/
- public void removeListener(ModeChangeListener listener) {
- mListeners.remove(listener);
+ public boolean transitionToConversationMode() {
+ return setModeInternal(CONVERSATION);
}
/**
- * Dispatches a change event for the mode.
- * Always happens in the UI thread.
+ * Requests a transition of the mode to show the folder list as the prominent view.
+ * @return Whether or not a change occured.
*/
- private void dispatchModeChange() {
- ArrayList<ModeChangeListener> list = new ArrayList<ModeChangeListener>(mListeners);
- for (ModeChangeListener listener : list) {
- listener.onViewModeChanged(this);
- }
+ public boolean transitionToFolderListMode() {
+ return setModeInternal(FOLDER_LIST);
}
}