calderwoodra | 21e24b6 | 2017-09-05 18:49:07 -0700 | [diff] [blame] | 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; |
calderwoodra | 21e24b6 | 2017-09-05 18:49:07 -0700 | [diff] [blame] | 22 | import com.android.dialer.logging.Logger; |
| 23 | import com.android.dialer.logging.ScreenEvent; |
| 24 | |
| 25 | /** TODO(calderwoodra): documentation */ |
calderwoodra | 58d0b2a | 2018-03-21 16:57:10 -0700 | [diff] [blame] | 26 | public class BlockedNumbersSettingsActivity extends AppCompatActivity { |
calderwoodra | 21e24b6 | 2017-09-05 18:49:07 -0700 | [diff] [blame] | 27 | |
| 28 | private static final String TAG_BLOCKED_MANAGEMENT_FRAGMENT = "blocked_management"; |
calderwoodra | 21e24b6 | 2017-09-05 18:49:07 -0700 | [diff] [blame] | 29 | private static final String TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT = "view_numbers_to_import"; |
| 30 | |
| 31 | @Override |
| 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. */ |
| 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 | |
calderwoodra | 21e24b6 | 2017-09-05 18:49:07 -0700 | [diff] [blame] | 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 | */ |
| 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 |
| 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 |
| 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 | } |
calderwoodra | 21e24b6 | 2017-09-05 18:49:07 -0700 | [diff] [blame] | 97 | } |