Example usage for android.content.res Resources getDimensionPixelSize

List of usage examples for android.content.res Resources getDimensionPixelSize

Introduction

In this page you can find the example usage for android.content.res Resources getDimensionPixelSize.

Prototype

public int getDimensionPixelSize(@DimenRes int id) throws NotFoundException 

Source Link

Document

Retrieve a dimensional for a particular resource ID for use as a size in raw pixels.

Usage

From source file:com.example.android.sampletvinput.PlaybackOverlayFragment.java

private void updateMetadata(final Video video) {
    final MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder();

    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_MEDIA_ID, video.id + "");
    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_TITLE, video.title);
    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_SUBTITLE, video.studio);
    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_DISPLAY_DESCRIPTION, video.description);

    /*/*w ww .  j  ava 2  s  .  c  o m*/
    long duration = Utils.getDuration(video.videoUrl);
    metadataBuilder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration);
    */
    long duration = getDuration();
    metadataBuilder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, duration);

    // And at minimum the title and artist for legacy support
    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_TITLE, video.title);
    metadataBuilder.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, video.studio);

    Resources res = getResources();
    int cardWidth = res.getDimensionPixelSize(R.dimen.playback_overlay_width);
    int cardHeight = res.getDimensionPixelSize(R.dimen.playback_overlay_height);

    Glide.with(this).load(Uri.parse(video.cardImageUrl)).asBitmap().centerCrop()
            .into(new SimpleTarget<Bitmap>(cardWidth, cardHeight) {
                @Override
                public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
                    metadataBuilder.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, bitmap);
                    mSession.setMetadata(metadataBuilder.build());
                }
            });
}

From source file:com.aqtx.app.common.ui.viewpager.PagerSlidingTabStrip.java

private void addTabView(final int position, String title) {
    View tabView = null;/*from  w  ww.  java2s . 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 titltTV = ((TextView) tabView.findViewById(R.id.tab_title_label));
    TextView unreadTV = ((TextView) tabView.findViewById(R.id.tab_new_msg_label));
    final boolean needAdaptation = ScreenUtil.density <= 1.5 && screenAdaptation;
    final Resources resources = getContext().getResources();
    if (titltTV != null) {
        titltTV.setTextSize(TypedValue.COMPLEX_UNIT_PX,
                needAdaptation ? resources.getDimensionPixelSize(R.dimen.text_size_11)
                        : resources.getDimensionPixelSize(R.dimen.text_size_15));
        titltTV.setText(title);
    }
    if (unreadTV != null) {
        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.squareup.picasso3.RequestCreator.java

/** Resize the image to the specified dimension size. */
@NonNull//from   ww  w .  j a  va  2 s  .co m
public RequestCreator resizeDimen(int targetWidthResId, int targetHeightResId) {
    Resources resources = picasso.context.getResources();
    int targetWidth = resources.getDimensionPixelSize(targetWidthResId);
    int targetHeight = resources.getDimensionPixelSize(targetHeightResId);
    return resize(targetWidth, targetHeight);
}

From source file:com.example.ray.firstapp.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.c o m

    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));
                        }

                        ViewTreeObserver obs = outerContainer.getViewTreeObserver();

                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                            obs.removeOnGlobalLayoutListener(this);
                        } else {
                            obs.removeGlobalOnLayoutListener(this);
                        }
                    }
                });
    }
}

From source file:org.xbmc.kore.ui.sections.video.TVShowDetailsFragment.java

