Open top menu



In this tutorial explain how to open new Activity when swipe this listview possition right to left .
i have earlier  implement the swipe gesture detector code, this code get the  X,Y pixel point when onTouch finger.


class SwipeGestureListener extends SimpleOnGestureListener implements
    OnTouchListener {
   Context context;
   GestureDetector gestureDetector;
   static final int SWIPE_MIN_DISTANCE = 120;
   static final int SWIPE_MAX_OFF_PATH = 250;
   static final int SWIPE_THRESHOLD_VELOCITY = 200;

   public SwipeGestureListener() {
    super();
   }

   public SwipeGestureListener(Context context) {
    this(context, null);
   }

   public SwipeGestureListener(Context context, GestureDetector gestureDetector) {

    if (gestureDetector == null)
    gestureDetector = new GestureDetector(context, this);

    this.context = context;
    this.gestureDetector = gestureDetector;
   }

   @Override
   public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
     float velocityY) {

    final int position = tutorials.pointToPosition(
      Math.round(e1.getX()), Math.round(e1.getY()));

    String tutorialName = (String) tutorials.getItemAtPosition(position);

    if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
     if (Math.abs(e1.getX() - e2.getX()) > SWIPE_MAX_OFF_PATH
       || Math.abs(velocityY) < SWIPE_THRESHOLD_VELOCITY) {
      return false;
     }
     if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this, "bottomToTop" + tutorialName,
        Toast.LENGTH_SHORT).show();
     } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this,
        "topToBottom  " + tutorialName, Toast.LENGTH_SHORT)
        .show();
     }
    } else {
     if (Math.abs(velocityX) < SWIPE_THRESHOLD_VELOCITY) {
      return false;
     }
// open new activity

     if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this, "swipe RightToLeft " + tutorialName, 5000).show();
       
      Intent intent=new Intent(MainActivity.this,second.class);
      startActivity(intent);
      
     }


else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this,
        "swipe LeftToright  " + tutorialName, 5000).show();
     }
    }

    return super.onFling(e1, e2, velocityX, velocityY);

   }

   @Override
   public boolean onTouch(View v, MotionEvent event) {

    return gestureDetector.onTouchEvent(event);
   }

   public GestureDetector getDetector() {
    return gestureDetector;
   }

  }


................................................................................................................................................................
learn More
http://androidbeginnerpoint.blogspot.in/2015/12/swipegesture-inside-listview-in-android.html
Read more


 In this Blog explain how to used swipe gesture detector inside ListView in android.
the swipe gesture is an impotent part of user  interaction on user interface your android app.


