List of usage examples for android.view Gravity CENTER_HORIZONTAL
int CENTER_HORIZONTAL
To view the source code for android.view Gravity CENTER_HORIZONTAL.
Click Source Link
From source file:com.eugene.fithealthmaingit.UI.ManualEntrySaveMealFragment.java
private void updateItems() { mToolbar.setNavigationIcon(R.mipmap.ic_arrow_back); mToolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override//ww w .j a va2 s.co m public void onClick(View v) { Intent intent = new Intent(getActivity(), ChooseAddMealActivity.class); intent.putExtra(Globals.MEAL_TYPE, mealType); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent); } }); mToolbar.inflateMenu(R.menu.menu_user_info); mToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { if (menuItem.getItemId() == R.id.action_save) saveMeal(); return false; } }); mServingSizeUpdated.setText("1"); LinearLayout changeServing = (LinearLayout) v.findViewById(R.id.changeServing); changeServing.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setTitle("Update Serving Size: "); alert.setMessage("Servings Consumed"); final EditText input = new EditText(getActivity()); input.setText(mServingg.getText().toString()); input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); input.selectAll(); input.setGravity(Gravity.CENTER_HORIZONTAL); alert.setView(input, 64, 0, 64, 0); alert.setPositiveButton("Update", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { double values = Double.valueOf(input.getText().toString()); mServingg.setText(df.format(values)); mServingSizeUpdated.setText(df.format(values)); mCalUpdate.setText(dfW.format(Double.valueOf(mCalories) * values)); mCalorieProgress = Double.valueOf(mCalories) * values; mFattieUpdate.setText(df.format(Double.valueOf(mFat) * values)); mFatProgress = Double.valueOf(mFat) * values; mSaturatedFatUpdate.setText(df.format(Double.valueOf(mSaturatedFat) * values)); mCholesterolUpdate.setText(df.format(Double.valueOf(mCholesterol) * values)); mSodiumUpdate.setText(df.format(Double.valueOf(mSodium) * values)); mCarbUpdate.setText(df.format(Double.valueOf(mCarbohydrates) * values)); mCarbProgress = Double.valueOf(mCarbohydrates) * values; mFiberUpdate.setText(df.format(Double.valueOf(mFiber) * values)); mSugarUpdate.setText(df.format(Double.valueOf(mSugar) * values)); mProUpdate.setText(df.format(Double.valueOf(mProtein) * values)); mProteinProgress = Double.valueOf(mProtein) * values; mVitAUpdate.setText(df.format(Double.valueOf(mVitA) * values)); mVitCUpdate.setText(df.format(Double.valueOf(mVitC) * values)); mCalciumUpdate.setText(df.format(Double.valueOf(mCalcium) * values)); mIronUpdate.setText(df.format(Double.valueOf(mIron) * values)); progressBars(); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(input.getWindowToken(), 0); } }); alert.setCancelable(false); alert.show(); ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_NOT_ALWAYS); } }); }
From source file:com.mischivous.wormysharpyloggy.wsl.GameScreen.java
/** * Displays a message to the user in a Toast. * * @param msg The message to display/*from w w w. j a v a 2s. c o m*/ */ private void messageUser(@NonNull String msg) { if (msg == null) { throw new NullPointerException("Message to user cannot be null."); } Toast toast = Toast.makeText(this, msg, (msg.length() > 24 ? Toast.LENGTH_LONG : Toast.LENGTH_SHORT)); toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0); toast.show(); }
From source file:org.rm3l.ddwrt.tiles.status.wan.WANMonthlyTrafficTile.java
@Override public void onLoadFinished(Loader<NVRAMInfo> loader, NVRAMInfo data) { Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data + " / traffData=" + traffData); setLoadingViewVisibility(View.GONE); Exception preliminaryCheckException = null; if (data == null) { preliminaryCheckException = new DDWRTNoDataException("No Data!"); } else //noinspection ThrowableResultOfMethodCallIgnored if (data.getException() == null) { if (!"1".equals(data.getProperty(NVRAMInfo.TTRAFF_ENABLE))) { preliminaryCheckException = new IllegalStateException("Traffic monitoring disabled!"); } else if (traffData == null || traffData.isEmpty()) { preliminaryCheckException = new DDWRTNoDataException("No Traffic Data!"); }//from www. j av a2 s.c o m } if (preliminaryCheckException != null) { data = new NVRAMInfo().setException(preliminaryCheckException); } @NotNull final TextView errorPlaceHolderView = (TextView) this.layout .findViewById(R.id.tile_status_wan_monthly_traffic_error); @Nullable final Exception exception = data.getException(); final View displayButton = this.layout .findViewById(R.id.tile_status_wan_monthly_traffic_graph_placeholder_display_button); final View currentButton = this.layout .findViewById(R.id.tile_status_wan_monthly_traffic_graph_placeholder_current); final View previousButton = this.layout .findViewById(R.id.tile_status_wan_monthly_traffic_graph_placeholder_previous); final View nextButton = this.layout .findViewById(R.id.tile_status_wan_monthly_traffic_graph_placeholder_next); final TextView monthYearDisplayed = (TextView) this.layout .findViewById(R.id.tile_status_wan_monthly_month_displayed); final View[] ctrlViews = new View[] { monthYearDisplayed, displayButton, currentButton, previousButton, nextButton }; if (exception == null) { errorPlaceHolderView.setVisibility(View.GONE); final String currentMonthYearAlreadyDisplayed = monthYearDisplayed.getText().toString(); final Date currentDate = new Date(); final String currentMonthYear = (isNullOrEmpty(currentMonthYearAlreadyDisplayed) ? SIMPLE_DATE_FORMAT.format(currentDate) : currentMonthYearAlreadyDisplayed); //TODO Load last value from preferences monthYearDisplayed.setText(currentMonthYear); displayButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Intent intent = WANMonthlyTrafficTile.this .renderTraffDateForMonth(monthYearDisplayed.getText().toString()); if (intent == null) { Toast.makeText(WANMonthlyTrafficTile.this.mParentFragmentActivity, String.format("No traffic data for '%s'", monthYearDisplayed.getText()), Toast.LENGTH_SHORT).show(); } else { final AlertDialog alertDialog = Utils.buildAlertDialog(mParentFragmentActivity, null, String.format("Loading traffic data for '%s'", monthYearDisplayed.getText()), false, false); alertDialog.show(); ((TextView) alertDialog.findViewById(android.R.id.message)) .setGravity(Gravity.CENTER_HORIZONTAL); new Handler().postDelayed(new Runnable() { @Override public void run() { WANMonthlyTrafficTile.this.mParentFragmentActivity.startActivity(intent); alertDialog.cancel(); } }, 2500); } } }); currentButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { monthYearDisplayed.setText(SIMPLE_DATE_FORMAT.format(currentDate)); } }); previousButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final int[] currentYearMonth = getCurrentYearAndMonth(currentDate, monthYearDisplayed.getText().toString()); if (currentYearMonth.length < 2) { return; } final int currentMonth = currentYearMonth[1]; final int currentYear = currentYearMonth[0]; final int previousMonth = currentMonth - 1; final String previousMonthYear = ((previousMonth <= 0) ? ("12-" + (currentYear - 1)) : (((previousMonth <= 9) ? ("0" + previousMonth) : previousMonth) + "-" + currentYear)); monthYearDisplayed.setText(previousMonthYear); } }); nextButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final int[] currentYearMonth = getCurrentYearAndMonth(currentDate, monthYearDisplayed.getText().toString()); if (currentYearMonth.length < 2) { return; } final int currentMonth = currentYearMonth[1]; final int currentYear = currentYearMonth[0]; final int nextMonth = currentMonth + 1; final String nextMonthYear = ((nextMonth >= 13) ? ("01-" + (currentYear + 1)) : (((nextMonth <= 9) ? ("0" + nextMonth) : nextMonth) + "-" + currentYear)); monthYearDisplayed.setText(nextMonthYear); } }); setVisibility(ctrlViews, View.VISIBLE); } if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) { //noinspection ThrowableResultOfMethodCallIgnored final Throwable rootCause = Throwables.getRootCause(exception); errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null")); final Context parentContext = this.mParentFragmentActivity; errorPlaceHolderView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { //noinspection ThrowableResultOfMethodCallIgnored if (rootCause != null) { Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show(); } } }); errorPlaceHolderView.setVisibility(View.VISIBLE); setVisibility(ctrlViews, View.GONE); } else { if (traffData == null || traffData.isEmpty()) { errorPlaceHolderView.setText("Error: No Data!"); errorPlaceHolderView.setVisibility(View.VISIBLE); setVisibility(ctrlViews, View.GONE); } } doneWithLoaderInstance(this, loader, R.id.tile_status_wan_monthly_traffic_togglebutton_title, R.id.tile_status_wan_monthly_traffic_togglebutton_separator); Log.d(LOG_TAG, "onLoadFinished(): done loading!"); }
From source file:com.lambdasoup.quickfit.ui.WorkoutListActivity.java
private void showSchedulesPane(long workoutId) { if (!isTwoPane) { Timber.wtf("showSchedulesPane called despite not in two-pane layout mode"); return;/*www .j a v a2s . c om*/ } CoordinatorLayout.LayoutParams fabLayoutParams = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); fabLayoutParams.setAnchorId(R.id.list_pane); fabLayoutParams.anchorGravity = Gravity.BOTTOM | Gravity.END; fabLayoutParams.gravity = Gravity.CENTER_HORIZONTAL; fab.setLayoutParams(fabLayoutParams); fab.setOnClickListener(view -> showMiniFabs()); masterDetailView.requestShowDetail(); SchedulesFragment newFragment = SchedulesFragment.create(workoutId); getSupportFragmentManager().beginTransaction().add(R.id.schedules_container, newFragment).commit(); }
From source file:com.tr4android.support.extension.widget.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); mCollapsedTextHeight = -mTextPaint.ascent(); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom - mCollapsedTextOffsetBottom; break;//from w w w. j a v a2s .c o m case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent() + mCollapsedTextOffsetTop; break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset - (mCollapsedTextOffsetBottom / 2) + (mCollapsedTextOffsetTop / 2); break; } switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); mExpandedTextHeight = -mTextPaint.ascent(); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom - mExpandedTextOffsetBottom; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent() + mExpandedTextOffsetTop; break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset - (mExpandedTextOffsetBottom / 2) + (mExpandedTextOffsetTop / 2); break; } switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:com.qiscus.sdk.filepicker.util.TabLayoutHelper.java
private void adjustTabModeInternal(@NonNull TabLayout tabLayout, int prevScrollX) { int prevTabMode = tabLayout.getTabMode(); tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE); tabLayout.setTabGravity(TabLayout.GRAVITY_CENTER); int newTabMode = determineTabMode(tabLayout); cancelPendingUpdateScrollPosition(); if (newTabMode == TabLayout.MODE_FIXED) { tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); tabLayout.setTabMode(TabLayout.MODE_FIXED); } else {//www .j a v a 2 s . com LinearLayout slidingTabStrip = (LinearLayout) tabLayout.getChildAt(0); slidingTabStrip.setGravity(Gravity.CENTER_HORIZONTAL); if (prevTabMode == TabLayout.MODE_SCROLLABLE) { // restore scroll position tabLayout.scrollTo(prevScrollX, 0); } else { // scroll to current selected tab updateScrollPositionRunnable = () -> { updateScrollPositionRunnable = null; updateScrollPosition(); }; this.tabLayout.post(updateScrollPositionRunnable); } } }
From source file:org.rm3l.ddwrt.mgmt.RouterManagementActivity.java
@Override public void onClick(@Nullable View view) { if (view == null) { return;// w w w .j a v a 2s . c o m } if (view.getId() == R.id.router_list_add) { this.openAddRouterForm(); } else if (view.getId() == R.id.container_list_item) { // item click final int idx = mRecyclerView.getChildPosition(view); final RouterListRecycleViewAdapter adapter = (RouterListRecycleViewAdapter) mAdapter; if (actionMode != null) { final int previousSelectedItemCount = adapter.getSelectedItemCount(); myToggleSelection(idx); //Set background color, depending on whether this is a selection or a de-selection final int currentSelectedItemCount = adapter.getSelectedItemCount(); if (currentSelectedItemCount == previousSelectedItemCount - 1) { //De-selection: remove background view.setBackgroundResource(android.R.color.transparent); } else if (currentSelectedItemCount == previousSelectedItemCount + 1) { //Selection: apply background view.setBackgroundResource(android.R.color.background_light); } //other cases should not occur (as this is a single selection) //Now hide ActionMode if selected items count falls to 0 if (currentSelectedItemCount == 0) { actionMode.finish(); } return; } final AlertDialog alertDialog = Utils.buildAlertDialog(this, null, "Loading...", false, false); alertDialog.show(); ((TextView) alertDialog.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_HORIZONTAL); new Handler().postDelayed(new Runnable() { @Override public void run() { //No action mode - normal mode => open up main activity for this router final List<Router> routersList = adapter.getRoutersList(); final Router router; if (idx < 0 || idx >= routersList.size() || (router = routersList.get(idx)) == null) { Crouton.makeText(RouterManagementActivity.this, "Unknown router - please refresh list or add a new one.", Style.ALERT).show(); return; } final Intent ddWrtMainIntent = new Intent(RouterManagementActivity.this, DDWRTMainActivity.class); ddWrtMainIntent.putExtra(ROUTER_SELECTED, router.getUuid()); RouterManagementActivity.this.startActivity(ddWrtMainIntent); alertDialog.cancel(); } }, 2000); } }
From source file:android.support.design.widget.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom; break;//w w w .j ava 2s . com case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; break; } switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; break; } switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:org.buffer.android.buffertextinputlayout.util.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom; break;//from w w w. j a v a 2 s. co m case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; break; } switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; break; } switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }
From source file:com.aries.ui.view.title.util.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom - mTextPaint.descent(); break;// w w w. ja v a 2 s . c om case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset; break; } switch (collapsedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mCollapsedDrawX = mCollapsedBounds.right - width; break; case Gravity.LEFT: default: mCollapsedDrawX = mCollapsedBounds.left; break; } calculateUsingTextSize(mExpandedTextSize); width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0; final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom - mTextPaint.descent(); break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent(); break; case Gravity.CENTER_VERTICAL: default: float textHeight = mTextPaint.descent() - mTextPaint.ascent(); float textOffset = (textHeight / 2) - mTextPaint.descent(); mExpandedDrawY = mExpandedBounds.centerY() + textOffset; break; } switch (expandedAbsGravity & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: mExpandedDrawX = mExpandedBounds.centerX() - (width / 2); break; case Gravity.RIGHT: mExpandedDrawX = mExpandedBounds.right - width; break; case Gravity.LEFT: default: mExpandedDrawX = mExpandedBounds.left; break; } // The bounds have changed so we need to clear the texture clearTexture(); // Now reset the text size back to the original setInterpolatedTextSize(currentTextSize); }