Android Marshmallow 6.0 is release see some feture of this android os watch video to details 


https://www.youtube.com/watch?v=N72ksDKrX6c&feature=youtu.be
https://www.youtube.com/watch?v=iZqDdvhTZj0
In design section fragment is very important feature to set view as a fream you can
set diffarent diffarent view into signle window in that case you can use fragment .
Before the using of Fragment need to userstand how the fragment work , so you need to learn
fragment life cycle

below image is show the life cycle , execution follow of fragment

                     

How can data set in Pei Chat

package com.myandroid.peichart;

2.Main.java file


package com.myandroid.peichart;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class Main extends Activity {
 List<PieDetailsItem> piedata = new ArrayList<PieDetailsItem>(0);

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  PieDetailsItem item;
  int maxCount = 0;
  int itemCount = 0;
  int items[] = { 20, 40, 10, 15, 5 };
  int colors[] = { -6777216, -16776961, -16711681, -12303292, -7829368 };
  String itemslabel[] = { " vauesr ur 100", " vauesr ur 200",
    " vauesr ur 300", " vauesr ur 400", " vauesr ur 500" };
  for (int i = 0; i < items.length; i++) {
   itemCount = items[i];
   item = new PieDetailsItem();
   item.count = itemCount;
   item.label = itemslabel[i];
   item.color = colors[i];
   piedata.add(item);
   maxCount = maxCount + itemCount;
  }
  int size = 155;
  int BgColor = 0xffa11b1;
  Bitmap mBaggroundImage = Bitmap.createBitmap(size, size,
    Bitmap.Config.ARGB_8888);
  View_PieChart piechart = new View_PieChart(this);
  piechart.setLayoutParams(new LayoutParams(size, size));
  piechart.setGeometry(size, size, 2, 2, 2, 2,             2130837504      );
  piechart.setSkinparams(BgColor);
  piechart.setData(piedata, maxCount);
  piechart.invalidate();
  piechart.draw(new Canvas(mBaggroundImage));
  piechart = null;
  ImageView mImageView = new ImageView(this);
  mImageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
    LayoutParams.WRAP_CONTENT));
  mImageView.setBackgroundColor(BgColor);
  mImageView.setImageBitmap(mBaggroundImage);
  LinearLayout finalLayout = (LinearLayout) findViewById(R.id.pie_container);
  finalLayout.addView(mImageView);
 }
}

========================================================================
3.PieDetailsItem.java file


package com.myandroid.peichart;

public class PieDetailsItem {
public int count, color;
public float percent;
public String label;

}

============================================================

4.View_PieChart .java file



package com.myandroid.peichart;

import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

public class View_PieChart extends View
{
 public static final int WAIT = 0;
 public static final int IS_READY_TO_DRAW = 1;
 public static final int IS_DRAW = 2;
 private static final float START_INC = 30;
 private Paint mBagpaints = new Paint();
 private Paint mLinePaints = new Paint();

 private int mWidth;
 private int mHeight;
 private int mGapTop;
 private int mGapBottm;
 private int mBgcolor;
 private int mGapleft;
 private int mGapright;
 private int mState = WAIT;
 private float mStart;
 private float mSweep;
 private int mMaxConnection;
 private List<PieDetailsItem> mdataArray;

 public View_PieChart(Context context) {
  super(context);
  Log.w(" single cons ", " single cons");
 }

 public View_PieChart(Context context, AttributeSet attr) {
  super(context, attr);
  Log.w(" double cons ", " double cons");
 }

 @Override
 protected void onDraw(Canvas canvas) {
  super.onDraw(canvas);
  if (mState != IS_READY_TO_DRAW) {
   return;
  }
  canvas.drawColor(mBgcolor);
  mBagpaints.setAntiAlias(true);
  mBagpaints.setStyle(Paint.Style.FILL);
  mBagpaints.setColor(0x88FF0000);
  mBagpaints.setStrokeWidth(0.0f);
  mLinePaints.setAntiAlias(true);
  mLinePaints.setColor(0xff000000);
  mLinePaints.setStrokeWidth(3.0f);
  mLinePaints.setStyle(Paint.Style.STROKE);
  RectF mOvals = new RectF(mGapleft, mGapTop, mWidth - mGapright, mHeight
    - mGapBottm);
  mStart = START_INC;
  PieDetailsItem item;
  for (int i = 0; i < mdataArray.size(); i++) {
   item = (PieDetailsItem) mdataArray.get(i);
   mBagpaints.setColor(item.color);
   mSweep = (float) 360* ((float) item.count / (float) mMaxConnection);
   canvas.drawArc(mOvals, mStart, mSweep, true, mBagpaints);
   canvas.drawArc(mOvals, mStart, mSweep, true, mLinePaints);
   mStart = mStart + mSweep;
  }

  mState = IS_DRAW;
 }

