package app.test;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
class FrameAnimationActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.frame_animations_layout);
this.setupButton();
}
private void setupButton()
{
Button b = (Button)this.findViewById(R.id.startFAButtonId);
b.setOnClickListener(
new Button.OnClickListener(){
public void onClick(View v)
{
parentButtonClicked(v);
}
});
}
private void parentButtonClicked(View v)
{
animate();
}
private void animate()
{
ImageView imgView = (ImageView)findViewById(R.id.imageView);
imgView.setVisibility(ImageView.VISIBLE);
imgView.setBackgroundResource(R.drawable.frame_animation);
AnimationDrawable frameAnimation =
(AnimationDrawable) imgView.getBackground();
if (frameAnimation.isRunning())
{
frameAnimation.stop();
}
else
{
frameAnimation.stop();
frameAnimation.start();
}
}
}
public class Test extends Activity
{
Menu myMenu = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
//call the parent to attach any system level menus
super.onCreateOptionsMenu(menu);
this.myMenu = menu;
MenuInflater mi = this.getMenuInflater();
mi.inflate(R.menu.main_menu,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
handleMenus(item);
return true;
}
private void handleMenus(MenuItem item)
{
this.appendMenuItemText(item);
if (item.getItemId() == R.id.menu_clear)
{
this.emptyText();
}
else if (item.getItemId() == R.id.menu_list_animation)
{
Intent intent = new Intent(this, FrameAnimationActivity.class);
startActivity(intent);
}
}
private TextView getTextView()
{
TextView tv =
(TextView)this.findViewById(R.id.textViewId);
return tv;
}
public void appendText(String text)
{
TextView tv =
(TextView)this.findViewById(R.id.textViewId);
tv.setText(tv.getText() + text);
}
public void appendMenuItemText(MenuItem menuItem)
{
String title = menuItem.getTitle().toString();
TextView tv =
(TextView)this.findViewById(R.id.textViewId);
tv.setText(tv.getText() + "\n" + title + ":" + menuItem.getItemId());
}
private void emptyText()
{
TextView tv =
(TextView)this.findViewById(R.id.textViewId);
tv.setText("");
}
}
//main.xml