Java Code Examples for android.view.View#requestFocusFromTouch()

The following examples show how to use android.view.View#requestFocusFromTouch() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private boolean validateForm() {
	if (formFragment == null) return true;

	List<Field<?>> invalid = new ArrayList<>();

	for (Field<?> editField : formFragment.getEditFields()) {
		if (!editField.validate(true)) {
			invalid.add(editField);
		}
	}


	if (!invalid.isEmpty()) {
		// scroll to first invalid control
		View firstInvalid = invalid.get(0);
		findViewById(R.id.properties).scrollTo(0, firstInvalid.getBottom());
		firstInvalid.clearFocus();
		firstInvalid.requestFocus();
		firstInvalid.requestFocusFromTouch();

		return false;
	}

	return true;
}
 
Example 2
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void clearInputMethodManagerLeak() {
    try {
        Object lock = mHField.get(inputMethodManager);
        // This is highly dependent on the InputMethodManager implementation.
        synchronized (lock) {
            View servedView = (View) mServedViewField.get(inputMethodManager);
            if (servedView != null) {

                boolean servedViewAttached = servedView.getWindowVisibility() != View.GONE;

                if (servedViewAttached) {
                    // The view held by the IMM was replaced without a global focus change. Let's make
                    // sure we get notified when that view detaches.

                    // Avoid double registration.
                    servedView.removeOnAttachStateChangeListener(this);
                    servedView.addOnAttachStateChangeListener(this);
                } else {
                    // servedView is not attached. InputMethodManager is being stupid!
                    Activity activity = extractActivity(servedView.getContext());
                    if (activity == null || activity.getWindow() == null) {
                        // Unlikely case. Let's finish the input anyways.
                        finishInputLockedMethod.invoke(inputMethodManager);
                    } else {
                        View decorView = activity.getWindow().peekDecorView();
                        boolean windowAttached = decorView.getWindowVisibility() != View.GONE;
                        if (!windowAttached) {
                            finishInputLockedMethod.invoke(inputMethodManager);
                        } else {
                            decorView.requestFocusFromTouch();
                        }
                    }
                }
            }
        }
    } catch (IllegalAccessException | InvocationTargetException unexpected) {
        Log.e("IMMLeaks", "Unexpected reflection exception", unexpected);
    }
}
 
Example 3
@Override
public boolean onTouch(View view, MotionEvent event) {
    view.getParent().requestDisallowInterceptTouchEvent(true);
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            view.setPressed(true);
            mTouched = true;
            return true;
        case MotionEvent.ACTION_UP:
            if (mTouched && ViewUtils.isInsideView(view, (int)event.getRawX(), (int)event.getRawY())) {
                view.requestFocus();
                view.requestFocusFromTouch();
                if (mClickListener != null) {
                    mClickListener.onClick(view);
                }
            }
            view.setPressed(false);
            mTouched = false;
            return true;
        case MotionEvent.ACTION_MOVE:
            return true;
        case MotionEvent.ACTION_CANCEL:
            view.setPressed(false);
            mTouched = false;
            return true;
    }
    return false;
}
 
Example 4
@Override
public void onFxALogin(@NonNull View view) {
    view.requestFocusFromTouch();
    if (mAccounts.getAccountStatus() == Accounts.AccountStatus.SIGNED_IN) {
        mAccounts.logoutAsync();

    } else {
        CompletableFuture<String> result = mAccounts.authUrlAsync();
        if (result != null) {
            result.thenAcceptAsync((url) -> {
                if (url == null) {
                    mAccounts.logoutAsync();

                } else {
                    mAccounts.setLoginOrigin(Accounts.LoginOrigin.HISTORY);
                    mWidgetManager.openNewTabForeground(url);
                    mWidgetManager.getFocusedWindow().getSession().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_MOBILE);
                    GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.FXA_LOGIN);

                    WindowWidget window = mWidgetManager.getFocusedWindow();
                    window.hidePanel(Windows.PanelType.HISTORY);
                }

            }, mUIThreadExecutor).exceptionally(throwable -> {
                Log.d(LOGTAG, "Error getting the authentication URL: " + throwable.getLocalizedMessage());
                throwable.printStackTrace();
                return null;
            });
        }
    }
}
 
Example 5
Source Project: ProjectX   File: InputMethodUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 打开输入法
 * 会使得view得到焦点
 *
 * @param view View
 */
public static void openInputMethod(View view) {
    if (null == view) {
        return;
    }
    view.requestFocus();
    view.requestFocusFromTouch();
    InputMethodManager imm = ((InputMethodManager) (view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE)));
    if (imm != null) {
        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }
}
 
