List of usage examples for android.widget TextView getHeight
@ViewDebug.ExportedProperty(category = "layout") public final int getHeight()
From source file:com.roughike.bottombar.BottomBar.java
private void updateTitleBottomPadding() { if (isIconsOnlyMode()) { return;/*from w ww.j av a 2 s. c om*/ } int tabCount = getTabCount(); if (tabContainer == null || tabCount == 0 || !isShiftingMode()) { return; } for (int i = 0; i < tabCount; i++) { BottomBarTab tab = getTabAtPosition(i); TextView title = tab.getTitleView(); if (title == null) { continue; } int baseline = title.getBaseline(); int height = title.getHeight(); int paddingInsideTitle = height - baseline; int missingPadding = tenDp - paddingInsideTitle; if (missingPadding > 0) { title.setPadding(title.getPaddingLeft(), title.getPaddingTop(), title.getPaddingRight(), missingPadding + title.getPaddingBottom()); } } }
From source file:kankan.wheel.widget.WheelView.java
/** * Draws items/* www . ja v a2s. com*/ * @param canvas the canvas for drawing */ private void drawItems(Canvas canvas) { canvas.save(); int top = (currentItem - firstItem) * getItemHeight() + (getItemHeight() - getHeight()) / 2; canvas.translate(PADDING, -top + scrollingOffset); //?? AbstractWheelTextAdapter adapter = null; if (viewAdapter instanceof AbstractWheelTextAdapter) { adapter = (AbstractWheelTextAdapter) viewAdapter; } if (adapter != null && adapter.isEnableMultiTextColor()) { int targetIndex = -1; int minDis = Integer.MAX_VALUE; for (int i = 0; i < itemsLayout.getChildCount(); i++) { TextView child = (TextView) itemsLayout.getChildAt(i); int realTop = child.getTop() - top + scrollingOffset; int viewCenter = realTop + child.getHeight() / 2; Rect bounds = centerDrawable.getBounds(); int dis = Math.abs(viewCenter - bounds.centerY()); if (dis < minDis) { minDis = dis; targetIndex = i; } } for (int i = 0; i < itemsLayout.getChildCount(); i++) { TextView view = (TextView) itemsLayout.getChildAt(i); view.setAlpha(0.5f); view.setTextColor(adapter.getTextColor()); view.setTextSize(adapter.getTextSize()); adapter.setTextViewPadding(view, adapter.getTextPaddingTop(), adapter.getTextPaddingBottom()); } if (targetIndex != -1) { TextView view = (TextView) itemsLayout.getChildAt(targetIndex); view.setAlpha(1); view.setTextColor(adapter.getTextSelectedColor()); view.setTextSize(adapter.getTextSize() + 4); adapter.setTextViewPadding(view, adapter.getTextPaddingTop() - 2, adapter.getTextPaddingBottom() - 2); } TextView view = (TextView) itemsLayout.getChildAt(targetIndex - 1); if (view != null) view.setAlpha(1); view = (TextView) itemsLayout.getChildAt(targetIndex + 1); if (view != null) view.setAlpha(1); } itemsLayout.draw(canvas); canvas.restore(); }
From source file:com.juick.android.MessageMenu.java
private int getLineAtCoordinate(TextView textView2, float y) { y -= textView2.getTotalPaddingTop(); // Clamp the position to inside of the view. y = Math.max(0.0f, y);//from w ww . j av a 2 s .c o m y = Math.min(textView2.getHeight() - textView2.getTotalPaddingBottom() - 1, y); y += textView2.getScrollY(); return textView2.getLayout().getLineForVertical((int) y); }
From source file:com.example.zayankovsky.homework.ui.ImageDetailActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.image_detail); getWindow().getDecorView().setBackgroundResource( PreferenceManager.getDefaultSharedPreferences(this).getString("theme", "light").equals("dark") ? R.color.darkColorTransparent : R.color.lightColorTransparent); // Set up activity to go full screen getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN); // Locate the main ImageView and TextView mImageView = (ImageView) findViewById(R.id.imageView); final TextView mTextView = (TextView) findViewById(R.id.textView); mSectionNumber = getIntent().getIntExtra(SECTION_NUMBER, 0); registerForContextMenu(mImageView);// w w w . ja v a 2s. co m mImageView.setLongClickable(false); // Enable some additional newer visibility and ActionBar features // to create a more immersive photo viewing experience final ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { // Set home as up actionBar.setDisplayHomeAsUpEnabled(true); // Hide and show the ActionBar and TextView as the visibility changes mImageView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int vis) { if ((vis & View.SYSTEM_UI_FLAG_LOW_PROFILE) != 0) { actionBar.hide(); if (mSectionNumber == 1) { mTextView.animate().translationY(mTextView.getHeight()) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mTextView.setVisibility(View.GONE); } }); } } else { actionBar.show(); if (mSectionNumber == 1) { mTextView.animate().translationY(0).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { mTextView.setVisibility(View.VISIBLE); } }); } } } }); // Start low profile mode and hide ActionBar mImageView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); actionBar.hide(); } GestureListener.init(this, mImageView); ScaleGestureListener.init(mImageView); // Use the ImageWorker to load the image into the ImageView // (so a single cache can be used over all pages in the ViewPager) // based on the extra passed in to this activity int position = getIntent().getIntExtra(POSITION, 0); switch (mSectionNumber) { case 0: GalleryWorker.loadImage(position, mImageView); break; case 1: FotkiWorker.loadImage(position, mImageView); mTextView.setText(getResources().getString(R.string.detail_text, FotkiWorker.getAuthor(), new SimpleDateFormat("d MMMM yyyy", Locale.getDefault()).format(FotkiWorker.getPublished()))); break; case 2: ResourcesWorker.loadImage(position, mImageView); break; } setTitle(ImageWorker.getTitle()); // First we create the GestureListener that will include all our callbacks. // Then we create the GestureDetector, which takes that listener as an argument. GestureDetector.SimpleOnGestureListener gestureListener = new GestureListener(); final GestureDetector gd = new GestureDetector(this, gestureListener); ScaleGestureDetector.SimpleOnScaleGestureListener scaleGestureListener = new ScaleGestureListener(); final ScaleGestureDetector sgd = new ScaleGestureDetector(this, scaleGestureListener); /* For the view where gestures will occur, we create an onTouchListener that sends * all motion events to the gesture detectors. When the gesture detectors * actually detects an event, it will use the callbacks we created in the * SimpleOnGestureListener and SimpleOnScaleGestureListener to alert our application. */ findViewById(R.id.frameLayout).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { gd.onTouchEvent(motionEvent); sgd.onTouchEvent(motionEvent); return true; } }); }
From source file:com.pitchedapps.primenumbercalculator.Calculator.java
License:asdf
@Override public void onTextSizeChanged(final TextView textView, float oldSize) { if (mCurrentState != CalculatorState.INPUT) { // Only animate text changes that occur from user input. return;/* w w w . j av a 2 s. co m*/ } // Calculate the values needed to perform the scale and translation animations, // maintaining the same apparent baseline for the displayed text. final float textScale = oldSize / textView.getTextSize(); final float translationX = (1.0f - textScale) * (textView.getWidth() / 2.0f - textView.getPaddingEnd()); final float translationY = (1.0f - textScale) * (textView.getHeight() / 2.0f - textView.getPaddingBottom()); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(ObjectAnimator.ofFloat(textView, View.SCALE_X, textScale, 1.0f), ObjectAnimator.ofFloat(textView, View.SCALE_Y, textScale, 1.0f), ObjectAnimator.ofFloat(textView, View.TRANSLATION_X, translationX, 0.0f), ObjectAnimator.ofFloat(textView, View.TRANSLATION_Y, translationY, 0.0f)); animatorSet.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.start(); }
From source file:org.onebusaway.android.ui.ArrivalsListHeader.java
/** * Sets the popup for the status/*from www . ja v a2 s . c om*/ * * @param index 0 if this is for the top ETA row, 1 if it is for the second * @param color color resource id to use for the popup background * @param statusText text to show in the status popup * @return a new PopupWindow initialized based on the provided parameters */ private PopupWindow setupPopup(final int index, int color, String statusText) { LayoutInflater inflater = LayoutInflater.from(mContext); TextView statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_large, null); statusView.setBackgroundResource(R.drawable.round_corners_style_b_status); GradientDrawable d = (GradientDrawable) statusView.getBackground(); if (color != R.color.stop_info_ontime) { // Show early/late color d.setColor(mResources.getColor(color)); } else { // For on-time, use header default color d.setColor(mResources.getColor(R.color.theme_primary)); } d.setStroke(UIUtils.dpToPixels(mContext, 1), mResources.getColor(R.color.header_text_color)); int pSides = UIUtils.dpToPixels(mContext, 5); int pTopBottom = UIUtils.dpToPixels(mContext, 2); statusView.setPadding(pSides, pTopBottom, pSides, pTopBottom); statusView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); statusView.measure(TextView.MeasureSpec.UNSPECIFIED, TextView.MeasureSpec.UNSPECIFIED); statusView.setText(statusText); PopupWindow p = new PopupWindow(statusView, statusView.getWidth(), statusView.getHeight()); p.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); p.setBackgroundDrawable(new ColorDrawable(mResources.getColor(android.R.color.transparent))); p.setOutsideTouchable(true); p.setTouchInterceptor(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { boolean touchInView; if (index == 0) { touchInView = UIUtils.isTouchInView(mEtaAndMin1, event); } else { touchInView = UIUtils.isTouchInView(mEtaAndMin2, event); } return touchInView; } }); return p; }
From source file:com.httrack.android.HTTrackActivity.java
private void setProgressLinesInternal(final String[] lines) { // Get line divider position of the bottom coordinate final View lineDivider = findViewById(R.id.buttonStop); if (lineDivider == null) { return;//from w w w .j a va 2s . c om } final int[] textPosition = new int[2]; final int[] linePosition = new int[2]; lineDivider.getLocationInWindow(linePosition); final int lineYTopPosition = linePosition[1]; // Explode lines final LinearLayout layout = LinearLayout.class.cast(findViewById(R.id.layout)); // Remove any additional lines removeLinesFromLayout(layout, lines.length); // Add lines while we can final int currSize = layout.getChildCount(); for (int i = 0; i < lines.length; i++) { // Fetch or create next layout line. final TextView text = i < currSize ? TextView.class.cast(layout.getChildAt(i)) : addEmptyLineToLayout(layout); // Stop adding lines if overlapping to the end of the screen text.getLocationInWindow(textPosition); final int height = text.getHeight(); final int textYBottomPosition = textPosition[1] + height; if (textYBottomPosition >= lineYTopPosition) { // Then cut everything remaining removeLinesFromLayout(layout, i); // Stop here break; } // Set text (html-formatted) for this line final String line = lines[i].trim(); if (line.length() != 0) { text.setText(Html.fromHtml(line)); } else { // Otherwise Android 3.0 does not insert any blank line text.setText(Html.fromHtml(" ")); } } }