List of usage examples for android.view Gravity CENTER_VERTICAL
int CENTER_VERTICAL
To view the source code for android.view Gravity CENTER_VERTICAL.
Click Source Link
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;/*from w w w. j av a 2s . c o 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 - 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); }
From source file:org.telegram.ui.Components.Switch.java
@Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); wasLayout = true;//from w w w . j a v a2s.co m int opticalInsetLeft = 0; int opticalInsetRight = 0; if (mThumbDrawable != null) { final Rect trackPadding = mTempRect; if (mTrackDrawable != null) { mTrackDrawable.getPadding(trackPadding); } else { trackPadding.setEmpty(); } final Insets insets = Insets.NONE; opticalInsetLeft = Math.max(0, insets.left - trackPadding.left); opticalInsetRight = Math.max(0, insets.right - trackPadding.right); } final int switchRight; final int switchLeft; if (LocaleController.isRTL) { switchLeft = getPaddingLeft() + opticalInsetLeft; switchRight = switchLeft + mSwitchWidth - opticalInsetLeft - opticalInsetRight; } else { switchRight = getWidth() - getPaddingRight() - opticalInsetRight; switchLeft = switchRight - mSwitchWidth + opticalInsetLeft + opticalInsetRight; } final int switchTop; final int switchBottom; switch (getGravity() & Gravity.VERTICAL_GRAVITY_MASK) { default: case Gravity.TOP: switchTop = getPaddingTop(); switchBottom = switchTop + mSwitchHeight; break; case Gravity.CENTER_VERTICAL: switchTop = (getPaddingTop() + getHeight() - getPaddingBottom()) / 2 - mSwitchHeight / 2; switchBottom = switchTop + mSwitchHeight; break; case Gravity.BOTTOM: switchBottom = getHeight() - getPaddingBottom(); switchTop = switchBottom - mSwitchHeight; break; } mSwitchLeft = switchLeft; mSwitchTop = switchTop; mSwitchBottom = switchBottom; mSwitchRight = switchRight; }
From source file:paulscode.android.mupen64plusae.persistent.GlobalPrefs.java
/** * Instantiates a new user preferences wrapper. * * @param context/* w ww . j a va2 s . c o m*/ * The application context. */ public GlobalPrefs(Context context, AppData appData) { mPreferences = PreferenceManager.getDefaultSharedPreferences(context); // Locale mLocaleCode = mPreferences.getString(KEY_LOCALE_OVERRIDE, DEFAULT_LOCALE_OVERRIDE); mLocale = TextUtils.isEmpty(mLocaleCode) ? Locale.getDefault() : createLocale(mLocaleCode); final Locale[] availableLocales = Locale.getAvailableLocales(); String[] values = context.getResources().getStringArray(R.array.localeOverride_values); String[] entries = new String[values.length]; for (int i = values.length - 1; i > 0; i--) { final Locale locale = createLocale(values[i]); // Get intersection of languages (available on device) and (translated for Mupen) if (ArrayUtils.contains(availableLocales, locale)) { // Get the name of the language, as written natively entries[i] = WordUtils.capitalize(locale.getDisplayName(locale)); } else { // Remove the item from the list entries = (String[]) ArrayUtils.remove(entries, i); values = (String[]) ArrayUtils.remove(values, i); } } entries[0] = context.getString(R.string.localeOverride_entrySystemDefault); mLocaleNames = entries; mLocaleCodes = values; // Files userDataDir = mPreferences.getString("pathGameSaves", ""); galleryCacheDir = userDataDir + "/GalleryCache"; coverArtDir = galleryCacheDir + "/CoverArt"; unzippedRomsDir = galleryCacheDir + "/UnzippedRoms"; profilesDir = userDataDir + "/Profiles"; crashLogDir = userDataDir + "/CrashLogs"; coreUserDataDir = userDataDir + "/CoreConfig/UserData"; coreUserCacheDir = userDataDir + "/CoreConfig/UserCache"; hiResTextureDir = coreUserDataDir + "/mupen64plus/hires_texture/"; // MUST match what rice assumes natively textureCacheDir = coreUserCacheDir + "/mupen64plus/cache"; romInfoCache_cfg = galleryCacheDir + "/romInfoCache.cfg"; controllerProfiles_cfg = profilesDir + "/controller.cfg"; touchscreenProfiles_cfg = profilesDir + "/touchscreen.cfg"; emulationProfiles_cfg = profilesDir + "/emulation.cfg"; customCheats_txt = profilesDir + "/customCheats.txt"; touchscreenCustomSkinsDir = userDataDir + "/CustomSkins"; legacyAutoSaves = userDataDir + "/AutoSaves"; legacySlotSaves = userDataDir + "/SlotSaves"; // Plug-ins audioPlugin = new Plugin(mPreferences, appData.libsDir, "audioPlugin"); // Library prefs isRecentShown = mPreferences.getBoolean("showRecentlyPlayed", true); isFullNameShown = mPreferences.getBoolean("showFullNames", true); // Touchscreen prefs isTouchscreenFeedbackEnabled = mPreferences.getBoolean("touchscreenFeedback", false); touchscreenScale = (mPreferences.getInt("touchscreenScale", 100)) / 100.0f; touchscreenTransparency = (255 * mPreferences.getInt("touchscreenTransparency", 100)) / 100; touchscreenAutoHold = getSafeInt(mPreferences, "touchscreenAutoHold", 0); // Video prefs displayOrientation = getSafeInt(mPreferences, "displayOrientation", 0); displayPosition = getSafeInt(mPreferences, "displayPosition", Gravity.CENTER_VERTICAL); final int transparencyPercent = mPreferences.getInt("displayActionBarTransparency", 50); displayActionBarTransparency = (255 * transparencyPercent) / 100; isFpsEnabled = mPreferences.getBoolean("displayFps", false); final int selectedHardwareType = getSafeInt(mPreferences, "videoHardwareType", -1); isPolygonOffsetHackEnabled = selectedHardwareType > -2; videoHardwareType = selectedHardwareType < 0 ? appData.hardwareInfo.hardwareType : selectedHardwareType; switch (videoHardwareType) { case HardwareInfo.HARDWARE_TYPE_OMAP: videoPolygonOffset = 0.2f; break; case HardwareInfo.HARDWARE_TYPE_OMAP_2: videoPolygonOffset = -1.5f; break; case HardwareInfo.HARDWARE_TYPE_QUALCOMM: videoPolygonOffset = -0.2f; break; case HardwareInfo.HARDWARE_TYPE_IMAP: videoPolygonOffset = -0.001f; break; case HardwareInfo.HARDWARE_TYPE_TEGRA: videoPolygonOffset = -2.0f; break; case HardwareInfo.HARDWARE_TYPE_UNKNOWN: videoPolygonOffset = -1.5f; break; default: videoPolygonOffset = SafeMethods.toFloat(mPreferences.getString("videoPolygonOffset", "-1.5"), -1.5f); break; } isImmersiveModeEnabled = mPreferences.getBoolean("displayImmersiveMode", false); // Audio prefs audioSwapChannels = mPreferences.getBoolean("audioSwapChannels", false); audioSDLSecondaryBufferSize = getSafeInt(mPreferences, "audioSDLBufferSize", 2048); audioSLESSecondaryBufferSize = getSafeInt(mPreferences, "audioSLESBufferSize2", 256); audioSLESSecondaryBufferNbr = getSafeInt(mPreferences, "audioSLESBufferNbr2", 20); audioSLESSamplingRate = getSafeInt(mPreferences, "audioSLESSamplingRate", 0); if (audioPlugin.enabled) isFramelimiterEnabled = !mPreferences.getBoolean("audioSynchronize", true); else isFramelimiterEnabled = !mPreferences.getString("audioPlugin", "").equals("nospeedlimit"); // User interface modes final String navMode = mPreferences.getString("navigationMode", "auto"); if (navMode.equals("bigscreen")) isBigScreenMode = true; else if (navMode.equals("standard")) isBigScreenMode = false; else isBigScreenMode = AppData.IS_OUYA_HARDWARE || appData.isAndroidTv; // TODO: Add other systems as they enter market // Peripheral share mode isControllerShared = mPreferences.getBoolean("inputShareController", false); maxAutoSaves = mPreferences.getInt("gameAutoSaves", 5); // Determine the key codes that should not be mapped to controls final boolean volKeysMappable = mPreferences.getBoolean("inputVolumeMappable", false); final List<Integer> unmappables = new ArrayList<>(); unmappables.add(KeyEvent.KEYCODE_MENU); // Back key is needed to show/hide the action bar in HC+ unmappables.add(KeyEvent.KEYCODE_BACK); if (!volKeysMappable) { unmappables.add(KeyEvent.KEYCODE_VOLUME_UP); unmappables.add(KeyEvent.KEYCODE_VOLUME_DOWN); unmappables.add(KeyEvent.KEYCODE_VOLUME_MUTE); } unmappableKeyCodes = Collections.unmodifiableList(unmappables); // Controller profiles controllerProfile1 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE1, getControllerProfileDefault(1), GetControllerProfilesConfig(), appData.GetControllerProfilesConfig()); controllerProfile2 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE2, getControllerProfileDefault(2), GetControllerProfilesConfig(), appData.GetControllerProfilesConfig()); controllerProfile3 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE3, getControllerProfileDefault(3), GetControllerProfilesConfig(), appData.GetControllerProfilesConfig()); controllerProfile4 = loadControllerProfile(mPreferences, GamePrefs.CONTROLLER_PROFILE4, getControllerProfileDefault(4), GetControllerProfilesConfig(), appData.GetControllerProfilesConfig()); // Player map playerMap = new PlayerMap(mPreferences.getString(GamePrefs.PLAYER_MAP, "")); // Determine whether controller deconfliction is needed int numControllers = 0; numControllers += controllerProfile1 != null ? 1 : 0; numControllers += controllerProfile2 != null ? 1 : 0; numControllers += controllerProfile3 != null ? 1 : 0; numControllers += controllerProfile4 != null ? 1 : 0; playerMap.setEnabled(numControllers > 1 && !isControllerShared); }
From source file:fiskinfoo.no.sintef.fiskinfoo.CardViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View rootView = inflater.inflate(R.layout.fragment_card_view, container, false); RelativeLayout textAreaPlaceHolder = (RelativeLayout) rootView.findViewById(R.id.card_view_container); TextView title = (TextView) rootView.findViewById(R.id.card_view_title_text_view); if (subscription != null) { title.setText(subscription.GeoDataServiceName); TextView idView = generateTextViewWithText("id: " + subscription.Id, title); TextView geoDataServiceNameView = generateTextViewWithText( "Navn p kartlaget: " + subscription.GeoDataServiceName, idView); TextView fileFormatTypeView = generateTextViewWithText("Filformat: " + subscription.FileFormatType, geoDataServiceNameView); TextView userEmailView = generateTextViewWithText("Bruker e-post: " + subscription.UserEmail, fileFormatTypeView);//from w w w. j ava2s . co m TextView subscriptionEmailView = generateTextViewWithText( "Abbonents e-post: " + subscription.SubscriptionEmail, userEmailView); TextView subscriptionIntervalNameView = generateTextViewWithText( "Kartet sendes: " + subscription.SubscriptionIntervalName, subscriptionEmailView); TextView createdView = generateTextViewWithText("Opprettet: " + subscription.Created, subscriptionIntervalNameView); TextView lastModifiedView = generateTextViewWithText("Sist oppdatert: " + subscription.LastModified, createdView); textAreaPlaceHolder.addView(idView); textAreaPlaceHolder.addView(geoDataServiceNameView); textAreaPlaceHolder.addView(fileFormatTypeView); textAreaPlaceHolder.addView(userEmailView); textAreaPlaceHolder.addView(subscriptionEmailView); textAreaPlaceHolder.addView(subscriptionIntervalNameView); textAreaPlaceHolder.addView(createdView); textAreaPlaceHolder.addView(lastModifiedView); } if (propertyDescription != null) { title.setText(propertyDescription.Name); Button notificationIconButton = (Button) rootView.findViewById(R.id.card_notification_image_view); CardViewInformationRow row; Button downloadMapButton; Button showOnMapButton; final ScrollView scrollView = (ScrollView) rootView.findViewById(R.id.card_view_scroll_view); final LinearLayout informationContainer = (LinearLayout) rootView .findViewById(R.id.card_view_information_container); LinearLayout bottomButtonContainer = (LinearLayout) rootView.findViewById(R.id.bottom_button_container); showOnMapButton = new Button(getActivity()); downloadMapButton = (Button) rootView.findViewById(R.id.card_view_download_map_button); row = utilityRows.getCardViewInformationRow(getActivity(), getString(R.string.last_updated), propertyDescription.LastUpdated.replace('T', ' '), true); informationContainer.addView(row.getView()); String description = (propertyDescription.LongDescription == null || propertyDescription.LongDescription.trim().equals("")) ? propertyDescription.Description : propertyDescription.LongDescription; String hyperlink = null; description = description.replace("<p>", ""); description = description.replace("</p>", ""); // TODO: should rewrite in order to handle multiple links. if (description.contains("<a href=\"")) { hyperlink = "<a href='" + description.substring(description.indexOf("href=") + 6, description.indexOf(">", description.indexOf("href=")) - 1) + "'>" + "\t\t\t* " + getString(R.string.see_more_info) + "</a>"; description = description.substring(0, description.indexOf("<a href")) + description.substring(description.indexOf(">", description.indexOf("<a href")) + 1, description.indexOf("</a")) + "*" + (description.indexOf("a>") > description.length() - 3 ? "" : description.substring(description.indexOf("a>") + 2, description.length())); } row = utilityRows.getCardViewInformationRow(getActivity(), getString(R.string.information), description, true); informationContainer.addView(row.getView()); if (hyperlink != null) { TextView textView = new TextView(getActivity()); textView.setClickable(true); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setText(Html.fromHtml(hyperlink)); textView.setTextSize(getResources().getInteger(R.integer.hyperlinkTextSize)); informationContainer.addView(textView); } String updateFrequency = (propertyDescription.UpdateFrequencyText == null || propertyDescription.UpdateFrequencyText.trim().equals("")) ? getString(R.string.update_frequency_not_available) : propertyDescription.UpdateFrequencyText; row = utilityRows.getCardViewInformationRow(getActivity(), getString(R.string.update_frequency), updateFrequency, true); informationContainer.addView(row.getView()); if (ApiErrorType.getType(propertyDescription.ErrorType) == ApiErrorType.WARNING) { row = utilityRows.getCardViewInformationRow(getActivity(), getString(R.string.error_text), propertyDescription.ErrorText, true); final View dataField = row.getView(); final Animation animation = getBlinkAnimation(); notificationIconButton.setVisibility(View.VISIBLE); notificationIconButton .setBackground(ContextCompat.getDrawable(getActivity(), R.drawable.ic_warning_black_36dp)); row.setTextColor(getResources().getColor(R.color.warning_orange)); notificationIconButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { focusOnView(scrollView, dataField); dataField.startAnimation(animation); } }); informationContainer.addView(row.getView()); } else if (ApiErrorType.getType(propertyDescription.ErrorType) == ApiErrorType.WARNING) { row = utilityRows.getCardViewInformationRow(getActivity(), getString(R.string.error_text), propertyDescription.ErrorText, true); final TextView dataField = row.getFieldDataTextView(); final Animation animation = getBlinkAnimation(); notificationIconButton.setVisibility(View.VISIBLE); notificationIconButton.setBackground( ContextCompat.getDrawable(getActivity(), R.drawable.ic_error_outline_black_36dp)); row.setTextColor(getResources().getColor(R.color.error_red)); notificationIconButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { focusOnView(scrollView, dataField); dataField.startAnimation(animation); } }); informationContainer.addView(row.getView()); } row = utilityRows.getCardViewInformationRow(getActivity(), getString(R.string.data_owner), propertyDescription.DataOwner, true); informationContainer.addView(row.getView()); if (propertyDescription.DataOwnerLink != null && !propertyDescription.DataOwnerLink.trim().equals("")) { String partnerLink = (propertyDescription.DataOwnerLink.contains("http") || propertyDescription.DataOwnerLink.contains("www")) ? "<a href='" + propertyDescription.DataOwnerLink + "'>" + propertyDescription.DataOwnerLink + "</a>" : "<a href='" + getString(R.string.about_partners_base_address) + propertyDescription.DataOwnerLink + "'>" + getString(R.string.about_partners_base_address) + propertyDescription.DataOwnerLink + "</a>"; row = utilityRows.getCardViewInformationRow(getActivity(), getString(R.string.data_owner_link), partnerLink, true); row.setHyperlink(partnerLink); row.getFieldDataTextView().setMovementMethod(LinkMovementMethod.getInstance()); informationContainer.addView(row.getView()); } StringBuilder stringBuilder = new StringBuilder(); for (String format : propertyDescription.Formats) { stringBuilder.append(format); stringBuilder.append("\n"); } row = utilityRows.getCardViewInformationRow(getActivity(), getString(R.string.formats), stringBuilder.toString().trim(), false); informationContainer.addView(row.getView()); stringBuilder.setLength(0); for (String interval : propertyDescription.SubscriptionInterval) { stringBuilder.append(SubscriptionInterval.getType(interval).toString()); stringBuilder.append("\n"); } row = utilityRows.getCardViewInformationRow(getActivity(), getString(R.string.subscription_frequencies), stringBuilder.toString().trim(), false); informationContainer.addView(row.getView()); row = utilityRows.getCardViewInformationRow(getActivity(), getString(R.string.map_creation_date), propertyDescription.Created.substring(0, propertyDescription.Created.indexOf('T')), true); informationContainer.addView(row.getView()); LinearLayout.LayoutParams bottomButtonLayoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); bottomButtonLayoutParams.gravity = Gravity.CENTER_VERTICAL; bottomButtonLayoutParams.weight = (float) 0.5; showOnMapButton.setLayoutParams(bottomButtonLayoutParams); showOnMapButton.setText(getString(R.string.show_on_map)); showOnMapButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //TODO: Need to update the toolbar as well. List<String> layersList = new ArrayList<>(); String layerName = propertyDescription.Name; layersList.add("Grunnkart"); layersList.add(layerName); user.setActiveLayers(layersList); user.writeToSharedPref(getActivity()); getFragmentManager().beginTransaction().replace(R.id.fragment_container, new FiskInfoUtility().createFragment(MapFragment.TAG, user, TAG), MapFragment.TAG) .addToBackStack(null).commit(); } }); bottomButtonContainer.addView(showOnMapButton); downloadMapButton.setOnClickListener(utilityOnClickListeners .getSubscriptionDownloadButtonOnClickListener(getActivity(), propertyDescription, user, TAG)); } if (warning != null) { TextView content = generateTextViewWithText(warning, title); textAreaPlaceHolder.addView(content); } clearIds(); return rootView; }
From source file:net.opacapp.multilinecollapsingtoolbar.CollapsingTextHelper.java
private void calculateBaseOffsets() { final float currentTextSize = mCurrentTextSize; // We then calculate the collapsed text size, using the same logic calculateUsingTextSize(mCollapsedTextSize); // BEGIN MODIFICATION: set mTextToDrawCollapsed and calculate width using it mTextToDrawCollapsed = mTextToDraw;//from w ww . j av a 2 s .c o m float width = mTextToDrawCollapsed != null ? mTextPaint.measureText(mTextToDrawCollapsed, 0, mTextToDrawCollapsed.length()) : 0; // END MODIFICATION final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); // BEGIN MODIFICATION: calculate height and Y position using mTextLayout float textHeight = mTextLayout != null ? mTextLayout.getHeight() : 0; switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mCollapsedDrawY = mCollapsedBounds.bottom - textHeight; break; case Gravity.TOP: mCollapsedDrawY = mCollapsedBounds.top; break; case Gravity.CENTER_VERTICAL: default: float textOffset = (textHeight / 2); mCollapsedDrawY = mCollapsedBounds.centerY() - textOffset; break; } // END MODIFICATION 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); // BEGIN MODIFICATION: calculate width using mTextLayout based on first line and store that padding width = mTextLayout != null ? mTextLayout.getLineWidth(0) : 0; mExpandedFirstLineDrawX = mTextLayout != null ? mTextLayout.getLineLeft(0) : 0; // END MODIFICATION final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity, mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); // BEGIN MODIFICATION: calculate height and Y position using mTextLayout textHeight = mTextLayout != null ? mTextLayout.getHeight() : 0; switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) { case Gravity.BOTTOM: mExpandedDrawY = mExpandedBounds.bottom - textHeight; break; case Gravity.TOP: mExpandedDrawY = mExpandedBounds.top; break; case Gravity.CENTER_VERTICAL: default: float textOffset = (textHeight / 2); mExpandedDrawY = mExpandedBounds.centerY() - textOffset; break; } // END MODIFICATION 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.jakewharton.behavior.drawer.BehaviorDelegate.java
boolean onLayoutChild() { int width = parent.getMeasuredWidth(); int height = parent.getMeasuredHeight(); int childWidth = child.getMeasuredWidth(); int childHeight = child.getMeasuredHeight(); int childLeft; float newOffset; if (isLeft) { childLeft = -childWidth + (int) (childWidth * onScreen); newOffset = (float) (childWidth + childLeft) / childWidth; } else {/*ww w . jav a 2 s. co m*/ childLeft = width - (int) (childWidth * onScreen); newOffset = (float) (width - childLeft) / childWidth; } boolean changeOffset = newOffset != onScreen; CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) child.getLayoutParams(); int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK; switch (vgrav) { default: case Gravity.TOP: { child.layout(childLeft, lp.topMargin, childLeft + childWidth, lp.topMargin + childHeight); break; } case Gravity.BOTTOM: { child.layout(childLeft, height - lp.bottomMargin - child.getMeasuredHeight(), childLeft + childWidth, height - lp.bottomMargin); break; } case Gravity.CENTER_VERTICAL: { int childTop = (height - childHeight) / 2; // Offset for margins. If things don't fit right because of // bad measurement before, oh well. if (childTop < lp.topMargin) { childTop = lp.topMargin; } else if (childTop + childHeight > height - lp.bottomMargin) { childTop = height - lp.bottomMargin - childHeight; } child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); break; } } if (changeOffset) { setDrawerViewOffset(newOffset); } int newVisibility = onScreen > 0 ? VISIBLE : INVISIBLE; if (child.getVisibility() != newVisibility) { child.setVisibility(newVisibility); } return true; }
From source file:net.evecom.androidecssp.activity.event.ContinueAddActivity.java
/** * /*w w w . j av a2s . c om*/ * * * @author Stark Zhou * @created 2016-4-5 10:27:57 */ private void initGallery() { mGallery = (GalleryFlow) findViewById(R.id.continue_add_gallery_flow); mGallery.setBackgroundColor(Color.parseColor("#ffffff")); // mGallery.setSpacing(90);// mGallery.setMaxRotationAngle(20);// mGallery.setFadingEdgeLength(10); // mGallery.setGravity(Gravity.CENTER_VERTICAL); // mGallery.setAdapter(new GalleryAdapter()); mGallery.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(getApplicationContext(), AfnailPictureActivity.class); BaseActivity.pushObjData("filebean", filebeans.get(position), intent); startActivityForResult(intent, R.layout.afnail_picture_activity); } }); }
From source file:com.plusapp.pocketbiceps.app.MainActivity.java
private void initializeCountDrawer() { // Gravity property aligns the text momentsCounter.setGravity(Gravity.CENTER_VERTICAL); momentsCounter.setTypeface(null, Typeface.BOLD); if (isDarkTheme) { momentsCounter.setTextColor(getResources().getColor(R.color.colorCardViewBlue)); } else {// w ww .j a v a 2s . c o m momentsCounter.setTextColor(getResources().getColor(R.color.colorAccent)); } momentsCounter.setText(String.valueOf(momentsCount)); }
From source file:com.cloverstudio.spika.CameraCropActivity.java
public void scaleView() { // instantiate the views View top_view = findViewById(R.id.topView); View bottom_view = findViewById(R.id.bottomView); LinearLayout footer = (LinearLayout) findViewById(R.id.llFooter); LinearLayout crop_frame = (LinearLayout) findViewById(R.id.llCropFrame); Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); // 90% of width crop_container_size = (int) ((float) width * (1f - (10f / 100f))); // 10% margins float margin = ((float) width * (1f - (90f / 100f))); // Parameters for white crop border LinearLayout.LayoutParams par = new LinearLayout.LayoutParams(crop_container_size, crop_container_size); par.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL; par.setMargins((int) (margin / 2f), 0, (int) (margin / 2f), 0); crop_frame.setLayoutParams(par);/*from ww w.j a va 2 s . c o m*/ // Margins for other transparent views float top_view_height = ((float) (height - crop_container_size - footer.getHeight())) / (float) 2; top_view.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) top_view_height)); bottom_view .setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, (int) top_view_height)); // Image container RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(crop_container_size, crop_container_size); params.setMargins((int) (margin / 2f), (int) top_view_height, (int) (margin / 2f), 0); mImageView.setLayoutParams(params); mImageView.setImageBitmap(mBitmap); mImageView.setMaxZoom(4f); }
From source file:com.example.jesse.barscan.BarcodeCaptureActivity.java
/** * onTap returns the tapped barcode result to the calling Activity. *///from w ww .j a va 2 s. co m public boolean onTap(float rawX, float rawY) { // Find tap point in preview frame coordinates. int[] location = new int[2]; mGraphicOverlay.getLocationOnScreen(location); float x = (rawX - location[0]) / mGraphicOverlay.getWidthScaleFactor(); float y = (rawY - location[1]) / mGraphicOverlay.getHeightScaleFactor(); // Find the barcode whose center is closest to the tapped point. Barcode best = null; float bestDistance = Float.MAX_VALUE; for (BarcodeGraphic graphic : mGraphicOverlay.getGraphics()) { Barcode barcode = graphic.getBarcode(); if (barcode.getBoundingBox().contains((int) x, (int) y)) { // Exact hit, no need to keep looking. best = barcode; break; } float dx = x - barcode.getBoundingBox().centerX(); float dy = y - barcode.getBoundingBox().centerY(); float distance = (dx * dx) + (dy * dy); // actually squared distance if (distance < bestDistance) { best = barcode; bestDistance = distance; } } if (best != null) { Intent data = new Intent(); data.putExtra(BarcodeObject, best); setResult(CommonStatusCodes.SUCCESS, data); LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.barcode_toast, (ViewGroup) findViewById(R.id.custom_toast_container)); Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject); //Barcode.DriverLicense dlBarcode = barcode.driverLicense; Barcode.DriverLicense sample = barcode.driverLicense; TextView name = (TextView) layout.findViewById(R.id.name); TextView address = (TextView) layout.findViewById(R.id.address); TextView cityStateZip = (TextView) layout.findViewById(R.id.cityStateZip); TextView gender = (TextView) layout.findViewById(R.id.gender); TextView dob = (TextView) layout.findViewById(R.id.dob); TableLayout tbl = (TableLayout) layout.findViewById(R.id.tableLayout); try { int age = DateDifference.generateAge(sample.birthDate); if (age < minAge) tbl.setBackgroundColor(Color.parseColor("#980517")); else tbl.setBackgroundColor(Color.parseColor("#617C17")); } catch (ParseException e) { e.printStackTrace(); } String cityContent = new String( sample.addressCity + ", " + sample.addressState + " " + (sample.addressZip).substring(0, 5)); address.setText(sample.addressStreet); cityStateZip.setText(cityContent); String genderString; if ((sample.gender).equals("1")) genderString = "Male"; else if ((sample.gender).equals("2")) genderString = "Female"; else genderString = "Other"; gender.setText(genderString); dob.setText((sample.birthDate).substring(0, 2) + "/" + (sample.birthDate).substring(2, 4) + "/" + (sample.birthDate).substring(4, 8)); String nameString = new String(sample.firstName + " " + sample.middleName + " " + sample.lastName); name.setText(nameString); Toast toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); Date today = Calendar.getInstance().getTime(); String reportDate = df.format(today); SQLiteDatabase db = helper.getWritableDatabase(); ContentValues row = new ContentValues(); row.put("dateVar", reportDate); row.put("dobVar", sample.birthDate); row.put("zipVar", sample.addressZip); row.put("genderVar", genderString); db.insert("test", null, row); db.close(); return true; } return false; }