Wednesday, December 22, 2010

Android Customize Dialog

Android-Customize Dialog window.


Full Source Code:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/LinearLayout01"
    android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@drawable/bg_android" android:orientation="vertical"
    android:gravity="center" android:layout_width="200dip">
    <TextView android:id="@+id/TextView01"
   
    android:layout_height="wrap_content"
        android:textColor="#ffa800" android:textStyle="bold"
       
        android:layout_width="wrap_content" android:text=" iamvijayakumar.blogs.com "></TextView>
    <TextView android:id="@+id/TextView02" android:layout_height="wrap_content"
        android:textColor="#FFFFFF" android:layout_width="wrap_content"
        android:textStyle="bold"
        android:layout_margin="7dip" android:text="Testing Customize Dialog"
        android:gravity="center"></TextView>
    <Button android:layout_width="60dip"
    android:layout_height="40dip" android:text="OK"
    android:id="@+id/OkButton"></Button>
</LinearLayout>






CustomizeDialog.java
package com.CustomDialog;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;

/** Class Must extends with Dialog */
/** Implement onClickListener to dismiss dialog when OK Button is pressed */
public class CustomizeDialog extends Dialog implements OnClickListener {
    Button okButton;

    public CustomizeDialog(Context context) {
        super(context);
        /** 'Window.FEATURE_NO_TITLE' - Used to hide the title */
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        /** Design the dialog in main.xml file */
        setContentView(R.layout.main);
        okButton = (Button) findViewById(R.id.OkButton);
        okButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        /** When OK Button is clicked, dismiss the dialog */
        if (v == okButton)
            dismiss();
    }

}


Activity:
CustomDialogExample.java
package com.CustomDialog;

import android.app.Activity;
import android.os.Bundle;

public class CustomDialogExample extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        /** Display Custom Dialog */
        CustomizeDialog customizeDialog = new CustomizeDialog(this);
        customizeDialog.show();
    }
}

Wednesday, December 15, 2010

Install APK file in Android emulator using Command;

You can Install APK file With Out  Eclipse Using Command;

Run->cmd-> c:\android-sdk-windows\tools\adb install (where that APK file) .



Tuesday, December 14, 2010

AsyncTask With HttpClient in Android

Asynctask with HttpClient in android












Complete Source Code:


Activity Code:
loginPage.java


public class LoginPage extends Activity {
Button button1;
EditText txtbox1,txtbox2;
TextView tv;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.login_page);
txtbox1= (EditText) findViewById(R.id.userName);
button1 = (Button) findViewById(R.id.login);
tv = (TextView) findViewById(R.id.Validation);
txtbox2= (EditText) findViewById(R.id.Password);
button1.setOnClickListener(new clicker());
}
class clicker implements Button.OnClickListener
{
public void onClick(View v)
{
String a,b;

a = txtbox1.getText().toString();
b = txtbox2.getText().toString();

if(a.equals(b))
    reportview();

else
    tv.setText("check U'r Passwor");


}

private Object clear() {
    // TODO Auto-generated method stub
    return null;
}
}


private void reportview(){
   
   
   
    Intent reportintent = new Intent( this, httpclient.class);
       Activity parentAct = (Activity)this;
   
       parentAct.startActivity(reportintent);
}
}            




HttpClient.java



public class httpclient extends Activity { 
    private Object GetURL;

    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
   
         TextView tv = new TextView(this);
         this.GetURL=GetURL;
   
         setContentView(tv);
        getURL("http://www.google.co.in/"); 
    } 
     
    public void getURL(String url) { 
        new GetURL().execute(url); 
    } 
     
    private class GetURL extends AsyncTask<String, Void, Void> { 
        private final HttpClient Client = new DefaultHttpClient(); 
        private String Content; 
        private String Error = null; 
        private ProgressDialog Dialog = new ProgressDialog(httpclient.this); 
         
        protected void onPreExecute() { 
            Dialog.setMessage("loading source.."); 
         
            Dialog.setTitle("vijay");
            Dialog.show(); 
        } 
 
        protected Void doInBackground(String... urls) { 
            try { 
                HttpGet httpget = new HttpGet(urls[0]); 
                ResponseHandler<String> responseHandler = new BasicResponseHandler(); 
                Content = Client.execute(httpget, responseHandler); 
            } catch (ClientProtocolException e) { 
                Error = e.getMessage(); 
                cancel(true); 
            } catch (IOException e) { 
                Error = e.getMessage(); 
                cancel(true); 
            } 
             
            return null; 
        } 
         
        protected void onPostExecute(Void unused) { 
            Dialog.dismiss(); 
            if (Error != null) { 
                Toast.makeText(httpclient.this, "Wrong Url", Toast.LENGTH_LONG).show(); 
            } else { 
                Toast.makeText(httpclient.this, "Source: " + Content, Toast.LENGTH_LONG).show(); 
            } 
        } 
         
    } 

