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:com.xiaomi.account.utils.SysHelper.java

public static Bitmap createPhoto(Activity activity, String avatarFileName) {
    Bitmap origin = null;/*  ww w .  j a  v  a 2  s  . c  o m*/
    if (avatarFileName != null) {
        origin = SnsUtils.getUserAvatarByAbsPath(activity, avatarFileName);
    }
    if (origin == null) {
        origin = android.graphics.BitmapFactory.decodeResource(activity.getResources(),
                R.drawable.default_avatar_in_settings);
    }
    if (origin == null) {
        return null;
    }
    Bitmap avatar = BitmapFactory.createPhoto(activity, origin);
    origin.recycle();
    return avatar;
}

From source file:Main.java

/**
 * Get Bitmap from Uri/*from   ww w . j a  v a  2 s .co  m*/
 *
 * @param uri Uri to get Bitmap
 * @return
 * @throws FileNotFoundException
 * @throws IOException
 */
public static Bitmap getImageFromUri(Activity activity, Uri uri, File file) throws IOException {

    BitmapFactory.Options onlyBoundsOptions = new BitmapFactory.Options();
    onlyBoundsOptions.inJustDecodeBounds = true;
    onlyBoundsOptions.inDither = true;//optional
    onlyBoundsOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional
    if (file != null) {
        BitmapFactory.decodeFile(file.getAbsolutePath(), onlyBoundsOptions);
    } else {
        InputStream input = activity.getContentResolver().openInputStream(uri);
        BitmapFactory.decodeStream(input, null, onlyBoundsOptions);
        input.close();
    }

    if ((onlyBoundsOptions.outWidth == -1) || (onlyBoundsOptions.outHeight == -1))
        return null;

    float scale = activity.getResources().getDisplayMetrics().density;
    int pHeight = (int) (activity.getResources().getConfiguration().screenHeightDp * scale + 0.5f);
    int originalSize = (onlyBoundsOptions.outHeight > onlyBoundsOptions.outWidth) ? onlyBoundsOptions.outHeight
            : onlyBoundsOptions.outWidth;

    double ratio = (originalSize > pHeight) ? (originalSize / pHeight) : 1.0;

    int REQUIRED_SIZE = activity.getResources().getDisplayMetrics().heightPixels / 2;

    /**/
    int Scale = 1;
    while (onlyBoundsOptions.outWidth / Scale / 2 >= REQUIRED_SIZE
            && onlyBoundsOptions.outHeight / Scale / 2 >= REQUIRED_SIZE) {
        Scale *= 2;
    }
    /**/

    BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
    bitmapOptions.inSampleSize = Scale;//getPowerOfTwoForSampleRatio(ratio);
    bitmapOptions.inDither = true;//optional
    bitmapOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;//optional

    Bitmap bitmap;
    if (file != null) {
        bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(), bitmapOptions);
    } else {
        InputStream input = activity.getContentResolver().openInputStream(uri);
        bitmap = BitmapFactory.decodeStream(input, null, bitmapOptions);
        input.close();
    }

    return bitmap;
}

From source file:me.barrasso.android.volume.activities.ConfigurationActivity.java

public static void setupActionBar(Activity activity) {

    // Tint the status bar, if available.
    SystemBarTintManager tintManager = new SystemBarTintManager(activity);
    tintManager.setStatusBarTintEnabled(true);
    tintManager.setTintColor(activity.getResources().getColor(R.color.action_bar_dark));

    ActionBar actionBar = activity.getActionBar();
    if (null != actionBar) {
        actionBar.setIcon(DateUtils.AppIcon());
        actionBar.setDisplayHomeAsUpEnabled(!activity.isTaskRoot());
        actionBar.setDisplayShowTitleEnabled(true);
    }/*from www  .  ja v a2s  .c o  m*/
}

From source file:jahirfiquitiva.iconshowcase.dialogs.ISDialogs.java

