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 CustomAppWidgetProviderInfo(Parcel parcel, boolean readSelf)36 protected CustomAppWidgetProviderInfo(Parcel parcel, boolean readSelf) { 37 super(parcel); 38 if (readSelf) { 39 provider = new ComponentName(parcel.readString(), 40 CLS_CUSTOM_WIDGET_PREFIX + parcel.readString()); 41 42 label = parcel.readString(); 43 initialLayout = parcel.readInt(); 44 icon = parcel.readInt(); 45 previewImage = parcel.readInt(); 46 47 resizeMode = parcel.readInt(); 48 spanX = parcel.readInt(); 49 spanY = parcel.readInt(); 50 minSpanX = parcel.readInt(); 51 minSpanY = parcel.readInt(); 52 } 53 } 54 55 @Override initSpans(Context context, InvariantDeviceProfile idp)56 public void initSpans(Context context, InvariantDeviceProfile idp) { 57 mIsMinSizeFulfilled = Math.min(spanX, minSpanX) <= idp.numColumns 58 && Math.min(spanY, minSpanY) <= idp.numRows; 59 } 60 61 @Override getLabel(PackageManager packageManager)62 public String getLabel(PackageManager packageManager) { 63 return Utilities.trim(label); 64 } 65 66 @Override toString()67 public String toString() { 68 return "WidgetProviderInfo(" + provider + ")"; 69 } 70 71 @Override writeToParcel(Parcel out, int flags)72 public void writeToParcel(Parcel out, int flags) { 73 super.writeToParcel(out, flags); 74 out.writeString(provider.getPackageName()); 75 out.writeString(provider.getClassName()); 76 77 out.writeString(label); 78 out.writeInt(initialLayout); 79 out.writeInt(icon); 80 out.writeInt(previewImage); 81 82 out.writeInt(resizeMode); 83 out.writeInt(spanX); 84 out.writeInt(spanY); 85 out.writeInt(minSpanX); 86 out.writeInt(minSpanY); 87 } 88 89 public static final Parcelable.Creator<CustomAppWidgetProviderInfo> CREATOR = 90 new Parcelable.Creator<>() { 91 92 @Override 93 public CustomAppWidgetProviderInfo createFromParcel(Parcel parcel) { 94 return new CustomAppWidgetProviderInfo(parcel, true); 95 } 96 97 @Override 98 public CustomAppWidgetProviderInfo[] newArray(int size) { 99 return new CustomAppWidgetProviderInfo[size]; 100 } 101 }; 102 } 103