summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/values/cm_arrays.xml7
-rw-r--r--res/values/cm_strings.xml6
-rw-r--r--src/com/android/settings/profiles/AbstractTriggerPreference.java38
-rw-r--r--src/com/android/settings/profiles/BluetoothTriggerPreference.java45
-rw-r--r--src/com/android/settings/profiles/ProfileConfig.java16
-rw-r--r--src/com/android/settings/profiles/TriggersFragment.java229
-rw-r--r--src/com/android/settings/profiles/WifiTriggerAPPreference.java31
-rw-r--r--src/com/android/settings/profiles/WifiTriggerFragment.java139
8 files changed, 339 insertions, 172 deletions
diff --git a/res/values/cm_arrays.xml b/res/values/cm_arrays.xml
index 16d2384..74fc542 100644
--- a/res/values/cm_arrays.xml
+++ b/res/values/cm_arrays.xml
@@ -226,6 +226,13 @@
<item>@string/profile_trigger_notrigger</item>
</string-array>
+ <!-- Values for profile trigger types -->
+ <string-array name="profile_trigger_filters" translatable="false">
+ <item>@string/profile_trigger_filter_all</item>
+ <item>@string/profile_trigger_filter_wifi</item>
+ <item>@string/profile_trigger_filter_bluetooth</item>
+ </string-array>
+
<!-- Profile lock mode options. Do not translate. -->
<string-array name="profile_lockmode_entries" translatable="false">
<item>@string/profile_lockmode_default</item>
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml
index b4bcd88..80eb7a4 100644
--- a/res/values/cm_strings.xml
+++ b/res/values/cm_strings.xml
@@ -446,9 +446,11 @@
<string name="increasing_ring_interval_5seconds">5 seconds</string>
<string name="increasing_ring_interval_10seconds">10 seconds</string>
- <string name="profile_trigger_title_wifi">Wi-Fi triggers for <xliff:g id="profile">%s</xliff:g></string>
<string name="profile_trigger_configure">Configure trigger</string>
- <string name="profile_trigger_wifi">Wi-Fi triggers</string>
+ <string name="profile_triggers">Triggers</string>
+ <string name="profile_trigger_filter_all">All triggers</string>
+ <string name="profile_trigger_filter_wifi">Wi-Fi triggers</string>
+ <string name="profile_trigger_filter_bluetooth">Bluetooth triggers</string>
<string name="profile_write_nfc_tag">Write to NFC tag</string>
<string name="profile_write_touch_tag">Touch tag to write</string>
<string name="profile_write_success">Tag successfully written</string>
diff --git a/src/com/android/settings/profiles/AbstractTriggerPreference.java b/src/com/android/settings/profiles/AbstractTriggerPreference.java
new file mode 100644
index 0000000..1bc2ec0
--- /dev/null
+++ b/src/com/android/settings/profiles/AbstractTriggerPreference.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2013 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.profiles;
+
+import android.app.Profile;
+import android.content.Context;
+import android.preference.Preference;
+
+public class AbstractTriggerPreference extends Preference {
+
+ public AbstractTriggerPreference(Context context) {
+ super(context);
+ }
+
+ private int mTriggerState = Profile.TriggerState.DISABLED;
+
+ public void setTriggerState(int trigger) {
+ mTriggerState = trigger;
+ }
+
+ public int getTriggerState() {
+ return mTriggerState;
+ }
+}
diff --git a/src/com/android/settings/profiles/BluetoothTriggerPreference.java b/src/com/android/settings/profiles/BluetoothTriggerPreference.java
new file mode 100644
index 0000000..848fc28
--- /dev/null
+++ b/src/com/android/settings/profiles/BluetoothTriggerPreference.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2013 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.profiles;
+
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+
+public class BluetoothTriggerPreference extends AbstractTriggerPreference {
+
+ private String mAddress;
+
+ BluetoothTriggerPreference(Context context, BluetoothDevice device) {
+ super(context);
+ mAddress = device.getAddress();
+ if (device.getAlias() != null) {
+ setTitle(device.getAlias());
+ } else {
+ setTitle(device.getName());
+ }
+ }
+
+ BluetoothTriggerPreference(Context context, String name, String address) {
+ super(context);
+ mAddress = address;
+ setTitle(name);
+ }
+
+ public String getAddress() {
+ return mAddress;
+ }
+}
diff --git a/src/com/android/settings/profiles/ProfileConfig.java b/src/com/android/settings/profiles/ProfileConfig.java
index a27baa7..1a7a53e 100644
--- a/src/com/android/settings/profiles/ProfileConfig.java
+++ b/src/com/android/settings/profiles/ProfileConfig.java
@@ -63,7 +63,7 @@ public class ProfileConfig extends SettingsPreferenceFragment
private static final int MENU_DELETE = Menu.FIRST + 1;
- private static final int MENU_WIFI = Menu.FIRST + 2;
+ private static final int MENU_TRIGGERS = Menu.FIRST + 2;
private Profile mProfile;
@@ -135,9 +135,9 @@ public class ProfileConfig extends SettingsPreferenceFragment
nfc.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
}
- MenuItem wifi = menu.add(0, MENU_WIFI, 0, R.string.profile_trigger_wifi)
+ MenuItem triggers = menu.add(0, MENU_TRIGGERS, 0, R.string.profile_triggers)
.setIcon(R.drawable.ic_location);
- wifi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
+ triggers.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM |
MenuItem.SHOW_AS_ACTION_WITH_TEXT);
MenuItem delete = menu.add(0, MENU_DELETE, 1, R.string.profile_menu_delete)
.setIcon(R.drawable.ic_menu_trash_holo_dark);
@@ -154,8 +154,8 @@ public class ProfileConfig extends SettingsPreferenceFragment
case MENU_NFC_WRITE:
startNFCProfileWriter();
return true;
- case MENU_WIFI:
- startWifiTrigger();
+ case MENU_TRIGGERS:
+ startTriggerFragment();
return true;
default:
return false;
@@ -186,14 +186,12 @@ public class ProfileConfig extends SettingsPreferenceFragment
pa.startActivity(i);
}
- private void startWifiTrigger() {
+ private void startTriggerFragment() {
final PreferenceActivity pa = (PreferenceActivity) getActivity();
- final String title = getResources().getString(R.string.profile_trigger_title_wifi,
- mProfile.getName());
final Bundle args = new Bundle();
args.putParcelable("profile", mProfile);
- pa.startPreferencePanel(WifiTriggerFragment.class.getName(), args, 0, title, null, 0);
+ pa.startPreferencePanel(TriggersFragment.class.getName(), args, 0, "", null, 0);
}
private void fillList() {
diff --git a/src/com/android/settings/profiles/TriggersFragment.java b/src/com/android/settings/profiles/TriggersFragment.java
new file mode 100644
index 0000000..d3d01e9
--- /dev/null
+++ b/src/com/android/settings/profiles/TriggersFragment.java
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2013 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.profiles;
+
+import android.app.ActionBar;
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.Profile;
+import android.app.Profile.ProfileTrigger;
+import android.app.Profile.TriggerType;
+import android.app.ProfileManager;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.res.Resources;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.os.Bundle;
+import android.preference.Preference;
+import android.preference.PreferenceScreen;
+import android.util.Log;
+import android.widget.ArrayAdapter;
+
+import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * Settings Preference to configure triggers to switch profiles base on Wi-Fi events
+ */
+public class TriggersFragment extends SettingsPreferenceFragment implements ActionBar.OnNavigationListener {
+ private Profile mProfile;
+ private Preference mSelectedTrigger;
+ private ProfileManager mProfileManager;
+ private WifiManager mWifiManager;
+ private BluetoothAdapter mBluetoothAdapter;
+
+ private int mTriggerFilter = 0;
+ private static final int WIFI_TRIGGER = 1;
+ private static final int BT_TRIGGER = 2;
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ mProfileManager = (ProfileManager) getSystemService(Context.PROFILE_SERVICE);
+ mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();;
+ addPreferencesFromResource(R.xml.wifi_settings);
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ loadPreferences();
+ loadActionBar();
+ }
+
+ private void loadActionBar() {
+ final ActionBar actionBar = getActivity().getActionBar();
+ actionBar.setDisplayShowTitleEnabled(true);
+ actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
+ Resources res = getResources();
+
+ String[] navItems = res.getStringArray(R.array.profile_trigger_filters);
+ ArrayAdapter<String> navAdapter = new ArrayAdapter<String>(
+ actionBar.getThemedContext(), android.R.layout.simple_list_item_1, navItems);
+
+ // Set up the dropdown list navigation in the action bar.
+ actionBar.setListNavigationCallbacks(navAdapter, this);
+ actionBar.setDisplayOptions(ActionBar.DISPLAY_HOME_AS_UP
+ | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Bundle args = getArguments();
+ if (args != null) {
+ mProfile = args.getParcelable("profile");
+ }
+ }
+
+ private void initPreference(AbstractTriggerPreference pref, int state, Resources res, int icon) {
+ String summary = res.getStringArray(R.array.profile_trigger_wifi_options)[state];
+ pref.setSummary(summary);
+ pref.setTriggerState(state);
+ pref.setIcon(icon);
+ }
+
+ private void loadPreferences() {
+ final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
+ final Resources res = getResources();
+ final List<AbstractTriggerPreference> prefs = new ArrayList<AbstractTriggerPreference>();
+
+ getPreferenceScreen().removeAll();
+
+ if (mTriggerFilter == WIFI_TRIGGER || mTriggerFilter == 0) {
+ if (configs != null ) {
+ for (WifiConfiguration config : configs) {
+ WifiTriggerAPPreference accessPoint =
+ new WifiTriggerAPPreference(getActivity(), config);
+ int state = mProfile.getTrigger(Profile.TriggerType.WIFI, accessPoint.getSSID());
+ initPreference(accessPoint, state, res, R.drawable.ic_wifi_signal_4);
+ prefs.add(accessPoint);
+ }
+ } else {
+ final List<ProfileTrigger> triggers = mProfile.getTriggersFromType(TriggerType.WIFI);
+ for (ProfileTrigger trigger : triggers) {
+ WifiTriggerAPPreference accessPoint =
+ new WifiTriggerAPPreference(getActivity(), trigger.getName());
+ initPreference(accessPoint, trigger.getState(), res, R.drawable.ic_wifi_signal_4);
+ prefs.add(accessPoint);
+ }
+ }
+ }
+
+ Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
+ if (mTriggerFilter == BT_TRIGGER || mTriggerFilter == 0) {
+ if (!pairedDevices.isEmpty()) {
+ for (BluetoothDevice device : pairedDevices) {
+ BluetoothTriggerPreference bt =
+ new BluetoothTriggerPreference(getActivity(), device);
+ int state = mProfile.getTrigger(Profile.TriggerType.BLUETOOTH, bt.getAddress());
+ initPreference(bt, state, res, R.drawable.ic_settings_bluetooth2);
+ prefs.add(bt);
+ }
+ } else {
+ final List<ProfileTrigger> triggers = mProfile.getTriggersFromType(TriggerType.BLUETOOTH);
+ for (ProfileTrigger trigger : triggers) {
+ BluetoothTriggerPreference bt = new BluetoothTriggerPreference(getActivity(),
+ trigger.getName(), trigger.getId());
+ initPreference(bt, trigger.getState(), res, R.drawable.ic_settings_bluetooth2);
+ prefs.add(bt);
+ }
+ }
+ }
+
+ Collections.sort(prefs, new Comparator<AbstractTriggerPreference>() {
+ @Override
+ public int compare(AbstractTriggerPreference o1, AbstractTriggerPreference o2) {
+ if (o1.getTriggerState() == o2.getTriggerState()) {
+ return o1.compareTo(o2);
+ }
+ return o1.getTriggerState() < o2.getTriggerState() ? -1 : 1;
+ }
+ });
+ for (Preference pref: prefs) {
+ getPreferenceScreen().addPreference(pref);
+ }
+
+ }
+
+ @Override
+ public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
+ mSelectedTrigger = preference;
+ if (preference instanceof WifiTriggerAPPreference) {
+ showDialog(WIFI_TRIGGER);
+ return true;
+ } else if (preference instanceof BluetoothTriggerPreference) {
+ showDialog(BT_TRIGGER);
+ return true;
+ }
+ return super.onPreferenceTreeClick(screen, preference);
+ }
+
+ @Override
+ public Dialog onCreateDialog(final int dialogId) {
+ final String id;
+ final String triggerName = mSelectedTrigger.getTitle().toString();
+ final int triggerType;
+
+ switch (dialogId) {
+ case WIFI_TRIGGER:
+ WifiTriggerAPPreference pref = (WifiTriggerAPPreference) mSelectedTrigger;
+ id = pref.getSSID();
+ triggerType = Profile.TriggerType.WIFI;
+ break;
+ case BT_TRIGGER:
+ BluetoothTriggerPreference btpref = (BluetoothTriggerPreference) mSelectedTrigger;
+ id = btpref.getAddress();
+ triggerType = Profile.TriggerType.BLUETOOTH;
+ break;
+ default:
+ return super.onCreateDialog(dialogId);
+ }
+
+ return new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.profile_trigger_configure)
+ .setSingleChoiceItems(R.array.profile_trigger_wifi_options,
+ mProfile.getTrigger(triggerType, id),
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ mProfile.setTrigger(triggerType, id, which, triggerName);
+ mProfileManager.updateProfile(mProfile);
+ loadPreferences();
+ dialog.dismiss();
+ }
+ })
+ .create();
+ }
+
+ @Override
+ public boolean onNavigationItemSelected(int itemPosition, long itemId) {
+ mTriggerFilter = itemPosition;
+ loadPreferences();
+ return true;
+ }
+}
diff --git a/src/com/android/settings/profiles/WifiTriggerAPPreference.java b/src/com/android/settings/profiles/WifiTriggerAPPreference.java
index c886bc1..239509a 100644
--- a/src/com/android/settings/profiles/WifiTriggerAPPreference.java
+++ b/src/com/android/settings/profiles/WifiTriggerAPPreference.java
@@ -16,46 +16,33 @@
package com.android.settings.profiles;
-import android.app.Profile;
import android.content.Context;
import android.net.wifi.WifiConfiguration;
-import android.os.Bundle;
-import android.preference.Preference;
-import com.android.settings.R;
+public class WifiTriggerAPPreference extends AbstractTriggerPreference {
-public class WifiTriggerAPPreference extends Preference {
-
- private String mSsid;
- private int mTriggerType = Profile.TriggerState.DISABLED;
+ private String mSSID;
private WifiConfiguration mConfig;
WifiTriggerAPPreference(Context context, WifiConfiguration config) {
super(context);
- setWidgetLayoutResource(R.layout.preference_widget_wifi_signal);
loadConfig(config);
- setTitle(mSsid);
- }
-
- public void setTriggerType(int trigger) {
- mTriggerType = trigger;
+ setTitle(mSSID);
}
- public int getTriggerType() {
- return mTriggerType;
+ WifiTriggerAPPreference(Context context, String ssid) {
+ super(context);
+ mSSID = ssid;
+ setTitle(mSSID);
}
private void loadConfig(WifiConfiguration config) {
- mSsid = (config.SSID == null ? "" : removeDoubleQuotes(config.SSID));
+ mSSID = (config.SSID == null ? "" : removeDoubleQuotes(config.SSID));
mConfig = config;
}
- public WifiConfiguration getConfig() {
- return mConfig;
- }
-
public String getSSID() {
- return mSsid;
+ return mSSID;
}
public static String removeDoubleQuotes(String string) {
diff --git a/src/com/android/settings/profiles/WifiTriggerFragment.java b/src/com/android/settings/profiles/WifiTriggerFragment.java
deleted file mode 100644
index 73d40a2..0000000
--- a/src/com/android/settings/profiles/WifiTriggerFragment.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Copyright (C) 2013 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.profiles;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.Profile;
-import android.app.ProfileManager;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.res.Resources;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiManager;
-import android.os.Bundle;
-import android.preference.Preference;
-import android.preference.PreferenceScreen;
-
-import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
-
-/**
- * Settings Preference to configure triggers to switch profiles base on Wi-Fi events
- */
-public class WifiTriggerFragment extends SettingsPreferenceFragment {
- private Profile mProfile;
- private WifiTriggerAPPreference mSelectedAccessPoint;
- private ProfileManager mProfileManager;
- private WifiManager mWifiManager;
-
- private static final int WIFI_TRIGGER = 1;
-
- @Override
- public void onActivityCreated(Bundle savedInstanceState) {
- super.onActivityCreated(savedInstanceState);
- mProfileManager = (ProfileManager) getSystemService(Context.PROFILE_SERVICE);
- mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
- addPreferencesFromResource(R.xml.wifi_settings);
- }
-
- @Override
- public void onResume() {
- super.onResume();
- loadWifiConfiguration();
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Bundle args = getArguments();
- if (args != null) {
- mProfile = args.getParcelable("profile");
- }
- }
-
- private void loadWifiConfiguration() {
- final List<WifiConfiguration> configs = mWifiManager.getConfiguredNetworks();
- final Resources res = getResources();
- final List<WifiTriggerAPPreference> aps = new ArrayList<WifiTriggerAPPreference>();
-
- getPreferenceScreen().removeAll();
-
- if (configs != null) {
- for (WifiConfiguration config : configs) {
- WifiTriggerAPPreference accessPoint = new WifiTriggerAPPreference(getActivity(), config);
- int state = mProfile.getWifiTrigger(accessPoint.getSSID());
- String summary = res.getStringArray(R.array.profile_trigger_wifi_options)[state];
-
- accessPoint.setSummary(summary);
- accessPoint.setTriggerType(state);
- aps.add(accessPoint);
- }
- }
-
- Collections.sort(aps, new Comparator<WifiTriggerAPPreference>() {
- @Override
- public int compare(WifiTriggerAPPreference o1, WifiTriggerAPPreference o2) {
- if (o1.getTriggerType() == o2.getTriggerType()) {
- return o1.getSSID().compareTo(o2.getSSID());
- }
- return o1.getTriggerType() < o2.getTriggerType() ? -1 : 1;
- }
- });
- for (WifiTriggerAPPreference ap: aps) {
- getPreferenceScreen().addPreference(ap);
- }
- }
-
- @Override
- public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
- if (preference instanceof WifiTriggerAPPreference) {
- mSelectedAccessPoint = (WifiTriggerAPPreference) preference;
- showDialog(WIFI_TRIGGER);
- return true;
- }
- return super.onPreferenceTreeClick(screen, preference);
- }
-
- @Override
- public Dialog onCreateDialog(int dialogId) {
- switch (dialogId) {
- case WIFI_TRIGGER:
- final String ssid = mSelectedAccessPoint.getSSID();
- int currentTriggerType = mProfile.getWifiTrigger(ssid);
-
- return new AlertDialog.Builder(getActivity())
- .setTitle(R.string.profile_trigger_configure)
- .setSingleChoiceItems(R.array.profile_trigger_wifi_options, currentTriggerType,
- new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- mProfile.setWifiTrigger(ssid, which);
- mProfileManager.updateProfile(mProfile);
- loadWifiConfiguration();
- dialog.dismiss();
- }
- })
- .create();
- }
- return super.onCreateDialog(dialogId);
- }
-}