06 January, 2016

List of HTML Self-Closing Tags

This page is a list of HTML elements that do not have a closing tag. They are also called {self-closing tag, empty tag, void element, singleton tag}.

Here's a complete list of self-closing tags for HTML 5.

<area />
<base />
<br />
<col />
<command />
<embed />
<hr />
<img />
<input />
<keygen />
<link />
<meta />
<param />
<source />
<track />
<wbr />

The space before the slash is optional.

Is the Ending Slash Optional?

  • HTML5: the slash is optional.
  • HTML4: the slash is technically invalid. However, it's accepted by W3C's HTML validator.
  • XHTML: The slash is REQUIRED.
I recommend to always add the slash. Because, it provides a visual clue of non-closing tags. It's also convenient if you write simples scripts to check your HTML, without a lookup table or using heavy HTML parser.

XHTML Supports Self-Closing Syntax for All Tags

In XML/XHTML, every tag can be self-closed by the ending slash <… />. When you test it, you have to make sure the server is sending the correct Internet media type as XHTML (⁖ application/xhtml+xml), otherwise browsers will treat it as HTML, regardless of the DOCTYPE in your file.
I do NOT recommend self-closing for normal tags.

Reference:


Thank you. #keepSharing

Android JSON Parsing Using okHttp Example with Custom View (ImageView + TextView)

Hello Androiders, Today I will show you demo about "How to Parse JSON using okHttp and Bind data with Custom View (ImageView + TextView) (Loading Image using Picasso)". 

In Last Post We have seen Android JSON Parsing Using okHttp Example with New Material Design Library in which you have learn How to Parse JSON using okHttp.

I hope you know how to Create Project in Android Studio and add gradle dependency:


In this Project we required following Dependency in your build.gradle:

compile 'com.squareup.okhttp:okhttp:2.4.0'  
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'  
compile 'com.squareup.picasso:picasso:2.4.0'

Don't forget to take permission of Internet Connection.

<uses-permission android:name="android.permission.INTERNET" />
Our Project Structure will be like:





To Check InternetConnection.java:

 public class InternetConnection {  
   
           /** CHECK WHETHER INTERNET CONNECTION IS AVAILABLE OR NOT */  
           public static boolean checkConnection(@NonNull Context context) {  
                     return ((ConnectivityManager) context.getSystemService  
                                         (Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo() != null;  
           }  
 }  


Now First of all we will get JSON from http://pratikbutani.x10.mx/json_data.json which provides following type of data.

JSON DATA:

 {  
   "contacts": [  
     {  
         "id": "c200",  
         "name": "Pratik Butani",  
         "email": "pratik13butani@gmail.com",  
         "address": "xx-xx-xxxx,x - street, x - country",  
         "gender" : "male",  
                     "profile_pic" : "http://lorempixel.com/100/100/",  
         "phone": {  
           "mobile": "+91 0000000000",  
           "home": "00 000000",  
           "office": "00 000000"  
         }  
     },  
     {  
         "id": "c201",  
         "name": "Johnny Depp",  
         "email": "johnny_depp@gmail.com",  
         "address": "xx-xx-xxxx,x - street, x - country",  
         "gender" : "male",  
         "profile_pic" : "http://lorempixel.com/105/105/",  
         "phone": {  
           "mobile": "+91 0000000000",  
           "home": "00 000000",  
           "office": "00 000000"  
         }  
     },  
     {  
         "id": "c202",  
         "name": "Leonardo Dicaprio",  
         "email": "leonardo_dicaprio@gmail.com",  
         "address": "xx-xx-xxxx,x - street, x - country",  
         "gender" : "male",  
         "profile_pic" : "http://lorempixel.com/110/110/",  
         "phone": {  
           "mobile": "+91 0000000000",  
           "home": "00 000000",  
           "office": "00 000000"  
         }  
     }  
   ]  
 }  


Constant Keys defined in on Keys class:

 public class Keys {  
   public static final String KEY_CONTACTS = "contacts";  
   public static final String KEY_NAME = "name";  
   public static final String KEY_PHONE = "phone";  
   public static final String KEY_MOBILE = "mobile";  
   public static final String KEY_PROFILE_PIC = "profile_pic";  
   public static final String KEY_EMAIL = "email";  
 }  


Now we will make Model for this Data so we can set or get the values of particular fields.


MyDataModel.java

 public class MyDataModel {  
   
   private int id;  
   
   private String name;  
   
   private String image;  
   
   private String email;  
   
   private String phone;  
   
   public int getId() {  
     return id;  
   }  
   
   public void setId(int id) {  
     this.id = id;  
   }  
   
   public String getName() {  
     return name;  
   }  
   
   public void setName(String name) {  
     this.name = name;  
   }  
   
   public String getImage() {  
     return image;  
   }  
   
   public void setImage(String image) {  
     this.image = image;  
   }  
   
   public String getEmail() {  
     return email;  
   }  
   
   public void setEmail(String email) {  
     this.email = email;  
   }  
   
   public String getPhone() {  
     return phone;  
   }  
   
   public void setPhone(String phone) {  
     this.phone = phone;  
   }  
 }


Now Its time to create XML file for layout which will display data like NAME, IMAGE, EMAIL.

layout_row_view.xml

<?xml version="1.0" encoding="utf-8"?>  
 <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="wrap_content"  
   android:orientation="vertical">  
   
   <ImageView  
     android:id="@+id/imageView"  
     android:layout_width="100dp"  
     android:layout_height="100dp"  
     android:layout_margin="5dp"  
     android:src="@mipmap/ic_launcher" />  
   
   <LinearLayout  
     android:layout_width="match_parent"  
     android:orientation="vertical"  
     android:layout_centerVertical="true"  
     android:layout_height="wrap_content"  
     android:layout_toRightOf="@+id/imageView">  
   
     <TextView  
       android:id="@+id/textViewName"  
       android:layout_width="match_parent"  
       android:layout_height="wrap_content"  
       android:layout_margin="5dp"  
       android:textAppearance="?android:textAppearanceLarge"  
       tools:text="TextView" />  
   
     <TextView  
       android:id="@+id/textViewEmail"  
       android:layout_width="match_parent"  
       android:layout_height="wrap_content"  
       android:layout_margin="5dp"  
       android:textAppearance="?android:textAppearanceMedium"  
       tools:text="TextView" />  
   
   </LinearLayout>  
 </RelativeLayout> 


Its fine we have created Layout for Particular row of ListView. Now We have to create Custom Adapter to bind Data in that row.

I found best tool Android Layout Finder to create that type of Adapters Quickly.

MyArrayAdapter.java

 import android.content.Context;  
 import android.view.LayoutInflater;  
 import android.view.View;  
 import android.view.ViewGroup;  
 import android.widget.ArrayAdapter;  
 import android.widget.ImageView;  
 import android.widget.RelativeLayout;  
 import android.widget.TextView;  
   
 import com.androidbuts.jsonparsing.R;  
 import com.androidbuts.jsonparsing.model.MyDataModel;  
 import com.squareup.picasso.Picasso;  
   
 import java.util.List;  
   
 public class MyArrayAdapter extends ArrayAdapter<MyDataModel> {  
   
   List<MyDataModel> modelList;  
   Context context;  
   private LayoutInflater mInflater;  
   
   // Constructors  
   public MyArrayAdapter(Context context, List<MyDataModel> objects) {  
     super(context, 0, objects);  
     this.context = context;  
     this.mInflater = LayoutInflater.from(context);  
     modelList = objects;  
   }  
   
   @Override  
   public MyDataModel getItem(int position) {  
     return modelList.get(position);  
   }  
   
   @Override  
   public View getView(int position, View convertView, ViewGroup parent) {  
     final ViewHolder vh;  
     if (convertView == null) {  
       View view = mInflater.inflate(R.layout.layout_row_view, parent, false);  
       vh = ViewHolder.create((RelativeLayout) view);  
       view.setTag(vh);  
     } else {  
       vh = (ViewHolder) convertView.getTag();  
     }  
   
     MyDataModel item = getItem(position);  
   
     vh.textViewName.setText(item.getName());  
     vh.textViewEmail.setText(item.getEmail());  
     Picasso.with(context).load(item.getImage()).placeholder(R.mipmap.ic_launcher).error(R.mipmap.ic_launcher).into(vh.imageView);  
   
     return vh.rootView;  
   }  
   
   /**  
    * ViewHolder class for layout.<br />  
    * <br />  
    * Auto-created on 2016-01-05 00:50:26 by Android Layout Finder  
    * (http://www.buzzingandroid.com/tools/android-layout-finder)  
    */  
   private static class ViewHolder {  
     public final RelativeLayout rootView;  
     public final ImageView imageView;  
     public final TextView textViewName;  
     public final TextView textViewEmail;  
   
     private ViewHolder(RelativeLayout rootView, ImageView imageView, TextView textViewName, TextView textViewEmail) {  
       this.rootView = rootView;  
       this.imageView = imageView;  
       this.textViewName = textViewName;  
       this.textViewEmail = textViewEmail;  
     }  
   
     public static ViewHolder create(RelativeLayout rootView) {  
       ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);  
       TextView textViewName = (TextView) rootView.findViewById(R.id.textViewName);  
       TextView textViewEmail = (TextView) rootView.findViewById(R.id.textViewEmail);  
       return new ViewHolder(rootView, imageView, textViewName, textViewEmail);  
     }  
   }  
 }


JSONParser.java (Copy and Paste this class in your Package): (Same as Previous Post)

 import android.support.annotation.NonNull;  
 import android.util.Log;  
 import com.squareup.okhttp.FormEncodingBuilder;  
 import com.squareup.okhttp.OkHttpClient;  
 import com.squareup.okhttp.Request;  
 import com.squareup.okhttp.RequestBody;  
 import com.squareup.okhttp.Response;  
 import org.json.JSONException;  
 import org.json.JSONObject;  
 import java.io.IOException;  
 /**  
  * @author Pratik Butani  
  */  
 public class JSONParser {  
   /********  
    * URLS  
    *******/  
   private static final String MAIN_URL = "http://pratikbutani.x10.mx/json_data.json";  
   /**  
    * TAGs Defined Here...  
    */  
   public static final String TAG = "TAG";  
   /**  
    * Key to Send  
    */  
   private static final String KEY_USER_ID = "user_id";  
   /**  
    * Response  
    */  
   private static Response response;  
   /**  
    * Get Data From WEB  
    *  
    * @return JSON Object  
    */  
   public static JSONObject getDataFromWeb() {  
     try {  
       OkHttpClient client = new OkHttpClient();  
       Request request = new Request.Builder()  
           .url(MAIN_URL)  
           .build();  
       response = client.newCall(request).execute();  
       return new JSONObject(response.body().string());  
     } catch (@NonNull IOException | JSONException e) {  
       Log.e(TAG, "" + e.getLocalizedMessage());  
     }  
     return null;  
   }  
 }  


activity_main.xml (Same as Previous Post) :

 <?xml version="1.0" encoding="utf-8"?>  
 <android.support.design.widget.CoordinatorLayout 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:id="@+id/parentLayout"  
   android:layout_height="match_parent"  
   android:fitsSystemWindows="true"  
   tools:context=".MainActivity">  
   
   <android.support.design.widget.AppBarLayout  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:theme="@style/AppTheme.AppBarOverlay">  
   
     <android.support.v7.widget.Toolbar  
       android:id="@+id/toolbar"  
       android:layout_width="match_parent"  
       android:layout_height="?attr/actionBarSize"  
       android:background="?attr/colorPrimary"  
       app:popupTheme="@style/AppTheme.PopupOverlay" />  
   
   </android.support.design.widget.AppBarLayout>  
   
   <ListView app:layout_behavior="@string/appbar_scrolling_view_behavior"  
     android:id="@+id/listView"  
     android:layout_width="fill_parent"  
     android:layout_height="match_parent" />  
   
   <android.support.design.widget.FloatingActionButton  
     android:id="@+id/fab"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:layout_gravity="bottom|end"  
     android:layout_margin="@dimen/fab_margin"  
     android:src="@android:drawable/stat_sys_download" />  
   
 </android.support.design.widget.CoordinatorLayout>  


MainActivity.java:

(Same as Previous Post, Just Created Custom Adapter so Created Class type ArrayAdapter and ArrayList.)

 import android.app.ProgressDialog;  
 import android.os.AsyncTask;  
 import android.os.Bundle;  
 import android.support.annotation.NonNull;  
 import android.support.annotation.Nullable;  
 import android.support.design.widget.FloatingActionButton;  
 import android.support.design.widget.Snackbar;  
 import android.support.v7.app.AppCompatActivity;  
 import android.support.v7.widget.Toolbar;  
 import android.util.Log;  
 import android.view.Gravity;  
 import android.view.View;  
 import android.widget.AdapterView;  
 import android.widget.ListView;  
 import android.widget.Toast;  
   
 import com.androidbuts.jsonparsing.adapter.MyArrayAdapter;  
 import com.androidbuts.jsonparsing.model.MyDataModel;  
 import com.androidbuts.jsonparsing.parser.JSONParser;  
 import com.androidbuts.jsonparsing.utils.InternetConnection;  
 import com.androidbuts.jsonparsing.utils.Keys;  
   
 import org.json.JSONArray;  
 import org.json.JSONException;  
 import org.json.JSONObject;  
   
 import java.util.ArrayList;  
   
 public class MainActivity extends AppCompatActivity {  
   
   private ListView listView;  
   private ArrayList<MyDataModel> list;  
   private MyArrayAdapter adapter;  
   
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_main);  
   
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);  
     setSupportActionBar(toolbar);  
   
     /**  
      * Array List for Binding Data from JSON to this List  
      */  
     list = new ArrayList<>();  
     /**  
      * Binding that List to Adapter  
      */  
     adapter = new MyArrayAdapter(this, list);  
   
     /**  
      * Getting List and Setting List Adapter  
      */  
     listView = (ListView) findViewById(R.id.listView);  
     listView.setAdapter(adapter);  
     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {  
       @Override  
       public void onItemClick(AdapterView<?> parent, View view, int position, long id) {  
         Snackbar.make(findViewById(R.id.parentLayout), list.get(position).getName() + " => " + list.get(position).getPhone(), Snackbar.LENGTH_LONG).show();  
       }  
     });  
   
     /**  
      * Just to know onClick and Printing Hello Toast in Center.  
      */  
     Toast toast = Toast.makeText(getApplicationContext(), "Click on FloatingActionButton to Load JSON", Toast.LENGTH_LONG);  
     toast.setGravity(Gravity.CENTER, 0, 0);  
     toast.show();  
   
     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);  
     fab.setOnClickListener(new View.OnClickListener() {  
       @Override  
       public void onClick(@NonNull View view) {  
   
         /**  
          * Checking Internet Connection  
          */  
         if (InternetConnection.checkConnection(getApplicationContext())) {  
           new GetDataTask().execute();  
         } else {  
           Snackbar.make(view, "Internet Connection Not Available", Snackbar.LENGTH_LONG).show();  
         }  
       }  
     });  
   }  
   
   /**  
    * Creating Get Data Task for Getting Data From Web  
    */  
   class GetDataTask extends AsyncTask<Void, Void, Void> {  
   
     ProgressDialog dialog;  
   
     @Override  
     protected void onPreExecute() {  
       super.onPreExecute();  
       /**  
        * Progress Dialog for User Interaction  
        */  
       dialog = new ProgressDialog(MainActivity.this);  
       dialog.setTitle("Hey Wait Please...");  
       dialog.setMessage("I am getting your JSON");  
       dialog.show();  
     }  
   
     @Nullable  
     @Override  
     protected Void doInBackground(Void... params) {  
   
       /**  
        * Getting JSON Object from Web Using okHttp  
        */  
       JSONObject jsonObject = JSONParser.getDataFromWeb();  
   
       try {  
         /**  
          * Check Whether Its NULL???  
          */  
         if (jsonObject != null) {  
           /**  
            * Check Length...  
            */  
           if(jsonObject.length() > 0) {  
             /**  
              * Getting Array named "contacts" From MAIN Json Object  
              */  
             JSONArray array = jsonObject.getJSONArray(Keys.KEY_CONTACTS);  
   
             /**  
              * Check Length of Array...  
              */  
             int lenArray = array.length();  
             if(lenArray > 0) {  
               for(int jIndex = 0; jIndex < lenArray; jIndex++) {  
   
                 /**  
                  * Creating Every time New Object  
                  * and  
                  * Adding into List  
                  */  
                 MyDataModel model = new MyDataModel();  
   
                 /**  
                  * Getting Inner Object from contacts array...  
                  * and  
                  * From that We will get Name of that Contact  
                  *  
                  */  
                 JSONObject innerObject = array.getJSONObject(jIndex);  
                 String name = innerObject.getString(Keys.KEY_NAME);  
                 String email = innerObject.getString(Keys.KEY_EMAIL);  
                 String image = innerObject.getString(Keys.KEY_PROFILE_PIC);  
   
                 /**  
                  * Getting Object from Object "phone"  
                  */  
                 JSONObject phoneObject = innerObject.getJSONObject(Keys.KEY_PHONE);  
                 String phone = phoneObject.getString(Keys.KEY_MOBILE);  
   
                 model.setName(name);  
                 model.setEmail(email);  
                 model.setPhone(phone);  
                 model.setImage(image);  
   
                 /**  
                  * Adding name and phone concatenation in List...  
                  */  
                 list.add(model);  
               }  
             }  
           }  
         } else {  
   
         }  
       } catch (JSONException je) {  
         Log.i(JSONParser.TAG, "" + je.getLocalizedMessage());  
       }  
       return null;  
     }  
   
     @Override  
     protected void onPostExecute(Void aVoid) {  
       super.onPostExecute(aVoid);  
       dialog.dismiss();  
       /**  
        * Checking if List size if more than zero then  
        * Update ListView  
        */  
       if(list.size() > 0) {  
         adapter.notifyDataSetChanged();  
       } else {  
         Snackbar.make(findViewById(R.id.parentLayout), "No Data Found", Snackbar.LENGTH_LONG).show();  
       }  
     }  
   }  
 }  


