Thursday 27 March 2014


Lets Look at Servlets...

In this post you are going to learn how to create a simple Dynamic Web Project

Download the eclipse from
https://www.eclipse.org/downloads/packages/eclipse-ide-java-and-report-developers/keplersr2

and go through the following steps


  •   Create a Dynamic Web Project 





  • and here is the hierarchy looks like 



  • Right click on the app and create a new Servlet
  • Note : Dont select the Class because in order to run this app u need to create URL pattern in web.xml , and if u select servlet from the list eclipse will do it for u 


Monday 10 December 2012

Lets Look At VXML

Voice Xml Application development

Getting start with Voice XML(vxml) application

How to start the eclipse and configuration details you can probably get it in previous section

today lets start the application with voice XML which deals with JSP


Go to Eclipse 

Select New

Select Dynamic Web Project

Simply Right click on the project and select JSP and name it as sample.jsp

which looks like as follows




In this example vxml is the root tag for all the tags and form is the sub tag vxml tag as well you can also use menu tag but the sub tags will get change we will discuss in the later sessions

so deploy the application in the prophecy and run it


Friday 28 September 2012

ExapndableListView With Checkbox Sample

ExpandableListView

A view that shows items in a vertically scrolling two-level list. This differs from the ListView by allowing two levels: groups which can individually be expanded to show its children. The items come from the ExpandableListAdapter associated with this view. 

 Source Code 

main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ExpandableListView
        android:id="@+id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ExpandableListView>

</LinearLayout>


group.xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="40dip"
        android:text="Items"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>


child.xml 

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/textViewchild"
        android:layout_width="220dp"
        android:layout_height="40dip"
        android:text="child values "
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <CheckBox
        android:id="@+id/checkBoxchild"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="" />

</LinearLayout>

above xml files are declared for Main page where you can get the component Representation 

and the other two are used to get the parent and child values 

Activities of which uses the above xml files are shown below 

package com.pack.android;

import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnGroupExpandListener;

public class CoutmLIstActivity extends ExpandableListActivity {

    DisplayMetrics dismat;
    ExpandableListView matrix;
    int width;
    static final String Groupvalues[] = { "Android", "Flex", "Voice Xml",
            };
    static final String childvalues[][] = {
            { "SaiNath", "Anudeep", "Deppeak"},
            { "Kranthi", "Ramakrishna", "Nagarjuna" }, { "Sushma", "Meghana", "Sathya" } };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ExpandableListView ep = getExpandableListView();
        dismat = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dismat);
        width = dismat.widthPixels;
            ep.setIndicatorBounds(width - GetDipsFromPixel(50), width
                - GetDipsFromPixel(10));
        ep.setAdapter(new ExpandbleAdpter(CoutmLIstActivity.this));

        ep.setOnGroupExpandListener(new OnGroupExpandListener() {

            @Override
            public void onGroupExpand(int groupPosition) {
               
            }
        });
    }

    public int GetDipsFromPixel(float pixels) {
        final float scale = getResources().getDisplayMetrics().density;
                return (int) (pixels * scale + 0.5f);
    }

}

Adapter class for List Component 

package com.pack.android;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class ExpandbleAdpter extends BaseExpandableListAdapter {

    Context myconContext;

    public ExpandbleAdpter(Context context) {
        myconContext = context;
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return 0;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater lay = (LayoutInflater) myconContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = lay.inflate(R.layout.child, null);
        }
        final TextView name = (TextView) convertView
                .findViewById(R.id.textViewchild);
        name
                .setText(CoutmLIstActivity.childvalues[groupPosition][childPosition]);

        CheckBox child = (CheckBox) convertView
                .findViewById(R.id.checkBoxchild);
        child.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                Toast.makeText(myconContext,
                        "Name" + name.getText().toString(), Toast.LENGTH_LONG)
                        .show();
            }
        });

        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return CoutmLIstActivity.childvalues.length;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return null;
    }

    @Override
    public int getGroupCount() {
        return CoutmLIstActivity.Groupvalues.length;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return 0;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {

        if (convertView == null) {
            LayoutInflater lay2 = (LayoutInflater) myconContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = lay2.inflate(R.layout.group, null);

        }
        TextView cidlvalue = (TextView) convertView
                .findViewById(R.id.textView1);
        cidlvalue.setText(CoutmLIstActivity.Groupvalues[groupPosition]);

        return convertView;

    }

    @Override
    public boolean hasStableIds() {
        return false;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return false;
    }

}

Finally the tree view looks like as fallows 




Tuesday 17 July 2012

Sample Remainder Using Service and Sqlite

