Java 类android.support.annotation.IdRes 实例源码

项目:GitHub    文件:BaseViewHolder.java   
/**
 * add childView id
 *
 * @param viewId add the child view id   can support childview click
 * @return if you use adapter bind listener
 * @link {(adapter.setOnItemChildClickListener(listener))}
 * <p>
 * or if you can use  recyclerView.addOnItemTouch(listerer)  wo also support this menthod
 */
@SuppressWarnings("unchecked")
public BaseViewHolder addOnClickListener(@IdRes final int viewId) {
    childClickViewIds.add(viewId);
    final View view = getView(viewId);
    if (view != null) {
        if (!view.isClickable()) {
            view.setClickable(true);
        }
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (adapter.getOnItemChildClickListener() != null) {
                    adapter.getOnItemChildClickListener().onItemChildClick(adapter, v, getClickPosition());
                }
            }
        });
    }

    return this;
}
项目:Xndroid    文件:BookmarksFragment.java   
private void setupNavigationButton(@NonNull View view, @IdRes int buttonId, @IdRes int imageId) {
    FrameLayout frameButton = view.findViewById(buttonId);
    frameButton.setOnClickListener(this);
    frameButton.setOnLongClickListener(this);
    ImageView buttonImage = view.findViewById(imageId);
    buttonImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
}
项目:MyEyepetizer    文件:MainActivity.java   
@Override
public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
    switch (checkedId) {
        case R.id.home_radio:
            changeFragment(HOME_RADIO_BUTTON_INDEX);
            break;
        case R.id.found_radio:
            changeFragment(FOUND_RADIO_BUTTON_INDEX);
            break;
        case R.id.follow_radio:
            changeFragment(FOLLOW_RADIO_BUTTON_INDEX);
            break;
        case R.id.mine_radio:
            changeFragment(MINE_RADIO_BUTTON_INDEX);
            break;
        default:
            break;
    }
}
项目:Cable-Android    文件:PassphraseRequiredActionBarActivity.java   
protected <T extends Fragment> T initFragment(@IdRes int target,
                                              @NonNull T fragment,
                                              @NonNull MasterSecret masterSecret,
                                              @Nullable Locale locale,
                                              @Nullable Bundle extras)
{
  Bundle args = new Bundle();
  args.putParcelable("master_secret", masterSecret);
  args.putSerializable(LOCALE_EXTRA, locale);

  if (extras != null) {
    args.putAll(extras);
  }

  fragment.setArguments(args);
  getSupportFragmentManager().beginTransaction()
                             .replace(target, fragment)
                             .commit();
  return fragment;
}
项目:HeadlineNews    文件:FragmentUtils.java   
/**
 * 新增多个fragment
 *
 * @param fragmentManager fragment管理器
 * @param fragments       fragments
 * @param containerId     布局Id
 * @param showIndex       要显示的fragment索引
 * @param lists           共享元素链表
 * @return 要显示的fragment
 */
public static Fragment addFragments(@NonNull final FragmentManager fragmentManager,
                                    @NonNull final List<Fragment> fragments,
                                    @IdRes final int containerId,
                                    final int showIndex,
                                    @NonNull final List<SharedElement>... lists) {
    for (int i = 0, size = fragments.size(); i < size; ++i) {
        Fragment fragment = fragments.get(i);
        List<SharedElement> list = lists[i];
        if (fragment != null) {
            if (list != null) {
                putArgs(fragment, new Args(containerId, showIndex != i, false));
                return operateFragment(fragmentManager, null, fragment, TYPE_ADD_FRAGMENT, list.toArray(new SharedElement[0]));
            }
        }
    }
    return fragments.get(showIndex);
}
项目:Android-UtilCode    文件:FragmentUtils.java   
/**
 * 新增多个fragment
 *
 * @param fragmentManager fragment管理器
 * @param fragments       fragments
 * @param containerId     布局Id
 * @param showIndex       要显示的fragment索引
 * @param lists           共享元素链表
 * @return 要显示的fragment
 */
