use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class WallpaperManager method hasResourceWallpaper.
/**
* Return whether any users are currently set to use the wallpaper
* with the given resource ID. That is, their wallpaper has been
* set through {@link #setResource(int)} with the same resource id.
*/
public boolean hasResourceWallpaper(int resid) {
if (sGlobals.mService == null) {
Log.w(TAG, "WallpaperService not running");
return false;
}
try {
Resources resources = mContext.getResources();
String name = "res:" + resources.getResourceName(resid);
return sGlobals.mService.hasNamedWallpaper(name);
} catch (RemoteException e) {
return false;
}
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class DateUtils method getRelativeDateTimeString.
/**
* Return string describing the elapsed time since startTime formatted like
* "[relative time/date], [time]".
* <p>
* Example output strings for the US date format.
* <ul>
* <li>3 mins ago, 10:15 AM</li>
* <li>yesterday, 12:20 PM</li>
* <li>Dec 12, 4:12 AM</li>
* <li>11/14/2007, 8:20 AM</li>
* </ul>
*
* @param time some time in the past.
* @param minResolution the minimum elapsed time (in milliseconds) to report
* when showing relative times. For example, a time 3 seconds in
* the past will be reported as "0 minutes ago" if this is set to
* {@link #MINUTE_IN_MILLIS}.
* @param transitionResolution the elapsed time (in milliseconds) at which
* to stop reporting relative measurements. Elapsed times greater
* than this resolution will default to normal date formatting.
* For example, will transition from "6 days ago" to "Dec 12"
* when using {@link #WEEK_IN_MILLIS}.
*/
public static CharSequence getRelativeDateTimeString(Context c, long time, long minResolution, long transitionResolution, int flags) {
Resources r = Resources.getSystem();
long now = System.currentTimeMillis();
long duration = Math.abs(now - time);
// transitionResolution as needed.
if (transitionResolution > WEEK_IN_MILLIS) {
transitionResolution = WEEK_IN_MILLIS;
} else if (transitionResolution < DAY_IN_MILLIS) {
transitionResolution = DAY_IN_MILLIS;
}
CharSequence timeClause = formatDateRange(c, time, time, FORMAT_SHOW_TIME);
String result;
if (duration < transitionResolution) {
CharSequence relativeClause = getRelativeTimeSpanString(time, now, minResolution, flags);
result = r.getString(com.android.internal.R.string.relative_time, relativeClause, timeClause);
} else {
CharSequence dateClause = getRelativeTimeSpanString(c, time, false);
result = r.getString(com.android.internal.R.string.date_time, dateClause, timeClause);
}
return result;
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
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 = Math.abs(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;
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class TimeUtils method getTimeZones.
/**
* Returns the time zones for the country, which is the code
* attribute of the timezone element in time_zones_by_country.xml. Do not modify.
*
* @param country is a two character country code.
* @return TimeZone list, maybe empty but never null. Do not modify.
* @hide
*/
public static ArrayList<TimeZone> getTimeZones(String country) {
synchronized (sLastLockObj) {
if ((country != null) && country.equals(sLastCountry)) {
if (DBG)
Log.d(TAG, "getTimeZones(" + country + "): return cached version");
return sLastZones;
}
}
ArrayList<TimeZone> tzs = new ArrayList<TimeZone>();
if (country == null) {
if (DBG)
Log.d(TAG, "getTimeZones(null): return empty list");
return tzs;
}
Resources r = Resources.getSystem();
XmlResourceParser parser = r.getXml(com.android.internal.R.xml.time_zones_by_country);
try {
XmlUtils.beginDocument(parser, "timezones");
while (true) {
XmlUtils.nextElement(parser);
String element = parser.getName();
if (element == null || !(element.equals("timezone"))) {
break;
}
String code = parser.getAttributeValue(null, "code");
if (country.equals(code)) {
if (parser.next() == XmlPullParser.TEXT) {
String zoneIdString = parser.getText();
TimeZone tz = TimeZone.getTimeZone(zoneIdString);
if (tz.getID().startsWith("GMT") == false) {
// tz.getID doesn't start not "GMT" so its valid
tzs.add(tz);
if (DBG) {
Log.d(TAG, "getTimeZone('" + country + "'): found tz.getID==" + ((tz != null) ? tz.getID() : "<no tz>"));
}
}
}
}
}
} catch (XmlPullParserException e) {
Log.e(TAG, "Got xml parser exception getTimeZone('" + country + "'): e=", e);
} catch (IOException e) {
Log.e(TAG, "Got IO exception getTimeZone('" + country + "'): e=", e);
} finally {
parser.close();
}
synchronized (sLastLockObj) {
// Cache the last result;
sLastZones = tzs;
sLastCountry = country;
return sLastZones;
}
}
use of android.content.res.Resources in project android_frameworks_base by ParanoidAndroid.
the class ColorUtils method getComplementaryColor.
public static int getComplementaryColor(int bgcolor, Context context) {
Resources res = context.getResources();
// so we check each color individually
if (Color.red(bgcolor) < BLACK_OFFSET && Color.green(bgcolor) < BLACK_OFFSET && Color.blue(bgcolor) < BLACK_OFFSET) {
return res.getColor(R.color.holo_blue_dark);
}
int minKey = 0;
double lumDiff = 0;
double colDiff = 0;
double currValue = 0;
double minValue = -1;
for (int i = 0; i < AVAILABLE_COLORS.length; i++) {
lumDiff = COMPARATIVE_FACTOR * getLuminanceDifference(bgcolor, res.getColor(AVAILABLE_COLORS[i]));
colDiff = getColorDifference(bgcolor, res.getColor(AVAILABLE_COLORS[i]));
lumDiff = Math.abs(COMPARATIVE_NUMBER - lumDiff);
colDiff = Math.abs(COMPARATIVE_NUMBER - colDiff);
currValue = lumDiff + colDiff;
if (minValue == -1 || currValue < minValue) {
minKey = i;
minValue = currValue;
}
}
return res.getColor(AVAILABLE_COLORS[minKey]);
}
Aggregations