Monday, 27 April 2015

Add ksoap2 to android studio

apply plugin: 'com.android.application'

android 
{
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.as0060.mylifeinbytes"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes
      {
        release
             
       {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        repositories {
            maven { url 'http://ksoap2-android.googleco/svde.cmomn/2-repo' }
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
   
    compile 'com.google.code.ksoap2-android:ksoap2-android:3.1.1'

}

Sunday, 26 April 2015

Android Ripple Touch Effect Example


Step 1):main_activity.xml

<RelativeLayout     xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
         <com.xgc1986.ripplebutton.widget.RippleButton
            android:id="@+id/Summit"
            android:layout_width="260dp"
            android:layout_height="50dp"
            android:text="Login"
            android:textColor="@color/white"
            android:textStyle="bold"
            app:buttonColor="@color/Button"
            app:rippleColor="@color/white" />
  </RelativeLayout>


Step 2):build.gradle file



android 
 {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.as0060.mylifeinbytes"
        minSdkVersion 16
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release
                {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),                'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.0'
    compile 'com.xgc1986.android:ripplebutton:0.4.0'
}


  compile 'com.xgc1986.android:ripplebutton:0.4.0' ...we have to include this Library in our gradle file to use android ripple effect


Happy Coding:)

Tuesday, 14 April 2015

Android Calendar View


Calendar View 

Calendar View class is a calendar widget for displaying and selecting dates. The range of dates supported by this calendar is configurable. A user can select a date by taping on it and can scroll and fling the calendar to a desired date.
                                       

Step 1):calendar_main.xml
   
       Create a XML file for CalendarActivity


  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relative"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="30dp"
        android:text="AndroidDhinaBlog"
        android:textColor="#000000"
        android:textSize="20dp" />

 </RelativeLayout>



Step 2):list_layout.xml

   Create a layout for Listview.

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

         <ListView
             android:background="#99CCFF"
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="#b5b5b5"
            android:dividerHeight="1dp" />
     </LinearLayout>

  



Step 3):CalendarActivity



          Create a class CalendarActivity.
          

          package com.calenderview;

          import android.app.Activity;
          import android.annotation.SuppressLint;
         
          import android.os.Bundle;
          import android.widget.CalendarView;
          import android.widget.CalendarView.OnDateChangeListener;
          import android.widget.RelativeLayout;
          import android.widget.RelativeLayout.LayoutParams;
          import android.widget.Toast;

          public class CalendarActivity extends Activity 
            {

          RelativeLayout relative;
          CalendarView calendar;

              @SuppressLint({ "NewApi", "NewApi" })
             @Override
              public void onCreate(Bundle savedInstanceState) 
              {
               super.onCreate(savedInstanceState);
               setContentView(R.layout.
calendar_main);
        
               relative= (RelativeLayout ) findViewById(R.id.relative);
        
               
calendar= new CalendarView (CalendarActivity .this);
        
               RelativeLayout .LayoutParams params
                    new RelativeLayout .LayoutParams((int)
               LayoutParams.MATCH_PARENT,(int)LayoutParams.MATCH_PARENT);                 
        
               params .topMargin = 100;
               calendar.setLayoutParams(
calendar);
        
               relative.addView(
calendar);
        
             
calendar.setOnDateChangeListener(new OnDateChangeListener() 
              {
@Override
              public void onSelectedDayChange
(CalendarView view,
                                                                 int year,int month,int day)
                {
             Toast.makeText(getBaseContext(),"Selected Date is\n\n"+
                         dayOfMonth+":"+month+":"+year,                           
Toast.LENGTH_LONG).show();
}  
});
            }
}









                        








Wednesday, 8 April 2015

Delete column and row in the sqlite database using android


   In my previous post I have explained how to insert values in database using SQLite.Now I am going to explain about deleting the values in database using SQLite.



      public void deleteChat(String GroupId
                {
String deleteQuery =  
                                "Delete   FROM " + "TableName"+ "  Where  "
+ "" + "Group"+ " in " + "(" + GroupId + ")";
SQLiteDatabase db = getWritableDatabase();
db.execSQL(deleteQuery);

              }

            "TableName"=Name of the Table
            "Group"=Column Name

Syntax:
          
            Delete from TableName where columnName in(id);


Happy Coding:)

Insert data into a table in android using sqlite



Here i am going to explain how to insert value in database using SQLite  in android.Before that, you must Know about SQLite 



SQLite 
   
            SQLite is an in-process library that implements a self-contained, serverless, zero- configuration, transactional SQL database engine. The code for SQLite is in the public domain and is thus free for use for any purpose, commercial or private

public void insertEntry() 

{
 
    try 
        {
SQLiteDatabase db = this.getWritableDatabase();

              ContentValues values = new ContentValues();

values.put("Messsage", msg);
                     values.put("Name", SenderName);
                     values.put("GroupName", Groupname);

db.insert("TableName", null, Values);


        catch (Exception e) 
{

}

}

Tuesday, 7 April 2015

Android Pinch Zoom


In previous article I  explained how to implement share via option.Now I am going to explain android pinch zoom


Step 1).imageView.java


package com.groupchat;
import java.io.File;
import com.docx.R;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.net.Uri;
import android.os.Bundle;
import android.util.FloatMath;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.widget.ImageView;
import android.widget.Toast


public class ImageView extends Activity 
{
String path;
ImageView i;
private ScaleGestureDetector scaleGestureDetector;
private Matrix matrix = new Matrix();

Matrix savedMatrix = new Matrix();


static final int NONE = 0;
static final int DRAG = 1;
static final int ZOOM = 2;
int mode = NONE;

// Remember for zooming
PointF start = new PointF();
PointF mid = new PointF();
float oldDist = 1f;
String savedItemClicked;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.imageview);


