diff options
| author | Diogo Ferreira <defer@cyngn.com> | 2014-12-03 15:02:57 +0000 |
|---|---|---|
| committer | Steve Kondik <steve@cyngn.com> | 2015-11-13 09:01:09 +0100 |
| commit | 9897751d02be1f51caeb5a8d9647c1f8ae7a03ff (patch) | |
| tree | 3c98ece0a058da3a7d880d326210a5dd83167682 /src/com/android/settings/blacklist | |
| parent | 1bf1d26827d35dca4564c4195bf86bc629c1e93b (diff) | |
| download | packages_apps_Settings-9897751d02be1f51caeb5a8d9647c1f8ae7a03ff.tar.gz packages_apps_Settings-9897751d02be1f51caeb5a8d9647c1f8ae7a03ff.tar.bz2 packages_apps_Settings-9897751d02be1f51caeb5a8d9647c1f8ae7a03ff.zip | |
privacy: Actually set the blacklist preference
The preference was not being set, which caused this code to throw an NPE on
devices without telephony when opening the privacy preferences.
This bug also affects devices with telephony in that the preference doesn't
update its text. I also got rid of the null check because the preference
always exists, the null check is pointless and ended up hiding this bug.
Change-Id: I95555d44349700a8f29a71a2f2ee9aedf419b49b
Settings: Fix blacklist settings crash
Change-Id: Idd261aa9f8e2867312aaaece26150671b177994c
Settings: materialize Blacklist settings
* Add a FAB
* Add a (generic system) enable/disable switch bar
Change-Id: I0984bf6769abef48cc7e0a643c2bdd73219954fc
Signed-off-by: Roman Birg <roman@cyngn.com>
Settings: add a way to open blacklist settings externally
Opening the activity doesn't theme the switch bar - an alias works.
Change-Id: I78efb382f4f1f4d208f122fedb0d71a86b515405
Signed-off-by: Roman Birg <roman@cyngn.com>
blacklist: make it possible to unblacklist phone/messages via checkboxes
Change-Id: I7d982d17818efe065e4e22f2a86a46493672584a
Settings: fix blacklist settings crash
On a device rotate, the MultiSelectListPreference would try and restore
its state since the preferences aren't persisted. Clear the persisted
flag so the MultiSelectPreference doesn't try and restore the states, as
they get populated in onResume().
Change-Id: I0d0304e2367ade66e35ae7df432575d13ed0993e
Signed-off-by: Roman Birg <roman@cyngn.com>
Settings : Update blacklist strings
Change-Id: I08ea4405f41f86a9eaf7bae74cbb61fa1fb0c8aa
(cherry picked from commit 6d8cc2c697752a1357915ea88651b2fe220a54ba)
Settings : Add input checks for blacklist input
There can be situations where user enters invalid input.
Ensure that is handled.
Repro :
1. Add new blacklist entry
2. Enter /
3. Press ok
4. Enjoy crash
issue-id: CYNGNOS-980
Change-Id: Ica90ac835f374569123e679ba39c3caa7179ef65
Settings : Fix blacklist delete number crash
issue-id : HAM-795
Change-Id: I25306b3d4bead5487f039c3f51b631b1ef88b18d
Diffstat (limited to 'src/com/android/settings/blacklist')
| -rw-r--r-- | src/com/android/settings/blacklist/BlacklistPreferences.java (renamed from src/com/android/settings/blacklist/PreferenceFragment.java) | 9 | ||||
| -rw-r--r-- | src/com/android/settings/blacklist/BlacklistSettings.java | 121 | ||||
| -rw-r--r-- | src/com/android/settings/blacklist/EntryEditDialogFragment.java | 29 |
3 files changed, 98 insertions, 61 deletions
diff --git a/src/com/android/settings/blacklist/PreferenceFragment.java b/src/com/android/settings/blacklist/BlacklistPreferences.java index b8ecddd18..2ee449f66 100644 --- a/src/com/android/settings/blacklist/PreferenceFragment.java +++ b/src/com/android/settings/blacklist/BlacklistPreferences.java @@ -24,14 +24,16 @@ import android.preference.Preference; import android.preference.PreferenceScreen; import android.provider.Settings; +import com.android.internal.logging.MetricsLogger; import com.android.internal.telephony.util.BlacklistUtils; import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; +import com.android.settings.SubSettings; import java.util.HashSet; import java.util.Set; -public class PreferenceFragment extends SettingsPreferenceFragment implements +public class BlacklistPreferences extends SettingsPreferenceFragment implements Preference.OnPreferenceChangeListener { private static final String BUTTON_BLACKLIST_PRIVATE = "button_blacklist_private_numbers"; @@ -141,4 +143,9 @@ public class PreferenceFragment extends SettingsPreferenceFragment implements pref.setSummary(getString(summaryResId, getString(typeResId))); } + + @Override + protected int getMetricsCategory() { + return MetricsLogger.PRIVACY; + } } diff --git a/src/com/android/settings/blacklist/BlacklistSettings.java b/src/com/android/settings/blacklist/BlacklistSettings.java index c30d410e1..db7fe5ac5 100644 --- a/src/com/android/settings/blacklist/BlacklistSettings.java +++ b/src/com/android/settings/blacklist/BlacklistSettings.java @@ -16,14 +16,12 @@ package com.android.settings.blacklist; -import android.app.ActionBar; -import android.app.Activity; -import android.app.FragmentTransaction; import android.app.ListFragment; import android.content.ContentResolver; import android.content.ContentUris; import android.content.ContentValues; import android.content.Context; +import android.database.ContentObserver; import android.database.Cursor; import android.location.CountryDetector; import android.net.Uri; @@ -39,22 +37,22 @@ import android.provider.Telephony.Blacklist; import android.telephony.PhoneNumberUtils; import android.text.TextUtils; import android.util.SparseArray; -import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.CompoundButton; -import android.widget.ListAdapter; +import android.widget.FrameLayout; import android.widget.ListView; import android.widget.ResourceCursorAdapter; -import android.widget.Switch; import android.widget.TextView; import com.android.internal.telephony.util.BlacklistUtils; import com.android.settings.R; +import com.android.settings.SettingsActivity; +import com.android.settings.SubSettings; +import com.android.settings.cyanogenmod.BaseSystemSettingSwitchBar; import java.util.HashMap; @@ -62,7 +60,7 @@ import java.util.HashMap; * Blacklist settings UI for the Phone app. */ public class BlacklistSettings extends ListFragment - implements CompoundButton.OnCheckedChangeListener { + implements BaseSystemSettingSwitchBar.SwitchBarChangeCallback { private static final String[] BLACKLIST_PROJECTION = { Blacklist._ID, @@ -75,18 +73,37 @@ public class BlacklistSettings extends ListFragment private static final int COLUMN_PHONE = 2; private static final int COLUMN_MESSAGE = 3; - private Switch mEnabledSwitch; + private BaseSystemSettingSwitchBar mEnabledSwitch; private boolean mLastEnabledState; private BlacklistAdapter mAdapter; private Cursor mCursor; private TextView mEmptyView; + private Context mContext; + private View mFab; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + mContext = getActivity(); + } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return inflater.inflate(com.android.internal.R.layout.preference_list_fragment, - container, false); + return inflater.inflate(R.layout.preference_blacklist, container, false); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + mFab = view.findViewById(R.id.floating_action_button); + mFab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showEntryEditDialog(-1); + } + }); } @Override @@ -95,14 +112,6 @@ public class BlacklistSettings extends ListFragment setHasOptionsMenu(true); - final Activity activity = getActivity(); - mEnabledSwitch = new Switch(activity); - - final int padding = activity.getResources().getDimensionPixelSize( - R.dimen.action_bar_switch_padding); - mEnabledSwitch.setPaddingRelative(0, 0, padding, 0); - mEnabledSwitch.setOnCheckedChangeListener(this); - mCursor = getActivity().managedQuery(Blacklist.CONTENT_URI, BLACKLIST_PROJECTION, null, null, null); mAdapter = new BlacklistAdapter(getActivity(), null); @@ -112,6 +121,14 @@ public class BlacklistSettings extends ListFragment final ListView listView = getListView(); listView.setAdapter(mAdapter); listView.setEmptyView(mEmptyView); + + // Add a footer to avoid a situation where the FAB would cover the last + // item's options in a non-scrollable listview. + View footer = LayoutInflater.from(getActivity()) + .inflate(R.layout.empty_list_entry_footer, listView, false); + listView.addFooterView(footer); + listView.setFooterDividersEnabled(false); + footer.setOnClickListener(null); } @Override @@ -123,23 +140,16 @@ public class BlacklistSettings extends ListFragment @Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - menu.findItem(R.id.blacklist_add).setEnabled(mLastEnabledState); - menu.findItem(R.id.blacklist_prefs).setEnabled(mLastEnabledState); + menu.findItem(R.id.blacklist_prefs).setVisible(mLastEnabledState); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { - case R.id.blacklist_add: - showEntryEditDialog(-1); - return true; case R.id.blacklist_prefs: - PreferenceFragment prefs = new PreferenceFragment(); - FragmentTransaction ft = getFragmentManager().beginTransaction(); - ft.replace(android.R.id.content, prefs); - ft.hide(this); - ft.addToBackStack(null); - ft.commitAllowingStateLoss(); + SettingsActivity pa = (SettingsActivity) getActivity(); + pa.startPreferencePanel(BlacklistPreferences.class.getCanonicalName(), null, + 0, null, this, 0); return true; } @@ -149,31 +159,35 @@ public class BlacklistSettings extends ListFragment @Override public void onStart() { super.onStart(); - final Activity activity = getActivity(); - activity.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, - ActionBar.DISPLAY_SHOW_CUSTOM); - activity.getActionBar().setCustomView(mEnabledSwitch, new ActionBar.LayoutParams( - ActionBar.LayoutParams.WRAP_CONTENT, - ActionBar.LayoutParams.WRAP_CONTENT, - Gravity.CENTER_VERTICAL | Gravity.END)); + final SettingsActivity activity = (SettingsActivity) getActivity(); + mEnabledSwitch = new BaseSystemSettingSwitchBar(activity, activity.getSwitchBar(), + Settings.System.PHONE_BLACKLIST_ENABLED, true, this); } @Override - public void onStop() { - super.onStop(); - final Activity activity = getActivity(); - activity.getActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_CUSTOM); - activity.getActionBar().setCustomView(null); + public void onResume() { + super.onResume(); + + final SettingsActivity activity = (SettingsActivity) getActivity(); + if (mEnabledSwitch != null) { + mEnabledSwitch.resume(activity); + } } @Override - public void onResume() { - super.onResume(); + public void onPause() { + super.onPause(); + if (mEnabledSwitch != null) { + mEnabledSwitch.pause(); + } + } - final Context context = getActivity(); - mLastEnabledState = BlacklistUtils.isBlacklistEnabled(context); - mEnabledSwitch.setChecked(mLastEnabledState); - updateEnabledState(); + @Override + public void onDestroyView() { + super.onDestroyView(); + if (mEnabledSwitch != null) { + mEnabledSwitch.teardownSwitchBar(); + } } @Override @@ -187,6 +201,7 @@ public class BlacklistSettings extends ListFragment } private void updateEnabledState() { + mFab.setVisibility(mLastEnabledState ? View.VISIBLE : View.GONE); getListView().setEnabled(mLastEnabledState); getActivity().invalidateOptionsMenu(); @@ -197,13 +212,9 @@ public class BlacklistSettings extends ListFragment } @Override - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - if (buttonView == mEnabledSwitch && isChecked != mLastEnabledState) { - Settings.System.putInt(getActivity().getContentResolver(), - Settings.System.PHONE_BLACKLIST_ENABLED, isChecked ? 1 : 0); - mLastEnabledState = isChecked; - updateEnabledState(); - } + public void onEnablerChanged(boolean isEnabled) { + mLastEnabledState = BlacklistUtils.isBlacklistEnabled(mContext); + updateEnabledState(); } private static class BlacklistAdapter extends ResourceCursorAdapter diff --git a/src/com/android/settings/blacklist/EntryEditDialogFragment.java b/src/com/android/settings/blacklist/EntryEditDialogFragment.java index 3e29279d2..9fda2bacf 100644 --- a/src/com/android/settings/blacklist/EntryEditDialogFragment.java +++ b/src/com/android/settings/blacklist/EntryEditDialogFragment.java @@ -21,7 +21,6 @@ import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.content.ContentUris; -import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -31,10 +30,11 @@ import android.os.Bundle; import android.provider.ContactsContract.CommonDataKinds; import android.provider.Telephony.Blacklist; import android.text.Editable; +import android.text.TextUtils; import android.text.TextWatcher; import android.text.method.ArrowKeyMovementMethod; import android.text.method.DialerKeyListener; -import android.util.Log; +import android.util.Pair; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; @@ -199,6 +199,7 @@ public class EntryEditDialogFragment extends DialogFragment private void updateBlacklistEntry() { String number = mEditText.getText().toString(); int flags = 0; + int valid = BlacklistUtils.BLOCK_CALLS | BlacklistUtils.BLOCK_MESSAGES; if (mBlockCalls.isChecked()) { flags = flags | BlacklistUtils.BLOCK_CALLS; } @@ -207,7 +208,7 @@ public class EntryEditDialogFragment extends DialogFragment } // Since BlacklistProvider enforces validity for a number to be added // we should alert the user if and when it gets rejected - if (!BlacklistUtils.addOrUpdate(getActivity(), number, flags, flags)) { + if (!BlacklistUtils.addOrUpdate(getActivity(), number, flags, valid)) { Toast.makeText(getActivity(), getString(R.string.blacklist_bad_number_add), Toast.LENGTH_LONG).show(); } @@ -221,8 +222,24 @@ public class EntryEditDialogFragment extends DialogFragment } } + boolean validInput = false; + String input = mEditText.getText().toString(); + if (!TextUtils.isEmpty(input)) { + Pair<String, Boolean> normalizeResult = + BlacklistUtils.isValidBlacklistInput(getActivity(), input); + if (normalizeResult.second) { + validInput = true; + } + } + + if (!validInput && !TextUtils.isEmpty(input)) { + mEditText.setError(getString(R.string.wifi_error)); + } else { + mEditText.setError(null); + } + if (mOkButton != null) { - mOkButton.setEnabled(mEditText.getText().length() != 0); + mOkButton.setEnabled(validInput); } } @@ -269,8 +286,10 @@ public class EntryEditDialogFragment extends DialogFragment } } - private static class DeleteConfirmationFragment extends DialogFragment + public static class DeleteConfirmationFragment extends DialogFragment implements DialogInterface.OnClickListener { + public DeleteConfirmationFragment() { + } public static DialogFragment newInstance(EntryEditDialogFragment parent) { DialogFragment fragment = new DeleteConfirmationFragment(); fragment.setTargetFragment(parent, 0); |
