androidx.annotation.IdRes Java Examples

The following examples show how to use androidx.annotation.IdRes. 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: PlaceAndPhotoTestActivity.java    From android-places-demos with Apache License 2.0 6 votes vote down vote up
@Nullable
private Integer readIntFromTextView(@IdRes int resId) {
  Integer intValue = null;
  View view = findViewById(resId);

  if (view instanceof TextView) {
    CharSequence contents = ((TextView) view).getText();
    if (!TextUtils.isEmpty(contents)) {
      try {
        intValue = Integer.parseInt(contents.toString());
      } catch (NumberFormatException e) {
        showErrorAlert(R.string.error_alert_message_invalid_photo_size);
      }
    }
  }

  return intValue;
}
 
Example #2
Source File: AppProgressDialog.java    From hash-checker with Apache License 2.0 6 votes vote down vote up
@SuppressLint("ResourceType")
@NonNull
public static ProgressDialog getDialog(
        @NonNull Context context,
        @IdRes int textMessageResId
) {
    android.app.ProgressDialog progressDialog
            = new android.app.ProgressDialog(context);
    progressDialog.setMessage(
            context.getString(
                    textMessageResId
            )
    );
    progressDialog.setIndeterminate(false);
    progressDialog.setCancelable(false);
    progressDialog.getWindow().setBackgroundDrawable(
            new ColorDrawable(
                    UIUtils.getCommonBackgroundColor(
                            context
                    )
            )
    );
    return progressDialog;
}
 
Example #3
Source File: RadioGroupSetting.java    From FirefoxReality with Mozilla Public License 2.0 6 votes vote down vote up
public void setChecked(@IdRes int checkedId, boolean doApply) {
    mRadioGroup.setOnCheckedChangeListener(null);
    for (int i=0; i<mRadioGroup.getChildCount(); i++) {
        RadioButton button = (RadioButton) mRadioGroup.getChildAt(i);
        if (i == checkedId) {
            button.setChecked(true);

        } else {
            button.setChecked(false);
        }
    }
    mRadioGroup.setOnCheckedChangeListener(mInternalRadioListener);

    if (mRadioGroupListener != null && doApply) {
        mRadioGroupListener.onCheckedChanged(mRadioGroup, checkedId, doApply);
    }
}
 
Example #4
Source File: PlaceAndPhotoTestActivity.java    From android-places-demos with Apache License 2.0 6 votes vote down vote up
@Nullable
private Integer readIntFromTextView(@IdRes int resId) {
  Integer intValue = null;
  View view = findViewById(resId);

  if (view instanceof TextView) {
    CharSequence contents = ((TextView) view).getText();
    if (!TextUtils.isEmpty(contents)) {
      try {
        intValue = Integer.parseInt(contents.toString());
      } catch (NumberFormatException e) {
        showErrorAlert(R.string.error_alert_message_invalid_photo_size);
      }
    }
  }

  return intValue;
}
 
Example #5
Source File: MainFragment.java    From AndroidFastScroll with Apache License 2.0 5 votes vote down vote up
private void setNavigationCheckedItem(@IdRes int itemId) {
    MenuItem item = mNavigationView.getCheckedItem();
    if (item != null && item.getItemId() == itemId) {
        return;
    }
    Fragment fragment;
    switch (itemId) {
        case R.id.recycler_view_list:
            fragment = RecyclerViewListFragment.newInstance();
            break;
        case R.id.recycler_view_list_classic:
            fragment = RecyclerViewListClassicFragment.newInstance();
            break;
        case R.id.recycler_view_list_stateful:
            fragment = RecyclerViewListStatefulFragment.newInstance();
            break;
        case R.id.recycler_view_grid:
            fragment = RecyclerViewGridFragment.newInstance();
            break;
        case R.id.scroll_view:
            fragment = ScrollViewFragment.newInstance();
            break;
        case R.id.nested_scroll_view:
            fragment = NestedScrollViewFragment.newInstance();
            break;
        case R.id.web_view:
            fragment = WebViewFragment.newInstance();
            break;
        default:
            throw new AssertionError(itemId);
    }
    getChildFragmentManager().beginTransaction()
            .replace(R.id.content, fragment)
            .commit();
    mNavigationView.setCheckedItem(itemId);
}
 
Example #6
Source File: ViewUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化 View
 * @param activity {@link Activity}
 * @param id       R.id.viewId
 * @param <T>      泛型
 * @return {@link View}
 */
public static <T extends View> T findViewById(final Activity activity, @IdRes final int id) {
    if (activity != null) {
        try {
            return activity.findViewById(id);
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "findViewById");
        }
    }
    return null;
}
 
Example #7
Source File: DynamicSystemActivity.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the shared element according to the given id.
 *
 * @param resultCode The transition result code.
 * @param position The position of the shared element.
 * @param viewId The id resource to find the view by id.
 *
 * @return The view according to the view id.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
