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 int getStatusBarHeight(Activity context) {
    int result = 0;
    int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        result = context.getResources().getDimensionPixelSize(resourceId);
    }/* w  ww . j  a  v a 2s .c o  m*/
    return result;
}

From source file:Main.java

public static int getPixels(Activity v, double dipValue) {
    return getPixels(v.getResources(), dipValue);
}

From source file:Main.java

private static String createFromResource(final Activity activity, final int id) {
    final Resources resources = activity.getResources();
    return resources.getString(id);
}

From source file:Main.java

public static void endAppFailure(Activity activity, int id) {
    Toast.makeText(activity, activity.getResources().getString(id), Toast.LENGTH_LONG).show();
    activity.finish();// ww w  .  j  a va 2  s.  com
}

From source file:Main.java

public static float[] getScreen_dpi(Activity context) {
    float[] array = new float[2];
    array[0] = context.getResources().getDisplayMetrics().xdpi;
    array[1] = context.getResources().getDisplayMetrics().ydpi;
    return array;
}

From source file:Main.java

public static String getText(Activity showWebActivity, int loadingTrans) {
    Resources resources = showWebActivity.getResources();
    return resources.getString(loadingTrans);
}

From source file:Main.java

/**
 * Untested, taken from stack-overflow.//w ww  .  ja  va  2 s .c om
 *
 * @param activity
 */
public static void disableScreenOrientationChange(Activity activity) {
    final int orientation = activity.getResources().getConfiguration().orientation;
    final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();

    if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
        if (orientation == Configuration.ORIENTATION_PORTRAIT) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        }
    } else if (rotation == Surface.ROTATION_180 || rotation == Surface.ROTATION_270) {
        if (orientation == Configuration.ORIENTATION_PORTRAIT) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
        } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
        }
    }
}

From source file:Main.java

public static View findActionBarContainer(Activity activity) {
    if (Build.VERSION.SDK_INT > 11) {
        int id = activity.getResources().getIdentifier("action_bar_container", "id", "android");
        return activity.findViewById(id);
    } else {//w w w. j  a v  a  2 s.co  m
        return null;
    }
}

From source file:Main.java

@SuppressLint("NewApi")
public static void lockScreenOrientation(Activity activity) {
    switch (activity.getResources().getConfiguration().orientation) {
    case Configuration.ORIENTATION_PORTRAIT:
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        } else {//from  w  ww.j a v  a  2  s.c o m
            int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_180) {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
            } else {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            }
        }
        break;

    case Configuration.ORIENTATION_LANDSCAPE:
        if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.FROYO) {
            activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
            if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90) {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
            } else {
                activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
            }
        }
        break;
    }
}

From source file:Main.java

public static void rotateOrientation(Activity activity) {
    int currentOrientation = activity.getResources().getConfiguration().orientation;

    switch (currentOrientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        rotateToPortrait(activity);/*from w w w.  j  a  va2s .co  m*/
        break;
    case Configuration.ORIENTATION_PORTRAIT:
        rotateToLandscape(activity);
        break;
    default:
        rotateToLandscape(activity);
    }
}