package com.example.androidbegnnerpoint;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity  extends Activity {

  ListView tutorials;
String[] tutorial =
 { "1.SWIPE GETSTURE TUTORIAL",
"2.HOW TO BACK WEBVIEW TO ANDROID APP",
"3.LOAD WEBVIEW WITH PROGRESSBAR IN ANDROID",
"4.TABHOST WITH ACTIVITY IN ANDROID",
"5.DRAW CANVAS LINE ONTOUCH FINGER IN ANDROID",
"6.HOW TO SET DRAWABLE IMAGE IN TEXTVIEW PROGRAMATICALLY IN ANDROID",
"7.IMAGE SHADOW EFFECT (HIGHLIGHT/FOCUS) IN IMAGEVIEW IN ANDROID",
"8.GLOW EFFECT ON IMAGEVIEW IN ANDROID",
"9.DARG IMAGE ONTOUCH FINGER IN ANDROID",
"10.ANDROID BASIC CALCULATOR"};


 SwipeGestureListener gestureListener;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  tutorials= (ListView) findViewById(R.id.list_tutorials);
   ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
     MainActivity.this, android.R.layout.simple_list_item_1, tutorial);
 
   tutorials.setAdapter(arrayAdapter);
      gestureListener = new SwipeGestureListener(MainActivity.this);
      tutorials.setOnTouchListener(gestureListener);
 }



  class SwipeGestureListener extends SimpleOnGestureListener implements
    OnTouchListener {
   Context context;
   GestureDetector gestureDetector;
   static final int SWIPE_MIN_DISTANCE = 120;
   static final int SWIPE_MAX_OFF_PATH = 250;
   static final int SWIPE_THRESHOLD_VELOCITY = 200;

   public SwipeGestureListener() {
    super();
   }

   public SwipeGestureListener(Context context) {
    this(context, null);
   }

   public SwipeGestureListener(Context context, GestureDetector gestureDetector) {

    if (gestureDetector == null)
    gestureDetector = new GestureDetector(context, this);

    this.context = context;
    this.gestureDetector = gestureDetector;
   }

   @Override
   public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
     float velocityY) {

    final int position = tutorials.pointToPosition(
      Math.round(e1.getX()), Math.round(e1.getY()));

    String tutorialName = (String) tutorials.getItemAtPosition(position);

    if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
     if (Math.abs(e1.getX() - e2.getX()) > SWIPE_MAX_OFF_PATH
       || Math.abs(velocityY) < SWIPE_THRESHOLD_VELOCITY) {
      return false;
     }
     if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this, "bottomToTop" + tutorialName,
        Toast.LENGTH_SHORT).show();
     } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this,
        "topToBottom  " + tutorialName, Toast.LENGTH_SHORT)
        .show();
     }
    } else {
     if (Math.abs(velocityX) < SWIPE_THRESHOLD_VELOCITY) {
      return false;
     }
     if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this,
        "swipe RightToLeft " + tutorialName, 5000).show();
     } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this,
        "swipe LeftToright  " + tutorialName, 5000).show();
     }
    }

    return super.onFling(e1, e2, velocityX, velocityY);

   }

   @Override
   public boolean onTouch(View v, MotionEvent event) {

    return gestureDetector.onTouchEvent(event);
   }

   public GestureDetector getDetector() {
    return gestureDetector;
   }

  }

}


activity_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"
    android:id="@+id/layout">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/logoweb" />

    <ListView
        android:id="@+id/list_tutorials"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
          >
    </ListView>
</LinearLayout>
...............................................................................................................................................................






try this code...

Read more



In this blog implement the Basic calculator, try this code


Step 1:
 Create a activity_main.xml inside res/layout folder....

activity_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" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10pt"
        android:layout_marginRight="10pt"
        android:layout_marginTop="3pt" >

        <EditText
            android:id="@+id/editNumber"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="5pt"
            android:layout_weight="1"
            android:inputType="numberDecimal" >
        </EditText>

        <EditText
            android:id="@+id/editNumbers"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5pt"
            android:layout_weight="1"
            android:inputType="numberDecimal" >
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5pt"
        android:layout_marginRight="5pt"
        android:layout_marginTop="3pt" >

        <Button
            android:id="@+id/btnAddtion"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="+"
            android:textSize="8pt" >
        </Button>

        <Button
            android:id="@+id/btnSubtract"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="-"
            android:textSize="8pt" >
        </Button>

        <Button
            android:id="@+id/btnMultiply"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="*"
            android:textSize="8pt" >
        </Button>

        <Button
            android:id="@+id/btnDivision"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="/"
            android:textSize="8pt" >
        </Button>
    </LinearLayout>

    <TextView
        android:id="@+id/tvResult"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5pt"
        android:layout_marginRight="5pt"
        android:layout_marginTop="3pt"
        android:gravity="center_horizontal"
        android:textSize="12pt" >
    </TextView>

</LinearLayout>


Step:2
Create MainActivity.java inside src folder