Example 6
protected void showSortingContextMenu(@NonNull View view) {
    view.requestFocusFromTouch();

    hideContextMenu();

    WindowWidget window = mWidgetManager.getFocusedWindow();

    float ratio = WidgetPlacement.viewToWidgetRatio(getContext(), window);

    Rect offsetViewBounds = new Rect();
    getDrawingRect(offsetViewBounds);
    offsetDescendantRectToMyCoords(view, offsetViewBounds);

    SortingContextMenuWidget menu = new SortingContextMenuWidget(getContext());
    menu.setItemDelegate(item -> {
        mSortingComparator = getSorting(item);
        onDownloadsUpdate(mDownloadsManager.getDownloads());
        mBinding.downloadsList.scrollToPosition(0);
    });
    menu.getPlacement().parentHandle = window.getHandle();

    menu.getPlacement().anchorY = 1.0f;
    PointF position = new PointF(
            (offsetViewBounds.left + view.getWidth()) * ratio,
            -(offsetViewBounds.top + view.getHeight()) * ratio);
    menu.getPlacement().translationX = position.x - (menu.getWidth() / menu.getPlacement().density);
    menu.getPlacement().translationY = position.y + getResources().getDimension(R.dimen.library_menu_top_margin) / menu.getPlacement().density;
    menu.show(UIWidget.REQUEST_FOCUS);
}
 
Example 7
@Override
public void onFxALogin(@NonNull View view) {
    view.requestFocusFromTouch();
    if (mAccounts.getAccountStatus() == Accounts.AccountStatus.SIGNED_IN) {
        mAccounts.logoutAsync();

    } else {
        CompletableFuture<String> result = mAccounts.authUrlAsync();
        if (result != null) {
            result.thenAcceptAsync((url) -> {
                if (url == null) {
                    mAccounts.logoutAsync();

                } else {
                    mAccounts.setLoginOrigin(Accounts.LoginOrigin.BOOKMARKS);
                    WidgetManagerDelegate widgetManager = ((VRBrowserActivity) getContext());
                    widgetManager.openNewTabForeground(url);
                    widgetManager.getFocusedWindow().getSession().setUaMode(GeckoSessionSettings.USER_AGENT_MODE_MOBILE);
                    GleanMetricsService.Tabs.openedCounter(GleanMetricsService.Tabs.TabSource.FXA_LOGIN);

                    WindowWidget window = mWidgetManager.getFocusedWindow();
                    window.hidePanel(Windows.PanelType.BOOKMARKS);
                }

            }, mUIThreadExecutor).exceptionally(throwable -> {
                Log.d(LOGTAG, "Error getting the authentication URL: " + throwable.getLocalizedMessage());
                throwable.printStackTrace();
                return null;
            });
        }
    }
}
 
Example 8
private void clearInputMethodManagerLeak() {
    try {
        Object lock = mHField.get(inputMethodManager);
        // This is highly dependent on the InputMethodManager implementation.
        synchronized (lock) {
            View servedView = (View) mServedViewField.get(inputMethodManager);
            if (servedView != null) {

                boolean servedViewAttached = servedView.getWindowVisibility() != View.GONE;

                if (servedViewAttached) {
                    // The view held by the IMM was replaced without a global focus change. Let's make
                    // sure we get notified when that view detaches.

                    // Avoid double registration.
                    servedView.removeOnAttachStateChangeListener(this);
                    servedView.addOnAttachStateChangeListener(this);
                } else {
                    // servedView is not attached. InputMethodManager is being stupid!
                    Activity activity = extractActivity(servedView.getContext());
                    if (activity == null || activity.getWindow() == null) {
                        // Unlikely case. Let's finish the input anyways.
                        finishInputLockedMethod.invoke(inputMethodManager);
                    } else {
                        View decorView = activity.getWindow().peekDecorView();
                        boolean windowAttached = decorView.getWindowVisibility() != View.GONE;
                        if (!windowAttached) {
                            finishInputLockedMethod.invoke(inputMethodManager);
                        } else {
                            decorView.requestFocusFromTouch();
                        }
                    }
                }
            }
        }
    } catch (Exception unexpected) {
        Log.e("IMMLeaks", "Unexpected reflection exception", unexpected);
    }
}
 
Example 9
@Override
public void onClick(View v) {
	clickButton(v, true);
	if(v.getId() != R.id.btnClose) {
		v.requestFocusFromTouch();
		focusedView = v;
	}
}
 
Example 10
Source Project: letv   File: BasicActivity.java    License: Apache License 2.0 5 votes vote down vote up
public void setViewFocus(View view) {
    if (view != null) {
        view.setFocusable(true);
        view.setFocusableInTouchMode(true);
        view.requestFocus();
        view.requestFocusFromTouch();
    }
}
 
