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 17 package com.android.server.am; 18 19 import com.android.internal.R; 20 21 import android.app.AlertDialog; 22 import android.content.Context; 23 import android.content.pm.ApplicationInfo; 24 import android.content.pm.PackageManager; 25 import android.view.Window; 26 import android.view.WindowManager; 27 import android.widget.CheckBox; 28 29 public class UnsupportedDisplaySizeDialog { 30 private final AlertDialog mDialog; 31 private final String mPackageName; 32 33 public UnsupportedDisplaySizeDialog(final ActivityManagerService service, Context context, 34 ApplicationInfo appInfo) { 35 mPackageName = appInfo.packageName; 36 37 final PackageManager pm = context.getPackageManager(); 38 final CharSequence label = appInfo.loadSafeLabel(pm); 39 final CharSequence message = context.getString( 40 R.string.unsupported_display_size_message, label); 41 42 mDialog = new AlertDialog.Builder(context) 43 .setPositiveButton(R.string.ok, null) 44 .setMessage(message) 45 .setView(R.layout.unsupported_display_size_dialog_content) 46 .create(); 47 48 // Ensure the content view is prepared. 49 mDialog.create(); 50 51 final Window window = mDialog.getWindow(); 52 window.setType(WindowManager.LayoutParams.TYPE_PHONE); 53 54 // DO NOT MODIFY. Used by CTS to verify the dialog is displayed. 55 window.getAttributes().setTitle("UnsupportedDisplaySizeDialog"); 56 57 final CheckBox alwaysShow = (CheckBox) mDialog.findViewById(R.id.ask_checkbox); 58 alwaysShow.setChecked(true); 59 alwaysShow.setOnCheckedChangeListener((buttonView, isChecked) -> { 60 synchronized (service) { 61 service.mCompatModePackages.setPackageNotifyUnsupportedZoomLocked( 62 mPackageName, isChecked); 63 } 64 }); 65 } 66 67 public String getPackageName() { 68 return mPackageName; 69 } 70 71 public void show() { 72 mDialog.show(); 73 } 74 75 public void dismiss() { 76 mDialog.dismiss(); 77 } 78 } 79