Retrieve entry selected in keyboard

This commit is contained in:
J-Jamet committed 2018-06-10 14:03:34 +02:00
1 parent b4b215fe30
commit 4ad65c8f4a
15 files changed
+357 -58

No files matched your search

@@ -70,6 +70,7 @@ import com.kunzisoft.keepass.dialogs.GroupEditDialogFragment;
import com.kunzisoft.keepass.dialogs.IconPickerDialogFragment;
import com.kunzisoft.keepass.dialogs.ReadOnlyDialog;
import com.kunzisoft.keepass.icons.IconPackChooser;
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
import com.kunzisoft.keepass.search.SearchResultsActivity;
import com.kunzisoft.keepass.settings.PreferencesUtil;
import com.kunzisoft.keepass.tasks.SaveDatabaseProgressTaskDialogFragment;
@@ -109,7 +110,7 @@ public class GroupActivity extends ListNodesActivity
public static void launch(Activity act) {
startRecordTime(act);
launch(act, (PwGroup) null);
launch(act, null);
}
public static void launch(Activity act, PwGroup group) {
@@ -122,18 +123,37 @@ public class GroupActivity extends ListNodesActivity
}
}
public static void launchForKeyboardResult(Activity act) {
startRecordTime(act);
launchForKeyboardResult(act, null);
}
public static void launchForKeyboardResult(Activity act, PwGroup group) {
// TODO remove
if (checkTimeIsAllowedOrFinish(act)) {
Intent intent = new Intent(act, GroupActivity.class);
if (group != null) {
intent.putExtra(GROUP_ID_KEY, group.getId());
}
EntrySelectionHelper.addEntrySelectionModeExtraInIntent(intent);
act.startActivityForResult(intent, EntrySelectionHelper.ENTRY_SELECTION_RESPONSE_REQUEST_CODE);
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
public static void launch(Activity act, AssistStructure assistStructure) {
public static void launchForAutofillResult(Activity act, AssistStructure assistStructure) {
if ( assistStructure != null ) {
startRecordTime(act);
launch(act, null, assistStructure);
launchForAutofillResult(act, null, assistStructure);
} else {
launch(act);
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
public static void launch(Activity act, PwGroup group, AssistStructure assistStructure) {
public static void launchForAutofillResult(Activity act, PwGroup group, AssistStructure assistStructure) {
// TODO remove
if ( assistStructure != null ) {
if (checkTimeIsAllowedOrFinish(act)) {
Intent intent = new Intent(act, GroupActivity.class);
@@ -248,7 +268,7 @@ public class GroupActivity extends ListNodesActivity
if (currentGroup != null) {
addGroupEnabled = !readOnly;
addEntryEnabled = !readOnly; // TODO ReadOnly
addEntryEnabled = !readOnly; // TODO consultation mode
isRoot = (currentGroup == root);
if (!currentGroup.allowAddEntryIfIsRoot())
addEntryEnabled = !isRoot && addEntryEnabled;
@@ -41,6 +41,7 @@ import com.kunzisoft.keepass.database.PwNode;
import com.kunzisoft.keepass.database.SortNodeEnum;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.SortDialogFragment;
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
import com.kunzisoft.keepass.lock.LockingActivity;
import com.kunzisoft.keepass.password.AssignPasswordHelper;
import com.kunzisoft.keepass.utils.MenuUtil;
@@ -58,6 +59,7 @@ public abstract class ListNodesActivity extends LockingActivity
protected PwGroup mCurrentGroup;
protected TextView groupNameView;
protected boolean entrySelectionMode;
protected AutofillHelper autofillHelper;
@Override
@@ -80,6 +82,7 @@ public abstract class ListNodesActivity extends LockingActivity
initializeListNodesFragment(mCurrentGroup);
entrySelectionMode = EntrySelectionHelper.isIntentInEntrySelectionMode(getIntent());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
autofillHelper = new AutofillHelper();
autofillHelper.retrieveAssistStructure(getIntent());
@@ -174,13 +177,25 @@ public abstract class ListNodesActivity extends LockingActivity
}
}
if ( assistStructure == null ){
switch (node.getType()) {
case GROUP:
openGroup((PwGroup) node);
break;
case ENTRY:
EntryActivity.launch(this, (PwEntry) node);
break;
if (entrySelectionMode) {
switch (node.getType()) {
case GROUP:
openGroup((PwGroup) node);
break;
case ENTRY:
EntrySelectionHelper.buildResponseWhenEntrySelected(this, (PwEntry) node);
finish();
break;
}
} else {
switch (node.getType()) {
case GROUP:
openGroup((PwGroup) node);
break;
case ENTRY:
EntryActivity.launch(this, (PwEntry) node);
break;
}
}
}
}
@@ -233,6 +248,7 @@ public abstract class ListNodesActivity extends LockingActivity
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
EntrySelectionHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
}
@@ -54,7 +54,7 @@ public class AutoFillAuthActivity extends AppCompatActivity {
// Pass extra for Autofill (EXTRA_ASSIST_STRUCTURE)
AssistStructure assistStructure = autofillHelper.retrieveAssistStructure(getIntent());
if (assistStructure != null) {
FileSelectActivity.launch(this, assistStructure);
FileSelectActivity.launchForAutofillResult(this, assistStructure);
} else {
setResult(RESULT_CANCELED);
finish();
@@ -36,6 +36,7 @@ import android.widget.RemoteViews;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.database.PwEntry;
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
import java.util.ArrayList;
import java.util.List;
@@ -64,6 +65,7 @@ public class AutofillHelper {
public static void addAssistStructureExtraInIntent(Intent intent, AssistStructure assistStructure) {
if (assistStructure != null) {
EntrySelectionHelper.addEntrySelectionModeExtraInIntent(intent);
intent.putExtra(android.view.autofill.AutofillManager.EXTRA_ASSIST_STRUCTURE, assistStructure);
}
}
@@ -144,7 +146,7 @@ public class AutofillHelper {
/**
* Utility method to loop and close each activity with return data
*/
public static void onActivityResultSetResult(Activity activity, int requestCode, int resultCode, Intent data) {
public static void onActivityResultSetResultAndFinish(Activity activity, int requestCode, int resultCode, Intent data) {
if (requestCode == AUTOFILL_RESPONSE_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
activity.setResult(resultCode, data);
@@ -152,15 +154,6 @@ public class AutofillHelper {
if (resultCode == Activity.RESULT_CANCELED) {
activity.setResult(Activity.RESULT_CANCELED);
}
}
}
/**
* Utility method to loop and close each activity with return data
*/
public static void onActivityResultSetResultAndFinish(Activity activity, int requestCode, int resultCode, Intent data) {
if (requestCode == AUTOFILL_RESPONSE_REQUEST_CODE) {
onActivityResultSetResult(activity, requestCode, resultCode, data);
activity.finish();
}
}
@@ -56,6 +56,7 @@ import com.kunzisoft.keepass.database.action.FileOnFinishRunnable;
import com.kunzisoft.keepass.database.exception.ContentFileNotFoundException;
import com.kunzisoft.keepass.dialogs.AssignMasterKeyDialogFragment;
import com.kunzisoft.keepass.dialogs.CreateFileDialogFragment;
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
import com.kunzisoft.keepass.password.AssignPasswordHelper;
import com.kunzisoft.keepass.password.PasswordActivity;
import com.kunzisoft.keepass.settings.PreferencesUtil;
@@ -102,6 +103,8 @@ public class FileSelectActivity extends StylishActivity implements
// TODO Consultation Mode
private boolean consultationMode = false;
private boolean entrySelectionMode;
private AutofillHelper autofillHelper;
private View fileSelectExpandableButton;
@@ -118,11 +121,17 @@ public class FileSelectActivity extends StylishActivity implements
public static void launch(Activity activity) {
Intent intent = new Intent(activity, FileSelectActivity.class);
// only to avoid visible flickering when redirecting
activity.startActivityForResult(intent, 0);
activity.startActivityForResult(intent, RESULT_CANCELED);
}
public static void launchForKeyboardResult(Activity activity) {
Intent intent = new Intent(activity, FileSelectActivity.class);
EntrySelectionHelper.addEntrySelectionModeExtraInIntent(intent);
activity.startActivityForResult(intent, EntrySelectionHelper.ENTRY_SELECTION_RESPONSE_REQUEST_CODE);
}
@RequiresApi(api = Build.VERSION_CODES.O)
public static void launch(Activity activity, AssistStructure assistStructure) {
public static void launchForAutofillResult(Activity activity, AssistStructure assistStructure) {
if ( assistStructure != null ) {
Intent intent = new Intent(activity, FileSelectActivity.class);
AutofillHelper.addAssistStructureExtraInIntent(intent, assistStructure);
@@ -136,11 +145,6 @@ public class FileSelectActivity extends StylishActivity implements
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (AutofillHelper.isIntentContainsExtraAssistStructureKey(getIntent()))
consultationMode = true;
}
fileHistory = App.getFileHistory();
setContentView(R.layout.file_selection);
@@ -173,6 +177,7 @@ public class FileSelectActivity extends StylishActivity implements
RecyclerView mListFiles = findViewById(R.id.file_list);
mListFiles.setLayoutManager(new LinearLayoutManager(this));
entrySelectionMode = EntrySelectionHelper.isIntentInEntrySelectionMode(getIntent());
// To retrieve info for AutoFill
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
autofillHelper = new AutofillHelper();
@@ -244,13 +249,17 @@ public class FileSelectActivity extends StylishActivity implements
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
assistStructure = autofillHelper.getAssistStructure();
if (assistStructure != null) {
PasswordActivity.launch(FileSelectActivity.this,
PasswordActivity.launchForAutofillResult(FileSelectActivity.this,
path,
assistStructure);
}
}
if (assistStructure == null) {
PasswordActivity.launch(FileSelectActivity.this, path);
if (entrySelectionMode) {
PasswordActivity.launchForKeyboardResult(FileSelectActivity.this, path);
} else {
PasswordActivity.launch(FileSelectActivity.this, path);
}
}
// Delete flickering for kitkat <=
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
@@ -596,12 +605,16 @@ public class FileSelectActivity extends StylishActivity implements
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
assistStructure = autofillHelper.getAssistStructure();
if (assistStructure != null) {
PasswordActivity.launch(FileSelectActivity.this,
PasswordActivity.launchForAutofillResult(FileSelectActivity.this,
fileName, keyFile, assistStructure);
}
}
if (assistStructure == null) {
PasswordActivity.launch(FileSelectActivity.this, fileName, keyFile);
if (entrySelectionMode) {
PasswordActivity.launchForKeyboardResult(FileSelectActivity.this, fileName, keyFile);
} else {
PasswordActivity.launch(FileSelectActivity.this, fileName, keyFile);
}
}
} catch (ContentFileNotFoundException e) {
Toast.makeText(FileSelectActivity.this,
@@ -639,6 +652,8 @@ public class FileSelectActivity extends StylishActivity implements
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Get the entry result in entry selection mode
EntrySelectionHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
}
@@ -56,6 +56,7 @@ import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import com.kunzisoft.keepass.R;
import com.kunzisoft.keepass.activities.GroupActivity;
import com.kunzisoft.keepass.selection.EntrySelectionHelper;
import com.kunzisoft.keepass.lock.LockingActivity;
import com.kunzisoft.keepass.app.App;
import com.kunzisoft.keepass.autofill.AutofillHelper;
@@ -127,6 +128,7 @@ public class PasswordActivity extends StylishActivity
private KeyFileHelper keyFileHelper;
protected boolean entrySelectionMode;
private AutofillHelper autofillHelper;
public static void launch(
@@ -145,19 +147,39 @@ public class PasswordActivity extends StylishActivity
intent.putExtra(UriIntentInitTask.KEY_FILENAME, fileName);
intent.putExtra(UriIntentInitTask.KEY_KEYFILE, keyFile);
// only to avoid visible flickering when redirecting
act.startActivityForResult(intent, 0);
act.startActivityForResult(intent, RESULT_CANCELED);
}
public static void launchForKeyboardResult(
Activity act,
String fileName) throws FileNotFoundException {
launchForKeyboardResult(act, fileName, "");
}
public static void launchForKeyboardResult(
Activity act,
String fileName,
String keyFile) throws FileNotFoundException {
verifyFileNameUriFromLaunch(fileName);
Intent intent = new Intent(act, PasswordActivity.class);
intent.putExtra(UriIntentInitTask.KEY_FILENAME, fileName);
intent.putExtra(UriIntentInitTask.KEY_KEYFILE, keyFile);
EntrySelectionHelper.addEntrySelectionModeExtraInIntent(intent);
// only to avoid visible flickering when redirecting
act.startActivityForResult(intent, EntrySelectionHelper.ENTRY_SELECTION_RESPONSE_REQUEST_CODE);
}
@RequiresApi(api = Build.VERSION_CODES.O)
public static void launch(
public static void launchForAutofillResult(
Activity act,
String fileName,
AssistStructure assistStructure) throws FileNotFoundException {
launch(act, fileName, "", assistStructure);
launchForAutofillResult(act, fileName, "", assistStructure);
}
@RequiresApi(api = Build.VERSION_CODES.O)
public static void launch(
public static void launchForAutofillResult(
Activity act,
String fileName,
String keyFile,
@@ -199,6 +221,8 @@ public class PasswordActivity extends StylishActivity
Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// To get entry in result
EntrySelectionHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
AutofillHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
}
@@ -295,6 +319,8 @@ public class PasswordActivity extends StylishActivity
fingerprintImageView);
}
entrySelectionMode = EntrySelectionHelper.isIntentInEntrySelectionMode(getIntent());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
autofillHelper = new AutofillHelper();
autofillHelper.retrieveAssistStructure(getIntent());
@@ -901,11 +927,15 @@ public class PasswordActivity extends StylishActivity
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
assistStructure = autofillHelper.getAssistStructure();
if (assistStructure != null) {
GroupActivity.launch(PasswordActivity.this, assistStructure);
GroupActivity.launchForAutofillResult(PasswordActivity.this, assistStructure);
}
}
if (assistStructure == null) {
GroupActivity.launch(PasswordActivity.this);
if (entrySelectionMode) {
GroupActivity.launchForKeyboardResult(PasswordActivity.this);
} else {
GroupActivity.launch(PasswordActivity.this);
}
}
}
@@ -0,0 +1,49 @@
/*
* Copyright 2017 Jeremy Jamet / Kunzisoft.
*
* This file is part of KeePass DX.
*
* KeePass DX is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* KeePass DX is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with KeePass DX. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.kunzisoft.keepass.selection;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import com.kunzisoft.keepass.fileselect.FileSelectActivity;
@RequiresApi(api = Build.VERSION_CODES.O)
public class EntrySelectionAuthActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
startFileSelectActivity();
super.onCreate(savedInstanceState);
}
protected void startFileSelectActivity() {
// Pass extra to get entry
FileSelectActivity.launchForKeyboardResult(this);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
EntrySelectionHelper.onActivityResultSetResultAndFinish(this, requestCode, resultCode, data);
}
}
@@ -0,0 +1,56 @@
package com.kunzisoft.keepass.selection;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import com.kunzisoft.keepass.database.PwEntry;
public class EntrySelectionHelper {
public static final int ENTRY_SELECTION_RESPONSE_REQUEST_CODE = 5164;
public static final String EXTRA_ENTRY_SELECTION_MODE = "com.kunzisoft.keepass.extra.ENTRY_SELECTION_MODE";
public static void addEntrySelectionModeExtraInIntent(Intent intent) {
intent.putExtra(EXTRA_ENTRY_SELECTION_MODE, true);
}
public static boolean isIntentInEntrySelectionMode(Intent intent) {
return intent.getBooleanExtra(EXTRA_ENTRY_SELECTION_MODE, false);
}
/**
* Method to hit when right key is selected
*/
public static void buildResponseWhenEntrySelected(Activity activity, PwEntry entry) {
Intent mReplyIntent;
Intent intent = activity.getIntent();
boolean entrySelectionMode = isIntentInEntrySelectionMode(intent);
if (entrySelectionMode) {
mReplyIntent = new Intent();
Log.d(activity.getClass().getName(), "Reply entry selection");
mReplyIntent.putExtra(
EXTRA_ENTRY_SELECTION_MODE,
entry);
activity.setResult(Activity.RESULT_OK, mReplyIntent);
} else {
activity.setResult(Activity.RESULT_CANCELED);
}
}
/**
* Utility method to loop and close each activity with return data
*/
public static void onActivityResultSetResultAndFinish(Activity activity, int requestCode, int resultCode, Intent data) {
if (requestCode == ENTRY_SELECTION_RESPONSE_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
activity.setResult(resultCode, data);
}
if (resultCode == Activity.RESULT_CANCELED) {
activity.setResult(Activity.RESULT_CANCELED);
}
activity.finish();
}
}
}