android:Debug无法在所有(End,Repeat或Start)事件上点击AnimationListener

时间:2011-07-09 19:29:56

标签: java android mobile-application

我一直试图弄清楚为什么我的AnimationListener事件在调试时没有被命中。我需要监听器监听onAnimationEnd事件,这样我就可以启动一个新的Activity。我可能会遗漏一些非常愚蠢的东西;我将非常感谢任何帮助。下面是我的代码。

public class QuizSplashActivity extends QuizActivity implements AnimationListener {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      configAnimationEndListener(); //<-----------------------See bellow    
      setContentView(R.layout.splash);
      startAnimation();
  }

@Override
protected void onPause() {
    super.onPause();
    stopAnimationPerControl();
    stopAnimationForAllChilds();
}

@Override
protected void onResume() {
 super.onResume();
 //Lets kick of all the animations again for full effect
 startAnimation();
     //I am having to cheat by manually calling it here temporary to proceed
 Intent myIntent = new Intent(this, QuizMenuActivity.class);
 startActivity(myIntent);
}

/**
 * Configures and kicks of animation
 */
private void startAnimation(){
    configAnimationsPerControl();
    configAnimationsForAllChilds();
}

/**
 * finds the specific control by its id and applies an Animation per Control
 * the Animation is then started using the control
 */    
private void configAnimationsPerControl() {
    TextView logo1 = (TextView) findViewById(R.id.TextViewTopTitle);
    Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.fade_in);
    logo1.startAnimation(fade1);        

    TextView logo2 = (TextView) findViewById(R.id.TextViewBottomTitle);
    Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.fade_in2);
    logo2.startAnimation(fade2);
}

private void configAnimationsForAllChilds() {

    //gets animation resource
    Animation spinin = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
    //Applys animation xml to a Layout controller
    LayoutAnimationController controller = new LayoutAnimationController(spinin);

    //Applies LayoutAnimation controller to each table Row next
    TableLayout table = (TableLayout) findViewById(R.id.tableLayout01);
    for (int i = 0; i < table.getChildCount(); i++) {
        TableRow row = (TableRow) table.getChildAt(i);
        row.setLayoutAnimation(controller);
    }
}

/**
 * Stops all animations
 * This should be called on pause
 */
private void stopAnimationPerControl() {
    //Stop Animation
    TextView logo1 = (TextView) findViewById(R.id.TextViewTopTitle);
    logo1.clearAnimation();

    TextView logo2 = (TextView) findViewById(R.id.TextViewBottomTitle);
    logo2.clearAnimation();
}

/**
 * Goes through a Layout control and fetch all child
 * Stops the Animation for each
 */
private void stopAnimationForAllChilds() {
    TableLayout table = (TableLayout) findViewById(R.id.tableLayout01);
    for (int i = 0; i < table.getChildCount(); i++) {
        TableRow row = (TableRow) table.getChildAt(i);
        row.clearAnimation();
    }
}

/**
 * Listen into the control with the longest animation
 * Thin Starts an intent to launch the menu screen
 * then closes the Splash screen from the application stack as you 
 * don't want the back button to return the user here again
 */
private void configAnimationEndListener() { //<--------------------------- here 
    Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
    fade2.setAnimationListener(new AnimationListener() {

@Override
public void onAnimationEnd(Animation animation) {
startActivity(new Intent(QuizSplashActivity.this, QuizMenuActivity.class));
        QuizSplashActivity.this.finish();
    }

@Override
public void onAnimationRepeat(Animation animation) {
}

@Override
public void onAnimationStart(Animation animation) {
}
  });
}

}

我无法回答我自己的问题,因为我的声誉低于100,所以改为编辑我的问题:

此处更正:

   public class QuizSplashActivity extends QuizActivity {
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
    //        configAnimationEndListener();     
         setContentView(R.layout.splash);
        configSharedPref();
        getSharedPrefTime();
        startAnimation();
  }

@Override
protected void onPause() {
    super.onPause();
    stopAnimationPerControl();
    stopAnimationForAllChilds();
}

