List of usage examples for org.joda.time Duration Duration
public Duration(Object duration)
From source file:io.github.benas.jpopulator.randomizers.joda.DefaultJodaDurationRandomizer.java
License:Open Source License
@Override public Duration getRandomValue() { return new Duration(Math.abs(ConstantsUtil.RANDOM.nextLong())); }
From source file:io.github.benas.randombeans.randomizers.jodatime.JodaTimeDurationRandomizer.java
License:Open Source License
@Override public Duration getRandomValue() { return new Duration(Math.abs(Constants.RANDOM.nextLong())); }
From source file:io.v.android.apps.namespace_browser.MainActivity.java
License:Open Source License
private void fetchNames(final LinearLayout dirView) { ViewUtil.updateDirectoryView(dirView, true); GlobReply entry = (GlobReply) dirView.getTag(); if (!(entry instanceof GlobReply.Entry)) { return;/* w w w .j av a 2s . co m*/ } final MountEntry dirEntry = ((GlobReply.Entry) entry).getElem(); final ProgressDialog progressDialog = new ProgressDialog(MainActivity.this); progressDialog.setMessage("Fetching Names..."); progressDialog.show(); String root = dirEntry.getName(); io.v.v23.namespace.Namespace n = V.getNamespace(mBaseContext); VContext ctxT = mBaseContext.withTimeout(new Duration(20000)); // 20s Futures.addCallback(InputChannels.withCallback(n.glob(ctxT, root.isEmpty() ? "*" : root + "/*"), new InputChannelCallback<GlobReply>() { @Override public ListenableFuture<Void> onNext(GlobReply reply) { if (reply instanceof GlobReply.Error) { GlobError error = ((GlobReply.Error) reply).getElem(); String msg = String.format("Couldn't fetch namespace subtree \"%s\": %s", error.getName(), error.getError().getMessage()); android.util.Log.e(TAG, msg); return null; } MountEntry entry = ((GlobReply.Entry) reply).getElem(); String text = ""; if (dirEntry.getName().isEmpty()) { text = entry.getName(); } else if (entry.getName().startsWith(dirEntry.getName() + "/")) { text = entry.getName().substring(dirEntry.getName().length() + 1); } else { Log.e(TAG, String.format("Entry %s doesn't start with parent prefix %s", entry.getName(), dirEntry.getName() + "/")); return null; } LinearLayout childView = (entry.getServers() == null || entry.getServers().size() <= 0) ? ViewUtil.createDirectoryView(text, reply, getLayoutInflater()) : ViewUtil.createObjectView(text, reply, getLayoutInflater()); dirView.addView(childView); return null; } }), new FutureCallback<Void>() { @Override public void onSuccess(Void result) { progressDialog.dismiss(); } @Override public void onFailure(Throwable t) { progressDialog.dismiss(); Log.e(TAG, "Error fetching names: " + t.getMessage()); } }); }
From source file:io.v.android.apps.namespace_browser.Methods.java
License:Open Source License
static ListenableFuture<List<String>> get(VContext ctx, String name) { Client client = V.getClient(ctx);/*from w ww . j a v a 2s . co m*/ VContext ctxT = ctx.withTimeout(new Duration(20000)); // 20s ListenableFuture<ClientCall> callFuture = client.startCall(ctxT, name, "__Signature", new Object[0], new Type[0]); final Type[] resultTypes = new Type[] { new TypeToken<Interface[]>() { }.getType() }; ListenableFuture<Interface[]> sign = Futures.transform(callFuture, new AsyncFunction<ClientCall, Interface[]>() { @Override public ListenableFuture<Interface[]> apply(ClientCall call) throws Exception { return Futures.transform(call.finish(resultTypes), new Function<Object[], Interface[]>() { @Override public Interface[] apply(Object[] input) { return (Interface[]) (input[0]); } }); } }); return Futures.transform(sign, new Function<Interface[], List<String>>() { @Override public List<String> apply(Interface[] input) { List<String> ret = new ArrayList<String>(); for (Interface iface : input) { if (iface.getMethods() != null) { for (Method method : iface.getMethods()) { ret.add(method.getName()); } } } return ret; } }); }
From source file:io.v.android.apps.namespace_browser.Namespace.java
License:Open Source License
/** * Returns the list of entries mounted under the provided namespace root. * * @param root root of the namespace/*from w ww.j a va2 s.c o m*/ * @return list of entries mounted under the provided root. * @throws VException if there was an error fetching the entries. */ public static List<GlobReply> glob(String root, VContext ctx) throws VException { io.v.v23.namespace.Namespace n = V.getNamespace(ctx); VContext ctxT = ctx.withTimeout(new Duration(20000)); // 20s return ImmutableList.copyOf(n.glob(ctxT, root.isEmpty() ? "*" : root + "/*")); }
From source file:io.v.chat.ChatChannel.java
License:Open Source License
public void sendMessage(String s) throws VException { VContext context = ctx.withTimeout(new Duration(3000)); for (Participant participant : getParticipants()) { try {//from w w w . j av a2 s .c o m participant.sendMessage(context, s); } catch (VException e) { System.err.println("Could not send message to " + participant); e.printStackTrace(); } } }
From source file:io.v.chat.ChatChannel.java
License:Open Source License
public List<Participant> getParticipants() throws VException { List<Participant> participants = new ArrayList<>(); VContext context = ctx.withTimeout(new Duration(3000)); Namespace namespace = V.getNamespace(context); for (GlobReply reply : namespace.glob(context, name + "/*")) { if (reply instanceof GlobReply.Entry) { MountEntry entry = ((GlobReply.Entry) reply).getElem(); for (MountedServer server : entry.getServers()) { participants.add(new Participant(endpointUsername(server.getServer()), server.getServer())); break; }/*from w w w . j a v a 2s . c o m*/ } } return participants; }
From source file:it.d4nguard.rgrpg.profile.CharacterInfo.java
License:Open Source License
public CharacterInfo() { this.creation = DateTime.now(); this.played = new Duration(0); this.last = new DateTime(this.creation.getMillis()); this.lastDuration = new Duration(0); this.lastExp = 0; this.current = false; }
From source file:it.unibz.inf.ait.distanceestimatorapp.TrackingActivity.java
License:Apache License
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tracking); chronometer = (Chronometer) findViewById(R.id.tracking_chronometer); kilometerView = (TextView) findViewById(R.id.tracking_text); pauseButton = (Button) findViewById(R.id.pause_tracking_button); Intent intent = getIntent();/*w ww.ja v a 2 s . c o m*/ int id = Integer.valueOf(intent.getStringExtra(MainActivity.EXTRA_MESSAGE)); dbHelper = new DatabaseManager(this); SportType sportType = dbHelper.getSportType(id); Training training = new Training(); training.setSportType(sportType); training.setStartTime(DateTime.now()); training.setEndTime(DateTime.now()); training.setDuration(new Duration(DateTime.now().getMillis() - DateTime.now().getMillis())); dbHelper.createTraining(training); kilometerView.setText(String.valueOf(training.getDistance() + " km")); trainingId = dbHelper.getHighestTraining(); Intent serviceIntent = new Intent(this, TrackingService.class); startService(serviceIntent); LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) { showToast("You need to enable your GPS!"); Log.d("gps on?", "" + lm.isProviderEnabled(LocationManager.GPS_PROVIDER)); } Log.d("locationCount", "" + dbHelper.getLocationCount()); pauseButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (pauseButton.getText().equals("Pause")) { chronometer.stop(); stopService(new Intent(v.getContext(), TrackingService.class)); pauseButton.setText("Resume"); } else { String time = (String) chronometer.getText(); String[] array = time.split(":"); int milliseconds = Integer.valueOf(array[0]) * 60 * 1000 + Integer.valueOf(array[1]) * 1000; chronometer.setBase(SystemClock.elapsedRealtime() - milliseconds); chronometer.start(); Intent serviceIntent = new Intent(TrackingActivity.this, TrackingService.class); startService(serviceIntent); pauseButton.setText("Pause"); } } }); }
From source file:it.unibz.inf.ait.distanceestimatorapp.TrackingActivity.java
License:Apache License
public void saveTrack(View view) { unregisterReceiver(receiver);//w w w .java 2 s . c om stopService(new Intent(this, TrackingService.class)); chronometer.stop(); dbHelper = new DatabaseManager(this); Training training = dbHelper.getTraining(trainingId); String time = (String) chronometer.getText(); String[] array = time.split(":"); Long milliseconds = Long.valueOf(array[1]) * 1000 + Long.valueOf(array[0]) * 1000 * 60; training.setDuration(new Duration(milliseconds)); training.setEndTime(DateTime.now()); training.compute(dbHelper); if (training.getDistance() > 0) { dbHelper.updateTraining(training); } else { dbHelper.deleteTraining(training); Toast.makeText(this, "Training hasn't been saved, because the distance is 0", Toast.LENGTH_SHORT) .show(); } Log.d("savedTrack", "track saved"); Log.d("locationCount", "" + dbHelper.getLocationCount()); Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent); }