Example usage for android.content.res Resources getInteger

List of usage examples for android.content.res Resources getInteger

Introduction

In this page you can find the example usage for android.content.res Resources getInteger.

Prototype

public int getInteger(@IntegerRes int id) throws NotFoundException 

Source Link

Document

Return an integer associated with a particular resource ID.

Usage

From source file:Main.java

public static int getInteger(Context context, int res) {
    Resources resource = context.getResources();
    return resource.getInteger(res);
}

From source file:Main.java

public static int getMaximumScreenBrightnessSetting(Context context) {
    final Resources res = Resources.getSystem();
    final int id = res.getIdentifier("config_screenBrightnessSettingMaximum", "integer", "android"); // API17+
    if (id != 0) {
        try {/*w  ww. j  a  v  a  2  s. c o  m*/
            return res.getInteger(id);
        } catch (Resources.NotFoundException e) {
            // ignore
        }
    }
    return 255;
}

From source file:org.alfresco.mobile.android.application.fragments.DisplayUtils.java

public static int getWidth(FragmentActivity context) {
    Display display = context.getWindowManager().getDefaultDisplay();
    DisplayMetrics outMetrics = new DisplayMetrics();
    display.getMetrics(outMetrics);//from w  w w . jav a 2 s .c  om

    float density = context.getResources().getDisplayMetrics().density;
    int width = Math.round(outMetrics.widthPixels / density);

    Resources res = context.getResources();

    int coeff;
    if (width < 320) {
        coeff = res.getInteger(R.integer.width_320);
    } else if (width < 480) {
        coeff = res.getInteger(R.integer.width_480);
    } else if (width < 600) {
        coeff = res.getInteger(R.integer.width_600);
    } else if (width < 720) {
        coeff = res.getInteger(R.integer.width_720);
    } else if (width < 1000) {
        coeff = res.getInteger(R.integer.width_1000);
    } else {
        coeff = res.getInteger(R.integer.width_max);
    }

    return coeff;
}

From source file:Main.java

public static int getMinimumScreenBrightnessSetting(Context context) {
    final Resources res = Resources.getSystem();
    int id = res.getIdentifier("config_screenBrightnessSettingMinimum", "integer", "android"); // API17+
    if (id == 0)/*from   w w  w. jav a 2s  .  c  om*/
        id = res.getIdentifier("config_screenBrightnessDim", "integer", "android"); // lower API levels
    if (id != 0) {
        try {
            return res.getInteger(id);
        } catch (Resources.NotFoundException e) {
            // ignore
        }
    }
    return 0;
}

From source file:Main.java

public static Object getResource(Context context, Field field, int value) {
    Resources resources = context.getResources();
    Class type = field.getType();

    if (type.isAssignableFrom(Boolean.TYPE) || type.isAssignableFrom(Boolean.class))
        return resources.getBoolean(value);
    else if (type.isAssignableFrom(Integer.TYPE) || type.isAssignableFrom(Integer.class)) {
        return resources.getInteger(value);
    } else if (type.isAssignableFrom(ColorStateList.class))
        return resources.getColorStateList(value);
    else if (type.isAssignableFrom(XmlResourceParser.class))
        return resources.getXml(value);
    else if (type.isAssignableFrom(Float.TYPE) || type.isAssignableFrom(Float.class))
        return resources.getDimension(value);
    else if (type.isAssignableFrom(Drawable.class))
        return resources.getDrawable(value);
    else if (type.isAssignableFrom(Animation.class))
        return AnimationUtils.loadAnimation(context, value);
    else if (type.isAssignableFrom(Movie.class))
        return resources.getMovie(value);
    else if (type.isAssignableFrom(String.class))
        return resources.getString(value);
    else if (type.isArray()) {
        if (type.getName().equals("[I")) {
            return resources.getIntArray(value);
        } else if (type.isAssignableFrom(String[].class)) {
            return resources.getStringArray(value);
        }//from   w w w  .j  a  v a 2  s.c  o  m
    }

    return null;
}

From source file:com.android.mail.browse.ConversationItemViewCoordinates.java

/**
 * Returns the length (maximum of characters) of subject in this mode.
 *///from www  .  j  a v  a  2  s .c o  m
public static int getSendersLength(Context context, boolean hasAttachments) {
    final Resources res = context.getResources();
    if (hasAttachments) {
        return res.getInteger(R.integer.senders_with_attachment_lengths);
    } else {
        return res.getInteger(R.integer.senders_lengths);
    }
}

From source file:org.bottiger.podcast.utils.UIUtils.java

@TargetApi(19)
public static Transition getDefaultTransition(@NonNull Resources argResources) {
    android.support.transition.AutoTransition autoTransition = new android.support.transition.AutoTransition();
    autoTransition.setDuration(argResources.getInteger(R.integer.animation_quick));
    autoTransition.setOrdering(TransitionSet.ORDERING_TOGETHER);
    return autoTransition;
}

From source file:jahirfiquitiva.iconshowcase.utilities.utils.NotificationUtils.java

