blob: 88506632d7c3ab015b4dbf259717fc5459c2bb34 [file] [log] [blame]
Alan Viverette7df9b452016-06-16 12:47:58 -04001/*
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 com.android.internal.R;
20
21import android.app.AlertDialog;
22import android.content.Context;
23import android.content.pm.ApplicationInfo;
24import android.content.pm.PackageManager;
25import android.view.Window;
26import android.view.WindowManager;
27import android.widget.CheckBox;
28
29public class UnsupportedDisplaySizeDialog {
30 private final AlertDialog mDialog;
31 private final String mPackageName;
32
Alan Viveretteb6a25732017-11-21 14:49:24 -050033 public UnsupportedDisplaySizeDialog(final AppWarnings manager, Context context,
Alan Viverette7df9b452016-06-16 12:47:58 -040034 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
Alan Viveretteb6a25732017-11-21 14:49:24 -050057 final CheckBox alwaysShow = mDialog.findViewById(R.id.ask_checkbox);
Alan Viverette7df9b452016-06-16 12:47:58 -040058 alwaysShow.setChecked(true);
Alan Viveretteb6a25732017-11-21 14:49:24 -050059 alwaysShow.setOnCheckedChangeListener((buttonView, isChecked) -> manager.setPackageFlag(
60 mPackageName, AppWarnings.FLAG_HIDE_DISPLAY_SIZE, !isChecked));
Alan Viverette7df9b452016-06-16 12:47:58 -040061 }
62
63 public String getPackageName() {
64 return mPackageName;
65 }
66
67 public void show() {
68 mDialog.show();
69 }
70
71 public void dismiss() {
72 mDialog.dismiss();
73 }
74}