Example usage for android.util TypedValue complexToDimensionPixelSize

List of usage examples for android.util TypedValue complexToDimensionPixelSize

Introduction

In this page you can find the example usage for android.util TypedValue complexToDimensionPixelSize.

Prototype

public static int complexToDimensionPixelSize(int data, DisplayMetrics metrics) 

Source Link

Document

Converts a complex data value holding a dimension to its final value as an integer pixel size.

Usage

From source file:com.xperia64.timidityae.SettingsActivity.java

public void setUpNestedScreen(PreferenceScreen preferenceScreen) {
    final Dialog dialog = preferenceScreen.getDialog();

    Toolbar bar;//from w w w.  j  a v a2s .  c  om

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent();
        bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
        bar.setElevation(abElevation);
        root.addView(bar, 0);
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent();
        bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
        root.addView(bar, 0); // insert at top
    } else {
        ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content);
        ListView content = (ListView) root.getChildAt(0);

        root.removeAllViews();

        bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);

        int height;
        TypedValue tv = new TypedValue();
        if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
            height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        } else {
            height = bar.getHeight();
        }

        content.setPadding(0, height, 0, 0);

        root.addView(content);
        root.addView(bar);
    }

    bar.setTitle(preferenceScreen.getTitle());

    bar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
}

From source file:com.example.google.walkway.MainActivity.java

@SuppressLint("InlinedApi")
@Override//from   w  ww . ja v a2  s . c o m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    supportRequestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    setContentView(R.layout.activity_main);

    mSelectedPlaceTypes.addAll(Arrays.asList(NAV_PLACE_TYPES));
    mPlaces = retrievePlaces();

    setupMapIfNeeded();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.app_name,
            R.string.app_name) {

        public void onDrawerClosed(View view) {
            // getActionBar().setTitle(mTitle);

            if (view.equals(mNavListView)) {
                // XXX no need to recreate the markers if the place
                // types haven't changed.
                mMap.clear();
                mPlaces = retrievePlaces();

                if (mPlaceViewPager != null) {
                    mPlaceViewPager.getAdapter().notifyDataSetChanged();
                    mPlaceViewPager.requestLayout();
                }

                addPlacesToMap();
                setSelectedPlace(0);
                showPlacesOnMap(true); // overrides animation from
                                       // setSelectedPlace
                setupPlaceList();
            }
        }

        public void onDrawerOpened(View drawerView) {
            // getActionBar().setTitle(mDrawerTitle);
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);

    setupPlaceViewPager();
    setupPlaceList();
    setupNavList();

    // Set the map padding once the UI views have dimensions.
    ViewTreeObserver observer = mDrawerLayout.getViewTreeObserver();
    observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            removeListener();

            // Pad the top of the map to accommodate the transparent action
            // bar.
            TypedValue tv = new TypedValue();
            int actionbarHeight = 0;
            if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
                actionbarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                        getResources().getDisplayMetrics());
            }

            // Pad the bottom of the map to accommodate the place viewpager.
            int viewPagerHeight = 0;
            if (mPlaceViewPager != null) {
                viewPagerHeight = mPlaceViewPager.getHeight();
            }

            // If the place list isn't in a DrawerLayout, pad the map for it.
            int placeListWidth = 0;
            // Use if listview overlays map.
            //                if (mPlaceListView.getVisibility() == View.VISIBLE) {
            //                    placeListWidth = mPlaceListView.getWidth();
            //                }

            mMap.setPadding(0, actionbarHeight, placeListWidth, viewPagerHeight);

            // Once the map is ready, add the markers to it.
            addPlacesToMap();
            showPlacesOnMap(false);
            setSelectedPlace(0);
        }

        @SuppressWarnings("deprecation")
        @SuppressLint("NewApi")
        private void removeListener() {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                mDrawerLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            } else {
                mDrawerLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
        }
    });
}

From source file:com.aniruddhc.acemusic.player.MainActivity.MainActivity.java

/**
 * Apply KitKat specific translucency./*from   ww w  .j  a va 2 s .c om*/
 */
private void applyKitKatTranslucency() {

    //KitKat translucent navigation/status bar.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

        //Set the window background.
        getWindow().setBackgroundDrawable(UIElementsHelper.getGeneralActionBarBackground(mContext));

        int topPadding = Common.getStatusBarHeight(mContext);
        if (mDrawerLayout != null) {
            mDrawerLayout.setPadding(0, topPadding, 0, 0);
            mNavDrawerLayout.setPadding(0, topPadding, 0, 0);
            mCurrentQueueDrawerLayout.setPadding(0, topPadding, 0, 0);
        }

        //Calculate ActionBar and navigation bar height.
        TypedValue tv = new TypedValue();
        int actionBarHeight = 0;
        if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                    getResources().getDisplayMetrics());
        }

        if (mDrawerParentLayout != null) {
            mDrawerParentLayout.setPadding(0, actionBarHeight, 0, 0);
            mDrawerParentLayout.setClipToPadding(false);
        }

    }

}

