List of usage examples for android.text Editable length
int length();
From source file:org.adaway.ui.WhitelistFragment.java
/** * Edit entry based on selection in context menu * * @param info//from w w w .j a va 2 s . c om */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; CheckBox cBox = (CheckBox) v.findViewWithTag(position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_whitelist_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); inputEditText.setText(cBox.getText()); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidWhitelistHostname(input)) { ProviderHelper.updateWhitelistItemHostname(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(org.adaway.R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.adawaycn.ui.WhitelistFragment.java
/** * Edit entry based on selection in context menu * * @param info/* w ww. jav a 2 s .c o m*/ */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; CheckBox cBox = (CheckBox) v.findViewWithTag(position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_whitelist_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); inputEditText.setText(cBox.getText()); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidWhitelistHostname(input)) { ProviderHelper.updateWhitelistItemHostname(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.adawaycn.ui.BlacklistFragment.java
/** * Edit entry based on selection in context menu * /*from w w w. ja va 2s. com*/ * @param info */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; CheckBox cBox = (CheckBox) v.findViewWithTag(position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_hostname_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_hostname); inputEditText.setText(cBox.getText()); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (org.adawaycn.util.RegexUtils.isValidHostname(input)) { org.adawaycn.provider.ProviderHelper.updateBlacklistItemHostname(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_hostname_title); alertDialog.setMessage(getString(R.string.no_hostname)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:com.wart.magister.SelectSchoolActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_select_school); // Display the Actionbar arrow getActionBar().setDisplayHomeAsUpEnabled(false); ((EditText) findViewById(R.id.select_school_edittext)).addTextChangedListener(new TextWatcher() { @Override/*from w w w .j ava 2s .co m*/ public void afterTextChanged(Editable e) { if (e.length() > 0) { showProgress(true); if (mRetrieveSchoolsRequest != null && !mRetrieveSchoolsRequest.isFinished()) mRetrieveSchoolsRequest.cancel(true); mRetrieveSchoolsRequest = Global.AsyncHttpClient.get( "http://app.schoolmaster.nl/schoolLicentieService.asmx/Search?term=" + e.toString().replace(" ", "%20").toLowerCase().trim(), new TextHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, String responseBody) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser saxParser = factory.newSAXParser(); mRetrievedSchools.clear(); DefaultHandler handler = new DefaultHandler() { private String currentValue; private School currentSchool; @Override public void characters(char ch[], int start, int length) throws SAXException { currentValue = new String(ch, start, length); } @Override public void endElement(String uri, String localName, String qName) throws SAXException { if (qName.equalsIgnoreCase("medius")) currentSchool.URL = currentValue; else if (qName.equalsIgnoreCase("licentie")) currentSchool.License = currentValue; } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equalsIgnoreCase("school")) { currentSchool = new School(); mRetrievedSchools.add(currentSchool); } } }; saxParser.parse(new InputSource(new StringReader(responseBody)), handler); String[] names = new String[mRetrievedSchools.size()]; for (int i = 0; i < mRetrievedSchools.size(); i++) names[i] = mRetrievedSchools.get(i).License; mSchoolsList.setAdapter(new ArrayAdapter<String>(SelectSchoolActivity.this, android.R.layout.simple_list_item_1, names)); } catch (Exception e) { Log.e(TAG, "Error in onSuccess", e); } } @Override public void onFailure(String responseBody, Throwable error) { mSchoolsList.setAdapter(null); Log.e(TAG, "Retrieving schools failed", error); } @Override public void onFinish() { showProgress(false); } }); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); mSchoolsList = (ListView) findViewById(R.id.select_school_listview); mSchoolsList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (mTestMediusRequest != null && !mTestMediusRequest.isFinished()) mTestMediusRequest.cancel(true); ((TextView) findViewById(R.id.select_school_status_message)).setText("Testing school..."); showProgress(true); Data.set(Data.MEDIUSURL, Data.buildMediusUrl(mRetrievedSchools.get(position).URL)); Log.v(TAG, "posting to " + Data.getString(Data.MEDIUSURL)); byte[] request = new byte[54]; request[0] = 0x52; request[1] = 0x4f; request[2] = 49; request[3] = 48; request[4] = 55; request[12] = 95; request[13] = -38; request[14] = -109; request[15] = 13; request[16] = -14; request[17] = 92; request[18] = 7; request[19] = 86; request[20] = -77; request[21] = -23; request[22] = 9; request[23] = 22; request[24] = 71; request[25] = -53; request[26] = -81; request[27] = 45; request[28] = 5; request[32] = 76; request[33] = 111; request[34] = 103; request[35] = 105; request[36] = 110; request[37] = 13; request[41] = 71; request[42] = 101; request[43] = 116; request[44] = 83; request[45] = 99; request[46] = 104; request[47] = 111; request[48] = 111; request[49] = 108; request[50] = 78; request[51] = 97; request[52] = 109; request[53] = 101; Log.i(TAG, "Testing the url..."); mTestMediusRequest = Global.AsyncHttpClient.post(SelectSchoolActivity.this, Data.getString(Data.MEDIUSURL), new ByteArrayEntity(request), "text/html", new BinaryHttpResponseHandler(new String[] { "text/html" }) { @Override public void onSuccess(byte[] binaryData) { if (binaryData != null) { Log.i(TAG, "Received " + binaryData.length + " bytes of data"); Serializer s = new Serializer(binaryData); try { if (s.readROHeader(null, "login", "getschoolname")) { Data.set(Data.LICENSE, s.readString()); MediusCall.setLicense(Data.getString(Data.LICENSE)); } else Log.e(TAG, "Geblokkeerd door webserver"); } catch (Exception e) { Log.e(TAG, "Error in TestMedius.onSuccess", e); } Log.i(TAG, "Succesfully tested the medius"); SelectSchoolActivity.this.startActivity( new Intent(SelectSchoolActivity.this, LoginActivity.class)); } else Log.e(TAG, "TestMedius timed out"); } @Override public void onFailure(int statusCode, Header[] headers, byte[] binaryData, Throwable error) { Log.e(TAG, "Error in TestMedius.onFaillure", error); } @Override public void onFinish() { showProgress(false); } }); } }); mSearchLayout = (LinearLayout) findViewById(R.id.select_school_status_layout); }
From source file:sssemil.com.hostsaway.ui.HostsSourcesFragment.java
/** * Edit entry based on selection in context menu * * @param info/*from ww w . j a v a 2 s. c o m*/ */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; TextView urlTextView = (TextView) v.findViewWithTag("url_" + position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_url_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_url); // set text from list inputEditText.setText(urlTextView.getText()); inputEditText.setInputType(InputType.TYPE_TEXT_VARIATION_URI); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidUrl(input)) { // update in db ProviderHelper.updateHostsSourceUrl(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_url_title); alertDialog.setMessage(getString(sssemil.com.hostsaway.R.string.no_url)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.adaway.ui.HostsSourcesFragment.java
/** * Edit entry based on selection in context menu * * @param info/* www . java 2s. c om*/ */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; TextView urlTextView = (TextView) v.findViewWithTag("url_" + position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_url_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_url); // set text from list inputEditText.setText(urlTextView.getText()); inputEditText.setInputType(InputType.TYPE_TEXT_VARIATION_URI); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidUrl(input)) { // update in db ProviderHelper.updateHostsSourceUrl(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_url_title); alertDialog.setMessage(getString(org.adaway.R.string.no_url)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.adawaycn.ui.HostsSourcesFragment.java
/** * Edit entry based on selection in context menu * * @param info/*from w w w . j a va 2 s . c o m*/ */ private void menuEditEntry(AdapterContextMenuInfo info) { mCurrentRowId = info.id; // set global RowId to row id from cursor to use inside save button int position = info.position; View v = info.targetView; TextView urlTextView = (TextView) v.findViewWithTag("url_" + position); AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); builder.setCancelable(true); builder.setTitle(getString(R.string.checkbox_list_edit_dialog_title)); // build view from layout LayoutInflater factory = LayoutInflater.from(mActivity); final View dialogView = factory.inflate(R.layout.lists_url_dialog, null); final EditText inputEditText = (EditText) dialogView.findViewById(R.id.list_dialog_url); // set text from list inputEditText.setText(urlTextView.getText()); inputEditText.setInputType(InputType.TYPE_TEXT_VARIATION_URI); // move cursor to end of EditText Editable inputEditContent = inputEditText.getText(); inputEditText.setSelection(inputEditContent.length()); builder.setView(dialogView); builder.setPositiveButton(getResources().getString(R.string.button_save), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); String input = inputEditText.getText().toString(); if (RegexUtils.isValidUrl(input)) { // update in db ProviderHelper.updateHostsSourceUrl(mActivity, mCurrentRowId, input); } else { AlertDialog alertDialog = new AlertDialog.Builder(mActivity).create(); alertDialog.setIcon(android.R.drawable.ic_dialog_alert); alertDialog.setTitle(R.string.no_url_title); alertDialog.setMessage(getString(R.string.no_url)); alertDialog.setButton(getString(R.string.button_close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sum) { dlg.dismiss(); } }); alertDialog.show(); } } }); builder.setNegativeButton(getResources().getString(R.string.button_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:org.thaliproject.nativetest.app.fragments.SettingsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_settings, container, false); mSettings = Settings.getInstance(view.getContext()); mSettings.load();/*from w w w. j a v a2s . co m*/ mConnectionTimeoutEditText = (EditText) view.findViewById(R.id.connectionTimeoutEditText); mConnectionTimeoutEditText.setText(String.valueOf(mSettings.getConnectionTimeout())); mConnectionTimeoutEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { if (editable.length() > 0) { try { mSettings.setConnectionTimeout(Long.parseLong(editable.toString())); } catch (NumberFormatException e) { Log.e(TAG, e.getMessage(), e); mConnectionTimeoutEditText.setText(String.valueOf(mSettings.getConnectionTimeout())); } } } }); mPortNumberEditText = (EditText) view.findViewById(R.id.portNumberEditText); mPortNumberEditText.setText(String.valueOf(mSettings.getPortNumber())); mPortNumberEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { if (editable.length() > 0 && !editable.toString().equals("-")) { try { mSettings.setPortNumber(Integer.parseInt(editable.toString())); } catch (NumberFormatException e) { Log.e(TAG, e.getMessage(), e); mPortNumberEditText.setText(String.valueOf(mSettings.getPortNumber())); } } } }); mListenForIncomingConnectionsCheckbox = (CheckBox) view .findViewById(R.id.listenForIncomingConnectionCheckbox); mListenForIncomingConnectionsCheckbox.setChecked(mSettings.getListenForIncomingConnections()); mListenForIncomingConnectionsCheckbox .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { mSettings.setListenForIncomingConnections(b); } }); mHandshakeRequiredCheckbox = (CheckBox) view.findViewById(R.id.handshakeRequiredCheckBox); mHandshakeRequiredCheckbox.setChecked(mSettings.getHandshakeRequired()); mHandshakeRequiredCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { mSettings.setHandshakeRequired(b); } }); mEnableWifiCheckBox = (CheckBox) view.findViewById(R.id.enableWifiCheckBox); mEnableWifiCheckBox.setChecked(mSettings.getEnableWifiDiscovery()); mEnableWifiCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { mSettings.setEnableWifiDiscovery(b); } }); mEnableBleCheckBox = (CheckBox) view.findViewById(R.id.enableBleCheckBox); mEnableBleCheckBox.setChecked(mSettings.getEnableBleDiscovery()); mEnableBleCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { mSettings.setEnableBleDiscovery(b); } }); Spinner spinner = (Spinner) view.findViewById(R.id.advertiseModeSpinner); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(view.getContext(), R.array.advertise_mode_string_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setSelection(mSettings.getAdvertiseMode()); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int index, long l) { mSettings.setAdvertiseMode(index); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); spinner = (Spinner) view.findViewById(R.id.advertiseTxPowerLevelSpinner); adapter = ArrayAdapter.createFromResource(view.getContext(), R.array.advertise_tx_power_level_string_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setSelection(mSettings.getAdvertiseTxPowerLevel()); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int index, long l) { mSettings.setAdvertiseTxPowerLevel(index); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); spinner = (Spinner) view.findViewById(R.id.scanModeSpinner); adapter = ArrayAdapter.createFromResource(view.getContext(), R.array.scan_mode_string_array, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setSelection(mSettings.getScanMode()); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int index, long l) { mSettings.setScanMode(index); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); mBufferSizeEditText = (EditText) view.findViewById(R.id.bufferSizeEditText); mBufferSizeEditText.setText(String.valueOf(mSettings.getBufferSize())); mBufferSizeEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { if (editable.length() > 0) { try { mSettings.setBufferSize(Integer.parseInt(editable.toString())); } catch (NumberFormatException e) { Log.e(TAG, e.getMessage(), e); mBufferSizeEditText.setText(String.valueOf(mSettings.getBufferSize())); } } } }); mDataAmountEditText = (EditText) view.findViewById(R.id.dataAmountEditText); mDataAmountEditText.setText(String.valueOf(mSettings.getDataAmount())); mDataAmountEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { } @Override public void afterTextChanged(Editable editable) { if (editable.length() > 0) { try { mSettings.setDataAmount(Long.parseLong(editable.toString())); } catch (NumberFormatException e) { Log.e(TAG, e.getMessage(), e); mDataAmountEditText.setText(String.valueOf(mSettings.getDataAmount())); } } } }); mEnableAutoConnectCheckBox = (CheckBox) view.findViewById(R.id.autoConnectCheckBox); mEnableAutoConnectCheckBox.setChecked(mSettings.getAutoConnect()); mEnableAutoConnectCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { mSettings.setAutoConnect(b); } }); mEnableAutoConnectEvenWhenIncomingConnectionEstablishedCheckBox = (CheckBox) view .findViewById(R.id.autoConnectEvenWhenIncomingCheckBox); mEnableAutoConnectEvenWhenIncomingConnectionEstablishedCheckBox .setChecked(mSettings.getAutoConnectEvenWhenIncomingConnectionEstablished()); mEnableAutoConnectEvenWhenIncomingConnectionEstablishedCheckBox .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { mSettings.setAutoConnectEvenWhenIncomingConnectionEstablished(b); } }); return view; }
From source file:dk.moerks.ratebeermobile.Rate.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.rate);/*ww w.j av a2 s . com*/ Bundle extras = getIntent().getExtras(); if (extras != null) { beername = extras.getString("BEERNAME"); beerid = extras.getString("BEERID"); } rateCharleftText = (TextView) findViewById(R.id.rate_label_charleft); rateCharleftText.setText(getText(R.string.rate_charleft) + " 75"); EditText rateComment = (EditText) findViewById(R.id.rate_value_comments); rateComment.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { int charNumber = s.length(); int resultNumber = 75 - charNumber; if (resultNumber > 0) { rateCharleftText.setText(getText(R.string.rate_charleft) + " " + resultNumber); } else { rateCharleftText.setText(""); } } }); TextView beernameText = (TextView) findViewById(R.id.rate_label_beername); beernameText.setText(beername); Button rateButton = (Button) findViewById(R.id.rate_button); rateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { EditText comment = (EditText) findViewById(R.id.rate_value_comments); final String commentString = comment.getText().toString(); if (commentString.length() > 74) { Spinner aromaText = (Spinner) findViewById(R.id.rate_value_aroma); Spinner appearanceText = (Spinner) findViewById(R.id.rate_value_appearance); Spinner flavorText = (Spinner) findViewById(R.id.rate_value_flavor); Spinner palateText = (Spinner) findViewById(R.id.rate_value_palate); Spinner overallText = (Spinner) findViewById(R.id.rate_value_overall); final String aromaString = (String) aromaText.getSelectedItem(); final String appearanceString = (String) appearanceText.getSelectedItem(); final String flavorString = (String) flavorText.getSelectedItem(); final String palateString = (String) palateText.getSelectedItem(); final String overallString = (String) overallText.getSelectedItem(); String totalScore = calculateTotalScore(aromaString, appearanceString, flavorString, palateString, overallString); List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("BeerID", beerid)); parameters.add(new BasicNameValuePair("aroma", aromaString)); parameters.add(new BasicNameValuePair("appearance", appearanceString)); parameters.add(new BasicNameValuePair("flavor", flavorString)); parameters.add(new BasicNameValuePair("palate", palateString)); parameters.add(new BasicNameValuePair("overall", overallString)); parameters.add(new BasicNameValuePair("totalscore", totalScore)); parameters.add(new BasicNameValuePair("Comments", commentString)); new SaveRatingTask(Rate.this).execute(parameters.toArray(new NameValuePair[] {})); SharedPreferences prefs = getSharedPreferences(Settings.PREFERENCETAG, 0); if (prefs.getBoolean("rb_twitter_ratings", false)) { new PostTwitterStatusTask(Rate.this).execute(buildTwitterMessage(totalScore)); } finish(); } else { Toast.makeText(Rate.this, R.string.toast_minimum_length, Toast.LENGTH_LONG).show(); } } private String buildTwitterMessage(String score) { return getString(R.string.twitter_rating_message, beername, score, getUserId()); } private String calculateTotalScore(String aromaString, String appearanceString, String flavorString, String palateString, String overallString) { int aroma = Integer.parseInt(aromaString); int appearance = Integer.parseInt(appearanceString); int flavor = Integer.parseInt(flavorString); int palate = Integer.parseInt(palateString); int overall = Integer.parseInt(overallString); int total = (aroma + appearance + flavor + palate + overall); float totalscore = ((float) total) / 10; String result = "" + totalscore; return result; } }); }
From source file:com.dirkgassen.wator.ui.fragment.NewWorld.java
/** * Validate the "initial fish count" {@link EditText}. The text is already provided as a parameter. * * If the text is valid the "initial shark count" {@link EditText} is validated as well to eventually remove an * error that previously existed (e.g., number of initial fish was reduced so that the number of shark are now valid). * * Note that the "initial shark count" {@link EditText} is not validated if the text is invalid to not add * an error message to the "initial shark count" {@link EditText} if this text value is invalid. * @param s text of the "initial fish count" {@link EditText} * @param worldSize size of the world//www. j ava 2 s . c o m */ private void validateInitialFishCount(Editable s, int worldSize) { if (s.length() == 0) { inputs[INITIAL_FISH_COUNT_INPUT].setError(getString(R.string.initial_fish_count_empty_error)); } else { Editable sharkCount = inputs[INITIAL_SHARK_COUNT_INPUT].getText(); int initialFishValue = Integer.valueOf(s.toString()); int initialSharkCount = sharkCount.length() == 0 ? 0 : Integer.valueOf(sharkCount.toString()); int max = worldSize - initialSharkCount; if (max < 0) { max = 0; } if (initialFishValue > max) { inputs[INITIAL_FISH_COUNT_INPUT].setError(getString(R.string.too_many_fish_error, max)); } else { inputs[INITIAL_FISH_COUNT_INPUT].setError(null); if (sharkCount.length() > 0 && initialSharkCount < worldSize - initialFishValue) { inputs[INITIAL_SHARK_COUNT_INPUT].setError(null); } } } }