TwoPaneController.java revision 28d5f72e0ad0db75b6243ee8125bfe3aadbdcb85
1/******************************************************************************* 2 * Copyright (C) 2012 Google Inc. 3 * Licensed to The Android Open Source Project. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 *******************************************************************************/ 17 18package com.android.mail.ui; 19 20import com.android.mail.ConversationListContext; 21import com.android.mail.R; 22 23import android.app.Fragment; 24import android.app.FragmentTransaction; 25import android.os.Bundle; 26import android.view.Window; 27 28 29/** 30 * Controller for one-pane Mail activity. One Pane is used for phones, where screen real estate is 31 * limited. 32 */ 33 34// Called OnePaneActivityController in Gmail. 35public final class TwoPaneController extends AbstractActivityController { 36 private boolean mJumpToFirstConversation; 37 private TwoPaneLayout mLayout; 38 39 /** 40 * @param activity 41 * @param viewMode 42 */ 43 public TwoPaneController(MailActivity activity, ViewMode viewMode) { 44 super(activity, viewMode); 45 // TODO(viki): Auto-generated constructor stub 46 } 47 48 /** 49 * Display the conversation list fragment. 50 * @param show 51 */ 52 private void initializeConversationListFragment(boolean show) { 53 if (show) { 54 mViewMode.enterConversationListMode(); 55 } 56 FragmentTransaction fragmentTransaction = mActivity.getFragmentManager().beginTransaction(); 57 // Use cross fading animation. 58 fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 59 Fragment conversationListFragment = ConversationListFragment 60 .newInstance(mConvListContext); 61 fragmentTransaction.replace(R.id.conversation_list_pane, conversationListFragment); 62 fragmentTransaction.commitAllowingStateLoss(); 63 } 64 65 @Override 66 protected boolean isConversationListVisible() { 67 // TODO(viki): Auto-generated method stub 68 return false; 69 } 70 71 @Override 72 public void showConversationList(ConversationListContext context) { 73 initializeConversationListFragment(true); 74 } 75 76 @Override 77 public void showFolderList() { 78 // TODO: auto-generated method stub. 79 } 80 81 @Override 82 public boolean onCreate(Bundle savedState) { 83 mActivity.setContentView(R.layout.two_pane_activity); 84 85 mLayout = (TwoPaneLayout) mActivity.findViewById(R.id.two_pane_activity); 86 mLayout.initializeLayout(mActivity.getApplicationContext()); 87 88 // The tablet layout needs to refer to mode changes. 89 mViewMode.addListener(mLayout); 90 // The activity controller needs to listen to layout changes. 91 mLayout.setListener(this); 92 93 final boolean isParentInitialized = super.onCreate(savedState); 94 if (isParentInitialized && savedState == null) { 95 // Show a Label list, in the real application 96 // renderLabelList(); 97 // In our case, we show a conversation list for everything. 98 } 99 return isParentInitialized; 100 } 101 102 @Override 103 public void onViewModeChanged(int newMode) { 104 super.onViewModeChanged(newMode); 105 if (newMode != ViewMode.CONVERSATION) { 106 // Clear this flag if the user jumps out of conversation mode 107 // before a load completes. 108 mJumpToFirstConversation = false; 109 } 110 } 111 112 @Override 113 public void resetActionBarIcon() { 114 if (mViewMode.getMode() == ViewMode.CONVERSATION_LIST) { 115 mActionBarView.removeBackButton(); 116 } else { 117 mActionBarView.setBackButton(); 118 } 119 } 120 121} 122