| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.content.pm; |
| 18 |
|
| 19 |
import android.content.Intent; |
| 20 |
import android.graphics.drawable.Drawable; |
| 21 |
import android.os.Parcel; |
| 22 |
import android.text.TextUtils; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class LabeledIntent extends Intent { |
| 29 |
private String mSourcePackage; |
| 30 |
private int mLabelRes; |
| 31 |
private CharSequence mNonLocalizedLabel; |
| 32 |
private int mIcon; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
public LabeledIntent(Intent origIntent, String sourcePackage, |
| 44 |
int labelRes, int icon) { |
| 45 |
super(origIntent); |
| 46 |
mSourcePackage = sourcePackage; |
| 47 |
mLabelRes = labelRes; |
| 48 |
mNonLocalizedLabel = null; |
| 49 |
mIcon = icon; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public LabeledIntent(Intent origIntent, String sourcePackage, |
| 62 |
CharSequence nonLocalizedLabel, int icon) { |
| 63 |
super(origIntent); |
| 64 |
mSourcePackage = sourcePackage; |
| 65 |
mLabelRes = 0; |
| 66 |
mNonLocalizedLabel = nonLocalizedLabel; |
| 67 |
mIcon = icon; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
public LabeledIntent(String sourcePackage, int labelRes, int icon) { |
| 79 |
mSourcePackage = sourcePackage; |
| 80 |
mLabelRes = labelRes; |
| 81 |
mNonLocalizedLabel = null; |
| 82 |
mIcon = icon; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
public LabeledIntent(String sourcePackage, |
| 94 |
CharSequence nonLocalizedLabel, int icon) { |
| 95 |
mSourcePackage = sourcePackage; |
| 96 |
mLabelRes = 0; |
| 97 |
mNonLocalizedLabel = nonLocalizedLabel; |
| 98 |
mIcon = icon; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public String getSourcePackage() { |
| 105 |
return mSourcePackage; |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
public int getLabelResource() { |
| 112 |
return mLabelRes; |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
public CharSequence getNonLocalizedLabel() { |
| 119 |
return mNonLocalizedLabel; |
| 120 |
} |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
public int getIconResource() { |
| 126 |
return mIcon; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public CharSequence loadLabel(PackageManager pm) { |
| 135 |
if (mNonLocalizedLabel != null) { |
| 136 |
return mNonLocalizedLabel; |
| 137 |
} |
| 138 |
if (mLabelRes != 0 && mSourcePackage != null) { |
| 139 |
CharSequence label = pm.getText(mSourcePackage, mLabelRes, null); |
| 140 |
if (label != null) { |
| 141 |
return label; |
| 142 |
} |
| 143 |
} |
| 144 |
return null; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
public Drawable loadIcon(PackageManager pm) { |
| 153 |
if (mIcon != 0 && mSourcePackage != null) { |
| 154 |
Drawable icon = pm.getDrawable(mSourcePackage, mIcon, null); |
| 155 |
if (icon != null) { |
| 156 |
return icon; |
| 157 |
} |
| 158 |
} |
| 159 |
return null; |
| 160 |
} |
| 161 |
|
| 162 |
public void writeToParcel(Parcel dest, int parcelableFlags) { |
| 163 |
super.writeToParcel(dest, parcelableFlags); |
| 164 |
dest.writeString(mSourcePackage); |
| 165 |
dest.writeInt(mLabelRes); |
| 166 |
TextUtils.writeToParcel(mNonLocalizedLabel, dest, parcelableFlags); |
| 167 |
dest.writeInt(mIcon); |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
protected LabeledIntent(Parcel in) { |
| 172 |
readFromParcel(in); |
| 173 |
} |
| 174 |
|
| 175 |
public void readFromParcel(Parcel in) { |
| 176 |
super.readFromParcel(in); |
| 177 |
mSourcePackage = in.readString(); |
| 178 |
mLabelRes = in.readInt(); |
| 179 |
mNonLocalizedLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 180 |
mIcon = in.readInt(); |
| 181 |
} |
| 182 |
|
| 183 |
public static final @android.annotation.NonNull Creator<LabeledIntent> CREATOR |
| 184 |
= new Creator<LabeledIntent>() { |
| 185 |
public LabeledIntent createFromParcel(Parcel source) { |
| 186 |
return new LabeledIntent(source); |
| 187 |
} |
| 188 |
public LabeledIntent[] newArray(int size) { |
| 189 |
return new LabeledIntent[size]; |
| 190 |
} |
| 191 |
}; |
| 192 |
|
| 193 |
} |