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 package com.android.dialer.app.filterednumber; 17 18 import android.os.Bundle; 19 import android.support.v7.app.AppCompatActivity; 20 import android.view.MenuItem; 21 import com.android.dialer.app.R; 22 import com.android.dialer.logging.Logger; 23 import com.android.dialer.logging.ScreenEvent; 24 25 /** TODO(calderwoodra): documentation */ 26 public class BlockedNumbersSettingsActivity extends AppCompatActivity { 27 28 private static final String TAG_BLOCKED_MANAGEMENT_FRAGMENT = "blocked_management"; 29 private static final String TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT = "view_numbers_to_import"; 30 31 @Override onCreate(Bundle savedInstanceState)32 protected void onCreate(Bundle savedInstanceState) { 33 super.onCreate(savedInstanceState); 34 setContentView(R.layout.blocked_numbers_activity); 35 36 // If savedInstanceState != null, the Activity will automatically restore the last fragment. 37 if (savedInstanceState == null) { 38 showManagementUi(); 39 } 40 } 41 42 /** Shows fragment with the list of currently blocked numbers and settings related to blocking. */ showManagementUi()43 public void showManagementUi() { 44 BlockedNumbersFragment fragment = 45 (BlockedNumbersFragment) 46 getFragmentManager().findFragmentByTag(TAG_BLOCKED_MANAGEMENT_FRAGMENT); 47 if (fragment == null) { 48 fragment = new BlockedNumbersFragment(); 49 } 50 51 getFragmentManager() 52 .beginTransaction() 53 .replace(R.id.blocked_numbers_activity_container, fragment, TAG_BLOCKED_MANAGEMENT_FRAGMENT) 54 .commit(); 55 56 Logger.get(this).logScreenView(ScreenEvent.Type.BLOCKED_NUMBER_MANAGEMENT, this); 57 } 58 59 /** 60 * Shows fragment with UI to preview the numbers of contacts currently marked as send-to-voicemail 61 * in Contacts. These numbers can be imported into Dialer's blocked number list. 62 */ showNumbersToImportPreviewUi()63 public void showNumbersToImportPreviewUi() { 64 ViewNumbersToImportFragment fragment = 65 (ViewNumbersToImportFragment) 66 getFragmentManager().findFragmentByTag(TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT); 67 if (fragment == null) { 68 fragment = new ViewNumbersToImportFragment(); 69 } 70 71 getFragmentManager() 72 .beginTransaction() 73 .replace( 74 R.id.blocked_numbers_activity_container, fragment, TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT) 75 .addToBackStack(null) 76 .commit(); 77 } 78 79 @Override onOptionsItemSelected(MenuItem item)80 public boolean onOptionsItemSelected(MenuItem item) { 81 if (item.getItemId() == android.R.id.home) { 82 onBackPressed(); 83 return true; 84 } 85 return false; 86 } 87 88 @Override onBackPressed()89 public void onBackPressed() { 90 // TODO: Achieve back navigation without overriding onBackPressed. 91 if (getFragmentManager().getBackStackEntryCount() > 0) { 92 getFragmentManager().popBackStack(); 93 } else { 94 super.onBackPressed(); 95 } 96 } 97 } 98