Friday, April 11, 2014

ListView-Swipe To Delete list in android.

Fragment

ANDROID – Upload an image to a server -- Base64

http://www.coderzheaven.com/category/uploaing-a-file/

http://sunil-android.blogspot.in/2013/03/image-upload-on-server.html

FIND PATH OF IMAGE FROM THE MOBILE DEVICE 

http://www.androidsnippets.com/get-file-path-of-gallery-image 

http://stackoverflow.com/questions/19834842/android-gallery-on-kitkat-returns-different-uri-for-intent-action-get-content 

BEST Example to get image path

http://viralpatel.net/blogs/pick-image-from-galary-android-app/

/**
 * Get a file path from a Uri. This will get the the path for Storage Access
 * Framework Documents, as well as the _data field for the MediaStore and
 * other file-based ContentProviders.
 *
 * @param context The context.
 * @param uri The Uri to query.
 * @author paulburke
 */
public static String getPath(final Context context, final Uri uri) {

    final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

    // DocumentProvider
    if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
        // ExternalStorageProvider
        if (isExternalStorageDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            if ("primary".equalsIgnoreCase(type)) {
                return Environment.getExternalStorageDirectory() + "/" + split[1];
            }

            // TODO handle non-primary volumes
        }
        // DownloadsProvider
        else if (isDownloadsDocument(uri)) {

            final String id = DocumentsContract.getDocumentId(uri);
            final Uri contentUri = ContentUris.withAppendedId(
                    Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

            return getDataColumn(context, contentUri, null, null);
        }
        // MediaProvider
        else if (isMediaDocument(uri)) {
            final String docId = DocumentsContract.getDocumentId(uri);
            final String[] split = docId.split(":");
            final String type = split[0];

            Uri contentUri = null;
            if ("image".equals(type)) {
                contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
            } else if ("video".equals(type)) {
                contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
            } else if ("audio".equals(type)) {
                contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
            }

            final String selection = "_id=?";
            final String[] selectionArgs = new String[] {
                    split[1]
            };

            return getDataColumn(context, contentUri, selection, selectionArgs);
        }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {
        return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
        return uri.getPath();
    }

    return null;
}

/**
 * Get the value of the data column for this Uri. This is useful for
 * MediaStore Uris, and other file-based ContentProviders.
 *
 * @param context The context.
 * @param uri The Uri to query.
 * @param selection (Optional) Filter used in the query.
 * @param selectionArgs (Optional) Selection arguments used in the query.
 * @return The value of the _data column, which is typically a file path.
 */
public static String getDataColumn(Context context, Uri uri, String selection,
        String[] selectionArgs) {

    Cursor cursor = null;
    final String column = "_data";
    final String[] projection = {
            column
    };

    try {
        cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                null);
        if (cursor != null && cursor.moveToFirst()) {
            final int column_index = cursor.getColumnIndexOrThrow(column);
            return cursor.getString(column_index);
        }
    } finally {
        if (cursor != null)
            cursor.close();
    }
    return null;
}


/**
 * @param uri The Uri to check.
 * @return Whether the Uri authority is ExternalStorageProvider.
 */
public static boolean isExternalStorageDocument(Uri uri) {
    return "com.android.externalstorage.documents".equals(uri.getAuthority());
}

/**
 * @param uri The Uri to check.
 * @return Whether the Uri authority is DownloadsProvider.
 */
public static boolean isDownloadsDocument(Uri uri) {
    return "com.android.providers.downloads.documents".equals(uri.getAuthority());
}

/**
 * @param uri The Uri to check.
 * @return Whether the Uri authority is MediaProvider.
 */
public static boolean isMediaDocument(Uri uri) {
    return "com.android.providers.media.documents".equals(uri.getAuthority());
}
 

Sqlite tutorial with customlistview

http://tausiq.wordpress.com/2012/08/22/android-list-view-from-database-with-cursor-adapter/

http://tausiq.wordpress.com/2012/08/22/android-list-view-from-database-with-cursor-adapter/

Thursday, April 3, 2014

Imortant Link

 

Custom ListView with Image and Text Using BaseAdapter  

http://www.tutorialsbuzz.com/2014/03/watsapp-custom-listview-imageview-textview-baseadapter.html