 public void setGeometry(int width, int height, int gapleft, int gapright,
   int gaptop, int gapbottom, int overlayid) {

  mWidth = width;
  mHeight = height;
  mGapleft = gapleft;
  mGapright = gapright;
  mGapBottm = gapbottom;
  mGapTop = gaptop;

 }

 public void setSkinparams(int bgcolor) {
  Log.w(" Set bg color  : ", bgcolor + "");
  mBgcolor = bgcolor;
 }

 public void setData(List<PieDetailsItem> data, int maxconnection) {
  mdataArray = data;
  mMaxConnection = maxconnection;
  Log.w(" Max Connection  ", maxconnection + " " + "  Adataarray :"
    + data.toString());
  mState = IS_READY_TO_DRAW;
 }

 public void setState(int state) {
  mState = state;
 }

 public int getColorValues(int index) {
  if (mdataArray == null) {
   return 0;
  }

  else if (index < 0)
   return ((PieDetailsItem) mdataArray.get(0)).color;
  else if (index > mdataArray.size())
   return ((PieDetailsItem) mdataArray.get(mdataArray.size() - 1)).color;
  else
   return ((PieDetailsItem) mdataArray.get(mdataArray.size() - 1)).color;

 }

}

========================================================================
XML file Detail

main.xml
========

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

 <LinearLayout android:id="@+id/pie_container"
  android:layout_width="fill_parent" android:layout_height="wrap_content"

  android:orientation="vertical">
 </LinearLayout>

 <TextView android:id="@+id/tvAndroid" android:layout_width="110dip"
  android:layout_height="wrap_content" android:layout_below="@+id/pie_container"
  android:text="Android" android:padding="10dip" android:textStyle="bold"
  android:background="#444544" android:layout_marginTop="200dip" />

 <TextView android:id="@+id/tvIphone" android:layout_width="110dip"
  android:layout_height="wrap_content" android:layout_below="@+id/pie_container"
  android:layout_toRightOf="@+id/tvAndroid" android:text="IPhone"
  android:padding="10dip" android:textStyle="bold" android:background="#878887"
  android:layout_marginTop="200dip" />
 <TextView android:id="@+id/tvBlackBerry" android:layout_width="110dip"
  android:layout_height="wrap_content" android:layout_below="@+id/pie_container"
  android:layout_toRightOf="@+id/tvIphone" android:text="BlackBerry"
  android:padding="10dip" android:textStyle="bold" android:background="#98967F"
  android:layout_marginTop="200dip" />

 <TextView android:id="@+id/tvNokia" android:layout_width="160dip"
  android:layout_height="wrap_content" android:layout_below="@+id/tvBlackBerry"
  android:layout_toRightOf="@+id/tvSamsung" android:text="Others"
  android:padding="10dip" android:textStyle="bold" android:background="#A1A1A1" />

 <TextView android:id="@+id/tvSamsung" android:layout_width="160dip"
  android:layout_height="wrap_content" android:layout_below="@+id/tvAndroid"
  android:text="Nokia" android:padding="10dip" android:textStyle="bold"

  android:background="#0000FF" />
</RelativeLayout> 

==================================================================
5. AndroidManifest.xml



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myandroid.peichart"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".PeiChartActivity"
            android:label="@string/app_name" >
        </activity>
        <activity android:name="Main"><intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter></activity>
        <activity android:name="PeiChartActivity"></activity>
    </application>

</manifest>
========================================================



Auto search on listview TextWatcher android

activity class:

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class Search_DemoMainActivity extends Activity {



private ListView lv1;
   private String lv_arr[] =
    {
"Android", "iPhone",
"BlackBerry", "me",
"J2ME", "Listview",
"ArrayAdapter", "ListItem",
"Us", "UK", "India"
   };
ListView lst;
EditText edt;
ArrayAdapter<String> arrad;
Button btn;




    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
     
        lv1=(ListView)findViewById(R.id.listView1);
        edt = (EditText) findViewById(R.id.editText1);
     
             
     
        btn=(Button)findViewById(R.id.button1);
     
        arrad =  new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , lv_arr);
     
        lv1.setAdapter(arrad);
        // By using setTextFilterEnabled method in listview we can filter the listview items.
 
        btn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