Main_Activity.java
..................................................................................................................................................................
package com.example.androidbeginnerpoin;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

 EditText editNum1;
 EditText editNum2;

 Button buttionAdd;
 Button buttionSub;
 Button buttionMult;
 Button buttionDiv;

 TextView  textResult;

 String oper = "";


 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

 
   editNum1 = (EditText) findViewById(R.id.editNumber);
   editNum2 = (EditText) findViewById(R.id.editNumbers);

   buttionAdd = (Button) findViewById(R.id.btnAddtion);
   buttionSub = (Button) findViewById(R.id.btnSubtract);
   buttionMult = (Button) findViewById(R.id.btnMultiply);
   buttionDiv = (Button) findViewById(R.id.btnDivision);

     textResult= (TextView) findViewById(R.id.tvResult);

 
   buttionAdd.setOnClickListener((OnClickListener) this);
   buttionSub.setOnClickListener(this);
   buttionMult.setOnClickListener(this);
   buttionDiv.setOnClickListener(this);

 }

 @Override
 public void onClick(View v) {
 
   float num1 = 0;
   float num2 = 0;
   float result = 0;

 
   if (TextUtils.isEmpty(editNum1.getText().toString())
       || TextUtils.isEmpty(editNum2.getText().toString())) {
     return;
   }

 
   num1 = Float.parseFloat(editNum1.getText().toString());
   num2 = Float.parseFloat(editNum2.getText().toString());

   
   switch (v.getId()) {
   case R.id.btnAddtion:
     oper = "+";
     result = num1 + num2;
     break;
   case R.id.btnSubtract:
     oper = "-";
     result = num1 - num2;
     break;
   case R.id.btnMultiply:
     oper = "*";
     result = num1 * num2;
     break;
   case R.id.btnDivision:
     oper = "/";
     result = num1 / num2;
     break;
   default:
     break;
   }

 
   textResult.setText(num1 + " " + oper + " " + num2 + " = " + result);
 }
}



Read more



In this bloag implement  How to Back WebView to Our android app. try this code



// To handle "Back" key press event for WebView to go back to previous screen.
   @Override
   public boolean onKeyDown(int keyCode, KeyEvent event)
   {
       if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
        webview.goBack();
           return true;
       }
       return super.onKeyDown(keyCode, event);
   }
Read more


try this code..

// first, get all checked checkBox in listview
final SparseBooleanArray checkedItems = listviewroti_prata.getCheckedItemPositions();

for (int i = 0; i < checkedItems.size(); i++){
  
//find all checked or not
final boolean isChecked; = checkedItems.valueAt(i);
   
if (!isChecked){
   
Toast.makeText(getApplicationContext(), "not checked", Toast.LENGTH_LONG).show();                                                            
 } else{
Toast.makeText(getApplicationContext(), " checked", Toast.LENGTH_LONG).show();
}
Read more


In this blog explain how to show loading process webview in android.

we will discuss already earlier webview but as per required show loading process webview in our application.

try this code...

MainActivity.java
...................................................................................................................................................................

package com.example.androidbeginnerpoin;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;


public class MainActivity extends Activity {
private WebView mWebview ;
ProgressBar progressBar;
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 mWebview  = (WebView)findViewById(R.id.webView1);
 mWebview.getSettings().setJavaScriptEnabled(true);



  String Url="http://androidbeginnerpoint.blogspot.in/";
  startWebView(Url);
}


private void startWebView(String url) {
     
       
mWebview.setWebViewClient(new WebViewClient() {    
           ProgressDialog progressDialog;
       
     
           public boolean shouldOverrideUrlLoading(WebView view, String url) {            
               view.loadUrl(url);
               return true;
           }
     
       
           public void onLoadResource (WebView view, String url) {
               if (progressDialog == null) {                
                   progressDialog = new ProgressDialog(MainActivity.this);
                   progressDialog.setMessage("Loading...");
                   progressDialog.show();
                   progressDialog.setCanceledOnTouchOutside(false);
               }
           }
           public void onPageFinished(WebView view, String url) {
               try{
               if (progressDialog.isShowing()) {
                   progressDialog.dismiss();
                   progressDialog=null;
               
               }
               }catch(Exception exception){
               
                   exception.printStackTrace();
               }
           }
         
       });
       
     
mWebview.getSettings().setJavaScriptEnabled(true);
     
   
     
     
mWebview.loadUrl(url);
       
       
   }
 

}
activity_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" >

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>





 
Read more


