1 /*
2  * Copyright (C) 2024 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.settings.development;
18 
19 import android.app.Activity;
20 import android.app.AlertDialog;
21 import android.content.DialogInterface;
22 import android.os.Bundle;
23 import android.text.Html;
24 import android.text.method.LinkMovementMethod;
25 import android.widget.TextView;
26 
27 import androidx.annotation.NonNull;
28 
29 import com.android.settings.R;
30 
31 public class PageAgnosticWarningActivity extends Activity {
32 
33     @Override
onCreate(Bundle bundle)34     protected void onCreate(Bundle bundle) {
35         super.onCreate(bundle);
36 
37         String title =
38                 Enable16kUtils.isUsing16kbPages()
39                         ? getString(R.string.page_agnostic_16k_pages_title)
40                         : getString(R.string.page_agnostic_4k_pages_title);
41 
42         String warningText =
43                 Enable16kUtils.isUsing16kbPages()
44                         ? getString(R.string.page_agnostic_16k_pages_text)
45                         : getString(R.string.page_agnostic_4k_pages_text);
46         showWarningDialog(title, warningText);
47     }
48 
49     // Create warning dialog and make links clickable
showWarningDialog(String title, String warningText)50     private void showWarningDialog(String title, String warningText) {
51 
52         AlertDialog dialog =
53                 new AlertDialog.Builder(this)
54                         .setTitle(title)
55                         .setMessage(Html.fromHtml(warningText, Html.FROM_HTML_MODE_COMPACT))
56                         .setCancelable(false)
57                         .setPositiveButton(
58                                 android.R.string.ok,
59                                 new DialogInterface.OnClickListener() {
60                                     public void onClick(
61                                             @NonNull DialogInterface dialog, int which) {
62                                         dialog.cancel();
63                                         finish();
64                                     }
65                                 })
66                         .create();
67         dialog.show();
68 
69         ((TextView) dialog.findViewById(android.R.id.message))
70                 .setMovementMethod(LinkMovementMethod.getInstance());
71     }
72 }
73