Skip to content

Instantly share code, notes, and snippets.

View bherbst's full-sized avatar

Bryan Herbst bherbst

View GitHub Profile
@bherbst
bherbst / progresbars.xml
Created March 24, 2014 13:52
ProgressBar layout
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ProgressBar
android:id="@+id/redBar"
style="@android:style/Widget.ProgressBar.Horizontal"
@bherbst
bherbst / DetailsTransition.java
Created October 29, 2015 18:02
DetailsTransition for animating image transitions between a RecyclerView and a details Fragment
public class DetailsTransition extends TransitionSet {
public DetailsTransition() {
setOrdering(ORDERING_TOGETHER);
addTransition(new ChangeBounds()).
addTransition(new ChangeTransform()).
addTransition(new ChangeImageTransform()));
}
}
@bherbst
bherbst / FragmentTransition.java
Last active October 29, 2015 18:14
Animated fragment transition
DetailsFragment details = DetailsFragment.newInstance();
// Note that we need the API version check here because the actual transition classes (e.g. Fade)
// are not in the support library and are only available in API 21+. The methods we are calling on the Fragment
// ARE available in the support library (though they don't do anything on API < 21)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
details.setSharedElementEnterTransition(new DetailsTransition());
details.setEnterTransition(new Fade());
setExitTransition(new Fade());
details.setSharedElementReturnTransition(new DetailsTransition());
@bherbst
bherbst / CopyDrawableImageTransform.java
Created November 4, 2015 16:24
Transform that copies the drawable from a starting ImageView to an ending ImageView
/**
* Similar to {@link ChangeImageTransform}, but prior to capturing the end values for the transition
* it will copy the drawable from the starting image to the ending image.
*
* This allows the image transform to work when the end ImageView doesn't immediately have content,
* such as when the image will be loaded via Picasso.
*
* @author bherbst
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@bherbst
bherbst / PicassoFragment.java
Last active November 4, 2015 16:39
Picasso delay for Fragment transitions
public class PicassoFragment extends Fragment {
private static final String KEY_WILL_ANIMATE_IMAGE = "keyWillAnimateImage";
private boolean willAnimateImage;
/**
* Get a new PicassoFragment instance
* @param wilAnimateImage True if the image will animate in during the tragment transaction
*/
public static PicassoFragment newInstance(boolean willAnimateImage) {
@bherbst
bherbst / Backstack.java
Last active May 13, 2016 15:53
Bad backstack management
public void addSubscreen(Fragment fragment) {
getSupportManager()
.beginTransaction()
.replace(R.id.container, fragment)
.addToBackStack(null)
.commit();
subscreensOnTheStack++;
}
@bherbst
bherbst / Backstack.java
Last active September 4, 2018 13:56
Good backstack
public class MainActivity extends Activity {
private static final String BACK_STACK_ROOT_TAG = "root_fragment";
public void onTabSelected(int position) {
// Pop off everything up to and including the current tab
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.popBackStack(BACK_STACK_ROOT_TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE);
// Add the new tab fragment
fragmentManager.beginTransaction()
@bherbst
bherbst / gradle.properties
Created June 16, 2017 15:30
Typical gradle.properties
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
@bherbst
bherbst / SampleFragment.kt
Last active July 21, 2017 14:35
Kotlin Android Extensions nullability
import kotlinx.android.synthetic.main.fragment_main.*
class SampleFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_main, container, false)
}
override fun onDestroy() {
super.onDestroy()
@bherbst
bherbst / SampleFragment.kt
Last active July 21, 2017 14:21
Android View Nullability
class SampleFragment : Fragment() {
private var textView: TextView? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_main2, container, false)
}
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {