Showing posts with label keyboard. Show all posts
Showing posts with label keyboard. Show all posts

Wednesday, May 23, 2018

Keyboard Extension Memory Leak?

Leave a Comment

I am building a custom keyboard extension (iOS 9+) and have found a more than annoying memory leak.

Just from using the template provided by Apple, there appears to be a nasty memory leak derived from an NSMutableDictionary cycle.

When leaving an application (in this test case the Messages app) then returning, this leak occurs. Typically 25 leaked items (seen in the photos of Xcode's Instruments7 below)

enter image description here

enter image description here

I have literally done nothing to the template but receive this leak. Does anyone have any suggestions on how to fix this?...

EDIT: Because Xcode tends to exaggerate (handle) memory usages differently than any physical device (my case iPhone 6s iOS 11.2), I'm not entirely sure this will even have any impact to the performance / run-life of my keyboard. From testing I did not find any issues. Going back and forth to and from Safari or Messages did not crash or switch back to the default keyboard. Nevertheless... memory leak... not good.

1 Answers

Answers 1

I sometimes find sporadic leaks that Xcode Instruments flags as such, but I cannot do anything about it, because the problem is in Apple's code, which is apparently your case. The only thing you can do is to file a bug report and go on with your project, in particular if the leak is sporadic, and is only a question of a few bytes, and does not build up in time. In summary, if these conditions apply, I wouldn't worry too much about it.

Read More

Monday, April 9, 2018

HTML Input: force numeric keyboard by default but allow letters

Leave a Comment

I have an HTML input. The input is on the web page which is opened in Chrome on an Android phone.

I want an option to let the user to see a numeric keyboard when he starts entering the value. But at the same moment, I want him to have a possibility to enter alphanumeric characters.

  • I cannot use type="number" because it doesn't allow entering letters.

  • I cannot use type="text" because it opens alpha keyboard by default and a user have to switch to numeric keyboard.

So the option I'm trying to find is when the standard alpha-numeric keyboard got opened but the digits input is already selected (Like when you press ?123 on the standard keyboard).

I have tried to use type="tel" but I don't understand how to switch to letters from numbers.

I'm using Cordova, so if there's no option to do this using HTML I could use native plugins if you suggest me any of them.


I use cordova so if there's no HTML way to do things I'm ready to integrate any sort of plugin, if you could suggest me anyone.


TL;DR: This is what I want to see as a default keyboard layout. Is it possible?

enter image description here

1 Answers

Answers 1

You cannot do this as the keyboard layout provided to the user is based on the input type of your input. It would be a bad UI principle to show the user a numeric keypad, when he can in reality enter alphanumeric characters. The tel input type won't let you change the keyboard to a numeric one, since it is specifically designed to accept only phone numbers.

So if you want to let the user enter alphanumeric characters in your input, you should not set the keyboard to be numeric. See the example below:

<input type="text" name="valText"/> 

If on the other hand you want to allow the user to only enter numeric characters, then you should set the input type to number as below:

<input type="number" name="valNumber"/> 

A workaround to this would be to create multiple inputs and set their type to whatever you want the user to enter in that particular field. You can then concatenate them to a single value to save them in that way. However you will need to save them as a concatenated String which contains both characters and numbers.

You can also take a look at the link here to check the different input types you can use in case you find one of them more of use to you. What you must remember however is that the input type will define the keypad layout. You may also take a look at this for a better understanding.

Read More

Tuesday, March 13, 2018

Android show view and hide keyboard at same time. Weird behaviour

Leave a Comment

I have a custom view that could show a view in same space that should be soft keyboard native for android.

I need to having the keyboard opened, click in a button, hide the keyboard and shows other view in same place that keyboard be/was.

I have that implemented right now just with a hide keyboard and show custom view but has a weird behavior and min lag and overlapping.

Has someone implemented a similar stuff?

3 Answers

Answers 1

I have checked the Github project and found the bug and I have fixed that bug with the following code:

if (isRedPanelVisible()) {     showRedPanel(false);     showKeyboard(true, new KeyboardCallback() {         @Override         public void onKeyboardDone(boolean isVisible) {          }     }); } if (KeyboardVisibilityEvent.isKeyboardVisible(TestActivity.this)) {     hideKeyboard(TestActivity.this);     new android.os.Handler().postDelayed(new Runnable() {         @Override         public void run() {             showRedPanel(true);         }     }, 100); 

Note: You just have to put this in TestActivity.java under button's click event and Remove the previous code.

What I did

if your readPanel is visible then I called the showRedPanel to false and try to open the keyboard.

After that I have added a check for Keyboard's visibility event and if keyboard is visible I called hideKeyboard to make keyboard go away and call showReadPanel with true after a delay of 100 ms

Code: hideKeyboard

public void hideKeyboard(Activity activity) {         // Check if no view has focus:         try {             View view = activity.getCurrentFocus();             if (view != null) {                 InputMethodManager inputManager = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);                 inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);             }         } catch (Exception e) {          }     } 

Answers 2

So what happens in your code is that: Tell system to close the keyboard -> Show red panel with a small delay -> Red panel is shown before keyboard closing -> Since keyboard mode is in adjustResize the red panel shown above keyboard -> Keyboard get closed -> Everything in place

Try to change windowSoftInputMode in manifest from adjustResize to adjustNothing.

Sadly keyboard in android doesn't work smoothly like in IOS, keyboard is handled by OS means you are control over it size, opening/closing animation and no callback! So the best way is to always show red panel and when needed Open keyboard on top of it.

Answers 3

se the following functions to show/hide the keyboard:

/**  * Hides the soft keyboard  */ public void hideSoftKeyboard() {     if(getCurrentFocus()!=null) {         InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);         inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);     } }  /**  * Shows the soft keyboard  */ public void showSoftKeyboard(View view) {     InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);     view.requestFocus();     inputMethodManager.showSoftInput(view, 0); } 
Read More

