mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Assign entry elements to keys
This commit is contained in:
@@ -115,4 +115,5 @@ dependencies {
|
||||
implementation project(path: ':icon-pack-classic')
|
||||
implementation project(path: ':icon-pack-material')
|
||||
implementation project(path: ':magikeyboard')
|
||||
implementation project(path: ':keepass-model')
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.content.Intent;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kunzisoft.keepass.database.PwEntry;
|
||||
import com.kunzisoft.keepass_model.Entry;
|
||||
|
||||
public class EntrySelectionHelper {
|
||||
|
||||
@@ -30,9 +31,17 @@ public class EntrySelectionHelper {
|
||||
if (entrySelectionMode) {
|
||||
mReplyIntent = new Intent();
|
||||
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(
|
||||
EXTRA_ENTRY_SELECTION_MODE,
|
||||
entry);
|
||||
entryModel);
|
||||
activity.setResult(Activity.RESULT_OK, mReplyIntent);
|
||||
} else {
|
||||
activity.setResult(Activity.RESULT_CANCELED);
|
||||
|
||||
1
keepass-model/.gitignore
vendored
Normal file
1
keepass-model/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
||||
26
keepass-model/build.gradle
Normal file
26
keepass-model/build.gradle
Normal 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
21
keepass-model/proguard-rules.pro
vendored
Normal 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
|
||||
2
keepass-model/src/main/AndroidManifest.xml
Normal file
2
keepass-model/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,2 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.kunzisoft.keepass_model" />
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -25,4 +25,5 @@ android {
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'com.android.support:appcompat-v7:27.1.1'
|
||||
implementation project(path: ':keepass-model')
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
|
||||
import com.kunzisoft.keepass_model.Entry;
|
||||
|
||||
public class EntryRetrieverActivity extends AppCompatActivity {
|
||||
|
||||
public static final String TAG = EntryRetrieverActivity.class.getName();
|
||||
@@ -18,7 +20,6 @@ public class EntryRetrieverActivity extends AppCompatActivity {
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // TODO lock for < jelly bean
|
||||
Intent intent;
|
||||
try {
|
||||
@@ -38,8 +39,8 @@ public class EntryRetrieverActivity extends AppCompatActivity {
|
||||
Log.i(TAG, "Retrieve the entry selected");
|
||||
if (requestCode == ENTRY_REQUEST_CODE) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
// TODO get entry
|
||||
Log.e(TAG, data.getSerializableExtra("com.kunzisoft.keepass.extra.ENTRY_SELECTION_MODE").toString());
|
||||
Entry entry = data.getParcelableExtra("com.kunzisoft.keepass.extra.ENTRY_SELECTION_MODE");
|
||||
MagikIME.setEntryKey(entry);
|
||||
}
|
||||
if (resultCode == Activity.RESULT_CANCELED) {
|
||||
Log.w(TAG, "Entry not retrieved");
|
||||
|
||||
@@ -25,9 +25,12 @@ import android.inputmethodservice.Keyboard;
|
||||
import android.inputmethodservice.KeyboardView;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import com.kunzisoft.keepass_model.Entry;
|
||||
|
||||
public class MagikIME extends InputMethodService
|
||||
implements KeyboardView.OnKeyboardActionListener {
|
||||
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_FIELDS = 530;
|
||||
|
||||
private static Entry entryKey = null;
|
||||
|
||||
private KeyboardView keyboardView;
|
||||
private Keyboard keyboard;
|
||||
private Keyboard keyboard_entry;
|
||||
@@ -50,13 +55,36 @@ public class MagikIME extends InputMethodService
|
||||
keyboardView = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard, null);
|
||||
keyboard = new Keyboard(this, R.xml.password_keys);
|
||||
keyboard_entry = new Keyboard(this, R.xml.password_entry_keys);
|
||||
keyboardView.setKeyboard(keyboard);
|
||||
|
||||
assignKeyboardView();
|
||||
keyboardView.setOnKeyboardActionListener(this);
|
||||
keyboardView.setPreviewEnabled(false);
|
||||
|
||||
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
|
||||
public void onKey(int primaryCode, int[] keyCodes) {
|
||||
InputConnection ic = getCurrentInputConnection();
|
||||
@@ -66,6 +94,7 @@ public class MagikIME extends InputMethodService
|
||||
if (imeManager != null)
|
||||
imeManager.showInputMethodPicker();
|
||||
break;
|
||||
case KEY_ENTRY:
|
||||
case KEY_UNLOCK:
|
||||
Intent intent = new Intent(this, EntryRetrieverActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
@@ -74,14 +103,26 @@ public class MagikIME extends InputMethodService
|
||||
case KEY_LOCK:
|
||||
Intent lockIntent = new Intent("com.kunzisoft.keepass.LOCK");
|
||||
sendBroadcast(lockIntent);
|
||||
break;
|
||||
case KEY_ENTRY:
|
||||
deleteEntryKey();
|
||||
assignKeyboardView();
|
||||
break;
|
||||
case KEY_USERNAME:
|
||||
if (entryKey != null) {
|
||||
InputConnection inputConnection = getCurrentInputConnection();
|
||||
inputConnection.commitText(entryKey.getUsername(), 1);
|
||||
}
|
||||
break;
|
||||
case KEY_PASSWORD:
|
||||
if (entryKey != null) {
|
||||
InputConnection inputConnection = getCurrentInputConnection();
|
||||
inputConnection.commitText(entryKey.getPassword(), 1);
|
||||
}
|
||||
break;
|
||||
case KEY_URL:
|
||||
if (entryKey != null) {
|
||||
InputConnection inputConnection = getCurrentInputConnection();
|
||||
inputConnection.commitText(entryKey.getUrl(), 1);
|
||||
}
|
||||
break;
|
||||
case KEY_FIELDS:
|
||||
break;
|
||||
|
||||
@@ -1 +1 @@
|
||||
include ':app', ':icon-pack-classic', ':icon-pack-material', ':magikeyboard'
|
||||
include ':app', ':icon-pack-classic', ':icon-pack-material', ':magikeyboard', ':keepass-model'
|
||||
|
||||
Reference in New Issue
Block a user