Example usage for com.google.gson GsonBuilder setDateFormat

List of usage examples for com.google.gson GsonBuilder setDateFormat

Introduction

In this page you can find the example usage for com.google.gson GsonBuilder setDateFormat.

Prototype

public GsonBuilder setDateFormat(int style) 

Source Link

Document

Configures Gson to to serialize Date objects according to the style value provided.

Usage

From source file:com.googleapis.ajax.services.impl.BaseGoogleSearchApiQuery.java

License:Apache License

/**
 * Gets the gson builder./* ww w.j  a  v a  2 s. c o  m*/
 * 
 * @return the gson builder
 */
protected GsonBuilder getGsonBuilder() {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat(ApplicationConstants.RFC822DATEFORMAT);
    builder.registerTypeAdapter(ListingType.class, new JsonDeserializer<ListingType>() {

        @Override
        public ListingType deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return ListingType.fromValue(arg0.getAsString());
        }

    });
    builder.registerTypeAdapter(PatentStatus.class, new JsonDeserializer<PatentStatus>() {

        @Override
        public PatentStatus deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return PatentStatus.fromValue(arg0.getAsString());
        }

    });
    builder.registerTypeAdapter(VideoType.class, new JsonDeserializer<VideoType>() {

        @Override
        public VideoType deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return VideoType.fromValue(arg0.getAsString());
        }

    });
    builder.registerTypeAdapter(ViewPortMode.class, new JsonDeserializer<ViewPortMode>() {

        @Override
        public ViewPortMode deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return ViewPortMode.fromValue(arg0.getAsString());
        }

    });
    builder.registerTypeAdapter(GsearchResultClass.class, new JsonDeserializer<GsearchResultClass>() {

        @Override
        public GsearchResultClass deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return GsearchResultClass.fromValue(arg0.getAsString());
        }

    });
    builder.registerTypeAdapter(PhoneNumberType.class, new JsonDeserializer<PhoneNumberType>() {

        @Override
        public PhoneNumberType deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return PhoneNumberType.fromValue(arg0.getAsString());
        }

    });
    builder.registerTypeAdapter(Language.class, new JsonDeserializer<Language>() {

        @Override
        public Language deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return Language.fromValue(arg0.getAsString());
        }
    });

    return builder;
}

From source file:com.googleapis.maps.services.impl.BaseGoogleMapsApiQuery.java

License:Apache License

/**
 * Gets the gson builder.//from  w  ww .j  av  a2s . c  om
 * 
 * @return the gson builder
 */
protected GsonBuilder getGsonBuilder() {
    GsonBuilder builder = new GsonBuilder();
    builder.setDateFormat(ApplicationConstants.RFC822DATEFORMAT);
    builder.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES);
    builder.registerTypeAdapter(LocationType.class, new JsonDeserializer<LocationType>() {
        @Override
        public LocationType deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return LocationType.fromValue(arg0.getAsString());
        }
    });
    builder.registerTypeAdapter(AddressComponentType.class, new JsonDeserializer<AddressComponentType>() {
        @Override
        public AddressComponentType deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2)
                throws JsonParseException {
            return AddressComponentType.fromValue(arg0.getAsString());
        }
    });
    //      builder.registerTypeAdapter(TravelMode.class, new JsonDeserializer<TravelMode>() {
    //         @Override
    //         public TravelMode deserialize(JsonElement arg0, Type arg1,
    //               JsonDeserializationContext arg2) throws JsonParseException {
    //            return TravelMode.fromValue(arg0.getAsString());
    //         }
    //      });

    return builder;
}

From source file:com.goplace.service.generic.implementation.ViewServiceGenImpl.java

License:Open Source License

