Monday, 25 September 2017

Web API library

Parser class

package parser;
import android.os.Parcel;import android.os.Parcelable;
import java.util.ArrayList;import java.util.List;
/** * Created by sphere65 on 8/6/17. */
public class GetMissingTags implements Parcelable {

    List<MissiongTagData> missing_tag;
    public List<MissiongTagData> getMissing_tag() {
        return missing_tag;    }

    public void setMissing_tag(List<MissiongTagData> missing_tag) {
        this.missing_tag = missing_tag;    }
    public GetMissingTags(){}
    protected GetMissingTags(Parcel in) {
        missing_tag = new ArrayList<MissiongTagData>();        in.readTypedList(missing_tag, MissiongTagData.CREATOR);    }

    public static final Creator<GetMissingTags> CREATOR = new Creator<GetMissingTags>() {
        @Override        public GetMissingTags createFromParcel(Parcel in) {
            return new GetMissingTags(in);        }

        @Override        public GetMissingTags[] newArray(int size) {
            return new GetMissingTags[size];        }
    };
    @Override    public int describeContents() {
        return 0;    }

    @Override    public void writeToParcel(Parcel parcel, int i) {
    }

    public static class MissiongTagData implements Parcelable {

        String tag_no = "";        String count="";
        public String getCount() {
            return count;        }

        public void setCount(String count) {
            this.count = count;        }

        public String getTag_no() {
            return tag_no;        }

        public void setTag_no(String tag_no) {
            this.tag_no = tag_no;        }

        public MissiongTagData(){}

        protected MissiongTagData(Parcel in) {
            tag_no = in.readString();        }

        public static final Creator<MissiongTagData> CREATOR = new Creator<MissiongTagData>() {
            @Override            public MissiongTagData createFromParcel(Parcel in) {
                return new MissiongTagData(in);            }

            @Override            public MissiongTagData[] newArray(int size) {
                return new MissiongTagData[size];            }
        };
        @Override        public int describeContents() {
            return 0;        }

        @Override        public void writeToParcel(Parcel parcel, int i) {
            parcel.writeString(tag_no);        }
    }
}

Web API Code

package com.srtpl.rkuhf;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import com.google.gson.Gson;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SingleClientConnManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import java.io.File;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import parser.GetMessage;
import parser.GetMissingTags;
import parser.GetTotalTags;
import parser.PostAllTags;

public class PostParseGet {

 public Activity mContext;
 public boolean isNetError = false;
 public boolean isOtherError = false;
 public boolean isDeviceToken = false;
 List < NameValuePair > nameValuePairs;
 Object mFillObject;
 public static String mStringresponse = "";
 public static ArrayList < String > mflist;
 ConnectivityManager mConnectivityManager;
 NetworkInfo mNetworkInfo;
 Gson mGson;
 public PostParseGet(Activity context) {
  mContext = context;
  mGson = new Gson();
  mflist = new ArrayList < String > ();
 }

 public PostParseGet(FragmentActivity context) {
  mContext = context;
  mGson = new Gson();
  mflist = new ArrayList < String > ();
 }


 public Object getmFillObject() {
  return mFillObject;
 }

 public void setmFillObject(Object mFillObject) {
  this.mFillObject = mFillObject;
 }

 public boolean isDeviceToken() {
  return isDeviceToken;
 }

 public void setDeviceToken(boolean isDeviceToken) {
  this.isDeviceToken = isDeviceToken;
 }

