Why is the Android example SoftKeyboard layouted like this? - android

I'm currently experimenting with the sample SoftKeyboard on my tablet (Android 3.2).
When I open the Google mail app and set the focus to the recipient field, the textfield is expanded to fill the available space above the keyboard.
This looks very much like the fullscreen or extract mode as described in Onscreen Input Methods in the documentation. From what I gathered there, this is set by the activity, which uses the SoftKeyboard.
What bugs me is
this is not very convenient for the recipient input field (although that might be a matter of taste)
that the stock softkeyboard manages to prevent this, as shown below:
also sometimes the textcolor in the input box is set to white (probably some adjustment due to daytime/nighttime?). White on white is more or less unreadable.
So my question is: What do I have to change to get a similar behaviour in the example SoftKeyboard?
Thanks & all the best
Andreas

The sample soft keyboard is very out-dated -- it uses a layout that hasn't been seen since Froyo/Eclair.
The sample soft keyboard is just that: a sample, not to be confused with a fully-fledged android keyboard. If you are looking for a full implementation of an Android keyboard, check out AnySoftKeyboard's source code or the AOSP source code.
To get rid of fullscreen, I know part of the issue lies in the onComputeInsets() function. Like I said though, I'd base your code off full Android keyboard (i.e. AOSP or Cyanogenmod) rather than trying to get the sample to work. I tried that for months, and there's just too many problems you'll run in to (multitouch and theming, just to name a couple).
Send me an email if you have any questions.

you can design your desired softkeyboard layout using buttons, textview whatever you want to display on keyboard.
and setOnclickListener to all Buttons of your keyboard
Override onCreateInputView() like this
#Override
public View onCreateInputView() {
View mInputView = getLayoutInflater().inflate(
R.layout.yourkeyboardlayout, null);
Button btn1 = mInputView.findViewById(R.id.btn1);
btn1 .setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// append text in selected TextField
String buttonLabel = ((Button)v).getText().toString();
getCurrentInputConnection().commitText(buttonLabel, 1);
}
});
return mInputView;
}

I had a similar question as I created my own keyboard and this blog post pretty much answered what I needed to know:
http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
Maybe it will help you too.

Related

How to implement key preview popup in custom android keyboard

I'm currently developing a custom andriod keyboard for my personal use: https://github.com/soobakjonmat/Custom-Layout-Keyboard-for-Android
Sample Image
The basic structure of my keyboard is based on Microsoft SwiftKey.
I have pretty much finished everything except that I cannot find a way to implement the key preview popup.
For example (Gboard and Microsoft SwiftKey
):
I have looked at different posts on this implementation but all of them were like at least 5 years old and they were using the KeyboardView class, which is now deprecated and I have not used it to create my keyboard. So I tried to implement it by myself.
At first I tried to implement it like Microsoft SwiftKey, and I tried increasing the Button height each time when I pressed it but it also increased other Buttons' heights because they are in the same LinearLayout and I have used weight to set their height.
So instead I tried to implement it like Gboard but I can't quite figure out how to show the image or text above the key that the user have pressed. I tried using ImageView to show the key preview but I'm not sure how or where to add the view in the layout.
Any help or adivce would be apprecited.
I found out the solution by myself.
Use PopupWindow: https://developer.android.com/reference/kotlin/android/widget/PopupWindow
Create a PopupWindow and set its contentView with a TextView. Then whenever you want to show it call showAtLocation and update method.
For example:
val btn = Button(baseContext)
val popup = PopupWindow()
popup.contentView = TextView(baseContext)
val loc = IntArray(2)
btn.getLocationInWindow(loc)
popup.showAtLocation(btn, Gravity.NO_GRAVITY, 0, 0)
popup.update(loc[0], loc[1]-128, 128, 128, false)
For future people if anyone also encounters the same problem and want more details check out my github repository which was mentioned at the beginning of this post.

Android webView touchEvents

