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:org.chromium.chrome.browser.ntp.snippets.SnippetArticleViewHolder.java

private void fadeThumbnailIn(SnippetArticle snippet, Bitmap thumbnail) {
    mImageCallback = null;//from w w w  . j  av  a 2  s  .  com
    if (thumbnail == null)
        return; // Nothing to do, we keep the placeholder.

    // We need to crop and scale the downloaded bitmap, as the ImageView we set it on won't be
    // able to do so when using a TransitionDrawable (as opposed to the straight bitmap).
    // That's a limitation of TransitionDrawable, which doesn't handle layers of varying sizes.
    Resources res = mThumbnailView.getResources();
    int targetSize = res.getDimensionPixelSize(R.dimen.snippets_thumbnail_size);
    Bitmap scaledThumbnail = ThumbnailUtils.extractThumbnail(thumbnail, targetSize, targetSize,
            ThumbnailUtils.OPTIONS_RECYCLE_INPUT);

    // Store the bitmap to skip the download task next time we display this snippet.
    snippet.setThumbnailBitmap(scaledThumbnail);

    // Cross-fade between the placeholder and the thumbnail.
    Drawable[] layers = { mThumbnailView.getDrawable(),
            new BitmapDrawable(mThumbnailView.getResources(), scaledThumbnail) };
    TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
    mThumbnailView.setImageDrawable(transitionDrawable);
    transitionDrawable.startTransition(FADE_IN_ANIMATION_TIME_MS);
}

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

@Override
@TargetApi(21)/*from   w ww  .  j a v a2s.c om*/
protected View createView(LayoutInflater inflater, ViewGroup container) {
    Bundle bundle = getArguments();
    tvshowId = bundle.getInt(TVShowDetailsFragment.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(TVShowDetailsFragment.BUNDLE_KEY_TITLE);

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

    if (Utils.isLollipopOrLater()) {
        mediaPoster.setTransitionName(getArguments().getString(TVShowDetailsFragment.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.actionbarsherlock.internal.view.menu.MenuPopupHelper.java

public MenuPopupHelper(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly) {
    mContext = context;/*from ww w .j a  va 2s.c  om*/
    mInflater = LayoutInflater.from(context);
    mMenu = menu;
    mOverflowOnly = overflowOnly;

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

    mAnchorView = anchorView;

    menu.addMenuPresenter(this);
}

From source file:com.squareup.picasso.RequestCreator.java

/**
 * Resizes the image to the specified dimensions
 * @param targetWidthResId target width//from  w w w. j a v a  2 s. c  o m
 * @param targetHeightResId target height
 * @param onlyIfBigger If true the bitmap will be resized only only if bigger than targetWidth or targetHeight. If false the bitmap will be always resized
 * @return
 */
public RequestCreator resizeDimen(int targetWidthResId, int targetHeightResId, boolean onlyIfBigger) {
    Resources resources = picasso.context.getResources();
    int targetWidth = resources.getDimensionPixelSize(targetWidthResId);
    int targetHeight = resources.getDimensionPixelSize(targetHeightResId);
    return resize(targetWidth, targetHeight, onlyIfBigger);
}

From source file:com.silentcircle.silentphone2.list.ShortcutCardsAdapter.java

@TargetApi(Build.VERSION_CODES.M)
@SuppressWarnings("deprecation")
public ShortcutCardsAdapter(Context context, ListsFragment fragment, CallLogAdapter callLogAdapter) {
    final Resources resources = context.getResources();
    mContext = context;/* w  w w . j  a v  a2  s.c  om*/
    mFragment = fragment;
    mCallLogMarginHorizontal = resources.getDimensionPixelSize(R.dimen.recent_call_log_item_margin_horizontal);
    mCallLogMarginTop = resources.getDimensionPixelSize(R.dimen.recent_call_log_item_margin_top);
    mCallLogMarginBottom = resources.getDimensionPixelSize(R.dimen.recent_call_log_item_margin_bottom);
    mCallLogPaddingStart = resources.getDimensionPixelSize(R.dimen.recent_call_log_item_padding_start);
    mCallLogPaddingTop = resources.getDimensionPixelSize(R.dimen.recent_call_log_item_padding_top);
    mCallLogPaddingBottom = resources.getDimensionPixelSize(R.dimen.recent_call_log_item_padding_bottom);
    mShortCardBackgroundColor = ViewUtil.getColorFromAttributeId(context,
            R.attr.call_log_primary_background_color);

    mCallLogAdapter = callLogAdapter;
    mCallLogAdapter.registerDataSetObserver(new CustomDataSetObserver());
    mCallLogQueryHandler = new CallLogQueryHandler(mContext.getContentResolver(), mCallLogQueryHandlerListener);

    mContext.getContentResolver().registerContentObserver(ContactsContract.Contacts.CONTENT_URI, true,
            mChangeObserver);
}

From source file:org.getlantern.firetweet.fragment.support.DirectMessagesFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final View view = getView();
    if (view == null)
        throw new AssertionError();
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    final Context viewContext = view.getContext();
    mMultiSelectManager = getMultiSelectManager();
    mAdapter = new MessageEntriesAdapter(viewContext);
    mAdapter.setListener(this);
    mLayoutManager = new FixedLinearLayoutManager(viewContext);
    mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mSwipeRefreshLayout.setColorSchemeColors(ThemeUtils.getUserAccentColor(viewContext));
    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mAdapter);//from   ww w.ja  v  a2 s  .  com

    final ContentListScrollListener scrollListener = new ContentListScrollListener(this);
    scrollListener.setTouchSlop(ViewConfiguration.get(viewContext).getScaledTouchSlop());
    mRecyclerView.setOnScrollListener(scrollListener);

    final DividerItemDecoration itemDecoration = new DividerItemDecoration(viewContext,
            mLayoutManager.getOrientation());
    final Resources res = viewContext.getResources();
    final int decorPaddingLeft = res.getDimensionPixelSize(R.dimen.element_spacing_normal) * 3
            + res.getDimensionPixelSize(R.dimen.icon_size_status_profile_image);
    itemDecoration.setPadding(decorPaddingLeft, 0, 0, 0);
    itemDecoration.setDecorationEndOffset(1);
    mRecyclerView.addItemDecoration(itemDecoration);
    getLoaderManager().initLoader(0, null, this);
    setListShown(false);
}

From source file:com.syncedsynapse.kore2.ui.TVShowOverviewFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    tvshowId = getArguments().getInt(TVSHOWID, -1);

    if ((container == null) || (tvshowId == -1)) {
        // We're not being shown or there's nothing to show
        return null;
    }/*from w w  w  . j  av a 2 s.  c  o  m*/

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

    bus = EventBus.getDefault();
    hostManager = HostManager.getInstance(getActivity());
    hostInfo = hostManager.getHostInfo();

    swipeRefreshLayout.setOnRefreshListener(this);
    //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);
        }
    });

    // 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:org.xbmc.kore.ui.ArtistOverviewFragment.java

@TargetApi(21)
@Override/*from   www .  j ava 2s. c  o  m*/
protected View createView(LayoutInflater inflater, ViewGroup container) {
    Bundle bundle = getArguments();
    artistId = bundle.getInt(BUNDLE_KEY_ARTISTID, -1);

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

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_artist_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) fabButton).attachToScrollView((ObservableScrollView) mediaPanel);

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

    artistTitle = bundle.getString(BUNDLE_KEY_TITLE);

    mediaTitle.setText(artistTitle);

    mediaUndertitle.setText(bundle.getString(BUNDLE_KEY_GENRE));
    mediaDescription.setText(bundle.getString(BUNDLE_KEY_DESCRIPTION));
    setArt(bundle.getString(BUNDLE_KEY_POSTER), bundle.getString(BUNDLE_KEY_FANART));

    return root;
}

From source file:at.florian_lentsch.expirysync.AddProductActivity.java

/**
 * Adds the image from the form to {@link Article#images} (if there is one)
 * /* w  w w .  j a v  a  2  s.c  o  m*/
 * @param article
 *            the article to add the image to
 * @return list of images (currently only contains 1 or 0
 *         {@link ArticleImage}s)
 */
private ArrayList<ArticleImage> addFormImageToArticle(Article article) {
    final DatabaseManager dbManager = DatabaseManager.getInstance();
    final ArrayList<ArticleImage> imagesList = new ArrayList<ArticleImage>();
    final ImageView productImageView = (ImageView) findViewById(R.id.product_img);
    final BitmapDrawable drawable = ((BitmapDrawable) productImageView.getDrawable());
    final Bitmap productBitmap = drawable != null ? drawable.getBitmap() : null;

    article = dbManager.updateOrAddArticle(article);
    if (this.photoPath != null || productBitmap != null) {
        final Resources res = getResources();
        ArticleImage image = new ArticleImage();
        // TODO: Make hardcoded dimensions configurable:
        image.imageData = (this.photoPath != null) ? getPhotoData(300, 200)
                : getBitmapData(productBitmap, res.getDimensionPixelSize(R.dimen.product_img_width),
                        res.getDimensionPixelSize(R.dimen.product_img_height));
        image.article = article;
        article.images = dbManager.initializeArticleImagesCollection();
        article.images.add(image);
        imagesList.add(image);
    }

    return imagesList;
}

From source file:ru.yandex.subtitles.ui.fragment.phrases.PhrasesFragment.java

@Override
public void onViewCreated(final View view, @Nullable final Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    final Context context = getContext();

    mRecyclerView = findView(R.id.recycler);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(context));

    final GeneralItemAnimator itemAnimator = new RefactoredDefaultItemAnimator();
    itemAnimator.setChangeDuration(0L);/*w  w w.  ja  v a  2  s.  co m*/
    mRecyclerView.setItemAnimator(itemAnimator);

    mRecyclerViewDragDropManager = new RecyclerViewDragDropManager();
    final NinePatchDrawable drawable = (NinePatchDrawable) ContextCompat.getDrawable(getContext(),
            R.drawable.material_shadow_z3);
    mRecyclerViewDragDropManager.setDraggingItemShadowDrawable(drawable);
    mRecyclerViewDragDropManager.setInitiateOnLongPress(true);
    mRecyclerViewDragDropManager.setInitiateOnMove(false);

    mAdapter = new StartingPhrasesAdapter(context);
    mAdapter.setOnItemClickListener(this);
    mAdapter.setOnItemMoveListener(this);

    mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(mAdapter);
    mRecyclerView.setAdapter(mWrappedAdapter);

    mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView);

    final Resources resources = getResources();
    final Bitmap textBitmap = BitmapUtils.createTypefaceBitmap(context,
            TextUtilsExt.toUpperCase(getString(R.string.start_conversation)),
            resources.getColor(R.color.text_primary_color),
            resources.getDimensionPixelSize(R.dimen.text_size_primary));
    final ImageView startConversationButton = findView(R.id.start_conversation);
    startConversationButton.setImageBitmap(textBitmap);
    startConversationButton.setOnClickListener(this);

    getLoaderManager().initLoader(R.id.starting_phrases_loader, null, this);
}