diff options
32 files changed, 270 insertions, 150 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 28489d6..c224210 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2225,7 +2225,6 @@ <!-- "Blacklist settings" UI, used only on voice-capable phone devices. --> <activity android:name="Settings$BlacklistSettingsActivity" - android:theme="@style/Theme.SubSettingsDialogWhenLarge" android:uiOptions="splitActionBarWhenNarrow" android:label="@string/blacklist_title" android:excludeFromRecents="true"> @@ -2239,6 +2238,18 @@ android:resource="@id/security_settings" /> </activity> + <activity-alias android:name=".blacklist.BlacklistSettings" + android:taskAffinity="com.android.settings" + android:label="@string/blacklist_title" + android:targetActivity="Settings$BlacklistSettingsActivity" + android:configChanges="orientation|keyboardHidden|screenSize" + android:exported="true"> + <meta-data android:name="com.android.settings.FRAGMENT_CLASS" + android:value="com.android.settings.blacklist.BlacklistSettings" /> + <meta-data android:name="com.android.settings.TOP_LEVEL_HEADER_ID" + android:resource="@id/security_settings" /> + </activity-alias> + <!-- CyanogenMod activities End --> <!-- Pseudo-activity used to provide an intent-filter entry point to encryption settings --> diff --git a/res/drawable-hdpi/ic_blacklist_calls_on.png b/res/drawable-hdpi/ic_blacklist_calls_icon.png Binary files differindex 5073d63..5073d63 100644 --- a/res/drawable-hdpi/ic_blacklist_calls_on.png +++ b/res/drawable-hdpi/ic_blacklist_calls_icon.png diff --git a/res/drawable-hdpi/ic_blacklist_calls_off.png b/res/drawable-hdpi/ic_blacklist_calls_off.png Binary files differdeleted file mode 100644 index 22a05c2..0000000 --- a/res/drawable-hdpi/ic_blacklist_calls_off.png +++ /dev/null diff --git a/res/drawable-hdpi/ic_blacklist_messages_on.png b/res/drawable-hdpi/ic_blacklist_messages_icon.png Binary files differindex 4d7c809..4d7c809 100644 --- a/res/drawable-hdpi/ic_blacklist_messages_on.png +++ b/res/drawable-hdpi/ic_blacklist_messages_icon.png diff --git a/res/drawable-hdpi/ic_blacklist_messages_off.png b/res/drawable-hdpi/ic_blacklist_messages_off.png Binary files differdeleted file mode 100644 index 812aaa5..0000000 --- a/res/drawable-hdpi/ic_blacklist_messages_off.png +++ /dev/null diff --git a/res/drawable-mdpi/ic_blacklist_calls_on.png b/res/drawable-mdpi/ic_blacklist_calls_icon.png Binary files differindex 9ec572d..9ec572d 100644 --- a/res/drawable-mdpi/ic_blacklist_calls_on.png +++ b/res/drawable-mdpi/ic_blacklist_calls_icon.png diff --git a/res/drawable-mdpi/ic_blacklist_calls_off.png b/res/drawable-mdpi/ic_blacklist_calls_off.png Binary files differdeleted file mode 100644 index 7917f46..0000000 --- a/res/drawable-mdpi/ic_blacklist_calls_off.png +++ /dev/null diff --git a/res/drawable-mdpi/ic_blacklist_messages_on.png b/res/drawable-mdpi/ic_blacklist_messages_icon.png Binary files differindex 01b4747..01b4747 100644 --- a/res/drawable-mdpi/ic_blacklist_messages_on.png +++ b/res/drawable-mdpi/ic_blacklist_messages_icon.png diff --git a/res/drawable-mdpi/ic_blacklist_messages_off.png b/res/drawable-mdpi/ic_blacklist_messages_off.png Binary files differdeleted file mode 100644 index a2e53e3..0000000 --- a/res/drawable-mdpi/ic_blacklist_messages_off.png +++ /dev/null diff --git a/res/drawable-xhdpi/ic_blacklist_calls_on.png b/res/drawable-xhdpi/ic_blacklist_calls_icon.png Binary files differindex cb67ee0..cb67ee0 100644 --- a/res/drawable-xhdpi/ic_blacklist_calls_on.png +++ b/res/drawable-xhdpi/ic_blacklist_calls_icon.png diff --git a/res/drawable-xhdpi/ic_blacklist_calls_off.png b/res/drawable-xhdpi/ic_blacklist_calls_off.png Binary files differdeleted file mode 100644 index 6fd91de..0000000 --- a/res/drawable-xhdpi/ic_blacklist_calls_off.png +++ /dev/null diff --git a/res/drawable-xhdpi/ic_blacklist_messages_on.png b/res/drawable-xhdpi/ic_blacklist_messages_icon.png Binary files differindex c12e04c..c12e04c 100644 --- a/res/drawable-xhdpi/ic_blacklist_messages_on.png +++ b/res/drawable-xhdpi/ic_blacklist_messages_icon.png diff --git a/res/drawable-xhdpi/ic_blacklist_messages_off.png b/res/drawable-xhdpi/ic_blacklist_messages_off.png Binary files differdeleted file mode 100644 index f32eab6..0000000 --- a/res/drawable-xhdpi/ic_blacklist_messages_off.png +++ /dev/null diff --git a/res/drawable-xxhdpi/ic_blacklist_calls_on.png b/res/drawable-xxhdpi/ic_blacklist_calls_icon.png Binary files differindex 7f252d3..7f252d3 100644 --- a/res/drawable-xxhdpi/ic_blacklist_calls_on.png +++ b/res/drawable-xxhdpi/ic_blacklist_calls_icon.png diff --git a/res/drawable-xxhdpi/ic_blacklist_calls_off.png b/res/drawable-xxhdpi/ic_blacklist_calls_off.png Binary files differdeleted file mode 100644 index 0841442..0000000 --- a/res/drawable-xxhdpi/ic_blacklist_calls_off.png +++ /dev/null diff --git a/res/drawable-xxhdpi/ic_blacklist_messages_on.png b/res/drawable-xxhdpi/ic_blacklist_messages_icon.png Binary files differindex 50dd562..50dd562 100644 --- a/res/drawable-xxhdpi/ic_blacklist_messages_on.png +++ b/res/drawable-xxhdpi/ic_blacklist_messages_icon.png diff --git a/res/drawable-xxhdpi/ic_blacklist_messages_off.png b/res/drawable-xxhdpi/ic_blacklist_messages_off.png Binary files differdeleted file mode 100644 index 10a07db..0000000 --- a/res/drawable-xxhdpi/ic_blacklist_messages_off.png +++ /dev/null diff --git a/res/drawable/ic_blacklist_calls.xml b/res/drawable/ic_blacklist_calls.xml index 401fb4a..33aa301 100644 --- a/res/drawable/ic_blacklist_calls.xml +++ b/res/drawable/ic_blacklist_calls.xml @@ -15,7 +15,14 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:state_checked="true" android:drawable="@drawable/ic_blacklist_calls_on" /> - <item android:drawable="@drawable/ic_blacklist_calls_off" /> + <item android:state_checked="true"> + <bitmap android:src="@drawable/ic_blacklist_calls_icon" + android:tint="@color/theme_accent"/> + </item> + <item> + <bitmap + android:src="@drawable/ic_blacklist_calls_icon" + android:tint="@*android:color/secondary_text_default_material_light"/> + </item> </selector> diff --git a/res/drawable/ic_blacklist_messages.xml b/res/drawable/ic_blacklist_messages.xml index f0fafa1..8365b9e 100644 --- a/res/drawable/ic_blacklist_messages.xml +++ b/res/drawable/ic_blacklist_messages.xml @@ -15,7 +15,13 @@ --> <selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:state_checked="true" android:drawable="@drawable/ic_blacklist_messages_on" /> - <item android:drawable="@drawable/ic_blacklist_messages_off" /> + <item android:state_checked="true"> + <bitmap android:src="@drawable/ic_blacklist_messages_icon" + android:tint="@color/theme_accent"/> + </item> + <item> + <bitmap android:src="@drawable/ic_blacklist_messages_icon" + android:tint="@*android:color/secondary_text_default_material_light"/> + </item> </selector> diff --git a/res/layout/empty_list_entry_footer.xml b/res/layout/empty_list_entry_footer.xml new file mode 100644 index 0000000..47e8967 --- /dev/null +++ b/res/layout/empty_list_entry_footer.xml @@ -0,0 +1,18 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 The CyanogenMod 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. +--> +<View xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="?android:attr/listPreferredItemHeight"/> diff --git a/res/layout/preference_blacklist.xml b/res/layout/preference_blacklist.xml new file mode 100644 index 0000000..38cceb7 --- /dev/null +++ b/res/layout/preference_blacklist.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2014 The CyanogenMod 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. +--> +<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <include layout="@*android:layout/preference_list_fragment"/> + + <include layout="@layout/fab" /> +</FrameLayout> diff --git a/res/menu/blacklist.xml b/res/menu/blacklist.xml index a3d294e..f3f6cce 100644 --- a/res/menu/blacklist.xml +++ b/res/menu/blacklist.xml @@ -16,13 +16,8 @@ <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item - android:id="@+id/blacklist_add" - android:title="@string/add_blacklist_number" - android:icon="@drawable/ic_menu_add" - android:showAsAction="ifRoom|withText" /> - <item android:id="@+id/blacklist_prefs" android:title="@string/blacklist_prefs" - android:icon="@drawable/ic_sysbar_quicksettings" + android:icon="@drawable/ic_settings_24dp" android:showAsAction="ifRoom|withText" /> </menu> diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 7d71b61..ba3a0cb 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -721,21 +721,21 @@ <string name="select_custom_activity_title">Select custom activity</string> <!-- Blacklist preferences --> - <string name="blacklist_title">Blacklist</string> - <string name="blacklist_edit_dialog_title">Edit blacklist entry</string> + <string name="blacklist_title">Blocked caller list</string> + <string name="blacklist_edit_dialog_title">Edit blocked phone number</string> <string name="blacklist_prefs">Settings</string> <string name="blacklist_button_delete">Delete</string> - <string name="blacklist_empty_text">You don\'t have any blacklisted numbers. Add an entry by touching the Add (+) button.</string> - <string name="blacklist_disabled_empty_text">To blacklist calls and/or messages from certain numbers, enable the blacklist.</string> + <string name="blacklist_empty_text">You don\'t have any blocked numbers. Add an entry by touching the Add (+) button.</string> + <string name="blacklist_disabled_empty_text">To prevent phone numbers from calling or messaging you, enable the blocked caller list.</string> <string name="blacklist_summary_disabled">Disabled</string> - <string name="blacklist_summary">Incoming calls and messages from phone numbers in the blacklist will be blocked</string> + <string name="blacklist_summary">You will not receive incoming calls or messages from phone numbers on the blocked caller list</string> <string name="blacklist_notify">Show notification</string> <string name="blacklist_private_numbers_title">Private numbers</string> <string name="blacklist_private_numbers_summary_disabled">Don\'t block calls from private numbers</string> - <string name="blacklist_private_numbers_summary">Block incoming <xliff:g id="type">%2$s</xliff:g> from private numbers</string> + <string name="blacklist_private_numbers_summary">Block incoming <xliff:g id="type">%s</xliff:g> from private numbers</string> <string name="blacklist_unknown_numbers_title">Unknown numbers</string> <string name="blacklist_unknown_numbers_summary_disabled">Don\'t block calls or messages from numbers not in the contact list</string> - <string name="blacklist_unknown_numbers_summary">Block incoming <xliff:g id="type">%2$s</xliff:g> from numbers not in the contact list</string> + <string name="blacklist_unknown_numbers_summary">Block incoming <xliff:g id="type">%s</xliff:g> from numbers not in the contact list</string> <string name="blacklist_summary_type_calls_only">calls</string> <string name="blacklist_summary_type_messages_only">messages</string> <string name="blacklist_summary_type_calls_and_messages">calls and messages</string> @@ -743,12 +743,11 @@ <string name="blacklist_regex_summary">Use . as a wildcard and * for repetition. E.g. 123.* blocks numbers starting with 123 and .*123.* blocks numbers containing 123</string> <string name="blacklist_policy_block_calls">Block incoming calls</string> <string name="blacklist_policy_block_messages">Block incoming messages</string> - <string name="blacklist_bad_number_add">Unable to add invalid number to blacklist</string> + <string name="blacklist_bad_number_add">Unable to add invalid phone number to blocked caller list</string> <!-- Blacklist management --> - <string name="add_blacklist_number">Add number</string> <string name="remove_blacklist_number_title">Remove number</string> - <string name="remove_blacklist_entry">Do you want to remove this blacklist entry?</string> + <string name="remove_blacklist_entry">Do you want to remove this blocked phone number?</string> <string name="select_contact">Select contact</string> <!-- Sms security limit --> diff --git a/res/xml/blacklist_prefs.xml b/res/xml/blacklist_prefs.xml index be63b7d..3b33ba2 100644 --- a/res/xml/blacklist_prefs.xml +++ b/res/xml/blacklist_prefs.xml @@ -27,16 +27,14 @@ android:title="@string/blacklist_private_numbers_title" android:dialogTitle="@string/blacklist_private_numbers_title" android:entries="@array/blacklist_policy_private_entries" - android:entryValues="@array/blacklist_policy_private_values" - android:persistent="false" /> + android:entryValues="@array/blacklist_policy_private_values" /> <MultiSelectListPreference android:key="button_blacklist_unknown_numbers" android:title="@string/blacklist_unknown_numbers_title" android:dialogTitle="@string/blacklist_unknown_numbers_title" android:entries="@array/blacklist_policy_unknown_entries" - android:entryValues="@array/blacklist_policy_unknown_values" - android:persistent="false" /> + android:entryValues="@array/blacklist_policy_unknown_values" /> <com.android.settings.cyanogenmod.SystemSettingCheckBoxPreference android:key="phone_blacklist_regex_enabled" diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index 74b8ff9..c8c8ec7 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -364,7 +364,7 @@ public class SettingsActivity extends Activity DrawOverlayDetails.class.getName(), WriteSettingsDetails.class.getName(), LiveDisplay.class.getName(), - com.android.settings.cyanogenmod.PrivacySettings.class.getName() + com.android.settings.cyanogenmod.PrivacySettings.class.getName(), BlacklistSettings.class.getName() }; diff --git a/src/com/android/settings/blacklist/PreferenceFragment.java b/src/com/android/settings/blacklist/BlacklistPreferences.java index b8ecddd..2ee449f 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 c30d410..db7fe5a 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 3e29279..9fda2ba 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); diff --git a/src/com/android/settings/profiles/ProfileEnabler.java b/src/com/android/settings/cyanogenmod/BaseSystemSettingSwitchBar.java index 8bf450c..22f5277 100644 --- a/src/com/android/settings/profiles/ProfileEnabler.java +++ b/src/com/android/settings/cyanogenmod/BaseSystemSettingSwitchBar.java @@ -1,48 +1,31 @@ /* - * Copyright (C) 2010 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.settings.profiles; - -import cyanogenmod.app.ProfileManager; -import android.content.BroadcastReceiver; +* Copyright (C) 2014 The CyanogenMod 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.settings.cyanogenmod; + import android.content.ContentResolver; import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; import android.database.ContentObserver; -import android.net.NetworkInfo; import android.net.Uri; -import android.net.wifi.SupplicantState; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; import android.os.Handler; -import android.os.Message; +import android.provider.Settings; import android.widget.Switch; -import android.widget.Toast; -import com.android.settings.R; -import com.android.settings.WirelessSettings; -import com.android.settings.search.Index; import com.android.settings.widget.SwitchBar; -import com.android.settings.wifi.WifiSettings; - -import cyanogenmod.providers.CMSettings; -import java.util.concurrent.atomic.AtomicBoolean; - -public class ProfileEnabler implements SwitchBar.OnSwitchChangeListener { +public class BaseSystemSettingSwitchBar implements SwitchBar.OnSwitchChangeListener { private Context mContext; private SwitchBar mSwitchBar; private SettingsObserver mSettingsObserver; @@ -50,9 +33,21 @@ public class ProfileEnabler implements SwitchBar.OnSwitchChangeListener { private boolean mStateMachineEvent; - public ProfileEnabler(Context context, SwitchBar switchBar) { + private final String mSettingKey; + private final int mDefaultState; + + private final SwitchBarChangeCallback mCallback; + public interface SwitchBarChangeCallback { + public void onEnablerChanged(boolean isEnabled); + } + + public BaseSystemSettingSwitchBar(Context context, SwitchBar switchBar, String key, + boolean defaultState, SwitchBarChangeCallback callback) { mContext = context; mSwitchBar = switchBar; + mSettingKey = key; + mDefaultState = defaultState ? 1 : 0; + mCallback = callback; mSettingsObserver = new SettingsObserver(new Handler()); setupSwitchBar(); } @@ -97,11 +92,14 @@ public class ProfileEnabler implements SwitchBar.OnSwitchChangeListener { mStateMachineEvent = true; mSwitchBar.setChecked(checked); mStateMachineEvent = false; + if (mCallback != null) { + mCallback.onEnablerChanged(checked); + } } private void setSwitchState() { - boolean enabled = CMSettings.System.getInt(mContext.getContentResolver(), - CMSettings.System.SYSTEM_PROFILES_ENABLED, 1) == 1; + boolean enabled = Settings.System.getInt(mContext.getContentResolver(), + mSettingKey, mDefaultState) == 1; mStateMachineEvent = true; setSwitchBarChecked(enabled); mStateMachineEvent = false; @@ -115,18 +113,12 @@ public class ProfileEnabler implements SwitchBar.OnSwitchChangeListener { } // Handle a switch change - CMSettings.System.putInt(mContext.getContentResolver(), - CMSettings.System.SYSTEM_PROFILES_ENABLED, isChecked ? 1 : 0); - - // Send a broadcast intent to the world - // TODO Enabling or disabling profiles should be at ProfileManager, not here - Intent intent=new Intent(ProfileManager.PROFILES_STATE_CHANGED_ACTION); - intent.putExtra( - ProfileManager.EXTRA_PROFILES_STATE, - isChecked ? - ProfileManager.PROFILES_STATE_ENABLED : - ProfileManager.PROFILES_STATE_DISABLED); - mContext.sendBroadcast(intent); + Settings.System.putInt(mContext.getContentResolver(), + mSettingKey, isChecked ? 1 : 0); + + if (mCallback != null) { + mCallback.onEnablerChanged(isChecked); + } } class SettingsObserver extends ContentObserver { @@ -136,8 +128,8 @@ public class ProfileEnabler implements SwitchBar.OnSwitchChangeListener { void observe() { ContentResolver resolver = mContext.getContentResolver(); - resolver.registerContentObserver(CMSettings.System.getUriFor( - CMSettings.System.SYSTEM_PROFILES_ENABLED), false, this); + resolver.registerContentObserver(Settings.System.getUriFor( + mSettingKey), false, this); update(); } @@ -151,6 +143,11 @@ public class ProfileEnabler implements SwitchBar.OnSwitchChangeListener { update(); } + @Override + public void onChange(boolean selfChange, Uri uri) { + update(); + } + public void update() { setSwitchState(); } diff --git a/src/com/android/settings/cyanogenmod/PrivacySettings.java b/src/com/android/settings/cyanogenmod/PrivacySettings.java index ced0832..0e62915 100644 --- a/src/com/android/settings/cyanogenmod/PrivacySettings.java +++ b/src/com/android/settings/cyanogenmod/PrivacySettings.java @@ -40,13 +40,15 @@ public class PrivacySettings extends SettingsPreferenceFragment { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.privacy_settings_cyanogenmod); + mBlacklist = (PreferenceScreen) findPreference(KEY_BLACKLIST); + // Add package manager to check if features are available PackageManager pm = getPackageManager(); // Determine options based on device telephony support if (!pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) { // No telephony, remove dependent options - PreferenceScreen root = getPreferenceScreen(); + PreferenceScreen root = getPreferenceScreen(); root.removePreference(mBlacklist); } } @@ -63,12 +65,10 @@ public class PrivacySettings extends SettingsPreferenceFragment { } private void updateBlacklistSummary() { - if (mBlacklist != null) { - if (BlacklistUtils.isBlacklistEnabled(getActivity())) { - mBlacklist.setSummary(R.string.blacklist_summary); - } else { - mBlacklist.setSummary(R.string.blacklist_summary_disabled); - } + if (BlacklistUtils.isBlacklistEnabled(getActivity())) { + mBlacklist.setSummary(R.string.blacklist_summary); + } else { + mBlacklist.setSummary(R.string.blacklist_summary_disabled); } } diff --git a/src/com/android/settings/profiles/ProfilesList.java b/src/com/android/settings/profiles/ProfilesList.java index 250051a..34e53a0 100644 --- a/src/com/android/settings/profiles/ProfilesList.java +++ b/src/com/android/settings/profiles/ProfilesList.java @@ -26,9 +26,12 @@ import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceScreen; import android.text.TextUtils; +import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.View; +import android.widget.ListView; import com.android.settings.R; import com.android.settings.SettingsPreferenceFragment; @@ -59,6 +62,19 @@ public class ProfilesList extends SettingsPreferenceFragment implements refreshList(); } + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + // Add a footer to avoid a situation where the FAB would cover the last + // item's options in a non-scrollable listview. + ListView listView = getListView(); + View footer = LayoutInflater.from(getActivity()) + .inflate(R.layout.empty_list_entry_footer, listView, false); + listView.addFooterView(footer); + listView.setFooterDividersEnabled(false); + footer.setOnClickListener(null); + } + public void refreshList() { PreferenceScreen plist = getPreferenceScreen(); plist.removeAll(); diff --git a/src/com/android/settings/profiles/ProfilesSettings.java b/src/com/android/settings/profiles/ProfilesSettings.java index 59078ae..cf6c161 100644 --- a/src/com/android/settings/profiles/ProfilesSettings.java +++ b/src/com/android/settings/profiles/ProfilesSettings.java @@ -50,11 +50,13 @@ import com.android.settings.SettingsActivity; import com.android.settings.SettingsPreferenceFragment; import com.android.settings.SubSettings; import com.android.settings.Utils; +import com.android.settings.cyanogenmod.BaseSystemSettingSwitchBar; import cyanogenmod.providers.CMSettings; import java.util.UUID; -public class ProfilesSettings extends SettingsPreferenceFragment { +public class ProfilesSettings extends SettingsPreferenceFragment + implements BaseSystemSettingSwitchBar.SwitchBarChangeCallback { private static final String TAG = "ProfilesSettings"; public static final String EXTRA_PROFILE = "Profile"; @@ -67,7 +69,7 @@ public class ProfilesSettings extends SettingsPreferenceFragment { private final BroadcastReceiver mReceiver; private ProfileManager mProfileManager; - private ProfileEnabler mProfileEnabler; + private BaseSystemSettingSwitchBar mProfileEnabler; private ViewPager mViewPager; private TextView mEmptyText; @@ -156,7 +158,8 @@ public class ProfilesSettings extends SettingsPreferenceFragment { public void onStart() { super.onStart(); final SettingsActivity activity = (SettingsActivity) getActivity(); - mProfileEnabler = new ProfileEnabler(activity, activity.getSwitchBar()); + mProfileEnabler = new BaseSystemSettingSwitchBar(activity, activity.getSwitchBar(), + CMSettings.System.SYSTEM_PROFILES_ENABLED, true, this); } @Override @@ -231,6 +234,16 @@ public class ProfilesSettings extends SettingsPreferenceFragment { mEmptyText.setVisibility(mEnabled ? View.GONE : View.VISIBLE); } + @Override + public void onEnablerChanged(boolean isEnabled) { + Intent intent = new Intent(ProfileManager.PROFILES_STATE_CHANGED_ACTION); + intent.putExtra(ProfileManager.EXTRA_PROFILES_STATE, + isEnabled ? + ProfileManager.PROFILES_STATE_ENABLED : + ProfileManager.PROFILES_STATE_DISABLED); + getActivity().sendBroadcast(intent); + } + class ProfilesPagerAdapter extends FragmentStatePagerAdapter { Fragment[] frags = { new ProfilesList() }; String[] titles = { getString(R.string.profile_profiles_manage) }; |