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:fi.tuukka.weather.utils.Utils.java

public static BitmapDrawable loadBitmapDrawableFromUrl(Activity activity, String imageAddress) {
    Bitmap bmp = loadBitmapFromUrl(imageAddress);
    return new BitmapDrawable(activity.getResources(), bmp);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public static void showProgress(Activity activity, final View defaultView, final View progressView,
        final boolean show) {

    // On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
    // for very easy animations. If available, use these APIs to fade-in
    // the progress spinner.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        int shortAnimTime = activity.getResources().getInteger(android.R.integer.config_shortAnimTime);

        defaultView.setVisibility(show ? View.GONE : View.VISIBLE);
        defaultView.animate().setDuration(shortAnimTime).alpha(show ? 0 : 1)
                .setListener(new AnimatorListenerAdapter() {
                    @Override/*from w w w.  j  a  v a  2 s . co  m*/
                    public void onAnimationEnd(Animator animation) {
                        defaultView.setVisibility(show ? View.GONE : View.VISIBLE);
                    }
                });

        progressView.setVisibility(show ? View.VISIBLE : View.GONE);
        progressView.animate().setDuration(shortAnimTime).alpha(show ? 1 : 0)
                .setListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator animation) {
                        progressView.setVisibility(show ? View.VISIBLE : View.GONE);
                    }
                });

    } else {
        // The ViewPropertyAnimator APIs are not available, so simply show
        // and hide the relevant UI components.
        progressView.setVisibility(show ? View.VISIBLE : View.GONE);
        defaultView.setVisibility(show ? View.GONE : View.VISIBLE);
    }
}

From source file:Main.java

public static void startActivity(final Activity thisActivity, final Intent intent, final View triggerView,
        int colorOrImageRes, final long durationMills) {
    int[] location = new int[2];
    triggerView.getLocationInWindow(location);
    final int cx = location[0] + triggerView.getWidth();
    final int cy = location[1] + triggerView.getHeight() + (int) TypedValue
            .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 160, thisActivity.getResources().getDisplayMetrics());
    final ImageView view = new ImageView(thisActivity);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageResource(colorOrImageRes);
    final ViewGroup decorView = (ViewGroup) thisActivity.getWindow().getDecorView();
    int w = decorView.getWidth();
    int h = decorView.getHeight();
    decorView.addView(view, w, h);//from   ww w  .  ja  v  a 2 s  . c  o m
    final int finalRadius = (int) Math.sqrt(w * w + h * h) + 1;
    Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius);
    anim.setDuration(durationMills);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            thisActivity.startActivity(intent);
            thisActivity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        }
    });
    anim.start();
}

From source file:com.example.angelina.travelapp.data.CategoryHelper.java

/**
 * Return appropriate drawable base on place type
 * @param p - Place item/* w w  w.j ava2  s.co m*/
 * @param a - Activity
 * @return - Drawable
 */
public static Drawable getDrawableForPlace(final Place p, final Activity a) {

    final String placeType = p.getType();
    final String category = CategoryHelper.getCategoryForFoodType(placeType);
    final Drawable d;
    switch (category) {
    case "Pizza":
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_pizza_black_24dp, null);
        break;
    case "Hotel":
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_hotel_black_24dp, null);
        break;
    case "Food":
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_dining_black_24dp, null);
        break;
    case "Bar or Pub":
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_bar_black_24dp, null);
        break;
    case "Coffee Shop":
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_local_cafe_black_24dp, null);
        break;
    default:
        d = ResourcesCompat.getDrawable(a.getResources(), R.drawable.ic_place_black_24dp, null);
    }
    return d;
}

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

public static void showHideIconErrorDialog(final Activity context) {
    String content = context.getResources().getString(R.string.launcher_icon_restorer_error,
            Utils.getStringFromResources(context, R.string.app_name));
    new MaterialDialog.Builder(context).title(R.string.pref_title_launcher_icon).content(content)
            .positiveText(android.R.string.ok).show();
}

From source file:fi.tuukka.weather.utils.Utils.java

public static void setBackGroundDrawable(Activity activity, LinearLayout layout, Bitmap bmp) {
    // int sdk = android.os.Build.VERSION.SDK_INT;
    // if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
    layout.setBackgroundDrawable(new BitmapDrawable(activity.getResources(), bmp));
    // } else {//from   ww  w  .j av  a 2s.  com
    // layout.setBackground(new BitmapDrawable(activity.getResources(), bmp));
    // }
}

From source file:de.baumann.hhsmoodle.helper.helper_main.java

public static void setImageHeader(Activity activity, ImageView imageView) {

    if (imageView != null) {
        TypedArray images = activity.getResources().obtainTypedArray(R.array.splash_images);
        int choice = (int) (Math.random() * images.length());
        imageView.setImageResource(images.getResourceId(choice, R.drawable.splash1));
        images.recycle();/* w  w  w  .j  av  a  2s  .c  o  m*/
    }
}

From source file:org.chromium.chrome.browser.init.InvalidStartupDialog.java

/**
 * Shows the invalid startup dialog for a given error code.
 *
 * @param activity The activity showing the dialog.
 * @param errorCode The error code that triggered the failure.
 *//*  w  ww.  j a  v  a 2s  .c o m*/
