Skip to content

Instantly share code, notes, and snippets.

View andersonleite's full-sized avatar
🎯
Focusing

Anderson Leite andersonleite

🎯
Focusing
View GitHub Profile
TextFragment textFragment = TextFragment.newInstance("Hello there!");
public class TextFragment extends Fragment {
private static final String ARG_TEXT = "arg_text";
public static TextFragment newInstance(String text) {
TextFragment textFragment = new TextFragment();
Bundle bundle = new Bundle();
bundle.putString(ARG_TEXT, text);
textFragment.setArguments(bundle);
TextFragment textFragment = new TextFragment();
Bundle bundle = new Bundle();
bundle.putString("myText", "Hey ya!");
textFragment.setArguments(bundle);
Toast toast = Toast.makeText(context, text, duration);
toast.show();
@andersonleite
andersonleite / effectiveJava.txt
Created August 19, 2015 14:52
notes from effective java
Effective Java
==============
[Creating and Destroying Objects]
/ Consider static factory methods instead of constructors
+ they have names
+ they are not required to create a new object each time they’re invoked
+ they can return an object of any subtype of their return type
- classes without public or protected constructors cannot be subclassed
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
@Override
public void onAnimationEnd(Animation animation) {
Animation fadeIn = new AlphaAnimation(0, 1);
fadeIn.setInterpolator(new DecelerateInterpolator());
fadeIn.setDuration(3000);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setStartOffset(3000);
public class MainActivity extends Activity implements Animation.AnimationListener{
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
public void fallDownWordAnimation() {
// define animation to be used
Animation animator = AnimationUtils.loadAnimation(
getActivity().getApplicationContext(), R.anim.fall_down);
// set animation listener
animator.setAnimationListener(this);
// start the animation
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromYDelta="0%p"
android:toYDelta="50%p"
android:duration="4000" />