From 3663afe2e1afb109e117e5b707e8ed9547ed2103 Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Sun, 4 Oct 2015 01:31:28 -0700 Subject: Combine blocked number fragments into Activity. Mocks indicate that after adding, the user should be returned to the management UI and the snackbar should be shown there. This is kind of pain to do across fragments in different activities. To help address this, make one Activity the parent of both the blocked number manage and add/search UI. This also makes sense in terms of logical organization. Bug: 24134038 Change-Id: I682342a73c964a5d4eb90469f10d6584b85400f1 --- .../filterednumber/BlockedNumberFragment.java | 13 +- .../BlockedNumberSearchActivity.java | 163 -------------- .../ManageBlockedNumbersActivity.java | 240 +++++++++++++++++++++ .../dialer/list/BlockedListSearchFragment.java | 30 +-- src/com/android/dialer/list/SearchFragment.java | 4 +- .../dialer/settings/DialerSettingsActivity.java | 6 +- 6 files changed, 262 insertions(+), 194 deletions(-) delete mode 100644 src/com/android/dialer/filterednumber/BlockedNumberSearchActivity.java create mode 100644 src/com/android/dialer/filterednumber/ManageBlockedNumbersActivity.java (limited to 'src/com/android/dialer') diff --git a/src/com/android/dialer/filterednumber/BlockedNumberFragment.java b/src/com/android/dialer/filterednumber/BlockedNumberFragment.java index 79e5861dc..e12fd6b38 100644 --- a/src/com/android/dialer/filterednumber/BlockedNumberFragment.java +++ b/src/com/android/dialer/filterednumber/BlockedNumberFragment.java @@ -27,7 +27,6 @@ import android.view.View; import android.view.ViewGroup; import com.android.dialer.R; -import com.android.dialer.database.FilteredNumberAsyncQueryHandler; import com.android.dialer.database.FilteredNumberContract; public class BlockedNumberFragment extends ListFragment implements @@ -38,12 +37,14 @@ public class BlockedNumberFragment extends ListFragment implements @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); + LayoutInflater inflater = LayoutInflater.from(getContext()); getListView().addHeaderView(inflater.inflate(R.layout.blocked_number_header, null)); if (mAdapter == null) { mAdapter = new BlockedNumberAdapter(getContext()); } setListAdapter(mAdapter); + getActivity().findViewById(R.id.add_number_button).setOnClickListener(this); getListView().getEmptyView().findViewById(R.id.add_number_button).setOnClickListener(this); } @@ -61,8 +62,8 @@ public class BlockedNumberFragment extends ListFragment implements } @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + public View onCreateView( + LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.blocked_number_fragment, container, false); return view; } @@ -95,6 +96,10 @@ public class BlockedNumberFragment extends ListFragment implements @Override public void onClick(final View v) { - startActivity(new Intent(getActivity(), BlockedNumberSearchActivity.class)); + ManageBlockedNumbersActivity manageBlockedNumbersActivity = + (ManageBlockedNumbersActivity) getActivity(); + if (manageBlockedNumbersActivity != null && v.getId() == R.id.add_number_button) { + manageBlockedNumbersActivity.enterSearchUi(); + } } } diff --git a/src/com/android/dialer/filterednumber/BlockedNumberSearchActivity.java b/src/com/android/dialer/filterednumber/BlockedNumberSearchActivity.java deleted file mode 100644 index cfa404f05..000000000 --- a/src/com/android/dialer/filterednumber/BlockedNumberSearchActivity.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.dialer.filterednumber; - -import android.app.Fragment; -import android.app.FragmentTransaction; -import android.content.Intent; -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.widget.EditText; -import android.widget.FrameLayout; -import android.widget.FrameLayout.LayoutParams; -import android.widget.Toast; - -import com.android.contacts.common.GeoUtil; -import com.android.contacts.common.dialog.IndeterminateProgressDialog; -import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; -import com.android.dialer.R; -import com.android.dialer.database.FilteredNumberAsyncQueryHandler; -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 BlockedNumberSearchActivity extends AppCompatActivity - implements SearchFragment.HostInterface { - private static final String TAG_BLOCKED_SEARCH_FRAGMENT = "blocked_search"; - - private FilteredNumberAsyncQueryHandler mFilteredNumberAsyncQueryHandler; - private SearchFragment mSearchFragment; - private EditText mSearchView; - private ActionBar mActionBar; - private String mSearchQuery; - - 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) { - } - }; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mFilteredNumberAsyncQueryHandler = - new FilteredNumberAsyncQueryHandler(getContentResolver()); - - setContentView(R.layout.search_activity); - - mActionBar = getSupportActionBar(); - mActionBar.setCustomView(R.layout.search_edittext); - mActionBar.setBackgroundDrawable(null); - 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(new SearchEditTextLayout.Callback() { - @Override - public void onBackButtonClicked() { - onBackPressed(); - } - - @Override - public void onSearchViewClicked() { - } - }); - - mSearchView = (EditText) searchEditTextLayout.findViewById(R.id.search_view); - mSearchView.addTextChangedListener(mPhoneSearchQueryTextListener); - mSearchView.setHint(R.string.block_number_search_hint); - mSearchView.setTextSize(TypedValue.COMPLEX_UNIT_PX, - getResources().getDimension(R.dimen.blocked_number_search_text_size)); - - enterSearchUi(); - } - - private void enterSearchUi() { - if (mSearchFragment != null) { - return; - } - final FragmentTransaction transaction = getFragmentManager().beginTransaction(); - BlockedListSearchFragment fragment = (BlockedListSearchFragment) getFragmentManager() - .findFragmentByTag(TAG_BLOCKED_SEARCH_FRAGMENT); - if (fragment == null) { - fragment = new BlockedListSearchFragment(); - transaction.add(R.id.search_activity_container, fragment, TAG_BLOCKED_SEARCH_FRAGMENT); - } else { - transaction.show(fragment); - } - fragment.setHasOptionsMenu(false); - fragment.setShowEmptyListForNullQuery(true); - fragment.setDirectorySearchEnabled(false); - transaction.commit(); - } - - @Override - public void onAttachFragment(Fragment fragment) { - if (fragment instanceof BlockedListSearchFragment) { - mSearchFragment = (BlockedListSearchFragment) fragment; - } - } - - @Override - public boolean isActionBarShowing() { - return true; - } - - @Override - public boolean isDialpadShown() { - return false; - } - - @Override - public int getDialpadHeight() { - return 0; - } - - @Override - public int getActionBarHideOffset() { - return getSupportActionBar().getHideOffset(); - } - - @Override - public int getActionBarHeight() { - return getResources().getDimensionPixelSize(R.dimen.action_bar_height_large); - } -} diff --git a/src/com/android/dialer/filterednumber/ManageBlockedNumbersActivity.java b/src/com/android/dialer/filterednumber/ManageBlockedNumbersActivity.java new file mode 100644 index 000000000..356c55cee --- /dev/null +++ b/src/com/android/dialer/filterednumber/ManageBlockedNumbersActivity.java @@ -0,0 +1,240 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.dialer.filterednumber; + +import android.app.Fragment; +import android.app.FragmentTransaction; +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; + +import com.android.contacts.common.GeoUtil; +import com.android.contacts.common.dialog.IndeterminateProgressDialog; +import com.android.contacts.common.list.OnPhoneNumberPickerActionListener; +import com.android.dialer.R; +import com.android.dialer.database.FilteredNumberAsyncQueryHandler; +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() { + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.blocked_numbers_activity); + + mFilteredNumberAsyncQueryHandler = + new FilteredNumberAsyncQueryHandler(getContentResolver()); + + showManagementUi(); + } + + private void showManagementUi() { + mIsShowingManagementUi = true; + + showManagementUiActionBar(); + + final FragmentTransaction transaction = getFragmentManager().beginTransaction(); + if (mSearchFragment != null) { + transaction.hide(mSearchFragment); + } + + BlockedNumberFragment fragment = (BlockedNumberFragment) 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); + } + 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); + } + + 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) { + fragment = new BlockedListSearchFragment(); + 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)); + } + + @Override + public void onAttachFragment(Fragment fragment) { + if (fragment instanceof BlockedNumberFragment) { + mManagementFragment = (BlockedNumberFragment) fragment; + } else if (fragment instanceof BlockedListSearchFragment) { + mSearchFragment = (BlockedListSearchFragment) fragment; + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + if (item.getItemId() == android.R.id.home) { + onBackPressed(); + return true; + } + return false; + } + + @Override + public void onBackPressed() { + if (mIsShowingManagementUi) { + super.onBackPressed(); + } else { + showManagementUi(); + } + } + + @Override + public boolean isActionBarShowing() { + return true; + } + + @Override + public boolean isDialpadShown() { + return false; + } + + @Override + public int getDialpadHeight() { + return 0; + } + + @Override + public int getActionBarHideOffset() { + return getSupportActionBar().getHideOffset(); + } + + @Override + public int getActionBarHeight() { + return getSupportActionBar().getHeight(); + } +} diff --git a/src/com/android/dialer/list/BlockedListSearchFragment.java b/src/com/android/dialer/list/BlockedListSearchFragment.java index 675081254..eef24afb1 100644 --- a/src/com/android/dialer/list/BlockedListSearchFragment.java +++ b/src/com/android/dialer/list/BlockedListSearchFragment.java @@ -86,13 +86,9 @@ public class BlockedListSearchFragment extends RegularSearchFragment { private void blockNumber(final String number) { final String countryIso = GeoUtil.getCurrentCountryIso(getContext()); - final IndeterminateProgressDialog progressDialog = - IndeterminateProgressDialog.show(getFragmentManager(), - getString(R.string.checkingNumber, number), null, 500); final String normalizedNumber = FilteredNumberAsyncQueryHandler.getNormalizedNumber(number, countryIso); if (normalizedNumber == null) { - progressDialog.dismiss(); Toast.makeText(getContext(), getString(R.string.invalidNumber, number), Toast.LENGTH_SHORT).show(); return; @@ -100,12 +96,11 @@ public class BlockedListSearchFragment extends RegularSearchFragment { final OnCheckBlockedListener onCheckListener = new OnCheckBlockedListener() { @Override public void onCheckComplete(Integer id) { - progressDialog.dismiss(); if (id == null) { final FilterNumberDialogFragment newFragment = FilterNumberDialogFragment .newInstance(id, normalizedNumber, number, countryIso, number); newFragment.setParentView( - getActivity().findViewById(R.id.search_activity_container)); + getActivity().findViewById(R.id.blocked_numbers_activity_container)); newFragment.show( getFragmentManager(), FilterNumberDialogFragment.BLOCK_DIALOG_FRAGMENT); } else { @@ -118,9 +113,11 @@ public class BlockedListSearchFragment extends RegularSearchFragment { onCheckListener, normalizedNumber, number, countryIso); } - private void blockContactNumber(final BlockedListSearchAdapter adapter, - final ContactListItemView view, final String number, - final Integer blockId) { + private void blockContactNumber( + final BlockedListSearchAdapter adapter, + final ContactListItemView view, + final String number, + final Integer blockId) { final String countryIso = GeoUtil.getCurrentCountryIso(getContext()); final String normalizedNumber = FilteredNumberAsyncQueryHandler.getNormalizedNumber(number, countryIso); @@ -136,19 +133,8 @@ public class BlockedListSearchFragment extends RegularSearchFragment { } final FilterNumberDialogFragment newFragment = FilterNumberDialogFragment .newInstance(blockId, normalizedNumber, number, countryIso, number); - newFragment.setParentView(getActivity().findViewById(R.id.search_activity_container)); - newFragment.setOnUndoBlockListener(new FilterNumberDialogFragment.OnUndoBlockListener() { - @Override - public void onUndoBlockComplete() { - adapter.setViewUnblocked(view); - } - }); - newFragment.setOnBlockListener(new FilterNumberDialogFragment.OnBlockListener() { - @Override - public void onBlockComplete(Uri uri) { - adapter.setViewBlocked(view, Long.valueOf(ContentUris.parseId(uri)).intValue()); - } - }); + newFragment.setParentView( + getActivity().findViewById(R.id.blocked_numbers_activity_container)); newFragment.show(getFragmentManager(), FilterNumberDialogFragment.BLOCK_DIALOG_FRAGMENT); } } diff --git a/src/com/android/dialer/list/SearchFragment.java b/src/com/android/dialer/list/SearchFragment.java index 1c895d3af..c8711e769 100644 --- a/src/com/android/dialer/list/SearchFragment.java +++ b/src/com/android/dialer/list/SearchFragment.java @@ -289,12 +289,12 @@ public class SearchFragment extends PhoneNumberPickerFragment { public void updatePosition(boolean animate) { // Use negative shadow height instead of 0 to account for the 9-patch's shadow. int startTranslationValue = - mActivity.isDialpadShown() ? mActionBarHeight - mShadowHeight: -mShadowHeight; + mActivity.isDialpadShown() ? mActionBarHeight - mShadowHeight : -mShadowHeight; int endTranslationValue = 0; // Prevents ListView from being translated down after a rotation when the ActionBar is up. if (animate || mActivity.isActionBarShowing()) { endTranslationValue = - mActivity.isDialpadShown() ? 0 : mActionBarHeight -mShadowHeight; + mActivity.isDialpadShown() ? 0 : mActionBarHeight - mShadowHeight; } if (animate) { // If the dialpad will be shown, then this animation involves sliding the list up. diff --git a/src/com/android/dialer/settings/DialerSettingsActivity.java b/src/com/android/dialer/settings/DialerSettingsActivity.java index 58b0ab8e6..6fcd22195 100644 --- a/src/com/android/dialer/settings/DialerSettingsActivity.java +++ b/src/com/android/dialer/settings/DialerSettingsActivity.java @@ -28,7 +28,7 @@ import android.view.MenuItem; import android.widget.Toast; import com.android.dialer.R; -import com.android.dialer.filterednumber.BlockedNumberFragment; +import com.android.dialer.filterednumber.ManageBlockedNumbersActivity; import java.util.List; @@ -87,8 +87,8 @@ public class DialerSettingsActivity extends AppCompatPreferenceActivity { } Header blockedCallsHeader = new Header(); - blockedCallsHeader.titleRes = R.string.blocked_calls_settings_label; - blockedCallsHeader.fragment = BlockedNumberFragment.class.getName(); + blockedCallsHeader.titleRes = R.string.manage_blocked_numbers_label; + blockedCallsHeader.intent = new Intent(this, ManageBlockedNumbersActivity.class); target.add(blockedCallsHeader); if (telephonyManager.isTtyModeSupported() -- cgit v1.2.3