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:Main.java

@TargetApi(14)
public static int getActionBarHeight(Context context) {
    int result = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        TypedValue tv = new TypedValue();
        context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true);
        result = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }//from  w  ww .  ja  va  2s .  c o m
    return result;
}

From source file:Main.java

/**
 * get action bar height//from   w w w.  j av a2s. c o m
 *
 * @param context
 * @return
 */
public static int getActionBarHeight(Context context) {
    int actionBarHeight = 0;
    if (context instanceof Activity && ((Activity) context).getActionBar() != null) {
        actionBarHeight = ((Activity) context).getActionBar().getHeight();
    }

    if (actionBarHeight == 0) {
        final TypedValue tv = new TypedValue();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB && (context.getTheme() != null
                && context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))) {
            actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                    context.getResources().getDisplayMetrics());
        }
    }
    return actionBarHeight;
}

From source file:Main.java

public static int getActionBarSize(Context context) {
    TypedValue tv = new TypedValue();
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        int actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,
                context.getResources().getDisplayMetrics());
        return actionBarHeight;
    }/*  www.j  av  a2s .co  m*/
    return 0;
}

From source file:Main.java

public static int getABHeight(Context context) {

    int actionBarHeight = 0;
    TypedValue tva = new TypedValue();
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tva, true))
        actionBarHeight = TypedValue.complexToDimensionPixelSize(tva.data,
                context.getResources().getDisplayMetrics());
    return actionBarHeight;
}

From source file:Main.java

/**
 * Gets the action bar height in pixels/*from  www .jav a2  s  .  c o m*/
 *
 * @param context
 * @return action bar height in pixels
 */
public static int getActionBarHeight(Context context) {
    TypedValue tv = new TypedValue();
    View view = new View(context);
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        return TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }

    return 0;
}

From source file:com.monmonja.library.utils.ViewUtils.java

public static void makeToast(Context context, int resId) {
    TypedValue tv = new TypedValue();
    int offsetY = 0;
    if (context.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        offsetY = TypedValue.complexToDimensionPixelSize(tv.data, context.getResources().getDisplayMetrics());
    }//  ww  w .j av  a2s .c  o  m

    Toast toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, 0, 0);
    View view = toast.getView();
    view.setBackgroundColor(context.getResources().getColor(R.color.toast_background));
    TextView text = (TextView) view.findViewById(android.R.id.message);
    text.setTextColor(context.getResources().getColor(android.R.color.white));
    toast.show();
}

From source file:com.ww.administrator.demotest.util.ViewUtil.java

public static int getActionBarSize(Context context) {
    if (actionBarSize < 0) {
        TypedValue value = new TypedValue();
        context.getTheme().resolveAttribute(android.R.attr.actionBarSize, value, true);
        actionBarSize = TypedValue.complexToDimensionPixelSize(value.data,
                context.getResources().getDisplayMetrics());
    }/*  w w  w  .j a  v a2  s .  com*/
    return actionBarSize;
}

From source file:com.agenmate.lollipop.util.ViewUtils.java

public static int getActionBarSize(@NonNull Context context) {
    TypedValue value = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.actionBarSize, value, true);
    int actionBarSize = TypedValue.complexToDimensionPixelSize(value.data,
            context.getResources().getDisplayMetrics());
    return actionBarSize;
}

