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.permissioncontroller.role.ui.handheld; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.os.Bundle; 22 import android.os.UserHandle; 23 24 import androidx.annotation.NonNull; 25 import androidx.annotation.Nullable; 26 import androidx.annotation.StringRes; 27 import androidx.preference.Preference; 28 import androidx.preference.TwoStatePreference; 29 30 import com.android.permissioncontroller.R; 31 import com.android.permissioncontroller.role.ui.DefaultAppChildFragment; 32 33 /** 34 * Handheld fragment for a default app. 35 */ 36 public class HandheldDefaultAppFragment extends SettingsFragment 37 implements DefaultAppChildFragment.Parent { 38 39 private String mRoleName; 40 41 private UserHandle mUser; 42 43 /** 44 * Create a new instance of this fragment. 45 * 46 * @param roleName the name of the role for the default app 47 * @param user the user for the default app 48 * 49 * @return a new instance of this fragment 50 */ 51 @NonNull newInstance(@onNull String roleName, @NonNull UserHandle user)52 public static HandheldDefaultAppFragment newInstance(@NonNull String roleName, 53 @NonNull UserHandle user) { 54 HandheldDefaultAppFragment fragment = new HandheldDefaultAppFragment(); 55 Bundle arguments = new Bundle(); 56 arguments.putString(Intent.EXTRA_ROLE_NAME, roleName); 57 arguments.putParcelable(Intent.EXTRA_USER, user); 58 fragment.setArguments(arguments); 59 return fragment; 60 } 61 62 @Override onCreate(@ullable Bundle savedInstanceState)63 public void onCreate(@Nullable Bundle savedInstanceState) { 64 super.onCreate(savedInstanceState); 65 66 Bundle arguments = getArguments(); 67 mRoleName = arguments.getString(Intent.EXTRA_ROLE_NAME); 68 mUser = arguments.getParcelable(Intent.EXTRA_USER); 69 } 70 71 @Override onActivityCreated(@ullable Bundle savedInstanceState)72 public void onActivityCreated(@Nullable Bundle savedInstanceState) { 73 super.onActivityCreated(savedInstanceState); 74 75 if (savedInstanceState == null) { 76 DefaultAppChildFragment fragment = DefaultAppChildFragment.newInstance(mRoleName, 77 mUser); 78 getChildFragmentManager().beginTransaction() 79 .add(fragment, null) 80 .commit(); 81 } 82 } 83 84 @Override 85 @StringRes getEmptyTextResource()86 protected int getEmptyTextResource() { 87 return R.string.default_app_no_apps; 88 } 89 90 @Override setTitle(@onNull CharSequence title)91 public void setTitle(@NonNull CharSequence title) { 92 requireActivity().setTitle(title); 93 } 94 95 @NonNull 96 @Override createApplicationPreference(@onNull Context context)97 public TwoStatePreference createApplicationPreference(@NonNull Context context) { 98 return new AppIconRadioButtonPreference(context); 99 } 100 101 @NonNull 102 @Override createFooterPreference(@onNull Context context)103 public Preference createFooterPreference(@NonNull Context context) { 104 return new FooterPreference(context); 105 } 106 107 @Override onPreferenceScreenChanged()108 public void onPreferenceScreenChanged() { 109 updateState(); 110 } 111 } 112