1 /* 2 * Copyright (C) 2019 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.car.settings.applications.managedomainurls; 18 19 import android.car.drivingstate.CarUxRestrictions; 20 import android.content.Context; 21 import android.util.ArraySet; 22 23 import androidx.preference.Preference; 24 25 import com.android.car.settings.R; 26 import com.android.car.settings.common.ConfirmationDialogFragment; 27 import com.android.car.settings.common.FragmentController; 28 29 /** Business logic to generate and see the list of supported domain urls. */ 30 public class DomainUrlsPreferenceController extends 31 AppLaunchSettingsBasePreferenceController<Preference> { 32 33 private ArraySet<String> mDomains; 34 DomainUrlsPreferenceController(Context context, String preferenceKey, FragmentController fragmentController, CarUxRestrictions uxRestrictions)35 public DomainUrlsPreferenceController(Context context, String preferenceKey, 36 FragmentController fragmentController, CarUxRestrictions uxRestrictions) { 37 super(context, preferenceKey, fragmentController, uxRestrictions); 38 } 39 40 @Override getPreferenceType()41 protected Class<Preference> getPreferenceType() { 42 return Preference.class; 43 } 44 45 @Override onCreateInternal()46 protected void onCreateInternal() { 47 mDomains = DomainUrlsUtils.getHandledDomains(getContext().getPackageManager(), 48 getPackageName()); 49 } 50 51 @Override updateState(Preference preference)52 protected void updateState(Preference preference) { 53 preference.setEnabled(!isBrowserApp()); 54 preference.setSummary( 55 DomainUrlsUtils.getDomainsSummary(getContext(), getPackageName(), 56 getCurrentUserId(), mDomains)); 57 } 58 59 @Override handlePreferenceClicked(Preference preference)60 protected boolean handlePreferenceClicked(Preference preference) { 61 String newLines = System.lineSeparator() + System.lineSeparator(); 62 String message = String.join(newLines, mDomains); 63 64 // Not exactly a "confirmation" dialog, but reusing to remove the need for a custom 65 // dialog fragment. 66 ConfirmationDialogFragment dialogFragment = new ConfirmationDialogFragment.Builder( 67 getContext()) 68 .setTitle(R.string.app_launch_supported_domain_urls_title) 69 .setMessage(message) 70 .setNegativeButton(android.R.string.cancel, /* rejectListener= */ null) 71 .build(); 72 getFragmentController().showDialog(dialogFragment, ConfirmationDialogFragment.TAG); 73 return true; 74 } 75 } 76