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

The following examples show how to use android.view.View#requestFocusFromTouch() . 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
Source File: ObservationEditActivity.java    From mage-android with Apache License 2.0 6 votes vote down vote up
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
Source File: InputMethodUtils.java    From Printer with 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 3
Source File: TKeybord.java    From Upchain-wallet with GNU Affero General Public License v3.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 4
Source File: SettingActivity.java    From HaiNaBaiChuan with 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 5
Source File: IMMLeaks.java    From diycode with 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 6
Source File: BasicActivity.java    From letv with 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 7
Source File: IMEService.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
	clickButton(v, true);
	if(v.getId() != R.id.btnClose) {
		v.requestFocusFromTouch();
		focusedView = v;
	}
}
 
Example 8
Source File: IMMLeaks.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
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
Source File: BookmarksView.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
@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 10
Source File: DownloadsView.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
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 11
Source File: InputMethodUtils.java    From ProjectX with 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 12
Source File: HistoryView.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
@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 13
Source File: ViewUtils.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
@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 14
Source File: BookmarksView.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onSyncBookmarks(@NonNull View view) {
    view.requestFocusFromTouch();
    mAccounts.syncNowAsync(SyncReason.User.INSTANCE, false);
}
 
Example 15
Source File: HistoryView.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onFxASynSettings(@NonNull View view) {
    view.requestFocusFromTouch();
    mWidgetManager.getTray().showSettingsDialog(FXA);
}
 
Example 16
Source File: BookmarksView.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onFxASynSettings(@NonNull View view) {
    view.requestFocusFromTouch();
    mWidgetManager.getTray().showSettingsDialog(FXA);
}
 
Example 17
Source File: HistoryView.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onSyncHistory(@NonNull View view) {
    view.requestFocusFromTouch();
    mAccounts.syncNowAsync(SyncReason.User.INSTANCE, false);
}
 
Example 18
Source File: HistoryView.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onClearHistory(@NonNull View view) {
    view.requestFocusFromTouch();
    showClearCacheDialog();
    hideContextMenu();
}
 
Example 19
Source File: VectorClippedEventDelegate.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
@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 20
Source File: ClippedEventDelegate.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
@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;
    }
}