 public Object postHttpURLWithGetMethod(String url, List < NameValuePair > nameValuePairs, Object mObject) {
  HttpGet httpGet;
  HttpParams httpParameters;
  int timeoutConnection = 60000;
  HttpClient httpclient = null;
  HttpResponse response = null;
  String data = "";
  isOtherError = false;
  //url = url.replaceAll(" ", "%C2%A0");
  System.out.println("Url " + url);
  mFillObject = null;
  if (check_Internet()) {
   try {
    mFillObject = mObject.getClass().newInstance();
    URL urlToRequest = new URL(url);
    HttpURLConnection urlConnection = (HttpURLConnection) urlToRequest.openConnection();
    urlConnection.setDoOutput(true);
    //urlConnection.setRequestMethod("GET"); 
    //urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    httpGet = new HttpGet(url);
    /*httpGet.addHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");   
             httpGet.addHeader("X-Requested-With", "XMLHttpRequest");
            httpGet.addHeader("Mobile-Tokon", Staticvalues.mStringMobileToken);*/
    int code = urlConnection.getResponseCode();
    Log.d("CODE", String.valueOf(code));
    httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutConnection);
    httpclient = new DefaultHttpClient(httpParameters);
    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    if (nameValuePairs != null) {
     for (int index = 0; index < nameValuePairs.size(); index++) {
      String paramName = nameValuePairs.get(index).getName();
      String paramValue = nameValuePairs.get(index).getValue();
      System.out.println("paramName " + paramName);
      System.out.println("paramValue " + paramValue);

      if (paramName.equalsIgnoreCase("image")) {
       if (paramValue.length() > 0) {
        System.out.print("File Object found");
        entity.addPart(paramName, new FileBody(new File(paramValue)));
       }
      } else {
       entity.addPart(nameValuePairs.get(index).getName(), new StringBody(nameValuePairs.get(index).getValue()));
      }
     }
     /*httpGet.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));*/
    }

    response = httpclient.execute(httpGet);

    System.out.println("httppost " + httpGet.toString());
    data = EntityUtils.toString(response.getEntity());
    System.out.println("Final Data " + data);
    if (data.equalsIgnoreCase("{\"is_device_deleted\":true}"))
     setDeviceToken(true);
    mFillObject = mGson.fromJson(data, mFillObject.getClass());

   } catch (Exception e) {
    isOtherError = true;
   }

  }
  return mFillObject;
 }


 public Object postHttpURL(String url, List < NameValuePair > nameValuePairs, Object mObject) {
  HttpPost httppost;
  HttpParams httpParameters;
  int timeoutConnection = 60000;
  HttpClient httpclient = null;
  HttpResponse response = null;
  String data = "";
  isOtherError = false;
  System.out.println("Url " + url);
  mFillObject = null;
  if (check_Internet()) {
   try {
    mFillObject = mObject.getClass().newInstance();
    HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
    DefaultHttpClient client = new DefaultHttpClient();
    SchemeRegistry registry = new SchemeRegistry();
    SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
    socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
    registry.register(new Scheme("https", socketFactory, 443));
    SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
    DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());
    httppost = new HttpPost(url);
    httpParameters = new BasicHttpParams(); 

    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    System.out.println("nameValuePairs " + nameValuePairs.size());
    if (nameValuePairs != null) {
     for (int index = 0; index < nameValuePairs.size(); index++) {
      String paramName = nameValuePairs.get(index).getName();
      String paramValue = nameValuePairs.get(index).getValue();
      System.out.println("paramName " + paramName);
      System.out.println("paramValue " + paramValue);
      if (paramName.equalsIgnoreCase("file") || paramName.equalsIgnoreCase("profile_image")) {
       Log.d("Profile", "Profiel");
       if (paramValue.length() > 0) {

        entity.addPart(paramName, new FileBody(new File(paramValue)));
        Log.d("Profile value", "Profiel valu");
       }
      } else {
       //                   mflist.clear();                         
       entity.addPart(nameValuePairs.get(index).getName(), new StringBody(nameValuePairs.get(index).getValue()));
      }
     }
     httppost.setEntity(entity);
    }


    response = httpclient.execute(httppost);
    System.out.println("httppost " + httppost.toString());
    data = EntityUtils.toString(response.getEntity());
    System.out.println("Final Data " + data);
    mStringresponse = data;
    if (data.equalsIgnoreCase("{\"is_device_deleted\":true}"))
     setDeviceToken(true);
    mFillObject = mGson.fromJson(data, mFillObject.getClass());

   } catch (Exception e) {

    isOtherError = true;
    e.printStackTrace();
   }
  }
  return mFillObject;
 }

 public Object postHttpURLWithHeaderGetMethod(String url, List < NameValuePair > nameValuePairs, Object mObject) {
  HttpGet httpGet;
  HttpParams httpParameters;
  int timeoutConnection = 60000;
  HttpClient httpclient = null;
  HttpResponse response = null;
  String data = "";
  isOtherError = false;
  //url = url.replaceAll(" ", "%C2%A0");        System.out.println("Url " + url);        mFillObject = null;
  if (check_Internet()) {
   try {
    mFillObject = mObject.getClass().newInstance();
    URL urlToRequest = new URL(url);
    HttpURLConnection urlConnection = (HttpURLConnection) urlToRequest.openConnection();
    urlConnection.setDoOutput(true); //urlConnection.setRequestMethod("GET");         
    //urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    httpGet = new HttpGet(url);
    httpGet.addHeader("Accept", "application/json");
    httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutConnection);
    httpclient = new DefaultHttpClient(httpParameters);
    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    if (nameValuePairs != null) {
     for (int index = 0; index < nameValuePairs.size(); index++) {
      String paramName = nameValuePairs.get(index).getName();
      String paramValue = nameValuePairs.get(index).getValue();
      System.out.println("paramName " + paramName);
      System.out.println("paramValue " + paramValue);

      if (paramName.equalsIgnoreCase("image")) {
       if (paramValue.length() > 0) {
        System.out.print("File Object found");
        entity.addPart(paramName, new FileBody(new File(paramValue)));
       }
      } else {
       entity.addPart(nameValuePairs.get(index).getName(), new StringBody(nameValuePairs.get(index).getValue()));
      }
     }
     /*httpGet.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));*/
    }

    response = httpclient.execute(httpGet);
    data = EntityUtils.toString(response.getEntity());
    System.out.println("Final Data " + data);
    Log.e("JSON", data);
    mStringresponse = data;
    if (data.equalsIgnoreCase("{\"is_device_deleted\":true}"))
     setDeviceToken(true);
    mFillObject = mGson.fromJson(data, mFillObject.getClass());

   } catch (Exception e) {
    isOtherError = true;
   }
  }
  return mFillObject;
 }

 public Object postHttpURLWithHeaderPostMethod(String url, List < NameValuePair > nameValuePairs, Object mObject) {
  HttpPost httppost;
  HttpParams httpParameters;
  int timeoutConnection = 60000;
  HttpClient httpclient = null;
  HttpResponse response = null;
  String data = "";
  isOtherError = false;
  System.out.println("Url " + url);
  mFillObject = null;
  if (check_Internet()) {
   try {
    mFillObject = mObject.getClass().newInstance();
    URL urlToRequest = new URL(url);
    HttpURLConnection urlConnection = (HttpURLConnection) urlToRequest.openConnection();
    urlConnection.setDoOutput(true);
    httppost = new HttpPost(url); 

    httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
    HttpConnectionParams.setSoTimeout(httpParameters, timeoutConnection);
    httpclient = new DefaultHttpClient(httpParameters);

    MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    if (nameValuePairs != null) {
     for (int index = 0; index < nameValuePairs.size(); index++) {
      String paramName = nameValuePairs.get(index).getName();
      String paramValue = nameValuePairs.get(index).getValue();
      System.out.println("paramName " + paramName);
      System.out.println("paramValue " + paramValue);

      if (paramName.equalsIgnoreCase("image")) {
       if (paramValue.length() > 0) {
        System.out.print("File Object found");
        entity.addPart(paramName, new FileBody(new File(paramValue)));
       }
      } else {
       entity.addPart(nameValuePairs.get(index).getName(), new StringBody(nameValuePairs.get(index).getValue()));
      }
     }
     httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
    }

    System.out.println("Final Data " + data);
    mStringresponse = data;
    if (data.equalsIgnoreCase("{\"is_device_deleted\":true}"))
     setDeviceToken(true);
    mFillObject = mGson.fromJson(data, mFillObject.getClass());

   } catch (Exception e) {
    isOtherError = true;
   }
  }
  return mFillObject;
 }


 public boolean check_Internet() {
  mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
  mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
  if (mNetworkInfo != null && mNetworkInfo.isConnectedOrConnecting()) {
   isNetError = false;
   return true;
  } else {
   isNetError = true;
   return false;
  }
 }


 public Object postHttpURLWithHeaderFileUpload(String url, List < NameValuePair > nameValuePairs, Object mObject) {
  HttpPost httppost;
  HttpParams httpParameters;
  int timeoutConnection = 60000;
  HttpClient httpclient = null;
  HttpResponse response = null;
  String data = "";
  isOtherError = false;
  System.out.println("Url " + url);
  String boundary = "-------------" + System.currentTimeMillis();
  mFillObject = null;
  if (check_Internet()) {
   try {
    mFillObject = mObject.getClass().newInstance();
    URL urlToRequest = new URL(url);
    HttpURLConnection urlConnection = (HttpURLConnection) urlToRequest.openConnection();
    urlConnection.setDoOutput(true);
    urlConnection.setDoInput(true);
    urlConnection.setUseCaches(false);
    urlConnection.setRequestMethod("POST");
    System.out.print("boundary " + boundary);
    httppost = new HttpPost(url);
    if (paramName.equalsIgnoreCase("image") ||
    paramName.equalsIgnoreCase("file_path") ||
    paramName.equalsIgnoreCase("uploaded_path")
    ||
    paramName.equalsIgnoreCase("items[0][uploaded_path]"))
    {

     if (paramValue.length() > 0) {

      entity.addPart(paramName, new FileBody(new File(paramValue)));
      Log.d("File", "File Object found");
     }
    } else {
     entity.addPart(nameValuePairs.get(index).getName(), new StringBody(nameValuePairs.get(index).getValue()));
    }
   }
   httppost.setEntity(entity); // httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));                }


   System.out.println("httppost " + httppost.toString());
   data = EntityUtils.toString(response.getEntity());
   System.out.println("Final Data " + data);
   mStringresponse = data;
   if (data.equalsIgnoreCase("{\"is_device_deleted\":true}"))
    setDeviceToken(true);
   mFillObject = mGson.fromJson(data, mFillObject.getClass());

  } catch (Exception e) {
   isOtherError = true;
  }
 }
 return mFillObject;
}



