Methods Summary |
---|
protected android.widget.ListAdapter | createAdapter()Override this to provide an different adapter for your scenario
return new MyAdapter();
|
protected android.view.View | createView(int position, android.view.ViewGroup parent, int desiredHeight)Create a view for a grid item. Override this to create a custom view beyond
the simple focusable / unfocusable text view.
TextView result = new TextView(parent.getContext());
result.setHeight(desiredHeight);
result.setText(getValueAtPosition(position));
final ViewGroup.LayoutParams lp = new AbsListView.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
result.setLayoutParams(lp);
result.setId(position);
result.setBackgroundColor(0x55ffffff);
return result;
|
public int | getDesiredItemHeight()
return (int) (mScreenHeight * mItemScreenSizeFactor);
|
public android.widget.GridView | getGridView()
return mGridView;
|
protected int | getInitialNumItems()
return mNumItems;
|
protected int | getScreenHeight()
return mScreenHeight;
|
public final java.lang.String | getValueAtPosition(int position)
return "postion " + position;
|
protected abstract void | init(com.android.frameworktest.util.GridScenario$Params params)How each scenario customizes its behavior.
|
protected void | nothingSelected()Override this if you want to know that nothing is selected.
|
protected void | onCreate(android.os.Bundle icicle)
super.onCreate(icicle);
// turn off title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
mScreenHeight = getWindowManager().getDefaultDisplay().getHeight();
final Params params = new Params();
init(params);
readAndValidateParams(params);
mGridView = new GridView(this);
mGridView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.FILL_PARENT));
mGridView.setDrawSelectorOnTop(false);
if (mNumColumns >= GridView.AUTO_FIT) {
mGridView.setNumColumns(mNumColumns);
}
if (mColumnWidth > 0) {
mGridView.setColumnWidth(mColumnWidth);
}
if (mVerticalSpacing > 0) {
mGridView.setVerticalSpacing(mVerticalSpacing);
}
mGridView.setStretchMode(mStretchMode);
mGridView.setAdapter(createAdapter());
if (mStartingSelectionPosition >= 0) {
mGridView.setSelection(mStartingSelectionPosition);
}
mGridView.setPadding(10, 10, 10, 10);
mGridView.setStackFromBottom(mStackFromBottom);
mGridView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView parent, View v, int position, long id) {
positionSelected(position);
}
public void onNothingSelected(AdapterView parent) {
nothingSelected();
}
});
setContentView(mGridView);
|
protected void | positionSelected(int positon)Override this if you want to know when something has been selected (perhaps
more importantly, that {@link android.widget.AdapterView.OnItemSelectedListener} has
been triggered).
|
private void | readAndValidateParams(com.android.frameworktest.util.GridScenario$Params params)Read in and validate all of the params passed in by the scenario.
if (params.mMustFillScreen ) {
double totalFactor = 0.0;
for (int i = 0; i < params.mNumItems; i++) {
if (params.mOverrideItemScreenSizeFactors.containsKey(i)) {
totalFactor += params.mOverrideItemScreenSizeFactors.get(i);
} else {
totalFactor += params.mItemScreenSizeFactor;
}
}
if (totalFactor < 1.0) {
throw new IllegalArgumentException("grid items must combine to be at least " +
"the height of the screen. this is not the case with " + params.mNumItems
+ " items and " + params.mItemScreenSizeFactor + " screen factor and " +
"screen height of " + mScreenHeight);
}
}
mNumItems = params.mNumItems;
mStartingSelectionPosition = params.mStartingSelectionPosition;
mItemScreenSizeFactor = params.mItemScreenSizeFactor;
mOverrideItemScreenSizeFactors.putAll(params.mOverrideItemScreenSizeFactors);
mStackFromBottom = params.mStackFromBottom;
mColumnWidth = params.mColumnWidth;
mNumColumns = params.mNumColumns;
mStretchMode = params.mStretchMode;
mVerticalSpacing = params.mVerticalSpacing;
|