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);
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.ant debug
platform-tools/
directory is included in your PATH
environment variable, then execute:adb install bin/MyFirstApp-debug.apk
<sdk>/tools/
and execute:android avd
ant debug
platform-tools/
directory is included in your PATH
environment variable, then execute:adb install bin/MyFirstApp-debug.apk
This post would be helpful if you’re planning to book railway ticket (Indian Railways Tatkal).
Today morning, I was trying to book tatkal ticket from my office laptop/computer and it was giving me the the following error/warning. So, I’m unable to book the ticket. I’ve connected my data card to get new public IP and booked the ticket.
Recently, the Railway booking system had gone through very interesting and useful enhancements ( https://www.irctc.co.in/ ).
Tatkal ticken booking timing has been modified.
IP tracing is enabled. This will help to avoid bulk booking by agents. Because of IP tracing we won’t be able to book railways tickets from our office computers. Most of the offices use proxy to provide internet connectivity to individual computers however they’ve only one public IP. Hence, we won’t be able to book ticket (Only 2 tatkal tickets between 10:00 Hrs to 12:00 Hrs per IP Address.) if somebody from your office already booked a ticket or two just before :)
More Details about the enhancements can be found below.
Solution:
|
LinearLayout
, use: android:layout_gravity="center"
.RelativeLayout
, use: android:layout_centerInParent="true"
.Imageview.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
ImageView.setGravity(Gravity.CENTER)
public class ScrollTextView extends TextView {
// scrolling feature
private Scroller mSlr;
// milliseconds for a round of scrolling
private int mRndDuration = 10000;
// the X offset when paused
private int mXPaused = 0;
// whether it's being paused
private boolean mPaused = true;
/*
* constructor
*/
public ScrollTextView(Context context) {
this(context, null);
// customize the TextView
setSingleLine();
setEllipsize(null);
setVisibility(INVISIBLE);
}
/*
* constructor
*/
public ScrollTextView(Context context, AttributeSet attrs) {
this(context, attrs, android.R.attr.textViewStyle);
// customize the TextView
setSingleLine();
setEllipsize(null);
setVisibility(INVISIBLE);
}
/*
* constructor
*/
public ScrollTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// customize the TextView
setSingleLine();
setEllipsize(null);
setVisibility(INVISIBLE);
}
/**
* begin to scroll the text from the original position
*/
public void startScroll() {
// begin from the very right side
mXPaused = -1 * getWidth();
// assume it's paused
mPaused = true;
resumeScroll();
}
/**
* resume the scroll from the pausing point
*/
public void resumeScroll() {
if (!mPaused)
return;
// Do not know why it would not scroll sometimes
// if setHorizontallyScrolling is called in constructor.
setHorizontallyScrolling(true);
// use LinearInterpolator for steady scrolling
mSlr = new Scroller(this.getContext(), new LinearInterpolator());
setScroller(mSlr);
int scrollingLen = calculateScrollingLen();
int distance = scrollingLen - (getWidth() + mXPaused);
int duration = (new Double(mRndDuration * distance * 1.00000
/ scrollingLen)).intValue();
setVisibility(VISIBLE);
mSlr.startScroll(mXPaused, 0, distance, 0, duration);
invalidate();
mPaused = false;
}
/**
* calculate the scrolling length of the text in pixel
*
* @return the scrolling length in pixels
*/
private int calculateScrollingLen() {
TextPaint tp = getPaint();
Rect rect = new Rect();
String strTxt = getText().toString();
tp.getTextBounds(strTxt, 0, strTxt.length(), rect);
int scrollingLen = rect.width() + getWidth();
rect = null;
return scrollingLen;
}
/**
* pause scrolling the text
*/
public void pauseScroll() {
if (null == mSlr)
return;
if (mPaused)
return;
mPaused = true;
// abortAnimation sets the current X to be the final X,
// and sets isFinished to be true
// so current position shall be saved
mXPaused = mSlr.getCurrX();
mSlr.abortAnimation();
}
@Override
/*
* override the computeScroll to restart scrolling when finished so as that
* the text is scrolled forever
*/
public void computeScroll() {
super.computeScroll();
if (null == mSlr) return;
if (mSlr.isFinished() && (!mPaused)) {
this.startScroll();
}
}
public int getRndDuration() {
return mRndDuration;
}
public void setRndDuration(int duration) {
this.mRndDuration = duration;
}
public boolean isPaused() {
return mPaused;
}
}
<yourpackagename.ScrollTextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/scrolltext">
</yourpackagename.ScrollTextView>
ScrollTextView scrolltext=(ScrollTextView) findViewById(R.id.scrolltext);
scrolltext.setText(yourscrollingtext);
scrolltext.setTextColor(Color.BLACK);
scrolltext.startScroll();
private int mRndDuration = 10000;//reduce the value of mRndDuration to increase scrolling speed