Controlling Brightness of tablet with Qt Android - java

I tried the Qt forums but with no avail. I'm trying to develop an Android application that one of the functionality is changing the brightness of the tablet backlight. I have successfully written two programs in Android Studio (in Java) using the LayoutParams and Android putInt system brightness to change brightness. The issue comes when I try to move the code to my Qt application. I have the JNI code working and it runs my functions, but when I paste the brightness code in to change brightness method the application fails.
From what I understand of Android and the error statements, my issue (I think) is I am not running the code on the UI thread. I've tried to force my Java method to be a Runnable and use runonUiThread but that doesn't support the ContentResolver or Window because it is not an Activity.
Does anyone have experience with this that can guide me? Or have any experience getting anything in the Android settings to work?
I appreciate everyone helping out,
Andrew

You could have it in a static Java method like :
package com.MyApp;
public class BrightnessChanger
{
public static int change(int n)
{
float brightness = n / (float)255;
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = brightness;
getWindow().setAttributes(lp);
}
}
You can then call this static Java function from your C++ code :
bool retVal = QAndroidJniObject::callStaticMethod<jint>
("com/MyApp/BrightnessChanger" // class name
, "change" // method name
, "(I)I" // signature
, 50);
Here you pass a value between 1 and 255 to the function.

Related

Anychart Android Java export chart as SVG or PNG in specific local folder