public static void showIconsChangelogDialog(final Activity context) {

    if (((ShowcaseActivity) context).getChangelogDialog() != null) {
        ((ShowcaseActivity) context).getChangelogDialog().dismiss();
        ((ShowcaseActivity) context).setChangelogDialog(null);
    }//from  ww  w.  j a  va  2s .co m

    ((ShowcaseActivity) context).setChangelogDialog(new MaterialDialog.Builder(context)
            .title(R.string.changelog).customView(R.layout.icons_changelog, false)
            .positiveText(context.getResources().getString(R.string.close)).build());

    final View v = ((ShowcaseActivity) context).getChangelogDialog().getCustomView();
    if (v != null) {
        final RecyclerView iconsGrid = (RecyclerView) v.findViewById(R.id.changelogRV);
        final int grids = context.getResources().getInteger(R.integer.icons_grid_width);
        iconsGrid.setLayoutManager(new GridLayoutManager(context, grids));

        ArrayList<IconItem> icons = null;

        if (LoadIconsLists.getIconsLists() != null) {
            icons = LoadIconsLists.getIconsLists().get(0).getIconsArray();
        }

        final IconsAdapter adapter = new IconsAdapter(context, icons, true);
        iconsGrid.setAdapter(adapter);
    }

    ((ShowcaseActivity) context).getChangelogDialog().show();
}

From source file:Main.java

/**
 * Get a BitmapDrawable from a local file that is scaled down
 * to fit the current Window size./*w  ww . j  ava  2 s .  c o  m*/
 */
@SuppressWarnings("deprecation")
static BitmapDrawable getScaledBitmap(String path, Activity a) {
    Display display = a.getWindowManager().getDefaultDisplay();
    float destWidth = display.getWidth();
    float destHeight = display.getHeight();

    // read in the dimensions of the image on disk
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, options);

    float srcWidth = options.outWidth;
    float srcHeight = options.outHeight;

    int inSampleSize = 1;
    if (srcHeight > destHeight || srcWidth > destWidth) {
        if (srcWidth > srcHeight) {
            inSampleSize = Math.round(srcHeight / destHeight);
        } else {
            inSampleSize = Math.round(srcWidth / destWidth);
        }
    }

    options = new BitmapFactory.Options();
    options.inSampleSize = inSampleSize;

    Bitmap bitmap = BitmapFactory.decodeFile(path, options);
    return new BitmapDrawable(a.getResources(), bitmap);
}

From source file:com.google.android.gms.common.C0270e.java

