Use AccessibilityNodeInfo to turn switch on and off - android

Okay, so I want to know if it is possible to use AccessibilityService/AccessibilityNodeInfo to turn an android.widget.Switch on/off? Here is my current code and it works to click the text on the screen, but it does not turn a switch on/off.
public void onAccessibilityEvent(AccessibilityEvent event) {
AccessibilityNodeInfo source = event.getSource();
if (source == null) {
return;
}
Log.v(TAG, "Event happened");
processUI(source);
}
And of course, the processUI does everything like compares package, text, etc. and sends it all to clickScreen where it actually clicks the screen.
protected void clickScreen(AccessibilityNodeInfo source, final String text, final String type, final int length)
{
Log.v(TAG, "Clicking: " + source + " / " + text + " / " + type + " / " + length);
if (text == null)
{
Log.v(TAG, "Text is NULL");
return;
}
List<AccessibilityNodeInfo> list = source.findAccessibilityNodeInfosByText(text);
for (AccessibilityNodeInfo node : list) {
Log.i(TAG, "SHOULD BE CLICKING: " + node);
node.performAction(4);
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
list = source
.findAccessibilityNodeInfosByText(text);
for (AccessibilityNodeInfo node : list) {
Log.i(TAG, "MIGHT BE CLICKING: " + node);
node.performAction(4);
node.performAction(AccessibilityNodeInfo.ACTION_CLICK);
}
}

Related

Position indicator in HERE SDK premium is not showing

Here is my simple implementation.
The MapFragment is already initialized. If I do the simulation mode the position indicator is showing but if I switched to the actual TBT navigation it is not showing where I am located.
PositionManager positioningManager;
if(positioningManager == null) {
positioningManager = PositioningManager.getInstance();
positioningManager.addListener(new WeakReference<>(positionChangedListener));
positioningManager.start(PositioningManager.LocationMethod.GPS_NETWORK);
}
positionIndicator = mMap.getPositionIndicator();
positionIndicator.setVisible(true);
positionIndicator.setAccuracyIndicatorVisible(true);
private PositioningManager.OnPositionChangedListener positionChangedListener =
new PositioningManager.OnPositionChangedListener() {
#Override
public void onPositionUpdated(PositioningManager.LocationMethod locationMethod,
GeoPosition geoPosition, boolean b) {
Log.d(TAG, "onPositionUpdated " + locationMethod.name());
Log.d(TAG, "Coordinates " +geoPosition.getCoordinate());
}
#Override
public void onPositionFixChanged(PositioningManager.LocationMethod locationMethod,
PositioningManager.LocationStatus locationStatus) {
Log.d(TAG, "onPositionFixChanged " + locationMethod.name() + " status " + locationStatus.name());
}
};

How to disable input from the Amazon Fire TV Controller once an Click Listener has been pressed?

I have a list view with a list of channels on them and when I press one of the channels, it starts to load a streaming URL to watch the channel. However, I can still navigate through the list and select another entry in the list which causes an Exception to occur. How can I disable controller input similar to how I can disable touch input once something has been pressed?
Here is the code for my onItemClickListener:
channel_list_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
main_progressBar.setVisibility(View.VISIBLE);
//to disable touch input
//getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
final int channel = channelListAdapter.getItem(position);
final String switch_major = majorChannelNumberList.get(channel);
Log.d(TAG, "Switch Major :" + switch_major);
final String switch_minor = minorChannelNumberList.get(channel);
Log.d(TAG, "Switch Minor :" + switch_minor);
final String switch_name = channelNameList.get(channel);
Log.d(TAG, "Switch Name :" + switch_name);
final String tuner = tuneLink + "Major=" + switch_major + "&Minor=" + switch_minor + "&Resolution=" + "1280x720";
Log.d(TAG, "Tuner String :" + tuner);
new Thread(new Runnable() {
#Override
public void run() {
String playlive = "";
String tuneResponse = tuneConnection.get_response(tuner);
if(tuneResponse.contains("successful")){
long startTime = System.currentTimeMillis();
do {
String hlsStatusResponse = hlsConnection.get_response(HLSLink);
Log.d(TAG,"HLS Status Response :" + hlsStatusResponse);
Matcher matcher = Pattern.compile("<hls_link>(.+?)</hls_link>").matcher(hlsStatusResponse);
while(matcher.find()){
playlive = matcher.group(1);
}
playlink = "http://" + ip + "/" + playlive;
} while (Objects.equals(playlive, "none") && (System.currentTimeMillis()-startTime)<20000);
if(!playlink.contains("none")){
streamConnection.get_response(playlink);
} else {
//TODO: implement some sort of message here to show no channel, see tablet app
}
} else {
Toast.makeText(OfflineActivity.this, "Ch " + switch_major + "-" + switch_minor + " " + switch_name + " is not available now",
Toast.LENGTH_LONG).show();
}
}
}).start();
//start player activity
streamConnection.responseHandler = new Handler(){
#Override
public void handleMessage(Message message){
Toast.makeText(OfflineActivity.this, "Tune to Channel " + switch_major + "-" + switch_minor, Toast.LENGTH_LONG).show();
Intent intent = new Intent(OfflineActivity.this, OfflinePlaybackActivity.class);
intent.putExtra("stream",playlink);
intent.putExtra("channel_index", channel);
startActivity(intent);
main_progressBar.setVisibility(View.INVISIBLE);
}
};
}
});
I know I can use
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
to disable touch input, looking for something similar for Amazon Fire TV.
Decided to use channel_list_view.setClickable(false) to prevent user from clicking on it.