I have a webapp I am trying to interface with android. It is very easy to get a webview to display the page, however the page uses an on screen keyboard. If only one input was on a page, it would be easy to set
android:focusableInTouchMode="false"
in the webview, however there are a few places where multiple inputs are present, and this disables the ability to select any them (the first one on the page is automatically selected).
Would it work to maybe extend and override a webView to be able to select an input but not open the softKeyboard?
I have also looked at
this example, however I don't think that will work with a webview.
EDIT:
To help clarify, i can just override with myWebView.setOnTouchListener(...), and have done so in test, this is great as it does not allow the softKeyboard to show, however it also does not let anything else happen ie. input selection. Ideally there would be a happy medium where everything happens except the softKeyboard appearing. (yes I have tried other methods such as
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
I feel that my question was somewhat vague as I was at my wits end after several hours of looking into this.
My end goal was to be able to display a web page with an on screen keyboard with multiple input fields. The problem was that the android softKeyboard would be shown whenever focus was on an input field.
I tried multiple workarounds, one listed in the question did not work because I could not select any inputs as touch commands were not registered.
I tried overriding onTouch, however the keyboard is shown after an 'up' touch and so it was impossible to have default behavior and still intercept and disable the keyboard.
The solution that worked for my problem was to extend the WebView class, and then override 'onCreateInputConnection'. This is where android interprets the 'type' of the html input field. The problem is that html does not have a 'null' type for this, so android will always display some sort of keyboard based on the input type. Android does however have a null input type which tells the keyboard there is no need for input here.
#Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
BaseInputConnection fic = new BaseInputConnection(this, true);
outAttrs.actionLabel = null;
outAttrs.inputType = InputType.TYPE_NULL;
return fic;
}
This overriden method is all that was needed for my webview to completely disable inputs on all of my text fields.
NOTE: This does also disable attached hardware keyboard input...not a problem in my case, however I would be interested in learning about a work around there.

Android Keyboard with Emoji

So I want to have a keyboard in my app that has emoji just like Whatsapp or Hangouts. How can I do that? I want to leave my key keyboard as it is I just want to add tabs to put emojis. I would think it would be easily supported by the soft keyboard but I can find nothing so far. Anyone could tell how to do it?
UPDATE:
The keyboard with emoji is included in Android KitKat and can be accessed by long pressing the new line button in the keyboard. The Hangouts keyboard however has the emoji icon visible instead of the "new line" key. If someone knows how to make this the default (either in layout or programmatically) I will take that as the correct answer.
As #dbar pointed out, the answer is:
android:inputType="textShortMessage"
But in my case, I was already using textMultiLine, so I had to use the both of them together:
android:inputType="textMultiLine|textShortMessage"
Looks like this:
I'm not sure about the Exact android version, but this should work only on Android 4.1 and above
Finally the answer was:
android:inputType="textShortMessage"
The new line key becomes a key to take out the emoji keyboard. The only quibble is the 'new line' key from the keyboard disappears with this configuration (before you could long press to choose between emoji/new line but now it's only emoji).
In Google Hangout, the emoji button is not on the keyboard (at least on my phone which is already using a third party keyboard), it's inside of the TextEdit box, and so it's part of the application itself (Gabe, I'm talking about the latest Google Hangout on top of KitKat with emoji support, all the current screenshots I found of Google Hangout do not show what I'm seeing on my phone, so this must be a very recent feature).
This is actually pretty easy to do, placing an ImageButton to the right of a TextView inside a RelativeLayout (the RelativeLayout which is made to look like a TextView with a custom background).
Then, it's just a matter of hiding the keyboard when clicking on that ImageButton and replacing it with a panel full of emojis when that happens (like in this open source emoji android keyboard, which is under a creative commons non-commercial license).
There is no functionality to add tabs to any generic keyboard. Certain keyboards may support it, but it isn't a common feature. You could write your own fully custom keyboard, but that's a lot of work and will piss off many users.
Also, I'm not sure what you mean about by like in hangouts. I use hangouts- it doesn't do anything odd with my keyboard. It stays as Swype, there's no special emoji tab. It may be a feature of your favorite keyboard based on the input type (I assume both use input type textShortMessage). But it isn't a generic feature.

Android Edit Text Cursor Doesn't Appear

in my app I disabled the keyboard (I use now my custom keyboard) using this code:
editText.setInputType(InputType.TYPE_NULL);
Now, my problem is that the text cursor does not appear anymore in the edit text. What should I do? Any suggestion would be very appreciated.
There is an Issue opened in bug tracker Issue opened in bug tracker for this.
One of the users suggests the approach which works on "most" devices.
Briefly, all you have to do is call:
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
for your EditText view (after you called editText.setInputType(InputType.TYPE_NULL);).
You should probably also set:
editText.setTextIsSelectable(true);
in order for text to be selectable (though in does not seem to work properly with Samsung Galaxy SIII). This method is only available starting from HONEYCOMB (api11) so keep that in mind when developing for older Android versions.
Also it is stated that your EditText should not be the first view to receive focus when activity starts (if it is - just requestFocus() from another view). Though I (personally) have not experienced any problems with this.
Rather than just using a custom view for your custom keyboard, why not implement a full-fledged IME? That will solve your cursor problem, and even make your keyboard available outside your app (if you want).
This answer has a couple useful links if you want to do that:
How to develop a soft keyboard for Android?
I really wouldn't suggest this. Writing a good full fledged IME is really hard. In addition, users come to expect functionality from their keyboard (auto-correct, Swyping, next word prediction, the ability to change languages) that you won't have unless you spend months on the keyboard itself. Any app that wouldn't allow me to use Swype would immediately be removed (bias note: I worked on Swype android).
But if you want to integrate fully with the OS as a keyboard, you're going to have to write an InputMethodService. Your keyboard would then be selectable by the user in the keyboard select menu, and usable for any app. That's the only way to get full OS integration, otherwise you'll need to really start from scratch- writing your own EditView. Have fun with that, getting one that looks nice is decidedly non-trivial.
Also, setting input type null won't disable most keyboards. It just puts them into dumb mode and turns off things like prediction.
I tried the below answer and it worked, but take care that
1) EditText must not be focused on initialization
2) when your orientation changes while the user's focus is on the editText, the stock keyboard pops up, which is another "solvable" problem.
This was mentioned in a previous answer but take care that you MUST make sure your editText element do not get focus on instantiation:
https://code.google.com/p/android/issues/detail?id=27609#c7
#7 nyphb...#gmail.com
I have finally found a (for me) working solution to this.
First part (in onCreate):
mText.setInputType(InputType.TYPE_NULL);
if (android.os.Build.VERSION.SDK_INT >= 11 /*android.os.Build.VERSION_CODES.HONEYCOMB*/) {
// this fakes the TextView (which actually handles cursor drawing)
// into drawing the cursor even though you've disabled soft input
// with TYPE_NULL
mText.setRawInputType(InputType.TYPE_CLASS_TEXT);
}
In addition, android:textIsSelectable needs to be set to true (or set in onCreate) and the EditText must not be focused on initialization. If your EditText is the first focusable View (which it was in my case), you can work around this by putting this just above it:
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" >
<requestFocus />
</LinearLayout>

