Sunday, July 22, 2012

Sliding Panel from right to left



click here to download source code


package Name  :  selva.sliding

project Name    :  Sliding3

Version             :  1.5 ( Supports 1.5 and above versions)


main.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:gravity="right"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
    <Button
        android:id="@+id/show1"
        android:layout_width="wrap_content"
        android:layout_marginTop="250dp"
        android:layout_height="wrap_content"
        android:background="@drawable/prev_item" />
 

        <selva.sliding.Sliding
            android:id="@+id/sliding1"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="200dp"
            android:gravity="left"
            android:padding="1px"
            android:background="#ffffff">
                <CheckBox android:id="@+id/check1"
                        android:layout_width="wrap_content"
                        android:textColor="#FFFFFF"
                        android:layout_height="wrap_content"
                        android:text="Option1" />
                <CheckBox android:id="@+id/check2"
                        android:layout_width="wrap_content"
                        android:textColor="#FFFFFF"
                        android:layout_height="wrap_content"
                         android:text="Option2" />
                <CheckBox android:id="@+id/check3"
                        android:textColor="#FFFFFF"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                         android:text="Option3" />
        </selva.sliding.Sliding>
   
</LinearLayout>
 


 Sliding2Activity.java


package selva.sliding;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

public class Sliding2Activity extends Activity
{
      CheckBox c1,c2,c3;
        int key=0;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final Sliding popup = (Sliding) findViewById(R.id.sliding1);
        popup.setVisibility(View.GONE);

                final Button btn=(Button)findViewById(R.id.show1);
                btn.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                                if(key==0){
                                        key=1;
                                        popup.setVisibility(View.VISIBLE);
                                        btn.setBackgroundResource(R.drawable.prev_item);
                                }
                                else if(key==1){
                                        key=0;
                                        popup.setVisibility(View.GONE);
                                        btn.setBackgroundResource(R.drawable.prev_item);
                                }
                        }
                });

        }
    }

 

 Sliding.java



package selva.sliding;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class Sliding extends LinearLayout
{
private Paint innerPaint, borderPaint ;
public Sliding(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public Sliding(Context context) {
super(context);
init();
}
private void init() {
innerPaint = new Paint();
innerPaint.setARGB(225, 75, 75, 75); //gray
innerPaint.setAntiAlias(true);
borderPaint = new Paint();
borderPaint.setARGB(255, 255, 255, 255);
borderPaint.setAntiAlias(true);
borderPaint.setStyle(Style.STROKE);
borderPaint.setStrokeWidth(2);
}
public void setInnerPaint(Paint innerPaint) {
this.innerPaint = innerPaint;
}
public void setBorderPaint(Paint borderPaint) {
this.borderPaint = borderPaint;
}
@Override
protected void dispatchDraw(Canvas canvas) {
RectF drawRect = new RectF();
drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
canvas.drawRoundRect(drawRect, 5, 5, borderPaint);
super.dispatchDraw(canvas);
}
}



Output:














































click icon
















































click here to download source code


Sliding Panel From Top to Bottom



Click Here To Download Source Code

Package Name   :    selva.sliding

Project Name     :    Sliding2

Version              :    1.5 ( Supports 1.5 and above versions)


main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
        <selva.sliding.Sliding
            android:id="@+id/sliding1"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:padding="1px"
            android:background="#ffffff">
                <CheckBox android:id="@+id/check1"
                        android:layout_width="wrap_content"
                        android:textColor="#FFFFFF"
                        android:layout_height="wrap_content"
                        android:text="Option1" />
                <CheckBox android:id="@+id/check2"
                        android:layout_width="wrap_content"
                        android:textColor="#FFFFFF"
                        android:layout_height="wrap_content"
                         android:text="Option2" />
                <CheckBox android:id="@+id/check3"
                        android:textColor="#FFFFFF"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                         android:text="Option3" />
        </selva.sliding.Sliding>

    <Button android:id="@+id/show1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/expand"/>
</LinearLayout>
 

 Sliding2Activity.java

package selva.sliding;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

public class Sliding2Activity extends Activity
{
      CheckBox c1,c2,c3;
        int key=0;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final Sliding popup = (Sliding) findViewById(R.id.sliding1);
        popup.setVisibility(View.GONE);

                final Button btn=(Button)findViewById(R.id.show1);
                btn.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                                if(key==0){
                                        key=1;
                                        popup.setVisibility(View.VISIBLE);
                                        btn.setBackgroundResource(R.drawable.expand);
                                }
                                else if(key==1){
                                        key=0;
                                        popup.setVisibility(View.GONE);
                                        btn.setBackgroundResource(R.drawable.expand);
                                }
                        }
                });

        }
    }
 



 Sliding.java

