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.android.systemui.statusbar.phone.NavigationBarView.java

public NavigationBarView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;/*from  w w w .j  a  va2  s .c  o  m*/

    mHidden = false;

    mDisplay = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    mBarService = IStatusBarService.Stub.asInterface(ServiceManager.getService(Context.STATUS_BAR_SERVICE));

    final Resources res = mContext.getResources();
    mBarSize = res.getDimensionPixelSize(R.dimen.navigation_bar_size);
    mVertical = false;
    mShowMenu = false;
    mDelegateHelper = new DelegateViewHelper(this);

    mBackIcon = res.getDrawable(R.drawable.ic_sysbar_back);
    mBackLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_land);
    mBackAltIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);
    mBackAltLandIcon = res.getDrawable(R.drawable.ic_sysbar_back_ime);

    mContext.getContentResolver().registerContentObserver(
            Settings.System.getUriFor(Settings.System.NAV_BAR_COLOR), false,
            new ContentObserver(new Handler()) {
                @Override
                public void onChange(boolean selfChange) {
                    updateColor(false);
                }
            });
}

From source file:org.xbmc.kore.ui.sections.remote.NowPlayingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_now_playing, container, false);
    ButterKnife.inject(this, root);

    volumeLevelIndicator.setOnVolumeChangeListener(new VolumeLevelIndicator.OnVolumeChangeListener() {
        @Override/*from   w  w w.ja va2 s  .com*/
        public void onVolumeChanged(int volume) {
            new Application.SetVolume(volume).execute(hostManager.getConnection(), defaultIntActionCallback,
                    callbackHandler);
        }
    });

    mediaProgressIndicator.setOnProgressChangeListener(this);

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

    volumeLevelIndicator.setOnVolumeChangeListener(new VolumeLevelIndicator.OnVolumeChangeListener() {
        @Override
        public void onVolumeChanged(int volume) {
            new Application.SetVolume(volume).execute(hostManager.getConnection(), defaultIntActionCallback,
                    callbackHandler);
        }
    });

    //        // 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.tomahawk.tomahawk_android.fragments.ContentHeaderFragment.java

private void setupButtonAnimation(final View view) {
    if (view != null) {
        View moreButton = view.findViewById(R.id.more_button);
        if (moreButton != null) {
            ViewUtils.afterViewGlobalLayout(new ViewUtils.ViewRunnable(moreButton) {
                @Override//from   www  .  j ava2  s .  c  o m
                public void run() {
                    // get resources first
                    Resources resources = TomahawkApp.getContext().getResources();
                    int buttonHeight = TomahawkApp.getContext().getResources()
                            .getDimensionPixelSize(R.dimen.show_context_menu_icon_height);
                    int largePadding = TomahawkApp.getContext().getResources()
                            .getDimensionPixelSize(R.dimen.padding_large);
                    int smallPadding = resources.getDimensionPixelSize(R.dimen.padding_small);
                    int actionBarHeight = resources
                            .getDimensionPixelSize(R.dimen.abc_action_bar_default_height_material);
                    View pageIndicator = view.findViewById(R.id.page_indicator);
                    int pageIndicatorHeight = 0;
                    if (pageIndicator != null && pageIndicator.getVisibility() == View.VISIBLE) {
                        pageIndicatorHeight = TomahawkApp.getContext().getResources()
                                .getDimensionPixelSize(R.dimen.pager_indicator_height);
                    }

                    // now calculate the animation goal and instantiate the animation
                    int initialY = view.getHeight() - buttonHeight - largePadding - pageIndicatorHeight;
                    ValueAnimator animator = ObjectAnimator
                            .ofFloat(getLayedOutView(), "y", initialY, actionBarHeight + smallPadding)
                            .setDuration(10000);
                    animator.setInterpolator(new LinearInterpolator());
                    addAnimator(ANIM_BUTTON_ID, animator);

                    refreshAnimations();
                }
            });
        }
    }
}

From source file:com.android.mail.utils.NotificationUtils.java