in this blog we will how to load webpage in android. its a very simple explain below

you can load webpage URL in WebView android wigets. show below code.

MainActivity.java,
.............................................................................................................................................................
package com.example.androidbeginnerpoin;

import android.app.Activity;
import android.app.TabActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

@SuppressWarnings("deprecation")
public class MainActivity extends Activity {
private WebView mWebview ;
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 mWebview  = (WebView)findViewById(R.id.webView1);
 mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript

      final Activity activity = this;

      mWebview.setWebViewClient(new WebViewClient() {
          public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
              Toast.makeText(activity, description, Toast.LENGTH_SHORT).show();
          }
      });

      mWebview .loadUrl("http://androidbeginnerpoint.blogspot.in/");
 

}

}



activity_main.xml.
.................................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />







try this code.......



 
Read more



1.TAB ACTIVITY ,
2.TAB LAYOUT,
3.TABHOST WITH ACTIVITY.


In this blog implement tabhost with activity in TabWidget.

Step 1.

create a android project in your plateform inside workspace.

Step 2

create MainActivity,java inside src folder..

MainActivity,java
.........................................................................................................................................................
package com.example.androidbeginnerpoin;

import android.support.v7.app.ActionBarActivity;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TabHost;

public class MainActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);

 Resources res = getResources();
 TabHost tabHost = getTabHost();
 TabHost.TabSpec spec;
 Intent intent;


 intent = new Intent().setClass(this, CallActivity.class);
 spec = tabHost.newTabSpec("Call")
    .setIndicator("Call", res.getDrawable(R.drawable.button_action))
   .setContent(intent);
 tabHost.addTab(spec);



 intent = new Intent().setClass(this, MessageActivity.class);
 spec = tabHost.newTabSpec("Message")
    .setIndicator("Message", res.getDrawable(R.drawable.button_action))
   .setContent(intent);
 tabHost.addTab(spec);


 intent = new Intent().setClass(this, ContactActivity.class);
 spec = tabHost
   .newTabSpec("Contact")
   .setIndicator("Contact", res.getDrawable(R.drawable.button_action))
 
   .setContent(intent);
 tabHost.addTab(spec);


 tabHost.setCurrentTab(0);


}

}

Step 3.

create activity_main.xml inside res folder....

in this class dropdwon TabWidget.
............................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
 
     <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"/>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:layout_marginBottom="-4dp"/>
   
    </LinearLayout>
</TabHost>


Step 4.

you can create  three Activity insede res folder


CallActivity .java.
..............................................................................................................................................................
package com.example.androidbeginnerpoin;

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

public class CallActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
  setContentView(R.layout.call_activity);
}
}


ContactActivity.java.
.............................................................................................................................................................
package com.example.androidbeginnerpoin;

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

public class ContactActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.contact);
}
}


MessageActivity .java
...........................................................................................................................................................
package com.example.androidbeginnerpoin;

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

public class MessageActivity extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.message);
}
}

Step5.


create three xml class inside res folder.

call_activity.xml.
..............................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#b5f2bc">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="300dp"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="141dp"
        android:src="@drawable/poin_logo" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="61dp"
        android:text="CALL TAB"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

contact.xml.
..................................................................................................................................................................

  <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#9ccee9">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="300dp"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="141dp"
        android:src="@drawable/poin_logo" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="61dp"
        android:text="CONTACT TAB"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

message.xml.
...................................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#e3e560">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="300dp"
        android:layout_height="100dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="141dp"
        android:src="@drawable/poin_logo" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="61dp"
        android:text="MESSAGE TAB"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>







