Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 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 | |
Wale Ogunwale | 5950709 | 2018-10-29 09:00:30 -0700 | [diff] [blame] | 17 | package com.android.server.wm; |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 18 | |
| 19 | import com.android.internal.R; |
| 20 | |
| 21 | import android.app.AlertDialog; |
| 22 | import android.content.Context; |
| 23 | import android.content.pm.ApplicationInfo; |
Philip P. Moltmann | a6f5c70 | 2018-04-23 09:09:16 -0700 | [diff] [blame] | 24 | import android.content.pm.PackageItemInfo; |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 25 | import android.content.pm.PackageManager; |
| 26 | import android.view.Window; |
| 27 | import android.view.WindowManager; |
| 28 | import android.widget.CheckBox; |
| 29 | |
| 30 | public class UnsupportedDisplaySizeDialog { |
| 31 | private final AlertDialog mDialog; |
| 32 | private final String mPackageName; |
| 33 | |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 34 | public UnsupportedDisplaySizeDialog(final AppWarnings manager, Context context, |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 35 | ApplicationInfo appInfo) { |
| 36 | mPackageName = appInfo.packageName; |
| 37 | |
| 38 | final PackageManager pm = context.getPackageManager(); |
Philip P. Moltmann | a6f5c70 | 2018-04-23 09:09:16 -0700 | [diff] [blame] | 39 | final CharSequence label = appInfo.loadSafeLabel(pm, |
| 40 | PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX, |
| 41 | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE |
| 42 | | PackageItemInfo.SAFE_LABEL_FLAG_TRIM); |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 43 | final CharSequence message = context.getString( |
| 44 | R.string.unsupported_display_size_message, label); |
| 45 | |
| 46 | mDialog = new AlertDialog.Builder(context) |
| 47 | .setPositiveButton(R.string.ok, null) |
| 48 | .setMessage(message) |
| 49 | .setView(R.layout.unsupported_display_size_dialog_content) |
| 50 | .create(); |
| 51 | |
| 52 | // Ensure the content view is prepared. |
| 53 | mDialog.create(); |
| 54 | |
| 55 | final Window window = mDialog.getWindow(); |
| 56 | window.setType(WindowManager.LayoutParams.TYPE_PHONE); |
| 57 | |
| 58 | // DO NOT MODIFY. Used by CTS to verify the dialog is displayed. |
| 59 | window.getAttributes().setTitle("UnsupportedDisplaySizeDialog"); |
| 60 | |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 61 | final CheckBox alwaysShow = mDialog.findViewById(R.id.ask_checkbox); |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 62 | alwaysShow.setChecked(true); |
Alan Viverette | b6a2573 | 2017-11-21 14:49:24 -0500 | [diff] [blame] | 63 | alwaysShow.setOnCheckedChangeListener((buttonView, isChecked) -> manager.setPackageFlag( |
| 64 | mPackageName, AppWarnings.FLAG_HIDE_DISPLAY_SIZE, !isChecked)); |
Alan Viverette | 7df9b45 | 2016-06-16 12:47:58 -0400 | [diff] [blame] | 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 | } |