// TODO Auto-generated method stub

}
});
     
     
        lv1.setTextFilterEnabled(true);
     
        lv1.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {

// TODO Auto-generated method stub

AlertDialog.Builder builder = new AlertDialog.Builder(Search_DemoMainActivity.this);

builder.setTitle("Pick a color");

builder.setSingleChoiceItems(lv_arr, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {

Toast.makeText(getApplicationContext(), lv_arr[item], Toast.LENGTH_SHORT).show();

}});

AlertDialog alert = builder.create();
alert.show();
}
});
     
     
        edt.addTextChangedListener(new TextWatcher()    
        {  
       
    public void onTextChanged( CharSequence arg0, int arg1, int arg2, int arg3)  
       {          
    // TODO Auto-generated method stub  
   
       }  
   
   
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3)
        {      
        // TODO Auto-generated method stub  
       
        }  
       
        @Override    
        public void afterTextChanged( Editable arg0)  
                   {
               
        Search_DemoMainActivity.this.arrad.getFilter().filter(arg0);
       
                   }  
       
        });
        }
       
 
     
    }
==============================================================
main.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/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <requestFocus />
    </EditText>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

    <ListView
        android:id="@+id/listView1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>


How can make AudioRecorder android

main 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" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />


    <Button
        android:id="@+id/button1"
        android:layout_width="125dp"
        android:layout_height="wrap_content"
        android:text="Play" />

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_below="@+id/button1"
        android:layout_marginTop="20dp"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <MediaController
            android:id="@+id/mediaController1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
         
             >
        </MediaController>

    </LinearLayout>


    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="44dp"
        android:layout_toRightOf="@+id/button1"
        android:text="Stop" />

</RelativeLayout>

=============================================
activity class :AudioRecoderActivity .java
===================================

code :
====================

import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.SurfaceView;
import android.view.View.OnClickListener;
import android.widget.Button;


public class AudioRecoderActivity extends Activity {
private SurfaceHolder surfaceHolder;
private SurfaceView surfaceView;
public MediaRecorder mrec = new MediaRecorder();
private Button startRecording ;
private Button stopRecording ;
//private Button stopRecording = null;
File video;
AudioRecorder audioRecorder;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
 
    startRecording = (Button)findViewById(R.id.button1);
    stopRecording= (Button)findViewById(R.id.button2);
 
 
  /*recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
44100, AudioFormat.CHANNEL_IN_STEREO,
AudioFormat.ENCODING_PCM_16BIT, 1000);
*/
 
    audioRecorder=new AudioRecorder();
 
 
    startRecording.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

try {
audioRecorder.start();
} catch (IOException e) {


}


}
});
 
    stopRecording.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {

try {
audioRecorder.stop();
} catch (IOException e) {


}


}
});
 
}
}

===============================================
2 nd java class :AudioRecorder
=========================




import java.io.IOException;
import java.util.Random;

import android.media.MediaRecorder;

public class AudioRecorder {

final MediaRecorder recorder = new MediaRecorder();
 public void start() throws IOException {

   recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
   recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
   recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

   int min = 1;
   int max = 999;
 
    Random r = new Random();
    int ramNum = r.nextInt(max - min + 1) + min;

    recorder.setOutputFile("/mnt/sdcard/recode_"+ramNum+".3gp");
    recorder.prepare();
    recorder.start();
 
 }


 public void stop() throws IOException {
   recorder.stop();
   recorder.release();
 }


}
===================================================================
take two permission in menifest :

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>






how can take picture by camera simple code android

main 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" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Capture Image" />

    <Button
        android:id="@+id/btCamera_main"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Take Picture" />

</LinearLayout>

======================================

activity class Name=CameraTestAppsActivity.java
============
code :
======

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class CameraTestAppsActivity extends Activity {

Button btCamera;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btCamera=(Button)findViewById(R.id.btCamera_main);
     
     
        btCamera.setOnClickListener(new OnClickListener()
        {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(mInterface.getTempFile()));
     startActivityForResult(intent, 0);

}
});
     
   
    }
 
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK && requestCode == 0) {
    String result = data.toURI();
    // ...
    }
    }
}

==========================================


how can dwonlode pdf,music file,vedio from url or http server programing android


call this function :

 private void startDownload() {
     //   String url = Searchpdf.ArrUrl.get(IntPos);// set your url where from dwonlode the file li
        new DownloadFileAsync().execute("http://db.lcs.mit.edu/madden/html/vldb04.pdf");
    }