From source file:ca.mymenuapp.ui.activities.RestaurantActivity.java

/**
 * Get the height of the action bar./*  ww  w .j  a  va2  s  .  c om*/
 */
public int getActionBarHeight() {
    if (actionBarHeight != 0) {
        return actionBarHeight;
    }
    getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true);
    actionBarHeight = TypedValue.complexToDimensionPixelSize(typedValue.data,
            getResources().getDisplayMetrics());
    return actionBarHeight;
}

From source file:com.antew.redditinpictures.library.ui.ImageViewerActivity.java

/**
 * Enable some additional newer visibility and ActionBar features to create a more
 * immersive photo viewing experience./*  w w  w  .ja  va  2s.c  o m*/
 * <p/>
 * Initialize the mActionBarHeight variable.
 */
private void initializeActionBar() {
    final ActionBar actionBar = getActionBar();

    // Hide title text and set home as up
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(R.string.reddit_in_pictures);
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Calculate ActionBar height
    TypedValue tv = new TypedValue();
    if (getTheme() != null && getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        mActionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }
}

From source file:com.xengar.android.stocktracker.ui.SettingsActivity.java

/**
 * Set up the {@link android.support.v7.widget.Toolbar}, if the API is available.
 *///w  w w. j  a v a 2  s. co m
private void setupToolBar() {
    Toolbar toolbar;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        ViewGroup root = (ViewGroup) findViewById(android.R.id.list).getParent().getParent().getParent();
        toolbar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.view_toolbar, root, false);
        root.addView(toolbar, 0);
    } else {
        ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
        ListView content = (ListView) root.getChildAt(0);
        root.removeAllViews();
        toolbar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.view_toolbar, root, false);
        int height;
        TypedValue tv = new TypedValue();
        if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
            height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        } else {
            height = toolbar.getHeight();
        }
        content.setPadding(0, height, 0, 0);
        root.addView(content);
        root.addView(toolbar);
    }
    toolbar.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}

From source file:drawnzer.anurag.kollosal.KollosalPlayer.java

/**
 * //  ww  w  . j  a  va 2  s  .  c om
 * @return height of status bar along with height of action bar....
 */
private int getStatusBarHeight() {
    int res = 0;
    int resId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resId > 0)
        res = getResources().getDimensionPixelSize(resId);
    TypedValue val = new TypedValue();
    getTheme().resolveAttribute(android.R.attr.actionBarSize, val, true);
    int action_size = TypedValue.complexToDimensionPixelSize(val.data, getResources().getDisplayMetrics());
    res += action_size;
    return res;
}

From source file:com.sbgapps.scoreit.ui.ScoreItActivity.java

private void initDrawer() {
    mDrawerList.setClipToPadding(false);
    mDrawerList.setLayoutManager(new LinearLayoutManager(this));
    mDrawerList.setAdapter(new NavigationDrawerAdapter(this));
    mDrawerList.setHasFixedSize(true);/*from   w w  w .j av a  2 s  .c o m*/

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.navigation_drawer_open,
            R.string.navigation_drawer_close) {
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            if (null != mSnackBar)
                mSnackBar.clear();
            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    DrawerLayout.LayoutParams dlp = (DrawerLayout.LayoutParams) mNavigationDrawer.getLayoutParams();

    TypedValue tv = new TypedValue();
    int actionBarHeight;
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        int maxWidth = getResources().getDimensionPixelSize(R.dimen.navigation_drawer_max_width);
        Display display = getWindowManager().getDefaultDisplay();
        int width;
        Point size = new Point();
        display.getSize(size);
        width = size.x - actionBarHeight;
        dlp.width = Math.min(width, maxWidth);
    } else {
        dlp.width = getResources().getDimensionPixelSize(R.dimen.navigation_drawer_min_width);
    }
    mNavigationDrawer.setLayoutParams(dlp);

    View cover = findViewById(R.id.drawer_cover);
    LinearLayout.LayoutParams llp = (LinearLayout.LayoutParams) cover.getLayoutParams();
    llp.height = dlp.width * 9 / 16;
    cover.setLayoutParams(llp);
}

From source file:com.sabaibrowser.UI.java

