Example usage for java.lang CharSequence length

List of usage examples for java.lang CharSequence length

Introduction

In this page you can find the example usage for java.lang CharSequence length.

Prototype

int length();

Source Link

Document

Returns the length of this character sequence.

Usage

From source file:com.example.carsharing.CommuteActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    photouri = Uri/*from   w w w . jav  a 2s  . co  m*/
            .fromFile(new File(this.getExternalFilesDir(Environment.DIRECTORY_PICTURES), IMAGE_FILE_NAME2));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_commute);

    activity_drawer = new Drawer(this, R.id.commute_layout);
    mDrawerToggle = activity_drawer.newdrawer();
    mDrawerLayout = activity_drawer.setDrawerLayout();

    // 
    standard_date = new SimpleDateFormat("yyyy-MM-dd", Locale.SIMPLIFIED_CHINESE);
    primary_date = new SimpleDateFormat("yyyyMMdd", Locale.SIMPLIFIED_CHINESE);
    standard_time = new SimpleDateFormat("HH:mm:ss", Locale.SIMPLIFIED_CHINESE);
    primary_time = new SimpleDateFormat("HHmmss", Locale.SIMPLIFIED_CHINESE);

    drawername = (TextView) findViewById(R.id.drawer_name);
    drawernum = (TextView) findViewById(R.id.drawer_phone);
    queue = Volley.newRequestQueue(this);
    exchange = (ImageView) findViewById(R.id.commute_exchange);
    exchange.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            String temp = startplace.getText().toString();
            if (!temp.equals("") && !endplace.getText().toString().equals("")) {
                startplace.setText(endplace.getText().toString());
                endplace.setText(temp);
                float a, b;
                a = startplace_longitude;
                b = startplace_latitude;
                startplace_longitude = destination_longitude;
                startplace_latitude = destination_latitude;
                destination_longitude = a;
                destination_latitude = b;

            }
        }
    });

    bdriver = true;
    bmon = true;
    btue = true;
    bwed = true;
    bthu = true;
    bfri = true;

    startdate = (Button) findViewById(R.id.commute_startdate);
    earlystarttime = (Button) findViewById(R.id.commute_earliest_start_time);
    enddate = (Button) findViewById(R.id.commute_enddate);
    latestarttime = (Button) findViewById(R.id.commute_latest_start_time);
    increase = (Button) findViewById(R.id.commute_increase);
    decrease = (Button) findViewById(R.id.commute_decrease);
    s1 = (TextView) findViewById(R.id.commute_count);
    drawericon = (ImageView) findViewById(R.id.drawer_icon);
    startplace = (Button) findViewById(R.id.commute_startplace);
    endplace = (Button) findViewById(R.id.commute_endplace);
    sure = (Button) findViewById(R.id.commute_sure);
    sure.setEnabled(false);

    carbrand = (EditText) findViewById(R.id.commute_CarBrand);
    model = (EditText) findViewById(R.id.commute_CarModel);
    color = (EditText) findViewById(R.id.commute_color);
    licensenum = (EditText) findViewById(R.id.commute_Num);

    licensenum.addTextChangedListener(numTextWatcher);
    carbrand.addTextChangedListener(detTextWatcher);
    color.addTextChangedListener(coTextWatcher);
    model.addTextChangedListener(moTextWatcher);

    final TextView content = (TextView) findViewById(R.id.commute_content);

    commute_group = (RadioGroup) findViewById(R.id.commute_radiobutton);
    mRadio1 = (RadioButton) findViewById(R.id.commute_radioButton1);
    mRadio2 = (RadioButton) findViewById(R.id.commute_radioButton2);// RadioGroup

    mon = (CheckBox) findViewById(R.id.commute_checkBox1);
    tue = (CheckBox) findViewById(R.id.commute_checkBox2);
    wed = (CheckBox) findViewById(R.id.commute_checkBox3);
    thu = (CheckBox) findViewById(R.id.commute_checkBox4);
    fri = (CheckBox) findViewById(R.id.commute_checkBox5);
    sat = (CheckBox) findViewById(R.id.commute_checkBox6);
    sun = (CheckBox) findViewById(R.id.commute_checkBox7);

    commute = findViewById(R.id.drawer_commute);
    shortway = findViewById(R.id.drawer_shortway);
    longway = findViewById(R.id.drawer_longway);
    setting = findViewById(R.id.drawer_setting);
    personalcenter = findViewById(R.id.drawer_personalcenter);
    taxi = findViewById(R.id.drawer_taxi);

    star1 = (ImageView) findViewById(R.id.cummute_star);
    star2 = (ImageView) findViewById(R.id.commute_star01);

    // 
    SharedPreferences sharedPref = this.getSharedPreferences(getString(R.string.PreferenceDefaultName),
            Context.MODE_PRIVATE);
    UserPhoneNumber = sharedPref.getString(getString(R.string.PreferenceUserPhoneNumber), "0");

    // judge the value of "pre_page"
    Bundle bundle = this.getIntent().getExtras();
    String PRE_PAGE = bundle.getString("pre_page");
    if (PRE_PAGE.compareTo("ReOrder") == 0) { // 
        startplace.setText(bundle.getString("stpusername") + "," + bundle.getString("stpmapname"));
        bstart = true;
        endplace.setText(bundle.getString("epusername") + "," + bundle.getString("epmapname"));
        bend = true;
        startplace_longitude = bundle.getFloat("stpx");
        Log.e("startplace_longitude", String.valueOf(startplace_longitude));
        startplace_latitude = bundle.getFloat("stpy");
        Log.e("startplace_latitude", String.valueOf(startplace_latitude));
        destination_longitude = bundle.getFloat("epx");
        Log.e("destination_longitude", String.valueOf(destination_longitude));
        destination_latitude = bundle.getFloat("epy");
        Log.e("destination_latitude", String.valueOf(destination_latitude));
        startdate.setText(bundle.getString("re_commute_startdate"));
        bstartdate = true;
        enddate.setText(bundle.getString("re_commute_enddate"));
        benddate = true;
        weekrepeat = bundle.getString("weekrepeat");
        earlystarttime.setText(bundle.getString("re_commute_starttime"));
        bearlystarttime = true;
        latestarttime.setText(bundle.getString("re_commute_endtime"));
        blatestarttime = true;

        // weekrepeatcheckbox
        int len = weekrepeat.length();
        for (int i = 0; i < len; i++) {
            if (weekrepeat.charAt(i) == '1') {
                mon.setChecked(true);
                bmon = true;
            }
            if (weekrepeat.charAt(i) == '2') {
                tue.setChecked(true);
                btue = true;
            }
            if (weekrepeat.charAt(i) == '3') {
                wed.setChecked(true);
                bwed = true;
            }
            if (weekrepeat.charAt(i) == '4') {
                thu.setChecked(true);
                bthu = true;
            }
            if (weekrepeat.charAt(i) == '5') {
                fri.setChecked(true);
                bfri = true;
            }
            if (weekrepeat.charAt(i) == '6') {
                sat.setChecked(true);
                bsat = true;
            }
            if (weekrepeat.charAt(i) == '7') {
                sun.setChecked(true);
                bsun = true;
            }
        }
        // end
    }
    // judge the value of "pre_page"

    // database
    db = new DatabaseHelper(getApplicationContext(), UserPhoneNumber, null, 1);
    db1 = db.getWritableDatabase();
    about = findViewById(R.id.drawer_respond);
    about.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent about = new Intent(CommuteActivity.this, AboutActivity.class);
            startActivity(about);
        }
    });
    setting.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent setting = new Intent(CommuteActivity.this, SettingActivity.class);
            startActivity(setting);
        }
    });

    // database end

    star1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            if (bstart) {
                if (Pointisliked(StartPointMapName)) {
                    // Define 'where' part of query.
                    String selection = getString(R.string.dbstring_PlaceMapName) + " LIKE ?";
                    // Specify arguments in placeholder order.
                    String[] selelectionArgs = { StartPointMapName };
                    // Issue SQL statement.
                    db1.delete(getString(R.string.dbtable_placeliked), selection, selelectionArgs);
                    star1.setImageResource(R.drawable.ic_action_not_important);

                } else {
                    ContentValues content = new ContentValues();
                    content.put(getString(R.string.dbstring_PlaceUserName), StartPointUserName);
                    content.put(getString(R.string.dbstring_PlaceMapName), StartPointMapName);
                    content.put(getString(R.string.dbstring_longitude), startplace_longitude);
                    content.put(getString(R.string.dbstring_latitude), startplace_latitude);
                    db1.insert(getString(R.string.dbtable_placeliked), null, content);

                    // Define 'where' part of query.
                    String selection = getString(R.string.dbstring_PlaceMapName) + " LIKE ?";
                    // Specify arguments in placeholder order.
                    String[] selelectionArgs = { StartPointMapName };
                    // Issue SQL statement.
                    db1.delete(getString(R.string.dbtable_placehistory), selection, selelectionArgs);
                    star1.setImageResource(R.drawable.ic_action_important);
                }

            }

        }
    });

    star2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            if (bend) {
                if (Pointisliked(EndPointMapName)) {
                    // Define 'where' part of query.
                    String selection = getString(R.string.dbstring_PlaceMapName) + " LIKE ?";
                    // Specify arguments in placeholder order.
                    String[] selelectionArgs = { EndPointMapName };
                    // Issue SQL statement.
                    db1.delete(getString(R.string.dbtable_placeliked), selection, selelectionArgs);
                    star2.setImageResource(R.drawable.ic_action_not_important);

                } else {
                    ContentValues content = new ContentValues();
                    content.put(getString(R.string.dbstring_PlaceUserName), EndPointUserName);
                    content.put(getString(R.string.dbstring_PlaceMapName), EndPointMapName);
                    content.put(getString(R.string.dbstring_longitude), destination_longitude);
                    content.put(getString(R.string.dbstring_latitude), destination_latitude);
                    db1.insert(getString(R.string.dbtable_placeliked), null, content);

                    // Define 'where' part of query.
                    String selection = getString(R.string.dbstring_PlaceMapName) + " LIKE ?";
                    // Specify arguments in placeholder order.
                    String[] selelectionArgs = { EndPointMapName };
                    // Issue SQL statement.
                    db1.delete(getString(R.string.dbtable_placehistory), selection, selelectionArgs);
                    star2.setImageResource(R.drawable.ic_action_important);
                }

            }

        }
    });

    taxi.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
        }
    });

    personalcenter.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent personalcenter = new Intent(CommuteActivity.this, PersonalCenterActivity.class);
            startActivity(personalcenter);
        }
    });

    shortway.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent shortway = new Intent(CommuteActivity.this, ShortWayActivity.class);
            shortway.putExtra("pre_page", "Drawer");
            startActivity(shortway);
        }
    });

    longway.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));
            Intent longway = new Intent(CommuteActivity.this, MainActivity.class);
            startActivity(longway);
        }
    });

    commute.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer));

        }
    });

    mon.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                bmon = true;
            } else {
                bmon = false;
            }
            confirm();
        }
    });
    tue.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                btue = true;
            } else {
                btue = false;
            }
            confirm();
        }
    });
    wed.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                bwed = true;
            } else {
                bwed = false;
            }
            confirm();
        }
    });
    thu.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                bthu = true;
            } else {
                bthu = false;
            }
            confirm();
        }
    });
    fri.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                bfri = true;
            } else {
                bfri = false;
            }
            confirm();
        }
    });
    sat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                bsat = true;
            } else {
                bsat = false;
            }
            confirm();
        }
    });
    sun.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub
            if (isChecked) {
                bsun = true;
            } else {
                bsun = false;
            }
            confirm();
        }
    });

    commute_group.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup arg0, int checkedId) {
            // TODO Auto-generated method stub18
            // ID

            // """"textView
            if (checkedId == mRadio2.getId()) {

                bpassenager = true;
                bdriver = false;

                licensenum.setEnabled(false);
                carbrand.setEnabled(false);
                color.setEnabled(false);
                model.setEnabled(false);

                licensenum.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                carbrand.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                color.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                model.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";
                    }
                } });
                content.setText(getString(R.string.warningInfo_seatNeed));
                licensenum.setHintTextColor(getResources().getColor(R.color.gray_cccccc));
                carbrand.setHintTextColor(getResources().getColor(R.color.gray_cccccc));
                color.setHintTextColor(getResources().getColor(R.color.gray_cccccc));
                model.setHintTextColor(getResources().getColor(R.color.gray_cccccc));
                licensenum.setInputType(InputType.TYPE_NULL);
                carbrand.setInputType(InputType.TYPE_NULL);
                color.setInputType(InputType.TYPE_NULL);
                model.setInputType(InputType.TYPE_NULL);
            } else {

                bpassenager = false;
                bdriver = true;

                licensenum.setEnabled(true);
                carbrand.setEnabled(true);
                color.setEnabled(true);
                model.setEnabled(true);

                licensenum.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                carbrand.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {
                        return null;
                    }
                } });
                color.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                model.setFilters(new InputFilter[] { new InputFilter() {
                    @Override
                    public CharSequence filter(CharSequence source, int start, int end, Spanned dest,
                            int dstart, int dend) {

                        return null;
                    }
                } });
                content.setText(getString(R.string.warningInfo_seatOffer));
                licensenum.setHintTextColor(getResources().getColor(R.color.purple_9F35FF));
                carbrand.setHintTextColor(getResources().getColor(R.color.purple_9F35FF));
                color.setHintTextColor(getResources().getColor(R.color.purple_9F35FF));
                model.setHintTextColor(getResources().getColor(R.color.purple_9F35FF));
                // licensenum.setText("");
                // carbrand.setText("");
                // color.setText("");
                // model.setText("");
                licensenum.setInputType(InputType.TYPE_CLASS_TEXT);
                carbrand.setInputType(InputType.TYPE_CLASS_TEXT);
                color.setInputType(InputType.TYPE_CLASS_TEXT);
                model.setInputType(InputType.TYPE_CLASS_TEXT);

                // start!
                selectcarinfo(UserPhoneNumber);
                // end!
            }
            confirm();
        }

        private void selectcarinfo(final String phonenum) {
            // TODO Auto-generated method stub
            String carinfo_selectrequest_baseurl = getString(R.string.uri_base)
                    + getString(R.string.uri_CarInfo) + getString(R.string.uri_selectcarinfo_action);

            Log.d("carinfo_selectrequest_baseurl", carinfo_selectrequest_baseurl);
            StringRequest stringRequest = new StringRequest(Request.Method.POST, carinfo_selectrequest_baseurl,
                    new Response.Listener<String>() {

                        @Override
                        public void onResponse(String response) {
                            // TODO Auto-generated method stub
                            Log.d("carinfo_select", response);
                            String jas_id = null;
                            JSONObject json1 = null;
                            try {
                                json1 = new JSONObject(response);
                                JSONObject json = json1.getJSONObject("result");
                                jas_id = json.getString("id");

                                if (jas_id.compareTo("") != 0) { // 

                                    carinfochoosing_type = 2;
                                    carbrand.setText(json.getString("carBrand"));
                                    model.setText(json.getString("carModel"));
                                    licensenum.setText(json.getString("carNum"));
                                    color.setText(json.getString("carColor"));

                                } else {
                                    carinfochoosing_type = 1;
                                }
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }
                        }
                    }, new Response.ErrorListener() {

                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // TODO Auto-generated method stub
                            Log.e("carinfo_selectresult_result", error.getMessage(), error);
                        }
                    }) {
                protected Map<String, String> getParams() {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("phonenum", phonenum);
                    return params;
                }
            };

            queue.add(stringRequest);
        }

    });

    sure.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

            if (commute_group.getCheckedRadioButtonId() == mRadio1.getId()) {
                supplycar = "y";
            } else
                supplycar = "n";

            // start!
            Context phonenumber = CommuteActivity.this;
            SharedPreferences filename = phonenumber
                    .getSharedPreferences(getString(R.string.PreferenceDefaultName), Context.MODE_PRIVATE);
            username = filename.getString("refreshfilename", "0");
            commute_request(username, startdate.getText().toString(), enddate.getText().toString(),
                    earlystarttime.getText().toString(), latestarttime.getText().toString());
            // end!

        }

        private void commute_request(final String commute_phonenum, final String commute_startdate,
                final String commute_enddate, final String commute_starttime, final String commute_endtime) {
            // TODO Auto-generated method stub

            weekrepeat = "";
            if (bmon)
                weekrepeat += "1";
            if (btue)
                weekrepeat += "2";
            if (bwed)
                weekrepeat += "3";
            if (bthu)
                weekrepeat += "4";
            if (bfri)
                weekrepeat += "5";
            if (bsat)
                weekrepeat += "6";
            if (bsun)
                weekrepeat += "7";

            // start
            try {
                test_date = primary_date.parse(commute_startdate);
                standard_commute_startdate = standard_date.format(test_date);
                test_date = primary_date.parse(commute_enddate);
                standard_commute_enddate = standard_date.format(test_date);
                test_date = primary_time.parse(commute_starttime);
                standard_commute_starttime = standard_time.format(test_date);
                test_date = primary_time.parse(commute_endtime);
                standard_commute_endtime = standard_time.format(test_date);
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // end!

            String commute_baseurl = getString(R.string.uri_base) + getString(R.string.uri_CommuteRequest)
                    + getString(R.string.uri_addrequest_action);
            // + "phonenum=" + commute_phonenum + "&startplacex=" +
            // String.valueOf(startplace_longitude) +
            // "&startplacey=" + String.valueOf(startplace_latitude) +
            // "&destinationx=" + String.valueOf(destination_longitude) +
            // "&destinationy=" + String.valueOf(destination_latitude) +
            // "&startdate=" + standard_commute_startdate
            // + "&enddate=" + standard_commute_enddate
            // + "&starttime=" + standard_commute_starttime
            // + "&endtime=" + standard_commute_endtime + "&weekrepeat=" +
            // weekrepeat + "&supplycar=" + supplycar;

            Log.e("commute_URL", commute_baseurl);
            // Instantiate the RequestQueue.
            // Request a string response from the provided URL.
            StringRequest stringRequest = new StringRequest(Request.Method.POST, commute_baseurl,
                    new Response.Listener<String>() {

                        @Override
                        public void onResponse(String response) {
                            Log.d("commute_result", response);
                            JSONObject json1 = null;
                            try {
                                json1 = new JSONObject(response);
                                requestok = json1.getBoolean("result");
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }

                            if (requestok == true) {

                                if (carinfochoosing_type == 1) {
                                    // add
                                    // start!
                                    carinfo(commute_phonenum, licensenum.getText().toString(),
                                            carbrand.getText().toString(), model.getText().toString(),
                                            color.getText().toString(), String.valueOf(sum), 1);
                                    // end!
                                } else {
                                    // update
                                    // start!
                                    carinfo(commute_phonenum, licensenum.getText().toString(),
                                            carbrand.getText().toString(), model.getText().toString(),
                                            color.getText().toString(), String.valueOf(sum), 2);
                                    // end!
                                }

                                Intent sure = new Intent(CommuteActivity.this, OrderResponseActivity.class);
                                sure.putExtra(getString(R.string.request_response), "true");
                                sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(sure);
                            } else {
                                // Toast errorinfo =
                                // Toast.makeText(getApplicationContext(),
                                // "", Toast.LENGTH_LONG);
                                // errorinfo.show();
                                Intent sure = new Intent(CommuteActivity.this, OrderResponseActivity.class);
                                sure.putExtra(getString(R.string.request_response), "false");
                                sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                startActivity(sure);
                            }
                        }
                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Log.e("commute_result", error.getMessage(), error);
                            commute_result = null;
                            // Toast errorinfo = Toast.makeText(null,
                            // "", Toast.LENGTH_LONG);
                            // errorinfo.show();
                            Intent sure = new Intent(CommuteActivity.this, OrderResponseActivity.class);
                            sure.putExtra(getString(R.string.request_response), "false");
                            sure.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                            startActivity(sure);
                        }
                    }) {
                protected Map<String, String> getParams() {
                    // POSTgetParams

                    // start
                    try {
                        test_date = primary_date.parse(commute_startdate);
                        standard_commute_startdate = standard_date.format(test_date);
                        test_date = primary_date.parse(commute_enddate);
                        standard_commute_enddate = standard_date.format(test_date);
                        test_date = primary_time.parse(commute_starttime);
                        standard_commute_starttime = standard_time.format(test_date);
                        test_date = primary_time.parse(commute_endtime);
                        standard_commute_endtime = standard_time.format(test_date);
                    } catch (ParseException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                    // end!

                    Map<String, String> params = new HashMap<String, String>();
                    params.put(getString(R.string.uri_phonenum), commute_phonenum);
                    params.put(getString(R.string.uri_startplacex), String.valueOf(startplace_longitude));
                    params.put(getString(R.string.uri_startplacey), String.valueOf(startplace_latitude));
                    params.put(getString(R.string.uri_startplace), startplace.getText().toString());
                    params.put(getString(R.string.uri_destinationx), String.valueOf(destination_longitude));
                    params.put(getString(R.string.uri_destinationy), String.valueOf(destination_latitude));
                    params.put(getString(R.string.uri_destination), endplace.getText().toString());
                    params.put(getString(R.string.uri_startdate), standard_commute_startdate);
                    params.put(getString(R.string.uri_enddate), standard_commute_enddate);
                    params.put(getString(R.string.uri_starttime), standard_commute_starttime);
                    params.put(getString(R.string.uri_endtime), standard_commute_endtime);
                    params.put(getString(R.string.uri_weekrepeat), weekrepeat);
                    params.put(getString(R.string.uri_supplycar), supplycar);
                    // Log.w("phonemum", commute_phonenum);
                    // Log.w("startplacex",
                    // String.valueOf(startplace_longitude));
                    // Log.w("startdate", standard_commute_startdate);
                    // Log.w("starttime", standard_commute_starttime);
                    // Log.w("weekrepeat",weekrepeat );
                    // Log.w("supplycar",supplycar );
                    // Log.w("enddate",standard_commute_enddate );

                    return params;
                }
            };

            queue.add(stringRequest);

        }
    });

    startplace.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivityForResult(new Intent(CommuteActivity.this, ChooseAddressActivity.class), 1);
        }
    });

    endplace.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            startActivityForResult(new Intent(CommuteActivity.this, ChooseArrivalActivity.class), 2);
        }
    });

    increase.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            sum++;
            s1.setText("" + sum);
            confirm();
        }
    });

    decrease.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            sum--;
            if (sum < 0) {
                sum = 0;
            }
            s1.setText("" + sum);
            confirm();
        }
    });

    startdate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            showDialog(DATE_DIALOG);
        }

    });

    enddate.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            showDialog(DATE_DIALOG01);

        }
    });

    earlystarttime.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            showDialog(TIME_DIALOG);
        }
    });

    latestarttime.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            showDialog(TIME_DIALOG01);

        }
    });
}

