I have use
Android Cube Demo
In CubeLayout class. I add a interface CubeCompleted
public class CubeLayout extends FrameLayout {
private BaseInterpolator mInterpolator = new AccelerateDecelerateInterpolator();
public CubeLayout(Context context) {
this(context, null);
}
public CubeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public CubeLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
View foregroundView = getChildAt(0);
View backgroundView = getChildAt(1);
CubeLeftOutAnimation cubeLeftOutAnimation = new CubeLeftOutAnimation();
cubeLeftOutAnimation.setDuration(1000);
cubeLeftOutAnimation.setFillAfter(true);
CubeRightInAnimation cubeRightInAnimation = new CubeRightInAnimation();
cubeRightInAnimation.setDuration(1000);
cubeRightInAnimation.setFillAfter(true);
foregroundView.startAnimation(cubeLeftOutAnimation);
backgroundView.startAnimation(cubeRightInAnimation);
cubeRightInAnimation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
completed.completedCube();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
public interface CubeCompleted {
public void completedCube();
}
CubeCompleted completed;
}
In my Activity. I have Replace a Fragment
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager manager = getSupportFragmentManager();
manager.beginTransaction()
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.content_main, mHomeFragment)
.commit();
}
In MyFragment. I overide completedCube
public class HomeFragment extends Fragment implements CubeLayout.CubeCompleted {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_home, container, false);
return view;
}
@Override
public void completedCube() {
// donutProgress();
}
}
This is my Bug in Logcat
Process: com.seesaa.newsaudiocast, PID: 31189
java.lang.NullPointerException: Attempt to invoke interface method 'void com.view.CubeLayout$CubeCompleted.completedCube()' on a null object reference
at com.seesaa.newsaudiocast.view.CubeLayout$1.onAnimationEnd(CubeLayout.java:56)
at android.view.animation.Animation$3.run(Animation.java:374)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)