private static Dialog m3391b(int i, Activity activity, Fragment fragment, int i2,
        OnCancelListener onCancelListener) {
    Builder builder;/*from w  ww  . j av  a  2s.  c o m*/
    Intent a;
    OnClickListener c0420i;
    CharSequence c;
    if (C0516u.m4166a((Context) activity) && i == 2) {
        i = 42;
    }
    if (C0519x.m4174c()) {
        TypedValue typedValue = new TypedValue();
        activity.getTheme().resolveAttribute(16843529, typedValue, true);
        if ("Theme.Dialog.Alert".equals(activity.getResources().getResourceEntryName(typedValue.resourceId))) {
            builder = new Builder(activity, 5);
            if (builder == null) {
                builder = new Builder(activity);
            }
            builder.setMessage(C0270e.m3392b(activity, i));
            if (onCancelListener != null) {
                builder.setOnCancelListener(onCancelListener);
            }
            a = C0270e.m3382a(i);
            c0420i = fragment != null ? new C0420i(activity, a, i2) : new C0420i(fragment, a, i2);
            c = C0270e.m3397c(activity, i);
            if (c != null) {
                builder.setPositiveButton(c, c0420i);
            }
            switch (i) {
            case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoPanelHeight /*0*/:
                return null;
            case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoShadowHeight /*1*/:
                return builder.setTitle(R.common_google_play_services_install_title).create();
            case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoParalaxOffset /*2*/:
                return builder.setTitle(R.common_google_play_services_update_title).create();
            case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoFadeColor /*3*/:
                return builder.setTitle(R.common_google_play_services_enable_title).create();
            case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoFlingVelocity /*4*/:
            case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoOverlay /*6*/:
                return builder.create();
            case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoDragView /*5*/:
                Log.e("GooglePlayServicesUtil",
                        "An invalid account was specified when connecting. Please provide a valid account.");
                return builder.setTitle(R.common_google_play_services_invalid_account_title).create();
            case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoClipPanel /*7*/:
                Log.e("GooglePlayServicesUtil", "Network error occurred. Please retry request later.");
                return builder.setTitle(R.common_google_play_services_network_error_title).create();
            case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoAnchorPoint /*8*/:
                Log.e("GooglePlayServicesUtil",
                        "Internal error occurred. Please see logs for detailed information");
                return builder.create();
            case HTTP.HT /*9*/:
                Log.e("GooglePlayServicesUtil", "Google Play services is invalid. Cannot recover.");
                return builder.setTitle(R.common_google_play_services_unsupported_title).create();
            case HTTP.LF /*10*/:
                Log.e("GooglePlayServicesUtil",
                        "Developer error occurred. Please see logs for detailed information");
                return builder.create();
            case com.olacabs.customer.R.R.MapM4bAttrs_m4b_uiZoomControls /*11*/:
                Log.e("GooglePlayServicesUtil", "The application is not licensed to the user.");
                return builder.create();
            case Constants.DEFAULT_MAP_ZOOM_LEVEL /*16*/:
                Log.e("GooglePlayServicesUtil",
                        "One of the API components you attempted to connect to is not available.");
                return builder.create();
            case LangUtils.HASH_SEED /*17*/:
                Log.e("GooglePlayServicesUtil", "The specified account could not be signed in.");
                return builder.setTitle(R.common_google_play_services_sign_in_failed_title).create();
            case 42:
                return builder.setTitle(R.common_android_wear_update_title).create();
            default:
                Log.e("GooglePlayServicesUtil", "Unexpected error code " + i);
                return builder.create();
            }
        }
    }
    builder = null;
    if (builder == null) {
        builder = new Builder(activity);
    }
    builder.setMessage(C0270e.m3392b(activity, i));
    if (onCancelListener != null) {
        builder.setOnCancelListener(onCancelListener);
    }
    a = C0270e.m3382a(i);
    if (fragment != null) {
    }
    c = C0270e.m3397c(activity, i);
    if (c != null) {
        builder.setPositiveButton(c, c0420i);
    }
    switch (i) {
    case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoPanelHeight /*0*/:
        return null;
    case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoShadowHeight /*1*/:
        return builder.setTitle(R.common_google_play_services_install_title).create();
    case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoParalaxOffset /*2*/:
        return builder.setTitle(R.common_google_play_services_update_title).create();
    case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoFadeColor /*3*/:
        return builder.setTitle(R.common_google_play_services_enable_title).create();
    case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoFlingVelocity /*4*/:
    case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoOverlay /*6*/:
        return builder.create();
    case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoDragView /*5*/:
        Log.e("GooglePlayServicesUtil",
                "An invalid account was specified when connecting. Please provide a valid account.");
        return builder.setTitle(R.common_google_play_services_invalid_account_title).create();
    case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoClipPanel /*7*/:
        Log.e("GooglePlayServicesUtil", "Network error occurred. Please retry request later.");
        return builder.setTitle(R.common_google_play_services_network_error_title).create();
    case com.sothree.slidinguppanel.p086a.R.R.SlidingUpPanelLayout_umanoAnchorPoint /*8*/:
        Log.e("GooglePlayServicesUtil", "Internal error occurred. Please see logs for detailed information");
        return builder.create();
    case HTTP.HT /*9*/:
        Log.e("GooglePlayServicesUtil", "Google Play services is invalid. Cannot recover.");
        return builder.setTitle(R.common_google_play_services_unsupported_title).create();
    case HTTP.LF /*10*/:
        Log.e("GooglePlayServicesUtil", "Developer error occurred. Please see logs for detailed information");
        return builder.create();
    case com.olacabs.customer.R.R.MapM4bAttrs_m4b_uiZoomControls /*11*/:
        Log.e("GooglePlayServicesUtil", "The application is not licensed to the user.");
        return builder.create();
    case Constants.DEFAULT_MAP_ZOOM_LEVEL /*16*/:
        Log.e("GooglePlayServicesUtil",
                "One of the API components you attempted to connect to is not available.");
        return builder.create();
    case LangUtils.HASH_SEED /*17*/:
        Log.e("GooglePlayServicesUtil", "The specified account could not be signed in.");
        return builder.setTitle(R.common_google_play_services_sign_in_failed_title).create();
    case 42:
        return builder.setTitle(R.common_android_wear_update_title).create();
    default:
        Log.e("GooglePlayServicesUtil", "Unexpected error code " + i);
        return builder.create();
    }
}

From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java

