Home | History | Annotate | Download | only in filterednumber
      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.filterednumber;
     17 
     18 import android.support.v4.app.Fragment;
     19 import android.support.v4.app.FragmentManager;
     20 import android.content.Intent;
     21 import android.net.Uri;
     22 import android.os.Bundle;
     23 import android.support.v7.app.AppCompatActivity;
     24 import android.util.Log;
     25 import android.view.MenuItem;
     26 import android.widget.FrameLayout;
     27 import android.widget.FrameLayout.LayoutParams;
     28 import android.widget.Toast;
     29 
     30 import com.android.contacts.common.GeoUtil;
     31 import com.android.contacts.common.dialog.IndeterminateProgressDialog;
     32 import com.android.contacts.common.list.OnPhoneNumberPickerActionListener;
     33 import com.android.dialer.R;
     34 import com.android.dialer.database.FilteredNumberAsyncQueryHandler;
     35 import com.android.dialer.list.BlockedListSearchAdapter;
     36 import com.android.dialer.list.OnListFragmentScrolledListener;
     37 import com.android.dialer.list.BlockedListSearchFragment;
     38 import com.android.dialer.list.SearchFragment;
     39 import com.android.dialer.logging.Logger;
     40 import com.android.dialer.logging.ScreenEvent;
     41 
     42 public class BlockedNumbersSettingsActivity extends AppCompatActivity
     43         implements SearchFragment.HostInterface {
     44 
     45     private static final String TAG_BLOCKED_MANAGEMENT_FRAGMENT = "blocked_management";
     46     private static final String TAG_BLOCKED_SEARCH_FRAGMENT = "blocked_search";
     47     private static final String TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT = "view_numbers_to_import";
     48 
     49     @Override
     50     protected void onCreate(Bundle savedInstanceState) {
     51         super.onCreate(savedInstanceState);
     52         setContentView(R.layout.blocked_numbers_activity);
     53 
     54         // If savedInstanceState != null, the Activity will automatically restore the last fragment.
     55         if (savedInstanceState == null) {
     56             showManagementUi();
     57         }
     58     }
     59 
     60     /**
     61      * Shows fragment with the list of currently blocked numbers and settings related to blocking.
     62      */
     63     public void showManagementUi() {
     64         BlockedNumbersFragment fragment = (BlockedNumbersFragment) getFragmentManager()
     65                 .findFragmentByTag(TAG_BLOCKED_MANAGEMENT_FRAGMENT);
     66         if (fragment == null) {
     67             fragment = new BlockedNumbersFragment();
     68         }
     69 
     70         getFragmentManager().beginTransaction()
     71                 .replace(R.id.blocked_numbers_activity_container, fragment,
     72                         TAG_BLOCKED_MANAGEMENT_FRAGMENT)
     73                 .commit();
     74 
     75         Logger.logScreenView(ScreenEvent.BLOCKED_NUMBER_MANAGEMENT, this);
     76     }
     77 
     78     /**
     79      * Shows fragment with search UI for browsing/finding numbers to block.
     80      */
     81     public void showSearchUi() {
     82         BlockedListSearchFragment fragment = (BlockedListSearchFragment) getFragmentManager()
     83                 .findFragmentByTag(TAG_BLOCKED_SEARCH_FRAGMENT);
     84         if (fragment == null) {
     85             fragment = new BlockedListSearchFragment();
     86             fragment.setHasOptionsMenu(false);
     87             fragment.setShowEmptyListForNullQuery(true);
     88             fragment.setDirectorySearchEnabled(false);
     89         }
     90 
     91         getFragmentManager().beginTransaction()
     92                 .replace(R.id.blocked_numbers_activity_container, fragment,
     93                         TAG_BLOCKED_SEARCH_FRAGMENT)
     94                 .addToBackStack(null)
     95                 .commit();
     96 
     97         Logger.logScreenView(ScreenEvent.BLOCKED_NUMBER_ADD_NUMBER, this);
     98     }
     99 
    100     /**
    101      * Shows fragment with UI to preview the numbers of contacts currently marked as
    102      * send-to-voicemail in Contacts. These numbers can be imported into Dialer's blocked number
    103      * list.
    104      */
    105     public void showNumbersToImportPreviewUi() {
    106         ViewNumbersToImportFragment fragment = (ViewNumbersToImportFragment) getFragmentManager()
    107                 .findFragmentByTag(TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT);
    108         if (fragment == null) {
    109             fragment = new ViewNumbersToImportFragment();
    110         }
    111 
    112         getFragmentManager().beginTransaction()
    113                 .replace(R.id.blocked_numbers_activity_container, fragment,
    114                         TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT)
    115                 .addToBackStack(null)
    116                 .commit();
    117     }
    118 
    119     @Override
    120     public boolean onOptionsItemSelected(MenuItem item) {
    121         if (item.getItemId() == android.R.id.home) {
    122             onBackPressed();
    123             return true;
    124         }
    125         return false;
    126     }
    127 
    128     @Override
    129     public void onBackPressed() {
    130         // TODO: Achieve back navigation without overriding onBackPressed.
    131         if (getFragmentManager().getBackStackEntryCount() > 0) {
    132             getFragmentManager().popBackStack();
    133         } else {
    134             super.onBackPressed();
    135         }
    136     }
    137 
    138     @Override
    139     public boolean isActionBarShowing() {
    140         return false;
    141     }
    142 
    143     @Override
    144     public boolean isDialpadShown() {
    145         return false;
    146     }
    147 
    148     @Override
    149     public int getDialpadHeight() {
    150         return 0;
    151     }
    152 
    153     @Override
    154     public int getActionBarHideOffset() {
    155         return 0;
    156     }
    157 
    158     @Override
    159     public int getActionBarHeight() {
    160         return 0;
    161     }
    162 }
    163