Java Code Examples for android.support.annotation.IdRes

The following are top voted examples for showing how to use android.support.annotation.IdRes. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: BaseViewHolder.java   View source code 7 votes vote down vote up
/**
 * 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;
}
 
Example 2
Project: Xndroid   File: BookmarksFragment.java   View source code 6 votes vote down vote up
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);
}
 
Example 3
Project: MyEyepetizer   File: MainActivity.java   View source code 6 votes vote down vote up
@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;
    }
}
 
Example 4
Project: Cable-Android   File: PassphraseRequiredActionBarActivity.java   View source code 6 votes vote down vote up
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;
}
 
Example 5
Project: HeadlineNews   File: FragmentUtils.java   View source code 6 votes vote down vote up
/**
 * 新增多个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);
}
 
Example 6
Project: Android-UtilCode   File: FragmentUtils.java   View source code 6 votes vote down vote up
/**
 * 新增多个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);
}
 
Example 7
Project: CIA   File: HomeTabbedActivity.java   View source code 5 votes vote down vote up
/**
 * 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;
        }
    });
}
 
Example 8
Project: CXJPadProject   File: BActivity.java   View source code 5 votes vote down vote up
/**
     * 替换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();
    }
 
Example 9
Project: UIKit-ViewBlock   File: ViewBlock.java   View source code 5 votes vote down vote up
protected <T> T bindViewById(@IdRes int id) {
    //noinspection unchecked
    if (id < 0 || mBlockingView == null) {
        return null;
    }
    //noinspection unchecked
    return (T) mBlockingView.findViewById(id);
}
 
Example 10
Project: MultiSelecter   File: BaseViewHolder.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 11
Project: garras   File: BaseViewHolder.java   View source code 5 votes vote down vote up
@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;
}
 
Example 12
Project: q-mail   File: PgpEnabledErrorDialog.java   View source code 5 votes vote down vote up
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;
}
 
Example 13
Project: Stage   File: DirectorTest.java   View source code 5 votes vote down vote up
@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());
}
 
Example 14
Project: GitHub   File: MediaVariationsFragment.java   View source code 5 votes vote down vote up
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;
}
 
Example 15
Project: GitHub   File: Utils.java   View source code 5 votes vote down vote up
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);
  }
}
 
Example 16
Project: RLibrary   File: RModelAdapter.java   View source code 5 votes vote down vote up
/**
 * 在执行 {@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();
    }
}
 
Example 17
Project: garras   File: BaseViewHolder.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 18
Project: anitrend-app   File: MarkdownInputEditor.java   View source code 5 votes vote down vote up
/**
 * 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;
}
 
Example 19
Project: FriendBook   File: BaseActivity.java   View source code 5 votes vote down vote up
public void bindOnClickLister(View.OnClickListener listener, @IdRes int... ids) {
    for (int id : ids) {
        View view = findViewById(id);
        if (view != null) {
            view.setOnClickListener(listener);
        }
    }
}
 
Example 20
Project: RendererRecyclerViewAdapter   File: ViewFinderImpl.java   View source code 5 votes vote down vote up
@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;
}
 
Example 21
Project: JKCloud   File: SwipeBackAppCompatActivity.java   View source code 5 votes vote down vote up
@Override
public View findViewById(@IdRes int id) {
    View v = super.findViewById(id);
    if (v == null && mHelper != null) {
        return mHelper.findViewById(id);
    }
    return v;

}
 
Example 22
Project: GitHub   File: paginator.java   View source code 5 votes vote down vote up
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
    }
}
 
Example 23
Project: Kutuk   File: ObjectDetailActivity.java   View source code 5 votes vote down vote up
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);
}
 
Example 24
Project: ascii_generate   File: ArtViewGroup.java   View source code 5 votes vote down vote up
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++;
        }
    }

}
 
Example 25
Project: QiangHongBao   File: LViewHolder.java   View source code 5 votes vote down vote up
/** 通过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;
}
 
Example 26
Project: QiangHongBao   File: BottomBar.java   View source code 4 votes vote down vote up
/**
 * 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);
}
 
Example 27
Project: SuperRecyclerViewAdapter   File: SuperRecyclerHolder.java   View source code 4 votes vote down vote up
public SuperRecyclerHolder setOnClickListenner(@IdRes int viewId,
    @Nullable View.OnClickListener listener) {
    retrieveView(viewId).setOnClickListener(listener);
    return this;
}
 
Example 28
Project: OpenEyesReading-android   File: BaseActivity.java   View source code 4 votes vote down vote up
public void setToolbarTitle(@IdRes int titleId) {
    TextView textView = (TextView) findViewById(titleId);
    if (textView != null) textView.setText(mToolbarTitle);
}
 
Example 29
Project: XFrame   File: XViewHolder.java   View source code 4 votes vote down vote up
public XViewHolder linkify(@IdRes int viewId) {
    TextView view = getView(viewId);
    Linkify.addLinks(view, Linkify.ALL);
    return this;
}
 
Example 30
Project: XFrame   File: XViewHolder.java   View source code 4 votes vote down vote up
public XViewHolder setBackgroundColor(@IdRes int viewId, int color) {
    View view = getView(viewId);
    view.setBackgroundColor(color);
    return this;
}
 
Example 31
Project: RLibrary   File: RModelAdapter.java   View source code 4 votes vote down vote up
/**
 * 选中所有
 */
public void setSelectorAll(@NonNull RRecyclerView recyclerView, @IdRes int viewId) {
    setSelectedList(recyclerView, viewId, getAllDatas());
}
 
Example 32
Project: Android-Code-Demos   File: BaseSimpleViewHolder.java   View source code 4 votes vote down vote up
public void setVisible(@IdRes int id, boolean visible) {
    getView(id).setVisibility(visible ? View.VISIBLE : View.GONE);
}
 
Example 33
Project: AndroidViewHelper   File: AndroidViewHelper.java   View source code 4 votes vote down vote up
public static EditTextHelper editText(@NonNull Activity activity, @IdRes int
        viewId) {
    return new EditTextHelper((EditText) findView(activity, viewId));
}
 
Example 34
Project: PeSanKita-android   File: ViewUtil.java   View source code 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T extends View> T findById(@NonNull Activity parent, @IdRes int resId) {
  return (T) parent.findViewById(resId);
}
 
Example 35
Project: mvvm-template   File: BaseSingleFragmentActivity.java   View source code 4 votes vote down vote up
@IdRes
    protected int getContainerId() {
//        return R.id.container;
        return 0;
    }
 
Example 36
Project: godlibrary   File: ListViewRefresh.java   View source code 4 votes vote down vote up
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);
}
 
Example 37
Project: CustomFormViews   File: ValidityClassBase.java   View source code 4 votes vote down vote up
@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;
}
 
Example 38
Project: AndroidViewHelper   File: AndroidViewHelper.java   View source code 4 votes vote down vote up
public static TableLayoutHelper tableLayout(@NonNull View view, @IdRes int viewId) {
    return new TableLayoutHelper((TableLayout) findView(view, viewId));
}
 
Example 39
Project: XFrame   File: XViewHolder.java   View source code 4 votes vote down vote up
public XViewHolder setProgress(@IdRes int viewId, int progress) {
    ProgressBar view = getView(viewId);
    view.setProgress(progress);
    return this;
}
 
Example 40
Project: Mvvm   File: MvvmActivity.java   View source code 4 votes vote down vote up
protected final <V extends View> V $(@IdRes int id) {
    return Utils.getView(this, id);
}