Wenyi Wang | 1fc3ef4 | 2016-01-14 18:21:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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.contacts.activities; |
| 18 | |
| 19 | import android.os.Bundle; |
| 20 | import android.support.v7.app.ActionBar; |
| 21 | import android.view.MenuItem; |
| 22 | |
| 23 | import com.android.contacts.AppCompatContactsActivity; |
| 24 | import com.android.contacts.R; |
| 25 | import com.android.contacts.callblocking.BlockedNumbersFragment; |
| 26 | import com.android.contacts.callblocking.SearchFragment; |
| 27 | import com.android.contacts.callblocking.ViewNumbersToImportFragment; |
| 28 | |
| 29 | public class BlockedNumbersActivity extends AppCompatContactsActivity |
| 30 | implements SearchFragment.HostInterface { |
| 31 | private static final String TAG_BLOCKED_MANAGEMENT_FRAGMENT = "blocked_management"; |
| 32 | private static final String TAG_BLOCKED_SEARCH_FRAGMENT = "blocked_search"; |
| 33 | private static final String TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT = "view_numbers_to_import"; |
| 34 | |
| 35 | @Override |
| 36 | protected void onCreate(Bundle savedInstanceState) { |
| 37 | super.onCreate(savedInstanceState); |
| 38 | setContentView(R.layout.blocked_numbers_activity); |
| 39 | |
| 40 | final ActionBar actionBar = getSupportActionBar(); |
| 41 | |
| 42 | actionBar.setDisplayShowHomeEnabled(true); |
| 43 | actionBar.setDisplayHomeAsUpEnabled(true); |
| 44 | |
| 45 | // If savedInstanceState != null, the activity will automatically restore the last fragment. |
| 46 | if (savedInstanceState == null) { |
| 47 | showManagementUi(); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Shows fragment with the list of currently blocked numbers and settings related to blocking. |
| 53 | */ |
| 54 | public void showManagementUi() { |
| 55 | BlockedNumbersFragment fragment = (BlockedNumbersFragment) getFragmentManager() |
| 56 | .findFragmentByTag(TAG_BLOCKED_MANAGEMENT_FRAGMENT); |
| 57 | if (fragment == null) { |
| 58 | fragment = new BlockedNumbersFragment(); |
| 59 | } |
| 60 | |
| 61 | getFragmentManager().beginTransaction() |
| 62 | .replace(R.id.blocked_numbers_activity_container, fragment, |
| 63 | TAG_BLOCKED_MANAGEMENT_FRAGMENT) |
| 64 | .commit(); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Shows fragment with search UI for browsing/finding numbers to block. |
| 69 | */ |
| 70 | public void showSearchUi() { |
| 71 | SearchFragment fragment = (SearchFragment) getFragmentManager() |
| 72 | .findFragmentByTag(TAG_BLOCKED_SEARCH_FRAGMENT); |
| 73 | if (fragment == null) { |
| 74 | fragment = new SearchFragment(); |
| 75 | fragment.setHasOptionsMenu(false); |
| 76 | fragment.setShowEmptyListForNullQuery(true); |
| 77 | fragment.setDirectorySearchEnabled(false); |
| 78 | } |
| 79 | |
| 80 | getFragmentManager().beginTransaction() |
| 81 | .replace(R.id.blocked_numbers_activity_container, fragment, |
| 82 | TAG_BLOCKED_SEARCH_FRAGMENT) |
| 83 | .addToBackStack(null) |
| 84 | .commit(); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Shows fragment with UI to preview the numbers of contacts currently marked as |
| 89 | * send-to-voicemail in Contacts. These numbers can be imported into blocked number list. |
| 90 | */ |
| 91 | public void showNumbersToImportPreviewUi() { |
| 92 | ViewNumbersToImportFragment fragment = (ViewNumbersToImportFragment) getFragmentManager() |
| 93 | .findFragmentByTag(TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT); |
| 94 | if (fragment == null) { |
| 95 | fragment = new ViewNumbersToImportFragment(); |
| 96 | } |
| 97 | |
| 98 | getFragmentManager().beginTransaction() |
| 99 | .replace(R.id.blocked_numbers_activity_container, fragment, |
| 100 | TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT) |
| 101 | .addToBackStack(null) |
| 102 | .commit(); |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public boolean onOptionsItemSelected(MenuItem item) { |
| 107 | if (item.getItemId() == android.R.id.home) { |
| 108 | onBackPressed(); |
| 109 | return true; |
| 110 | } |
| 111 | return false; |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public void onBackPressed() { |
| 116 | // TODO: Achieve back navigation without overriding onBackPressed. |
| 117 | if (getFragmentManager().getBackStackEntryCount() > 0) { |
| 118 | getFragmentManager().popBackStack(); |
| 119 | } else { |
| 120 | super.onBackPressed(); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public boolean isActionBarShowing() { |
| 126 | return true; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public boolean isDialpadShown() { |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public int getDialpadHeight() { |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public int getActionBarHideOffset() { |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | @Override |
| 145 | public int getActionBarHeight() { |
| 146 | return 0; |
| 147 | } |
| 148 | } |