private static ContactIconInfo getContactIcon(final Context context, String accountName,
        final String displayName, final String senderAddress, final Folder folder,
        final ContactFetcher contactFetcher) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
        throw new IllegalStateException("getContactIcon should not be called on the main thread.");
    }//from w  w  w  .  j  a  v a  2s  . com

    final ContactIconInfo contactIconInfo;
    if (TextUtils.isEmpty(senderAddress)) {
        contactIconInfo = new ContactIconInfo();
    } else {
        // Get the ideal size for this icon.
        final Resources res = context.getResources();
        final int idealIconHeight = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
        final int idealIconWidth = res.getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
        final int idealWearableBgWidth = res.getDimensionPixelSize(R.dimen.wearable_background_width);
        final int idealWearableBgHeight = res.getDimensionPixelSize(R.dimen.wearable_background_height);

        if (contactFetcher != null) {
            contactIconInfo = contactFetcher.getContactPhoto(context, accountName, senderAddress,
                    idealIconWidth, idealIconHeight, idealWearableBgWidth, idealWearableBgHeight);
        } else {
            contactIconInfo = getContactInfo(context, senderAddress, idealIconWidth, idealIconHeight,
                    idealWearableBgWidth, idealWearableBgHeight);
        }

        if (contactIconInfo.icon == null) {
            // Make a colorful tile!
            final Dimensions dimensions = new Dimensions(idealIconWidth, idealIconHeight, Dimensions.SCALE_ONE);

            contactIconInfo.icon = new LetterTileProvider(context.getResources()).getLetterTile(dimensions,
                    displayName, senderAddress);
        }

        // Only turn the square photo/letter tile into a circle for L and later
        if (Utils.isRunningLOrLater()) {
            contactIconInfo.icon = BitmapUtil.frameBitmapInCircle(contactIconInfo.icon);
        }
    }

    if (contactIconInfo.icon == null) {
        // Use anonymous icon due to lack of sender
        contactIconInfo.icon = getIcon(context, R.drawable.ic_notification_anonymous_avatar_32dp);
    }

    if (contactIconInfo.wearableBg == null) {
        contactIconInfo.wearableBg = getDefaultWearableBg(context);
    }

    return contactIconInfo;
}

From source file:com.wjjiang.materialdesigns.ui.navigationview.SpaceNavigationView.java

/**
 * Init custom attributes/*from   w w  w  . j a  v a2  s .  co  m*/
 *
 * @param attrs attributes
 */
private void init(AttributeSet attrs) {
    if (attrs != null) {
        Resources resources = getResources();

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SpaceNavigationView);
        spaceItemIconSize = typedArray.getDimensionPixelSize(
                R.styleable.SpaceNavigationView_space_item_icon_size,
                resources.getDimensionPixelSize(R.dimen.space_item_icon_default_size));
        spaceItemIconOnlySize = typedArray.getDimensionPixelSize(
                R.styleable.SpaceNavigationView_space_item_icon_only_size,
                resources.getDimensionPixelSize(R.dimen.space_item_icon_only_size));
        spaceItemTextSize = typedArray.getDimensionPixelSize(
                R.styleable.SpaceNavigationView_space_item_text_size,
                resources.getDimensionPixelSize(R.dimen.space_item_text_default_size));
        spaceItemIconOnlySize = typedArray.getDimensionPixelSize(
                R.styleable.SpaceNavigationView_space_item_icon_only_size,
                resources.getDimensionPixelSize(R.dimen.space_item_icon_only_size));
        spaceBackgroundColor = typedArray.getColor(R.styleable.SpaceNavigationView_space_background_color,
                resources.getColor(R.color.default_color));
        centreButtonColor = typedArray.getColor(R.styleable.SpaceNavigationView_centre_button_color,
                resources.getColor(R.color.centre_button_color));
        activeSpaceItemColor = typedArray.getColor(R.styleable.SpaceNavigationView_active_item_color,
                resources.getColor(R.color.white));
        inActiveSpaceItemColor = typedArray.getColor(R.styleable.SpaceNavigationView_inactive_item_color,
                resources.getColor(R.color.default_inactive_item_color));

        typedArray.recycle();
    }
}

From source file:com.android.inputmethod.keyboard.EmojiPalettesView.java

@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    final Resources res = getContext().getResources();
    // The main keyboard expands to the entire this {@link KeyboardView}.
    final int width = ResourceUtils.getDefaultKeyboardWidth(res) + getPaddingLeft() + getPaddingRight();
    final int height = ResourceUtils.getDefaultKeyboardHeight(res)
            + res.getDimensionPixelSize(R.dimen.suggestions_strip_height) + getPaddingTop()
            + getPaddingBottom();//  w  w  w  .  j  a  v a 2  s .  co m
    setMeasuredDimension(width, height);
}

From source file:com.marlonjones.voidlauncher.allapps.AllAppsGridAdapter.java

