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:co.carlosjimenez.android.currencyalerts.app.MenuTint.java

private static ViewGroup findActionBar(Activity activity) {
    int id = activity.getResources().getIdentifier("action_bar", "id", "android");
    ViewGroup actionBar = null;//from   w w  w  .  ja v  a 2 s  .  c o  m
    if (id != 0) {
        actionBar = (ViewGroup) activity.findViewById(id);
    }
    if (actionBar == null) {
        actionBar = findToolbar((ViewGroup) activity.findViewById(android.R.id.content).getRootView());
    }
    return actionBar;
}

From source file:com.todoroo.astrid.activity.FilterListFragment.java

public static Bitmap superImposeListIcon(Activity activity, Bitmap listingIcon, String listingTitle) {
    Bitmap emblem = listingIcon;//from  w  w w .  java 2 s  .  co  m
    if (emblem == null)
        emblem = ((BitmapDrawable) activity.getResources()
                .getDrawable(TagService.getDefaultImageIDForTag(listingTitle))).getBitmap();

    // create icon by superimposing astrid w/ icon
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
    Bitmap bitmap = ((BitmapDrawable) activity.getResources().getDrawable(R.drawable.icon_blank)).getBitmap();
    bitmap = bitmap.copy(bitmap.getConfig(), true);
    Canvas canvas = new Canvas(bitmap);
    int dimension = 22;
    canvas.drawBitmap(emblem, new Rect(0, 0, emblem.getWidth(), emblem.getHeight()),
            new Rect(bitmap.getWidth() - dimension, bitmap.getHeight() - dimension, bitmap.getWidth(),
                    bitmap.getHeight()),
            null);
    return bitmap;
}

From source file:com.github.rutvijkumar.twittfuse.Util.java

public static void setupSearchView(final Activity activity, final SearchView searchView) {

    int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null,
            null);/* ww  w  .  ja  v a  2  s .  c o  m*/
    EditText searchPlate = (EditText) searchView.findViewById(searchPlateId);
    searchPlate.setTextColor(activity.getResources().getColor(android.R.color.white));
    searchView.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            boolean isValidSubmit = false;
            if (query != null && !query.isEmpty()) {
                search(activity, query);
                isValidSubmit = true;
            }

            return isValidSubmit;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // TODO Auto-generated method stub
            return false;
        }
    });
}

From source file:Main.java

private static int getStatusBarHeight(Activity activity) {
    Class<?> c;/*ww  w.  j a  va 2 s. co  m*/
    Object obj;
    Field field;
    int x;
    int statusBarHeight = 0;
    try {
        c = Class.forName("com.android.internal.R$dimen");
        obj = c.newInstance();
        field = c.getField("status_bar_height");
        x = Integer.parseInt(field.get(obj).toString());
        statusBarHeight = activity.getResources().getDimensionPixelSize(x);
    } catch (Exception e1) {
        e1.printStackTrace();
    }
    return statusBarHeight;
}

From source file:tv.ouya.sdk.OuyaUnityPlugin.java

public static String getStringResource(String name) {
    final Activity activity = IOuyaActivity.GetActivity();
    if (null == activity) {
        return "";
    }/*from  w w  w  .j a  v  a2s . c  o  m*/
    Resources resources = activity.getResources();
    if (null == resources) {
        return "";
    }
    int id = resources.getIdentifier(name, "string", activity.getPackageName());
    if (id <= 0) {
        return "";
    }
    return resources.getString(id);
}

From source file:com.microsoft.azure.engagement.utils.CustomTabActivityHelper.java

/**
 * Opens the URL on a Custom Tab if possible. Otherwise fallsback to opening it on a WebView.
 *
 * @param activity   The host activity./*from w  w  w.j  a  v a 2  s  .com*/
 * @param uri        The Uri to be opened.
 * @param eventName  The tracking eventName.
 * @param eventTitle The tracking eventTitle.
 * @param eventUrl   The tracking eventUrl.
 */