and after ..

 @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
            case DIALOG_DOWNLOAD_PROGRESS:
                mProgressDialog = new ProgressDialog(this);
                mProgressDialog.setMessage("Downloading file..");
                mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                mProgressDialog.setCancelable(false);
                mProgressDialog.show();
                return mProgressDialog;
            default:
                return null;
        }
    }
    class DownloadFileAsync extends AsyncTask<String, String, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            showDialog(DIALOG_DOWNLOAD_PROGRESS);
           
            //new added
            ProgressBar myProgress = (ProgressBar)findViewById(R.id.progressBar);
          //  myProgress.setMax(maxValue);
            myProgress.setVisibility(View.GONE);
        }

        @Override
        protected String doInBackground(String... aurl) {
            int count;

            try {
                URL url = new URL(aurl[0]);
                URLConnection conexion = url.openConnection();
                conexion.connect();
               // File root = Environment.getExternalStorageDirectory();
                int lenghtOfFile = conexion.getContentLength();
                Log.d("ANDRO_ASYNC", "Lenght of file: " + lenghtOfFile);
               
                InputStream input = new BufferedInputStream(url.openStream());
                //  "/sdcard/moon.m4v"
               
                OutputStream output = new FileOutputStream("/sdcard/"+fileName);
               // FileOutputStream f = new FileOutputStream(new File(root, fileName));

                byte data[] = new byte[1024];

                long total = 0;

                while ((count = input.read(data)) != -1) {
                    total += count;
                    publishProgress(""+(int)((total*100)/lenghtOfFile));
                    output.write(data, 0, count);
                }

                output.flush();
                output.close();
                input.close();
            } catch (Exception e) {}
            return null;

        }
        protected void onProgressUpdate(String... progress) {
             Log.d("ANDRO_ASYNC",progress[0]);
             mProgressDialog.setProgress(Integer.parseInt(progress[0]));
             //newly added
          //   myProgress.setProgress(Integer.parseInt(progress[0]));
        }

        @Override
        protected void onPostExecute(String unused) {
            dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
        }
    }


how can add jar library

create folder lib in you project
and after put the jar into lib folder

and then , right click on your project ->property -> Java Build path->on Libraries , add jar file
->ok

Activity life cycle of Android



create XML file android



       String HEADER_TAG="<?xml version=\"1.0\" encoding=\"UTF-8\"?>" ;
String ROOT_TAG_NAME="Example";

String TAG_START_FRIST="<";
String TAG_START_END=">";

String TAG_END_FRIST="</";
String TAG_END_END=">" ;
String TAG_NAME_ARRAY[]={

               "No","City","State"
             };
String TAG_VALUE[]={

        "1","kolkata","West bengal",
        "2","delhi","Delhi",
        "3","pune","Maharastra",
        "4","bengalor","AP","5","mumbai"
       
       };


in your main use this


String returnXML;
-------------------     returnXML=myXMLCreator(ROOT_TAG_NAME,TAG_NAME_ARRAY,TAG_VALUE);



=======================================================================

Use this mathod and paraMeterPass Value from the main

private String myXMLCreator(String mROOT_TAG_NAME,String mTAG_NAME_ARRAY[],String mTAG_VALUE[]) {




if((mTAG_VALUE.length)%(mTAG_NAME_ARRAY.length)!=0)
{
int rem;
 rem=(mTAG_VALUE.length)%(mTAG_NAME_ARRAY.length);

String msg=" tag name array and value array not same ";
Log.v(" ERROR  ",msg);
      }



String XMLString=HEADER_TAG+"\n"+
           TAG_START_FRIST+mROOT_TAG_NAME+TAG_START_END+"\n";

         for(int i=0,j=0;j<mTAG_VALUE.length;i++,j++)
          {
              XMLString=XMLString+TAG_START_FRIST+mTAG_NAME_ARRAY[i]+TAG_START_END;
           
          XMLString=XMLString+mTAG_VALUE[j];
         
              XMLString=XMLString+TAG_END_FRIST+mTAG_NAME_ARRAY[i]+TAG_END_END+" \n ";
           
          if(i==2){
         
            i=-1;                                    // one array store all data and tag have three
           }
                                                                 // after  3 time change value from the 0
          }
 
   XMLString=XMLString+TAG_END_FRIST+ROOT_TAG_NAME+TAG_END_END;

return XMLString;
     }

IRCTC Share Price Declines by 2% Despite 30% Jump in Q4 Net Profit; Board Announces Dividend of INR 2 per Share

Introduction: The share price of Indian Railway Catering and Tourism Corporation (IRCTC) experienced a decline of 2% in today's trading ...