Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simultaneous Translations on Android

I'm trying to do several translations simultaneously on Android.

I have 2 or more buttons on a layout (all the same size), and when I press one I want the others to move out of the screen.

I've done a test app to try to implement this behaviour.

On it I've set a listener on click of one button to test, something like:

button.setOnClickListener(new View.OnClickListener() {

    public void onClick(View view) {
        Button toMove = (Button) findViewById(R.id.button_test2);
        Button toMove2 = (Button) findViewById(R.id.button_test3);

        AnimationSet set = new AnimationSet(true);

        TranslateAnimation anim = new TranslateAnimation(0, -toMove
          .getWidth(), 0, 0);
        anim.setFillAfter(true);
        anim.setDuration(1000);

        toMove.setAnimation(anim);
        toMove2.setAnimation(anim);

        set.addAnimation(anim);

        set.startNow();
    }

The view:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <Button android:id="@+id/button_test" android:layout_width="200px"
        android:layout_height="50px" android:text="@string/hello" />

    <Button android:id="@+id/button_test2" android:layout_width="200px"
        android:layout_height="50px" android:text="@string/hello"/>

    <Button android:id="@+id/button_test3" android:layout_width="200px"
        android:layout_height="50px" android:text="@string/hello"/>

</LinearLayout>

The thing is that the two buttons start the animation, one slightly after the other. I've read that it is due to getDelayForView() that returns different delays of each. Is there any way to move 2 or more buttons simultaneously?

Google was not very helpful :-\

like image 290
neteinstein Avatar asked Nov 16 '10 16:11

neteinstein


People also ask

Is there a simultaneous translation app?

Linguali. The first mobile app for congresses, meetings and events, to listen to the conference interpreter, or speaker, on mobile, without the translation headsets. One of the special features, is that it is possible to have 10,000 participants receive simultaneous interpretation in an unlimited number of languages.

What is the best simultaneous translation app?

Google Translate is probably the very best translation app on mobile. It supports over 100 languages online and over 50 languages offline (via typing). It also translates stuff with your camera like menus or street signs. The app also supports handwriting, voice input, and typing input (obviously).


1 Answers

Issue:

It seems that setAnimation will acutally start the animation and probably asynchronously. However there might be a lock on setting the animation for the second view. There must be a dispatcher because setting the animation for the buttons in different order does not affect the fact that bottom one is faster.

The solution is to prevent this hypothetical lock by creating two individual animations.

Code:

public void onClick(View view) {
    Button toMove = (Button) findViewById(R.id.button_test2);
    Button toMove2 = (Button) findViewById(R.id.button_test3);

    TranslateAnimation anim = new TranslateAnimation(0, -toMove
            .getWidth(), 0, 0);
    anim.setFillAfter(true);
    anim.setDuration(1000);

    TranslateAnimation anim2 = new TranslateAnimation(0, -toMove
            .getWidth(), 0, 0);
    anim2.setFillAfter(true);
    anim2.setDuration(1000);

    //THERE IS ONE MORE TRICK

    toMove.setAnimation(anim);
    toMove2.setAnimation(anim2);
}

Note:

In the //THERE IS ONE MORE TRICK, you could add the following code to ensure that they move together. There still must be a lag of 1 millisecond or so.

long time =AnimationUtils.currentAnimationTimeMillis();

//This invalidate is needed in new Android versions at least in order for the view to be refreshed.
toMove.invalidate(); 
toMove2.invalidate();
anim.setStartTime(time);
anim2.setStartTime(time);
like image 132
Sherif elKhatib Avatar answered Oct 29 '22 04:10

Sherif elKhatib