@SuppressFBWarnings("DM_EXIT")
public static void show(Activity activity, int errorCode) {
    int msg;
    switch (errorCode) {
    case LoaderErrors.LOADER_ERROR_NATIVE_LIBRARY_LOAD_FAILED:
        msg = R.string.os_version_missing_features;
        break;
    case LoaderErrors.LOADER_ERROR_NATIVE_LIBRARY_WRONG_VERSION:
        msg = R.string.incompatible_libraries;
        break;
    default:
        msg = R.string.native_startup_failed;
    }
    final String message = activity.getResources().getString(msg);

    if (!(activity instanceof FragmentActivity)) {
        Log.e(TAG, "Unable to start chrome due to: " + msg);
        System.exit(-1);
        return;
    }

    Bundle dialogArgs = new Bundle();
    dialogArgs.putString(MESSAGE_KEY, message);

    InvalidStartupDialog dialog = new InvalidStartupDialog();
    dialog.setArguments(dialogArgs);
    dialog.show(((FragmentActivity) activity).getSupportFragmentManager(), "InvalidStartupDialog");
}

From source file:com.tinyhydra.botd.BotdServerOperations.java

public static void CastVote(final Activity activity, final Handler handler, final String email,
        final String shopId, final String shopRef) {
    new Thread() {
        @Override//from  www.  j  a v  a  2s. c o m
        public void run() {
            try {
                URI uri = new URI(activity.getResources().getString(R.string.server_url));
                HttpClient client = new DefaultHttpClient();
                HttpPut put = new HttpPut(uri);

                JSONObject voteObj = new JSONObject();

                // user's phone-account-email-address is used to prevent multiple votes
                // the server will validate. 'shopId' is a consistent id for a specific location
                // but can't be used to get more data. 'shopRef' is an id that changes based on
                // some criteria that google places has imposed, but will let us grab data later on
                // and various Ref codes with the same id will always resolve to the same location.
                voteObj.put(JSONvalues.email.toString(), email);
                voteObj.put(JSONvalues.shopId.toString(), shopId);
                voteObj.put(JSONvalues.shopRef.toString(), shopRef);
                put.setEntity(new StringEntity(voteObj.toString()));

                HttpResponse response = client.execute(put);
                InputStream is = response.getEntity().getContent();
                int ch;
                StringBuffer sb = new StringBuffer();
                while ((ch = is.read()) != -1) {
                    sb.append((char) ch);
                }
                if (sb.toString().equals("0")) {
                    Utils.PostToastMessageToHandler(handler, "Vote cast!", Toast.LENGTH_SHORT);
                    // Set a local flag to prevent duplicate voting
                    SharedPreferences settings = activity.getSharedPreferences(Const.GenPrefs, 0);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putLong(Const.LastVoteDate, Utils.GetDate());
                    editor.commit();
                } else {
                    // The user shouldn't see this. The above SharedPreferences code will be evaluated
                    // when the user hits the Vote button. If the user gets sneaky and deletes local data though,
                    // the server will catch the duplicate vote based on the user's email address and send back a '1'.
                    Utils.PostToastMessageToHandler(handler,
                            "Vote refused. You've probably already voted today.", Toast.LENGTH_LONG);
                }
                GetTopTen(activity, handler, true);
                // Catch blocks. Return a generic error if anything goes wrong.
                //TODO: implement some better/more appropriate error handling.
            } catch (URISyntaxException usex) {
                usex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (UnsupportedEncodingException ueex) {
                ueex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (ClientProtocolException cpex) {
                cpex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (IOException ioex) {
                ioex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (JSONException jex) {
                jex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            }
        }
    }.start();
}

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

public static MaterialDialog showThemeChooserDialog(final Activity context) {
    int defaultTheme = context.getResources().getInteger(R.integer.default_theme) - 1;
    final int[] selectedTheme = {
            PreferenceManager.getDefaultSharedPreferences(context).getInt("theme", defaultTheme) };
    final int[] newSelectedTheme = new int[1];
    final Preferences mPrefs = new Preferences(context);
    return new MaterialDialog.Builder(context).title(R.string.pref_title_themes).items(R.array.themes)
            .itemsCallbackSingleChoice(selectedTheme[0], new MaterialDialog.ListCallbackSingleChoice() {
                @Override/*  w  ww.  j  a v  a2 s . c o m*/
                public boolean onSelection(MaterialDialog dialog, View view, int position, CharSequence text) {
                    switch (position) {
                    case 0:
                        ThemeUtils.changeToTheme(context, ThemeUtils.LIGHT);
                        break;
                    case 1:
                        ThemeUtils.changeToTheme(context, ThemeUtils.DARK);
                        break;
                    case 2:
                        ThemeUtils.changeToTheme(context, ThemeUtils.CLEAR);
                        break;
                    case 3:
                        ThemeUtils.changeToTheme(context, ThemeUtils.AUTO);
                        break;
                    }
                    PreferenceManager.getDefaultSharedPreferences(context).edit().putInt("theme", position)
                            .apply();
                    newSelectedTheme[0] = position;
                    if (newSelectedTheme[0] != selectedTheme[0]) {
                        mPrefs.setSettingsModified(true);
                        ThemeUtils.restartActivity(context);
                    }
                    return true;
                }
            }).positiveText(android.R.string.ok).negativeText(android.R.string.cancel).build();
}