• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.car.settings.applications.appinfo;
18 
19 import android.content.Context;
20 import android.os.Bundle;
21 import android.os.UserHandle;
22 
23 import com.android.car.settings.R;
24 import com.android.car.settings.applications.ApplicationPreferenceController;
25 import com.android.car.settings.common.Logger;
26 import com.android.car.settings.common.SettingsFragment;
27 import com.android.settingslib.applications.ApplicationsState;
28 
29 /**
30  * Shows aspect ratio selections for an application.
31  */
32 public class AppAspectRatioFragment extends SettingsFragment {
33 
34     private static final Logger LOG = new Logger(AppAspectRatioFragment.class);
35 
36     private static final String EXTRA_PACKAGE_NAME = "aspect_ratio_package_name";
37 
38     private String mPackageName;
39 
40     // Application state info
41     private ApplicationsState.AppEntry mAppEntry;
42     private ApplicationsState mAppState;
43 
44     /** Creates an instance of this fragment, passing packageName as an argument. */
getInstance(String packageName)45     public static AppAspectRatioFragment getInstance(String packageName) {
46         AppAspectRatioFragment appAspectRatioFragment =
47                 new AppAspectRatioFragment();
48         Bundle bundle = new Bundle();
49         bundle.putString(EXTRA_PACKAGE_NAME, packageName);
50         appAspectRatioFragment.setArguments(bundle);
51         return appAspectRatioFragment;
52     }
53 
54     @Override
getPreferenceScreenResId()55     protected int getPreferenceScreenResId() {
56         return R.xml.app_aspect_ratio_fragment;
57     }
58 
59     @Override
onAttach(Context context)60     public void onAttach(Context context) {
61         super.onAttach(context);
62         int userId = UserHandle.myUserId();
63         mPackageName = getArguments().getString(EXTRA_PACKAGE_NAME);
64         mAppState = ApplicationsState.getInstance(requireActivity().getApplication());
65         mAppEntry = mAppState.getEntry(mPackageName, userId);
66 
67         use(ApplicationPreferenceController.class,
68                 R.string.pk_app_aspect_ratio_details)
69                 .setAppEntry(mAppEntry).setAppState(mAppState);
70         use(AppAspectRatioActionButtonsPreferenceController.class,
71                 R.string.pk_app_aspect_ratio_details_action_buttons)
72                 .setPackageName(mPackageName);
73         use(AppAspectRatiosGroupPreferenceController.class,
74                 R.string.pk_app_aspect_ratio_details_group)
75                 .setPackageName(mPackageName);
76     }
77 }
78