From source file:it.feio.android.omninotes.DetailFragment.java

private void displayLocationDialog() {
    PermissionsHelper.requestPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION,
            R.string.permission_coarse_location, snackBarPlaceholder,
            () -> GeocodeHelper.getLocation(new OnGeoUtilResultListener() {
                @Override/*from w w w.jav a2  s.c om*/
                public void onAddressResolved(String address) {
                }

                @Override
                public void onCoordinatesResolved(Location location, String address) {
                }

                @Override
                public void onLocationUnavailable() {
                    mainActivity.showMessage(R.string.location_not_found, ONStyle.ALERT);
                }

                @Override
                public void onLocationRetrieved(Location location) {
                    if (location == null) {
                        return;
                    }
                    if (!ConnectionManager.internetAvailable(mainActivity)) {
                        noteTmp.setLatitude(location.getLatitude());
                        noteTmp.setLongitude(location.getLongitude());
                        onAddressResolved("");
                        return;
                    }
                    LayoutInflater inflater = mainActivity.getLayoutInflater();
                    View v = inflater.inflate(R.layout.dialog_location, null);
                    final AutoCompleteTextView autoCompView = (AutoCompleteTextView) v
                            .findViewById(R.id.auto_complete_location);
                    autoCompView.setHint(getString(R.string.search_location));
                    autoCompView.setAdapter(
                            new PlacesAutoCompleteAdapter(mainActivity, R.layout.simple_text_layout));
                    final MaterialDialog dialog = new MaterialDialog.Builder(mainActivity)
                            .customView(autoCompView, false).positiveText(R.string.use_current_location)
                            .callback(new MaterialDialog.ButtonCallback() {
                                @Override
                                public void onPositive(MaterialDialog materialDialog) {
                                    if (TextUtils.isEmpty(autoCompView.getText().toString())) {
                                        noteTmp.setLatitude(location.getLatitude());
                                        noteTmp.setLongitude(location.getLongitude());
                                        //                           GeocodeHelper.getAddressFromCoordinates(location, mFragment);
                                    } else {
                                        GeocodeHelper.getCoordinatesFromAddress(
                                                autoCompView.getText().toString(), mFragment);
                                    }
                                }
                            }).build();
                    autoCompView.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                        }

                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                            if (s.length() != 0) {
                                dialog.setActionButton(DialogAction.POSITIVE, getString(R.string.confirm));
                            } else {
                                dialog.setActionButton(DialogAction.POSITIVE,
                                        getString(R.string.use_current_location));
                            }
                        }

                        @Override
                        public void afterTextChanged(Editable s) {
                        }
                    });
                    dialog.show();
                }
            }));
}