@Override
public String get(Integer id) throws Exception {
    String data = null;/*from  ww w.  j a  v  a  2 s .c  o  m*/
    try {
        oConnection.setAutoCommit(false);
        BeanGenImpl oGenericBean = (BeanGenImpl) Class
                .forName("com.goplace.bean.generic.specific.implementation." + strPojo + "BeanGenSpImpl")
                .newInstance();
        Constructor c = Class
                .forName("com.goplace.dao.generic.specific.implementation." + strPojo + "DaoGenSpImpl")
                .getConstructor(String.class, Connection.class);
        TableDaoGenImpl oGenericDao = (TableDaoGenImpl) c.newInstance(strObjectName, oConnection);
        oGenericBean.setId(id);
        oGenericBean = (BeanGenImpl) (BeanInterface) oGenericDao.get(oGenericBean,
                AppConfigurationHelper.getJsonDepth());
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy");
        Gson gson = gsonBuilder.excludeFieldsWithoutExposeAnnotation().create();
        data = gson.toJson(oGenericBean);
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":get ERROR: " + ex.getMessage()));
    } finally {
        oConnection.commit();
    }
    return data;
}

From source file:com.goplace.service.generic.implementation.ViewServiceGenImpl.java

License:Open Source License

@Override
public String getPage(int intRegsPerPag, int intPage, ArrayList<FilterBeanHelper> alFilter,
        HashMap<String, String> hmOrder) throws Exception {
    String data = null;/*from  w  ww  .  j a v a2s. c om*/
    try {
        oConnection.setAutoCommit(false);
        BeanGenImpl oGenericBean = (BeanGenImpl) Class
                .forName("com.goplace.bean.generic.specific.implementation." + strPojo + "BeanGenSpImpl")
                .newInstance();
        Constructor c = Class
                .forName("com.goplace.dao.generic.specific.implementation." + strPojo + "DaoGenSpImpl")
                .getConstructor(String.class, Connection.class);
        TableDaoGenImpl oGenericDao = (TableDaoGenImpl) c.newInstance(strObjectName, oConnection);
        List<BeanInterface> loGenericBean = oGenericDao.getPage(intRegsPerPag, intPage, alFilter, hmOrder);
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy");
        Gson gson = gsonBuilder.excludeFieldsWithoutExposeAnnotation().create();
        data = gson.toJson(loGenericBean);
        data = "{\"list\":" + data + "}";
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":getPage ERROR: " + ex.getMessage()));
    } finally {
        oConnection.commit();
    }
    return data;
}

From source file:com.goplace.service.generic.specific.implementation.ComentarioServiceGenSpImpl.java

License:Open Source License

@Override
public String get(Integer id) throws Exception {
    String data = null;//w  w w  .  j  a va  2s .c  om
    try {
        oConnection.setAutoCommit(false);
        ComentarioDaoGenSpImpl oComentarioDAO = new ComentarioDaoGenSpImpl(strObjectName, oConnection);
        ComentarioBeanGenSpImpl oComentario = new ComentarioBeanGenSpImpl(id);
        oComentario = oComentarioDAO.get(oComentario, AppConfigurationHelper.getJsonDepth());
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy HH:mm:ss");
        Gson gson = gsonBuilder.create();
        data = gson.toJson(oComentario);
        oConnection.commit();
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":get ERROR: " + ex.getMessage()));
    }
    return data;
}

From source file:com.goplace.service.generic.specific.implementation.ComentarioServiceGenSpImpl.java

License:Open Source License

public String getPageComentarios(int id_evento, int intRegsPerPag, int intPage,
        ArrayList<FilterBeanHelper> alFilter, HashMap<String, String> hmOrder) throws Exception {
    String data = null;/*w  w w. ja  va  2  s  .  c  o  m*/
    try {
        oConnection.setAutoCommit(false);
        ComentarioDaoGenSpImpl oComentarioDAO = new ComentarioDaoGenSpImpl(strObjectName, oConnection);
        List<ComentarioBeanGenSpImpl> oComentarios = oComentarioDAO.getPageComentarios(id_evento, intRegsPerPag,
                intPage, alFilter, hmOrder);
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy HH:mm:ss");
        Gson gson = gsonBuilder.create();
        data = gson.toJson(oComentarios);
        data = "{\"list\":" + data + "}";
        oConnection.commit();
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":getPage ERROR: " + ex.getMessage()));
    }
    return data;
}

From source file:com.goplace.service.generic.specific.implementation.PublicacionServiceGenSpImpl.java

License:Open Source License