Output:




YOU CAN VISIT FOR WHOLE CODE: 

JSONParsingUsingOkHTTP on GitHub

#KeepSharing #KeepLearning #KeepReviewing :)

Thank you.


13 December, 2015

Android JSON Parsing Using okHttp Example with New Material Design Library

Hello to everyone, Today I am posting about JSON Parsing in Android using okHttp Library.

HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP efficiently makes your stuff load faster and saves bandwidth.

I found many documentation to understand okHttp but I want to share my example which i have created as Demo.

Prerequisites: 

1. What is JSON?
2. Android Studio Basics

Example:

Create New Project in Android Studio android follow the instructions.

Permissions in AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />


Add following gradle dependency in build.gradle:

compile 'com.android.support:appcompat-v7:23.1.0'  
compile 'com.android.support:design:23.1.0'  
compile 'com.squareup.okhttp:okhttp:2.0.0'  

JSON Parser File (Copy Class and Paste in Your src Folder):


 /**  
  * @author Pratik Butani  
  */  
 public class JSONParser {  
   /********  
    * URLS  
    *******/  
   private static final String MAIN_URL = "http://pratikbutani.x10.mx/json_data.json";  
   /**  
    * TAGs Defined Here...  
    */  
   public static final String TAG = "TAG";  
   /**  
    * Key to Send  
    */  
   private static final String KEY_USER_ID = "user_id";  
   /**  
    * Response  
    */  
   private static Response response;  
   /**  
    * Get Table Booking Charge  
    *  
    * @return JSON Object  
    */  
   public static JSONObject getDataFromWeb() {  
     try {  
       OkHttpClient client = new OkHttpClient();  
       Request request = new Request.Builder()  
           .url(MAIN_URL)  
           .build();  
       response = client.newCall(request).execute();  
       return new JSONObject(response.body().string());  
     } catch (@NonNull IOException | JSONException e) {  
       Log.e(TAG, "" + e.getLocalizedMessage());  
     }  
     return null;  
   }  
 }  

