List of usage examples for android.view ViewGroup getWidth
@ViewDebug.ExportedProperty(category = "layout") public final int getWidth()
From source file:net.naonedbus.card.impl.HoraireCard.java
private int getTextViewCount(final ViewGroup parent) { final TextView textView = (TextView) mLayoutInflater.inflate(R.layout.card_horaire_text, parent, false); final DateTime noon = new DateTime().withHourOfDay(12).withMinuteOfHour(00); final int padding = getContext().getResources().getDimensionPixelSize(R.dimen.padding_medium); textView.setText(FormatUtils.formatTimeAmPm(getContext(), mTimeFormat.format(noon.toDate()))); final int specY = MeasureSpec.makeMeasureSpec(parent.getHeight(), MeasureSpec.UNSPECIFIED); final int specX = MeasureSpec.makeMeasureSpec(parent.getWidth(), MeasureSpec.UNSPECIFIED); textView.measure(specX, specY);//from w w w . j ava 2 s. c om return (parent.getWidth() - padding) / textView.getMeasuredWidth(); }
From source file:com.android.deskclock.alarms.AlarmActivity.java
private Animator getAlertAnimator(final View source, final int titleResId, final String infoText, final String accessibilityText, final int revealColor, final int backgroundColor) { final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);//from w w w. j ava 2 s . co m containerView.addView(revealView); // TODO: Fade out source icon over the reveal (like LOLLIPOP version). final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS); revealAnimator.setInterpolator(REVEAL_INTERPOLATOR); revealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.setVisibility(View.VISIBLE); mAlertTitleView.setText(titleResId); if (infoText != null) { mAlertInfoView.setText(infoText); mAlertInfoView.setVisibility(View.VISIBLE); } mContentView.setVisibility(View.GONE); getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor)); } }); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet alertAnimator = new AnimatorSet(); alertAnimator.play(revealAnimator).before(fadeAnimator); alertAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.announceForAccessibility(accessibilityText); mHandler.postDelayed(new Runnable() { @Override public void run() { finish(); } }, ALERT_DISMISS_DELAY_MILLIS); } }); return alertAnimator; }
From source file:com.onyx.deskclock.deskclock.alarms.AlarmActivity.java
private Animator getAlertAnimator(final View source, final int titleResId, final String infoText, final String accessibilityText, final int revealColor, final int backgroundColor) { final ViewGroup containerView = (ViewGroup) findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(this).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);/* ww w . j a v a 2 s. c om*/ containerView.addView(revealView); // TODO: Fade out source icon over the reveal (like LOLLIPOP version). final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setDuration(ALERT_REVEAL_DURATION_MILLIS); revealAnimator.setInterpolator(REVEAL_INTERPOLATOR); revealAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { mAlertView.setVisibility(View.VISIBLE); mAlertTitleView.setText(titleResId); if (infoText != null) { mAlertInfoView.setText(infoText); mAlertInfoView.setVisibility(View.VISIBLE); } mContentView.setVisibility(View.GONE); getWindow().setBackgroundDrawable(new ColorDrawable(backgroundColor)); } }); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.setDuration(ALERT_FADE_DURATION_MILLIS); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet alertAnimator = new AnimatorSet(); alertAnimator.play(revealAnimator).before(fadeAnimator); alertAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { if (Build.VERSION.SDK_INT >= 16) { mAlertView.announceForAccessibility(accessibilityText); } mHandler.postDelayed(new Runnable() { @Override public void run() { finish(); } }, ALERT_DISMISS_DELAY_MILLIS); } }); return alertAnimator; }
From source file:android.support.transition.SidePropagation.java
@Override public long getStartDelay(ViewGroup sceneRoot, Transition transition, TransitionValues startValues, TransitionValues endValues) {/* w w w . ja v a2 s . com*/ if (startValues == null && endValues == null) { return 0; } int directionMultiplier = 1; Rect epicenter = transition.getEpicenter(); TransitionValues positionValues; if (endValues == null || getViewVisibility(startValues) == View.VISIBLE) { positionValues = startValues; directionMultiplier = -1; } else { positionValues = endValues; } int viewCenterX = getViewX(positionValues); int viewCenterY = getViewY(positionValues); int[] loc = new int[2]; sceneRoot.getLocationOnScreen(loc); int left = loc[0] + Math.round(sceneRoot.getTranslationX()); int top = loc[1] + Math.round(sceneRoot.getTranslationY()); int right = left + sceneRoot.getWidth(); int bottom = top + sceneRoot.getHeight(); int epicenterX; int epicenterY; if (epicenter != null) { epicenterX = epicenter.centerX(); epicenterY = epicenter.centerY(); } else { epicenterX = (left + right) / 2; epicenterY = (top + bottom) / 2; } float distance = distance(sceneRoot, viewCenterX, viewCenterY, epicenterX, epicenterY, left, top, right, bottom); float maxDistance = getMaxDistance(sceneRoot); float distanceFraction = distance / maxDistance; long duration = transition.getDuration(); if (duration < 0) { duration = 300; } return Math.round(duration * directionMultiplier / mPropagationSpeed * distanceFraction); }
From source file:io.github.douglasjunior.androidSimpleTooltip.SimpleTooltip.java
public void show() { verifyDismissed();//from w w w. j a va 2 s.c o m final ViewGroup rootView = (ViewGroup) mAnchorView.getRootView(); createOverlay(rootView); mContentLayout.getViewTreeObserver().addOnGlobalLayoutListener(mLocationLayoutListener); rootView.post(new Runnable() { @Override public void run() { mPopupWindow.showAtLocation(rootView, Gravity.NO_GRAVITY, rootView.getWidth(), rootView.getHeight()); } }); }
From source file:org.dmfs.android.colorpicker.PaletteFragment.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); /*/* w w w. ja va 2 s. c om*/ * TODO: build the layout programmatically to get rid of the resources, so we can distribute this in a single jar */ final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.org_dmfs_colorpickerdialog_palette_grid, container, false); final GridView gridview = (GridView) rootView.findViewById(android.R.id.content); mAdapter = new PaletteGridAdapter(getActivity(), mPalette); gridview.setAdapter(mAdapter); gridview.setOnItemClickListener(this); gridview.setNumColumns(mAdapter.getNumColumns()); /* * Adjust the layout of the gridview to a square. * * Inspired by Bill Lahti, see http://blahti.wordpress.com/2012/07/23/three-variations-of-image-squares/ */ gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressLint("NewApi") public void onGlobalLayout() { int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom(); int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight(); int gridWidth = Math.min(parentWidth, parentHeight); int columnSpacing; if (android.os.Build.VERSION.SDK_INT >= 16) { columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1); } else { /* * TODO: getHorizontalSpacing() has been introduced in SDK level 16. We need to find a way to get get the actual spacing. Until then we use * a hard coded value of 8 dip. * * One way would be to use a dimension in the layout. That would allow us to resolve the dimension here. However, that would be one step * away from a library without resource dependencies. Maybe there is an Android dimension resource with a reasonable value? */ DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics(); if (android.os.Build.VERSION.SDK_INT > 10) { columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * (mAdapter.getNumColumns() - 1); } else { // Android 2 seems to add spacing around the entire gridview columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * mAdapter.getNumColumns(); } } // width of a single column int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns(); // estimated width of the grid int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing; // add padding to center the grid if we don't use the entire space due to rounding errors if (actualGridWidth < gridWidth - 1) { int padding = (gridWidth - actualGridWidth) / 2; if (padding > 0) { gridview.setPadding(padding, padding, padding, padding); } } else { // no padding needed gridview.setPadding(0, 0, 0, 0); } // set the column width gridview.setColumnWidth(columnWidth); android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams(); if (params == null || params.height != gridWidth) // avoid unnecessary updates { LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth); gridview.setLayoutParams(lparams); } } }); return rootView; }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java
/** * Layout suggestions to the suggestions strip. And returns the start index of more * suggestions./* ww w. j a v a 2s . c om*/ * * @param suggestedWords suggestions to be shown in the suggestions strip. * @param stripView the suggestions strip view. * @param placerView the view where the debug info will be placed. * @return the start index of more suggestions. */ public int layoutAndReturnStartIndexOfMoreSuggestions(final SuggestedWords suggestedWords, final ViewGroup stripView, final ViewGroup placerView) { if (suggestedWords.isPunctuationSuggestions()) { return layoutPunctuationsAndReturnStartIndexOfMoreSuggestions((PunctuationSuggestions) suggestedWords, stripView); } final int startIndexOfMoreSuggestions = setupWordViewsAndReturnStartIndexOfMoreSuggestions(suggestedWords, mSuggestionsCountInStrip); final TextView centerWordView = mWordViews.get(mCenterPositionInStrip); final int stripWidth = stripView.getWidth(); final int centerWidth = getSuggestionWidth(mCenterPositionInStrip, stripWidth); if (suggestedWords.size() == 1 || getTextScaleX(centerWordView.getText(), centerWidth, centerWordView.getPaint()) < MIN_TEXT_XSCALE) { // Layout only the most relevant suggested word at the center of the suggestion strip // by consolidating all slots in the strip. final int countInStrip = 1; mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip); layoutWord(mCenterPositionInStrip, stripWidth - mPadding); stripView.addView(centerWordView); setLayoutWeight(centerWordView, 1.0f, ViewGroup.LayoutParams.MATCH_PARENT); if (SuggestionStripView.DBG) { layoutDebugInfo(mCenterPositionInStrip, placerView, stripWidth); } final Integer lastIndex = (Integer) centerWordView.getTag(); return (lastIndex == null ? 0 : lastIndex) + 1; } final int countInStrip = mSuggestionsCountInStrip; mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip); int x = 0; for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) { if (positionInStrip != 0) { final View divider = mDividerViews.get(positionInStrip); // Add divider if this isn't the left most suggestion in suggestions strip. addDivider(stripView, divider); x += divider.getMeasuredWidth(); } final int width = getSuggestionWidth(positionInStrip, stripWidth); final TextView wordView = layoutWord(positionInStrip, width); stripView.addView(wordView); setLayoutWeight(wordView, getSuggestionWeight(positionInStrip), ViewGroup.LayoutParams.MATCH_PARENT); x += wordView.getMeasuredWidth(); if (SuggestionStripView.DBG) { layoutDebugInfo(positionInStrip, placerView, x); } } return startIndexOfMoreSuggestions; }
From source file:com.mobiletin.inputmethod.indic.suggestions.SuggestionStripLayoutHelper.java
/** * Layout suggestions to the suggestions strip. And returns the start index of more * suggestions./* www.j av a 2s . c om*/ * * @param suggestedWords suggestions to be shown in the suggestions strip. * @param stripView the suggestions strip view. * @param placerView the view where the debug info will be placed. * @return the start index of more suggestions. */ public int layoutAndReturnStartIndexOfMoreSuggestions(final SuggestedWords suggestedWords, final ViewGroup stripView, final ViewGroup placerView) { if (suggestedWords.isPunctuationSuggestions()) { return layoutPunctuationsAndReturnStartIndexOfMoreSuggestions((PunctuationSuggestions) suggestedWords, stripView); } final int startIndexOfMoreSuggestions = setupWordViewsAndReturnStartIndexOfMoreSuggestions(suggestedWords, mSuggestionsCountInStrip); final TextView centerWordView = mWordViews.get(mCenterPositionInStrip); final int stripWidth = stripView.getWidth(); final int centerWidth = getSuggestionWidth(mCenterPositionInStrip, stripWidth); if (suggestedWords.size() == 1 || getTextScaleX(centerWordView.getText(), centerWidth, centerWordView.getPaint()) < MIN_TEXT_XSCALE) { // Layout only the most relevant suggested word at the center of the suggestion strip // by consolidating all slots in the strip. final int countInStrip = 1; mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip); layoutWord(mCenterPositionInStrip, stripWidth - mPadding); stripView.addView(centerWordView); setLayoutWeight(centerWordView, 1.0f, ViewGroup.LayoutParams.MATCH_PARENT); if (SuggestionStripView.DBG) { layoutDebugInfo(mCenterPositionInStrip, placerView, stripWidth); } final Integer lastIndex = (Integer) centerWordView.getTag(); return (lastIndex == null ? 0 : lastIndex) + 1; } // final int countInStrip = mSuggestionsCountInStrip; // // Changes apply here // // Increase the strip size coloum final int countInStrip = mSuggestionsCountInStrip; mMoreSuggestionsAvailable = (suggestedWords.size() > countInStrip); int x = 0; for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) { if (positionInStrip != 0) { final View divider = mDividerViews.get(positionInStrip); // Add divider if this isn't the left most suggestion in suggestions strip. addDivider(stripView, divider); x += divider.getMeasuredWidth(); } final int width = getSuggestionWidth(positionInStrip, stripWidth); final TextView wordView = layoutWord(positionInStrip, width); stripView.addView(wordView); setLayoutWeight(wordView, getSuggestionWeight(positionInStrip), ViewGroup.LayoutParams.MATCH_PARENT); x += wordView.getMeasuredWidth(); if (SuggestionStripView.DBG) { layoutDebugInfo(positionInStrip, placerView, x); } } return startIndexOfMoreSuggestions; }
From source file:ti.org.dmfs.android.colorpicker.PaletteFragment.java
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); /*//from w w w .j av a 2s . c o m * TODO: build the layout programmatically to get rid of the resources, * so we can distribute this in a single jar */ final ViewGroup rootView = (ViewGroup) inflater .inflate(RHelper.getLayout("org_dmfs_colorpickerdialog_palette_grid"), container, false); final GridView gridview = (GridView) rootView.findViewById(android.R.id.content); mAdapter = new PaletteGridAdapter(getActivity(), mPalette); gridview.setAdapter(mAdapter); gridview.setOnItemClickListener(this); gridview.setNumColumns(mAdapter.getNumColumns()); /* * Adjust the layout of the gridview to a square. * * Inspired by Bill Lahti, see * http://blahti.wordpress.com/2012/07/23/three * -variations-of-image-squares/ */ gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressLint("NewApi") public void onGlobalLayout() { int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom(); int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight(); int gridWidth = Math.min(parentWidth, parentHeight); int columnSpacing; if (android.os.Build.VERSION.SDK_INT >= 16) { columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1); } else { /* * TODO: getHorizontalSpacing() has been introduced * in SDK level 16. We need to find a way to get get * the actual spacing. Until then we use a hard * coded value of 8 dip. * * One way would be to use a dimension in the * layout. That would allow us to resolve the * dimension here. However, that would be one step * away from a library without resource * dependencies. Maybe there is an Android dimension * resource with a reasonable value? */ DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics(); if (android.os.Build.VERSION.SDK_INT > 10) { columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * (mAdapter.getNumColumns() - 1); } else { // Android 2 seems to add spacing around the // entire gridview columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * mAdapter.getNumColumns(); } } // width of a single column int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns(); // estimated width of the grid int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing; // add padding to center the grid if we don't use the // entire space due to rounding errors if (actualGridWidth < gridWidth - 1) { int padding = (gridWidth - actualGridWidth) / 2; if (padding > 0) { gridview.setPadding(padding, padding, padding, padding); } } else { // no padding needed gridview.setPadding(0, 0, 0, 0); } // set the column width gridview.setColumnWidth(columnWidth); android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams(); if (params == null || params.height != gridWidth) // avoid // unnecessary // updates { LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth); gridview.setLayoutParams(lparams); } } }); return rootView; }
From source file:com.android.deskclock.timer.TimerFullScreenFragment.java
private Animator getRevealAnimator(View source, int revealColor) { final ViewGroup containerView = (ViewGroup) source.getRootView().findViewById(android.R.id.content); final Rect sourceBounds = new Rect(0, 0, source.getHeight(), source.getWidth()); containerView.offsetDescendantRectToMyCoords(source, sourceBounds); final int centerX = sourceBounds.centerX(); final int centerY = sourceBounds.centerY(); final int xMax = Math.max(centerX, containerView.getWidth() - centerX); final int yMax = Math.max(centerY, containerView.getHeight() - centerY); final float startRadius = Math.max(sourceBounds.width(), sourceBounds.height()) / 2.0f; final float endRadius = (float) Math.sqrt(xMax * xMax + yMax * yMax); final CircleView revealView = new CircleView(source.getContext()).setCenterX(centerX).setCenterY(centerY) .setFillColor(revealColor);/* w w w . j a va2 s.c o m*/ containerView.addView(revealView); final Animator revealAnimator = ObjectAnimator.ofFloat(revealView, CircleView.RADIUS, startRadius, endRadius); revealAnimator.setInterpolator(PathInterpolatorCompat.create(0.0f, 0.0f, 0.2f, 1.0f)); final ValueAnimator fadeAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); fadeAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { containerView.removeView(revealView); } }); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.setDuration(TimerFragment.ANIMATION_TIME_MILLIS); animatorSet.playSequentially(revealAnimator, fadeAnimator); return revealAnimator; }