Saturday, January 27, 2018

How to keep fixed html element visible on bottom of screen when the soft keyboard is open on iOS Safari?

Leave a Comment

In a web page I have an input field and a div that is fixed to the bottom of the window (with these CSS properties: position:fixed; and bottom:0;

I made a Codepen to show what I'm talking about: https://codepen.io/anon/pen/xpQWbb/

Chrome on Android keeps the div visible even when the soft keyboard is open:

enter image description here

However, Safari on iOS seems to draw the soft keyboard over the fixed element:

enter image description here

(I should mention I'm testing on the iOS simulator on my Macbook, because I don't have a working iPhone)

Is there a way to make iOS Safari keep the element visible even when the soft keyboard is open, like how Chrome does it?

4 Answers

Answers 1

i experienced this before. What i did back then was :

  1. Make a listener when keyboard is hit.
  2. When keyboard is hit resize you webview's height with screen height - keyboard height.
  3. To do this trick you need to make sure that you html is responsive.

I can show more code in the IOS side, if you're interested i can edit my answer and show you my IOS code. Thank you.

Hi again, sorry, i was mistaken, i thought you were creating apps with webview inside. If you still wanna do this by listening the keyboard i still have work around for you. It may not the perfect way, but i believe this will work if you want to try. Here my suggestion :

  1. You still can have listener from webpage when the keyboard is up. You can put a listener on your textfield by jquery onkeyup or onfocus.
  2. Then you will know when the input is hit and the keyboard will show.
  3. Then you can create a condition in your java script to manipulate your screen.

Hope this give you an insight friend. @Beaniie thank you !.

Answers 2

No, there is no way.

The keyboard is not part of browser process and there is no way for the browser to know when the keyboard opened. All it knows is that it gets resized, if it does. It's the OS's decision to resize the browser (or any other app requesting the keyboard) or to just draw the keyboard over it and, again, the browser has no control over it and no programmable method to determine when it happens.

As a side note, you should not be using position:fixed for anything except a tiny menu opener (and perhaps the menu itself, when open) on mobile devices.

Answers 3

Try using position:absolute and height:100% for the whole page.

When the system displays the keyboard,it plTaces it on top of the app content. One way is to manage both the keyboard and objects is to embed them inside a UIScrollView object or one of its subclasses, like UITableView. Note that UITableViewController automatically resizes and repositions its table view when there is inline editing of text fields.

When the keyboard is displayed, all you have to do is reset the content area of the scroll view and scroll the desired text object into position. Thus, in response to a UIKeyboardDidShowNotification, your handler method would do the following:

1.Get the size of the keyboard.

2.Adjust the bottom content inset of your scroll view by the keyboard height.

3.Scroll the target text field into view.

Check the Apple developer's guideline to learn more:https://developer.apple.com/library/content/documentation/StringsTextFonts/Conceptual/TextAndWebiPhoneOS/KeyboardManagement/KeyboardManagement.html

Answers 4

Check out this thread, it talks about a work around that may be more feasible in terms of code. In brief it talks about using the height of the keyboard to move the content into view. All be it a bit hacky it may be difficult to pin down the exact height of the keyboard across devices.

Unfortunately, due to the nature of the IOs Safari keyboard it's not part of the browser viewport so cannot be referenced as you would do typical elements.

@Bhimbim's answer may a good shot too.

Regards, -B

Read More

Friday, December 1, 2017

binding key event in python using ctypes function

Leave a Comment

I have been trying to use python to bind my customize event to keyboard event with specific event code number like below

ctypes.windll.user32.keybd_event('0x24',0,2,0)

but as you already know

windll

the library only worked on Windows OS. how can I do something like this in Linux machines? I read about

CDLL('libc.so.6')

but I can't figure it out if this library is helpful or not?

is there another way to set keypress listener in OS level with python using the virtual key code?

1 Answers

Answers 1

Linux input subsystem is composed of three parts: the driver layer, the input subsystem core layer and the event processing layer. and the keyboard or other input event is all describe by input_event.

use below code and type in your Terminal python filename.py | grep "keyboard"

#!/usr/bin/env python #coding: utf-8 import os  deviceFilePath = '/sys/class/input/'  def showDevice():     os.chdir(deviceFilePath)     for i in os.listdir(os.getcwd()):         namePath = deviceFilePath + i + '/device/name'         if os.path.isfile(namePath):             print "Name: %s Device: %s" % (i, file(namePath).read())  if __name__ == '__main__':     showDevice() 

you should get Name: event1 Device: AT Translated Set 2 keyboard. then use

#!/usr/bin/env python #coding: utf-8 from evdev import InputDevice from select import select  def detectInputKey():     dev = InputDevice('/dev/input/event1')      while True:         select([dev], [], [])         for event in dev.read():             print "code:%s value:%s" % (event.code, event.value)   if __name__ == '__main__':     detectInputKey() 

evdev is a package provides bindings to the generic input event interface in Linux. The evdev interface serves the purpose of passing events generated in the kernel directly to userspace through character devices that are typically located in /dev/input/.andselect is select.

Read More

Monday, January 16, 2017

android move layout up when soft keyboard is shown with viewpagers

Leave a Comment

ok im already doing (i believe) everything i need to do to make my applications layout scroll/move up when the soft keyboard is shown but it is not working so im guessing there must be something im doing stopping it, i wonder if its the fixed heights im giving my viewpagers or something im unaware of, ive read through posts that describe relative layouts as 'crushing child views' when the keyboard is shown and linear layouts not crushing child views, so with that in mind here are my layouts

MAIN_ACTIVITY

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout     xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity">      <RelativeLayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         app:layout_behavior="@string/appbar_scrolling_view_behavior"         android:id="@+id/viewpagerHolder">          <android.support.v4.view.ViewPager             android:id="@+id/viewpager2"             android:layout_width="match_parent"             android:layout_marginLeft="8dp"             android:layout_marginRight="8dp"             android:layout_marginTop="8dp"             android:layout_height="@dimen/card_pager_height" />          <RelativeLayout             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:id="@+id/predictsHolder"             android:layout_below="@id/viewpager2">          <android.support.v4.view.ViewPager             android:id="@+id/viewpager_predicts"             android:layout_width="wrap_content"             android:layout_marginLeft="8dp"             android:layout_marginRight="8dp"             android:layout_marginTop="4dp"             android:layout_height="@dimen/predicts_pager_height" />          </RelativeLayout>          <android.support.design.widget.TabLayout             android:id="@+id/tabs"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_below="@id/predictsHolder"             app:tabGravity="fill"             android:theme="@style/CustomTabLayoutStyle" />          <LinearLayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_below="@id/tabs">           <android.support.v4.view.ViewPager             android:id="@+id/viewpager"             android:background="@color/windowBackground"             android:layout_width="match_parent"             android:layout_height="wrap_content"              />          </LinearLayout>      </RelativeLayout>  <android.support.design.widget.AppBarLayout     android:layout_width="match_parent"     android:layout_height="wrap_content">      <android.support.v7.widget.Toolbar         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="?attr/actionBarSize" />  </android.support.design.widget.AppBarLayout>  <RelativeLayout     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_marginTop="@dimen/card_pager_height">      <android.support.design.widget.FloatingActionButton         android:id="@+id/fab2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_marginRight="12dp"         android:layout_marginEnd="12dp"         app:elevation="4dp"         android:src="@drawable/ic_playlist_play_white_24dp"         android:layout_gravity="right|top"         android:layout_alignParentRight="true"         android:layout_alignParentEnd="true"/>  </RelativeLayout>  </android.support.design.widget.CoordinatorLayout> 

There a total of 3 viewpagers each has a different layout the first (top most)

FIRST VIEWPAGER

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/border" android:paddingLeft="2dp" android:paddingRight="2dp" tools:context=".SpeakGridDB">  <android.support.v7.widget.RecyclerView     android:id="@+id/card_speak_grid"     android:layout_width="match_parent"     android:layout_gravity="center"     android:layout_height="wrap_content"/>  </RelativeLayout> 

SECOND VIEWPAGER

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="5dp" android:paddingLeft="2dp" android:paddingRight="2dp" android:background="@drawable/border">  <android.support.v7.widget.RecyclerView     android:id="@+id/predicts_card_speak_grid"     android:layout_width="match_parent"     android:layout_gravity="center"     android:layout_height="wrap_content"/>  </RelativeLayout> 

THIRD VIEWPAGER

i would like this layout to still be present when the keyboard pops up its currently the bottom of the layout ive put it in a linear layout and also tried putting its viewpager in a linear layout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:background="@color/windowBackground" tools:context=".OneFragment">  <android.support.v4.widget.SwipeRefreshLayout     android:id="@+id/activity_main_swipe_refresh_layout"     android:layout_width="match_parent"     android:background="@color/windowBackground"     android:layout_height="wrap_content">      <android.support.v7.widget.RecyclerView         android:id="@+id/card_grid"         android:background="@color/windowBackground"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:clipToPadding="false"/>  </android.support.v4.widget.SwipeRefreshLayout>  </LinearLayout> 

I'm also using

        android:windowSoftInputMode="adjustResize" 

in my manifest and have also tried

        android:windowSoftInputMode="adjustPan" 

but no joy it seems like the tabLayout shifts up slightly when keyboard is shown but generally the top two views stay in place and the bottom one (one i want shown) is hidden by the keyboard any help is appreciated

UPDATE still no further with this i can make a layout witht the fixed heights and have it scroll up perfectly with the softkeyboard shown so there not the problem but i must use layout center vertical on an element and this isnt what i want to do ive also tried wrapping it all in a scroll view and using isScrollContainer true but still no joy anyone got any ideas?

2 Answers

Answers 1

I may mistake, but cause of this problem is probably the known Android bug.

So, firstly, you need to add android:windowSoftInputMode="stateHidden|adjustResize" inside your <activity> tag.

Secondly, you need to add this class to your project:

public class AndroidBug5497Workaround {      // For more information, see https://code.google.com/p/android/issues/detail?id=5497     // To use this class, simply invoke assistActivity() on an Activity that already has its content view set.      public static void assistActivity (Activity activity) {         new AndroidBug5497Workaround(activity);     }     private View mChildOfContent;     private int usableHeightPrevious;     private FrameLayout.LayoutParams frameLayoutParams;      private AndroidBug5497Workaround(Activity activity) {         FrameLayout content = (FrameLayout)  activity.findViewById(android.R.id.content);         mChildOfContent = content.getChildAt(0);         mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {             public void onGlobalLayout() {                 possiblyResizeChildOfContent();             }         });         frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();     }      private void possiblyResizeChildOfContent() {         int usableHeightNow = computeUsableHeight();         if (usableHeightNow != usableHeightPrevious) {             int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();             int heightDifference = usableHeightSansKeyboard - usableHeightNow;             if (heightDifference > (usableHeightSansKeyboard/4)) {                 // keyboard probably just became visible                 frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;                 } else {                 // keyboard probably just became hidden                 frameLayoutParams.height = usableHeightSansKeyboard;             }             mChildOfContent.requestLayout();             usableHeightPrevious = usableHeightNow;         }     }      private int computeUsableHeight() {         Rect r = new Rect();         mChildOfContent.getWindowVisibleDisplayFrame(r);         return (r.bottom - r.top);     }  } 

And then simply use it by calling assistActivity() method in your MainActivity that holds ViewPagers:

@Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(...);     AndroidBug5497Workaround.assistActivity(this);     ... } 

For more background check this thread.

Answers 2

You can try adding android:fitsSystemWindows="true" to your coordinator layout

Read More

Thursday, April 28, 2016

How to intercept music control keyboard shortcuts in Java?

Leave a Comment

If your keyboard has buttons for play/pause/etc (music control shortcuts), and you press them, iTunes will open (at least on Mac).

If you recently opened another music player, like Spotify, it will actually intercept the shortcut keys, and iTunes won't do anything.

Well, I want to make a music player with Java, and I want to have the same behavior. I want my application to intercept such shortcuts, and other programs shouldn't be able to interfere.

I am using JavaFX, although I don't think that really matters.

How can I achieve this?

I am already able to detect they keys the user presses using JNativeHook, but I do not know how to intercept the keys so that other applications won't do things with them.

2 Answers

Answers 1

Once you detect the keys, you could send the pause key so that the song that is being played by itunes is paused, you could use a boolean variable to detect between the shortcuts being typed on the keyboard or being send by the program(in case if you need)

or

You could use some c code(start the c program along with your java program) take a look at @Dave Delongs answer over here Modify NSEvent to send a different key than the one that was pressed You could have a different keyboard shortcut and modify the c program to send your shortcut keys while the Itunes Shortcut keys are pressed, if you need the key codes Where can I find a list of Mac virtual key codes?

for example if your music program uses p to play songs and r to listen to the next song, and itunes uses spacebar to play songs and right arrow key to go to the next one, you could do modify @Dave Delongs answer here are the changes :-

#import <Cocoa/Cocoa.h>  CGEventRef myCGEventCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) {  //0x31 is the virtual keycode for "Spacebar" //0x23 is the virtual keycode for "p"   if (CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode) == 0x31) {     CGEventSetIntegerValueField(event, kCGKeyboardEventKeycode, 0x23);   }  //0x7C is the virtual keycode for "Right arrow" //0x0F is the virtual keycode for "R"   if (CGEventGetIntegerValueField(event, kCGKeyboardEventKeycode) == 0x7C) {     CGEventSetIntegerValueField(event, kCGKeyboardEventKeycode, 0x0F);   }    return event; }  int main(int argc, char *argv[]) {   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];   CFRunLoopSourceRef runLoopSource;    CFMachPortRef eventTap = CGEventTapCreate(kCGHIDEventTap, kCGHeadInsertEventTap, kCGEventTapOptionDefault, kCGEventMaskForAllEvents, myCGEventCallback, NULL);    if (!eventTap) {     NSLog(@"Couldn't create event tap!");     exit(1);   }    runLoopSource = CFMachPortCreateRunLoopSource(kCFAllocatorDefault, eventTap, 0);    CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, kCFRunLoopCommonModes);    CGEventTapEnable(eventTap, true);    CFRunLoopRun();    CFRelease(eventTap);   CFRelease(runLoopSource);   [pool release];    exit(0); } 

Answers 2

You may be able to use some of the code from iTunesPatch to accomplish what you're looking for, but it appears that a system daemon may need to be modified upon installation, and you will likely have to use Objective-C/Swift.

There are further details about iTunesPatch in a blog post here.

Read More

Sunday, April 17, 2016

xcode iOS 9 Keyboard Issue

Leave a Comment

My old project is having an issue with the iOS 9 Keyboard. After the library that I developed was installed through Cocoapods, I am getting this error on the simulator when trying to use the Keyboard.

-[UIWindow endDisablingInterfaceAutorotationAnimated:] called on <UIRemoteKeyboardWindow: 0x78f0ff60; frame = (0 0; 1024 768); opaque = NO; autoresize = W+H; layer = <UIWindowLayer: 0x78f10240>> without matching -beginDisablingInterfaceAutorotation. Ignoring. 

Keyboard behavior:

  • Letters with 'accents' (example: â) are popping up even without holding the character

  • The dismiss keyboard button does not dismiss the Keyboard. It will only display the options 'Split' and 'Dock'

Any ideas on why is this happening? Thanks very much

1 Answers

Answers 1

Try reinstalling Xcode, because maybe the application became corrupt somehow, and if that doesn't work, also try deleting its library files (~/library/application support/xcode and ~/library/containers/xcode) because they might also be corrupt. Hope this helps!

Read More

Friday, March 18, 2016

Soft keyboard's POPUP layout

Leave a Comment

I'm developing a soft keyboard and doing well, but I don't know how to customize the popup layout for a long keypress.

My KeyboardView:

<?xml version="1.0" encoding="UTF-8"?> <android.inputmethodservice.KeyboardView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/keyboard" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:keyPreviewLayout="@layout/preview" android:keyBackground="@drawable/key_selector" android:shadowRadius="0.0" android:keyTextColor="#000000" /> 

My keyboard layout:

<?xml version="1.0" encoding="utf-8"?> <Keyboard xmlns:android="http://schemas.android.com/apk/res/android" android:keyWidth="10%p" android:keyHeight="10%p">  <Row android:verticalGap="1%p"  android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p">     <Key android:codes="113"    android:keyLabel="q" />     <Key android:codes="119"    android:keyLabel="w" />     <Key android:codes="101"    android:keyLabel="e"           />     <Key android:codes="114"    android:keyLabel="r" />     <Key android:codes="116"    android:keyLabel="t" />     <Key android:codes="121"    android:keyLabel="y"          android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="yýÿ"/>     <Key android:codes="117"    android:keyLabel="u"          android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="uúùũûü"/>     <Key android:codes="105"    android:keyLabel="i"           android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="iíìĩîï"/>     <Key android:codes="111"    android:keyLabel="o"           android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="oóò&#245;ôö" />     <Key android:codes="112"    android:keyLabel="p" /> </Row> <Row android:verticalGap="1%p" android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p">     <Key android:codes="97"    android:keyLabel="a" android:keyEdgeFlags="left" android:horizontalGap="5%p"          android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="aáà&#227;âä"/>     <Key android:codes="115"    android:keyLabel="s" />     <Key android:codes="100"    android:keyLabel="d" />     <Key android:codes="102"    android:keyLabel="f" />     <Key android:codes="103"    android:keyLabel="g" />     <Key android:codes="104"    android:keyLabel="h" />     <Key android:codes="106"    android:keyLabel="j" />     <Key android:codes="107"    android:keyLabel="k" />     <Key android:codes="108"    android:keyLabel="l" /> </Row> <Row android:verticalGap="1%p"  android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p">     <Key android:codes="3"      android:keyIcon="@drawable/keyboard_shift_off"           android:keyHeight="7.6%p" android:keyWidth="13.7%p"/>     <Key android:codes="122"    android:keyLabel="z" android:horizontalGap="1%p"/>     <Key android:codes="120"    android:keyLabel="x" />     <Key android:codes="99"     android:keyLabel="c"          android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="cç"/>     <Key android:codes="118"    android:keyLabel="v" />     <Key android:codes="98"     android:keyLabel="b" />     <Key android:codes="110"    android:keyLabel="n"          android:popupKeyboard="@xml/keyboard_popup" android:popupCharacters="nñ"/>     <Key android:codes="109"    android:keyLabel="m" />     <Key android:codes="-5"     android:keyIcon="@drawable/sym_keyboard_delete_dim"         android:keyHeight="7.6%p" android:keyWidth="13.7%p"          android:horizontalGap="1%p"/> </Row> <Row android:verticalGap="1%p"  android:horizontalGap="0.5%p" android:keyHeight="8%p" android:keyWidth="9.6%p">     <Key android:codes="-16"    android:keyIcon="@drawable/keyboard_symbol"          android:keyHeight="7.6%p" android:keyWidth="18.7%p"/>     <Key android:codes="44"     android:keyLabel="," android:horizontalGap="1%p"/>     <Key android:codes="32"     android:keyIcon="@drawable/sym_keyboard_feedback_space" android:keyWidth="40%p"/>     <Key android:codes="46"     android:keyLabel="."/>     <Key android:codes="-3"     android:keyIcon="@drawable/keyboard_go"          android:keyHeight="7.6%p" android:keyWidth="18.5%p" android:horizontalGap="1%p"/> </Row> 

The keyboard popup XML:

<?xml version="1.0" encoding="utf-8"?> <Keyboard xmlns:android="http://schemas.android.com/apk/res/android" android:keyWidth="10%p" android:keyHeight="10%p"> </Keyboard> 

I tried putting keyBackground and background properties everywhere, but not successfully. I tried to put:

android:popupLayout="@layout/keyboard" 

...On the keyboardView but get nullpointer, maybe I'm putting a wrong XML in that parameter?

In the keyboard popup XML that I put here:

android:popupKeyboard="@xml/keyboard_popup" 

I can change the layout's size, key size, key gap, and other things, but can't change the colors or backgrounds.

The key preview also is doing well, I put this on the keyboardView:

android:keyPreviewLayout="@layout/preview" 

...And it works. I think the popup should be the same way, but it's not.

How can I customize the popup window that appears for a long keypress?

1 Answers

Answers 1

Well, it is not exactly what I was looking for, but this resolves the problem.

I made my own keyboard view and made a popup window to show when a key is long pressed.

public class MyKeyboardView extends KeyboardView{    @Override    protected boolean onLongPress(final Key popupKey) {         final View custom = LayoutInflater.from(context)         .inflate(R.layout.popup_layout, new FrameLayout(context));         popup = new PopupWindow(context);         popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT);         popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT);         popup.showAtLocation(this, Gravity.NO_GRAVITY, popupKey.x, popupKey.y-50);    } } 

This way you can customize the popup any way you want in the xml.

Read More