本文整理汇总了Java中android.view.View.clearFocus方法的典型用法代码示例。如果您正苦于以下问题:Java View.clearFocus方法的具体用法?Java View.clearFocus怎么用?Java View.clearFocus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.View
的用法示例。
在下文中一共展示了View.clearFocus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createBitmapFromView
import android.view.View; //导入方法依赖的package包/类
/**
* 从一个view创建Bitmap。
* 注意点:绘制之前要清掉 View 的焦点,因为焦点可能会改变一个 View 的 UI 状态。
* 来源:https://github.com/tyrantgit/ExplosionField
*
* @param view 传入一个 View,会获取这个 View 的内容创建 Bitmap。
* @param scale 缩放比例,对创建的 Bitmap 进行缩放,数值支持从 0 到 1。
*/
public static Bitmap createBitmapFromView(View view, float scale) {
if (view instanceof ImageView) {
Drawable drawable = ((ImageView) view).getDrawable();
if (drawable != null && drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
}
view.clearFocus();
Bitmap bitmap = createBitmapSafely((int) (view.getWidth() * scale),
(int) (view.getHeight() * scale), Bitmap.Config.ARGB_8888, 1);
if (bitmap != null) {
synchronized (sCanvas) {
Canvas canvas = sCanvas;
canvas.setBitmap(bitmap);
canvas.save();
canvas.drawColor(Color.WHITE); // 防止 View 上面有些区域空白导致最终 Bitmap 上有些区域变黑
canvas.scale(scale, scale);
view.draw(canvas);
canvas.restore();
canvas.setBitmap(null);
}
}
return bitmap;
}
示例2: createBitmapFromView
import android.view.View; //导入方法依赖的package包/类
public static Bitmap createBitmapFromView(View view) {
if (view instanceof ImageView) {
Drawable drawable = ((ImageView) view).getDrawable();
if (drawable != null && drawable instanceof BitmapDrawable) {
return ((BitmapDrawable) drawable).getBitmap();
}
}
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);
view.draw(canvas);
canvas.setBitmap(null);
}
}
return bitmap;
}
示例3: dispatchTouchEvent
import android.view.View; //导入方法依赖的package包/类
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if ( v instanceof EditText) {
Rect outRect = new Rect();
v.getGlobalVisibleRect(outRect);
if (!outRect.contains((int)event.getRawX(), (int)event.getRawY())) {
v.clearFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
}
}
return super.dispatchTouchEvent( event );
}
示例4: clearFocus
import android.view.View; //导入方法依赖的package包/类
private void clearFocus(Activity activity) {
View v = activity.getCurrentFocus();
if (v != null) {
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
v.clearFocus();
}
}
示例5: onFocusChange
import android.view.View; //导入方法依赖的package包/类
@Override
public void onFocusChange(View view, boolean isFocused) {
if (isFocused && !mCursorVisible) {
if (mDelPressed) {
currentFocus = view;
mDelPressed = false;
return;
}
for (final EditText editText : editTextList) {
if (editText.length() == 0) {
if (editText != view) {
editText.requestFocus();
} else {
currentFocus = view;
}
return;
}
}
if (editTextList.get(editTextList.size() - 1) != view) {
editTextList.get(editTextList.size() - 1).requestFocus();
} else {
currentFocus = view;
}
} else if (isFocused && mCursorVisible) {
currentFocus = view;
} else {
view.clearFocus();
}
}
示例6: clearViewFocus
import android.view.View; //导入方法依赖的package包/类
/**
* 清除editText的焦点
*
* @param v 焦点所在View
* @param ids 输入框
*/
public void clearViewFocus(View v, int... ids) {
if (null != v && null != ids && ids.length > 0) {
for (int id : ids) {
if (v.getId() == id) {
v.clearFocus();
break;
}
}
}
}
示例7: theTimePickerIsGoneWhenEditingTheSearchField
import android.view.View; //导入方法依赖的package包/类
@Test
public void theTimePickerIsGoneWhenEditingTheSearchField() {
SetAlarmActivity activity = Robolectric.buildActivity(SetAlarmActivity.class).create().get();
View searchField = activity.findViewById(R.id.podcast_rss_feed);
View timePicker = activity.findViewById(R.id.time_picker);
searchField.requestFocus();
assertEquals(View.GONE, timePicker.getVisibility());
searchField.clearFocus();
assertEquals(View.VISIBLE, timePicker.getVisibility());
}
示例8: dispatchTouchEvent
import android.view.View; //导入方法依赖的package包/类
@Override public boolean dispatchTouchEvent(MotionEvent ev) {
if (isAutoHideInputView) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
View v = getCurrentFocus();
if (v != null) {
if ((v instanceof EditText)) {
if (!AppUtils.isEventInVIew(v, ev)) {
if (AppUtils.hideInput(this, v) && isClearFocusWhileAutoHideInputView) {
v.clearFocus();
}
}
}
}
return super.dispatchTouchEvent(ev);
}
// 必不可少,否则所有的组件都不会有TouchEvent了
if (getWindow().superDispatchTouchEvent(ev)) {
return true;
}
}
try {
return super.dispatchTouchEvent(ev);
} catch (Exception e) {
// ignored
}
return false;
}
示例9: hideSoftKeyboard
import android.view.View; //导入方法依赖的package包/类
public static void hideSoftKeyboard(View view) {
if (view == null) return;
View mFocusView = view;
Context context = view.getContext();
if (context != null && context instanceof Activity) {
Activity activity = ((Activity) context);
mFocusView = activity.getCurrentFocus();
}
if (mFocusView == null) return;
mFocusView.clearFocus();
InputMethodManager manager = (InputMethodManager) mFocusView.getContext()
.getSystemService(Context.INPUT_METHOD_SERVICE);
manager.hideSoftInputFromWindow(mFocusView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
示例10: getViewBitmap
import android.view.View; //导入方法依赖的package包/类
public static Bitmap getViewBitmap(View v) {
v.clearFocus();
v.setPressed(false);
boolean willNotCache = v.willNotCacheDrawing();
v.setWillNotCacheDrawing(false);
// Reset the drawing cache background color to fully transparent
// for the duration of this operation
int color = v.getDrawingCacheBackgroundColor();
v.setDrawingCacheBackgroundColor(0);
if (color != 0) {
v.destroyDrawingCache();
}
v.buildDrawingCache();
Bitmap cacheBitmap = v.getDrawingCache();
if (cacheBitmap == null) {
Log.e("Folder", "failed getViewBitmap(" + v + ")", new RuntimeException());
return null;
}
Bitmap bitmap = Bitmap.createBitmap(cacheBitmap);
// Restore the view
v.destroyDrawingCache();
v.setWillNotCacheDrawing(willNotCache);
v.setDrawingCacheBackgroundColor(color);
return bitmap;
}
示例11: getViewBitmap
import android.view.View; //导入方法依赖的package包/类
public static Bitmap getViewBitmap(View comBitmap, int width, int height) {
Bitmap bitmap = null;
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(0xffffff);
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(comBitmap.getLeft(), comBitmap.getTop(), comBitmap.getLeft()+width, comBitmap.getTop()+height);
comBitmap.buildDrawingCache();
Bitmap cacheBitmap = comBitmap.getDrawingCache();
if (cacheBitmap == null) {
Log.e("view.ProcessImageToBlur", "failed getViewBitmap(" + comBitmap);
return null;
}
bitmap = Bitmap.createBitmap(cacheBitmap);
// Restore the view
comBitmap.setAlpha(alpha);
comBitmap.destroyDrawingCache();
comBitmap.setWillNotCacheDrawing(willNotCache);
comBitmap.setDrawingCacheBackgroundColor(color);
}
return bitmap;
}
示例12: hidePanelAndKeyboard
import android.view.View; //导入方法依赖的package包/类
public static void hidePanelAndKeyboard(View panelLayout) {
Activity activity = (Activity) panelLayout.getContext();
View focusView = activity.getCurrentFocus();
if (focusView != null) {
KeyboardUtil.hideKeyboard(activity.getCurrentFocus());
focusView.clearFocus();
}
panelLayout.setVisibility(8);
}
示例13: toBitmap
import android.view.View; //导入方法依赖的package包/类
/**
* 把view转化为bitmap(截图)
* 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html
*/
public static Bitmap toBitmap(View view) {
int width = view.getWidth();
int height = view.getHeight();
if (view instanceof ListView) {
height = 0;
// 获取listView实际高度
ListView listView = (ListView) view;
for (int i = 0; i < listView.getChildCount(); i++) {
height += listView.getChildAt(i).getHeight();
}
} else if (view instanceof ScrollView) {
height = 0;
// 获取scrollView实际高度
ScrollView scrollView = (ScrollView) view;
for (int i = 0; i < scrollView.getChildCount(); i++) {
height += scrollView.getChildAt(i).getHeight();
}
}
view.setDrawingCacheEnabled(true);
view.clearFocus();
view.setPressed(false);
boolean willNotCache = view.willNotCacheDrawing();
view.setWillNotCacheDrawing(false);
// Reset the drawing cache background color to fully transparent for the duration of this operation
int color = view.getDrawingCacheBackgroundColor();
view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素)
if (color != Color.WHITE) {
view.destroyDrawingCache();
}
view.buildDrawingCache();
Bitmap cacheBitmap = view.getDrawingCache();
if (cacheBitmap == null) {
return null;
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(cacheBitmap, 0, 0, null);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
if (!bitmap.isRecycled()) {
LogUtils.verbose("recycle bitmap: " + bitmap.toString());
bitmap.recycle();
}
// Restore the view
view.destroyDrawingCache();
view.setWillNotCacheDrawing(willNotCache);
view.setDrawingCacheBackgroundColor(color);
return bitmap;
}
示例14: toBitmap
import android.view.View; //导入方法依赖的package包/类
/**
* 把view转化为bitmap(截图)
* 参见:http://www.cnblogs.com/lee0oo0/p/3355468.html
*/
public static Bitmap toBitmap(View view) {
int width = view.getWidth();
int height = view.getHeight();
if (view instanceof ListView) {
height = 0;
// 获取listView实际高度
ListView listView = (ListView) view;
for (int i = 0; i < listView.getChildCount(); i++) {
height += listView.getChildAt(i).getHeight();
}
} else if (view instanceof ScrollView) {
height = 0;
// 获取scrollView实际高度
ScrollView scrollView = (ScrollView) view;
for (int i = 0; i < scrollView.getChildCount(); i++) {
height += scrollView.getChildAt(i).getHeight();
}
}
view.setDrawingCacheEnabled(true);
view.clearFocus();
view.setPressed(false);
boolean willNotCache = view.willNotCacheDrawing();
view.setWillNotCacheDrawing(false);
// Reset the drawing cache background color to fully transparent for the duration of this operation
int color = view.getDrawingCacheBackgroundColor();
view.setDrawingCacheBackgroundColor(Color.WHITE);//截图去黑色背景(透明像素)
if (color != Color.WHITE) {
view.destroyDrawingCache();
}
view.buildDrawingCache();
Bitmap cacheBitmap = view.getDrawingCache();
if (cacheBitmap == null) {
return null;
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.drawBitmap(cacheBitmap, 0, 0, null);
canvas.save(Canvas.ALL_SAVE_FLAG);
canvas.restore();
if (!bitmap.isRecycled()) {
// LogUtils.verbose("recycle bitmap: " + bitmap.toString());
bitmap.recycle();
}
// Restore the view
view.destroyDrawingCache();
view.setWillNotCacheDrawing(willNotCache);
view.setDrawingCacheBackgroundColor(color);
return bitmap;
}
示例15: saveFocusView
import android.view.View; //导入方法依赖的package包/类
private void saveFocusView(View focusView) {
this.recordedFocusView = focusView;
focusView.clearFocus();
this.panelLayout.setVisibility(8);
}