try this code, i hope my blog help you.
Read more





In this tutorial draw a finger feedback paint line. in this code implement draw canvas view and show finger touch circle path.

create subclass DrawingView  and extends View Class ,the DrawingView  class add on MainActivity .java .


setContentView(drawingview);

try this code........................................

MainActivity .java
..............................................................................................................................................
package com.example.androidbeginnerpoint;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;

public class MainActivity extends Activity {
DrawingView drawingview;
private Paint mPaintcanvas;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
drawingview = new DrawingView(this);
setContentView(drawingview);

mPaintcanvas = new Paint();
mPaintcanvas.setAntiAlias(true);
mPaintcanvas.setDither(true);
mPaintcanvas.setColor(Color.GREEN);
mPaintcanvas.setStyle(Paint.Style.STROKE);
mPaintcanvas.setStrokeJoin(Paint.Join.ROUND);
mPaintcanvas.setStrokeCap(Paint.Cap.ROUND);
mPaintcanvas.setStrokeWidth(40);
}

public class DrawingView extends View {

public int width;
public int height;
private Bitmap mBitmap;
private Canvas mCanvaspaint;
private Path mPath;
private Paint mBitmapPaint;
Context context;
private Paint circlePaint;
private Path circlePath;

public DrawingView(Context c) {
super(c);
context = c;
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
circlePaint = new Paint();
circlePath = new Path();
circlePaint.setAntiAlias(true);
circlePaint.setColor(Color.BLUE);
circlePaint.setStyle(Paint.Style.STROKE);
circlePaint.setStrokeJoin(Paint.Join.MITER);
circlePaint.setStrokeWidth(4f);


}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);

mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
mCanvaspaint = new Canvas(mBitmap);


}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);

canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaintcanvas);
canvas.drawPath(circlePath, circlePaint);
}

private float mX, mY;
private static final float TOUCH_TOLERANCE = 4;

private void touch_start(float x, float y) {
mPath.reset();
mPath.moveTo(x, y);
mX = x;
mY = y;


}

private void touch_move(float x, float y) {
float dx = Math.abs(x - mX);
float dy = Math.abs(y - mY);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.quadTo(mX, mY, (x + mX) / 2, (y + mY) / 2);
mX = x;
mY = y;

circlePath.reset();
circlePath.addCircle(mX, mY, 40, Path.Direction.CW);

}
}

private void touch_up() {
mPath.lineTo(mX, mY);
circlePath.reset();

mCanvaspaint.drawPath(mPath, mPaintcanvas);

mPath.reset();

}

@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touch_start(x, y);
invalidate();
break;
case MotionEvent.ACTION_MOVE:
touch_move(x, y);
invalidate();
break;
case MotionEvent.ACTION_UP:
touch_up();
invalidate();
break;
}
return true;
}

public void clear() {
if (mCanvaspaint != null) {
mPaintcanvas.setARGB(0xff, 0, 0, 0);
mCanvaspaint.drawPaint(mPaintcanvas);
invalidate();

}
}


}

}

// this is aniamtion Code
/*
 * this.requestWindowFeature(Window.FEATURE_NO_TITLE);
 * this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
 * WindowManager.LayoutParams.FLAG_FULLSCREEN ); DisplayMetrics dm = new
 * DisplayMetrics();
 *
 * this.getWindowManager().getDefaultDisplay().getMetrics(dm);
 * this.setContentView(new WaterEffectView(this, dm.widthPixels,
 * dm.heightPixels));
 */
Read more

 In this blog implement the finger feedback touch line draw on image view. the draw as a straight line . in this tutorial we will used Bitmap,Canvas, paint class.

Bitmap class- loading bitmap Objects and keep your UI.
Canvas class-with the help draw  a line and bitmap to hold pixels,
Paint class-holds style and color information.

first, you create activity_main.xml class inside res folder.
...............................................................................................................................................................

<?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:id="@+id/layout">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/s" />