Create an application which remands you some thing on selected  date and time which

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:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Time"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/editTexttime"
            android:layout_width="300px"
            android:layout_height="wrap_content"
            android:editable="false" >

            <requestFocus />
        </EditText>

        <Button
            android:id="@+id/buttontime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="Time" />
    </LinearLayout>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Date"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <EditText
            android:id="@+id/editTextdate"
            android:layout_width="300px"
            android:layout_height="wrap_content"
            android:editable="false" />

        <Button
            android:id="@+id/buttondate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="Date" />
    </LinearLayout>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Remainder Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <EditText
        android:id="@+id/editTextremaindtext"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <RadioButton
            android:id="@+id/radiovibrate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Vibrate" />

        <RadioButton
            android:id="@+id/radioring"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Ring" />
    </RadioGroup>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/buttonsave"
            android:layout_width="200px"
            android:layout_height="wrap_content"
            android:text="Save" />
    </LinearLayout>

</LinearLayout>

 
Graphical layout 


Sqlite Helper class looks as fallows 

public class SqliteHelper extends SQLiteOpenHelper {

    static final String DBNAME = "DBNAME";
    static final String REMAINDER_TABLE = "REMAINDER_TABLE";
    static final String ID = "ID";
    static final String TIME = "TIME";
    static final String Date = "DATE";
    static final String REMAIND_TEXT = "REMAIND";
    static final String ALERT_FLAG = "ALERT_FLAG";
    static final String ALERT_TYPE = "ALERT_TYPE";

    public SqliteHelper(Context context) {
        super(context, DBNAME, null, 1);

    }

    @Override
    public void onCreate(SQLiteDatabase db) {

        db.execSQL("CREATE TABLE " + REMAINDER_TABLE + " (" + TIME + " TEXT, "
                + Date + " TEXT, " + REMAIND_TEXT + " TEXT, " + ALERT_FLAG
                + " TEXT, " + ALERT_TYPE + " TEXT," + ID + " TEXT)");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        db.execSQL("DROP TABLE IF EXISTS " + REMAINDER_TABLE);
        onCreate(db);

    }

    public int remaindMySchedule(String time, String date, String desc,
            String flag, String type) {
        SQLiteDatabase db = null;
        int a = 0;
        try {
            db = this.getWritableDatabase();
            ContentValues cv = new ContentValues();
            cv.put(TIME, time);
            cv.put(Date, date);
            cv.put(REMAIND_TEXT, desc);
            cv.put(ALERT_FLAG, flag);
            cv.put(ALERT_TYPE, type);
            cv.put(ID, "" + Sequncer() + 1);

            a = (int) db.insert(REMAINDER_TABLE, null, cv);

        } catch (Exception e) {
            Log.d("Exception", "Sorry" + e);

        } finally {
            db.close();
        }
        return a;

    }

    public ArrayList<HashMap<String, String>> CheckMyschedule(String time,
            String date) {
        SQLiteDatabase db = null;
        Cursor cur = null;
        ArrayList<HashMap<String, String>> DATA = new ArrayList<HashMap<String, String>>();
        try {
            db = this.getReadableDatabase();
            String query = "SELECT " + REMAIND_TEXT + ", " + ALERT_FLAG + ","
                    + ALERT_TYPE + "," + ID + " FROM " + REMAINDER_TABLE
                    + " WHERE " + TIME + "='" + time + "' AND " + Date + "='"
                    + date + "' AND " + ALERT_FLAG + "='true'";
            Log.d("Message", "query" + query);
            cur = db.rawQuery(query, null);
            Log.d("Message", "count" + cur.getCount());

            while (cur.moveToNext()) {
                HashMap<String, String> values = new HashMap<String, String>();
                values.put(REMAIND_TEXT, cur.getString(0));
                values.put(ALERT_FLAG, cur.getString(1));
                values.put(ALERT_TYPE, cur.getString(2));
                values.put(ID, cur.getString(3));

                DATA.add(values);
                Log.d("Message", "values" + DATA.toString());

            }

        } catch (Exception e) {
            e.printStackTrace();
            // Log.d("Message", "Failed" + e);
        } finally {
            cur.close();
            db.close();
        }
        return DATA;

    }

    private int Sequncer() {
        // TODO Auto-generated method stub
        SQLiteDatabase db = null;
        Cursor cur = null;
        int PK = 0;
        try {
            db = this.getReadableDatabase();
            String query = "SELECT * FROM " + REMAINDER_TABLE;
            cur = db.rawQuery(query, null);
            if (cur.moveToNext()) {
                PK = cur.getCount();
            }

        } catch (Exception e) {
            Log.d("Message", "Failed" + e);

        }
        return PK;

    }