@Override
@TargetApi(21)// w  ww .jav a  2s .  co m
protected View createView(LayoutInflater inflater, ViewGroup container) {
    Bundle bundle = getArguments();
    tvshowId = bundle.getInt(BUNDLE_KEY_TVSHOWID, -1);

    if (tvshowId == -1) {
        // There's nothing to show
        return null;
    }

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_tvshow_overview, container, false);
    ButterKnife.inject(this, root);

    //UIUtils.setSwipeRefreshLayoutColorScheme(swipeRefreshLayout);

    // Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp
    Resources resources = getActivity().getResources();
    final int pixelsToTransparent = 4 * resources.getDimensionPixelSize(R.dimen.default_icon_size);
    mediaPanel.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            float y = mediaPanel.getScrollY();
            float newAlpha = Math.min(1, Math.max(0, 1 - (y / pixelsToTransparent)));
            mediaArt.setAlpha(newAlpha);
        }
    });

    tvshowTitle = bundle.getString(BUNDLE_KEY_TITLE);

    mediaTitle.setText(tvshowTitle);
    setMediaUndertitle(bundle.getInt(BUNDLE_KEY_EPISODE), bundle.getInt(BUNDLE_KEY_WATCHEDEPISODES));
    setMediaPremiered(bundle.getString(BUNDLE_KEY_PREMIERED), bundle.getString(BUNDLE_KEY_STUDIO));
    mediaGenres.setText(bundle.getString(BUNDLE_KEY_GENRES));
    setMediaRating(bundle.getDouble(BUNDLE_KEY_RATING));
    mediaDescription.setText(bundle.getString(BUNDLE_KEY_PLOT));

    if (Utils.isLollipopOrLater()) {
        mediaPoster.setTransitionName(getArguments().getString(POSTER_TRANS_NAME));
    }
    // Pad main content view to overlap with bottom system bar
    //        UIUtils.setPaddingForSystemBars(getActivity(), mediaPanel, false, false, true);
    //        mediaPanel.setClipToPadding(false);

    return root;
}

From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java

public AllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    Resources res = context.getResources();

    mLauncher = Launcher.getLauncher(context);
    mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin);
    mApps = new AlphabeticalAppsList(context);
    mAdapter = new AllAppsGridAdapter(mLauncher, mApps, mLauncher, this);
    mApps.setAdapter(mAdapter);/*  w w w.j a  va  2s  .  c  om*/
    mLayoutManager = mAdapter.getLayoutManager();
    mItemDecoration = mAdapter.getItemDecoration();
    DeviceProfile grid = mLauncher.getDeviceProfile();
    if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && !grid.isVerticalBarLayout()) {
        mRecyclerViewBottomPadding = 0;
        setPadding(0, 0, 0, 0);
    } else {
        mRecyclerViewBottomPadding = res.getDimensionPixelSize(R.dimen.all_apps_list_bottom_padding);
    }
    mSearchQueryBuilder = new SpannableStringBuilder();
    Selection.setSelection(mSearchQueryBuilder, 0);

}

From source file:org.mariotaku.twidere.fragment.AbsStatusesFragment.java

@Nullable
@Override//  ww  w.  j  a  va2 s.  c om
protected RecyclerView.ItemDecoration createItemDecoration(Context context, final RecyclerView recyclerView,
        final LinearLayoutManager layoutManager) {
    final ParcelableStatusesAdapter 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) == ParcelableStatusesAdapter.ITEM_VIEW_TYPE_STATUS;
                }
                if (nextItemIsStatus && itemViewType == ParcelableStatusesAdapter.ITEM_VIEW_TYPE_STATUS) {
                    rect.left = decorPaddingLeft;
                } else {
                    rect.left = 0;
                }
                return true;
            }
        });
    }
    itemDecoration.setDecorationEndOffset(1);
    return itemDecoration;
}

From source file:org.xbmc.kore.ui.AlbumDetailsFragment.java

