Sceneform - How to make the camera view too autofocus - android

So, the default camera view in sceneform is in fixed focus settings. But its blur and doesn't feels good. I want to get the camera to show everything clearly (Autofocus mode).
I tried changing the session config. But it is not really working.

override fun getSessionConfiguration(session: Session?): Config {
val config = Config(session)
config.focusMode = Config.FocusMode.AUTO
return config
}

Related

Android Picture in Picture Potrait Mode

I am trying to implement Picture in Picture mode but so far as per the example given the only orientation I see is landscape mode.
https://developer.android.com/guide/topics/ui/picture-in-picture
I am trying to have a functionally similar to the WhatsApp app. When the user accepts a call and enters picture in picture mode the window is shown in portrait mode so the user can see the other person well. Will appreciate thoughts on how I can implement this.
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean,
newConfig: Configuration) {
if (isInPictureInPictureMode) {
// Hide the full-screen UI (controls, etc.) while in picture-in-picture mode.
} else {
// Restore the full-screen UI.
}
}
You can use enterPictureInPictureMode to configure the PIP window.
To have a portrait PIP window use an aspect ratio of ~2/3. (The aspect ratio must be between 0,42 and 2,39.)
override fun onUserLeaveHint() {
enterPictureInPictureMode(PictureInPictureParams.Builder()
.setAspectRatio(Rational(2, 3))
.build())
}
Example:

Android CameraX stuck with two use cases

I'm novice in Android development (more Python and ML engineer) but wanted to try this example from TensorFlow: TF Lite Transfer Learning.
I succesfully run it on Android Studio but spotted that I cannot do anything with the app as it works extraordinary slow. I was digging through the code to find a root cause a found out this.
In function CameraFragment::startCamera() a preview context is created
PreviewConfig config = new PreviewConfig.Builder()
.setLensFacing(LENS_FACING)
.setTargetAspectRatio(screenAspectRatio)
.setTargetRotation(viewFinder.getDisplay().getRotation())
.build();
Preview preview = new Preview(config);
preview.setOnPreviewOutputUpdateListener(previewOutput -> {
ViewGroup parent = (ViewGroup) viewFinder.getParent();
parent.removeView(viewFinder);
parent.addView(viewFinder, 0);
As well as other use case that we can keep empty:
final ImageAnalysisConfig imageAnalysisConfig =
new ImageAnalysisConfig.Builder()
.setLensFacing(LENS_FACING)
.setTargetResolution(new Size(224, 224))
.setCallbackHandler(new Handler(inferenceThread.getLooper()))
.setImageReaderMode(ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
.build();
final ImageAnalysis imageAnalysis2 = new ImageAnalysis(imageAnalysisConfig);
imageAnalysis2.setAnalyzer((image, rotationDegrees) -> { });
New we have a line to bring them to life:
CameraX.bindToLifecycle(this, preview, imageAnalysis2);
And here is where the problem starts. If we keep them like that the application is unusable. But if we keep only one (either one) we can use the app to the point that all novigation works normally. Do you know what is causing this behaviour?
This build.gradle uses a rather old version; migrate to version 1.0.0-beta01.

Why does Android Studio display "only be called from with the same library group" when I remove #SuppressLint("RestrictedApi")?

The Code A is from CameraX project, you can see source code.
Android Studio will display "only be called from with the same library group" when I remove #SuppressLint("RestrictedApi"), you can see Image 1.
Why can't I remove #SuppressLint("RestrictedApi") in Code A ? What deos a restriction API mean?
Code A
#SuppressLint("RestrictedApi")
private fun updateCameraUi() {
...
// Listener for button used to switch cameras
controls.findViewById<ImageButton>(R.id.camera_switch_button).setOnClickListener {
lensFacing = if (CameraX.LensFacing.FRONT == lensFacing) {
CameraX.LensFacing.BACK
} else {
CameraX.LensFacing.FRONT
}
try {
// Only bind use cases if we can query a camera with this orientation
CameraX.getCameraWithLensFacing(lensFacing)
// Unbind all use cases and bind them again with the new lens facing configuration
CameraX.unbindAll()
bindCameraUseCases()
} catch (exc: Exception) {
// Do nothing
}
}
}
Image 1
There have been breaking changes in the library since the tutorial was made.
Reverting the package version to 1.0.0-alpha06, same as the tutorial, solves the problem.
These are issues with the library that don't affect your code.
In several code examples using these APIs there is often a #SuppressLint("RestrictedApi") in the file hiding the warning.
The projects should still compile and run as they should, although you must make sure that you are using the correct dependency version. The APIs are changing quite frequently still, and if you're referencing an example it might be using an older version which has since changed.
Your best bet is to look directly at the source code and if the method you are calling is declared as public then you probably won't have a problem.

How to make my Unity 3d (AR) project play in a full screen on my phone?

Testing Augmented Reality made with Unity 3d and vuforia on my android device is not showing in full screen !
I have tried to change everything in unity player settings but nothing changed
i even tried to do a script for the AR Camera
public class fullscreen : MonoBehaviour
{
// Start is called before the first frame update
void Start() =>
// Toggle fullscreen
Screen.fullScreen = !Screen.fullScreen;
// Update is called once per frame
void Update()
{
}
}
but it didnt work
I want to show it in the full screen
check my imageon Android device
If your game is in fullscreen Screen.fullScreen = !Screen.fullScreen; will make your game not fullscreen anymore. Use Screen.fullScreen = true;
Then, under Project Settings -> Player -> Resolution and Presentation check Start in fullscreen mode.

how to capture a screenshot?

I know that there are a lot of questions about capturing screenshots, and I have checked most of them. They have the same answer (with small code variations).
I have following method for screenshot capturing:
#NonNull
public static Bitmap takeScreenShot(Window window) throws IOException {
final View rootView = window.getDecorView().getRootView();
final boolean drawingCacheEnabled = rootView.isDrawingCacheEnabled();
rootView.setDrawingCacheEnabled(true);
try {
return Bitmap.createBitmap(rootView.getDrawingCache());
} finally {
rootView.setDrawingCacheEnabled(drawingCacheEnabled);
}
}
And you can use it like these: takeScreenShot(getActivity().getWindow())
However these approach has several limitations:
If you have some dialogs on the screen they will not be captured on
screenshot.
Will it work with hardware accelerated views? According
to documentation:
When hardware acceleration is turned on, enabling the
drawing cache has no effect on rendering because the system uses a
different mechanism for acceleration which ignores the flag
Screenshot contains black boxes
instead of GLviews. (e.g. when you app has maps.). It seems to be as a result of 2nd point.
So my question is, is there any solution without rooting that can solve at least some of my issues?
Check out the following GitHub repo (not mine!): https://github.com/AndroidDeveloperLB/ScreenshotSample
Also, the following will be useful reading:
How to properly take a screenshot, globally?

Categories

Resources