i = (ImageView) findViewById(R.id.ChatImage);
i.setImageURI("");//Insert your image uri

scaleGestureDetector = new ScaleGestureDetector(this,
new ScaleListener());

}



        @Override
public boolean onTouchEvent(MotionEvent event)
{
   ImageView view = (ImageView)findViewById(R.id.ChatImage);
   dumpEvent(event);

   // Handle touch events here...
   switch (event.getAction() & MotionEvent.ACTION_MASK)
   {
    case  MotionEvent.ACTION_DOWN:
       savedMatrix.set(matrix);
        start .set(event.getX(), event.getY());
     
       mode = DRAG;
       break;
   case MotionEvent.ACTION_POINTER_DOWN:
           oldDist = spacing(event);
 
       if (oldDist > 10f)
       {
            savedMatrix.set(matrix);
           midPoint(mid event);
            mode = ZOOM;
       
       }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
     
        break;
    case  MotionEvent.ACTION_MOVE:
       if (mode == DRAG) {
           // ...
            matrix.set(savedMatrix);
            matrix.postTranslate(event.getX() - start.x, event.getY()
                   - start.y);
       } else if (mode == ZOOM)
       {
           float newDist = spacing(event);
     
           if (newDist > 10f)
           {
               matrix.set(savedMatrix);
               float scale = newDist / oldDist;
                matrix.postScale(scale, scalemid .x, mid .y);
           }
       }
        break;
   }

   view.setImageMatrix(matrix);
   return true;

}


      private void dumpEvent(MotionEvent event)
{
   String names[] = { "DOWN", "UP", "MOVE", "CANCEL", "OUTSIDE",
           "POINTER_DOWN", "POINTER_UP", "7?", "8?", "9?" };
   StringBuilder sb = new StringBuilder();
   int action = event.getAction();
   int actionCode = action & MotionEvent.ACTION_MASK;
   sb.append("event ACTION_").append(names[actionCode]);
   if (actionCode == MotionEvent.ACTION_POINTER_DOWN
           || actionCode == MotionEvent.ACTION_POINTER_UP)
   {
       sb.append("(pid ").append(
               action >> MotionEvent.ACTION_POINTER_ID_SHIFT);
       sb.append(")");
   }
   sb.append("[");
   for (int i = 0; i < event.getPointerCount(); i++)
   {
         sb.append("#").append(i);
         sb.append("(pid ").append(event.getPointerId(i));
         sb.append(")=").append((int) event.getX(i));
         sb.append(",").append((int) event.getY(i));
       if (i + 1 < event.getPointerCount())
            sb.append(";");
   }
         sb.append("]");

}
     private float spacing(MotionEvent event
{
   float xevent.getX(0) - event.getX(1);
   float yevent.getY(0) - event.getY(1);
   return FloatMath.sqrt(x *x + y * y);
}

private void midPoint(PointF point, MotionEvent event)
       {
   float x = event.getX(0) + event.getX(1);
   float y = event.getY(0) + event.getY(1);
   point.set(x / 2, y / 2);
}
private class ScaleListener extends
ScaleGestureDetector.SimpleOnScaleGestureListener 
          {
@Override
public boolean onScale(ScaleGestureDetector detector
{
float scaleFactor detector.getScaleFactor();
scaleFactor = Math.max(0.1f, Math.min(scaleFactor , 5.0f));
matrix.setScale(scaleFactor scaleFactor );
i.setImageMatrix(matrix);
return true;
}
 }
}


Happy Coding :)


Android How to add app to Share Via List

Now I am going to explain how to add our android application to share via list


Step 1).Create Mainactivity.java



package com.sharevia;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;

public class MainActivity extends Activity 
{
        ImageView ShareImage;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ShareImage = (ImageView)findViewById(R.id.ShareImage);

Intent intent = getIntent();

Bundle extras = intent.getExtras();

String action = intent.getAction();

if (Intent.ACTION_SEND.equals(action)) 
{
if (extras.containsKey(Intent.EXTRA_STREAM)) 
{

          Uri uri = (Uri) extras.getParcelable(Intent.EXTRA_STREAM);

          ShareImage.setImageURI(uri);

}

}
}

}

Step 2).Create activity_main.xml


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.sharevia.MainActivity" >

    <ImageView

        android:id="@+id/ShareImage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

</RelativeLayout>


Step 3).AndroidManifest.xml

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.SEND" />

                <category android:name="android.intent.category.DEFAULT" />

                <data android:mimeType="image/*" />
            </intent-filter>
        </activity>
    </application>

</manifest>




Happy Coding :)

Thursday, 2 April 2015

Add fonts to android application

Here I am going to explain how to add an external font style to android application programmatically.

Step 1).Download the font type from here.
Step 2).Create a folder "fonts" inside the "assests" folder.
Step 3).Import The jar file into the folder "fonts".




Step 4).Open the fonts.xml file and create Textview.



<?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"
    android:background="#000000" >
    <TextView
        android:id="@+id/newfont"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:textSize="50dip"
        android:gravity="center"
        android:textColor="#ffffff"
        android:layout_marginTop="60dip"
        android:text="NewFont" />
</LinearLayout>

Step 4).Fonts.java


package com.example.androidhive;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
public class Fonts extends Activity 
{
TextView newFont;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
  String Path= "";//Type your path
   newFont=(TextView)findViewById(R.id.newfont);
      Typeface T = Typeface.createFromAsset(getAssets(), Path);
   newFont.setTypeface(T);
       
       
    }
}

Happy Coding :)....