Example usage for android.widget ImageView requestFocus

List of usage examples for android.widget ImageView requestFocus

Introduction

In this page you can find the example usage for android.widget ImageView requestFocus.

Prototype

public final boolean requestFocus() 

Source Link

Document

Call this to try to give focus to a specific view or to one of its descendants.

Usage

From source file:com.cognizant.trumobi.PersonaLauncher.java

public void showPreviews(final View anchor, int start, int end) {
    if (mWorkspace != null && mWorkspace.getChildCount() > 0) {
        if (newPreviews) {
            showingPreviews = true;/*from   ww  w  . ja v a2  s .  c  o m*/
            hideDesktop(true);
            mWorkspace.lock();
            mWorkspace.openSense(true);
        } else {
            // check first if it's already open
            final PopupWindow window = (PopupWindow) anchor.getTag(R.id.TAG_PREVIEW);
            if (window != null)
                return;
            Resources resources = getResources();

            PersonaWorkspace personaWorkspace = mWorkspace;
            PersonaCellLayout cell = ((PersonaCellLayout) personaWorkspace.getChildAt(start));
            float max;
            ViewGroup preview;
            max = personaWorkspace.getChildCount();
            preview = new LinearLayout(this);

            Rect r = new Rect();
            // ADW: seems sometimes this throws an out of memory error....
            // so...
            try {
                resources.getDrawable(R.drawable.pr_preview_background).getPadding(r);
            } catch (OutOfMemoryError e) {
            }
            int extraW = (int) ((r.left + r.right) * max);
            int extraH = r.top + r.bottom;

            int aW = cell.getWidth() - extraW;
            float w = aW / max;

            int width = cell.getWidth();
            int height = cell.getHeight();
            // width -= (x + cell.getRightPadding());
            // height -= (y + cell.getBottomPadding());
            if (width != 0 && height != 0) {
                showingPreviews = true;
                float scale = w / width;

                int count = end - start;

                final float sWidth = width * scale;
                float sHeight = height * scale;

                PreviewTouchHandler handler = new PreviewTouchHandler(anchor);
                ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count);

                for (int i = start; i < end; i++) {
                    ImageView image = new ImageView(this);
                    cell = (PersonaCellLayout) personaWorkspace.getChildAt(i);
                    Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight, Bitmap.Config.ARGB_8888);
                    cell.setDrawingCacheEnabled(false);
                    Canvas c = new Canvas(bitmap);
                    c.scale(scale, scale);
                    c.translate(-cell.getLeftPadding(), -cell.getTopPadding());
                    cell.dispatchDraw(c);

                    image.setBackgroundDrawable(resources.getDrawable(R.drawable.pr_preview_background));
                    image.setImageBitmap(bitmap);
                    image.setTag(i);
                    image.setOnClickListener(handler);
                    image.setOnFocusChangeListener(handler);
                    image.setFocusable(true);
                    if (i == mWorkspace.getCurrentScreen())
                        image.requestFocus();

                    preview.addView(image, LinearLayout.LayoutParams.WRAP_CONTENT,
                            LinearLayout.LayoutParams.WRAP_CONTENT);

                    bitmaps.add(bitmap);
                }

                PopupWindow p = new PopupWindow(this);
                p.setContentView(preview);
                p.setWidth((int) (sWidth * count + extraW));
                p.setHeight((int) (sHeight + extraH));
                p.setAnimationStyle(R.style.AnimationPreview);
                p.setOutsideTouchable(true);
                p.setFocusable(true);
                p.setBackgroundDrawable(new ColorDrawable(0));
                p.showAsDropDown(anchor, 0, 0);
                p.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    public void onDismiss() {
                        dismissPreview(anchor);
                    }
                });
                anchor.setTag(R.id.TAG_PREVIEW, p);
                anchor.setTag(R.id.workspace, preview);
                anchor.setTag(R.id.icon, bitmaps);
            }
        }
    }
}