Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.tablet; |
| 18 | |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 19 | import android.app.StatusBarManager; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 20 | import android.content.Context; |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 21 | import android.content.Intent; |
Dianne Hackborn | f02b60a | 2012-08-16 10:48:27 -0700 | [diff] [blame] | 22 | import android.os.UserHandle; |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 23 | import android.provider.Settings; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 24 | import android.util.AttributeSet; |
| 25 | import android.util.Slog; |
| 26 | import android.widget.LinearLayout; |
| 27 | import android.view.View; |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 28 | import android.widget.CompoundButton; |
| 29 | import android.widget.ImageView; |
| 30 | import android.widget.TextView; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 31 | |
| 32 | import com.android.systemui.R; |
Michael Wright | 0087a14 | 2013-02-05 16:29:39 -0800 | [diff] [blame] | 33 | import com.android.systemui.settings.BrightnessController; |
| 34 | import com.android.systemui.settings.ToggleSlider; |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 35 | import com.android.systemui.statusbar.policy.AirplaneModeController; |
| 36 | import com.android.systemui.statusbar.policy.AutoRotateController; |
Joe Onorato | 2039e48 | 2010-11-29 14:54:24 -0800 | [diff] [blame] | 37 | import com.android.systemui.statusbar.policy.DoNotDisturbController; |
Joe Onorato | 1e28f41 | 2010-12-01 09:33:36 -0800 | [diff] [blame] | 38 | import com.android.systemui.statusbar.policy.VolumeController; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 39 | |
Joe Onorato | 755cc74 | 2010-11-27 15:45:35 -0800 | [diff] [blame] | 40 | public class SettingsView extends LinearLayout implements View.OnClickListener { |
| 41 | static final String TAG = "SettingsView"; |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 42 | |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 43 | AirplaneModeController mAirplane; |
| 44 | AutoRotateController mRotate; |
Joe Onorato | 1e28f41 | 2010-12-01 09:33:36 -0800 | [diff] [blame] | 45 | BrightnessController mBrightness; |
Joe Onorato | 2039e48 | 2010-11-29 14:54:24 -0800 | [diff] [blame] | 46 | DoNotDisturbController mDoNotDisturb; |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 47 | View mRotationLockContainer; |
| 48 | View mRotationLockSeparator; |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 49 | |
Joe Onorato | 755cc74 | 2010-11-27 15:45:35 -0800 | [diff] [blame] | 50 | public SettingsView(Context context, AttributeSet attrs) { |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 51 | this(context, attrs, 0); |
| 52 | } |
| 53 | |
Joe Onorato | 755cc74 | 2010-11-27 15:45:35 -0800 | [diff] [blame] | 54 | public SettingsView(Context context, AttributeSet attrs, int defStyle) { |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 55 | super(context, attrs, defStyle); |
| 56 | } |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 57 | |
| 58 | @Override |
| 59 | protected void onFinishInflate() { |
| 60 | super.onFinishInflate(); |
| 61 | |
| 62 | final Context context = getContext(); |
| 63 | |
| 64 | mAirplane = new AirplaneModeController(context, |
| 65 | (CompoundButton)findViewById(R.id.airplane_checkbox)); |
| 66 | findViewById(R.id.network).setOnClickListener(this); |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 67 | |
| 68 | mRotationLockContainer = findViewById(R.id.rotate); |
| 69 | mRotationLockSeparator = findViewById(R.id.rotate_separator); |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 70 | mRotate = new AutoRotateController(context, |
Jeff Brown | 207673cd | 2012-06-05 17:47:11 -0700 | [diff] [blame] | 71 | (CompoundButton)findViewById(R.id.rotate_checkbox), |
| 72 | new AutoRotateController.RotationLockCallbacks() { |
| 73 | @Override |
| 74 | public void setRotationLockControlVisibility(boolean show) { |
| 75 | mRotationLockContainer.setVisibility(show ? View.VISIBLE : View.GONE); |
| 76 | mRotationLockSeparator.setVisibility(show ? View.VISIBLE : View.GONE); |
| 77 | } |
| 78 | }); |
| 79 | |
Joe Onorato | 1e28f41 | 2010-12-01 09:33:36 -0800 | [diff] [blame] | 80 | mBrightness = new BrightnessController(context, |
John Spurlock | f5bc42d | 2012-10-12 15:24:36 -0400 | [diff] [blame] | 81 | (ImageView)findViewById(R.id.brightness_icon), |
Joe Onorato | 1e28f41 | 2010-12-01 09:33:36 -0800 | [diff] [blame] | 82 | (ToggleSlider)findViewById(R.id.brightness)); |
Joe Onorato | 2039e48 | 2010-11-29 14:54:24 -0800 | [diff] [blame] | 83 | mDoNotDisturb = new DoNotDisturbController(context, |
| 84 | (CompoundButton)findViewById(R.id.do_not_disturb_checkbox)); |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 85 | findViewById(R.id.settings).setOnClickListener(this); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | protected void onDetachedFromWindow() { |
| 90 | super.onDetachedFromWindow(); |
| 91 | mAirplane.release(); |
Joe Onorato | 2039e48 | 2010-11-29 14:54:24 -0800 | [diff] [blame] | 92 | mDoNotDisturb.release(); |
John Spurlock | 781f0f4 | 2012-05-22 10:12:09 -0400 | [diff] [blame] | 93 | mRotate.release(); |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | public void onClick(View v) { |
| 97 | switch (v.getId()) { |
| 98 | case R.id.network: |
| 99 | onClickNetwork(); |
| 100 | break; |
| 101 | case R.id.settings: |
| 102 | onClickSettings(); |
| 103 | break; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | private StatusBarManager getStatusBarManager() { |
| 108 | return (StatusBarManager)getContext().getSystemService(Context.STATUS_BAR_SERVICE); |
| 109 | } |
| 110 | |
| 111 | // Network |
| 112 | // ---------------------------- |
| 113 | private void onClickNetwork() { |
Joe Onorato | 64eb5d2 | 2010-12-08 15:46:59 -0800 | [diff] [blame] | 114 | getContext().startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS) |
| 115 | .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 116 | getStatusBarManager().collapsePanels(); |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | // Settings |
| 120 | // ---------------------------- |
| 121 | private void onClickSettings() { |
Amith Yamasani | 8264408 | 2012-08-03 13:09:11 -0700 | [diff] [blame] | 122 | getContext().startActivityAsUser(new Intent(Settings.ACTION_SETTINGS) |
Dianne Hackborn | 79af1dd | 2012-08-16 16:42:52 -0700 | [diff] [blame] | 123 | .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), |
| 124 | new UserHandle(UserHandle.USER_CURRENT)); |
Daniel Sandler | 11cf178 | 2012-09-27 14:03:08 -0400 | [diff] [blame] | 125 | getStatusBarManager().collapsePanels(); |
Joe Onorato | a8e3418 | 2010-11-26 13:19:58 -0800 | [diff] [blame] | 126 | } |
Joe Onorato | 8a57671 | 2010-11-15 16:50:34 -0800 | [diff] [blame] | 127 | } |
| 128 | |