Wednesday, 2 May 2012

Show Textview, LinearLayout in Different shape


This is a generic shape defined in XML.we can use this xml to create new shape of android controls like textview and linearlayout etc...
file location:
res/drawable/filename.xml
The filename is used as the resource ID.
compiled resource datatype:
Resource pointer to a GradientDrawable.
resource reference:
In Java: R.drawable.filename
In XML: @[package:]drawable/filename
syntax:
<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape=["rectangle" | "oval" | "line" | "ring"] >
    <corners
        android:radius="integer"
        android:topLeftRadius="integer"
        android:topRightRadius="integer"
        android:bottomLeftRadius="integer"
        android:bottomRightRadius="integer" />
    <gradient
        android:angle="integer"
        android:centerX="integer"
        android:centerY="integer"
        android:centerColor="integer"
        android:endColor="color"
        android:gradientRadius="integer"
        android:startColor="color"
        android:type=["linear" | "radial" | "sweep"]
        android:useLevel=["true" | "false"] />
    <padding
        android:left="integer"
        android:top="integer"
        android:right="integer"
        android:bottom="integer" />
    <size
        android:width="integer"
        android:height="integer" />
    <solid
        android:color="color" />
    <stroke
        android:width="integer"
        android:color="color"
        android:dashWidth="integer"
        android:dashGap="integer" />
</shape>

example:
XML file saved at res/drawable/gradient_box.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:startColor="#FFFF0000"
        android:endColor="#80FF00FF"
        android:angle="45"/>
    <padding android:left="7dp"
        android:top="7dp"
        android:right="7dp"
        android:bottom="7dp" />
    <corners android:radius="8dp" />
</shape>
This layout XML applies the shape drawable to a View:
<TextView
    android:background="@drawable/gradient_box"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content" />
This application code gets the shape drawable and applies it to a View:
Resources res = getResources();
Drawable shape = res. getDrawable(R.drawable.gradient_box);
TextView tv = (TextView)findViewByID(R.id.textview);
tv.setBackground(shape);

Friday, 20 April 2012

Create DataBase In Android (Part 2)

Step 1:- Now create Insert Method in database class for inserting data in database table

public long insert(String title,String type) {


this.insertStmt.bindString(1,title);
this.insertStmt.bindString(2,type);
return this.insertStmt.executeInsert();
}

Step 2:- Now Create Select Method


     public void selectAll() {
Cursor cursor = null;
    cursor = this.db.query(TABLE_NAME, new String[] { "title","type"},
"", null, null, null, "id desc");
 
if (cursor.moveToFirst()) {

do {
System.out.println(cursor.getString(0));
       System.out.println(cursor.getString(1));

} while (cursor.moveToNext());
}
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}


Setp 3: - Method for delete and Update Table Data


public void deleteAll() {
this.db.delete(TABLE_NAME, null, null);
}

public void deleteRow(long rowId) {
db.delete(TABLE_NAME, "id=" + rowId, null);
}

public void updateRow(long rowId, String text, String title, String date) {
ContentValues args = new ContentValues();
args.put("memodata", text);
args.put("title", title);
db.update(TABLE_NAME, args, "id=" + rowId, null);
}



Create DataBase In Android (Part 1)

Setp by Step Procedure for Create Database in android :-

Setp 1:- Create a new Class Database first

public class Database{
          public Database(Context context)
          {
           }
}

Setp 2:- Create  static class in Database class which extend SQLiteOpenHelper same as below


private static class OpenHelper extends SQLiteOpenHelper {
OpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + TABLE_NAME
+ "          (id INTEGER PRIMARY KEY,title TEXT, type TEXT)");
}


@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w("Example",
"Upgrading database, this will drop tables and recreate.");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);


onCreate(db);
}
}


Step 3:- Now create below object in Database Class



        private static final String DATABASE_NAME = "DBName.db";
private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME="DBNAME" ;
private Context context;
private SQLiteDatabase db;
private SQLiteStatement insertStmt;
private String INSERT="insert into " + TABLE_NAME + " (title,type) values (?,?)";


Step 4:- Initialize object in Database class constructor 


      public Database(Context context) {
this.context = context;
OpenHelper openHelper = new OpenHelper(this.context);
this.db = openHelper.getWritableDatabase();
this.insertStmt = this.db.compileStatement(INSERT);
}



Bitmap Object for Resource Image in android

Bitmap bitmap;
bitmap=BitmapFactory.decodeResource( context.getResources(), R.drawable.MyImage);


Thursday, 19 April 2012

Email, SMS and Facebook Integration in Android App

* If you want to send email, sms or post any comments on Facebook then below i show code which we can use for send email, sms and post any comments on facebook with image and text *

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("android.resource://com.hanuma/" + R.drawable.front);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
sharingIntent.putExtra(Intent.EXTRA_TITLE, "Your Title Text");
sharingIntent.putExtra(Intent.EXTRA_TEXT,"Other Text");
context.startActivity(Intent.createChooser(sharingIntent, "Send"));

Read Resource Contain using URI

Uri of Resource Contain:-
Uri uri=Uri.parse("android.resource://com.androidbook.samplevideo/" + R.raw.myvideo);

Tuesday, 17 April 2012

Alert Message Box in Android

*Show Alart Message Box in Android *

AlertDialog.Builder adb=new AlertDialog.Builder(activity);

    adb.setTitle("Alert?");
    adb.setMessage("Do you want to delete Note.");
    adb.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int id) {
                
            System.out.println("zdfsdfksjDfjkds:hi me hi me  "+holder.id.getText());
          }
    }
      );
    adb.setNegativeButton("No", null);
    adb.show();