package selva.sliding;


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class Sliding extends LinearLayout
{
private Paint innerPaint, borderPaint ;
public Sliding(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public Sliding(Context context) {
super(context);
init();
}
private void init() {
innerPaint = new Paint();
innerPaint.setARGB(225, 75, 75, 75); //gray
innerPaint.setAntiAlias(true);
borderPaint = new Paint();
borderPaint.setARGB(255, 255, 255, 255);
borderPaint.setAntiAlias(true);
borderPaint.setStyle(Style.STROKE);
borderPaint.setStrokeWidth(2);
}
public void setInnerPaint(Paint innerPaint) {
this.innerPaint = innerPaint;
}
public void setBorderPaint(Paint borderPaint) {
this.borderPaint = borderPaint;
}
@Override
protected void dispatchDraw(Canvas canvas) {
RectF drawRect = new RectF();
drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
canvas.drawRoundRect(drawRect, 5, 5, borderPaint);
super.dispatchDraw(canvas);
}
}


Output : 














































click expand icon

 








Click Here To Download Source Code





Sliding Panel from Left To Right



Click Here to download Source Code

Package Name   :  selva.sliding

Project Name     :  Sliding1

Version              :  1.5  ( Supports 1.5 and above versions)

main.xml

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

        <selva.sliding.Sliding
            android:id="@+id/sliding1"
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="left"
            android:padding="1px"
            android:background="#ffffff">
                <CheckBox android:id="@+id/check1"
                        android:layout_width="wrap_content"
                        android:textColor="#FFFFFF"
                        android:layout_height="wrap_content"
                        android:text="Option1" />
                <CheckBox android:id="@+id/check2"
                        android:layout_width="wrap_content"
                        android:textColor="#FFFFFF"
                        android:layout_height="wrap_content"
                         android:text="Option2" />
                <CheckBox android:id="@+id/check3"
                        android:textColor="#FFFFFF"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                         android:text="Option3" />
        </selva.sliding.Sliding>

    <Button android:id="@+id/show1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/next_item"/>
</LinearLayout>


 Sliding1Activity.java


package selva.sliding;


import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;

public class Sliding1Activity extends Activity
{
      CheckBox c1,c2,c3;
        int key=0;
   
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final Sliding popup = (Sliding) findViewById(R.id.sliding1);
        popup.setVisibility(View.GONE);

                final Button btn=(Button)findViewById(R.id.show1);
                btn.setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View arg0) {
                                if(key==0){
                                        key=1;
                                        popup.setVisibility(View.VISIBLE);
                                        btn.setBackgroundResource(R.drawable.next_item);
                                }
                                else if(key==1){
                                        key=0;
                                        popup.setVisibility(View.GONE);
                                        btn.setBackgroundResource(R.drawable.next_item);
                                }
                        }
                });

        }
    }
 


 Sliding.java



package selva.sliding;



import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.LinearLayout;
public class Sliding extends LinearLayout
{
private Paint innerPaint, borderPaint ;
public Sliding(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public Sliding(Context context) {
super(context);
init();
}
private void init() {
innerPaint = new Paint();
innerPaint.setARGB(225, 75, 75, 75); //gray
innerPaint.setAntiAlias(true);
borderPaint = new Paint();
borderPaint.setARGB(255, 255, 255, 255);
borderPaint.setAntiAlias(true);
borderPaint.setStyle(Style.STROKE);
borderPaint.setStrokeWidth(2);
}
public void setInnerPaint(Paint innerPaint) {
this.innerPaint = innerPaint;
}
public void setBorderPaint(Paint borderPaint) {
this.borderPaint = borderPaint;
}
@Override
protected void dispatchDraw(Canvas canvas) {
RectF drawRect = new RectF();
drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight());
canvas.drawRoundRect(drawRect, 5, 5, innerPaint);
canvas.drawRoundRect(drawRect, 5, 5, borderPaint);
super.dispatchDraw(canvas);
}
}


Output :






click next icon











































Click Here to download Source Code




Make a New Line , Space and Displaying text with different color



Click Here to download source code

Package Name     :    selva.textbox

Project Name       :    TextBox

Version                :     1.5 ( Supports 1.5 and above versions)



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="fill_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Me" />
  
     <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Click Me" />
  

</LinearLayout>



 
TextBoxActivity.java


package selva.textbox;

import android.app.Activity;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class TextBoxActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        Button ok=(Button) findViewById(R.id.button1);
        final TextView tv=(TextView) findViewById(R.id.textView1);
       
        Button ok1=(Button) findViewById(R.id.button2);
        final TextView tv1=(TextView) findViewById(R.id.textView2);
       
        ok.setOnClickListener(new View.OnClickListener() {
           
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                String str="This is first line in textview1\nThis is\tsecond line in textview1";
                tv.setText(str);
               
            }
        });
       
       
