List of usage examples for android.app Activity getResources
@Override
public Resources getResources()
From source file:com.example.android.unsplash.ui.pager.DetailViewPagerAdapter.java
public DetailViewPagerAdapter(@NonNull Activity activity, @NonNull List<Photo> photos, @NonNull DetailSharedElementEnterCallback callback) { layoutInflater = LayoutInflater.from(activity); allPhotos = photos;/*from w ww .j a v a 2s . c o m*/ photoWidth = activity.getResources().getDisplayMetrics().widthPixels; host = activity; sharedElementCallback = callback; authorTransitionFormat = activity.getResources().getString(R.string.transition_author); photoTransitionFormat = activity.getResources().getString(R.string.transition_photo); }
From source file:com.cyanogenmod.eleven.adapters.ArtistDetailAlbumAdapter.java
public ArtistDetailAlbumAdapter(final Activity activity) { mActivity = activity;/* ww w .j a v a 2 s . c om*/ mImageFetcher = ApolloUtils.getImageFetcher(activity); mInflater = LayoutInflater.from(activity); mListMargin = activity.getResources().getDimensionPixelSize(R.dimen.list_item_general_margin); }
From source file:com.qhn.bhne.xhmusic.utils.MyUtils.java
public static void setCircleIMG(final Activity activity, Object resImageId, final ImageView userPhoto) { if (resImageId instanceof String && TextUtils.isEmpty((String) resImageId)) { Toast.makeText(activity, "?", Toast.LENGTH_SHORT).show(); return;/*w w w .jav a 2 s . c o m*/ } if (resImageId instanceof Integer && (Integer) resImageId == 0) { Toast.makeText(activity, "?", Toast.LENGTH_SHORT).show(); return; } if (userPhoto == null) { Toast.makeText(activity, "", Toast.LENGTH_SHORT).show(); return; } Glide.with(activity).load(resImageId).asBitmap().placeholder(R.drawable.ic_placeholder).centerCrop() .into(new BitmapImageViewTarget(userPhoto) { @Override protected void setResource(Bitmap resource) { RoundedBitmapDrawable circularBitmapDrawable = RoundedBitmapDrawableFactory .create(activity.getResources(), resource); //circularBitmapDrawable.setCircular(true); circularBitmapDrawable.setCornerRadius(2); userPhoto.setImageDrawable(circularBitmapDrawable); } }); }
From source file:br.com.bioscada.apps.biotracks.fragments.ChooseActivityTypeDialogFragment.java
public static Dialog getDialog(final Activity activity, final String category, final ChooseActivityTypeCaller caller) { View view = activity.getLayoutInflater().inflate(R.layout.choose_activity_type, null); GridView gridView = (GridView) view.findViewById(R.id.choose_activity_type_grid_view); final View weightContainer = view.findViewById(R.id.choose_activity_type_weight_container); TextView weightLabel = (TextView) view.findViewById(R.id.choose_activity_type_weight_label); weightLabel.setText(PreferencesUtils.isMetricUnits(activity) ? R.string.description_weight_metric : R.string.description_weight_imperial); final TextView weight = (TextView) view.findViewById(R.id.choose_activity_type_weight); List<Integer> imageIds = new ArrayList<Integer>(); for (String iconValue : TrackIconUtils.getAllIconValues()) { imageIds.add(TrackIconUtils.getIconDrawable(iconValue)); }/*ww w .j av a 2 s . c o m*/ Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_track_airplane, options); int padding = 32; int width = options.outWidth + 2 * padding; int height = options.outHeight + 2 * padding; gridView.setColumnWidth(width); final ChooseActivityTypeImageAdapter imageAdapter = new ChooseActivityTypeImageAdapter(activity, imageIds, width, height, padding); gridView.setAdapter(imageAdapter); final String weightValue = StringUtils.formatWeight(PreferencesUtils.getWeightDisplayValue(activity)); final AlertDialog alertDialog = new AlertDialog.Builder(activity) .setNegativeButton(R.string.generic_cancel, null) .setPositiveButton(R.string.generic_ok, new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { boolean newWeight = false; if (weightContainer.getVisibility() == View.VISIBLE) { String newValue = weight.getText().toString(); if (!newValue.equals(weightValue)) { newWeight = true; PreferencesUtils.storeWeightValue(activity, newValue); } } int selected = imageAdapter.getSelected(); caller.onChooseActivityTypeDone(TrackIconUtils.getAllIconValues().get(selected), newWeight); } }).setTitle(R.string.track_edit_activity_type_hint).setView(view).create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { int position = getPosition(activity, category); alertDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(position != -1); if (position != -1) { imageAdapter.setSelected(position); imageAdapter.notifyDataSetChanged(); } updateWeightContainer(weightContainer, position); weight.setText(weightValue); DialogUtils.setDialogTitleDivider(activity, alertDialog); } }); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { alertDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(true); imageAdapter.setSelected(position); imageAdapter.notifyDataSetChanged(); updateWeightContainer(weightContainer, position); } }); return alertDialog; }
From source file:com.farmerbb.secondscreen.util.U.java
public static String generateBlurb(Activity a, String key, String value, boolean isNotification) { String blurb = " "; if (a instanceof TaskerQuickActionsActivity) { blurb = a.getResources().getStringArray(R.array.pref_notification_action_list)[1]; // If this blurb is being generated for the notification, and the value is "Toggle", // set value to the actual "On" or "Off" state if (isNotification && value.equals("Toggle")) { SharedPreferences prefCurrent = getPrefCurrent(a); switch (key) { case "temp_backlight_off": if (prefCurrent.getBoolean("backlight_off", false)) value = a.getResources().getStringArray(R.array.pref_quick_actions)[0]; else value = a.getResources().getStringArray(R.array.pref_quick_actions)[1]; break; case "temp_chrome": if (prefCurrent.getBoolean("chrome", false)) value = a.getResources().getStringArray(R.array.pref_quick_actions)[1]; else value = a.getResources().getStringArray(R.array.pref_quick_actions)[0]; break; case "temp_immersive": case "temp_immersive_new": if (key.equals("temp_immersive_new")) key = "temp_immersive"; switch (prefCurrent.getString("immersive_new", "fallback")) { case "immersive-mode": value = a.getResources().getStringArray(R.array.pref_quick_actions)[1]; break; default: value = a.getResources().getStringArray(R.array.pref_quick_actions)[0]; break; }/*from w ww .j a v a2s.com*/ break; case "temp_overscan": if (prefCurrent.getBoolean("overscan", false)) value = a.getResources().getStringArray(R.array.pref_quick_actions)[1]; else value = a.getResources().getStringArray(R.array.pref_quick_actions)[0]; break; case "temp_vibration_off": if (prefCurrent.getBoolean("vibration_off", false)) value = a.getResources().getStringArray(R.array.pref_quick_actions)[0]; else value = a.getResources().getStringArray(R.array.pref_quick_actions)[1]; break; case "temp_freeform": if (prefCurrent.getBoolean("freeform", false)) value = a.getResources().getStringArray(R.array.pref_quick_actions)[1]; else value = a.getResources().getStringArray(R.array.pref_quick_actions)[0]; break; case "temp_hdmi_rotation": switch (prefCurrent.getString("hdmi_rotation", "landscape")) { case "portrait": value = a.getResources().getStringArray(R.array.pref_hdmi_rotation_list)[1]; break; case "landscape": value = a.getResources().getStringArray(R.array.pref_hdmi_rotation_list)[0]; break; } break; } } // Modifications for non-English locales if (value.equals(a.getResources().getStringArray(R.array.pref_quick_actions_values)[0])) value = a.getResources().getStringArray(R.array.pref_quick_actions)[0]; else if (value.equals(a.getResources().getStringArray(R.array.pref_quick_actions_values)[1])) { if (key.equals("temp_overscan")) value = a.getResources().getStringArray(R.array.pref_quick_actions_overscan)[0]; else value = a.getResources().getStringArray(R.array.pref_quick_actions)[1]; } } switch (key) { case "turn_off": blurb = a.getResources().getString(R.string.quick_turn_off); break; case "lock_device": blurb = a.getResources().getStringArray(R.array.pref_notification_action_list)[2]; break; case "temp_backlight_off": blurb = a.getResources().getString(R.string.quick_backlight) + " " + value; break; case "temp_chrome": blurb = a.getResources().getString(R.string.quick_chrome) + " " + value; break; case "temp_immersive": blurb = a.getResources().getString(R.string.quick_immersive) + " " + value; break; case "temp_immersive_new": switch (value) { case "do-nothing": blurb = a.getResources().getStringArray(R.array.pref_immersive_list_alt)[0]; break; case "status-only": blurb = a.getResources().getStringArray(R.array.pref_immersive_list_alt)[1]; break; case "immersive-mode": blurb = a.getResources().getStringArray(R.array.pref_immersive_list_alt)[2]; break; case "Toggle": blurb = a.getResources().getStringArray(R.array.pref_immersive_list_alt)[3]; break; } break; case "density": case "temp_density": switch (value) { case "reset": blurb = a.getResources().getStringArray(R.array.pref_dpi_list)[0]; break; case "120": blurb = a.getResources().getStringArray(R.array.pref_dpi_list)[1]; break; case "160": blurb = a.getResources().getStringArray(R.array.pref_dpi_list)[2]; break; case "213": blurb = a.getResources().getStringArray(R.array.pref_dpi_list)[3]; break; case "240": blurb = a.getResources().getStringArray(R.array.pref_dpi_list)[4]; break; case "320": blurb = a.getResources().getStringArray(R.array.pref_dpi_list)[6]; break; case "480": blurb = a.getResources().getStringArray(R.array.pref_dpi_list)[8]; break; case "640": blurb = a.getResources().getStringArray(R.array.pref_dpi_list)[10]; break; default: blurb = value + a.getResources().getString(R.string.dpi); break; } break; case "temp_overscan": blurb = a.getResources().getString(R.string.quick_overscan) + " " + value; break; case "size": case "temp_size": SharedPreferences prefMain = getPrefMain(a); if (value.equals("reset")) blurb = a.getResources().getStringArray(R.array.pref_resolution_list)[0]; else if (prefMain.getBoolean("landscape", false)) { switch (value) { case "1920x1080": blurb = a.getResources().getStringArray(R.array.pref_resolution_list)[1]; break; case "1280x720": blurb = a.getResources().getStringArray(R.array.pref_resolution_list)[2]; break; case "854x480": blurb = a.getResources().getStringArray(R.array.pref_resolution_list)[3]; break; default: blurb = value; break; } } else { switch (value) { case "1080x1920": blurb = a.getResources().getStringArray(R.array.pref_resolution_list)[1]; break; case "720x1280": blurb = a.getResources().getStringArray(R.array.pref_resolution_list)[2]; break; case "480x854": blurb = a.getResources().getStringArray(R.array.pref_resolution_list)[3]; break; default: Scanner scanner = new Scanner(value); scanner.useDelimiter("x"); int height = scanner.nextInt(); int width = scanner.nextInt(); scanner.close(); blurb = Integer.toString(width) + "x" + Integer.toString(height); break; } } break; case "temp_rotation_lock_new": switch (value) { case "do-nothing": blurb = a.getResources().getStringArray(R.array.pref_rotation_list)[0]; break; case "auto-rotate": blurb = a.getResources().getStringArray(R.array.pref_rotation_list)[1]; break; case "landscape": blurb = a.getResources().getStringArray(R.array.pref_rotation_list)[2]; break; } break; case "temp_vibration_off": blurb = a.getResources().getString(R.string.quick_vibration) + " " + value; break; case "temp_freeform": blurb = a.getResources().getString(R.string.quick_freeform) + " " + value; break; case "temp_hdmi_rotation": blurb = a.getResources().getString(R.string.quick_hdmi_rotation) + " " + value; break; } return blurb; }
From source file:com.none.tom.simplerssreader.fragment.CurrentFeedFragment.java
@SuppressWarnings("ConstantConditions") @Override/*from www. j a v a2s .c o m*/ public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.fragment_current_feed_recyclerview, container, false); final Activity activity = getActivity(); mSwipeRefreshLayout = view.findViewById(R.id.CurrentFeedSwipeToRefreshLayout); mSwipeRefreshLayout.setColorSchemeColors(activity.getResources().getIntArray(R.array.color_palette)); mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { isFeedUpdateAvailable(); } }); final VerticalSpaceItemDecoration decor = new VerticalSpaceItemDecoration(activity); decor.setDrawable(activity.getDrawable(R.drawable.divider)); mRecyclerView = view.findViewById(R.id.CurrentFeedRecyclerView); mRecyclerView.setLayoutManager(new CenterLayoutManager(activity)); mRecyclerView.setAdapter(new CurrentFeedAdapter(activity)); mRecyclerView.addItemDecoration(decor); super.onCreateView((CoordinatorLayout) view, mRecyclerView); return view; }
From source file:org.mozilla.gecko.tests.BaseRobocopTest.java
@Override protected void setUp() throws Exception { // Disable the updater. UpdateServiceHelper.setEnabled(false); // Load config file from root path (set up by Python script). mRootPath = FennecInstrumentationTestRunner.getFennecArguments().getString("deviceroot"); if (mRootPath == null) { Log.w("Robocop", "Did not find deviceroot in arguments; falling back to: " + DEFAULT_ROOT_PATH); mRootPath = DEFAULT_ROOT_PATH;//from ww w . j a v a 2s. com } String configFile = FennecNativeDriver.getFile(mRootPath + "/robotium.config"); mConfig = FennecNativeDriver.convertTextToTable(configFile); mLogFile = mConfig.get("logfile"); mProfile = mConfig.get("profile"); mBaseHostnameUrl = mConfig.get("host").replaceAll("(/$)", ""); mBaseIpUrl = mConfig.get("rawhost").replaceAll("(/$)", ""); // Initialize the asserter. if (getTestType() == Type.TALOS) { mAsserter = new FennecTalosAssert(); } else { mAsserter = new FennecMochitestAssert(); } mAsserter.setLogFile(mLogFile); mAsserter.setTestName(getClass().getName()); // Start the activity. final Intent intent = createActivityIntent(); setActivityIntent(intent); // Set up Robotium.solo and Driver objects Activity tempActivity = getActivity(); StringHelper.initialize(tempActivity.getResources()); mStringHelper = StringHelper.get(); mSolo = new Solo(getInstrumentation(), tempActivity); mDriver = new FennecNativeDriver(tempActivity, mSolo, mRootPath); mActions = new FennecNativeActions(tempActivity, mSolo, getInstrumentation(), mAsserter); }
From source file:com.camnter.newlife.widget.decorator.DividerItemDecoration.java
public DividerItemDecoration(Activity activity, int orientation, int drawableId) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { this.mDivider = activity.getTheme().getDrawable(drawableId); } else {/* www .ja v a 2 s .co m*/ this.mDivider = activity.getResources().getDrawable(drawableId); } this.setOrientation(orientation); }
From source file:com.repkap11.repcast.utils.Utils.java
public static void showUpdateDialogIfNecessary(Activity activity) { try {//from w w w .ja v a 2 s . c o m SharedPreferences prefs = activity.getSharedPreferences("CHANGELOG", Context.MODE_PRIVATE); int currentVersionCode = activity.getPackageManager().getPackageInfo(activity.getPackageName(), 0).versionCode; boolean hasShownPrevious = prefs.getBoolean("has-shown-prefs-" + (currentVersionCode - 1), false); boolean hasShownCurrent = prefs.getBoolean("has-shown-prefs-" + currentVersionCode, false); //Log.e(TAG, "hasShownPrevious:" + hasShownPrevious + " hasShownCurrent:" + hasShownCurrent); SharedPreferences.Editor editor = prefs.edit(); editor.putBoolean("has-shown-prefs-" + currentVersionCode, true); editor.putBoolean("has-shown-prefs-" + (currentVersionCode - 1), true); if ((hasShownPrevious && !hasShownCurrent)) { AlertDialog d = new AlertDialog.Builder(activity) .setTitle("Changelog: App Version " + currentVersionCode) .setMessage(activity.getResources().getString(R.string.changelog_message)) .setCancelable(false).setNegativeButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); //DisplayMetrics metrics = activity.getResources().getDisplayMetrics(); //int width = metrics.widthPixels; //int height = metrics.heightPixels; //Log.e(TAG, "Width:" + width + " Height:" + height); //d.getWindow().setLayout(width,height); } editor.apply(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
From source file:com.blogspot.codigogoogle.listloadingsamples.ImageLoaderListAdapter.java
public ImageLoaderListAdapter(Activity context, ArrayList<Map<String, String>> listItems) { this.context = context; this.listItems = listItems; mPlaceHolderBitmap = decodeSampledBitmapFromResource(context.getResources(), R.drawable.img_placeholder, 20, 20);//from ww w. j a v a 2 s . com final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); final int cacheSize = maxMemory / 8; mMemoryCache = new LruCache<String, Bitmap>(cacheSize) { @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override protected int sizeOf(String key, Bitmap bitmap) { if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB_MR1) { return bitmap.getByteCount() / 1024; } else { return bitmap.getRowBytes() * bitmap.getHeight() / 1024; } } }; }