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 getActionBarSize(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   ww  w  .j av a2s.  c o  m*/

    return 0;

}

From source file:Main.java

public static String getResourceString(String paramString, Activity paramActivity) {
    Class localClass = null;/*from  www . j a  v  a  2  s. co m*/
    if (0 == 0)
        ;
    try {
        localClass = Class.forName(paramActivity.getPackageName() + ".R$string");
        String str = paramActivity.getResources()
                .getString(((Integer) localClass.getDeclaredField(paramString).get(null)).intValue());
        return str;
    } catch (Exception localException) {
        Log.e(paramActivity.getPackageName(), localException.getMessage(), localException);
        paramActivity.finish();
    }
    return "";
}

From source file:com.google.android.apps.forscience.whistlepunk.metadata.TriggerHelper.java

public static String buildDescription(SensorTrigger trigger, Activity activity) {
    Resources res = activity.getResources();
    int actionType = trigger.getActionType();
    String action = "";
    if (actionType == TriggerInformation.TRIGGER_ACTION_START_RECORDING) {
        action = res.getString(R.string.trigger_type_start_recording);
    } else if (actionType == TriggerInformation.TRIGGER_ACTION_STOP_RECORDING) {
        action = res.getString(R.string.trigger_type_stop_recording);
    } else if (actionType == TriggerInformation.TRIGGER_ACTION_NOTE) {
        action = res.getString(R.string.trigger_type_note);
    } else if (actionType == TriggerInformation.TRIGGER_ACTION_ALERT) {
        action = res.getString(R.string.trigger_type_alert);
    }/*  w w  w  .j  a  v  a2  s.  com*/
    String units = AppSingleton.getInstance(activity).getSensorAppearanceProvider()
            .getAppearance(trigger.getSensorId()).getUnits(activity);
    Double value = trigger.getValueToTrigger();
    String result = "";
    int when = trigger.getTriggerWhen();
    if (when == TriggerInformation.TRIGGER_WHEN_AT) {
        result = res.getString(R.string.trigger_when_at_description, action, value, units);
    } else if (when == TriggerInformation.TRIGGER_WHEN_RISES_ABOVE) {
        result = res.getString(R.string.trigger_when_rises_above_description, action, value, units);
    } else if (when == TriggerInformation.TRIGGER_WHEN_DROPS_BELOW) {
        result = res.getString(R.string.trigger_when_drops_below_description, action, value, units);
    } else if (when == TriggerInformation.TRIGGER_WHEN_ABOVE) {
        result = res.getString(R.string.trigger_when_above_description, action, value, units);
    } else if (when == TriggerInformation.TRIGGER_WHEN_BELOW) {
        result = res.getString(R.string.trigger_when_above_description, action, value, units);
    }
    return result;
}

From source file:Main.java

public static View getActionBarView(Activity activity) {
    Window window = activity.getWindow();
    View v = window.getDecorView();
    //      int resId = activity.getResources().getIdentifier("action_bar_container", "id", "android");
    int resId = activity.getResources().getIdentifier("action_bar_container", "id", activity.getPackageName());
    return v.findViewById(resId);
}

From source file:Main.java

public static int getSurfaceOrientation(Activity activity) {

    // Sanity check:
    if (activity == null) {
        return -1; // invalid value
    }//w  w  w .java 2 s  .com

    Configuration config = activity.getResources().getConfiguration();
    Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();

    int displayRotation;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        displayRotation = display.getRotation(); // only available from Froyo
    } else {
        displayRotation = display.getOrientation();
    }

    int activityOrientation = SCREEN_ORIENTATION_UNKNOWN;

    switch (config.orientation) {
    case Configuration.ORIENTATION_PORTRAIT:
    case Configuration.ORIENTATION_SQUARE:
        activityOrientation = ((displayRotation == Surface.ROTATION_0
                || displayRotation == Surface.ROTATION_270) ? SCREEN_ORIENTATION_PORTRAIT
                        : SCREEN_ORIENTATION_PORTRAITUPSIDEDOWN);
        break;

    case Configuration.ORIENTATION_LANDSCAPE:
        activityOrientation = ((displayRotation == Surface.ROTATION_0 || displayRotation == Surface.ROTATION_90)
                ? SCREEN_ORIENTATION_LANDSCAPELEFT
                : SCREEN_ORIENTATION_LANDSCAPERIGHT);
        break;

    case Configuration.ORIENTATION_UNDEFINED:
    default:
        break;
    }

    return activityOrientation;
}

From source file:Main.java

public static void lockOrientation(Activity activity) {
    Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int rotation = display.getRotation();
    int tempOrientation = activity.getResources().getConfiguration().orientation;
    int orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
    switch (tempOrientation) {
    case Configuration.ORIENTATION_LANDSCAPE:
        if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_90)
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        else/*from   w  ww  .  j a v  a  2  s. c o m*/
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
        break;
    case Configuration.ORIENTATION_PORTRAIT:
        if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_270)
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        else
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
    }

    activity.setRequestedOrientation(orientation);
}

From source file:com.example.froyoandwams.FroyoSupport.java

private static SSLSocketFactory createAdditionalCertsSSLSocketFactory() {
    try {//w ww .  j  a v  a 2s.  c  om
        final KeyStore ks = KeyStore.getInstance("BKS");

        Activity mainActivity = MainActivity.getInstance();
        final InputStream in = mainActivity.getResources().openRawResource(R.raw.mobileservicestore);
        try {
            ks.load(in, "mobileservices".toCharArray());
        } finally {
            in.close();
        }

        return new AdditionalKeyStoresSSLSocketFactory(ks);

    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:net.tentrup.einsatzserver.InfoActivity.java

private static String readAboutText(Activity activity) {
    BufferedReader reader = null;
    try {/*from w  ww. j  av  a2 s.c  om*/
        InputStream stream = activity.getResources().openRawResource(R.raw.about);
        reader = new BufferedReader(new InputStreamReader(stream));
        String line;
        StringBuilder buffer = new StringBuilder();
        while ((line = reader.readLine()) != null) {
            buffer.append(line).append(System.getProperty("line.separator"));
        }
        return buffer.toString();
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException exc) {
                // Ignore
            }
        }
    }
}

From source file:codepath.watsiapp.utils.Util.java

public static float getPixels(Activity activity, float dp) {
    Resources r = activity.getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics());
    return px;/*from  w w  w. ja v a  2 s .  c  o  m*/
}

From source file:codepath.watsiapp.utils.Util.java

public static float getPixelsFont(Activity activity, float sp) {
    Resources r = activity.getResources();
    float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, r.getDisplayMetrics());
    return px;// w w  w  . ja v  a 2 s. co m
}