Giter Club home page Giter Club logo

Comments (6)

ajalt avatar ajalt commented on May 26, 2024

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

from multistateanimation.

iwwi avatar iwwi commented on May 26, 2024

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 [email protected] 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.

from multistateanimation.

ajalt avatar ajalt commented on May 26, 2024

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.

from multistateanimation.

iwwi avatar iwwi commented on May 26, 2024

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 [email protected] 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.

from multistateanimation.

ajalt avatar ajalt commented on May 26, 2024

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

from multistateanimation.

iwwi avatar iwwi commented on May 26, 2024

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 [email protected] wrote:

visibility

from multistateanimation.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.