diff options
author | Joe Onorato <joeo@google.com> | 2010-11-26 13:19:58 -0800 |
---|---|---|
committer | Joe Onorato <joeo@google.com> | 2010-11-26 13:19:58 -0800 |
commit | a8e34189073c8f29f8e95db488b9a2a81019721e (patch) | |
tree | 553b77200560530071e8870d6c787a9ecf860478 /packages/SystemUI/src | |
parent | 7750c2ac61d933cdb50114c2fc2e0a0c558a140e (diff) | |
download | frameworks_base-a8e34189073c8f29f8e95db488b9a2a81019721e.zip frameworks_base-a8e34189073c8f29f8e95db488b9a2a81019721e.tar.gz frameworks_base-a8e34189073c8f29f8e95db488b9a2a81019721e.tar.bz2 |
Start filling in the system settings panel.
Change-Id: I3384bb1cf6c2339d6136764635bb010ba096659b
Diffstat (limited to 'packages/SystemUI/src')
3 files changed, 227 insertions, 1 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/AirplaneModeController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/AirplaneModeController.java new file mode 100644 index 0000000..da60f0d --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/AirplaneModeController.java @@ -0,0 +1,92 @@ +/* + * 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.RemoteException; +import android.os.ServiceManager; +import android.provider.Settings; +import android.util.Slog; +import android.widget.CompoundButton; + +public class AirplaneModeController extends BroadcastReceiver + implements CompoundButton.OnCheckedChangeListener { + private static final String TAG = "StatusBar.AirplaneModeController"; + + private Context mContext; + private CompoundButton mCheckBox; + + private boolean mAirplaneMode; + + public AirplaneModeController(Context context, CompoundButton checkbox) { + mContext = context; + mAirplaneMode = getAirplaneMode(); + mCheckBox = checkbox; + checkbox.setChecked(mAirplaneMode); + checkbox.setOnCheckedChangeListener(this); + + IntentFilter filter = new IntentFilter(); + filter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED); + context.registerReceiver(this, filter); + + } + + public void release() { + mContext.unregisterReceiver(this); + } + + public void onCheckedChanged(CompoundButton view, boolean checked) { + Slog.d(TAG, "onCheckedChanged checked=" + checked + " mAirplaneMode=" + mAirplaneMode); + if (checked != mAirplaneMode) { + mAirplaneMode = checked; + unsafe(checked); + } + } + + public void onReceive(Context context, Intent intent) { + if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) { + final boolean enabled = intent.getBooleanExtra("state", false); + if (enabled != mAirplaneMode) { + mAirplaneMode = enabled; + mCheckBox.setChecked(enabled); + } + } + } + + private boolean getAirplaneMode() { + 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(boolean enabled) { + 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); + } +} + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/AutoRotateController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/AutoRotateController.java new file mode 100644 index 0000000..866e5fc --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/AutoRotateController.java @@ -0,0 +1,73 @@ +/* + * 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.ContentResolver; +import android.content.Context; +import android.os.RemoteException; +import android.os.ServiceManager; +import android.provider.Settings; +import android.util.Slog; +import android.view.IWindowManager; +import android.widget.CompoundButton; + +/** + * TODO: Listen for changes to the setting. + */ +public class AutoRotateController implements CompoundButton.OnCheckedChangeListener { + private static final String TAG = "StatusBar.AutoRotateController"; + + private Context mContext; + private CompoundButton mCheckBox; + + private boolean mLockRotation; + + public AutoRotateController(Context context, CompoundButton checkbox) { + mContext = context; + mLockRotation = getLockRotation(); + mCheckBox = checkbox; + checkbox.setChecked(mLockRotation); + checkbox.setOnCheckedChangeListener(this); + } + + public void onCheckedChanged(CompoundButton view, boolean checked) { + Slog.d(TAG, "onCheckedChanged checked=" + checked + " mLockRotation=" + mLockRotation); + if (checked != mLockRotation) { + setLockRotation(checked); + } + } + + private boolean getLockRotation() { + ContentResolver cr = mContext.getContentResolver(); + return 0 == Settings.System.getInt(cr, Settings.System.ACCELEROMETER_ROTATION, 0); + } + + private void setLockRotation(boolean locked) { + mLockRotation = locked; + try { + IWindowManager wm = IWindowManager.Stub.asInterface(ServiceManager.getService( + Context.WINDOW_SERVICE)); + ContentResolver cr = mContext.getContentResolver(); + if (locked) { + wm.freezeRotation(); + } else { + wm.thawRotation(); + } + } catch (RemoteException exc) { + } + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsPanel.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsPanel.java index 9013f5c..fea326e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsPanel.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/SettingsPanel.java @@ -16,17 +16,28 @@ package com.android.systemui.statusbar.tablet; +import android.app.StatusBarManager; import android.content.Context; +import android.content.Intent; +import android.provider.Settings; import android.util.AttributeSet; import android.util.Slog; import android.widget.LinearLayout; import android.view.View; +import android.widget.CompoundButton; +import android.widget.ImageView; +import android.widget.TextView; import com.android.systemui.R; +import com.android.systemui.statusbar.policy.AirplaneModeController; +import com.android.systemui.statusbar.policy.AutoRotateController; -public class SettingsPanel extends LinearLayout { +public class SettingsPanel extends LinearLayout implements View.OnClickListener { static final String TAG = "SettingsPanel"; + AirplaneModeController mAirplane; + AutoRotateController mRotate; + public SettingsPanel(Context context, AttributeSet attrs) { this(context, attrs, 0); } @@ -34,5 +45,55 @@ public class SettingsPanel extends LinearLayout { public SettingsPanel(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + + final Context context = getContext(); + + mAirplane = new AirplaneModeController(context, + (CompoundButton)findViewById(R.id.airplane_checkbox)); + findViewById(R.id.network).setOnClickListener(this); + mRotate = new AutoRotateController(context, + (CompoundButton)findViewById(R.id.rotate_checkbox)); + findViewById(R.id.settings).setOnClickListener(this); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + mAirplane.release(); + } + + public void onClick(View v) { + switch (v.getId()) { + case R.id.network: + onClickNetwork(); + break; + case R.id.settings: + onClickSettings(); + break; + } + } + + private StatusBarManager getStatusBarManager() { + return (StatusBarManager)getContext().getSystemService(Context.STATUS_BAR_SERVICE); + } + + // Network + // ---------------------------- + private void onClickNetwork() { + Slog.d(TAG, "onClickNetwork"); + } + + // Settings + // ---------------------------- + private void onClickSettings() { + Slog.d(TAG, "onClickSettings"); + getContext().startActivity(new Intent(Settings.ACTION_SETTINGS) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + getStatusBarManager().collapse(); + } } |