How to identify button click using android accessibility? - java

I have located a button using accessibility, now I need to identify when it is pressed.
List<AccessibilityNodeInfo> sendMessageNodeList = getRootInActiveWindow().findAccessibilityNodeInfosByViewId("com.whatsapp:id/send");
if(sendMessageNodeList == null || sendMessageNodeList.isEmpty()){
return;
}
AccessibilityNodeInfo sendMessage = sendMessageNodeList.get(0);
if(!sendMessage.isVisibleToUser()){
return;
}

Related

How to find whether audio recording is empty or not?

I want to add validation of the save button i.e., check if edit text or recorded audio (one among these two) has been entered by the user or not if both are not entered then the user gets notified that either enter text or record your audio. I have done this code, but it's getting crashed onClick of save button
File fileName = new File(finalpath);
Log.e("FileName::",""+fileName);
// convertfiletobase64(strreminder_txt, strreminder_time, finalpath, finalStrcheckDialy);
if (listfiles.size()==0) {
listfiles.add(fileName);
} else {
if (notifiadapeterpos < listfiles.size()) {
listfiles.set(notifiadapeterpos, fileName);
} else {
listfiles.add(fileName);
}
}
notificationPart = prepareFilePart1(listfiles);
if(mediaRecorder==null&&mediaPlayer==null){
if (strreminder_txt.isEmpty()){
Toast.makeText(RegisterMember.this, "Please enter Reminder Text or Record your Reminder!", Toast.LENGTH_SHORT).show();
}else {
if (btnsaveReminder.getText().equals("Update")){
updateReminder(strreminder_txt, strreminder_time, fileName, finalStrcheckDialy,notificationPart);
}else {
saveReminder(strreminder_txt, strreminder_time, fileName, finalStrcheckDialy,notificationPart);
}
}
}
How to resolve this?

How to get button press event from camera

I've got a dental camera and iam try to get windows to press space when the camera button is pressed
I have the OEM software and driver installed, it works perfect, gets the feed and makes a snapshot when camera button is pressed. I need to use another software for the feed and the snapshot, the software gets the feed but doesn't react to camera button, it only reacts to space key press(part of the oem driver), so my way of solving this was getting the device by product id and listening the button press event and remapping it space press.
I am pretty much stuck at this point.
How can I listen on events coming from the device I've got?
public static Device findDCam(){
// Create the libusb context
Context context = new Context();
// Initialize the libusb context
int result = LibUsb.init(context);
if (result < 0)
{
throw new LibUsbException("Unable to initialize libusb", result);
}
// Read the USB device list
DeviceList list = new DeviceList();
result = LibUsb.getDeviceList(context, list);
if (result < 0)
{
throw new LibUsbException("Unable to get device list", result);
}
try
{
// Iterate over all devices and list them
for (Device device: list)
{
DeviceDescriptor descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result < 0)
{
throw new LibUsbException(
"Unable to read device descriptor", result);
}
if(descriptor.idProduct()== -3810){
System.out.println("D cam found");
return device;
}
}
}
finally
{
// Ensure the allocated device list is freed
LibUsb.freeDeviceList(list, true);
}
// Deinitialize the libusb context
LibUsb.exit(context);
return null;
}
I've also thought that maybe it's impossible using usb4java since as far as i understood, if i want to listen on the usb port i need to take control from the driver and then its pointless.
Maybe iam going all wrong and i should use the driver instead?
Or maybe there is an app that can read button presses from a specific device and remap it?
If the camera has a standard driver, this should work through this video capture SDK. To quick test it, run the demo executable included in the package, select the camera in the list, check the "webcam snapshot button" checkbox and start the camera. Then press the camera button to test the snapshot.

How to Detect Multiple Images with AR core

