List of usage examples for android.content.res Resources getDisplayMetrics
public DisplayMetrics getDisplayMetrics()
From source file:com.tmall.wireless.tangram.view.LinearScrollView.java
private int getScreenWidth() { Resources resources = getContext().getResources(); DisplayMetrics dm = resources.getDisplayMetrics(); Configuration configuration = resources.getConfiguration(); return configuration.orientation == Configuration.ORIENTATION_PORTRAIT ? dm.widthPixels : dm.heightPixels; }
From source file:org.mariotaku.gallery3d.GLImageLoader.java
public GLImageLoader(final Context context, final DownloadListener listener, final Uri uri) { super(context); mHandler = new Handler(); mUri = uri;/* www. ja v a 2 s . c om*/ mListener = listener; final TwidereApplication app = TwidereApplication.getInstance(context); mDownloader = app.getFullImageDownloader(); mDiscCache = app.getFullDiscCache(); final Resources res = context.getResources(); final DisplayMetrics dm = res.getDisplayMetrics(); mFallbackSize = Math.max(dm.heightPixels, dm.widthPixels); }
From source file:org.openmrs.mobile.activities.fragments.FormPageFragment.java
void addQuestion(Question question, LinearLayout parent) { if (question.getQuestionOptions().getRendering().equals("group")) { LinearLayout questionLL = new LinearLayout(getActivity()); questionLL.setOrientation(LinearLayout.VERTICAL); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); questionLL.setGravity(Gravity.CENTER); parent.addView(questionLL);/* ww w . j av a 2 s .co m*/ Resources r = getActivity().getResources(); float pxLeftMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxTopMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxRightMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxBottomMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); layoutParams.setMargins(Math.round(pxLeftMargin), Math.round(pxTopMargin), Math.round(pxRightMargin), Math.round(pxBottomMargin)); TextView tv = new TextView(getActivity()); tv.setText(question.getLabel()); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); tv.setTextColor(ContextCompat.getColor(getActivity(), R.color.primary)); questionLL.addView(tv, layoutParams); for (Question subquestion : question.getQuestions()) { addQuestion(subquestion, questionLL); } } if (question.getQuestionOptions().getRendering().equals("number")) { LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); Resources r = getActivity().getResources(); float pxLeftMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxTopMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxRightMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); float pxBottomMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, r.getDisplayMetrics()); layoutParams.setMargins(Math.round(pxLeftMargin), Math.round(pxTopMargin), Math.round(pxRightMargin), Math.round(pxBottomMargin)); RangeEditText ed = new RangeEditText(getActivity()); ed.setName(question.getLabel()); if (question.getQuestionOptions().getMax() != null) { ed.setHint(question.getLabel() + " [" + question.getQuestionOptions().getMin() + "-" + question.getQuestionOptions().getMax() + "]"); ed.setUpperlimit(Double.parseDouble(question.getQuestionOptions().getMax())); ed.setLowerlimit(Double.parseDouble(question.getQuestionOptions().getMin())); } else { ed.setHint(question.getLabel()); ed.setLowerlimit(-1.0); ed.setUpperlimit(-1.0); } ed.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16); ed.setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); int id = InputField.generateViewId(); InputField field = new InputField(); ed.setId(id); field.setId(id); field.setConcept(question.getQuestionOptions().getConcept()); inputFields.add(field); parent.addView(ed, layoutParams); } }
From source file:com.silentcircle.contacts.ContactPhotoManager.java
/** * Returns the resource id of the default avatar. Tries to find a resource that is bigger * than the given extent (width or height). If extent=-1, a thumbnail avatar is returned *///from www. j a v a 2 s .com public static int getDefaultAvatarResId(Context context, int extent, boolean darkTheme) { // TODO: Is it worth finding a nicer way to do hires/lores here? In practice, the // default avatar doesn't look too different when stretched if (s180DipInPixel == -1) { Resources r = context.getResources(); s180DipInPixel = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 180, r.getDisplayMetrics()); } final boolean hires = (extent != -1) && (extent > s180DipInPixel); return getDefaultAvatarResId(hires, darkTheme); }
From source file:com.ruesga.rview.widget.MergedStatusChart.java
public MergedStatusChart(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setLayerType(View.LAYER_TYPE_SOFTWARE, null); final Resources res = getResources(); mHeightBarPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, res.getDisplayMetrics()); mMinBarWidth = 0f;/*from w w w. j a va 2s .c o m*/ int openColor = Color.DKGRAY; int mergedColor = Color.DKGRAY; int abandonedColor = Color.DKGRAY; int textColor = Color.WHITE; Resources.Theme theme = context.getTheme(); TypedArray a = theme.obtainStyledAttributes(attrs, R.styleable.MergedStatusChart, defStyleAttr, 0); int n = a.getIndexCount(); for (int i = 0; i < n; i++) { int attr = a.getIndex(i); switch (attr) { case R.styleable.MergedStatusChart_heightBarPadding: mHeightBarPadding = a.getDimension(attr, mHeightBarPadding); break; case R.styleable.MergedStatusChart_minBarWidth: mMinBarWidth = a.getDimension(attr, mMinBarWidth); break; case R.styleable.MergedStatusChart_openColor: openColor = a.getColor(attr, openColor); break; case R.styleable.MergedStatusChart_mergedColor: mergedColor = a.getColor(attr, mergedColor); break; case R.styleable.MergedStatusChart_abandonedColor: abandonedColor = a.getColor(attr, abandonedColor); break; case R.styleable.MergedStatusChart_statusLabelTextColor: textColor = a.getColor(attr, textColor); break; } } a.recycle(); mOpenPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mOpenPaint.setStyle(Paint.Style.FILL); mMergedPaint = new Paint(mOpenPaint); mAbandonedPaint = new Paint(mOpenPaint); mOpenPaint.setColor(openColor); mMergedPaint.setColor(mergedColor); mAbandonedPaint.setColor(abandonedColor); mLabelPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.LINEAR_TEXT_FLAG); mLabelPaint.setTextAlign(Paint.Align.LEFT); mLabelPaint.setFakeBoldText(true); mLabelPaint.setColor(textColor); mLabelPaint .setTextSize(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 10f, res.getDisplayMetrics())); mLabelPadding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 2f, res.getDisplayMetrics()); Rect bounds = new Rect(); mLabelPaint.getTextBounds("0", 0, 1, bounds); mLabelHeight = bounds.height(); if (getBackground() == null) { setBackgroundColor(Color.TRANSPARENT); } }
From source file:com.forrestguice.suntimeswidget.LocationConfigDialog.java
/** * @param savedInstanceState a Bundle containing previously saved dialog state * @return an AlertDialog ready for display *///from w w w.j a v a 2 s . co m @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { super.onCreateDialog(savedInstanceState); final FragmentActivity myParent = getActivity(); dialogContent = new com.forrestguice.suntimeswidget.LocationConfigView(myParent); dialogContent.init(myParent, true); dialogContent.setHideTitle(hideTitle); Resources r = getResources(); int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, r.getDisplayMetrics()); AlertDialog.Builder builder = new AlertDialog.Builder(myParent); builder.setTitle(myParent.getString(R.string.location_dialog_title)); builder.setView(dialogContent, 0, padding, 0, 0); final AlertDialog dialog = builder.create(); dialog.setCanceledOnTouchOutside(false); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, myParent.getString(R.string.location_dialog_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialogContent.cancelGetFix(); dialog.dismiss(); if (onCanceled != null) { onCanceled.onClick(dialog, which); } } }); dialog.setButton(AlertDialog.BUTTON_POSITIVE, myParent.getString(R.string.location_dialog_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { /** EMPTY */ } }); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { // set the dialog's onAccept listener /after/ the dialog is shown; explicit call to `dismiss` req. // http://stackoverflow.com/questions/2620444/how-to-prevent-a-dialog-from-closing-when-a-button-is-clicked dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { dialogContent.cancelGetFix(); if (dialogContent.saveSettings(myParent)) { LocationConfigView.LocationViewMode mode = dialogContent.getMode(); switch (mode) { case MODE_CUSTOM_ADD: case MODE_CUSTOM_EDIT: dialogContent.setMode(LocationConfigView.LocationViewMode.MODE_CUSTOM_SELECT); dialogContent.populateLocationList(); // triggers 'add place' break; } dialog.dismiss(); if (onAccepted != null) { onAccepted.onClick(dialog, 0); } } } }); } }); if (savedInstanceState != null) { loadSettings(savedInstanceState); } else if (presetData != null) { dialogContent.loadSettings(myParent, presetData); } return dialog; }
From source file:com.quran.labs.androidquran.widgets.SlidingTabLayout.java
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Make sure that the Tab Strips fills this View setFillViewport(true);//from w w w .j a v a 2s.c o m final Resources resources = getResources(); final float density = resources.getDisplayMetrics().density; mTitleOffset = (int) (TITLE_OFFSET_DIPS * density); mTabPadding = (int) (TAB_VIEW_PADDING_DIPS * density); mSelectedTabColor = ContextCompat.getColor(context, R.color.color_control_activated); mUnselectedTabColor = ContextCompat.getColor(context, R.color.color_control_normal); mTabStrip = new SlidingTabStrip(context); mTabStrip.setSelectedIndicatorColors(ContextCompat.getColor(context, R.color.indicator_color)); addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); }
From source file:me.lizheng.deckview.helpers.DeckViewConfig.java
/** * Updates the state, given the specified context */// w w w . j a v a 2 s . c o m void update(Context context) { Resources res = context.getResources(); DisplayMetrics dm = res.getDisplayMetrics(); // Debug mode debugModeEnabled = false; // Layout isLandscape = res.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; // Insets displayRect.set(0, 0, dm.widthPixels, dm.heightPixels); // Animations animationPxMovementPerSecond = res.getDimensionPixelSize(R.dimen.animation_movement_in_dps_per_second); // Filtering filteringCurrentViewsAnimDuration = res.getInteger(R.integer.filter_animate_current_views_duration); filteringNewViewsAnimDuration = res.getInteger(R.integer.filter_animate_new_views_duration); // Task stack taskStackScrollDuration = res.getInteger(R.integer.animate_deck_scroll_duration); TypedValue widthPaddingPctValue = new TypedValue(); res.getValue(R.dimen.deck_width_padding_percentage, widthPaddingPctValue, true); taskStackWidthPaddingPct = widthPaddingPctValue.getFloat(); TypedValue stackOverscrollPctValue = new TypedValue(); res.getValue(R.dimen.deck_overscroll_percentage, stackOverscrollPctValue, true); taskStackOverscrollPct = stackOverscrollPctValue.getFloat(); taskStackMaxDim = res.getInteger(R.integer.max_deck_view_dim); taskStackTopPaddingPx = res.getDimensionPixelSize(R.dimen.deck_top_padding); // Transition transitionEnterFromAppDelay = res.getInteger(R.integer.enter_from_app_transition_duration); transitionEnterFromHomeDelay = res.getInteger(R.integer.enter_from_home_transition_duration); // Task view animation and styles taskViewEnterFromAppDuration = res.getInteger(R.integer.task_enter_from_app_duration); taskViewEnterFromHomeDuration = res.getInteger(R.integer.task_enter_from_home_duration); taskViewEnterFromHomeStaggerDelay = res.getInteger(R.integer.task_enter_from_home_stagger_delay); taskViewExitToAppDuration = res.getInteger(R.integer.task_exit_to_app_duration); taskViewExitToHomeDuration = res.getInteger(R.integer.task_exit_to_home_duration); taskViewRemoveAnimDuration = res.getInteger(R.integer.animate_task_view_remove_duration); taskViewRemoveAnimTranslationXPx = res.getDimensionPixelSize(R.dimen.task_view_remove_anim_translation_x); taskViewRoundedCornerRadiusPx = res.getDimensionPixelSize(R.dimen.task_view_rounded_corners_radius); taskViewHighlightPx = res.getDimensionPixelSize(R.dimen.task_view_highlight); taskViewTranslationZMinPx = res.getDimensionPixelSize(R.dimen.task_view_z_min); taskViewTranslationZMaxPx = res.getDimensionPixelSize(R.dimen.task_view_z_max); taskViewAffiliateGroupEnterOffsetPx = res .getDimensionPixelSize(R.dimen.task_view_affiliate_group_enter_offset); TypedValue thumbnailAlphaValue = new TypedValue(); res.getValue(R.dimen.task_view_thumbnail_alpha, thumbnailAlphaValue, true); taskViewThumbnailAlpha = thumbnailAlphaValue.getFloat(); // Task bar colors taskBarViewDefaultBackgroundColor = ContextCompat.getColor(context, R.color.task_bar_default_background_color); taskBarViewLightTextColor = ContextCompat.getColor(context, R.color.task_bar_light_text_color); taskBarViewDarkTextColor = ContextCompat.getColor(context, R.color.task_bar_dark_text_color); taskBarViewHighlightColor = ContextCompat.getColor(context, R.color.task_bar_highlight_color); TypedValue affMinAlphaPctValue = new TypedValue(); res.getValue(R.dimen.task_affiliation_color_min_alpha_percentage, affMinAlphaPctValue, true); taskBarViewAffiliationColorMinAlpha = affMinAlphaPctValue.getFloat(); // Task bar size & animations taskBarHeight = res.getDimensionPixelSize(R.dimen.deck_child_header_bar_height); taskBarDismissDozeDelaySeconds = res.getInteger(R.integer.task_bar_dismiss_delay_seconds); // Nav bar scrim navBarScrimEnterDuration = res.getInteger(R.integer.nav_bar_scrim_enter_duration); // Misc useHardwareLayers = res.getBoolean(R.bool.config_use_hardware_layers); altTabKeyDelay = res.getInteger(R.integer.deck_alt_tab_key_delay); fakeShadows = res.getBoolean(R.bool.config_fake_shadows); svelteLevel = res.getInteger(R.integer.deck_svelte_level); }
From source file:org.devconmyanmar.apps.devcon.adapter.ScheduleAdapter.java
@Override public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) { Talk mTalk = mTalks.get(position);//w w w.j ava 2 s . c om Resources r = mContext.getResources(); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, r.getDisplayMetrics()); switch (viewHolder.getItemViewType()) { case VIEW_TYPE_KEYNOTE: KeynoteViewHolder keynoteViewHolder = (KeynoteViewHolder) viewHolder; keynoteViewHolder.mKeynoteTitle.setText(mTalk.getTitle()); String dateString = mTalk.getDate(); String formattedDate = TimeUtils.parseDateString(dateString); String keynoteFormattedFrom = TimeUtils.parseFromToString(mTalk.getFrom_time()); String keynoteFormattedTo = TimeUtils.parseFromToString(mTalk.getTo_time()); String keynoteRoom = TimeUtils.getProperRoomName(mTalk.getRoom()); // Phrase yo! CharSequence keyNoteTimeAndPlace = Phrase.from(mContext, R.string.talk_detail_time_and_place) .put("day", formattedDate).put("from_time", keynoteFormattedFrom) .put("to_time", keynoteFormattedTo).put("room", keynoteRoom).format(); keynoteViewHolder.mKeyNoteTime.setText(keyNoteTimeAndPlace); break; case VIEW_TYPE_NORMAL: NormalViewHolder normalViewHolder = (NormalViewHolder) viewHolder; if (Build.VERSION.SDK_INT >= 21) { normalViewHolder.mNormalContainer.setPadding(0, px, 0, 0); } String normalFormattedFrom = TimeUtils.parseFromToString(mTalk.getFrom_time()); String normalFormattedTo = TimeUtils.parseFromToString(mTalk.getTo_time()); String talkTitle = mTalk.getTitle(); normalViewHolder.mScheduleTitle.setText(talkTitle); if (isMyanmarText(talkTitle)) { mmtext.prepareView(mContext, normalViewHolder.mScheduleTitle, mmtext.TEXT_UNICODE, true, true); } normalViewHolder.mFromTime.setText(normalFormattedFrom); normalViewHolder.mToTime.setText(normalFormattedTo); String speakers = flatternSpeakerNames(mTalk.getSpeakers()); normalViewHolder.mScheduleSpeakers.setText(speakers); break; case VIEW_TYPE_WORKSHOP: WorkshopViewHolder workshopViewHolder = (WorkshopViewHolder) viewHolder; workshopViewHolder.mWorkshopBackground .setBackgroundColor(ContextCompat.getColor(mContext, R.color.fb_button_background)); workshopViewHolder.mWorkshopTitle.setText(mTalk.getTitle()); String workshopDate = mTalk.getDate(); formattedDate = TimeUtils.parseDateString(workshopDate); String wsFormattedFrom = TimeUtils.parseFromToString(mTalk.getFrom_time()); String wsFormattedTo = TimeUtils.parseFromToString(mTalk.getTo_time()); String wsRoom = TimeUtils.getProperRoomName(mTalk.getRoom()); // Phrase yo! CharSequence wsNoteTimeAndPlace = Phrase.from(mContext, R.string.talk_detail_time_and_place) .put("day", formattedDate).put("from_time", wsFormattedFrom).put("to_time", wsFormattedTo) .put("room", wsRoom).format(); workshopViewHolder.mWorkshopTime.setText(wsNoteTimeAndPlace); break; } }
From source file:ir.rasen.charsoo.view.fragment.FragmentUserRegisterOfferFriendInvite.java
public int getSizeInPixelFromDp(int dpToConvert) { Resources r = getResources(); float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpToConvert, r.getDisplayMetrics()); return (int) px; }