How to Extract Name,Phone Number and Email Address From Vision OCR result text in Android?

Here is my sample code where i want to get details...
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PHOTO_REQUEST && resultCode == RESULT_OK) {
launchMediaScanIntent();
try {
Bitmap bitmap = decodeBitmapUri(this, imageUri);
if (detector.isOperational() && bitmap != null) {
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray<TextBlock> textBlocks = detector.detect(frame);
String blocks = "";
String lines = "";
String words = "";
for (int index = 0; index < textBlocks.size(); index++) {
//extract scanned text blocks here
TextBlock tBlock = textBlocks.valueAt(index);
blocks = blocks + tBlock.getValue() + "\n" + "\n";
for (Text line : tBlock.getComponents()) {
//extract scanned text lines here
lines = lines + line.getValue() + "\n";
for (Text element : line.getComponents()) {
//extract scanned text words here
words = words + element.getValue() + ", ";
}
}
}
if (textBlocks.size() == 0) {
scanResults.setText("Scan Failed: Found nothing to scan");
} else {
scanResults.setText(scanResults.getText() + "Blocks: " + "\n");
scanResults.setText(scanResults.getText() + blocks + "\n");
scanResults.setText(scanResults.getText() + "---------" + "\n");
scanResults.setText(scanResults.getText() + "Lines: " + "\n");
scanResults.setText(scanResults.getText() + lines + "\n");
scanResults.setText(scanResults.getText() + "---------" + "\n");
scanResults.setText(scanResults.getText() + "Words: " + "\n");
scanResults.setText(scanResults.getText() + words + "\n");
scanResults.setText(scanResults.getText() + "---------" + "\n");
}
} else {
scanResults.setText("Could not set up the detector!");
}
} catch (Exception e) {
Toast.makeText(this, "Failed to load Image", Toast.LENGTH_SHORT).show();
Log.e(LOG_TAG, e.toString());
}
}
}
You have nice libraries to parse link (emails,websites etc) like org.nibor.autolink
Concerning numbers you can have a look to libphonenumber. It is proposed by google and used by android. If you provide the country it can parse for you any format of the number.
Concerning names it is difficult. If you are using your app only for a country you can create a database with the names (in france we have a file in opendata proposed by a public servive) but it won't be complete...

onSimulatorDataUpdated() not getting called

private void initFlightController() {
DJIAircraft aircraft = DJISimulatorApplication.getAircraftInstance();
if (aircraft == null || !aircraft.isConnected()) {
log("initFlightController: aircraft not connected");
showToast("Disconnected");
mFlightController = null;
return;
} else {
log("initFlightController: aircraft CONNECTED");
mFlightController = aircraft.getFlightController();
DJISimulator djiSimulator = mFlightController.getSimulator();
log("initFlightController: djiSimulator has started : "+djiSimulator.hasSimulatorStarted());
djiSimulator.setUpdatedSimulatorStateDataCallback(new DJISimulator.UpdatedSimulatorStateDataCallback() {
#Override
public void onSimulatorDataUpdated(final DJISimulatorStateData djiSimulatorStateData) {
log("onSimulatorDataUpdated: ");
new Handler(Looper.getMainLooper()).post(new Runnable() {
#Override
public void run() {
String yaw = String.format("%.2f", djiSimulatorStateData.getYaw());
String pitch = String.format("%.2f", djiSimulatorStateData.getPitch());
String roll = String.format("%.2f", djiSimulatorStateData.getRoll());
String positionX = String.format("%.2f", djiSimulatorStateData.getPositionX());
String positionY = String.format("%.2f", djiSimulatorStateData.getPositionY());
String positionZ = String.format("%.2f", djiSimulatorStateData.getPositionZ());
mTextView.setText("Yaw : " + yaw + ", Pitch : " + pitch + ", Roll : " + roll + "\n" + ", PosX : " + positionX +
", PosY : " + positionY +
", PosZ : " + positionZ);
}
});
}
});
}
}
I am testing the sample code given for android in Dji-Developer. Every thing goes fine but the onSimulatorDataUpdated() doesnt get called.
it even prints the log
"initFlightController: djiSimulator has started : true"
I found the solution for the problem. The code doesn't have any problem, the RC has a button at the left front area which has to be set to P mode.