@Override
public String get(Integer id) throws Exception {
    String data = null;//ww  w. j a  v  a 2 s.com
    try {
        oConnection.setAutoCommit(false);
        PublicacionDaoGenSpImpl oPublicacionDAO = new PublicacionDaoGenSpImpl(strObjectName, oConnection);
        PublicacionBeanGenSpImpl oPublicacion = new PublicacionBeanGenSpImpl(id);
        oPublicacion = oPublicacionDAO.get(oPublicacion, AppConfigurationHelper.getJsonDepth());
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy");
        Gson gson = gsonBuilder.create();
        data = gson.toJson(oPublicacion);
        oConnection.commit();
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":get ERROR: " + ex.getMessage()));
    }
    return data;
}

From source file:com.goplace.service.generic.specific.implementation.PublicacionServiceGenSpImpl.java

License:Open Source License

public String getPageEventos(int id_usuario, int intRegsPerPag, int intPage,
        ArrayList<FilterBeanHelper> alFilter, HashMap<String, String> hmOrder) throws Exception {
    String data = null;//from   w  w  w.  j av  a2 s.  c om
    try {
        oConnection.setAutoCommit(false);
        PublicacionDaoGenSpImpl oPublicacionDAO = new PublicacionDaoGenSpImpl(strObjectName, oConnection);
        List<PublicacionBeanGenSpImpl> oPublicacions = oPublicacionDAO.getPageEventos(id_usuario, intRegsPerPag,
                intPage, alFilter, hmOrder);
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.setDateFormat("dd/MM/yyyy HH:mm:ss");
        Gson gson = gsonBuilder.create();
        data = gson.toJson(oPublicacions);
        data = "{\"list\":" + data + "}";
        oConnection.commit();
    } catch (Exception ex) {
        oConnection.rollback();
        ExceptionBooster.boost(new Exception(this.getClass().getName() + ":getPage ERROR: " + ex.getMessage()));
    }
    return data;
}

From source file:com.gullakh.gullakhandroidapp.GoogleCardsMediaActivity.java