public static Fragment addFragments(@NonNull FragmentManager fragmentManager,
                                    @NonNull List<Fragment> fragments,
                                    @IdRes int containerId,
                                    int showIndex,
                                    @NonNull List<SharedElement>... lists) {
    for (int i = 0, size = fragments.size(); i < size; ++i) {
        Fragment fragment = fragments.get(i);
        List<SharedElement> list = lists[i];
        if (fragment != null) {
            if (list != null) {
                putArgs(fragment, new Args(containerId, showIndex != i, false));
                return operateFragment(fragmentManager, null, fragment, TYPE_ADD_FRAGMENT, list.toArray(new SharedElement[0]));
            }
        }
    }
    return fragments.get(showIndex);
}
项目:CIA    文件:HomeTabbedActivity.java   
/**
 * set up the navigation tabs at the bottom of the screen
 * navigation items:
 *      dashboard
 *      search
 *      add new habit
 *      follow requests
 *      profile
 */
private void initializeBottomBar() {
    bottomBar = (BottomBar) findViewById(R.id.bottomBar);
    bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
        @Override
        public void onTabSelected(@IdRes int tabId) {
            switch (tabId) {
                case R.id.tab_dashboard:
                    onDashboardClicked();
                    break;
                case R.id.tab_search:
                    onSearchClicked();
                    break;
                case R.id.tab_addHabit:
                    break;
                case R.id.tab_followRequests:
                    onFollowRequestClicked();
                    break;
                case R.id.tab_profile:
                    onProfileClicked();
                    break;
            }
        }
    });

    bottomBar.setTabSelectionInterceptor(new TabSelectionInterceptor() {
        @Override
        public boolean shouldInterceptTabSelection(@IdRes int oldTabId, @IdRes int newTabId) {
            if (newTabId == R.id.tab_addHabit) {
                onAddHabitClicked();
                return true;
            }
            return false;
        }
    });
}
项目:CXJPadProject    文件:BActivity.java   
/**
     * 替换fragement 并添加动画
     * 替换fragement的同时对fragment进行“入back栈”操作 ,据我所知并不是真正的进入内存栈
     *
     * @param id_content
     * @param anim_in
     * @param anim_out
     * @param fragment
     */
    @Deprecated
    public void replaceFragmentWithBackStack(@IdRes int id_content, @AnimRes int anim_in, @AnimRes int anim_out, Fragment fragment) {
        String tag = fragment.getClass().getSimpleName();
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
//        transaction.setCustomAnimations(anim_in, anim_out);
        transaction.replace(id_content, fragment, tag);
        //记录commit一次操作,与mFragmentManager.popBackStack();匹配使用
        transaction.addToBackStack(tag);
        //commitAllowingStateLoss 优于 commit 方法,当使用commit方法时,系统将进行状态判断,如果状态(mStateSaved)已经保存,将发生"Can not perform this action after onSaveInstanceState"错误。
        //如果mNoTransactionsBecause已经存在,将发生"Can not perform this action inside of " + mNoTransactionsBecause错误。
        transaction.commitAllowingStateLoss();
    }
项目:UIKit-ViewBlock    文件:ViewBlock.java   
protected <T> T bindViewById(@IdRes int id) {
    //noinspection unchecked
    if (id < 0 || mBlockingView == null) {
        return null;
    }
    //noinspection unchecked
    return (T) mBlockingView.findViewById(id);
}
项目:MultiSelecter    文件:BaseViewHolder.java   
/**
 * Add an action to set the alpha of a view. Can be called multiple times.
 * Alpha between 0-1.
 */