public AllAppsGridAdapter(Launcher launcher, AlphabeticalAppsList apps, View.OnClickListener iconClickListener,
        View.OnLongClickListener iconLongClickListener) {
    Resources res = launcher.getResources();
    mLauncher = launcher;//w  ww  .j a  va2  s.  c om
    mApps = apps;
    mEmptySearchMessage = res.getString(R.string.all_apps_loading_message);
    mGridSizer = new GridSpanSizer();
    mGridLayoutMgr = new AppsGridLayoutManager(launcher);
    mGridLayoutMgr.setSpanSizeLookup(mGridSizer);
    mItemDecoration = new GridItemDecoration();
    mLayoutInflater = LayoutInflater.from(launcher);
    mIconClickListener = iconClickListener;
    mIconLongClickListener = iconLongClickListener;
    mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin);
    mSectionHeaderOffset = res.getDimensionPixelSize(R.dimen.all_apps_grid_section_y_offset);
    mIsRtl = Utilities.isRtl(res);

    mSectionTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mSectionTextPaint.setTextSize(res.getDimensionPixelSize(R.dimen.all_apps_grid_section_text_size));
    mSectionTextPaint.setColor(Utilities.getColorAccent(launcher));
}

From source file:com.jihao.imtest.viewpager.PagerSlidingTabStrip.java

private void addTabView(final int position, String title) {
    View tabView = null;// www  . j a  va 2 s.  c o 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 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:org.getlantern.firetweet.activity.support.HomeActivity.java

private void setupSlidingMenu() {
    if (mSlidingMenu == null)
        return;//from w w  w. jav a2  s .co m
    final Resources res = getResources();
    final int marginThreshold = res.getDimensionPixelSize(R.dimen.default_sliding_menu_margin_threshold);
    final boolean relativeBehindWidth = res.getBoolean(R.bool.relative_behind_width);
    mSlidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
    mSlidingMenu.setShadowWidthRes(R.dimen.default_sliding_menu_shadow_width);
    mSlidingMenu.setShadowDrawable(R.drawable.shadow_left);
    mSlidingMenu.setSecondaryShadowDrawable(R.drawable.shadow_right);
    if (relativeBehindWidth) {
        mSlidingMenu.setBehindOffsetRes(R.dimen.drawer_offset_home);
    } else {
        mSlidingMenu.setBehindWidthRes(R.dimen.drawer_width_home);
    }
    mSlidingMenu.setTouchmodeMarginThreshold(marginThreshold);
    mSlidingMenu.setFadeDegree(0.5f);
    mSlidingMenu.setMenu(R.layout.drawer_home_accounts);
    mSlidingMenu.setSecondaryMenu(R.layout.drawer_home_quick_menu);
    mSlidingMenu.setOnOpenedListener(this);
    mSlidingMenu.setOnClosedListener(this);
    mLeftDrawerContainer = (LeftDrawerFrameLayout) mSlidingMenu.getMenu()
            .findViewById(R.id.left_drawer_container);
    mRightDrawerContainer = (RightDrawerFrameLayout) mSlidingMenu.getSecondaryMenu()
            .findViewById(R.id.right_drawer_container);
    final boolean isTransparentBackground = ThemeUtils.isTransparentBackground(this);
    mLeftDrawerContainer.setClipEnabled(isTransparentBackground);
    mLeftDrawerContainer.setScrollScale(mSlidingMenu.getBehindScrollScale());
    mRightDrawerContainer.setClipEnabled(isTransparentBackground);
    mRightDrawerContainer.setScrollScale(mSlidingMenu.getBehindScrollScale());
    mSlidingMenu.setBehindCanvasTransformer(new ListenerCanvasTransformer(this));
    final Window window = getWindow();
    final Drawable windowBackground = ThemeUtils.getWindowBackground(this, getCurrentThemeResourceId());
    ViewAccessor.setBackground(mSlidingMenu.getContent(), windowBackground);
    window.setBackgroundDrawable(new EmptyDrawable(windowBackground));
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_now_playing, container, false);
    ButterKnife.inject(this, root);

    setupVolumeRepeatButton(volumeDownButton,
            new Application.SetVolume(GlobalType.IncrementDecrement.DECREMENT));
    setupVolumeRepeatButton(volumeUpButton, new Application.SetVolume(GlobalType.IncrementDecrement.INCREMENT));

    // 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//w ww .j  a v a 2s .c  o  m
        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;
}