Layout File: activity_main.xml


<android.support.design.widget.CoordinatorLayout 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:id="@+id/parentLayout"  
   android:layout_height="match_parent"  
   android:fitsSystemWindows="true"  
   tools:context=".MainActivity">  
   
   <android.support.design.widget.AppBarLayout  
     android:layout_width="match_parent"  
     android:layout_height="wrap_content"  
     android:theme="@style/AppTheme.AppBarOverlay">  
   
     <android.support.v7.widget.Toolbar  
       android:id="@+id/toolbar"  
       android:layout_width="match_parent"  
       android:layout_height="?attr/actionBarSize"  
       android:background="?attr/colorPrimary"  
       app:popupTheme="@style/AppTheme.PopupOverlay" />  
   
   </android.support.design.widget.AppBarLayout>  
   
   <ListView app:layout_behavior="@string/appbar_scrolling_view_behavior"  
     android:id="@+id/listView"  
     android:layout_width="fill_parent"  
     android:layout_height="match_parent" />  
   
   <android.support.design.widget.FloatingActionButton  
     android:id="@+id/fab"  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:layout_gravity="bottom|end"  
     android:layout_margin="@dimen/fab_margin"  
     android:src="@android:drawable/stat_sys_download" />  
   
 </android.support.design.widget.CoordinatorLayout>  

