I'm writing a program using Java and I need to use a splash screen to let the user know that the application is starting. I have tested how long the application is to set up using the following code:
long startTime = System.currentTimeMillis();
frame = new CFSMainFrame(); // main app
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
System.out.println("Total time: " + ((float)totalTime/1000) + " seconds!");
and it returns a total time of 2.66 seconds in average. I want to show a splash screen during this time. I have looked around and even checked the splash-screen API, but I don't find it very "noob"-friendly and was wondering if someone in here could give me a very simple example for showing an image during this time, there is no need for a fancy loading bar or anything..
Related
I need to make sure that after pressing one button, the other is not available for 15 minutes. To do this, I use a method like this:
disposableTimer = Observable.timer(15,TimeUnit.MINUTES)
.subscribeOn(Schedulers.io())
.observeOn(Schedulers.io())
.subscribe(aLong -> {
buttonSimpleAct.setEnabled(true);
});
This works well when the program is active, but I need this timer to work even when the program is closed.
That is, if the first button was pressed, the application was closed and returned after 15 minutes, the second button should already be active.
Are there any ways to make the Observable work in the background, or alternatives to this?
What I'd do is save (in a persistent manner) the timestamp for when the button should be re-enabled and restart the timer with the remaining time when the app comes back.
// when the first button is clicked:
long reenableAfter = System.currentTimeMillis() + 15 * 60 * 1000L;
save(reenableAfter);
disposableTimer = Observable.timer(15 ,TimeUnit.MINUTES, AndroidSchedulers.mainThread())
.subscribe(aLong -> buttonSimpleAct.setEnabled(true));
// when the app starts
long reenableAfter = load();
disposableTimer = Observable.timer(reenableAfter - System.currentTimeMillis(),
TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
.subscribe(aLong -> buttonSimpleAct.setEnabled(true));
Using Selenium webdriver with java
Example we have lot of fields like the image below
I tried using explicit wait like
i) waiting for elements to load (but the elements are dynamically loaded and does not populate until i click and wait for couple of seconds)
but does not work until I pause for couple of seconds.
I am using the below method
I am creating a framework and wanted to know if in other organisations programmers do use similar methods to pause the script or is it not used ? because I need to use it so much.
Using below method as I did not want to use Thread.sleep courtesy stack overflow.
public static void customewait(int seconds){
Date start = new Date();
Date end = new Date();
while(end.getTime() - start.getTime() < seconds * 1000){
end = new Date();
}
}
You can use waits provided by selenium as following:
WebDriverWait wait = new WebDriverWait(driver, 5000);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("idOfElement")));
This code will wait for element to be visible for 5000ms and when it finds that element it initializes the object.
5000 is timeout time in milliseconds (ms)
you can read more at this link
Thread.sleep will stop the execution of the thread for the given time while Webdriver wait only waits till the mentioned condition is not met. So, the Best practice is to use web driver wait.
By ByLocator = By.xpath("Any XPath");
int seconds = 5 * 1000; // seconds in milli.
WebDriverWait wait = new WebDriverWait(driver, seconds);
wait.until(ExpectedConditions.presenceOfElementLocated(ByLocator));
The image quality and the framerate I get when using the camera2 API does not match the one I get when I manually record a video using the camera app to a file.
I am trying to do real-time image processing using OpenCV on Android. I have manually recorded a video using the built-in camera application and everything worked perfectly: the image quality was good, the framerate was a stable 30 FPS.
My min SDK version is 22, so I am using the camera2 API's repeating requests. I have set it up, together with an ImageReader and the YUV_420_888 format. I have tried both the PREVIEW and the RECORD capture request templates, tried manually setting 18 capture request parameters in the builder (eg. disabling auto-white-balance, setting the color correction mode to fast), but the FPS was still around 8-9 and the image quality was poor as well. Another phone yielded the same results, despite its max. FPS being 16.67 (instead of 30).
The culprit is not my image processing (which happens in another thread, except for reading the image's buffer): I checked the FPS when I don't do anything with the frame (I didn't even display the image), it was still around 8-9.
You can see the relevant code for that here:
//constructor:
HandlerThread thread = new HandlerThread("MyApp:CameraCallbacks", Process.THREAD_PRIORITY_MORE_FAVORABLE);
thread.start();
captureCallbackHandler = new Handler(thread.getLooper());
//some UI event:
cameraManager.openCamera(cameraId, new CameraStateCallback()), null);
//CameraStateCallback#onOpened:
//size is 1280x720, same as the manually captured video's
imageReader = ImageReader.newInstance(size.getWidth(), size.getHeight(), ImageFormat.YUV_420_888, 1);
imageReader.setOnImageAvailableListener(new ImageAvailableListener(), captureCallbackHandler);
camera.createCaptureSession(Collections.singletonList(imageReader.getSurface()), new CaptureStateCallback(), captureCallbackHandler);
//CaptureStateCallback#onConfigured:
CaptureRequest.Builder builder = activeCamera.createCaptureRequest(CameraDevice.TEMPLATE_RECORD);
builder.addTarget(imageReader.getSurface());
//setting the FPS range has no effect: this phone only has one option
session.setRepeatingRequest(builder.build(), null, captureCallbackHandler);
//ImageAvailableListener#onImageAvailable:
long current = System.nanoTime();
deltaTime += (current - last - deltaTime) * 0.1;
Log.d("MyApp", "onImageAvailable FPS: " + (1000000000 / deltaTime));
//prints around 8.7
last = current;
try (Image image = reader.acquireLatestImage()) { }
On Samsung Galaxy J3 (2016), doing Camera.Parameters#setRecordingHint(true) (while using the deprecated camera API) achieves exactly what I wanted: the video quality and the framerate becomes the same as the built-in video recorder's. Unfortunately, it also means that I was unable to modify the resolution, and setting that hint did not achieve this same effect on a Doogee X5 MAX.
I would like to use a timer that counts up like: 00:00:00 -> 00:00:01 and so on , I tried it with
Long start = System.currentTimeMillis();
Long end = System.currentTimeMillis() - start;
but didn't worked. This is how i get my data from my localhost. I would like to use this to calculate the timer via my Server , but it doesnt work.
I just would like to see a timer alongside my uploaded file in my client GUI
Hope someone can help, if you have more questions ask me :)
ResponseEntity<String> response = restTemplate.postForEntity(format("http://localhost:8080/file/upload?uid={0}&time={1}", uid , time)
EDIT: This is how my Client JTable looks like Its not my idea but my supervisor just want to see what the average time is that the server needs to run the (.bat) File. And u cant calc how long a (.bat) file needs so i need a timer that counts up.
And i was thinking this should be possible via the server.
Without going into details if it is smart to do a server-side timer for uploads, you can't make a second-step with this
Long start = System.currentTimeMillis();
Long end = System.currentTimeMillis() - start;
because it will just execute at whatever speed your system is running at.
Something like the code below will trigger once every second, but you'll have to run that in its own thread as not to block the main-thread with the while:
while(true){
System.out.printLine("tick");
Thread.sleep(1000);
}
I am developing an app that will play certain sound at 9:15AM and 10:30AM in the morning,
I am done with playing the sound part already but I am facing issues while monitoring the current android system time.
Here is what I am doing,
I have an array where 9:15AM and 10:30AM are stored as String.
While I am using Java Calendar class to get current time of the System,
Calendar cTime = Calendar.getInstance();
public String currentTime() {
String hour = cTime.get(Calendar.HOUR) + "";
String mins = cTime.get(Calendar.MINUTE) + "";
return hour+""+mins+"AM";
}
and I am playing the sound using this code,
public void playSound() {
MediaPlayer player = MediaPlayer.create(this, R.raw.s);
player.start();
player.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
}
The problem is,
If it is 9:15AM in the morning and I run the app then the app would play the sound, or if it is 10:30 in the morning and I run the app then App will play the sound, but this isn't what I want,
I want my app to keep monitoring the time all the time and when its 9:15AM or 10:30AM, the sound should play regardless of the app is running or not.
i tried one approach by comparing the current time with 10:30AM or 9:30AM in a while loop, but it hangs my phone and this seems ugly idea.
I couldn't think of any other way to monitor the time, please suggest me something.
Use AlarmManager to schedule to get control at those points in time.
I think you should try these codes ( Android apis)
Use AlarmManager class to schedule and execute actions/operations that you want to perform regardless of the status of your android application whether it's running or not.
But before applying this concept you you should go through more details about this class , as it provides two types of alarm Elapsed Realtime and Real Time Clock..
and you will have to use BroadcastReceiver to receive the Intent .
if you want to use loops the you should use following codes(better than java calendar classes)
Time t = new Time();
t.setToNow();
or more better codes will be because now you will get current time zone of your user , so here you go;
Time t = new Time(Time.getCurrentTimezone());
t .setToNow();