public UI(Activity browser, UiController controller) {
    mActivity = browser;//from ww w.ja  v  a 2 s . c  o m
    mUiController = controller;
    mTabControl = controller.getTabControl();
    Resources res = mActivity.getResources();
    mInputManager = (InputMethodManager) browser.getSystemService(Activity.INPUT_METHOD_SERVICE);
    FrameLayout frameLayout = (FrameLayout) mActivity.getWindow().getDecorView()
            .findViewById(android.R.id.content);
    LayoutInflater.from(mActivity).inflate(R.layout.custom_screen, frameLayout);
    mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(R.id.fixed_titlebar_container);
    mContentView = (FrameLayout) frameLayout.findViewById(R.id.main_content);
    mCustomViewContainer = (FrameLayout) frameLayout.findViewById(R.id.fullscreen_custom_content);
    mBlockedElementsContainer = (FrameLayout) frameLayout.findViewById(R.id.blocked_dialog_container);
    mBubbleMenu = (BubbleMenu) frameLayout.findViewById(R.id.bubble_menu);
    setImmersiveFullscreen(false);
    mTitleBar = new TitleBar(mActivity, mUiController, this, mContentView);
    mTitleBar.setProgress(100);
    mNavigationBar = mTitleBar.getNavigationBar();
    mUrlBarAutoShowManager = new UrlBarAutoShowManager(this);
    mSwipeContainer = (SwipeRefreshLayout) frameLayout.findViewById(R.id.swipe_container);
    mSwipeContainer.setColorSchemeColors(browser.getResources().getColor(R.color.primary));
    mSwipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            mUiController.getCurrentTopWebView().reload();
            mSwipeContainer.setRefreshing(false);
        }
    });
    mSwipeContainer.getViewTreeObserver()
            .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
                @Override
                public void onScrollChanged() {
                    if (getWebView() == null)
                        return;
                    int scrollY = getWebView().getScrollY();

                    // workaround for swipetorefresh not "stealing" the scrolling
                    if (scrollY == 0) {
                        mSwipeContainer.setEnabled(true);
                    } else {
                        mSwipeContainer.setEnabled(false);
                    }

                    if (mLastWebViewScrollY < scrollY && mLastWebViewScrollY != 0 && !mTitleBar.isShrank()) {
                        mTitleBar.shrink();
                    } else if (mLastWebViewScrollY > scrollY && scrollY != 0 && mTitleBar.isShrank()) {
                        mTitleBar.unShrink();
                    }
                    mLastWebViewScrollY = scrollY;
                }
            });

    mNavigationBar = mTitleBar.getNavigationBar();
    mNavigationBar.setFabMenu(mBubbleMenu);
    initBubbleMenu();
    TypedValue heightValue = new TypedValue();
    browser.getTheme().resolveAttribute(android.R.attr.actionBarSize, heightValue, true);
    mActionBarHeight = TypedValue.complexToDimensionPixelSize(heightValue.data,
            browser.getResources().getDisplayMetrics());

    MainThreadBus.get().register(this);
}

From source file:org.jorge.cmp.ui.fragment.FeedListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHasOptionsMenu(Boolean.TRUE);
    final View ret = inflater.inflate(R.layout.fragment_feed_article_list, container, Boolean.FALSE);
    mNewsView = (RecyclerView) ret.findViewById(R.id.feed_article_list_view);

    mRefreshLayout = (ChainableSwipeRefreshLayout) ret.findViewById(R.id.refreshable_layout);
    mRefreshLayout.setColorSchemeResources(R.color.material_orange_500, R.color.material_blue_500);
    TypedValue tv = new TypedValue();
    int actionBarHeight = -1;
    if (mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, Boolean.TRUE)) {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }//from  www.  j a  v a2 s.  c  o m
    if (actionBarHeight == -1)
        throw new IllegalStateException("Couldn't get the ActionBar height attribute");
    final Integer progressBarStartMargin = mContext.getResources()
            .getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_start_margin),
            progressBarEndMargin = mContext.getResources()
                    .getDimensionPixelSize(R.dimen.swipe_refresh_progress_bar_end_margin);
    mRefreshLayout.setProgressViewOffset(Boolean.FALSE, actionBarHeight + progressBarStartMargin,
            actionBarHeight + progressBarEndMargin);
    mRefreshLayout.setOnRefreshListener(mOnRefreshListener);
    mRefreshLayout.setRecyclerView(mNewsView);

    mActionBar = mActivity.getSupportActionBar();
    mActionBar.setDisplayHomeAsUpEnabled(Boolean.FALSE);
    mActionBar.setBackgroundDrawable(mActionBarBackgroundDrawable);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mOriginalElevation = mActionBar.getElevation();
        mActionBar.setElevation(0); //So that the shadow of the ActionBar doesn't show over
        // the title
    }

    mParallaxScrollView = (StickyParallaxNotifyingScrollView) ret.findViewById(R.id.scroll_view);
    mIsDualPane = mParallaxScrollView != null;
    mHeaderView = ret.findViewById(R.id.image);
    mArticleTitleView = (TextView) ret.findViewById(R.id.title);
    mArticlePreviewView = (TextView) ret.findViewById(android.R.id.text1);
    mNewsView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    mEmptyView = ret.findViewById(android.R.id.empty);
    mFeedAdapter = new FeedAdapter(mContext, this, mDefaultImageId, TAG, mTableName, ret);
    if (mIsDualPane) {
        reCalculateDualPaneDimensions();
    }

    return ret;
}