MainActivity.java

 public class MainActivity extends AppCompatActivity {  
   
   private ListView listView;  
   private ArrayList<String> list;  
   private ArrayAdapter<String> adapter;  
   
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_main);  
   
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);  
     setSupportActionBar(toolbar);  
   
     /**  
      * Array List for Binding Data from JSON to this List  
      */  
     list = new ArrayList<>();  
     /**  
      * Binding that List to Adapter  
      */  
     adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, android.R.id.text1, list);  
   
     /**  
      * Getting List and Setting List Adapter  
      */  
     listView = (ListView) findViewById(R.id.listView);  
     listView.setAdapter(adapter);  
     listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {  
       @Override  
       public void onItemClick(AdapterView<?> parent, View view, int position, long id) {  
         Snackbar.make(findViewById(R.id.parentLayout), list.get(position), Snackbar.LENGTH_LONG).show();  
       }  
     });  
   
   
     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);  
     fab.setOnClickListener(new View.OnClickListener() {  
       @Override  
       public void onClick(@NonNull View view) {  
   
         /**  
          * Just to know onClick and Printing Hello Toast in Center.  
          */  
         Toast toast = Toast.makeText(getApplicationContext(), "Hello in Center", Toast.LENGTH_LONG);  
         toast.setGravity(Gravity.CENTER,0,0);  
         toast.show();  
   
         /**  
          * Checking Internet Connection  
          */  
         if (InternetConnection.checkConnection(getApplicationContext())) {  
           new GetDataTask().execute();  
         } else {  
           Snackbar.make(view, "Internet Connection Not Available", Snackbar.LENGTH_LONG).show();  
         }  
       }  
     });  
   }  
   
   /**  
    * Creating Get Data Task for Getting Data From Web  
    */  
   class GetDataTask extends AsyncTask<Void, Void, Void> {  
   
     ProgressDialog dialog;  
   
     @Override  
     protected void onPreExecute() {  
       super.onPreExecute();  
       /**  
        * Progress Dialog for User Interaction  
        */  
       dialog = new ProgressDialog(MainActivity.this);  
       dialog.setTitle("Hey Wait Please...");  
       dialog.setMessage("I am getting your JSON");  
       dialog.show();  
     }  
   
     @Nullable  
     @Override  
     protected Void doInBackground(Void... params) {  
   
       /**  
        * Getting JSON Object from Web Using okHttp  
        */  
       JSONObject jsonObject = JSONParser.getDataFromWeb();  
   
       try {  
         /**  
          * Check Whether Its NULL???  
          */  
         if (jsonObject != null) {  
           /**  
            * Check Length...  
            */  
           if(jsonObject.length() > 0) {  
             /**  
              * Getting Array named "contacts" From MAIN Json Object  
              */  
             JSONArray array = jsonObject.getJSONArray(Keys.KEY_CONTACTS);  
   
             /**  
              * Check Length of Array...  
              */  
             int lenArray = array.length();  
             if(lenArray > 0) {  
               for(int jIndex = 0; jIndex < lenArray; jIndex++) {  
                 /**  
                  * Getting Inner Object from contacts array...  
                  * and  
                  * From that We will get Name of that Contact  
                  *  
                  */  
                 JSONObject innerObject = array.getJSONObject(jIndex);  
                 String name = innerObject.getString(Keys.KEY_NAME);  
   
                 /**  
                  * Getting Object from Object "phone"  
                  */  
                 JSONObject phoneObject = innerObject.getJSONObject(Keys.KEY_PHONE);  
                 String phone = phoneObject.getString(Keys.KEY_MOBILE);  
   
                 /**  
                  * Adding name and phone concatenation in List...  
                  */  
                 list.add(name + " - " + phone);  
               }  
             }  
           }  
         } else {  
   
         }  
       } catch (JSONException je) {  
         Log.i(JSONParser.TAG, "" + je.getLocalizedMessage());  
       }  
       return null;  
     }  
   
     @Override  
     protected void onPostExecute(Void aVoid) {  
       super.onPostExecute(aVoid);  
       dialog.dismiss();  
       /**  
        * Checking if List size if more than zero then  
        * Update ListView  
        */  
       if(list.size() > 0) {  
         adapter.notifyDataSetChanged();  
       } else {  
         Snackbar.make(findViewById(R.id.parentLayout), "No Data Found", Snackbar.LENGTH_LONG).show();  
       }  
     }  
   }  
 }  

