List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:im.vector.VectorApp.java
/** * Compute a localised context//from ww w. j a v a 2 s . c o m * * @param context the context * @return the localised context */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") public static Context getLocalisedContext(Context context) { try { Resources resources = context.getResources(); Locale locale = getApplicationLocale(); Configuration configuration = resources.getConfiguration(); configuration.fontScale = getFontScaleValue(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { configuration.setLocale(locale); configuration.setLayoutDirection(locale); return context.createConfigurationContext(configuration); } else { configuration.locale = locale; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { configuration.setLayoutDirection(locale); } resources.updateConfiguration(configuration, resources.getDisplayMetrics()); return context; } } catch (Exception e) { Log.e(LOG_TAG, "## getLocalisedContext() failed : " + e.getMessage()); } return context; }
From source file:lewa.support.v7.widget.SwitchCompat.java
/** * Construct a new Switch with a default style determined by the given theme attribute, * overriding specific style attributes as requested. * * @param context The Context that will determine this widget's theming. * @param attrs Specification of attributes that should deviate from the default styling. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default values for * the view. Can be 0 to not look for defaults. */// ww w. j a v a2 s . c om public SwitchCompat(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); final Resources res = getResources(); mTextPaint.density = res.getDisplayMetrics().density; final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SwitchCompat, defStyleAttr, 0); mThumbDrawable = a.getDrawable(R.styleable.SwitchCompat_android_thumb); mTrackDrawable = a.getDrawable(R.styleable.SwitchCompat_track); mTextOn = a.getText(R.styleable.SwitchCompat_android_textOn); mTextOff = a.getText(R.styleable.SwitchCompat_android_textOff); mShowText = a.getBoolean(R.styleable.SwitchCompat_showText, true); mThumbTextPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0); mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0); mSwitchPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0); mSplitTrack = a.getBoolean(R.styleable.SwitchCompat_splitTrack, false); final int appearance = a.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0); if (appearance != 0) { setSwitchTextAppearance(context, appearance); } mTintManager = a.getTintManager(); a.recycle(); final ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }
From source file:com.etalio.android.EtalioBase.java
protected String getEtalioUserAgent() { Locale locale = Locale.getDefault(); Resources resources; resources = mContext.getApplicationContext().getResources(); return "Etalio/" + getVersion() + " (Linux; " + " Android " + Build.VERSION.RELEASE + "; " + locale.toString() + "; " + Build.MANUFACTURER + " " + Build.MODEL + " Build/" + Build.DISPLAY + "; " + " Density/" + (resources != null ? resources.getDisplayMetrics().density : "unknown") + ")"; }
From source file:com.duy.pascal.ui.view.console.ConsoleView.java
public float getTextSize(int unit, float size) { Context c = getContext();/*w ww . ja va2s. co m*/ Resources r; if (c == null) r = Resources.getSystem(); else r = c.getResources(); return TypedValue.applyDimension(unit, size, r.getDisplayMetrics()); }
From source file:android.support.v7.widget.SwitchCompat.java
/** * Construct a new Switch with a default style determined by the given theme attribute, * overriding specific style attributes as requested. * * @param context The Context that will determine this widget's theming. * @param attrs Specification of attributes that should deviate from the default styling. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default values for * the view. Can be 0 to not look for defaults. *//*from w w w .j av a2s. co m*/ public SwitchCompat(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); final Resources res = getResources(); mTextPaint.density = res.getDisplayMetrics().density; final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SwitchCompat, defStyleAttr, 0); mThumbDrawable = a.getDrawable(R.styleable.SwitchCompat_android_thumb); if (mThumbDrawable != null) { mThumbDrawable.setCallback(this); } mTrackDrawable = a.getDrawable(R.styleable.SwitchCompat_track); if (mTrackDrawable != null) { mTrackDrawable.setCallback(this); } mTextOn = a.getText(R.styleable.SwitchCompat_android_textOn); mTextOff = a.getText(R.styleable.SwitchCompat_android_textOff); mShowText = a.getBoolean(R.styleable.SwitchCompat_showText, true); mThumbTextPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0); mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0); mSwitchPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0); mSplitTrack = a.getBoolean(R.styleable.SwitchCompat_splitTrack, false); final int appearance = a.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0); if (appearance != 0) { setSwitchTextAppearance(context, appearance); } mTintManager = a.getTintManager(); a.recycle(); final ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }
From source file:android.support.v7ox.widget.SwitchCompat.java
/** * Construct a new Switch with a default style determined by the given theme attribute, * overriding specific style attributes as requested. * * @param context The Context that will determine this widget's theming. * @param attrs Specification of attributes that should deviate from the default styling. * @param defStyleAttr An attribute in the current theme that contains a * reference to a style resource that supplies default values for * the view. Can be 0 to not look for defaults. *///ww w . java 2 s . c o m public SwitchCompat(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); final Resources res = getResources(); mTextPaint.density = res.getDisplayMetrics().density; final TintTypedArray a = TintTypedArray.obtainStyledAttributes(context, attrs, R.styleable.SwitchCompat, defStyleAttr, 0); mThumbDrawable = a.getDrawable(R.styleable.SwitchCompat_android_thumb); if (mThumbDrawable != null) { mThumbDrawable.setCallback(this); } mTrackDrawable = a.getDrawable(R.styleable.SwitchCompat_track); if (mTrackDrawable != null) { mTrackDrawable.setCallback(this); } mTextOn = a.getText(R.styleable.SwitchCompat_android_textOn); mTextOff = a.getText(R.styleable.SwitchCompat_android_textOff); mShowText = a.getBoolean(R.styleable.SwitchCompat_showText, true); mThumbTextPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0); mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0); mSwitchPadding = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0); mSplitTrack = a.getBoolean(R.styleable.SwitchCompat_splitTrack, false); final int appearance = a.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0); if (appearance != 0) { setSwitchTextAppearance(context, appearance); } mDrawableManager = AppCompatDrawableManager.get(); a.recycle(); final ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); // Refresh display with current params refreshDrawableState(); setChecked(isChecked()); }
From source file:de.schildbach.wallet.util.CrashReporter.java
public static void appendDeviceInfo(final Appendable report, final Context context) throws IOException { final Resources res = context.getResources(); final android.content.res.Configuration config = res.getConfiguration(); final ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); final DevicePolicyManager devicePolicyManager = (DevicePolicyManager) context .getSystemService(Context.DEVICE_POLICY_SERVICE); report.append("Device Model: " + Build.MODEL + "\n"); report.append("Android Version: " + Build.VERSION.RELEASE + "\n"); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) report.append("Android security patch level: ").append(Build.VERSION.SECURITY_PATCH).append("\n"); report.append("ABIs: ").append(Joiner.on(", ").skipNulls().join(Strings.emptyToNull(Build.CPU_ABI), Strings.emptyToNull(Build.CPU_ABI2))).append("\n"); report.append("Board: " + Build.BOARD + "\n"); report.append("Brand: " + Build.BRAND + "\n"); report.append("Device: " + Build.DEVICE + "\n"); report.append("Display: " + Build.DISPLAY + "\n"); report.append("Finger Print: " + Build.FINGERPRINT + "\n"); report.append("Host: " + Build.HOST + "\n"); report.append("ID: " + Build.ID + "\n"); report.append("Product: " + Build.PRODUCT + "\n"); report.append("Tags: " + Build.TAGS + "\n"); report.append("Time: " + Build.TIME + "\n"); report.append("Type: " + Build.TYPE + "\n"); report.append("User: " + Build.USER + "\n"); report.append("Configuration: " + config + "\n"); report.append("Screen Layout: size " + (config.screenLayout & android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK) + " long " + (config.screenLayout & android.content.res.Configuration.SCREENLAYOUT_LONG_MASK) + "\n"); report.append("Display Metrics: " + res.getDisplayMetrics() + "\n"); report.append("Memory Class: " + activityManager.getMemoryClass() + "/" + activityManager.getLargeMemoryClass() + (ActivityManagerCompat.isLowRamDevice(activityManager) ? " (low RAM device)" : "") + "\n"); report.append("Storage Encryption Status: " + devicePolicyManager.getStorageEncryptionStatus() + "\n"); report.append("Bluetooth MAC: " + bluetoothMac() + "\n"); report.append("Runtime: ").append(System.getProperty("java.vm.name")).append(" ") .append(System.getProperty("java.vm.version")).append("\n"); }
From source file:edu.ttu.spm.cheapride.MainActivity.java
public void activateComparisonChart(RideEstimateDTO rideEstimateDto) { Resources resources = this.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); float pxRatio = ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT); double uberTimeWidth = this.getUberTimeWidth(rideEstimateDto); double lyftTimeWidth = this.getLyftTimeWidth(rideEstimateDto); this.uberArrivalTime.setWidth((int) (uberTimeWidth * pxRatio)); this.uberArrivalTime.setText(String.valueOf(rideEstimateDto.getUberArrivalTime())); this.lyftArrivalTime.setWidth((int) (lyftTimeWidth * pxRatio)); this.lyftArrivalTime.setText(String.valueOf(rideEstimateDto.getLyftArrivalTime())); double uberCostWidth = this.getUberCostWidth(rideEstimateDto); double lyftCostWidth = this.getLyftCostWidth(rideEstimateDto); this.uberCost.setWidth((int) (uberCostWidth * pxRatio)); this.uberCost.setText(String.valueOf(rideEstimateDto.getUberCost())); this.lyftCost.setWidth((int) (lyftCostWidth * pxRatio)); this.lyftCost.setText(String.valueOf(rideEstimateDto.getLyftCost())); this.comparisonChart.setVisibility(View.VISIBLE); if (LoginActivity.isLogin) { driveInfoBoard.setVisibility(View.INVISIBLE); this.rideBooking.setVisibility(View.VISIBLE); bookingButtons.setVisibility(View.VISIBLE); }//from www . java 2 s.co m }
From source file:com.aptoide.amethyst.utils.AptoideUtils.java
public static int getPixels(Context context, int dipValue) { Resources r = context.getResources(); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics()); Logger.d("getPixels", "" + px); return px;//ww w . ja v a 2 s . c o m }
From source file:com.android.launcher3.Utilities.java
public static boolean getAllowRotationDefaultValue(Context context) { if (isNycOrAbove()) { // If the device was scaled, used the original dimensions to determine if rotation // is allowed of not. Resources res = context.getResources(); int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp * res.getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEVICE_STABLE; return originalSmallestWidth >= 600; }/*from w w w. j a v a 2 s .c om*/ return false; }