Bug 1001129 - Allow setting a default selected item in grid views. r=mfinkle

This commit is contained in:
Wes Johnston 2014-05-21 12:16:26 -07:00
parent d87141ca8f
commit 6a7829a41a
3 changed files with 11 additions and 2 deletions

View File

@ -17,6 +17,7 @@ import org.mozilla.gecko.gfx.BitmapUtils;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.os.Build;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
@ -38,7 +39,7 @@ public class IconGridInput extends PromptInput implements OnItemClickListener {
private static int mColumnWidth = -1; // The maximum width of columns
private static int mMaxColumns = -1; // The maximum number of columns to show
private static int mIconSize = -1; // Size of icons in the grid
private int mSelected = -1; // Current selection
private int mSelected = 0; // Current selection
private JSONArray mArray;
public IconGridInput(JSONObject obj) {
@ -76,12 +77,17 @@ public class IconGridInput extends PromptInput implements OnItemClickListener {
items.add(item);
if (item.selected) {
mSelected = i;
view.setSelection(i);
}
}
view.setNumColumns(Math.min(items.size(), maxColumns));
view.setOnItemClickListener(this);
// Despite what the docs say, setItemChecked was not moved into the AbsListView class until sometime between
// Android 2.3.7 and Android 4.0.3. For other versions the item won't be visually highlighted, BUT we really only
// mSelected will still be set so that we default to its behavior.
if (Build.VERSION.SDK_INT >= 11 && mSelected > -1) {
view.setItemChecked(mSelected, true);
}
mAdapter = new IconGridAdapter(context, -1, items);
view.setAdapter(mAdapter);

View File

@ -19,8 +19,10 @@
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/grid_icon_bg_focused" />
<item android:state_activated="true"
android:drawable="@drawable/grid_icon_bg_activated" />
<item android:drawable="@android:color/transparent" />
</selector>

View File

@ -134,6 +134,7 @@ HelperAppLauncherDialog.prototype = {
name: bundle.GetStringFromName("helperapps.saveToDisk"),
packageName: "org.mozilla.gecko.Download",
iconUri: "drawable://icon",
selected: true, // Default to download for files
launch: function() {
// Reset the preferredAction here.
aLauncher.MIMEInfo.preferredAction = Ci.nsIMIMEInfo.saveToDisk;