Loading packages/SystemUI/res/layout-sw720dp/status_bar_settings_button.xml 0 → 100644 +15 −0 Original line number Diff line number Diff line <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/StatusBarPanelSettingsRow"> <ImageView style="@style/StatusBarPanelSettingsIcon"/> <TextView style="@style/StatusBarPanelSettingsContents"/> <Switch android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp"/> </LinearLayout> packages/SystemUI/res/layout/system_bar_settings_view.xml +2 −152 Original line number Diff line number Diff line Loading @@ -18,168 +18,18 @@ <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui" android:layout_height="match_parent" android:layout_width="match_parent"> <com.android.systemui.statusbar.tablet.SettingsView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <!-- Toggle 1 --> <LinearLayout android:id="@+id/toggle_1" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_1_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/ic_sysbar_airplane_on" /> <TextView android:id="@+id/toggle_1_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_airplane" /> <Switch android:id="@+id/toggle_1_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View android:id="@+id/rotate_separator" style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Toggle 2 --> <LinearLayout android:id="@+id/toggle_2" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_2_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/ic_sysbar_wifi_on" /> <TextView android:id="@+id/toggle_2_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_wifi_button" /> <Switch android:id="@+id/toggle_2_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Toggle 3 --> <LinearLayout android:id="@+id/toggle_3" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_3_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/stat_sys_data_bluetooth" /> <TextView android:id="@+id/toggle_3_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_bluetooth_button" /> <Switch android:id="@+id/toggle_3_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Toggle 4 --> <LinearLayout android:id="@+id/toggle_4" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_4_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/ic_sysbar_rotate_on" /> <TextView android:id="@+id/toggle_4_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_auto_rotation" /> <Switch android:id="@+id/toggle_4_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Toggle 5 --> <LinearLayout android:id="@+id/toggle_5" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_5_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/stat_gps_on" /> <TextView android:id="@+id/toggle_5_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_location" /> <Switch android:id="@+id/toggle_5_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Power widget buttons will be added here --> <!-- Toggle 6 --> <LinearLayout android:id="@+id/toggle_6" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_6_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/stat_flashlight_on" /> <TextView android:id="@+id/toggle_6_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_flashlight" /> <Switch android:id="@+id/toggle_6_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Brightness --> Loading packages/SystemUI/res/values/styles.xml +23 −0 Original line number Diff line number Diff line Loading @@ -108,4 +108,27 @@ <item name="android:textSize">14dp</item> </style> <style name="StatusBarPanelSettingsIcon"> <item name="android:layout_height">match_parent</item> <item name="android:layout_width">64dp</item> <item name="android:scaleType">center</item> </style> <style name="StatusBarPanelSettingsRow"> <item name="android:paddingRight">16dp</item> <item name="android:layout_height">64dp</item> <item name="android:layout_width">match_parent</item> <item name="android:orientation">horizontal</item> <item name="android:background">?android:attr/listChoiceBackgroundIndicator</item> </style> <style name="StatusBarPanelSettingsContents"> <item name="android:layout_height">wrap_content</item> <item name="android:layout_width">0dp</item> <item name="android:layout_weight">1</item> <item name="android:layout_gravity">left|center_vertical</item> <item name="android:textColor">?android:attr/textColorPrimary</item> <item name="android:textSize">18sp</item> </style> </resources> packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiController.java 0 → 100644 +160 −0 Original line number Diff line number Diff line /* * 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.systemui.statusbar.policy; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.AsyncTask; import android.os.RemoteException; import android.os.ServiceManager; import android.provider.Settings; import android.util.Slog; import android.widget.CompoundButton; import android.net.NetworkInfo; import android.net.wifi.SupplicantState; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import java.util.concurrent.atomic.AtomicBoolean; public class WifiController extends BroadcastReceiver implements CompoundButton.OnCheckedChangeListener { private static final String TAG = "StatusBar.WifiController"; private Context mContext; private CompoundButton mCheckBox; private boolean mStateMachineEvent; private final WifiManager mWifiManager; private AtomicBoolean mConnected = new AtomicBoolean(false); private boolean mWifi; public WifiController(Context context, CompoundButton checkbox) { mContext = context; mWifi = getWifi(); mCheckBox = checkbox; checkbox.setChecked(mWifi); checkbox.setOnCheckedChangeListener(this); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); IntentFilter filter = new IntentFilter(); filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); context.registerReceiver(this, filter); } public void release() { mContext.unregisterReceiver(this); } public void onCheckedChanged(CompoundButton view, boolean checked) { //Do nothing if called as a result of a state machine event if (mStateMachineEvent) { return; } // Show toast message if Wi-Fi is not allowed in airplane mode // Disable tethering if enabling Wifi int wifiApState = mWifiManager.getWifiApState(); if (mCheckBox.isChecked() && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) || (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) { mWifiManager.setWifiApEnabled(null, false); } if (mWifiManager.setWifiEnabled(mCheckBox.isChecked())) { // Intent has been taken into account, disable until new state is active mCheckBox.setChecked(false); } } public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { handleWifiStateChanged(intent.getIntExtra( WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN)); } else if (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION.equals(action)) { if (!mConnected.get()) { handleStateChanged(WifiInfo.getDetailedStateOf((SupplicantState) intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE))); } } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { NetworkInfo info = (NetworkInfo) intent.getParcelableExtra( WifiManager.EXTRA_NETWORK_INFO); mConnected.set(info.isConnected()); handleStateChanged(info.getDetailedState()); } } private void handleStateChanged(@SuppressWarnings("unused") NetworkInfo.DetailedState state) { } private void handleWifiStateChanged(int state) { switch (state) { case WifiManager.WIFI_STATE_ENABLING: mCheckBox.setEnabled(false); break; case WifiManager.WIFI_STATE_ENABLED: setSwitchChecked(true); mCheckBox.setEnabled(true); break; case WifiManager.WIFI_STATE_DISABLING: mCheckBox.setEnabled(false); break; case WifiManager.WIFI_STATE_DISABLED: setSwitchChecked(false); mCheckBox.setEnabled(true); break; default: setSwitchChecked(false); mCheckBox.setEnabled(true); break; } } private void setSwitchChecked(boolean checked) { if (checked != mCheckBox.isChecked()) { mStateMachineEvent = true; mCheckBox.setChecked(checked); mStateMachineEvent = false; } } private boolean getWifi() { ContentResolver cr = mContext.getContentResolver(); return 0 != Settings.System.getInt(cr, Settings.System.AIRPLANE_MODE_ON, 0); } // TODO: Fix this racy API by adding something better to TelephonyManager or // ConnectivityService. private void unsafe(final boolean enabled) { AsyncTask.execute(new Runnable() { public void run() { Settings.System.putInt( mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, enabled ? 1 : 0); Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.putExtra("state", enabled); mContext.sendBroadcast(intent); } }); } } packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java +69 −79 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ import android.widget.LinearLayout; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.TextView; import android.widget.Switch; import android.view.LayoutInflater; import com.android.systemui.R; import com.android.systemui.statusbar.policy.AirplaneModeController; Loading @@ -51,7 +53,6 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { static final String TAG = "SettingsView"; private static final String NO_TOGGLES = "no_toggles"; private static final int[] TOGGLE_ID_ARRAY = new int[6]; private static final int AIRPLANE_ID = 0; private static final int ROTATE_ID = 1; private static final int BLUETOOTH_ID = 2; Loading @@ -62,15 +63,6 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { private static final int NETWORK_MODE_ID = 7; private static final int SOUND_ID = 8; private static final int[] mToggleIds = new int[]{ R.id.toggle_1, R.id.toggle_2, R.id.toggle_3, R.id.toggle_4, R.id.toggle_5, R.id.toggle_6}; private static final int[] mToggleIcons = new int[]{ R.id.toggle_1_icon, R.id.toggle_2_icon, R.id.toggle_3_icon, R.id.toggle_4_icon, R.id.toggle_5_icon, R.id.toggle_6_icon}; private static final int[] mToggleLabels = new int[]{ R.id.toggle_1_label, R.id.toggle_2_label, R.id.toggle_3_label, R.id.toggle_4_label, R.id.toggle_5_label, R.id.toggle_6_label}; private static final int[] mToggleCheckBoxes = new int[]{ R.id.toggle_1_checkbox, R.id.toggle_2_checkbox, R.id.toggle_3_checkbox, R.id.toggle_4_checkbox, R.id.toggle_5_checkbox, R.id.toggle_6_checkbox}; private static final String[] KEY_TOGGLES = new String[]{"pref_airplane_toggle", "pref_rotate_toggle", "pref_bluetooth_toggle", "pref_gps_toggle", "pref_wifi_toggle", "pref_flashlight_toggle", "pref_mobile_data_toggle", "pref_network_mode_toggle", "pref_sound_toggle"}; private static final String BUTTON_DELIMITER = "\\|"; Loading @@ -91,7 +83,6 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { SoundController mSound; WifiController mWifi; View mRotationLockContainer; View mRotationLockSeparator; private Context mContext; private Handler mHandler; Loading Loading @@ -120,6 +111,13 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { } } private class ButtonTag { public int toggleId; public ButtonTag(int id) { toggleId = id; } } public SettingsView(Context context, AttributeSet attrs) { this(context, attrs, 0); } Loading @@ -138,8 +136,6 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { final Context context = getContext(); mRotationLockSeparator = findViewById(R.id.rotate_separator); mBrightness = new BrightnessController(context, (ToggleSlider)findViewById(R.id.brightness)); mDoNotDisturb = new DoNotDisturbController(context, Loading @@ -147,36 +143,45 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { if(mToggleContainer == null) mToggleContainer = BUTTONS_DEFAULT; if(!mToggleContainer.equals(NO_TOGGLES)){ if(!mToggleContainer.equals(NO_TOGGLES)) updateToggles(); int mLastVisible = mToggles.length; for(int i=0; i<mToggleIds.length; i++){ if(i<mLastVisible) findViewById(mToggleIds[i]).setOnClickListener(this); else findViewById(mToggleIds[i]).setVisibility(View.GONE); } } else { for(int i=0; i<mToggleIds.length; i++){ findViewById(mToggleIds[i]).setVisibility(View.GONE); } } findViewById(R.id.settings).setOnClickListener(this); } private void clearToggles() { for (int i = getChildCount() - 1; i >= 0; i--) { View v = getChildAt(i); if (v.getTag() instanceof ButtonTag) removeView(v); } } private void updateToggles(){ clearToggleControllers(); clearToggles(); mToggles = mToggleContainer.split("\\|"); for(int i=0; i<mToggles.length; i++){ for(int i=mToggles.length - 1; i>=0; i--){ String mToggleName = mToggles[i].replace("\\", ""); int[] resources = getResourcesById(mToggleName); setToggleResources(mToggleIds[i], mToggleIcons[i], mToggleLabels[i], resources[0], resources[1]); TOGGLE_ID_ARRAY[i] = resources[2]; setToggleController(mToggleName, i); addToggle(resources, mToggleName); } } private void addToggle(final int[] res, String name) { LinearLayout toggle = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.status_bar_settings_button, this, false); addView(toggle,0); ImageView icon = (ImageView)toggle.getChildAt(0); icon.setImageResource(res[0]); TextView label = (TextView)toggle.getChildAt(1); label.setText(res[1]); Switch checkbox = (Switch)toggle.getChildAt(2); toggle.setTag(new ButtonTag(res[2])); toggle.setOnClickListener(this); setToggleController(name, (CompoundButton)checkbox, toggle); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); Loading @@ -191,36 +196,45 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { mDoNotDisturb.release(); } private void setToggleController(String id, int i){ int checkBox = mToggleCheckBoxes[i]; private void clearToggleControllers() { mAirplane = null; mRotate = null; mBluetooth = null; mFlashLight = null; mGps = null; mMobileData = null; mNetworkMode = null; mSound = null; mWifi = null; } private void setToggleController(String id, CompoundButton checkbox, LinearLayout toggle) { if(id.equals(KEY_TOGGLES[0])) mAirplane = new AirplaneModeController(mContext, (CompoundButton)findViewById(checkBox)); mAirplane = new AirplaneModeController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[1])){ mRotationLockContainer = findViewById(mToggleIds[i]); mRotate = new AutoRotateController(mContext, (CompoundButton)findViewById(checkBox), mRotationLockContainer = toggle; mRotate = new AutoRotateController(mContext, checkbox, new AutoRotateController.RotationLockCallbacks() { @Override public void setRotationLockControlVisibility(boolean show) { mRotationLockContainer.setVisibility(show ? View.VISIBLE : View.GONE); mRotationLockSeparator.setVisibility(show ? View.VISIBLE : View.GONE); } }); } else if(id.equals(KEY_TOGGLES[2])) mBluetooth = new BluetoothController(mContext, (CompoundButton)findViewById(checkBox)); mBluetooth = new BluetoothController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[3])) mGps = new LocationController(mContext, (CompoundButton)findViewById(checkBox)); mGps = new LocationController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[4])) mWifi = new WifiController(mContext, (CompoundButton)findViewById(checkBox)); mWifi = new WifiController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[5])) mFlashLight = new FlashlightController(mContext, (CompoundButton)findViewById(checkBox)); mFlashLight = new FlashlightController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[6])) mMobileData = new MobileDataController(mContext, (CompoundButton)findViewById(checkBox)); mMobileData = new MobileDataController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[7])) mNetworkMode = new NetworkModeController(mContext, (CompoundButton)findViewById(checkBox)); mNetworkMode = new NetworkModeController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[8])) mSound = new SoundController(mContext, (CompoundButton)findViewById(checkBox)); mSound = new SoundController(mContext, checkbox); } private int[] getResourcesById(String id){ Loading @@ -246,41 +260,17 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { return new int[]{0, 0}; } private void setToggleResources(int resourceId, int resourceIcon, int resourceLabel, int newResourceIcon, int newResourceLabel){ LinearLayout mToggle = (LinearLayout) findViewById(resourceId); ImageView mToggleImageView = (ImageView) mToggle.findViewById(resourceIcon); mToggleImageView.setImageResource(newResourceIcon); TextView mToggleTextView = (TextView) mToggle.findViewById(resourceLabel); mToggleTextView.setText(newResourceLabel); } private StatusBarManager getStatusBarManager() { return (StatusBarManager)getContext().getSystemService(Context.STATUS_BAR_SERVICE); } public void onClick(View v) { switch (v.getId()) { case R.id.toggle_1: onClickToggle(TOGGLE_ID_ARRAY[0]); break; case R.id.toggle_2: onClickToggle(TOGGLE_ID_ARRAY[1]); break; case R.id.toggle_3: onClickToggle(TOGGLE_ID_ARRAY[2]); break; case R.id.toggle_4: onClickToggle(TOGGLE_ID_ARRAY[3]); break; case R.id.toggle_5: onClickToggle(TOGGLE_ID_ARRAY[4]); break; case R.id.toggle_6: onClickToggle(TOGGLE_ID_ARRAY[5]); break; case R.id.settings: if (v.getId() == R.id.settings) { onClickSettings(); break; } else { Object tag = v.getTag(); if (tag instanceof ButtonTag) onClickToggle(((ButtonTag) tag).toggleId); } } Loading Loading
packages/SystemUI/res/layout-sw720dp/status_bar_settings_button.xml 0 → 100644 +15 −0 Original line number Diff line number Diff line <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/StatusBarPanelSettingsRow"> <ImageView style="@style/StatusBarPanelSettingsIcon"/> <TextView style="@style/StatusBarPanelSettingsContents"/> <Switch android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp"/> </LinearLayout>
packages/SystemUI/res/layout/system_bar_settings_view.xml +2 −152 Original line number Diff line number Diff line Loading @@ -18,168 +18,18 @@ <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui" android:layout_height="match_parent" android:layout_width="match_parent"> <com.android.systemui.statusbar.tablet.SettingsView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <!-- Toggle 1 --> <LinearLayout android:id="@+id/toggle_1" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_1_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/ic_sysbar_airplane_on" /> <TextView android:id="@+id/toggle_1_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_airplane" /> <Switch android:id="@+id/toggle_1_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View android:id="@+id/rotate_separator" style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Toggle 2 --> <LinearLayout android:id="@+id/toggle_2" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_2_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/ic_sysbar_wifi_on" /> <TextView android:id="@+id/toggle_2_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_wifi_button" /> <Switch android:id="@+id/toggle_2_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Toggle 3 --> <LinearLayout android:id="@+id/toggle_3" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_3_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/stat_sys_data_bluetooth" /> <TextView android:id="@+id/toggle_3_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_bluetooth_button" /> <Switch android:id="@+id/toggle_3_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Toggle 4 --> <LinearLayout android:id="@+id/toggle_4" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_4_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/ic_sysbar_rotate_on" /> <TextView android:id="@+id/toggle_4_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_auto_rotation" /> <Switch android:id="@+id/toggle_4_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Toggle 5 --> <LinearLayout android:id="@+id/toggle_5" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_5_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/stat_gps_on" /> <TextView android:id="@+id/toggle_5_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_location" /> <Switch android:id="@+id/toggle_5_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Power widget buttons will be added here --> <!-- Toggle 6 --> <LinearLayout android:id="@+id/toggle_6" style="@style/StatusBarPanelSettingsRow" > <ImageView android:id="@+id/toggle_6_icon" style="@style/StatusBarPanelSettingsIcon" android:src="@drawable/stat_flashlight_on" /> <TextView android:id="@+id/toggle_6_label" style="@style/StatusBarPanelSettingsContents" android:text="@string/status_bar_settings_flashlight" /> <Switch android:id="@+id/toggle_6_checkbox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginRight="5dp" /> </LinearLayout> <View style="@style/StatusBarPanelSettingsPanelSeparator" /> <!-- Brightness --> Loading
packages/SystemUI/res/values/styles.xml +23 −0 Original line number Diff line number Diff line Loading @@ -108,4 +108,27 @@ <item name="android:textSize">14dp</item> </style> <style name="StatusBarPanelSettingsIcon"> <item name="android:layout_height">match_parent</item> <item name="android:layout_width">64dp</item> <item name="android:scaleType">center</item> </style> <style name="StatusBarPanelSettingsRow"> <item name="android:paddingRight">16dp</item> <item name="android:layout_height">64dp</item> <item name="android:layout_width">match_parent</item> <item name="android:orientation">horizontal</item> <item name="android:background">?android:attr/listChoiceBackgroundIndicator</item> </style> <style name="StatusBarPanelSettingsContents"> <item name="android:layout_height">wrap_content</item> <item name="android:layout_width">0dp</item> <item name="android:layout_weight">1</item> <item name="android:layout_gravity">left|center_vertical</item> <item name="android:textColor">?android:attr/textColorPrimary</item> <item name="android:textSize">18sp</item> </style> </resources>
packages/SystemUI/src/com/android/systemui/statusbar/policy/WifiController.java 0 → 100644 +160 −0 Original line number Diff line number Diff line /* * 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.systemui.statusbar.policy; import android.content.BroadcastReceiver; import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.AsyncTask; import android.os.RemoteException; import android.os.ServiceManager; import android.provider.Settings; import android.util.Slog; import android.widget.CompoundButton; import android.net.NetworkInfo; import android.net.wifi.SupplicantState; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import java.util.concurrent.atomic.AtomicBoolean; public class WifiController extends BroadcastReceiver implements CompoundButton.OnCheckedChangeListener { private static final String TAG = "StatusBar.WifiController"; private Context mContext; private CompoundButton mCheckBox; private boolean mStateMachineEvent; private final WifiManager mWifiManager; private AtomicBoolean mConnected = new AtomicBoolean(false); private boolean mWifi; public WifiController(Context context, CompoundButton checkbox) { mContext = context; mWifi = getWifi(); mCheckBox = checkbox; checkbox.setChecked(mWifi); checkbox.setOnCheckedChangeListener(this); mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); IntentFilter filter = new IntentFilter(); filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION); filter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION); context.registerReceiver(this, filter); } public void release() { mContext.unregisterReceiver(this); } public void onCheckedChanged(CompoundButton view, boolean checked) { //Do nothing if called as a result of a state machine event if (mStateMachineEvent) { return; } // Show toast message if Wi-Fi is not allowed in airplane mode // Disable tethering if enabling Wifi int wifiApState = mWifiManager.getWifiApState(); if (mCheckBox.isChecked() && ((wifiApState == WifiManager.WIFI_AP_STATE_ENABLING) || (wifiApState == WifiManager.WIFI_AP_STATE_ENABLED))) { mWifiManager.setWifiApEnabled(null, false); } if (mWifiManager.setWifiEnabled(mCheckBox.isChecked())) { // Intent has been taken into account, disable until new state is active mCheckBox.setChecked(false); } } public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action)) { handleWifiStateChanged(intent.getIntExtra( WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN)); } else if (WifiManager.SUPPLICANT_STATE_CHANGED_ACTION.equals(action)) { if (!mConnected.get()) { handleStateChanged(WifiInfo.getDetailedStateOf((SupplicantState) intent.getParcelableExtra(WifiManager.EXTRA_NEW_STATE))); } } else if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { NetworkInfo info = (NetworkInfo) intent.getParcelableExtra( WifiManager.EXTRA_NETWORK_INFO); mConnected.set(info.isConnected()); handleStateChanged(info.getDetailedState()); } } private void handleStateChanged(@SuppressWarnings("unused") NetworkInfo.DetailedState state) { } private void handleWifiStateChanged(int state) { switch (state) { case WifiManager.WIFI_STATE_ENABLING: mCheckBox.setEnabled(false); break; case WifiManager.WIFI_STATE_ENABLED: setSwitchChecked(true); mCheckBox.setEnabled(true); break; case WifiManager.WIFI_STATE_DISABLING: mCheckBox.setEnabled(false); break; case WifiManager.WIFI_STATE_DISABLED: setSwitchChecked(false); mCheckBox.setEnabled(true); break; default: setSwitchChecked(false); mCheckBox.setEnabled(true); break; } } private void setSwitchChecked(boolean checked) { if (checked != mCheckBox.isChecked()) { mStateMachineEvent = true; mCheckBox.setChecked(checked); mStateMachineEvent = false; } } private boolean getWifi() { ContentResolver cr = mContext.getContentResolver(); return 0 != Settings.System.getInt(cr, Settings.System.AIRPLANE_MODE_ON, 0); } // TODO: Fix this racy API by adding something better to TelephonyManager or // ConnectivityService. private void unsafe(final boolean enabled) { AsyncTask.execute(new Runnable() { public void run() { Settings.System.putInt( mContext.getContentResolver(), Settings.System.AIRPLANE_MODE_ON, enabled ? 1 : 0); Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED); intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING); intent.putExtra("state", enabled); mContext.sendBroadcast(intent); } }); } }
packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsView.java +69 −79 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ import android.widget.LinearLayout; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.TextView; import android.widget.Switch; import android.view.LayoutInflater; import com.android.systemui.R; import com.android.systemui.statusbar.policy.AirplaneModeController; Loading @@ -51,7 +53,6 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { static final String TAG = "SettingsView"; private static final String NO_TOGGLES = "no_toggles"; private static final int[] TOGGLE_ID_ARRAY = new int[6]; private static final int AIRPLANE_ID = 0; private static final int ROTATE_ID = 1; private static final int BLUETOOTH_ID = 2; Loading @@ -62,15 +63,6 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { private static final int NETWORK_MODE_ID = 7; private static final int SOUND_ID = 8; private static final int[] mToggleIds = new int[]{ R.id.toggle_1, R.id.toggle_2, R.id.toggle_3, R.id.toggle_4, R.id.toggle_5, R.id.toggle_6}; private static final int[] mToggleIcons = new int[]{ R.id.toggle_1_icon, R.id.toggle_2_icon, R.id.toggle_3_icon, R.id.toggle_4_icon, R.id.toggle_5_icon, R.id.toggle_6_icon}; private static final int[] mToggleLabels = new int[]{ R.id.toggle_1_label, R.id.toggle_2_label, R.id.toggle_3_label, R.id.toggle_4_label, R.id.toggle_5_label, R.id.toggle_6_label}; private static final int[] mToggleCheckBoxes = new int[]{ R.id.toggle_1_checkbox, R.id.toggle_2_checkbox, R.id.toggle_3_checkbox, R.id.toggle_4_checkbox, R.id.toggle_5_checkbox, R.id.toggle_6_checkbox}; private static final String[] KEY_TOGGLES = new String[]{"pref_airplane_toggle", "pref_rotate_toggle", "pref_bluetooth_toggle", "pref_gps_toggle", "pref_wifi_toggle", "pref_flashlight_toggle", "pref_mobile_data_toggle", "pref_network_mode_toggle", "pref_sound_toggle"}; private static final String BUTTON_DELIMITER = "\\|"; Loading @@ -91,7 +83,6 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { SoundController mSound; WifiController mWifi; View mRotationLockContainer; View mRotationLockSeparator; private Context mContext; private Handler mHandler; Loading Loading @@ -120,6 +111,13 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { } } private class ButtonTag { public int toggleId; public ButtonTag(int id) { toggleId = id; } } public SettingsView(Context context, AttributeSet attrs) { this(context, attrs, 0); } Loading @@ -138,8 +136,6 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { final Context context = getContext(); mRotationLockSeparator = findViewById(R.id.rotate_separator); mBrightness = new BrightnessController(context, (ToggleSlider)findViewById(R.id.brightness)); mDoNotDisturb = new DoNotDisturbController(context, Loading @@ -147,36 +143,45 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { if(mToggleContainer == null) mToggleContainer = BUTTONS_DEFAULT; if(!mToggleContainer.equals(NO_TOGGLES)){ if(!mToggleContainer.equals(NO_TOGGLES)) updateToggles(); int mLastVisible = mToggles.length; for(int i=0; i<mToggleIds.length; i++){ if(i<mLastVisible) findViewById(mToggleIds[i]).setOnClickListener(this); else findViewById(mToggleIds[i]).setVisibility(View.GONE); } } else { for(int i=0; i<mToggleIds.length; i++){ findViewById(mToggleIds[i]).setVisibility(View.GONE); } } findViewById(R.id.settings).setOnClickListener(this); } private void clearToggles() { for (int i = getChildCount() - 1; i >= 0; i--) { View v = getChildAt(i); if (v.getTag() instanceof ButtonTag) removeView(v); } } private void updateToggles(){ clearToggleControllers(); clearToggles(); mToggles = mToggleContainer.split("\\|"); for(int i=0; i<mToggles.length; i++){ for(int i=mToggles.length - 1; i>=0; i--){ String mToggleName = mToggles[i].replace("\\", ""); int[] resources = getResourcesById(mToggleName); setToggleResources(mToggleIds[i], mToggleIcons[i], mToggleLabels[i], resources[0], resources[1]); TOGGLE_ID_ARRAY[i] = resources[2]; setToggleController(mToggleName, i); addToggle(resources, mToggleName); } } private void addToggle(final int[] res, String name) { LinearLayout toggle = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.status_bar_settings_button, this, false); addView(toggle,0); ImageView icon = (ImageView)toggle.getChildAt(0); icon.setImageResource(res[0]); TextView label = (TextView)toggle.getChildAt(1); label.setText(res[1]); Switch checkbox = (Switch)toggle.getChildAt(2); toggle.setTag(new ButtonTag(res[2])); toggle.setOnClickListener(this); setToggleController(name, (CompoundButton)checkbox, toggle); } @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); Loading @@ -191,36 +196,45 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { mDoNotDisturb.release(); } private void setToggleController(String id, int i){ int checkBox = mToggleCheckBoxes[i]; private void clearToggleControllers() { mAirplane = null; mRotate = null; mBluetooth = null; mFlashLight = null; mGps = null; mMobileData = null; mNetworkMode = null; mSound = null; mWifi = null; } private void setToggleController(String id, CompoundButton checkbox, LinearLayout toggle) { if(id.equals(KEY_TOGGLES[0])) mAirplane = new AirplaneModeController(mContext, (CompoundButton)findViewById(checkBox)); mAirplane = new AirplaneModeController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[1])){ mRotationLockContainer = findViewById(mToggleIds[i]); mRotate = new AutoRotateController(mContext, (CompoundButton)findViewById(checkBox), mRotationLockContainer = toggle; mRotate = new AutoRotateController(mContext, checkbox, new AutoRotateController.RotationLockCallbacks() { @Override public void setRotationLockControlVisibility(boolean show) { mRotationLockContainer.setVisibility(show ? View.VISIBLE : View.GONE); mRotationLockSeparator.setVisibility(show ? View.VISIBLE : View.GONE); } }); } else if(id.equals(KEY_TOGGLES[2])) mBluetooth = new BluetoothController(mContext, (CompoundButton)findViewById(checkBox)); mBluetooth = new BluetoothController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[3])) mGps = new LocationController(mContext, (CompoundButton)findViewById(checkBox)); mGps = new LocationController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[4])) mWifi = new WifiController(mContext, (CompoundButton)findViewById(checkBox)); mWifi = new WifiController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[5])) mFlashLight = new FlashlightController(mContext, (CompoundButton)findViewById(checkBox)); mFlashLight = new FlashlightController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[6])) mMobileData = new MobileDataController(mContext, (CompoundButton)findViewById(checkBox)); mMobileData = new MobileDataController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[7])) mNetworkMode = new NetworkModeController(mContext, (CompoundButton)findViewById(checkBox)); mNetworkMode = new NetworkModeController(mContext, checkbox); else if(id.equals(KEY_TOGGLES[8])) mSound = new SoundController(mContext, (CompoundButton)findViewById(checkBox)); mSound = new SoundController(mContext, checkbox); } private int[] getResourcesById(String id){ Loading @@ -246,41 +260,17 @@ public class SettingsView extends LinearLayout implements View.OnClickListener { return new int[]{0, 0}; } private void setToggleResources(int resourceId, int resourceIcon, int resourceLabel, int newResourceIcon, int newResourceLabel){ LinearLayout mToggle = (LinearLayout) findViewById(resourceId); ImageView mToggleImageView = (ImageView) mToggle.findViewById(resourceIcon); mToggleImageView.setImageResource(newResourceIcon); TextView mToggleTextView = (TextView) mToggle.findViewById(resourceLabel); mToggleTextView.setText(newResourceLabel); } private StatusBarManager getStatusBarManager() { return (StatusBarManager)getContext().getSystemService(Context.STATUS_BAR_SERVICE); } public void onClick(View v) { switch (v.getId()) { case R.id.toggle_1: onClickToggle(TOGGLE_ID_ARRAY[0]); break; case R.id.toggle_2: onClickToggle(TOGGLE_ID_ARRAY[1]); break; case R.id.toggle_3: onClickToggle(TOGGLE_ID_ARRAY[2]); break; case R.id.toggle_4: onClickToggle(TOGGLE_ID_ARRAY[3]); break; case R.id.toggle_5: onClickToggle(TOGGLE_ID_ARRAY[4]); break; case R.id.toggle_6: onClickToggle(TOGGLE_ID_ARRAY[5]); break; case R.id.settings: if (v.getId() == R.id.settings) { onClickSettings(); break; } else { Object tag = v.getTag(); if (tag instanceof ButtonTag) onClickToggle(((ButtonTag) tag).toggleId); } } Loading