List of usage examples for android.content.res Resources getDimensionPixelSize
public int getDimensionPixelSize(@DimenRes int id) throws NotFoundException
From source file:org.mariotaku.twidere.fragment.AbsActivitiesFragment.java
@Nullable @Override/*from w ww. j a v a 2 s . c o m*/ protected RecyclerView.ItemDecoration createItemDecoration(Context context, final RecyclerView recyclerView, final LinearLayoutManager layoutManager) { final ParcelableActivitiesAdapter adapter = getAdapter(); final DividerItemDecoration itemDecoration = new DividerItemDecoration(context, ((LinearLayoutManager) recyclerView.getLayoutManager()).getOrientation()); final Resources res = context.getResources(); if (adapter.isProfileImageEnabled()) { final int decorPaddingLeft = res.getDimensionPixelSize(R.dimen.element_spacing_normal) * 2 + res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image); itemDecoration.setPadding(new DividerItemDecoration.Padding() { @Override public boolean get(int position, Rect rect) { final int itemViewType = adapter.getItemViewType(position); boolean nextItemIsStatus = false; if (position < adapter.getItemCount() - 1) { nextItemIsStatus = adapter .getItemViewType(position + 1) == ParcelableActivitiesAdapter.ITEM_VIEW_TYPE_STATUS; } if (nextItemIsStatus && itemViewType == ParcelableActivitiesAdapter.ITEM_VIEW_TYPE_STATUS) { rect.left = decorPaddingLeft; } else { rect.left = 0; } return true; } }); } itemDecoration.setDecorationEndOffset(1); return itemDecoration; }
From source file:com.cloudTop.starshare.ui.wangyi.common.ui.viewpager.PagerSlidingTabStrip.java
private void addTabView(final int position, String title) { View tabView = null;/*from ww w . ja v a 2s . co m*/ boolean screenAdaptation = false; final LayoutInflater inflater = LayoutInflater.from(getContext()); if (this.onCustomTabListener != null) { int tabResId = onCustomTabListener.getTabLayoutResId(position); if (tabResId != 0) { tabView = inflater.inflate(tabResId, null); } else { tabView = onCustomTabListener.getTabLayoutView(inflater, position); } screenAdaptation = onCustomTabListener.screenAdaptation(); } if (tabView == null) { tabView = inflater.inflate(R.layout.tab_layout_main, null); } TextView titleTV = ((TextView) tabView.findViewById(R.id.tab_title_label)); final boolean needAdaptation = ScreenUtil.density <= 1.5 && screenAdaptation; final Resources resources = getContext().getResources(); if (titleTV != null) { titleTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, needAdaptation ? resources.getDimensionPixelSize(R.dimen.text_size_11) : resources.getDimensionPixelSize(R.dimen.text_size_15)); titleTV.setText(title); } final DropFake unreadTV = ((DropFake) tabView.findViewById(R.id.tab_new_msg_label)); if (unreadTV != null) { unreadTV.setTouchListener(new DropFake.ITouchListener() { @Override public void onDown() { DropManager.getInstance().setCurrentId(String.valueOf(position)); DropManager.getInstance().down(unreadTV, unreadTV.getText()); } @Override public void onMove(float curX, float curY) { DropManager.getInstance().move(curX, curY); } @Override public void onUp() { DropManager.getInstance().up(); } }); //unreadTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, needAdaptation ? resources.getDimensionPixelSize(R.dimen.text_size_9) : resources.getDimensionPixelSize(R.dimen.text_size_12)); } addTab(position, tabView); }
From source file:com.worksum.android.nim.common.ui.viewpager.PagerSlidingTabStrip.java
private void addTabView(final int position, String title) { View tabView = null;//www .jav a 2s . com boolean screenAdaptation = false; final LayoutInflater inflater = LayoutInflater.from(getContext()); if (this.onCustomTabListener != null) { int tabResId = onCustomTabListener.getTabLayoutResId(position); if (tabResId != 0) { tabView = inflater.inflate(tabResId, null); } else { tabView = onCustomTabListener.getTabLayoutView(inflater, position); } screenAdaptation = onCustomTabListener.screenAdaptation(); } if (tabView == null) { tabView = inflater.inflate(R.layout.tab_layout_main, null); } TextView titleTV = ((TextView) tabView.findViewById(R.id.tab_title_label)); final boolean needAdaptation = ScreenUtil.density <= 1.5 && screenAdaptation; final Resources resources = getContext().getResources(); if (titleTV != null) { titleTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, needAdaptation ? resources.getDimensionPixelSize(R.dimen.text_size_11) : resources.getDimensionPixelSize(R.dimen.text_size_15)); titleTV.setText(title); } final DropFake unreadTV = ((DropFake) tabView.findViewById(R.id.tab_new_msg_label)); if (unreadTV != null) { unreadTV.setClickListener(new DropFake.ITouchListener() { @Override public void onDown() { DropManager.getInstance().setCurrentId(String.valueOf(position)); DropManager.getInstance().getDropCover().down(unreadTV, unreadTV.getText()); } @Override public void onMove(float curX, float curY) { DropManager.getInstance().getDropCover().move(curX, curY); } @Override public void onUp() { DropManager.getInstance().getDropCover().up(); } }); //unreadTV.setTextSize(TypedValue.COMPLEX_UNIT_PX, needAdaptation ? resources.getDimensionPixelSize(R.dimen.text_size_9) : resources.getDimensionPixelSize(R.dimen.text_size_12)); } addTab(position, tabView); }
From source file:com.lite.android.launcher3.allapps.AllAppsGridAdapter.java
public void setSectionStrategy(int sectionStrategy) { Resources res = mLauncher.getResources(); mSectionStrategy = sectionStrategy;/*w w w. ja va 2s.co m*/ mSectionNamesMargin = mSectionStrategy == AllAppsContainerView.SECTION_STRATEGY_GRID ? res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin) : res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin_with_sections); }
From source file:com.btmura.android.reddit.app.AbstractBrowserActivity.java
private void measureThingBodyWidth() { if (isSinglePane || drawerLayout != null && navContainer != null) { return;/*w ww .ja va 2 s .c om*/ } Resources r = getResources(); DisplayMetrics dm = r.getDisplayMetrics(); int padding = r.getDimensionPixelSize(R.dimen.element_padding); if (navContainer != null) { int newWidth = hasLeftFragment() ? leftWidth : 0; thingBodyWidth = dm.widthPixels - newWidth - padding * 2; } else { thingBodyWidth = dm.widthPixels / 5 * 2 - padding * 3; } }
From source file:org.tomahawk.tomahawk_android.fragments.ContentHeaderFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Resources res = getResources(); if (getArguments() != null) { mCurrentMode = getArguments().getInt(TomahawkFragment.CONTENT_HEADER_MODE, -1); switch (mCurrentMode) { case MODE_HEADER_DYNAMIC: mHeaderScrollableHeight = res.getDimensionPixelSize(R.dimen.header_clear_space_scrollable); mHeaderNonscrollableHeight = res.getDimensionPixelSize(R.dimen.header_clear_space_nonscrollable); break; case MODE_HEADER_DYNAMIC_PAGER: mHeaderScrollableHeight = res.getDimensionPixelSize(R.dimen.header_clear_space_scrollable); mHeaderNonscrollableHeight = res.getDimensionPixelSize(R.dimen.header_clear_space_nonscrollable) + res.getDimensionPixelSize(R.dimen.pager_indicator_height); break; case MODE_HEADER_STATIC: mHeaderNonscrollableHeight = res .getDimensionPixelSize(R.dimen.header_clear_space_nonscrollable_static); break; case MODE_HEADER_STATIC_USER: mHeaderNonscrollableHeight = res .getDimensionPixelSize(R.dimen.header_clear_space_nonscrollable_static_user); break; case MODE_HEADER_STATIC_SMALL: mHeaderNonscrollableHeight = res .getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material) + res.getDimensionPixelSize(R.dimen.pager_indicator_height); break; case MODE_ACTIONBAR_FILLED: mHeaderNonscrollableHeight = res .getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material); break; case MODE_HEADER_PLAYBACK: mHeaderNonscrollableHeight = res .getDimensionPixelSize(R.dimen.header_clear_space_nonscrollable_playback); break; default://from w w w.ja va 2s . co m throw new RuntimeException("Missing or invalid ContentHeaderFragment mode"); } if (getArguments().containsKey(TomahawkFragment.CONTAINER_FRAGMENT_ID)) { mContainerFragmentId = getArguments().getLong(TomahawkFragment.CONTAINER_FRAGMENT_ID); } if (getArguments().containsKey(TomahawkFragment.CONTAINER_FRAGMENT_PAGE)) { mContainerFragmentPage = getArguments().getInt(TomahawkFragment.CONTAINER_FRAGMENT_PAGE); } } }
From source file:com.harlan.jxust.ui.view.bottombar.BottomBar.java
private static void navBarMagic(Activity activity, final BottomBar bottomBar) { Resources res = activity.getResources(); int softMenuIdentifier = res.getIdentifier("config_showNavigationBar", "bool", "android"); int navBarIdentifier = res.getIdentifier("navigation_bar_height", "dimen", "android"); int navBarHeight = 0; if (navBarIdentifier > 0) { navBarHeight = res.getDimensionPixelSize(navBarIdentifier); }/*from www . j a v a2s .com*/ if (!bottomBar.drawBehindNavBar() || navBarHeight == 0 || (!(softMenuIdentifier > 0 && res.getBoolean(softMenuIdentifier)))) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && ViewConfiguration.get(activity).hasPermanentMenuKey()) { return; } /** * Copy-paste coding made possible by: * http://stackoverflow.com/a/14871974/940036 */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { Display d = activity.getWindowManager().getDefaultDisplay(); DisplayMetrics realDisplayMetrics = new DisplayMetrics(); d.getRealMetrics(realDisplayMetrics); int realHeight = realDisplayMetrics.heightPixels; int realWidth = realDisplayMetrics.widthPixels; DisplayMetrics displayMetrics = new DisplayMetrics(); d.getMetrics(displayMetrics); int displayHeight = displayMetrics.heightPixels; int displayWidth = displayMetrics.widthPixels; boolean hasSoftwareKeys = (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; if (!hasSoftwareKeys) { return; } } /** * End of delicious copy-paste code */ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { activity.getWindow().getAttributes().flags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION; if (bottomBar.useTopOffset()) { int offset; int statusBarResource = res.getIdentifier("status_bar_height", "dimen", "android"); if (statusBarResource > 0) { offset = res.getDimensionPixelSize(statusBarResource); } else { offset = MiscUtils.dpToPixel(activity, 25); } if (!bottomBar.useOnlyStatusbarOffset()) { TypedValue tv = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { offset += TypedValue.complexToDimensionPixelSize(tv.data, res.getDisplayMetrics()); } else { offset += MiscUtils.dpToPixel(activity, 56); } } bottomBar.getUserContainer().setPadding(0, offset, 0, 0); } final View outerContainer = bottomBar.getOuterContainer(); final int navBarHeightCopy = navBarHeight; bottomBar.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @Override public void onGlobalLayout() { bottomBar.shyHeightAlreadyCalculated(); int newHeight = outerContainer.getHeight() + navBarHeightCopy; outerContainer.getLayoutParams().height = newHeight; if (bottomBar.isShy()) { int defaultOffset = bottomBar.useExtraOffset() ? navBarHeightCopy : 0; bottomBar.setTranslationY(defaultOffset); ((CoordinatorLayout.LayoutParams) bottomBar.getLayoutParams()) .setBehavior(new BottomNavigationBehavior(newHeight, defaultOffset, bottomBar.isShy(), bottomBar.mIsTabletMode)); } ViewTreeObserver obs = outerContainer.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); } else { obs.removeGlobalOnLayoutListener(this); } } }); } }
From source file:com.mediatek.galleryfeature.stereo.segment.ImageShow.java
private void setupImageShow(Context context) { Resources res = context.getResources(); res.getColor(R.color.background_screen); mGestureDetector = new GestureDetector(context, this); mScaleGestureDetector = new ScaleGestureDetector(context, this); mActivity = (Activity) context;/*from w w w .j a v a 2 s . c o m*/ mEdgeEffect = new EdgeEffectCompat(context); mEdgeSize = res.getDimensionPixelSize(R.dimen.edge_glow_size); }
From source file:connect.app.com.connect.calendar.SimpleMonthView.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public SimpleMonthView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); final Resources res = context.getResources(); mDesiredMonthHeight = res.getDimensionPixelSize(R.dimen.date_picker_month_height); mDesiredDayOfWeekHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_of_week_height); mDesiredDayHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_height); mDesiredCellWidth = res.getDimensionPixelSize(R.dimen.date_picker_day_width); mDesiredDaySelectorRadius = res.getDimensionPixelSize(R.dimen.date_picker_day_selector_radius); // Set up accessibility components. mTouchHelper = new MonthViewTouchHelper(this); // setAccessibilityDelegate(mTouchHelper); setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES); final Locale locale = res.getConfiguration().locale; final String titleFormat = DateFormat.getBestDateTimePattern(locale, DEFAULT_TITLE_FORMAT); mTitleFormatter = new SimpleDateFormat(titleFormat, locale); mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale); mDayFormatter = NumberFormat.getIntegerInstance(locale); initPaints(res);/*from ww w. j a v a 2s . c o m*/ }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
public SimpleMonthView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final Resources res = context.getResources(); mDesiredMonthHeight = res.getDimensionPixelSize(R.dimen.date_picker_month_height); mDesiredDayOfWeekHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_of_week_height); mDesiredDayHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_height); mDesiredCellWidth = res.getDimensionPixelSize(R.dimen.date_picker_day_width); mDesiredDaySelectorRadius = res.getDimensionPixelSize(R.dimen.date_picker_day_selector_radius); // Set up accessibility components. mTouchHelper = new MonthViewTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); final Locale locale = res.getConfiguration().locale; final String titleFormat = DateFormatUtils.getBestDateTimePattern(locale, DEFAULT_TITLE_FORMAT); mTitleFormatter = new SimpleDateFormat(titleFormat, locale); mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale); mDayFormatter = NumberFormat.getIntegerInstance(locale); initPaints(res);//from ww w . ja v a 2 s .c o m }