List of usage examples for android.support.v4.content ContextCompat getDrawable
public static final Drawable getDrawable(Context context, int i)
From source file:com.cocosw.bottomsheet.ActionMenuItem.java
public MenuItem setIcon(int iconRes) { mIconResId = iconRes;/* www.j a v a 2 s .c o m*/ if (iconRes > 0) mIconDrawable = ContextCompat.getDrawable(mContext, iconRes); return this; }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_e.RecyclerListViewFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); //noinspection ConstantConditions mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view); mLayoutManager = new LinearLayoutManager(getContext()); final Parcelable eimSavedState = (savedInstanceState != null) ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER) : null;//from w w w . j a va2 s. com mRecyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(eimSavedState); mRecyclerViewExpandableItemManager.setOnGroupExpandListener(this); mRecyclerViewExpandableItemManager.setOnGroupCollapseListener(this); //adapter final MyExpandableItemAdapter myItemAdapter = new MyExpandableItemAdapter(getDataProvider()); mWrappedAdapter = mRecyclerViewExpandableItemManager.createWrappedAdapter(myItemAdapter); // wrap for expanding final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator(); // Change animations are enabled by default since support-v7-recyclerview v22. // Need to disable them when using animation indicator. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); mRecyclerView.setHasFixedSize(false); // additional decorations //noinspection StatementWithEmptyBody if (supportsViewElevation()) { // Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required. } else { mRecyclerView.addItemDecoration(new ItemShadowDecorator( (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1))); } mRecyclerView.addItemDecoration(new SimpleListDividerDecorator( ContextCompat.getDrawable(getContext(), R.drawable.list_divider_h), true)); mRecyclerViewExpandableItemManager.attachRecyclerView(mRecyclerView); }
From source file:android.support.v7.internal.view.menu.ActionMenuItem.java
public MenuItem setIcon(int iconRes) { mIconResId = iconRes; mIconDrawable = ContextCompat.getDrawable(mContext, iconRes); return this; }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_e_basic.ExpandableExampleFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); //noinspection ConstantConditions mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view); mLayoutManager = new LinearLayoutManager(getContext()); final Parcelable eimSavedState = (savedInstanceState != null) ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER) : null;//w ww . ja v a 2 s.c o m mRecyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(eimSavedState); mRecyclerViewExpandableItemManager.setOnGroupExpandListener(this); mRecyclerViewExpandableItemManager.setOnGroupCollapseListener(this); //adapter final ExpandableExampleAdapter myItemAdapter = new ExpandableExampleAdapter(getDataProvider()); mWrappedAdapter = mRecyclerViewExpandableItemManager.createWrappedAdapter(myItemAdapter); // wrap for expanding final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator(); // Change animations are enabled by default since support-v7-recyclerview v22. // Need to disable them when using animation indicator. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); mRecyclerView.setHasFixedSize(false); // additional decorations //noinspection StatementWithEmptyBody if (supportsViewElevation()) { // Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required. } else { mRecyclerView.addItemDecoration(new ItemShadowDecorator( (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1))); } mRecyclerView.addItemDecoration(new SimpleListDividerDecorator( ContextCompat.getDrawable(getContext(), R.drawable.list_divider_h), true)); mRecyclerViewExpandableItemManager.attachRecyclerView(mRecyclerView); }
From source file:com.justplay1.shoppist.shared.base.adapters.BaseGroupSwipeableItemAdapter.java
@Override public void onSetChildItemSwipeBackground(CVH holder, int groupPosition, int childPosition, int type) { int bgResId = R.drawable.bg_swipe_item_neutral; LayerDrawable drawable = (LayerDrawable) ContextCompat.getDrawable(context, bgResId); switch (type) { case SwipeableItemConstants.DRAWABLE_SWIPE_LEFT_BACKGROUND: switch (getLeftSwipeActionType()) { case SwipeActionType.MOVE_ITEM: if (getChildItem(groupPosition, childPosition).getStatus()) { bgResId = getMoveToStatusNotDoneIcon(); } else { bgResId = getMoveToStatusDoneIcon(); }/*from www. j a v a 2 s . c o m*/ break; case SwipeActionType.DELETE_ITEM: bgResId = R.drawable.bg_swipe_item_delete_action; break; case SwipeActionType.EDIT_ITEM: bgResId = R.drawable.bg_swipe_item_edit_action; break; } drawable = (LayerDrawable) ContextCompat.getDrawable(context, bgResId); ((BitmapDrawable) drawable.findDrawableByLayerId(R.id.image)) .setGravity(Gravity.END | Gravity.CENTER_VERTICAL); break; case SwipeableItemConstants.DRAWABLE_SWIPE_RIGHT_BACKGROUND: bgResId = R.drawable.bg_swipe_item_move_to_cart_action; switch (getRightSwipeActionType()) { case SwipeActionType.MOVE_ITEM: if (getChildItem(groupPosition, childPosition).getStatus()) { bgResId = getMoveToStatusNotDoneIcon(); } else { bgResId = getMoveToStatusDoneIcon(); } break; case SwipeActionType.DELETE_ITEM: bgResId = R.drawable.bg_swipe_item_delete_action; break; case SwipeActionType.EDIT_ITEM: bgResId = R.drawable.bg_swipe_item_edit_action; break; } drawable = (LayerDrawable) ContextCompat.getDrawable(context, bgResId); ((BitmapDrawable) drawable.findDrawableByLayerId(R.id.image)) .setGravity(Gravity.START | Gravity.CENTER_VERTICAL); break; } DrawableUtils.setViewDrawable(holder.itemView, drawable); }
From source file:com.afeng.xf.widget.snackbarlight.Light.java
/** * Make a Snackbar of {@link Light#TYPE_SUCCESS} to display a message. * The method {@link Light#make(View, CharSequence, Drawable, int, int, int)} * is called internal./*w w w.j ava2s . c o m*/ * * @param view The view to find a parent from. * @param text The message to display. Formatted text is supported. * @param duration How long to show the message. * Either {@link Light#LENGTH_SHORT} or {@link Light#LENGTH_LONG}. * @return The Snackbar that will be displayed. */ public static Snackbar success(@NonNull View view, @NonNull CharSequence text, int duration) { Context context = view.getContext(); return make(view, text, // DO NOT use the resource id directly. // It should be a resolved drawable or color. ContextCompat.getDrawable(context, R.drawable.ic_success_white_24dp), // getResources().getColor() is deprecated. ContextCompat.getColor(context, R.color.color_success), ContextCompat.getColor(context, android.R.color.white), duration); }
From source file:com.android.projectz.teamrocket.thebusapp.adapters.MainRecyclerAdapter.java
@Override public void onBindViewHolder(final MainRecyclerAdapter.ViewHolder holder, final int position) { int lastPosition = -1; if (position > lastPosition) { Animation animation = AnimationUtils.loadAnimation(context, (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top); holder.itemView.startAnimation(animation); lastPosition = position;/* w w w . j a v a 2s . com*/ } if (SharedPreferencesUtils.getSelectedTheme(context).equals("ThemeDark")) { holder.cardView.setBackgroundColor(ContextCompat.getColor(context, R.color.cardview_dark_background)); holder.txtTitle.setTextColor(ContextCompat.getColor(context, android.R.color.primary_text_dark)); holder.txtSubtitle.setTextColor(ContextCompat.getColor(context, android.R.color.secondary_text_dark)); holder.txtOther.setTextColor(ContextCompat.getColor(context, android.R.color.secondary_text_dark)); image = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_arrow_row)); DrawableCompat.setTint(image, context.getResources().getColor(R.color.iconDark)); } else { holder.cardView.setBackgroundColor(ContextCompat.getColor(context, R.color.cardview_light_background)); holder.txtTitle.setTextColor(ContextCompat.getColor(context, android.R.color.primary_text_light)); holder.txtSubtitle.setTextColor(ContextCompat.getColor(context, android.R.color.secondary_text_light)); holder.txtOther.setTextColor(ContextCompat.getColor(context, android.R.color.secondary_text_light)); image = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_arrow_row)); DrawableCompat.setTint(image, context.getResources().getColor(R.color.iconLight)); } holder.txtTitle.setText(myObjects.get(position).getTextTitle()); holder.txtSubtitle.setText(myObjects.get(position).getTextSubtitle()); holder.txtOther.setText(myObjects.get(position).getTextOther()); holder.imageView.setImageResource(myObjects.get(position).getImageId()); holder.arrowRow.setImageDrawable(image); //ascoltatore del *tap* sulla card holder.relativeLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(context, "Loading...", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(context, DetailViewerActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); //senza di esso va in crash, perch bisogna creare l'intent come se fosse una nuova activity intent.putExtra("title", myObjects.get(position).getTextTitle()); intent.putExtra("subtitle", myObjects.get(position).getTextSubtitle()); intent.putExtra("other", myObjects.get(position).getTextOther()); intent.putExtra("fermataId", myObjects.get(position).getFermataId()); ArrayList<String> holderData = new ArrayList<String>(); holderData.add(myObjects.get(position).getTextTitle()); holderData.add(myObjects.get(position).getTextSubtitle()); holderData.add(myObjects.get(position).getTextOther()); intent.putStringArrayListExtra("holderData", holderData); context.startActivity(intent); } }); //MainActivity.recyclerView.scrollToPosition(myObjects.get(position).isNear != -1 ? position : null); }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_ed_with_section.RecyclerListViewFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); //noinspection ConstantConditions mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view); mLayoutManager = new LinearLayoutManager(getContext()); final Parcelable eimSavedState = (savedInstanceState != null) ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER) : null;/*from w w w .j ava 2s . c o m*/ mRecyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(eimSavedState); mRecyclerViewExpandableItemManager.setOnGroupExpandListener(this); mRecyclerViewExpandableItemManager.setOnGroupCollapseListener(this); // touch guard manager (this class is required to suppress scrolling while swipe-dismiss animation is running) mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager(); mRecyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true); mRecyclerViewTouchActionGuardManager.setEnabled(true); // drag & drop manager mRecyclerViewDragDropManager = new RecyclerViewDragDropManager(); mRecyclerViewDragDropManager.setDraggingItemShadowDrawable( (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3)); // swipe manager mRecyclerViewSwipeManager = new RecyclerViewSwipeManager(); //adapter getDataProvider(); final MyExpandableDraggableWithSectionItemAdapter myItemAdapter = new MyExpandableDraggableWithSectionItemAdapter( getDataProvider()); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewExpandableItemManager.createWrappedAdapter(myItemAdapter); // wrap for expanding mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(mWrappedAdapter); // wrap for dragging mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(mWrappedAdapter); // wrap for swiping final GeneralItemAnimator animator = new SwipeDismissItemAnimator(); // Change animations are enabled by default since support-v7-recyclerview v22. // Need to disable them when using animation indicator. animator.setSupportsChangeAnimations(false); mRecyclerView.setLayoutManager(mLayoutManager); mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter mRecyclerView.setItemAnimator(animator); mRecyclerView.setHasFixedSize(false); // additional decorations //noinspection StatementWithEmptyBody if (supportsViewElevation()) { // Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required. } else { mRecyclerView.addItemDecoration(new ItemShadowDecorator( (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1))); } mRecyclerView.addItemDecoration(new SimpleListDividerDecorator( ContextCompat.getDrawable(getContext(), R.drawable.list_divider_h), true)); // NOTE: // The initialization order is very important! This order determines the priority of touch event handling. // // priority: TouchActionGuard > Swipe > DragAndDrop > ExpandableItem mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView); mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView); mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView); mRecyclerViewExpandableItemManager.attachRecyclerView(mRecyclerView); }
From source file:com.esri.arcgisruntime.sample.choosecameracontroller.MainActivity.java
private void setupToolbar() { Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar);// ww w. j a v a 2 s.c om toolbar.setOverflowIcon(ContextCompat.getDrawable(this, R.drawable.ic_photo_camera)); }
From source file:com.github.antoniodisanto92.swipeselector.SwipeAdapter.java
private SwipeAdapter(ViewPager viewPager, ViewGroup indicatorContainer, int indicatorSize, int indicatorMargin, int inActiveIndicatorColor, int activeIndicatorColor, int leftButtonResource, int rightButtonResource, ImageView leftButton, ImageView rightButton, String customFontPath, int titleTextAppearance, int descriptionTextAppearance, int descriptionGravity) { mContext = viewPager.getContext();/*from w w w.j a v a2s . c o m*/ mViewPager = viewPager; mViewPager.addOnPageChangeListener(this); mIndicatorContainer = indicatorContainer; mCircleParams = new LinearLayout.LayoutParams(indicatorSize, indicatorSize); mCircleParams.leftMargin = indicatorMargin; mInActiveCircleDrawable = Indicator.newOne(indicatorSize, inActiveIndicatorColor); mActiveCircleDrawable = Indicator.newOne(indicatorSize, activeIndicatorColor); if (customFontPath != null && ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && !customFontPath.isEmpty()) || customFontPath.length() > 0)) { mCustomTypeFace = Typeface.createFromAsset(mContext.getAssets(), customFontPath); } mTitleTextAppearance = titleTextAppearance; mDescriptionTextAppearance = descriptionTextAppearance; mDescriptionGravity = getGravity(descriptionGravity); mLeftButton = leftButton; mLeftButton.setImageResource(leftButtonResource); mRightButton = rightButton; mRightButton.setImageResource(rightButtonResource); // Calculate paddings for the content so the left and right buttons // don't overlap. mSweetSixteen = (int) PixelUtils.dpToPixel(mContext, 16); mContentLeftPadding = ContextCompat.getDrawable(mContext, leftButtonResource).getIntrinsicWidth() + mSweetSixteen; mContentRightPadding = ContextCompat.getDrawable(mContext, rightButtonResource).getIntrinsicWidth() + mSweetSixteen; mLeftButton.setOnClickListener(this); mRightButton.setOnClickListener(this); mLeftButton.setTag(TAG_HIDDEN); mLeftButton.setClickable(false); setAlpha(0.0f, mLeftButton); }