I created one animation in which I used one radio button as object and a matrix background. when the activity starts the object will move along the each cells in the matrix. now I want the object to be stopped when i click on it. how can i do this??
public class MainActivity extends Activity {
RadioButton rad;
Animation animation1;
Context context = this;
Button move;
Handler handler = new Handler();
Runnable handlerTask;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridview = (GridView) findViewById(R.id.gridView1);
rad = (RadioButton) findViewById(R.id.radioButton1);
// move=(Button)findViewById(R.id.button1);
gridview.setAdapter(new ImageAdapter(this));
animation1 = AnimationUtils.loadAnimation(this, R.anim.animation);
// userInputHandler();
/*
* move.setOnClickListener(new View.OnClickListener() {
*
* #Override public void onClick(View arg0) { // TODO Auto-generated
* method stub
*/
handlerTask = new Runnable() {
public void run() {
if (rad.isChecked()) {
animation1.cancel();
} else {
rad.startAnimation(animation1);
}
}
};
handlerTask.run();
// }
// });
}
public void onAnimationEnd(Animation animation) {
rad.setVisibility(View.VISIBLE);
}
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
rad.setVisibility(View.VISIBLE);
}
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
rad.setVisibility(View.VISIBLE);
}
}
Related
In my code, I have implemented the sliding layouts. I have a front page which runs a video, while the user interaction is being done with layouts sliding up and down. Here's the code:
package org.udoo.androidadkdemobidirect;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Point;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.ToggleButton;
import android.widget.VideoView;
import java.io.DataOutputStream;
import java.io.IOException;
//import org.udoo.androidadkdemobidirect.sAdkManager;
public class MainActivity extends Activity{
// private static final String TAG = "UDOO_AndroidADKFULL";
private static String mAdkManager=null;
private VideoView myVideoView;
private MediaController mediaControls=null;
private int position = 0;
private String ppm_val=null;
private ToggleButton buttonLED;
private TextView distance;
private Button res_nextBtn;
private TextView res_tv;
private AdkReadTask mAdkReadTask;
private int myInt = -10;
private TextView tv;
private FrameLayout current=null;
private Animation slide_down;
private Animation slide_up;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
//hideNavigationBar();
buttonLED = (ToggleButton) findViewById(R.id.toggleButtonLed);
distance = (TextView) findViewById(R.id.textViewIntro);
buttonLED.setVisibility(View.INVISIBLE);
tv = (TextView) findViewById(R.id.ppm_unique);
if (mediaControls == null) {
mediaControls = new MediaController(this);
}
slide_down = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.slide_down);
slide_up = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.slide_up);
res_nextBtn = (Button) findViewById(R.id.result_next_btn);
res_tv = (TextView) findViewById(R.id.result_number_text);
myVideoView = (VideoView) findViewById(R.id.videoView);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
myVideoView.getHolder().setFixedSize(size.x, size.y);
tv.setText(""+size.x+":"+size.y);
final Animation animation1 = new AlphaAnimation(0.0f, 1.0f);
animation1.setDuration(1000);
animation1.setStartOffset(000);
final Animation animation2 = new AlphaAnimation(1.0f, 0.0f);
animation2.setDuration(1000);
animation2.setStartOffset(500);
//animation1 AnimationListener
animation1.setAnimationListener(new Animation.AnimationListener(){
#Override
public void onAnimationEnd(Animation arg0) {
// start animation2 when animation1 ends (continue)
distance.startAnimation(animation2);
}
#Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
});
//animation2 AnimationListener
animation2.setAnimationListener(new Animation.AnimationListener(){
#Override
public void onAnimationEnd(Animation arg0) {
// start animation1 when animation2 ends (repeat)
distance.startAnimation(animation1);
}
#Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
});
distance.startAnimation(animation1);
try {
myVideoView.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.sound_758));
} catch (Exception e) {
}
// myVideoView.requestFocus();
//we also set an setOnPreparedListener in order to know when the video file is ready for playback
myVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mediaPlayer) {
// close the progress bar and play the video
//progressDialog.dismiss();
//if we have a position on savedInstanceState, the video playback should start from here
mediaPlayer.setLooping(true);
myVideoView.seekTo(position);
if (position == 0) {
myVideoView.start();
} else {
//if we come from a resumed activity, video playback will be paused
myVideoView.pause();
}
}
});
((MyApplication) this.getApplication()).init(this);
((MyApplication) this.getApplication()).open();
if (mAdkReadTask==null) {
mAdkReadTask = new AdkReadTask();
mAdkReadTask.execute();
}
}
/************************************************************************************************
* *
* OnClickEvents *
* *
************************************************************************************************/
public void BR_onBuyClick(View view) {
next((FrameLayout) findViewById(R.id.flavours_inc_layout));
}
public void Flavours_onBackClick(View v){
next((FrameLayout) findViewById(R.id.br_inc_layout));
}
public void Flavours_onF1Click(View view) {
next((FrameLayout) findViewById(R.id.ty_inc_layout));
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
home();
}
},
5000);
}
public void Flavours_onF2Click(View view) {
next((FrameLayout) findViewById(R.id.ty_inc_layout));
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
home();
}
},
5000);
}
public void Flavours_onF3Click(View view) {
next((FrameLayout) findViewById(R.id.ty_inc_layout));
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
home();
}
},
5000);
}
private void home() {
current.startAnimation(slide_down);
current.setVisibility(View.INVISIBLE);
current=null;
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
distance.startAnimation(slide_up);
distance.setVisibility(View.VISIBLE);
final Animation animation1 = new AlphaAnimation(0.0f, 1.0f);
animation1.setDuration(1000);
animation1.setStartOffset(000);
final Animation animation2 = new AlphaAnimation(1.0f, 0.0f);
animation2.setDuration(1000);
animation2.setStartOffset(500);
//animation1 AnimationListener
animation1.setAnimationListener(new Animation.AnimationListener(){
#Override
public void onAnimationEnd(Animation arg0) {
// start animation2 when animation1 ends (continue)
distance.startAnimation(animation2);
}
#Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
});
//animation2 AnimationListener
animation2.setAnimationListener(new Animation.AnimationListener(){
#Override
public void onAnimationEnd(Animation arg0) {
// start animation1 when animation2 ends (repeat)
distance.startAnimation(animation1);
}
#Override
public void onAnimationRepeat(Animation arg0) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation arg0) {
// TODO Auto-generated method stub
}
});
distance.startAnimation(animation1);
((MyApplication) getApplication()).write("1");
}
},
1000);
}
public void BR_onRecycleClick(View view) {
next((FrameLayout) findViewById(R.id.ready_inc_layout));
}
public void proc_onDoneClick(View v){
next((FrameLayout) findViewById(R.id.delay_inc_layout));
onDelay();
}
public void proc_onCancelClick(View v){
next((FrameLayout) findViewById(R.id.br_inc_layout));
}
private void onDelay() {
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.delay_progressBar);
progressBar.setProgress(0);
progressBar.setVisibility(View.VISIBLE);
ValueAnimator animator = new ValueAnimator();
animator.setObjectValues(0, 100);
animator.setDuration(7000);
final TextView tv = (TextView) findViewById(R.id.delay_textPoints);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
tv.setText("" + animation.getAnimatedValue() +"%");
}
});
animator.addListener(new AnimatorListenerAdapter(){
#Override
public void onAnimationEnd(Animator animator) {
progressBar.setVisibility(View.INVISIBLE);
((MyApplication) getApplication()).write("4");
next((FrameLayout) findViewById(R.id.result_inc_layout));
((MyApplication) getApplication()).write("8");
res_nextBtn.setVisibility(View.INVISIBLE);
}
});
animator.start();
}
public void Res_onNextClick(View v){
next((FrameLayout) findViewById(R.id.points_inc_layout));
onPoints();
}
private void onPoints() {
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.points_progressBar);
progressBar.setProgress(0);
progressBar.setVisibility(View.VISIBLE);
final ValueAnimator animator = new ValueAnimator();
if (myInt>=0) {
animator.setObjectValues(0, (myInt) * 5);
}
else{
animator.setObjectValues(0, 1);
}
animator.setDuration(2000);
final TextView tv = (TextView) findViewById(R.id.points_textPoints);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
tv.setText("" + animation.getAnimatedValue());
}
});
animator.addListener(new AnimatorListenerAdapter(){
#Override
public void onAnimationEnd(Animator animator) {
progressBar.setVisibility(View.INVISIBLE);
}
});
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
animator.start();
}
},
1500);
}
public void pts_onConfirmClick(View v){
next((FrameLayout) findViewById(R.id.end_inc_layout));
((MyApplication) getApplication()).write("3");
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
home();
}
},
5000);
}
public void Ready_onYesClick(View v){
((MyApplication) this.getApplication()).write("2");
next((FrameLayout) findViewById(R.id.processing_inc_layout));
onProcessing();
}
private void onProcessing() {
final int[] i = {0};
final int[] drawablearray = new int[]{R.drawable.processing_butts_3, R.drawable.processing_butts_2, R.drawable.processing_butts_1, R.drawable.processing_butts_0};
final ImageView backgroundImageView = (ImageView) findViewById(R.id.processing_textButts);
backgroundImageView.postDelayed(new Runnable() {
public void run() {
backgroundImageView.setImageResource(drawablearray[i[0]++ % drawablearray.length]);
backgroundImageView.postDelayed(this, 1000);
}
}, 1500);
}
public void Ready_onCancelClick(View v){
next((FrameLayout) findViewById(R.id.br_inc_layout));
}
#Override
public void onResume() {
super.onResume();
((MyApplication) this.getApplication()).write("1");
}
#Override
public void onPause() {
super.onPause();
}
#Override
public void onDestroy() {
super.onDestroy();
}
private void hideNavigationBar() {
try {
Process process = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(process.getOutputStream());
/*
enable = enable navigation bar
disable = disable navigation bar
*/
os.writeBytes("pm enable com.android.systemui\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
process.waitFor();
//////////////////////////////////////
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public String output="";
/*
* We put the readSerial() method in an AsyncTask to run the
* continuous read task out of the UI main thread
*/
private class AdkReadTask extends AsyncTask<Void, String, String> {
private boolean running = true;
public void pause(){
running = false;
}
public void start(){
running = true;
}
#Override
protected String doInBackground(Void... params) {
while(running) {
if (this.isCancelled())
break;
String s = ((MyApplication) getApplication()).read();
publishProgress(s);
}
return output;
}
#Override
protected void onProgressUpdate(String... progress) {
if(progress[0].charAt(0)=='P') {
/*
TODO: change text+ppm_val to image+text
TODO: send ppm values to server
*/
tv.setText("Air quality: " + progress[0].substring(1, progress[0].length()));
ppm_val = progress[0].substring(1, progress[0].length());
((MyApplication) getApplication()).setPPM(ppm_val);
}
else if (progress[0].charAt(0)=='R'){
/*
TODO: add server verification of RFID
*/
distance.startAnimation(slide_down);
distance.setVisibility(View.GONE);
next((FrameLayout) findViewById(R.id.br_inc_layout));
}
else if (progress[0].charAt(0)=='C'){
/*
TODO: send data to server
*/
res_tv.setText(""+(int) progress[0].charAt(1));
myInt = (int) progress[0].charAt(1);
res_nextBtn.setVisibility(View.VISIBLE);
}
}
#Override
protected void onPostExecute(String result){
}
}
private void next(final FrameLayout fl) {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) fl.getLayoutParams();
if (fl == (FrameLayout) findViewById(R.id.flavours_inc_layout)){
params.height = (int) (size.y*0.6);
}
else{
params.height = (int) (size.y*0.3);
}
params.width = size.x;
int delay_delta = 1000;
// Set it back.
fl.setLayoutParams(params);
if(current!=null){
current.startAnimation(slide_down);
current.setVisibility(View.INVISIBLE);
delay_delta=0;
}
new android.os.Handler().postDelayed(
new Runnable() {
public void run() {
fl.startAnimation(slide_up);
fl.setVisibility(View.VISIBLE);
current = fl;
}
},
1200-delay_delta);
}
}
And everything worked fine before I tried changing the slide-up height. After I set up a special case for a layout 0.6*y instead of 0.3*y. The layout is being not displayed above 0.3 mark. It does function, and when I click the supposed button place it displays just before sliding down.
Ok, it was solved by accident. I changed all View.INVISIBLE to View.GONE and it works like swiss watch. I guess there's some black magic involved and I would really appreciate (and accept the answer of course) if someone could explain to me why it works. Thanks.
I have change code to below and my purpose is to set a button
when I click the timer run,how to change the code below? thanks
new code below
I have change code to below and my purpose is to set a button
when I click the timer run,how to change the code below? thanks
new code below
public class MainActivity extends Activity {
/** Called when the activity is first created. */
Handler aHandler;
TextView aTextView;
Button aButton;
EditText aEditText;
Handler aHandler01;
TextView aTextView01;
Button aButton01;
EditText aEditText01;
Boolean checker=false;
int count = 11;
int count01 = 11;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
aEditText = (EditText)findViewById(R.id.editText01);
aTextView = (TextView)findViewById(R.id.TextView01);
aEditText01 = (EditText)findViewById(R.id.editText02);
aTextView01 = (TextView)findViewById(R.id.TextView02);
aButton=(Button)findViewById(R.id.button01);
aButton01=(Button)findViewById(R.id.button02);
//第一個計時器
aButton.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v){ if(!aEditText.getText().toString().equalsIgnoreCase(""))
{count=Integer.parseInt(aEditText.getText().toString());}
aHandler = new Handler();
if(checker==false){
aHandler.post(runnable);
checker=true;
}
}
});
//第二個計時器
aButton01.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
if (!aEditText01.getText().toString().equalsIgnoreCase("")) {
count01 = Integer.parseInt(aEditText01.getText().toString());
}
aHandler01 = new Handler();
aHandler01.post(runnable01);
}
});
}
//第一個計時器
final Runnable runnable = new Runnable() {
public void run() { // TODO Auto-generated method stub
if (count> 0) {
aTextView.setText(Integer.toString(count-1));
count--;
aHandler.postDelayed(runnable, 1000);
}else{
aTextView.setText("boom");
}
}
};
//第二個計時器
final Runnable runnable01 = new Runnable() {
public void run() { // TODO Auto-generated method stub
if (count01> 0) {
aTextView01.setText(Integer.toString(count01-1));
count01--;
aHandler01.postDelayed(runnable01, 1000);
}else{
aTextView01.setText("boom");
}
}
};
#Override
protected void onPause() { // TODO Auto-generated method stub
super.onPause();
if (aHandler != null) {
aHandler.removeCallbacks(runnable);
}
}
}
try this
private Handler handler = new Handler();
Boolean checker=false;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
aEditText = (EditText)findViewById(R.id.editText01);
aTextView = (TextView)findViewById(R.id.TextView01);
aButton=(Button)findViewById(R.id.button01);
aButton.setOnClickListener(new Button.OnClickListener(){
#Override
public void onClick(View v){ if(!aEditText.getText().toString().equalsIgnoreCase(""))
{count=Integer.parseInt(aEditText.getText().toString());}
if(!checker){
checker=true;
handler.post(runnable);//to start timer
}
}
});
}
final Runnable runnable = new Runnable() {
public void run() {
// TODO Auto-generated method stub
if(checker)
{
checker=false;
return;
}
if (count> 0) {
aTextView.setText(""+Integer.toString(count-1));
count--;
aHandler.postDelayed(runnable, 1000);
}else{
aTextView.setText("boom");
}
}
};
as you are assigning the value to 'count' variable in OnCreate from editText when editText is empty, it is returning null string which then you are parsing for int value which returns NumberFormatException
try to do it as follows
if (!aEditText.getText().toString().equalsIgnoreCase(""))
{
count = Integer.parseInt(aEditText.getText().toString());
}
OR you can assign a value to 'count' from editText on any button's click or using TextChangedListener(TextWatcher) to monitor and get text from edittext at run time.
Im rotating a LinearLayout, using an ObjectAnimator. Clicking the button causes the LinearLayout to rotate 360(degrees) with the bottom part as the Pivot.
After the Layout completes the rotation, it leaves back a 'trail'/black mark and the complete view looks odd. How do I avoid this from happening? After the Layout completes the 360 animation, I want the view to look as it did in the beginning (clean basically).
Is there a view.refresh or update command im suppose to call somewhere?
1)How do I have a clean looking view at the end?
2)When the image is is in the intermediatestate, why does the back-part appear black? How do I get that to look while(ie,color of the relative layout)?
InitialState>IntermediateState>FinalState:
MainActivity
Button bt1;
float pivotX=0f;
float pivotY=0f;
int a=0;
float width,height;
ViewGroup mContainer=null;
Thread t;
private Handler mHandler = new Handler();
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bt1 = (Button) findViewById(R.id.button1);
mContainer = (ViewGroup) findViewById(R.id.container);
bt1.setOnClickListener(this);
t=new Thread()
{
#Override
public void run()
{
try {
while(true)
{
relativeLayout.postInvalidate();
}
} catch (Exception e) {
// TODO: handle exception
}
}
};
}
#Override
public void onWindowFocusChanged(boolean hasFocus)
{
super.onWindowFocusChanged(hasFocus);
//Here you can get the size!
width = mContainer.getWidth();
height = mContainer.getHeight();
pivotX = mContainer.getPivotX()+width;
pivotY = mContainer.getPivotY()+height;
mContainer.setPivotX(pivotX);
mContainer.setPivotY(pivotY);
}
private void rotate()
{
a -=360;
ObjectAnimator rotate = ObjectAnimator.ofFloat(mContainer, View.ROTATION_X,a);
rotate.setDuration(2000);
AnimatorSet aSet = new AnimatorSet();
aSet.play(rotate);
aSet.start();
mHandler.post(new Runnable()
{
#Override
public void run()
{
b+=1;
relativeLayout.invalidate();
relativeLayout.postInvalidate();
bt1.setText(Integer.toString(b));
}
});
rotate.addListener(new AnimatorListener()
{
#Override
public void onAnimationStart(Animator animation) {
// TODO Auto-generated method stub
//relativeLayout.invalidate();
t.start();
}
#Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
//mContainer.invalidate();
//relativeLayout.invalidate();
try {
t.join();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
}
#Override
public void onClick(View v)
{
switch(v.getId())
{
case R.id.button1:
rotate();
break;
}
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="#140A1F"
android:orientation="horizontal" >
</LinearLayout>
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/container"
android:layout_centerHorizontal="true"
android:layout_marginTop="80dp"
android:text="Rotate" />
</RelativeLayout>
Edit: Added a thread.
**Edit2:**** Added a handler and commented out the thread
Adding this to the code fixes the view once the animation is competed, but the intermediate stage still looks the same. Will update this once I figure that out.
rotate.addListener(new AnimatorListener()
{
#Override
public void onAnimationStart(Animator animation) {
// TODO Auto-generated method stub
relativeLayout.invalidate();
}
#Override
public void onAnimationRepeat(Animator animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animator animation) {
// TODO Auto-generated method stub
//mContainer.invalidate();
relativeLayout.invalidate();
}
#Override
public void onAnimationCancel(Animator animation) {
// TODO Auto-generated method stub
}
});
I'm new to android. I'm trying to play video after animation , but before animation video is playing, after animation video is not playing, i have used animationlistener, it's also not working for me.
public class MainActivity extends Activity{
ImageView image;
VideoView video;
ImageButton play;
RelativeLayout videolay;
Animation LR;
ZoomView zoomview;
String uriPath = null;
static boolean playpause = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView) findViewById(R.id.image);
video = (VideoView) findViewById(R.id.video);
play = (ImageButton) findViewById(R.id.play);
videolay = (RelativeLayout) findViewById(R.id.videolay);
zoomview = (ZoomView) findViewById(R.id.zoomlay);
LR = AnimationUtils.loadAnimation(this, R.anim.move);
videolay.startAnimation(LR);
LR.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
uriPath = "android.resource://" + MainActivity.this.getPackageName() + "/" + "raw/video";
Log.v("uripath",""+uriPath);
MediaController ctrl = new MediaController(MainActivity.this);
ctrl.setVisibility(View.GONE);
video.setMediaController(ctrl);
video.setVideoURI(Uri.parse(uriPath));
}
});
video.setOnTouchListener(new OnTouchListener()
{
#Override
public boolean onTouch(View v, MotionEvent event)
{
video.pause();
playpause = false;
play.setVisibility(View.VISIBLE);
return false;
}
});
play.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
Log.v("buttonclicked","");
if(playpause == false)
{
video.start();
Log.v("videostarted","");
playpause = true;
play.setVisibility(View.GONE);
}
}
});
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}
#Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Please help to fix this.
I need to toast the stopwatch's value
ie.,time taken between start and stop
If i click the stop button it should toast that time duration.
How to do this?
Here i have tried some code
chrono_meter.java
public class Chrono_meter extends Activity {
Chronometer chr;
Button btn_stop_travel;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.chronometer_layout);
chr = (Chronometer)findViewById(R.id.chronometer1);
chr.start();
btn_stop_travel = (Button)findViewById(R.id.btn_stop_inspection);
btn_stop_travel.setOnClickListener(mStopListener);
}
View.OnClickListener mStopListener = new OnClickListener() {
public void onClick(View v) {
chr.stop();
}
};
}
Try this
View.OnClickListener mStopListener = new OnClickListener() {
public void onClick(View v) {
chr.stop();
Toast.makeText(Chrono_meter.this, chr.getText(), Toast.LENGTH_LONG).show() ;
}
};