Home | History | Annotate | Download | only in dashboard
      1 /*
      2  * Copyright (C) 2017 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.util.ArrayMap;
     20 
     21 import com.android.settings.DisplaySettings;
     22 import com.android.settings.SecuritySettings;
     23 import com.android.settings.accounts.AccountDetailDashboardFragment;
     24 import com.android.settings.accounts.UserAndAccountDashboardFragment;
     25 import com.android.settings.applications.AdvancedAppSettings;
     26 import com.android.settings.applications.AppAndNotificationDashboardFragment;
     27 import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
     28 import com.android.settings.development.DevelopmentSettings;
     29 import com.android.settings.deviceinfo.StorageDashboardFragment;
     30 import com.android.settings.fuelgauge.PowerUsageSummary;
     31 import com.android.settings.language.LanguageAndInputSettings;
     32 import com.android.settings.network.NetworkDashboardFragment;
     33 import com.android.settings.notification.ConfigureNotificationSettings;
     34 import com.android.settings.notification.SoundSettings;
     35 import com.android.settings.system.SystemDashboardFragment;
     36 import com.android.settingslib.drawer.CategoryKey;
     37 
     38 import java.util.Map;
     39 
     40 /**
     41  * A registry to keep track of which page hosts which category.
     42  */
     43 public class DashboardFragmentRegistry {
     44 
     45     /**
     46      * Map from parent fragment to category key. The parent fragment hosts child with
     47      * category_key.
     48      */
     49     public static final Map<String, String> PARENT_TO_CATEGORY_KEY_MAP;
     50 
     51     /**
     52      * Map from category_key to parent. This is a helper to look up which fragment hosts the
     53      * category_key.
     54      */
     55     public static final Map<String, String> CATEGORY_KEY_TO_PARENT_MAP;
     56 
     57     static {
     58         PARENT_TO_CATEGORY_KEY_MAP = new ArrayMap<>();
     59         PARENT_TO_CATEGORY_KEY_MAP.put(
     60                 NetworkDashboardFragment.class.getName(), CategoryKey.CATEGORY_NETWORK);
     61         PARENT_TO_CATEGORY_KEY_MAP.put(ConnectedDeviceDashboardFragment.class.getName(),
     62                 CategoryKey.CATEGORY_DEVICE);
     63         PARENT_TO_CATEGORY_KEY_MAP.put(AppAndNotificationDashboardFragment.class.getName(),
     64                 CategoryKey.CATEGORY_APPS);
     65         PARENT_TO_CATEGORY_KEY_MAP.put(PowerUsageSummary.class.getName(),
     66                 CategoryKey.CATEGORY_BATTERY);
     67         PARENT_TO_CATEGORY_KEY_MAP.put(AdvancedAppSettings.class.getName(),
     68                 CategoryKey.CATEGORY_APPS_DEFAULT);
     69         PARENT_TO_CATEGORY_KEY_MAP.put(DisplaySettings.class.getName(),
     70                 CategoryKey.CATEGORY_DISPLAY);
     71         PARENT_TO_CATEGORY_KEY_MAP.put(SoundSettings.class.getName(),
     72                 CategoryKey.CATEGORY_SOUND);
     73         PARENT_TO_CATEGORY_KEY_MAP.put(StorageDashboardFragment.class.getName(),
     74                 CategoryKey.CATEGORY_STORAGE);
     75         PARENT_TO_CATEGORY_KEY_MAP.put(SecuritySettings.class.getName(),
     76                 CategoryKey.CATEGORY_SECURITY);
     77         PARENT_TO_CATEGORY_KEY_MAP.put(AccountDetailDashboardFragment.class.getName(),
     78                 CategoryKey.CATEGORY_ACCOUNT);
     79         PARENT_TO_CATEGORY_KEY_MAP.put(UserAndAccountDashboardFragment.class.getName(),
     80                 CategoryKey.CATEGORY_ACCOUNT);
     81         PARENT_TO_CATEGORY_KEY_MAP.put(
     82                 SystemDashboardFragment.class.getName(), CategoryKey.CATEGORY_SYSTEM);
     83         PARENT_TO_CATEGORY_KEY_MAP.put(LanguageAndInputSettings.class.getName(),
     84                 CategoryKey.CATEGORY_SYSTEM_LANGUAGE);
     85         PARENT_TO_CATEGORY_KEY_MAP.put(DevelopmentSettings.class.getName(),
     86                 CategoryKey.CATEGORY_SYSTEM_DEVELOPMENT);
     87         PARENT_TO_CATEGORY_KEY_MAP.put(ConfigureNotificationSettings.class.getName(),
     88                 CategoryKey.CATEGORY_NOTIFICATIONS);
     89 
     90         CATEGORY_KEY_TO_PARENT_MAP = new ArrayMap<>(PARENT_TO_CATEGORY_KEY_MAP.size());
     91 
     92         for (Map.Entry<String, String> parentToKey : PARENT_TO_CATEGORY_KEY_MAP.entrySet()) {
     93             CATEGORY_KEY_TO_PARENT_MAP.put(parentToKey.getValue(), parentToKey.getKey());
     94         }
     95     }
     96 }
     97