Home | History | Annotate | Download | only in drawer
      1 /**
      2  * Copyright (C) 2015 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.settingslib.drawer;
     18 
     19 import android.os.Parcel;
     20 import android.os.Parcelable;
     21 import android.text.TextUtils;
     22 
     23 import java.util.ArrayList;
     24 import java.util.List;
     25 
     26 public class DashboardCategory implements Parcelable {
     27 
     28     /**
     29      * Title of the category that is shown to the user.
     30      */
     31     public CharSequence title;
     32 
     33     /**
     34      * Key used for placing external tiles.
     35      */
     36     public String key;
     37 
     38     /**
     39      * Used to control display order.
     40      */
     41     public int priority;
     42 
     43     /**
     44      * List of the category's children
     45      */
     46     public List<Tile> tiles = new ArrayList<Tile>();
     47 
     48 
     49     public DashboardCategory() {
     50         // Empty
     51     }
     52 
     53     public void addTile(Tile tile) {
     54         tiles.add(tile);
     55     }
     56 
     57     public void addTile(int n, Tile tile) {
     58         tiles.add(n, tile);
     59     }
     60 
     61     public void removeTile(Tile tile) {
     62         tiles.remove(tile);
     63     }
     64 
     65     public void removeTile(int n) {
     66         tiles.remove(n);
     67     }
     68 
     69     public int getTilesCount() {
     70         return tiles.size();
     71     }
     72 
     73     public Tile getTile(int n) {
     74         return tiles.get(n);
     75     }
     76 
     77     @Override
     78     public int describeContents() {
     79         return 0;
     80     }
     81 
     82     @Override
     83     public void writeToParcel(Parcel dest, int flags) {
     84         TextUtils.writeToParcel(title, dest, flags);
     85         dest.writeString(key);
     86         dest.writeInt(priority);
     87 
     88         final int count = tiles.size();
     89         dest.writeInt(count);
     90 
     91         for (int n = 0; n < count; n++) {
     92             Tile tile = tiles.get(n);
     93             tile.writeToParcel(dest, flags);
     94         }
     95     }
     96 
     97     public void readFromParcel(Parcel in) {
     98         title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
     99         key = in.readString();
    100         priority = in.readInt();
    101 
    102         final int count = in.readInt();
    103 
    104         for (int n = 0; n < count; n++) {
    105             Tile tile = Tile.CREATOR.createFromParcel(in);
    106             tiles.add(tile);
    107         }
    108     }
    109 
    110     DashboardCategory(Parcel in) {
    111         readFromParcel(in);
    112     }
    113 
    114     public static final Creator<DashboardCategory> CREATOR = new Creator<DashboardCategory>() {
    115         public DashboardCategory createFromParcel(Parcel source) {
    116             return new DashboardCategory(source);
    117         }
    118 
    119         public DashboardCategory[] newArray(int size) {
    120             return new DashboardCategory[size];
    121         }
    122     };
    123 }
    124