Output:

Download Demo from GitHub: JSON Parsing using okHttp

Hope You will enjoy with Android JSON Parsing with okHttp and basic of Android Design Library.

Any question, Any query, Any suggestion Always Welcome. Do comment.

Thank you.

11 September, 2015

Paryushan Parv - Janism

આત્મીય સ્નેહીજનો, પ્રણામ, જય જિનેન્દ્ર ,

આપ સહુ શાતામા હશો. સઘળું આનંદ મંગળ હશે. કદાચ સ્નેહીજનો શબ્દ પરીવાર માટે વાપરવામાં આવે છે, પરંતુ પરમાત્મ ભક્તિ દ્વારા બંધાયેલ આપણો આ સંબંધ એક પરિવારજન સમાન જ છે.

જોત-જોતામાં પર્યુષણ મહાપર્વ પણ આવી ગયા..!

સર્વજીવો સાથેની મૈત્રી નો કરાર કરવાનો ઉત્તમ અવસર એટલે જ પર્યુષણ..!

કર્મોના ભાર થી દબાયેલાં આત્માને પુણ્યથી ઉગારી લેવાનો અવસર એટલે જ પર્યુષણ..!

ને તમારા ને અમારા આ આત્મીય સંબંધોને સંવત્સરી મિચ્છામી દુક્કડમ્ થી શણગારવાનો અવસર એટલે જ પર્યુષણ..!




