implement a new way to select additional fields in the keyboard, closes https://github.com/PhilippC/keepass2android/issues/377

This commit is contained in:
Philipp Crocoll
2018-08-27 11:18:46 +02:00
parent bc2dc1b2e9
commit dbb291fb86
12 changed files with 132 additions and 55 deletions

View File

@@ -19,6 +19,7 @@
android:resource="@xml/accserviceconfig" />
</service-->
<activity android:excludeFromRecents="true"
android:taskAffinity=""
android:theme="@android:style/Theme.Dialog"
android:name=".Kp2aDialog"></activity>
</application>

View File

@@ -10,20 +10,18 @@ public class KeyboardData
public static List<StringForTyping> availableFields = new ArrayList<StringForTyping>();
public static String entryName;
public static String entryId;
public static int kp2aFieldIndex = 0;
public static boolean hasData()
{
return !TextUtils.isEmpty(entryId);
}
public static boolean bla2()
{
return !TextUtils.isEmpty(entryId);
}
public static void clear()
{
availableFields.clear();
entryName = entryId = "";
kp2aFieldIndex = 0;
}
}

View File

@@ -1,6 +1,10 @@
package keepass2android.kbbridge;
import java.util.ArrayList;
import java.util.HashMap;
import keepass2android.softkeyboard.IKeyboardService;
import keepass2android.softkeyboard.KP2AKeyboard;
public class KeyboardDataBuilder {
private ArrayList<StringForTyping> availableFields = new ArrayList<StringForTyping>();
@@ -16,5 +20,8 @@ public class KeyboardDataBuilder {
public void commit()
{
KeyboardData.availableFields = this.availableFields;
KeyboardData.kp2aFieldIndex = 0;
if (KP2AKeyboard.CurrentlyRunningService != null)
KP2AKeyboard.CurrentlyRunningService.onNewData();
}
}

View File

@@ -0,0 +1,9 @@
package keepass2android.softkeyboard;
import keepass2android.kbbridge.StringForTyping;
public interface IKeyboardService
{
void commitStringForTyping(StringForTyping stringForTyping);
void onNewData();
}

View File

@@ -62,6 +62,7 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import keepass2android.kbbridge.KeyboardData;
import keepass2android.kbbridge.StringForTyping;
import keepass2android.softkeyboard.LatinIMEUtil.RingCharBuffer;
@@ -71,16 +72,13 @@ import java.io.FileDescriptor;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
interface IKeyboardService
{
void commitStringForTyping(StringForTyping stringForTyping);
}
import java.util.Objects;
/**
* Input method implementation for Qwerty'ish keyboard.
@@ -1086,6 +1084,7 @@ public class KP2AKeyboard extends InputMethodService
private void reloadKeyboards() {
mKeyboardSwitcher.setLanguageSwitcher(mLanguageSwitcher);
mKeyboardSwitcher.makeKeyboards(true);
updateKp2aKeyLabels();
}
private void commitTyped(InputConnection inputConnection) {
@@ -1275,6 +1274,9 @@ public class KP2AKeyboard extends InputMethodService
case LatinKeyboardView.KEYCODE_OPTIONS:
onOptionKeyPressed();
break;
case LatinKeyboardView.KEYCODE_KP2A_NEXTFIELDS:
onKp2aNextFieldsPressed();
break;
case LatinKeyboardView.KEYCODE_KP2A:
onKp2aKeyPressed();
break;
@@ -1363,28 +1365,72 @@ public class KP2AKeyboard extends InputMethodService
}
private void onKp2aPasswordKeyPressed() {
commitStringForTyping(findStringForTyping("Password"));
commitStringForTyping(KeyboardData.availableFields.get(KeyboardData.kp2aFieldIndex+1));
}
private StringForTyping findStringForTyping(String key) {
for (StringForTyping s: keepass2android.kbbridge.KeyboardData.availableFields)
{
if (key.equals(s.key))
{
return s;
}
}
//found nothing: return empty struct:
return new StringForTyping();
}
private void onKp2aUserKeyPressed() {
commitStringForTyping(findStringForTyping("UserName"));
commitStringForTyping(KeyboardData.availableFields.get(KeyboardData.kp2aFieldIndex));
}
private void onKp2aKeyPressed() {
private void onKp2aNextFieldsPressed()
{
List<StringForTyping> availableFields = keepass2android.kbbridge.KeyboardData.availableFields;
if (KeyboardData.kp2aFieldIndex >= availableFields.size()-2)
{
KeyboardData.kp2aFieldIndex = 0;
}
else if (KeyboardData.kp2aFieldIndex == availableFields.size()-3)
{
KeyboardData.kp2aFieldIndex++;
}
else
KeyboardData.kp2aFieldIndex += 2;
updateKp2aKeyLabels();
}
private void updateKp2aKeyLabels() {
for (Keyboard.Key key : mKeyboardSwitcher.getInputView().getKeyboard().getKeys()) {
boolean isFirstKey = false;
boolean isSecondKey = false;
for (int code : key.codes) {
if (code == -201)
isFirstKey = true;
if (code == -202)
isSecondKey = true;
}
int fieldIndex = -1;
if (isFirstKey) {
fieldIndex = KeyboardData.kp2aFieldIndex;
}
if (isSecondKey)
{
fieldIndex = KeyboardData.kp2aFieldIndex+1;
}
if (fieldIndex >= 0)
{
String displayName = KeyboardData.availableFields.get(fieldIndex).displayName;
if ("Password".equals(KeyboardData.availableFields.get(fieldIndex).key))
displayName = getString(R.string.kp2a_password); //might be a shorter variant
if ("UserName".equals(KeyboardData.availableFields.get(fieldIndex).key ))
displayName = getString(R.string.kp2a_user); //might be a shorter variant
key.label = displayName;
}
mKeyboardSwitcher.getInputView().invalidateAllKeys();
}
}
private void onKp2aKeyPressed() {
if ((mKeyboardSwitcher.getKeyboardMode() == KeyboardSwitcher.MODE_KP2A)
|| (!mKp2aEnableSimpleKeyboard)
|| (!keepass2android.kbbridge.KeyboardData.hasData()))
@@ -1417,7 +1463,6 @@ public class KP2AKeyboard extends InputMethodService
i.putExtra("clientPackageName", clientPackageName);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
}
public void commitStringForTyping(StringForTyping theItem) {
@@ -1439,8 +1484,13 @@ public class KP2AKeyboard extends InputMethodService
commitKp2aString(theItem.value, getCurrentInputEditorInfo());
}
public void onText(CharSequence text) {
@Override
public void onNewData() {
updateKp2aKeyLabels();
}
public void onText(CharSequence text) {
InputConnection ic = getCurrentInputConnection();
if (ic == null) return;
if (text == null)

View File

@@ -26,19 +26,13 @@ public class Kp2aDialog extends Activity {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
setContentView(R.layout.activity_kp2a_dialog);
ListView listview = ((ListView)findViewById(R.id.mylist));
final String clientPackageName = getIntent().getStringExtra("clientPackageName");
List<StringForTyping> availableFields = keepass2android.kbbridge.KeyboardData.availableFields;
final ArrayList<StringForTyping> items = new ArrayList<StringForTyping>();
for (StringForTyping entry : availableFields)
{
items.add(entry.clone());
}
@@ -117,11 +111,11 @@ public class Kp2aDialog extends Activity {
StringForTyping theItem = items.get(item);
Kp2aDialog.this.finish();
KP2AKeyboard.CurrentlyRunningService.commitStringForTyping(theItem);
}
Kp2aDialog.this.finish();
}
});

View File

@@ -43,6 +43,7 @@ public class LatinKeyboardView extends LatinKeyboardBaseView {
static final int KEYCODE_KP2A_ALPHA = -203;
static final int KEYCODE_KP2A_SWITCH = -204;
static final int KEYCODE_KP2A_LOCK = -205;
static final int KEYCODE_KP2A_NEXTFIELDS = -206;
private Keyboard mPhoneKeyboard;

View File

@@ -35,6 +35,7 @@
<integer name="key_kp2a_alpha">-203</integer>
<integer name="key_kp2a_switch">-204</integer>
<integer name="key_kp2a_lock">-205</integer>
<integer name="key_kp2a_nextfields">-206</integer>
</resources>

View File

@@ -376,6 +376,7 @@
<!-- Title for Latin keyboard debug settings activity / dialog -->
<string name="english_ime_debug_settings" translatable="false">Android keyboard Debug settings</string>
<string name="prefs_debug_mode" translatable="false">Debug Mode</string>
<string name="kp2a_nextfields"><![CDATA[>]]></string>
</resources>

View File

@@ -12,32 +12,37 @@
<Key
android:codes="@integer/key_kp2a_alpha"
android:keyLabel="@string/label_alpha_key"
android:keyWidth="12%p"
android:keyWidth="10%p"
android:isModifier="true"
android:keyEdgeFlags="left" />
<Key
android:codes="@integer/key_kp2a_user"
android:keyLabel="@string/kp2a_user"
android:keyWidth="25%p"
android:keyWidth="22%p"
/>
<Key
android:codes="@integer/key_kp2a_pass"
android:keyLabel="@string/kp2a_password"
android:keyWidth="15%p"
android:keyWidth="12%p"
/>
<Key
android:codes="@integer/key_kp2a_nextfields"
android:keyLabel="@string/kp2a_nextfields"
android:keyWidth="8%p"
/>
<Key
android:codes="@integer/key_kp2a"
android:keyIcon="@drawable/sym_keyboard_kp2a"
android:iconPreview="@drawable/sym_keyboard_feedback_kp2a"
android:popupKeyboard="@xml/popup_kp2a"
android:keyWidth="12%p"
android:keyWidth="10%p"
android:isModifier="true" />
<Key
android:codes="@integer/key_delete"
android:keyIcon="@drawable/sym_keyboard_delete"
android:iconPreview="@drawable/sym_keyboard_feedback_delete"
android:keyWidth="12%p"
android:keyWidth="10%p"
android:isModifier="true"
android:isRepeatable="true"
/>

View File

@@ -12,32 +12,37 @@
<Key
android:codes="@integer/key_kp2a_alpha"
android:keyLabel="@string/label_alpha_key"
android:keyWidth="12%p"
android:keyWidth="10%p"
android:isModifier="true"
android:keyEdgeFlags="left" />
<Key
android:codes="@integer/key_kp2a_user"
android:keyLabel="@string/kp2a_user"
android:keyWidth="20%p"
android:keyWidth="19%p"
/>
<Key
android:codes="@integer/key_kp2a_pass"
android:keyLabel="@string/kp2a_password"
android:keyWidth="20%p"
android:keyWidth="19%p"
/>
<Key
android:codes="@integer/key_kp2a_nextfields"
android:keyLabel="@string/kp2a_nextfields"
android:keyWidth="8%p"
/>
<Key
android:codes="@integer/key_kp2a"
android:keyIcon="@drawable/sym_keyboard_kp2a"
android:iconPreview="@drawable/sym_keyboard_feedback_kp2a"
android:popupKeyboard="@xml/popup_kp2a"
android:keyWidth="12%p"
android:keyWidth="10%p"
android:isModifier="true" />
<Key
android:codes="@integer/key_delete"
android:keyIcon="@drawable/sym_keyboard_delete"
android:iconPreview="@drawable/sym_keyboard_feedback_delete"
android:keyWidth="12%p"
android:keyWidth="10%p"
android:isModifier="true"
android:isRepeatable="true"
/>

View File

@@ -12,32 +12,37 @@
<Key
android:codes="@integer/key_kp2a_alpha"
android:keyLabel="@string/label_alpha_key"
android:keyWidth="12%p"
android:keyWidth="10%p"
android:isModifier="true"
android:keyEdgeFlags="left" />
<Key
android:codes="@integer/key_kp2a_user"
android:keyLabel="@string/kp2a_user"
android:keyWidth="20%p"
/>
android:keyWidth="19%p"
/>
<Key
android:codes="@integer/key_kp2a_pass"
android:keyLabel="@string/kp2a_password"
android:keyWidth="20%p"
/>
android:keyWidth="19%p"
/>
<Key
android:codes="@integer/key_kp2a_nextfields"
android:keyLabel="@string/kp2a_nextfields"
android:keyWidth="8%p"
/>
<Key
android:codes="@integer/key_kp2a"
android:keyIcon="@drawable/sym_bkeyboard_kp2a"
android:iconPreview="@drawable/sym_keyboard_feedback_kp2a"
android:popupKeyboard="@xml/popup_kp2a"
android:keyWidth="12%p"
android:keyWidth="10%p"
android:isModifier="true" />
<Key
android:codes="@integer/key_delete"
android:keyIcon="@drawable/sym_bkeyboard_delete"
android:iconPreview="@drawable/sym_keyboard_feedback_delete"
android:keyWidth="12%p"
android:keyWidth="10%p"
android:isRepeatable="true"
/>
<Key