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