From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java

/**
 * Find out the position of a word in the text being input
 * @param cursor starting position in the text from which to begin the search (backwards)
 * @param text the text having been input so far
 * @return a WordDetails object with the start and end position of a given word
 *//*from ww  w .  ja va2s . co  m*/
public WordDetails findWord(int cursor, CharSequence text) {
    WordDetails word = new WordDetails();

    //loop backwards to find start of current word
    for (int x = cursor - 1; x >= 0; x--) {
        if (x == 0) {
            word.wordStart = x;
            break;
        } else if (isWordSeparator(text.charAt(x))) {
            word.wordStart = x + 1;
            break;
        }
    }
    //loop forwards to find end of current word
    for (int x = cursor - 1; x < text.length(); x++) {
        if (x < 0)
            break;
        if (isWordSeparator(text.charAt(x)) || x == text.length() - 1) {
            word.wordEnd = x;
            break;
        }
    }

    return word;
}

From source file:com.example.fastgive.CaptureActivity.java

private void handleDecodeInternally(Result rawResult, ResultHandler resultHandler, Bitmap barcode) {
    onPause();//from   w  w w .  j  a v  a2s  . c om
    showResults();

    //        ImageView barcodeImageView = (ImageView) findViewById(R.id.barcode_image_view);
    //        if (barcode == null) {
    //            barcodeImageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
    //        } else {
    //            barcodeImageView.setImageBitmap(barcode);
    //        }
    //
    //        TextView formatTextView = (TextView) findViewById(R.id.format_text_view);
    //        formatTextView.setText(rawResult.getBarcodeFormat().toString());
    //
    //        TextView typeTextView = (TextView) findViewById(R.id.type_text_view);
    //        typeTextView.setText(resultHandler.getType().toString());
    //
    //        DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    //        String formattedTime = formatter.format(new Date(rawResult.getTimestamp()));
    //        TextView timeTextView = (TextView) findViewById(R.id.time_text_view);
    //        timeTextView.setText(formattedTime);
    //
    //        TextView metaTextView = (TextView) findViewById(R.id.meta_text_view);
    //        View metaTextViewLabel = findViewById(R.id.meta_text_view_label);
    //        metaTextView.setVisibility(View.GONE);
    //        metaTextViewLabel.setVisibility(View.GONE);
    //        Map<ResultMetadataType, Object> metadata = rawResult.getResultMetadata();
    //        if (metadata != null) {
    //            StringBuilder metadataText = new StringBuilder(20);
    //            for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
    //                if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
    //                    metadataText.append(entry.getValue()).append('\n');
    //                }
    //            }
    //            if (metadataText.length() > 0) {
    //                metadataText.setLength(metadataText.length() - 1);
    //                metaTextView.setText(metadataText);
    //                metaTextView.setVisibility(View.VISIBLE);
    //                metaTextViewLabel.setVisibility(View.VISIBLE);
    //            }
    //        }

    //Qr Reader
    contentsTextView = (TextView) findViewById(R.id.contents_text_view);
    CharSequence displayContents = resultHandler.getDisplayContents();
    //        contentsTextView.setText(displayContents);
    Log.d(TAG, "displayContents:" + displayContents);

    String resultString = "" + displayContents;
    Log.d(TAG, "resultString:" + resultString);
    if (resultString.length() > 24 && resultString.length() < 35) {
        Log.d(TAG, "resultString is 34 characters");

        try {
            String resultStringresultString = resultString.substring(24, 34);
            Log.d(TAG, "resultString now:" + resultStringresultString);

            String sampleString = "JM208OB791AN578TE662VI34";
            Log.d(TAG, "First 24 characters:" + resultString.substring(0, 24));
            if (resultString.substring(0, 24).toLowerCase().contains(sampleString.toLowerCase())) {
                Log.d(TAG, "YES!!!");
                contentsTextView.setText("Thanks for purchasing this thicket");

                if (JSONParser.isNetworkAvailable() == true) {
                    AsyncTask<String, String, String> responce = new SendRequest()
                            .execute("http://117.58.246.154/fastgive/fastgive-website/event/check_ticket/"
                                    + resultStringresultString);
                    //                     Log.d(TAG, "Final Result:"+responce.toString());
                    //                         contentsTextView.setText(""+responce);
                } else {
                    Toast.makeText(getBaseContext(), "No Internet Connection", Toast.LENGTH_SHORT).show();
                }
            } else {
                Log.d(TAG, "NO");
                contentsTextView.setText("This does not seem to be the genuine ticket. \nPlease try again.");
            }
        } catch (Exception e) {
            contentsTextView.setText("This does not seem to be the genuine ticket. \nPlease try again.");
        }
    } else {
        Log.d(TAG, "resultString is more than 34 characters");
        contentsTextView.setText("It seems that this code was not genarated by Fastgive.");
    }

    // Crudely scale betweeen 22 and 32 -- bigger font for shorter text
    int scaledSize = Math.max(22, 32 - displayContents.length() / 4);
    contentsTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, scaledSize);
}