ભવિષ્યમાં આવનારા પ્રભુ-ભક્તિ, ગુરુ-ભક્તિ અને જિન-શાસન શોભા વૃદ્ધિના અવસરો એ ફરી ફરી ને આપણું મિલન થતું રહે એજ અભ્યર્થના સહ..

સંવત્સરી મિચ્છામી દુક્કડમ્..

18 August, 2015

MarshMallow : Android M is now #MarshMallow

Get your apps ready for Android Marshmallow:

The final Android 6.0 SDK is now available to download via the SDK Manager in Android Studio. With the Android 6.0 SDK you have access to the final Android APIs and the latest build tools so that you can target API 23. Once you have downloaded the Android 6.0 SDK into Android Studio, update your app project compileSdkVersion to 23 and you are ready to test your app with the new platform. You can also update your app to targetSdkVersion to 23 test out API 23 specific features like auto-backup and app permissions.

Along with the Android 6.0 SDK, we also updated the Android Support Library to v23. The new Android Support library makes it easier to integrate many of the new platform APIs, such as permissions and fingerprint support, in a backwards-compatible manner. This release contains a number of new support libraries including: customtabs, percent, recommendation, preference-v7, preference-v14, and preference-leanback-v17.

Check your App Permissions:

Along with the new platform features like fingerprint support and Doze power saving mode, Android Marshmallow features anew permissions model that streamlines the app install and update process. To give users this flexibility and to make sure your app behaves as expected when an Android Marshmallow user disables a specific permission, it’s important that you update your app to target API 23, and test the app thoroughly with Android Marshmallow users.

How to Get the Update:

The Android emulator system images and developer preview system images have been updated for supported Nexus devices (Nexus 5, Nexus 6, Nexus 9 & Nexus Player) to help with your testing. You can download the device system images from the developer preview site. Also, similar to the previous developer update, supported Nexus devices will receive an Over-the-Air (OTA) update over the next couple days.

Although the Android 6.0 SDK is final, the devices system images are still developer preview versions. The preview images are near final but they are not intended for consumer use. Remember that when Android 6.0 Marshmallow launches to the public later this fall, you'll need to manually re-flash your device to a factory image to continue to receive consumer OTA updates for your Nexus device.

What is New

Compared to the previous developer preview update, you will find this final API update fairly incremental. You can check out all the API differences here, but a few of the changes since the last developer update include:
  • Android Platform Change:
    • Final Permissions User Interface — we updated the permissions user interface and enhanced some of the permissions behavior.
  • API Change:
    • Updates to the Fingerprint API — which enables better error reporting, better fingerprint enrollment experience, plus enumeration support for greater reliability.

Upload your Android Marshmallow apps to Google Play:

Google Play is now ready to accept your API 23 apps via the Google Play Developer Console on all release channels (Alpha, Beta & Production). At the consumer launch this fall, the Google Play store will also be updated so that the app install and update process supports the new permissions model for apps using API 23.

To make sure that your updated app runs well on Android Marshmallow and older versions, we recommend that you use Google Play’s newly improved beta testing feature to get early feedback, then do a staged rollout as you release the new version to all users.

01 August, 2015

Best Useful Links for Laravelers

Hello to all Laravelers,

Hope you are doing well with Laravel and Playing with Errors :)

I am basically Android Application Developer and Love to Stackoverflowing. I just found following links by My Research while learning Laravel. It will may useful to you also.

Communities:

People to Follow:

PHP PaaS(Platform as a Service) Providers:



Laravel Chat:

#Laravel #Links #LaravelTutorials

Thank you..

14 July, 2015

How to debug Angular JavaScript Code

1. Chrome:

For Debug AngularJS in chrome you can use AngularJS Batarang. (From recent reviews on the plugin it seems like AngularJS Batarang is no longer being maintained. Tested in various versions of chrome does not work)

Here is the Link for description and Demo:


Introduction of Angular JS Batarang

Download chrome plugin from here: Chrome plugin for debug AngularJS

You can also refer this link: ng-book: Debugging AngularJS

2. Firefox:

For Firefox with the help of Firebug you can debug the code.

Also use this Firefox Add-Ons : AngScope: Add-ons for Firefox (Not official extension by AngularJS Team)


3. Debugging AngularJS:

Check the Link : Debugging AngularJS


Reference: http://stackoverflow.com/a/18782130/1318946

02 July, 2015

Google Drive : Create, Share and manage Custom Maps

Hey Howdy, Now Share your Custom Maps Whether you're planning your cricket schedule, learning about new things, or mapping your favorite places, Google My Maps makes it easy to put your world on a custom map.

