Assign entry elements to keys

This commit is contained in:
J-Jamet
2018-06-10 21:51:09 +02:00
parent 4ad65c8f4a
commit 5f14596ed2
11 changed files with 203 additions and 8 deletions

View File

@@ -115,4 +115,5 @@ dependencies {
implementation project(path: ':icon-pack-classic') implementation project(path: ':icon-pack-classic')
implementation project(path: ':icon-pack-material') implementation project(path: ':icon-pack-material')
implementation project(path: ':magikeyboard') implementation project(path: ':magikeyboard')
implementation project(path: ':keepass-model')
} }

View File

@@ -5,6 +5,7 @@ import android.content.Intent;
import android.util.Log; import android.util.Log;
import com.kunzisoft.keepass.database.PwEntry; import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass_model.Entry;
public class EntrySelectionHelper { public class EntrySelectionHelper {
@@ -30,9 +31,17 @@ public class EntrySelectionHelper {
if (entrySelectionMode) { if (entrySelectionMode) {
mReplyIntent = new Intent(); mReplyIntent = new Intent();
Log.d(activity.getClass().getName(), "Reply entry selection"); Log.d(activity.getClass().getName(), "Reply entry selection");
Entry entryModel = new Entry();
entryModel.setUsername(entry.getUsername());
entryModel.setPassword(entry.getPassword());
entryModel.setUrl(entry.getUrl());
// TODO Fields
//entryModel.setCustomField(entry.getFields());
mReplyIntent.putExtra( mReplyIntent.putExtra(
EXTRA_ENTRY_SELECTION_MODE, EXTRA_ENTRY_SELECTION_MODE,
entry); entryModel);
activity.setResult(Activity.RESULT_OK, mReplyIntent); activity.setResult(Activity.RESULT_OK, mReplyIntent);
} else { } else {
activity.setResult(Activity.RESULT_CANCELED); activity.setResult(Activity.RESULT_CANCELED);

1
keepass-model/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,26 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}

21
keepass-model/proguard-rules.pro vendored Normal file
View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.kunzisoft.keepass_model" />

View File

@@ -0,0 +1,92 @@
package com.kunzisoft.keepass_model;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class Entry implements Parcelable {
private String username;
private String password;
private String url;
private Map<String, String> customFields;
public Entry() {
this.username = "";
this.password = "";
this.url = "";
this.customFields = new HashMap<>();
}
protected Entry(Parcel in) {
username = in.readString();
password = in.readString();
url = in.readString();
//noinspection unchecked
customFields = in.readHashMap(String.class.getClassLoader());
}
public static final Creator<Entry> CREATOR = new Creator<Entry>() {
@Override
public Entry createFromParcel(Parcel in) {
return new Entry(in);
}
@Override
public Entry[] newArray(int size) {
return new Entry[size];
}
};
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Set<String> getCustomFieldsKeys() {
return customFields.keySet();
}
public String getCustomField(String key) {
return customFields.get(key);
}
public void setCustomField(String key, String value) {
this.customFields.put(key, value);
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(username);
parcel.writeString(password);
parcel.writeString(url);
parcel.writeMap(customFields);
}
}

View File

@@ -25,4 +25,5 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:appcompat-v7:27.1.1'
implementation project(path: ':keepass-model')
} }

View File

@@ -8,6 +8,8 @@ import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import com.kunzisoft.keepass_model.Entry;
public class EntryRetrieverActivity extends AppCompatActivity { public class EntryRetrieverActivity extends AppCompatActivity {
public static final String TAG = EntryRetrieverActivity.class.getName(); public static final String TAG = EntryRetrieverActivity.class.getName();
@@ -18,7 +20,6 @@ public class EntryRetrieverActivity extends AppCompatActivity {
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // TODO lock for < jelly bean if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // TODO lock for < jelly bean
Intent intent; Intent intent;
try { try {
@@ -38,8 +39,8 @@ public class EntryRetrieverActivity extends AppCompatActivity {
Log.i(TAG, "Retrieve the entry selected"); Log.i(TAG, "Retrieve the entry selected");
if (requestCode == ENTRY_REQUEST_CODE) { if (requestCode == ENTRY_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
// TODO get entry Entry entry = data.getParcelableExtra("com.kunzisoft.keepass.extra.ENTRY_SELECTION_MODE");
Log.e(TAG, data.getSerializableExtra("com.kunzisoft.keepass.extra.ENTRY_SELECTION_MODE").toString()); MagikIME.setEntryKey(entry);
} }
if (resultCode == Activity.RESULT_CANCELED) { if (resultCode == Activity.RESULT_CANCELED) {
Log.w(TAG, "Entry not retrieved"); Log.w(TAG, "Entry not retrieved");

View File

@@ -25,9 +25,12 @@ import android.inputmethodservice.Keyboard;
import android.inputmethodservice.KeyboardView; import android.inputmethodservice.KeyboardView;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import com.kunzisoft.keepass_model.Entry;
public class MagikIME extends InputMethodService public class MagikIME extends InputMethodService
implements KeyboardView.OnKeyboardActionListener { implements KeyboardView.OnKeyboardActionListener {
private static final String TAG = MagikIME.class.getName(); private static final String TAG = MagikIME.class.getName();
@@ -41,6 +44,8 @@ public class MagikIME extends InputMethodService
private static final int KEY_URL = 520; private static final int KEY_URL = 520;
private static final int KEY_FIELDS = 530; private static final int KEY_FIELDS = 530;
private static Entry entryKey = null;
private KeyboardView keyboardView; private KeyboardView keyboardView;
private Keyboard keyboard; private Keyboard keyboard;
private Keyboard keyboard_entry; private Keyboard keyboard_entry;
@@ -50,13 +55,36 @@ public class MagikIME extends InputMethodService
keyboardView = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard, null); keyboardView = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard, null);
keyboard = new Keyboard(this, R.xml.password_keys); keyboard = new Keyboard(this, R.xml.password_keys);
keyboard_entry = new Keyboard(this, R.xml.password_entry_keys); keyboard_entry = new Keyboard(this, R.xml.password_entry_keys);
keyboardView.setKeyboard(keyboard);
assignKeyboardView();
keyboardView.setOnKeyboardActionListener(this); keyboardView.setOnKeyboardActionListener(this);
keyboardView.setPreviewEnabled(false); keyboardView.setPreviewEnabled(false);
return keyboardView; return keyboardView;
} }
private void assignKeyboardView() {
if (entryKey != null) {
keyboardView.setKeyboard(keyboard_entry);
} else {
keyboardView.setKeyboard(keyboard);
}
}
@Override
public void onStartInputView(EditorInfo info, boolean restarting) {
super.onStartInputView(info, restarting);
assignKeyboardView();
}
public static void setEntryKey(Entry entry) {
entryKey = entry;
}
public static void deleteEntryKey() {
entryKey = null;
}
@Override @Override
public void onKey(int primaryCode, int[] keyCodes) { public void onKey(int primaryCode, int[] keyCodes) {
InputConnection ic = getCurrentInputConnection(); InputConnection ic = getCurrentInputConnection();
@@ -66,6 +94,7 @@ public class MagikIME extends InputMethodService
if (imeManager != null) if (imeManager != null)
imeManager.showInputMethodPicker(); imeManager.showInputMethodPicker();
break; break;
case KEY_ENTRY:
case KEY_UNLOCK: case KEY_UNLOCK:
Intent intent = new Intent(this, EntryRetrieverActivity.class); Intent intent = new Intent(this, EntryRetrieverActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@@ -74,14 +103,26 @@ public class MagikIME extends InputMethodService
case KEY_LOCK: case KEY_LOCK:
Intent lockIntent = new Intent("com.kunzisoft.keepass.LOCK"); Intent lockIntent = new Intent("com.kunzisoft.keepass.LOCK");
sendBroadcast(lockIntent); sendBroadcast(lockIntent);
break; deleteEntryKey();
case KEY_ENTRY: assignKeyboardView();
break; break;
case KEY_USERNAME: case KEY_USERNAME:
if (entryKey != null) {
InputConnection inputConnection = getCurrentInputConnection();
inputConnection.commitText(entryKey.getUsername(), 1);
}
break; break;
case KEY_PASSWORD: case KEY_PASSWORD:
if (entryKey != null) {
InputConnection inputConnection = getCurrentInputConnection();
inputConnection.commitText(entryKey.getPassword(), 1);
}
break; break;
case KEY_URL: case KEY_URL:
if (entryKey != null) {
InputConnection inputConnection = getCurrentInputConnection();
inputConnection.commitText(entryKey.getUrl(), 1);
}
break; break;
case KEY_FIELDS: case KEY_FIELDS:
break; break;

View File

@@ -1 +1 @@
include ':app', ':icon-pack-classic', ':icon-pack-material', ':magikeyboard' include ':app', ':icon-pack-classic', ':icon-pack-material', ':magikeyboard', ':keepass-model'