Skip to content

Image disapiear #1

Closed
Closed

Description

@iwwi

Hello! Im new in MultiSatateAnimation and in Java Android too, but I have a NavigationDrawawelFragment, and when I navigate thought the fragments, the image of my animation disapear I cant make it apear back how can I do that or is an issue of the MultiStateAnimation, please help me, thx in advance.

Activity

  1. ajalt commented on Nov 17, 2015

    @ajalt
    Contributor

    Can you provide some more information? I'm not sure what the problem you're having is.

  2. iwwi commented on Nov 17, 2015

    @iwwi
    Author

    Ok this is my code, all worlks fine, but when I press back and return to my fragment the ImageView of the element to animate disappear:

    XML

    <LinearLayout style="@style/listParent"
        android:background="@color/gray">
    
        <com.mikepenz.iconics.view.IconicsTextView
            android:layout_width="58dp"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_gravity="center"
            android:layout_weight="0"
            android:gravity="center"
            android:maxWidth="60dp"
            android:singleLine="true"
            android:text="{gmd-access-time}"
            android:textColor="@color/soft_black"
            android:textSize="28dp" />
    
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingRight="10dp"
            android:gravity="center|right"
            android:layout_gravity="center|right"
            android:layout_weight="1"
            android:text="AGENDAR"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="@color/soft_black" />
    
    </LinearLayout>
    
    <LinearLayout
        android:id="@+id/syncLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:background="@color/gray"
        android:orientation="vertical">
        <ImageView
            android:id="@+id/animationLoading"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            tools:src="@drawable/loading_animation_end_023"/>
        <TextView
            android:id="@+id/textSync"
            android:gravity="center"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/push_sync"/>
    </LinearLayout>
    
    
    
    <android.support.v7.widget.RecyclerView
        android:scrollbars="vertical"
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    
    and here is my Fragment

    public class NewsFragment extends AbstractSyncFragment implements MultiStateAnimation.AnimationSeriesListener{
    private RecyclerView recyclerView;
    private LiveQuery liveQuery;
    private LinearLayout syncLayout;
    private LinearLayout.LayoutParams mSyncLayoutParams;
    private ImageView animationLoadiong;
    private MultiStateAnimation mSyncAnimation;
    private TextView mCurrentSincronizationText;
    private Boolean isSinc = false;

    private SincronizacionAdapter sincronizacionAdapter;
    
    public String getTitle() {
        return Application.getInstance().getResources().getString(R.string.titulo_sincronizar_nuevo);
    }
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate( savedInstanceState );
    }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    
        View rootView = inflater.inflate(R.layout.fragment, container, false);
        DebugLog.logDebug("onCreateView");
        initComponents( rootView );
    
        return rootView;
    }
    
    private void initComponents( View rootView ){
        animationLoadiong = (ImageView) rootView.findViewById( R.id.animationLoading );
        mCurrentSincronizationText = (TextView) rootView.findViewById( R.id.textSync );
    
        mSyncAnimation = MultiStateAnimation.fromJsonResource( getActivity().getApplicationContext(), animationLoadiong, R.raw.loading_animation );
        mSyncAnimation.setSeriesAnimationFinishedListener( this );
    
        setStateAnimation();
    }
    
    private void setStateAnimation(){
        switch ( DocumentManager.getSyncState() ){
            case HECHO:
                syncLayout.setVisibility( View.GONE );
                break;
            case ERROR:
            case INICIAL:
                mSyncAnimation.transitionNow("pending");
                break;
            case PROCESO:
            case REQUERIDO:
                mSyncAnimation.queueTransition( "loading" );
                mCurrentSincronizationText.setText( getString( R.string.sync ) );
                break;
        }
    }
    
    @Override
    public void onUpdate() {
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                public void run() {
                    finishAnimationLoadin();
    
                }
            });
    }
    
    public void startLoading() {
        if (mSyncLayoutParams !=  null){
            mSyncLayoutParams.setMargins( 0,0,0,0 );
            syncLayout.setLayoutParams( mSyncLayoutParams );
            syncLayout.setVisibility( View.VISIBLE );
        }
        mSyncAnimation.queueTransition( "loading" );
        mCurrentSincronizationText.setText( getString( R.string.sync ) );
    }
    
    public void finishAnimationLoadin(){
        if (mSyncAnimation.getCurrentSectionId() == null) {
            mSyncAnimation.transitionNow("pending");
            return;
        }
    
        mSyncAnimation.queueTransition( "finished");
        mCurrentSincronizationText.setText(R.string.sync_complete);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                syncLayout.startAnimation( new AnimationGone( 1.0f, 1.0f, 1.0f, 0.0f, 500, syncLayout, true ) );
            }
        }, 3000);
    }
    
    
    /**
     * Called when a playing animation finishes and before the drawable is replaced.
     */
    @Override
    public void onAnimationFinished(){
    
    }
    
    /**
     * Called after a new animation has been created, but before the animation has started.
     * The new animation can be accessed through getCurrentDrawable.
     */
    @Override
    public void onAnimationStarting(){
    
    
    }
    
    public class AnimationGone extends ScaleAnimation{
    
        private View mView;
        private LinearLayout.LayoutParams mLayoutParams;
        private int mMarginBottomFromY, mMarginBottomToY;
    
        private boolean mVanishAfter = false;
    
        public AnimationGone(float fromX, float toX, float fromY, float toY, int duration, View view,
                        boolean vanishAfter) {
            super( fromX, toX, fromY, toY );
            setDuration( duration );
            mView = view;
            mVanishAfter = vanishAfter;
            mLayoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            mSyncLayoutParams = mLayoutParams;
            int height = mView.getHeight();
            mMarginBottomFromY = (int) (height * fromY) + mLayoutParams.bottomMargin - height;
            mMarginBottomToY = (int) (0 - ((height * toY) + mLayoutParams.bottomMargin)) - height;
        }
    
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            super.applyTransformation(interpolatedTime, t);
            if (interpolatedTime < 1.0f) {
                int newMarginBottom = mMarginBottomFromY
                        + (int) ((mMarginBottomToY - mMarginBottomFromY) * interpolatedTime);
                mLayoutParams.setMargins(mLayoutParams.leftMargin, mLayoutParams.topMargin,
                        mLayoutParams.rightMargin, newMarginBottom);
                mView.getParent().requestLayout();
            } else if (mVanishAfter) {
                mView.setVisibility(View.GONE);
            }
        }
    }
    

    So, when all work fine but when I go back to another fragment and return to this frogmen the image of the animation desappear

    On Nov 17, 2015, at 10:54 AM, AJ Alt notifications@github.com wrote:

    Can you provide some more information? I'm not sure what the problem you're having is.

    —
    Reply to this email directly or view it on GitHub.

  3. ajalt commented on Nov 17, 2015

    @ajalt
    Contributor

    This isn't a problem with this library. You need to start the animation in onResume if you want it to start when you navigate away and back. The onCreate method is only called once when the fragment is created.

  4. iwwi commented on Nov 17, 2015

    @iwwi
    Author

    Im sorry if Im too nub for this but I put the code in my onResume and still without working, sorry, show the image at the begin of que init the fragment but once I back to one fragment and return to this frogmen the image of the animation disappear, look how I change the code:

    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    
        View rootView = inflater.inflate(R.layout.fragment_nuevos, container, false);
        DebugLog.logDebug( "onCreateView" );
        initComponents( rootView );
    
        return rootView;
    }
    
    private void initComponents( View rootView ){
        recyclerView = (RecyclerView) rootView.findViewById( R.id.my_recycler_view );
        syncLayout = (LinearLayout) rootView.findViewById( R.id.syncLayout );
        animationLoadiong = (ImageView) rootView.findViewById( R.id.animationLoading );
        mCurrentSincronizationText = (TextView) rootView.findViewById( R.id.textSync );
    
    }
    
    private void setStateAnimation(){
        switch ( DocumentManager.getSyncState() ){
            case HECHO:
                syncLayout.setVisibility( View.GONE );
                break;
            case ERROR:
            case INICIAL:
                mSyncAnimation.transitionNow("pending");
                break;
            case PROCESO:
            case REQUERIDO:
                mSyncAnimation.queueTransition( "loading" );
                mCurrentSincronizationText.setText( getString( R.string.sync ) );
                break;
        }
    }
    
    @Override
    public void onUpdate() {
            new Handler(Looper.getMainLooper()).post(new Runnable() {
                public void run() {
                    Toast.makeText(GuatexApplication.getInstance().getApplicationContext(), R.string.sync_complete, Toast.LENGTH_SHORT).show();
                    finishAnimationLoadin();
    
                }
    
    }
    
    public void startLoading() {
        if (mSyncLayoutParams !=  null){
            mSyncLayoutParams.setMargins( 0,0,0,0 );
            syncLayout.setLayoutParams( mSyncLayoutParams );
            syncLayout.setVisibility( View.VISIBLE );
        }
        mSyncAnimation.queueTransition( "loading" );
        mCurrentSincronizationText.setText( getString( R.string.sync ) );
    }
    
    public void finishAnimationLoadin(){
        if (mSyncAnimation.getCurrentSectionId() == null) {
            mSyncAnimation.transitionNow("pending");
            return;
        }
    
        mSyncAnimation.queueTransition( "finished");
        mCurrentSincronizationText.setText(R.string.sync_complete);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                syncLayout.startAnimation( new AnimationGone( 1.0f, 1.0f, 1.0f, 0.0f, 500, syncLayout, true ) );
            }
        }, 3000);
    }
    
    @Override
    public void onResume() {
        super.onResume();
    
        initComponents( getView() );
        mSyncAnimation = MultiStateAnimation.fromJsonResource( getActivity().getApplicationContext(), animationLoadiong, R.raw.loading_animation );
        mSyncAnimation.setSeriesAnimationFinishedListener( this );
    
        setStateAnimation();
    
    }
    

    On Nov 17, 2015, at 10:54 AM, AJ Alt notifications@github.com wrote:

    Can you provide some more information? I'm not sure what the problem you're having is.

    —
    Reply to this email directly or view it on GitHub.

  5. ajalt commented on Nov 17, 2015

    @ajalt
    Contributor

    You set the icon's visibility to GONE, but never back to VISIBLE. That might be the issue.

  6. iwwi commented on Nov 17, 2015

    @iwwi
    Author

    Im not, I set to gone to my layout, but can you show me where in my code I put gone ?
    I also commented all the code where I put Gone, and doesn’t works, excuse me if Im making you work but isn’t work, maybe I have a mistake but I think otherwise, thx :D

    On Nov 17, 2015, at 11:31 AM, AJ Alt notifications@github.com wrote:

    visibility

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions