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.runbuddy.tomahawk.views.PlaybackPanel.java

public void setupStationContainerAnimation() {
    Resources resources = TomahawkApp.getContext().getResources();
    int resolverIconSize = resources.getDimensionPixelSize(R.dimen.playback_panel_resolver_icon_size);
    int padding = resources.getDimensionPixelSize(R.dimen.padding_small);

    // Setup mStationContainer animation
    Keyframe kfX0 = Keyframe.ofFloat(0f, mStationContainer.getWidth() - resolverIconSize);
    Keyframe kfX1 = Keyframe.ofFloat(0.5f, Math.max(resolverIconSize + padding,
            mStationContainer.getWidth() / 2 - mStationContainerInner.getWidth() / 2));
    Keyframe kfX2 = Keyframe.ofFloat(1f, mStationContainer.getWidth() - resolverIconSize);
    PropertyValuesHolder pvhX = PropertyValuesHolder.ofKeyframe("x", kfX0, kfX1, kfX2);
    ValueAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mStationContainerInner, pvhX)
            .setDuration(20000);/*from   w ww . j  a v a  2 s . com*/
    animator.setInterpolator(new LinearInterpolator());
    animator.setCurrentPlayTime(mLastPlayTime);
    if (mStationContainerAnimation != null) {
        mAnimators.remove(mStationContainerAnimation);
    }
    mStationContainerAnimation = animator;
    mAnimators.add(mStationContainerAnimation);
}

From source file:com.iangclifton.auid.horizontaliconview.HorizontalIconView.java

/**
 * Perform one-time initialization/*from   ww  w  . java2s .co m*/
 * 
 * @param context Context to load Resources and ViewConfiguration data
 */
private void init(Context context) {
    final Resources res = context.getResources();
    mIconSize = res.getDimensionPixelSize(R.dimen.icon_size);
    mIconSpacing = res.getDimensionPixelSize(R.dimen.icon_spacing);

    // Cache ViewConfiguration values
    final ViewConfiguration config = ViewConfiguration.get(context);
    mTouchSlop = config.getScaledTouchSlop();
    mMinimumVelocity = config.getScaledMinimumFlingVelocity();
    mMaximumVelocity = config.getScaledMaximumFlingVelocity();
    mOverflingDistance = config.getScaledOverflingDistance();
    mOverscrollDistance = config.getScaledOverscrollDistance();

    // Verify this View will be drawn
    setWillNotDraw(false);

    // Other setup
    mEdgeEffectLeft = new EdgeEffectCompat(context);
    mEdgeEffectRight = new EdgeEffectCompat(context);
    mScroller = new OverScroller(context);
    setFocusable(true);
}

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

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

    if ((container == null) || (musicVideoId == -1)) {
        // We're not being shown or there's nothing to show
        return null;
    }/*www  . j a  v a2 s .  c  o m*/

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_music_video_details, 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);
        }
    });

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

    // 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.MusicVideoDetailsFragment.java

@TargetApi(21)
@Override/*from   w ww. j  a v  a 2s . c  o  m*/
protected View createView(LayoutInflater inflater, ViewGroup container) {
    Bundle bundle = getArguments();
    musicVideoId = bundle.getInt(BUNDLE_KEY_ID, -1);

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

    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_music_video_details, 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);
        }
    });

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

    mediaTitle.setText(bundle.getString(BUNDLE_KEY_TITLE));
    setMediaUndertitle(bundle.getString(BUNDLE_KEY_ARTIST), bundle.getString(BUNDLE_KEY_ALBUM));
    setMediaYear(bundle.getInt(BUNDLE_KEY_RUNTIME), bundle.getInt(BUNDLE_KEY_YEAR));
    mediaGenres.setText(bundle.getString(BUNDLE_KEY_GENRES));
    mediaDescription.setText(bundle.getString(BUNDLE_KEY_PLOT));

    if (Utils.isLollipopOrLater()) {
        mediaPoster.setTransitionName(bundle.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.bullmobi.message.ui.components.MediaWidget.java

public MediaWidget(@NonNull Callback callback, @NonNull EasyNotificationFragment fragment) {
    super(callback, fragment);
    mMediaController = fragment.getMediaController2();

    Resources res = fragment.getResources();
    mPlayPauseDrawable = new PlayPauseDrawable();
    mPlayPauseDrawable.setSize(res.getDimensionPixelSize(R.dimen.media_btn_actual_size));
    mWarningDrawable = ResUtils.getDrawable(fragment.getActivity(), R.drawable.ic_action_warning_white);
}

From source file:com.achep.acdisplay.ui.components.MediaWidget.java

public MediaWidget(@NonNull Callback callback, @NonNull AcDisplayFragment fragment) {
    super(callback, fragment);
    mMediaController = fragment.getMediaController2();

    Resources res = fragment.getResources();
    mPlayPauseDrawable = new PlayPauseDrawable();
    mPlayPauseDrawable.setSize(res.getDimensionPixelSize(R.dimen.media_btn_actual_size));
    mWarningDrawable = ResUtils.getDrawable(fragment.getActivity(), R.drawable.ic_action_warning_white);
}

From source file:org.solovyev.android.widget.menu.CustomPopupMenuHelper.java

public CustomPopupMenuHelper(Context context, MenuBuilder menu, View anchorView, boolean overflowOnly,
        int popupStyleAttr, int popupStyleRes) {
    mContext = context;//w  ww .j  av  a2  s.  co m
    mInflater = LayoutInflater.from(context);
    mMenu = menu;
    mAdapter = new MenuAdapter(mMenu);
    mOverflowOnly = overflowOnly;
    mPopupStyleAttr = popupStyleAttr;
    mPopupStyleRes = popupStyleRes;

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

    mAnchorView = anchorView;

    // Present the menu using our context, not the menu builder's context.
    menu.addMenuPresenter(this, context);
}

From source file:com.affectiva.affdexme.MetricSelectionFragment.java

void populateGrid() {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    Resources res = getResources();
    int minColumnWidth = res.getDimensionPixelSize(R.dimen.metric_chooser_column_width);

    //calculate number of columns
    int gridWidth = gridLayout.getWidth();
    int numColumns = gridWidth / minColumnWidth; //intentional integer division
    if (numColumns <= 0) {
        Log.e(LOG_TAG, "Desired Column Width too large! Unable to populate Grid");
        return;/*w w  w .jav a2  s .  com*/
    }
    int columnWidth = (int) ((float) gridWidth / (float) numColumns);

    //This integer reference will be used across methods to keep track of how many rows we have created.
    //Each method we pass it into leaves it at a value indicating the next row number that views should be added to.
    IntRef currentRow = new IntRef();

    addHeader("Emotions", currentRow, numColumns, inflater);
    addGridItems(currentRow, numColumns, inflater, res, columnWidth, MetricsManager.Emotions.values());
    addHeader("Expressions", currentRow, numColumns, inflater);
    addGridItems(currentRow, numColumns, inflater, res, columnWidth, MetricsManager.Expressions.values());

    // If you wanted to add Emoji as selectable metrics, you would uncomment the two lines below
    //        addHeader("Emoji", currentRow, numColumns, inflater);
    //        addGridItems(currentRow, numColumns, inflater, res, columnWidth, MetricsManager.Emojis.values());

    gridLayout.setColumnCount(numColumns);
    gridLayout.setRowCount(currentRow.value);
}

From source file:com.jaredrummler.materialspinner.MaterialSpinner.java

private void init(Context context, AttributeSet attrs) {
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialSpinner);
    int defaultColor = getTextColors().getDefaultColor();
    backgroundColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_background_color, Color.WHITE);
    textColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_text_color, defaultColor);
    arrowColor = typedArray.getColor(R.styleable.MaterialSpinner_ms_arrow_tint, textColor);
    hideArrow = typedArray.getBoolean(R.styleable.MaterialSpinner_ms_hide_arrow, false);
    typedArray.recycle();//  w w  w.j ava  2  s . c  om

    setGravity(Gravity.CENTER_VERTICAL | Gravity.START);

    boolean rtl = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        Configuration config = getResources().getConfiguration();
        rtl = config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
        if (rtl) {
            setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
            setTextDirection(View.TEXT_DIRECTION_RTL);
        }
    }

    Resources resources = getResources();
    int left, right, bottom, top;
    left = right = bottom = top = resources.getDimensionPixelSize(R.dimen.ms__padding_top);
    if (rtl) {
        right = resources.getDimensionPixelSize(R.dimen.ms__padding_left);
    } else {
        left = resources.getDimensionPixelSize(R.dimen.ms__padding_left);
    }

    setClickable(true);
    setPadding(left, top, right, bottom);
    setBackgroundResource(R.drawable.ms__selector);

    if (!hideArrow) {
        arrowDrawable = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ms__arrow));
        DrawableCompat.setTint(arrowDrawable, arrowColor);
        if (rtl) {
            setCompoundDrawablesWithIntrinsicBounds(arrowDrawable, null, null, null);
        } else {
            setCompoundDrawablesWithIntrinsicBounds(null, null, arrowDrawable, null);
        }
    }

    listView = new ListView(context);
    listView.setId(getId());
    listView.setDivider(null);
    listView.setItemsCanFocus(true);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position >= selectedIndex && position < adapter.getCount()) {
                position++;
            }
            selectedIndex = position;
            nothingSelected = false;
            Object item = adapter.get(position);
            adapter.notifyItemSelected(position);
            setText(item.toString());
            collapse();
            if (onItemSelectedListener != null) {
                //noinspection unchecked
                onItemSelectedListener.onItemSelected(MaterialSpinner.this, position, id, item);
            }
        }
    });

    popupWindow = new PopupWindow(context);
    popupWindow.setContentView(listView);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setFocusable(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        popupWindow.setElevation(16);
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drawable));
    } else {
        popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(context, R.drawable.ms__drop_down_shadow));
    }

    if (backgroundColor != Color.WHITE) { // default color is white
        setBackgroundColor(backgroundColor);
    }
    if (textColor != defaultColor) {
        setTextColor(textColor);
    }

    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

        @Override
        public void onDismiss() {
            if (nothingSelected && onNothingSelectedListener != null) {
                onNothingSelectedListener.onNothingSelected(MaterialSpinner.this);
            }
            if (!hideArrow) {
                animateArrow(false);
            }
        }
    });
}

From source file:org.runbuddy.tomahawk.views.PlaybackPanel.java

private void setupAnimations() {
    ViewUtils.afterViewGlobalLayout(new ViewUtils.ViewRunnable(this) {
        @Override//from  ww w.  j  ava  2 s.  c om
        public void run() {
            mAnimators.clear();
            // get relevant dimension sizes first
            Resources resources = TomahawkApp.getContext().getResources();
            int panelHeight = resources.getDimensionPixelSize(R.dimen.playback_panel_height);
            int paddingSmall = resources.getDimensionPixelSize(R.dimen.padding_small);
            int paddingLarge = resources.getDimensionPixelSize(R.dimen.padding_large);
            int panelBottom = resources.getDimensionPixelSize(R.dimen.playback_clear_space_bottom);
            int headerClearSpace = resources
                    .getDimensionPixelSize(R.dimen.header_clear_space_nonscrollable_playback);
            boolean isLandscape = resources.getBoolean(R.bool.is_landscape);

            // Setup mTextViewContainer animation
            Keyframe kfY0 = Keyframe.ofFloat(0f,
                    getHeight() - mTextViewContainer.getHeight() / 2 - panelHeight / 2);
            Keyframe kfY1 = Keyframe.ofFloat(0.5f,
                    isLandscape ? getHeight() + paddingLarge - panelBottom - mTextViewContainer.getHeight()
                            : getHeight() + paddingSmall - panelBottom);
            Keyframe kfY2 = Keyframe.ofFloat(1f, headerClearSpace / 2 - mTextViewContainer.getHeight() / 2);
            PropertyValuesHolder pvhY = PropertyValuesHolder.ofKeyframe("y", kfY0, kfY1, kfY2);
            Keyframe kfScale0 = Keyframe.ofFloat(0f, 1f);
            Keyframe kfScale1 = Keyframe.ofFloat(0.5f, isLandscape ? 1.25f : 1.5f);
            Keyframe kfScale2 = Keyframe.ofFloat(1f, isLandscape ? 1.25f : 1.5f);
            PropertyValuesHolder pvhScaleY = PropertyValuesHolder.ofKeyframe("scaleY", kfScale0, kfScale1,
                    kfScale2);
            PropertyValuesHolder pvhScaleX = PropertyValuesHolder.ofKeyframe("scaleX", kfScale0, kfScale1,
                    kfScale2);
            ValueAnimator animator = ObjectAnimator
                    .ofPropertyValuesHolder(mTextViewContainer, pvhY, pvhScaleX, pvhScaleY).setDuration(20000);
            animator.setInterpolator(new LinearInterpolator());
            animator.setCurrentPlayTime(mLastPlayTime);
            mAnimators.add(animator);

            // Setup mPanelContainer animation
            kfY0 = Keyframe.ofFloat(0f, getHeight() - mPanelContainer.getHeight());
            kfY1 = Keyframe.ofFloat(0.5f, getHeight() - mPanelContainer.getHeight());
            kfY2 = Keyframe.ofFloat(1f, headerClearSpace - mPanelContainer.getHeight());
            pvhY = PropertyValuesHolder.ofKeyframe("y", kfY0, kfY1, kfY2);
            animator = ObjectAnimator.ofPropertyValuesHolder(mPanelContainer, pvhY).setDuration(20000);
            animator.setInterpolator(new LinearInterpolator());
            animator.setCurrentPlayTime(mLastPlayTime);
            mAnimators.add(animator);

            // Setup mTextViewContainer backgroundColor alpha animation
            Keyframe kfColor1 = Keyframe.ofInt(0f, 0x0);
            Keyframe kfColor2 = Keyframe.ofInt(0.5f, isLandscape ? 0xFF : 0x0);
            Keyframe kfColor3 = Keyframe.ofInt(1f, 0xFF);
            PropertyValuesHolder pvhColor = PropertyValuesHolder.ofKeyframe("color", kfColor1, kfColor2,
                    kfColor3);
            animator = ValueAnimator.ofPropertyValuesHolder(pvhColor).setDuration(20000);
            animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    mTextViewContainer.findViewById(R.id.textview_container_inner).getBackground()
                            .setAlpha((Integer) animation.getAnimatedValue());
                }
            });
            animator.setInterpolator(new LinearInterpolator());
            animator.setCurrentPlayTime(mLastPlayTime);
            mAnimators.add(animator);

            // Setup mPanelContainer background fade animation
            Keyframe kfBgAlpha0 = Keyframe.ofInt(0f, 0);
            Keyframe kfBgAlpha1 = Keyframe.ofInt(0.5f, 0);
            Keyframe kfBgAlpha2 = Keyframe.ofInt(1f, 255);
            PropertyValuesHolder pvhBgAlpha = PropertyValuesHolder.ofKeyframe("alpha", kfBgAlpha0, kfBgAlpha1,
                    kfBgAlpha2);
            animator = ObjectAnimator.ofPropertyValuesHolder(mPanelContainer.getBackground(), pvhBgAlpha)
                    .setDuration(20000);
            animator.setInterpolator(new LinearInterpolator());
            animator.setCurrentPlayTime(mLastPlayTime);
            mAnimators.add(animator);

            setupStationContainerAnimation();
        }
    });
}