1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.messaging.ui.conversationlist;
18 
19 import android.graphics.drawable.ColorDrawable;
20 import android.os.Bundle;
21 import android.support.v7.app.ActionBar;
22 import android.view.Menu;
23 import android.view.MenuItem;
24 
25 import com.android.messaging.R;
26 import com.android.messaging.ui.UIIntents;
27 import com.android.messaging.util.DebugUtils;
28 import com.android.messaging.util.Trace;
29 
30 public class ConversationListActivity extends AbstractConversationListActivity {
31     @Override
onCreate(final Bundle savedInstanceState)32     protected void onCreate(final Bundle savedInstanceState) {
33         Trace.beginSection("ConversationListActivity.onCreate");
34         super.onCreate(savedInstanceState);
35         setContentView(R.layout.conversation_list_activity);
36         Trace.endSection();
37         invalidateActionBar();
38     }
39 
40     @Override
updateActionBar(final ActionBar actionBar)41     protected void updateActionBar(final ActionBar actionBar) {
42         actionBar.setTitle(getString(R.string.app_name));
43         actionBar.setDisplayShowTitleEnabled(true);
44         actionBar.setDisplayHomeAsUpEnabled(false);
45         actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
46         actionBar.setBackgroundDrawable(new ColorDrawable(
47                 getResources().getColor(R.color.action_bar_background_color)));
48         actionBar.show();
49         super.updateActionBar(actionBar);
50     }
51 
52     @Override
onResume()53     public void onResume() {
54         super.onResume();
55         // Invalidate the menu as items that are based on settings may have changed
56         // while not in the app (e.g. Talkback enabled/disable affects new conversation
57         // button)
58         supportInvalidateOptionsMenu();
59     }
60 
61     @Override
onBackPressed()62     public void onBackPressed() {
63         if (isInConversationListSelectMode()) {
64             exitMultiSelectState();
65         } else {
66             super.onBackPressed();
67         }
68     }
69 
70     @Override
onCreateOptionsMenu(final Menu menu)71     public boolean onCreateOptionsMenu(final Menu menu) {
72         if (super.onCreateOptionsMenu(menu)) {
73             return true;
74         }
75         getMenuInflater().inflate(R.menu.conversation_list_fragment_menu, menu);
76         final MenuItem item = menu.findItem(R.id.action_debug_options);
77         if (item != null) {
78             final boolean enableDebugItems = DebugUtils.isDebugEnabled();
79             item.setVisible(enableDebugItems).setEnabled(enableDebugItems);
80         }
81         return true;
82     }
83 
84     @Override
onOptionsItemSelected(final MenuItem menuItem)85     public boolean onOptionsItemSelected(final MenuItem menuItem) {
86         switch(menuItem.getItemId()) {
87             case R.id.action_start_new_conversation:
88                 onActionBarStartNewConversation();
89                 return true;
90             case R.id.action_settings:
91                 onActionBarSettings();
92                 return true;
93             case R.id.action_debug_options:
94                 onActionBarDebug();
95                 return true;
96             case R.id.action_show_archived:
97                 onActionBarArchived();
98                 return true;
99             case R.id.action_show_blocked_contacts:
100                 onActionBarBlockedParticipants();
101                 return true;
102         }
103         return super.onOptionsItemSelected(menuItem);
104     }
105 
106     @Override
onActionBarHome()107     public void onActionBarHome() {
108         exitMultiSelectState();
109     }
110 
onActionBarStartNewConversation()111     public void onActionBarStartNewConversation() {
112         UIIntents.get().launchCreateNewConversationActivity(this, null);
113     }
114 
onActionBarSettings()115     public void onActionBarSettings() {
116         UIIntents.get().launchSettingsActivity(this);
117     }
118 
onActionBarBlockedParticipants()119     public void onActionBarBlockedParticipants() {
120         UIIntents.get().launchBlockedParticipantsActivity(this);
121     }
122 
onActionBarArchived()123     public void onActionBarArchived() {
124         UIIntents.get().launchArchivedConversationsActivity(this);
125     }
126 
127     @Override
isSwipeAnimatable()128     public boolean isSwipeAnimatable() {
129         return !isInConversationListSelectMode();
130     }
131 
132     @Override
onWindowFocusChanged(final boolean hasFocus)133     public void onWindowFocusChanged(final boolean hasFocus) {
134         super.onWindowFocusChanged(hasFocus);
135         final ConversationListFragment conversationListFragment =
136                 (ConversationListFragment) getFragmentManager().findFragmentById(
137                         R.id.conversation_list_fragment);
138         // When the screen is turned on, the last used activity gets resumed, but it gets
139         // window focus only after the lock screen is unlocked.
140         if (hasFocus && conversationListFragment != null) {
141             conversationListFragment.setScrolledToNewestConversationIfNeeded();
142         }
143     }
144 }
145