From source file:HSqlPrimerDesign.java

@SuppressWarnings("Duplicates")
//calculates melting temperature of a oligonucleotide
//based off Primer3 code source code
public static double primerTm(CharSequence primer, double salt_conc, double dna_conc, double divalent,
        double dntp) {
    /**//from  w w w.  ja  v a 2 s.  c  o  m
     *Tables of nearest-neighbor thermodynamics for DNA bases, from the
     * paper [SantaLucia JR (1998) "A unified view of polymer, dumbbell
     * and oligonucleotide DNA nearest-neighbor thermodynamics", Proc Natl
     * Acad Sci 95:1460-65 http://dx.doi.org/10.1073/pnas.95.4.1460]
     */
    final double T_KELVIN = 273.15;

    //delta S for nucleotide pairs
    int DS_A_A = 222;
    int DS_A_C = 224;
    int DS_A_G = 210;
    int DS_A_T = 204;
    int DS_A_N = 224;
    int DS_C_A = 227;
    int DS_C_C = 199;
    int DS_C_G = 272;
    int DS_C_T = 210;
    int DS_C_N = 272;
    int DS_G_A = 222;
    int DS_G_C = 244;
    int DS_G_G = 199;
    int DS_G_T = 224;
    int DS_G_N = 244;
    int DS_T_A = 213;
    int DS_T_C = 222;
    int DS_T_G = 227;
    int DS_T_T = 222;
    int DS_T_N = 227;
    int DS_N_A = 168;
    int DS_N_C = 210;
    int DS_N_G = 220;
    int DS_N_T = 215;
    int DS_N_N = 220;

    //delta H for nucleotide pairs
    int DH_A_A = 79;
    int DH_A_C = 84;
    int DH_A_G = 78;
    int DH_A_T = 72;
    int DH_A_N = 72;
    int DH_C_A = 85;
    int DH_C_C = 80;
    int DH_C_G = 106;
    int DH_C_T = 78;
    int DH_C_N = 78;
    int DH_G_A = 82;
    int DH_G_C = 98;
    int DH_G_G = 80;
    int DH_G_T = 84;
    int DH_G_N = 80;
    int DH_T_A = 72;
    int DH_T_C = 82;
    int DH_T_G = 85;
    int DH_T_T = 79;
    int DH_T_N = 72;
    int DH_N_A = 72;
    int DH_N_C = 80;
    int DH_N_G = 78;
    int DH_N_T = 72;
    int DH_N_N = 72;

    // Delta G's of disruption * 1000.
    int DG_A_A = 1000;
    int DG_A_C = 1440;
    int DG_A_G = 1280;
    int DG_A_T = 880;
    int DG_A_N = 880;
    int DG_C_A = 1450;
    int DG_C_C = 1840;
    int DG_C_G = 2170;
    int DG_C_T = 1280;
    int DG_C_N = 1450;
    int DG_G_A = 1300;
    int DG_G_C = 2240;
    int DG_G_G = 1840;
    int DG_G_T = 1440;
    int DG_G_N = 1300;
    int DG_T_A = 580;
    int DG_T_C = 1300;
    int DG_T_G = 1450;
    int DG_T_T = 1000;
    int DG_T_N = 580;
    int DG_N_A = 580;
    int DG_N_C = 1300;
    int DG_N_G = 1280;
    int DG_N_T = 880;
    int DG_N_N = 580;

    //loops through primer to determine dh and ds
    int dh = 0;
    int ds = 0;
    int dg = 0;
    for (int i = 0; i < (primer.length() - 1); i++) {
        char first = primer.charAt(i);
        char sec = primer.charAt(i + 1);
        if (first == 'g' || first == 'G') {
            if (sec == 'g' || sec == 'G') {
                dh += DH_G_G;
                dg += DG_G_G;
                ds += DS_G_G;
            } else if (sec == 'c' || sec == 'C') {
                dh += DH_G_C;
                dg += DG_G_C;
                ds += DS_G_C;
            } else if (sec == 't' || sec == 'T') {
                dh += DH_G_T;
                dg += DG_G_T;
                ds += DS_G_T;
            } else if (sec == 'a' || sec == 'A') {
                dh += DH_G_A;
                dg += DG_G_A;
                ds += DS_G_A;
            }
        } else if (first == 'c' || first == 'C') {
            if (sec == 'g' || sec == 'G') {
                dh += DH_C_G;
                dg += DG_C_G;
                ds += DS_C_G;
            } else if (sec == 'c' || sec == 'C') {
                dh += DH_C_C;
                dg += DG_C_C;
                ds += DS_C_C;
            } else if (sec == 't' || sec == 'T') {
                dh += DH_C_T;
                dg += DG_C_T;
                ds += DS_C_T;
            } else if (sec == 'a' || sec == 'A') {
                dh += DH_C_A;
                dg += DG_C_A;
                ds += DS_C_A;
            }
        } else if (first == 't' || first == 'T') {
            if (sec == 'g' || sec == 'G') {
                dh += DH_T_G;
                dg += DG_T_G;
                ds += DS_T_G;
            } else if (sec == 'c' || sec == 'C') {
                dh += DH_T_C;
                dg += DG_T_C;
                ds += DS_T_C;
            } else if (sec == 't' || sec == 'T') {
                dh += DH_T_T;
                dg += DG_T_T;
                ds += DS_T_T;
            } else if (sec == 'a' || sec == 'A') {
                dh += DH_T_A;
                dg += DG_T_A;
                ds += DS_T_A;
            }
        } else if (first == 'a' || first == 'A') {
            if (sec == 'g' || sec == 'G') {
                dh += DH_A_G;
                dg += DG_A_G;
                ds += DS_A_G;
            } else if (sec == 'c' || sec == 'C') {
                dh += DH_A_C;
                dg += DG_A_C;
                ds += DS_A_C;
            } else if (sec == 't' || sec == 'T') {
                dh += DH_A_T;
                dg += DG_A_T;
                ds += DS_A_T;
            } else if (sec == 'a' || sec == 'A') {
                dh += DH_A_A;
                dg += DG_A_A;
                ds += DS_A_A;
            }
        }
    }
    //checks for symmetry
    int sym = -1;
    if (primer.length() % 2 == 1) {
        sym = 0;
    } else {
        for (int i = 0; i < (primer.length() / 2); i++) {
            if ((primer.charAt(i) == 'A' && primer.charAt(primer.length() - i - 1) != 'T')
                    || (primer.charAt(i) == 'T' && primer.charAt(primer.length() - i - 1) != 'A')
                    || (primer.charAt(i) == 'C' && primer.charAt(primer.length() - i - 1) != 'G')
                    || (primer.charAt(i) == 'G' && primer.charAt(primer.length() - i - 1) != 'C')) {
                sym = 0;
                break;
            }
            i++;
        }
        if (sym == -1) {
            sym = 1;
        }
    }
    //Assigns AT end penalty
    if (primer.charAt(0) == 'A' || primer.charAt(0) == 'T') {
        ds += -41;
        dh += -23;
    } else if (primer.charAt(0) == 'G' || primer.charAt(0) == 'C') {
        ds += 28;
        dh += -1;
    }

    if (primer.charAt(primer.length() - 1) == 'A' || primer.charAt(primer.length() - 1) == 'T') {
        ds += -41;
        dh += -23;
    } else if (primer.charAt(primer.length() - 1) == 'G' || primer.charAt(primer.length() - 1) == 'C') {
        ds += 28;
        dh += -1;
    }
    if (divalent == 0)
        dntp = 0;
    if (divalent < dntp)
        divalent = dntp;
    salt_conc = salt_conc + 120 * (Math.sqrt(divalent - dntp));

    double delta_H = dh * -100.0;
    double delta_S = ds * -0.1;
    delta_S = delta_S + 0.368 * (primer.length() - 1) * Math.log(salt_conc / 1000.0);
    double tm;

    if (sym == 1) {
        tm = delta_H / (delta_S + 1.987 * Math.log(dna_conc / 1000000000.0)) - T_KELVIN;
    } else {
        tm = delta_H / (delta_S + 1.987 * Math.log(dna_conc / 4000000000.0)) - T_KELVIN;
    }
    return tm;
}

From source file:com.androidquery.AQuery.java

/**
 * Set the text of a TextView. Hide the view (gone) if text is empty.
 *
 * @param text the text/*w ww  .  j  a v  a2 s .c  om*/
 * @param goneIfEmpty hide if text is null or length is 0
 * @return self
 */

public AQuery text(CharSequence text, boolean goneIfEmpty) {

    if (goneIfEmpty && (text == null || text.length() == 0)) {
        return gone();
    } else {
        return text(text);
    }
}

From source file:com.ringdroid.RingdroidEditActivity.java

private String makeRingtoneFilename(CharSequence title, String extension) {
    String parentdir;/*from   w  w w.  ja  v a2s .  co  m*/
    switch (mNewFileKind) {
    default:
    case FileSaveDialog.FILE_KIND_MUSIC:
        parentdir = "/sdcard/media/audio/music";
        break;
    case FileSaveDialog.FILE_KIND_ALARM:
        parentdir = "/sdcard/media/audio/alarms";
        break;
    case FileSaveDialog.FILE_KIND_NOTIFICATION:
        parentdir = "/sdcard/media/audio/notifications";
        break;
    case FileSaveDialog.FILE_KIND_RINGTONE:
        parentdir = "/sdcard/media/audio/ringtones";
        break;
    }

    // Create the parent directory
    File parentDirFile = new File(parentdir);
    parentDirFile.mkdirs();

    // If we can't write to that special path, try just writing
    // directly to the sdcard
    if (!parentDirFile.isDirectory()) {
        parentdir = "/sdcard";
    }

    // Turn the title into a filename
    String filename = "";
    for (int i = 0; i < title.length(); i++) {
        if (Character.isLetterOrDigit(title.charAt(i))) {
            filename += title.charAt(i);
        }
    }

    // Try to make the filename unique
    String path = null;
    for (int i = 0; i < 100; i++) {
        String testPath;
        if (i > 0)
            testPath = parentdir + "/" + filename + i + extension;
        else
            testPath = parentdir + "/" + filename + extension;

        try {
            RandomAccessFile f = new RandomAccessFile(new File(testPath), "r");
        } catch (Exception e) {
            // Good, the file didn't exist
            path = testPath;
            break;
        }
    }

    return path;
}

From source file:com.androidquery.AbstractAQuery.java

/**
 * Set the text of a TextView. Hide the view (gone) if text is empty.
 *
 * @param text the text//from   w ww  .j a  va 2 s  . c  o m
 * @param goneIfEmpty hide if text is null or length is 0
 * @return self
 */

public T text(CharSequence text, boolean goneIfEmpty) {

    if (goneIfEmpty && (text == null || text.length() == 0)) {
        return gone();
    } else {
        return text(text);
    }
}

From source file:com.silentcircle.silenttext.application.SilentTextApplication.java

public CharSequence getFullJIDForUsername(CharSequence username) {
    CharArrayWriter out = new CharArrayWriter();
    boolean shouldAppend = true;
    for (int i = 0; i < username.length(); i++) {
        char c = username.charAt(i);
        out.append(username.charAt(i));/* w  w w.  j  ava  2 s.co  m*/
        if (c == '@') {
            shouldAppend = false;
        }
    }
    if (shouldAppend) {
        out.append('@');
        out.append(getDomain());
    }
    return CharBuffer.wrap(out.toCharArray());
}