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.content.Intent;
     20 import android.graphics.drawable.Icon;
     21 import android.os.Bundle;
     22 import android.os.Parcel;
     23 import android.os.Parcelable;
     24 import android.os.UserHandle;
     25 import android.text.TextUtils;
     26 import android.widget.RemoteViews;
     27 
     28 import java.util.ArrayList;
     29 
     30 /**
     31  * Description of a single dashboard tile that the user can select.
     32  */
     33 public class Tile implements Parcelable {
     34 
     35     /**
     36      * Title of the tile that is shown to the user.
     37      * @attr ref android.R.styleable#PreferenceHeader_title
     38      */
     39     public CharSequence title;
     40 
     41     /**
     42      * Optional summary describing what this tile controls.
     43      * @attr ref android.R.styleable#PreferenceHeader_summary
     44      */
     45     public CharSequence summary;
     46 
     47     /**
     48      * Optional icon to show for this tile.
     49      * @attr ref android.R.styleable#PreferenceHeader_icon
     50      */
     51     public Icon icon;
     52 
     53     /**
     54      * Whether the icon can be tinted. This should be set to true for monochrome (single-color)
     55      * icons that can be tinted to match the design.
     56      */
     57     public boolean isIconTintable;
     58 
     59     /**
     60      * Intent to launch when the preference is selected.
     61      */
     62     public Intent intent;
     63 
     64     /**
     65      * Optional list of user handles which the intent should be launched on.
     66      */
     67     public ArrayList<UserHandle> userHandle = new ArrayList<>();
     68 
     69     /**
     70      * Optional additional data for use by subclasses of the activity
     71      */
     72     public Bundle extras;
     73 
     74     /**
     75      * Category in which the tile should be placed.
     76      */
     77     public String category;
     78 
     79     /**
     80      * Priority of the intent filter that created this tile, used for display ordering.
     81      */
     82     public int priority;
     83 
     84     /**
     85      * The metaData from the activity that defines this tile.
     86      */
     87     public Bundle metaData;
     88 
     89     /**
     90      * Optional key to use for this tile.
     91      */
     92     public String key;
     93 
     94     /**
     95      * Optional remote view which will be displayed instead of the regular title-summary item.
     96      */
     97     public RemoteViews remoteViews;
     98 
     99     public Tile() {
    100         // Empty
    101     }
    102 
    103     @Override
    104     public int describeContents() {
    105         return 0;
    106     }
    107 
    108     @Override
    109     public void writeToParcel(Parcel dest, int flags) {
    110         TextUtils.writeToParcel(title, dest, flags);
    111         TextUtils.writeToParcel(summary, dest, flags);
    112         if (icon != null) {
    113             dest.writeByte((byte) 1);
    114             icon.writeToParcel(dest, flags);
    115         } else {
    116             dest.writeByte((byte) 0);
    117         }
    118         if (intent != null) {
    119             dest.writeByte((byte) 1);
    120             intent.writeToParcel(dest, flags);
    121         } else {
    122             dest.writeByte((byte) 0);
    123         }
    124         final int N = userHandle.size();
    125         dest.writeInt(N);
    126         for (int i = 0; i < N; i++) {
    127             userHandle.get(i).writeToParcel(dest, flags);
    128         }
    129         dest.writeBundle(extras);
    130         dest.writeString(category);
    131         dest.writeInt(priority);
    132         dest.writeBundle(metaData);
    133         dest.writeString(key);
    134         dest.writeParcelable(remoteViews, flags);
    135         dest.writeBoolean(isIconTintable);
    136     }
    137 
    138     public void readFromParcel(Parcel in) {
    139         title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
    140         summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
    141         if (in.readByte() != 0) {
    142             icon = Icon.CREATOR.createFromParcel(in);
    143         }
    144         if (in.readByte() != 0) {
    145             intent = Intent.CREATOR.createFromParcel(in);
    146         }
    147         final int N = in.readInt();
    148         for (int i = 0; i < N; i++) {
    149             userHandle.add(UserHandle.CREATOR.createFromParcel(in));
    150         }
    151         extras = in.readBundle();
    152         category = in.readString();
    153         priority = in.readInt();
    154         metaData = in.readBundle();
    155         key = in.readString();
    156         remoteViews = in.readParcelable(RemoteViews.class.getClassLoader());
    157         isIconTintable = in.readBoolean();
    158     }
    159 
    160     Tile(Parcel in) {
    161         readFromParcel(in);
    162     }
    163 
    164     public static final Creator<Tile> CREATOR = new Creator<Tile>() {
    165         public Tile createFromParcel(Parcel source) {
    166             return new Tile(source);
    167         }
    168         public Tile[] newArray(int size) {
    169             return new Tile[size];
    170         }
    171     };
    172 }
    173