public static void sendFirebaseNotification(Context context, Class mainActivity, Map<String, String> data,
        String title, String content) {
    Preferences mPrefs = new Preferences(context);
    if (!(mPrefs.getNotifsEnabled()))
        return;// w  w w.ja  v a  2 s .  c o  m

    int ledColor = ThemeUtils.darkOrLight(context, R.color.dark_theme_accent, R.color.light_theme_accent);

    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.ic_notifications).setContentTitle(title).setTicker(title)
            .setContentText(content).setAutoCancel(true).setOngoing(false).setColor(ledColor);

    Intent intent = new Intent();
    int flag = 0;
    if (mPrefs.getLauncherIconShown()) {
        intent = new Intent(context, mainActivity);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (data != null) {
            if (data.size() > 0) {
                for (int i = 0; i < data.size(); i++) {
                    String[] dataValue = data.toString().replace("{", "").replace("}", "").split(",")[i]
                            .split("=");
                    Timber.d("Key: " + dataValue[0] + " - Value: " + dataValue[1]);
                    intent.putExtra(dataValue[0], dataValue[1]);
                }
            }
        }
        flag = PendingIntent.FLAG_ONE_SHOT;
    }
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0 /* Request code
                                                                       */, intent, flag);
    notificationBuilder.setContentIntent(pendingIntent);

    Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    Resources resources = context.getResources(), systemResources = Resources.getSystem();

    notificationBuilder.setSound(mPrefs.getNotifsSoundEnabled() ? ringtoneUri : null);
    notificationBuilder.setVibrate(mPrefs.getNotifsVibrationEnabled() ? new long[] { 500, 500 } : null);

    NotificationManager notificationManager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);

    Notification notification = notificationBuilder.build();

    if (mPrefs.getNotifsEnabled()) {
        notification.flags |= Notification.FLAG_SHOW_LIGHTS;
        notification.ledARGB = ledColor;
        notification.ledOnMS = resources.getInteger(
                systemResources.getIdentifier("config_defaultNotificationLedOn", "integer", "android"));
        notification.ledOffMS = resources.getInteger(
                systemResources.getIdentifier("config_defaultNotificationLedOff", "integer", "android"));
    } else {
        notification.ledOnMS = 0;
        notification.ledOffMS = 0;
    }

    notificationManager.notify(1 /* ID of notification */, notificationBuilder.build());
}

From source file:org.xbmc.kore.utils.UIUtils.java

/**
 * Fills the standard cast info list, consisting of a {@link android.widget.GridLayout}
 * with actor images and a Textview with the name and the role of the additional cast.
 * The number of actor presented on the {@link android.widget.GridLayout} is controlled
 * through the global setting, and only actors with images are presented.
 * The rest are presented in the additionalCastView TextView
 *
 * @param activity Activity//from   ww  w  .  j a v a2  s .  com
 * @param castList Cast list
 * @param castListView GridLayout on which too show actors that have images
 */
public static void setupCastInfo(final Activity activity, List<VideoType.Cast> castList,
        GridLayout castListView, final Intent allCastActivityLaunchIntent) {
    HostManager hostManager = HostManager.getInstance(activity);
    Resources resources = activity.getResources();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager windowManager = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
    windowManager.getDefaultDisplay().getMetrics(displayMetrics);

    View.OnClickListener castListClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Utils.openImdbForPerson(activity, (String) v.getTag());
        }
    };

    castListView.removeAllViews();
    int numColumns = castListView.getColumnCount();
    int numRows = resources.getInteger(R.integer.cast_grid_view_rows);
    int maxCastPictures = numColumns * numRows;

    int layoutMarginPx = 2 * resources.getDimensionPixelSize(R.dimen.remote_content_hmargin);
    int imageMarginPx = 2 * resources.getDimensionPixelSize(R.dimen.image_grid_margin);
    int imageWidth = (displayMetrics.widthPixels - layoutMarginPx - numColumns * imageMarginPx) / numColumns;
    int imageHeight = (int) (imageWidth * 1.5);

    for (int i = 0; i < Math.min(castList.size(), maxCastPictures); i++) {
        VideoType.Cast actor = castList.get(i);

        View castView = LayoutInflater.from(activity).inflate(R.layout.grid_item_cast, castListView, false);
        ImageView castPicture = (ImageView) castView.findViewById(R.id.picture);
        TextView castName = (TextView) castView.findViewById(R.id.name);
        TextView castRole = (TextView) castView.findViewById(R.id.role);

        castView.getLayoutParams().width = imageWidth;
        castView.getLayoutParams().height = imageHeight;
        castView.setTag(actor.name);

        UIUtils.loadImageWithCharacterAvatar(activity, hostManager, actor.thumbnail, actor.name, castPicture,
                imageWidth, imageHeight);

        if ((i == maxCastPictures - 1) && (castList.size() > i + 1)) {
            View castNameGroup = castView.findViewById(R.id.cast_name_group);
            View allCastGroup = castView.findViewById(R.id.all_cast_group);
            TextView remainingCastCount = (TextView) castView.findViewById(R.id.remaining_cast_count);

            castNameGroup.setVisibility(View.GONE);
            allCastGroup.setVisibility(View.VISIBLE);
            remainingCastCount.setText(String.format(activity.getString(R.string.remaining_cast_count),
                    castList.size() - maxCastPictures + 1));
            castView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    activity.startActivity(allCastActivityLaunchIntent);
                    activity.overridePendingTransition(R.anim.activity_in, R.anim.activity_out);
                }
            });
        } else {
            castName.setText(actor.name);
            castRole.setText(actor.role);
            castView.setOnClickListener(castListClickListener);
        }

        castListView.addView(castView);
    }
}

From source file:org.namelessrom.devicecontrol.Application.java

private void dumpInformation() {
    if (!Logger.getEnabled()) {
        return;/*from   www .j  a  v  a2s  . co m*/
    }

    final Resources res = getResources();
    final int gmsVersion = res.getInteger(R.integer.google_play_services_version);
    Logger.i(this, "Google Play Services -> %s", gmsVersion);
}