login_page.xml


 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:orientation="vertical"
    android:layout_height="fill_parent">
  
  
      
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:paddingTop="100dip"
        android:background="#000000"
        android:layout_height="fill_parent">
        <LinearLayout android:orientation="vertical"
                android:layout_width="fill_parent"
                 android:paddingTop="6dip"
                android:paddingLeft="6dip"
                android:paddingRight="6dip"
                android:background="#000000"
                android:layout_height="wrap_content">
      
      
      
            <LinearLayout android:orientation="vertical"
                android:layout_width="fill_parent"
                 android:paddingTop="6dip"
                android:paddingLeft="6dip"
                android:paddingRight="6dip"
                android:background="#000000"
                android:layout_height="wrap_content">  
      
  
                       
                <TableLayout android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:gravity="center_horizontal"
                    android:background="#000000"
                    android:layout_height="wrap_content" android:padding="5dip">
        <TableRow android:paddingTop="25dip">
      
                <TextView
            
             android:id="@+id/userNameText" 
             android:layout_height="fill_parent"
            android:textColor="#e7a71c"
            android:textSize="7pt"
            android:textStyle="bold"
            android:paddingLeft="8dip"
            android:text="User Name:"
             android:layout_span="2"
            android:layout_width="fill_parent"                                                                                                
            android:gravity="left"
            />
      
        <EditText
            android:id="@+id/userName"
          
            android:layout_width="144px"
            android:layout_height="40px"
            android:text=""
            android:singleLine="True"></EditText>
      
      
        </TableRow>
      
        <TableRow>
      
                <TextView
            
            android:id="@+id/PasswordText" 
             android:layout_height="fill_parent"
            android:textColor="#e7a71c"
            android:textSize="7pt"
            android:textStyle="bold"
            android:paddingLeft="8dip"
            android:text="Password:"
             android:layout_span="2"
            android:layout_width="fill_parent"                                                                                                
            android:gravity="left"
            />
      
        <EditText
            android:id="@+id/Password"
            android:password="true"
            android:layout_width="144px"
            android:layout_height="40px"
            android:text="Password"
            android:singleLine="True"></EditText>
      
      
        </TableRow>
      
        <TableRow android:paddingLeft="80dip"
                  android:paddingTop="10dip">
        <Button
         android:id="@+id/login"
         android:gravity="center"
       
         android:layout_width="fill_parent"
         android:layout_height="40px"
         android:text="Log In"/>
       </TableRow>
<TableRow>
<TextView
android:id="@+id/Validation"
android:layout_width="115dip"
android:layout_height="wrap_content"

android:textStyle="bold"

android:layout_x="5px"
android:layout_y="150px"
></TextView>



                            
                </TableRow>                                                                                                                                                                                                                                                                              
        </TableLayout>
      
      

</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

Saturday, December 4, 2010

Spinner with XML in Android

Spinner Using XML in Android






Complete CODE:


Activity Code:





public class ApplicationSetting<View> extends Activity {

     String[] presidents = {
                "Async Task",
                "Flipper",
              
        };
   
        Spinner s1;
        TextView tv;
        @Override   
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.application_setting);
   
            s1 = (Spinner) findViewById(R.id.spinner1);
            tv=(TextView)findViewById(R.id.userName);
            tv.setText("http://192.168.2.175:8080/ezeeMobileServer/seam/resource/rest/hotelLists/byChain?chainId=1");
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, presidents);
   
            s1.setAdapter(adapter);
            s1.setOnItemSelectedListener(new OnItemSelectedListener()
            {
                public void onItemSelected(AdapterView<?> arg0,
                View arg1, int arg2, long arg3)
                {
                    int index = s1.getSelectedItemPosition();
                    Toast.makeText(getBaseContext(),
                        "You have selected item : " + presidents[index],
                        Toast.LENGTH_SHORT).show();               
                }
   
                public void onNothingSelected(AdapterView<?> arg0) {}

                @Override
                public void onItemSelected(AdapterView<?> arg0,
                        android.view.View arg1, int arg2, long arg3) {
                    // TODO Auto-generated method stub
                   
                }
            });
        }

   

}
 







XML Code:




<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:background="@layout/summarylist_logo_titlebar_custemshape" android:orientation="vertical"
    android:layout_height="fill_parent">
   
   
    <ImageView android:layout_width="wrap_content"
        android:gravity="center"
        android:paddingTop="6dip"
        android:paddingBottom="4dip"
        android:paddingLeft="100dip"
        android:src="@drawable/lo_g_o"
        android:layout_height="wrap_content" />
       
    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:paddingTop="100dip"
        android:background="@layout/summarylist_backgroundstyle_customshape"
        android:layout_height="fill_parent">
        <LinearLayout android:orientation="vertical"
                android:layout_width="fill_parent"
                 android:paddingTop="6dip"
                android:paddingLeft="6dip"
                android:paddingRight="6dip"
                android:background="@layout/summarylist_backgroundstyle_customshape"
                android:layout_height="wrap_content">
       
       
       
            <LinearLayout android:orientation="vertical"
                android:layout_width="fill_parent"
                 android:paddingTop="6dip"
                android:paddingLeft="6dip"
                android:paddingRight="6dip"
                android:background="@layout/summarylist_backgroundstyle_customshape"
                android:layout_height="wrap_content">   
       
       
       
         <TableLayout android:layout_width="fill_parent"
                         android:orientation="vertical"
                         android:gravity="center_horizontal"
                         android:layout_height="wrap_content" 
                         android:stretchColumns="*"
                         android:background="@layout/login_tablelayout_borderline">
                        
                <TableLayout android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:gravity="center_horizontal"
                    android:background="@layout/login_table_background"
                    android:layout_height="wrap_content" android:padding="5dip">
        <TableRow android:paddingTop="25dip">
       
                <TextView
           
             android:id="@+id/userNameText"  
             android:layout_height="fill_parent"
            android:textColor="#e7a71c"
            android:textSize="7pt" 
            android:textStyle="bold"
            android:paddingLeft="8dip"
            android:text="Sync Url:"
          
          android:layout_width="100px"                                                                                              
            android:gravity="left"
            />
       
        <EditText
            android:id="@+id/userName"
           
            android:layout_width="160px"
            android:layout_height="40px"
         
            android:singleLine="True"></EditText>
       
       
        </TableRow>
       
        <TableRow>
       
                <TextView
           
            android:id="@+id/PasswordText"  
             android:layout_height="fill_parent"
            android:textColor="#e7a71c"
            android:textSize="7pt" 
            android:textStyle="bold"
            android:paddingLeft="8dip"
            android:text="Sync:"
          
          android:layout_width="100px"                                                                                            
            android:gravity="left"
            />
       
   
         <Spinner
        android:id="@+id/spinner1"
       android:layout_width="160px"
            android:layout_height="40px"
        android:drawSelectorOnTop="true" />      
       
       
        </TableRow>
       
   
    </TableLayout>
        </TableLayout>
       

</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>

Wednesday, December 1, 2010

Line charts and BAr charts


Complete Code:

U have ADD ACHARTENGINE.JAR file Also


LINE CHART:





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

import org.achartengine.ChartFactory;
import org.achartengine.chart.PointStyle;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;

/**
 * Average temperature demo chart.
 */
public class LineChartForDailyReport extends AbstractChart {

    private LinkedHashMap rptMap;
    private String name;
    public LineChartForDailyReport(LinkedHashMap rptMap)
    {
        this.rptMap = rptMap;
    }
    public void setName( String name)
      {
        this.name = name; 
      }


public String getName() {
        return this.name;
      }
 
/**
   * Returns the chart name.
   * @return the chart name
   */
  public String getName1() {
    return "Average temperature";
  }
 
  /**
   * Returns the chart description.
   * @return the chart description
   */
  public String getDesc() {
    return "The average temperature in 4 Greek islands (line chart)";
  }
 
