List of usage examples for android.support.v4.content ContextCompat getDrawable
public static final Drawable getDrawable(Context context, int i)
From source file:com.android.projectz.teamrocket.thebusapp.activities.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { this.setTheme(getResources().getIdentifier(SharedPreferencesUtils.getSelectedTheme(this), "style", getPackageName()));/*w w w . j a v a2s. c o m*/ super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarSettings); setSupportActionBar(toolbar); getSupportActionBar().setTitle(R.string.action_settings); getSupportActionBar().setDisplayHomeAsUpEnabled(true); TextView t1, t2, t3; try { t1 = (TextView) findViewById(R.id.versionText); t1.setText("Versione: " + getPackageManager().getPackageInfo(getPackageName(), 0).versionName); t2 = (TextView) findViewById(R.id.copyrightText); t2.setText("App over GNU General Public License"); t3 = (TextView) findViewById(R.id.teamText); t3.setText("Copyright (C) 2016-2017 RockeTeam"); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } String[] settingText = { getResources().getString(R.string.setting_general), getResources().getString(R.string.setting_language), getResources().getString(R.string.setting_licenses), getResources().getString(R.string.action_changelog), getResources().getString(R.string.action_about) }; Drawable[] settingImg = { ContextCompat.getDrawable(this, R.drawable.ic_generals), ContextCompat.getDrawable(this, R.drawable.ic_language), ContextCompat.getDrawable(this, R.drawable.ic_licenses), ContextCompat.getDrawable(this, R.drawable.ic_changelog), ContextCompat.getDrawable(this, R.drawable.ic_about) }; CustomListSettingMain adapter = new CustomListSettingMain(SettingsActivity.this, settingText, settingImg); ListView list = (ListView) findViewById(R.id.settings_list); list.setAdapter(adapter); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { switch (position) { case 0: startActivity(new Intent(SettingsActivity.this, SettingGeneralActivity.class)); SettingsActivity.this.overridePendingTransition(R.anim.anim_slide_in_left, R.anim.anim_slide_out_left); break; case 1: startActivity(new Intent(SettingsActivity.this, SettingLanguageActivity.class)); SettingsActivity.this.overridePendingTransition(R.anim.anim_slide_in_left, R.anim.anim_slide_out_left); break; case 2: startActivity(new Intent(SettingsActivity.this, ShowLicenceActivity.class)); SettingsActivity.this.overridePendingTransition(R.anim.anim_slide_in_left, R.anim.anim_slide_out_left); break; case 3: startActivity(new Intent(SettingsActivity.this, ChangelogActivity.class)); SettingsActivity.this.overridePendingTransition(R.anim.anim_slide_in_left, R.anim.anim_slide_out_left); break; case 4: Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse( SharedPreferencesUtils.getWebsiteUrl(getApplicationContext()) + "/web/about.php")); startActivity(browserIntent); SettingsActivity.this.overridePendingTransition(R.anim.anim_slide_in_left, R.anim.anim_slide_out_left); break; default: Toast.makeText(SettingsActivity.this, "La tua richiesta ha generato un conflitto. Riprova", Toast.LENGTH_SHORT).show(); break; } } }); }
From source file:com.akalizakeza.apps.ishusho.activity.UserDetailActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_user_detail); Intent intent = getIntent();// w w w.jav a 2 s .c om mUserId = intent.getStringExtra(USER_ID_EXTRA_NAME); mUser = intent.getStringExtra(USER_EXTRA_NAME); final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); final CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById( R.id.collapsing_toolbar); // TODO: Investigate why initial toolbar title is activity name instead of blank. mPeopleRef = FirebaseUtil.getPeopleRef(); final String currentUserId = FirebaseUtil.getCurrentUserId(); final FloatingActionButton followUserFab = (FloatingActionButton) findViewById(R.id.follow_user_fab); mFollowingListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { if (dataSnapshot.exists()) { followUserFab.setImageDrawable( ContextCompat.getDrawable(UserDetailActivity.this, R.drawable.ic_done_black_48dp)); } else { followUserFab.setImageDrawable(ContextCompat.getDrawable(UserDetailActivity.this, R.drawable.ic_person_follow_black_48dp)); } } @Override public void onCancelled(DatabaseError firebaseError) { } }; if (currentUserId != null) { mPeopleRef.child(currentUserId).child("following").child(mUserId) .addValueEventListener(mFollowingListener); } followUserFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (currentUserId == null) { Toast.makeText(UserDetailActivity.this, "You need to sign in to follow someone.", Toast.LENGTH_SHORT).show(); return; } // TODO: Convert these to actually not be single value, for live updating when // current user follows. mPeopleRef.child(currentUserId).child("following").child(mUserId) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Map<String, Object> updatedUserData = new HashMap<>(); if (dataSnapshot.exists()) { // Already following, need to unfollow updatedUserData.put("people/" + currentUserId + "/following/" + mUserId, null); updatedUserData.put("followers/" + mUserId + "/" + currentUserId, null); } else { updatedUserData.put("people/" + currentUserId + "/following/" + mUserId, true); updatedUserData.put("followers/" + mUserId + "/" + currentUserId, true); } FirebaseUtil.getBaseRef().updateChildren(updatedUserData, new DatabaseReference.CompletionListener() { @Override public void onComplete(DatabaseError firebaseError, DatabaseReference firebase) { if (firebaseError != null) { Toast.makeText(UserDetailActivity.this, R.string.follow_user_error, Toast.LENGTH_LONG).show(); Log.d(TAG, getString(R.string.follow_user_error) + "\n" + firebaseError.getMessage()); } } }); } @Override public void onCancelled(DatabaseError firebaseError) { } }); } }); mRecyclerGrid = (RecyclerView) findViewById(R.id.user_posts_grid); mGridAdapter = new GridAdapter(); mRecyclerGrid.setAdapter(mGridAdapter); mRecyclerGrid.setLayoutManager(new GridLayoutManager(this, GRID_NUM_COLUMNS)); mPersonRef = FirebaseUtil.getPeopleRef().child(mUserId); mPersonInfoListener = mPersonRef.addValueEventListener (new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Person person = dataSnapshot.getValue(Person.class); CircleImageView userPhoto = (CircleImageView) findViewById(R.id.user_detail_photo); GlideUtil.loadProfileIcon(person.getProfile_picture(), userPhoto); String name = mUser; if (name == null) { name = getString(R.string.user_info_no_name); } collapsingToolbar.setTitle(name); if (person.getFollowing() != null) { int numFollowing = person.getFollowing().size(); ((TextView) findViewById(R.id.user_num_following)).setText(numFollowing + " following"); } List<String> paths = new ArrayList<String>(person.getPosts().keySet()); mGridAdapter.addPaths(paths); String firstPostKey = paths.get(0); FirebaseUtil.getPostsRef().child(firstPostKey) .addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { Post post = dataSnapshot.getValue(Post.class); ImageView imageView = (ImageView) findViewById(R.id.backdrop); GlideUtil.loadImage(post.getFull_url(), imageView); } @Override public void onCancelled(DatabaseError firebaseError) { } }); } @Override public void onCancelled(DatabaseError firebaseError) { } }); mFollowersRef = FirebaseUtil.getFollowersRef().child(mUserId); mFollowersListener = new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { long numFollowers = dataSnapshot.getChildrenCount(); ((TextView) findViewById(R.id.user_num_followers)) .setText(numFollowers + " follower" + (numFollowers == 1 ? "" : "s")); } @Override public void onCancelled(DatabaseError databaseError) { } }; mFollowersRef.addValueEventListener(mFollowersListener); }
From source file:com.amaze.filemanager.activities.DatabaseViewerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); if (getAppTheme().equals(AppTheme.DARK)) { setTheme(R.style.appCompatDark); getWindow().getDecorView().setBackgroundColor(Utils.getColor(this, R.color.holo_dark_background)); } else if (getAppTheme().equals(AppTheme.BLACK)) { setTheme(R.style.appCompatBlack); getWindow().getDecorView().setBackgroundColor(Utils.getColor(this, android.R.color.black)); }/*www.j a v a 2 s .co m*/ setContentView(R.layout.activity_db_viewer); toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); @ColorInt int primaryColor = ColorPreferenceHelper.getPrimary(getCurrentColorPreference(), MainActivity.currentTab); if (SDK_INT >= 21) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("Amaze", ((BitmapDrawable) ContextCompat.getDrawable(this, R.mipmap.ic_launcher)).getBitmap(), primaryColor); setTaskDescription(taskDescription); } getSupportActionBar().setBackgroundDrawable(new ColorDrawable(primaryColor)); boolean useNewStack = sharedPref.getBoolean(PreferencesConstants.PREFERENCE_TEXTEDITOR_NEWSTACK, false); getSupportActionBar().setDisplayHomeAsUpEnabled(!useNewStack); if (SDK_INT == 20 || SDK_INT == 19) { SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintColor( ColorPreferenceHelper.getPrimary(getCurrentColorPreference(), MainActivity.currentTab)); FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.parentdb) .getLayoutParams(); SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); p.setMargins(0, config.getStatusBarHeight(), 0, 0); } else if (SDK_INT >= 21) { Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); window.setStatusBarColor(PreferenceUtils.getStatusColor(primaryColor)); if (getBoolean(PREFERENCE_COLORED_NAVIGATION)) window.setNavigationBarColor(PreferenceUtils.getStatusColor(primaryColor)); } path = getIntent().getStringExtra("path"); pathFile = new File(path); listView = findViewById(R.id.listView); load(pathFile); listView.setOnItemClickListener((parent, view, position, id) -> { FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); DbViewerFragment fragment = new DbViewerFragment(); Bundle bundle = new Bundle(); bundle.putString("table", arrayList.get(position)); fragment.setArguments(bundle); fragmentTransaction.add(R.id.content_frame, fragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); }); }
From source file:com.appyvet.rangebar.PinView.java
/** * The view is created empty with a default constructor. Use init to set all the initial * variables for the pin//from w w w. j a v a 2 s . c o m * * @param ctx Context * @param y The y coordinate to raw the pin (i.e. the bar location) * @param pinRadiusDP the initial size of the pin * @param pinColor the color of the pin * @param textColor the color of the value text in the pin * @param circleRadius the radius of the selector circle * @param circleColor the color of the selector circle */ public void init(Context ctx, float y, float pinRadiusDP, int pinColor, int textColor, float circleRadius, int circleColor, float minFont, float maxFont) { mRes = ctx.getResources(); mPin = ContextCompat.getDrawable(ctx, R.drawable.rotate); mDensity = getResources().getDisplayMetrics().density; mMinPinFont = minFont / mDensity; mMaxPinFont = maxFont / mDensity; mPinPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, mRes.getDisplayMetrics()); mCircleRadiusPx = circleRadius; mTextYPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3.5f, mRes.getDisplayMetrics()); // If one of the attributes are set, but the others aren't, set the // attributes to default if (pinRadiusDP == -1) { mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_THUMB_RADIUS_DP, mRes.getDisplayMetrics()); } else { mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pinRadiusDP, mRes.getDisplayMetrics()); } //Set text size in px from dp int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 15, mRes.getDisplayMetrics()); // Creates the paint and sets the Paint values mTextPaint = new Paint(); mTextPaint.setColor(textColor); mTextPaint.setAntiAlias(true); mTextPaint.setTextSize(textSize); // Creates the paint and sets the Paint values mCirclePaint = new Paint(); mCirclePaint.setColor(circleColor); mCirclePaint.setAntiAlias(true); //Color filter for the selection pin mPinFilter = new LightingColorFilter(pinColor, pinColor); // Sets the minimum touchable area, but allows it to expand based on // image size int targetRadius = (int) Math.max(MINIMUM_TARGET_RADIUS_DP, mPinRadiusPx); mTargetRadiusPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, targetRadius, mRes.getDisplayMetrics()); mY = y; }
From source file:com.farmerbb.notepad.fragment.WelcomeFragment.java
@Override public void onStart() { super.onStart(); // Read preferences SharedPreferences prefMain = getActivity().getPreferences(Context.MODE_PRIVATE); // Before we do anything else, check for a saved draft; if one exists, load it if (prefMain.getLong("draft-name", 0) != 0) { Bundle bundle = new Bundle(); bundle.putString("filename", "draft"); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle);/* w w w .ja v a 2 s .co m*/ // Add NoteEditFragment getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit(); } else { // Change window title String title = getResources().getString(R.string.app_name); getActivity().setTitle(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.ic_recents_logo)).getBitmap(); ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, bitmap, ContextCompat.getColor(getActivity(), R.color.primary)); getActivity().setTaskDescription(taskDescription); } // Don't show the Up button in the action bar, and disable the button ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(false); ((AppCompatActivity) getActivity()).getSupportActionBar().setHomeButtonEnabled(false); // Floating action button FloatingActionButton floatingActionButton = getActivity() .findViewById(R.id.button_floating_action_welcome); floatingActionButton.setImageResource(R.drawable.ic_action_new); floatingActionButton.setOnClickListener(v -> { Bundle bundle = new Bundle(); bundle.putString("filename", "new"); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); // Add NoteEditFragment getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE).commit(); }); } }
From source file:com.example.cassi.hal.adapter.CardPresenter.java
@Override public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) { T411TorrentItem torrentItem = (T411TorrentItem) item; ImageCardView cardView = (ImageCardView) viewHolder.view; Log.d(TAG, "onBindViewHolder"); cardView.setTitleText(torrentItem.getName()); cardView.setContentText(getSeedAndLeech(torrentItem)); cardView.getMainImageView()/* w ww .j a v a2 s . c o m*/ .setLayoutParams(new android.support.v17.leanback.widget.BaseCardView.LayoutParams(CARD_WIDTH, android.support.v17.leanback.widget.BaseCardView.LayoutParams.WRAP_CONTENT)); cardView.setLayoutParams(new FrameLayout.LayoutParams(CARD_WIDTH, FrameLayout.LayoutParams.WRAP_CONTENT)); cardView.getMainImageView() .setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.poster_placeholder)); if (torrentItem.getBackgroundUrl() != null) { Glide.with(mContext) .load(mContext.getString(R.string.themoviedb_poster_url) + torrentItem.getPosterUrl()) .error(ContextCompat.getDrawable(mContext, R.drawable.poster_placeholder)) .placeholder(ContextCompat.getDrawable(mContext, R.drawable.poster_placeholder)) .into(cardView.getMainImageView()); } else { if (torrentItem.getCategoryName().equals(Category.MOVIE.getT411CatName()) || torrentItem.getCategoryName().equals(Category.ANIME.getT411CatName())) getMovieTMDBdetail(cardView, torrentItem, Category.MOVIE); if (torrentItem.getCategoryName().equals(Category.TV.getT411CatName())) getMovieTMDBdetail(cardView, torrentItem, Category.TV); } }
From source file:com.android.projectz.teamrocket.thebusapp.settings.SettingGeneralActivity.java
/** * Metodo che serve a far visualizzare la lista con le relative personalizzazioni all'interno della schermata * <p>// www .ja v a 2s .com * ho deciso di fare ci in modo tale da richiamare il metodo quando la lingua viene cambiata, cosi la vista * aggiornata con la lingua selezionata */ @Override protected void onStart() { super.onStart(); String[] settingText = { getResources().getString(R.string.setting_theme), getResources().getString(R.string.setting_instrictions) }; String[] settingSubtext = { SharedPreferencesUtils.getSelectedTheme(SettingGeneralActivity.this).equals("AppTheme") ? "Light" : "Dark", getResources().getString(R.string.short_instruction) }; Resources res = getResources(); Drawable[] settingImg = { ContextCompat.getDrawable(this, R.drawable.ic_theme_chooser), ContextCompat.getDrawable(this, R.drawable.ic_instruction) }; CustomListSettingOther adapter = new CustomListSettingOther(SettingGeneralActivity.this, settingText, settingSubtext, settingImg); ListView list = (ListView) findViewById(R.id.general_setting_list); list.setAdapter(adapter); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { switch (position) { case 0: new MaterialDialog.Builder(SettingGeneralActivity.this).title(R.string.dialog_title_theme) .items(R.array.theme) .itemsCallbackSingleChoice( SharedPreferencesUtils.getSelectedTheme(SettingGeneralActivity.this) .equals("AppTheme") ? 0 : 1, new MaterialDialog.ListCallbackSingleChoice() { @Override public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) { try { SharedPreferencesUtils.setSelectedTheme(SettingGeneralActivity.this, text.equals("Light") ? "AppTheme" : "ThemeDark"); reload(); } catch (Exception e) { e.printStackTrace(); SharedPreferencesUtils.setSelectedLanguage( SettingGeneralActivity.this, "AppTheme"); } return true; } }) .positiveText(R.string.dialog_ok_button).show(); break; case 1: Intent inst = new Intent(SettingGeneralActivity.this, IntroApp.class); startActivity(inst); SettingGeneralActivity.this.overridePendingTransition(R.anim.anim_slide_in_right, R.anim.anim_slide_out_right); break; } } }); }
From source file:arun.com.chromer.browsing.article.util.ArticleUtil.java
/** * Changes the text selection handle colors. *///from w w w . java2s.c o m public static void changeTextSelectionHandleColors(TextView textView, int color) { textView.setHighlightColor(Color.argb(40, Color.red(color), Color.green(color), Color.blue(color))); try { Field editorField = TextView.class.getDeclaredField("mEditor"); if (!editorField.isAccessible()) { editorField.setAccessible(true); } Object editor = editorField.get(textView); Class<?> editorClass = editor.getClass(); String[] handleNames = { "mSelectHandleLeft", "mSelectHandleRight", "mSelectHandleCenter" }; String[] resNames = { "mTextSelectHandleLeftRes", "mTextSelectHandleRightRes", "mTextSelectHandleRes" }; for (int i = 0; i < handleNames.length; i++) { Field handleField = editorClass.getDeclaredField(handleNames[i]); if (!handleField.isAccessible()) { handleField.setAccessible(true); } Drawable handleDrawable = (Drawable) handleField.get(editor); if (handleDrawable == null) { Field resField = TextView.class.getDeclaredField(resNames[i]); if (!resField.isAccessible()) { resField.setAccessible(true); } int resId = resField.getInt(textView); handleDrawable = ContextCompat.getDrawable(textView.getContext(), resId); } if (handleDrawable != null) { Drawable drawable = handleDrawable.mutate(); drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); handleField.set(editor, drawable); } } } catch (Exception ignored) { } }
From source file:com.google.blockly.android.ui.TrashCanView.java
/** * Assigns a drawable resource id for the default state, when no block is hovering with a * pending drop. Usually, this is a closed trashcan. * * @param drawableRes Default drawable resource id. *//*from w w w . java 2s . com*/ public void setDefaultIcon(int drawableRes) { setDefaultIcon(ContextCompat.getDrawable(getContext(), drawableRes)); }
From source file:com.hannesdorfmann.mosby3.sample.mvi.view.shoppingcartoverview.ShoppingCartOverviewFragment.java
private void setUpItemTouchHelper() { ////from www . j a v a2 s. c om // Borrowed from https://github.com/nemanja-kovacevic/recycler-view-swipe-to-delete/blob/master/app/src/main/java/net/nemanjakovacevic/recyclerviewswipetodelete/MainActivity.java // ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) { // we want to cache these and not allocate anything repeatedly in the onChildDraw method Drawable background; Drawable xMark; int xMarkMargin; boolean initiated; private void init() { background = new ColorDrawable(ContextCompat.getColor(getActivity(), R.color.delete_background)); xMark = ContextCompat.getDrawable(getActivity(), R.drawable.ic_remove); xMarkMargin = (int) getActivity().getResources().getDimension(R.dimen.ic_clear_margin); initiated = true; } // not important, we don't want drag & drop @Override public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) { return false; } @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) { int swipedPosition = viewHolder.getAdapterPosition(); Product productAt = adapter.getProductAt(swipedPosition); removeRelay.onNext(productAt); } @Override public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { View itemView = viewHolder.itemView; // not sure why, but this method get's called for viewholder that are already swiped away if (viewHolder.getAdapterPosition() == -1) { // not interested in those return; } if (!initiated) { init(); } // draw red background background.setBounds(itemView.getRight() + (int) dX, itemView.getTop(), itemView.getRight(), itemView.getBottom()); background.draw(c); // draw x mark int itemHeight = itemView.getBottom() - itemView.getTop(); int intrinsicWidth = xMark.getIntrinsicWidth(); int intrinsicHeight = xMark.getIntrinsicWidth(); int xMarkLeft = itemView.getRight() - xMarkMargin - intrinsicWidth; int xMarkRight = itemView.getRight() - xMarkMargin; int xMarkTop = itemView.getTop() + (itemHeight - intrinsicHeight) / 2; int xMarkBottom = xMarkTop + intrinsicHeight; xMark.setBounds(xMarkLeft, xMarkTop, xMarkRight, xMarkBottom); // xMark.draw(c); super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive); } }; ItemTouchHelper mItemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback); mItemTouchHelper.attachToRecyclerView(recyclerView); }