@Override
protected void onResume() {
    super.onResume();
    //Lets kick of all the animations again for full effect
    startAnimation();

    //Having the cheat here for a sec
/*  Intent myIntent = new Intent(this, QuizMenuActivity.class);
    startActivity(myIntent);
    QuizSplashActivity.this.finish();*/
}

/**
 * Configures and kicks of animation
 */
private void startAnimation(){
    configAnimationsPerControl();
    configAnimationsForAllChilds();
}

/**
 * finds the specific control by its id and applies an Animation per Control
 * the Animation is then started using the control
 */    
private void configAnimationsPerControl() {
    TextView logo1 = (TextView) findViewById(R.id.TextViewTopTitle);
    Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.fade_in);
    logo1.startAnimation(fade1);        

    TextView logo2 = (TextView) findViewById(R.id.TextViewBottomTitle);
    Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.fade_in2);

    fade2.setAnimationListener(new AnimationListener() {

@Override
    public void onAnimationStart(Animation arg0) {
            // TODO Auto-generated method stub

        }

@Override
public void onAnimationRepeat(Animation arg0) {
            // TODO Auto-generated method stub

        }

@Override
  public void onAnimationEnd(Animation arg0) {
            startActivity(new Intent(QuizSplashActivity.this,
      QuizMenuActivity.class));
QuizSplashActivity.this.finish();

        }
    });

    logo2.startAnimation(fade2);
}

private void configAnimationsForAllChilds() {

//gets animation resource
Animation spinin = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
//Applys animation xml to a Layout controller
LayoutAnimationController controller = new LayoutAnimationController(spinin);

//Applies LayoutAnimation controller to each table Row next
TableLayout table = (TableLayout) findViewById(R.id.tableLayout01);
for (int i = 0; i < table.getChildCount(); i++) {
    TableRow row = (TableRow) table.getChildAt(i);
    row.setLayoutAnimation(controller);
}
}

/**
 * Stops all animations
 * This should be called on pause
 */
private void stopAnimationPerControl() {
    //Stop Animation
    TextView logo1 = (TextView) findViewById(R.id.TextViewTopTitle);
    logo1.clearAnimation();

    TextView logo2 = (TextView) findViewById(R.id.TextViewBottomTitle);
    logo2.clearAnimation();
}

/**
 * Goes through a Layout control and fetch all child
 * Stops the Animation for each
 */
   private void stopAnimationForAllChilds() {
    TableLayout table = (TableLayout) findViewById(R.id.tableLayout01);
    for (int i = 0; i < table.getChildCount(); i++) {
        TableRow row = (TableRow) table.getChildAt(i);
        row.clearAnimation();
    }
}

  /**
   * Listen into the control with the longest animation
   * Thin Starts an intent to launch the menu screen
    * then closes the Splash screen from the application stack as you 
   * don't want the back button to return the user here again
   */
  /* private void configAnimationEndListener() {
      Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.custom_anim);
      fade2.setAnimationListener(new AnimationListener() {

 @Override
  public void onAnimationEnd(Animation animation) {
            startActivity(new Intent(QuizSplashActivity.this,
     QuizMenuActivity.class));
            QuizSplashActivity.this.finish();
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationStart(Animation animation) {
        }
    });
}*/

/**
 * Configures the preferences for global usage in the application
 */
private void configSharedPref() {
    SharedPreferences settingsAct = getPreferences(MODE_PRIVATE);
    SharedPreferences.Editor actPrefEditor = settingsAct.edit();

    String time = new Time().toString();        
    actPrefEditor.putString("Current time", time);
    actPrefEditor.commit();
}

/**
 * Retrieves the preferences for global usage in the application
 */
private String getSharedPrefTime(){
    String time = null;

    SharedPreferences settings = getPreferences(MODE_PRIVATE);
    if(settings.contains("Current time")){
        //We have a user Name
        time = settings.getString("Current time", "Default");
        Log.i("Shared Pref",  "******** " + time);
    }
    return time;
}   
   }

1 个答案:

答案 0 :(得分:0)

  

我一直试图弄清楚为什么我的AnimationListener事件在调试时没有被击中。

我看不到你在哪里开始实际拥有注册监听器的动画。你设置的唯一一个地方是configAnimationEndListener(),那个动画永远不会开始。