Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dlew
dlew / script.sh
Created November 9, 2018 16:36
Simple AndroidX Migration Script
#!/usr/bin/env bash
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very
# well, so I wrote my own script to do the simple job of converting package names.
#
# You can download a CSV of package names here: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv
#
# It'll run faster on a clean build because then there are fewer files to scan over.
#
# Uses `gsed` because I'm on a Mac. Can easily replace with `sed` if you don't have `gsed`.
@Zhuinden
Zhuinden / DynamicFragmentPagerAdapter.java
Last active January 30, 2023 06:58
Dynamic FragmentPagerAdapter
public class DynamicFragmentPagerAdapter extends PagerAdapter {
private static final String TAG = "DynamicFragmentPagerAdapter";
private final FragmentManager fragmentManager;
public static abstract class FragmentIdentifier implements Parcelable {
private final String fragmentTag;
private final Bundle args;
public FragmentIdentifier(@NonNull String fragmentTag, @Nullable Bundle args) {
@curioustechizen
curioustechizen / EnhancedCheckBox.java
Last active September 14, 2020 05:50
Android programmatically checkable widgets, differentiate between user clicks & programmatic setChecked calls. Based on this answer on StackOverflow: http://stackoverflow.com/a/14307643/570930. There are times when setting a switch to ON results in some action (Save to DB/ perform an HTTP POST etc). However, you want this action to happen only o…
/**
* An enhanced {@code CheckBox} that differentiates between user clicks and
* programmatic clicks. In particular, the {@code OnCheckedChangeListener} is
* <strong>not</strong> triggered when the state of the checkbox is changed
* programmatically.
*
*/
public class EnhancedCheckBox extends CheckBox implements ProgrammaticallyCheckable{
private CompoundButton.OnCheckedChangeListener mListener = null;
public EnhancedCheckBox(Context context) {