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