License:Apache License

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = getIntent();/*  www  . j  a v a2  s .c  o  m*/
    String data = intent.getStringExtra("data");
    bankid_cibil = intent.getStringExtra("bankid");

    if (bankid_cibil == null)//first time ..initialize only once
    {

        Log.d("bankname_cibil is null", "1");

    } else {
        /*if (savedInstanceState != null) {
        Log.d("savedInstanceState not null","1");
        high_cibil = savedInstanceState.getStringArrayList("cibil_high");
        Log.d("high_cibil in oncreate", String.valueOf(high_cibil));
        }*/
        if (((GlobalData) getApplication()).gethigh_cibil() != null) {
            high_cibil = ((GlobalData) getApplication()).gethigh_cibil();
            Log.d("high_cibil in oncreate", String.valueOf(high_cibil));

        }

        Log.d("bankname_cibil is not null", bankid_cibil);
        high_cibil.add(bankid_cibil);
        Log.d("bankname_cibil is in goog", String.valueOf(high_cibil));
    }

    //********************changing actionbar

    android.support.v7.app.ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowCustomEnabled(true);

    LayoutInflater inflator = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflator.inflate(R.layout.custom_actionbar_eachactivity, null);
    title = (TextView) v.findViewById(R.id.title);
    ImageView review = (ImageView) v.findViewById(R.id.edit);
    review.setVisibility(View.GONE);
    ImageView close = (ImageView) v.findViewById(R.id.close);
    close.setOnClickListener(this);

    actionBar.setCustomView(v);

    View v2 = getSupportActionBar().getCustomView();
    ViewGroup.LayoutParams lp = v2.getLayoutParams();
    lp.width = AbsListView.LayoutParams.MATCH_PARENT;
    v2.setLayoutParams(lp);
    //******************************************
    DataHandler dbobjectsess = new DataHandler(GoogleCardsMediaActivity.this);
    Cursor crsess = dbobjectsess.displayData("select * from session");
    if (crsess.moveToFirst()) {
        sessionid = crsess.getString(1);
        Log.e("sessionid-cartypes", sessionid);
    }
    age = ((GlobalData) getApplication()).getage();
    if (data.equals("searchgo")) {
        Log.e("flow test carloan", String.valueOf(0));
        loan_amtcalcutn("oncreate");
        Log.e("flow test loan cal done", String.valueOf(CustomListViewValuesArr.size()));

        setContentView(R.layout.list_display);

        //ListView listView = (ListView) findViewById(R.id.list_view);
        layout = (LinearLayout) findViewById(R.id.linear);
        linedit = (LinearLayout) findViewById(R.id.linedit);
        filter = (LinearLayout) findViewById(R.id.filter);
        //  lcomp = (LinearLayout) findViewById(R.id.lcomp);
        loan_amt = (TextView) findViewById(R.id.loan_amt);
        tenr_amt = (TextView) findViewById(R.id.tenr_amt);
        tten = (TextView) findViewById(R.id.tenure);
        TextView tloan_amt = (TextView) findViewById(R.id.tloan_amt);
        TextView tfilter = (TextView) findViewById(R.id.tfilter);

        /*loan_amt.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Light.ttf"));
        tloan_amt.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Light.ttf"));
        tfilter.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Light.ttf"));
        tenr_amt.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Light.ttf"));
        tten.setTypeface(Typeface.createFromAsset(this.getAssets(), "fonts/OpenSans-Light.ttf"));*/

        linedit.setOnClickListener(this);
        filter.setOnClickListener(this);
        // lcomp.setOnClickListener(this);
        // createListView();
        format = NumberFormat.getCurrencyInstance(new Locale("en", "in"));
        //nullpointer

        if (savedInstanceState != null) {
            Log.d("savedInstanceState not null", "1");
            loant = String.valueOf(format.format(new BigDecimal(savedInstanceState.getString("loan_amt"))));
            loant = loant.replaceAll("\\.00", "");
            loan = savedInstanceState.getString("loan_amt");

            globaltenure = savedInstanceState.getString("tenure");
            globalloan_type = savedInstanceState.getString("loan_type");
            globalsal = savedInstanceState.getString("net_sal");

        } else {
            loan = ((GlobalData) getApplication()).getloanamt();
            // Log.d("loan amt is", loan);

            globaltenure = ((GlobalData) getApplication()).getTenure();
            globalloan_type = ((GlobalData) getApplication()).getLoanType();

            globalsal = ((GlobalData) getApplication()).getnetsalary().toString();

        }
        if (loan != null) {
            loant = String.valueOf(format.format(new BigDecimal(loan)));
            loant = loant.replaceAll("\\.00", "");
            Log.d("loan amt is not null", loant);
            // loan = loan.replaceAll("Rs.", "");
        }
        loan_amt.setText("" + loant);

        filter.setOnClickListener(this);
        createListView();

        Spinner s1 = (Spinner) findViewById(R.id.spinner1);

        MyArrayAdapter ma = new MyArrayAdapter(this);
        s1.setAdapter(ma);

        s1.setPrompt("Sort By");

        // if(globalloan_type.equals("Home Loan") || globalloan_type.equals("Loan Against Property"))
        if (globalloan_type.equals("Home Loan")) {
            Log.d("its home or LAP -", globalloan_type);
            f_fixed = false;
            f_float = true;
        }
        //******get data from search
        //  setsearchdb();

        s1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                sortbyposition = position;
                Log.d("test position", String.valueOf(position));

                if (position != 0)
                    calculate();

                setadapter(CustomListViewValuesArr);
            }

            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

    } else if (data.equals("search")) {

        DataHandler dbobject = new DataHandler(GoogleCardsMediaActivity.this);
        Cursor crobj = dbobject.displayData("select * from userlogin");

        if (crobj.moveToFirst()) {
            Log.d("my search clicked", "2");
            setContentView(R.layout.seach_display);
            layout = (LinearLayout) findViewById(R.id.linear);

            setsearchdb();
            createListView();
            setsearchadapter(searchlistviewArry);

        } else {

            Toast.makeText(GoogleCardsMediaActivity.this, "Please login to view search details!!!",
                    Toast.LENGTH_LONG).show();
            title.setText("Search Result");
        }
    }

    /*Log.e("You are not logged in", String.valueOf(0));
        Intent intentsignin=new Intent(this,signinPrepage.class);
        startActivity(intentsignin);
        finish();*/

    if (data.equals("myapplicatn")) {

        DataHandler dbobject = new DataHandler(GoogleCardsMediaActivity.this);
        Cursor crobj = dbobject.displayData("select * from userlogin");
        title.setText("My Applications");
        if (crobj.moveToFirst()) {

            // DataHandler dh1 = new DataHandler(this);
            // Cursor cr = dh1.displayData("select * from mysearch");

            try {
                //    if (cr.moveToFirst()) {

                requestgetserver8 = new JSONServerGet(new AsyncResponse() {
                    @Override
                    public void processFinish(JSONObject output) {

                    }

                    public void processFinishString(String str_result, Dialog dg) {
                        GsonBuilder gsonBuilder = new GsonBuilder();
                        gsonBuilder.setDateFormat("M/d/yy hh:mm a");
                        Gson gson = gsonBuilder.create();
                        dgthis = dg;
                        JsonParser parser = new JsonParser();
                        JsonObject jsonObject = parser.parse(str_result).getAsJsonObject();
                        Log.d("checkloandetail", String.valueOf(jsonObject.get("result")));
                        JsonObject jsonObject1 = parser.parse(String.valueOf(jsonObject.get("result")))
                                .getAsJsonObject();
                        LoanReqForMyapp[] loanDeatils = gson.fromJson(jsonObject1.get("loanrequest"),
                                LoanReqForMyapp[].class);
                        //JsonArray jsonArr = jsonObject1.getAsJsonArray("loanrequest");
                        if (loanDeatils.length > 0) {
                            for (int i = 0; i < loanDeatils.length; i++) {
                                //JsonObject jsonObject2 = jsonArr.get(i).getAsJsonObject();
                                //LoanReqForMyapp loanDeatils = gson.fromJson(jsonObject2, LoanReqForMyapp.class);// LoanReqForMyapp[] loandetailsobj = gson.fromJson(jsonObject2, LoanReqForMyapp[].class);
                                if (loanDeatils[i] != null) {
                                    Log.d("here is data", loanDeatils[i].getLoan_amount());
                                    ListModel sched = new ListModel();
                                    sched.setapplno(loanDeatils[i].case_loan_number);//data is present in listmodel class variables,values are put inside listmodel class variables, accessed in CustHotel class put in list here
                                    sched.setappldate(loanDeatils[i].getCreatedtime());
                                    sched.setstatus(loanDeatils[i].getStage());
                                    sched.setLoancaseid(loanDeatils[i].getLoanrequestcaseid());
                                    sched.setContactid(String.valueOf(jsonObject1.get("contactid")));
                                    sched.setD0(loanDeatils[i].getD0());
                                    sched.setD1(loanDeatils[i].getD1());
                                    sched.setD2(loanDeatils[i].getD2());
                                    sched.setD3(loanDeatils[i].getD3());
                                    sched.setD4(loanDeatils[i].getD4());
                                    sched.setD5(loanDeatils[i].getD5());
                                    sched.setD6(loanDeatils[i].getD6());

                                    sched.setD7(loanDeatils[i].getD7());
                                    sched.setD8(loanDeatils[i].getD8());

                                    sched.setCompletedpercentage(loanDeatils[i].getCompletedpercentage());
                                    sched.setLoan_amount(loanDeatils[i].getLoan_amount());
                                    sched.setBank_name(loanDeatils[i].getPrimary_lender());
                                    sched.setLoan_type(loanDeatils[i].getLoantype());
                                    sched.setPlemi(loanDeatils[i].getPlemi());
                                    sched.setPlroi(loanDeatils[i].getPlroi());
                                    sched.setdoc_collect_by(loanDeatils[i].getdoc_collect_by());
                                    searchlistviewArry.add(sched);

                                }
                            }

                            setContentView(R.layout.seach_display);
                            layout = (LinearLayout) findViewById(R.id.linear);
                            createListView();
                            setapplicatnadapter(searchlistviewArry);

                        } else {
                            AlertDialog.Builder alertadd = new AlertDialog.Builder(
                                    GoogleCardsMediaActivity.this);
                            LayoutInflater factory = LayoutInflater.from(getApplicationContext());
                            final View view = factory.inflate(R.layout.applnotfound, null);
                            TextView name = (TextView) view.findViewById(R.id.nf);
                            name.setText("No Application Found");
                            alertadd.setView(view);
                            alertadd.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    Intent intent = new Intent(GoogleCardsMediaActivity.this,
                                            MainActivity.class);
                                    intent.setFlags(
                                            Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                    startActivity(intent);
                                    overridePendingTransition(R.transition.left, R.transition.right);
                                }
                            });
                            alertadd.show();
                        }
                        dgthis.dismiss();
                    }
                }, GoogleCardsMediaActivity.this, "wait");
                DataHandler dbobj = new DataHandler(GoogleCardsMediaActivity.this);
                Cursor cre = dbobj.displayData("select * from userlogin");
                String userid = "", contactid = "";
                if (cre != null) {
                    if (cre.moveToFirst()) {
                        userid = cre.getString(1);
                        contactid = cre.getString(2);
                        Log.d("userid myapp", userid);
                        Log.d("contactid myapp", contactid);
                        cre.close();
                        dbobject.close();
                    }

                }

                requestgetserver8.execute("token", "getloandetails", sessionid, contactid);

                //     }

            } catch (Exception e) {
                System.out.println("error3 " + e.toString());
                //   dh1.cr.close();
                //   dh1.db.close();
            } finally {

                //   dh1.cr.close();
                //   dh1.db.close();
            }

        } else {
            Toast.makeText(GoogleCardsMediaActivity.this, "Please login to view application details!!!",
                    Toast.LENGTH_LONG).show();
        }

    }

    //******
    //format

    df = new DecimalFormat("#,##,###");
    // df.setDecimalSeparatorAlwaysShown(true);

}