public Object getTotalTags(GetTotalTags mGetFlag) {

 nameValuePairs = new ArrayList < NameValuePair > ();
 return postHttpURLWithHeaderGetMethod(AllUrl.url + "totaltag", nameValuePairs, mGetFlag);
}
public Object getMissingTags(GetMissingTags mGetFlag) {

 nameValuePairs = new ArrayList < NameValuePair > ();
 return postHttpURLWithHeaderGetMethod(AllUrl.url + "missingtag", nameValuePairs, mGetFlag);
}

public Object postAllTags(GetMessage mGetFlag, ArrayList < PostAllTags > list) {

 nameValuePairs = new ArrayList < NameValuePair > ();
 if (list != null && list.size() > 0) {
  for (int i = 0; i < list.size(); i++) {
   nameValuePairs.add(new BasicNameValuePair("label_creation_id[" + i + "]", list.get(i).getEpctag()));
  }
 }
 return postHttpURLWithHeaderPostMethod(AllUrl.url + "verifyTag", nameValuePairs, mGetFlag);
}

}

Monday, 19 June 2017

React Native Application run command

Make sure in your system node install than after do below process:

npm install -g react-native-cli


react-native init {project name}

cd {project name}

react-native run-android

Saturday, 17 June 2017

Install ATOM and run project in ionic through command line

