Posts

Showing posts from February, 2015

Android - GPS Location with Listener

/****  * GPS Process  *  * First of all call listener of Location  * then checking for GPS_PROVIDER  * if not available then check for NETWORK_PROVIDER  * and if its also not available then pass 0.00,0.00 to longitude and latitude  *  ****  */ /** PROCESS for Get Longitude and Latitude **/ locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); // Define a listener that responds to location updates locationListener = new LocationListener() { public void onLocationChanged(Location location) { // Called when a new location is found by the network location provider. longitude = String.valueOf(location.getLongitude()); latitude = String.valueOf(location.getLatitude()); Log.d(TAG, "changed Loc : " + longitude + ":" + latitude); } public void onStatusChanged(String provider, int status, Bundle extras) { } public void onProviderEnabled(String provider) { } public void onProviderDisabled(Str...

Android - Camera Taking picture through android camera & surfaceview example

Camera Integration with Surface View provide you a way to take photo in android application. You can Intent Activity for taking photo. But Surface View provide a way to take photo in Customization way. This article address about SurfaceView and Android Phone camera integration Make one XML file path res/layout which Include on simple SurfaceView <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <SurfaceView android:id="@+id/surface_camera" android:layout_width="fill_parent" android:layout_height="10dip" android:layout_weight="1"> </SurfaceView> </LinearLayout> Camera Implementation code Create an activity called CameraView that implements the interface SurfaceHolder.Callback. This will overide some method which control life cycle of...

Android Battery Management API

Getting Battery Level and monitoring/determining its state programmatically using Battery Receiver BatteryManager API exists in android to provide battery related function. It allow developer to develop application without draining battery of android user. Smart Developer never waste battery of android phone. This tutorial teach you how to get current battery level of android phone and notify every time when battery level changes Getting Current Battery Level IntentFilter mIntentFilter = new IntentFilter();                 mIntentFilter.addAction(Intent.ACTION_BATTERY_LOW);                 mIntentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);                 mIntentFilter.addAction(Intent.ACTION_BATTERY_OKAY);                 Intent batteryIntent = registerReceiver(null, mIntentFilter);      ...

Advance Pinch zoom in android ImageView

1) Create a new project and Download this library , add this Jar to libs folder of your project 2) Create one layout with one ImageView (Which need to be zoom) 3) Create one Activity and change to following code. This will handle all attributes required for pinch to zoom ImageView import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.RectF; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import com.imagezoom.ImageAttacher; import com.imagezoom.ImageAttacher.OnMatrixChangedListener; import com.imagezoom.ImageAttacher.OnPhotoTapListener; public class SampleZoom extends Activity {     ImageView mImaView;     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.pinch_sample);         ...

Adjust the color of a drawable

private Drawable adjust(Drawable drawableToAdjust,int colorAdjust) { int pixelFrom,pixelTo; Bitmap src = ((BitmapDrawable) drawableToAdjust).getBitmap(); Bitmap bitmap = src.copy(Bitmap.Config.ARGB_8888, true); for(int x = 0;x < bitmap.getWidth();x++) for(int y = 0;y < bitmap.getHeight();y++) { pixelFrom=bitmap.getPixel(x, y);         pixelTo=Color.argb( (int)(     (double)Color.alpha(pixelFrom)*Color.alpha(colorAdjust)/255), (int)(255-((double)Color.red  (pixelFrom)*(1-(double)Color.red  (colorAdjust)/255))), (int)(255-((double)Color.green(pixelFrom)*(1-(double)Color.green(colorAdjust)/255))), (int)(255-((double)Color.blue (pixelFrom)*(1-(double)Color.blue (colorAdjust)/255))) ); bitmap.setPixel(x,y,pixelTo); } return new BitmapDrawable(bitmap); }

Add and Handle Menu Items

public class TestProject extends Activity {     /* Set ID's */     private final int MENU_NEW_GAME = 0;     private final int MENU_QUIT = 1;         /* Create Menu Items */     public boolean onCreateOptionsMenu(Menu menu) {         menu.add(0, MENU_NEW_GAME, 0, "Help");         menu.add(0, MENU_QUIT, 0, "About");         return true;     }         /* Handles Item Selection */     public boolean onOptionsItemSelected(MenuItem item) {         switch (item.getItemId()) {             case MENU_NEW_GAME:                 newGame();                 return true;             case MENU_QUIT:                 finish(); ...