List of usage examples for android.text InputType TYPE_NUMBER_FLAG_DECIMAL
int TYPE_NUMBER_FLAG_DECIMAL
To view the source code for android.text InputType TYPE_NUMBER_FLAG_DECIMAL.
Click Source Link
From source file:com.citrus.sample.WalletPaymentFragment.java
@OnClick(R.id.btnMasterpass) public void testMasterPass() { final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); String message = null;//www.j a va 2 s. c om String positiveButtonText = null; message = "Please enter the transaction amount."; positiveButtonText = "Make Payment"; LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); alert.setTitle("Transaction Amount?"); alert.setMessage(message); // Set an EditText view to get user input final EditText input = new EditText(getActivity()); input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); alert.setView(input); alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); input.clearFocus(); // Hide the keyboard. InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(input.getWindowToken(), 0); try { MasterPassOption masterPassOption = new MasterPassOption(); PaymentType.PGPayment pgPayment = new PaymentType.PGPayment(new Amount(value), Constants.BILL_URL, masterPassOption, null); mCitrusClient.simpliPay(pgPayment, new Callback<TransactionResponse>() { @Override public void success(TransactionResponse transactionResponse) { Toast.makeText(getActivity(), transactionResponse.getMessage(), Toast.LENGTH_SHORT) .show(); } @Override public void error(CitrusError error) { Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show(); } }); } catch (CitrusException e) { e.printStackTrace(); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); input.requestFocus(); alert.show(); }
From source file:com.citrus.sample.WalletPaymentFragment.java
private void showUpdateSubscriptionPrompt(final boolean isUpdateToHigherValue) { final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); // final String message = "Update Subscription to Lowe Amount"; String positiveButtonText = "Update Subscription "; LinearLayout linearLayout = new LinearLayout(getActivity()); linearLayout.setOrientation(LinearLayout.VERTICAL); final TextView labelsubscriptionID = new TextView(getActivity()); final EditText edtAmount = new EditText(getActivity()); final TextView labelAmount = new TextView(getActivity()); final EditText editLoadAmount = new EditText(getActivity()); final TextView labelMobileNo = new TextView(getActivity()); final EditText editThresholdAmount = new EditText(getActivity()); editLoadAmount.setSingleLine(true);//ww w. j a va 2 s . com editThresholdAmount.setSingleLine(true); edtAmount.setSingleLine(true); edtAmount.setInputType(InputType.TYPE_NULL); labelsubscriptionID.setText("Load Money Amount"); labelAmount.setText("Current Auto Load Amount"); editLoadAmount.setText(String.valueOf(activeSubscription.getLoadAmount())); labelMobileNo.setText("Current Threshold Amount"); editThresholdAmount.setText(String.valueOf(activeSubscription.getThresholdAmount())); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); labelsubscriptionID.setLayoutParams(layoutParams); edtAmount.setLayoutParams(layoutParams); labelAmount.setLayoutParams(layoutParams); labelMobileNo.setLayoutParams(layoutParams); editLoadAmount.setLayoutParams(layoutParams); editThresholdAmount.setLayoutParams(layoutParams); linearLayout.addView(labelAmount); linearLayout.addView(editLoadAmount); linearLayout.addView(labelMobileNo); linearLayout.addView(editThresholdAmount); linearLayout.addView(labelsubscriptionID); linearLayout.addView(edtAmount); edtAmount.setText("1.00"); int paddingPx = Utils.getSizeInPx(getActivity(), 32); linearLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx); editLoadAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); edtAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); editLoadAmount.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { /* if (!hasFocus) { if (Double.valueOf(editLoadAmount.getText().toString()) > activeSubscription.getLoadAmount()) { labelsubscriptionID.setVisibility(View.VISIBLE); edtAmount.setVisibility(View.VISIBLE); edtAmount.setText("1.00"); } else { labelsubscriptionID.setVisibility(View.INVISIBLE); edtAmount.setVisibility(View.INVISIBLE); } }*/ } }); editThresholdAmount.setInputType(InputType.TYPE_CLASS_NUMBER); alert.setTitle("Update Subscription "); alert.setMessage("Updating Load amount to higher will require Load Money transactions."); alert.setView(linearLayout); alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { final String trAmount = edtAmount.getText().toString(); final String loadAmount = editLoadAmount.getText().toString(); final String thresHoldAmount = editThresholdAmount.getText().toString(); // Hide the keyboard. InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(edtAmount.getWindowToken(), 0); if (TextUtils.isEmpty(trAmount) && edtAmount.getVisibility() == View.VISIBLE) { Toast.makeText(getActivity(), " load amount cant be blank", Toast.LENGTH_SHORT).show(); return; } if (TextUtils.isEmpty(loadAmount)) { Toast.makeText(getActivity(), "Auto Load Amount cant be blank", Toast.LENGTH_SHORT).show(); return; } if (TextUtils.isEmpty(thresHoldAmount)) { Toast.makeText(getActivity(), "thresHoldAmount cant be blank", Toast.LENGTH_SHORT).show(); return; } if (Double.valueOf(thresHoldAmount) < new Double("500")) { Toast.makeText(getActivity(), "thresHoldAmount should not be less than 500", Toast.LENGTH_SHORT).show(); return; } if (Double.valueOf(loadAmount) < new Double(thresHoldAmount)) { Toast.makeText(getActivity(), "Load Amount should not be less than thresHoldAmount", Toast.LENGTH_SHORT).show(); return; } if (Double.valueOf(editLoadAmount.getText().toString()) > activeSubscription.getLoadAmount()) { //update to higher value mListener.onAutoLoadSelected(AUTO_LOAD_MONEY, new Amount(trAmount), editLoadAmount.getText().toString(), editThresholdAmount.getText().toString(), true); } else { //update to lower value mCitrusClient.updateSubScriptiontoLoweValue(new Amount(thresHoldAmount), new Amount(loadAmount), new Callback<SubscriptionResponse>() { @Override public void success(SubscriptionResponse subscriptionResponse) { Toast.makeText(getActivity(), subscriptionResponse.toString(), Toast.LENGTH_SHORT).show(); Logger.d("updateSubscription response **" + subscriptionResponse.toString()); activeSubscription = subscriptionResponse;//update the active subscription Object } @Override public void error(CitrusError error) { Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_SHORT).show(); Logger.d("ERROR ***updateSubscription" + error.getMessage()); } }); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); editLoadAmount.requestFocus(); alert.show(); }
From source file:usbong.android.retrocc.UsbongDecisionTreeEngineActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { if (mTts.isSpeaking()) { mTts.stop();/*w w w.j a v a 2 s.c o m*/ } StringBuffer sb = new StringBuffer(); switch (item.getItemId()) { /* case(R.id.set_language): initSetLanguage(); //refresh the menu options supportInvalidateOptionsMenu(); //added by Mike, 20160507 invalidateOptionsMenu(); return true; case(R.id.speak): processSpeak(sb); return true; case(R.id.settings): //20160417 //Reference: http://stackoverflow.com/questions/16954196/alertdialog-with-checkbox-in-android; //last accessed: 20160408; answer by: kamal; edited by: Empty2K12 final CharSequence[] items = {UsbongConstants.AUTO_NARRATE_STRING, UsbongConstants.AUTO_PLAY_STRING, UsbongConstants.AUTO_LOOP_STRING}; // arraylist to keep the selected items selectedSettingsItems=new ArrayList<Integer>(); //check saved settings if (UsbongUtils.IS_IN_AUTO_NARRATE_MODE) { selectedSettingsItems.add(UsbongConstants.AUTO_NARRATE); } if (UsbongUtils.IS_IN_AUTO_PLAY_MODE) { selectedSettingsItems.add(UsbongConstants.AUTO_PLAY); selectedSettingsItems.add(UsbongConstants.AUTO_NARRATE); //if AUTO_PLAY is checked, AUTO_NARRATE should also be checked } if (UsbongUtils.IS_IN_AUTO_LOOP_MODE) { selectedSettingsItems.add(UsbongConstants.AUTO_LOOP); } selectedSettingsItemsInBoolean = new boolean[items.length]; for(int k=0; k<items.length; k++) { selectedSettingsItemsInBoolean[k] = false; } for(int i=0; i<selectedSettingsItems.size(); i++) { selectedSettingsItemsInBoolean[selectedSettingsItems.get(i)] = true; } inAppSettingsDialog = new AlertDialog.Builder(this) .setTitle("Settings") .setMultiChoiceItems(items, selectedSettingsItemsInBoolean, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) { Log.d(">>>","onClick"); if (isChecked) { // If the user checked the item, add it to the selected items selectedSettingsItems.add(indexSelected); if ((indexSelected==UsbongConstants.AUTO_PLAY) && !selectedSettingsItems.contains(UsbongConstants.AUTO_NARRATE)) { final ListView list = inAppSettingsDialog.getListView(); list.setItemChecked(UsbongConstants.AUTO_NARRATE, true); } } else if (selectedSettingsItems.contains(indexSelected)) { if ((indexSelected==UsbongConstants.AUTO_NARRATE) && selectedSettingsItems.contains(UsbongConstants.AUTO_PLAY)) { final ListView list = inAppSettingsDialog.getListView(); list.setItemChecked(indexSelected, false); } else { // Else, if the item is already in the array, remove it selectedSettingsItems.remove(Integer.valueOf(indexSelected)); } } //updated selectedSettingsItemsInBoolean for(int k=0; k<items.length; k++) { selectedSettingsItemsInBoolean[k] = false; } for(int i=0; i<selectedSettingsItems.size(); i++) { selectedSettingsItemsInBoolean[selectedSettingsItems.get(i)] = true; } } }).setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { try { InputStreamReader reader = UsbongUtils.getFileFromSDCardAsReader(UsbongUtils.BASE_FILE_PATH + "usbong.config"); BufferedReader br = new BufferedReader(reader); String currLineString; //write first to a temporary file PrintWriter out = UsbongUtils.getFileFromSDCardAsWriter(UsbongUtils.BASE_FILE_PATH + "usbong.config" +"TEMP"); while((currLineString=br.readLine())!=null) { Log.d(">>>", "currLineString: "+currLineString); if ((currLineString.contains("IS_IN_AUTO_NARRATE_MODE=")) || (currLineString.contains("IS_IN_AUTO_PLAY_MODE=")) || (currLineString.contains("IS_IN_AUTO_LOOP_MODE="))) { continue; } else { out.println(currLineString); } } for (int i=0; i<items.length; i++) { Log.d(">>>>", i+""); if (selectedSettingsItemsInBoolean[i]==true) { if (i==UsbongConstants.AUTO_NARRATE) { out.println("IS_IN_AUTO_NARRATE_MODE=ON"); UsbongUtils.IS_IN_AUTO_NARRATE_MODE=true; } else if (i==UsbongConstants.AUTO_PLAY) { out.println("IS_IN_AUTO_PLAY_MODE=ON"); UsbongUtils.IS_IN_AUTO_PLAY_MODE=true; } else if (i==UsbongConstants.AUTO_LOOP) { out.println("IS_IN_AUTO_LOOP_MODE=ON"); UsbongUtils.IS_IN_AUTO_LOOP_MODE=true; } } else { if (i==UsbongConstants.AUTO_NARRATE) { out.println("IS_IN_AUTO_NARRATE_MODE=OFF"); UsbongUtils.IS_IN_AUTO_NARRATE_MODE=false; } else if (i==UsbongConstants.AUTO_PLAY) { out.println("IS_IN_AUTO_PLAY_MODE=OFF"); UsbongUtils.IS_IN_AUTO_PLAY_MODE=false; } else if (i==UsbongConstants.AUTO_LOOP) { out.println("IS_IN_AUTO_LOOP_MODE=OFF"); UsbongUtils.IS_IN_AUTO_LOOP_MODE=false; } } } out.close(); //remember to close //copy temp file to actual usbong.config file InputStreamReader reader2 = UsbongUtils.getFileFromSDCardAsReader(UsbongUtils.BASE_FILE_PATH + "usbong.config"+"TEMP"); BufferedReader br2 = new BufferedReader(reader2); String currLineString2; //write to actual usbong.config file PrintWriter out2 = UsbongUtils.getFileFromSDCardAsWriter(UsbongUtils.BASE_FILE_PATH + "usbong.config"); while((currLineString2=br2.readLine())!=null) { out2.println(currLineString2); } out2.close(); UsbongUtils.deleteRecursive(new File(UsbongUtils.BASE_FILE_PATH + "usbong.config"+"TEMP")); } catch(Exception e) { e.printStackTrace(); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { // Your code when user clicked on Cancel } }).create(); inAppSettingsDialog.show(); return true; */ case (R.id.about): new AlertDialog.Builder(UsbongDecisionTreeEngineActivity.this).setTitle("About") .setMessage(UsbongUtils.readTextFileInAssetsFolder(UsbongDecisionTreeEngineActivity.this, "credits.txt")) //don't add a '/', otherwise the file would not be found .setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).show(); return true; case (R.id.account): final EditText firstName = new EditText(this); firstName.setHint("First Name"); final EditText surName = new EditText(this); surName.setHint("Surname"); final EditText contactNumber = new EditText(this); contactNumber.setHint("Contact Number"); contactNumber.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); //added by Mike, 20170223 final RadioGroup preference = new RadioGroup(this); preference.setOrientation(RadioGroup.HORIZONTAL); RadioButton meetup = new AppCompatRadioButton(this); meetup.setText("Meet-up"); preference.addView(meetup); RadioButton shipping = new AppCompatRadioButton(this); shipping.setText("Shipping"); preference.addView(shipping); final EditText shippingAddress = new EditText(this); shippingAddress.setHint("Shipping Address"); shippingAddress.setMinLines(5); //added by Mike, 20170223 final RadioGroup modeOfPayment = new RadioGroup(this); modeOfPayment.setOrientation(RadioGroup.VERTICAL); RadioButton cashUponMeetup = new AppCompatRadioButton(this); cashUponMeetup.setText("Cash upon meet-up"); modeOfPayment.addView(cashUponMeetup); RadioButton bankDeposit = new AppCompatRadioButton(this); bankDeposit.setText("Bank Deposit"); modeOfPayment.addView(bankDeposit); RadioButton peraPadala = new AppCompatRadioButton(this); peraPadala.setText("Pera Padala"); modeOfPayment.addView(peraPadala); //Reference: http://stackoverflow.com/questions/23024831/android-shared-preferences-example //; last accessed: 20150609 //answer by Elenasys //added by Mike, 20150207 SharedPreferences prefs = getSharedPreferences(UsbongConstants.MY_ACCOUNT_DETAILS, MODE_PRIVATE); if (prefs != null) { firstName.setText(prefs.getString("firstName", ""));//"" is the default value. surName.setText(prefs.getString("surname", "")); //"" is the default value. contactNumber.setText(prefs.getString("contactNumber", "")); //"" is the default value. //added by Mike, 20170223 ((RadioButton) preference.getChildAt(prefs.getInt("preference", UsbongConstants.defaultPreference))) .setChecked(true); shippingAddress.setText(prefs.getString("shippingAddress", "")); //"" is the default value. //added by Mike, 20170223 ((RadioButton) modeOfPayment .getChildAt(prefs.getInt("modeOfPayment", UsbongConstants.defaultModeOfPayment))) .setChecked(true); } LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); ll.addView(firstName); ll.addView(surName); ll.addView(contactNumber); ll.addView(preference); ll.addView(shippingAddress); ll.addView(modeOfPayment); new AlertDialog.Builder(this).setTitle("My Account").setView(ll) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //ACTION } }).setPositiveButton("Save & Exit", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { //ACTION //Reference: http://stackoverflow.com/questions/23024831/android-shared-preferences-example //; last accessed: 20150609 //answer by Elenasys //added by Mike, 20170207 SharedPreferences.Editor editor = getSharedPreferences( UsbongConstants.MY_ACCOUNT_DETAILS, MODE_PRIVATE).edit(); editor.putString("firstName", firstName.getText().toString()); editor.putString("surname", surName.getText().toString()); editor.putString("contactNumber", contactNumber.getText().toString()); for (int i = 0; i < preference.getChildCount(); i++) { if (((RadioButton) preference.getChildAt(i)).isChecked()) { currPreference = i; } } editor.putInt("preference", currPreference); //added by Mike, 20170223 editor.putString("shippingAddress", shippingAddress.getText().toString()); for (int i = 0; i < modeOfPayment.getChildCount(); i++) { if (((RadioButton) modeOfPayment.getChildAt(i)).isChecked()) { currModeOfPayment = i; } } editor.putInt("modeOfPayment", currModeOfPayment); //added by Mike, 20170223 editor.commit(); } }).show(); return true; case android.R.id.home: //added by Mike, 22 Sept. 2015 /*//commented out by Mike, 201702014; UsbongDecisionTreeEngineActivity is already the main menu processReturnToMainMenuActivity(); */ return true; default: return super.onOptionsItemSelected(item); } }