List of usage examples for android.text.method LinkMovementMethod getInstance
public static MovementMethod getInstance()
From source file:mobi.omegacentauri.ptimer.PTimerEditActivity.java
private void handleFatalError(final CharSequence errorInternalName, final CharSequence errorString, final Exception exception) { Log.i("Ringdroid", "handleFatalError"); SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); int failureCount = prefs.getInt(PREF_ERROR_COUNT, 0); final SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_ERROR_COUNT, failureCount + 1); prefsEditor.commit();/* w ww . j av a 2s . c o m*/ // Check if we already have a pref for whether or not we can // contact the server. int serverAllowed = prefs.getInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_UNKNOWN); if (serverAllowed == SERVER_ALLOWED_NO) { Log.i("Ringdroid", "ERR: SERVER_ALLOWED_NO"); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } if (serverAllowed == SERVER_ALLOWED_YES) { Log.i("Ringdroid", "SERVER_ALLOWED_YES"); new AlertDialog.Builder(PTimerEditActivity.this).setTitle(R.string.alert_title_failure) .setMessage(errorString) .setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sendErrToServerAndFinish(errorInternalName, exception); return; } }).setCancelable(false).show(); return; } // The number of times the user must have had a failure before // we'll ask them. Defaults to 1, and each time they click "Later" // we double and add 1. final int allowServerCheckIndex = prefs.getInt(PREF_ERR_SERVER_CHECK, 1); if (failureCount < allowServerCheckIndex) { Log.i("Ringdroid", "failureCount " + failureCount + " is less than " + allowServerCheckIndex); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } final SpannableString message = new SpannableString( errorString + ". " + getResources().getText(R.string.error_server_prompt)); Linkify.addLinks(message, Linkify.ALL); AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure) .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); sendErrToServerAndFinish(errorInternalName, exception); } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_CHECK, 1 + allowServerCheckIndex * 2); Log.i("Ringdroid", "Won't check again until " + (1 + allowServerCheckIndex * 2) + " errors."); prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.SpeechEd.SpeechEdEditActivity.java
private void handleFatalError(final CharSequence errorInternalName, final CharSequence errorString, final Exception exception) { Log.i("Speech-Ed", "handleFatalError"); SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); int failureCount = prefs.getInt(PREF_ERROR_COUNT, 0); final SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_ERROR_COUNT, failureCount + 1); prefsEditor.commit();// www . j a va2s . c om // Check if we already have a pref for whether or not we can // contact the server. int serverAllowed = prefs.getInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_UNKNOWN); if (serverAllowed == SERVER_ALLOWED_NO) { Log.i("Speech-Ed", "ERR: SERVER_ALLOWED_NO"); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } if (serverAllowed == SERVER_ALLOWED_YES) { Log.i("Speech-Ed", "SERVER_ALLOWED_YES"); new AlertDialog.Builder(SpeechEdEditActivity.this).setTitle(R.string.alert_title_failure) .setMessage(errorString) .setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sendErrToServerAndFinish(errorInternalName, exception); return; } }).setCancelable(false).show(); return; } // The number of times the user must have had a failure before // we'll ask them. Defaults to 1, and each time they click "Later" // we double and add 1. final int allowServerCheckIndex = prefs.getInt(PREF_ERR_SERVER_CHECK, 1); if (failureCount < allowServerCheckIndex) { Log.i("Speech-Ed", "failureCount " + failureCount + " is less than " + allowServerCheckIndex); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } final SpannableString message = new SpannableString( errorString + ". " + getResources().getText(R.string.error_server_prompt)); Linkify.addLinks(message, Linkify.ALL); AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure) .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); sendErrToServerAndFinish(errorInternalName, exception); } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_CHECK, 1 + allowServerCheckIndex * 2); Log.i("Speech-Ed", "Won't check again until " + (1 + allowServerCheckIndex * 2) + " errors."); prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:org.de.jmg.learn._MainActivity.java
@SuppressLint("ClickableViewAccessibility") private void InitControls() throws Exception { View v = findViewById(R.id.btnRight); Button b = (Button) v; _btnRight = b;/*from w w w. j ava 2 s.co m*/ assert b != null; b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { if (_lastIsWrongVokID == _vok.getIndex()) { lib.playSound(_main, Sounds.Beep); getVokabel(false, true); } else { int Zaehler = _vok.AntwortRichtig(); lib.playSound(_main, Zaehler); getVokabel(false, false); } _lastIsWrongVokID = -1; } catch (Exception e) { lib.ShowException(_main, e); } } }); v = findViewById(R.id.btnWrong); b = (Button) v; _btnWrong = b; assert b != null; b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { _vok.AntwortFalsch(); lib.playSound(_main, _vok.getZaehler()); _lastIsWrongVokID = _vok.getIndex(); if (!_vok.getCardMode()) { setBtnsEnabled(false); flashwords(); } else { getVokabel(false, false); } } catch (Exception e) { lib.ShowException(_main, e); } } }); v = findViewById(R.id.btnSkip); b = (Button) v; _btnSkip = b; assert b != null; b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { _vok.SkipVokabel(); getVokabel(false, false); } catch (Exception e) { lib.ShowException(_main, e); } } }); v = findViewById(R.id.btnView); b = (Button) v; _btnView = b; assert b != null; b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { getVokabel(true, false); } catch (Exception e) { lib.ShowException(_main, e); } } }); v = findViewById(R.id.btnEdit); b = (Button) v; _btnEdit = b; assert b != null; b.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { try { edit(); } catch (Exception e) { lib.ShowException(_main, e); } } }); _txtMeaning1 = (BorderedEditText) findViewById(R.id.txtMeaning1); //int bottom = (_txtMeaning1.getPaddingBottom() == 0 ? 5 : _txtMeaning1.getPaddingBottom()); /*_txtMeaning1.setPadding(_txtMeaning1.getPaddingLeft() , 0 , _txtMeaning1.getPaddingRight() , 0); */ OnTouchListenerScrollMeaning1 = new OnTouchListenerScroll(detectorMeaning1, this); ListenerMeaning1.l = OnTouchListenerScrollMeaning1; ListenerMeaning1.t = _txtMeaning1; _txtMeaning1.setOnTouchListener(OnTouchListenerScrollMeaning1); _txtMeaning1.setOnLongClickListener(textlongclicklistener); //_txtMeaning1.setBackgroundColor(Color.BLACK); _MeaningBG = _txtMeaning1.getBackground(); //_txtMeaning1.setBackgroundResource(0); //_txtMeaning1.setOnTouchListener(OnTouchListenerRemoveCallbacks); _txtMeaning2 = (BorderedEditText) findViewById(R.id.txtMeaning2); assert _txtMeaning2 != null; _txtMeaning2.setOnLongClickListener(textlongclicklistener); //_txtMeaning2.setBackgroundResource(0); _txtMeaning2.setOnTouchListener(OnTouchListenerRemoveCallbacks); _txtMeaning3 = (BorderedEditText) findViewById(R.id.txtMeaning3); assert _txtMeaning3 != null; _txtMeaning3.setOnLongClickListener(textlongclicklistener); //_txtMeaning3.setBackgroundResource(0); _txtMeaning3.setOnTouchListener(OnTouchListenerRemoveCallbacks); _txtWord = (BorderedTextView) findViewById(R.id.word); assert _txtWord != null; _txtWord.setOnLongClickListener(textlongclicklistener); //_txtWord.setOnTouchListener(OnTouchListenerRemoveCallbacks); OnTouchListenerScrollWord = new OnTouchListenerScroll(detectorWord, this); ListenerWord.l = OnTouchListenerScrollWord; ListenerWord.t = _txtWord; _txtWord.setOnTouchListener(OnTouchListenerScrollWord); _txtedWord = (BorderedEditText) findViewById(R.id.edword); assert _txtedWord != null; _txtedWord.setOnLongClickListener(textlongclicklistener); OnTouchListenerScrolledWord = new OnTouchListenerScroll(detectoredWord, this); ListenerEdWord.l = OnTouchListenerScrolledWord; ListenerEdWord.t = _txtedWord; _txtedWord.setOnTouchListener(OnTouchListenerScrolledWord); _txtedKom = (BorderedEditText) findViewById(R.id.edComment); assert _txtedKom != null; _txtedKom.setOnLongClickListener(textlongclicklistener); OnTouchListenerScrolledKom = new OnTouchListenerScroll(detectoredKom, this); ListenerEdKom.l = OnTouchListenerScrolledKom; ListenerEdKom.t = _txtedKom; _txtedKom.setOnTouchListener(OnTouchListenerScrolledKom); _txtKom = (BorderedTextView) findViewById(R.id.Comment); assert _txtKom != null; _txtKom.setOnLongClickListener(textlongclicklistener); OnTouchListenerScrollKom = new OnTouchListenerScroll(detectorKom, this); ListenerKom.l = OnTouchListenerScrollKom; ListenerKom.t = _txtKom; _txtKom.setOnTouchListener(OnTouchListenerScrollKom); _txtKom.setMovementMethod(LinkMovementMethod.getInstance()); _txtStatus = (BorderedTextView) findViewById(R.id.txtStatus); _scrollView = (ScrollView) findViewById(R.id.layoutMain); assert _scrollView != null; _scrollView.setOnTouchListener(OnTouchListenerRemoveCallbacks); setBtnsEnabled(false); setTextColors(); }
From source file:github.daneren2005.dsub.fragments.SelectDirectoryFragment.java
private void setupTextDisplay(final View header) { final TextView titleView = (TextView) header.findViewById(R.id.select_album_title); if (playlistName != null) { titleView.setText(playlistName); } else if (podcastName != null) { titleView.setText(podcastName);//from www .ja v a 2 s. co m titleView.setPadding(0, 6, 4, 8); } else if (name != null) { titleView.setText(name); if (artistInfo != null) { titleView.setPadding(0, 6, 4, 8); } } else if (share != null) { titleView.setVisibility(View.GONE); } int songCount = 0; Set<String> artists = new HashSet<String>(); Set<Integer> years = new HashSet<Integer>(); Integer totalDuration = 0; for (Entry entry : entries) { if (!entry.isDirectory()) { songCount++; if (entry.getArtist() != null) { artists.add(entry.getArtist()); } if (entry.getYear() != null) { years.add(entry.getYear()); } Integer duration = entry.getDuration(); if (duration != null) { totalDuration += duration; } } } final TextView artistView = (TextView) header.findViewById(R.id.select_album_artist); if (podcastDescription != null || artistInfo != null) { artistView.setVisibility(View.VISIBLE); String text = podcastDescription != null ? podcastDescription : artistInfo.getBiography(); Spanned spanned = null; if (text != null) { spanned = Html.fromHtml(text); } artistView.setText(spanned); artistView.setSingleLine(false); final int minLines = context.getResources().getInteger(R.integer.TextDescriptionLength); artistView.setLines(minLines); artistView.setTextAppearance(context, android.R.style.TextAppearance_Small); final Spanned spannedText = spanned; artistView.setOnClickListener(new View.OnClickListener() { @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onClick(View v) { if (artistView.getMaxLines() == minLines) { // Use LeadingMarginSpan2 to try to make text flow around image Display display = context.getWindowManager().getDefaultDisplay(); ImageView coverArtView = (ImageView) header.findViewById(R.id.select_album_art); coverArtView.measure(display.getWidth(), display.getHeight()); int height, width; ViewGroup.MarginLayoutParams vlp = (ViewGroup.MarginLayoutParams) coverArtView .getLayoutParams(); if (coverArtView.getDrawable() != null) { height = coverArtView.getMeasuredHeight() + coverArtView.getPaddingBottom(); width = coverArtView.getWidth() + coverArtView.getPaddingRight(); } else { height = coverArtView.getHeight(); width = coverArtView.getWidth() + coverArtView.getPaddingRight(); } float textLineHeight = artistView.getPaint().getTextSize(); int lines = (int) Math.ceil(height / textLineHeight); SpannableString ss = new SpannableString(spannedText); ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); View linearLayout = header.findViewById(R.id.select_album_text_layout); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout .getLayoutParams(); int[] rules = params.getRules(); rules[RelativeLayout.RIGHT_OF] = 0; params.leftMargin = vlp.rightMargin; artistView.setText(ss); artistView.setMaxLines(100); vlp = (ViewGroup.MarginLayoutParams) titleView.getLayoutParams(); vlp.leftMargin = width; } else { artistView.setMaxLines(minLines); } } }); artistView.setMovementMethod(LinkMovementMethod.getInstance()); } else if (topTracks) { artistView.setText(R.string.menu_top_tracks); artistView.setVisibility(View.VISIBLE); } else if (showAll) { artistView.setText(R.string.menu_show_all); artistView.setVisibility(View.VISIBLE); } else if (artists.size() == 1) { String artistText = artists.iterator().next(); if (years.size() == 1) { artistText += " - " + years.iterator().next(); } artistView.setText(artistText); artistView.setVisibility(View.VISIBLE); } else { artistView.setVisibility(View.GONE); } TextView songCountView = (TextView) header.findViewById(R.id.select_album_song_count); TextView songLengthView = (TextView) header.findViewById(R.id.select_album_song_length); if (podcastDescription != null || artistInfo != null) { songCountView.setVisibility(View.GONE); songLengthView.setVisibility(View.GONE); } else { String s = context.getResources().getQuantityString(R.plurals.select_album_n_songs, songCount, songCount); songCountView.setText(s.toUpperCase()); songLengthView.setText(Util.formatDuration(totalDuration)); } }
From source file:github.popeen.dsub.fragments.SelectDirectoryFragment.java
private void setupTextDisplay(final View header) { final TextView titleView = (TextView) header.findViewById(R.id.select_album_title); if (playlistName != null) { titleView.setText(playlistName); } else if (podcastName != null) { Collections.reverse(entries); titleView.setText(podcastName);//from w ww . j a v a2 s . co m titleView.setPadding(0, 6, 4, 8); } else if (name != null) { titleView.setText(name); if (artistInfo != null) { titleView.setPadding(0, 6, 4, 8); } } else if (share != null) { titleView.setVisibility(View.GONE); } int songCount = 0; Set<String> artists = new HashSet<String>(); Set<Integer> years = new HashSet<Integer>(); totalDuration = 0; for (Entry entry : entries) { if (!entry.isDirectory()) { songCount++; if (entry.getArtist() != null) { artists.add(entry.getArtist()); } if (entry.getYear() != null) { years.add(entry.getYear()); } Integer duration = entry.getDuration(); if (duration != null) { totalDuration += duration; } } } String artistName = ""; bookDescription = "Could not collect any info about the book at this time"; try { artistName = artists.iterator().next(); String endpoint = "getBookDirectory"; if (Util.isTagBrowsing(context)) { endpoint = "getBook"; } SharedPreferences prefs = Util.getPreferences(context); String url = Util.getRestUrl(context, endpoint) + "&id=" + directory.getId() + "&f=json"; Log.w("GetInfo", url); String artist, title; int year = 0; artist = title = ""; try { artist = artists.iterator().next(); } catch (Exception e) { Log.w("GetInfoArtist", e.toString()); } try { title = titleView.getText().toString(); } catch (Exception e) { Log.w("GetInfoTitle", e.toString()); } try { year = years.iterator().next(); } catch (Exception e) { Log.w("GetInfoYear", e.toString()); } BookInfoAPIParams params = new BookInfoAPIParams(url, artist, title, year); bookInfo = new BookInfoAPI(context).execute(params).get(); bookDescription = bookInfo[0]; bookReader = bookInfo[1]; } catch (Exception e) { Log.w("GetInfoError", e.toString()); } if (bookDescription.equals("noInfo")) { bookDescription = "The server has no description for this book"; } final TextView artistView = (TextView) header.findViewById(R.id.select_album_artist); if (podcastDescription != null || artistInfo != null || bookDescription != null) { artistView.setVisibility(View.VISIBLE); String text = ""; if (bookDescription != null) { text = bookDescription; } if (podcastDescription != null) { text = podcastDescription; } if (artistInfo != null) { text = artistInfo.getBiography(); } Spanned spanned = null; if (text != null) { String newText = ""; try { if (!artistName.equals("")) { newText += "<b>" + context.getResources().getString(R.string.main_artist) + "</b>: " + artistName + "<br/>"; } } catch (Exception e) { } try { if (totalDuration > 0) { newText += "<b>" + context.getResources().getString(R.string.album_book_reader) + "</b>: " + bookReader + "<br/>"; } } catch (Exception e) { } try { if (totalDuration > 0) { newText += "<b>" + context.getResources().getString(R.string.album_book_length) + "</b>: " + Util.formatDuration(totalDuration) + "<br/>"; } } catch (Exception e) { } try { newText += text + "<br/>"; } catch (Exception e) { } spanned = Html.fromHtml(newText); } artistView.setText(spanned); artistView.setSingleLine(false); final int minLines = context.getResources().getInteger(R.integer.TextDescriptionLength); artistView.setLines(minLines); artistView.setTextAppearance(context, android.R.style.TextAppearance_Small); final Spanned spannedText = spanned; artistView.setOnClickListener(new View.OnClickListener() { @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onClick(View v) { if (artistView.getMaxLines() == minLines) { // Use LeadingMarginSpan2 to try to make text flow around image Display display = context.getWindowManager().getDefaultDisplay(); ImageView coverArtView = (ImageView) header.findViewById(R.id.select_album_art); coverArtView.measure(display.getWidth(), display.getHeight()); int height, width; ViewGroup.MarginLayoutParams vlp = (ViewGroup.MarginLayoutParams) coverArtView .getLayoutParams(); if (coverArtView.getDrawable() != null) { height = coverArtView.getMeasuredHeight() + coverArtView.getPaddingBottom(); width = coverArtView.getWidth() + coverArtView.getPaddingRight(); } else { height = coverArtView.getHeight(); width = coverArtView.getWidth() + coverArtView.getPaddingRight(); } float textLineHeight = artistView.getPaint().getTextSize(); int lines = (int) Math.ceil(height / textLineHeight) + 1; SpannableString ss = new SpannableString(spannedText); ss.setSpan(new MyLeadingMarginSpan2(lines, width), 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); View linearLayout = header.findViewById(R.id.select_album_text_layout); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) linearLayout .getLayoutParams(); int[] rules = params.getRules(); rules[RelativeLayout.RIGHT_OF] = 0; params.leftMargin = vlp.rightMargin; artistView.setText(ss); artistView.setMaxLines(100); vlp = (ViewGroup.MarginLayoutParams) titleView.getLayoutParams(); vlp.leftMargin = width; } else { artistView.setMaxLines(minLines); } } }); artistView.setMovementMethod(LinkMovementMethod.getInstance()); } else if (topTracks) { artistView.setText(R.string.menu_top_tracks); artistView.setVisibility(View.VISIBLE); } else if (showAll) { artistView.setText(R.string.menu_show_all); artistView.setVisibility(View.VISIBLE); } else if (artists.size() == 1) { String artistText = artists.iterator().next(); if (years.size() == 1) { artistText += " - " + years.iterator().next(); } artistView.setText(artistText); artistView.setVisibility(View.VISIBLE); } else { artistView.setVisibility(View.GONE); } TextView songCountView = (TextView) header.findViewById(R.id.select_album_song_count); TextView songLengthView = (TextView) header.findViewById(R.id.select_album_song_length); if (podcastDescription != null || artistInfo != null) { songCountView.setVisibility(View.GONE); songLengthView.setVisibility(View.GONE); } else { String s = context.getResources().getQuantityString(R.plurals.select_album_n_songs, songCount, songCount); songCountView.setVisibility(View.GONE); songLengthView.setVisibility(View.GONE); } }
From source file:com.Beat.RingdroidEditActivity.java
private void handleFatalError(final CharSequence errorInternalName, final CharSequence errorString, final Exception exception) { Log.i("Ringdroid", "handleFatalError"); SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); int failureCount = prefs.getInt(PREF_ERROR_COUNT, 0); final SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_ERROR_COUNT, failureCount + 1); prefsEditor.commit();/*from w ww. j av a2s.com*/ // Check if we already have a pref for whether or not we can // contact the server. int serverAllowed = prefs.getInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_UNKNOWN); if (serverAllowed == SERVER_ALLOWED_NO) { Log.i("Ringdroid", "ERR: SERVER_ALLOWED_NO"); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } if (serverAllowed == SERVER_ALLOWED_YES) { Log.i("Ringdroid", "SERVER_ALLOWED_YES"); new AlertDialog.Builder(RingdroidEditActivity.this).setTitle(R.string.alert_title_failure) .setMessage(errorString) .setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sendErrToServerAndFinish(errorInternalName, exception); return; } }).setCancelable(false).show(); return; } // The number of times the user must have had a failure before // we'll ask them. Defaults to 1, and each time they click "Later" // we double and add 1. final int allowServerCheckIndex = prefs.getInt(PREF_ERR_SERVER_CHECK, 1); if (failureCount < allowServerCheckIndex) { Log.i("Ringdroid", "failureCount " + failureCount + " is less than " + allowServerCheckIndex); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } final SpannableString message = new SpannableString( errorString + ". " + getResources().getText(R.string.error_server_prompt)); Linkify.addLinks(message, Linkify.ALL); AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure) .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); sendErrToServerAndFinish(errorInternalName, exception); } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_CHECK, 1 + allowServerCheckIndex * 2); Log.i("Ringdroid", "Won't check again until " + (1 + allowServerCheckIndex * 2) + " errors."); prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:org.de.jmg.learn._MainActivity.java
void StartEdit() throws Exception { _txtWord.setText(lib.getSpanableString(_vok.getWort()), TextView.BufferType.SPANNABLE); _txtWord.setVisibility(View.GONE); _txtKom.setVisibility(View.GONE); _txtedWord.setVisibility(View.VISIBLE); _txtedWord.setText(_txtWord.getText()); /*//from ww w .j a v a 2s .co m if (_vok.getSprache() == EnumSprachen.Hebrew) { try { lib.setLocale(context, "he"); } catch (Exception ex) { try { lib.setLocale(context, "iw"); } catch (Exception eex) { lib.ShowException(_main,eex); } } } */ _txtedWord.setTextSize(TypedValue.COMPLEX_UNIT_PX, _txtWord.getTextSize()); View LayWord = findViewById(R.id.LayWord); assert LayWord != null; RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) LayWord.getLayoutParams(); params.width = LayoutParams.MATCH_PARENT; LayWord.setLayoutParams(params); _txtedKom.setVisibility(View.VISIBLE); _txtedKom.setText(_vok.getKommentar()); _txtedKom.setTextSize(TypedValue.COMPLEX_UNIT_PX, _txtKom.getTextSize()); _txtedWord.setImeOptions(EditorInfo.IME_ACTION_NEXT); _txtedKom.setImeOptions(EditorInfo.IME_ACTION_NEXT); _txtedWord.setSingleLine(false); _txtedWord.setMaxLines(3); _txtedKom.setSingleLine(false); _txtedKom.setMaxLines(3); if (!_vok.getCardMode()) { _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_NEXT); _txtMeaning2.setVisibility(View.VISIBLE); _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_NEXT); _txtMeaning3.setVisibility(View.VISIBLE); _txtMeaning3.setImeOptions(EditorInfo.IME_ACTION_DONE); _txtMeaning2.setText(_vok.getBedeutung2()); _txtMeaning3.setText(_vok.getBedeutung3()); lib.setBgEditText(_txtMeaning1, _MeaningBG); lib.setBgEditText(_txtMeaning2, _MeaningBG); lib.setBgEditText(_txtMeaning3, _MeaningBG); _txtMeaning1.setLines(1); _txtMeaning1.setSingleLine(); _txtMeaning2.setLines(1); _txtMeaning2.setSingleLine(); _txtMeaning3.setLines(1); _txtMeaning3.setSingleLine(); } else { lib.setBgEditText(_txtMeaning1, _MeaningBG); _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_DONE); //_originalMovementmethod = _txtMeaning1.getMovementMethod(); //_txtMeaning1.setAutoLinkMask(0); if (_originalMovementmethod != null && _txtMeaning1.getMovementMethod() == LinkMovementMethod.getInstance()) { _txtMeaning1.setMovementMethod(_originalMovementmethod); } //_txtMeaning1.requestFocus(); //InputMethodManager Imn = (InputMethodManager) _main.getSystemService(Context.INPUT_METHOD_SERVICE); //Imn.showSoftInputFromInputMethod(_txtMeaning1.getWindowToken(), 0); } //_txtMeaning1.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE); _txtMeaning1.setText(_vok.getBedeutung1()); setBtnsEnabled(false); _btnEdit.setEnabled(true); _txtMeaning1.clearFocus(); _txtedWord.clearFocus(); //_txtedWord.requestFocusFromTouch(); _txtedWord.requestFocus(); mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { lib.removeLayoutListener(mainView.getViewTreeObserver(), this); _txtedWord.requestFocus(); } }); }
From source file:de.azapps.mirakel.main_activity.MainActivity.java
private void handleIntent(final Intent intent) { if ((intent == null) || (intent.getAction() == null)) { Log.d(MainActivity.TAG, "action null"); } else if (DefinitionsHelper.SHOW_TASK.equals(intent.getAction()) || DefinitionsHelper.SHOW_TASK_REMINDER.equals(intent.getAction()) || DefinitionsHelper.SHOW_TASK_FROM_WIDGET.equals(intent.getAction())) { final Optional<Task> task = TaskHelper.getTaskFromIntent(intent); if (task.isPresent()) { this.currentList = task.get().getList(); if (this.mDrawerLayout != null) { this.mDrawerLayout.postDelayed(new Runnable() { @Override/*from w w w. j ava 2 s. com*/ public void run() { setCurrentTask(task.get(), true); } }, 10L); } } else { Log.d(MainActivity.TAG, "task null"); } if (intent.getAction().equals(DefinitionsHelper.SHOW_TASK_FROM_WIDGET)) { this.closeOnBack = true; } } else if (intent.getAction().equals(Intent.ACTION_SEND) || intent.getAction().equals(Intent.ACTION_SEND_MULTIPLE)) { this.closeOnBack = true; this.newTaskContent = intent.getStringExtra(Intent.EXTRA_TEXT); this.newTaskSubject = intent.getStringExtra(Intent.EXTRA_SUBJECT); // If from google now, the content is the subject if ((intent.getCategories() != null) && intent.getCategories().contains("com.google.android.voicesearch.SELF_NOTE") && !this.newTaskContent.isEmpty()) { this.newTaskSubject = this.newTaskContent; this.newTaskContent = ""; } if (!"text/plain".equals(intent.getType()) && (this.newTaskSubject == null)) { this.newTaskSubject = MirakelCommonPreferences.getImportFileTitle(); } final Optional<ListMirakel> listFromSharing = MirakelModelPreferences.getImportDefaultList(); if (listFromSharing.isPresent()) { addTaskFromSharing(listFromSharing.get(), intent); } else { final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.import_to); final List<CharSequence> items = new ArrayList<>(); final List<Long> list_ids = new ArrayList<>(); final int currentItem = 0; for (final ListMirakel list : ListMirakel.all()) { if (list.getId() > 0) { items.add(list.getName()); list_ids.add(list.getId()); } } builder.setSingleChoiceItems(items.toArray(new CharSequence[items.size()]), currentItem, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final Optional<ListMirakel> listMirakelOptional = ListMirakel .get(list_ids.get(which)); withOptional(listMirakelOptional, new OptionalUtils.Procedure<ListMirakel>() { @Override public void apply(final ListMirakel input) { addTaskFromSharing(input, intent); dialog.dismiss(); } }); } }); builder.create().show(); } } else if (intent.getAction().equals(DefinitionsHelper.SHOW_LIST) || intent.getAction().contains(DefinitionsHelper.SHOW_LIST_FROM_WIDGET)) { final Optional<ListMirakel> listMirakelOptional = ListHelper.getListMirakelFromIntent(intent); if (listMirakelOptional.isPresent()) { final ListMirakel list = listMirakelOptional.get(); setCurrentList(list); final Optional<Task> taskOptional = list.getFirstTask(); if (taskOptional.isPresent()) { this.currentTask = taskOptional.get(); } if (getTaskFragment() != null) { getTaskFragment().update(this.currentTask); } } else { Log.d(TAG, "show_list does not pass list, so ignore this"); } } else if (intent.getAction().equals(DefinitionsHelper.SHOW_LISTS)) { this.mDrawerLayout.openDrawer(DefinitionsHelper.GRAVITY_LEFT); } else if (intent.getAction().equals(Intent.ACTION_SEARCH)) { final String query = intent.getStringExtra(SearchManager.QUERY); search(query); } else if (intent.getAction().contains(DefinitionsHelper.ADD_TASK_FROM_WIDGET)) { final int listId = Integer .parseInt(intent.getAction().replace(DefinitionsHelper.ADD_TASK_FROM_WIDGET, "")); final Optional<ListMirakel> listMirakelOptional = ListMirakel.get(listId); if (listMirakelOptional.isPresent()) { setCurrentList(listMirakelOptional.get()); } else { setCurrentList(ListMirakel.safeFirst()); } this.mDrawerLayout.postDelayed(new Runnable() { @Override public void run() { if ((getTasksFragment() != null) && getTasksFragment().isReady()) { getTasksFragment().focusNew(true); } else if (!MirakelCommonPreferences.isTablet()) { runOnUiThread(new Runnable() { @Override public void run() { if (getTasksFragment() != null) { getTasksFragment().focusNew(true); } else { Log.wtf(MainActivity.TAG, "Tasksfragment null"); } } }); } } }, 10); } else if (intent.getAction().equals(DefinitionsHelper.SHOW_MESSAGE)) { final String message = intent.getStringExtra(Intent.EXTRA_TEXT); String subject = intent.getStringExtra(Intent.EXTRA_SUBJECT); if (message != null) { if (subject == null) { subject = getString(R.string.message_notification); } final TextView msg = (TextView) getLayoutInflater().inflate(R.layout.alertdialog_textview, null); msg.setText(Html.fromHtml(message)); msg.setMovementMethod(LinkMovementMethod.getInstance()); msg.setClickable(true); new AlertDialog.Builder(this).setTitle(subject).setView(msg).show(); } } else { setCurrentItem(getTaskFragmentPosition()); } if (((intent == null) || (intent.getAction() == null) || !intent.getAction().contains(DefinitionsHelper.ADD_TASK_FROM_WIDGET)) && (getTasksFragment() != null)) { getTasksFragment().clearFocus(); } setIntent(null); if (this.currentList == null) { setCurrentList(SpecialList.firstSpecialSafe()); } }
From source file:mobi.omegacentauri.ptimer.PTimerEditActivity.java
void showServerPrompt(final boolean userInitiated) { final SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); final SpannableString message = new SpannableString(getResources().getText(R.string.server_prompt)); Linkify.addLinks(message, Linkify.ALL); final AlertDialog dialog = new AlertDialog.Builder(PTimerEditActivity.this).setTitle(R.string.server_title) .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); if (userInitiated) { finish();/* w w w.j av a 2 s . c om*/ } else { sendStatsToServerAndFinish(); } } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { int allowServerCheckIndex = prefs.getInt(PREF_STATS_SERVER_CHECK, 2); int successCount = prefs.getInt(PREF_SUCCESS_COUNT, 0); SharedPreferences.Editor prefsEditor = prefs.edit(); if (userInitiated) { prefsEditor.putInt(PREF_STATS_SERVER_CHECK, successCount + 2); } else { prefsEditor.putInt(PREF_STATS_SERVER_CHECK, allowServerCheckIndex * 2); } prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_NO); if (userInitiated) { // If the user initiated, err on the safe side and disable // sending crash reports too. There's no way to turn them // back on now aside from clearing data from this app, but // it doesn't matter, we don't need error reports from every // user ever. prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); } prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.SpeechEd.SpeechEdEditActivity.java
void showServerPrompt(final boolean userInitiated) { final SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); final SpannableString message = new SpannableString(getResources().getText(R.string.server_prompt)); Linkify.addLinks(message, Linkify.ALL); final AlertDialog dialog = new AlertDialog.Builder(SpeechEdEditActivity.this) .setTitle(R.string.server_title).setMessage(message) .setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); if (userInitiated) { finish();//from w ww. j a v a2 s. c o m } else { sendStatsToServerAndFinish(); } } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { int allowServerCheckIndex = prefs.getInt(PREF_STATS_SERVER_CHECK, 2); int successCount = prefs.getInt(PREF_SUCCESS_COUNT, 0); SharedPreferences.Editor prefsEditor = prefs.edit(); if (userInitiated) { prefsEditor.putInt(PREF_STATS_SERVER_CHECK, successCount + 2); } else { prefsEditor.putInt(PREF_STATS_SERVER_CHECK, allowServerCheckIndex * 2); } prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_STATS_SERVER_ALLOWED, SERVER_ALLOWED_NO); if (userInitiated) { // If the user initiated, err on the safe side and disable // sending crash reports too. There's no way to turn them // back on now aside from clearing data from this app, but // it doesn't matter, we don't need error reports from every // user ever. prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); } prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }