Android : The Connection To Adb Is Down, And A Severe Error Has Occurred.

Problem
- Example] The connection to adb is down, and a severe error has occured.
- Example] You must restart adb and Eclipse.
- Example] Please ensure that adb is correctly located at 
Solution
In some cases, Android project may get crashed or shutdown abnormally, and caused the “adb.exe” to function abnormally.
To solve it, just restart the “adb.exe” process. Restart the Eclipse will not shut down the “adb.exe” process automatically, you need to kill it manually.
Try below steps:
  1. Close the Eclipse if running
  2. Go to the Android SDK platform-tools directory in Command Prompt
  3. type adb kill-server
  4. then type adb start-server
  5. No error message is thrown while starting ADB server, then adb is started successfully.
  6. Now you can start Eclipse again.
it worked for me this way, Eclipse should be closed before issuing these commands.
Restart your phone as well!

PHP Alert Dialog in webview

Activity.jave
here is onpagefinished() method
http://developer.android.com/reference/android/webkit/WebViewClient.html#onPageFinished(android.webkit.WebView, java.lang.String)

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String ss = "sdffffffffffffffffffffffff rgfvdg dfgh";
web = (WebView) findViewById(R.id.webView1);

web.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {

web.loadUrl("javascript:(function() { alert('hai'); })()");
}
});

web.setWebChromeClient(new WebChromeClient());
web.getSettings().setJavaScriptEnabled(true);
web.loadDataWithBaseURL("", ss, "text/html", "UTF-8", " ");
}

XML R.layout.activity_main

   <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

output




High lite Specific text in Android Webview

this is main activity class


public class HighliteActivity extends Activity {

@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final WebView webView = (WebView) findViewById(R.id.webView);
webView.loadUrl("http://polamreddyn.blogspot.in/2013/01/android-text-links-using-linkify.html");

webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
Log.i("", "" +url);

@SuppressWarnings("deprecation")
                              // here by default "of" selected
int i = webView.findAll("of"); // is not supposed to crash
Toast.makeText(getApplicationContext(), "Found " + i + " results !", Toast.LENGTH_SHORT).show();
try {
Method m = WebView.class.getMethod("setFindIsUp",Boolean.TYPE);
m.invoke(webView, true);
} catch (Throwable ignored) {
} }
});
}
}

Here `OF` word is selected





Button Animation Example

Android Button Animation Example

MainActivity .java


public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final Animation animTranslate = AnimationUtils.loadAnimation(this,R.anim.anim_translate);
final Animation animAlpha = AnimationUtils.loadAnimation(this,R.anim.anim_alpha);
final Animation animScale = AnimationUtils.loadAnimation(this,R.anim.anim_scale);
final Animation animRotate = AnimationUtils.loadAnimation(this,R.anim.anim_rotate);

Button btnTranslate = (Button) findViewById(R.id.translate);
Button btnAlpha = (Button) findViewById(R.id.alpha);
Button btnScale = (Button) findViewById(R.id.scale);
Button btnRotate = (Button) findViewById(R.id.rotate);

btnTranslate.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
v.startAnimation(animTranslate);
}
});
btnAlpha.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
v.startAnimation(animAlpha);
}
});
btnScale.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
v.startAnimation(animScale);
}
});
btnRotate.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
v.startAnimation(animRotate);
}
});
}
XML 


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/translate"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Translate Animation" />

    <Button
        android:id="@+id/alpha"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Alpha Animation" />

    <Button
        android:id="@+id/scale"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Scale Animation" />

    <Button
        android:id="@+id/rotate"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:text="Rotate Animation" />

</LinearLayout>

Create new fili in
  /res/anim/anim_alpha.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator" >

    <alpha
        android:duration="500"
        android:fromAlpha="1.0"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:toAlpha="0.1" />
</set>
 /res/anim/anim_rotate.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
   android:interpolator="@android:anim/linear_interpolator">
   <rotate
       android:fromDegrees="0"
       android:toDegrees="360"
       android:pivotX="50%"
       android:pivotY="50%"
       android:duration="500"
       android:startOffset="0"
       android:repeatCount="1"
       android:repeatMode="reverse" />
</set>

 /res/anim/anim_scale.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
   android:interpolator="@android:anim/linear_interpolator">
   <scale
       android:fromXScale="1.0"
       android:toXScale="3.0"
       android:fromYScale="1.0"
       android:toYScale="3.0"
       android:pivotX="50%"
       android:pivotY="50%"
       android:duration="500"
       android:repeatCount="1"
       android:repeatMode="reverse" />
</set>


 /res/anim/anim_translate.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator" >

    <translate

        android:duration="500"
        android:fromXDelta="0"
        android:repeatCount="1"
        android:repeatMode="reverse"
        android:toXDelta="100%p" />
</set>

All contacts Attatched to .vcf file And send to Mail

 Here is code get all contacts of your mobile and store to file and that file send to mail. see here http://stackoverflow.com/questions/12798001/android-how-to-send-multiple-contacts-are-attached-in-single-vcf-file-and-send


 button = (Button) findViewById(R.id.send);          
     button.setOnClickListener(new OnClickListener() {          
        public void onClick(View v) {        
            data();
        }
    });  
    getVcardString();           
}       

 public static void getVcardString() {   

    String path = null;     
    String vfile = null;

     vfile = "Contacts.vcf";           
    Cursor phones = mContext.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                    null, null, null);

    phones.moveToFirst();
    Log.i("Number of contacts", "cursorCount" +phones.getCount());  
    for(int i =0;i<phones.getCount();i++)   {       

         String lookupKey = phones.getString(phones.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
         Log.i("lookupKey", " " +lookupKey);
         Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_VCARD_URI, lookupKey);
         AssetFileDescriptor fd;

         try  {
             fd = mContext.getContentResolver().openAssetFileDescriptor(uri, "r");
             FileInputStream fis = fd.createInputStream();
             byte[] buf = new byte[(int) fd.getDeclaredLength()];
             fis.read(buf);
             String VCard = new String(buf);          

             path = Environment.getExternalStorageDirectory().toString() + File.separator + vfile;
             FileOutputStream mFileOutputStream = new FileOutputStream(path, true);
             mFileOutputStream.write(VCard.toString().getBytes());    

             phones.moveToNext();               

             filevcf = new File(path);
             Log.i("file", "file" +filevcf);

         }catch(Exception e1) {
             e1.printStackTrace();  
         }
    }       
    Log.i("TAG", "No Contacts in Your Phone");          
}