I was trying to create and save an image with AnyChart for an android application. This image is created without being rendered since the idea is to use the data from a vector to generate the image and save it on the phone's memory. I am using Java for programming the android application.
I have been testing the ".saveAsPng()" and ".saveAsSVG()" functions from the Anychart Library but there has been no success... I don't receive an error but I don't get the image either... and I don't know exactly how to proceed...
I tried to follow this guideline (https://docs.anychart.com/Common_Settings/Server-Side_Rendering) but as I said, I haven't succeeded in generating and saving the file.
This is the code that I have been using:
private class CustomDataEntry2 extends ValueDataEntry {
CustomDataEntry2(double x, Number value) {
super(x, value);
}
}
_
List<DataEntry> dataLateral = new ArrayList<>();
for (int p=0; p<DataX.size();p++) {
dataLateral.add(new CustomDataEntry2(DataY.get(p), DataX.get(p)));
}
AnyChartView anyChartViewLateral = new com.anychart.AnyChartView(this);
APIlib.getInstance().setActiveAnyChartView(anyChartViewLateral);
anyChartViewLateral.setProgressBar(new ProgressBar(this));
Polar polarLateralImage = AnyChart.polar();
polarLateralImage.startAngle(90);
Linear xScaleLateral = Linear.instantiate();
xScaleLateral.minimum(-180).maximum(180);
xScaleLateral.ticks().interval(90);
polarLateralImage.xScale(xScaleLateral);
Line polarSeriesLine = polarLateralImage.line(dataLateral);
polarSeriesLine.closed(false).markers(true);
polarSeriesLine.markers().size(3);
polarLateralImage.autoRedraw(true);
anyChartViewLateral.setChart(polarLateralImage);
polarLateralImage.saveAsPng(400,400,0.3,"testImage.png");
Could anyone tell me what am I missing or what amb I doing wrong? I know I might be asking too much, but if it were possible, I would be happy if someone could provide a code snippet that works.
Thank you very much!
Unfortunately, the current version of the AnyChart Android native library doesn't support exporting features, it was no implemented yet.

Kivy Android Camera API 2 - Camera Rotation

I am using the camera feature defined in the following repo but with some changes. I just want to rotate the SurfaceTexture defined in camera2.py so that the camera can also work in portrait mode.
I tried Push- and Pop- Matrix solution but it shadows the buttons in the camera. Hence, I want it to be solved on the Java side rather than the Kivy side.
This is the link to the repo:
https://github.com/inclement/colour-blind-camera
This is where the main problem lies in:
https://github.com/inclement/colour-blind-camera/blob/master/camera2/camera2.py
I do not add the whole snippet here since it is too long but it is basically somewhere around the following snippet (Line 263):
self.preview_resolution = resolution
self._prepare_preview_fbo(resolution)
self.preview_texture = Texture(
width=resolution[0], height=resolution[1], target=GL_TEXTURE_EXTERNAL_OES, colorfmt="rgba")
logger.info("Texture id is {}".format(self.preview_texture.id))
self.java_preview_surface_texture = SurfaceTexture(int(self.preview_texture.id))
self.java_preview_surface_texture.setDefaultBufferSize(*resolution)
self.java_preview_surface = Surface(self.java_preview_surface_texture)
Any help appreciated a lot!

Unity AndroidJavaObject not working without showing errors

I have been trying to call a Java method in unity. Not working for me, even the simplest example from the docs
using System.Collections;
using UnityEngine;
public class ExampleClass : MonoBehaviour {
void Start () {
AndroidJavaObject jo = new AndroidJavaObject ("java.lang.String", "some string");
int hash = jo.Call<int> ("hashCode");
Debug.Log ("hash=" + hash);
}
}
Unity console prints hash=0, which is not the hash code for provided String. Even if I change and use java.lang.StringInvalidClass as class name, unity still reports same result to the console without notifying errors. I can even try to call toString, toStringa, toInvalid2 and they always return empty string without showing errors.
This is a brand new 2d project with only script displayed above, attached to camara object. I am using Ubuntu, Unity 2019.4 and project platform is Android.
Thanks for the assistance.
Answering myself after some time working with unity.
All examples in the web and unity documentation doesn't mention it, which is weird since it is something simple to mention and about confusions: code needs to run as an android application. Editor or even unity remote does not work, in order to use AndroidJavaObject and related classes, your code needs to run as an android application installed in the phone.

Android: setPictureFormat() error

I'm a beginner in Andoird, currently trying to write an application using the Camera class of Android in Eclipse. The problem is when I call the parameters.setPictureFormat() method with ImageFormat.JPEG as the argument, I get an error.
Here's how my code looks like:
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h){
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(854,480); // (h,w)
parameters.setPictureFormat(ImageFormat.JPEG);
parameters.set("jpeg-quality", 100);
parameters.set("orientation", "lanscape");
parameters.set("rotation", 90);
mCamera.setParameters(parameters);
mCamera.startPreview();
}
And I get this error in return:
ImageFormat cannot be resolved to a variable
I've tried using PixelFormat.JPEG as well, but I get the same error that says "PixelFormat cannot be resolved to a variable". I've checked, it's not importing android.R. I also tried importing android.graphics.ImageFormat but it doesn't work.
Could anybody help point out what the problem is?
For what target are you trying to build this app? android.graphics.ImageFormat is only available for android 2.2. I suppose your selected target is android 2.0 or below.
Two important points:
For Android 1.5 and Android 1.6, you
can't call setPictureFormat. Only
getPictureFormat is supported.
For Android 2.0 you will need to call
getSupportedPictureFormat to get the
list of formats supported.

How to make a J2ME application run in Background?

I have a written a J2ME application which uses Bluetooth and search a file within the peer mobile and download it. I would like to make my application run in background , whenever I get a call , or message and later resume after few seconds , Has anybody worked on this please share your experience . Is there any way to run a Midlet in background ?
to set a j2me app to the background use the following in your midlet class:
Display.getDisplay (this).setCurrent (null);
to get the screen back use the following:
Display.getDisplay (this).setCurrent (myCanvas);
Where myCanvas is your canvas instantiation
R
p.s. You can still use a thread or timer to do things in the background while your midlet is hidden.
p.s.2: this does not work on all models. (Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others.
A device's ability to run an application in the background depends on its ability to multitask. Therefore, more expensive, PDA-type devices are more likely to support background execution than lower-cost devices.
For in background :-
private Display display = Display.getDisplay(this);
private Displayable previousDisplayable;
public void toBack() {
previousDisplayable = display.getCurrent();
display.setCurrent(null);
}
And to come in Fore ground :-
public void toFront() {
display.setCurrent(previousDisplayable);
}
But be aware that it not supports every device.(Works on Nokia s60, SonyEricsson, but not on Nokia s40, Samsung and some others).

Categories