1/* 2 * Copyright (C) 2011 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.server.am; 18 19import android.app.ActivityManager; 20import android.app.Dialog; 21import android.content.Context; 22import android.content.pm.ApplicationInfo; 23import android.view.Gravity; 24import android.view.View; 25import android.view.Window; 26import android.view.WindowManager; 27import android.widget.CheckBox; 28import android.widget.CompoundButton; 29import android.widget.Switch; 30 31public class CompatModeDialog extends Dialog { 32 final ActivityManagerService mService; 33 final ApplicationInfo mAppInfo; 34 35 final Switch mCompatEnabled; 36 final CheckBox mAlwaysShow; 37 final View mHint; 38 39 public CompatModeDialog(ActivityManagerService service, Context context, 40 ApplicationInfo appInfo) { 41 super(context, com.android.internal.R.style.Theme_Holo_Dialog_MinWidth); 42 setCancelable(true); 43 setCanceledOnTouchOutside(true); 44 getWindow().requestFeature(Window.FEATURE_NO_TITLE); 45 getWindow().setType(WindowManager.LayoutParams.TYPE_PHONE); 46 getWindow().setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL); 47 mService = service; 48 mAppInfo = appInfo; 49 50 setContentView(com.android.internal.R.layout.am_compat_mode_dialog); 51 mCompatEnabled = (Switch)findViewById(com.android.internal.R.id.compat_checkbox); 52 mCompatEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 53 @Override 54 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 55 synchronized (mService) { 56 mService.mCompatModePackages.setPackageScreenCompatModeLocked( 57 mAppInfo.packageName, 58 mCompatEnabled.isChecked() ? ActivityManager.COMPAT_MODE_ENABLED 59 : ActivityManager.COMPAT_MODE_DISABLED); 60 updateControls(); 61 } 62 } 63 }); 64 mAlwaysShow = (CheckBox)findViewById(com.android.internal.R.id.ask_checkbox); 65 mAlwaysShow.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 66 @Override 67 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 68 synchronized (mService) { 69 mService.mCompatModePackages.setPackageAskCompatModeLocked( 70 mAppInfo.packageName, mAlwaysShow.isChecked()); 71 updateControls(); 72 } 73 } 74 }); 75 mHint = findViewById(com.android.internal.R.id.reask_hint); 76 77 updateControls(); 78 } 79 80 void updateControls() { 81 synchronized (mService) { 82 int mode = mService.mCompatModePackages.computeCompatModeLocked(mAppInfo); 83 mCompatEnabled.setChecked(mode == ActivityManager.COMPAT_MODE_ENABLED); 84 boolean ask = mService.mCompatModePackages.getPackageAskCompatModeLocked( 85 mAppInfo.packageName); 86 mAlwaysShow.setChecked(ask); 87 mHint.setVisibility(ask ? View.INVISIBLE : View.VISIBLE); 88 } 89 } 90} 91