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.af.synapse.MainActivity.java

private void setPaddingDimensions() {
    int resourceId;

    topPadding = 0;/*from  w  w w.  ja v a 2s.c  om*/
    resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0)
        topPadding += getResources().getDimensionPixelSize(resourceId);

    TypedValue tv = new TypedValue();
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
        topPadding += TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());

    View v;

    v = findViewById(R.id.activity_loading);
    if (v != null)
        v.setPadding(0, topPadding, 0, 0);

    v = findViewById(R.id.activity_main);
    if (v != null)
        v.setPadding(0, topPadding, 0, 0);

    if (Utils.appStarted && Utils.hasSoftKeys(getWindowManager())) {
        bottomPadding = 0;

        resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
        if (resourceId > 0)
            bottomPadding += getResources().getDimensionPixelSize(resourceId);

        if (bottomPadding == 0)
            return;

        for (TabSectionFragment f : fragments) {
            if (f != null && f.fragmentView != null)
                f.fragmentView.findViewById(R.id.section_container_linear_layout).setPadding(0, 0, 0,
                        bottomPadding);
        }
    }
}

From source file:info.papdt.blacklight.support.Utility.java

public static int getActionBarHeight(Context context) {
    TypedValue v = new TypedValue();

    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, v, true)) {
        return TypedValue.complexToDimensionPixelSize(v.data, context.getResources().getDisplayMetrics());
    } else {//from   w ww . ja v  a2  s .c o  m
        return 0;
    }
}

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

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    populatePostData(mPostInformationWrapper);

    if (savedInstanceState != null) {
        loadSavedInstanceState(savedInstanceState);
    }/*from   w  w  w.  j a  v  a2 s .  c o  m*/

    final Activity act = getActivity();

    LocalBroadcastManager.getInstance(act).registerReceiver(mScoreUpdateReceiver,
            new IntentFilter(Constants.Broadcast.BROADCAST_UPDATE_SCORE));
    LocalBroadcastManager.getInstance(act).registerReceiver(mToggleFullscreenIntent,
            new IntentFilter(Constants.Broadcast.BROADCAST_TOGGLE_FULLSCREEN));

    // Set up on our tap listener for the PhotoView which we use to toggle between fullscreen
    // and windowed mode
    ((PhotoView) mImageView).setOnPhotoTapListener(getOnPhotoTapListener(act));

    MOVE_THRESHOLD = 20 * getResources().getDisplayMetrics().density;

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

    try {
        mSystemUiStateProvider = (SystemUiStateProvider) getActivity();
    } catch (ClassCastException e) {
        Ln.e(e, "The activity must implement the SystemUiStateProvider interface");
    }
}

From source file:ly.apps.android.rest.client.example.activities.MainActivity.java

private void checkImmersiveMode() {
    FrameLayout.LayoutParams params;//from  w  w w.  j a  va 2  s.com
    TypedValue typedValue;
    int actionBarHeight;
    Resources.Theme theme;

    typedValue = new TypedValue();
    theme = getTheme();
    params = (FrameLayout.LayoutParams) linearLayoutContent.getLayoutParams();

    if (theme != null && params != null) {
        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
                && theme.resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(typedValue.data,
                    getResources().getDisplayMetrics());
            params.setMargins(0, actionBarHeight + getStatusBarHeight(), 0, getNavigationBarHeight());

        }
    }

}

From source file:com.shopify.buy.ui.ProductDetailsFragmentView.java

/**
 * Get the Action Bar height.//from  w w  w .  j a  v a  2  s  .c o m
 * @return the action bar height in pixels.
 */
private int getActionBarHeightPixels() {
    TypedValue tv = new TypedValue();
    if (getContext().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        return TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }
    return 0;
}

From source file:com.alusorstroke.jjvm.MainActivity.java

private int getDrawerWidth() {
    // Navigation Drawer layout width
    int width = getResources().getDisplayMetrics().widthPixels;

    TypedValue tv = new TypedValue();
    int actionBarHeight;
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    } else {/*from   ww  w.  ja v  a  2 s  .  c o m*/
        actionBarHeight = 0;
    }

    int possibleMinDrawerWidth = width - actionBarHeight;

    int maxDrawerWidth = getResources().getDimensionPixelSize(R.dimen.drawer_width);

    return Math.min(possibleMinDrawerWidth, maxDrawerWidth);
}

