Java Code Examples for android.util.typedvalue#getDimension()
The following examples show how to use
android.util.typedvalue#getDimension() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppContactFragment.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Gets the preferred height for each item in the ListView, in pixels, after accounting for * screen density. ImageLoader uses this value to resize thumbnail images to match the ListView * item height. * * @return The preferred height in pixels, based on the current theme. */ private int getListPreferredItemHeight() { final TypedValue typedValue = new TypedValue(); // Resolve list item preferred height theme attribute into typedValue getActivity().getTheme().resolveAttribute( android.R.attr.listPreferredItemHeight, typedValue, true); // Create a new DisplayMetrics object final DisplayMetrics metrics = new DisplayMetrics(); // Populate the DisplayMetrics getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); // Return theme value based on DisplayMetrics return (int) typedValue.getDimension(metrics); }
Example 2
Source File: ContactSelectionFragment.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 6 votes |
private int getListPreferredItemHeight() { final TypedValue typedValue = new TypedValue(); // Resolve list item preferred height theme attribute into typedValue getActivity().getTheme().resolveAttribute( android.R.attr.listPreferredItemHeight, typedValue, true); // Create a new DisplayMetrics object final DisplayMetrics metrics = new DisplayMetrics(); // Populate the DisplayMetrics getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); // Return theme value based on DisplayMetrics return (int) typedValue.getDimension(metrics); }
Example 3
Source File: ChannelFragment.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 6 votes |
private int getListPreferredItemHeight() { final TypedValue typedValue = new TypedValue(); // Resolve list item preferred height theme attribute into typedValue getActivity().getTheme().resolveAttribute( android.R.attr.listPreferredItemHeight, typedValue, true); // Create a new DisplayMetrics object final DisplayMetrics metrics = new DisplayMetrics(); // Populate the DisplayMetrics getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); // Return theme value based on DisplayMetrics return (int) typedValue.getDimension(metrics); }
Example 4
Source File: RenderCoordinates.java From 365browser with Apache License 2.0 | 6 votes |
void setDeviceScaleFactor(float dipScale, WeakReference<Context> displayContext) { mDeviceScaleFactor = dipScale; // The wheel scroll factor depends on the theme in the context. // This code assumes that the theme won't change between this call and // getWheelScrollFactor(). Context context = displayContext.get(); TypedValue outValue = new TypedValue(); // This is the same attribute used by Android Views to scale wheel // event motion into scroll deltas. if (context != null && context.getTheme().resolveAttribute( android.R.attr.listPreferredItemHeight, outValue, true)) { mWheelScrollFactor = outValue.getDimension(context.getResources().getDisplayMetrics()); } else { // If attribute retrieval fails, just use a sensible default. mWheelScrollFactor = 64 * mDeviceScaleFactor; } }
Example 5
Source File: NestedScrollView.java From MyBlogDemo with Apache License 2.0 | 5 votes |
private float getVerticalScrollFactorCompat() { if (mVerticalScrollFactor == 0) { TypedValue outValue = new TypedValue(); final Context context = getContext(); if (!context.getTheme().resolveAttribute( android.R.attr.listPreferredItemHeight, outValue, true)) { throw new IllegalStateException( "Expected theme to define listPreferredItemHeight."); } mVerticalScrollFactor = outValue.getDimension( context.getResources().getDisplayMetrics()); } return mVerticalScrollFactor; }
Example 6
Source File: AbsHListView.java From Klyph with MIT License | 5 votes |
/** * Gets a scale factor that determines the distance the view should scroll vertically in response to * {@link MotionEvent#ACTION_SCROLL}. * * @return The vertical scroll scale factor. */ protected float getHorizontalScrollFactor() { if ( mHorizontalScrollFactor == 0 ) { TypedValue outValue = new TypedValue(); if ( !getContext().getTheme().resolveAttribute( R.attr.sephiroth_listPreferredItemWidth, outValue, true ) ) { throw new IllegalStateException( "Expected theme to define listPreferredItemHeight." ); } mHorizontalScrollFactor = outValue.getDimension( getContext().getResources().getDisplayMetrics() ); } return mHorizontalScrollFactor; }
Example 7
Source File: FakeDialogPhoneWindow.java From android-apps with MIT License | 5 votes |
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { final DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); final boolean isPortrait = metrics.widthPixels < metrics.heightPixels; super.onMeasure(widthMeasureSpec, heightMeasureSpec); int width = getMeasuredWidth(); boolean measure = false; widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, EXACTLY); final TypedValue tv = isPortrait ? mMinWidthMinor : mMinWidthMajor; if (tv.type != TypedValue.TYPE_NULL) { final int min; if (tv.type == TypedValue.TYPE_DIMENSION) { min = (int)tv.getDimension(metrics); } else if (tv.type == TypedValue.TYPE_FRACTION) { min = (int)tv.getFraction(metrics.widthPixels, metrics.widthPixels); } else { min = 0; } if (width < min) { widthMeasureSpec = MeasureSpec.makeMeasureSpec(min, EXACTLY); measure = true; } } // TODO: Support height? if (measure) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); } }
Example 8
Source File: ChannelInfoActivity.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
private int getListPreferredItemHeight() { final TypedValue typedValue = new TypedValue(); getTheme().resolveAttribute( android.R.attr.listPreferredItemHeight, typedValue, true); final DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); return (int) typedValue.getDimension(metrics); }
Example 9
Source File: MessageInfoFragment.java From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License | 5 votes |
private int getListPreferredItemHeight() { final TypedValue typedValue = new TypedValue(); getActivity().getTheme().resolveAttribute( android.R.attr.listPreferredItemHeight, typedValue, true); final DisplayMetrics metrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics); return (int) typedValue.getDimension(metrics); }
Example 10
Source File: SettingsFragment.java From DesignOverlay-Android with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); // Bind the summaries of EditText/List/Dialog/Ringtone preferences // to their values. When their values change, their summaries are // updated to reflect the new value, per the Android Design // guidelines. bindPreferenceSummaryToValue(findPreference(PrefUtil.PREF_GRID_SIZE)); mAppContext = getActivity().getApplicationContext(); // get listPreferredItemHeight value in pixel and set it to mImageSize TypedValue value = new TypedValue(); getActivity().getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, value, true); mImageSize = (int) value.getDimension(getResources().getDisplayMetrics()); mImagePreference = (ImagePreference) findPreference(PrefUtil.PREF_DESIGN_IMAGE_URI); mImagePreference.setOnPreferenceClickListener(this); // load image if already set Uri imageUri = PrefUtil.getDesignImageUri(mAppContext); if (imageUri != null) { loadDesignImage(imageUri); } // Set application version Preference appVer = findPreference("pref_app_version"); appVer.setSummary(AppUtil.getVersion(mAppContext) + " - " + BuildConfig.BUILD_NUMBER); }
Example 11
Source File: ThemeUtil.java From mollyim-android with GNU General Public License v3.0 | 5 votes |
public static float getThemedDimen(@NonNull Context context, @AttrRes int attr) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); if (theme.resolveAttribute(attr, typedValue, true)) { return typedValue.getDimension(context.getResources().getDisplayMetrics()); } return 0; }
Example 12
Source File: ScannerActivity.java From attendee-checkin with Apache License 2.0 | 5 votes |
private int calcSlideDistance() { DisplayMetrics metrics = getResources().getDisplayMetrics(); int height = metrics.heightPixels; TypedValue value = new TypedValue(); getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, value, true); float itemHeight = value.getDimension(metrics); float paddingTop = getResources().getDimension(R.dimen.list_vertical_padding); return (int) ((height - itemHeight + paddingTop) / 2); }
Example 13
Source File: BothScrollView.java From Nimingban with Apache License 2.0 | 5 votes |
/** * Gets a scale factor that determines the distance the view should scroll * vertically in response to {@link MotionEvent#ACTION_SCROLL}. * @return The vertical scroll scale factor. */ protected float getVerticalScrollFactor() { if (mVerticalScrollFactor == 0) { Context context = getContext(); TypedValue outValue = new TypedValue(); if (!context.getTheme().resolveAttribute(16842829, outValue, true)) { // listPreferredItemHeight throw new IllegalStateException( "Expected theme to define listPreferredItemHeight."); } mVerticalScrollFactor = outValue.getDimension( context.getResources().getDisplayMetrics()); } return mVerticalScrollFactor; }
Example 14
Source File: MaterialAttributes.java From material-components-android with Apache License 2.0 | 5 votes |
/** * Returns the pixel value of the dimension specified by {@code attributeResId}. Defaults to * {@code defaultDimenResId} if {@code attributeResId} cannot be found or is not a dimension * within the given {@code context}. */ @Px public static int resolveDimension( @NonNull Context context, @AttrRes int attributeResId, @DimenRes int defaultDimenResId) { TypedValue dimensionValue = resolve(context, attributeResId); if (dimensionValue == null || dimensionValue.type != TypedValue.TYPE_DIMENSION) { return (int) context.getResources().getDimension(defaultDimenResId); } else { return (int) dimensionValue.getDimension(context.getResources().getDisplayMetrics()); } }
Example 15
Source File: ActionBarPlugin.java From cordova-android-actionbar with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public View getDropDownView(int position, View convertView, ViewGroup parent) { final Activity ctx = (Activity)plugin.cordova; final Item item = items.get(position); IconTextView view; if(convertView instanceof IconTextView) { view = (IconTextView)convertView; view.Icon.setImageDrawable(item.Icon); view.Text.setText(item.Text); } else { view = new IconTextView(ctx.getActionBar().getThemedContext(), item.Icon, item.Text); } // Get preferred list height if(listPreferredItemHeight == -1) { DisplayMetrics metrics = new DisplayMetrics(); ctx.getWindowManager().getDefaultDisplay().getMetrics(metrics); TypedValue value = new TypedValue(); ctx.getTheme().resolveAttribute(android.R.attr.listPreferredItemHeight, value, true); listPreferredItemHeight = (int)value.getDimension(metrics); } view.setLayoutParams(new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT)); return view; }
Example 16
Source File: NestedScrollView.java From AndroidAnimationExercise with Apache License 2.0 | 5 votes |
private float getVerticalScrollFactorCompat() { if (mVerticalScrollFactor == 0) { TypedValue outValue = new TypedValue(); final Context context = getContext(); if (!context.getTheme().resolveAttribute( android.R.attr.listPreferredItemHeight, outValue, true)) { throw new IllegalStateException( "Expected theme to define listPreferredItemHeight."); } mVerticalScrollFactor = outValue.getDimension( context.getResources().getDisplayMetrics()); } return mVerticalScrollFactor; }
Example 17
Source File: NestedScrollView.java From letv with Apache License 2.0 | 5 votes |
private float getVerticalScrollFactorCompat() { if (this.mVerticalScrollFactor == 0.0f) { TypedValue outValue = new TypedValue(); Context context = getContext(); if (context.getTheme().resolveAttribute(16842829, outValue, true)) { this.mVerticalScrollFactor = outValue.getDimension(context.getResources().getDisplayMetrics()); } else { throw new IllegalStateException("Expected theme to define listPreferredItemHeight."); } } return this.mVerticalScrollFactor; }
Example 18
Source File: AbsHListView.java From letv with Apache License 2.0 | 5 votes |
protected float getHorizontalScrollFactor() { if (this.mHorizontalScrollFactor == 0.0f) { TypedValue outValue = new TypedValue(); if (getContext().getTheme().resolveAttribute(2130771970, outValue, true)) { this.mHorizontalScrollFactor = outValue.getDimension(getContext().getResources().getDisplayMetrics()); } else { throw new IllegalStateException("Expected theme to define hlv_listPreferredItemWidth."); } } return this.mHorizontalScrollFactor; }
Example 19
Source File: Carbon.java From Carbon with Apache License 2.0 | 4 votes |
public static float getThemeDimen(Context context, int attr) { Resources.Theme theme = context.getTheme(); TypedValue typedValueAttr = new TypedValue(); theme.resolveAttribute(attr, typedValueAttr, true); return typedValueAttr.getDimension(context.getResources().getDisplayMetrics()); }
Example 20
Source File: MaterialNavigationDrawer.java From AdvancedMaterialDrawer with Apache License 2.0 | 4 votes |
@SuppressLint("LongLogTag") private void initThemeVars(Resources.Theme theme) { DisplayMetrics dm = getResources().getDisplayMetrics(); // init theme params TypedValue typedValue = new TypedValue(); theme.resolveAttribute(R.attr.colorPrimary, typedValue, true); primaryColor = typedValue.data; theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); primaryDarkColor = typedValue.data; theme.resolveAttribute(R.attr.autoDarkStatusBar, typedValue, true); autoDarkStatusbar = typedValue.data != 0; theme.resolveAttribute(R.attr.uniqueToolbarColor, typedValue, false); uniqueToolbarColor = typedValue.data != 0; theme.resolveAttribute(R.attr.drawerColor, typedValue, true); drawerColor = typedValue.data; /* theme.resolveAttribute(R.attr.dividerColor, typedValue, true); dividerColor = typedValue.data; */ theme.resolveAttribute(R.attr.drawerWidth, typedValue, true); drawerWidth = (int) typedValue.getDimension(dm); //TypedValue.complexToDimensionPixelSize(typedValue.data, getResources().getDisplayMetrics()); if (drawerWidth < 0) { drawerWidth = 1; } else { setDrawerStateListener(new DefaultDrawerListener(drawerWidth)); } theme.resolveAttribute(R.attr.dividerStrokeWidth, typedValue, true); dividerStrokeThickness = (int) typedValue.getDimension(dm); //TypedValue.complexToDimensionPixelSize(typedValue.data, getResources().getDisplayMetrics()); if (dividerStrokeThickness < 0) { dividerStrokeThickness = 1; } theme.resolveAttribute(R.attr.belowToolbar, typedValue, true); belowToolbar = typedValue.data != 0; theme.resolveAttribute(R.attr.multipaneSupport, typedValue, false); multiPaneSupport = typedValue.data != 0; theme.resolveAttribute(R.attr.titleColor, typedValue, true); theme.resolveAttribute(R.attr.headItemStyle, typedValue, true); // Values of the NavigationDrawer TypedArray valuesNavigationDrawer = theme.obtainStyledAttributes(typedValue.resourceId, R.styleable.MaterialNavigationDrawer); dividerColor = valuesNavigationDrawer.getDrawable(R.styleable.MaterialNavigationDrawer_dividerColor); // Values of the Account TypedArray values = theme.obtainStyledAttributes(typedValue.resourceId, R.styleable.MaterialHeadItem); theme.resolveAttribute(R.attr.actionBarOverlay, typedValue, false); actionBarOverlay = typedValue.data != 0; theme.resolveAttribute(R.attr.actionBarOverlayAlpha, typedValue, false); actionBarOverlayAlpha = typedValue.getFloat(); //actionbar style customization theme.resolveAttribute(R.attr.drawerActionBarStyle, typedValue, true); drawerActionBarStyle = typedValue.data; }