public BaseViewHolder setAlpha(@IdRes int viewId, float value) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        getView(viewId).setAlpha(value);
    } else {
        // Pre-honeycomb hack to set Alpha value
        AlphaAnimation alpha = new AlphaAnimation(value, value);
        alpha.setDuration(0);
        alpha.setFillAfter(true);
        getView(viewId).startAnimation(alpha);
    }
    return this;
}
项目:garras    文件:BaseViewHolder.java   
@SuppressWarnings("unchecked")
public <T extends View> T getView(@IdRes int viewId) {
    View view = views.get(viewId);
    if (view == null) {
        view = itemView.findViewById(viewId);
        views.put(viewId, view);
    }
    return (T) view;
}
项目:q-mail    文件:PgpEnabledErrorDialog.java   
public static PgpEnabledErrorDialog newInstance(boolean isGotItDialog, @IdRes int showcaseView) {
    PgpEnabledErrorDialog dialog = new PgpEnabledErrorDialog();

    Bundle args = new Bundle();
    args.putInt(ARG_HIGHLIGHT_VIEW, showcaseView);
    args.putBoolean(ARG_IS_GOTIT, isGotItDialog);
    dialog.setArguments(args);

    return dialog;
}
项目:Stage    文件:DirectorTest.java   
@Test
public void testTarget() {
  ViewGroup container1 = new TestContainer(RuntimeEnvironment.application);
  ViewGroup container2 = new TestContainer(RuntimeEnvironment.application);
  @IdRes int containerId1 = 1;
  @IdRes int containerId2 = 2;
  container1.setId(containerId1);
  container2.setId(containerId2);

  Stage stage1 = director.direct(container1);
  Stage stage2 = director.direct(container2);

  Scene scene1 = new TestScene();
  Scene scene2 = new TestScene();
  stage1.pushScene(scene1);
  stage1.pushScene(scene2);

  Scene scene3 = new TestScene();
  Scene scene4 = new TestScene();
  stage2.pushScene(scene3);
  stage2.pushScene(scene4);

  Director director2 = scene2.hireChildDirector();
  Stage stage3 = director2.direct(new TestContainer(RuntimeEnvironment.application));
  Scene scene5 = new TestScene();
  stage3.pushScene(scene5);

  Director director3 = scene3.hireChildDirector();
  Stage stage4 = director3.direct(new TestContainer(RuntimeEnvironment.application));
  Scene scene6 = new TestScene();
  stage4.pushScene(scene6);

  scene5.setTarget(scene6);
  assertEquals(scene6, scene5.getTarget());
}
项目:GitHub    文件:MediaVariationsFragment.java   
Size(
    @IdRes int thumbViewId,
    String name,
    String extension,
    int width,
    int height,
    CacheChoice cacheChoice) {
  this.thumbViewId = thumbViewId;
  this.name = name;
  this.uri = Uri.parse(String.format(URI_TEMPLATE, name, extension));
  this.width = width;
  this.height = height;
  this.cacheChoice = cacheChoice;
}
项目:GitHub    文件:Utils.java   
public static <T> T castView(View view, @IdRes int id, String who, Class<T> cls) {
  try {
    return cls.cast(view);
  } catch (ClassCastException e) {
    String name = getResourceEntryName(view, id);
    throw new IllegalStateException("View '"
        + name
        + "' with ID "
        + id
        + " for "
        + who
        + " was of the wrong type. See cause for more info.", e);
  }
}
项目:RLibrary    文件:RModelAdapter.java   
/**
 * 在执行 {@link #onUnSelectorPosition(RBaseViewHolder, int, boolean)}后, 调用此方法, 可以便捷的取消 CompoundButton 的状态
 */
public void unSelector(@NonNull List<Integer> list, @NonNull RRecyclerView recyclerView, @IdRes int viewId) {
    boolean notify = false;

    for (Integer pos : list) {
        removeSelectorPosition(pos);
        RBaseViewHolder vh = (RBaseViewHolder) recyclerView.findViewHolderForAdapterPosition(pos);
        if (vh != null) {
            final View view = vh.v(viewId);
            if (view != null) {
                if (view instanceof CompoundButton) {
                    checkedButton((CompoundButton) view, false);
                } else if (view instanceof RCheckGroup.ICheckView) {
                    ((RCheckGroup.ICheckView) view).setChecked(false);
                }
                notify = true;
            }
        } else {
            notifyItemChanged(pos);
        }
    }

    if (notify) {
        //防止在视图还没有加载的时候,通知事件
        notifySelectorChange();
    }
}
项目:garras    文件:BaseViewHolder.java   
/**
 * Sets the checked status of a checkable.
 *
 * @param viewId  The view id.
 * @param checked The checked status;
 * @return The BaseViewHolder for chaining.
 */