Can't change soft keyboard enter to "done" button after upgrading to gingerbread

very simply:
inputField.setImeOptions(EditorInfo.IME_ACTION_DONE);
used to make my soft keyboard show the "done" key instead of carraige return.
Since I updated my phone (Samsung Galaxy S) to gingerbread this line of code is having no effect.
Any ideas?
I have seen this problem also and I believe it occurs when you have not set an inputType. Actually all imeOptions properties (along with a few others) get ignored completely if the inputType is set to EditorInfo.TYPE_NULL (the default).
So give one of these a shot (I picked next but you can put any type in):
XML:
android:inputType="text"
android:imeOptions="actionNext"
JAVA
text.setInputType(EditorInfo.TYPE_CLASS_TEXT);
text.setImeOptions(EditorInfo.IME_ACTION_NEXT);
And if you really want to go nuts you can use setImeActionLabel('Add', SOME_ID) and completely configure the action key (there are xml equivalentes also).
That being said. I could be completely wrong about your individual device but I figured this is easy to test and seems to always solve my problem so I should share.
I have been researching the same problem. The IME (input method editor) on your device is it at fault and will not display the done button in the soft keyboard or the next button for that matter. HTC sense has its own soft keyboard and does not recognize ime directives. there are others and your samsung obviously is one. this is the first time I have ran head long into android fragmentation.
I did try setting it in XML, inflating, and creating a helper class, and a heap of other things. I was relieved to find out that it simply does not work.
So now instead of the keyboard editor completing the entry we must add a done button. I'm adding it to the end of my edit text using a relative layout to align them. Ill leave the IME code for those that have that functionality.... this is the is the only quick solution, the other being writing a entire custom soft keyboard for your app.
I've checked inside the method TextView.setInputType and at the end of this method, InputMethodManager restarts the keyboard. So this is the trigger to change the imeOptions, not InputType.TYPE_NULL.
private void changeInputTypeAndImeOptions(EditText fieldValue, int inputType, int imeOption) {
if (inputType == InputType.TYPE_NULL) inputType = fieldValue.getInputType();
fieldValue.setImeOptions(imeOption | EditorInfo.IME_FLAG_NO_FULLSCREEN);
//Makes the trigger for the imeOptions to change while typing!
//fieldValue.setInputType(InputType.TYPE_NULL);
fieldValue.setInputType(inputType);
InputMethodManager imm = (InputMethodManager)
mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) imm.restartInput(fieldValue);
}
NOTE:
Setting the setInputType with same previous value, doesn't give any effect so better to restart imm (this doesn't close the kb, only refreshes the buttons).
Also fieldValue.setInputType(InputType.TYPE_NULL); has a bad effect the return button is visible during the multiple set, that's why is commented and it should be removed. Better restart the kb with imm.

Categories

Resources