类androidx.annotation.IdRes源码实例Demo

下面列出了怎么用androidx.annotation.IdRes的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: FirefoxReality   文件: RadioGroupSetting.java
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);
    }
}
 
@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;
}
 
@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;
}
 
源代码4 项目: hash-checker   文件: AppProgressDialog.java
@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;
}
 
源代码5 项目: dynamic-support   文件: DynamicSystemActivity.java
/**
 * 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;
}
 
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;
  }
}
 
源代码7 项目: mollyim-android   文件: HelpFragment.java
static Feeling getByViewId(@IdRes int viewId) {
  for (Feeling feeling : values()) {
    if (feeling.viewId == viewId) {
      return feeling;
    }
  }

  throw new AssertionError();
}
 
源代码8 项目: AndroidProject   文件: BaseDialog.java
/**
 * 根据 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);
}
 
源代码9 项目: SAI   文件: ViewSwitcherLayout.java
/**
 * 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);
    }
}
 
源代码10 项目: DevUtils   文件: ViewUtils.java
/**
 * 初始化 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;
}
 
源代码11 项目: DevUtils   文件: ListenerUtils.java
/**
 * 设置长按事件
 * @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;
}
 
源代码12 项目: EasyPhotos   文件: StickerCache.java
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;
}
 
源代码13 项目: EasyPhotos   文件: PuzzleActivity.java
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();
        }
    }

}
 
源代码14 项目: DevUtils   文件: ViewUtils.java
/**
 * 设置下一个获取焦点的 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;
}
 
源代码15 项目: lrkFM   文件: BaseArrayAdapter.java
/**
 * 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.");
    }
}
 
源代码16 项目: MyBookshelf   文件: ImmersionBar.java
/**
 * 通过状态栏高度动态设置状态栏布局,只能在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);
}
 
源代码17 项目: a   文件: ImmersionBar.java
/**
 * 解决状态栏与布局顶部重叠又多了种方法,只支持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);
}
 
源代码18 项目: a   文件: ImmersionBar.java
/**
 * 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);
}
 
源代码19 项目: a   文件: ImmersionBar.java
/**
 * 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);
}
 
源代码20 项目: AndroidFastScroll   文件: MainFragment.java
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);
}
 
源代码21 项目: MHViewer   文件: BaseScene.java
/**
 * @param resId 0 for clear
 */
public void setNavCheckedItem(@IdRes int resId) {
    FragmentActivity activity = getActivity();
    if (activity instanceof MainActivity) {
        ((MainActivity) activity).setNavCheckedItem(resId);
    }
}
 
源代码22 项目: DevUtils   文件: ViewUtils.java
/**
 * 设置向左移动焦点时, 下一个获取焦点的 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;
}
 
源代码23 项目: MyBookshelf   文件: ImmersionBar.java
/**
 * 解决状态栏与布局顶部重叠又多了种方法,只支持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);
}
 
源代码24 项目: MyBookshelf   文件: ImmersionBar.java
/**
 * 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);
}
 
源代码25 项目: hash-checker   文件: UIUtils.java
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;
}
 
源代码26 项目: pandora   文件: UniversalAdapter.java
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;
}
 
源代码27 项目: AndroidProject   文件: BaseDialog.java
/**
 * 设置点击事件
 */
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;
}
 
源代码28 项目: Aria2App   文件: ConnectionFragment.java
@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);
    }
}
 
源代码29 项目: AndroidProject   文件: BaseDialog.java
/**
 * 设置图片
 */
public B setImageDrawable(@IdRes int viewId, @DrawableRes int drawableId) {
    return setBackground(viewId, ContextCompat.getDrawable(mContext, drawableId));
}
 
private ViewRef(@IdRes int idRes) {
  this.idRes = idRes;
}