public static RepeaterList loadData(int resource, Activity activity) {
    RepeaterList mlist = new RepeaterList(150);
    int line = 0;
    try {//from  w w w.java 2s  .  c  o  m

        InputStreamReader is = new InputStreamReader(activity.getResources().openRawResource(resource));
        BufferedReader in = new BufferedReader(is);
        CSVReader csv = new CSVReader(in, ';', '\"', 0);
        String data[];

        while ((data = csv.readNext()) != null) {
            line++;
            mlist.add(new Repeater("", data[1], data[2], data[3], data[9], Double.parseDouble(data[4]),
                    Double.parseDouble(data[5]), Double.parseDouble(data[6]), Double.parseDouble(data[7]),
                    Double.parseDouble(data[8])));

        }

        in.close();

    } catch (IOException ioe) {
        Log.e("Read CSV Error mypapit", "Some CSV Error: ", ioe.getCause());

    } catch (NumberFormatException nfe) {
        Log.e("Number error", "parse number error - line: " + line + "  " + nfe.getMessage(), nfe.getCause());
    } catch (Exception ex) {
        Log.e("Some Exception", "some exception at line :" + line + " \n " + ex.getCause());
        ex.printStackTrace(System.err);
    }

    return mlist;

}

From source file:Main.java

/**
 * Get a BitmapDrawable from a local file that is scaled down
 * to fit the current Window size.//from  w  ww. j a  va  2s  . c om
 */
@SuppressWarnings("deprecation")
public static BitmapDrawable getScaledDrawable(Activity a, String path) {
    Display display = a.getWindowManager().getDefaultDisplay();
    float destWidth = display.getWidth();
    float destHeight = display.getHeight();

    // read in the dimensions of the image on disk
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, options);

    float srcWidth = options.outWidth;
    float srcHeight = options.outHeight;

    int inSampleSize = 1;
    if (srcHeight > destHeight || srcWidth > destWidth) {
        if (srcWidth > srcHeight) {
            inSampleSize = Math.round((float) srcHeight / ((float) destHeight) * 3);
        } else {
            inSampleSize = Math.round((float) srcWidth / ((float) destWidth) * 3);
        }
    }

    options = new BitmapFactory.Options();
    options.inSampleSize = inSampleSize;

    Bitmap bitmap = BitmapFactory.decodeFile(path, options);
    return new BitmapDrawable(a.getResources(), bitmap);
}

From source file:io.selendroid.server.model.internal.execute_native.GetL10nKeyTranslation.java

private String getLocalizedString(String l10nKey) {
    Activity currentActivity = serverInstrumentation.getCurrentActivity();
    int resourceId = currentActivity.getResources().getIdentifier(l10nKey, "string",
            currentActivity.getPackageName());
    try {/*from   w  w  w.  j a va 2 s  .  com*/
        return currentActivity.getResources().getString(resourceId);
    } catch (Resources.NotFoundException e) {
        return "";
    }
}

From source file:com.nuvolect.securesuite.data.ExportVcf.java

public static void emailVcf(Activity act, long contact_id) {

    String messageTitle = "vCard for ";
    String messageBody = "\n\n\nContact from SecureSuite, a secure contact manager";

    try {//from w ww.ja v a 2s  .  c om
        String displayName = SqlCipher.get(contact_id, ATab.display_name);
        String fileName = displayName.replaceAll("\\W+", "");
        if (fileName.isEmpty())
            fileName = "contact";
        fileName = fileName + ".vcf";

        new File(act.getFilesDir() + CConst.SHARE_FOLDER).mkdirs();
        File vcf_file = new File(act.getFilesDir() + CConst.SHARE_FOLDER + fileName);

        writeContactVcard(contact_id, vcf_file);

        // Must match "authorities" in Manifest provider definition
        String authorities = act.getResources().getString(R.string.app_authorities) + ".provider";

        Uri uri = null;
        try {
            uri = FileProvider.getUriForFile(act, authorities, vcf_file);
        } catch (IllegalArgumentException e) {
            LogUtil.logException(act, LogType.EXPORT_VCF, e);
        }

        //convert from paths to Android friendly Parcelable Uri's
        ArrayList<Uri> uris = new ArrayList<Uri>();
        uris.add(uri);

        Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
        intent.setType("text/plain");
        intent.putExtra(Intent.EXTRA_SUBJECT, messageTitle + displayName);
        intent.putExtra(Intent.EXTRA_TEXT, messageBody);
        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra("path", vcf_file.getAbsolutePath());

        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
        act.startActivityForResult(Intent.createChooser(intent, "Share with..."),
                CConst.RESPONSE_CODE_SHARE_VCF);

    } catch (Exception e) {
        LogUtil.logException(act, LogType.EXPORT_VCF, e);
    }
}