mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-11 14:28:42 +00:00
Bug 942270 - Add intents to PromptListItems. r=bnicholson
This commit is contained in:
parent
dfc7896cba
commit
1da084a933
@ -1197,10 +1197,10 @@ public class GeckoAppShell
|
||||
* @return an <code>Intent</code>, or <code>null</code> if none could be
|
||||
* produced.
|
||||
*/
|
||||
static Intent getShareIntent(final Context context,
|
||||
final String targetURI,
|
||||
final String mimeType,
|
||||
final String title) {
|
||||
public static Intent getShareIntent(final Context context,
|
||||
final String targetURI,
|
||||
final String mimeType,
|
||||
final String title) {
|
||||
Intent shareIntent = getIntentForActionString(Intent.ACTION_SEND);
|
||||
shareIntent.putExtra(Intent.EXTRA_TEXT, targetURI);
|
||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);
|
||||
|
@ -102,6 +102,25 @@ public class MenuItemActionView extends LinearLayout
|
||||
mMenuItem.setShowIcon(show);
|
||||
}
|
||||
|
||||
public void setIcon(Drawable icon) {
|
||||
mMenuItem.setIcon(icon);
|
||||
mMenuButton.setIcon(icon);
|
||||
}
|
||||
|
||||
public void setIcon(int icon) {
|
||||
mMenuItem.setIcon(icon);
|
||||
mMenuButton.setIcon(icon);
|
||||
}
|
||||
|
||||
public void setTitle(CharSequence title) {
|
||||
mMenuItem.setTitle(title);
|
||||
mMenuButton.setContentDescription(title);
|
||||
}
|
||||
|
||||
public void setSubMenuIndicator(boolean hasSubMenu) {
|
||||
mMenuItem.setSubMenuIndicator(hasSubMenu);
|
||||
}
|
||||
|
||||
public void addActionButton(Drawable drawable) {
|
||||
// If this is the first icon, retain the text.
|
||||
// If not, make the menu item an icon.
|
||||
|
@ -142,7 +142,7 @@ public class MenuItemDefault extends TextView
|
||||
}
|
||||
}
|
||||
|
||||
private void setSubMenuIndicator(boolean hasSubMenu) {
|
||||
void setSubMenuIndicator(boolean hasSubMenu) {
|
||||
if (mHasSubMenu != hasSubMenu) {
|
||||
mHasSubMenu = hasSubMenu;
|
||||
refreshDrawableState();
|
||||
|
@ -61,7 +61,7 @@ public class IntentChooserPrompt {
|
||||
|
||||
// If there's only one item in the intent list, just return it
|
||||
if (mItems.size() == 1) {
|
||||
handler.onIntentSelected(mItems.get(0).intent, 0);
|
||||
handler.onIntentSelected(mItems.get(0).getIntent(), 0);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ public class IntentChooserPrompt {
|
||||
if (itemId == -1) {
|
||||
handler.onCancelled();
|
||||
} else {
|
||||
handler.onIntentSelected(mItems.get(itemId).intent, itemId);
|
||||
handler.onIntentSelected(mItems.get(itemId).getIntent(), itemId);
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -128,12 +128,14 @@ public class IntentChooserPrompt {
|
||||
|
||||
private PromptListItem getItemForResolveInfo(ResolveInfo info, PackageManager pm, Intent intent) {
|
||||
PromptListItem item = new PromptListItem(info.loadLabel(pm).toString());
|
||||
item.icon = info.loadIcon(pm);
|
||||
item.intent = new Intent(intent);
|
||||
item.setIcon(info.loadIcon(pm));
|
||||
|
||||
Intent i = new Intent(intent);
|
||||
// These intents should be implicit.
|
||||
item.intent.setComponent(new ComponentName(info.activityInfo.applicationInfo.packageName,
|
||||
info.activityInfo.name));
|
||||
i.setComponent(new ComponentName(info.activityInfo.applicationInfo.packageName,
|
||||
info.activityInfo.name));
|
||||
item.setIntent(new Intent(i));
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
@ -90,11 +90,11 @@ public class PromptListAdapter extends ArrayAdapter<PromptListItem> {
|
||||
|
||||
public void toggleSelected(int position) {
|
||||
PromptListItem item = getItem(position);
|
||||
item.selected = !item.selected;
|
||||
item.setSelected(!item.getSelected());
|
||||
}
|
||||
|
||||
private void maybeUpdateIcon(PromptListItem item, TextView t) {
|
||||
if (item.icon == null && !item.inGroup && !item.isParent) {
|
||||
if (item.getIcon() == null && !item.inGroup && !item.isParent) {
|
||||
t.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
|
||||
return;
|
||||
}
|
||||
@ -103,10 +103,10 @@ public class PromptListAdapter extends ArrayAdapter<PromptListItem> {
|
||||
Resources res = getContext().getResources();
|
||||
// Set the padding between the icon and the text.
|
||||
t.setCompoundDrawablePadding(mIconTextPadding);
|
||||
if (item.icon != null) {
|
||||
if (item.getIcon() != null) {
|
||||
// We want the icon to be of a specific size. Some do not
|
||||
// follow this rule so we have to resize them.
|
||||
Bitmap bitmap = ((BitmapDrawable) item.icon).getBitmap();
|
||||
Bitmap bitmap = ((BitmapDrawable) item.getIcon()).getBitmap();
|
||||
d = new BitmapDrawable(res, Bitmap.createScaledBitmap(bitmap, mIconSize, mIconSize, true));
|
||||
} else if (item.inGroup) {
|
||||
// We don't currently support "indenting" items with icons
|
||||
@ -130,12 +130,12 @@ public class PromptListAdapter extends ArrayAdapter<PromptListItem> {
|
||||
// Apparently just using ct.setChecked(true) doesn't work, so this
|
||||
// is stolen from the android source code as a way to set the checked
|
||||
// state of these items
|
||||
list.setItemChecked(position, item.selected);
|
||||
list.setItemChecked(position, item.getSelected());
|
||||
}
|
||||
}
|
||||
|
||||
boolean isSelected(int position){
|
||||
return getItem(position).selected;
|
||||
return getItem(position).getSelected();
|
||||
}
|
||||
|
||||
ArrayList<Integer> getSelected() {
|
||||
|
@ -1,11 +1,15 @@
|
||||
package org.mozilla.gecko.prompts;
|
||||
|
||||
import org.mozilla.gecko.gfx.BitmapUtils;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONException;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
@ -18,28 +22,74 @@ public class PromptListItem {
|
||||
public final boolean inGroup;
|
||||
public final boolean disabled;
|
||||
public final int id;
|
||||
public boolean selected;
|
||||
public Intent intent;
|
||||
public final boolean showAsActions;
|
||||
public final boolean isParent;
|
||||
|
||||
public boolean isParent;
|
||||
public Drawable icon;
|
||||
public Intent mIntent;
|
||||
public boolean mSelected;
|
||||
public Drawable mIcon;
|
||||
|
||||
PromptListItem(JSONObject aObject) {
|
||||
label = aObject.optString("label");
|
||||
label = aObject.isNull("label") ? "" : aObject.optString("label");
|
||||
isGroup = aObject.optBoolean("isGroup");
|
||||
inGroup = aObject.optBoolean("inGroup");
|
||||
disabled = aObject.optBoolean("disabled");
|
||||
id = aObject.optInt("id");
|
||||
isParent = aObject.optBoolean("isParent");
|
||||
selected = aObject.optBoolean("selected");
|
||||
mSelected = aObject.optBoolean("selected");
|
||||
|
||||
JSONObject obj = aObject.optJSONObject("shareData");
|
||||
if (obj != null) {
|
||||
showAsActions = true;
|
||||
String uri = obj.isNull("uri") ? "" : obj.optString("uri");
|
||||
String type = obj.isNull("type") ? "" : obj.optString("type");
|
||||
mIntent = GeckoAppShell.getShareIntent(GeckoAppShell.getContext(), uri, type, "");
|
||||
isParent = true;
|
||||
} else {
|
||||
mIntent = null;
|
||||
showAsActions = false;
|
||||
isParent = aObject.optBoolean("isParent");
|
||||
}
|
||||
|
||||
BitmapUtils.getDrawable(GeckoAppShell.getContext(), aObject.optString("icon"), new BitmapUtils.BitmapLoader() {
|
||||
@Override
|
||||
public void onBitmapFound(Drawable d) {
|
||||
mIcon = d;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setIntent(Intent i) {
|
||||
mIntent = i;
|
||||
}
|
||||
|
||||
public Intent getIntent() {
|
||||
return mIntent;
|
||||
}
|
||||
|
||||
public void setIcon(Drawable icon) {
|
||||
mIcon = icon;
|
||||
}
|
||||
|
||||
public Drawable getIcon() {
|
||||
return mIcon;
|
||||
}
|
||||
|
||||
public void setSelected(boolean selected) {
|
||||
mSelected = selected;
|
||||
}
|
||||
|
||||
public boolean getSelected() {
|
||||
return mSelected;
|
||||
}
|
||||
|
||||
public PromptListItem(String aLabel) {
|
||||
label = aLabel;
|
||||
isGroup = false;
|
||||
inGroup = false;
|
||||
isParent = false;
|
||||
disabled = false;
|
||||
id = 0;
|
||||
showAsActions = false;
|
||||
}
|
||||
|
||||
static PromptListItem[] getArray(JSONArray items) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user