There are several articles/tutorials to use Accessibility service on Android to find elements by id/text but there is None (that I could find) which makes use if XPath.
As far as my understanding goes, Accessibility service would take a snapshot of the current ui hierarchy with corresponding attribute and then would search the id/text.
This is significantly slower than having a direct XPath to the element we already have knowledge of - no need to take snapshot of whole ui or search for text in it. (Please correct me if I'm wrong) and can even interact when the item is below the screen; i.e. it has potential to click item when it's not visible yet and will be so after scrolling.
Android does have support of javax.XPath https://android-doc.github.io/reference/javax/xml/xpath/package-summary.html but I couldn't find any sample to try it on.
Any link/resource/guidance will be appreciated. Use of external libraries is fine as well assuming it doesn't hinder performance. Idea is to click an element (I have XPath for it) as soon as it is inflated/rendered in apps making use of some kind of webview element.
Related
I always wonder how apps like Airbnb, Flipkart, and Swiggy update their UI on the fly. Even if I didn’t update the app, Flipkart shows different UIs during festivals, while Swiggy always changes its UI based on the device location.
How I implement this in my react-native-app?
Webview is the solution?
Kindly help me..
Thanks
There are multiple ways you can go about doing this.
One way would be to use WebViews as you've mentioned, this would make it trivial to change the interfaces as it's entierly controled in the servers. But the main issue with this approch will be performance and non native look and feel. These are the two main advantages of using React Native over hybrid frameworks in the first place and therefor, it wouldn't make much sense to use WebViews everywhere. But if there's a small slice of your application that updates regularly(ex - terms of service) you could use a WebView to do the custom views.
A more common way that's low effort would be to have all the code in place for the different looks, but use feature flags to toggle different views. This would work the same way that a dark theme would work. The amount of customization we can do this way is limited because we need to code everything ahead of time.
Another way is to use server driven UIs. With this approch, you will have a pre defined templates in the client that you them populate on run-time with data from the server. For a very simple example, you could have a header image that could be populated with a seasonal greeting image. But instead of simple things like images, this can be much more visible chagnes as well. (ex - List view instead of Grid View)
One more involved way would be to use code push. This would allow things like seasonal UI changes. But this requires a lot more setup and might not provide the best user experience.
Webview is best because this way you can change the UI and the business logic or UI handling logic.
But you have to develop a minimum architecture for that.
Here is my way.
Develop Host layer to use camera, shared preference, file system etc.
Develop a communication layer which will be responsible for communication between your webview and the host layer so that your webview can access all the required device platform(eg. android or ios) features which can not be normally accessed directly from webview.
So now you can render whatever UI(by HTML and CSS) you want, you can put whatever logic you want via javascript also now you can access all the required device features you really need.
So, now you are the king of your app.
Just you have to keep updating the UI or logic in server when you really need.
Some cons are there like
webview in android is different than our normal browser. Some required features are not available.
Its behaviors is different in different API level. So you have to test it very well. For testing, you can use Genymotion.
It does not work well in some old devices/APIs.
Look and feel really matters. But smart design can fix that problem.
If you want your whole app in a single webview then you have to compromise with page transition feature of android or ios. But again smart animation design will fix that.
But this is just a working solution not a smart solution for server driven UI.
I have used some server driven UI frameworks. But they seems to be overhead and lacks some features.
So there should be a framework by which we can render native UI dynamically from server with corresponding business logic change feature and accessibility of all the possible device functionalities.
A few months before I started to develop a Server driven UI framework. I did it little bit. But due to lack of time I really could not complete it.
If someone interested to contribute in this project feel free to contact with me.
I have a solid idea and architecture for this project.
This framework can create a revolution in the world of app development.
email: bedmad82#gmail.com
Sorry for the poorly worded title, allow me to explain.
I have an idea for a translator app that will translate any text across all apps. Is it possible to create a listener that can watch all apps, and whenever a TextView is created, modify the content if the content contains a certain keyword?
Thanks!
It may be possible through the Accessibility API, by implementing an AccessibilityService. I've never used it myself, so I'm not sure, though.
But AccessibilityNodeInfo sounds promising:
This class represents a node of the window content as well as actions that can be requested from its source.
I have android application that is written "regular" way. layouts, java, APK.
Now, depending on some factors I want data to be presented differently to different users with different preferences, etc. Doing it using XML layouts will be very problematic in couple of reasons:
Upgrade issue - we have bunch of users and they not good at upgrading.
Hard to maintain and code.
So, I'm toying with idea of "templates" where we can serve templates from server and just use device to generate those.
Web app won't work because our data available offline in case there is no connection.
There is buttons and stuff that user can press to call regular Activities and do things.
I envision something like:
HTML 5 template with {tags} that I will populate from data. I will receive tempaltes and data separately from server. I will merge that data and display on UI.
Now my question is how do I:
Display HTML5 inside Activity
Intercept button push in HTML in my Java code?
Is this bad idea to write something like this?
It sounds reasonable to me. You can use a WebView for displaying the content. Your app can manage a cache of downloaded templates and other content and display it in the web view either from the web site or from the cache if offline.
I think your objections to layouts are offbase. You really might be better off with layouts. Here's why:
Your app can be set to auto-update by users if you do not change permissions. But pushing updates to your app will remain an issue unless your app is entirely web-based. (not a bad approach by the way) But so long as you have a native app, you will need to push updates from time to time.
And as far as being hard to maintain and code, layouts are specifically designed to make this type of customization manageable. You can break pieces of the layout common to different settings into separate files, and add them with includes.
You can use fragments to adapt to a variety of form factors.
You can serve up different layout based on screen size, language, orientation, or any of a wide variety of variables.
Check out some of the series on layout tricks, and get more familiar with being a layout power user. I think in the long run it will save you a lot of effort, assuming you don't switch to making your app a web app instead.
http://android-developers.blogspot.com/2009/02/android-layout-tricks-2-reusing-layouts.html
http://developer.android.com/resources/articles/layout-tricks-merge.html
http://android-developers.blogspot.com/2009/02/android-layout-tricks-1.html
http://www.curious-creature.org/2009/03/16/android-layout-tricks-4-optimize-part-2/
Google: Android Layout Tricks.
Great stuff.
Another benefit: Compiler checking. No broken functionality because a variable or field has the wrong name. Not the case with HTML.
Another benefit: works offline too with no messing around.
And last - you will have a non-trivial amount of work attempting to get this hybrid HTML stuff working the way you want, and then have a very unusual and custom code base that nobody here on Stack Overflow will be able to help you with. Stick with Layouts and there are lots of experts who can help you tackle the stickiest layout puzzles.
I'm working on an app that involves displaying comments from a website. These comments are threaded on the original site, so I'd like to replicate that experience within the app. I know that Android has an ExpandableListView, but it only does two levels and I was hoping for more.
Each top-level content would be aligned to the left. Replies would be indented by x units, replies to the reply would be indented x*2 units, etc.
Additionally, I'd like the ability for the user (or even the application code) to minimize/maximize threads. This would be particularly useful if the first comment has 8724 replies - you could just minimize the original comment instead of scrolling endlessly until you reach the second top-level comment.
What is the best way to present this multi-level list to the user? Are there any native/third-party classes/libraries I can use, or would I be better of coding this list in HTML and displaying that to the user instead?
I don't really think you should use a tree for displaying thread. Device screens are too small for this kind of widget. I would prefer multiple activities for displaying different levels of the thread. But I'm not a UI designer so my opinion may be far from the ideal solution.
EDIT: Here's an open-source tree-view widget: http://code.google.com/p/tree-view-list-android/.
I have a long "cities" list. I was looking for an equivalent to
sectionIndexTitlesForTableView in the iphone world. It provides a way to "jump" to a particular point in long lists without having to scroll through all the elements. I think FastScrollView implements this but it's not part of the API and I can't find any documentation on how to use it. It appears in the baked in contacts application of the device. I want to use this functionality within an AlertDialog. Is this possible?
Fast scroll can be used for any list; the most common being the alphabetical lists. You can write your own custom SectionIndexer for other fast scrolling operations such as moving to a list based on some other attribute of your list item (e.g. name, address - where section indexer will be alphabetical, and phone number, address etc where it can be numerical)
P.S. This is more of a comment aimed at matto1990's answer.
Fast scroll is something you can only use in alphabetical lists really. The view which pops up (to show where you are) can only provide space for a single letter. I've looked in the source code for ways to extend it, however lots of the methods needed are protected and can only be used by classes in the same package (the core framework one).
The only thing I can think to do is to just write it all yourself. It's annoying but until Google make it possible for us to extend it via an API that's the best that's possible.
My similar question