Here is the solution, tested and verified
@Override
protected void onPause() {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
}
@Override
protected void onPause() {
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
}
package com.successmobigroup.imageswitcherexample; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.view.animation.Animation; import android.widget.Button; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.Toast; import android.widget.ViewSwitcher.ViewFactory; import com.successmobigroup.imageswitcherexample.R; public class ImageSwitcherExampleActivity extends Activity implements ViewFactory{ ImageSwitcher is; int [] imgid = {R.drawable.android1,R.drawable.android2,R.drawable.android3,R.drawable.android4}; Button prev, next; int count =0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image_switcher_example); is = (ImageSwitcher)findViewById(R.id.imageSwitcher1); prev = (Button)findViewById(R.id.button1); next = (Button)findViewById(R.id.button2); is.setFactory(this); is.setInAnimation(this, android.R.anim . slide_in_left); is.setOutAnimation(this, android.R.anim.slide_out_right); prev.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if(count>0) { count--; try{ is.setImageResource(imgid[count]); } catch(Exception e) { e.printStackTrace(); } } else { Toast.makeText(ImageSwitcherExampleActivity.this, "First", Toast.LENGTH_LONG).show(); } } }); next.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if(count<imgid.length) { try{ is.setImageResource(imgid[count]); } catch(Exception e) { e.printStackTrace(); } count++; } else { Toast.makeText(ImageSwitcherExampleActivity.this, "Last", Toast.LENGTH_LONG).show(); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.image_switcher_example, menu); return true; } @Override public View makeView() { // TODO Auto-generated method stub ImageView iv = new ImageView(this); iv.setScaleType(ImageView.ScaleType.FIT_CENTER); iv.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); return iv; } }
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".ImageSwitcherExampleActivity" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:orientation="vertical" > <ImageSwitcher android:id="@+id/imageSwitcher1" android:layout_width="match_parent" android:layout_height="match_parent" > </ImageSwitcher> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="<<" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text=">>" /> </LinearLayout> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextSwitcher
android:id="@+id/textSwitcher1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</TextSwitcher>
</LinearLayout>
tv = (TextSwitcher) findViewById(R.id.textSwitcher1);
tv.setInAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_in));
tv.setOutAnimation(AnimationUtils.loadAnimation(this,
android.R.anim.fade_out));
class MyGestureDetector extends SimpleOnGestureListener {
final String TAG = MyGestureDetector.class.getSimpleName();
// for touch left or touch right events
private static final int SWIPE_MIN_DISTANCE = 80; //default is 120
private static final int SWIPE_MAX_OFF_PATH = 400;
private static final int SWIPE_THRESHOLD_VELOCITY = 70;
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
return super.onSingleTapConfirmed(e);
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Log.d(TAG, " on filing event, first velocityX :" + velocityX +
" second velocityY" + velocityY);
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
if(e1.getX() - e2.getX()
> SWIPE_MIN_DISTANCE && Math.abs(velocityX)
> SWIPE_THRESHOLD_VELOCITY) {
onHorizonTouch(true); // left
} else if (e2.getX() - e1.getX()
> SWIPE_MIN_DISTANCE && Math.abs(velocityX)
> SWIPE_THRESHOLD_VELOCITY) {
onHorizonTouch(false); // right
}
} catch (Exception e) {
// nothing
}
return false;
}
void onHorizonTouch(Boolean toLeft) {
if(!toLeft && imageIdx>0) {
tv.setInAnimation(AnimationUtils.loadAnimation(
MainActivity.this, android.R.anim.fade_in));
tv.setOutAnimation(AnimationUtils.loadAnimation(
MainActivity.this, android.R.anim.fade_out));
imageIdx--;
MainActivity.this.tv.setText("Text1");
}
if(toLeft && imageIdx<1) {
vs.setInAnimation(AnimationUtils.loadAnimation(
MainActivity.this, android.R.anim.fade_in));
vs.setOutAnimation(AnimationUtils.loadAnimation(
MainActivity.this, android.R.anim.fade_out));
imageIdx++;
MainActivity.this.tv.setText("Text2");
}
}
}
gestureDetector = new GestureDetector(new MyGestureDetector());
View.OnTouchListener gestureListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
tv.setOnTouchListener(gestureListener);
in the toolbar.
tools/ path.android list targets
android create project --target <target-id> --name MyFirstApp \ --path <path-to-workspace>/MyFirstApp --activity MainActivity \ --package com.example.myfirstapp
<target-id> with an id from the list of targets (from the previous step) and replace <path-to-workspace> with the location in which you want to save your Android projects.platform-tools/ as well as the tools/ directory to your PATH environment variable.AndroidManifest.xml<uses-sdk> element. This declares your app's compatibility with different Android versions using the android:minSdkVersion andandroid:targetSdkVersion attributes. For your first app, it should look like this:<manifest xmlns:android="http://schemas.android.com/apk/res/android" ... > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> ...</manifest>
android:targetSdkVersion as high as possible and test your app on the corresponding platform version. For more information, read Supporting Different Platform Versions.src/Activity class that runs when your app is launched using the app icon.res/drawable-hdpi/layout/values/Activity class starts and loads a layout file that says "Hello World." The result is nothing exciting, but it's important that you understand how to run your app before you start developing.
from the toolbar.ant debug
platform-tools/ directory is included in your PATH environment variable, then execute:adb install bin/MyFirstApp-debug.apk

from the toolbar.<sdk>/tools/ and execute:android avd
from the toolbar.ant debug
platform-tools/ directory is included in your PATH environment variable, then execute:adb install bin/MyFirstApp-debug.apk