</LinearLayout>



MainActivity .java
................................................................................................................................................................

package com.androidbeginner.testcode;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.Display;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;

public class MainActivity extends Activity implements OnTouchListener {
 ImageView imageView;
 Bitmap mbitmap;
 Canvas mcanvas;
 Paint mpaint;
 float downaxies_x = 0, downaxies_y = 0, upaxies_X = 0, upaxies_y = 0;
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

   imageView = (ImageView) this.findViewById(R.id.imageView1);

   Display currentDisplay = getWindowManager().getDefaultDisplay();
   float dwidth = currentDisplay.getWidth();
   float dhight = currentDisplay.getHeight();

   mbitmap = Bitmap.createBitmap((int) dwidth, (int) dhight,
       Bitmap.Config.ARGB_8888);
   mcanvas = new Canvas(mbitmap);
 
   mpaint = new Paint();
   mpaint.setColor(Color.RED);
   imageView.setImageBitmap(mbitmap);

   imageView.setOnTouchListener(this);
 }

 public boolean onTouch(View v, MotionEvent event) {
   int action = event.getAction();
   switch (action) {
   case MotionEvent.ACTION_DOWN:
    downaxies_x = event.getX();
    downaxies_y = event.getY();
     break;
   case MotionEvent.ACTION_MOVE:
     break;
   case MotionEvent.ACTION_UP:
    upaxies_X = event.getX();
    upaxies_y = event.getY();
       mcanvas.drawLine(downaxies_x, downaxies_y, upaxies_X, upaxies_y, mpaint);
     imageView.invalidate();
     break;
   case MotionEvent.ACTION_CANCEL:
     break;
   default:
     break;
   }
   return true;
 }
}

Read more


In this blog explain how to set image left,right ,bottom,top  in TextView in android programmatic.

first, you have create an activity inside src folder..

scond ,you have create onCreate() method inside MainActivity.java class.
 show below.

setCompoundDrawablesWithIntrinsicBounds (int left, int top, int right, int bottom)


MainActvity .java
..............................................................................................................................................


package com.androidbeginner.testcode;

import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.support.v4.widget.DrawerLayout.LayoutParams;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MainActivity extends Activity {    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
     
        final LinearLayout lm = (LinearLayout) findViewById(R.id.layout);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        params.setMargins(10,10,10,10);
        // set image left in textview
        TextView text=new TextView(this);
         text.setText("textview");
         text.setCompoundDrawablesWithIntrinsicBounds(R.drawable.dwon_arrow, 0, 0,0);
         text.setLayoutParams(params);
         text.setBackgroundColor(Color.RED);
         lm.addView(text);
       
       // set image top in textview
         TextView text1=new TextView(this);
         text1.setText("textview");
         text1.setLayoutParams(params);
         text1.setBackgroundColor(Color.RED);
         text1.setCompoundDrawablesWithIntrinsicBounds(0,R.drawable.dwon_arrow,0,0);
         lm.addView(text1);
       
        // set image right in textview
         TextView text2=new TextView(this);
         text2.setText("textview");
         text2.setLayoutParams(params);
         text2.setBackgroundColor(Color.RED);
         text2.setCompoundDrawablesWithIntrinsicBounds( 0, 0,R.drawable.dwon_arrow,0);
         lm.addView(text2);
        // set image bottomt in textview
         TextView text3=new TextView(this);
         text3.setText("textview");
         text3.setLayoutParams(params);
         text3.setBackgroundColor(Color.RED);
         text3.setCompoundDrawablesWithIntrinsicBounds( 0, 0,0,R.drawable.dwon_arrow );
         lm.addView(text3);
    }
}

Read more


In this blog explain ,how to set Array in TextView in android.

try this code.
....................................................................................................

String text="";

for(int i=0; i<ArrayList.size();i++){

String text1=ArratList.get(i);

text=text+text1;
}
text_view.setText(text);



try this code.
...............................................................................................


