1/*
2 * Copyright (C) 2011 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
17package com.android.settingslib;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21import android.util.SparseBooleanArray;
22
23public class AppItem implements Comparable<AppItem>, Parcelable {
24    public static final int CATEGORY_USER = 0;
25    public static final int CATEGORY_APP_TITLE = 1;
26    public static final int CATEGORY_APP = 2;
27
28    public final int key;
29    public boolean restricted;
30    public int category;
31
32    public SparseBooleanArray uids = new SparseBooleanArray();
33    public long total;
34
35    public AppItem() {
36        this.key = 0;
37    }
38
39    public AppItem(int key) {
40        this.key = key;
41    }
42
43    public AppItem(Parcel parcel) {
44        key = parcel.readInt();
45        uids = parcel.readSparseBooleanArray();
46        total = parcel.readLong();
47    }
48
49    public void addUid(int uid) {
50        uids.put(uid, true);
51    }
52
53    @Override
54    public void writeToParcel(Parcel dest, int flags) {
55        dest.writeInt(key);
56        dest.writeSparseBooleanArray(uids);
57        dest.writeLong(total);
58    }
59
60    @Override
61    public int describeContents() {
62        return 0;
63    }
64
65    @Override
66    public int compareTo(AppItem another) {
67        int comparison = Integer.compare(category, another.category);
68        if (comparison == 0) {
69            comparison = Long.compare(another.total, total);
70        }
71        return comparison;
72    }
73
74    public static final Creator<AppItem> CREATOR = new Creator<AppItem>() {
75        @Override
76        public AppItem createFromParcel(Parcel in) {
77            return new AppItem(in);
78        }
79
80        @Override
81        public AppItem[] newArray(int size) {
82            return new AppItem[size];
83        }
84    };
85}
86