Search in sources :

Example 86 with Resources

use of android.content.res.Resources in project XobotOS by xamarin.

the class IccCard method onIccSwap.

private void onIccSwap(boolean isAdded) {
    // TODO: Here we assume the device can't handle SIM hot-swap
    //      and has to reboot. We may want to add a property,
    //      e.g. REBOOT_ON_SIM_SWAP, to indicate if modem support
    //      hot-swap.
    DialogInterface.OnClickListener listener = null;
    // TODO: SimRecords is not reset while SIM ABSENT (only reset while
    //       Radio_off_or_not_available). Have to reset in both both
    //       added or removed situation.
    listener = new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mDbg)
                    log("Reboot due to SIM swap");
                PowerManager pm = (PowerManager) mPhone.getContext().getSystemService(Context.POWER_SERVICE);
                pm.reboot("SIM is added.");
            }
        }
    };
    Resources r = Resources.getSystem();
    String title = (isAdded) ? r.getString(R.string.sim_added_title) : r.getString(R.string.sim_removed_title);
    String message = (isAdded) ? r.getString(R.string.sim_added_message) : r.getString(R.string.sim_removed_message);
    String buttonTxt = r.getString(R.string.sim_restart_button);
    AlertDialog dialog = new AlertDialog.Builder(mPhone.getContext()).setTitle(title).setMessage(message).setPositiveButton(buttonTxt, listener).create();
    dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    dialog.show();
}
Also used : PowerManager(android.os.PowerManager) AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Resources(android.content.res.Resources)

Example 87 with Resources

use of android.content.res.Resources in project PhotoNoter by yydcdut.

the class AppCompat method getNavigationBarHeight.

public static int getNavigationBarHeight(Context context) {
    int navigationBarHeight = 0;
    Resources rs = context.getResources();
    int id = rs.getIdentifier("navigation_bar_height", "dimen", "android");
    if (id > 0 && hasNavigationBar(context)) {
        navigationBarHeight = rs.getDimensionPixelSize(id);
    }
    return navigationBarHeight;
}
Also used : Resources(android.content.res.Resources)

Example 88 with Resources

use of android.content.res.Resources in project XobotOS by xamarin.

the class AutoText method getInstance.

/**
     * Returns the instance of AutoText. If the locale has changed, it will create a new
     * instance of AutoText for the locale.
     * @param view to get the resources from
     * @return the single instance of AutoText
     */
private static AutoText getInstance(View view) {
    Resources res = view.getContext().getResources();
    Locale locale = res.getConfiguration().locale;
    AutoText instance;
    synchronized (sLock) {
        instance = sInstance;
        if (!locale.equals(instance.mLocale)) {
            instance = new AutoText(res);
            sInstance = instance;
        }
    }
    return instance;
}
Also used : Locale(java.util.Locale) Resources(android.content.res.Resources)

Example 89 with Resources

use of android.content.res.Resources in project XobotOS by xamarin.

the class DateUtils method getRelativeTimeSpanString.

/**
     * @return a relative time string to display the time expressed by millis.  Times
     * are counted starting at midnight, which means that assuming that the current
     * time is March 31st, 0:30:
     * <ul>
     *   <li>"millis=0:10 today" will be displayed as "0:10"</li> 
     *   <li>"millis=11:30pm the day before" will be displayed as "Mar 30"</li>
     * </ul>
     * If the given millis is in a different year, then the full date is
     * returned in numeric format (e.g., "10/12/2008").
     * 
     * @param withPreposition If true, the string returned will include the correct 
     * preposition ("at 9:20am", "on 10/12/2008" or "on May 29").
     */
public static CharSequence getRelativeTimeSpanString(Context c, long millis, boolean withPreposition) {
    String result;
    long now = System.currentTimeMillis();
    long span = now - millis;
    synchronized (DateUtils.class) {
        if (sNowTime == null) {
            sNowTime = new Time();
        }
        if (sThenTime == null) {
            sThenTime = new Time();
        }
        sNowTime.set(now);
        sThenTime.set(millis);
        int prepositionId;
        if (span < DAY_IN_MILLIS && sNowTime.weekDay == sThenTime.weekDay) {
            // Same day
            int flags = FORMAT_SHOW_TIME;
            result = formatDateRange(c, millis, millis, flags);
            prepositionId = R.string.preposition_for_time;
        } else if (sNowTime.year != sThenTime.year) {
            // Different years
            int flags = FORMAT_SHOW_DATE | FORMAT_SHOW_YEAR | FORMAT_NUMERIC_DATE;
            result = formatDateRange(c, millis, millis, flags);
            // This is a date (like "10/31/2008" so use the date preposition)
            prepositionId = R.string.preposition_for_date;
        } else {
            // Default
            int flags = FORMAT_SHOW_DATE | FORMAT_ABBREV_MONTH;
            result = formatDateRange(c, millis, millis, flags);
            prepositionId = R.string.preposition_for_date;
        }
        if (withPreposition) {
            Resources res = c.getResources();
            result = res.getString(prepositionId, result);
        }
    }
    return result;
}
Also used : Resources(android.content.res.Resources)

Example 90 with Resources

use of android.content.res.Resources in project XobotOS by xamarin.

the class DateUtils method getMonthString.

/**
     * Return a localized string for the month of the year.
     * @param month One of {@link Calendar#JANUARY Calendar.JANUARY},
     *               {@link Calendar#FEBRUARY Calendar.FEBRUARY}, etc.
     * @param abbrev One of {@link #LENGTH_LONG}, {@link #LENGTH_MEDIUM},
     *               or {@link #LENGTH_SHORTEST}.
     *               Undefined lengths will return {@link #LENGTH_MEDIUM}
     *               but may return something different in the future.
     * @return Localized month of the year.
     */
public static String getMonthString(int month, int abbrev) {
    // Note that here we use sMonthsMedium for MEDIUM, SHORT and SHORTER. 
    // This is a shortcut to not spam the translators with too many variations
    // of the same string.  If we find that in a language the distinction
    // is necessary, we can can add more without changing this API.
    int[] list;
    switch(abbrev) {
        case LENGTH_LONG:
            list = sMonthsLong;
            break;
        case LENGTH_MEDIUM:
            list = sMonthsMedium;
            break;
        case LENGTH_SHORT:
            list = sMonthsMedium;
            break;
        case LENGTH_SHORTER:
            list = sMonthsMedium;
            break;
        case LENGTH_SHORTEST:
            list = sMonthsShortest;
            break;
        default:
            list = sMonthsMedium;
            break;
    }
    Resources r = Resources.getSystem();
    return r.getString(list[month - Calendar.JANUARY]);
}
Also used : Resources(android.content.res.Resources)

Aggregations

Resources (android.content.res.Resources)3268 Context (android.content.Context)304 Intent (android.content.Intent)286 View (android.view.View)239 TextView (android.widget.TextView)217 PackageManager (android.content.pm.PackageManager)216 IOException (java.io.IOException)212 Drawable (android.graphics.drawable.Drawable)199 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)179 Paint (android.graphics.Paint)179 DisplayMetrics (android.util.DisplayMetrics)175 Bitmap (android.graphics.Bitmap)174 Configuration (android.content.res.Configuration)154 Point (android.graphics.Point)153 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)139 ArrayList (java.util.ArrayList)137 XmlResourceParser (android.content.res.XmlResourceParser)133 TypedArray (android.content.res.TypedArray)132 Test (org.junit.Test)127 PendingIntent (android.app.PendingIntent)123