List of usage examples for java.util TimeZone SHORT
int SHORT
To view the source code for java.util TimeZone SHORT.
Click Source Link
getDisplayName()
indicating a short name, such as "PST." From source file:com.application.utils.FastDatePrinter.java
/** * <p>Returns a list of Rules given a pattern.</p> * * @return a {@code List} of Rule objects * @throws IllegalArgumentException if pattern is invalid *///from w w w . j a va 2 s . c o m protected List<Rule> parsePattern() { final DateFormatSymbols symbols = new DateFormatSymbols(mLocale); final List<Rule> rules = new ArrayList<Rule>(); final String[] ERAs = symbols.getEras(); final String[] months = symbols.getMonths(); final String[] shortMonths = symbols.getShortMonths(); final String[] weekdays = symbols.getWeekdays(); final String[] shortWeekdays = symbols.getShortWeekdays(); final String[] AmPmStrings = symbols.getAmPmStrings(); final int length = mPattern.length(); final int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; final String token = parseToken(mPattern, indexRef); i = indexRef[0]; final int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; final char c = token.charAt(0); switch (c) { case 'G': // era designator (text) rule = new TextField(Calendar.ERA, ERAs); break; case 'y': // year (number) if (tokenLen == 2) { rule = TwoDigitYearField.INSTANCE; } else { rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen); } break; case 'M': // month in year (text and number) if (tokenLen >= 4) { rule = new TextField(Calendar.MONTH, months); } else if (tokenLen == 3) { rule = new TextField(Calendar.MONTH, shortMonths); } else if (tokenLen == 2) { rule = TwoDigitMonthField.INSTANCE; } else { rule = UnpaddedMonthField.INSTANCE; } break; case 'd': // day in month (number) rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen); break; case 'h': // hour in am/pm (number, 1..12) rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen)); break; case 'H': // hour in day (number, 0..23) rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen); break; case 'm': // minute in hour (number) rule = selectNumberRule(Calendar.MINUTE, tokenLen); break; case 's': // second in minute (number) rule = selectNumberRule(Calendar.SECOND, tokenLen); break; case 'S': // millisecond (number) rule = selectNumberRule(Calendar.MILLISECOND, tokenLen); break; case 'E': // day in week (text) rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays); break; case 'D': // day in year (number) rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen); break; case 'F': // day of week in month (number) rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen); break; case 'w': // week in year (number) rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen); break; case 'W': // week in month (number) rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen); break; case 'a': // am/pm marker (text) rule = new TextField(Calendar.AM_PM, AmPmStrings); break; case 'k': // hour in day (1..24) rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen)); break; case 'K': // hour in am/pm (0..11) rule = selectNumberRule(Calendar.HOUR, tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text final String sub = token.substring(1); if (sub.length() == 1) { rule = new CharacterLiteral(sub.charAt(0)); } else { rule = new StringLiteral(sub); } break; default: throw new IllegalArgumentException("Illegal pattern component: " + token); } rules.add(rule); } return rules; }
From source file:org.alfresco.repo.web.scripts.calendar.CalendarEntryGet.java
/** * This method replicates the pre-existing behaviour for recurring events. * Rather than try to render the text for them on the client, we instead * statically render the description text here on the server. * When we properly support recurring events in the client (and not just * for SharePoint ones), this can be replaced. *//*from w w w. j a v a 2 s . c o m*/ protected String buildRecurrenceString(CalendarEntry event) { // If there's no recurrence rules, then there's nothing to do String recurrence = event.getRecurrenceRule(); if (recurrence == null || recurrence.trim().length() == 0) { return null; } // Get our days of the week, in the current locale, for each outlook two letter code Map<String, String> days = CalendarRecurrenceHelper.buildLocalRecurrenceDaysOfTheWeek(I18NUtil.getLocale()); // Get our weeks names, in the current locale Map<Integer, String> weeks = CalendarRecurrenceHelper.buildLocalRecurrenceWeekNames(I18NUtil.getLocale()); // Turn the string into a useful map Map<String, String> params = CalendarRecurrenceHelper.extractRecurrenceRule(event); // To hold our result StringBuffer text = new StringBuffer(); // Handle the different frequencies if (params.containsKey("FREQ")) { String freq = params.get("FREQ"); String interval = params.get("INTERVAL"); if (interval == null) { interval = "1"; } if ("WEEKLY".equals(freq)) { if ("1".equals(interval)) { text.append("Occurs each week on "); } else { text.append("Occurs every " + interval + " weeks on "); } for (String day : params.get("BYDAY").split(",")) { text.append(days.get(day)); text.append(", "); } } else if ("DAILY".equals(freq)) { if ("1".equals(interval)) { text.append("Occurs every day "); } else { text.append("Occurs every " + interval + " days "); } } else if ("MONTHLY".equals(freq)) { if (params.get("BYMONTHDAY") != null) { text.append("Occurs day " + params.get("BYMONTHDAY")); } else if (params.get("BYSETPOS") != null) { text.append("Occurs the "); text.append(weeks.get((Integer.parseInt(params.get("BYSETPOS")))) + " "); buildParams(params, text, days); } text.append(" of every " + interval + " month(s) "); } else if ("YEARLY".equals(freq)) { if (params.get("BYMONTHDAY") != null) { text.append("Occurs every " + params.get("BYMONTHDAY")); text.append("." + params.get("BYMONTH") + " "); } else { text.append("Occurs the "); text.append(weeks.get((Integer.parseInt(params.get("BYSETPOS")))) + " "); buildParams(params, text, days); text.append(" of " + params.get("BYMONTH") + " month "); } } else { logger.warn("Unsupported recurrence frequency " + freq); } } // And the rest DateFormat dFormat = SimpleDateFormat.getDateInstance(SimpleDateFormat.MEDIUM, I18NUtil.getLocale()); DateFormat tFormat = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT, I18NUtil.getLocale()); text.append("effective " + dFormat.format(event.getStart())); if (params.containsKey("COUNT")) { // Nothing to do, is already handled in the recurrence date } if (event.getLastRecurrence() != null) { text.append(" until " + dFormat.format(event.getLastRecurrence())); } text.append(" from " + tFormat.format(event.getStart())); text.append(" to " + tFormat.format(event.getEnd())); // Add timezone in which recurrence rule was parsed TimeZone timeZone = TimeZone.getDefault(); boolean daylight = timeZone.inDaylightTime(new Date()); String tzDisplayName = timeZone.getDisplayName(daylight, TimeZone.SHORT); text.append(" (" + tzDisplayName + ")"); // All done return text.toString(); }
From source file:org.sqlite.date.FastDatePrinter.java
/** * <p>Returns a list of Rules given a pattern.</p> * * @return a {@code List} of Rule objects * @throws IllegalArgumentException if pattern is invalid *//*from w ww . j a v a2 s. com*/ protected List<Rule> parsePattern() { final DateFormatSymbols symbols = new DateFormatSymbols(mLocale); final List<Rule> rules = new ArrayList<Rule>(); final String[] ERAs = symbols.getEras(); final String[] months = symbols.getMonths(); final String[] shortMonths = symbols.getShortMonths(); final String[] weekdays = symbols.getWeekdays(); final String[] shortWeekdays = symbols.getShortWeekdays(); final String[] AmPmStrings = symbols.getAmPmStrings(); final int length = mPattern.length(); final int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; final String token = parseToken(mPattern, indexRef); i = indexRef[0]; final int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; final char c = token.charAt(0); switch (c) { case 'G': // era designator (text) rule = new TextField(Calendar.ERA, ERAs); break; case 'y': // year (number) if (tokenLen == 2) { rule = TwoDigitYearField.INSTANCE; } else { rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen); } break; case 'M': // month in year (text and number) if (tokenLen >= 4) { rule = new TextField(Calendar.MONTH, months); } else if (tokenLen == 3) { rule = new TextField(Calendar.MONTH, shortMonths); } else if (tokenLen == 2) { rule = TwoDigitMonthField.INSTANCE; } else { rule = UnpaddedMonthField.INSTANCE; } break; case 'd': // day in month (number) rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen); break; case 'h': // hour in am/pm (number, 1..12) rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen)); break; case 'H': // hour in day (number, 0..23) rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen); break; case 'm': // minute in hour (number) rule = selectNumberRule(Calendar.MINUTE, tokenLen); break; case 's': // second in minute (number) rule = selectNumberRule(Calendar.SECOND, tokenLen); break; case 'S': // millisecond (number) rule = selectNumberRule(Calendar.MILLISECOND, tokenLen); break; case 'E': // day in week (text) rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays); break; case 'D': // day in year (number) rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen); break; case 'F': // day of week in month (number) rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen); break; case 'w': // week in year (number) rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen); break; case 'W': // week in month (number) rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen); break; case 'a': // am/pm marker (text) rule = new TextField(Calendar.AM_PM, AmPmStrings); break; case 'k': // hour in day (1..24) rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen)); break; case 'K': // hour in am/pm (0..11) rule = selectNumberRule(Calendar.HOUR, tokenLen); break; case 'X': // ISO 8601 rule = Iso8601_Rule.getRule(tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else if (tokenLen == 2) { rule = TimeZoneNumberRule.INSTANCE_ISO_8601; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text final String sub = token.substring(1); if (sub.length() == 1) { rule = new CharacterLiteral(sub.charAt(0)); } else { rule = new StringLiteral(sub); } break; default: throw new IllegalArgumentException("Illegal pattern component: " + token); } rules.add(rule); } return rules; }
From source file:org.apache.logging.log4j.core.util.datetime.FastDatePrinter.java
/** * <p>Returns a list of Rules given a pattern.</p> * * @return a {@code List} of Rule objects * @throws IllegalArgumentException if pattern is invalid *//*from w w w . j a v a 2 s. c o m*/ protected List<Rule> parsePattern() { final DateFormatSymbols symbols = new DateFormatSymbols(mLocale); final List<Rule> rules = new ArrayList<>(); final String[] ERAs = symbols.getEras(); final String[] months = symbols.getMonths(); final String[] shortMonths = symbols.getShortMonths(); final String[] weekdays = symbols.getWeekdays(); final String[] shortWeekdays = symbols.getShortWeekdays(); final String[] AmPmStrings = symbols.getAmPmStrings(); final int length = mPattern.length(); final int[] indexRef = new int[1]; for (int i = 0; i < length; i++) { indexRef[0] = i; final String token = parseToken(mPattern, indexRef); i = indexRef[0]; final int tokenLen = token.length(); if (tokenLen == 0) { break; } Rule rule; final char c = token.charAt(0); switch (c) { case 'G': // era designator (text) rule = new TextField(Calendar.ERA, ERAs); break; case 'y': // year (number) case 'Y': // week year if (tokenLen == 2) { rule = TwoDigitYearField.INSTANCE; } else { rule = selectNumberRule(Calendar.YEAR, tokenLen < 4 ? 4 : tokenLen); } if (c == 'Y') { rule = new WeekYear((NumberRule) rule); } break; case 'M': // month in year (text and number) if (tokenLen >= 4) { rule = new TextField(Calendar.MONTH, months); } else if (tokenLen == 3) { rule = new TextField(Calendar.MONTH, shortMonths); } else if (tokenLen == 2) { rule = TwoDigitMonthField.INSTANCE; } else { rule = UnpaddedMonthField.INSTANCE; } break; case 'd': // day in month (number) rule = selectNumberRule(Calendar.DAY_OF_MONTH, tokenLen); break; case 'h': // hour in am/pm (number, 1..12) rule = new TwelveHourField(selectNumberRule(Calendar.HOUR, tokenLen)); break; case 'H': // hour in day (number, 0..23) rule = selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen); break; case 'm': // minute in hour (number) rule = selectNumberRule(Calendar.MINUTE, tokenLen); break; case 's': // second in minute (number) rule = selectNumberRule(Calendar.SECOND, tokenLen); break; case 'S': // millisecond (number) rule = selectNumberRule(Calendar.MILLISECOND, tokenLen); break; case 'E': // day in week (text) rule = new TextField(Calendar.DAY_OF_WEEK, tokenLen < 4 ? shortWeekdays : weekdays); break; case 'u': // day in week (number) rule = new DayInWeekField(selectNumberRule(Calendar.DAY_OF_WEEK, tokenLen)); break; case 'D': // day in year (number) rule = selectNumberRule(Calendar.DAY_OF_YEAR, tokenLen); break; case 'F': // day of week in month (number) rule = selectNumberRule(Calendar.DAY_OF_WEEK_IN_MONTH, tokenLen); break; case 'w': // week in year (number) rule = selectNumberRule(Calendar.WEEK_OF_YEAR, tokenLen); break; case 'W': // week in month (number) rule = selectNumberRule(Calendar.WEEK_OF_MONTH, tokenLen); break; case 'a': // am/pm marker (text) rule = new TextField(Calendar.AM_PM, AmPmStrings); break; case 'k': // hour in day (1..24) rule = new TwentyFourHourField(selectNumberRule(Calendar.HOUR_OF_DAY, tokenLen)); break; case 'K': // hour in am/pm (0..11) rule = selectNumberRule(Calendar.HOUR, tokenLen); break; case 'X': // ISO 8601 rule = Iso8601_Rule.getRule(tokenLen); break; case 'z': // time zone (text) if (tokenLen >= 4) { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.LONG); } else { rule = new TimeZoneNameRule(mTimeZone, mLocale, TimeZone.SHORT); } break; case 'Z': // time zone (value) if (tokenLen == 1) { rule = TimeZoneNumberRule.INSTANCE_NO_COLON; } else if (tokenLen == 2) { rule = Iso8601_Rule.ISO8601_HOURS_COLON_MINUTES; } else { rule = TimeZoneNumberRule.INSTANCE_COLON; } break; case '\'': // literal text final String sub = token.substring(1); if (sub.length() == 1) { rule = new CharacterLiteral(sub.charAt(0)); } else { rule = new StringLiteral(sub); } break; default: throw new IllegalArgumentException("Illegal pattern component: " + token); } rules.add(rule); } return rules; }
From source file:morphy.user.SocketChannelUserSession.java
public void send(String message) { try {//from w w w. j av a2 s. c o m /* this logic block should be commented out to get rid of multiple-login implementation. */ if (multipleLoginsParent != null) { List<SocketChannelUserSession> list = multipleLoginsParent.multipleLogins; multipleLoginsParent.multipleLogins = null; multipleLoginsParent.send(message); multipleLoginsParent.multipleLogins = list; } else { if (multipleLogins != null) { for (SocketChannelUserSession sess : multipleLogins) { if (sess != null) sess.send(message); } } } if (isConnected()) { String prompt = "fics% "; HashMap<String, String> map = getUser().getUserVars().getVariables(); if (map.containsKey("prompt") && map.containsKey("ptime") && map.containsKey("tzone")) { prompt = map.get("prompt"); boolean useptime = map.get("ptime").equals("1"); if (useptime) { Date d = new Date(); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("HH:mm"); String tzone = getUser().getUserVars().getVariables().get("tzone").toUpperCase(); TimeZone tz = TimeZone.getDefault(); if (tzone.equals("SERVER")) tzone = tz.getDisplayName(tz.inDaylightTime(d), TimeZone.SHORT); sdf.setTimeZone(TimeZoneUtils.getTimeZone(tzone)); prompt = sdf.format(d) + "_" + prompt; } } ByteBuffer buffer = BufferUtils.createBuffer( SocketConnectionService.getInstance().formatMessage(this, message + "\n" + prompt + " ")); System.out.println((message + "\n\r" + prompt + " ").replace("\n", "\\n").replace("\r", "\\r")); try { channel.write(buffer); } catch (java.io.IOException e) { Morphy.getInstance().onError("IOException while trying to write to channel.", e); } } else { if (LOG.isInfoEnabled()) { LOG.info("Tried to send message to a logged off user " + user.getUserName() + " " + message); } disconnect(); } } catch (Throwable t) { if (LOG.isErrorEnabled()) LOG.error("Error sending message to user " + user.getUserName() + " " + message, t); disconnect(); } }
From source file:org.apache.cordova.core.Globalization.java
private JSONObject getDatePattern(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); try {//from w ww. j a v a 2 s .c o m SimpleDateFormat fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getDateFormat(this.cordova.getActivity()); //default user preference for date SimpleDateFormat fmtTime = (SimpleDateFormat) android.text.format.DateFormat .getTimeFormat(this.cordova.getActivity()); //default user preference for time String fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); //default SHORT date/time format. ex. dd/MM/yyyy h:mm a //get Date value + options (if available) if (options.getJSONObject(0).has(OPTIONS)) { //options were included JSONObject innerOptions = options.getJSONObject(0).getJSONObject(OPTIONS); //get formatLength option if (!innerOptions.isNull(FORMATLENGTH)) { String fmtOpt = innerOptions.getString(FORMATLENGTH); if (fmtOpt.equalsIgnoreCase(MEDIUM)) {//medium fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getMediumDateFormat(this.cordova.getActivity()); } else if (fmtOpt.equalsIgnoreCase(LONG) || fmtOpt.equalsIgnoreCase(FULL)) { //long/full fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getLongDateFormat(this.cordova.getActivity()); } } //return pattern type fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); if (!innerOptions.isNull(SELECTOR)) { String selOpt = innerOptions.getString(SELECTOR); if (selOpt.equalsIgnoreCase(DATE)) { fmt = fmtDate.toLocalizedPattern(); } else if (selOpt.equalsIgnoreCase(TIME)) { fmt = fmtTime.toLocalizedPattern(); } } } //TimeZone from users device //TimeZone tz = Calendar.getInstance(Locale.getDefault()).getTimeZone(); //substitute method TimeZone tz = TimeZone.getTimeZone(Time.getCurrentTimezone()); obj.put("pattern", fmt); obj.put("timezone", tz.getDisplayName(tz.inDaylightTime(Calendar.getInstance().getTime()), TimeZone.SHORT)); obj.put("utc_offset", tz.getRawOffset() / 1000); obj.put("dst_offset", tz.getDSTSavings() / 1000); return obj; } catch (Exception ge) { throw new GlobalizationError(GlobalizationError.PATTERN_ERROR); } }
From source file:org.apache.cordova.Globalization.java
private JSONObject getDatePattern(JSONArray options) throws GlobalizationError { JSONObject obj = new JSONObject(); try {//from w w w .jav a 2 s . co m SimpleDateFormat fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getDateFormat(this.cordova.getActivity()); //default user preference for date SimpleDateFormat fmtTime = (SimpleDateFormat) android.text.format.DateFormat .getTimeFormat(this.cordova.getActivity()); //default user preference for time String fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); //default SHORT date/time format. ex. dd/MM/yyyy h:mm a //get Date value + options (if available) boolean test = options.getJSONObject(0).has(OPTIONS); if (options.getJSONObject(0).has(OPTIONS)) { //options were included JSONObject innerOptions = options.getJSONObject(0).getJSONObject(OPTIONS); //get formatLength option if (!innerOptions.isNull(FORMATLENGTH)) { String fmtOpt = innerOptions.getString(FORMATLENGTH); if (fmtOpt.equalsIgnoreCase(MEDIUM)) {//medium fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getMediumDateFormat(this.cordova.getActivity()); } else if (fmtOpt.equalsIgnoreCase(LONG) || fmtOpt.equalsIgnoreCase(FULL)) { //long/full fmtDate = (SimpleDateFormat) android.text.format.DateFormat .getLongDateFormat(this.cordova.getActivity()); } } //return pattern type fmt = fmtDate.toLocalizedPattern() + " " + fmtTime.toLocalizedPattern(); if (!innerOptions.isNull(SELECTOR)) { String selOpt = innerOptions.getString(SELECTOR); if (selOpt.equalsIgnoreCase(DATE)) { fmt = fmtDate.toLocalizedPattern(); } else if (selOpt.equalsIgnoreCase(TIME)) { fmt = fmtTime.toLocalizedPattern(); } } } //TimeZone from users device //TimeZone tz = Calendar.getInstance(Locale.getDefault()).getTimeZone(); //substitute method TimeZone tz = TimeZone.getTimeZone(Time.getCurrentTimezone()); obj.put("pattern", fmt); obj.put("timezone", tz.getDisplayName(tz.inDaylightTime(Calendar.getInstance().getTime()), TimeZone.SHORT)); obj.put("utc_offset", tz.getRawOffset() / 1000); obj.put("dst_offset", tz.getDSTSavings() / 1000); return obj; } catch (Exception ge) { throw new GlobalizationError(GlobalizationError.PATTERN_ERROR); } }
From source file:com.landenlabs.all_devtool.SystemFragment.java
public void updateList() { // Time today = new Time(Time.getCurrentTimezone()); // today.setToNow(); // today.format(" %H:%M:%S") Date dt = new Date(); m_titleTime.setText(m_timeFormat.format(dt)); boolean expandAll = m_list.isEmpty(); m_list.clear();/*from w w w . ja v a 2s. com*/ // Swap colors int color = m_rowColor1; m_rowColor1 = m_rowColor2; m_rowColor2 = color; ActivityManager actMgr = (ActivityManager) getActivity().getSystemService(Context.ACTIVITY_SERVICE); try { String androidIDStr = Settings.Secure.getString(getContext().getContentResolver(), Settings.Secure.ANDROID_ID); addBuild("Android ID", androidIDStr); try { AdvertisingIdClient.Info adInfo = AdvertisingIdClient.getAdvertisingIdInfo(getContext()); final String adIdStr = adInfo.getId(); final boolean isLAT = adInfo.isLimitAdTrackingEnabled(); addBuild("Ad ID", adIdStr); } catch (IOException e) { // Unrecoverable error connecting to Google Play services (e.g., // the old version of the service doesn't support getting AdvertisingId). } catch (GooglePlayServicesNotAvailableException e) { // Google Play services is not available entirely. } /* try { InstanceID instanceID = InstanceID.getInstance(getContext()); if (instanceID != null) { // Requires a Google Developer project ID. String authorizedEntity = "<need to make this on google developer site>"; instanceID.getToken(authorizedEntity, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null); addBuild("Instance ID", instanceID.getId()); } } catch (Exception ex) { } */ ConfigurationInfo info = actMgr.getDeviceConfigurationInfo(); addBuild("OpenGL", info.getGlEsVersion()); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { long heapSize = Debug.getNativeHeapSize(); // long maxHeap = Runtime.getRuntime().maxMemory(); // ConfigurationInfo cfgInfo = actMgr.getDeviceConfigurationInfo(); int largHeapMb = actMgr.getLargeMemoryClass(); int heapMb = actMgr.getMemoryClass(); MemoryInfo memInfo = new MemoryInfo(); actMgr.getMemoryInfo(memInfo); final String sFmtMB = "%.2f MB"; Map<String, String> listStr = new TreeMap<String, String>(); listStr.put("Mem Available (now)", String.format(sFmtMB, (double) memInfo.availMem / MB)); listStr.put("Mem LowWhenOnlyAvail", String.format(sFmtMB, (double) memInfo.threshold / MB)); if (Build.VERSION.SDK_INT >= 16) { listStr.put("Mem Installed", String.format(sFmtMB, (double) memInfo.totalMem / MB)); } listStr.put("Heap (this app)", String.format(sFmtMB, (double) heapSize / MB)); listStr.put("HeapMax (default)", String.format(sFmtMB, (double) heapMb)); listStr.put("HeapMax (large)", String.format(sFmtMB, (double) largHeapMb)); addBuild("Memory...", listStr); } catch (Exception ex) { m_log.e(ex.getMessage()); } try { List<ProcessErrorStateInfo> procErrList = actMgr.getProcessesInErrorState(); int errCnt = (procErrList == null ? 0 : procErrList.size()); procErrList = null; // List<RunningAppProcessInfo> procList = actMgr.getRunningAppProcesses(); int procCnt = actMgr.getRunningAppProcesses().size(); int srvCnt = actMgr.getRunningServices(100).size(); Map<String, String> listStr = new TreeMap<String, String>(); listStr.put("#Processes", String.valueOf(procCnt)); listStr.put("#Proc With Err", String.valueOf(errCnt)); listStr.put("#Services", String.valueOf(srvCnt)); // Requires special permission // int taskCnt = actMgr.getRunningTasks(100).size(); // listStr.put("#Tasks", String.valueOf(taskCnt)); addBuild("Processes...", listStr); } catch (Exception ex) { m_log.e("System-Processes %s", ex.getMessage()); } try { Map<String, String> listStr = new LinkedHashMap<String, String>(); listStr.put("LargeIconDensity", String.valueOf(actMgr.getLauncherLargeIconDensity())); listStr.put("LargeIconSize", String.valueOf(actMgr.getLauncherLargeIconSize())); putIf(listStr, "isRunningInTestHarness", "Yes", ActivityManager.isRunningInTestHarness()); putIf(listStr, "isUserAMonkey", "Yes", ActivityManager.isUserAMonkey()); addBuild("Misc...", listStr); } catch (Exception ex) { m_log.e("System-Misc %s", ex.getMessage()); } // --------------- Locale / Timezone ------------- try { Locale ourLocale = Locale.getDefault(); Date m_date = new Date(); TimeZone tz = TimeZone.getDefault(); Map<String, String> localeListStr = new LinkedHashMap<String, String>(); localeListStr.put("Locale Name", ourLocale.getDisplayName()); localeListStr.put(" Variant", ourLocale.getVariant()); localeListStr.put(" Country", ourLocale.getCountry()); localeListStr.put(" Country ISO", ourLocale.getISO3Country()); localeListStr.put(" Language", ourLocale.getLanguage()); localeListStr.put(" Language ISO", ourLocale.getISO3Language()); localeListStr.put(" Language Dsp", ourLocale.getDisplayLanguage()); localeListStr.put("TimeZoneID", tz.getID()); localeListStr.put(" DayLightSavings", tz.useDaylightTime() ? "Yes" : "No"); localeListStr.put(" In DLS", tz.inDaylightTime(m_date) ? "Yes" : "No"); localeListStr.put(" Short Name", tz.getDisplayName(false, TimeZone.SHORT, ourLocale)); localeListStr.put(" Long Name", tz.getDisplayName(false, TimeZone.LONG, ourLocale)); addBuild("Locale TZ...", localeListStr); } catch (Exception ex) { m_log.e("Locale/TZ %s", ex.getMessage()); } // --------------- Location Services ------------- try { Map<String, String> listStr = new LinkedHashMap<String, String>(); final LocationManager locMgr = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); GpsStatus gpsStatus = locMgr.getGpsStatus(null); if (gpsStatus != null) { listStr.put("Sec ToGetGPS", String.valueOf(gpsStatus.getTimeToFirstFix())); Iterable<GpsSatellite> satellites = gpsStatus.getSatellites(); Iterator<GpsSatellite> sat = satellites.iterator(); while (sat.hasNext()) { GpsSatellite satellite = sat.next(); putIf(listStr, String.format("Azm:%.0f, Elev:%.0f", satellite.getAzimuth(), satellite.getElevation()), String.format("%.2f Snr", satellite.getSnr()), satellite.usedInFix()); } } Location location = null; if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { location = locMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (null == location) location = locMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (null == location) location = locMgr.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); } if (null != location) { listStr.put(location.getProvider() + " lat,lng", String.format("%.3f, %.3f", location.getLatitude(), location.getLongitude())); } if (listStr.size() != 0) { List<String> gpsProviders = locMgr.getAllProviders(); int idx = 1; for (String providerName : gpsProviders) { LocationProvider provider = locMgr.getProvider(providerName); if (null != provider) { listStr.put(providerName, (locMgr.isProviderEnabled(providerName) ? "On " : "Off ") + String.format("Accuracy:%d Pwr:%d", provider.getAccuracy(), provider.getPowerRequirement())); } } addBuild("GPS...", listStr); } else addBuild("GPS", "Off"); } catch (Exception ex) { m_log.e(ex.getMessage()); } // --------------- Application Info ------------- ApplicationInfo appInfo = getActivity().getApplicationInfo(); if (null != appInfo) { Map<String, String> appList = new LinkedHashMap<String, String>(); try { appList.put("ProcName", appInfo.processName); appList.put("PkgName", appInfo.packageName); appList.put("DataDir", appInfo.dataDir); appList.put("SrcDir", appInfo.sourceDir); // appList.put("PkgResDir", getActivity().getPackageResourcePath()); // appList.put("PkgCodeDir", getActivity().getPackageCodePath()); String[] dbList = getActivity().databaseList(); if (dbList != null && dbList.length != 0) appList.put("DataBase", dbList[0]); // getActivity().getComponentName(). } catch (Exception ex) { } addBuild("AppInfo...", appList); } // --------------- Account Services ------------- final AccountManager accMgr = (AccountManager) getActivity().getSystemService(Context.ACCOUNT_SERVICE); if (null != accMgr) { Map<String, String> strList = new LinkedHashMap<String, String>(); try { for (Account account : accMgr.getAccounts()) { strList.put(account.name, account.type); } } catch (Exception ex) { m_log.e(ex.getMessage()); } addBuild("Accounts...", strList); } // --------------- Package Features ------------- PackageManager pm = getActivity().getPackageManager(); FeatureInfo[] features = pm.getSystemAvailableFeatures(); if (features != null) { Map<String, String> strList = new LinkedHashMap<String, String>(); for (FeatureInfo featureInfo : features) { strList.put(featureInfo.name, ""); } addBuild("Features...", strList); } // --------------- Sensor Services ------------- final SensorManager senMgr = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE); if (null != senMgr) { Map<String, String> strList = new LinkedHashMap<String, String>(); // Sensor accelerometer = senMgr.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); // senMgr.registerListener(foo, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); List<Sensor> listSensor = senMgr.getSensorList(Sensor.TYPE_ALL); try { for (Sensor sensor : listSensor) { strList.put(sensor.getName(), sensor.getVendor()); } } catch (Exception ex) { m_log.e(ex.getMessage()); } addBuild("Sensors...", strList); } try { if (Build.VERSION.SDK_INT >= 17) { final UserManager userMgr = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); if (null != userMgr) { try { addBuild("UserName", userMgr.getUserName()); } catch (Exception ex) { m_log.e(ex.getMessage()); } } } } catch (Exception ex) { } try { Map<String, String> strList = new LinkedHashMap<String, String>(); int screenTimeout = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT); strList.put("ScreenTimeOut", String.valueOf(screenTimeout / 1000)); int rotate = Settings.System.getInt(getActivity().getContentResolver(), Settings.System.ACCELEROMETER_ROTATION); strList.put("RotateEnabled", String.valueOf(rotate)); if (Build.VERSION.SDK_INT >= 17) { // Global added in API 17 int adb = Settings.Global.getInt(getActivity().getContentResolver(), Settings.Global.ADB_ENABLED); strList.put("AdbEnabled", String.valueOf(adb)); } addBuild("Settings...", strList); } catch (Exception ex) { } if (expandAll) { // updateList(); int count = m_list.size(); for (int position = 0; position < count; position++) m_listView.expandGroup(position); } m_adapter.notifyDataSetChanged(); }
From source file:com.mirth.connect.server.controllers.DefaultConfigurationController.java
@Override public String getServerTimezone(Locale locale) { TimeZone timeZone = TimeZone.getDefault(); boolean daylight = timeZone.inDaylightTime(new Date()); // Get the short timezone display name with respect to DST String timeZoneDisplay = timeZone.getDisplayName(daylight, TimeZone.SHORT, locale); // Get the offset in hours (divide by number of milliseconds in an hour) int offset = timeZone.getOffset(System.currentTimeMillis()) / (3600000); // Get the offset display in either UTC -x or UTC +x String offsetDisplay = (offset < 0) ? String.valueOf(offset) : "+" + offset; timeZoneDisplay += " (UTC " + offsetDisplay + ")"; return timeZoneDisplay; }
From source file:org.apache.oozie.servlet.BaseAdminServlet.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private static void prepareGMTOffsetTimeZones() { for (String tzId : new String[] { "GMT-12:00", "GMT-11:00", "GMT-10:00", "GMT-09:00", "GMT-08:00", "GMT-07:00", "GMT-06:00", "GMT-05:00", "GMT-04:00", "GMT-03:00", "GMT-02:00", "GMT-01:00", "GMT+01:00", "GMT+02:00", "GMT+03:00", "GMT+04:00", "GMT+05:00", "GMT+06:00", "GMT+07:00", "GMT+08:00", "GMT+09:00", "GMT+10:00", "GMT+11:00", "GMT+12:00" }) { TimeZone tz = TimeZone.getTimeZone(tzId); JSONObject json = new JSONObject(); json.put(JsonTags.TIME_ZOME_DISPLAY_NAME, tz.getDisplayName(false, TimeZone.SHORT) + " (" + tzId + ")"); json.put(JsonTags.TIME_ZONE_ID, tzId); GMTOffsetTimeZones.add(json);/* ww w . j a va 2s. co m*/ } }