mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-09 07:18:34 -04:00
Mobile: Show Send text/icon on soft keyboard action button when opening keyboard for in-game chat input
This commit is contained in:
parent
d1ece08a58
commit
3fad0c7404
@ -488,7 +488,7 @@ public class MainActivity extends Activity
|
||||
// BaseInputConnection, IME_ACTION_GO, IME_FLAG_NO_EXTRACT_UI - API level 3
|
||||
attrs.actionLabel = null;
|
||||
attrs.inputType = MainActivity.this.getKeyboardType();
|
||||
attrs.imeOptions = EditorInfo.IME_ACTION_GO | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
|
||||
attrs.imeOptions = MainActivity.this.getKeyboardOptions();
|
||||
|
||||
kbText = new SpannableStringBuilder(MainActivity.this.keyboardText);
|
||||
|
||||
@ -621,9 +621,9 @@ public class MainActivity extends Activity
|
||||
// setTitle - API level 1
|
||||
public void setWindowTitle(String str) { setTitle(str); }
|
||||
|
||||
public void openKeyboard(String text, int type) {
|
||||
public void openKeyboard(String text, int flags) {
|
||||
// restartInput, showSoftInput - API level 3
|
||||
keyboardType = type;
|
||||
keyboardType = flags;
|
||||
keyboardText = text;
|
||||
//runOnUiThread(new Runnable() {
|
||||
//public void run() {
|
||||
@ -669,11 +669,22 @@ public class MainActivity extends Activity
|
||||
|
||||
public int getKeyboardType() {
|
||||
// TYPE_CLASS_TEXT, TYPE_CLASS_NUMBER, TYPE_TEXT_VARIATION_PASSWORD - API level 3
|
||||
if (keyboardType == 2) return InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
||||
if (keyboardType == 1) return InputType.TYPE_CLASS_NUMBER; // KEYBOARD_TYPE_NUMERIC
|
||||
if (keyboardType == 3) return InputType.TYPE_CLASS_NUMBER; // KEYBOARD_TYPE_INTEGER
|
||||
int type = keyboardType & 0xFF;
|
||||
|
||||
if (type == 2) return InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
||||
if (type == 1) return InputType.TYPE_CLASS_NUMBER; // KEYBOARD_TYPE_NUMERIC
|
||||
if (type == 3) return InputType.TYPE_CLASS_NUMBER; // KEYBOARD_TYPE_INTEGER
|
||||
return InputType.TYPE_CLASS_TEXT;
|
||||
}
|
||||
|
||||
public int getKeyboardOptions() {
|
||||
// IME_ACTION_GO, IME_FLAG_NO_EXTRACT_UI - API level 3
|
||||
if ((keyboardType & 0x100) != 0) {
|
||||
return EditorInfo.IME_ACTION_SEND | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
|
||||
} else {
|
||||
return EditorInfo.IME_ACTION_GO | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
|
||||
}
|
||||
}
|
||||
|
||||
public String getClipboardText() {
|
||||
// ClipboardManager, getText() - API level 11
|
||||
|
@ -1371,7 +1371,7 @@ void ChatScreen_OpenInput(const cc_string* text) {
|
||||
s->grabsInput = true;
|
||||
|
||||
Gui_UpdateInputGrab();
|
||||
OpenKeyboardArgs_Init(&args, text, KEYBOARD_TYPE_TEXT);
|
||||
OpenKeyboardArgs_Init(&args, text, KEYBOARD_TYPE_TEXT | KEYBOARD_FLAG_SEND);
|
||||
args.placeholder = "Enter chat";
|
||||
Window_OpenKeyboard(&args);
|
||||
|
||||
|
@ -34,8 +34,9 @@ struct Bitmap;
|
||||
struct DynamicLibSym;
|
||||
/* The states the window can be in. */
|
||||
enum WindowState { WINDOW_STATE_NORMAL, WINDOW_STATE_FULLSCREEN, WINDOW_STATE_MINIMISED };
|
||||
enum KeyboardType { KEYBOARD_TYPE_TEXT, KEYBOARD_TYPE_NUMBER, KEYBOARD_TYPE_PASSWORD, KEYBOARD_TYPE_INTEGER };
|
||||
enum SoftKeyboard { SOFT_KEYBOARD_NONE, SOFT_KEYBOARD_RESIZE, SOFT_KEYBOARD_SHIFT };
|
||||
enum KeyboardType { KEYBOARD_TYPE_TEXT, KEYBOARD_TYPE_NUMBER, KEYBOARD_TYPE_PASSWORD, KEYBOARD_TYPE_INTEGER };
|
||||
#define KEYBOARD_FLAG_SEND 0x100
|
||||
/* (can't name these structs Window/Display, as that conflicts with X11's Window/Display typedef) */
|
||||
|
||||
/* Data for the display monitor. */
|
||||
|
@ -245,10 +245,17 @@ void ShowDialogCore(const char* title, const char* msg) {
|
||||
}
|
||||
}
|
||||
|
||||
static void LInput_SetKeyboardType(UITextField* fld, int flags);
|
||||
static void LInput_SetPlaceholder(UITextField* fld, const char* placeholder);
|
||||
static UITextField* text_input;
|
||||
|
||||
void Window_OpenKeyboard(const struct OpenKeyboardArgs* args) {
|
||||
text_input = [[UITextField alloc] initWithFrame:CGRectZero];
|
||||
text_input.hidden = YES;
|
||||
|
||||
LInput_SetKeyboardType(text_input, args->type);
|
||||
LInput_SetPlaceholder(text_input, args->placeholder);
|
||||
|
||||
[view_handle addSubview:text_input];
|
||||
[text_input becomeFirstResponder];
|
||||
}
|
||||
@ -655,7 +662,7 @@ static NSString* cellID = @"CC_Cell";
|
||||
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
|
||||
}
|
||||
|
||||
struct ServerInfo* server = LTable_Get([indexPath row]);
|
||||
struct ServerInfo* server = Servers_Get([indexPath row]);
|
||||
struct Flag* flag = Flags_Get(server);
|
||||
|
||||
char descBuffer[128];
|
||||
@ -681,12 +688,9 @@ static NSString* cellID = @"CC_Cell";
|
||||
|
||||
// === UITableViewDelegate ===
|
||||
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||
Platform_LogConst("CLIKO");
|
||||
extern void LTable_ClickRow(struct LTable* w, int row);
|
||||
|
||||
struct LTable* w = FindWidgetForView(tableView);
|
||||
if (w == NULL) return;
|
||||
LTable_ClickRow(w, [indexPath row]);
|
||||
LTable_RowClick(w, [indexPath row]);
|
||||
}
|
||||
|
||||
@end
|
||||
@ -750,6 +754,26 @@ void LBackend_CheckboxDraw(struct LCheckbox* w) {
|
||||
/*########################################################################################################################*
|
||||
*------------------------------------------------------InputWidget--------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
static void LInput_SetKeyboardType(UITextField* fld, int flags) {
|
||||
int type = flags & 0xFF;
|
||||
if (type == KEYBOARD_TYPE_INTEGER) {
|
||||
[fld setKeyboardType:UIKeyboardTypeNumberPad];
|
||||
} else if (type == KEYBOARD_TYPE_PASSWORD) {
|
||||
fld.secureTextEntry = YES;
|
||||
}
|
||||
|
||||
if (flags & KEYBOARD_FLAG_SEND) {
|
||||
[fld setReturnKeyType:UIReturnKeySend];
|
||||
}
|
||||
}
|
||||
|
||||
static void LInput_SetPlaceholder(UITextField* fld, const char* placeholder) {
|
||||
if (!placeholder) return;
|
||||
|
||||
cc_string hint = String_FromReadonly(placeholder);
|
||||
fld.placeholder = ToNSString(&hint);
|
||||
}
|
||||
|
||||
void LBackend_InputInit(struct LInput* w, int width) {
|
||||
UITextField* fld = [[UITextField alloc] init];
|
||||
fld.frame = CGRectMake(0, 0, width, 30);
|
||||
@ -757,16 +781,8 @@ void LBackend_InputInit(struct LInput* w, int width) {
|
||||
fld.backgroundColor = [UIColor whiteColor];
|
||||
[fld addTarget:ui_controller action:@selector(handleTextChanged:) forControlEvents:UIControlEventEditingChanged];
|
||||
|
||||
if (w->inputType == KEYBOARD_TYPE_INTEGER) {
|
||||
[fld setKeyboardType:UIKeyboardTypeNumberPad];
|
||||
} else if (w->inputType == KEYBOARD_TYPE_PASSWORD) {
|
||||
fld.secureTextEntry = YES;
|
||||
}
|
||||
|
||||
if (w->hintText) {
|
||||
cc_string hint = String_FromReadonly(w->hintText);
|
||||
fld.placeholder = ToNSString(&hint);
|
||||
}
|
||||
LInput_SetKeyboardType(fld, w->type);
|
||||
LInput_SetPlaceholder(fld, w->hintText);
|
||||
|
||||
AssignView(w, fld);
|
||||
UpdateWidgetDimensions(w);
|
||||
|
@ -769,9 +769,11 @@ mergeInto(LibraryManager.library, {
|
||||
interop_ShowDialog: function(title, msg) {
|
||||
alert(UTF8ToString(title) + "\n\n" + UTF8ToString(msg));
|
||||
},
|
||||
interop_OpenKeyboard: function(text, type, placeholder) {
|
||||
interop_OpenKeyboard: function(text, flags, placeholder) {
|
||||
var elem = window.cc_inputElem;
|
||||
var shown = true;
|
||||
var type = flags & 0xFF;
|
||||
|
||||
if (!elem) {
|
||||
if (type == 1) { // KEYBOARD_TYPE_NUMBER
|
||||
elem = document.createElement('input');
|
||||
@ -790,7 +792,8 @@ mergeInto(LibraryManager.library, {
|
||||
}
|
||||
shown = false;
|
||||
}
|
||||
|
||||
|
||||
if (flags & 0x100) { elem.setAttribute('enterkeyhint', 'send'); }
|
||||
elem.setAttribute('style', 'position:absolute; left:0; bottom:0; margin: 0px; width: 100%');
|
||||
elem.setAttribute('placeholder', UTF8ToString(placeholder));
|
||||
elem.value = UTF8ToString(text);
|
||||
|
Loading…
x
Reference in New Issue
Block a user