From source file:lib.picturechooser.crop.CropFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.crop, null);

    DisplayMetrics metrics = new DisplayMetrics();
    ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
            .getMetrics(metrics);// w ww.  ja  va  2s.  c  o m

    int availableHeight = metrics.heightPixels;
    int availableWidth = metrics.widthPixels;

    TypedValue tv = new TypedValue();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
            availableHeight -= TypedValue.complexToDimensionPixelSize(tv.data,
                    getResources().getDisplayMetrics());
    }

    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0)
        availableHeight -= getResources().getDimensionPixelSize(resourceId);

    final float[] imgDetails = new float[3];

    ImageView iv = (ImageView) v.findViewById(R.id.image);
    iv.setImageBitmap(ImageLoader.decode(getArguments().getString("imgPath"), availableWidth, availableHeight,
            imgDetails));

    float imageViewWidth = imgDetails[0];
    float imageViewHeight = imgDetails[1];

    if (imageViewWidth > availableWidth || imageViewHeight > availableHeight) {
        while (imageViewWidth > availableWidth || imageViewHeight > availableHeight) {
            imageViewWidth *= 0.99f;
            imageViewHeight *= 0.99f;
        }
    } else {
        while (imageViewWidth < availableWidth && imageViewHeight < availableHeight) {
            imageViewWidth *= 1.01f;
            imageViewHeight *= 1.01f;
        }
    }

    float spareWidth = availableWidth - imageViewWidth;
    float spareHeight = availableHeight - imageViewHeight;

    final CropView cv = (CropView) v.findViewById(R.id.crop);
    final RectF imagePosition = new RectF();
    imagePosition.left = spareWidth / 2;
    imagePosition.top = spareHeight / 2;
    imagePosition.right = imagePosition.left + imageViewWidth;
    imagePosition.bottom = imagePosition.top + imageViewHeight;
    cv.setImagePosition(imagePosition);
    cv.setScale(imgDetails[0] / imagePosition.width());
    cv.setAspect(getArguments().getFloat("aspect", 0));

    v.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            new SaveTask((SelectPictureActivity) getActivity(), cv, imagePosition)
                    .execute(getArguments().getString("imgPath"));
        }
    });
    return v;
}

From source file:de.j4velin.picturechooser.crop.CropFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.crop, null);

    DisplayMetrics metrics = new DisplayMetrics();
    ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
            .getMetrics(metrics);/*  w  w w.  ja  va2s.com*/

    int availableHeight = metrics.heightPixels;
    int availableWidth = metrics.widthPixels;

    TypedValue tv = new TypedValue();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (getActivity().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
            availableHeight -= TypedValue.complexToDimensionPixelSize(tv.data,
                    getResources().getDisplayMetrics());
    }

    int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0)
        availableHeight -= getResources().getDimensionPixelSize(resourceId);

    final float[] imgDetails = new float[3];

    ImageView iv = (ImageView) v.findViewById(R.id.image);
    iv.setImageBitmap(ImageLoader.decode(getArguments().getString("imgPath"), availableWidth, availableHeight,
            imgDetails));

    float imageViewWidth = imgDetails[0];
    float imageViewHeight = imgDetails[1];

    if (imageViewWidth > availableWidth || imageViewHeight > availableHeight) {
        while (imageViewWidth > availableWidth || imageViewHeight > availableHeight) {
            imageViewWidth *= 0.99f;
            imageViewHeight *= 0.99f;
        }
    } else {
        while (imageViewWidth < availableWidth && imageViewHeight < availableHeight) {
            imageViewWidth *= 1.01f;
            imageViewHeight *= 1.01f;
        }
    }

    float spareWidth = availableWidth - imageViewWidth;
    float spareHeight = availableHeight - imageViewHeight;

    final CropView cv = (CropView) v.findViewById(R.id.crop);
    final RectF imagePosition = new RectF();
    imagePosition.left = spareWidth / 2;
    imagePosition.top = spareHeight / 2;
    imagePosition.right = imagePosition.left + imageViewWidth;
    imagePosition.bottom = imagePosition.top + imageViewHeight;
    cv.setImagePosition(imagePosition);
    cv.setScale(imgDetails[0] / imagePosition.width());
    cv.setAspect(getArguments().getFloat("aspect", 0));

    v.findViewById(R.id.save).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            new SaveTask((Main) getActivity(), cv, imagePosition).execute(getArguments().getString("imgPath"));
        }
    });
    return v;
}