protected void data() {             
    File filelocation = filevcf ;     
    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
    sharingIntent.setType("vnd.android.cursor.dir/email");      
    sharingIntent.setType("application/x-vcard");       
    sharingIntent.putExtra(Intent.EXTRA_EMAIL, "mail@gmail.com" );        
    sharingIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+filelocation.getAbsolutePath()));
    startActivity(Intent.createChooser(sharingIntent, "Send email"));            
 }  

Paint Undo And Redo Example


DrawActivity 

public class DrawActivity extends Activity {

     private Canvas  mCanvas;
     private Path    mPath;
     private Paint       mPaint;
     private ArrayList<Path> paths = new ArrayList<Path>();
     private ArrayList<Path> undonePaths = new ArrayList<Path>();
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final DrawView drawView = new DrawView(this);
        setContentView(R.layout.activity_main);
     
        FrameLayout frm_layout=(FrameLayout) findViewById(R.id.main_frame);
        frm_layout.addView(drawView);
     
        Button btn_undo=(Button) findViewById(R.id.undo);
        btn_undo.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {            
                drawView.onClickUndo();
            }
        });

        Button btn_redo=(Button) findViewById(R.id.redo);
        btn_redo.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {        
                drawView.onClickRedo();
            }
        });
     
        /*Button color = (Button) findViewById (R.id.color);
        color.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

int _color = R.color.red;
new PickerDialog(v.getContext(),new OnColorChangedListener()  {

         public void colorChanged(int color) {
         mPaint.setColor(color);
          }
      }, mPaint.getColor(), _color).show();

}
});  */    
    }
 
    /// color changed function, getting value from ColorPickerDialog ///

    public void colorChanged(int color) {
    mPaint.setColor(color);
    }
 
    public class DrawView extends View implements OnTouchListener  {
     
     
        public DrawView(Context context)   {    
        super(context);
        setFocusable(true);
        setFocusableInTouchMode(true);    
            this.setOnTouchListener(this);
         
            mPaint = new Paint();
            mPaint.setAntiAlias(true);
            mPaint.setDither(true);
            mPaint.setColor(Color.GREEN);
            mPaint.setStyle(Paint.Style.STROKE);
            mPaint.setStrokeJoin(Paint.Join.ROUND);
            mPaint.setStrokeCap(Paint.Cap.ROUND);
            mPaint.setStrokeWidth(5);
            mCanvas = new Canvas();
            mPath = new Path();
            paths.add(mPath);      
        }            
     
        @Override
        protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        }

        @Override
        protected void onDraw(Canvas canvas) {          
        for (Path p : paths){
        canvas.drawPath(p, mPaint);
        }
        }

        private float mX, mY;
        private static final float TOUCH_TOLERANCE = 4;

        private void touch_start(float x, float y) {
        mPath.reset();
        mPath.moveTo(x, y);
        mX = x;
        mY = y;
        }
         
        private void touch_move(float x, float y) {
        float dx = Math.abs(x - mX);
        float dy = Math.abs(y - mY);
        if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
        mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2);
        mX = x;
        mY = y;
        }
        }
         
        private void touch_up() {
        mPath.lineTo(mX, mY);
        // commit the path to our offscreen
        mCanvas.drawPath(mPath, mPaint);
        // kill this so we don't double draw          
        mPath = new Path();
        paths.add(mPath);
        }

        public void onClickUndo () {
        if (paths.size()>0)  {
        undonePaths.add(paths.remove(paths.size()-1));
        invalidate();
        } else  {
        Log.i("undo", "Undo elsecondition");
        }          
        }

        public void onClickRedo (){
        if (undonePaths.size()>0)  {
        paths.add(undonePaths.remove(undonePaths.size()-1));
        invalidate();
        }
        else  {
        Log.i("undo", "Redo elsecondition");
        }          
        }

        public boolean onTouch(View arg0, MotionEvent event) {
        float x = event.getX();
        float y = event.getY();

        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        touch_start(x, y);
        invalidate();
        break;
        case MotionEvent.ACTION_MOVE:
        touch_move(x, y);
        invalidate();
        break;
        case MotionEvent.ACTION_UP:
        touch_up();
        invalidate();
        break;
        }
        return true;
        }
    }
}

XML


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearlayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#FF4500"
        android:orientation="horizontal" >
     
        <Button
            android:id="@+id/undo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Undo" />

        <Button
            android:id="@+id/redo"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Redo" />    

      <!--   <Button
            android:id="@+id/color"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Color" /> -->
    </LinearLayout>

    <FrameLayout
        android:id="@+id/main_frame"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/linearlayout" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/cat" />
    </FrameLayout>

</RelativeLayout>

Select DateRange UsingRangePicker.

  /* * This Method is for select range from picker. * */ private fun selectDateRangeUsingRangePicker () { pageNumber = 1 val displ...