Thursday 23 May 2013

Read inbox messages of a particular number and display them in an activity

Share Preference in Android


Create Share Preference:

                 SharedPreferences sp=getSharedPreferences("HB", 0);
                SharedPreferences.Editor Ed=sp.edit();
                Ed.putString("HBstr",Value );             
                Ed.putInt("INTnm",Value);
                Ed.putBoolean("BOOLEANnm",Value);
                Ed.commit();


Get Value from Share preference:

                    SharedPreferences sp1=this.getSharedPreferences("HB",null);
          String abc=sp1.getString("HBstr", defValue);

          SharedPreferences sp2=this.getSharedPreferences("HB",0);
          int  fontsize = sp2.getInt("INTnm", 0);


          SharedPreferences sp3=this.getSharedPreferences("HB",0);
          boolean ans_bg=sp3.getBoolean("BOOLEANnm",false);


I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)

Monday 20 May 2013

Generate 3D Pie Chart using Google Chart Tools


import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

public class Android3dPieChartActivity extends Activity {
 
 final static String urlGoogleChart 
  = "http://chart.apis.google.com/chart";
 final static String urlp3Api 
  = "?cht=p3&chs=400x150&chl=A|B|C&chd=t:";
 
 EditText inputA, inputB, inputC;
 Button generate;
 ImageView pieChart;
 
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        inputA = (EditText)findViewById(R.id.adata);
        inputB = (EditText)findViewById(R.id.bdata);
        inputC = (EditText)findViewById(R.id.cdata);
        generate = (Button)findViewById(R.id.generate);
        pieChart = (ImageView)findViewById(R.id.pie);
        generate.setOnClickListener(generateOnClickListener);
    }
    
    Button.OnClickListener generateOnClickListener
    = new Button.OnClickListener(){

  @Override
  public void onClick(View arg0) {
   // TODO Auto-generated method stub
   String A = inputA.getText().toString();
   String B = inputB.getText().toString();
   String C = inputC.getText().toString();
   String urlRqs3DPie = urlGoogleChart 
     + urlp3Api 
     + A + "," + B + "," + C;
   
   Bitmap bm3DPie = loadChart(urlRqs3DPie);
   if(bm3DPie == null){
    Toast.makeText(Android3dPieChartActivity.this,
      "Problem in loading 3D Pie Chart",
      Toast.LENGTH_LONG).show(); 
   }else{
    pieChart.setImageBitmap(bm3DPie); 
   }
  }};
  
 private Bitmap loadChart(String urlRqs){
  Bitmap bm = null;
  InputStream inputStream = null;
  
  try {
   inputStream = OpenHttpConnection(urlRqs);
   bm = BitmapFactory.decodeStream(inputStream);
   inputStream.close(); 
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace(); 
  }
  
  return bm; 
 }
     
 private InputStream OpenHttpConnection(String strURL) throws IOException{
  InputStream is = null;
  URL url = new URL(strURL);
  URLConnection urlConnection = url.openConnection();
       
  try{
   HttpURLConnection httpConn = (HttpURLConnection)urlConnection;
   httpConn.setRequestMethod("GET");
   httpConn.connect();
   
   if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
    is = httpConn.getInputStream();  
   } 
  }catch (Exception ex){
  }
  
  return is;  
 }
}

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<LinearLayout
 android:orientation="horizontal"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">
<TextView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="A "
    />
<EditText 
    android:id="@+id/adata"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:inputType="number" />
</LinearLayout>
<LinearLayout
 android:orientation="horizontal"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">
<TextView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="B "
    />
<EditText 
    android:id="@+id/bdata"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:inputType="number" />
</LinearLayout>
<LinearLayout
 android:orientation="horizontal"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content">
<TextView  
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="C "
    />
<EditText 
    android:id="@+id/cdata"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:inputType="number" />
</LinearLayout>
<Button 
    android:id="@+id/generate"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="Generate 3D Pie Chart"
    />
<ImageView
    android:id="@+id/pie"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    />
