Android camera won't stop autofocusing - java

I am setting the focus mode to FocusModeAuto and then set the camera parameters.
Then I call Camera.AutoFocus(), get the result from the callback and start recording with a MediaRecorder.
The problem is that the camera keeps auto focusing on its own as if its in mode FocusModeContinuousVideo or FocusModeContinuousPicture.
I am having this issue on a LG K20 V phone, but I don't have this issue on older phones.
I tried setting the focus mode to FocusModeFixed after I get the focus I want to try and lock it in place, but that mode makes it jump the focus to a far distance and not the distance I auto focused to with my previous calls.
How can I lock the focus to the auto focus I previously obtained or set the focus directly so that I can have full control of it?
Also while it does the auto focuses I didn't request. The OnAutoFocus() callback is not being called.

Related

Handling Display Size change

I am migrating my app target SDK Version to android oreo.
One of the changes which might affect the app is that if the Display size of the device is changed then the app targeting Android Nougat and above will be notified as if there is a change in orientation of the device. Below is the source.
When the device density changes, the system notifies running apps in
the following ways:
If an app targets API level 23 or lower, the system automatically
kills all its background processes. This means that if a user switches
away from such an app to open the Settings screen and changes the
Display size setting, the system kills the app in the same manner that
it would in a low-memory situation. If the app has any foreground
processes, the system notifies those processes of the configuration
change as described in Handling Runtime Changes, just as if the
device's orientation had changed.
If an app targets Android 7.0, all
of its processes (foreground and background) are notified of the
configuration change as described in Handling Runtime Changes.
Now my app has a longrunning process which runs in an Async TSak in an Android Activity. Which means that the App has an AsyncTask which is inside the Activity Code.
I create a Dialog box on the start of the Async Task and hide it when the Async Task has done its work.
Now suppose the users start the task and then goes to the setting and changes the Display Size then return back to my app then the dialog box of the app is gone by the Async Task is still performed till the end which mean that the user might think that the app has finished the task but whereas the app would be actually performing the task. But my Activity is also responding as if restarted except that Async Task is running.
My app's orientation locked to portrait.
How should I handle such a scenario? Any help is appreciated. Thanks!
EDIT: This is the scenario
1) App Start
2) Main Screen
3) Users Press A Button
4) AsyncTask inside Main Screen Started
5) A Dialog Box is shown with the progress of task
6) User Minimizes the App and Goes to setting
7) Changes the Display Size/Density or changes the Font Size of the device
8) My App is called by the OS in such a way as if the device rotation is changed
9) Then the user returns back to the app
10) But the dialog box shown is no more being shown
11) But the async Task is running in the background and is still performing its task
12) The task is actually done but the user thinks that the task is still not done.
In your on_resume() method verify the screen size and the font size have not changed. If they have, adjust, remove and recreate, your dialog box appropriately. This is similar to handling orientation changes while suspended (adding font size as a condition).
EDIT:
Add android:configChanges="fontScale|density" to your manifest file.
static int fontScale = 1;
static int densityDpi = 0;
public void onConfigurationChanged(Configuration newConfig) {
if (newConfig.fontScale != fontScale) {
// destroy and recreate dialog adjusting for font size.
fontScale = newConfig.fontScale;
}
if (newConfig.densityDpi != densityDpi) {
// destroy and recreate dialog adjusting for new screen size.
densityDpi = newConfig.densityDpi;
}
}
It would probably be better to utilize notifications for the async task, since they are unaffected by config changes and are not terminated in low memory conditions.
When you rotate the phone, your activity is actually destroyed and recreated. This includes your dialog. There are two ways to fix it:
1) Turn off this "helpful" functionality. If you don't have different layouts for landscape and portrait its what I'd suggest. Add android:configChange="orientation|resize" to your activity in the manifest.
2) Implement onSaveInstanceState/onRestoreInstanceState and have a variable that says whether or not you need to recreate and relaunch the dialog.
Suggestions:
Try using WorkManager to schedule the task and also ViewModel from the android architecture components which helps to retain the state even after the configuration changes

