List of usage examples for android.text Layout getHeight
public int getHeight()
From source file:com.amazon.android.ui.widget.ReadTextView.java
/** * Draw a gradient on the text so that the bottom and top line have a faded effect if the user * can scroll in that direction./* www. ja va 2 s. c om*/ */ private void updateGradient() { if (mText == null || mScrollView == null) { return; } final Layout layout = mText.getLayout(); assert layout != null; final Rect bounds = new Rect(); getTextBounds(bounds); final int topLine = topVisibleLineOfText(layout, bounds); final int bottomLine = bottomVisibleLineOfText(layout, bounds); final int fullHeight = layout.getHeight(); if (fullHeight > 0) { final float bottomLineHeight = layout.getLineBottom(bottomLine) - layout.getLineTop(bottomLine); final float topLineHeight = layout.getLineBottom(topLine) - layout.getLineTop(topLine); this.setFadingEdgeLength((int) Math.max(topLineHeight, bottomLineHeight)); } }
From source file:com.coreform.open.android.formidablevalidation.SetErrorHandler.java
private void chooseSize(PopupWindow pop, CharSequence text, TextView tv) { int wid = tv.getPaddingLeft() + tv.getPaddingRight(); int ht = tv.getPaddingTop() + tv.getPaddingBottom(); //com.android.internal.R.dimen.textview_error_popup_default_width introduced after Gingerbread, only has one variant (240dip) int defaultWidthInPixels = mContext.getResources() .getDimensionPixelSize(R.dimen.textview_error_popup_default_width); Layout l = new StaticLayout(text, tv.getPaint(), defaultWidthInPixels, Layout.Alignment.ALIGN_NORMAL, 1, 0, true);//from w w w . j a v a 2 s. c o m float max = 0; for (int i = 0; i < l.getLineCount(); i++) { max = Math.max(max, l.getLineWidth(i)); } if (DEBUG) Log.d(TAG, "max: " + max + ", height: " + l.getHeight()); /* * Now set the popup size to be big enough for the text plus the border. */ pop.setWidth(wid + (int) Math.ceil(max)); pop.setHeight(ht + l.getHeight()); //TODO: buggy (the 2 shouldnt need to be there) }
From source file:org.asnelt.derandom.MainActivity.java
/** * Initializes this activity and eventually recovers its state. * @param savedInstanceState Bundle with saved state *//*from w w w . j a v a2 s.c o m*/ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); textHistoryInput = (HistoryView) findViewById(R.id.text_history_input); textHistoryInput.setHistoryViewListener(this); textHistoryPrediction = (HistoryView) findViewById(R.id.text_history_prediction); textHistoryPrediction.setHistoryViewListener(this); textPrediction = (TextView) findViewById(R.id.text_prediction); textInput = (EditText) findViewById(R.id.text_input); spinnerInput = (Spinner) findViewById(R.id.spinner_input); spinnerGenerator = (Spinner) findViewById(R.id.spinner_generator); progressBar = (ProgressBar) findViewById(R.id.progress_bar); textInput.setRawInputType(InputType.TYPE_CLASS_NUMBER); textHistoryInput.setHorizontallyScrolling(true); textHistoryPrediction.setHorizontallyScrolling(true); textPrediction.setHorizontallyScrolling(true); textHistoryInput.setMovementMethod(new ScrollingMovementMethod()); textHistoryPrediction.setMovementMethod(new ScrollingMovementMethod()); textPrediction.setMovementMethod(new ScrollingMovementMethod()); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayShowHomeEnabled(true); actionBar.setIcon(R.drawable.ic_launcher); } FragmentManager fragmentManager = getSupportFragmentManager(); processingFragment = (ProcessingFragment) fragmentManager.findFragmentByTag(TAG_PROCESSING_FRAGMENT); // Generate new fragment if there is no retained fragment if (processingFragment == null) { processingFragment = new ProcessingFragment(); fragmentManager.beginTransaction().add(processingFragment, TAG_PROCESSING_FRAGMENT).commit(); } // Apply predictions length preference int predictionLength = getNumberPreference(SettingsActivity.KEY_PREF_PREDICTION_LENGTH); processingFragment.setPredictionLength(predictionLength); // Apply server port preference int serverPort = getNumberPreference(SettingsActivity.KEY_PREF_SOCKET_PORT); processingFragment.setServerPort(serverPort); // Apply history length preference int historyLength = getNumberPreference(SettingsActivity.KEY_PREF_HISTORY_LENGTH); textHistoryInput.setCapacity(historyLength); textHistoryPrediction.setCapacity(historyLength); processingFragment.setCapacity(historyLength); // Apply color preference SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); if (sharedPreferences.getBoolean(SettingsActivity.KEY_PREF_COLORED_PAST, true)) { textHistoryPrediction.enableColor(null); } // Apply auto-detect preference boolean autoDetect = sharedPreferences.getBoolean(SettingsActivity.KEY_PREF_AUTO_DETECT, true); processingFragment.setAutoDetect(autoDetect); // Eventually recover state if (savedInstanceState != null) { Layout layout = textHistoryInput.getLayout(); if (layout != null) { textHistoryInput.scrollTo(0, layout.getHeight()); } layout = textHistoryPrediction.getLayout(); if (layout != null) { textHistoryPrediction.scrollTo(0, layout.getHeight()); } textPrediction.scrollTo(0, 0); Uri inputUri = processingFragment.getInputUri(); if (inputUri != null) { disableDirectInput(inputUri); } if (processingFragment.getInputSelection() == INDEX_SOCKET_INPUT) { disableDirectInput(null); } } // Create an ArrayAdapter using the string array and a default spinner layout String[] inputNames = new String[3]; inputNames[INDEX_DIRECT_INPUT] = getResources().getString(R.string.input_direct_name); inputNames[INDEX_FILE_INPUT] = getResources().getString(R.string.input_file_name); inputNames[INDEX_SOCKET_INPUT] = getResources().getString(R.string.input_socket_name); ArrayAdapter<String> spinnerInputAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, inputNames); // Specify the layout to use when the list of choices appears spinnerInputAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinnerInput.setAdapter(spinnerInputAdapter); spinnerInput.setOnItemSelectedListener(this); if (spinnerInput.getSelectedItemPosition() != processingFragment.getInputSelection()) { spinnerInput.setSelection(processingFragment.getInputSelection()); } // Create an ArrayAdapter using the string array and a default spinner layout String[] generatorNames = processingFragment.getGeneratorNames(); ArrayAdapter<String> spinnerGeneratorAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, generatorNames); // Specify the layout to use when the list of choices appears spinnerGeneratorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner spinnerGenerator.setAdapter(spinnerGeneratorAdapter); spinnerGenerator.setOnItemSelectedListener(this); if (processingFragment.isMissingUpdate()) { // The activity missed an update while it was reconstructed processingFragment.updateAll(); } onProgressUpdate(); }
From source file:lewa.support.v7.widget.SwitchCompat.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Rect padding = mTempRect; final Drawable trackDrawable = mTrackDrawable; if (trackDrawable != null) { trackDrawable.getPadding(padding); } else {/*w w w .j av a 2 s.c o m*/ padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final int switchInnerTop = switchTop + padding.top; final int switchInnerBottom = switchBottom - padding.bottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { trackDrawable.draw(canvas); } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; if (switchText != null) { final int drawableState[] = getDrawableState(); if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0)); } mTextPaint.drawableState = drawableState; final int cX; if (thumbDrawable != null) { final Rect bounds = thumbDrawable.getBounds(); cX = bounds.left + bounds.right; } else { cX = getWidth(); } final int left = cX / 2 - switchText.getWidth() / 2; final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2; canvas.translate(left, top); switchText.draw(canvas); } canvas.restoreToCount(saveCount); }
From source file:android.support.v7.widget.SwitchCompat.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Rect padding = mTempRect; final Drawable trackDrawable = mTrackDrawable; if (trackDrawable != null) { trackDrawable.getPadding(padding); } else {// w w w. j a v a 2 s.c o m padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final int switchInnerTop = switchTop + padding.top; final int switchInnerBottom = switchBottom - padding.bottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { if (mSplitTrack && thumbDrawable != null) { final Rect insets = DrawableUtils.getOpticalBounds(thumbDrawable); thumbDrawable.copyBounds(padding); padding.left += insets.left; padding.right -= insets.right; final int saveCount = canvas.save(); canvas.clipRect(padding, Region.Op.DIFFERENCE); trackDrawable.draw(canvas); canvas.restoreToCount(saveCount); } else { trackDrawable.draw(canvas); } } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; if (switchText != null) { final int drawableState[] = getDrawableState(); if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0)); } mTextPaint.drawableState = drawableState; final int cX; if (thumbDrawable != null) { final Rect bounds = thumbDrawable.getBounds(); cX = bounds.left + bounds.right; } else { cX = getWidth(); } final int left = cX / 2 - switchText.getWidth() / 2; final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2; canvas.translate(left, top); switchText.draw(canvas); } canvas.restoreToCount(saveCount); }
From source file:rikka.akashitoolkit.ui.widget.IconSwitchCompat.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); final Rect padding = mTempRect; final Drawable trackDrawable = mTrackDrawable; if (trackDrawable != null) { trackDrawable.getPadding(padding); } else {/*w w w . j a v a2 s.c o m*/ padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final int switchInnerTop = switchTop + padding.top; final int switchInnerBottom = switchBottom - padding.bottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { if (mSplitTrack && thumbDrawable != null) { final Rect insets = DrawableUtils.getOpticalBounds(thumbDrawable); thumbDrawable.copyBounds(padding); padding.left += insets.left; padding.right -= insets.right; final int saveCount = canvas.save(); canvas.clipRect(padding, Region.Op.DIFFERENCE); trackDrawable.draw(canvas); canvas.restoreToCount(saveCount); } else { trackDrawable.draw(canvas); } } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } final Drawable iconDrawable = mIconDrawable; if (iconDrawable != null) { if (mSplitTrack) { final Rect insets = DrawableUtils.getOpticalBounds(iconDrawable); iconDrawable.copyBounds(padding); padding.left += insets.left; padding.right -= insets.right; //final int saveCount = canvas.save(); canvas.clipRect(padding, Region.Op.DIFFERENCE); iconDrawable.draw(canvas); canvas.restoreToCount(saveCount); } else { iconDrawable.draw(canvas); } } final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; if (switchText != null) { final int drawableState[] = getDrawableState(); if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0)); } mTextPaint.drawableState = drawableState; final int cX; if (thumbDrawable != null) { final Rect bounds = thumbDrawable.getBounds(); cX = bounds.left + bounds.right; } else { cX = getWidth(); } final int left = cX / 2 - switchText.getWidth() / 2; final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2; canvas.translate(left, top); switchText.draw(canvas); } canvas.restoreToCount(saveCount); }
From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); if (!isEnabled()) {//wangbin added this line if (mThumbDrawable != null) { mThumbDrawable.setColor(getDisableColor(isChecked() ? mThumbColorOn : mThumbColorOff)); }/* w w w . j ava2s . com*/ if (mTrackDrawable != null) { mTrackDrawable.setColor(getDisableColor(isChecked() ? mTrackColorOn : mTrackColorOff)); } } final Rect padding = mTempRect; final Drawable trackDrawable = mTrackDrawable; if (trackDrawable != null) { trackDrawable.getPadding(padding); } else { padding.setEmpty(); } final int switchTop = mSwitchTop; final int switchBottom = mSwitchBottom; final int switchInnerTop = switchTop + padding.top; final int switchInnerBottom = switchBottom - padding.bottom; final Drawable thumbDrawable = mThumbDrawable; if (trackDrawable != null) { trackDrawable.draw(canvas); } final int saveCount = canvas.save(); if (thumbDrawable != null) { thumbDrawable.draw(canvas); } final Layout switchText = getTargetCheckedState() ? mOnLayout : mOffLayout; if (switchText != null) { final int drawableState[] = getDrawableState(); if (mTextColors != null) { mTextPaint.setColor(mTextColors.getColorForState(drawableState, 0)); } mTextPaint.drawableState = drawableState; final int cX; if (thumbDrawable != null) { final Rect bounds = thumbDrawable.getBounds(); cX = bounds.left + bounds.right; } else { cX = getWidth(); } final int left = cX / 2 - switchText.getWidth() / 2; final int top = (switchInnerTop + switchInnerBottom) / 2 - switchText.getHeight() / 2; canvas.translate(left, top); switchText.draw(canvas); } canvas.restoreToCount(saveCount); }