FileDocCategorySizeDatePackage
InternalSelectionFocus.javaAPI DocAndroid 1.5 API3047Wed May 06 22:41:08 BST 2009com.example.android.apis.view

InternalSelectionFocus

public class InternalSelectionFocus extends android.app.Activity
{@link android.view.View#requestFocus(int, android.graphics.Rect)} and {@link android.view.View#onFocusChanged(boolean, int, android.graphics.Rect)} work together to give a newly focused item a hint about the most interesting rectangle of the previously focused view. The view taking focus can use this to set an internal selection more appropriate using this rect. This Activity excercises that behavior using three adjacent {@link InternalSelectionView} that report interesting rects when giving up focus, and use interesting rects when taking focus to best select the internal row to show as selected. Were {@link InternalSelectionView} not to override {@link android.view.View#getFocusedRect}, or {@link android.view.View#onFocusChanged(boolean, int, android.graphics.Rect)}, the focus would jump to some default internal selection (the top) and not allow for the smooth handoff.

Fields Summary
Constructors Summary
Methods Summary
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);

        final LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.HORIZONTAL);
        layout.setLayoutParams(new ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.FILL_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT));

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0,
                ViewGroup.LayoutParams.FILL_PARENT, 1);

        final InternalSelectionView leftColumn = new InternalSelectionView(this, 5, "left column");
        leftColumn.setLayoutParams(params);
        leftColumn.setPadding(10, 10, 10, 10);
        layout.addView(leftColumn);

        final InternalSelectionView middleColumn = new InternalSelectionView(this, 5, "middle column");
        middleColumn.setLayoutParams(params);
        middleColumn.setPadding(10, 10, 10, 10);
        layout.addView(middleColumn);

        final InternalSelectionView rightColumn = new InternalSelectionView(this, 5, "right column");
        rightColumn.setLayoutParams(params);
        rightColumn.setPadding(10, 10, 10, 10);
        layout.addView(rightColumn);

        setContentView(layout);