public BaseViewHolder setChecked(@IdRes int viewId, boolean checked) {
    View view = getView(viewId);
    // View unable cast to Checkable
    if (view instanceof Checkable) {
        ((Checkable) view).setChecked(checked);
    }
    return this;
}
项目:anitrend-app    文件:MarkdownInputEditor.java   
/**
 * Used to get the correct selection end range depending on the text size
 * of the preferred mark_down styling.
 *
 * @param selection The menu item from the selection mode
 * @return end selection size with applied offset
 */
private int getSelectionEnd(@IdRes int selection) {
    int end = getSelectionEnd();
    final int init_end = getSelectionEnd();
    switch (selection) {
        case R.id.menu_bold:
            end += MD_BOLD.length();
            break;
        case R.id.menu_italic:
            end += MD_ITALIC.length();
            break;
        case R.id.menu_strike:
            end += MD_STRIKE.length();
            break;
        case R.id.menu_list:
            end += MD_NUMBER.length();
            break;
        case R.id.menu_bullet:
            end += MD_BULLET.length();
            break;
        case R.id.menu_heading:
            end += MD_HEADING.length();
            break;
        case R.id.menu_center:
            end += MD_CENTER_ALIGN.length();
            break;
        case R.id.menu_quote:
            end += MD_QUOTE.length();
            break;
        case R.id.menu_code:
            end += MD_CODE.length();
            break;
    }
    // Rare case but if it ever happens reduce end by 1
    final int text_length = getText().length();
    if(end > text_length + (end - init_end))
        end -= (end - init_end) - 1;
    return end;
}
项目:FriendBook    文件:BaseActivity.java   
public void bindOnClickLister(View.OnClickListener listener, @IdRes int... ids) {
    for (int id : ids) {
        View view = findViewById(id);
        if (view != null) {
            view.setOnClickListener(listener);
        }
    }
}
项目:RendererRecyclerViewAdapter    文件:ViewFinderImpl.java   
@NonNull
private View findViewById(@IdRes final int ID) {
    final View cachedView = mCachedViews.get(ID);
    if (cachedView != null) {
        return cachedView;
    }
    final View view = mItemView.findViewById(ID);
    mCachedViews.put(ID, view);
    return view;
}
项目:JKCloud    文件:SwipeBackAppCompatActivity.java   
@Override
public View findViewById(@IdRes int id) {
    View v = super.findViewById(id);
    if (v == null && mHelper != null) {
        return mHelper.findViewById(id);
    }
    return v;

}
项目:GitHub    文件:paginator.java   
protected void getProgressbar(View view, @IdRes final int progress_bar_id) {
    try {
        mProgress = (ProgressBar) view.findViewById(progress_bar_id);
    } catch (Exception e) {
        //unable to find loading progress bar
    }
}
项目:Kutuk    文件:ObjectDetailActivity.java   
private void setupFloatingButton(@IdRes int id, IconValue value, View.OnClickListener listener) {
    FloatingActionButton button = (FloatingActionButton) findViewById(id);
    button.setImageDrawable(
            MaterialDrawableBuilder.with(this)
                    .setIcon(value)
                    .setColorResource(R.color.text_light)
                    .build()
    );
    button.setOnClickListener(listener);
}
项目:ascii_generate    文件:ArtViewGroup.java   
public void create(int row, int col) {
    removeAllViews();

    int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2,
            getResources().getDisplayMetrics());


    this.row = row;
    this.col = col;
    @IdRes int id = 1;
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            ArtTextView artTextView = new ArtTextView(getContext());
            LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            artTextView.setId(id);
            artTextView.setText(Char.SPACE);
            if (j == 0) {
                params.addRule(ALIGN_PARENT_LEFT, TRUE);
            } else {
                params.addRule(RIGHT_OF, id - 1);
            }
            if (i == 0) {
                params.addRule(ALIGN_PARENT_TOP, TRUE);
            } else {
                params.addRule(BELOW, id - col);
            }
            params.setMargins(margin, 0, margin, 0);
            artTextView.setLayoutParams(params);
            addView(artTextView);
            id++;
        }
    }

}
项目:QiangHongBao    文件:LViewHolder.java   
/** 通过ViewId获取控件 */
public <T extends View> T getView(@IdRes int viewId) {
    View view = mViews.get(viewId);
    if (view == null) {
        view = mRootView.findViewById(viewId);
        mViews.put(viewId, view);
    }
    return (T) view;
}
项目:QiangHongBao    文件:BottomBar.java   
/**
 * Set the default selected to be the tab with the corresponding tab id.
 * By default, the first tab in the container is the default tab.
 */