Android Button State Change Example 

http://www.tutorialsbuzz.com/2014/04/android-button-state-change-example.html

 

OnActivityResult Demo



Android Fundamentals: IntentService Basics
IntentService (android.app.IntentService) is a simple type of service that can be used to handle asynchronous work off the main thread by way of Intent requests. Each intent is added to the IntentService’s queue and handled sequentially.



Custom checkbox and rediobutton


http://icetea09.com/blog/2014/03/18/android-android-action-bar/




http://www.grokkingandroid.com/adding-actionbarsherlock-to-your-project/

creating-frame-animations-in-android
http://javatechig.com/android/creating-frame-animations-in-android


http://brainflush.wordpress.com/2009/03/15/understanding-android-themes-and-styles/





Paypal Intigratioin


https://github.com/paypal/PayPal-Android-SDK

android-reverse-geocoding-yahoo-api.html



http://www.londatiga.net/it/how-to-send-image-to-twitpic-from-android/


/**
       * Take screenshot of the activity including the action bar
       *
       * @param activity
       * @return The screenshot of the activity including the action bar
       */
     
public static Bitmap takeScreenshot(Activity activity)
      {
            ViewGroup decor = (ViewGroup)activity.getWindow().getDecorView();
            ViewGroup decorChild = (ViewGroup)decor.getChildAt(0);
            decorChild.setDrawingCacheEnabled(true);
            decorChild.buildDrawingCache();
            Bitmap drawingCache = decorChild.getDrawingCache(true);
            Bitmap bitmap = Bitmap.createBitmap(drawingCache);
            decorChild.setDrawingCacheEnabled(false);
            return bitmap;
      }

/**
       * Print hash key
       */

      public static void printHashKey(Context context)
      {
            try
            {
                  String TAG = "com.sromku.simple.fb.example";
PackageInfo info = ontext.getPackageManager().getPackageInfo(TAG,
                        PackageManager.GET_SIGNATURES);
                  for (Signature signature: info.signatures)
                  {
                        MessageDigest md = MessageDigest.getInstance("SHA");
                        md.update(signature.toByteArray());
                        String keyHash = Base64.encodeToString(md.digest(),Base64.DEFAULT);
                        Log.d(TAG, "keyHash: " + keyHash);
                  }
            }
            catch (NameNotFoundException e)
            {

            }
            catch (NoSuchAlgorithmException e)
            {

            }
      }

Android Sliding Menu using Navigation Drawer


http://manishkpr.webheavens.com/android-navigation-drawer-example-using-fragments/

Working Code with Fragment

tutorial-activity-slide-animation

Monday, March 31, 2014

Create Json string Format to POST Json data to the Service-- With Array

 http://www.javacodegeeks.com/2013/10/android-json-tutorial-create-and-parse-json-data.html


public class JsonUtil {

public static String toJSon(Person person) {
      try {
        // Here we convert Java Object to JSON 
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("name", person.getName()); // Set the first name/pair 
        jsonObj.put("surname", person.getSurname());

        JSONObject jsonAdd = new JSONObject(); // we need another object to store the address
        jsonAdd.put("address", person.getAddress().getAddress());
        jsonAdd.put("city", person.getAddress().getCity());
        jsonAdd.put("state", person.getAddress().getState());

        // We add the object to the main object
        jsonObj.put("address", jsonAdd);

        // and finally we add the phone number
        // In this case we need a json array to hold the java list
        JSONArray jsonArr = new JSONArray();

        for (PhoneNumber pn : person.getPhoneList() ) {
            JSONObject pnObj = new JSONObject();
            pnObj.put("num", pn.getNumber());
            pnObj.put("type", pn.getType());
            jsonArr.put(pnObj);
        }

        jsonObj.put("phoneNumber", jsonArr);

        return jsonObj.toString();

    }
    catch(JSONException ex) {
        ex.printStackTrace();
    }

    return null;

}
 
 
{
   "phoneNumber": [
      {
         "type": "work",
         "num": "11111"
      },
      {
         "type": "home",
         "num": "2222"
      }
   ],
   "address": {
      "state": "World",
      "address": "infinite space, 000",
      "city": "Android city"
   },
   "surname": "Swa",
   "name": "Android"
}
========================================================