JavaFX UI elements hover style not rendering correctly after resizing application window

At times, certain UI elements that have a hover style will not render at all and a white box is left in it's place. This only happens after I resize the application window and when the UI element is completely outside of the original bounds of the application window. The button shown in the images below also does not immediately render correctly after removing the mouse pointer from the hover position, so the issue likely would occur whenever the button needs to be repainted.
"Device Logging" button is being hovered by the mouse, before resizing the window.
After resizing the window. Both the "Device Logging" and "Misc Tests" buttons are 100% outside of the original bounds of the window. The "Cloud Server Migration" button however is still rendering correctly.
I have set styles, but removing them has no effect. The issue only seems to appear when there is other processing taking place, such as running the firmware update function. That tells me that there may be something taking up UI time, but I would have expected that to affect every UI element, not just certain ones.
One other note, the UI was converted from Swing to JavaFX, so all of the threading did not include the use of Task or Platform.runlater(). I have since made sure all UI updates are using Platform.runlater(), but I have not yet converted all of the original threads that don't update the UI to Tasks. Below I am including the framework of running a firmware update.
Edit: Was able to reproduce the issue without starting a firmware update, so I don't think it has anything to do with processing blocking UI rendering. The issue occurred only after using some of the UI. As such I removed the code that was posted above. This leads me to believe it has more to do with the actual layout of the UI.
I believe I have figured out the issue. I use a ListView to hold an Object and a cellfactory to render each of the cells with a custom UI. When populating the list with items, additional threads are spawned to retrieve information for each Object within the cell. The variables associated with the Object are bound to a view property within the custom UI. I was not using Platform.runlater() to update these properties with the new information. After updating the sets to runlater, the issue appears to have been fixed.

Set rect focus in camera android

I am doing an Android application that uses camera. I want that camera focuses in faces. My dude is: Nexus 5 front camera only has "Fixed" in focus mode. Is there some way to use setRect areas or something like that.
I try to use facedetectionlistener and runs ok but when i also add a previewcallback to do some process stops running. (Issue with preview callback [ANDROID])
Thanks
You might want to take a look at Camera.Parameters. It has setFocusArea and setAutoFocus functions.
Check this one

android-how to prevent screen from turning on in this case? [duplicate]

I have an activity that shows up when the phone screen goes to sleep/turns off ie turns black.
For some reason, the phone turns on when the volume buttons or the camera buttons are pressed. By turns on, I mean the screen wakes up or comes back from the black screen state.
I've tried using dispatchKeyEvent(KeyEvent event) and the buttons are disabled on the activity, but they still wake up the phone.
You could try overriding the onKeyDown(KeyEvent) method and change what happens for those keys. However, I'm not too optimistic as if you're running an activity, it will be in an inactive state when the display is off, and also it could be that the phone is hard wired to wake up on those buttons. It could be device specific. Hard to say. Try that out and let me know how it goes, I'm currious

honoring rotation lock in android

I am trying to honor the android rotation lock setting - I want my app to display in whatever orientation the home screen is locked in. I found the following knobs:
Settings.System.ACCELEROMETER_ROTATION - determine if the screen orientation is locked.
Display.getRotation() - determine if the device is rotated from it's "natural" orientation, which may be portrait or landscape.
Display.getWidth()/getHeight() - determine the current orientation of the device.
I thought this would be simple to do, but I can't seem to find the right combination of the above to get this to work. The reported values seem inconsistent, especially during app startup (is onResume the right place to check these values?).
Note I don't want to simply always fix the orientation of my activity to portrait or landscape, I want to set it to the orientation the user has locked the screen in. For tablets this could be landscape or portrait. If the user sets the Auto-Rotate setting, I want my activity to operate in sensor mode.
after hours of debugging, it appears the answer is as simple as checking if rotation is locked and if so, calling setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR). Now excuse me while I go step off the nearest bridge...

Categories

Resources