From source file:com.gullakh.gullakhandroidapp.GoogleCardsMediaActivity.java

License:Apache License

public void loan_amtcalcutn(final String param) {

    //phase -2/*from w ww  .  ja va2  s  . c o  m*/

    requestgetserver2 = new JSONServerGet(new AsyncResponse() {
        @Override
        public void processFinish(JSONObject output) {

        }

        public void processFinishString(String str_result, Dialog dg) {

            try {

                Log.e("processFinishString in image", String.valueOf(0));

                GsonBuilder gsonBuilder = new GsonBuilder();
                gsonBuilder.setDateFormat("M/d/yy hh:mm a");
                Gson gson = gsonBuilder.create();

                JSONObject jsonObject = new JSONObject(str_result);

                Log.e("Check result in servicecharge", String.valueOf(jsonObject));
                Log.e("Check result in servicecharge", String.valueOf(jsonObject.get("result")));

                JSONObject jsonObject2 = new JSONObject(String.valueOf(jsonObject.get("result")));

                procegn_fee_perc = jsonObject2.getString("percentage");
                Log.e("Check result in servicecharge percentage", procegn_fee_perc);

            } catch (Throwable t) {
                Log.e("My App", "Could not parse malformed JSON: ");
            }

        }
    }, GoogleCardsMediaActivity.this, "2");
    //*******

    requestgetserver2.execute("sessn", "servicecharge", sessionid);

    requestgetserver3 = new JSONServerGet(new AsyncResponse() {
        @Override
        public void processFinish(JSONObject output) {

        }

        public void processFinishString(String str_result, Dialog dg) {

            dgthis = dg;
            GsonBuilder gsonBuilder = new GsonBuilder();
            gsonBuilder.setDateFormat("M/d/yy hh:mm a");
            Gson gson = gsonBuilder.create();

            JsonParser parser = new JsonParser();

            if (parser.parse(str_result).getAsJsonObject() != null) {
                JsonObject jsonObject = parser.parse(str_result).getAsJsonObject();
                Log.e("Check final data here3", str_result);

                //****cibilscore

                int maxLogSize = 2000;
                for (int i = 0; i <= str_result.length() / maxLogSize; i++) {
                    int start = i * maxLogSize;
                    int end = (i + 1) * maxLogSize;
                    end = end > str_result.length() ? str_result.length() : end;
                    Log.v("CHECK111", str_result.substring(start, end));
                }

                /* if(bankid_cibil!=null) {
                JSONArray resultarry = new JSONArray();
                resultarry.put(parse(str_result));
                        
                try {
                   // Log.d("bankid_cibil is not null cibil", String.valueOf(resultarry.getJSONArray(0)));
                    Log.d("bankid_cibil is not null cibil", String.valueOf(resultarry.get(0)));
                        
                    RM_cobj = gson.fromJson(String.valueOf(resultarry.get(0)), RuleMaster[].class);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                 }
                 else {
                    RM_cobj = gson.fromJson(jsonObject.get("result"), RuleMaster[].class);
                 }*/

                RuleMaster[] RM_cobj = gson.fromJson(jsonObject.get("result"), RuleMaster[].class);
                ArrayList Arr_RMid = new ArrayList<String>();

                JSONArray jsonArray = new JSONArray();

                //***********high cibil

                //***********

                if (RM_cobj != null) {
                    for (int i = 0; i < RM_cobj.length; i++) {

                        JSONObject imgob = new JSONObject();
                        Log.e("json Sizeee in RM_cobj", String.valueOf(RM_cobj.length));
                        Log.e("RM_cobj is ", String.valueOf(RM_cobj[i]));

                        Arr_RMid.add(RM_cobj[i].getaccount_lender());

                        try {
                            imgob.put("recordid", RM_cobj[i].getaccount_lender());
                            imgob.put("title", "logo");
                            jsonArray.put(imgob);

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

                        Log.e("json Checkkk", String.valueOf(jsonArray));
                    }

                    if (bankid_cibil != null) {

                        for (int i2 = 0; i2 < high_cibil.size(); i2++) {

                            Arr_RMid.remove(high_cibil.get(i2));
                            Log.e("high_cibil.get(i2)", high_cibil.get(i2));

                            for (int i = 0; i < jsonArray.length(); i++) {
                                JSONObject actor = null;
                                try {
                                    actor = jsonArray.getJSONObject(i);
                                    String name = actor.getString("recordid");
                                    if (name.equals(high_cibil.get(i2))) {
                                        Log.e("jsonArray recordid", name);
                                        jsonArray.remove(i);
                                    }

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

                            }

                        }

                        Log.e("Arr_RMid", String.valueOf(Arr_RMid));
                    }

                    Log.e("json object value KK", String.valueOf(jsonArray));

                    cobj_RM = RM_cobj;
                    listidmaster = Arr_RMid.toString();
                    //Log.e("listid2", listid);
                    listidmaster = listidmaster.toString().replace("[", "").replace("]", "");

                    requestgetserver3img.execute("token", "accountimg", sessionid, jsonArray.toString());

                } else {
                    dispalert("");
                }
                //******************kk
            } else {
                dispalert("");
            }

        }

    }, GoogleCardsMediaActivity.this, "1");

    requestgetserver3.execute("sessn", "RuleDetails");

    requestgetserver3img = new JSONServerGet(new AsyncResponse() {
        @Override
        public void processFinish(JSONObject output) {

        }

        public void processFinishString(String str_result, Dialog dg) {

            try {

                Log.e("processFinishString in image", String.valueOf(0));

                GsonBuilder gsonBuilder = new GsonBuilder();
                gsonBuilder.setDateFormat("M/d/yy hh:mm a");
                Gson gson = gsonBuilder.create();

                JsonParser parser = new JsonParser();
                JsonObject jsonObject = parser.parse(str_result).getAsJsonObject();
                Log.e("Check result in image", str_result);

                BankImg[] BL_cobj = gson.fromJson(jsonObject.get("result"), BankImg[].class);
                Arry_bankimg = new HashMap<>();

                for (int i = 0; i < BL_cobj.length; i++) {
                    Arry_bankimg.put(BL_cobj[i].getaccountid(), BL_cobj[i].geturl());
                }

                Log.e("Check final Arry_bankimg", String.valueOf(Arry_bankimg));
                requestgetserver4.execute("token", "accountname", sessionid, listidmaster);

            } catch (Throwable t) {
                Log.e("My App", "Could not parse malformed JSON: ");
            }

        }
    }, GoogleCardsMediaActivity.this, "2");

    requestgetserver4 = new JSONServerGet(new AsyncResponse() {
        @Override
        public void processFinish(JSONObject output) {

        }

        public void processFinishString(String str_result, Dialog dg) {
            GsonBuilder gsonBuilder = new GsonBuilder();
            gsonBuilder.setDateFormat("M/d/yy hh:mm a");
            Gson gson = gsonBuilder.create();

            JsonParser parser = new JsonParser();
            JsonObject jsonObject = parser.parse(str_result).getAsJsonObject();
            Log.e("Check final data here3", str_result);

            dgthis.dismiss();
            BankList[] BL_cobj = gson.fromJson(jsonObject.get("result"), BankList[].class);
            Map<String, String> Arry_banknamtemp = new HashMap<>();

            for (int i = 0; i < BL_cobj.length; i++) {
                Arry_banknamtemp.put(BL_cobj[i].getid(), BL_cobj[i].getaccountname());
            }

            Arry_banknam = Arry_banknamtemp;

            net_salry = Double.parseDouble(globalsal);

            //*cal tenure here
            String typ_loan = globalloan_type;

            Log.d("tenure loantyp", typ_loan);

            /* if (typ_loan.equals("Car Loan")) {
                    
            //calTenure(7,5);
            calTenure(7);
             } else if (typ_loan.equals("Home Loan")) {
            calTenure(30);
             } else if (typ_loan.equals("Loan Against Property")) {
            calTenure(30);
             } else if (typ_loan.equals("Personal Loan")) {
            calTenure(5);
            //calTenure(5, 15);
             }*/

            if (((GlobalData) getApplication()).getemptype().equals("Salaried"))
                calTenure(60);
            else
                calTenure(65);

            emi = ((GlobalData) getApplication()).getEmi().intValue();

            disbank = new ArrayList<String>();

            calculate();//here will get bank to be displayed i.e CustomListViewValuesArr

            Log.e("flow test", String.valueOf(CustomListViewValuesArr.size()));

            if (CustomListViewValuesArr.size() == 0 || Max_tenure == 0) {

                Log.d("CustomListViewValuesArr.size()", String.valueOf(CustomListViewValuesArr.size()));
                Log.d("Max_tenure val", String.valueOf(Max_tenure));
                AlertDialog.Builder builder = new AlertDialog.Builder(GoogleCardsMediaActivity.this);
                //  builder.setMessage("Sorry, there were no Loan Offers matching your criteria!!!")
                maxbp = maxbp - (maxbp % 1000);
                maxbpval = (int) maxbp;
                Log.d("reduced loan to server2", String.valueOf(Math.ceil(maxbpval)));

                builder.setMessage("You are eligible for Rs " + maxbpval + " amount only.").setCancelable(false)
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {

                                ((GlobalData) getApplication()).setloanamt(String.valueOf(maxbpval));
                                loan_amtcalcutn("oncreate");
                                loan_amt.setText(maxbpval + "");
                                /*Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                startActivity(intent);*/

                            }
                        });
                AlertDialog alert = builder.create();
                alert.show();

            } else {
                // Log.d("disbank", String.valueOf(disbank));

                if (param.equals("oncreate"))
                    setadapter(CustomListViewValuesArr);
                Log.e("flow test", String.valueOf(1));
            }

        }
    }, GoogleCardsMediaActivity.this, "3");

    ServerConnect cls2 = new ServerConnect();

    if (((GlobalData) getApplication()).getcarres() != null) {
        Log.d("checking city name here", ((GlobalData) getApplication()).getcarres());

        // requestgetserver6.execute("token", "City", sessionid, ((GlobalData) getApplication()).getcarres());
    }

    // requestgetserver5.execute("token", "LoanType", sessionid);

    Log.e("flow test", String.valueOf(3));
    prgmImages = new int[] { R.drawable.icici_bank_logo2, R.drawable.axisbank_logo, R.drawable.bankofindia_logo,
            R.drawable.hdfcbank_logo, R.drawable.hdfcbank_logo, R.drawable.hdfcbank_logo };
    prevloan = 0;

}