From source file:com.nextgis.mobile.MapFragment.java

public void showInfoPane(boolean isShow) {

    if (isShow) {
        mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mChangeLocationListener);
        mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
                mChangeLocationListener);
        mLocationManager.addGpsStatusListener(mGpsStatusListener);

        final RelativeLayout.LayoutParams RightParams = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        RightParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

        int nHeight = 0;

        if (mContext.getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE) {

            TypedValue typeValue = new TypedValue();

            mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, typeValue, true);
            nHeight = TypedValue.complexToDimensionPixelSize(typeValue.data,
                    mContext.getResources().getDisplayMetrics());

            //getTheme().resolveAttribute(android.R.attr.actionBarSize, typeValue, true);
            //nHeight = TypedValue.complexToDimensionPixelSize(
            //        typeValue.data,getResources().getDisplayMetrics());
        }/*  www . ja va 2  s . c  o m*/

        RightParams.setMargins(0, 0, 0, nHeight);
        mMapRelativeLayout.addView(mInfoPane, RightParams);

    } else {
        mLocationManager.removeUpdates(mChangeLocationListener);
        mLocationManager.removeGpsStatusListener(mGpsStatusListener);
        mMapRelativeLayout.removeView(mInfoPane);
    }

    mIsInfoPaneShow = isShow;
}

From source file:a.dev.mobile.thread.MainActivity.java

public int calculateDrawerWidth() {
    // Calculate ActionBar height
    TypedValue tv = new TypedValue();
    int actionBarHeight = 0;
    if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
    }/*from w  ww  .j  av  a  2s.c o m*/
    Display display = getWindowManager().getDefaultDisplay();
    int width;

    if (android.os.Build.VERSION.SDK_INT >= 13) {
        Point size = new Point();
        display.getSize(size);
        width = size.x;

    } else {
        width = display.getWidth(); // deprecated

    }
    return width - actionBarHeight;
}

From source file:com.github.shareme.gwsmaterialdrawer.library.DrawerView.java

private void updateDrawerWidth() {
    Log.d(TAG, "updateDrawerWidth()");

    int viewportWidth = getContext().getResources().getDisplayMetrics().widthPixels;
    int viewportHeight = getContext().getResources().getDisplayMetrics().heightPixels;

    //Minus the width of the vertical nav bar
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        int navigationBarWidthResId = getResources().getIdentifier("navigation_bar_width", "dimen", "android");
        if (navigationBarWidthResId > 0) {
            viewportWidth -= getResources().getDimensionPixelSize(navigationBarWidthResId);
        }//  ww  w. jav a2s  . c om
    }

    int viewportMin = Math.min(viewportWidth, viewportHeight);

    //App bar size
    TypedValue typedValue = new TypedValue();
    getContext().getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true);
    int actionBarSize = TypedValue.complexToDimensionPixelSize(typedValue.data,
            getResources().getDisplayMetrics());

    int width = viewportMin - actionBarSize;

    getLayoutParams().width = Math.min(width, drawerMaxWidth);

    updateProfileSpacing();
}

From source file:trendoidtechnologies.com.navigationdrawerlibrary.DrawerView.java

private void updateDrawerWidth() {
    if (loggingEnabled)
        Log.d(TAG, "updateDrawerWidth()");

    int viewportWidth = getContext().getResources().getDisplayMetrics().widthPixels;
    int viewportHeight = getContext().getResources().getDisplayMetrics().heightPixels;

    //Minus the width of the vertical nav bar
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
        int navigationBarWidthResId = getResources().getIdentifier("navigation_bar_width", "dimen", "android");
        if (navigationBarWidthResId > 0) {
            viewportWidth -= getResources().getDimensionPixelSize(navigationBarWidthResId);
        }//from  ww  w .ja  v  a2 s .  com
    }

    int viewportMin = Math.min(viewportWidth, viewportHeight);

    //App bar size
    TypedValue typedValue = new TypedValue();
    getContext().getTheme().resolveAttribute(R.attr.actionBarSize, typedValue, true);
    int actionBarSize = TypedValue.complexToDimensionPixelSize(typedValue.data,
            getResources().getDisplayMetrics());

    int width = viewportMin - actionBarSize;

    getLayoutParams().width = Math.min(width, drawerMaxWidth);

    updateProfileSpacing();
}