Example usage for android.app Activity getResources

List of usage examples for android.app Activity getResources

Introduction

In this page you can find the example usage for android.app Activity getResources.

Prototype

@Override
    public Resources getResources() 

Source Link

Usage

From source file:Main.java

public static void expand(final View v, Activity activity) {
    v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    Resources r = activity.getResources();
    final float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, r.getDisplayMetrics());
    final int targtetHeight = (int) px;//200;//v.getMeasuredHeight();

    v.getLayoutParams().height = 0;//w ww  .ja  v a2s.  co m
    v.setVisibility(View.VISIBLE);
    Animation a = new Animation() {
        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            v.getLayoutParams().height = interpolatedTime == 1 ? ((int) px)//200//ViewGroup.LayoutParams.WRAP_CONTENT
                    : (int) (targtetHeight * interpolatedTime);
            v.requestLayout();
        }

        @Override
        public boolean willChangeBounds() {
            return true;
        }
    };

    a.setDuration((int) (targtetHeight / v.getContext().getResources().getDisplayMetrics().density));
    v.startAnimation(a);
}

From source file:com.adguard.android.ui.utils.ActivityUtils.java

public static void setPortraitOnly(Activity activity) {
    if (activity.getResources().getBoolean(R.bool.portraitOnly) || getSmallestScreenSize(activity) <= 320) {
        activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }//from  www.j a  va2s  .  c  om
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static void setActionBar(Activity activity, int background) {

    // Action Bar Icon
    activity.getActionBar()//w  w  w . j a  v a2  s . c  om
            .setIcon(new ColorDrawable(activity.getResources().getColor(android.R.color.transparent)));

    // Action Bar Background
    Drawable draw;
    if (android.os.Build.VERSION.SDK_INT >= 21) {
        draw = activity.getResources().getDrawable(background, activity.getTheme());
        activity.getActionBar().setBackgroundDrawable(draw);
    } else {
        draw = activity.getResources().getDrawable(background);
        activity.getActionBar().setBackgroundDrawable(draw);
    }
}

From source file:Main.java

public static int getScreenHeight(Activity activity) {
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    int result = 0;
    int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = activity.getResources().getDimensionPixelSize(resourceId);
    }//from   w  w w.  ja  v a  2s. c  om
    int screenHeight = dm.heightPixels - result;
    return screenHeight;
}

From source file:Main.java

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
public static void setActionBar(Activity activity, int background, String title) {

    // Action Bar Icon
    activity.getActionBar()//from   w ww  .  j  a  va 2s  .  co m
            .setIcon(new ColorDrawable(activity.getResources().getColor(android.R.color.transparent)));

    // Action Bar Title
    activity.getActionBar().setTitle(title);

    // Action Bar Background
    Drawable draw;
    if (android.os.Build.VERSION.SDK_INT >= 21) {
        draw = activity.getResources().getDrawable(background, activity.getTheme());
        activity.getActionBar().setBackgroundDrawable(draw);
    } else {
        draw = activity.getResources().getDrawable(background);
        activity.getActionBar().setBackgroundDrawable(draw);
    }
}

From source file:Main.java

public static void setTaskDescription(final Activity activity, final String label, final int icon,
        final int color) {
    activity.setTaskDescription(new ActivityManager.TaskDescription(label,
            BitmapFactory.decodeResource(activity.getResources(), icon), color));
}

From source file:Main.java

public static int getScreenWidth(Activity ctx) {
    Display display = ctx.getWindowManager().getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);//from   w  w  w.j  av a  2 s. c  om

    float density = ctx.getResources().getDisplayMetrics().density;
    return Math.round(outMetrics.widthPixels);

}

From source file:com.ruesga.rview.misc.AndroidHelper.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void configureTaskDescription(Activity activity) {
    if (isLollipopOrGreater()) {
        Bitmap icon = BitmapFactory.decodeResource(activity.getResources(), R.mipmap.ic_launcher);
        TaskDescription taskDesc = new TaskDescription(null, icon,
                ContextCompat.getColor(activity, R.color.primaryDark));
        activity.setTaskDescription(taskDesc);
    }/*ww w.  ja v a  2 s  .  c o m*/
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static void setImageBackground(View view, int width, int height, int ResId, Activity context) {
    Options opts = new Options();
    opts.outHeight = height;//from  ww w.  j  a  v  a 2 s  .  c o  m
    opts.outWidth = width;
    opts.inJustDecodeBounds = false;
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), ResId, opts);
    view.setBackgroundDrawable(new BitmapDrawable(bitmap));
}

From source file:Main.java

public static int getActionBarHeight(Activity activity) {
    TypedValue tv = new TypedValue();
    if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
        return TypedValue.complexToDimensionPixelSize(tv.data, activity.getResources().getDisplayMetrics());
    }/*from  w ww. j  a va  2s. co m*/
    return 0;
}