Android Question Stopping default keyboard but without doing edittext input_type = none

RB Smissaert

Well-Known Member
Licensed User
Longtime User
As I am using my own custom keyboard (exact copy of the default samsung keyboard, but with lots of benefits, all working very nicely), but still not figured out how to properly avoid
the default keyboard popping up. I only use this for one particular edittext, which is used to run SQL. I can't do input_type is none as that means there is no cursor.
I can clear the default keyboard with the phone library, but that is after it has popped up and that is not great.
Would there be any Java code to do this?

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Trying to replace the keyboard like this will be problematic and the exact behavior will change between different devices and different keyboards.

Yes, had a feeling it might be problematic. I did it the simple way with a plain class, a panel with buttons and code in Main responding to the button
press events. Luckily for now I only have to deal with my own phone, but that may change in the future.
How would you suggest it should be done to avoid the problems on other devices?

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I think that you will need to set the input type to none and continue without the keyboard. Or use the standard keyboard and add other features in a different way.

> I think that you will need to set the input type to none and continue without the keyboard
That is what I did initially, but then there is no cursor and I couldn't get round that problem.
Would there be any combination of input_type flags that would give no keyboard, but still a cursor?

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I think that you will need to set the input type to none and continue without the keyboard. Or use the standard keyboard and add other features in a different way.

I had a look at this custom keyboard:

But it looks complex and not sure I would get the same full control as with my simple setup.
Is anybody using this library and did they manage to make a normal keyboard, but add special options eg a suggestions button, special action buttons
eg deleting SQL words with the Del key etc?
I think it is very useful to have total control over the keyboard, but it is not simple.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I don't think so.

Still trying to find a way to sort this problem and may have found a possible direction to look into.
I put a transparent label over the edittext (it is only one edittext in my app where I need this for) and made
sure this label is always the same size as the edittext. Then I made a SetOnTouchListener for that label via the
Reflector library. Touching the label will set the input_type of the edittext to INPUT_TYPE_NONE, so no default keyboard will popup.
Then in edittext_click the input_type will be set back to INPUT_TYPE_TEXT:

B4X:
'Sub Globals()
'Private rlblSQL As Reflector
'-------------------------------------------------
' Activity.LoadLayout("RunSQL")
' rlblSQL.Target = lblSQL
' rlblSQL.SetOnTouchListener("lblSQL_Touch")
'-------------------------------------------------
Sub lblSQL_Touch(viewtag As Object, action As Int, X As Float, Y As Float, motionevent As Object) As Boolean

'need to make sure that when the label is touched edtSQL.InputType = 131217 or INPUT_TYPE_TEXT
'also make sure lblSQL is brought to front in the designer
'---------------------------------------------------------------------------------------------
If action = 0 Then
edtSQL.InputType = edtSQL.INPUT_TYPE_NONE 'so default keyboard won't be triggered by edtSQL_Click
'just for testing for now, need to work out x and y conversion to SelStart
'-------------------------------------------------------------------------
edtSQL.SelectionStart = 0
End If

Return False

End Sub

Sub edtSQL_Click

 edtSQL.InputType = edtSQL.INPUT_TYPE_TEXT 'so we get the cursor

This works to an extent, in that there is no standard keyboard popup and we have a cursor.
Unfortunately there are problems with this, mainly that the edittext changes linebreaks to spaces.
Also after typing some 15 characters, you can't type anymore.
So, all in all this method is not working, but perhaps it could be made to work.
Does anybody have any idea how this approach could work?

RBS
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Have you investigated trying to set soft input mode?
According to the docs setting it to "SOFT_INPUT_STATE_ALWAYS_HIDDEN" should "always hide any soft input area when this window receives focus. "
the Java is:
B4X:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
but I'm not sure how you would implement that particular call in B4A.

Thanks, will have a look at that.

RBS
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
Wows, this is weirdly difficult, I'm sure there's a reason Google designed it this way, but I'm at a loss to come up with one. I've managed to accomplish it with in-line java:
Hide Soft Keyboard:
#IF JAVA
    import android.widget.EditText;
    import android.os.Build;
    import android.text.InputType;
    

 public void disableSoftKeyboard(final EditText v) {
    if (Build.VERSION.SDK_INT >= 11) {
        v.setRawInputType(InputType.TYPE_CLASS_TEXT);
        v.setTextIsSelectable(true);
        v.setShowSoftInputOnFocus(false);
        BA.Log(">= 11 set");
    } else {
        v.setRawInputType(InputType.TYPE_NULL);
        v.setFocusable(true);
        BA.Log("< 11 set");
    }
}

#END IF
To call it from your code, you'll need a Process_Globals variable:
Process Globals Additions:
Sub Process_Globals
    Private NativeMe As JavaObject
End Sub
Then modify your Activity_Create:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("layTest")  'contains 'EditText1' which is declared in my globals
    If FirstTime Then
        NativeMe.InitializeContext
    End If
End Sub

Then at some point before you display the edittext box:
B4X:
NativeMe.RunMethod("disableSoftKeyboard", Array As Object(EditText1))

I can't test the < 11 SDK method as I don't have a functioning device with that low of OS build on it right now.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Wows, this is weirdly difficult, I'm sure there's a reason Google designed it this way, but I'm at a loss to come up with one. I've managed to accomplish it with in-line java:
Hide Soft Keyboard:
#IF JAVA
    import android.widget.EditText;
    import android.os.Build;
    import android.text.InputType;
   

