Example usage for android.view View clearFocus

List of usage examples for android.view View clearFocus

Introduction

In this page you can find the example usage for android.view View clearFocus.

Prototype

public void clearFocus() 

Source Link

Document

Called when this view wants to give up focus.

Usage

From source file:Main.java

public static void closeKeyBoard(Context context, View view) {
    view.clearFocus();
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

From source file:Main.java

static Bitmap convertViewToBitmap(View view) {
    view.clearFocus();
    Bitmap bitmap = createBitmapSafely(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_4444, 2);
    if (bitmap != null) {
        mCanvas.setBitmap(bitmap);// w  w w.  jav  a 2 s .c o  m
        mCanvas.translate(-view.getScrollX(), -view.getScrollY());
        view.draw(mCanvas);
        mCanvas.setBitmap(null);
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap createBitmapFromView(View view) {
    view.clearFocus();
    Bitmap bitmap = createBitmapSafely(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888, 1);
    if (bitmap != null) {
        synchronized (sCanvas) {
            Canvas canvas = sCanvas;
            canvas.setBitmap(bitmap);//from w  w w  . j a  v  a  2 s  .co m
            view.draw(canvas);
            canvas.setBitmap(null);
        }
    }
    return bitmap;
}

From source file:Main.java

public static Bitmap createBitmapFromView(View view) {
    // Clear any focus from the view first to remove any cursor
    view.clearFocus();
    Bitmap drawingBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    drawingBitmap.eraseColor(Color.TRANSPARENT);
    Canvas canvas = new Canvas(drawingBitmap);
    view.draw(canvas);/*from ww w.j  a v a 2s  . c  om*/
    return drawingBitmap;
}

From source file:Main.java

/**
 * Hides the soft keyboard by clearing view's focus.
 *
 * @param view The view whose focus needs to be cleared.
 *//*from  ww  w .ja  v a  2s. c  o m*/
public static void clearViewFocus(@NonNull final View view) {
    view.post(new Runnable() {
        @Override
        public void run() {
            view.clearFocus();
        }
    });
}

From source file:Main.java

public static void hidePanelAndKeyboard(View panelLayout) {
    final Activity activity = (Activity) panelLayout.getContext();
    final View focusView = activity.getCurrentFocus();
    if (focusView != null) {
        hideKeyboard(activity.getCurrentFocus());
        focusView.clearFocus();
    }/*from   w w  w .  j  a  va2  s  .c om*/
    panelLayout.setVisibility(View.GONE);
}

From source file:com.lixplor.fastutil.utils.control.KeyboardUtil.java

public static void hide(@NonNull View view) {
    view.clearFocus();
    sInputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}

From source file:Main.java

public static Bitmap convertViewToBitmap(View comBitmap, int width, int height) {
    Bitmap bitmap = null;//from w  w w .j av a 2 s  .com
    if (comBitmap != null) {
        comBitmap.clearFocus();
        comBitmap.setPressed(false);

        boolean willNotCache = comBitmap.willNotCacheDrawing();
        comBitmap.setWillNotCacheDrawing(false);

        // Reset the drawing cache background color to fully transparent
        // for the duration of this operation
        int color = comBitmap.getDrawingCacheBackgroundColor();
        comBitmap.setDrawingCacheBackgroundColor(0);
        float alpha = comBitmap.getAlpha();
        comBitmap.setAlpha(1.0f);

        if (color != 0) {
            comBitmap.destroyDrawingCache();
        }

        int widthSpec = View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY);
        int heightSpec = View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY);
        comBitmap.measure(widthSpec, heightSpec);
        comBitmap.layout(0, 0, width, height);

        comBitmap.buildDrawingCache();
        Bitmap cacheBitmap = comBitmap.getDrawingCache();
        if (cacheBitmap == null) {
            Log.e("view.ProcessImageToBlur", "failed getViewBitmap(" + comBitmap + ")", new RuntimeException());
            return null;
        }
        bitmap = Bitmap.createBitmap(cacheBitmap);
        // Restore the view
        comBitmap.setAlpha(alpha);
        comBitmap.destroyDrawingCache();
        comBitmap.setWillNotCacheDrawing(willNotCache);
        comBitmap.setDrawingCacheBackgroundColor(color);
    }
    return bitmap;
}

From source file:Main.java

public static void closeSoftKeyboard(Context context) {
    if (context == null || !(context instanceof Activity) || ((Activity) context).getCurrentFocus() == null) {
        return;/*from  w  ww.jav a 2s .  c om*/
    }
    try {
        View view = ((Activity) context).getCurrentFocus();
        InputMethodManager imm = (InputMethodManager) view.getContext()
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        view.clearFocus();
        imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void hideKeyboard(Context context, View editText) {
    try {/* w  w  w  .  j  a v a  2  s. co  m*/
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        if (editText != null) {
            imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
            editText.clearFocus();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}