List of usage examples for android.app Activity getResources
@Override
public Resources getResources()
From source file:jahirfiquitiva.iconshowcase.utilities.utils.ThemeUtils.java
public static void onActivityCreateSetTheme(Activity activity) { final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); int mTheme = sp.getInt("theme", (activity.getResources().getInteger(R.integer.app_theme) - 1)); switch (mTheme) { default:/*from w w w . j a v a2 s . c o m*/ case LIGHT: activity.setTheme(R.style.AppTheme); darkTheme = false; transparent = false; break; case DARK: activity.setTheme(R.style.AppThemeDark); darkTheme = true; transparent = false; break; case CLEAR: activity.setTheme(R.style.AppThemeClear); darkTheme = true; transparent = true; break; case AUTO: Calendar c = Calendar.getInstance(); transparent = false; int timeOfDay = c.get(Calendar.HOUR_OF_DAY); if (timeOfDay >= 7 && timeOfDay < 20) { activity.setTheme(R.style.AppTheme); darkTheme = false; } else { activity.setTheme(R.style.AppThemeDark); darkTheme = true; } break; } }
From source file:Main.java
public static int getSystemUiActionBarHeight(Activity activity) { final TypedValue typedValue = new TypedValue(); if (activity.getTheme().resolveAttribute(android.R.attr.actionBarSize, typedValue, true)) { return TypedValue.complexToDimensionPixelSize(typedValue.data, activity.getResources().getDisplayMetrics()); }/*from www.j a v a 2 s . c o m*/ return -1; }
From source file:jahirfiquitiva.iconshowcase.utilities.ThemeUtils.java
public static void onActivityCreateSetTheme(Activity activity) { final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity); int mTheme = sp.getInt("theme", (activity.getResources().getInteger(R.integer.default_theme) - 1)); switch (mTheme) { default:// w w w .jav a 2 s. c o m case LIGHT: activity.setTheme(R.style.AppTheme); darkTheme = false; transparent = false; break; case DARK: activity.setTheme(R.style.AppThemeDark); darkTheme = true; transparent = false; break; case CLEAR: activity.setTheme(R.style.AppThemeClear); darkTheme = true; transparent = true; break; case AUTO: Calendar c = Calendar.getInstance(); transparent = false; int timeOfDay = c.get(Calendar.HOUR_OF_DAY); if (timeOfDay >= 7 && timeOfDay < 20) { activity.setTheme(R.style.AppTheme); darkTheme = false; } else { activity.setTheme(R.style.AppThemeDark); darkTheme = true; } break; } }
From source file:com.binomed.showtime.android.util.CineShowTimeLayoutUtils.java
/** Set the theme of the activity, according to the configuration. */ public static void onActivityCreateSetTheme(Activity activity, SharedPreferences pref) { String defaultTheme = activity.getResources().getString(R.string.preference_gen_default_theme); String theme = pref.getString(activity.getResources().getString(R.string.preference_gen_key_theme), defaultTheme);/*from www. j a v a 2 s.com*/ if (theme.equals(defaultTheme)) { activity.setTheme(R.style.Theme_Dark_Night); } else { activity.setTheme(R.style.Theme_Shine_the_lite); } }
From source file:org.nuxeo.android.simpleclient.forms.LinearFormManager.java
public static void displayForm(Activity targetActivity, LinearLayout currentLayout, Document doc, JSONArray fieldArray, boolean showHeader) throws JSONException { final int padding = targetActivity.getResources().getDimensionPixelSize(R.dimen.defaultPadding); if (showHeader) { final TextView hTextView = new TextView(targetActivity); String header = " <b><i>State</i></b> : " + doc.getState(); String size = doc.getProperties().getString("common:size"); if (size != null && !"null".equals(size)) { header += " <b><i> Size </i></b> : " + Integer.parseInt(size) / 1024 + "KB"; }/*from www. j a v a 2 s .c o m*/ hTextView.setText(Html.fromHtml(header)); currentLayout.addView(hTextView); String desc = doc.getProperties().getString("dc:description"); if (desc != null && !"null".equals(desc)) { desc = " <b><i>Description</i></b> : " + doc.getProperties().getString("dc:description"); final TextView descTextView = new TextView(targetActivity); descTextView.setText(Html.fromHtml(desc)); currentLayout.addView(descTextView); } } for (int i = 0; i < fieldArray.length(); i++) { JSONObject field = fieldArray.getJSONObject(i); String xpath = field.getString("xpath"); Object value = doc.getProperties().get(xpath); if ("null".equals(value)) { value = null; } if (value != null) { final TextView textView = new TextView(targetActivity); String txt = "<b><i>" + field.getString("label") + "</i></b> : "; if (value instanceof String) { txt += (String) value; } else if (value instanceof Date) { txt += dateFormat.format((Date) value); } else if (value instanceof PropertyList) { PropertyList list = (PropertyList) value; for (int j = 0; j < list.size(); j++) { txt += list.getString(j); txt += " "; } } textView.setText(Html.fromHtml(txt)); textView.setPadding(padding, 0, padding, 0); currentLayout.addView(textView); } } }
From source file:com.crea_si.eviacam.wizard.WizardUtils.java
static void checkEngineAndFinishIfNeeded(final Activity a) { AccessibilityServiceModeEngine engine = MainEngine.getAccessibilityServiceModeEngine(); if (engine == null || !engine.isReady()) { // Engine is not ready anymore final Resources res = a.getResources(); AlertDialog ad = new AlertDialog.Builder(a).create(); ad.setCancelable(false); // This blocks the 'BACK' button ad.setTitle(res.getText(R.string.eva_not_running)); ad.setMessage(res.getText(R.string.eva_not_running_summary)); ad.setButton(DialogInterface.BUTTON_NEUTRAL, res.getText(R.string.close), new DialogInterface.OnClickListener() { @Override//from www .j a v a 2 s . c o m public void onClick(DialogInterface dialog, int which) { finishWizard(a); } }); ad.show(); } }
From source file:Main.java
public static String getResourceString(String recourceName, Activity context) { Class rStringClass = null;//w w w .j av a 2s .c o m try { if (rStringClass == null) { rStringClass = Class.forName( new StringBuilder().append(context.getPackageName()).append(".R$string").toString()); } return context.getResources() .getString(((Integer) rStringClass.getDeclaredField(recourceName).get(null)).intValue()); } catch (Exception e) { Log.e(context.getPackageName(), e.getMessage(), e); context.finish(); } return ""; }
From source file:Main.java
public static void setStatusBarColor(Activity activity, int colorId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Window window = activity.getWindow(); // window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(activity.getResources().getColor(colorId)); }/*from w w w. j ava2 s . c o m*/ }
From source file:org.deviceconnect.android.deviceplugin.pebble.setting.PebbleSettingActivity.java
/** * ? pbw ?????? uri ?.//from w ww.j a v a 2s . c o m * @return uri ?. */ @SuppressLint("WorldReadableFiles") @SuppressWarnings("deprecation") private static Uri getPbwFileName(final Activity activity) { File file = activity.getFileStreamPath("dc_pebble.pbw"); try { fileCopy(activity.getResources().openRawResource(R.raw.dc_pebble), activity.openFileOutput(file.getName(), MODE_WORLD_READABLE)); } catch (IOException e) { e.printStackTrace(); } return Uri.fromFile(file); }
From source file:Main.java
public static Bitmap downSampleBitmap(Uri uri, Activity act, Boolean needRotate) { DisplayMetrics displaymetrics = new DisplayMetrics(); act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); Resources r = act.getResources(); int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, r.getDisplayMetrics()); // 50: magic num int targetWidth = displaymetrics.heightPixels; int targetHeight = displaymetrics.widthPixels - px; Bitmap resizedBitmap = decodeSampledBitmap(uri, targetWidth, targetHeight, act); Bitmap returnBitmap = null;//www.j a v a2 s .c o m ExifInterface exif; try { float degree = 0; exif = new ExifInterface(uri.toString()); int orient = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); if (resizedBitmap != null && needRotate) { degree = getDegree(orient); if (degree != 0) { returnBitmap = createRotatedBitmap(resizedBitmap, degree); } returnBitmap = returnBitmap == null ? resizedBitmap : returnBitmap; } } catch (IOException e) { Log.v(TAG, "not found file at downsample"); e.printStackTrace(); } return returnBitmap; }