List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:com.ruesga.rview.widget.TagEditTextView.java
private void init(Context ctx, AttributeSet attrs, int defStyleAttr) { mHandler = new Handler(mTagMessenger); mTriggerTagCreationThreshold = CREATE_CHIP_DEFAULT_DELAYED_TIMEOUT; Resources.Theme theme = ctx.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.TagEditTextView, defStyleAttr, 0); mReadOnly = a.getBoolean(R.styleable.TagEditTextView_readonly, false); mDefaultTagMode = TAG_MODE.HASH;/*from w ww .ja va 2s . c o m*/ // Create the internal EditText that holds the tag logic mTagEdit = mReadOnly ? new TagEditText(ctx, attrs, defStyleAttr) : new TagEditText(ctx, attrs); mTagEdit.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 0)); mTagEdit.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); mTagEdit.addTextChangedListener(mEditListener); mTagEdit.setTextIsSelectable(false); mTagEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE); mTagEdit.setOnFocusChangeListener((v, hasFocus) -> { // Remove any pending message mHandler.removeMessages(MESSAGE_CREATE_CHIP); }); mTagEdit.setCustomSelectionActionModeCallback(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { return false; } @Override public void onDestroyActionMode(ActionMode mode) { } }); addView(mTagEdit); // Configure the window mode for landscape orientation, to disallow hide the // EditText control, and show characters instead of chips int orientation = ctx.getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { if (ctx instanceof Activity) { Window window = ((Activity) ctx).getWindow(); if (window != null) { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); mTagEdit.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); } } } // Save the keyListener for later restore mEditModeKeyListener = mTagEdit.getKeyListener(); // Initialize resources for chips mChipBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mChipFgPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG); mChipFgPaint.setTextSize(mTagEdit.getTextSize() * (mReadOnly ? 1 : 0.8f)); if (CHIP_TYPEFACE != null) { mChipFgPaint.setTypeface(CHIP_TYPEFACE); } mChipFgPaint.setTextAlign(Paint.Align.LEFT); // Calculate the width area used to remove the tag in the chip mChipRemoveAreaWidth = (int) (mChipFgPaint.measureText(CHIP_REMOVE_TEXT) + 0.5f); if (ONE_PIXEL <= 0) { Resources res = getResources(); ONE_PIXEL = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, res.getDisplayMetrics()); } int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.TagEditTextView_supportUserTags: setSupportsUserTags(a.getBoolean(attr, false)); break; case R.styleable.TagEditTextView_chipBackgroundColor: mChipBackgroundColor = a.getColor(attr, mChipBackgroundColor); break; case R.styleable.TagEditTextView_chipTextColor: mChipFgPaint.setColor(a.getColor(attr, Color.WHITE)); break; } } a.recycle(); }
From source file:org.appcelerator.titanium.util.TiUIHelper.java
public static float getRawSize(final int unit, final float size, final Context context) { Resources r; if (context != null) { r = context.getResources();/*from ww w. j ava2 s . co m*/ } else { r = Resources.getSystem(); } return TypedValue.applyDimension(unit, size, r.getDisplayMetrics()); }
From source file:org.androidsoft.games.utils.level.LevelSelectorActivity.java
private void initGraphics(Resources res) { mGraphics = new Graphics(); mGraphics.setBitmapLock(BitmapFactory.decodeResource(res, R.drawable.lock)); mGraphics.setBitmap1star(BitmapFactory.decodeResource(res, R.drawable.star1)); mGraphics.setBitmap2stars(BitmapFactory.decodeResource(res, R.drawable.star2)); mGraphics.setBitmap3stars(BitmapFactory.decodeResource(res, R.drawable.star3)); mGraphics.setButtonShapeResId(sButtonShape); initColors(res, sColorsId, sColors); initColors(res, sDarkColorsId, sDarkColors); initColors(res, sLightColorsId, sLightColors); mGraphics.setColors(sColors);// w w w . j ava 2 s .com mGraphics.setLightColors(sLightColors); mGraphics.setDarkColors(sDarkColors); int width = res.getDisplayMetrics().widthPixels; int height = res.getDisplayMetrics().heightPixels; int viewWidth = (width < height) ? width : (height * 4) / 5; mGraphics.setViewWidth(viewWidth); initLabels(res, sGridTitlesId, sGridTitles); mGraphics.setGridTitles(sGridTitles); }
From source file:lewa.support.v7.internal.view.menu.ActionMenuItemView.java
public ActionMenuItemView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // LEWA ADD BEGIN mContext = context;/*from w ww. j a va2 s.co m*/ // LEWA ADD END final Resources res = context.getResources(); mAllowTextWithIcon = res.getBoolean(R.bool.abc_config_allowActionMenuItemTextWithIcon); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionMenuItemView, defStyle, 0); mMinWidth = a.getDimensionPixelSize(R.styleable.ActionMenuItemView_android_minWidth, 0); a.recycle(); final float density = res.getDisplayMetrics().density; // LEWA MODIFY BEGIN mMaxIconSize = Injector.getMaxIconSize(this); // LEWA MODIFY END // LEWA ADD BEGIN mMaxItemWidth = (int) (MAX_ITEM_WIDTH * density); // LEWA ADD END mMaxIconSize = (int) (MAX_ICON_SIZE * density + 0.5f); setOnClickListener(this); setOnLongClickListener(this); setTransformationMethod(new AllCapsTransformationMethod(context)); mSavedPaddingLeft = -1; // LEWA ADD BEGIN Injector.initColorfulStyle(this); // LEWA ADD END }
From source file:com.adherence.adherence.SwipeRevealLayout.java
private int pxToDp(int px) { Resources resources = getContext().getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return (int) (px / ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT)); }
From source file:com.adherence.adherence.SwipeRevealLayout.java
private int dpToPx(int dp) { Resources resources = getContext().getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); return (int) (dp * ((float) metrics.densityDpi / DisplayMetrics.DENSITY_DEFAULT)); }
From source file:lb.themike10452.game.Rendering.Animation.SpriteSheet.java
/** * @param spriteSheetResId resId of the bitmap containing the sprites * @param dataAsset name of the json data map file located in assets folder *///from ww w .j a v a2s . c o m public SpriteSheet(Resources resources, int spriteSheetResId, AssetManager assets, String dataAsset) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false; Bitmap = BitmapFactory.decodeResource(resources, spriteSheetResId, options); mSpriteMap = new HashMap<>(); try { JSONArray array = new JSONArray(Utils.readAsset(assets, dataAsset)); int length = array.length(); JSONObject obj; String name; int x, y, w, h; for (int i = 0; i < length; i++) { obj = array.getJSONObject(i); name = obj.getString("name"); x = obj.getInt("x"); y = obj.getInt("y"); w = obj.getInt("width"); h = obj.getInt("height"); mSpriteMap.put(name, new Sprite(x, y, w, h)); } } catch (JSONException e) { e.printStackTrace(); } DRAW_SCALE = resources.getDisplayMetrics().scaledDensity; }
From source file:com.example.angel.parkpanda.MainActivity.java
public Bitmap drawTextToBitmap(int gResId, String gText) { Resources resources = getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId); android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig(); if (bitmapConfig == null) { bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888; }/*w w w .j a v a2s . c om*/ bitmap = bitmap.copy(bitmapConfig, true); Canvas canvas = new Canvas(bitmap); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setColor(Color.rgb(0, 0, 0)); paint.setTextSize((int) (15 * scale)); paint.setShadowLayer(1f, 0f, 1f, Color.BLACK); Rect bounds = new Rect(); paint.getTextBounds(gText, 0, gText.length(), bounds); int x = (bitmap.getWidth() - bounds.width()) / 2; int y = (bitmap.getHeight() + bounds.height()) / 2 - 10; canvas.drawText(gText, x, y, paint); return bitmap; }
From source file:com.timekeeping.app.activities.MainActivity.java
@Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); //System setting might be changed, ie. language. Resources resources = getResources(); if (resources != null) { resources.updateConfiguration(newConfig, resources.getDisplayMetrics()); }// www .j a v a 2s. co m }