diff options
author | Andrew Lee <anwlee@google.com> | 2015-10-15 23:17:30 -0700 |
---|---|---|
committer | Andrew Lee <anwlee@google.com> | 2015-10-20 23:34:06 -0700 |
commit | 9af1b36e999036f4045b07285962cfdb7bfbcca7 (patch) | |
tree | 862f54198bc60a7303356f63eba48596875a9992 /src/com/android/dialer/filterednumber/ManageBlockedNumbersActivity.java | |
parent | 4f52db88d380e1d18926928059d7b0cd73b2a11e (diff) |
Add import fragment, rearrange fragments.
+ Add a fragment (and adapter) for displaying numbers from contacts
marked as send to voicemail. This fragment has import functionality.
+ Refactor logic around the Blocked Numbers activity; relocate a lot
of the fragment-specific logic, particularly around actionbars, to
within the fragments themselves.
+ Simplify fragment management logic by using replace instead of
show/hide.
Bug: 23351616
Change-Id: I5c1076d6d001a8401234f57c27ada4bcd90e6c27
Diffstat (limited to 'src/com/android/dialer/filterednumber/ManageBlockedNumbersActivity.java')
-rw-r--r-- | src/com/android/dialer/filterednumber/ManageBlockedNumbersActivity.java | 156 |
1 files changed, 29 insertions, 127 deletions
diff --git a/src/com/android/dialer/filterednumber/ManageBlockedNumbersActivity.java b/src/com/android/dialer/filterednumber/ManageBlockedNumbersActivity.java index bb194be69..581ff98b5 100644 --- a/src/com/android/dialer/filterednumber/ManageBlockedNumbersActivity.java +++ b/src/com/android/dialer/filterednumber/ManageBlockedNumbersActivity.java @@ -15,20 +15,14 @@ */ package com.android.dialer.filterednumber; -import android.app.Fragment; -import android.app.FragmentTransaction; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; import android.content.Intent; -import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.os.Bundle; -import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; -import android.text.Editable; -import android.text.TextWatcher; import android.util.Log; -import android.util.TypedValue; import android.view.MenuItem; -import android.widget.EditText; import android.widget.FrameLayout; import android.widget.FrameLayout.LayoutParams; import android.widget.Toast; @@ -42,112 +36,36 @@ import com.android.dialer.list.BlockedListSearchAdapter; import com.android.dialer.list.OnListFragmentScrolledListener; import com.android.dialer.list.BlockedListSearchFragment; import com.android.dialer.list.SearchFragment; -import com.android.dialer.widget.SearchEditTextLayout; public class ManageBlockedNumbersActivity extends AppCompatActivity implements SearchFragment.HostInterface { private static final String TAG_BLOCKED_MANAGEMENT_FRAGMENT = "blocked_management"; private static final String TAG_BLOCKED_SEARCH_FRAGMENT = "blocked_search"; - - private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler; - - private BlockedNumberFragment mManagementFragment; - private SearchFragment mSearchFragment; - - private EditText mSearchView; - private ActionBar mActionBar; - private String mSearchQuery; - - private boolean mIsShowingManagementUi; - - private final TextWatcher mPhoneSearchQueryTextListener = new TextWatcher() { - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - final String newText = s.toString(); - if (newText.equals(mSearchQuery)) { - return; - } - mSearchQuery = newText; - mSearchFragment.setQueryString(mSearchQuery, false); - } - - @Override - public void afterTextChanged(Editable s) { - } - }; - - private final SearchEditTextLayout.Callback mSearchLayoutCallback = - new SearchEditTextLayout.Callback() { - @Override - public void onBackButtonClicked() { - showManagementUi(); - } - - @Override - public void onSearchViewClicked() { - } - }; + private static final String TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT = "view_numbers_to_import"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.blocked_numbers_activity); - mFilteredNumberAsyncQueryHandler = - new FilteredNumberAsyncQueryHandler(getContentResolver()); - showManagementUi(); } public void showManagementUi() { - mIsShowingManagementUi = true; - - showManagementUiActionBar(); - - final FragmentTransaction transaction = getFragmentManager().beginTransaction(); - if (mSearchFragment != null) { - transaction.hide(mSearchFragment); - } - - BlockedNumberFragment fragment = (BlockedNumberFragment) getFragmentManager() + BlockedNumbersFragment fragment = (BlockedNumbersFragment) getFragmentManager() .findFragmentByTag(TAG_BLOCKED_MANAGEMENT_FRAGMENT); if (fragment == null) { - fragment = new BlockedNumberFragment(); - transaction.add(R.id.blocked_numbers_activity_container, fragment, - TAG_BLOCKED_MANAGEMENT_FRAGMENT); - } else { - transaction.show(fragment); + fragment = new BlockedNumbersFragment(); } - transaction.commit(); - } - private void showManagementUiActionBar() { - mActionBar = getSupportActionBar(); - ColorDrawable backgroundDrawable = new ColorDrawable(getColor(R.color.dialer_theme_color)); - mActionBar.setBackgroundDrawable(backgroundDrawable); - mActionBar.setElevation(getResources().getDimensionPixelSize(R.dimen.action_bar_elevation)); - mActionBar.setDisplayShowCustomEnabled(false); - mActionBar.setDisplayHomeAsUpEnabled(true); - mActionBar.setDisplayShowHomeEnabled(true); - mActionBar.setDisplayShowTitleEnabled(true); - mActionBar.setTitle(R.string.manage_blocked_numbers_label); + getFragmentManager().beginTransaction() + .replace(R.id.blocked_numbers_activity_container, fragment, + TAG_BLOCKED_MANAGEMENT_FRAGMENT) + .commit(); } public void enterSearchUi() { - mIsShowingManagementUi = false; - - showSearchUiActionBar(); - - final FragmentTransaction transaction = getFragmentManager().beginTransaction(); - if (mManagementFragment != null) { - transaction.hide(mManagementFragment); - } - BlockedListSearchFragment fragment = (BlockedListSearchFragment) getFragmentManager() .findFragmentByTag(TAG_BLOCKED_SEARCH_FRAGMENT); if (fragment == null) { @@ -155,44 +73,27 @@ public class ManageBlockedNumbersActivity extends AppCompatActivity fragment.setHasOptionsMenu(false); fragment.setShowEmptyListForNullQuery(true); fragment.setDirectorySearchEnabled(false); - transaction.add(R.id.blocked_numbers_activity_container, fragment, - TAG_BLOCKED_SEARCH_FRAGMENT); - } else { - transaction.show(fragment); } - transaction.commit(); - } - private void showSearchUiActionBar() { - mActionBar = getSupportActionBar(); - mActionBar.setCustomView(R.layout.search_edittext); - mActionBar.setBackgroundDrawable(null); - mActionBar.setElevation(0); - mActionBar.setDisplayShowCustomEnabled(true); - mActionBar.setDisplayHomeAsUpEnabled(false); - mActionBar.setDisplayShowHomeEnabled(false); - - final SearchEditTextLayout searchEditTextLayout = (SearchEditTextLayout) mActionBar - .getCustomView().findViewById(R.id.search_view_container); - searchEditTextLayout.expand(false, true); - searchEditTextLayout.setCallback(mSearchLayoutCallback); - - mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view); - mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); - mSearchView.setHint(R.string.block_number_search_hint); - - // TODO: Don't set custom text size; use default search text size. - mSearchView.setTextSize(TypedValue.COMPLEX_UNIT_PX, - getResources().getDimension(R.dimen.blocked_number_search_text_size)); + getFragmentManager().beginTransaction() + .replace(R.id.blocked_numbers_activity_container, fragment, + TAG_BLOCKED_SEARCH_FRAGMENT) + .addToBackStack(null) + .commit(); } - @Override - public void onAttachFragment(Fragment fragment) { - if (fragment instanceof BlockedNumberFragment) { - mManagementFragment = (BlockedNumberFragment) fragment; - } else if (fragment instanceof BlockedListSearchFragment) { - mSearchFragment = (BlockedListSearchFragment) fragment; + public void showNumbersToImportPreviewUi() { + ViewNumbersToImportFragment fragment = (ViewNumbersToImportFragment) getFragmentManager() + .findFragmentByTag(TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT); + if (fragment == null) { + fragment = new ViewNumbersToImportFragment(); } + + getFragmentManager().beginTransaction() + .replace(R.id.blocked_numbers_activity_container, fragment, + TAG_VIEW_NUMBERS_TO_IMPORT_FRAGMENT) + .addToBackStack(null) + .commit(); } @Override @@ -206,10 +107,11 @@ public class ManageBlockedNumbersActivity extends AppCompatActivity @Override public void onBackPressed() { - if (mIsShowingManagementUi) { - super.onBackPressed(); + // TODO: Achieve back navigation without overriding onBackPressed. + if (getFragmentManager().getBackStackEntryCount() > 0) { + getFragmentManager().popBackStack(); } else { - showManagementUi(); + super.onBackPressed(); } } |