Get pointer to onscreen keyboard view on Android - android

I am working to tint all UI elements reddish in an astronomy app. I have successfully done this for basically everything except the onscreen keyboard. I need to get a reference to the keyboard's Window or View in order to do this. I have not found anything in the API for doing so.
Can anyone suggest a way for me to get hold of this? I have seen postings explaining (a hack for) how to learn when the keyboard is shown or hidden, but not to actually get a reference to the view.
Thanks
Bill

Can anyone suggest a way for me to get hold of this?
Write your own input method editor and hope users use it. You cannot affect other developers' code this way.

Related

UI Automator with custom keyboard. Find exact keyboard button and click it

I'm trying to write UI automation tests for the custom soft keyboard using UI Automator and\or Espresso. Tried different ways but I can't find a proper solution to "find the exact button on the opened keyboard and click it".
Problems:
UIAtomator's UiDevice.findObject(By.text("Q")).click() doesn't find Q button on keyboard.
Espresso's onView(withText("Q")).perform(click()) doesn't find the button either.
For now, it looks like the only way to click button is to measure XY coordinates based on screen height and keyboard height. But this solution is ugly and not persistent.
typeText("text")and uiObject.text = "text" don't work since it bypasses keyboard input.
Was anyone working with custom keyboards? Please help.
Since you're building a custom soft keyboard then I expect you're using a KeyboardView. KeyboardView draws the keys using a canvas therefore it is not possible to get the resource ids of the keys... so no chance to find them through the UiDevice's findObject method.
Considering the KeyboardView class is deprecated since API 29, a possible solution will be to reimplement your own KeyboardView (as suggested here) and use AccessibilityNodeInfo class to build virtual elements (one for each key) that will be included into the view hierarchy.
The best solution in my opinion would be to create your own TCP server to solve this issue. Please refer to this link to find out how: https://ops.tips/blog/a-tcp-server-in-c/

How can I get the height of keyboard of current input method without showing it?

It seems that it cannot be achieved through InputMethodManager, but there seems to be a method getHeight() in Keyboard.
Thanks in advance.
EDIT
I am not writing my own input method.
This isn't the perfect answer, but it might help. From what I gather, you are looking for the keyboard height?
https://stackoverflow.com/a/16789324/3436942 suggests that this isn't quite as easy as you would hope, but may be a solution for you?
(1) Is there any way in android to get the height of virtual keyboard of device 's answer here suggests using Viewtree Observer and global layout listener, where you could possibly 'flash' the keyboard on screen (not perfect, I know). Or maybe (somewhere else in the program) store this vairable in a pointer. Then find 'height difference'.
(2) the answer to https://stackoverflow.com/a/6375724/3436942 says you can't, but maybe (again) find the height of your view instead?
Just suggestions, as it seems this question does not have an answer unfortunately.

Custom fonts for home screen widget TextView in android

the issue I face seems to have no solution and to be downright impossible to rectify, but I thought to ask here just in case I am missing something.
I need to display some text in an android widget using a non-system, non-standard font from assets folder.
Unfortunately, android does not allow extended view definitions in home screen widgets. Nor I can invoke a corresponding API method (setTypeface) from within the widget.
Does anyone know if there's any other alternative way to accomplish this?
(It seems quite natural to be able to customise text view appearance not only in the app but in widgets too, but it turns out to be impossible).
I'd appreciate any help on this.
Thank you...
Have you seen this link yet?
What is needed is to render the font onto a canvas, and then pass it
on to a bitmap and assign that to an imageview.
How to use a custom typeface in a widget?
By the way, you've asked 18 questions and have not accepted a single answer. I suggest you start accepting some or people will be less inclined to help you.

Creating a custom ui element and making it respond to user input

I have a volume knob and would like to know how to make it respond to user input in android. Please point me in the right direction as i have no idea how i can go about it ? Custom Knob looks like something created in this article. My question is what would be the general approach to port this knob into an android application. Do i have to extend the view class and draw this as a Bitmap. If so how exactly would i respond to user input. If this is not possible and i am on the wrong track could someone please tell me how to achieve this?
I would extend the View class.
View is the baseclass for widgets in android (by widgets I mean textfields, buttons, etc), so I think a volue knob would fit right in among those. About the user input, I'm not so sure. I think it depends on how you want to control the knob. I think looking at the onTouchEvent(MotionEvent) would be a good start. My guess is that you will need to overload a similar method anyways.
Related links:
http://developer.android.com/reference/android/view/View.html
http://www.vogella.com/articles/AndroidGestures/article.html

Appcelerator: Proper Way Automatically Dismiss Keyboard

I'm writing an app using Titanium. I want to be able to automatically dismiss the keyboard anytime something outside of the text field is clicked. I have yet to find an elegant solution for this issue.
Couple things that I've thought about, but am still looking for a better solution:
Assign event listeners to basically everything else present in the view, and dismiss the keyboard (using textField.blur()). I want to avoid this since it results in a LOT of code just to dismiss the keyboard. Also, if I end up adding anything else to the view, I'll have to add a click listener to that object as well, so it's not very maintainable.
Create a large transparent view, and have it take up the entire screen. Place it directly beneath the text field and add to it one click listener on that which will dismiss the keyboard. This is a better solution than #1, but still isn't great because I've had a lot of trouble getting zIndexes to work properly. It's also inefficient for my purposes because I've got views with a specific width and height that encapsulate text fields. I've used these for the sake of code simplicity and I re-use them throughout my application.
I've tried adding a listener for the "blur" event for the text field but that doesn't seem to get fired appropriately.
That's about it. I'm sort of at a loss. The zIndexing also behaves strangely on the iPhone, and I haven't tried on Android yet. Also, as I mentioned above, many of the text fields I use are encapsulated within small views with set widths/heights-- so I think that will affect the functionality of Z-indexes.
So the root question is: What's the best way to dismiss a keyboard whenever anything outside the text field that's in focus is clicked?
If I'm correct the click event propagates through all views and windows therefore your #1 option could be modified to check for clicks on the bottom most layer (view or window), check for its source then decide what to do.

Categories

Resources