List of usage examples for android.widget EditText setSelection
public void setSelection(int index)
From source file:com.kaliturin.blacklist.fragments.SMSSendFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // message counter view TextView counterTextView = (TextView) view.findViewById(R.id.text_message_counter); // message body edit EditText messageEdit = (EditText) view.findViewById(R.id.text_message); // init message length counting messageEdit.addTextChangedListener(new MessageLengthCounter(counterTextView)); // phone number edit final EditText numberEdit = (EditText) view.findViewById(R.id.edit_number); // init "add contact" button ImageButton addContactView = (ImageButton) view.findViewById(R.id.button_add_contact); addContactView.setOnClickListener(new View.OnClickListener() { @Override//w w w . j a va2 s. c o m public void onClick(View v) { String number = getNumberFromEdit(numberEdit); if (!number.isEmpty()) { // add number to contacts list addRowToContactsList(number, ""); } else { // open menu dialog showAddContactsMenuDialog(); } numberEdit.setText(""); } }); // init "send" button ImageButton sendButton = (ImageButton) view.findViewById(R.id.button_send); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (sendSMSMessage()) { finishActivity(Activity.RESULT_OK); } } }); // apply arguments if (savedInstanceState == null) { // get contact from arguments Bundle arguments = getArguments(); if (arguments != null) { String name = arguments.getString(CONTACT_NAME); if (name == null) { name = ""; } String number = arguments.getString(CONTACT_NUMBER); if (number != null) { // add row to contacts list addRowToContactsList(number, name); } String body = arguments.getString(SMS_MESSAGE_BODY); if (body != null) { messageEdit.setText(body); messageEdit.setSelection(body.length()); } } } }
From source file:org.anhonesteffort.flock.EditAutoRenewActivity.java
private void initCardNumberHelper() { Log.d(TAG, "initCardNumberHelper()"); final EditText cardNumberView = (EditText) findViewById(R.id.card_number); final EditText cardExpirationView = (EditText) findViewById(R.id.card_expiration); final CheckBox autoRenewIsEnabled = (CheckBox) findViewById(R.id.checkbox_enable_auto_renew); cardNumberView.setOnTouchListener(new View.OnTouchListener() { @Override/*from www.j av a 2 s . co m*/ public boolean onTouch(View v, MotionEvent event) { if (cardNumberView.getText() != null && cardNumberView.getText().toString().contains("*")) { cardNumberView.setText(""); } if (autoRenewIsEnabled.isChecked()) handleInitFormForEditing(); return false; } }); if (cardNumberTextWatcher != null) cardNumberView.removeTextChangedListener(cardNumberTextWatcher); cardNumberTextWatcher = new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { String cardNumber = s.toString().replace(" ", ""); String formattedCardNumber = ""; for (int i = 0; i < cardNumber.length(); i++) { if (i > 0 && i % 4 == 0) formattedCardNumber += " "; formattedCardNumber += cardNumber.charAt(i); } cardNumberView.removeTextChangedListener(this); cardNumberView.setText(formattedCardNumber); cardNumberView.setSelection(formattedCardNumber.length()); cardNumberView.addTextChangedListener(this); if (!cardNumber.contains("*") && cardNumber.length() == 16) cardExpirationView.requestFocus(); } }; cardNumberView.addTextChangedListener(cardNumberTextWatcher); }
From source file:com.httrack.android.HTTrackActivity.java
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { Log.d(getClass().getSimpleName(), "onActivityResult"); super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case ACTIVITY_OPTIONS: if (resultCode == Activity.RESULT_OK) { // Load modified map loadParcelable(data.getParcelableExtra("com.httrack.android.map")); }// ww w.j a v a 2 s . c o m break; case ACTIVITY_FILE_CHOOSER: if (resultCode == Activity.RESULT_OK) { // Load modified map final String path = data.getStringExtra("com.httrack.android.rootFile"); setBasePath(path); } break; case ACTIVITY_PROJECT_NAME_CHOOSER: if (resultCode == Activity.RESULT_OK) { final String projectName = data.getStringExtra("com.httrack.android.projectName"); final EditText name = EditText.class.cast(this.findViewById(R.id.fieldProjectName)); name.setText(projectName); name.setSelection(projectName.length()); name.requestFocus(); } break; case ACTIVITY_CLEANUP: if (resultCode == Activity.RESULT_OK) { final boolean rootWasDeleted = data.getBooleanExtra("com.httrack.android.rootPathWasDeleted", false); // Exit because otherwise we can't recreate the directory (!) if (rootWasDeleted && android.os.Build.VERSION.SDK_INT >= VERSION_CODES.KITKAT) { Log.w("httrack", "exiting because root path was deleted (Android >= Kitkat issue)"); // restartActivity(); finish(); // darn, this is not clean, but otherwise restarting the activity // won't be enough. I suspect FUSE-related issue here System.exit(0); } } break; } }
From source file:de.ub0r.android.websms.WebSMS.java
/** * Create a Emoticons {@link Dialog}.//from ww w . j av a2 s.c o m * * @return Emoticons {@link Dialog} */ private Dialog createEmoticonsDialog() { final Dialog d = new Dialog(this); d.setTitle(R.string.emo_); d.setContentView(R.layout.emo); d.setCancelable(true); final String[] emoticons = this.getResources().getStringArray(R.array.emoticons); final GridView gridview = (GridView) d.findViewById(R.id.gridview); gridview.setAdapter(new BaseAdapter() { // references to our images // keep order and count synced with string-array! private Integer[] mThumbIds = { R.drawable.emo_im_angel, R.drawable.emo_im_cool, R.drawable.emo_im_crying, R.drawable.emo_im_foot_in_mouth, R.drawable.emo_im_happy, R.drawable.emo_im_kissing, R.drawable.emo_im_laughing, R.drawable.emo_im_lips_are_sealed, R.drawable.emo_im_money_mouth, R.drawable.emo_im_sad, R.drawable.emo_im_surprised, R.drawable.emo_im_tongue_sticking_out, R.drawable.emo_im_undecided, R.drawable.emo_im_winking, R.drawable.emo_im_wtf, R.drawable.emo_im_yelling }; @Override public long getItemId(final int position) { return 0; } @Override public Object getItem(final int position) { return null; } @Override public int getCount() { return this.mThumbIds.length; } @Override public View getView(final int position, final View convertView, final ViewGroup parent) { ImageView imageView; if (convertView == null) { // if it's not recycled, // initialize some attributes imageView = new ImageView(WebSMS.this); imageView.setLayoutParams(new GridView.LayoutParams(EMOTICONS_SIZE, EMOTICONS_SIZE)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(EMOTICONS_PADDING, EMOTICONS_PADDING, EMOTICONS_PADDING, EMOTICONS_PADDING); } else { imageView = (ImageView) convertView; } imageView.setImageResource(this.mThumbIds[position]); return imageView; } }); gridview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> adapter, final View v, final int id, final long arg3) { EditText et = WebSMS.this.etText; final String e = emoticons[id]; int i = et.getSelectionStart(); int j = et.getSelectionEnd(); if (i > j) { int x = i; i = j; j = x; } String t = et.getText().toString(); et.setText(t.substring(0, i) + e + t.substring(j)); et.setSelection(i + e.length()); d.dismiss(); et.requestFocus(); } }); return d; }
From source file:com.smc.tw.waltz.MainActivity.java
private void showRenameDeviceDialog(int index) { if (DEBUG)//www. j av a 2s .c om Log.d(TAG, "showRenameDeviceDialog i:" + index); final WaltzDevice device = MainApplication.getWaltzDevice(index); LayoutInflater inflater = LayoutInflater.from(MainActivity.this); View dialogView = inflater.inflate(R.layout.dialog_edit_device, null); AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog); final EditText deviceNameText = (EditText) dialogView.findViewById(R.id.text_device_name); String name = device.getName(); deviceNameText.setText(name); deviceNameText.setSelection((name.length() > 0) ? (name.length()) : 0); builder.setIcon(R.drawable.ic_launcher); builder.setTitle(R.string.dialog_edit_device); builder.setView(dialogView); builder.setCancelable(false); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int id) { String deviceName = deviceNameText.getText().toString(); if (deviceName != null && deviceName.length() > 0) { device.setName(deviceName); MainApplication.renameWaltzDevice(index, deviceName); // rename device name in lcoud MainApplication.saveDeviceList(); mDeviceListFragment.notifyDataSetChanged(); } } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int id) { } }); builder.create().show(); }
From source file:com.amaze.filemanager.fragments.MainFragment.java
/** * Show dialog to rename a file/*w w w .j a v a 2 s . c o m*/ * * @param f the file to rename */ public void rename(final HybridFileParcelable f) { MaterialDialog renameDialog = GeneralDialogCreation.showNameDialog(getMainActivity(), "", f.getName(), getResources().getString(R.string.rename), getResources().getString(R.string.save), null, getResources().getString(R.string.cancel), (dialog, which) -> { EditText textfield = dialog.getCustomView().findViewById(R.id.singleedittext_input); String name1 = textfield.getText().toString(); if (f.isSmb()) { if (f.isDirectory() && !name1.endsWith("/")) name1 = name1 + "/"; } getMainActivity().mainActivityHelper.rename(openMode, f.getPath(), CURRENT_PATH + "/" + name1, getActivity(), getMainActivity().isRootExplorer()); }, (text) -> { boolean isValidFilename = FileUtil.isValidFilename(text); if (!isValidFilename) { return new WarnableTextInputValidator.ReturnState( WarnableTextInputValidator.ReturnState.STATE_ERROR, R.string.invalid_name); } else if (text.length() < 1) { return new WarnableTextInputValidator.ReturnState( WarnableTextInputValidator.ReturnState.STATE_ERROR, R.string.field_empty); } return new WarnableTextInputValidator.ReturnState(); }); // place cursor at the starting of edit text by posting a runnable to edit text // this is done because in case android has not populated the edit text layouts yet, it'll // reset calls to selection if not posted in message queue EditText textfield = renameDialog.getCustomView().findViewById(R.id.singleedittext_input); textfield.post(() -> { if (!f.isDirectory()) { textfield.setSelection(f.getNameString(getContext()).length()); } }); }
From source file:com.android2.calculator3.EventListener.java
@Override public void onClick(View view) { vibrate();//from www . ja v a 2 s.c o m View v; EditText active; int id = view.getId(); switch (id) { case R.id.del: mHandler.onDelete(); break; case R.id.clear: mHandler.onClear(); break; case R.id.equal: if (mHandler.getText().contains(mX) || mHandler.getText().contains(mY)) { if (!mHandler.getText().contains("=")) { mHandler.insert("="); returnToBasic(); } break; } mHandler.onEnter(); break; case R.id.hex: try { mHandler.setText(mHandler.getBaseModule().setBase(mHandler.getText().toString(), Base.HEXADECIMAL)); } catch (SyntaxException e) { e.printStackTrace(); } applyBannedResources(Base.HEXADECIMAL); break; case R.id.bin: try { mHandler.setText(mHandler.getBaseModule().setBase(mHandler.getText().toString(), Base.BINARY)); } catch (SyntaxException e) { e.printStackTrace(); } applyBannedResources(Base.BINARY); break; case R.id.dec: try { mHandler.setText(mHandler.getBaseModule().setBase(mHandler.getText().toString(), Base.DECIMAL)); } catch (SyntaxException e) { e.printStackTrace(); } applyBannedResources(Base.DECIMAL); break; case R.id.matrix: mHandler.insert(MatrixView.getPattern()); returnToBasic(); break; case R.id.matrix_inverse: mHandler.insert(MatrixInverseView.PATTERN); returnToBasic(); break; case R.id.matrix_transpose: mHandler.insert(MatrixTransposeView.PATTERN); returnToBasic(); break; case R.id.plus_row: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().addRow(); break; case R.id.minus_row: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().removeRow(); break; case R.id.plus_col: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().addColumn(); break; case R.id.minus_col: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().removeColumn(); break; case R.id.next: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); active = mHandler.mDisplay.getActiveEditText(); if (active.getSelectionStart() == active.getText().length()) { v = mHandler.mDisplay.getActiveEditText().focusSearch(View.FOCUS_FORWARD); if (v != null) v.requestFocus(); active = mHandler.mDisplay.getActiveEditText(); active.setSelection(0); } else { active.setSelection(active.getSelectionStart() + 1); } break; case R.id.parentheses: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); if (mHandler.getText().contains("=")) { String[] equation = mHandler.getText().split("="); if (equation.length > 1) { mHandler.setText(equation[0] + "=(" + equation[1] + ")"); } else { mHandler.setText(equation[0] + "=()"); } } else { mHandler.setText("(" + mHandler.getText() + ")"); } returnToBasic(); break; case R.id.mod: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); if (mHandler.getText().contains("=")) { String[] equation = mHandler.getText().split("="); if (equation.length > 1) { mHandler.setText(equation[0] + "=" + mModString + "(" + equation[1] + ","); } else { mHandler.insert(mModString + "("); } } else { if (mHandler.getText().length() > 0) { mHandler.setText(mModString + "(" + mHandler.getText() + ","); } else { mHandler.insert(mModString + "("); } } returnToBasic(); break; case R.id.easter: Toast.makeText(mContext, R.string.easter_egg, Toast.LENGTH_SHORT).show(); break; case R.id.zoomIn: mGraphDisplay.zoomIn(); break; case R.id.zoomOut: mGraphDisplay.zoomOut(); break; case R.id.zoomReset: mGraphDisplay.zoomReset(); break; default: if (view instanceof Button) { String text = ((Button) view).getText().toString(); if (text.equals(mDX) || text.equals(mDY)) { // Do nothing } else if (text.length() >= 2) { // Add paren after sin, cos, ln, etc. from buttons text += "("; } mHandler.insert(text); returnToBasic(); } } }
From source file:com.android.calculator2.EventListener.java
@Override public void onClick(View view) { View v;/* w w w . java 2 s . com*/ EditText active; int id = view.getId(); switch (id) { case R.id.del: mHandler.onDelete(); break; case R.id.clear: mHandler.onClear(); break; case R.id.equal: if (mHandler.getText().contains(mX) || mHandler.getText().contains(mY)) { if (!mHandler.getText().contains("=")) { mHandler.insert("="); returnToBasic(); } break; } mHandler.onEnter(); break; case R.id.hex: mHandler.setText(mHandler.mBaseModule.setMode(Mode.HEXADECIMAL)); view.setSelected(true); ((View) view.getParent()).findViewById(R.id.bin).setSelected(false); ((View) view.getParent()).findViewById(R.id.dec).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.HEXADECIMAL); break; case R.id.bin: mHandler.setText(mHandler.mBaseModule.setMode(Mode.BINARY)); view.setSelected(true); ((View) view.getParent()).findViewById(R.id.hex).setSelected(false); ((View) view.getParent()).findViewById(R.id.dec).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.BINARY); break; case R.id.dec: mHandler.setText(mHandler.mBaseModule.setMode(Mode.DECIMAL)); view.setSelected(true); ((View) view.getParent()).findViewById(R.id.bin).setSelected(false); ((View) view.getParent()).findViewById(R.id.hex).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.DECIMAL); break; case R.id.matrix: mHandler.insert(MatrixView.getPattern(mContext)); returnToBasic(); break; case R.id.matrix_inverse: mHandler.insert(MatrixInverseView.PATTERN); returnToBasic(); break; case R.id.matrix_transpose: mHandler.insert(MatrixTransposeView.PATTERN); returnToBasic(); break; case R.id.plus_row: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().addRow(); break; case R.id.minus_row: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().removeRow(); break; case R.id.plus_col: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().addColumn(); break; case R.id.minus_col: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().removeColumn(); break; case R.id.next: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); active = mHandler.mDisplay.getActiveEditText(); if (active.getSelectionStart() == active.getText().length()) { v = mHandler.mDisplay.getActiveEditText().focusSearch(View.FOCUS_FORWARD); if (v != null) v.requestFocus(); active = mHandler.mDisplay.getActiveEditText(); active.setSelection(0); } else { active.setSelection(active.getSelectionStart() + 1); } break; // +/-, changes the sign of the current number. Might be useful later // (but removed for now) // case R.id.sign: // if(mHandler.getText().equals(mErrorString)) mHandler.setText(""); // active = mHandler.mDisplay.getActiveEditText(); // int selection = active.getSelectionStart(); // if(active.getText().toString().matches(Logic.NUMBER)) { // if(active.getText().toString().startsWith(String.valueOf(Logic.MINUS))) // { // active.setText(active.getText().toString().substring(1)); // selection--; // } // else { // active.setText(Logic.MINUS + active.getText().toString()); // selection++; // } // if(selection > active.length()) selection--; // if(selection < 0) selection = 0; // active.setSelection(selection); // } // break; case R.id.parentheses: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); if (mHandler.getText().contains("=")) { String[] equation = mHandler.getText().split("="); if (equation.length > 1) { mHandler.setText(equation[0] + "=(" + equation[1] + ")"); } else { mHandler.setText(equation[0] + "=()"); } } else { mHandler.setText("(" + mHandler.getText() + ")"); } returnToBasic(); break; case R.id.mod: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); if (mHandler.getText().contains("=")) { String[] equation = mHandler.getText().split("="); if (equation.length > 1) { mHandler.setText(equation[0] + "=" + mModString + "(" + equation[1] + ","); } else { mHandler.insert(mModString + "("); } } else { if (mHandler.getText().length() > 0) { mHandler.setText(mModString + "(" + mHandler.getText() + ","); } else { mHandler.insert(mModString + "("); } } returnToBasic(); break; case R.id.easter: Toast.makeText(mContext, R.string.easter_egg, Toast.LENGTH_SHORT).show(); break; default: if (view instanceof Button) { String text = ((Button) view).getText().toString(); if (text.equals(mDX) || text.equals(mDY)) { // Do nothing } else if (text.length() >= 2) { // Add paren after sin, cos, ln, etc. from buttons text += "("; } mHandler.insert(text); returnToBasic(); } } }
From source file:com.numix.calculator.EventListener.java
@Override public void onClick(View view) { View v;//from w ww .j a v a2 s. c o m EditText active; int id = view.getId(); switch (id) { case R.id.del: mHandler.onDelete(); break; case R.id.clear: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { deleteAnimation(view); } break; case R.id.equal: if (mHandler.getText().contains(mX) || mHandler.getText().contains(mY)) { if (!mHandler.getText().contains("=")) { mHandler.insert("="); returnToBasic(); } break; } mHandler.onEnter(); break; case R.id.hex: mHandler.setText(mHandler.mBaseModule.setMode(Mode.HEXADECIMAL)); view.setSelected(true); ((View) view.getParent()).findViewById(R.id.bin).setSelected(false); ((View) view.getParent()).findViewById(R.id.dec).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.HEXADECIMAL); break; case R.id.bin: mHandler.setText(mHandler.mBaseModule.setMode(Mode.BINARY)); view.setSelected(true); ((View) view.getParent()).findViewById(R.id.hex).setSelected(false); ((View) view.getParent()).findViewById(R.id.dec).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.BINARY); break; case R.id.dec: mHandler.setText(mHandler.mBaseModule.setMode(Mode.DECIMAL)); view.setSelected(true); ((View) view.getParent()).findViewById(R.id.bin).setSelected(false); ((View) view.getParent()).findViewById(R.id.hex).setSelected(false); applyAllBannedResources(mHandler.mBaseModule, Mode.DECIMAL); break; case R.id.matrix: mHandler.insert(MatrixView.getPattern(mContext)); returnToBasic(); break; case R.id.matrix_inverse: mHandler.insert(MatrixInverseView.PATTERN); returnToBasic(); break; case R.id.matrix_transpose: mHandler.insert(MatrixTransposeView.PATTERN); returnToBasic(); break; case R.id.plus_row: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().addRow(); break; case R.id.minus_row: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().removeRow(); break; case R.id.plus_col: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().addColumn(); break; case R.id.minus_col: v = mHandler.mDisplay.getActiveEditText(); if (v instanceof MatrixEditText) ((MatrixEditText) v).getMatrixView().removeColumn(); break; case R.id.next: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); active = mHandler.mDisplay.getActiveEditText(); if (active.getSelectionStart() == active.getText().length()) { v = mHandler.mDisplay.getActiveEditText().focusSearch(View.FOCUS_RIGHT); if (v != null) v.requestFocus(); active = mHandler.mDisplay.getActiveEditText(); active.setSelection(0); } else { active.setSelection(active.getSelectionStart() + 1); } break; // +/-, changes the sign of the current number. Might be useful later // (but removed for now) // case R.id.sign: // if(mHandler.getText().equals(mErrorString)) mHandler.setText(""); // active = mHandler.mDisplay.getActiveEditText(); // int selection = active.getSelectionStart(); // if(active.getText().toString().matches(Logic.NUMBER)) { // if(active.getText().toString().startsWith(String.valueOf(Logic.MINUS))) // { // active.setText(active.getText().toString().substring(1)); // selection--; // } // else { // active.setText(Logic.MINUS + active.getText().toString()); // selection++; // } // if(selection > active.length()) selection--; // if(selection < 0) selection = 0; // active.setSelection(selection); // } // break; case R.id.parentheses: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); if (mHandler.getText().contains("=")) { String[] equation = mHandler.getText().split("="); if (equation.length > 1) { mHandler.setText(equation[0] + "=(" + equation[1] + ")"); } else { mHandler.setText(equation[0] + "=()"); } } else { mHandler.setText("(" + mHandler.getText() + ")"); } returnToBasic(); break; case R.id.mod: if (mHandler.getText().equals(mErrorString)) mHandler.setText(""); if (mHandler.getText().contains("=")) { String[] equation = mHandler.getText().split("="); if (equation.length > 1) { mHandler.setText(equation[0] + "=" + mModString + "(" + equation[1] + ","); } else { mHandler.insert(mModString + "("); } } else { if (mHandler.getText().length() > 0) { mHandler.setText(mModString + "(" + mHandler.getText() + ","); } else { mHandler.insert(mModString + "("); } } returnToBasic(); break; case R.id.easter: Toast.makeText(mContext, R.string.easter_egg, Toast.LENGTH_SHORT).show(); break; default: if (view instanceof Button) { String text = ((Button) view).getText().toString(); if (text.equals(mDX) || text.equals(mDY)) { // Do nothing } else if (text.length() >= 2) { // Add paren after sin, cos, ln, etc. from buttons text += "("; } mHandler.insert(text); returnToBasic(); } } }
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
public void scanRemoteNetworkDlg(final NotifyEvent p_ntfy, String port_number, boolean scan_start) { //??// w ww . ja v a 2 s . co m final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.scan_remote_ntwk_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_title_view); final TextView title = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok); final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel); final TextView tvmsg = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_msg); final TextView tv_result = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_scan_result_title); tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_press_scan_btn)); tv_result.setVisibility(TextView.GONE); final String from = CommonUtilities.getLocalIpAddress(); String subnet = from.substring(0, from.lastIndexOf(".")); String subnet_o1, subnet_o2, subnet_o3; subnet_o1 = subnet.substring(0, subnet.indexOf(".")); subnet_o2 = subnet.substring(subnet.indexOf(".") + 1, subnet.lastIndexOf(".")); subnet_o3 = subnet.substring(subnet.lastIndexOf(".") + 1, subnet.length()); final EditText baEt1 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o1); final EditText baEt2 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o2); final EditText baEt3 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o3); final EditText baEt4 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o4); final EditText eaEt4 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_end_address_o4); baEt1.setText(subnet_o1); baEt2.setText(subnet_o2); baEt3.setText(subnet_o3); baEt4.setText("1"); baEt4.setSelection(1); eaEt4.setText("254"); baEt4.requestFocus(); final CheckedTextView ctv_use_port_number = (CheckedTextView) dialog .findViewById(R.id.scan_remote_ntwk_ctv_use_port); final EditText et_port_number = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_port_number); CommonDialog.setDlgBoxSizeLimit(dialog, true); if (port_number.equals("")) { et_port_number.setEnabled(false); ctv_use_port_number.setChecked(false); } else { et_port_number.setEnabled(true); et_port_number.setText(port_number); ctv_use_port_number.setChecked(true); } ctv_use_port_number.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ctv_use_port_number.toggle(); boolean isChecked = ctv_use_port_number.isChecked(); et_port_number.setEnabled(isChecked); } }); final NotifyEvent ntfy_lv_click = new NotifyEvent(mContext); ntfy_lv_click.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { dialog.dismiss(); p_ntfy.notifyToListener(true, o); } @Override public void negativeResponse(Context c, Object[] o) { } }); final ArrayList<ScanAddressResultListItem> ipAddressList = new ArrayList<ScanAddressResultListItem>(); // ScanAddressResultListItem li=new ScanAddressResultListItem(); // li.server_name=mContext.getString(R.string.msgs_ip_address_no_address); // ipAddressList.add(li); final ListView lv = (ListView) dialog.findViewById(R.id.scan_remote_ntwk_scan_result_list); final AdapterScanAddressResultList adap = new AdapterScanAddressResultList(mContext, R.layout.scan_address_result_list_item, ipAddressList, ntfy_lv_click); lv.setAdapter(adap); lv.setScrollingCacheEnabled(false); lv.setScrollbarFadingEnabled(false); //SCAN? btn_scan.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ipAddressList.clear(); NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { if (ipAddressList.size() < 1) { tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_not_detected)); tv_result.setVisibility(TextView.GONE); } else { tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_select_detected_host)); tv_result.setVisibility(TextView.VISIBLE); } // adap.clear(); // for (int i=0;i<ipAddressList.size();i++) // adap.add(ipAddressList.get(i)); } @Override public void negativeResponse(Context c, Object[] o) { } }); if (auditScanAddressRangeValue(dialog)) { tv_result.setVisibility(TextView.GONE); String ba1 = baEt1.getText().toString(); String ba2 = baEt2.getText().toString(); String ba3 = baEt3.getText().toString(); String ba4 = baEt4.getText().toString(); String ea4 = eaEt4.getText().toString(); String subnet = ba1 + "." + ba2 + "." + ba3; int begin_addr = Integer.parseInt(ba4); int end_addr = Integer.parseInt(ea4); scanRemoteNetwork(dialog, lv, adap, ipAddressList, subnet, begin_addr, end_addr, ntfy); } else { //error } } }); //CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); p_ntfy.notifyToListener(false, null); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); dialog.show(); if (scan_start) btn_scan.performClick(); }