List of usage examples for android.widget EditText getText
@Override
public Editable getText()
From source file:com.ymt.demo1.main.sign.SignUpFragment.java
/** * ???// w ww. j a va 2 s . co m * ????????? */ protected void initView(View view) { /* */ //? final EditText phoneTxt = (EditText) view.findViewById(R.id.input_phone_num); final EditText accountTxt = (EditText) view.findViewById(R.id.input_account); final EditText pswTxt = (EditText) view.findViewById(R.id.input_psw); final EditText rePswTxt = (EditText) view.findViewById(R.id.re_input_psw); final TextView licenseTxt = (TextView) view.findViewById(R.id.licence_txt); /*???? ?? */ final TextView getCheckNums = (TextView) view.findViewById(R.id.get_check_nums); final EditText inputCheckNums = (EditText) view.findViewById(R.id.input_check_nums); getCheckNums.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //todo ???? } }); /** * todo spannableString * ? */ SpannableString spannableString = new SpannableString(getString(R.string.license)); ForegroundColorSpan span = new ForegroundColorSpan(getResources().getColor(R.color.material_blue_grey_800)); spannableString.setSpan(span, 0, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); licenseTxt.setText(spannableString); //switch(??) myCheckView = (MyCheckView) view.findViewById(R.id.switch_liscense); // Button signUpBtn = (Button) view.findViewById(R.id.do_sign_btn); signUpBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // String phoneNum = phoneTxt.getText().toString(); String account = accountTxt.getText().toString(); String psw = pswTxt.getText().toString(); String rePsw = rePswTxt.getText().toString(); //?? String checkNums = inputCheckNums.getText().toString(); //todo if(){}else{} ?? if (!TextUtils.isEmpty(phoneNum) && !TextUtils.isEmpty(account) && !TextUtils.isEmpty(psw) && psw.equals(rePsw)) { //? if (myCheckView.isChecked()) { queue.add(signUpRequest(account, psw, phoneNum, NORMAL_USER)); } else { Toast.makeText(getActivity(), "?????", Toast.LENGTH_SHORT).show(); } } else if (TextUtils.isEmpty(phoneNum)) { //??? Toast.makeText(getActivity(), "???", Toast.LENGTH_SHORT).show(); } else if (TextUtils.isEmpty(account)) { //??? Toast.makeText(getActivity(), "???", Toast.LENGTH_SHORT).show(); } else { //??? Toast.makeText(getActivity(), "???", Toast.LENGTH_SHORT) .show(); } } }); LinearLayout licence = (LinearLayout) view.findViewById(R.id.liscense_layout); licence.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { myCheckView.callOnClick(); } }); }
From source file:dk.moerks.ratebeermobile.MailAction.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mailaction); final boolean replyMode; final String messageId; final String from; final String senderId; final String subject; final String message; Bundle extras = getIntent().getExtras(); if (extras != null) { replyMode = extras.getBoolean("ISREPLY"); if (replyMode) { messageId = extras.getString("MESSAGEID"); from = extras.getString("SENDER"); senderId = extras.getString("SENDERID"); subject = extras.getString("SUBJECT"); message = extras.getString("MESSAGE"); extras.putString("CURRENT_USER_ID", null); EditText fromText = (EditText) findViewById(R.id.mail_action_to); fromText.setEnabled(false);/*from w w w . j ava 2s .c o m*/ EditText subjectText = (EditText) findViewById(R.id.mail_action_subject); EditText messageText = (EditText) findViewById(R.id.mail_action_message); fromText.setText(from); subjectText.setText(subject); messageText.setText("\n\n......................................................\n" + message); } else { messageId = null; from = null; senderId = null; subject = null; message = null; } } else { replyMode = false; messageId = null; from = null; senderId = null; subject = null; message = null; } Button sendMailButton = (Button) findViewById(R.id.sendMailButton); sendMailButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { EditText fromText = (EditText) findViewById(R.id.mail_action_to); EditText subjectText = (EditText) findViewById(R.id.mail_action_subject); EditText messageText = (EditText) findViewById(R.id.mail_action_message); // Prepare the 'send' action List<NameValuePair> parameters = new ArrayList<NameValuePair>(); if (replyMode) { parameters.add(new BasicNameValuePair("UserID", senderId)); parameters.add(new BasicNameValuePair("MessID", messageId)); parameters.add(new BasicNameValuePair("Referrer", "http://ratebeer.com/showmessage/" + messageId + "/")); parameters.add(new BasicNameValuePair("text2", from)); parameters.add(new BasicNameValuePair("Subject", subject)); parameters.add(new BasicNameValuePair("Body", messageText.getText().toString())); parameters.add(new BasicNameValuePair("nAllowEmail", "0")); parameters.add(new BasicNameValuePair("nCc", "0")); parameters.add(new BasicNameValuePair("nCcEmail", "android@moerks.dk")); parameters.add(new BasicNameValuePair("nCcEmail2", "android@moerks.dk")); } else { Log.d(LOGTAG, "USERID: " + getUserId()); parameters.add(new BasicNameValuePair("nSource", getUserId())); //MY User Id parameters.add(new BasicNameValuePair("Referrer", "http://ratebeer.com/inbox")); parameters.add(new BasicNameValuePair("UserID", "0")); parameters.add(new BasicNameValuePair("RecipientName", fromText.getText().toString())); parameters.add(new BasicNameValuePair("Subject", subjectText.getText().toString())); parameters.add(new BasicNameValuePair("Body", messageText.getText().toString())); parameters.add(new BasicNameValuePair("nAllowEmail", "1")); parameters.add(new BasicNameValuePair("nCc", "0")); parameters.add(new BasicNameValuePair("nCcEmail", "android@moerks.dk")); parameters.add(new BasicNameValuePair("nCcEmail2", "android@moerks.dk")); } new SendBeermailTask(MailAction.this, replyMode) .execute(parameters.toArray(new NameValuePair[] {})); } }); }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Display dialog to the user for the Spotlight web apps: * https://www.google.com/tv/spotlight-gallery.html Allow the user to add a * web app to an existing row or a new row. * //from w w w .java 2s . c o m * @param context */ public static void displayAddSpotlight(final Launcher context) { final Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.add_apps_grid); final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName); final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio); currentRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // hide the row name edit field if the current row radio button // is selected nameEditText.setVisibility(View.GONE); } }); final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio); newRadioButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // show the row name edit field if the new radio button is // selected nameEditText.setVisibility(View.VISIBLE); nameEditText.requestFocus(); } }); final GridView gridView = (GridView) dialog.findViewById(R.id.grid); final ArrayList<SpotlightInfo> spotlights = SpotlightTable.getAllSpotlights(context); gridView.setAdapter(new AllSpotlightAdapter(context, spotlights)); gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // if the new row radio button is selected, the user must enter // a name for the new row String name = nameEditText.getText().toString().trim(); if (newRadioButton.isChecked() && name.length() == 0) { nameEditText.requestFocus(); displayAlert(context, context.getString(R.string.dialog_new_row_name_alert)); return; } ItemInfo itemInfo = (ItemInfo) parent.getAdapter().getItem(position); boolean currentRow = !newRadioButton.isChecked(); context.addItem(itemInfo, currentRow ? null : name); context.showCover(false); dialog.dismiss(); if (currentRow) { Analytics.logEvent(Analytics.ADD_SPOTLIGHT_WEB_APP); } else { Analytics.logEvent(Analytics.ADD_SPOTLIGHT_WEB_APP_WITH_ROW); } } }); gridView.setDrawingCacheEnabled(true); gridView.setOnKeyListener(onKeyListener); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { context.showCover(false); } }); context.showCover(true); dialog.show(); Analytics.logEvent(Analytics.DIALOG_ADD_SPOTLIGHT_WEB_APP); }
From source file:bizapps.com.healthforusPatient.activity.RegisterActivity.java
public void verifyAccount() { final AlertDialog builder = new AlertDialog.Builder(this, R.style.InvitationDialog) .setPositiveButton("Done", null).setNegativeButton("Cancel", null).create(); LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); final EditText emailBox = new EditText(this); emailBox.setTextColor(getResources().getColor(R.color.icons)); emailBox.setHintTextColor(getResources().getColor(R.color.icons)); emailBox.setHint("Email"); layout.addView(emailBox);//from w ww . j a va 2s . co m final EditText codeBox = new EditText(this); codeBox.setTextColor(getResources().getColor(R.color.icons)); codeBox.setHintTextColor(getResources().getColor(R.color.icons)); codeBox.setHint("Code"); layout.addView(codeBox); builder.setView(layout); // final EditText etNickName = new EditText(this); // etNickName.setTextColor(Color.parseColor("#FFFFFF")); // builder.setView(etNickName); builder.setTitle("Verify registration"); builder.setMessage("Enter emailId and code to activate account"); builder.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { final Button btnAccept = builder.getButton(AlertDialog.BUTTON_POSITIVE); btnAccept.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (emailBox.getText().toString().isEmpty() && codeBox.getText().toString().isEmpty()) { Toast.makeText(getApplicationContext(), "Fields cannot be empty", Toast.LENGTH_SHORT) .show(); } else { verifyApi(emailBox.getText().toString(), codeBox.getText().toString()); builder.dismiss(); } } }); final Button btnDecline = builder.getButton(DialogInterface.BUTTON_NEGATIVE); btnDecline.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { builder.dismiss(); } }); } }); builder.show(); }
From source file:com.paramonod.kikos.MainActivity.java
public void makingFullStackIcon(int id, GeoPoint geoPoint) { OverlayItem oi = new OverlayItem(geoPoint, main.getResources().getDrawable(id)); final BalloonItem bi = new BalloonItem(main, oi.getGeoPoint()); if (id != R.drawable.orpgshop) { bi.setOnBalloonListener(new OnBalloonListener() { @Override//from www . j a va 2s. c o m public void onBalloonViewClick(BalloonItem balloonItem, View view) { } @Override public void onBalloonShow(BalloonItem balloonItem) { Intent intent = new Intent(main, DetailActivity.class); int m = 0; for (int i = 0; i < shopInterfaces.size(); i++) { GeoPoint g = new GeoPoint(shopInterfaces.get(i).getCoordX(), shopInterfaces.get(i).getCoordY()); if (g.equals(balloonItem.getGeoPoint())) { m = i; // Log.e("Search", "got here" + Integer.toString(m)); } } intent.putExtra(DetailActivity.EXTRA_POSITION, m); startActivity(intent); } @Override public void onBalloonHide(BalloonItem balloonItem) { } @Override public void onBalloonAnimationStart(BalloonItem balloonItem) { } @Override public void onBalloonAnimationEnd(BalloonItem balloonItem) { } }); } else { bi.setOnBalloonListener(new OnBalloonListener() { @Override public void onBalloonViewClick(BalloonItem balloonItem, View view) { } @Override public void onBalloonShow(BalloonItem balloonItem) { final AlertDialog.Builder b = new AlertDialog.Builder(main); b.setTitle(" ?"); b.setMessage( "? ? ? ? ? ? ?, "); b.setPositiveButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { AlertDialog.Builder builder = new AlertDialog.Builder(main); final EditText et = new EditText(main); builder.setMessage( " ?, ? ? ? ? ??: " + searchView.getQuery()); builder.setTitle(" "); builder.setView(et); builder.setPositiveButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String s = et.getText().toString(); if (s.equals("")) s = searchView.getQuery().toString(); GeoPoint biGeo = bi.getGeoPoint(); Pair p = new Pair(); p.first = s; p.second = biGeo; places.add(p); SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit(); String connectionsJSONString1 = new Gson().toJson(p); editor.putString("places" + placesIDX, connectionsJSONString1); editor.commit(); placesIDX++; } }); builder.show(); } }); b.setNegativeButton("", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); b.show(); /* mc.getDownloader().getGeoCode(new GeoCodeListener() { @Override public boolean onFinishGeoCode(final GeoCode geoCode) { if (geoCode != null) { Log.e("Not so fucking", "title" + geoCode.getTitle() + "\nsubtitle" + geoCode.getSubtitle() + "\ndisplayname" + geoCode.getDisplayName() + "\nkind" + geoCode.getKind()); main.name = geoCode.getTitle(); } else { } AsyncTask asyncTask = new AsyncTask() { @Override protected Object doInBackground(Object[] params) { String namme = ""; try { URL url = new URL("https://search-maps.yandex.ru/v1/?text=" + params[0] + "&type=biz&lang=ru_RU&apikey=245e2b86-5cfb-40c3-a064-516c37dba6b2"); System.out.println(url); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.connect(); // optional default is GET con.setRequestMethod("GET"); //int responseCode = con.getResponseCode(); if smth crashes BufferedReader in = new BufferedReader( new InputStreamReader(con.getInputStream())); String inputLine; String response = ""; while ((inputLine = in.readLine()) != null) { response += inputLine; } in.close(); con.disconnect(); MapActivity.jsonObject = new JSONObject(response); JSONArray ja1 = MapActivity.jsonObject.getJSONArray("features"); for (int i = 0; i < ja1.length(); i++) { JSONObject j0 = ja1.getJSONObject(i); JSONObject j11 = j0.getJSONObject("properties"); main.namme += " " + j11.getString("name"); } } catch (Exception e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Object o) { super.onPostExecute(o); main.selectName(); } }.execute(main.name); return true; } }, balloonItem.getGeoPoint()); intent = new Intent(main, DetailYandexActivity.class); */ } @Override public void onBalloonHide(BalloonItem balloonItem) { } @Override public void onBalloonAnimationStart(BalloonItem balloonItem) { } @Override public void onBalloonAnimationEnd(BalloonItem balloonItem) { } }); } bi.setDrawable(getResources().getDrawable(R.drawable.itkerk)); oi.setBalloonItem(bi); o.addOverlayItem(oi); }
From source file:nya.miku.wishmaster.ui.settings.AutohideActivity.java
@SuppressLint("InflateParams") @Override/* w w w. ja va 2 s. c o m*/ protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); Object item = l.getItemAtPosition(position); final int changeId; if (item instanceof AutohideRule) { changeId = position - 1; } else { changeId = -1; //-1 - ? } Context dialogContext = Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB ? new ContextThemeWrapper(this, R.style.Neutron_Medium) : this; View dialogView = LayoutInflater.from(dialogContext).inflate(R.layout.dialog_autohide_rule, null); final EditText regexEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_regex); final Spinner chanSpinner = (Spinner) dialogView.findViewById(R.id.dialog_autohide_chan_spinner); final EditText boardEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_boardname); final EditText threadEditText = (EditText) dialogView.findViewById(R.id.dialog_autohide_threadnum); final CheckBox inCommentCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_comment); final CheckBox inSubjectCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_subject); final CheckBox inNameCheckBox = (CheckBox) dialogView.findViewById(R.id.dialog_autohide_in_name); chanSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, chans)); if (changeId != -1) { AutohideRule rule = (AutohideRule) item; regexEditText.setText(rule.regex); int chanPosition = chans.indexOf(rule.chanName); chanSpinner.setSelection(chanPosition != -1 ? chanPosition : 0); boardEditText.setText(rule.boardName); threadEditText.setText(rule.threadNumber); inCommentCheckBox.setChecked(rule.inComment); inSubjectCheckBox.setChecked(rule.inSubject); inNameCheckBox.setChecked(rule.inName); } else { chanSpinner.setSelection(0); } DialogInterface.OnClickListener save = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String regex = regexEditText.getText().toString(); if (regex.length() == 0) { Toast.makeText(AutohideActivity.this, R.string.autohide_error_empty_regex, Toast.LENGTH_LONG) .show(); return; } try { Pattern.compile(regex, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL); } catch (Exception e) { CharSequence message = null; if (e instanceof PatternSyntaxException) { String eMessage = e.getMessage(); if (!TextUtils.isEmpty(eMessage)) { SpannableStringBuilder a = new SpannableStringBuilder( getString(R.string.autohide_error_incorrect_regex)); a.append('\n'); int startlen = a.length(); a.append(eMessage); a.setSpan(new TypefaceSpan("monospace"), startlen, a.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); message = a; } } if (message == null) message = getString(R.string.error_unknown); Toast.makeText(AutohideActivity.this, message, Toast.LENGTH_LONG).show(); return; } AutohideRule rule = new AutohideRule(); int spinnerSelectedPosition = chanSpinner.getSelectedItemPosition(); rule.regex = regex; rule.chanName = spinnerSelectedPosition > 0 ? chans.get(spinnerSelectedPosition) : ""; // 0 ? = ? rule.boardName = boardEditText.getText().toString(); rule.threadNumber = threadEditText.getText().toString(); rule.inComment = inCommentCheckBox.isChecked(); rule.inSubject = inSubjectCheckBox.isChecked(); rule.inName = inNameCheckBox.isChecked(); if (!rule.inComment && !rule.inSubject && !rule.inName) { Toast.makeText(AutohideActivity.this, R.string.autohide_error_no_condition, Toast.LENGTH_LONG) .show(); return; } if (changeId == -1) { rulesJson.put(rule.toJson()); } else { rulesJson.put(changeId, rule.toJson()); } rulesChanged(); } }; AlertDialog dialog = new AlertDialog.Builder(this).setView(dialogView) .setTitle(changeId == -1 ? R.string.autohide_add_rule_title : R.string.autohide_edit_rule_title) .setPositiveButton(R.string.autohide_save_button, save) .setNegativeButton(android.R.string.cancel, null).create(); dialog.setCanceledOnTouchOutside(false); dialog.show(); }
From source file:ar.rulosoft.mimanganu.PreferencesFragment.java
@Override public void onCreatePreferences(Bundle bundle, String s) { addPreferencesFromResource(R.xml.fragment_preferences); ColorListDialogPref primaryColor = (ColorListDialogPref) getPreferenceManager().findPreference("primario"); primaryColor.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override//from w ww.j a v a 2s.c o m public boolean onPreferenceChange(Preference preference, Object o) { ((MainActivity) getActivity()).setColorToBars(); return false; } }); PreferenceGroup preferenceGroup = (PreferenceGroup) findPreference("account"); ServerBase[] servers = ServerBase.getServers(getContext()); for (final ServerBase sb : servers) { if (sb.needLogin()) { SwitchPreferenceCompat preference = new SwitchPreferenceCompat(getContext()); preference.setTitle(sb.getServerName()); preference.setSelectable(true); preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { new LoginDialog(getContext(), sb).show(); return false; } }); preferenceGroup.addPreference(preference); } } /** Once, create necessary Data */ prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); final String current_filepath = prefs.getString("directorio", Environment.getExternalStorageDirectory().getAbsolutePath()) + "/MiMangaNu/"; /** This enables to hide downloaded images from gallery, just a toggle */ final SwitchPreferenceCompat cBoxPref = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("mostrar_en_galeria"); cBoxPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { boolean have_noMedia = (Boolean) newValue; if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { File mimaFolder = new File(current_filepath, ".nomedia"); if (have_noMedia) { try { mimaFolder.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } else { if (mimaFolder.exists()) { mimaFolder.delete(); } } } return true; } }); /** Set summary for Reader preference + seamless chapter transitions summary **/ // true: Paged Reader; false: Continuous Reader Boolean readType = prefs.getBoolean("reader_type", false); Preference reader_type = getPreferenceManager().findPreference("reader_type"); Preference seamlessChapterTransitionsPref = getPreferenceManager() .findPreference("seamless_chapter_transitions"); if (readType) { reader_type.setTitle(getString(R.string.paged_reader)); seamlessChapterTransitionsPref .setSummary(getString(R.string.seamless_chapter_transitions_paged_reader_subtitle)); } else { reader_type.setTitle(getString(R.string.continuous_reader)); seamlessChapterTransitionsPref .setSummary(getString(R.string.seamless_chapter_transitions_continuous_reader_subtitle)); } final SwitchPreferenceCompat readerTypePref = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("reader_type"); readerTypePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); Boolean readType = prefs.getBoolean("reader_type", false); Preference reader_type = getPreferenceManager().findPreference("reader_type"); Preference seamlessChapterTransitions = getPreferenceManager() .findPreference("seamless_chapter_transitions"); if (!readType) { reader_type.setTitle(getString(R.string.paged_reader)); seamlessChapterTransitions .setSummary(getString(R.string.seamless_chapter_transitions_paged_reader_subtitle)); } else { reader_type.setTitle(getString(R.string.continuous_reader)); seamlessChapterTransitions.setSummary( getString(R.string.seamless_chapter_transitions_continuous_reader_subtitle)); } return true; } }); /** enable / disable seamless_chapter_transitions_delete_read depending on the state of seamless_chapter_transitions **/ Preference seamlessChapterTransitionsDeleteReadPreference = getPreferenceManager() .findPreference("seamless_chapter_transitions_delete_read"); if (prefs.getBoolean("seamless_chapter_transitions", false)) { seamlessChapterTransitionsDeleteReadPreference.setEnabled(true); } else { seamlessChapterTransitionsDeleteReadPreference.setEnabled(false); } final SwitchPreferenceCompat seamlessChapterTransitionsSPC = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("seamless_chapter_transitions"); seamlessChapterTransitionsSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); Preference seamlessChapterTransitionsDeleteReadPreference = getPreferenceManager() .findPreference("seamless_chapter_transitions_delete_read"); if (!prefs.getBoolean("seamless_chapter_transitions", false)) { seamlessChapterTransitionsDeleteReadPreference.setEnabled(true); } else { seamlessChapterTransitionsDeleteReadPreference.setEnabled(false); SharedPreferences.Editor prefEdit = prefs.edit(); prefEdit.putBoolean("seamless_chapter_transitions_delete_read", false); prefEdit.apply(); } return true; } }); Preference autoImportPath = getPreferenceManager().findPreference("auto_import_path"); /** enable / disable auto_import_path depending on the state of auto_import **/ if (prefs.getBoolean("auto_import", false)) { autoImportPath.setEnabled(true); } else { autoImportPath.setEnabled(false); } final SwitchPreferenceCompat autoImportSPC = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("auto_import"); autoImportSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); Preference autoImportPath = getPreferenceManager().findPreference("auto_import_path"); if (!prefs.getBoolean("auto_import", false)) { autoImportPath.setEnabled(true); } else { autoImportPath.setEnabled(false); } return true; } }); /** This sets the download threads (parallel downloads) */ final SeekBarCustomPreference listPreferenceDT = (SeekBarCustomPreference) getPreferenceManager() .findPreference("download_threads"); listPreferenceDT.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int threads = (int) newValue; int antes = DownloadPoolService.SLOTS; DownloadPoolService.SLOTS = threads; if (DownloadPoolService.actual != null) DownloadPoolService.actual.slots += (threads - antes); return true; } }); /** This sets the maximum number of errors to tolerate */ final SeekBarCustomPreference listPrefET = (SeekBarCustomPreference) getPreferenceManager() .findPreference("error_tolerancia"); listPrefET.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { ChapterDownload.MAX_ERRORS = (int) newValue; return true; } }); /** This sets the number of retries to fetch images */ SeekBarCustomPreference listPrefRT = (SeekBarCustomPreference) getPreferenceManager() .findPreference("reintentos"); listPrefRT.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { SingleDownload.RETRY = (int) newValue; return true; } }); /** This sets the Update Interval of the mangas (i.e. once per week) */ final ListPreference listPrefCU = (ListPreference) getPreferenceManager().findPreference("update_interval"); listPrefCU.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { long time = Long.parseLong((String) newValue); if (time > 0) { AlarmReceiver.setAlarms(getActivity().getApplicationContext(), System.currentTimeMillis() + time, time); } else { AlarmReceiver.stopAlarms(getActivity().getApplicationContext()); } if (time < 0) MainActivity.coldStart = false; return true; } }); /** This is for Custom language selection */ final ListPreference listPrefBatotoLang = (ListPreference) getPreferenceManager() .findPreference("batoto_lang_selection"); listPrefBatotoLang.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (newValue.equals("Custom")) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rootView = inflater.inflate(R.layout.batoto_custom_lang_dialog, null); final EditText CustomLang = (EditText) rootView.findViewById(R.id.txtCustomLang); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext()); dialogBuilder.setTitle("Custom language"); dialogBuilder.setView(rootView); dialogBuilder.setPositiveButton("Ok", null); dialogBuilder.setNegativeButton("Cancel", null); AlertDialog dialog = dialogBuilder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(final DialogInterface dialog) { Button accept = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE); accept.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { prefs.edit().putString("batoto_custom_lang", CustomLang.getText().toString()) .apply(); Util.getInstance().toast(getContext(), "Custom Language: " + CustomLang.getText().toString()); dialog.dismiss(); } }); Button cancel = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_NEGATIVE); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); } }); dialog.show(); } return true; } }); /** This sets the Version Number, that's all */ final Preference prefAbout = getPreferenceManager().findPreference("about_text"); prefAbout.setSummary("v" + BuildConfig.VERSION_NAME); /** This will check how much storage is taken by the mangas */ new calcStorage().execute(current_filepath); final Preference prefLicense = getPreferenceManager().findPreference("license_view"); prefLicense.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { ((MainActivity) getActivity()).replaceFragment(new LicenseFragment(), "licence_fragment"); return false; } }); final SwitchPreferenceCompat onlyWifiUpdateSwitch = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("update_only_wifi"); SwitchPreferenceCompat onlyWifiSwitch = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("only_wifi"); onlyWifiSwitch.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object o) { NetworkUtilsAndReceiver.ONLY_WIFI = (Boolean) o; NetworkUtilsAndReceiver.connectionStatus = NetworkUtilsAndReceiver.ConnectionStatus.UNCHECKED; onlyWifiUpdateSwitch.setEnabled(!(Boolean) o); return true; } }); if (onlyWifiSwitch.isChecked()) { onlyWifiUpdateSwitch.setEnabled(false); } else { onlyWifiUpdateSwitch.setEnabled(true); } final SeekBarCustomPreference seekBarConnectionTimeout = (SeekBarCustomPreference) getPreferenceManager() .findPreference("connection_timeout"); seekBarConnectionTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Navigator.connectionTimeout = Integer.parseInt(prefs.getString("connection_timeout", "10")); return true; } }); final SeekBarCustomPreference seekBarWriteTimeout = (SeekBarCustomPreference) getPreferenceManager() .findPreference("write_timeout"); seekBarWriteTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Navigator.writeTimeout = Integer.parseInt(prefs.getString("write_timeout", "10")); return true; } }); final SeekBarCustomPreference seekBarReadTimeout = (SeekBarCustomPreference) getPreferenceManager() .findPreference("read_timeout"); seekBarReadTimeout.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { Navigator.readTimeout = Integer.parseInt(prefs.getString("read_timeout", "30")); return true; } }); Preference gridColumnsPref = getPreferenceManager().findPreference("grid_columns"); if (prefs.getBoolean("grid_columns_automatic_detection", true)) { gridColumnsPref.setEnabled(false); } else { gridColumnsPref.setEnabled(true); } final SwitchPreferenceCompat gridColumnsAutomaticDetectionSPC = (SwitchPreferenceCompat) getPreferenceManager() .findPreference("grid_columns_automatic_detection"); gridColumnsAutomaticDetectionSPC.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); Preference gridColumns = getPreferenceManager().findPreference("grid_columns"); if (prefs.getBoolean("grid_columns_automatic_detection", true)) { gridColumns.setEnabled(true); } else { gridColumns.setEnabled(false); } return true; } }); final Preference prefClearCache = getPreferenceManager().findPreference("clear_cache"); prefClearCache.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Preference clearCache = getPreferenceManager().findPreference("clear_cache"); clearCache.setEnabled(false); Thread t0 = new Thread(new Runnable() { @Override public void run() { new FileCache(getActivity()).clearCache(); } }); Thread t1 = new Thread(new Runnable() { @Override public void run() { Util.getInstance().createNotificationWithProgressbar(getContext(), 69, getString(R.string.deleting_empty_directories), ""); Util.getInstance().deleteEmptyDirectoriesRecursive(new File(current_filepath)); Util.getInstance().cancelNotification(69); } }); t0.start(); t1.start(); return true; } }); final Preference prefResetServersToDefaults = getPreferenceManager() .findPreference("reset_server_list_to_defaults"); prefResetServersToDefaults.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Preference resetServerListToDefaults = getPreferenceManager() .findPreference("reset_server_list_to_defaults"); resetServerListToDefaults.setEnabled(false); prefs.edit().putString("unused_servers", "").apply(); return true; } }); final Preference prefVacuumDatabase = getPreferenceManager().findPreference("vacuum_database"); prefVacuumDatabase.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { Preference vacuumDatabase = getPreferenceManager().findPreference("vacuum_database"); vacuumDatabase.setEnabled(false); Thread t0 = new Thread(new Runnable() { @Override public void run() { Util.getInstance().createNotificationWithProgressbar(getContext(), 70, getString(R.string.vacuum_database_notification_text), ""); Database.vacuumDatabase(getContext()); Util.getInstance().cancelNotification(70); } }); t0.start(); return true; } }); setFirstRunDefaults(); }
From source file:de.baumann.hhsmoodle.activities.Activity_todo.java
private void setupListViewListener() { lvItems.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override/*from ww w . j ava 2 s. c om*/ public boolean onItemLongClick(AdapterView<?> adapter, View item, final int pos, long id) { final String text = (String) adapter.getItemAtPosition(pos); // Remove the item within array at position items.remove(pos); // Refresh the adapter itemsAdapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItems(); Snackbar snackbar = Snackbar.make(lvItems, R.string.todo_removed, Snackbar.LENGTH_LONG) .setAction(R.string.todo_removed_back, new View.OnClickListener() { @Override public void onClick(View view) { items.add(pos, text); // Refresh the adapter itemsAdapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItems(); } }); snackbar.show(); return true; } }); lvItems.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> adapter, View item, final int pos, long id) { AlertDialog.Builder builder = new AlertDialog.Builder(Activity_todo.this); View dialogView = View.inflate(Activity_todo.this, R.layout.dialog_edit_text_singleline, null); final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title); ImageButton ib_paste = (ImageButton) dialogView.findViewById(R.id.imageButtonPaste); ib_paste.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final CharSequence[] options = { getString(R.string.paste_date), getString(R.string.paste_time) }; new android.app.AlertDialog.Builder(Activity_todo.this) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.dismiss(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.paste_date))) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); String dateNow = format.format(date); edit_title.getText().insert(edit_title.getSelectionStart(), dateNow); } if (options[item].equals(getString(R.string.paste_time))) { Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("HH:mm", Locale.getDefault()); String timeNow = format.format(date); edit_title.getText().insert(edit_title.getSelectionStart(), timeNow); } } }).show(); } }); String text = (String) adapter.getItemAtPosition(pos); edit_title.setText(text); builder.setView(dialogView); builder.setTitle(R.string.number_edit_entry); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTag = edit_title.getText().toString().trim(); // Remove the item within array at position items.remove(pos); items.add(pos, inputTag); // Refresh the adapter itemsAdapter.notifyDataSetChanged(); // Return true consumes the long click event (marks it handled) writeItems(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final AlertDialog dialog2 = builder.create(); // Display the custom alert dialog on interface dialog2.show(); helper_main.showKeyboard(Activity_todo.this, edit_title); } }); }
From source file:com.microsoft.onedrive.apiexplorer.ItemFragment.java
/** * Navigates to an item by path/*from w w w .ja va 2s. com*/ * @param item the source item */ private void navigateByPath(final Item item) { final BaseApplication application = (BaseApplication) getActivity().getApplication(); final IOneDriveClient oneDriveClient = application.getOneDriveClient(); final Activity activity = getActivity(); final EditText itemPath = new EditText(activity); itemPath.setInputType(InputType.TYPE_CLASS_TEXT); final DefaultCallback<Item> itemCallback = new DefaultCallback<Item>(activity) { @Override public void success(final Item item) { final ItemFragment fragment = ItemFragment.newInstance(item.id); navigateToFragment(fragment); } }; new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_map) .setTitle(R.string.navigate_by_path).setView(itemPath) .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { dialog.dismiss(); } }).setPositiveButton(R.string.navigate, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { oneDriveClient.getDrive().getItems(item.id).getItemWithPath(itemPath.getText().toString()) .buildRequest().expand(getExpansionOptions(oneDriveClient)).get(itemCallback); } }).create().show(); }