package my.mosaique.fm; import java.util.Date; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.view.animation.TranslateAnimation; import android.widget.ListView; /** * Simple Activity that uses each Button in the layout to invoke an Activity. */ public class MosaiqueActivity extends Activity implements AnimationListener { View app; acceuil menu; Bundle objetbunble = new Bundle(); boolean menuOut = false; AnimParams animParams = new AnimParams(); class ClickListener implements OnClickListener { @Override public void onClick(View v) { System.out.println("onClick " + new Date()); MosaiqueActivity me = MosaiqueActivity.this; Context context = me; Animation anim; int w = app.getMeasuredWidth(); int h = app.getMeasuredHeight(); int left = (int) (app.getMeasuredWidth() * 0.8); if (!menuOut) { //anim = AnimationUtils.loadAnimation(context, R.anim.push_right_out_80); anim = new TranslateAnimation(0, left, 0, 0); //On créé l'Intent qui va nous permettre d'afficher l'autre Activity //Attention il va surement falloir que vous modifier le premier paramètre (Tutoriel9_Android.this) //Mettez le nom de l'Activity dans la quelle vous êtes actuellement Intent intent = new Intent(MosaiqueActivity.this, acceuil.class); //On affecte à l'Intent le Bundle que l'on a créé intent.putExtras(objetbunble); //On démarre l'autre Activity startActivity(intent); animParams.init(left, 0, left + w, h); } else { // anim = AnimationUtils.loadAnimation(context, R.anim.push_left_in_80); anim = new TranslateAnimation(0, -left, 0, 0); animParams.init(0, 0, w, h); } anim.setDuration(500); anim.setAnimationListener(me); //Tell the animation to stay as it ended (we are going to set the app.layout first than remove this property) anim.setFillAfter(true); // Only use fillEnabled and fillAfter if we don't call layout ourselves. // We need to do the layout ourselves and not use fillEnabled and fillAfter because when the anim is finished // although the View appears to have moved, it is actually just a drawing effect and the View hasn't moved. // Therefore clicking on the screen where the button appears does not work, but clicking where the View *was* does // work. // anim.setFillEnabled(true); // anim.setFillAfter(true); app.startAnimation(anim); } } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.slide_animation_then_call_layout); // menu = findViewById(R.id.menu); app = findViewById(R.id.app); // ViewUtils.printView("menu", menu); ViewUtils.printView("app", app); //On créé un objet Bundle, c'est ce qui va nous permetre d'envoyer des données à l'autre Activity ListView listView = (ListView) app.findViewById(R.id.list); // ListView listView1 = (ListView) menu.findViewById(R.id.list1); ViewUtils.initListView(this, listView, "Item ", 10, android.R.layout.simple_list_item_1);// 10 c'est le nombre item dans listview //ViewUtils.initListView(this, listView1, "AAAAA ", 7, android.R.layout.simple_list_item_1); // menu.setVisibility(View.VISIBLE); app.findViewById(R.id.BtnSlide).setOnClickListener(new ClickListener()); //menu.findViewById(R.id.BtnSlide).setOnClickListener(new ClickListener()); } void layoutApp(boolean menuOut) { System.out.println("layout [" + animParams.left + "," + animParams.top + "," + animParams.right + "," + animParams.bottom + "]"); app.layout(animParams.left, animParams.top, animParams.right, animParams.bottom); //Now that we've set the app.layout property we can clear the animation, flicker avoided :) app.clearAnimation(); } @Override public void onAnimationEnd(Animation animation) { System.out.println("onAnimationEnd"); // ViewUtils.printView("menu", menu); ViewUtils.printView("app", app); menuOut = !menuOut; if (!menuOut) { //On créé l'Intent qui va nous permettre d'afficher l'autre Activity //Attention il va surement falloir que vous modifier le premier paramètre (Tutoriel9_Android.this) //Mettez le nom de l'Activity dans la quelle vous êtes actuellement Intent intent = new Intent(MosaiqueActivity.this, acceuil.class); //On affecte à l'Intent le Bundle que l'on a créé intent.putExtras(objetbunble); //On démarre l'autre Activity startActivity(intent); } layoutApp(menuOut); } public void onAnimationRepeat(Animation animation) { System.out.println("onAnimationRepeat"); } @Override public void onAnimationStart(Animation animation) { System.out.println("onAnimationStart"); } static class AnimParams { int left, right, top, bottom; void init(int left, int top, int right, int bottom) { this.left = left; this.top = top; this.right = right; this.bottom = bottom; } //setContentView(contentView); } }