protected @Nullable View getSharedElement(int resultCode, int position,
        @NonNull String transition, @IdRes int viewId) {
    View view = mDynamicTransitionListener == null ? findViewById(viewId)
            : mDynamicTransitionListener.onFindView(resultCode, position, transition, viewId);

    if (view != null) {
        view.setTag(null);
    }

    return view;
}
 
Example #8
Source File: HelpFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
static Feeling getByViewId(@IdRes int viewId) {
  for (Feeling feeling : values()) {
    if (feeling.viewId == viewId) {
      return feeling;
    }
  }

  throw new AssertionError();
}
 
Example #9
Source File: ConnectionFragment.java    From Aria2App with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onFieldError(@IdRes int fieldId, String reason) {
    if (layout == null) return;

    TextInputLayout inputLayout = layout.findViewById(fieldId);
    if (inputLayout != null) {
        inputLayout.setErrorEnabled(true);
        inputLayout.setError(reason);
    }
}
 
Example #10
Source File: UniversalAdapter.java    From pandora with Apache License 2.0 5 votes vote down vote up
public <T extends View> T getView(@IdRes int id) {
    if (id == View.NO_ID) {
        throw new RuntimeException("id is invalid");
    }
    View view = views.get(id);
    if (view == null) {
        view = itemView.findViewById(id);
        views.put(id, view);
    }
    return (T) view;
}
 
Example #11
Source File: BaseDialog.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * 设置点击事件
 */
public B setOnClickListener(@IdRes int id, @NonNull BaseDialog.OnClickListener listener) {
    if (isCreated()) {
        View view = mDialog.findViewById(id);
        if (view != null) {
            view.setOnClickListener(new ViewClickWrapper(mDialog, listener));
        }
    } else {
        if (mClickArray == null) {
            mClickArray = new SparseArray<>();
        }
        mClickArray.put(id, listener);
    }
    return (B) this;
}
 
Example #12
Source File: ViewSwitcherLayout.java    From SAI with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Show the view with {@code viewId} id and hide all others
 */
public void setShownView(@IdRes int viewId) {
    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        child.setVisibility(child.getId() == viewId ? VISIBLE : GONE);
    }
}
 
Example #13
Source File: BaseDialog.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * 根据 id 查找 View
 */
@Override
public  <V extends View> V findViewById(@IdRes int id) {
    if (mContentView == null) {
        // 没有 setContentView 就想 findViewById ?
        throw new IllegalStateException("are you ok?");
    }
    return mContentView.findViewById(id);
}
 
Example #14
Source File: GroupSettingsCoordinatorLayoutBehavior.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
private static @NonNull View getChildOrThrow(@NonNull View parent, @IdRes int id) {
  View child = parent.findViewById(id);

  if (child == null) {
    throw new AssertionError("Can't find view with ID " + R.id.avatar_target);
  } else {
    return child;
  }
}
 
Example #15
Source File: UIUtils.java    From hash-checker with Apache License 2.0 5 votes vote down vote up
private static int getColorFromAttrs(
        @NonNull Context context,
        @IdRes int themeColor
) {
    TypedValue typedValue = new TypedValue();
    Resources.Theme theme = context.getTheme();
    theme.resolveAttribute(
            themeColor,
            typedValue,
            true
    );
    return typedValue.data;
}
 
Example #16
Source File: ImmersionBar.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 解决状态栏与布局顶部重叠又多了种方法,只支持Activity
 * Title bar immersion bar.
 *
 * @param viewId the view id
 * @return the immersion bar
 */
public ImmersionBar titleBar(@IdRes int viewId) {
    View view = mActivity.findViewById(viewId);
    if (view == null) {
        throw new IllegalArgumentException("参数错误");
    }
    return titleBar(view, true);
}
 
Example #17
Source File: ViewUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 设置向左移动焦点时, 下一个获取焦点的 View id
 * @param view            {@link View}
 * @param nextFocusLeftId 下一个获取焦点的 View id
 * @return {@link View}
 */
public static View setNextFocusLeftId(final View view, @IdRes final int nextFocusLeftId) {
    if (view != null) {
        view.setNextFocusLeftId(nextFocusLeftId);
    }
    return view;
}
 
Example #18
Source File: ListenerUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 设置长按事件
 * @param activity            {@link Activity}
 * @param onLongClickListener {@link View.OnLongClickListener}
 * @param viewIds             View id 数组
 * @return {@code true} success, {@code false} fail
 */
public static boolean setOnLongClicks(final Activity activity, final View.OnLongClickListener onLongClickListener, @IdRes final int... viewIds) {
    if (activity != null && onLongClickListener != null && viewIds != null) {
        for (int i = 0, len = viewIds.length; i < len; i++) {
            View findView = ViewUtils.findViewById(activity, viewIds[i]);
            if (findView != null) {
                findView.setOnLongClickListener(onLongClickListener);
            }
        }
        return true;
    }
    return false;
}
 
