List of usage examples for android.text Editable toString
public String toString();
From source file:org.tpmkranz.notifyme.MainActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.main_menu_checkaccessibility: prefs.setPrevVersion(0);/*from ww w .ja v a2 s . c o m*/ ((TemporaryStorage) getApplicationContext()).accessGranted(false); finish(); startActivity(getIntent()); return true; case R.id.main_menu_popup: final View view = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.main_menu_popup, null); if (android.os.Build.VERSION.SDK_INT >= 11) view.findViewById(R.id.main_menu_popup_background).setVisibility(View.GONE); ((CheckBox) view.findViewById(R.id.main_menu_popup_background_checkbox)) .setChecked(prefs.isBackgroundColorInverted()); view.findViewById(R.id.main_menu_popup_background_caption) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((CheckBox) view.findViewById(R.id.main_menu_popup_background_checkbox)).toggle(); } }); ((CheckBox) view.findViewById(R.id.main_menu_popup_orientation_checkbox)) .setChecked(prefs.isOrientationFixed()); view.findViewById(R.id.main_menu_popup_orientation_caption) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((CheckBox) view.findViewById(R.id.main_menu_popup_orientation_checkbox)).toggle(); } }); ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r)).setMax(255); ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r)) .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_r)) .setText((progress == 0 ? "" : String.valueOf(progress))); } ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview)) .setImageDrawable(new ColorDrawable(Color.rgb(progress, ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g)) .getProgress(), ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b)) .getProgress()))); } }); ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_r)) .addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { try { if (Integer.parseInt(s.toString()) > 255) { s.replace(0, s.length(), "255"); return; } else if (Integer.parseInt(s.toString()) < 0) { s.replace(0, s.length(), "0"); return; } ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r)) .setProgress(Integer.parseInt(s.toString())); } catch (Exception e) { ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r)).setProgress(0); s.clear(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g)).setMax(255); ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g)) .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_g)) .setText((progress == 0 ? "" : String.valueOf(progress))); } ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview)) .setImageDrawable(new ColorDrawable(Color.rgb( ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r)) .getProgress(), progress, ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b)) .getProgress()))); } }); ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_g)) .addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { try { if (Integer.parseInt(s.toString()) > 255) { s.replace(0, s.length(), "255"); return; } else if (Integer.parseInt(s.toString()) < 0) { s.replace(0, s.length(), "0"); return; } ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g)) .setProgress(Integer.parseInt(s.toString())); } catch (Exception e) { ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g)).setProgress(0); s.clear(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b)).setMax(255); ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b)) .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) { ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_b)) .setText((progress == 0 ? "" : String.valueOf(progress))); } ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview)) .setImageDrawable(new ColorDrawable(Color.rgb( ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r)) .getProgress(), ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g)) .getProgress(), progress))); } }); ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_b)) .addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { try { if (Integer.parseInt(s.toString()) > 255) { s.replace(0, s.length(), "255"); return; } else if (Integer.parseInt(s.toString()) < 0) { s.replace(0, s.length(), "0"); return; } ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b)) .setProgress(Integer.parseInt(s.toString())); } catch (Exception e) { ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b)).setProgress(0); s.clear(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); ((ImageView) view.findViewById(R.id.main_menu_popup_color_preview)) .setImageDrawable(new ColorDrawable(Color.rgb(prefs.getSliderBackgroundR(), prefs.getSliderBackgroundG(), prefs.getSliderBackgroundB()))); ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_r)) .setText(String.valueOf(prefs.getSliderBackgroundR())); ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_g)) .setText(String.valueOf(prefs.getSliderBackgroundG())); ((EditText) view.findViewById(R.id.main_menu_popup_color_edit_b)) .setText(String.valueOf(prefs.getSliderBackgroundB())); ((EditText) view.findViewById(R.id.main_menu_popup_timeout_editor)).setText( (prefs.getScreenTimeout() == 0L ? "" : String.valueOf(prefs.getScreenTimeout() / 1000L))); ((EditText) view.findViewById(R.id.main_menu_popup_timeout_editor)) .addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { if (s.toString().equals("")) return; try { if (Long.parseLong(s.toString()) > 9999L) s.replace(0, s.length(), "9999"); else if (Long.parseLong(s.toString()) < 0L) s.replace(0, s.length(), "0"); } catch (Exception e) { s.clear(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)) .setChecked(prefs.isInterfaceSlider()); ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(0) .setEnabled(((CheckBox) v).isChecked()); for (int i = 0; i < 3; i++) { ((ViewGroup) ((ViewGroup) ((ViewGroup) view .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i)) .getChildAt(0).setEnabled(((CheckBox) v).isChecked()); ((ViewGroup) ((ViewGroup) ((ViewGroup) view .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i)) .getChildAt(1).setEnabled(((CheckBox) v).isChecked()); } ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(2) .setVisibility((((CheckBox) v).isChecked() ? View.VISIBLE : View.INVISIBLE)); } }); ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(0).setEnabled( ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)).isChecked()); for (int i = 0; i < 3; i++) { ((ViewGroup) ((ViewGroup) ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(1)) .getChildAt(i)).getChildAt(0) .setEnabled(((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)) .isChecked()); ((ViewGroup) ((ViewGroup) ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(1)) .getChildAt(i)).getChildAt(1) .setEnabled(((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)) .isChecked()); } ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(2).setVisibility( (((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)).isChecked() ? View.VISIBLE : View.INVISIBLE)); view.findViewById(R.id.main_menu_popup_interface_caption) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)).toggle(); ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(0).setEnabled( ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)) .isChecked()); for (int i = 0; i < 3; i++) { ((ViewGroup) ((ViewGroup) ((ViewGroup) view .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i)) .getChildAt(0) .setEnabled(((CheckBox) view .findViewById(R.id.main_menu_popup_interface_checkbox)) .isChecked()); ((ViewGroup) ((ViewGroup) ((ViewGroup) view .findViewById(R.id.main_menu_popup_color)).getChildAt(1)).getChildAt(i)) .getChildAt(1) .setEnabled(((CheckBox) view .findViewById(R.id.main_menu_popup_interface_checkbox)) .isChecked()); } ((ViewGroup) view.findViewById(R.id.main_menu_popup_color)).getChildAt(2).setVisibility( (((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)) .isChecked() ? View.VISIBLE : View.INVISIBLE)); } }); new AlertDialog.Builder(this).setView(view) .setPositiveButton(R.string.main_menu_popup_save_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { prefs.setBackgroundColorInverted( ((CheckBox) view.findViewById(R.id.main_menu_popup_background_checkbox)) .isChecked()); prefs.setInterfaceSlider( ((CheckBox) view.findViewById(R.id.main_menu_popup_interface_checkbox)) .isChecked()); prefs.setSliderBackground( ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_r)) .getProgress(), ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_g)) .getProgress(), ((SeekBar) view.findViewById(R.id.main_menu_popup_color_slider_b)) .getProgress()); prefs.setScreenTimeout( (((EditText) view.findViewById(R.id.main_menu_popup_timeout_editor)).getText() .toString().equals("") ? 0L : Long.parseLong(((EditText) view .findViewById(R.id.main_menu_popup_timeout_editor)) .getText().toString()) * 1000L)); prefs.setOrientationFixed( ((CheckBox) view.findViewById(R.id.main_menu_popup_orientation_checkbox)) .isChecked()); } }).setNegativeButton(R.string.main_menu_popup_cancel_button, null).show(); return true; case R.id.main_menu_help: new AlertDialog.Builder(this).setMessage(R.string.main_menu_help_message) .setTitle(R.string.main_menu_help_title) .setPositiveButton(R.string.main_menu_help_ok_button, null).setNegativeButton( R.string.main_menu_help_question_button, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://forum.xda-developers.com/showthread.php?t=2173226")) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); } }) .show(); return true; case R.id.main_menu_about: ViewGroup about = (ViewGroup) ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)) .inflate(R.layout.main_menu_about, null); ((TextView) about.getChildAt(0)).setMovementMethod(LinkMovementMethod.getInstance()); new AlertDialog.Builder(this).setView(about).setTitle(R.string.main_menu_about_title) .setPositiveButton(R.string.main_menu_about_ok_button, null).show(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.yahala.ui.GroupCreateActivity.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (fragmentView == null) { searching = false;// ww w . j a v a 2s .c o m searchWas = false; fragmentView = inflater.inflate(R.layout.group_create_layout, container, false); emptyTextView = (TextView) fragmentView.findViewById(R.id.searchEmptyView); emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); userSelectEditText = (EditText) fragmentView.findViewById(R.id.bubble_input_text); userSelectEditText.setHint(LocaleController.getString("SendMessageTo", R.string.SendMessageTo)); if (Build.VERSION.SDK_INT >= 11) { userSelectEditText.setTextIsSelectable(false); } userSelectEditText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) { if (!ignoreChange) { beforeChangeIndex = userSelectEditText.getSelectionStart(); changeString = new SpannableString(charSequence); } } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { } @Override public void afterTextChanged(Editable editable) { if (!ignoreChange) { boolean search = false; int afterChangeIndex = userSelectEditText.getSelectionEnd(); if (editable.toString().length() < changeString.toString().length()) { String deletedString = ""; try { deletedString = changeString.toString().substring(afterChangeIndex, beforeChangeIndex); } catch (Exception e) { FileLog.e("tmessages", e); } if (deletedString.length() > 0) { if (searching && searchWas) { search = true; } Spannable span = userSelectEditText.getText(); for (int a = 0; a < allSpans.size(); a++) { XImageSpan sp = allSpans.get(a); if (span.getSpanStart(sp) == -1) { allSpans.remove(sp); selectedContacts.remove(sp.jid); } } if (parentActivity != null) { ActionBar actionBar = parentActivity.getSupportActionBar(); actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(), LocaleController.getString("Members", R.string.Members))); } listView.invalidateViews(); } else { search = true; } } else { search = true; } if (search) { String text = userSelectEditText.getText().toString().replace("<", ""); if (text.length() != 0) { searchDialogs(text); searching = true; searchWas = true; emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult)); listViewAdapter.notifyDataSetChanged(); } else { searchResult = null; searchResultNames = null; searching = false; searchWas = false; emptyTextView .setText(LocaleController.getString("NoContacts", R.string.NoContacts)); listViewAdapter.notifyDataSetChanged(); } } } } }); listView = (PinnedHeaderListView) fragmentView.findViewById(R.id.listView); listView.setEmptyView(emptyTextView); listView.setVerticalScrollBarEnabled(false); listView.setAdapter(listViewAdapter = new ListAdapter(parentActivity)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { TLRPC.User user; int section = listViewAdapter.getSectionForPosition(i); int row = listViewAdapter.getPositionInSectionForPosition(i); if (searching && searchWas) { user = searchResult.get(row); } else { ArrayList<TLRPC.User> arr = com.yahala.xmpp.ContactsController .getInstance().usersSectionsDict.get( com.yahala.xmpp.ContactsController.getInstance().sortedUsersSectionsArray .get(section)); user = com.yahala.xmpp.ContactsController.getInstance().friendsDict.get(arr.get(row).jid); listView.invalidateViews(); } if (selectedContacts.containsKey(user.jid)) { XImageSpan span = selectedContacts.get(user.jid); selectedContacts.remove(user.jid); SpannableStringBuilder text = new SpannableStringBuilder(userSelectEditText.getText()); text.delete(text.getSpanStart(span), text.getSpanEnd(span)); allSpans.remove(span); ignoreChange = true; userSelectEditText.setText(text); userSelectEditText.setSelection(text.length()); ignoreChange = false; } else { if (selectedContacts.size() == 200) { return; } ignoreChange = true; XImageSpan span = createAndPutChipForUser(user); span.jid = user.jid; ignoreChange = false; } if (parentActivity != null) { ActionBar actionBar = parentActivity.getSupportActionBar(); actionBar.setSubtitle(String.format("%d/200 %s", selectedContacts.size(), LocaleController.getString("Members", R.string.Members))); } if (searching || searchWas) { searching = false; searchWas = false; emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); ignoreChange = true; SpannableStringBuilder ssb = new SpannableStringBuilder(""); for (ImageSpan sp : allSpans) { ssb.append("<<"); ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE); } userSelectEditText.setText(ssb); userSelectEditText.setSelection(ssb.length()); ignoreChange = false; listViewAdapter.notifyDataSetChanged(); } else { listView.invalidateViews(); } } }); } else { ViewGroup parent = (ViewGroup) fragmentView.getParent(); if (parent != null) { parent.removeView(fragmentView); } } return fragmentView; }
From source file:org.cirdles.chroni.FilePickerActivity.java
public void onNewFolderButtonClicked(View v) { AlertDialog.Builder dialog = new AlertDialog.Builder(this).setMessage("Enter the new folder's name below."); // creates the layout for the EditText, will be added to the dialog box final EditText newFolderText = new EditText(this); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); params.setMargins(25, 10, 20, 25);//from ww w . j a va 2 s. c o m LinearLayout dialogLayout = new LinearLayout(this); dialogLayout.addView(newFolderText); newFolderText.setLayoutParams(params); dialog.setView(dialogLayout); // adds EditText to dialog box dialog.setPositiveButton("Create", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Editable newFolderName = newFolderText.getText(); File newFolder = new File(mainDirectory.getAbsolutePath() + "/" + newFolderName.toString()); // creates the folder if the length of the text is greater than 0 AND the folder does not already exist if (newFolderName.length() > 0 && !newFolder.exists()) { // creates the actual folder boolean createdSuccessfully = newFolder.mkdir(); // alerts the user if the folder was not created if (!createdSuccessfully) Toast.makeText(FilePickerActivity.this, "ERROR: Folder could not be created", Toast.LENGTH_SHORT).show(); else { // if it succeeded, updates the adapter mAdapter.add(newFolder); Toast.makeText(FilePickerActivity.this, "Folder Created!", Toast.LENGTH_SHORT).show(); } } else Toast.makeText(FilePickerActivity.this, "ERROR: Invalid folder name", Toast.LENGTH_SHORT) .show(); dialog.dismiss(); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.show(); }
From source file:Rangoli.testapp.Feed.CommentsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_comments, container, false); RecyclerView mCommentsView = (RecyclerView) rootView.findViewById(R.id.comment_list); mEditText = (EditText) rootView.findViewById(R.id.editText); final Button sendButton = (Button) rootView.findViewById(R.id.send_comment); final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef); mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.comment_item, CommentViewHolder.class, commentsRef) { @Override/*from ww w.j av a 2s . co m*/ protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) { Author author = comment.getAuthor(); viewHolder.commentAuthor.setText(author.getFull_name()); PicassoUtil.loadProfileIcon(author.getProfile_picture(), viewHolder.commentPhoto); viewHolder.authorRef = author.getUid(); viewHolder.commentTime.setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp())); viewHolder.commentText.setText(comment.getText()); } }; sendButton.setEnabled(false); mEditText.setHint("add text here"); mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) }); mEditText.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) { sendButton.setEnabled(true); } else { sendButton.setEnabled(false); } } }); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Clear input box and hide keyboard. final Editable commentText = mEditText.getText(); mEditText.setText(""); InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user == null) { Toast.makeText(getActivity(), "user_logged_out_error", Toast.LENGTH_SHORT).show(); } Author author = new Author(user.getDisplayName(), user.getPhotoUrl().toString(), user.getUid()); Comment comment = new Comment(author, commentText.toString(), ServerValue.TIMESTAMP); commentsRef.push().setValue(comment, new DatabaseReference.CompletionListener() { @Override public void onComplete(DatabaseError error, DatabaseReference firebase) { if (error != null) { Log.w(TAG, "Error posting comment: " + error.getMessage()); Toast.makeText(getActivity(), "Error posting comment.", Toast.LENGTH_SHORT).show(); mEditText.setText(commentText); } } }); } }); mCommentsView.setLayoutManager(new LinearLayoutManager(getActivity())); mCommentsView.setAdapter(mAdapter); return rootView; }
From source file:be.brunoparmentier.wifikeyshare.ui.activities.WifiNetworkActivity.java
void showWifiPasswordDialog() { final LayoutInflater inflater = getLayoutInflater(); final View wifiPasswordDialogLayout = inflater.inflate(R.layout.dialog_wifi_password, null); final TextInputLayout wifiPasswordWrapper = (TextInputLayout) wifiPasswordDialogLayout .findViewById(R.id.wifi_key_wrapper); final EditText passwordEditText = (EditText) wifiPasswordDialogLayout.findViewById(R.id.wifi_key); //setPasswordRestrictions(passwordEditText); final CheckBox showPasswordCheckBox = (CheckBox) wifiPasswordDialogLayout .findViewById(R.id.show_password_checkbox); showPasswordCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override//from w w w.j a v a 2 s. c om public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { int selectionIndex = passwordEditText.getSelectionStart(); if (isChecked) { passwordEditText.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); } else { passwordEditText .setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); } passwordEditText.setSelection(selectionIndex); } }); final AlertDialog wifiPasswordDialog = new AlertDialog.Builder(this) .setTitle(getString(R.string.wifi_dialog_password_title)) .setMessage(String.format(getString(R.string.wifi_dialog_password_msg), wifiNetwork.getSsid())) .setView(wifiPasswordDialogLayout) .setPositiveButton(getString(R.string.action_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { // this method gets overriden after we show the dialog } }).setNegativeButton(getString(R.string.action_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { finish(); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { finish(); } }).create(); passwordEditText.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) { wifiPasswordDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(editable.length() >= 5); if (wifiPasswordWrapper.getError() != null) { try { if (WifiNetwork.isValidKeyLength(wifiNetwork.getAuthType(), editable.toString())) { wifiPasswordWrapper.setError(null); } } catch (final WifiException e) { switch (e.getErrorCode()) { case WifiException.WEP_KEY_LENGTH_ERROR: wifiPasswordWrapper.setError(getString(R.string.error_wep_password_length)); break; case WifiException.WPA_KEY_LENGTH_ERROR: wifiPasswordWrapper.setError(getString(R.string.error_wpa_password_length)); break; default: wifiPasswordWrapper.setError(e.getMessage()); break; } } } } }); wifiPasswordDialog.show(); wifiPasswordDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false); // disabled by default wifiPasswordDialog.getButton(DialogInterface.BUTTON_POSITIVE) .setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { if (WifiNetwork.isValidKeyLength(wifiNetwork.getAuthType(), passwordEditText.getText().toString())) { wifiPasswordWrapper.setError(null); wifiNetwork.setKey(passwordEditText.getText().toString()); // Update QR code image FragmentManager fm = getSupportFragmentManager(); QrCodeFragment qrCodeFragment = (QrCodeFragment) fm.getFragments().get(0); qrCodeFragment.updateQrCode(wifiNetwork); WifiKeysDataSource.getInstance().insertWifiKey(wifiNetwork); Intent passwordResultIntent = new Intent(); passwordResultIntent.putExtra(KEY_NETWORK_ID, wifiNetworkId); setResult(RESULT_OK, passwordResultIntent); wifiPasswordDialog.dismiss(); } } catch (WifiException e) { switch (e.getErrorCode()) { case WifiException.WEP_KEY_LENGTH_ERROR: wifiPasswordWrapper.setError(getString(R.string.error_wep_password_length)); break; case WifiException.WPA_KEY_LENGTH_ERROR: wifiPasswordWrapper.setError(getString(R.string.error_wpa_password_length)); break; default: wifiPasswordWrapper.setError(null); break; } } } }); }
From source file:com.akalizakeza.apps.ishusho.activity.CommentsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_comments, container, false); RecyclerView mCommentsView = (RecyclerView) rootView.findViewById(R.id.comment_list); mEditText = (EditText) rootView.findViewById(R.id.editText); final Button sendButton = (Button) rootView.findViewById(R.id.send_comment); final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef); mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.activity_comments_item, CommentViewHolder.class, commentsRef) { @Override/* w ww. ja v a 2s.c om*/ protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) { Artist artist = comment.getArtist(); viewHolder.commentAuthor.setText(artist.getFull_name()); GlideUtil.loadProfileIcon(artist.getProfile_picture(), viewHolder.commentPhoto); viewHolder.authorRef = artist.getUid(); viewHolder.commentTime.setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp())); viewHolder.commentText.setText(comment.getText()); } }; sendButton.setEnabled(false); mEditText.setHint(R.string.new_comment_hint); mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) }); mEditText.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) { sendButton.setEnabled(true); } else { sendButton.setEnabled(false); } } }); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Clear input box and hide keyboard. final Editable commentText = mEditText.getText(); mEditText.setText(""); InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user == null) { Toast.makeText(getActivity(), R.string.user_logged_out_error, Toast.LENGTH_SHORT).show(); } Artist artist = new Artist(user.getDisplayName(), user.getPhotoUrl().toString(), user.getUid()); Comment comment = new Comment(artist, commentText.toString(), ServerValue.TIMESTAMP); commentsRef.push().setValue(comment, new DatabaseReference.CompletionListener() { @Override public void onComplete(DatabaseError error, DatabaseReference firebase) { if (error != null) { Log.w(TAG, "Error posting comment: " + error.getMessage()); Toast.makeText(getActivity(), "Error posting comment.", Toast.LENGTH_SHORT).show(); mEditText.setText(commentText); } } }); } }); mCommentsView.setLayoutManager(new LinearLayoutManager(getActivity())); mCommentsView.setAdapter(mAdapter); return rootView; }
From source file:com.edicon.firebase.devs.firepix.CommentsFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View rootView = inflater.inflate(R.layout.fragment_comments, container, false); RecyclerView mCommentsView = (RecyclerView) rootView.findViewById(R.id.comment_list); mEditText = (EditText) rootView.findViewById(R.id.editText); final Button sendButton = (Button) rootView.findViewById(R.id.send_comment); final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef); mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(Comment.class, R.layout.comment_item, CommentViewHolder.class, commentsRef) { @Override/*from w w w. j av a2s. c o m*/ protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) { Author author = comment.getAuthor(); viewHolder.commentAuthor.setText(author.getFull_name()); GlideUtil.loadProfileIcon(author.getProfile_picture(), viewHolder.commentPhoto); viewHolder.authorRef = author.getUid(); viewHolder.commentTime.setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp())); viewHolder.commentText.setText(comment.getText()); } }; sendButton.setEnabled(false); mEditText.setHint(R.string.new_comment_hint); mEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(DEFAULT_MSG_LENGTH_LIMIT) }); mEditText.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) { sendButton.setEnabled(true); } else { sendButton.setEnabled(false); } } }); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Clear input box and hide keyboard. final Editable commentText = mEditText.getText(); mEditText.setText(""); InputMethodManager inputManager = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); inputManager.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); if (user == null) { Toast.makeText(getActivity(), R.string.user_logged_out_error, Toast.LENGTH_SHORT).show(); } Author author = new Author(user.getDisplayName(), user.getPhotoUrl().toString(), user.getUid()); Comment comment = new Comment(author, commentText.toString(), ServerValue.TIMESTAMP); commentsRef.push().setValue(comment, new DatabaseReference.CompletionListener() { @Override public void onComplete(DatabaseError error, DatabaseReference firebase) { if (error != null) { Log.w(TAG, "Error posting comment: " + error.getMessage()); Toast.makeText(getActivity(), "Error posting comment.", Toast.LENGTH_SHORT).show(); mEditText.setText(commentText); } } }); } }); mCommentsView.setLayoutManager(new LinearLayoutManager(getActivity())); mCommentsView.setAdapter(mAdapter); return rootView; }
From source file:com.nps.micro.view.TestsSectionFragment.java
@Override protected View buildRootView(LayoutInflater inflater, ViewGroup container) { View rootView = inflater.inflate(layout, container, false); runButton = (Button) rootView.findViewById(R.id.runButton); runButton.setOnClickListener(new OnClickListener() { @Override/*from w w w . j a v a 2 s .co m*/ public void onClick(View v) { prepareScenarios(); } }); repeatsInput = (EditText) rootView.findViewById(R.id.repeatsInput); repeatsInput.setText(String.valueOf(model.getRepeats())); repeatsInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setRepeats(Integer.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); repeatsButton = (Button) rootView.findViewById(R.id.setRepeatsButton); repeatsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.repeats).setItems(R.array.repeats_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { repeatsInput.setText(getResources().getStringArray(R.array.repeats_array)[which]); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } }); outSizeInput = (EditText) rootView.findViewById(R.id.packetOutSizeInput); outSizeInput.setText(String.valueOf(model.getStreamOutSize())); outSizeInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setStreamOutSize(Short.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); outSizeButton = (Button) rootView.findViewById(R.id.setOutSizeButton); outSizeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.out_size).setItems(R.array.out_size_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { outSizeInput.setText(getResources().getStringArray(R.array.out_size_array)[which]); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } }); inSizeInput = (EditText) rootView.findViewById(R.id.packetInSizeInput); inSizeInput.setText(String.valueOf(model.getStreamInSizes()[0])); inSizeInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String[] vals = s.toString().split(" "); List<Short> intVals = new ArrayList<Short>(); for (String val : vals) { try { intVals.add(Short.valueOf(val)); } catch (NumberFormatException e) { // TODO Auto-generated catch block } } short[] array = new short[intVals.size()]; for (int i = 0; i < intVals.size(); i++) array[i] = intVals.get(i); model.setStreamInSize(array); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); inSizeButton = (Button) rootView.findViewById(R.id.setInSizeButton); inSizeButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.in_size).setItems(R.array.in_size_array, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { inSizeInput.setText(getResources().getStringArray(R.array.in_size_array)[which]); dialog.dismiss(); } }); AlertDialog alert = builder.create(); alert.show(); } }); radioStorageGroup = (RadioGroup) rootView.findViewById(R.id.storageRadioGroup); externalStorageRadio = (RadioButton) rootView.findViewById(R.id.externalStorageRadio); internalStorageRadio = (RadioButton) rootView.findViewById(R.id.internalStorageRadio); switch (model.getStorageType()) { case EXTERNAL: externalStorageRadio.setChecked(true); break; case INTERNAL: internalStorageRadio.setChecked(true); break; } externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); radioStorageGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.internalStorageRadio: model.setStorageType(Storage.Type.INTERNAL); break; case R.id.externalStorageRadio: model.setStorageType(Storage.Type.EXTERNAL); break; } } }); saveLogsCheckBox = (CheckBox) rootView.findViewById(R.id.saveLogsCheckBox); saveLogsCheckBox.setChecked(model.isSaveLogs()); saveLogsCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setSaveLogs(isChecked); externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); } }); streamBufferSizeInput = (EditText) rootView.findViewById(R.id.bufferSizeEditText); streamBufferSizeInput.setText(String.valueOf(model.getStreamBufferSize())); streamBufferSizeInput.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setStreamBufferSize(Integer.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); memoryUnitSpinner = (Spinner) rootView.findViewById(R.id.memoryUnitSpinner); memoryUnitSpinner.setSelection(model.getStreamBufferUnit().getIndex()); memoryUnitSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { model.setStreamBufferUnit(MemoryUnit.fromIndex(pos)); } @Override public void onNothingSelected(AdapterView<?> parent) { // do nothing } }); saveStreamCheckBox = (CheckBox) rootView.findViewById(R.id.saveStreamDataCheckbox); saveStreamCheckBox.setChecked(model.isSaveStreams()); streamBufferSizeInput.setEnabled(saveStreamCheckBox.isChecked()); memoryUnitSpinner.setEnabled(saveStreamCheckBox.isChecked()); streamQueueSize = (EditText) rootView.findViewById(R.id.streamQueueSize); streamQueueSize.setText(String.valueOf(model.getStreamQueueSize())); streamQueueSize.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { String val = s.toString(); if (!val.isEmpty() && StringUtils.isNumeric(val)) { model.setStreamQueueSize(Integer.valueOf(s.toString())); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } }); streamQueueSize.setEnabled(model.isSaveStreams() && !model.isAutoStreamQueueSize()); radioQueueGroup = (RadioGroup) rootView.findViewById(R.id.queueRadioGroup); autoStreamQueueSizeRadio = (RadioButton) rootView.findViewById(R.id.autoBufferRadio); manualStreamQueueSizeRadio = (RadioButton) rootView.findViewById(R.id.manualBufferRadio); if (model.isAutoStreamQueueSize()) { autoStreamQueueSizeRadio.setChecked(true); } else { manualStreamQueueSizeRadio.setChecked(true); } autoStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); manualStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); radioQueueGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId) { case R.id.autoBufferRadio: model.setAutoStreamQueueSize(true); streamQueueSize.setEnabled(false); break; case R.id.manualBufferRadio: model.setAutoStreamQueueSize(false); streamQueueSize.setEnabled(true); break; } } }); saveStreamCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setSaveStreams(isChecked); externalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); internalStorageRadio.setEnabled(model.isSaveStreams() || model.isSaveLogs()); streamBufferSizeInput.setEnabled(isChecked); memoryUnitSpinner.setEnabled(isChecked); autoStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); manualStreamQueueSizeRadio.setEnabled(model.isSaveStreams()); streamQueueSize.setEnabled(model.isSaveStreams() && !model.isAutoStreamQueueSize()); } }); simulateEditText = (EditText) rootView.findViewById(R.id.simulateComputationsEditText); simulateEditText.setText(String.valueOf(model.getSimulateComputations())); simulateEditText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { model.setSimulateComputations(Short.valueOf(s.toString())); } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { } }); normalPriorityCheckBox = (CheckBox) rootView.findViewById(R.id.normalPriorityCheckbox); normalPriorityCheckBox.setChecked(model.isNormalThreadPriority()); normalPriorityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setNormalThreadPriority(isChecked); } }); hiPriorityAndroidCheckBox = (CheckBox) rootView.findViewById(R.id.hiAndroidPriorityCheckbox); hiPriorityAndroidCheckBox.setChecked(model.isHiAndroidThreadPriority()); hiPriorityAndroidCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setHiAndroidThreadPriority(isChecked); } }); hiPriorityJavaCheckBox = (CheckBox) rootView.findViewById(R.id.hiJavaPriorityCheckbox); hiPriorityJavaCheckBox.setChecked(model.isHiJavaThreadPriority()); hiPriorityJavaCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setHiJavaThreadPriority(isChecked); } }); extendedDevicesCombination = (CheckBox) rootView.findViewById(R.id.extendedDevicesCheckBox); extendedDevicesCombination.setChecked(model.isExtendedDevicesCombination()); extendedDevicesCombination.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setExtendedDevicesCombination(isChecked); } }); fastHub = (CheckBox) rootView.findViewById(R.id.fastHubCheckBox); fastHub.setChecked(model.isFastHub()); fastHub.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setFastHub(isChecked); } }); autoEnableGraphCheckBox = (CheckBox) rootView.findViewById(R.id.autoEnableGraphCheckBox); autoEnableGraphCheckBox.setChecked(model.isAutoEnableGraph()); autoEnableGraphCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { model.setAutoEnableGraph(isChecked); } }); createSequenceChooser(rootView); createDeviceChooser(rootView, runButton); updateStatus(rootView); return rootView; }
From source file:com.ruesga.rview.widget.TagEditTextView.java
private void performComputeChipsLocked(Editable s) { // If we are removing skip chip creation code if (mLockEdit) { return;// ww w.j a va 2 s.com } // Check if we need to create a new chip mLockEdit = true; try { String text = s.toString(); int textLength = text.length(); boolean isCreateChip = false; boolean nextIsTag = false; if (textLength > 0) { String lastChar = text.substring(textLength - 1); if (lastChar.charAt(0) != VALID_TAGS.charAt(1) || mSupportsUserTags) { isCreateChip = NON_UNICODE_CHAR_PATTERN.matcher(lastChar).matches(); nextIsTag = VALID_TAGS.contains(lastChar); } } if (isCreateChip || nextIsTag) { createChip(s, nextIsTag); notifyComputeTagEnded(); } else if (mTriggerTagCreationThreshold > 0) { int start = mTagList.size(); String tagText = s.subSequence(start, textLength).toString().trim(); if (tagText.length() >= CREATE_CHIP_LENGTH_THRESHOLD) { mHandler.removeMessages(MESSAGE_CREATE_CHIP); mHandler.sendMessageDelayed(mHandler.obtainMessage(MESSAGE_CREATE_CHIP), mTriggerTagCreationThreshold); } } } finally { mLockEdit = false; } }
From source file:file_manager.Activity_files.java
private void setFilesList() { deleteDatabase("files_DB_v01.db"); String folder = sharedPref.getString("folder", Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath()); File f = new File(sharedPref.getString("files_startFolder", folder)); final File[] files = f.listFiles(); if (files == null || files.length == 0) { Snackbar.make(listView, R.string.toast_files, Snackbar.LENGTH_LONG).show(); } else {// www . j av a2s .c o m // looping through all items <item> for (File file : files) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); String file_Name = file.getName(); String file_Size = getReadableFileSize(file.length()); String file_date = formatter.format(new Date(file.lastModified())); String file_path = file.getAbsolutePath(); String file_ext; if (file.isDirectory()) { file_ext = "."; } else { file_ext = file.getAbsolutePath().substring(file.getAbsolutePath().lastIndexOf(".")); } db.open(); if (file_ext.equals(".") || file_ext.equals(".pdf") || file_ext.equals(".") || file_ext.equals(".jpg") || file_ext.equals(".JPG") || file_ext.equals(".jpeg") || file_ext.equals(".png")) { if (db.isExist(file_Name)) { Log.i(TAG, "Entry exists" + file_Name); } else { db.insert(file_Name, file_Size, file_ext, file_path, file_date); } } } } try { db.insert("...", "", "", "", ""); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } //display data final int layoutstyle = R.layout.list_item; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes }; String[] column = new String[] { "files_title", "files_content", "files_creation" }; final Cursor row = db.fetchAllData(this); adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0) { @Override public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title")); final File pathFile = new File(files_attachment); View v = super.getView(position, convertView, parent); final ImageView iv = (ImageView) v.findViewById(R.id.icon_notes); iv.setVisibility(View.VISIBLE); if (pathFile.isDirectory()) { iv.setImageResource(R.drawable.folder); } else { switch (files_icon) { case ".gif": case ".bmp": case ".tiff": case ".svg": case ".png": case ".jpg": case ".JPG": case ".jpeg": try { Uri uri = Uri.fromFile(pathFile); Picasso.with(Activity_files.this).load(uri).resize(76, 76).centerCrop().into(iv); } catch (Exception e) { Log.w("HHS_Moodle", "Error Load image", e); } break; case ".pdf": iv.setImageResource(R.drawable.file_pdf); break; default: iv.setImageResource(R.drawable.arrow_up_dark); break; } } if (files_title.equals("...")) { new Handler().postDelayed(new Runnable() { public void run() { iv.setImageResource(R.drawable.arrow_up_dark); } }, 200); } return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_filesBY", "files_title"); sharedPref.edit().putString("filter_filesBY", "files_title").apply(); filter.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) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); listView.setAdapter(adapter); //onClick function listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_icon = row2.getString(row2.getColumnIndexOrThrow("files_icon")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { try { sharedPref.edit().putString("files_startFolder", files_attachment).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else if (files_attachment.equals("")) { try { final File pathActual = new File(sharedPref.getString("files_startFolder", Environment.getExternalStorageDirectory().getPath())); sharedPref.edit().putString("files_startFolder", pathActual.getParent()).apply(); setFilesList(); } catch (Exception e) { Snackbar.make(listView, R.string.toast_directory, Snackbar.LENGTH_LONG).show(); } } else if (files_icon.equals(".pdf")) { Uri uri = Uri.fromFile(pathFile); Intent intent = new Intent(Activity_files.this, MuPDFActivity.class); intent.setAction(Intent.ACTION_VIEW); intent.setData(uri); startActivity(intent); } else { helper_main.open(files_icon, Activity_files.this, pathFile, listView); } } }); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) listView.getItemAtPosition(position); final String files_title = row2.getString(row2.getColumnIndexOrThrow("files_title")); final String files_attachment = row2.getString(row2.getColumnIndexOrThrow("files_attachment")); final File pathFile = new File(files_attachment); if (pathFile.isDirectory()) { Snackbar snackbar = Snackbar .make(listView, R.string.toast_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { deleteRecursive(pathFile); setFilesList(); } }); snackbar.show(); } else { final CharSequence[] options = { getString(R.string.choose_menu_2), getString(R.string.choose_menu_3), getString(R.string.choose_menu_4) }; final AlertDialog.Builder dialog = new AlertDialog.Builder(Activity_files.this); dialog.setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); dialog.setItems(options, new DialogInterface.OnClickListener() { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.choose_menu_2))) { if (pathFile.exists()) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("image/png"); sharingIntent.putExtra(Intent.EXTRA_SUBJECT, files_title); sharingIntent.putExtra(Intent.EXTRA_TEXT, files_title); Uri bmpUri = Uri.fromFile(pathFile); sharingIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); startActivity(Intent.createChooser(sharingIntent, (getString(R.string.app_share_file)))); } } if (options[item].equals(getString(R.string.choose_menu_4))) { Snackbar snackbar = Snackbar .make(listView, R.string.toast_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { pathFile.delete(); setFilesList(); } }); snackbar.show(); } if (options[item].equals(getString(R.string.choose_menu_3))) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity_files.this); View dialogView = View.inflate(Activity_files.this, R.layout.dialog_edit_file, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); edit_title.setText(files_title); builder.setView(dialogView); builder.setTitle(R.string.choose_title); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = edit_title.getText().toString().trim(); File dir = pathFile.getParentFile(); File to = new File(dir, inputTag); pathFile.renameTo(to); pathFile.delete(); setFilesList(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(Activity_files.this, edit_title); } } }); dialog.show(); } return true; } }); }