List of usage examples for java.util TimeZone getID
public String getID()
From source file:org.sakaiproject.calendar.impl.RecurrenceRuleBase.java
/** * Return a List of all RecurrenceInstance objects generated by this rule within the given time range, based on the * prototype first range, in time order.// w w w . j av a 2 s.c o m * @param prototype The prototype first TimeRange. * @param range A time range to limit the generated ranges. * @param timeZone The time zone to use for displaying times. * %%% Note: this is currently not implemented, and always uses the "local" zone. * @return a List of RecurrenceInstance generated by this rule in this range. */ public List generateInstances(TimeRange prototype, TimeRange range, TimeZone timeZone) { // these calendars are used if local time zone and the time zone where the first event was created (timeZone) are different GregorianCalendar firstEventCalendarDate = null; GregorianCalendar nextFirstEventCalendarDate = null; // %%% Note: base the breakdonw on the "timeZone" parameter to support multiple timeZone displays -ggolden TimeBreakdown startBreakdown = prototype.firstTime().breakdownLocal(); GregorianCalendar startCalendarDate = TimeService.getCalendar(TimeService.getLocalTimeZone(), 0, 0, 0, 0, 0, 0, 0); startCalendarDate.set(startBreakdown.getYear(), startBreakdown.getMonth() - 1, startBreakdown.getDay(), startBreakdown.getHour(), startBreakdown.getMin(), startBreakdown.getSec()); // if local time zone and first event time zone are different // a new calendar is generated to calculate the re-occurring events // if not, the local time zone calendar is used boolean differentTimeZone = false; if (TimeService.getLocalTimeZone().getID().equals(timeZone.getID())) { differentTimeZone = false; } else { differentTimeZone = true; } if (differentTimeZone) { firstEventCalendarDate = TimeService.getCalendar(timeZone, 0, 0, 0, 0, 0, 0, 0); firstEventCalendarDate.setTimeInMillis(startCalendarDate.getTimeInMillis()); nextFirstEventCalendarDate = (GregorianCalendar) firstEventCalendarDate.clone(); } List rv = new Vector(); GregorianCalendar nextCalendarDate = (GregorianCalendar) startCalendarDate.clone(); int currentCount = 1; do { if (differentTimeZone) { // next time is calculated according to the first event time zone, not the local one nextCalendarDate.setTimeInMillis(nextFirstEventCalendarDate.getTimeInMillis()); } Time nextTime = TimeService.newTime(nextCalendarDate); // is this past count? if ((getCount() > 0) && (currentCount > getCount())) break; // is this past until? if ((getUntil() != null) && isAfter(nextTime, getUntil())) break; TimeRange nextTimeRange = TimeService.newTimeRange(nextTime.getTime(), prototype.duration()); // // Is this out of the range? // if (isOverlap(range, nextTimeRange)) { TimeRange eventTimeRange = null; // Single time cases require special handling. if (prototype.isSingleTime()) { eventTimeRange = TimeService.newTimeRange(nextTimeRange.firstTime()); } else { eventTimeRange = TimeService.newTimeRange(nextTimeRange.firstTime(), nextTimeRange.lastTime(), true, false); } // use this one rv.add(new RecurrenceInstance(eventTimeRange, currentCount)); } // if next starts after the range, stop generating else if (isAfter(nextTime, range.lastTime())) break; // advance interval years. if (differentTimeZone) { nextFirstEventCalendarDate = (GregorianCalendar) firstEventCalendarDate.clone(); nextFirstEventCalendarDate.add(getRecurrenceType(), getInterval() * currentCount); } else { nextCalendarDate = (GregorianCalendar) startCalendarDate.clone(); nextCalendarDate.add(getRecurrenceType(), getInterval() * currentCount); } currentCount++; } while (true); return rv; }
From source file:org.osaf.cosmo.service.account.OutOfTheBoxHelper.java
private NoteItem makeTryOutItem(OutOfTheBoxContext context) { NoteItem item = entityFactory.createNote(); TimeZone tz = context.getTimeZone(); Locale locale = context.getLocale(); User user = context.getUser();// w w w . j a v a2s . c om String name = _("Ootb.TryOut.Title", locale); String body = _("Ootb.TryOut.Body", locale); TriageStatus triage = entityFactory.createTriageStatus(); TriageStatusUtil.initialize(triage); triage.setCode(TriageStatus.CODE_LATER); item.setUid(contentDao.generateUid()); item.setDisplayName(name); item.setOwner(user); item.setClientCreationDate(Calendar.getInstance(tz, locale).getTime()); item.setClientModifiedDate(item.getClientCreationDate()); item.setTriageStatus(triage); item.setLastModifiedBy(user.getUsername()); item.setLastModification(ContentItem.Action.CREATED); item.setSent(Boolean.FALSE); item.setNeedsReply(Boolean.FALSE); item.setIcalUid(item.getUid()); item.setBody(body); Calendar start = Calendar.getInstance(tz, locale); start.add(Calendar.DAY_OF_MONTH, 1); start.set(Calendar.HOUR_OF_DAY, 10); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); DateTime startDate = (DateTime) Dates.getInstance(start.getTime(), Value.DATE_TIME); startDate.setTimeZone(vtz(tz.getID())); EventStamp es = entityFactory.createEventStamp(item); item.addStamp(es); es.createCalendar(); es.setStartDate(startDate); es.setDuration(new Dur(0, 1, 0, 0)); TaskStamp ts = entityFactory.createTaskStamp(); item.addStamp(ts); return item; }
From source file:org.unitedinternet.cosmo.service.account.OutOfTheBoxHelper.java
private NoteItem makeTryOutItem(OutOfTheBoxContext context) { NoteItem item = entityFactory.createNote(); TimeZone tz = context.getTimezone(); Locale locale = context.getLocale(); User user = context.getUser();// w w w. j a va2 s.c o m String name = "Download Chandler Desktop"; String body = "Learn more @ chandlerproject.org\n\nDownload @ chandlerproject.org/download"; TriageStatus triage = entityFactory.createTriageStatus(); TriageStatusUtil.initialize(triage); triage.setCode(TriageStatus.CODE_LATER); item.setUid(contentDao.generateUid()); item.setDisplayName(name); item.setOwner(user); item.setClientCreationDate(Calendar.getInstance(tz, locale).getTime()); item.setClientModifiedDate(item.getClientCreationDate()); item.setTriageStatus(triage); item.setLastModifiedBy(user.getUsername()); item.setLastModification(ContentItem.Action.CREATED); item.setSent(Boolean.FALSE); item.setNeedsReply(Boolean.FALSE); item.setIcalUid(item.getUid()); item.setBody(body); Calendar start = Calendar.getInstance(tz, locale); start.add(Calendar.DAY_OF_MONTH, 1); start.set(Calendar.HOUR_OF_DAY, 10); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); DateTime startDate = (DateTime) Dates.getInstance(start.getTime(), Value.DATE_TIME); startDate.setTimeZone(vtz(tz.getID())); EventStamp es = entityFactory.createEventStamp(item); item.addStamp(es); es.createCalendar(); es.setStartDate(startDate); es.setDuration(new Dur(0, 1, 0, 0)); TaskStamp ts = entityFactory.createTaskStamp(); item.addStamp(ts); return item; }
From source file:org.osaf.cosmo.service.account.OutOfTheBoxHelper.java
private NoteItem makeWelcomeItem(OutOfTheBoxContext context) { NoteItem item = entityFactory.createNote(); TimeZone tz = context.getTimeZone(); Locale locale = context.getLocale(); User user = context.getUser();/*from w w w. j a va2 s. co m*/ String name = _("Ootb.Welcome.Title", locale); String body = _("Ootb.Welcome.Body", locale); String from = _("Ootb.Welcome.From", locale); String sentBy = _("Ootb.Welcome.SentBy", locale); String to = _("Ootb.Welcome.To", locale, user.getFirstName(), user.getLastName(), user.getUsername()); item.setUid(contentDao.generateUid()); item.setDisplayName(name); item.setOwner(user); item.setClientCreationDate(Calendar.getInstance(tz, locale).getTime()); item.setClientModifiedDate(item.getClientCreationDate()); TriageStatus triage = entityFactory.createTriageStatus(); TriageStatusUtil.initialize(triage); item.setTriageStatus(triage); item.setLastModifiedBy(user.getUsername()); item.setLastModification(ContentItem.Action.CREATED); item.setSent(Boolean.FALSE); item.setNeedsReply(Boolean.FALSE); item.setIcalUid(item.getUid()); item.setBody(body); Calendar start = Calendar.getInstance(tz, locale); start.set(Calendar.MINUTE, 0); start.set(Calendar.SECOND, 0); DateTime startDate = (DateTime) Dates.getInstance(start.getTime(), Value.DATE_TIME); startDate.setTimeZone(vtz(tz.getID())); EventStamp es = entityFactory.createEventStamp(item); item.addStamp(es); es.createCalendar(); es.setStartDate(startDate); es.setDuration(new Dur(0, 1, 0, 0)); TaskStamp ts = entityFactory.createTaskStamp(); item.addStamp(ts); MessageStamp ms = entityFactory.createMessageStamp(); item.addStamp(ms); ms.setFrom(from); ms.setTo(to); ms.setOriginators(sentBy); ms.setDateSent(DateUtil.formatDate(MessageStamp.FORMAT_DATE_SENT, item.getClientCreationDate())); return item; }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChart.java
/** * Make the plot/* ww w. jav a 2s .c om*/ * * @return The plot_ */ public Plot doMakePlot() { IdvPreferenceManager pref = control.getControlContext().getIdv().getPreferenceManager(); TimeZone timeZone = pref.getDefaultTimeZone(); NumberAxis valueAxis = new FixedWidthNumberAxis(""); final SimpleDateFormat sdf = new SimpleDateFormat( ((dateFormat != null) ? dateFormat : pref.getDefaultDateFormat())); sdf.setTimeZone(timeZone); DateAxis timeAxis = new DateAxis("Time (" + timeZone.getID() + ")", timeZone) { protected List xxxxxrefreshTicksHorizontal(Graphics2D g2, Rectangle2D dataArea, RectangleEdge edge) { List ticks = super.refreshTicksHorizontal(g2, dataArea, edge); List<Tick> result = new java.util.ArrayList<Tick>(); Font tickLabelFont = getTickLabelFont(); g2.setFont(tickLabelFont); if (isAutoTickUnitSelection()) { selectAutoTickUnit(g2, dataArea, edge); } DateTickUnit unit = getTickUnit(); Date tickDate = calculateLowestVisibleTickValue(unit); Date upperDate = getMaximumDate(); Date firstDate = null; while (tickDate.before(upperDate)) { if (!isHiddenValue(tickDate.getTime())) { // work out the value, label and position String tickLabel; DateFormat formatter = getDateFormatOverride(); if (firstDate == null) { if (formatter != null) { tickLabel = formatter.format(tickDate); } else { tickLabel = getTickUnit().dateToString(tickDate); } firstDate = tickDate; } else { double msdiff = tickDate.getTime() - firstDate.getTime(); int hours = (int) (msdiff / 1000 / 60 / 60); tickLabel = hours + "H"; } // tickLabel = tickLabel; TextAnchor anchor = null; TextAnchor rotationAnchor = null; double angle = 0.0; if (isVerticalTickLabels()) { anchor = TextAnchor.CENTER_RIGHT; rotationAnchor = TextAnchor.CENTER_RIGHT; if (edge == RectangleEdge.TOP) { angle = Math.PI / 2.0; } else { angle = -Math.PI / 2.0; } } else { if (edge == RectangleEdge.TOP) { anchor = TextAnchor.BOTTOM_CENTER; rotationAnchor = TextAnchor.BOTTOM_CENTER; } else { anchor = TextAnchor.TOP_CENTER; rotationAnchor = TextAnchor.TOP_CENTER; } } Tick tick = new DateTick(tickDate, tickLabel, anchor, rotationAnchor, angle); result.add(tick); tickDate = unit.addToDate(tickDate, getTimeZone()); } else { tickDate = unit.rollDate(tickDate, getTimeZone()); continue; } // could add a flag to make the following correction optional... switch (unit.getUnit()) { case (DateTickUnit.MILLISECOND): case (DateTickUnit.SECOND): case (DateTickUnit.MINUTE): case (DateTickUnit.HOUR): case (DateTickUnit.DAY): break; case (DateTickUnit.MONTH): tickDate = calculateDateForPositionX(new Month(tickDate, getTimeZone()), getTickMarkPosition()); break; case (DateTickUnit.YEAR): tickDate = calculateDateForPositionX(new Year(tickDate, getTimeZone()), getTickMarkPosition()); break; default: break; } } return result; } private Date calculateDateForPositionX(RegularTimePeriod period, DateTickMarkPosition position) { if (position == null) { throw new IllegalArgumentException("Null 'position' argument."); } Date result = null; if (position == DateTickMarkPosition.START) { result = new Date(period.getFirstMillisecond()); } else if (position == DateTickMarkPosition.MIDDLE) { result = new Date(period.getMiddleMillisecond()); } else if (position == DateTickMarkPosition.END) { result = new Date(period.getLastMillisecond()); } return result; } }; timeAxis.setDateFormatOverride(sdf); final XYPlot[] xyPlotHolder = { null }; xyPlotHolder[0] = new MyXYPlot(new TimeSeriesCollection(), timeAxis, valueAxis, null) { public void drawBackground(Graphics2D g2, Rectangle2D area) { super.drawBackground(g2, area); drawSunriseSunset(g2, xyPlotHolder[0], area); } }; if (animationTimeAnnotation != null) { xyPlotHolder[0].addAnnotation(animationTimeAnnotation); } return xyPlotHolder[0]; }
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 . j a va 2s. c o m*/ // 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:hudson.plugins.dimensionsscm.DimensionsSCM.java
@Override public boolean pollChanges(final AbstractProject project, final Launcher launcher, final FilePath workspace, final TaskListener listener) throws IOException, InterruptedException { boolean bChanged = false; Logger.Debug("Invoking pollChanges - " + this.getClass().getName()); Logger.Debug("Checking job - " + project.getName()); long key = -1; if (getProject() == null || getProject().length() == 0) return false; if (project.getLastBuild() == null) return true; try {// ww w .j av a2 s . c o m Calendar lastBuildCal = null; if (project.getLastSuccessfulBuild() != null && project.getLastSuccessfulBuild().getTimestamp() != null) lastBuildCal = project.getLastSuccessfulBuild().getTimestamp(); else lastBuildCal = project.getLastBuild().getTimestamp(); Calendar nowDateCal = Calendar.getInstance(); TimeZone tz = (getJobTimeZone() != null && getJobTimeZone().length() > 0) ? TimeZone.getTimeZone(getJobTimeZone()) : TimeZone.getDefault(); if (getJobTimeZone() != null && getJobTimeZone().length() > 0) Logger.Debug("Job timezone setting is " + getJobTimeZone()); Logger.Debug("Checking for any updates between " + ((lastBuildCal != null) ? DateUtils.getStrDate(lastBuildCal, tz) : "0") + " -> " + DateUtils.getStrDate(nowDateCal, tz) + " (" + tz.getID() + ")"); if (dmSCM == null) { Logger.Debug("Creating new API interface object"); dmSCM = new DimensionsAPI(); } dmSCM.setLogger(listener.getLogger()); // Connect to Dimensions... key = dmSCM.login(jobUserName, getJobPasswd(), jobDatabase, jobServer); if (key > 0) { String[] folders = getFolders(); // Iterate through the project folders and process them in Dimensions for (int ii = 0; ii < folders.length; ii++) { if (bChanged) break; String folderN = folders[ii]; File fileName = new File(folderN); FilePath dname = new FilePath(fileName); Logger.Debug("Polling using key " + key); Logger.Debug("Polling '" + folderN + "'..."); bChanged = dmSCM.hasRepositoryBeenUpdated(key, getProject(), dname, lastBuildCal, nowDateCal, tz); } } } catch (Exception e) { String errMsg = e.getMessage(); if (errMsg == null) { errMsg = "An unknown error occurred. Please try the operation again."; } listener.fatalError("Unable to run pollChanges callout - " + errMsg); // e.printStackTrace(); //throw new IOException("Unable to run pollChanges callout - " + e.getMessage()); bChanged = false; } finally { dmSCM.logout(key); } if (bChanged) Logger.Debug("Polling returned true"); return bChanged; }
From source file:ucar.unidata.idv.control.chart.TimeSeriesChartWrapper.java
/** * Utility to create the DataAxis with the correct time zone * * @return data axis with timezone/* w ww . j a va 2 s. co m*/ */ private DateAxis doMakeDateAxis() { TimeZone timeZone = displayControl.getControlContext().getIdv().getPreferenceManager().getDefaultTimeZone(); return new DateAxis("Time (" + timeZone.getID() + ")", timeZone); }
From source file:hudson.plugins.dimensionsscm.DimensionsSCM.java
private boolean generateChangeSet(final AbstractBuild build, final BuildListener listener, final File changelogFile) throws IOException, InterruptedException { long key = -1; boolean bRet = false; DimensionsAPI dmSCM = new DimensionsAPI(); try {//ww w. ja v a 2 s .c o m // When are we building files for? // Looking for the last successful build and then going forward from there - could use the last build as well // // Calendar lastBuildCal = (build.getPreviousBuild() != null) ? build.getPreviousBuild().getTimestamp() : null; Calendar lastBuildCal = (build.getPreviousNotFailedBuild() != null) ? build.getPreviousNotFailedBuild().getTimestamp() : null; Calendar nowDateCal = Calendar.getInstance(); TimeZone tz = (getJobTimeZone() != null && getJobTimeZone().length() > 0) ? TimeZone.getTimeZone(getJobTimeZone()) : TimeZone.getDefault(); if (getJobTimeZone() != null && getJobTimeZone().length() > 0) Logger.Debug("Job timezone setting is " + getJobTimeZone()); Logger.Debug( "Log updates between " + ((lastBuildCal != null) ? DateUtils.getStrDate(lastBuildCal, tz) : "0") + " -> " + DateUtils.getStrDate(nowDateCal, tz) + " (" + tz.getID() + ")"); dmSCM.setLogger(listener.getLogger()); // Connect to Dimensions... key = dmSCM.login(getJobUserName(), getJobPasswd(), getJobDatabase(), getJobServer()); if (key > 0) { Logger.Debug("Login worked."); VariableResolver<String> myResolver = build.getBuildVariableResolver(); String baseline = myResolver.resolve("DM_BASELINE"); String requests = myResolver.resolve("DM_REQUEST"); if (baseline != null) { baseline = baseline.trim(); baseline = baseline.toUpperCase(); } if (requests != null) { requests = requests.replaceAll(" ", ""); requests = requests.toUpperCase(); } Logger.Debug("Extra parameters - " + baseline + " " + requests); String[] folders = getFolders(); if (baseline != null && baseline.length() == 0) baseline = null; if (requests != null && requests.length() == 0) requests = null; bRet = true; // Iterate through the project folders and process them in Dimensions for (int ii = 0; ii < folders.length; ii++) { if (!bRet) break; String folderN = folders[ii]; File fileName = new File(folderN); FilePath dname = new FilePath(fileName); Logger.Debug("Looking for changes in '" + folderN + "'..."); // Checkout the folder bRet = dmSCM.createChangeSetLogs(key, getProject(), dname, lastBuildCal, nowDateCal, changelogFile, tz, jobWebUrl, baseline, requests); if (requests != null) break; } // Close the changes log file { FileWriter logFile = null; try { logFile = new FileWriter(changelogFile, true); PrintWriter fmtWriter = new PrintWriter(logFile); fmtWriter.println("</changelog>"); logFile.flush(); bRet = true; } catch (Exception e) { throw new IOException("Unable to write change log - " + e.getMessage()); } finally { logFile.close(); } } } } catch (Exception e) { String errMsg = e.getMessage(); if (errMsg == null) { errMsg = "An unknown error occurred. Please try the operation again."; } listener.fatalError("Unable to run change set callout - " + errMsg); // e.printStackTrace(); //throw new IOException("Unable to run change set callout - " + e.getMessage()); bRet = false; } finally { dmSCM.logout(key); } return bRet; }
From source file:com.github.hipchat.api.HipChat.java
public User updateUser(UserId id, String email, String name, String title, boolean isGroupAdmin, String password, TimeZone timeZone) { String query = String.format(HipChatConstants.USERS_CREATE_QUERY_FORMAT, HipChatConstants.JSON_FORMAT, authToken);//www . j a v a 2s.c o m StringBuilder params = new StringBuilder(); if (id == null) { throw new IllegalArgumentException("updateUser: id cannot be null"); } else { params.append("user_id="); params.append(id.getId()); } if (email != null) { params.append("&email="); params.append(email); } if (name != null) { if (!name.contains(" ")) { throw new IllegalArgumentException( "updateUser: name must contain a space separating first and last name"); } else { params.append("&name="); params.append(name); } } if (title != null) { params.append("&title="); params.append(title); } if (isGroupAdmin) { params.append("&is_group_admin=1"); } else { params.append("&is_group_admin=0"); } if (password != null) { params.append("&password="); params.append(password); } if (timeZone != null) { String tz = timeZone.getID(); params.append("&timezone="); params.append(tz); } final String paramsToSend = params.toString(); OutputStream output = null; InputStream input = null; HttpURLConnection connection = null; User result = null; try { URL requestUrl = getRequestUrl(HipChatConstants.API_BASE, HipChatConstants.USERS_UPDATE, query); connection = getPostConnection(requestUrl, paramsToSend); output = new BufferedOutputStream(connection.getOutputStream()); IOUtils.write(paramsToSend, output); IOUtils.closeQuietly(output); input = connection.getInputStream(); result = UserParser.parseUser(this, input); } catch (IOException e) { LogMF.error(logger, "IO Exception: {0}", new Object[] { e.getMessage() }); } finally { IOUtils.closeQuietly(input); connection.disconnect(); } return result; }