1 /*
2  * Copyright (C) 2016 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.dashboard;
18 
19 import android.content.Context;
20 
21 import androidx.preference.Preference;
22 import androidx.preference.PreferenceScreen;
23 
24 import com.android.settings.core.PreferenceControllerMixin;
25 import com.android.settingslib.core.AbstractPreferenceController;
26 
27 /**
28  * PreferenceController for a dashboard_tile_placeholder, a special preference marking where
29  * dynamic dashboard tiles should be injected in a screen. It is optional when building
30  * preference screen in xml. If not present, all dynamic dashboard tiles will be added to the
31  * bottom of page.
32  */
33 class DashboardTilePlaceholderPreferenceController extends AbstractPreferenceController
34         implements PreferenceControllerMixin {
35 
36     private static final String KEY_PLACEHOLDER = "dashboard_tile_placeholder";
37 
38     private int mOrder = Preference.DEFAULT_ORDER;
39 
DashboardTilePlaceholderPreferenceController(Context context)40     public DashboardTilePlaceholderPreferenceController(Context context) {
41         super(context);
42     }
43 
44     @Override
displayPreference(PreferenceScreen screen)45     public void displayPreference(PreferenceScreen screen) {
46         final Preference pref = screen.findPreference(getPreferenceKey());
47         if (pref != null) {
48             mOrder = pref.getOrder();
49             screen.removePreference(pref);
50         }
51     }
52 
53     @Override
isAvailable()54     public boolean isAvailable() {
55         return false;
56     }
57 
58     @Override
getPreferenceKey()59     public String getPreferenceKey() {
60         return KEY_PLACEHOLDER;
61     }
62 
getOrder()63     public int getOrder() {
64         return mOrder;
65     }
66 }
67