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 17package com.android.systemui.statusbar.tablet; 18 19import android.app.StatusBarManager; 20import android.content.Context; 21import android.content.Intent; 22import android.provider.Settings; 23import android.util.AttributeSet; 24import android.util.Slog; 25import android.widget.LinearLayout; 26import android.view.View; 27import android.widget.CompoundButton; 28import android.widget.ImageView; 29import android.widget.TextView; 30 31import com.android.systemui.R; 32import com.android.systemui.statusbar.policy.AirplaneModeController; 33import com.android.systemui.statusbar.policy.AutoRotateController; 34import com.android.systemui.statusbar.policy.BrightnessController; 35import com.android.systemui.statusbar.policy.DoNotDisturbController; 36import com.android.systemui.statusbar.policy.ToggleSlider; 37import com.android.systemui.statusbar.policy.VolumeController; 38 39public class SettingsView extends LinearLayout implements View.OnClickListener { 40 static final String TAG = "SettingsView"; 41 42 AirplaneModeController mAirplane; 43 AutoRotateController mRotate; 44 BrightnessController mBrightness; 45 DoNotDisturbController mDoNotDisturb; 46 47 public SettingsView(Context context, AttributeSet attrs) { 48 this(context, attrs, 0); 49 } 50 51 public SettingsView(Context context, AttributeSet attrs, int defStyle) { 52 super(context, attrs, defStyle); 53 } 54 55 @Override 56 protected void onFinishInflate() { 57 super.onFinishInflate(); 58 59 final Context context = getContext(); 60 61 mAirplane = new AirplaneModeController(context, 62 (CompoundButton)findViewById(R.id.airplane_checkbox)); 63 findViewById(R.id.network).setOnClickListener(this); 64 mRotate = new AutoRotateController(context, 65 (CompoundButton)findViewById(R.id.rotate_checkbox)); 66 mBrightness = new BrightnessController(context, 67 (ToggleSlider)findViewById(R.id.brightness)); 68 mDoNotDisturb = new DoNotDisturbController(context, 69 (CompoundButton)findViewById(R.id.do_not_disturb_checkbox)); 70 findViewById(R.id.settings).setOnClickListener(this); 71 } 72 73 @Override 74 protected void onDetachedFromWindow() { 75 super.onDetachedFromWindow(); 76 mAirplane.release(); 77 mDoNotDisturb.release(); 78 } 79 80 public void onClick(View v) { 81 switch (v.getId()) { 82 case R.id.network: 83 onClickNetwork(); 84 break; 85 case R.id.settings: 86 onClickSettings(); 87 break; 88 } 89 } 90 91 private StatusBarManager getStatusBarManager() { 92 return (StatusBarManager)getContext().getSystemService(Context.STATUS_BAR_SERVICE); 93 } 94 95 // Network 96 // ---------------------------- 97 private void onClickNetwork() { 98 getContext().startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS) 99 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); 100 getStatusBarManager().collapse(); 101 } 102 103 // Settings 104 // ---------------------------- 105 private void onClickSettings() { 106 getContext().startActivity(new Intent(Settings.ACTION_SETTINGS) 107 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); 108 getStatusBarManager().collapse(); 109 } 110} 111 112