1 /* 2 * Copyright (C) 2018 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.car.carlauncher; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 import com.android.car.carlauncher.LauncherItemProto.LauncherItemMessage; 23 24 /** 25 * LauncherItem can be an app or a folder that contains app 26 */ 27 public abstract class LauncherItem implements Parcelable { 28 private String mPackageName; 29 private String mClassName; 30 private String mDisplayName; 31 LauncherItem(String packageName, String className, String displayName)32 public LauncherItem(String packageName, String className, String displayName) { 33 mPackageName = packageName; 34 mClassName = className; 35 mDisplayName = displayName; 36 } 37 LauncherItem(Parcel in)38 protected LauncherItem(Parcel in) { 39 mPackageName = in.readString(); 40 mClassName = in.readString(); 41 mDisplayName = in.readString(); 42 } 43 44 @Override writeToParcel(Parcel dest, int flags)45 public void writeToParcel(Parcel dest, int flags) { 46 dest.writeString(mPackageName); 47 dest.writeString(mClassName); 48 dest.writeString(mDisplayName); 49 } 50 getDisplayName()51 public String getDisplayName() { 52 return mDisplayName; 53 } 54 getPackageName()55 public String getPackageName() { 56 return mPackageName; 57 } 58 getClassName()59 public String getClassName() { 60 return mClassName; 61 } 62 63 64 /** 65 * This method is used to convert a LauncherItem to a protobuf class 66 */ launcherItem2Msg(int relativePosition, int containerID)67 public LauncherItemMessage launcherItem2Msg(int relativePosition, int containerID) { 68 LauncherItemMessage.Builder builder = LauncherItemMessage.newBuilder() 69 .setPackageName(mPackageName) 70 .setClassName(mClassName) 71 .setDisplayName(mDisplayName) 72 .setRelativePosition(relativePosition) 73 .setContainerID(containerID); 74 return builder.build(); 75 } 76 77 /** 78 * This method should return true if the two LauncherItems contain the same app and metadata. 79 */ areContentsTheSame(LauncherItem launcherItem)80 abstract boolean areContentsTheSame(LauncherItem launcherItem); 81 } 82