As i saw post while googling, I just want to share it with you that you can access My Maps right from Google Drive on your Google Apps account, so it’s even easier to create, find and share your custom maps. 

Here are some examples: 




In the following image i am pointing out My Home Place and My Work Place. You can also see Route of both place. 


Whatever your needs, Google My Maps—now accessible in Google Drive—makes teaching, learning, and getting things done that much easier.

Special Thanks to Google for Education.

30 June, 2015

Android Multiple Selection Spinner Item with Filtration

I have recently posted problem on stackoverflow but didn't get response what i want, stuck with that problem for 2 days continuously and got the solution.

I just want to share it with all #androiders so they can take it easily.

I have created Git Repository MultiSelectSpinner so you can directly download demo of Multi Selection Spinner with Search Functionality and without Search Functionality.

Download Demo from HERE:

Demo of MultiSelectSpinner
MultiSelectSpinner without Search

MultiSelectSpinner with Search

















































































































Thank you :) Keep Sharing :)

29 June, 2015

Android Basics Tutorial, PPT, Demos : Workshop at OM VVIM - Morbi

I would like to share my experience of Android Expert Lecture at OM VVIM college - Morbi. First of all I am thankful of Respected Staff Members Especially Hardik Sir. It was very excellent Experience in My Life as a Teacher.
Lets talk  about what we have taken in Lecture:

Key Notes:

  1. What is Android?
  2. Why Android?
  3. Features of Android
  4. History of Android
  5. Android Architecture
  6. Android Application Components
  7. Creating First Android App
  8. Anatomy of Android Application
  9. Accessing Resources in Java
  10. Accessing Resources in XML
  11. Activity Life Cycle
  12. Service Life Cycle
  13. Intents
You can find here attached Android PPT File and some demos which we had learn in 
 our Workshop.


You can visit Java Robot Example :)

Please give me your valuable FEEDBACK.


10 June, 2015

Laravel 5.1 is Released

Laravel has just announced the immediate availability of v5.1. This marks the first release in Laravel’s history to offer long-time support. Let’s look at some of the new features and also learn more about it.

Long Term Support

Since originally launching in 2011, Laravel has always followed the "release early, release often" mantra which is popular in open source applications. With the historic rise in popularity of the framework, it was time to start focusing on the needs of large organizations and mission-critical applications that need security fixes but can’t upgrade quickly. Laravel 5.1 will now include 3 years of security fixes.
The long-term support is arguably the biggest feature in 5.1, but it includes several other new features.

Commands

The second big change is the “Commands” folder is being renamed to “Jobs” to indicate it’s primarily for queued jobs. This folder change will not be a backwards compatibility break.

New Documentation

The documentation has been completely reworked to offer more clarity, to be more in-depth, and to have a nicer flow. This was a huge undertaking and countless hours was spent fine-tuning each page.

Taylor said he would delay an entire Laravel release rather than release something with poor documentation, when asked if spending this much time on it was worth it. Another new documentation feature is real-time search with auto-complete.





PSR-2

The app and generators are converting to PSR-2. If you are not familiar with PSR-2, it’s a Coding Style Guide. The biggest change from current Laravel style is tabs to spaces and control structures will now go on the same line.

Resolve a service from blade

You can now resolve a service directly from a Blade Template:

extends('layouts.app')inject('stats','StatisticsService')

<div>{{$stats->getCustomerCount()}}</div>


Envoy runs local SSH scripts

Finally, and this is available now, Envoy allows you to run local scripts without SSH. See this pull request for more details. To get the latest version just run:

global

Middleware Parameters

This new feature allows you to pass parameters into the middleware. Here is a screenshot of a demo:




Broadcasting Events

Laravel already included a powerful event system and this new feature builds on that by allowing you to broadcast events over a websocket so your client can consume them. With this new feature, it makes creating real-time applications simple.

Better Application Unit Testing

With an inclusion of Laracasts integrated testing package testing your application is going to be easier than ever before.


public function testNewUserRegistration(){

$this->visit('/register')->type('Taylor','name')->check('terms')->press('Register')->seePageIs('/dashboard');

}

CSRF Except

In Laravel 5.0 all requests are ran through the CSRF middleware and this is great for most use cases. However, one gotcha is using services with web hooks where you do not have the ability to set a token. A new feature in 5.1 is an except property on the VerifyCsrfToken class which will allow this to be easily over-ridden.

protected$except=['webhook/*'];


Where to go next

Head over to the new official documentation which includes everything you need to know about installation, upgrading, and all the framework features.

#laravel #laravel5.1 #laravel_new_release