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.launcher3.widget.custom; 18 19 import android.content.ComponentName; 20 import android.content.Context; 21 import android.content.pm.PackageManager; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import com.android.launcher3.InvariantDeviceProfile; 26 import com.android.launcher3.Utilities; 27 import com.android.launcher3.widget.LauncherAppWidgetProviderInfo; 28 29 /** 30 * Custom app widget provider info that can be used as a widget, but provide extra functionality 31 * by allowing custom code and views. 32 */ 33 public class CustomAppWidgetProviderInfo extends LauncherAppWidgetProviderInfo 34 implements Parcelable { 35 36 public final int providerId; 37 CustomAppWidgetProviderInfo(Parcel parcel, boolean readSelf, int providerId)38 protected CustomAppWidgetProviderInfo(Parcel parcel, boolean readSelf, int providerId) { 39 super(parcel); 40 if (readSelf) { 41 this.providerId = parcel.readInt(); 42 43 provider = new ComponentName(parcel.readString(), CLS_CUSTOM_WIDGET_PREFIX + providerId); 44 45 label = parcel.readString(); 46 initialLayout = parcel.readInt(); 47 icon = parcel.readInt(); 48 previewImage = parcel.readInt(); 49 50 resizeMode = parcel.readInt(); 51 spanX = parcel.readInt(); 52 spanY = parcel.readInt(); 53 minSpanX = parcel.readInt(); 54 minSpanY = parcel.readInt(); 55 } else { 56 this.providerId = providerId; 57 } 58 } 59 60 @Override initSpans(Context context, InvariantDeviceProfile idp)61 public void initSpans(Context context, InvariantDeviceProfile idp) { } 62 63 @Override getLabel(PackageManager packageManager)64 public String getLabel(PackageManager packageManager) { 65 return Utilities.trim(label); 66 } 67 68 @Override toString()69 public String toString() { 70 return "WidgetProviderInfo(" + provider + ")"; 71 } 72 73 @Override writeToParcel(Parcel out, int flags)74 public void writeToParcel(Parcel out, int flags) { 75 super.writeToParcel(out, flags); 76 out.writeInt(providerId); 77 out.writeString(provider.getPackageName()); 78 79 out.writeString(label); 80 out.writeInt(initialLayout); 81 out.writeInt(icon); 82 out.writeInt(previewImage); 83 84 out.writeInt(resizeMode); 85 out.writeInt(spanX); 86 out.writeInt(spanY); 87 out.writeInt(minSpanX); 88 out.writeInt(minSpanY); 89 } 90 91 public static final Parcelable.Creator<CustomAppWidgetProviderInfo> CREATOR 92 = new Parcelable.Creator<CustomAppWidgetProviderInfo>() { 93 94 @Override 95 public CustomAppWidgetProviderInfo createFromParcel(Parcel parcel) { 96 return new CustomAppWidgetProviderInfo(parcel, true, 0); 97 } 98 99 @Override 100 public CustomAppWidgetProviderInfo[] newArray(int size) { 101 return new CustomAppWidgetProviderInfo[size]; 102 } 103 }; 104 } 105