String[] s={1,2,3,4,5,6}

text_view.setText(s.toString(s));



try this code.
...............................................................................................

String[] s={1,2,3,4,5,6}

StringBuilder builder= new StringBuilder();

for(String y: s){

builder.append(y);
}
text_view.setText(builder,toString.trim());


Read more

In this tutorial explain how to set Actionbar background color and title color in android programmatically .

first ,you have create xml class inside drawable folder...




actionbar_background.xml.

in this class set three color and set on actionbar background.

..................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
    <gradient
        android:startColor="#000000"
        android:centerColor="#000000"
        android:endColor="#000000"
        android:angle="90"/>
    <corners
        android:radius="0dp"/>
</shape>


MainActivity.java

in this class set a actionbar_background.xml inside onCreate().
................................................................................................................................................



import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.Html;


public class MainActivity extends Activity {



@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tracking);

 // get Actionbar and set the tilte name and color

getActionBar().setTitle(Html.fromHtml("<font color='#ffffff'>Tracking</font>"));

              //   set actionbar background color xml .
Drawable drawable = getResources().getDrawable(R.drawable.actionbar_background);
getActionBar().setBackgroundDrawable(drawable);
}

}

try this code


 ActionBar actionbar = getActionBar();
 actionbar.setBackgroundDrawable(new ColorDrawable("COLOR"));

second ,you have implement style theme

styles.xml
...................................................................................................................................................
<resources>

     
    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
          <item name="android:actionBarStyle">@style/MyActionBar</item>
          <item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
    </style>
      
    <style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:background">@android:color/black</item>
    </style>
    
    <style name="MyTheme.ActionBar.TitleTextStyle"                                                                                    parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">@android:color/white</item>
    </style>
     
     
</resources>






Read more

In this blog implement the shadow effect on image.explain below

you have to create main.xml class and drop one ImageView show ....



<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:background="#1a496e"
    tools:context=".Splase" >


 <!--  you can drop ImageView Widgets -->


    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="300dip"
        android:layout_height="300dip"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:padding="6dp"
          />

</RelativeLayout>

Create MainActivity.java inside src folder....
..............................................................................................................................................




package com.webnetware.slcm;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BlurMaskFilter;
import android.graphics.BlurMaskFilter.Blur;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.widget.ImageView;
import android.graphics.PorterDuff;

public class MainActivity extends Activity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     
        setContentView(R.layout.activity_splase);
        ImageView im=(ImageView)findViewById(R.id.imageView1);

// set the Bitmap method in ImageView


        im.setImageBitmap(highlightImage(BitmapFactory.decodeResource(getResources(),                         R.drawable.imge)));
     
   
           
  }
    public Bitmap highlightImage(Bitmap src) {
     // create new bitmap, which will be painted
     Bitmap imageView = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);
     //  canvas for painting
     Canvas canvas = new Canvas(imageView);
     // default color
     canvas.drawColor(0, PorterDuff.Mode.CLEAR);
     // create a blur paint for capturing alpha
     Paint imageViewglow = new Paint();
     imageViewglow.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));
     int[] offsetXY = new int[2];
     // capture alpha into a bitmap
     Bitmap BitmapAlpha = src.extractAlpha(imageViewglow, offsetXY);
     // create a color paint
     Paint imageViewAlphaColor = new Paint();
     imageViewAlphaColor.setColor(0xFFFFFFFF);
     // paint color for captured alpha region (bitmap)
     canvas.drawBitmap(BitmapAlpha, offsetXY[0], offsetXY[1], imageViewAlphaColor);
     // free memory
     BitmapAlpha.recycle();
   
     // paint the image source
     canvas.drawBitmap(src, 0, 0, null);
   
     // return imageView out final image
     return imageView;
    }


}

Image Background glow effect .....try this code.

http://androidbeginnerpoint.blogspot.in/2015/11/glow-effect-on-imageview-in-android.html

Read more