</LinearLayout>


Permission: "android.permission.INTERNET" is needed.


Sunday 19 May 2013

PullToRefresh in android

Hello Friends, here today i am going to post Pull To refresh sample, It allows a user to refresh a list by pulling down and releasing from the top of the list. Hop this will help you.


Download Source code:

I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.

Thank you :)

Physical Enter key of device in Android


EditText edtsearch=(EditText) findViewById(R.id.search_edttext);
       edtsearch.setOnEditorActionListener(new OnEditorActionListener()
       {

              public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
              {
if(actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_NULL|| event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
                     {                      
                           SearchValue=edtsearch.getText().toString();
InputMethodManager mgr = (InputMethodManager)   getSystemService(Context.INPUT_METHOD_SERVICE);
                           mgr.hideSoftInputFromWindow(edtsearch.getWindowToken(), 0);

                           //Wright your Code here................
                           return true;
                     }
                     else
                     {
                           return false;
                     }
              }
       }


I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)

Physical back key of device in Android


public boolean onKeyDown(int keyCode, KeyEvent event)
       {
              if ((keyCode == KeyEvent.KEYCODE_BACK))
              {
                     keyCode=KeyEvent.KEYCODE_1;
                     //code here....
              }
              return super.onKeyDown(keyCode, event);
       }

Friday 17 May 2013

Paypal integration in android




http://androiddevelopement.blogspot.in/2011/04/adding-paypal-payment-in-android.html 

http://tutorials-android.blogspot.in/2012/05/paypal-intigration-in-android.html 


I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)

Pagination of screen in Android

There are different Pagination is available in android. you can used as per your requirements.

CIrcle Flow indicator.
 
Title Flow indicator.
Different view Flow.
AsyncDataLoading.

Download Code here...


i will be happy if you will provide your feedback or follow this blog. Any suggesion and help will be appreciated.
Thank you :)

Open wifi settings in 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="How to open Wifi Settings Demo" />

    <Button
        android:id="@+id/open"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Open Wifi settings" />

</LinearLayout>



OpenWifiSettingsDemo.class

public class OpenWifiSettingsDemo extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Button open = (Button)findViewById(R.id.open);
            open.setOnClickListener(new OnClickListener() {
                  @Override
                  public void onClick(View v) {
                        openWifiSettings();
                  }
            });
      }

      public void openWifiSettings(){

            final Intent intent = new Intent(Intent.ACTION_MAIN, null);
            intent.addCategory(Intent.CATEGORY_LAUNCHER);
            final ComponentName cn = newComponentName("com.android.settings","com.android.settings.wifi.WifiSettings");
            intent.setComponent(cn);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity( intent);
      }
}


I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)

Menu in android

http://www.androidhive.info/2011/09/how-to-create-android-menus/ 


I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)

Map in android

These are the important link for using map in android.

Display current location on Google Map:

http://wptrafficanalyzer.in/blog/showing-current-location-in-google-maps-with-gps-and-locationmanager-in-android/

http://www.androidhive.info/2012/01/android-working-with-google-maps/ 

http://android-er.blogspot.in/2009/11/display-marker-on-mapview-using.html 

http://android-codes-examples.blogspot.in/2011/04/google-map-example-in-android-with-info.html 

http://android-er.blogspot.in/2012/06/add-mylocationoverlay-on-openstreetmap.html 

http://android-er.blogspot.in/2012/05/create-multi-marker-openstreetmap-for.html 

Map with Map overlay: 
http://androidcodesnips.blogspot.in/2011/08/gooogle-maps-for-android.html 
http://android-coding.blogspot.in/2011/08/detect-touch-on-marker-in-mapview.html

Route Map in Android: 

Uri uri = Uri.parse("http://maps.google.com/maps?&saddr=slat,slon&daddr=dlat,dlon"); 

Here saddr -> source address 
daddr -> destination address 
slat -> source latitude 
slon -> source longitude 
dlat -> destination latitude 
dlon -> destination longitude 
Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
startActivity(intent); 

