1 /* 2 * Copyright (C) 2018 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; 18 19 import android.app.Activity; 20 import android.content.ActivityNotFoundException; 21 import android.content.DialogInterface; 22 import android.content.Intent; 23 import android.net.Uri; 24 import android.text.TextUtils; 25 import android.view.LayoutInflater; 26 import android.view.View; 27 import android.view.ViewGroup; 28 import android.widget.TextView; 29 30 import androidx.annotation.VisibleForTesting; 31 import androidx.appcompat.app.AlertDialog; 32 33 import com.android.settingslib.HelpUtils; 34 35 final class ActionDisabledByAppOpsHelper { 36 37 private final ViewGroup mDialogView; 38 private final Activity mActivity; 39 ActionDisabledByAppOpsHelper(Activity activity)40 ActionDisabledByAppOpsHelper(Activity activity) { 41 mActivity = activity; 42 mDialogView = (ViewGroup) LayoutInflater.from(mActivity).inflate( 43 R.layout.support_details_dialog, null); 44 } 45 prepareDialogBuilder()46 public AlertDialog.Builder prepareDialogBuilder() { 47 final String helpUrl = mActivity.getString( 48 R.string.help_url_action_disabled_by_restricted_settings); 49 AlertDialog.Builder builder = new AlertDialog.Builder(mActivity) 50 .setPositiveButton(R.string.okay, null) 51 .setView(mDialogView); 52 if (!TextUtils.isEmpty(helpUrl)) { 53 builder.setNeutralButton(R.string.learn_more, 54 (DialogInterface.OnClickListener) (dialog, which) -> { 55 final Intent intent = HelpUtils.getHelpIntent(mActivity, 56 helpUrl, mActivity.getClass().getName()); 57 if (intent != null) { 58 mActivity.startActivity(intent); 59 } 60 }); 61 } 62 initializeDialogViews(mDialogView); 63 return builder; 64 } 65 updateDialog()66 public void updateDialog() { 67 initializeDialogViews(mDialogView); 68 } 69 initializeDialogViews(View root)70 private void initializeDialogViews(View root) { 71 setSupportTitle(root); 72 setSupportDetails(root); 73 } 74 75 @VisibleForTesting setSupportTitle(View root)76 void setSupportTitle(View root) { 77 final TextView titleView = root.findViewById(R.id.admin_support_dialog_title); 78 if (titleView == null) { 79 return; 80 } 81 titleView.setText(R.string.blocked_by_restricted_settings_title); 82 } 83 setSupportDetails(final View root)84 void setSupportDetails(final View root) { 85 final TextView textView = root.findViewById(R.id.admin_support_msg); 86 textView.setText(R.string.blocked_by_restricted_settings_content); 87 } 88 } 89