public static final void openCustomTab(Activity activity, Uri uri, String eventName, String eventTitle,
        String eventUrl) {
    try {
        final String packageName = CustomTabsHelper.getPackageNameToUse(activity);
        final CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        builder.setToolbarColor(ContextCompat.getColor(activity, R.color.customTabColor));
        builder.enableUrlBarHiding();
        builder.setCloseButtonIcon(
                BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_arrow_back));
        builder.setStartAnimations(activity, R.anim.slide_in_right, R.anim.slide_out_left);
        builder.setExitAnimations(activity, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
        final CustomTabsIntent customTabsIntent = builder.build();
        customTabsIntent.intent.setPackage(packageName);
        customTabsIntent.launchUrl(activity, uri);

        AzmeTracker.sendEventForCustomTab(activity, eventName, eventTitle, eventUrl);
    } catch (Exception exception) {
        Log.w(CustomTabActivityHelper.TAG, "Cannot launch the uri '" + uri + "'");
    }
}

From source file:Main.java

private static int getSmartBarHeight(Activity activity) {
    ActionBar actionbar = activity.getActionBar();
    if (actionbar != null)
        try {//  w  w w  .j ava  2  s .c  om
            Class c = Class.forName("com.android.internal.R$dimen");
            Object obj = c.newInstance();
            Field field = c.getField("mz_action_button_min_height");
            int height = Integer.parseInt(field.get(obj).toString());
            return activity.getResources().getDimensionPixelSize(height);
        } catch (Exception e) {
            e.printStackTrace();
            actionbar.getHeight();
        }
    return 0;
}

From source file:tr.com.turkcellteknoloji.turkcellupdater.Utilities.java

@SuppressLint("NewApi")
static int getScreenOrientation(Activity activity) {
    if (Build.VERSION.SDK_INT < 8) {
        switch (activity.getResources().getConfiguration().orientation) {
        case Configuration.ORIENTATION_PORTRAIT:
            return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        case Configuration.ORIENTATION_LANDSCAPE:
            return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        default://from   w  w  w .j av a2 s  .  c om
            return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
        }
    }

    int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
    DisplayMetrics dm = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    int width = dm.widthPixels;
    int height = dm.heightPixels;
    int orientation;
    // if the device's natural orientation is portrait:
    if ((rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) && height > width
            || (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) && width > height) {
        switch (rotation) {
        case Surface.ROTATION_0:
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            break;
        case Surface.ROTATION_90:
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            break;
        case Surface.ROTATION_180:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
            break;
        case Surface.ROTATION_270:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
            break;
        default:
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            break;
        }
    }
    // if the device's natural orientation is landscape or if the device
    // is square:
    else {
        switch (rotation) {
        case Surface.ROTATION_0:
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            break;
        case Surface.ROTATION_90:
            orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
            break;
        case Surface.ROTATION_180:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
            break;
        case Surface.ROTATION_270:
            orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
            break;
        default:
            orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
            break;
        }
    }

    return orientation;
}

From source file:jahirfiquitiva.iconshowcase.fragments.WallpapersFragment.java

public static void refreshWalls(Activity context) {
    hideProgressBar();/*from w ww . j  av  a  2s.c om*/
    mRecyclerView.setVisibility(View.GONE);
    fastScroller.setVisibility(View.GONE);
    if (Utils.hasNetwork(context)) {
        Utils.showSimpleSnackbar(context, layout, context.getResources().getString(R.string.refreshing_walls));
    } else {
        Utils.showSimpleSnackbar(context, layout, context.getResources().getString(R.string.no_conn_title));
    }
    mSwipeRefreshLayout.setEnabled(true);
    mSwipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            mSwipeRefreshLayout.setRefreshing(true);
        }
    });
}

From source file:com.eyekabob.util.EyekabobHelper.java

public static void launchEmail(Activity activity) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.setType("plain/text");
    String to[] = { "philj21@yahoo.com", "adam.sill01@gmail.com", "coffbr01@gmail.com" };
    emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Eyekabob Advertising");
    String label = activity.getResources().getString(R.string.write_email);
    activity.startActivity(Intent.createChooser(emailIntent, label));
}