Google MapV2:
http://ramsandroid4all.blogspot.in/2013/03/google-maps-android-api-v2.html
http://patesush.blogspot.in/2012/12/how-to-create-app-for-google-map-v2-in.html

http://www.solutionanalysts.com/blog/android-custom-marker-icon-google-map-android-api-v2
http://wptrafficanalyzer.in/blog/custom-marker-icon-for-google-maps-android-api-v2/
http://wptrafficanalyzer.in/blog/gps-and-google-map-in-android-applications-series/

Saturday 11 May 2013

calender with gridview in Android



I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.
Thank you :)


Thursday 9 May 2013

Custom Animation Dialog in Android

Hello friends today i post sample code of custom animation dialog. i every app there will be thread is used for loading data from server or Database, here is the post which you can create custom dialog for your application with its themes.


Create dialog.xml in res folder :

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

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:contentDescription="@string/app_name"
        android:src="@drawable/loader1" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:contentDescription="@string/app_name"
        android:src="@drawable/pharma" />

</RelativeLayout>        

Create progress_anim.xml in res-anim folder :

<?xml version="1.0" encoding="utf-8"?>
<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromDegrees="0"
    android:toDegrees="360"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite" />


if you want loading dialog in particular activity.Here is the class file in this case :

public class MainActivity extends Activity
{

       @Override
       protected void onCreate(Bundle savedInstanceState)
       {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.dialog);
             
              ImageView imageView=(ImageView) findViewById(R.id.imageView1);
             
              Animation a = AnimationUtils.loadAnimation(MainActivity.this, R.anim.progress_anim);
              a.setDuration(1000);
              imageView.startAnimation(a);
             
              a.setInterpolator(new Interpolator()
              {
                  private final int frameCount = 8;

                  @Override
                  public float getInterpolation(float input)
                  {
                      return (float)Math.floor(input*frameCount)/frameCount;
                  }
              });
       }

if you want loading dialog with whole application with thread/AsyncTask .Here is the class file: it has different constructor for different look of dialog.

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import android.widget.ImageView;

public class LodingDialog extends Dialog
{
       private Dialog mpd = null;
       private LayoutInflater lyt_Inflater = null;
       public LodingDialog(Context context)
       {     
              super(context);
              LodingDialog1(context,"Loading...",false);
       }


       public LodingDialog(Context context,String LoadingText)
       {
              super(context);
              LodingDialog1(context,LoadingText,false);

       }

       public LodingDialog(Context context,String LoadingText, boolean cancelable)
       {
              super(context);
              LodingDialog1(context,LoadingText,cancelable);
       }

       public void LodingDialog1(Context context,String LoadingText, boolean cancelable)
       {
              lyt_Inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

              final View view_lyt = lyt_Inflater.inflate(     R.layout.dialognull);

              ImageView imageView = (ImageView) view_lyt.findViewById(R.id.imageView1);
              Animation a = AnimationUtils.loadAnimation(context, R.anim.progress_anim);
              a.setDuration(2000);
              imageView.startAnimation(a);

              a.setInterpolator(new Interpolator()
              {
                     private final int frameCount = 8;

                     @Override
                     public float getInterpolation(float input)
                     {
                           return (float)Math.floor(input*frameCount)/frameCount;
                     }
              });
              mpd = new Dialog(context, R.style.ThemeDialogCustom);
              mpd.setContentView(view_lyt);
              mpd.setCancelable(cancelable);
              mpd.show();
       }

       public void hide()
       {

              if (mpd != null) {
                     if (mpd.isShowing())
                     {
                           mpd.dismiss();
                     }
              }

       }
}


style.xml:

<resources>

    <style name="ThemeDialogCustom">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowIsFloating">false</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
        <item name="android:windowBackground">@color/transparent_color</item>
        <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
        <item name="android:colorBackgroundCacheHint">@null</item>
    </style>

</resources>


colors.xml:

<resources>
    <color name="transparent_color">#00000000</color> 
</resources>