ok1.setOnClickListener(new View.OnClickListener() {
           
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                String str1 = "<font color=#00cc00>First line is green color in textview2</font> <br />" +
                        " <font color=#ff0000>Second line is red color in textview2</font>";

                tv1.setText(Html.fromHtml(str1));
               
            }
        });
       
    }
}


OUTPUT :










  click "click Me" buttons











Click Here to download source code



Tuesday, July 17, 2012

Send SMS to more than one device



 Click Here to Download source code

Package Name   :  selva.sms

Project Name     :   SMS2

Version              :    1.5 ( Supports 1.5 and above versions)

  
main.xml


<?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">
    <Button
        android:id="@+id/btnSendSMS"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Send SMS" />
</LinearLayout>




 SMS2Activity.java



package selva.sms;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class SMS2Activity extends Activity {
Button btnSendSMS;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);
btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
btnSendSMS.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
    Intent i = new
            Intent(android.content.Intent.ACTION_VIEW);
            i.putExtra("address", "5556; 5558; 5560");
            i.putExtra("sms_body", "Hello my friends!");
            i.setType("vnd.android-dir/mms-sms");
            startActivity(i);
}
});
}


}




 AndroidManifest.xml


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

    <uses-sdk android:minSdkVersion="3" />
    <uses-permission android:name="android.permission.SEND_SMS"/>

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

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

</manifest>



OUTPUT:





 Click Here to Download source code


Monday, July 16, 2012

Send SMS and Receive Delivery Report in Android



Click Here To Download Source Code

Package Name   :  selva.sms

Project Name     :  SMS1

Version              :  1.5 ( Supports 1.5 and above versions)

main.xml


<?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">
    <Button
        android:id="@+id/btnSendSMS"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Send SMS" />
</LinearLayout>




SMS1Activity.java


package selva.sms;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class SMS1Activity extends Activity
{
Button btnSendSMS;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(R.layout.main);
btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
btnSendSMS.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
sendSMS("5556", "Hi You got a message!");
}
});
}
//---sends an SMS message to another device---

private void sendSMS(String phoneNumber, String message)
{
String SENT = "SMS_SENT";
String DELIVERED = "SMS_DELIVERED";
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,new Intent(DELIVERED), 0);
//---when the SMS has been sent---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS sent",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
Toast.makeText(getBaseContext(), "Generic failure",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NO_SERVICE:
Toast.makeText(getBaseContext(), "No service",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_NULL_PDU:
Toast.makeText(getBaseContext(), "Null PDU",
Toast.LENGTH_SHORT).show();
break;
case SmsManager.RESULT_ERROR_RADIO_OFF:
Toast.makeText(getBaseContext(), "Radio off",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(SENT));
//---when the SMS has been delivered---
registerReceiver(new BroadcastReceiver(){
@Override
public void onReceive(Context arg0, Intent arg1) {
switch (getResultCode())
{
case Activity.RESULT_OK:
Toast.makeText(getBaseContext(), "SMS delivered",
Toast.LENGTH_SHORT).show();
break;
case Activity.RESULT_CANCELED:
Toast.makeText(getBaseContext(), "SMS not delivered",
Toast.LENGTH_SHORT).show();
break;
}
}
}, new IntentFilter(DELIVERED));
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
}



 AndroidManifest.xml


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

    <uses-sdk android:minSdkVersion="3" />
    <uses-permission android:name="android.permission.SEND_SMS"/>

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

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

</manifest>



OUTPUT: 






Click Here To Download Source Code


How To Send SMS in Android



Click Here to download Source Code

Package Name   :  selva.sms

Project Name     :  SMS

Version              :  1.5 ( Supports 1.5 and above versions)



main.xml

<?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">
    <Button
        android:id="@+id/btnSendSMS"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Send SMS" />
</LinearLayout>



 SMSActivity.java



package selva.sms;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.gsm.SmsManager;
import android.view.View;
import android.widget.Button;
public class SMSActivity extends Activity {
Button btnSendSMS;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.main);
btnSendSMS = (Button) findViewById(R.id.btnSendSMS);
btnSendSMS.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
sendSMS("5556", "Hi You got a message!");
}
});
}
//---sends an SMS message to another device---

private void sendSMS(String phoneNumber, String message)
{
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, null, null);
}

}


AndroidManifest.xml

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

    <uses-sdk android:minSdkVersion="3" />
    <uses-permission android:name="android.permission.SEND_SMS"/>

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

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

</manifest>


 OUTPUT:








click Send SMS button in 5554 emulator




 




















You Will get message on top of the emulator 5556













Click Here to download Source Code