I'm trying out detecting multiple augmented images with AR core, with
https://developers.google.com/ar/develop/java/augmented-images/guide
and other online tutorials. Currently, I have the database setup and loaded with images. However
Collection<AugmentedImage> augmentedImages = frame.getUpdatedTrackables(AugmentedImage.class);
did not seem to capture and match the feature points of my images in my db.
Can you advise me about what I need to do?
I have set up and loaded multiple images from db. The app is able to detect only 1 image previously. However, after tweaking my code to detect multiple images, it did not work properly.
Tried researching and debugging however, still unable to solve it.
private void onUpdateFrame(FrameTime frameTime)
{
Frame frame = arFragment.getArSceneView().getArFrame();
Collection<AugmentedImage> augmentedImages = frame.getUpdatedTrackables(AugmentedImage.class);
for (AugmentedImage augmentedImage : augmentedImages)
{
int i =augmentedImages.size();
Log.d("NoImage",""+i);
if (augmentedImage.getTrackingState() == TrackingState.TRACKING)
{
if (augmentedImage.getName().contains("img1") && !modelAdded)
{
renderObject(arFragment, augmentedImage.createAnchor(augmentedImage.getCenterPose()),R.raw.car);
modelAdded = true;
}
else if (augmentedImage.getName().contains("img2") && !modelAdded)
{
renderObject(arFragment, augmentedImage.createAnchor(augmentedImage.getCenterPose()), R.raw.car);
modelAdded = true;
}
else if (augmentedImage.getName().contains("img3") && !modelAdded)
{
renderObject(arFragment, augmentedImage.createAnchor(augmentedImage.getCenterPose()), R.raw.car);
modelAdded = true;
}
}
}
}

How to read notifications correctly on Android

I am developing an App for read notifications all my code work great, but have two problems. I use this code for read notifications:
String pack = sbn.getPackageName();
String ticker ="";
if(sbn.getNotification().tickerText !=null) {
ticker = sbn.getNotification().tickerText.toString();
}
Bundle extras = sbn.getNotification().extras;
String title = extras.getString("android.title");
//String text = extras.getCharSequence("android.text").toString();
String text = null;
if (extras.getCharSequence("android.text") != null) {
text =(String) extras.getCharSequence("android.text");
}
if (text == null) {
// for whatsapp on kitkat second whats app text
// will be null
if (extras.get("android.textLines") != null) {
CharSequence[] charText = (CharSequence[]) extras
.get("android.textLines");
if (charText.length > 0) {
text = charText[charText.length - 1].toString();
}
}
}
The code works, but the problem is with WhatsApp, when I receive more than one message I get the following structure.
Title: NameUser
Text: Hi, how are you? <---- This is ok!
but the second message I get
Title: NameUser
Text : Hi again! <--- This is ok;
Title: NameUser
Text: 2 New messages <---- Agggr that is wrong!!!!!
How can avoid the "2 New messages"??
And the second question is Can I get images send via whatsapp? For the moment I only get the following structure.
Title: NameUser
Text: Image
Thanks in advance
There is no way you can influence (from your app) what notifications are sent by some other app's server to your phone.

JFileChooser set Control Buttons Are Shown are false and 1

I'm having difficulty getting the file back from a JFileChooser when setControlButtonsAreShown() is set to false.
If the user makes a selection of an exisiting file I can get this file with getSelectedFile(), but when they type in a new file name getSelectedFile() returns null.
When I use a JFileChooser with setControlButtonsAreShown(true) and I click on the Save button any filename the user has typed can be obtained with getSelectedFile() as expected, but when setControlButtonsAreShown(false) is used I just can't seem to get this file returned.
This happens even if I call approveSelection(), which supposedly does the same as clicking on the Save button if it had been show.
What am I doing wrong? Or any another way to assign JfileChooser open button action event to customized personal Jbutton?
This the workaround I came up with.
This will iterate through all the components inside FileChooser Container and get the text from the JTextField and set as selection in the FileChooser
Call this after some button click or any event.
private void failProofSetPath(JFileChooser chooser) {
File selectedFileFromTextBox = null;
String text = getTextOfFileViewer(chooser);
if (text != null && new File(text).exists()) {
selectedFileFromTextBox = new File(text);
}
if (selectedFileFromTextBox != null
&& (chooser.getSelectedFile() == null
|| !selectedFileFromTextBox.equals(chooser.getSelectedFile()))) {
chooser.setSelectedFile(selectedFileFromTextBox);
}
}
private String getTextOfFileViewer(Container c) {
int len = c.getComponentCount();
for (int i = 0; i < len; i++) {
Component comp = c.getComponent(i);
if (comp instanceof JTextField) {
JTextField b = (JTextField) comp;
return b.getText();
} else if (comp instanceof Container) {
String val = getTextOfFileViewer((Container) comp);
if (val != null) {
return val;
}
}
}
return null;
}

Categories

Resources