• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.dialer.main.impl;
18 
19 import android.content.Context;
20 import android.content.Intent;
21 import android.os.Bundle;
22 import com.android.dialer.common.Assert;
23 import com.android.dialer.common.LogUtil;
24 import com.android.dialer.configprovider.ConfigProviderBindings;
25 import com.android.dialer.interactions.PhoneNumberInteraction.DisambigDialogDismissedListener;
26 import com.android.dialer.interactions.PhoneNumberInteraction.InteractionErrorCode;
27 import com.android.dialer.interactions.PhoneNumberInteraction.InteractionErrorListener;
28 import com.android.dialer.main.MainActivityPeer;
29 import com.android.dialer.main.impl.bottomnav.BottomNavBar.TabIndex;
30 import com.android.dialer.util.TransactionSafeActivity;
31 
32 /** This is the main activity for dialer. It hosts favorites, call log, search, dialpad, etc... */
33 // TODO(calderwoodra): Do not extend TransactionSafeActivity after new SpeedDial is launched
34 public class MainActivity extends TransactionSafeActivity
35     implements MainActivityPeer.PeerSupplier,
36         // TODO(calderwoodra): remove these 2 interfaces when we migrate to new speed dial fragment
37         InteractionErrorListener,
38         DisambigDialogDismissedListener {
39 
40   private MainActivityPeer activePeer;
41 
getShowCallLogIntent(Context context)42   public static Intent getShowCallLogIntent(Context context) {
43     return getShowTabIntent(context, TabIndex.CALL_LOG);
44   }
45 
46   /** Returns intent that will open MainActivity to the specified tab. */
getShowTabIntent(Context context, @TabIndex int tabIndex)47   public static Intent getShowTabIntent(Context context, @TabIndex int tabIndex) {
48     if (ConfigProviderBindings.get(context).getBoolean("nui_peer_enabled", false)) {
49       // TODO(calderwoodra): implement this in NewMainActivityPeer
50       return null;
51     }
52     return OldMainActivityPeer.getShowTabIntent(context, tabIndex);
53   }
54 
55   /**
56    * @param context Context of the application package implementing MainActivity class.
57    * @return intent for MainActivity.class
58    */
getIntent(Context context)59   public static Intent getIntent(Context context) {
60     return new Intent(context, MainActivity.class)
61         .setAction(Intent.ACTION_VIEW)
62         .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
63   }
64 
65   @Override
onCreate(Bundle savedInstanceState)66   protected void onCreate(Bundle savedInstanceState) {
67     super.onCreate(savedInstanceState);
68     LogUtil.enterBlock("MainActivity.onCreate");
69     // If peer was set by the super, don't reset it.
70     activePeer = getNewPeer();
71     activePeer.onActivityCreate(savedInstanceState);
72   }
73 
getNewPeer()74   protected MainActivityPeer getNewPeer() {
75     if (ConfigProviderBindings.get(this).getBoolean("nui_peer_enabled", false)) {
76       return new NewMainActivityPeer(this);
77     } else {
78       return new OldMainActivityPeer(this);
79     }
80   }
81 
82   @Override
onNewIntent(Intent intent)83   protected void onNewIntent(Intent intent) {
84     super.onNewIntent(intent);
85     setIntent(intent);
86     activePeer.onNewIntent(intent);
87   }
88 
89   @Override
onResume()90   protected void onResume() {
91     super.onResume();
92     activePeer.onActivityResume();
93   }
94 
95   @Override
onUserLeaveHint()96   protected void onUserLeaveHint() {
97     super.onUserLeaveHint();
98     activePeer.onUserLeaveHint();
99   }
100 
101   @Override
onPause()102   protected void onPause() {
103     super.onPause();
104     activePeer.onActivityPause();
105   }
106 
107   @Override
onStop()108   protected void onStop() {
109     super.onStop();
110     activePeer.onActivityStop();
111   }
112 
113   @Override
onSaveInstanceState(Bundle bundle)114   protected void onSaveInstanceState(Bundle bundle) {
115     super.onSaveInstanceState(bundle);
116     activePeer.onSaveInstanceState(bundle);
117   }
118 
119   @Override
onActivityResult(int requestCode, int resultCode, Intent data)120   protected void onActivityResult(int requestCode, int resultCode, Intent data) {
121     super.onActivityResult(requestCode, resultCode, data);
122     activePeer.onActivityResult(requestCode, resultCode, data);
123   }
124 
125   @Override
onBackPressed()126   public void onBackPressed() {
127     if (activePeer.onBackPressed()) {
128       return;
129     }
130     super.onBackPressed();
131   }
132 
133   @Override
interactionError(@nteractionErrorCode int interactionErrorCode)134   public void interactionError(@InteractionErrorCode int interactionErrorCode) {
135     switch (interactionErrorCode) {
136       case InteractionErrorCode.USER_LEAVING_ACTIVITY:
137         // This is expected to happen if the user exits the activity before the interaction occurs.
138         return;
139       case InteractionErrorCode.CONTACT_NOT_FOUND:
140       case InteractionErrorCode.CONTACT_HAS_NO_NUMBER:
141       case InteractionErrorCode.OTHER_ERROR:
142       default:
143         // All other error codes are unexpected. For example, it should be impossible to start an
144         // interaction with an invalid contact from this activity.
145         throw Assert.createIllegalStateFailException(
146             "PhoneNumberInteraction error: " + interactionErrorCode);
147     }
148   }
149 
150   @Override
onDisambigDialogDismissed()151   public void onDisambigDialogDismissed() {
152     // Don't do anything; the app will remain open with favorites tiles displayed.
153   }
154 
155   @Override
getPeer()156   public MainActivityPeer getPeer() {
157     return activePeer;
158   }
159 }
160