public void disableSoftKeyboard(final EditText v) {
    if (Build.VERSION.SDK_INT >= 11) {
        v.setRawInputType(InputType.TYPE_CLASS_TEXT);
        v.setTextIsSelectable(true);
        v.setShowSoftInputOnFocus(false);
        BA.Log(">= 11 set");
    } else {
        v.setRawInputType(InputType.TYPE_NULL);
        v.setFocusable(true);
        BA.Log("< 11 set");
    }
}

#END IF
To call it from your code, you'll need a Process_Globals variable:
Process Globals Additions:
Sub Process_Globals
    Private NativeMe As JavaObject
End Sub
Then modify your Activity_Create:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("layTest")  'contains 'EditText1' which is declared in my globals
    If FirstTime Then
        NativeMe.InitializeContext
    End If
End Sub

Then at some point before you display the edittext box:
B4X:
NativeMe.RunMethod("disableSoftKeyboard", Array As Object(EditText1))

I can't test the < 11 SDK method as I don't have a functioning device with that low of OS build on it right now.

Will give that a try, and hope it doesn't mess up the cursor.

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Wows, this is weirdly difficult, I'm sure there's a reason Google designed it this way, but I'm at a loss to come up with one. I've managed to accomplish it with in-line java:
Hide Soft Keyboard:
#IF JAVA
    import android.widget.EditText;
    import android.os.Build;
    import android.text.InputType;
   

public void disableSoftKeyboard(final EditText v) {
    if (Build.VERSION.SDK_INT >= 11) {
        v.setRawInputType(InputType.TYPE_CLASS_TEXT);
        v.setTextIsSelectable(true);
        v.setShowSoftInputOnFocus(false);
        BA.Log(">= 11 set");
    } else {
        v.setRawInputType(InputType.TYPE_NULL);
        v.setFocusable(true);
        BA.Log("< 11 set");
    }
}

#END IF
To call it from your code, you'll need a Process_Globals variable:
Process Globals Additions:
Sub Process_Globals
    Private NativeMe As JavaObject
End Sub
Then modify your Activity_Create:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("layTest")  'contains 'EditText1' which is declared in my globals
    If FirstTime Then
        NativeMe.InitializeContext
    End If
End Sub

Then at some point before you display the edittext box:
B4X:
NativeMe.RunMethod("disableSoftKeyboard", Array As Object(EditText1))

I can't test the < 11 SDK method as I don't have a functioning device with that low of OS build on it right now.

Amazing!!
After some light testing it all seems to work perfect.
Had kind of given up hope that this was fixable.
Will do some more testing now and report back.
Thanks a lot!

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Happy to help! If you can test on SDK <11 please let me know if the other method works or not, I'd be interested to know one way or the other.

With other method did you refer to:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
?

> If you can test on SDK <11
Don't think got such a device, but will have a look.

RBS
 
Upvote 0

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
After I investigated the setSoftInputMode I didn't think it was what you wanted as it does the entire window (all text boxes) the method I eventually came up with is per-textbox. And the <11 is referring to the in-line java as the methods used are version-dependent.
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
After I investigated the setSoftInputMode I didn't think it was what you wanted as it does the entire window (all text boxes) the method I eventually came up with is per-textbox. And the <11 is referring to the in-line java as the methods used are version-dependent.

One thing I noticed is that I can't revert back to normal by simply doing:

B4X:
edtSQL.InputType = 131217 'text input, but no suggestions

I want to be able to swap from custom keyboard to normal keyboard, without reloading the layout.
If I do the above to revert the keyboard won't popup on clicking edtSQL, although this is not a problem
as I can do:

B4X:
ime.ShowKeyboard(edtSQL)

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
One thing I noticed is that I can't revert back to normal by simply doing:

B4X:
edtSQL.InputType = 131217 'text input, but no suggestions

I want to be able to swap from custom keyboard to normal keyboard, without reloading the layout.
If I do the above to revert the keyboard won't popup on clicking edtSQL, although this is not a problem
as I can do:

B4X:
ime.ShowKeyboard(edtSQL)

RBS

I think I solved this now:

B4X:
#IF JAVA
import android.widget.EditText;
import android.os.Build;
    import android.text.InputType;
 public void disableSoftKeyboard(final EditText v) {
if (Build.VERSION.SDK_INT >= 11) {
v.setRawInputType(InputType.TYPE_CLASS_TEXT);
v.setTextIsSelectable(true);
v.setShowSoftInputOnFocus(false);
} else {
v.setRawInputType(InputType.TYPE_NULL);
v.setFocusable(true);
}
}
 public void enableSoftKeyboard(final EditText v) {
if (Build.VERSION.SDK_INT >= 11) {
v.setRawInputType(InputType.TYPE_CLASS_TEXT);
v.setTextIsSelectable(true);
v.setShowSoftInputOnFocus(true);
} else {
v.setRawInputType(InputType.TYPE_CLASS_TEXT);
v.setFocusable(true);
}
}
#END IF

Sub SetedtSQLInput_Type

If NativeMe.IsInitialized = False Then
NativeMe.InitializeContext
End If

If bCustomKeyboard Then
NativeMe.RunMethod("disableSoftKeyboard", Array As Object(edtSQL))
Else
NativeMe.RunMethod("enableSoftKeyboard", Array As Object(edtSQL))
edtSQL.InputType = 131217 'no suggestions
End If

End Sub

RBS
 
Upvote 0
Top