List of usage examples for org.joda.time LocalTime now
public static LocalTime now()
ISOChronology
in the default time zone. From source file:act.apidoc.Endpoint.java
License:Apache License
private Object generateSampleData(BeanSpec spec, Set<Type> typeChain, List<String> nameChain) { Type type = spec.type();/*w ww.j a va2 s .co m*/ if (typeChain.contains(type) && !isCollection(type)) { return S.concat(spec.name(), ":", type); // circular reference detected } typeChain.add(type); String name = spec.name(); if (S.notBlank(name)) { nameChain.add(name); } if (null != fastJsonPropertyPreFilter) { String path = S.join(nameChain).by(".").get(); if (!fastJsonPropertyPreFilter.matches(path)) { return null; } } Class<?> classType = spec.rawType(); try { if (void.class == classType || Void.class == classType || Result.class.isAssignableFrom(classType)) { return null; } if (Object.class == classType) { return "<Any>"; } try { if (classType.isEnum()) { Object[] ea = classType.getEnumConstants(); int len = ea.length; return 0 < len ? ea[N.randInt(len)] : null; } else if (Locale.class == classType) { return (defLocale); } else if (String.class == classType) { String mockValue = S.random(5); if (spec.hasAnnotation(Sensitive.class)) { return Act.crypto().encrypt(mockValue); } return S.random(5); } else if (classType.isArray()) { Object sample = Array.newInstance(classType.getComponentType(), 2); Array.set(sample, 0, generateSampleData(BeanSpec.of(classType.getComponentType(), Act.injector()), C.newSet(typeChain), C.newList(nameChain))); Array.set(sample, 1, generateSampleData(BeanSpec.of(classType.getComponentType(), Act.injector()), C.newSet(typeChain), C.newList(nameChain))); return sample; } else if ($.isSimpleType(classType)) { if (Enum.class == classType) { return "<Any Enum>"; } if (!classType.isPrimitive()) { classType = $.primitiveTypeOf(classType); } return StringValueResolver.predefined().get(classType).resolve(null); } else if (LocalDateTime.class.isAssignableFrom(classType)) { return LocalDateTime.now(); } else if (DateTime.class.isAssignableFrom(classType)) { return DateTime.now(); } else if (LocalDate.class.isAssignableFrom(classType)) { return LocalDate.now(); } else if (LocalTime.class.isAssignableFrom(classType)) { return LocalTime.now(); } else if (Date.class.isAssignableFrom(classType)) { return new Date(); } else if (classType.getName().contains(".ObjectId")) { return "<id>"; } else if (BigDecimal.class == classType) { return BigDecimal.valueOf(1.1); } else if (BigInteger.class == classType) { return BigInteger.valueOf(1); } else if (ISObject.class.isAssignableFrom(classType)) { return null; } else if (Map.class.isAssignableFrom(classType)) { Map map = $.cast(Act.getInstance(classType)); List<Type> typeParams = spec.typeParams(); if (typeParams.isEmpty()) { typeParams = Generics.typeParamImplementations(classType, Map.class); } if (typeParams.size() < 2) { map.put(S.random(), S.random()); map.put(S.random(), S.random()); } else { Type keyType = typeParams.get(0); Type valType = typeParams.get(1); map.put(generateSampleData(BeanSpec.of(keyType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain)), generateSampleData(BeanSpec.of(valType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain))); map.put(generateSampleData(BeanSpec.of(keyType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain)), generateSampleData(BeanSpec.of(valType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain))); } } else if (Iterable.class.isAssignableFrom(classType)) { Collection col = $.cast(Act.getInstance(classType)); List<Type> typeParams = spec.typeParams(); if (typeParams.isEmpty()) { typeParams = Generics.typeParamImplementations(classType, Map.class); } if (typeParams.isEmpty()) { col.add(S.random()); } else { Type componentType = typeParams.get(0); col.add(generateSampleData(BeanSpec.of(componentType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain))); col.add(generateSampleData(BeanSpec.of(componentType, null, Act.injector()), C.newSet(typeChain), C.newList(nameChain))); } return col; } if (null != stringValueResolver(classType)) { return S.random(5); } Object obj = Act.getInstance(classType); List<Field> fields = $.fieldsOf(classType); for (Field field : fields) { if (Modifier.isStatic(field.getModifiers())) { continue; } if (ParamValueLoaderService.shouldWaive(field)) { continue; } Class<?> fieldType = field.getType(); Object val = null; try { field.setAccessible(true); val = generateSampleData(BeanSpec.of(field, Act.injector()), C.newSet(typeChain), C.newList(nameChain)); Class<?> valType = null == val ? null : val.getClass(); if (null != valType && fieldType.isAssignableFrom(valType)) { field.set(obj, val); } } catch (Exception e) { LOGGER.warn("Error setting value[%s] to field[%s.%s]", val, classType.getSimpleName(), field.getName()); } } return obj; } catch (Exception e) { LOGGER.warn("error generating sample data for type: %s", classType); return null; } } finally { //typeChain.remove(classType); } }
From source file:ch.eitchnet.android.mabea.MabeaConnection.java
License:Open Source License
/** * @param stateChange/*from www . java2s . c om*/ * @param stateChange2 */ private void simulateAction(State previousState, State stateChange) { Logger.i(TAG, "simulateAction", "Simulating state change from " + previousState + " to " + stateChange); String name = "von Burg"; String balanceS = "-1:7 (Std:Min)"; String remainingVacationS = "21,5 Tage"; String stateS; LocalTime now = LocalTime.now(); String time = "(" + now.getHourOfDay() + ":" + now.getMinuteOfHour() + ")"; if (stateChange == State.LOGGED_IN) { stateS = "Anwesend " + time; } else stateS = "Abwesend " + time; try { Duration balance = MabeaParsing.parseBalance(balanceS); Duration remainingVacation = MabeaParsing.parseRemainingVacation(remainingVacationS); MabeaState.State state = MabeaParsing.parseState(stateS); LocalDateTime stateTime = MabeaParsing.parseStateTime(stateS); this.mabeaState = new MabeaState(name, balance, remainingVacation, stateTime, state); } catch (MabeaParsingException e) { this.connectionError = e; } }
From source file:com.alliander.osgp.domain.core.valueobjects.smartmetering.CosemTime.java
License:Open Source License
public CosemTime() { this(LocalTime.now()); }
From source file:com.alliander.osgp.dto.valueobjects.smartmetering.CosemTimeDto.java
License:Open Source License
public CosemTimeDto() { this(LocalTime.now()); }
From source file:com.kccomy.orgar.ui.editor.NodeEditorFragment.java
License:Apache License
private void showTimePickerDialog(OrgTimestamp.Type type) { LocalTime src = null;//from w w w .j a v a 2 s. c o m if (OrgTimestamp.Type.SCHEDULED.equals(type)) { src = scheduledTime; } else if (OrgTimestamp.Type.DEADLINE.equals(type)) { src = deadlineTime; } LocalTime time = src != null ? src : LocalTime.now(); TimePickerDialog picker = TimePickerDialog.newInstance(this, time.getHourOfDay(), time.getMinuteOfHour(), true); picker.setAccentColor(getResources().getColor(R.color.colorAccent)); picker.show(getActivity().getFragmentManager(), type.toString()); }
From source file:com.metinkale.prayerapp.vakit.WidgetProviderClock.java
License:Apache License
public static void updateAppWidget(@NonNull Context context, @NonNull AppWidgetManager appWidgetManager, int widgetId) { if (mDP == 0) { Resources r = context.getResources(); mDP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics()); }/*from ww w.j av a 2 s . c o m*/ Resources r = context.getResources(); SharedPreferences widgets = context.getSharedPreferences("widgets", 0); int w = widgets.getInt(widgetId + "_width", 500); int h = widgets.getInt(widgetId + "_height", 200); w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, r.getDisplayMetrics()); h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, r.getDisplayMetrics()); float scaleX = (float) w / (float) 5; float scaleY = (float) h / (float) 2; float scale = Math.min(scaleY, scaleX); w = (int) (5 * scale); h = (int) (2 * scale); if ((w <= 0) || (h <= 0)) { SharedPreferences.Editor edit = widgets.edit(); edit.remove(widgetId + "_width"); edit.remove(widgetId + "_height"); edit.apply(); updateAppWidget(context, appWidgetManager, widgetId); return; } Times times = null; long id = 0; try { id = widgets.getLong(widgetId + "", 0L); } catch (ClassCastException e) { widgets.edit().remove(widgetId + "").apply(); } if (id != 0) { times = Times.getTimes(id); } if (times == null) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_city_removed); Intent i = new Intent(context, WidgetConfigureClock.class); i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId); remoteViews.setOnClickPendingIntent(R.id.image, PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); appWidgetManager.updateAppWidget(widgetId, remoteViews); return; } RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget_clock); remoteViews.setOnClickPendingIntent(R.id.abovePart, PendingIntent.getActivity(context, (int) System.currentTimeMillis(), new Intent(AlarmClock.ACTION_SHOW_ALARMS), PendingIntent.FLAG_UPDATE_CURRENT)); remoteViews.setOnClickPendingIntent(R.id.belowPart, Main.getPendingIntent(times)); Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); builder.appendPath("time"); builder.appendPath(Long.toString(System.currentTimeMillis())); Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); remoteViews.setOnClickPendingIntent(R.id.center, PendingIntent.getActivity(context, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT)); int next = times.getNext(); int last = next - 1; Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setDither(true); paint.setFilterBitmap(true); paint.setStyle(Style.FILL_AND_STROKE); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setShadowLayer(2, 2, 2, 0xFF555555); paint.setTextAlign(Align.CENTER); paint.setColor(Color.WHITE); LocalTime ltime = LocalTime.now(); paint.setTextSize(h * 0.55f); String time = ltime.toString("HH:mm"); if (Prefs.use12H()) { time = Utils.fixTime(time); String suffix = time.substring(time.indexOf(" ") + 1); time = time.substring(0, time.indexOf(" ")); canvas.drawText(time, (w / 2) - (paint.measureText(suffix) / 4), h * 0.4f, paint); paint.setTextSize(h * 0.275f); canvas.drawText(suffix, (w / 2) + paint.measureText(time), h * 0.2f, paint); } else { canvas.drawText(Utils.toArabicNrs(time), w / 2, h * 0.4f, paint); } LocalDate date = LocalDate.now(); String greg = Utils.format(date); String hicri = Utils.format(new HicriDate(date)); paint.setTextSize(h * 0.12f); float m = paint.measureText(greg + " " + hicri); if (m > (w * 0.8f)) { paint.setTextSize((h * 0.12f * w * 0.8f) / m); } paint.setTextAlign(Align.LEFT); canvas.drawText(greg, w * .1f, h * 0.55f, paint); paint.setTextAlign(Align.RIGHT); canvas.drawText(hicri, w * .9f, h * 0.55f, paint); remoteViews.setImageViewBitmap(R.id.widget, bmp); canvas.drawRect(w * 0.1f, h * 0.6f, w * 0.9f, h * 0.63f, paint); if (times.isKerahat()) { paint.setColor(0xffbf3f5b); } else { paint.setColor(Theme.Light.strokecolor); } canvas.drawRect(w * 0.1f, h * 0.6f, (w * 0.1f) + (w * 0.8f * times.getPassedPart()), h * 0.63f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.2f); paint.setTextAlign(Align.LEFT); if (Prefs.use12H()) { String l = Utils.fixTime(times.getTime(last)); String s = l.substring(l.indexOf(" ") + 1); l = l.substring(0, l.indexOf(" ")); canvas.drawText(l, w * 0.1f, h * 0.82f, paint); paint.setTextSize(h * 0.1f); canvas.drawText(s, (w * 0.1f) + (2 * paint.measureText(l)), h * 0.72f, paint); } else { canvas.drawText(Utils.fixTime(times.getTime(last)), w * 0.1f, h * 0.82f, paint); } paint.setTextSize(h * 0.12f); canvas.drawText(Vakit.getByIndex(last).getString(), w * 0.1f, h * 0.95f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.2f); paint.setTextAlign(Align.RIGHT); if (Prefs.use12H()) { String l = Utils.fixTime(times.getTime(next)); String s = l.substring(l.indexOf(" ") + 1); l = l.substring(0, l.indexOf(" ")); canvas.drawText(l, (w * 0.9f) - (paint.measureText(s) / 2), h * 0.82f, paint); paint.setTextSize(h * 0.1f); canvas.drawText(s, w * 0.9f, h * 0.72f, paint); } else { canvas.drawText(Utils.fixTime(times.getTime(next)), w * 0.9f, h * 0.82f, paint); } paint.setTextSize(h * 0.12f); canvas.drawText(Vakit.getByIndex(next).getString(), w * 0.9f, h * 0.95f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.25f); paint.setTextAlign(Align.CENTER); paint.setFakeBoldText(true); canvas.drawText(times.getLeft(next, false), w * 0.5f, h * 0.9f, paint); paint.setFakeBoldText(false); try { appWidgetManager.updateAppWidget(widgetId, remoteViews); } catch (RuntimeException e) { if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) { Crashlytics.logException(e); } } }
From source file:com.prayer.vakit.WidgetProviderClock.java
License:Apache License
public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int widgetId) { if (mDP == 0) { Resources r = context.getResources(); mDP = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 1, r.getDisplayMetrics()); }//from w ww. j a v a 2 s . co m Resources r = context.getResources(); SharedPreferences widgets = context.getSharedPreferences("widgets", 0); int w = widgets.getInt(widgetId + "_width", 500); int h = widgets.getInt(widgetId + "_height", 200); w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, w, r.getDisplayMetrics()); h = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, h, r.getDisplayMetrics()); float scaleX = (float) w / (float) 5; float scaleY = (float) h / (float) 2; float scale = Math.min(scaleY, scaleX); w = (int) (5 * scale); h = (int) (2 * scale); if ((w <= 0) || (h <= 0)) { SharedPreferences.Editor edit = widgets.edit(); edit.remove(widgetId + "_width"); edit.remove(widgetId + "_height"); edit.apply(); updateAppWidget(context, appWidgetManager, widgetId); return; } Times times = null; long id = 0; try { id = widgets.getLong(widgetId + "", 0L); } catch (ClassCastException e) { widgets.edit().remove(widgetId + "").apply(); } if (id != 0) { times = Times.getTimes(id); } if (times == null) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_city_removed_prayer); Intent i = new Intent(context, WidgetConfigureClock.class); i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId); remoteViews.setOnClickPendingIntent(R.id.image, PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_CANCEL_CURRENT)); appWidgetManager.updateAppWidget(widgetId, remoteViews); return; } RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.vakit_widget_clock_prayer); remoteViews.setOnClickPendingIntent(R.id.abovePart, PendingIntent.getActivity(context, (int) System.currentTimeMillis(), new Intent(AlarmClock.ACTION_SHOW_ALARMS), PendingIntent.FLAG_UPDATE_CURRENT)); remoteViews.setOnClickPendingIntent(R.id.belowPart, Main.getPendingIntent(times)); Uri.Builder builder = CalendarContract.CONTENT_URI.buildUpon(); builder.appendPath("time"); builder.appendPath(Long.toString(System.currentTimeMillis())); Intent intent = new Intent(Intent.ACTION_VIEW, builder.build()); remoteViews.setOnClickPendingIntent(R.id.center, PendingIntent.getActivity(context, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT)); int next = times.getNext(); int last = next - 1; Bitmap bmp = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_4444); Canvas canvas = new Canvas(bmp); Paint paint = new Paint(); paint.setAntiAlias(true); paint.setDither(true); paint.setFilterBitmap(true); paint.setStyle(Style.FILL_AND_STROKE); paint.setAntiAlias(true); paint.setSubpixelText(true); paint.setShadowLayer(2, 2, 2, 0xFF555555); paint.setTextAlign(Align.CENTER); paint.setColor(Color.WHITE); LocalTime ltime = LocalTime.now(); paint.setTextSize(h * 0.55f); String time = ltime.toString("HH:mm"); if (Prefs.use12H()) { time = Utils.fixTime(time); String suffix = time.substring(time.indexOf(" ") + 1); time = time.substring(0, time.indexOf(" ")); canvas.drawText(time, (w / 2) - (paint.measureText(suffix) / 4), h * 0.4f, paint); paint.setTextSize(h * 0.275f); canvas.drawText(suffix, (w / 2) + paint.measureText(time), h * 0.2f, paint); } else { canvas.drawText(Utils.toArabicNrs(time), w / 2, h * 0.4f, paint); } LocalDate date = LocalDate.now(); String greg = Utils.format(date); String hicri = Utils.format(new HicriDate(date)); paint.setTextSize(h * 0.12f); float m = paint.measureText(greg + " " + hicri); if (m > (w * 0.8f)) { paint.setTextSize((h * 0.12f * w * 0.8f) / m); } paint.setTextAlign(Align.LEFT); canvas.drawText(greg, w * .1f, h * 0.55f, paint); paint.setTextAlign(Align.RIGHT); canvas.drawText(hicri, w * .9f, h * 0.55f, paint); remoteViews.setImageViewBitmap(R.id.widget, bmp); canvas.drawRect(w * 0.1f, h * 0.6f, w * 0.9f, h * 0.63f, paint); if (times.isKerahat()) { paint.setColor(0xffbf3f5b); } else { paint.setColor(Theme.Light.strokecolor); } canvas.drawRect(w * 0.1f, h * 0.6f, (w * 0.1f) + (w * 0.8f * times.getPassedPart()), h * 0.63f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.2f); paint.setTextAlign(Align.LEFT); if (Prefs.use12H()) { String l = Utils.fixTime(times.getTime(last)); String s = l.substring(l.indexOf(" ") + 1); l = l.substring(0, l.indexOf(" ")); canvas.drawText(l, w * 0.1f, h * 0.82f, paint); paint.setTextSize(h * 0.1f); canvas.drawText(s, (w * 0.1f) + (2 * paint.measureText(l)), h * 0.72f, paint); } else { canvas.drawText(Utils.fixTime(times.getTime(last)), w * 0.1f, h * 0.82f, paint); } paint.setTextSize(h * 0.12f); canvas.drawText(Vakit.getByIndex(last).getString(), w * 0.1f, h * 0.95f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.2f); paint.setTextAlign(Align.RIGHT); if (Prefs.use12H()) { String l = Utils.fixTime(times.getTime(next)); String s = l.substring(l.indexOf(" ") + 1); l = l.substring(0, l.indexOf(" ")); canvas.drawText(l, (w * 0.9f) - (paint.measureText(s) / 2), h * 0.82f, paint); paint.setTextSize(h * 0.1f); canvas.drawText(s, w * 0.9f, h * 0.72f, paint); } else { canvas.drawText(Utils.fixTime(times.getTime(next)), w * 0.9f, h * 0.82f, paint); } paint.setTextSize(h * 0.12f); canvas.drawText(Vakit.getByIndex(next).getString(), w * 0.9f, h * 0.95f, paint); paint.setColor(Color.WHITE); paint.setTextSize(h * 0.25f); paint.setTextAlign(Align.CENTER); paint.setFakeBoldText(true); canvas.drawText(times.getLeft(next, false), w * 0.5f, h * 0.9f, paint); paint.setFakeBoldText(false); try { appWidgetManager.updateAppWidget(widgetId, remoteViews); } catch (RuntimeException e) { if (!e.getMessage().contains("exceeds maximum bitmap memory usage")) { } } }
From source file:domain.RaspberryPiGather.java
public WeatherReport gatherFrom() throws Exception { Client client = ClientBuilder.newClient(); WebTarget target = client.target(url).resolveTemplates(this.temperature); ObjectMapper objectMapper = new ObjectMapper(); String response = target.request(MediaType.APPLICATION_JSON).get(String.class); WeatherReport t = null;//from www.j a va 2 s . c o m try { JsonNode rootNode = objectMapper.readTree(response); JsonNode temp = rootNode.path("temp"); JsonNode humidity = rootNode.path("humidity"); LocalDate date = LocalDate.now(); LocalTime time = LocalTime.now(); t = new WeatherReport(temp.doubleValue(), humidity.textValue(), date, time); } catch (Exception e) { } return t; }
From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java
License:Open Source License
private void updateHourlyIntervalBox() { LocalTime t = schedule.startTime(); if (t == null) { t = LocalTime.now().withMinuteOfHour(0); schedule.setStartTime(t);//from w w w. ja v a 2 s . co m } String time = new LocalTime(t.getHourOfDay(), t.getMinuteOfHour()).toString("kk:mm"); hourlyIntervalFrom.setText(getString(R.string.first_intake) + ": " + time); if (schedule.rule().interval() < 1) { schedule.rule().setInterval(8); } schedule.rule().setFrequency(Frequency.HOURLY); hourlyIntervalEditText.setText(String.valueOf(schedule.rule().interval())); hourlyIntervalRepeatDose.setText(schedule.displayDose()); }
From source file:es.usc.citius.servando.calendula.persistence.DailyScheduleItem.java
License:Open Source License
public void setTakenToday(boolean takenToday) { this.takenToday = takenToday; if (takenToday) { timeTaken = LocalTime.now(); } else {/*from www . j av a 2 s. c o m*/ timeTaken = null; } }