  /**
   * Executes the chart demo.
   * @param context the context
   * @return the built intent
   */
  public Intent execute(Context context) {
    String[] titles = new String[] { this.getName() };
    List<double[]> x = new ArrayList<double[]>();
    for (int i = 0; i < titles.length; i++) {
      x.add(new double[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
    }
    List<double[]> values = new ArrayList<double[]>();
    //values.add(new double[] { 1203, 1250, 1308, 1608, 2004, 2404, 2604, 2601, 2306, 2003, 1702,
      //  1309 });
    //values.add(new double[] { 1000, 1000, 1200, 1500, 2000, 2400, 2600, 2600, 2300, 1800, 1400, 1100 });
   // values.add(new double[] { 500, 2300, 800, 1200, 1700, 2200, 2400, 2400, 1900, 1500, 900, 600 });
    values.add(new double[] { 900, 1000, 1100, 1500, 1900, 2300, 2600, 2500, 2200, 1800, 1300, 1000 });
    int[] colors = new int[] { Color.CYAN };
    PointStyle[] styles = new PointStyle[] { PointStyle.TRIANGLE };
       
    XYMultipleSeriesRenderer renderer = buildRenderer(colors, styles);
    int length = renderer.getSeriesRendererCount();
    for (int i = 0; i < length; i++) {
      ((XYSeriesRenderer) renderer.getSeriesRendererAt(i)).setFillPoints(true);
    }
    setChartSettings(renderer, this.getName(), "Day", "Revenue", 1, 13, 0, 3000,
        Color.GRAY, Color.WHITE);
    renderer.setXLabels(13);
    renderer.setYLabels(10);
    renderer.setShowGrid(true);
  
    Intent intent = ChartFactory.getLineChartIntent(context, buildDataset(titles, x, values),
        renderer, "Daily Reports");
    return intent;
  }


 

}




BAR CHARt



import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;

import org.achartengine.ChartFactory;
import org.achartengine.chart.BarChart.Type;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYMultipleSeriesRenderer.Orientation;

import android.R.color;
import android.content.Context;
import android.content.Intent;
import android.content.pm.LabeledIntent;
import android.graphics.Color;
import android.webkit.WebSettings.TextSize;

public class MonthlyBarChart extends AbstractChart {
   
    private LinkedHashMap rptMap;
    private String name;
   
    public MonthlyBarChart(LinkedHashMap rptMap)
    {
        this.rptMap = rptMap;
    }
    /**
       * Returns the chart name.
       * @return the chart name
       */
      public void setName( String name)
      {
        this.name = name; 
      }
      public String getName() {
        return this.name;
      }

     
     
      public String getDisplayName() {
            return "Woodland Chennai";
          }
     
      /**
       * Returns the chart description.
       * @return the chart description
       */
      public String getDesc() {
        return "The monthly sales for the last 2 years (horizontal bar chart)";
      }
     
     

      /**
       * Executes the chart demo.
       * @param context the context
       * @return the built intent
       */
      public Intent execute(Context context) {
        String title =  "2009";
       
        Collection colValues = rptMap.values();
        ArrayList<Float> values = new ArrayList<Float>(colValues);
      
        float maxValue  = ChartUtils.getMaxValue(this.rptMap) * ChartConstant.BAR_CHART_MAX_MULTIPLIER;
     //   values.add(new double[] { 230, 300, 240, 540/*, 900, 200, 30, 200, 500, 105,
        //   600, 500 */});
     
        int[] colors = new int[] { Color.parseColor("#ca892e")};
        XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
        renderer.setOrientation(Orientation.HORIZONTAL);
        setChartSettings(renderer, this.getName(), "Month", "Revenue", 0,
            13, 0, maxValue, Color.GRAY, Color.WHITE);
        renderer.setXLabels(1);
        renderer.setYLabels(10);
        renderer.addTextLabel(1, "Jan");
        renderer.addTextLabel(2, "Feb");
        renderer.addTextLabel(3, "Mar");
        renderer.addTextLabel(4, "Apr");
        renderer.addTextLabel(5, "May");
        renderer.addTextLabel(6, "June");
        renderer.addTextLabel(7, "Jul");
        renderer.addTextLabel(8, "Aug");
        renderer.addTextLabel(9, "Sep");
        renderer.addTextLabel(10, "Oct");
        renderer.addTextLabel(11, "Nov");
        renderer.addTextLabel(12, "Dec");
        renderer.setDisplayChartValues(true);
        renderer.setXTitle("Month");
        renderer.setYTitle("Revenue");
      

        return ChartFactory.getBarChartIntent(context, buildBarDataset(title, values), renderer, Type.DEFAULT);
      }

}

Android Apps Unstall insataling files...using Intent





private void reportUninstal(){

                   Intent reportintent = new Intent(Intent.ACTION_DELETE);
                  reportintent.setData(Uri.parse("package:com.paad.PasswordValidation"));
                  startActivity(reportintent);
}

Dial Activity Using Intent






 Button btPhone = (Button)v.findViewById(R.id.dialButton);

btPhone.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            dialPhone();
                        }
                                         });
                  



then


private void dialPhone() {
        Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri
                .parse("tel:9751076707"));
        Activity parentAct = (Activity)this.getContext();
        parentAct.startActivity(dialIntent);
    }

Thursday, November 18, 2010

Android Apps Unstall...using Intent

Android Apps Unstall Insatalling Files.

private void reportUninstal(){
   
    Intent reportintent = new Intent(Intent.ACTION_DELETE);    
    reportintent.setData(Uri.parse("package:com.paad.PasswordValidation"));
     startActivity(reportintent);   
                   
}

Check out this may be help you

Related Posts Plugin for WordPress, Blogger...