List of usage examples for android.text InputFilter InputFilter
InputFilter
From source file:be.brunoparmentier.wifikeyshare.ui.activities.WifiNetworkActivity.java
private static void setPasswordRestrictions(EditText editText) { // Source: http://stackoverflow.com/a/4401227 InputFilter filter = new InputFilter() { @Override/*from www . j av a 2 s. c o m*/ public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { // TODO: check that the filter follows WEP/WPA recommendations for (int i = start; i < end; i++) { if (!Character.isLetterOrDigit(source.charAt(i))) { return ""; } } return null; } }; editText.setFilters(new InputFilter[] { filter }); }
From source file:com.example.carsharing.LongWayActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { photouri = Uri/*from ww w . j a v a 2s . com*/ .fromFile(new File(this.getExternalFilesDir(Environment.DIRECTORY_PICTURES), IMAGE_FILE_NAME2)); System.out.println("abc"); super.onCreate(savedInstanceState); setContentView(R.layout.activity_long_way); activity_drawer = new Drawer(this, R.id.long_way_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); queue = Volley.newRequestQueue(this); exchange = (ImageView) findViewById(R.id.longway_exchange); exchange.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub String temp = startplace.getText().toString(); startplace.setText(endplace.getText().toString()); endplace.setText(temp); } }); bdriver = true; datebutton = (Button) findViewById(R.id.longway_dates); increase = (Button) findViewById(R.id.longway_increase); decrease = (Button) findViewById(R.id.longway_decrease); s1 = (TextView) findViewById(R.id.longway_count); sure = (Button) findViewById(R.id.longway_sure); sure.setEnabled(false); startplace = (EditText) findViewById(R.id.longway_start_place); endplace = (EditText) findViewById(R.id.longway_end_place); noteinfo = (EditText) findViewById(R.id.longway_remarkText); commute = findViewById(R.id.drawer_commute); shortway = findViewById(R.id.drawer_shortway); longway = findViewById(R.id.drawer_longway); drawericon = (ImageView) findViewById(R.id.drawer_icon); drawername = (TextView) findViewById(R.id.drawer_name); drawernum = (TextView) findViewById(R.id.drawer_phone); carbrand = (EditText) findViewById(R.id.longway_CarBrand); model = (EditText) findViewById(R.id.longway_CarModel); color = (EditText) findViewById(R.id.longway_color); setting = findViewById(R.id.drawer_setting); licensenum = (EditText) findViewById(R.id.longway_Num); licensenum.addTextChangedListener(numTextWatcher); carbrand.addTextChangedListener(detTextWatcher); color.addTextChangedListener(coTextWatcher); model.addTextChangedListener(moTextWatcher); startplace.addTextChangedListener(spTextWatcher); endplace.addTextChangedListener(epTextWatcher); final TextView content = (TextView) findViewById(R.id.longway_content); longway_group = (RadioGroup) findViewById(R.id.longway_radiobutton); passangerRadioButton = (RadioButton) findViewById(R.id.longway_radioButton02); driverRadioButton = (RadioButton) findViewById(R.id.longway_radioButton01); personalcenter = findViewById(R.id.drawer_personalcenter); taxi = findViewById(R.id.drawer_taxi); // 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("stpmapname")); bstart = true; endplace.setText(bundle.getString("epmapname")); bend = true; datebutton.setText(bundle.getString("re_longway_startdate")); bdate = true; } // judge the value of "pre_page" // SharedPreferences sharedPref = this.getSharedPreferences(getString(R.string.PreferenceDefaultName), Context.MODE_PRIVATE); UserPhoneNumber = sharedPref.getString(getString(R.string.PreferenceUserPhoneNumber), "0"); // 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(LongWayActivity.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(LongWayActivity.this, SettingActivity.class); startActivity(setting); } }); // database end 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(LongWayActivity.this, PersonalCenterActivity.class); personalcenter.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(personalcenter); } }); // RadioGroup longway_group.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup arg0, int checkedId) { // TODO Auto-generated method stub18 // ID // """"textView if (checkedId == passangerRadioButton.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(Color.parseColor("#cccccc")); carbrand.setHintTextColor(Color.parseColor("#cccccc")); color.setHintTextColor(Color.parseColor("#cccccc")); model.setHintTextColor(Color.parseColor("#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(Color.parseColor("#9F35FF")); carbrand.setHintTextColor(Color.parseColor("#9F35FF")); color.setHintTextColor(Color.parseColor("#9F35FF")); model.setHintTextColor(Color.parseColor("#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")); } { 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 (longway_group.getCheckedRadioButtonId() == passangerRadioButton.getId()) userrole = "p"; else userrole = "d"; // start! Context phonenumber = LongWayActivity.this; SharedPreferences filename = phonenumber .getSharedPreferences(getString(R.string.PreferenceDefaultName), Context.MODE_PRIVATE); username = filename.getString("refreshfilename", "0"); longway_request(username, userrole, datebutton.getText().toString(), startplace.getText().toString(), endplace.getText().toString(), noteinfo.getText().toString()); // end! } private void longway_request(final String longway_phonenum, final String longway_userrole, final String longway_startdate, final String longway_startplace, final String longway_destination, final String longway_noteinfo) { // TODO Auto-generated method stub String longway_addrequest_baseurl = getString(R.string.uri_base) + getString(R.string.uri_LongwayPublish) + getString(R.string.uri_addpublish_action); // + "phonenum=" + longway_phonenum // + "&userrole=" + longway_userrole // + "&startdate=" + standard_longway_startdate // + "&startplace=" + longway_startplace // + "&destination=" + longway_destination // + "¬einfo=" + longway_noteinfo; // Log.d("longway_baseurl",longway_addrequest_baseurl); StringRequest stringRequest = new StringRequest(Request.Method.POST, longway_addrequest_baseurl, new Response.Listener<String>() { @Override public void onResponse(String response) { Log.d("longway_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(longway_phonenum, licensenum.getText().toString(), carbrand.getText().toString(), model.getText().toString(), color.getText().toString(), String.valueOf(sum), 1); // end! } else { // update // start! carinfo(longway_phonenum, licensenum.getText().toString(), carbrand.getText().toString(), model.getText().toString(), color.getText().toString(), String.valueOf(sum), 2); // end! } Intent sure = new Intent(LongWayActivity.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(LongWayActivity.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("longway_result", error.getMessage(), error); // Toast errorinfo = Toast.makeText(null, // "", Toast.LENGTH_LONG); // errorinfo.show(); Intent sure = new Intent(LongWayActivity.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(longway_startdate); standard_longway_startdate = standard_date.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), longway_phonenum); params.put(getString(R.string.uri_userrole), longway_userrole); params.put(getString(R.string.uri_startplace), longway_startplace); params.put(getString(R.string.uri_destination), longway_destination); params.put(getString(R.string.uri_startdate), standard_longway_startdate); params.put(getString(R.string.uri_noteinfo), longway_noteinfo); return params; } }; queue.add(stringRequest); } }); // start! 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(LongWayActivity.this, ShortWayActivity.class); startActivity(shortway); } }); longway.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer)); } }); commute.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub mDrawerLayout.closeDrawer(findViewById(R.id.left_drawer)); Intent commute = new Intent(LongWayActivity.this, CommuteActivity.class); startActivity(commute); } }); // end! 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(); } }); datebutton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub showDialog(DATE_DIALOG); } }); }
From source file:com.xperia64.rompatcher.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); staticThis = MainActivity.this; setContentView(R.layout.main);//from w w w .j a v a 2 s . c om // Load native libraries try { System.loadLibrary("apsn64patcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab apspatcher!"); } try { System.loadLibrary("ipspatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab ipspatcher!"); } try { System.loadLibrary("ipspatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab ipspatcher!"); } try { System.loadLibrary("upspatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab upspatcher!"); } try { System.loadLibrary("xdelta3patcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab xdelta3patcher!"); } try { System.loadLibrary("bpspatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab bpspatcher!"); } try { System.loadLibrary("bzip2"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab bzip2!"); } try { System.loadLibrary("bsdiffpatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab bsdiffpatcher!"); } try { System.loadLibrary("ppfpatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab ppfpatcher!"); } try { System.loadLibrary("ips32patcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab ips32patcher!"); } try { System.loadLibrary("glib-2.0"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab glib-2.0!"); } try { System.loadLibrary("gmodule-2.0"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab gmodule-2.0!"); } try { System.loadLibrary("edsio"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab edsio!"); } try { System.loadLibrary("xdelta1patcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab ips32patcher!"); } try { System.loadLibrary("ips32patcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab ips32patcher!"); } try { System.loadLibrary("ecmpatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab ecmpatcher!"); } try { System.loadLibrary("dpspatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab dpspatcher!"); } try { System.loadLibrary("dldipatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab dldipatcher!"); } try { System.loadLibrary("xpcpatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab xpcpatcher!"); } try { System.loadLibrary("asarpatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab asarpatcher!"); } try { System.loadLibrary("asmpatcher"); } catch (UnsatisfiedLinkError e) { Log.e("Bad:", "Cannot grab asmpatcher!"); } c = (CheckBox) findViewById(R.id.backupCheckbox); d = (CheckBox) findViewById(R.id.altNameCheckbox); r = (CheckBox) findViewById(R.id.ignoreCRC); e = (CheckBox) findViewById(R.id.fileExtCheckbox); ed = (EditText) findViewById(R.id.txtOutFile); final Button romButton = (Button) findViewById(R.id.romButton); romButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Globals.mode = true; Intent intent = new Intent(staticThis, FileBrowserActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivityForResult(intent, 1); } }); final Button patchButton = (Button) findViewById(R.id.patchButton); patchButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Globals.mode = false; Intent intent = new Intent(staticThis, FileBrowserActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); startActivityForResult(intent, 1); } }); final ImageButton bkHelp = (ImageButton) findViewById(R.id.backupHelp); bkHelp.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { AlertDialog dialog = new AlertDialog.Builder(staticThis).create(); dialog.setTitle(getResources().getString(R.string.bkup_rom)); dialog.setMessage(getResources().getString(R.string.bkup_rom_desc)); dialog.setCancelable(true); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { } }); dialog.show(); } }); final ImageButton altNameHelp = (ImageButton) findViewById(R.id.outfileHelp); altNameHelp.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { AlertDialog dialog = new AlertDialog.Builder(staticThis).create(); dialog.setTitle(getResources().getString(R.string.rename1)); dialog.setMessage(getResources().getString(R.string.rename_desc)); dialog.setCancelable(true); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { } }); dialog.show(); } }); final ImageButton chkHelp = (ImageButton) findViewById(R.id.ignoreHelp); chkHelp.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { AlertDialog dialog = new AlertDialog.Builder(staticThis).create(); dialog.setTitle(getResources().getString(R.string.ignoreChks)); dialog.setMessage(getResources().getString(R.string.ignoreChks_desc)); dialog.setCancelable(true); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { } }); dialog.show(); } }); InputFilter filter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { String IC = "*/*\n*\r*\t*\0*\f*`*?***\\*<*>*|*\"*:*"; if (IC.contains("*" + source.charAt(i) + "*")) { return ""; } } return null; } }; ed.setFilters(new InputFilter[] { filter }); c.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (((CheckBox) v).isChecked()) { d.setEnabled(true); if (d.isChecked()) { ed.setEnabled(true); e.setEnabled(true); } } else { d.setEnabled(false); ed.setEnabled(false); e.setEnabled(false); } } }); d.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (((CheckBox) v).isChecked()) { ed.setEnabled(true); e.setEnabled(true); } else { e.setEnabled(false); ed.setEnabled(false); } } }); final Button applyButton = (Button) findViewById(R.id.applyPatch); applyButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Warn about patching archives. if (Globals.fileToPatch.toLowerCase(Locale.US).endsWith(".7z") || Globals.fileToPatch.toLowerCase(Locale.US).endsWith(".zip") || Globals.fileToPatch.toLowerCase(Locale.US).endsWith(".rar")) { AlertDialog dialog = new AlertDialog.Builder(staticThis).create(); dialog.setTitle(getResources().getString(R.string.warning)); dialog.setMessage(getResources().getString(R.string.zip_warning_desc)); dialog.setCancelable(false); dialog.setButton(DialogInterface.BUTTON_POSITIVE, getResources().getString(android.R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { patchCheck(); } }); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int buttonId) { Toast t = Toast.makeText(staticThis, getResources().getString(R.string.nopatch), Toast.LENGTH_SHORT); t.show(); } }); dialog.show(); } else { patchCheck(); } } }); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { // Uggh. requestPermissions(); } }
From source file:org.opendatakit.services.preferences.fragments.ServerSettingsFragment.java
/** * Disallows whitespace from user entry/* w w w .j a va 2 s.c om*/ * * @return */ private InputFilter getWhitespaceFilter() { InputFilter whitespaceFilter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { if (Character.isWhitespace(source.charAt(i))) { return ""; } } return null; } }; return whitespaceFilter; }
From source file:org.opendatakit.services.preferences.fragments.ServerSettingsFragment.java
/** * Disallows carriage returns from user entry * * @return//from w ww. ja va 2 s . com */ private InputFilter getReturnFilter() { InputFilter returnFilter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { if (Character.getType((source.charAt(i))) == Character.CONTROL) { return ""; } } return null; } }; return returnFilter; }
From source file:com.huofu.RestaurantOS.ui.splash.activate.java
/** * ?/*from w ww. j a v a 2s. c om*/ */ public void widgetConfigure() { buttonActivate.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (authDialog == null) { authDialog = new Dialog(activate.this, R.style.PauseDialog); } if (ttv.getParent() != null) { ttv = new TitanicTextView(ctxt); } String key = etActivteCode.getText().toString(); if (key.length() >= 16) { CommonUtils.LogWuwei(tag, "key is " + key); CommonUtils.sendMsg("?", activate.SHOW_LOADING_TEXT, mUiHandler); activate(ctxt, key); } else { CommonUtils.sendMsg("????", activate.SHOW_ERROR_MESSAGE, mUiHandler); } } }); InputFilter filter = new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { // TODO Auto-generated method stub for (int i = start; i < end; i++) { //???'-' if (!Character.isLetter(source.charAt(i)) && source.charAt(i) != '-') { return ""; } } return null; } }; InputFilter filterLength = new InputFilter.LengthFilter(19); etActivteCode.setCursorVisible(false); etActivteCode.setFilters(new InputFilter[] { filter, filterLength }); etActivteCode.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void afterTextChanged(Editable s) { // TODO Auto-generated method stub etActivteCode.setCursorVisible(true); etActivteCode.removeTextChangedListener(this);// ? etActivteCode.setText(s.toString().toUpperCase());// ? etActivteCode.setSelection(s.toString().length());// ?? etActivteCode.addTextChangedListener(this);// ? String licensePlateNumber = etActivteCode.getText().toString().trim(); if (s.length() == 19) { InputMethodUtils.HideKeyboard(etActivteCode); } } }); etActivteCode.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_DEL) { CommonUtils.LogWuwei(tag, "delete"); etActivteCode.setCursorVisible(false); } return false; } }); rl_activate_qrscan_ready.setVisibility(View.INVISIBLE); OnClickListener oclGetQrCode = new OnClickListener() { @Override public void onClick(View v) { flagInQrcodeDialog = true; CommonUtils.sendMsg("??", SHOW_LOADING_TEXT, mUiHandler); if (LocalDataDeal.readFromLocalPublicKey(ctxt) == null || LocalDataDeal.readFromLocalPublicKey(ctxt).equals("")) { ApisManager.GetPublicKey(new ApiCallback() { @Override public void success(Object object) { sendUIMessage(HIDE_LOADING, ""); try { org.json.JSONObject obj = new org.json.JSONObject((String) object); String public_key = obj.getString("public_key"); LocalDataDeal.writeToLocalPublicKey(public_key, ctxt);//key?base64? } catch (Exception e) { } CommonUtils.sendMsg("", GET_QRCODE, mUiHandler); } @Override public void error(BaseApi.ApiResponse response) { sendUIMessage(HIDE_LOADING, ""); sendUIMessage(SHOW_ERROR_MESSAGE, response.error_message); } }); } else { CommonUtils.sendMsg("", GET_QRCODE, mUiHandler); } rl_activate_input.setVisibility(View.INVISIBLE); rl_activate_qrscan_ready.setVisibility(View.VISIBLE); imageViewQrcode.setVisibility(View.INVISIBLE); rl_activate_qrscan_ready .startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.small_2_big)); textviewScanStauts.setTextColor(Color.parseColor("#898989")); textviewScanStauts.setText(R.string.activateByQrCodeTips); rl_activate_qrscan_ready .startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.slide_left_in)); rl_activate_input.startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.slide_right_out)); } }; buttonSwitchQrScan.setOnClickListener(oclGetQrCode); findViewById(R.id.rl_switch_activate_qrcode_way).setOnClickListener(oclGetQrCode); buttonSwitchInputCode.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub flagInQrcodeDialog = false; flagWaitingCmd = false; rl_activate_qrscan_ready.setVisibility(View.INVISIBLE); rl_activate_input.setVisibility(View.VISIBLE); rl_activate_input.startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.small_2_big)); stopQrScanTimer(); rl_activate_input.startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.slide_right_in)); rl_activate_qrscan_ready .startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.slide_left_out)); } }); findViewById(R.id.rl_switch_activate_keyboard_way).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub flagInQrcodeDialog = false; flagWaitingCmd = false; rl_activate_qrscan_ready.setVisibility(View.INVISIBLE); rl_activate_input.setVisibility(View.VISIBLE); rl_activate_input.startAnimation(new AnimationUtils().loadAnimation(ctxt, R.anim.small_2_big)); stopQrScanTimer(); } }); PackageManager manager; PackageInfo info = null; manager = this.getPackageManager(); String versionName = null; try { info = manager.getPackageInfo(this.getPackageName(), 0); versionName = info.versionName; } catch (NameNotFoundException e) { e.printStackTrace(); } ((TextView) findViewById(R.id.tv_app_version)) .setText(getResources().getString(R.string.app_name) + " V" + versionName); LocalDataDeal.writeToLocalVersion(versionName, ctxt); LocalDataDeal.writeToLocalVersionCode(info.versionCode, ctxt); ftpServiceStart(); }
From source file:com.example.carsharing.ShortWayActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { photouri = Uri//from w w w. j a v a2s . co m .fromFile(new File(this.getExternalFilesDir(Environment.DIRECTORY_PICTURES), IMAGE_FILE_NAME2)); super.onCreate(savedInstanceState); setContentView(R.layout.activity_short_way); activity_drawer = new Drawer(this, R.id.short_way_layout); mDrawerToggle = activity_drawer.newdrawer(); mDrawerLayout = activity_drawer.setDrawerLayout(); bdriver = true; // SharedPreferences sharedPref = this.getSharedPreferences(getString(R.string.PreferenceDefaultName), Context.MODE_PRIVATE); UserPhoneNumber = sharedPref.getString(getString(R.string.PreferenceUserPhoneNumber), "0"); // 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); queue = Volley.newRequestQueue(this); exchange = (ImageView) findViewById(R.id.shortway_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; } } }); datebutton = (Button) findViewById(R.id.shortway_dates); earlystarttime = (Button) findViewById(R.id.shortway_earliest_start_time); latestarttime = (Button) findViewById(R.id.shortway_latest_start_time); increase = (Button) findViewById(R.id.shortway_increase); decrease = (Button) findViewById(R.id.shortway_decrease); s2 = (TextView) findViewById(R.id.shortway_count); startplace = (Button) findViewById(R.id.shortway_startplace); endplace = (Button) findViewById(R.id.shortway_endplace); sure = (Button) findViewById(R.id.shortway_sure); 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); about = findViewById(R.id.drawer_respond); taxi = findViewById(R.id.drawer_taxi); drawericon = (ImageView) findViewById(R.id.drawer_icon); drawername = (TextView) findViewById(R.id.drawer_name); drawernum = (TextView) findViewById(R.id.drawer_phone); carbrand = (EditText) findViewById(R.id.shortway_CarBrand); model = (EditText) findViewById(R.id.shortway_CarModel); color = (EditText) findViewById(R.id.shortway_color); licensenum = (EditText) findViewById(R.id.shortway_Num); licensenum.addTextChangedListener(numTextWatcher); carbrand.addTextChangedListener(detTextWatcher); color.addTextChangedListener(coTextWatcher); model.addTextChangedListener(moTextWatcher); next = (Button) findViewById(R.id.shortway_sure); next.setEnabled(false); db = new DatabaseHelper(ShortWayActivity.this, "test", null, 1); db1 = db.getWritableDatabase(); final TextView content = (TextView) findViewById(R.id.shortway_content); mRadio1 = (RadioButton) findViewById(R.id.shortway_radioButton1); mRadio2 = (RadioButton) findViewById(R.id.shortway_radioButton2); shortway_group = (RadioGroup) findViewById(R.id.shortway_radiobutton01); star1 = (ImageView) findViewById(R.id.shortway_star); star2 = (ImageView) findViewById(R.id.shortway_star01); // 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)); datebutton.setText(bundle.getString("re_short_startdate")); bdate = true; earlystarttime.setText(bundle.getString("re_short_starttime")); best = true; latestarttime.setText(bundle.getString("re_short_endtime")); blst = true; } // judge the value of "pre_page" 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(ShortWayActivity.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(ShortWayActivity.this, SettingActivity.class); startActivity(setting); } }); // database db = new DatabaseHelper(getApplicationContext(), UserPhoneNumber, null, 1); db1 = db.getWritableDatabase(); // 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(ShortWayActivity.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)); } }); 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(ShortWayActivity.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)); Intent commute = new Intent(ShortWayActivity.this, CommuteActivity.class); commute.putExtra("pre_page", "Drawer"); startActivity(commute); } }); // RadioGroup shortway_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(Color.parseColor("#cccccc")); carbrand.setHintTextColor(Color.parseColor("#cccccc")); color.setHintTextColor(Color.parseColor("#cccccc")); model.setHintTextColor(Color.parseColor("#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(Color.parseColor("#9F35FF")); carbrand.setHintTextColor(Color.parseColor("#9F35FF")); color.setHintTextColor(Color.parseColor("#9F35FF")); model.setHintTextColor(Color.parseColor("#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(); } }); sure.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub if (shortway_group.getCheckedRadioButtonId() == mRadio1.getId()) userrole = "d"; else userrole = "p"; // start! shortway_request(UserPhoneNumber, datebutton.getText().toString(), earlystarttime.getText().toString(), latestarttime.getText().toString()); // end! } private void shortway_request(final String shortway_phonenum, final String shortway_date, final String shortway_starttime, final String shortway_endtime) { // TODO Auto-generated method stub // start try { test_date = primary_date.parse(shortway_date); standard_shortway_startdate = standard_date.format(test_date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { test_date = primary_time.parse(shortway_starttime); standard_shortway_starttime = standard_time.format(test_date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { test_date = primary_time.parse(shortway_endtime); standard_shortway_endtime = standard_time.format(test_date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } // end! String shortway_baseurl = getString(R.string.uri_base) + getString(R.string.uri_ShortwayRequest) + getString(R.string.uri_addrequest_action); // "http://192.168.1.111:8080/CarsharingServer/ShortwayRequest!addrequest.action?"; Log.w("URL", shortway_baseurl); StringRequest stringRequest = new StringRequest(Request.Method.POST, shortway_baseurl, new Response.Listener<String>() { @Override public void onResponse(String response) { Log.d("shortway_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(shortway_phonenum, licensenum.getText().toString(), carbrand.getText().toString(), model.getText().toString(), color.getText().toString(), String.valueOf(sum), 1); // end! } else { // update // start! carinfo(shortway_phonenum, licensenum.getText().toString(), carbrand.getText().toString(), model.getText().toString(), color.getText().toString(), String.valueOf(sum), 2); // end! } Intent sure = new Intent(ShortWayActivity.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(ShortWayActivity.this, OrderResponseActivity.class); sure.putExtra(getString(R.string.request_response), "false"); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("shortway_result", error.getMessage(), error); // Toast errorinfo = Toast.makeText(null, // "", Toast.LENGTH_LONG); // errorinfo.show(); Intent sure = new Intent(ShortWayActivity.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(shortway_date); standard_shortway_startdate = standard_date.format(test_date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { test_date = primary_time.parse(shortway_starttime); standard_shortway_starttime = standard_time.format(test_date); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { test_date = primary_time.parse(shortway_endtime); standard_shortway_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("phonenum", shortway_phonenum); params.put("userrole", userrole); params.put("startplacex", String.valueOf(startplace_longitude)); params.put("startplacey", String.valueOf(startplace_latitude)); params.put(getString(R.string.uri_startplace), startplace.getText().toString()); params.put("destinationx", String.valueOf(destination_longitude)); params.put("destinationy", String.valueOf(destination_latitude)); params.put(getString(R.string.uri_destination), endplace.getText().toString()); params.put("startdate", standard_shortway_startdate); params.put("starttime", standard_shortway_starttime); params.put("endtime", standard_shortway_endtime); return params; } }; queue.add(stringRequest); } }); startplace.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub startActivityForResult(new Intent(ShortWayActivity.this, ChooseAddressActivity.class), 1); } }); endplace.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub startActivityForResult(new Intent(ShortWayActivity.this, ChooseArrivalActivity.class), 2); } }); increase.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub sum++; s2.setText("" + sum); confirm(); } }); decrease.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub sum--; if (sum < 0) { sum = 0; } s2.setText("" + sum); confirm(); } }); datebutton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub showDialog(DATE_DIALOG); } }); 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_DIALOG1); } }); }
From source file:com.example.carsharing.CommuteActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { photouri = Uri/*ww w . ja v a 2 s.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:com.hichinaschool.flashcards.anki.CardEditor.java
@Override protected Dialog onCreateDialog(int id) { StyledDialog dialog = null;//from w w w.ja v a 2s. c om Resources res = getResources(); StyledDialog.Builder builder = new StyledDialog.Builder(this); switch (id) { case DIALOG_TAGS_SELECT: builder.setTitle(R.string.card_details_tags); builder.setPositiveButton(res.getString(R.string.select), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (mAddNote) { try { JSONArray ja = new JSONArray(); for (String t : selectedTags) { ja.put(t); } mCol.getModels().current().put("tags", ja); mCol.getModels().setChanged(); } catch (JSONException e) { throw new RuntimeException(e); } mEditorNote.setTags(selectedTags); } mCurrentTags = selectedTags; updateTags(); } }); builder.setNegativeButton(res.getString(R.string.cancel), null); mNewTagEditText = (EditText) new EditText(this); mNewTagEditText.setHint(R.string.add_new_tag); InputFilter filter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { for (int i = start; i < end; i++) { if (source.charAt(i) == ' ' || source.charAt(i) == ',') { return ""; } } return null; } }; mNewTagEditText.setFilters(new InputFilter[] { filter }); ImageView mAddTextButton = new ImageView(this); mAddTextButton.setImageResource(R.drawable.ic_addtag); mAddTextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String tag = mNewTagEditText.getText().toString(); if (tag.length() != 0) { if (mEditorNote.hasTag(tag)) { mNewTagEditText.setText(""); return; } selectedTags.add(tag); actualizeTagDialog(mTagsDialog); mNewTagEditText.setText(""); } } }); FrameLayout frame = new FrameLayout(this); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL); params.rightMargin = 10; mAddTextButton.setLayoutParams(params); frame.addView(mNewTagEditText); frame.addView(mAddTextButton); builder.setView(frame, false, true); dialog = builder.create(); mTagsDialog = dialog; break; case DIALOG_DECK_SELECT: ArrayList<CharSequence> dialogDeckItems = new ArrayList<CharSequence>(); // Use this array to know which ID is associated with each // Item(name) final ArrayList<Long> dialogDeckIds = new ArrayList<Long>(); ArrayList<JSONObject> decks = mCol.getDecks().all(); Collections.sort(decks, new JSONNameComparator()); builder.setTitle(R.string.deck); for (JSONObject d : decks) { try { if (d.getInt("dyn") == 0) { dialogDeckItems.add(d.getString("name")); dialogDeckIds.add(d.getLong("id")); } } catch (JSONException e) { throw new RuntimeException(e); } } // Convert to Array String[] items = new String[dialogDeckItems.size()]; dialogDeckItems.toArray(items); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { long newId = dialogDeckIds.get(item); if (mCurrentDid != newId) { if (mAddNote) { try { // TODO: mEditorNote.setDid(newId); mEditorNote.model().put("did", newId); mCol.getModels().setChanged(); } catch (JSONException e) { throw new RuntimeException(e); } } mCurrentDid = newId; updateDeck(); } } }); dialog = builder.create(); mDeckSelectDialog = dialog; break; case DIALOG_MODEL_SELECT: ArrayList<CharSequence> dialogItems = new ArrayList<CharSequence>(); // Use this array to know which ID is associated with each // Item(name) final ArrayList<Long> dialogIds = new ArrayList<Long>(); ArrayList<JSONObject> models = mCol.getModels().all(); Collections.sort(models, new JSONNameComparator()); builder.setTitle(R.string.note_type); for (JSONObject m : models) { try { dialogItems.add(m.getString("name")); dialogIds.add(m.getLong("id")); } catch (JSONException e) { throw new RuntimeException(e); } } // Convert to Array String[] items2 = new String[dialogItems.size()]; dialogItems.toArray(items2); builder.setItems(items2, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { long oldModelId; try { oldModelId = mCol.getModels().current().getLong("id"); } catch (JSONException e) { throw new RuntimeException(e); } long newId = dialogIds.get(item); if (oldModelId != newId) { mCol.getModels().setCurrent(mCol.getModels().get(newId)); JSONObject cdeck = mCol.getDecks().current(); try { cdeck.put("mid", newId); } catch (JSONException e) { throw new RuntimeException(e); } mCol.getDecks().save(cdeck); int size = mEditFields.size(); String[] oldValues = new String[size]; for (int i = 0; i < size; i++) { oldValues[i] = mEditFields.get(i).getText().toString(); } setNote(); resetEditFields(oldValues); mTimerHandler.removeCallbacks(checkDuplicatesRunnable); duplicateCheck(false); } } }); dialog = builder.create(); break; case DIALOG_RESET_CARD: builder.setTitle(res.getString(R.string.reset_card_dialog_title)); builder.setMessage(res.getString(R.string.reset_card_dialog_message)); builder.setPositiveButton(res.getString(R.string.yes), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // for (long cardId : // mDeck.getCardsFromFactId(mEditorNote.getId())) { // mDeck.cardFromId(cardId).resetCard(); // } // mDeck.reset(); // setResult(Reviewer.RESULT_EDIT_CARD_RESET); // mCardReset = true; // Themes.showThemedToast(CardEditor.this, // getResources().getString( // R.string.reset_card_dialog_confirmation), true); } }); builder.setNegativeButton(res.getString(R.string.no), null); builder.setCancelable(true); dialog = builder.create(); break; case DIALOG_INTENT_INFORMATION: dialog = createDialogIntentInformation(builder, res); } return dialog; }
From source file:org.totschnig.myexpenses.util.Utils.java
public static void configDecimalSeparator(final EditText editText, final char decimalSeparator, final int fractionDigits) { // mAmountText.setInputType( // InputType.TYPE_CLASS_NUMBER|InputType.TYPE_NUMBER_FLAG_DECIMAL); // due to bug in Android platform // http://code.google.com/p/android/issues/detail?id=2626 // the soft keyboard if it occupies full screen in horizontal orientation // does not display the , as comma separator // TODO we should take into account the arab separator as well final char otherSeparator = decimalSeparator == '.' ? ',' : '.'; editText.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); editText.setFilters(new InputFilter[] { new InputFilter() { @Override//from ww w . j a v a 2 s .c om public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { int separatorPositionInDest = dest.toString().indexOf(decimalSeparator); char[] v = new char[end - start]; TextUtils.getChars(source, start, end, v, 0); String input = new String(v).replace(otherSeparator, decimalSeparator); if (fractionDigits == 0 || separatorPositionInDest != -1 || dest.length() - dend > fractionDigits) { input = input.replace(String.valueOf(decimalSeparator), ""); } else { int separatorPositionInSource = input.lastIndexOf(decimalSeparator); if (separatorPositionInSource != -1) { //we make sure there is only one separator in the input and after the separator we do not use //more minor digits as allowed int existingMinorUnits = dest.length() - dend; int additionalAllowedMinorUnits = fractionDigits - existingMinorUnits; int additionalPossibleMinorUnits = input.length() - separatorPositionInSource - 1; int extractMinorUnits = additionalPossibleMinorUnits >= additionalAllowedMinorUnits ? additionalAllowedMinorUnits : additionalPossibleMinorUnits; input = input.substring(0, separatorPositionInSource) .replace(String.valueOf(decimalSeparator), "") + decimalSeparator + (extractMinorUnits > 0 ? input.substring(separatorPositionInSource + 1, separatorPositionInSource + 1 + extractMinorUnits) : ""); } } if (fractionDigits == 0) { return input; } if (separatorPositionInDest != -1 && dend > separatorPositionInDest && dstart > separatorPositionInDest) { int existingMinorUnits = dest.length() - (separatorPositionInDest + 1); int remainingMinorUnits = fractionDigits - existingMinorUnits; if (remainingMinorUnits < 1) { return ""; } return input.length() > remainingMinorUnits ? input.substring(0, remainingMinorUnits) : input; } else { return input; } } }, new InputFilter.LengthFilter(16) }); }