    public void FlagUpdate(String id) {
        SQLiteDatabase db = null;

        try {
            db = this.getWritableDatabase();
            ContentValues cv = new ContentValues();
            cv.put(ALERT_FLAG, "false");
            cv.put(ID, id);

            int a = db.update(REMAINDER_TABLE, cv, ID + "=?",
                    new String[] { id });
            Log.d("Message", "update-->" + a);

        } catch (Exception e) {

            e.printStackTrace();
        }

    }
}


Activity Class 


public class Schedule extends Activity {
    EditText time;
    EditText date;
    Button TimeBut;
    Button DateBut;
    EditText Remainder;
    Button Save;
    int hours, min, sec;
    RadioButton vibrate;
    RadioButton ring;
    static final int ID = 3;
    static String alert = "";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        time = (EditText) findViewById(R.id.editTexttime);
        date = (EditText) findViewById(R.id.editTextdate);
        TimeBut = (Button) findViewById(R.id.buttontime);
        DateBut = (Button) findViewById(R.id.buttondate);
        Save = (Button) findViewById(R.id.buttonsave);
        Save.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                startService(new Intent(Schedule.this, ServiceExample.class));
                SaveRemainder();

            }
        });
        vibrate = (RadioButton) findViewById(R.id.radiovibrate);
        vibrate.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                // TODO Auto-generated method stub
                alert = "VIBRATE";
            }
        });
        ring = (RadioButton) findViewById(R.id.radioring);
        ring.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                // TODO Auto-generated method stub
                alert = "RING";
            }
        });
        Remainder = (EditText) findViewById(R.id.editTextremaindtext);
        TimeBut.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onCreateDialog(ID).show();
            }
        });
        Calendar cad = Calendar.getInstance();
        hours = cad.get(Calendar.HOUR_OF_DAY);
        min = cad.get(Calendar.MINUTE);
        sec = cad.get(Calendar.SECOND);
        UpdateTime();
    }

    TimePickerDialog.OnTimeSetListener datedata = new TimePickerDialog.OnTimeSetListener() {

        @Override
        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
            // TODO Auto-generated method stub
            hours = hourOfDay;
            min = minute;
            UpdateTime();
        }
    };

    @Override
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case ID:
            return new TimePickerDialog(this, datedata, hours, min, true);

        }
        return null;
    }

    private void UpdateTime() {

        this.time.setText(new StringBuilder().append(hours).append("-")
                .append(min));

    }

    private void SaveRemainder() {

        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        String date = sdf.format(new Date());
        Log.d("Time----->", time.getText().toString());
        SqliteHelper sqliteHelper = new SqliteHelper(this);
        int a = sqliteHelper.remaindMySchedule(time.getText().toString(), date,
                Remainder.getText().toString(), "true", alert);
        if (a > 0) {
            Toast.makeText(this, "Done", Toast.LENGTH_LONG).show();
        }

    }
}


Service Class 
This class used to check the time and date which is selected by user for every 3000 mill seconds  

 public class ServiceExample extends Service {

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        return START_STICKY;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        looper();
    }

    private void looper() {
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                Method();
            }
        }, 10, 30 * 1000);
    }

    void Method() {

        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        String date = sdf.format(new Date());
        Log.d("Date", date);

        SimpleDateFormat sdf2 = new SimpleDateFormat("HH-mm");
        String time = sdf2.format(new Date());
        Log.d("Message", time);

        SqliteHelper helper = new SqliteHelper(this);

        ArrayList<HashMap<String, String>> names = new ArrayList<HashMap<String, String>>();
        names = helper.CheckMyschedule(time, date);

        if (names.isEmpty()) {
            Log.d("Message", "No data Found");
        } else {
            HashMap<String, String> values = names.get(0);
            if (values.isEmpty()) {
                Log.d("Message", "No data Found");

            } else {
                String text = values.get(SqliteHelper.REMAIND_TEXT);
                Message message = new Message();
                Bundle bundel = new Bundle();
                bundel.putString("Name", text);
                message.obj = bundel;
                handler.sendMessage(message);
                String id = values.get(SqliteHelper.ID);
                helper.FlagUpdate(id);
            }
        }
    }

    private Handler handler = new Handler() {
        public void handleMessage(android.os.Message msg) {
            Toast.makeText(getApplicationContext(),    "Hi Sai to day you have a meeting please check the details",Toast.LENGTH_LONG).show();

        };
    };
}


This is the screen when condition get satisfied throws a toast on the screen







get more about vibrate and ring options of the application