public void setDefaultTab(@IdRes int defaultTabId) {
    int defaultTabPosition = findPositionForTabWithId(defaultTabId);
    setDefaultTabPosition(defaultTabPosition);
}
项目:SuperRecyclerViewAdapter    文件:SuperRecyclerHolder.java   
public SuperRecyclerHolder setOnClickListenner(@IdRes int viewId,
    @Nullable View.OnClickListener listener) {
    retrieveView(viewId).setOnClickListener(listener);
    return this;
}
项目:OpenEyesReading-android    文件:BaseActivity.java   
public void setToolbarTitle(@IdRes int titleId) {
    TextView textView = (TextView) findViewById(titleId);
    if (textView != null) textView.setText(mToolbarTitle);
}
项目:XFrame    文件:XViewHolder.java   
public XViewHolder linkify(@IdRes int viewId) {
    TextView view = getView(viewId);
    Linkify.addLinks(view, Linkify.ALL);
    return this;
}
项目:XFrame    文件:XViewHolder.java   
public XViewHolder setBackgroundColor(@IdRes int viewId, int color) {
    View view = getView(viewId);
    view.setBackgroundColor(color);
    return this;
}
项目:RLibrary    文件:RModelAdapter.java   
/**
 * 选中所有
 */
public void setSelectorAll(@NonNull RRecyclerView recyclerView, @IdRes int viewId) {
    setSelectedList(recyclerView, viewId, getAllDatas());
}
项目:Android-Code-Demos    文件:BaseSimpleViewHolder.java   
public void setVisible(@IdRes int id, boolean visible) {
    getView(id).setVisibility(visible ? View.VISIBLE : View.GONE);
}
项目:AndroidViewHelper    文件:AndroidViewHelper.java   
public static EditTextHelper editText(@NonNull Activity activity, @IdRes int
        viewId) {
    return new EditTextHelper((EditText) findView(activity, viewId));
}
项目:PeSanKita-android    文件:ViewUtil.java   
@SuppressWarnings("unchecked")
public static <T extends View> T findById(@NonNull Activity parent, @IdRes int resId) {
  return (T) parent.findViewById(resId);
}
项目:mvvm-template    文件:BaseSingleFragmentActivity.java   
@IdRes
    protected int getContainerId() {
//        return R.id.container;
        return 0;
    }
项目:godlibrary    文件:ListViewRefresh.java   
public void setHeaderView(ViewGroup view, @IdRes int StateId, @IdRes int ImageViewId, @IdRes int ProgressBarId) {
    mProgressBar = (ProgressBar) view.findViewById(ProgressBarId);
    ivArrow = (ImageView) view.findViewById(ImageViewId);
    tvState = (TextView) view.findViewById(StateId);
    initHeaderView(view);
}
项目:CustomFormViews    文件:ValidityClassBase.java   
@SuppressWarnings("unchecked") protected <T> T getView(@IdRes int viewId, Class<T> aClass) {
    for (ValidityBase base : validators) {
        if (base.getId() == viewId && aClass.isInstance(base)) return (T) base;
    }
    return null;
}
项目:AndroidViewHelper    文件:AndroidViewHelper.java   
public static TableLayoutHelper tableLayout(@NonNull View view, @IdRes int viewId) {
    return new TableLayoutHelper((TableLayout) findView(view, viewId));
}
项目:XFrame    文件:XViewHolder.java   
public XViewHolder setProgress(@IdRes int viewId, int progress) {
    ProgressBar view = getView(viewId);
    view.setProgress(progress);
    return this;
}
项目:Mvvm    文件:MvvmActivity.java   
protected final <V extends View> V $(@IdRes int id) {
    return Utils.getView(this, id);
}