npm install -g gulp
npm install -g cordova
npm install -g  ionic

Atom install

    sudo dpkg -i atom-amd64.deb
    sudo apt-get -f install


cd path of project

For create project run below command

ionic start {Project name} {template type}

for template type refer this link https://ionicframework.com/docs//intro/tutorial/

path of project : ionic serve OR npm run ionic:serve
path of project : ionic cordova run android

IF error occurs for gradle than fire below command in project path
path of project : sudo apt-get install gradle


If any config file change than run below command

cordova platform rm android

after it run below command

path of project : ionic cordova run android

 if fire this command ionic serve and get below error             
Error: Node Sass does not yet support your current environment: Linux 64-bit with Unsupported runtime (57)
For more information on which environments are supported please see:
https://github.com/sass/node-sass/releases/tag/v4.5.0

than remove node_modules folder from project and fire command like npm install

Monday, 22 May 2017

git command for branch merge and checkout ubuntu android

When child branch i m working
➜  demobranch git:(promotion) ✗ git add --all
➜  demobranch git:(promotion) ✗ git commit -m 'exxpan dable view with recyckview'
➜  demobranch git:(promotion) git pull origin promotion
➜  demobranch git:(promotion) git push origin promotion

if idea file error occur than
➜  demobranch git:(promotion) ✗ git add --all                                  
➜  demobranch git:(promotion) ✗ git commit -m 'idea file push'                
➜  demobranch git:(promotion) git pull origin promotion  
➜  demobranch git:(promotion) git push origin promotion

Checkout promotion to master
➜  demobranch git:(promotion) git checkout master
➜  demobranch git:(master) git pull origin master
➜  demobranch git:(master) git merge promotion
➜  demobranch git:(master) git push origin master