Example 11
Source Project: diycode   File: IMMLeaks.java    License: Apache License 2.0 5 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
private void clearInputMethodManagerLeak() {
  try {
    Object lock = mHField.get(inputMethodManager);
    // This is highly dependent on the InputMethodManager implementation.
    synchronized (lock) {
      View servedView = (View) mServedViewField.get(inputMethodManager);
      if (servedView != null) {

        boolean servedViewAttached = servedView.getWindowVisibility() != View.GONE;

        if (servedViewAttached) {
          // The view held by the IMM was replaced without a global focus change. Let's make
          // sure we get notified when that view detaches.

          // Avoid double registration.
          servedView.removeOnAttachStateChangeListener(this);
          servedView.addOnAttachStateChangeListener(this);
        } else {
          // servedView is not attached. InputMethodManager is being stupid!
          Activity activity = extractActivity(servedView.getContext());
          if (activity == null || activity.getWindow() == null) {
            // Unlikely case. Let's finish the input anyways.
            finishInputLockedMethod.invoke(inputMethodManager);
          } else {
            View decorView = activity.getWindow().peekDecorView();
            boolean windowAttached = decorView.getWindowVisibility() != View.GONE;
            if (!windowAttached) {
              finishInputLockedMethod.invoke(inputMethodManager);
            } else {
              decorView.requestFocusFromTouch();
            }
          }
        }
      }
    }
  } catch (IllegalAccessException | InvocationTargetException unexpected) {
    Log.e("IMMLeaks", "Unexpected reflection exception", unexpected);
  }
}
 
Example 12
Source Project: HaiNaBaiChuan   File: SettingActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
	int i = v.getId();
	if (i == R.id.bu_setTime) {
		v.requestFocus();
		v.requestFocusFromTouch();
		setPushTime();

	}
}
 
Example 13
Source Project: Printer   File: InputMethodUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 打开输入法
 * 会使得view得到焦点
 *
 * @param view View
 */
@SuppressWarnings("unused")
public static void openInputMethod(View view) {
    if (null == view) {
        return;
    }
    view.requestFocus();
    view.requestFocusFromTouch();
    InputMethodManager imm = ((InputMethodManager) (view.getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE)));
    imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
 
Example 14
@Override
public boolean onTouch(View v, MotionEvent event) {
    v.getParent().requestDisallowInterceptTouchEvent(true);

    if(!mRegion.contains((int)event.getX(),(int) event.getY())) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_UP:
                if (mTouched) {
                    v.requestFocus();
                    v.requestFocusFromTouch();
                    if (mClickListener != null) {
                        mClickListener.onClick(v);
                    }
                }
                v.setPressed(false);
                mTouched = false;
        }

        return true;

    } else {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                v.setPressed(true);
                mTouched = true;
                return true;

            case MotionEvent.ACTION_UP:
                if (mTouched && ViewUtils.isInsideView(v, (int)event.getRawX(), (int)event.getRawY())) {
                    v.requestFocus();
                    v.requestFocusFromTouch();
                    if (mClickListener != null) {
                        mClickListener.onClick(v);
                    }
                }
                v.setPressed(false);
                mTouched = false;
                return true;

            case MotionEvent.ACTION_MOVE:
                return true;

            case MotionEvent.ACTION_CANCEL:
                v.setPressed(false);
                mTouched = false;
                return true;
        }

        return false;
    }
}
 
Example 15
@Override
public boolean onTouch(View v, MotionEvent event) {
    v.getParent().requestDisallowInterceptTouchEvent(true);

    if(!isInside(event)) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_UP:
                if (mTouched) {
                    v.requestFocus();
                    v.requestFocusFromTouch();
                    if (mClickListener != null) {
                        mClickListener.onClick(v);
                    }
                }
                v.setPressed(false);
                mTouched = false;
        }

        return true;

    } else {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                v.setPressed(true);
                mTouched = true;
                return true;

            case MotionEvent.ACTION_UP:
                if (mTouched && ViewUtils.isInsideView(v, (int)event.getRawX(), (int)event.getRawY())) {
                    v.requestFocus();
                    v.requestFocusFromTouch();
                    if (mClickListener != null) {
                        mClickListener.onClick(v);
                    }
                }
                v.setPressed(false);
                mTouched = false;
                return true;

            case MotionEvent.ACTION_MOVE:
                return true;

            case MotionEvent.ACTION_CANCEL:
                v.setPressed(false);
                mTouched = false;
                return true;
        }

        return false;
    }
}
 
Example 16
@Override
public void onClearHistory(@NonNull View view) {
    view.requestFocusFromTouch();
    showClearCacheDialog();
    hideContextMenu();
}
 
Example 17
@Override
public void onSyncHistory(@NonNull View view) {
    view.requestFocusFromTouch();
    mAccounts.syncNowAsync(SyncReason.User.INSTANCE, false);
}
 
Example 18
@Override
public void onFxASynSettings(@NonNull View view) {
    view.requestFocusFromTouch();
    mWidgetManager.getTray().showSettingsDialog(FXA);
}
 
Example 19
@Override
public void onSyncBookmarks(@NonNull View view) {
    view.requestFocusFromTouch();
    mAccounts.syncNowAsync(SyncReason.User.INSTANCE, false);
}
 
Example 20
@Override
public void onFxASynSettings(@NonNull View view) {
    view.requestFocusFromTouch();
    mWidgetManager.getTray().showSettingsDialog(FXA);
}