/services/java/com/android/server/am/CompatModeDialog.java

https://github.com/aizuzi/platform_frameworks_base · Java · 90 lines · 67 code · 8 blank · 15 comment · 1 complexity · 352bf40e733cfe94455237fccaf401dc MD5 · raw file

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