aChartEngine, GraphicalView OnClickListener not working

I'm new to android and am using aChartEngine to create a bar chart. I want to capture the x and y values when a user clicks on the chart. I have looked at the demos from aChartEngine and have my chart creating fine. However the onClickListner does not work when I click on the graphy. I have defined the listener in the OnResume method but it doesn't work. Any ideas would be greatly appreciated. Am I missing something here?
Here is my OnResume method which is taken from XYChartBuilder
#Override
protected void onResume() {
super.onResume();
Toast.makeText(Clickable2.this, "In OnResume", Toast.LENGTH_SHORT).show();
if (mChartView == null) {
Toast.makeText(Clickable2.this, "mChartView is null", Toast.LENGTH_SHORT).show();
LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
mChartView = ChartFactory.getBarChartView(this,mDatasetMethod(titles,x,values),renderer,Type.DEFAULT);
renderer.setClickEnabled(true);
renderer.setSelectableBuffer(100);
//OnClickListener
mChartView.setOnClickListener(new View.OnClickListener() {
// #Override
public void onClick(View v) {
Toast.makeText(Clickable2.this, "ON CLICK", Toast.LENGTH_SHORT).show();
SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
double[] xy = mChartView.toRealPoint(0);
if (seriesSelection == null) {
Toast.makeText(Clickable2.this, "No chart element was clicked", Toast.LENGTH_SHORT)
.show();
} else {
Toast.makeText(
Clickable2.this,
"Chart element in series index " + seriesSelection.getSeriesIndex()
+ " data point index " + seriesSelection.getPointIndex() + " was clicked"
+ " closest point value X=" + seriesSelection.getXValue() + ", Y=" + seriesSelection.getValue()
+ " clicked point value X=" + (float) xy[0] + ", Y=" + (float) xy[1], Toast.LENGTH_SHORT).show();
}
}
});
//LongClickListener
mChartView.setOnLongClickListener(new View.OnLongClickListener() {
// #Override
public boolean onLongClick(View v) {
SeriesSelection seriesSelection = mChartView.getCurrentSeriesAndPoint();
Toast.makeText(Clickable2.this, "ON LONG CLICK", Toast.LENGTH_SHORT).show();
if (seriesSelection == null) {
Toast.makeText(Clickable2.this, "No chart element was long pressed",
Toast.LENGTH_SHORT);
return false; // no chart element was long pressed, so let something
// else handle the event
} else {
Toast.makeText(Clickable2.this, "Chart element in series index "
+ seriesSelection.getSeriesIndex() + " data point index "
+ seriesSelection.getPointIndex() + " was long pressed", Toast.LENGTH_SHORT);
return true; // the element was long pressed - the event has been
// handled
}
}
});
mChartView.addZoomListener(new ZoomListener() {
public void zoomApplied(ZoomEvent e) {
String type = "out";
if (e.isZoomIn()) {
type = "in";
}
System.out.println("Zoom " + type + " rate " + e.getZoomRate());
}
public void zoomReset() {
System.out.println("Reset");
}
}, true, true);
mChartView.addPanListener(new PanListener() {
public void panApplied() {
System.out.println("New X range=[" + renderer.getXAxisMin() + ", " + renderer.getXAxisMax()
+ "], Y range=[" + renderer.getYAxisMax() + ", " + renderer.getYAxisMax() + "]");
}
});
layout.addView(mChartView, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT));
boolean enabled = mDataset.getSeriesCount() > 0;
} else {
mChartView.repaint();
Toast.makeText(Clickable2.this, "mChartView is NOT null", Toast.LENGTH_SHORT).show();
}
}
Can you check your code for some definition of an object like XYMultipleSeriesRenderer?
Maybe you forgot to set the setClickEnabled method to true?!
Or maybe you should try:
setOnTouchListener
with the method:
public boolean onTouch(View v, MotionEvent event)
It works for me.
Change the value of parameter of setSelectableBuffer method to a bigger number.

Categories

Resources