@TargetApi(21)
@Override/*w w  w . j  a va  2  s . c o  m*/
protected View createView(LayoutInflater inflater, ViewGroup container) {
    albumId = getArguments().getInt(BUNDLE_KEY_ALBUMID, -1);

    if ((container == null) || (albumId == -1)) {
        // We're not being shown or there's nothing to show
        return null;
    }

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_album_details, container, false);
    ButterKnife.inject(this, root);

    hostManager = HostManager.getInstance(getActivity());
    hostInfo = hostManager.getHostInfo();

    // Setup dim the fanart when scroll changes. Full dim on 4 * iconSize dp
    Resources resources = getActivity().getResources();
    final int pixelsToTransparent = 4 * resources.getDimensionPixelSize(R.dimen.default_icon_size);
    mediaPanel.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
        @Override
        public void onScrollChanged() {
            float y = mediaPanel.getScrollY();
            float newAlpha = Math.min(1, Math.max(0, 1 - (y / pixelsToTransparent)));
            mediaArt.setAlpha(newAlpha);
        }
    });

    FloatingActionButton fab = (FloatingActionButton) fabButton;
    fab.attachToScrollView((ObservableScrollView) mediaPanel);

    Bundle bundle = getArguments();

    if (Utils.isLollipopOrLater()) {
        mediaPoster.setTransitionName(bundle.getString(POSTER_TRANS_NAME));
    }

    mediaTitle.setText(bundle.getString(BUNDLE_KEY_ALBUMTITLE));
    mediaUndertitle.setText(bundle.getString(BUNDLE_KEY_ALBUMARTIST));
    setMediaYear(bundle.getString(BUNDLE_KEY_ALBUMGENRE), bundle.getInt(BUNDLE_KEY_ALBUMYEAR));
    setMediaRating(bundle.getDouble(BUNDLE_KEY_ALBUMRATING));

    // Pad main content view to overlap with bottom system bar
    //        UIUtils.setPaddingForSystemBars(getActivity(), mediaPanel, false, false, true);
    //        mediaPanel.setClipToPadding(false);

    return root;
}

From source file:android.support.v7.view.menu.CascadingMenuPopup.java

/**
 * Initializes a new cascading-capable menu popup.
 *
 * @param anchor A parent view to get the {@link android.view.View#getWindowToken()} token from.
 *//*from  www  .  j a v  a  2  s.co m*/
public CascadingMenuPopup(@NonNull Context context, @NonNull View anchor, @AttrRes int popupStyleAttr,
        @StyleRes int popupStyleRes, boolean overflowOnly) {
    mContext = context;
    mAnchorView = anchor;
    mPopupStyleAttr = popupStyleAttr;
    mPopupStyleRes = popupStyleRes;
    mOverflowOnly = overflowOnly;

    mForceShowIcon = false;
    mLastPosition = getInitialMenuPosition();

    final Resources res = context.getResources();
    mMenuMaxWidth = Math.max(res.getDisplayMetrics().widthPixels / 2,
            res.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));

    mSubMenuHoverHandler = new Handler();
}

From source file:be.virtualsushi.gaz.view.ActivityChooserView.java

/**
 * Create a new instance./*from   www . j av  a 2  s . co m*/
 * 
 * @param context
 *            The application environment.
 * @param attrs
 *            A collection of attributes.
 * @param defStyle
 *            The default style to apply to this view.
 */
public ActivityChooserView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.ActivityChooserView,
            defStyle, 0);

    mInitialActivityCount = attributesArray.getInt(R.styleable.ActivityChooserView_initialActivityCount,
            ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_DEFAULT);

    Drawable expandActivityOverflowButtonDrawable = attributesArray
            .getDrawable(R.styleable.ActivityChooserView_expandActivityOverflowButtonDrawable);

    attributesArray.recycle();

    LayoutInflater inflater = LayoutInflater.from(getContext());
    inflater.inflate(R.layout.abc_activity_chooser_view, this, true);

    mCallbacks = new Callbacks();

    mActivityChooserContent = (LinearLayout) findViewById(R.id.activity_chooser_view_content);
    mActivityChooserContent.setBackgroundDrawable(null);
    findViewById(R.id.default_activity_button).setVisibility(GONE);

    mExpandActivityOverflowButton = (FrameLayout) findViewById(R.id.expand_activities_button);
    mExpandActivityOverflowButton.setOnClickListener(mCallbacks);
    mExpandActivityOverflowButtonImage = (ImageView) mExpandActivityOverflowButton.findViewById(R.id.image);
    mExpandActivityOverflowButtonImage.setImageDrawable(expandActivityOverflowButtonDrawable);

    mAdapter = new ActivityChooserViewAdapter();
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            updateAppearance();
        }
    });

    Resources resources = context.getResources();
    mListPopupMaxWidth = Math.max(resources.getDisplayMetrics().widthPixels / 2,
            resources.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));
}