-> Added the ability to specify an AdapterView's empty view

through RemoteViews. An empty view is the view that appears
in lieu of the collection when the collection is empty.
-> Made StackViews start at their last item

Change-Id: Ica44e5e8f8f2a2e5589a6c74414ec4d08303887f
This commit is contained in:
Adam Cohen
2010-08-25 17:24:53 -07:00
parent deefe55322
commit 1480fddea8
5 changed files with 74 additions and 1 deletions

View File

@@ -228878,6 +228878,21 @@
<parameter name="value" type="double">
</parameter>
</method>
<method name="setEmptyView"
return="void"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="viewId" type="int">
</parameter>
<parameter name="emptyViewId" type="int">
</parameter>
</method>
<method name="setFloat"
return="void"
abstract="false"

View File

@@ -228,7 +228,6 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
super(context, attrs, defStyle);
}
/**
* Interface definition for a callback to be invoked when an item in this
* AdapterView has been clicked.
@@ -629,6 +628,7 @@ public abstract class AdapterView<T extends Adapter> extends ViewGroup {
/**
* Sets the view to show if the adapter is empty
*/
@android.view.RemotableViewMethod
public void setEmptyView(View emptyView) {
mEmptyView = emptyView;

View File

@@ -688,6 +688,7 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter>
}
mAdapter = adapter;
checkFocus();
if (mAdapter != null) {
mDataSetObserver = new AdapterDataSetObserver();

View File

@@ -17,6 +17,7 @@
package android.widget;
import android.app.PendingIntent;
import android.appwidget.AppWidgetHostView;
import android.content.Context;
import android.content.Intent;
import android.content.IntentSender;
@@ -110,6 +111,42 @@ public class RemoteViews implements Parcelable, Filter {
}
}
private class SetEmptyView extends Action {
int viewId;
int emptyViewId;
public final static int TAG = 6;
SetEmptyView(int viewId, int emptyViewId) {
this.viewId = viewId;
this.emptyViewId = emptyViewId;
}
SetEmptyView(Parcel in) {
this.viewId = in.readInt();
this.emptyViewId = in.readInt();
}
public void writeToParcel(Parcel out, int flags) {
out.writeInt(TAG);
out.writeInt(this.viewId);
out.writeInt(this.emptyViewId);
}
@Override
public void apply(View root) {
final View view = root.findViewById(viewId);
if (!(view instanceof AdapterView<?>)) return;
AdapterView<?> adapterView = (AdapterView<?>) view;
final View emptyView = root.findViewById(emptyViewId);
if (emptyView == null) return;
adapterView.setEmptyView(emptyView);
}
}
/**
* Equivalent to calling
* {@link android.view.View#setOnClickListener(android.view.View.OnClickListener)}
@@ -631,6 +668,9 @@ public class RemoteViews implements Parcelable, Filter {
case ReflectionActionWithoutParams.TAG:
mActions.add(new ReflectionActionWithoutParams(parcel));
break;
case SetEmptyView.TAG:
mActions.add(new SetEmptyView(parcel));
break;
default:
throw new ActionException("Tag " + tag + " not found");
}
@@ -759,6 +799,16 @@ public class RemoteViews implements Parcelable, Filter {
setBitmap(viewId, "setImageBitmap", bitmap);
}
/**
* Equivalent to calling AdapterView.setEmptyView
*
* @param viewId The id of the view on which to set the empty view
* @param emptyViewId The view id of the empty view
*/
public void setEmptyView(int viewId, int emptyViewId) {
addAction(new SetEmptyView(viewId, emptyViewId));
}
/**
* Equivalent to calling {@link Chronometer#setBase Chronometer.setBase},
* {@link Chronometer#setFormat Chronometer.setFormat},

View File

@@ -124,6 +124,9 @@ public class StackView extends AdapterViewAnimator {
}
setClipChildren(false);
setClipToPadding(false);
// This is a flag to indicate the the stack is loading for the first time
mWhichChild = -1;
}
/**
@@ -638,6 +641,10 @@ public class StackView extends AdapterViewAnimator {
@Override
public void onRemoteAdapterConnected() {
super.onRemoteAdapterConnected();
// On first run, we want to set the stack to the end.
if (mAdapter != null && mWhichChild == -1) {
mWhichChild = mAdapter.getCount() - 1;
}
setDisplayedChild(mWhichChild);
}