List of usage examples for android.widget TextView setOnFocusChangeListener
public void setOnFocusChangeListener(OnFocusChangeListener l)
From source file:layout.BeaconTabFragment.java
/** * Sets up the advertising tx power view. It is initially disabled. It is enabled by clicking * on the radio button in the UI. This opens a dialog to confirm that the user really wants to * change the advertising radio tx power. After this the advertising interval can be configured. * A list pops up where the user can choose which value they want to be broadcast as the * advertising tx power./*from ww w . j a v a2 s.com*/ */ private void setUpAdvertisedTxPower(final View v) { if (advTxPower != null) { LinearLayout advTxPowerContainer = (LinearLayout) v.findViewById(R.id.change_adv_tx_slot); final TextView advTxPowerView = (TextView) v.findViewById(R.id.adv_tx_power); advTxPowerView.setText(advTxPower); advTxPowerView.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View view, boolean hasFocus) { if (!hasFocus) { String newAdvTxPower = advTxPowerView.getText().toString(); if (newAdvTxPower.length() == 0) { advTxPowerView.setText(advTxPower); } } else { advTxPowerChanged = true; } } }); advTxPowerContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { advTxPowerChanged = true; final String[] possibleValues = Utils.generateArrayWithStringValuesInRange( Utils.findMinValue(capabilities.getSupportedTxPowers()) - 5, Utils.findMaxValue(capabilities.getSupportedTxPowers()) + 5); new AlertDialog.Builder(getActivity()).setTitle("Choose advertising tx power:") .setItems(possibleValues, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { advTxPower = possibleValues[i]; advTxPowerView.setText(possibleValues[i]); } }).show(); } }); UiUtils.disableAllChildren(advTxPowerContainer); final RadioButton enableChangeAdvTxPowerButton = (RadioButton) v .findViewById(R.id.change_slot_adv_tx_power); enableChangeAdvTxPowerButton.setChecked(false); enableChangeAdvTxPowerButton.setOnClickListener(new View.OnClickListener() { private boolean enabled = false; @Override public void onClick(View view) { if (enabled) { UiUtils.disableAllChildren(v.findViewById(R.id.change_adv_tx_slot)); enableChangeAdvTxPowerButton.setChecked(false); enabled = false; } else { ConfirmationDialog.confirm("Change Advertising Interval", "Are you sure " + "you want to change the advertising interval of this beacon?", "YES", "NO", getActivity(), new ConfirmationDialog.ConfirmationListener() { @Override public void confirm() { UiUtils.enableAllChildren(v.findViewById(R.id.change_adv_tx_slot)); enableChangeAdvTxPowerButton.setChecked(true); enabled = true; } @Override public void cancel() { enableChangeAdvTxPowerButton.setChecked(false); enabled = false; } }); } } }); } }
From source file:com.air.mobilebrowser.BrowserActivity.java
/** Logs an onscreen message for debugging. */ public void logMessage(final TextView consoleView, String message, String value, int color) { if (mIsDebugEnabled && consoleView != null) { consoleView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override/*from w ww .j a va2s . c o m*/ public void onFocusChange(View v, boolean hasFocus) { ViewParent parent = consoleView.getParent(); final ScrollView scroll = (ScrollView) parent; new Handler().postDelayed(new Runnable() { @Override public void run() { scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10); } }, 0); } }); Editable editable = consoleView.getEditableText(); SpannableString str = null; if (editable == null) { editable = new SpannableStringBuilder(); str = new SpannableString(message + ": " + value); str.setSpan(new ForegroundColorSpan(color), message.length() + 2, message.length() + 2 + value.length(), 0); } else { str = new SpannableString("\n" + message + ": " + value); str.setSpan(new ForegroundColorSpan(color), message.length() + 2, message.length() + 3 + value.length(), 0); } editable.append(str); consoleView.setText(editable, TextView.BufferType.EDITABLE); ViewParent parent = consoleView.getParent(); if (parent instanceof ScrollView) { final ScrollView scroll = (ScrollView) parent; new Handler().postDelayed(new Runnable() { @Override public void run() { scroll.smoothScrollTo(0, consoleView.getMeasuredHeight() + 10); } }, 1000); } } }
From source file:com.android.launcher3.Hotseat.java
void resetLayout() { mContent.removeAllViewsInLayout();/*from w ww . j ava2 s. co m*/ if (!FeatureFlags.NO_ALL_APPS_ICON) { // Add the Apps button Context context = getContext(); int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank(); LayoutInflater inflater = LayoutInflater.from(context); TextView allAppsButton = (TextView) inflater.inflate(R.layout.all_apps_button, mContent, false); Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon); mLauncher.resizeIconDrawable(d); int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down); Rect bounds = d.getBounds(); d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx, bounds.bottom - scaleDownPx / 2); allAppsButton.setCompoundDrawables(null, d, null, null); allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label)); allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener()); if (mLauncher != null) { mLauncher.setAllAppsButton(allAppsButton); allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener()); allAppsButton.setOnClickListener(mLauncher); allAppsButton.setOnLongClickListener(mLauncher); allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler); } // Note: We do this to ensure that the hotseat is always laid out in the orientation of // the hotseat in order regardless of which orientation they were added int x = getCellXFromOrder(allAppsButtonRank); int y = getCellYFromOrder(allAppsButtonRank); CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1); lp.canReorder = false; mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true); } }
From source file:org.de.jmg.learn._MainActivity.java
public void getVokabel(final boolean showBeds, boolean LoadNext, boolean requestFocusEdWord, boolean DontPrompt) throws Exception { if (iv != null) { iv.setVisibility(View.GONE); }//w w w.ja v a 2 s. c om if (iv2 != null) iv2.setVisibility(View.GONE); try { if (_btnRight == null) return; EndEdit(DontPrompt); setBtnsEnabled(true); if (showBeds && _vok.getIndex() >= 1) { _btnRight.setEnabled(true); _btnWrong.setEnabled(true); _btnEdit.setEnabled(true); _btnSkip.setEnabled(true); _btnView.setEnabled(true); } else { _btnRight.setEnabled(false); _btnWrong.setEnabled(false); if (_vok.getIndex() < 1) { _btnEdit.setEnabled(false); _btnSkip.setEnabled(false); _btnView.setEnabled(false); } } if (LoadNext) _vok.setLernIndex((short) (_vok.getLernIndex() + 1)); View v; TextView t; String txtBed = getString(R.string.cloze); if (showBeds) { v = findViewById(R.id.txtMeaning1); t = (TextView) v; assert t != null; t.setText(lib.getSpanableString(_vok.getBedeutung1())); txtBed = t.getText().toString(); } v = findViewById(R.id.word); t = (TextView) v; assert t != null; String txtWord = getString(R.string.cloze); if (!_vok.reverse || showBeds) { t.setText(lib.getSpanableString(_vok.getWort()), TextView.BufferType.SPANNABLE); txtWord = t.getText().toString(); txtWord = replaceClozes(txtWord, txtBed); speak(txtWord, _vok.getLangWord(), "word", true); } else { t.setText(""); } if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch || (_vok.getFontWort().getName().equalsIgnoreCase("Cardo"))) { t.setTypeface(_vok.TypefaceCardo); _txtedWord.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); _txtedWord.setTypeface(Typeface.DEFAULT); } t.scrollTo(0, 0); v = findViewById(R.id.Comment); t = (TextView) v; assert t != null; t.setVisibility(View.VISIBLE); SpannableString tspanKom = lib.getSpanableString(_vok.getKommentar()); URLSpan[] urlSpans = tspanKom.getSpans(0, tspanKom.length(), URLSpan.class); for (final URLSpan span : urlSpans) { int start = tspanKom.getSpanStart(span); int end = tspanKom.getSpanEnd(span); String txt = tspanKom.toString().substring(start, end); if (txtIsPicture(txt)) { tspanKom.removeSpan(span); tspanKom.setSpan(new urlclickablespan(span.getURL()) { @Override public void onClick(View widget) { Bitmap b; try { b = lib.downloadpicture(this.url); } catch (Exception ex) { b = null; } if (b != null) { if (iv == null) { iv = new ImageView(context); SetTouchListener(iv); } b = resizeBM(b); iv.setImageBitmap(b); if (iv.getParent() == null) { try { LayoutParams p = _txtMeaning1.getLayoutParams(); //p.width = LayoutParams.WRAP_CONTENT; //p.height = LayoutParams.WRAP_CONTENT; rellayoutMain.addView(iv, p); } catch (Exception ex) { Log.e("addImageView", ex.getMessage(), ex); } } else { Log.d("ImageView", "exists"); } _txtMeaning1.setVisibility(View.GONE); iv.setVisibility(View.VISIBLE); } } }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } t.setText(tspanKom, TextView.BufferType.SPANNABLE); if (_vok.getSprache() == EnumSprachen.Hebrew || _vok.getSprache() == EnumSprachen.Griechisch || (_vok.getFontKom().getName().equalsIgnoreCase("Cardo"))) { t.setTypeface(_vok.TypefaceCardo); _txtedKom.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); _txtedKom.setTypeface(Typeface.DEFAULT); } if (_isSmallDevice && libString.IsNullOrEmpty(t.getText().toString())) { t.setVisibility(View.GONE); } else { t.setVisibility(View.VISIBLE); } t.scrollTo(0, 0); v = findViewById(R.id.txtMeaning1); t = (TextView) v; assert t != null; if (!libString.IsNullOrEmpty(_vok.getBedeutung2())) { t.setImeOptions(EditorInfo.IME_ACTION_NEXT); } if (_vok.reverse || showBeds) { SpannableString tspan = lib.getSpanableString(_vok.getBedeutung1()); //final String picname = _main.getString(R.string.picture); t.setVisibility(View.VISIBLE); if (txtIsPicture(tspan.toString())) { URLSpan urlspn[] = tspan.getSpans(0, tspan.length(), URLSpan.class); for (URLSpan url : urlspn) { Bitmap b; try { b = lib.downloadpicture(url.getURL()); } catch (Exception ex) { b = null; } if (b != null) { if (iv == null) { iv = new ImageView(context); SetTouchListener(iv); } b = resizeBM(b); iv.setImageBitmap(b); if (iv.getParent() == null) { try { LayoutParams p = t.getLayoutParams(); //p.width = LayoutParams.WRAP_CONTENT; //p.height = LayoutParams.WRAP_CONTENT; rellayoutMain.addView(iv, p); } catch (Exception ex) { Log.e("Imagview", ex.getMessage(), ex); } } else { Log.d("ImageView", "exists"); } t.setVisibility(View.GONE); iv.setVisibility(View.VISIBLE); } } } else { // iv.setVisibility(View.GONE); t.setVisibility(View.VISIBLE); } t.setText(tspan); } else { t.setText(Vokabel.getComment(_vok.getBedeutung1())); } if (_vok.reverse || showBeds) { String txt = t.getText().toString(); txt = replaceClozes(txt, txtWord); speak(txt, _vok.getLangMeaning(), "meaning1", _vok.reverse); } if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) { t.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); } t.setOnFocusChangeListener(FocusListenerMeaning1); t.scrollTo(0, 0); v = findViewById(R.id.txtMeaning2); t = (TextView) v; assert t != null; t.setText((_vok.reverse || showBeds ? _vok.getBedeutung2() : Vokabel.getComment(_vok.getBedeutung2()))); if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) { t.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); } if (libString.IsNullOrEmpty(_vok.getBedeutung2()) || _vok.getCardMode()) { t.setVisibility(View.GONE); _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_DONE); } else { t.setVisibility(View.VISIBLE); _txtMeaning1.setImeOptions(EditorInfo.IME_ACTION_NEXT); if (_vok.reverse || showBeds) { String txt = t.getText().toString(); //if (txtWord != null) // txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord); speak(txt, _vok.getLangMeaning(), "meaning2"); } } v = findViewById(R.id.txtMeaning3); t = (TextView) v; assert t != null; t.setText((_vok.reverse || showBeds ? _vok.getBedeutung3() : Vokabel.getComment(_vok.getBedeutung3()))); if (_vok.getFontBed().getName().equalsIgnoreCase("Cardo")) { t.setTypeface(_vok.TypefaceCardo); } else { t.setTypeface(Typeface.DEFAULT); } if (libString.IsNullOrEmpty(_vok.getBedeutung3()) || _vok.getCardMode()) { t.setVisibility(View.GONE); _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_DONE); } else { t.setVisibility(View.VISIBLE); _txtMeaning2.setImeOptions(EditorInfo.IME_ACTION_NEXT); _txtMeaning3.setImeOptions(EditorInfo.IME_ACTION_DONE); if (_vok.reverse || showBeds) { String txt = t.getText().toString(); //if (txtWord != null) // txt = txt.replaceAll("_{2,}", txtWord).replaceAll("\\.{4,}", txtWord); speak(txt, _vok.getLangMeaning(), "meaning3"); } } if (_vok.reverse && showBeds) speak(txtWord, _vok.getLangWord(), "word"); lib.setBgEditText(_txtMeaning1, _MeaningBG); lib.setBgEditText(_txtMeaning2, _MeaningBG); lib.setBgEditText(_txtMeaning3, _MeaningBG); if (!_isSmallDevice && !requestFocusEdWord) { _txtMeaning1.requestFocus(); } else { if (!requestFocusEdWord) _txtWord.requestFocus(); else _txtedWord.requestFocus(); } SetActionBarTitle(); _scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { lib.removeLayoutListener(_scrollView.getViewTreeObserver(), this); hideKeyboard(); if (showBeds) { _scrollView.scrollTo(0, _txtMeaning1.getTop()); } else { _txtWord.requestFocus(); _scrollView.fullScroll(View.FOCUS_UP); } } }); } catch (Exception e) { lib.ShowException(_main, e); } }