Example #19
Source File: StickerCache.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
public Bitmap getSrcBitmap(Resources resources, @IdRes int resId) {
    String path = String.valueOf(resId);
    Bitmap bitmap = srcBitmapCache.get(path);
    if (null == bitmap) {
        bitmap = BitmapFactory.decodeResource(resources, resId);
        srcBitmapCache.put(path, bitmap);
        bitmapUsedCount.put(path, 0);
        convertMirror(path, bitmap);
    }

    int count = bitmapUsedCount.get(path);
    bitmapUsedCount.put(path, ++count);
    return bitmap;
}
 
Example #20
Source File: BaseScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
/**
 * @param resId 0 for clear
 */
public void setNavCheckedItem(@IdRes int resId) {
    FragmentActivity activity = getActivity();
    if (activity instanceof MainActivity) {
        ((MainActivity) activity).setNavCheckedItem(resId);
    }
}
 
Example #21
Source File: PuzzleActivity.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
private void toggleIvMenu(@IdRes int resId) {
    for (ImageView ivMenu : ivMenus) {
        if (ivMenu.getId() == resId) {
            ivMenu.setColorFilter(ContextCompat.getColor(this, R.color.easy_photos_fg_accent));
        } else {
            ivMenu.clearColorFilter();
        }
    }

}
 
Example #22
Source File: ViewUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 设置下一个获取焦点的 View id
 * @param view               {@link View}
 * @param nextFocusForwardId 下一个获取焦点的 View id
 * @return {@link View}
 */
public static View setNextFocusForwardId(final View view, @IdRes final int nextFocusForwardId) {
    if (view != null) {
        view.setNextFocusForwardId(nextFocusForwardId);
    }
    return view;
}
 
Example #23
Source File: BaseArrayAdapter.java    From lrkFM with MIT License 5 votes vote down vote up
/**
 * Sets file name in the text field of a dialog.
 *
 * @param alertDialog     the dialog
 * @param destinationName the id of the EditText
 * @param name            the name
 */
public void presetNameForDialog(AlertDialog alertDialog, @IdRes int destinationName, String name) {
    EditText editText = alertDialog.findViewById(destinationName);
    if (editText != null) {
        editText.setText(name);
    } else {
        Log.w(TAG, "Unable to find view, can not set file title.");
    }
}
 
Example #24
Source File: ImmersionBar.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 通过状态栏高度动态设置状态栏布局,只能在Activity中使用
 *
 * @param viewId the view id
 * @return the immersion bar
 */
public ImmersionBar statusBarView(@IdRes int viewId) {
    View view = mActivity.findViewById(viewId);
    if (view == null) {
        throw new IllegalArgumentException("未找到viewId");
    }
    return statusBarView(view);
}
 
Example #25
Source File: ImmersionBar.java    From a with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 解决状态栏与布局顶部重叠又多了种方法,只支持Activity
 * Title bar immersion bar.
 *
 * @param viewId the view id
 * @return the immersion bar
 */
public ImmersionBar titleBar(@IdRes int viewId) {
    View view = mActivity.findViewById(viewId);
    if (view == null) {
        throw new IllegalArgumentException("参数错误");
    }
    return titleBar(view, true);
}
 
Example #26
Source File: ImmersionBar.java    From a with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Title bar immersion bar.
 *
 * @param viewId        the view id
 * @param statusBarFlag the status bar flag
 * @return the immersion bar
 */
public ImmersionBar titleBar(@IdRes int viewId, boolean statusBarFlag) {
    View view = mActivity.findViewById(viewId);
    if (view == null) {
        throw new IllegalArgumentException("参数错误");
    }
    return titleBar(view, statusBarFlag);
}
 
Example #27
Source File: ImmersionBar.java    From a with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Title bar immersion bar.
 *
 * @param viewId   the view id
 * @param rootView the root view
 * @return the immersion bar
 */
public ImmersionBar titleBar(@IdRes int viewId, View rootView) {
    View view = rootView.findViewById(viewId);
    if (view == null) {
        throw new IllegalArgumentException("参数错误");
    }
    return titleBar(view, true);
}
 
Example #28
Source File: ImmersionBar.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Title bar immersion bar.
 *
 * @param viewId        the view id
 * @param statusBarFlag the status bar flag
 * @return the immersion bar
 */
public ImmersionBar titleBar(@IdRes int viewId, boolean statusBarFlag) {
    View view = mActivity.findViewById(viewId);
    if (view == null) {
        throw new IllegalArgumentException("参数错误");
    }
    return titleBar(view, statusBarFlag);
}
 
Example #29
Source File: PlaceAndPhotoTestActivity.java    From android-places-demos with Apache License 2.0 4 votes vote down vote up
private void setEnabled(@IdRes int resId, boolean enabled) {
  TextView view = findViewById(resId);
  view.setEnabled(enabled);
  view.setText("");
}
 
Example #30
Source File: BasePopupWindow.java    From AndroidProject with Apache License 2.0 4 votes vote down vote up
/**
 * 设置图片
 */
public B setImageDrawable(@IdRes int viewId, @DrawableRes int drawableId) {
    return setBackground(viewId, ContextCompat.getDrawable(mContext, drawableId));
}