mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
Merge remote-tracking branch 'origin/t/snackbar' into development
Conflicts: OpenKeychain/build.gradle
This commit is contained in:
commit
5564f65a69
@ -27,6 +27,7 @@ dependencies {
|
||||
compile 'com.google.zxing:core:3.0.1'
|
||||
compile 'com.jpardogo.materialtabstrip:library:1.0.8'
|
||||
compile 'it.neokree:MaterialNavigationDrawer:1.3'
|
||||
compile 'com.nispok:snackbar:2.7.4'
|
||||
}
|
||||
|
||||
android {
|
||||
|
@ -75,7 +75,7 @@
|
||||
android:theme="@style/KeychainTheme"
|
||||
android:label="@string/app_name">
|
||||
<activity
|
||||
android:name=".ui.KeyListActivity"
|
||||
android:name=".ui.MainActivity"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop">
|
||||
@ -85,6 +85,11 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.KeyListActivity"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
||||
android:label="@string/app_name"
|
||||
android:windowSoftInputMode="stateAlwaysHidden" />
|
||||
<activity
|
||||
android:name=".ui.FirstTimeActivity"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
||||
|
@ -21,18 +21,14 @@ package org.sufficientlysecure.keychain.operations.results;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.view.View;
|
||||
|
||||
import com.github.johnpersano.supertoasts.SuperCardToast;
|
||||
import com.github.johnpersano.supertoasts.SuperToast;
|
||||
import com.github.johnpersano.supertoasts.SuperToast.Duration;
|
||||
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
|
||||
import com.github.johnpersano.supertoasts.util.Style;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
|
||||
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
|
||||
public class CertifyResult extends OperationResult {
|
||||
|
||||
@ -78,30 +74,31 @@ public class CertifyResult extends OperationResult {
|
||||
}
|
||||
};
|
||||
|
||||
public SuperCardToast createNotify(final Activity activity) {
|
||||
public Showable createNotify(final Activity activity) {
|
||||
|
||||
int resultType = getResult();
|
||||
|
||||
String str;
|
||||
int duration, color;
|
||||
int duration;
|
||||
Style style;
|
||||
|
||||
// Not an overall failure
|
||||
if ((resultType & OperationResult.RESULT_ERROR) == 0) {
|
||||
String withWarnings;
|
||||
|
||||
duration = Duration.EXTRA_LONG;
|
||||
color = Style.GREEN;
|
||||
duration = Notify.LENGTH_LONG;
|
||||
style = Style.OK;
|
||||
withWarnings = "";
|
||||
|
||||
// Any warnings?
|
||||
if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) {
|
||||
duration = 0;
|
||||
color = Style.ORANGE;
|
||||
style = Style.WARN;
|
||||
withWarnings += activity.getString(R.string.with_warnings);
|
||||
}
|
||||
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
|
||||
duration = 0;
|
||||
color = Style.ORANGE;
|
||||
style = Style.WARN;
|
||||
withWarnings += activity.getString(R.string.with_cancelled);
|
||||
}
|
||||
|
||||
@ -111,46 +108,27 @@ public class CertifyResult extends OperationResult {
|
||||
if (mCertifyError > 0) {
|
||||
// definitely switch to warning-style message in this case!
|
||||
duration = 0;
|
||||
color = Style.RED;
|
||||
style = Style.ERROR;
|
||||
str += " " + activity.getResources().getQuantityString(
|
||||
R.plurals.certify_keys_with_errors, mCertifyError, mCertifyError);
|
||||
}
|
||||
|
||||
} else {
|
||||
duration = 0;
|
||||
color = Style.RED;
|
||||
style = Style.ERROR;
|
||||
str = activity.getResources().getQuantityString(R.plurals.certify_error,
|
||||
mCertifyError, mCertifyError);
|
||||
}
|
||||
|
||||
boolean button = getLog() != null && !getLog().isEmpty();
|
||||
SuperCardToast toast = new SuperCardToast(activity,
|
||||
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
|
||||
Style.getStyle(color, SuperToast.Animations.POPUP));
|
||||
toast.setText(str);
|
||||
toast.setDuration(duration);
|
||||
toast.setIndeterminate(duration == 0);
|
||||
toast.setSwipeToDismiss(true);
|
||||
// If we have a log and it's non-empty, show a View Log button
|
||||
if (button) {
|
||||
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
|
||||
activity.getResources().getString(R.string.view_log));
|
||||
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
|
||||
new SuperToast.OnClickListener() {
|
||||
return Notify.createNotify(activity, str, duration, style, new ActionListener() {
|
||||
@Override
|
||||
public void onClick(View view, Parcelable token) {
|
||||
public void onAction() {
|
||||
Intent intent = new Intent(
|
||||
activity, LogDisplayActivity.class);
|
||||
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, CertifyResult.this);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
return toast;
|
||||
}, R.string.view_log);
|
||||
|
||||
}
|
||||
|
||||
|
@ -24,15 +24,13 @@ import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.view.View;
|
||||
|
||||
import com.github.johnpersano.supertoasts.SuperCardToast;
|
||||
import com.github.johnpersano.supertoasts.SuperToast;
|
||||
import com.github.johnpersano.supertoasts.SuperToast.Duration;
|
||||
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
|
||||
import com.github.johnpersano.supertoasts.util.Style;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
|
||||
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
|
||||
public class DeleteResult extends OperationResult {
|
||||
|
||||
@ -68,31 +66,32 @@ public class DeleteResult extends OperationResult {
|
||||
}
|
||||
};
|
||||
|
||||
public SuperCardToast createNotify(final Activity activity) {
|
||||
public Showable createNotify(final Activity activity) {
|
||||
|
||||
int resultType = getResult();
|
||||
|
||||
String str;
|
||||
int duration, color;
|
||||
int duration;
|
||||
Style style;
|
||||
|
||||
// Not an overall failure
|
||||
if ((resultType & OperationResult.RESULT_ERROR) == 0) {
|
||||
String untilCancelled;
|
||||
|
||||
duration = Duration.EXTRA_LONG;
|
||||
color = Style.GREEN;
|
||||
duration = Notify.LENGTH_LONG;
|
||||
style = Style.OK;
|
||||
untilCancelled = "";
|
||||
|
||||
// Any warnings?
|
||||
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
|
||||
duration = 0;
|
||||
color = Style.ORANGE;
|
||||
style = Style.WARN;
|
||||
untilCancelled += activity.getString(R.string.with_cancelled);
|
||||
}
|
||||
|
||||
// New and updated keys
|
||||
if (mOk > 0 && mFail > 0) {
|
||||
color = Style.ORANGE;
|
||||
style = Style.WARN;
|
||||
duration = 0;
|
||||
str = activity.getResources().getQuantityString(
|
||||
R.plurals.delete_ok_but_fail_1, mOk, mOk);
|
||||
@ -105,13 +104,13 @@ public class DeleteResult extends OperationResult {
|
||||
str = activity.getString(R.string.delete_cancelled);
|
||||
} else {
|
||||
duration = 0;
|
||||
color = Style.RED;
|
||||
style = Style.ERROR;
|
||||
str = "internal error";
|
||||
}
|
||||
|
||||
} else {
|
||||
duration = 0;
|
||||
color = Style.RED;
|
||||
style = Style.ERROR;
|
||||
if (mFail == 0) {
|
||||
str = activity.getString(R.string.delete_nothing);
|
||||
} else {
|
||||
@ -119,34 +118,15 @@ public class DeleteResult extends OperationResult {
|
||||
}
|
||||
}
|
||||
|
||||
boolean button = getLog() != null && !getLog().isEmpty();
|
||||
SuperCardToast toast = new SuperCardToast(activity,
|
||||
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
|
||||
Style.getStyle(color, SuperToast.Animations.POPUP));
|
||||
toast.setText(str);
|
||||
toast.setDuration(duration);
|
||||
toast.setIndeterminate(duration == 0);
|
||||
toast.setSwipeToDismiss(true);
|
||||
// If we have a log and it's non-empty, show a View Log button
|
||||
if (button) {
|
||||
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
|
||||
activity.getResources().getString(R.string.view_log));
|
||||
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
|
||||
new SuperToast.OnClickListener() {
|
||||
return Notify.createNotify(activity, str, duration, style, new ActionListener() {
|
||||
@Override
|
||||
public void onClick(View view, Parcelable token) {
|
||||
public void onAction() {
|
||||
Intent intent = new Intent(
|
||||
activity, LogDisplayActivity.class);
|
||||
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, DeleteResult.this);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
return toast;
|
||||
}, R.string.view_log);
|
||||
|
||||
}
|
||||
|
||||
|
@ -21,18 +21,14 @@ package org.sufficientlysecure.keychain.operations.results;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.view.View;
|
||||
|
||||
import com.github.johnpersano.supertoasts.SuperCardToast;
|
||||
import com.github.johnpersano.supertoasts.SuperToast;
|
||||
import com.github.johnpersano.supertoasts.SuperToast.Duration;
|
||||
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
|
||||
import com.github.johnpersano.supertoasts.util.Style;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
|
||||
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
|
||||
public class ImportKeyResult extends OperationResult {
|
||||
|
||||
@ -118,30 +114,31 @@ public class ImportKeyResult extends OperationResult {
|
||||
}
|
||||
};
|
||||
|
||||
public SuperCardToast createNotify(final Activity activity) {
|
||||
public Showable createNotify(final Activity activity) {
|
||||
|
||||
int resultType = getResult();
|
||||
|
||||
String str;
|
||||
int duration, color;
|
||||
int duration;
|
||||
Style style;
|
||||
|
||||
// Not an overall failure
|
||||
if ((resultType & OperationResult.RESULT_ERROR) == 0) {
|
||||
String withWarnings;
|
||||
|
||||
duration = Duration.EXTRA_LONG;
|
||||
color = Style.GREEN;
|
||||
duration = Notify.LENGTH_LONG;
|
||||
style = Style.OK;
|
||||
withWarnings = "";
|
||||
|
||||
// Any warnings?
|
||||
if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) {
|
||||
duration = 0;
|
||||
color = Style.ORANGE;
|
||||
style = Style.WARN;
|
||||
withWarnings += activity.getString(R.string.with_warnings);
|
||||
}
|
||||
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
|
||||
duration = 0;
|
||||
color = Style.ORANGE;
|
||||
style = Style.WARN;
|
||||
withWarnings += activity.getString(R.string.with_cancelled);
|
||||
}
|
||||
|
||||
@ -159,20 +156,20 @@ public class ImportKeyResult extends OperationResult {
|
||||
R.plurals.import_keys_added, mNewKeys, mNewKeys, withWarnings);
|
||||
} else {
|
||||
duration = 0;
|
||||
color = Style.RED;
|
||||
style = Style.ERROR;
|
||||
str = "internal error";
|
||||
}
|
||||
if (isOkWithErrors()) {
|
||||
// definitely switch to warning-style message in this case!
|
||||
duration = 0;
|
||||
color = Style.RED;
|
||||
style = Style.ERROR;
|
||||
str += " " + activity.getResources().getQuantityString(
|
||||
R.plurals.import_keys_with_errors, mBadKeys, mBadKeys);
|
||||
}
|
||||
|
||||
} else {
|
||||
duration = 0;
|
||||
color = Style.RED;
|
||||
style = Style.ERROR;
|
||||
if (isFailNothing()) {
|
||||
str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0
|
||||
? R.string.import_error_nothing_cancelled
|
||||
@ -182,34 +179,15 @@ public class ImportKeyResult extends OperationResult {
|
||||
}
|
||||
}
|
||||
|
||||
boolean button = getLog() != null && !getLog().isEmpty();
|
||||
SuperCardToast toast = new SuperCardToast(activity,
|
||||
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
|
||||
Style.getStyle(color, SuperToast.Animations.POPUP));
|
||||
toast.setText(str);
|
||||
toast.setDuration(duration);
|
||||
toast.setIndeterminate(duration == 0);
|
||||
toast.setSwipeToDismiss(true);
|
||||
// If we have a log and it's non-empty, show a View Log button
|
||||
if (button) {
|
||||
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
|
||||
activity.getResources().getString(R.string.view_log));
|
||||
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
|
||||
new SuperToast.OnClickListener() {
|
||||
return Notify.createNotify(activity, str, duration, style, new ActionListener() {
|
||||
@Override
|
||||
public void onClick(View view, Parcelable token) {
|
||||
public void onAction() {
|
||||
Intent intent = new Intent(
|
||||
activity, LogDisplayActivity.class);
|
||||
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
return toast;
|
||||
}, R.string.view_log);
|
||||
|
||||
}
|
||||
|
||||
|
@ -20,19 +20,24 @@ package org.sufficientlysecure.keychain.operations.results;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.view.View;
|
||||
|
||||
import com.github.johnpersano.supertoasts.SuperCardToast;
|
||||
import com.github.johnpersano.supertoasts.SuperToast;
|
||||
import com.github.johnpersano.supertoasts.util.OnClickWrapper;
|
||||
import com.github.johnpersano.supertoasts.util.Style;
|
||||
import com.nispok.snackbar.Snackbar;
|
||||
import com.nispok.snackbar.Snackbar.SnackbarDuration;
|
||||
import com.nispok.snackbar.SnackbarManager;
|
||||
import com.nispok.snackbar.listeners.ActionClickListener;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
|
||||
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
@ -195,58 +200,44 @@ public abstract class OperationResult implements Parcelable {
|
||||
|
||||
}
|
||||
|
||||
public SuperCardToast createNotify(final Activity activity) {
|
||||
|
||||
int color;
|
||||
public Showable createNotify(final Activity activity) {
|
||||
|
||||
Log.d(Constants.TAG, "mLog.getLast()"+mLog.getLast());
|
||||
Log.d(Constants.TAG, "mLog.getLast().mType"+mLog.getLast().mType);
|
||||
Log.d(Constants.TAG, "mLog.getLast().mType.getMsgId()"+mLog.getLast().mType.getMsgId());
|
||||
|
||||
// Take the last message as string
|
||||
String str = activity.getString(mLog.getLast().mType.getMsgId());
|
||||
int msgId = mLog.getLast().mType.getMsgId();
|
||||
|
||||
Style style;
|
||||
|
||||
// Not an overall failure
|
||||
if (cancelled()) {
|
||||
color = Style.RED;
|
||||
style = Style.ERROR;
|
||||
} else if (success()) {
|
||||
if (getLog().containsWarnings()) {
|
||||
color = Style.ORANGE;
|
||||
style = Style.WARN;
|
||||
} else {
|
||||
color = Style.GREEN;
|
||||
style = Style.OK;
|
||||
}
|
||||
} else {
|
||||
color = Style.RED;
|
||||
style = Style.ERROR;
|
||||
}
|
||||
|
||||
boolean button = getLog() != null && !getLog().isEmpty();
|
||||
SuperCardToast toast = new SuperCardToast(activity,
|
||||
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD,
|
||||
Style.getStyle(color, SuperToast.Animations.POPUP));
|
||||
toast.setText(str);
|
||||
toast.setDuration(SuperToast.Duration.EXTRA_LONG);
|
||||
toast.setIndeterminate(false);
|
||||
toast.setSwipeToDismiss(true);
|
||||
// If we have a log and it's non-empty, show a View Log button
|
||||
if (button) {
|
||||
toast.setButtonIcon(R.drawable.ic_action_view_as_list,
|
||||
activity.getResources().getString(R.string.view_log));
|
||||
toast.setButtonTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setTextColor(activity.getResources().getColor(R.color.black));
|
||||
toast.setOnClickWrapper(new OnClickWrapper("supercardtoast",
|
||||
new SuperToast.OnClickListener() {
|
||||
if (getLog() == null || getLog().isEmpty()) {
|
||||
return Notify.createNotify(activity, msgId, Notify.LENGTH_LONG, style);
|
||||
}
|
||||
|
||||
return Notify.createNotify(activity, msgId, Notify.LENGTH_LONG, style,
|
||||
new ActionListener() {
|
||||
@Override
|
||||
public void onClick(View view, Parcelable token) {
|
||||
public void onAction() {
|
||||
Intent intent = new Intent(
|
||||
activity, LogDisplayActivity.class);
|
||||
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResult.this);
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
return toast;
|
||||
}, R.string.view_log);
|
||||
|
||||
}
|
||||
|
||||
|
@ -40,35 +40,6 @@ public class SingletonResult extends OperationResult {
|
||||
mLog.add(reason, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuperCardToast createNotify(final Activity activity) {
|
||||
|
||||
// there is exactly one error msg - use that one
|
||||
String str = activity.getString(mLog.iterator().next().mType.getMsgId());
|
||||
int color;
|
||||
|
||||
// Determine color by result type
|
||||
if (cancelled()) {
|
||||
color = Style.RED;
|
||||
} else if (success()) {
|
||||
if (getLog().containsWarnings()) {
|
||||
color = Style.ORANGE;
|
||||
} else {
|
||||
color = Style.GREEN;
|
||||
}
|
||||
} else {
|
||||
color = Style.RED;
|
||||
}
|
||||
|
||||
SuperCardToast toast = new SuperCardToast(activity, SuperToast.Type.STANDARD,
|
||||
Style.getStyle(color, SuperToast.Animations.POPUP));
|
||||
toast.setText(str);
|
||||
toast.setDuration(SuperToast.Duration.EXTRA_LONG);
|
||||
toast.setIndeterminate(false);
|
||||
toast.setSwipeToDismiss(true);
|
||||
return toast;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
|
@ -19,6 +19,7 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
@ -57,7 +58,12 @@ import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.ConsolidateResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.DeleteResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
import org.sufficientlysecure.keychain.util.ExportHelper;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
@ -68,7 +74,9 @@ import org.sufficientlysecure.keychain.ui.widget.ListAwareSwipeRefreshLayout;
|
||||
import org.sufficientlysecure.keychain.ui.util.Highlighter;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -83,6 +91,8 @@ public class KeyListFragment extends LoaderFragment
|
||||
implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener,
|
||||
LoaderManager.LoaderCallbacks<Cursor> {
|
||||
|
||||
ExportHelper mExportHelper;
|
||||
|
||||
private KeyListAdapter mAdapter;
|
||||
private StickyListHeadersListView mStickyList;
|
||||
private ListAwareSwipeRefreshLayout mSwipeRefreshLayout;
|
||||
@ -95,6 +105,14 @@ public class KeyListFragment extends LoaderFragment
|
||||
private String mQuery;
|
||||
private SearchView mSearchView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mExportHelper = new ExportHelper(getActivity());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Load custom layout with StickyListView from library
|
||||
*/
|
||||
@ -438,6 +456,15 @@ public class KeyListFragment extends LoaderFragment
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.key_list, menu);
|
||||
|
||||
if (Constants.DEBUG) {
|
||||
menu.findItem(R.id.menu_key_list_debug_cons).setVisible(true);
|
||||
menu.findItem(R.id.menu_key_list_debug_read).setVisible(true);
|
||||
menu.findItem(R.id.menu_key_list_debug_write).setVisible(true);
|
||||
menu.findItem(R.id.menu_key_list_debug_first_time).setVisible(true);
|
||||
}
|
||||
|
||||
// Get the searchview
|
||||
MenuItem searchItem = menu.findItem(R.id.menu_key_list_search);
|
||||
|
||||
@ -473,6 +500,71 @@ public class KeyListFragment extends LoaderFragment
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_key_list_add:
|
||||
Intent scanQrCode = new Intent(getActivity(), QrCodeScanActivity.class);
|
||||
scanQrCode.setAction(QrCodeScanActivity.ACTION_SCAN_WITH_RESULT);
|
||||
startActivityForResult(scanQrCode, 0);
|
||||
return true;
|
||||
|
||||
case R.id.menu_key_list_search_cloud:
|
||||
searchCloud();
|
||||
return true;
|
||||
|
||||
case R.id.menu_key_list_create:
|
||||
createKey();
|
||||
return true;
|
||||
|
||||
case R.id.menu_key_list_import_existing_key:
|
||||
Intent intentImportExisting = new Intent(getActivity(), ImportKeysActivity.class);
|
||||
intentImportExisting.setAction(ImportKeysActivity.ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN);
|
||||
startActivityForResult(intentImportExisting, 0);
|
||||
return true;
|
||||
|
||||
case R.id.menu_key_list_export:
|
||||
mExportHelper.showExportKeysDialog(null, Constants.Path.APP_DIR_FILE, true);
|
||||
return true;
|
||||
|
||||
case R.id.menu_key_list_debug_cons:
|
||||
consolidate();
|
||||
return true;
|
||||
|
||||
case R.id.menu_key_list_debug_read:
|
||||
try {
|
||||
KeychainDatabase.debugBackup(getActivity(), true);
|
||||
Notify.showNotify(getActivity(), "Restored debug_backup.db", Notify.Style.INFO);
|
||||
getActivity().getContentResolver().notifyChange(KeychainContract.KeyRings.CONTENT_URI, null);
|
||||
} catch (IOException e) {
|
||||
Log.e(Constants.TAG, "IO Error", e);
|
||||
Notify.showNotify(getActivity(), "IO Error " + e.getMessage(), Notify.Style.ERROR);
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.menu_key_list_debug_write:
|
||||
try {
|
||||
KeychainDatabase.debugBackup(getActivity(), false);
|
||||
Notify.showNotify(getActivity(), "Backup to debug_backup.db completed", Notify.Style.INFO);
|
||||
} catch (IOException e) {
|
||||
Log.e(Constants.TAG, "IO Error", e);
|
||||
Notify.showNotify(getActivity(), "IO Error: " + e.getMessage(), Notify.Style.ERROR);
|
||||
}
|
||||
return true;
|
||||
|
||||
case R.id.menu_key_list_debug_first_time:
|
||||
Preferences prefs = Preferences.getPreferences(getActivity());
|
||||
prefs.setFirstTime(true);
|
||||
Intent intent = new Intent(getActivity(), FirstTimeActivity.class);
|
||||
startActivity(intent);
|
||||
getActivity().finish();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String s) {
|
||||
return true;
|
||||
@ -495,6 +587,77 @@ public class KeyListFragment extends LoaderFragment
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void searchCloud() {
|
||||
Intent importIntent = new Intent(getActivity(), ImportKeysActivity.class);
|
||||
importIntent.putExtra(ImportKeysActivity.EXTRA_QUERY, (String) null); // hack to show only cloud tab
|
||||
startActivity(importIntent);
|
||||
}
|
||||
|
||||
private void createKey() {
|
||||
Intent intent = new Intent(getActivity(), CreateKeyActivity.class);
|
||||
startActivityForResult(intent, 0);
|
||||
}
|
||||
|
||||
private void consolidate() {
|
||||
// Message is received after importing is done in KeychainIntentService
|
||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
||||
getActivity(),
|
||||
getString(R.string.progress_importing),
|
||||
ProgressDialog.STYLE_HORIZONTAL) {
|
||||
public void handleMessage(Message message) {
|
||||
// handle messages by standard KeychainIntentServiceHandler first
|
||||
super.handleMessage(message);
|
||||
|
||||
if (message.arg1 == KeychainIntentServiceHandler.MESSAGE_OKAY) {
|
||||
// get returned data bundle
|
||||
Bundle returnData = message.getData();
|
||||
if (returnData == null) {
|
||||
return;
|
||||
}
|
||||
final ConsolidateResult result =
|
||||
returnData.getParcelable(OperationResult.EXTRA_RESULT);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
result.createNotify(getActivity()).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Send all information needed to service to import key in other thread
|
||||
Intent intent = new Intent(getActivity(), KeychainIntentService.class);
|
||||
|
||||
intent.setAction(KeychainIntentService.ACTION_CONSOLIDATE);
|
||||
|
||||
// fill values for this action
|
||||
Bundle data = new Bundle();
|
||||
|
||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||
|
||||
// Create a new Messenger for the communication back
|
||||
Messenger messenger = new Messenger(saveHandler);
|
||||
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
||||
|
||||
// show progress dialog
|
||||
saveHandler.showProgressDialog(getActivity());
|
||||
|
||||
// start service with intent
|
||||
getActivity().startService(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// if a result has been returned, display a notify
|
||||
if (data != null && data.hasExtra(OperationResult.EXTRA_RESULT)) {
|
||||
OperationResult result = data.getParcelableExtra(OperationResult.EXTRA_RESULT);
|
||||
result.createNotify(getActivity()).show();
|
||||
} else {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements StickyListHeadersAdapter from library
|
||||
*/
|
||||
|
@ -19,18 +19,23 @@ package org.sufficientlysecure.keychain.ui.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.github.johnpersano.supertoasts.SuperCardToast;
|
||||
import com.github.johnpersano.supertoasts.SuperToast;
|
||||
import com.nispok.snackbar.Snackbar;
|
||||
import com.nispok.snackbar.Snackbar.SnackbarDuration;
|
||||
import com.nispok.snackbar.SnackbarManager;
|
||||
import com.nispok.snackbar.listeners.ActionClickListener;
|
||||
|
||||
/**
|
||||
* @author danielhass
|
||||
* Notify wrapper which allows a more easy use of different notification libraries
|
||||
*/
|
||||
public class Notify {
|
||||
|
||||
public static enum Style {OK, WARN, INFO, ERROR}
|
||||
|
||||
public static final int LENGTH_INDEFINITE = 0;
|
||||
public static final int LENGTH_LONG = 3500;
|
||||
|
||||
/**
|
||||
* Shows a simple in-layout notification with the CharSequence given as parameter
|
||||
* @param activity
|
||||
@ -39,21 +44,94 @@ public class Notify {
|
||||
*/
|
||||
public static void showNotify(Activity activity, CharSequence text, Style style) {
|
||||
|
||||
SuperCardToast st = new SuperCardToast(activity);
|
||||
st.setText(text);
|
||||
st.setDuration(SuperToast.Duration.MEDIUM);
|
||||
switch (style){
|
||||
Snackbar bar = Snackbar.with(activity)
|
||||
.text(text)
|
||||
.duration(SnackbarDuration.LENGTH_LONG);
|
||||
|
||||
switch (style) {
|
||||
case OK:
|
||||
st.setBackground(SuperToast.Background.GREEN);
|
||||
break;
|
||||
case WARN:
|
||||
st.setBackground(SuperToast.Background.ORANGE);
|
||||
bar.textColor(Color.YELLOW);
|
||||
break;
|
||||
case ERROR:
|
||||
st.setBackground(SuperToast.Background.RED);
|
||||
bar.textColor(Color.RED);
|
||||
break;
|
||||
}
|
||||
st.show();
|
||||
|
||||
SnackbarManager.show(bar);
|
||||
|
||||
}
|
||||
|
||||
public static Showable createNotify (Activity activity, int resId, int duration, Style style) {
|
||||
final Snackbar bar = Snackbar.with(activity)
|
||||
.text(resId);
|
||||
if (duration == LENGTH_INDEFINITE) {
|
||||
bar.duration(SnackbarDuration.LENGTH_INDEFINITE);
|
||||
} else {
|
||||
bar.duration(duration);
|
||||
}
|
||||
|
||||
switch (style) {
|
||||
case OK:
|
||||
bar.actionColor(Color.GREEN);
|
||||
break;
|
||||
case WARN:
|
||||
bar.textColor(Color.YELLOW);
|
||||
break;
|
||||
case ERROR:
|
||||
bar.textColor(Color.RED);
|
||||
break;
|
||||
}
|
||||
|
||||
return new Showable () {
|
||||
@Override
|
||||
public void show() {
|
||||
SnackbarManager.show(bar);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static Showable createNotify(Activity activity, int resId, int duration, Style style,
|
||||
final ActionListener listener, int resIdAction) {
|
||||
return createNotify(activity, activity.getString(resId), duration, style, listener, resIdAction);
|
||||
}
|
||||
|
||||
public static Showable createNotify(Activity activity, String msg, int duration, Style style,
|
||||
final ActionListener listener, int resIdAction) {
|
||||
final Snackbar bar = Snackbar.with(activity)
|
||||
.text(msg)
|
||||
.actionLabel(resIdAction)
|
||||
.actionListener(new ActionClickListener() {
|
||||
@Override
|
||||
public void onActionClicked(Snackbar snackbar) {
|
||||
listener.onAction();
|
||||
}
|
||||
});
|
||||
if (duration == LENGTH_INDEFINITE) {
|
||||
bar.duration(SnackbarDuration.LENGTH_INDEFINITE);
|
||||
} else {
|
||||
bar.duration(duration);
|
||||
}
|
||||
|
||||
switch (style) {
|
||||
case OK:
|
||||
bar.actionColor(Color.GREEN);
|
||||
break;
|
||||
case WARN:
|
||||
bar.textColor(Color.YELLOW);
|
||||
break;
|
||||
case ERROR:
|
||||
bar.textColor(Color.RED);
|
||||
break;
|
||||
}
|
||||
|
||||
return new Showable () {
|
||||
@Override
|
||||
public void show() {
|
||||
SnackbarManager.show(bar);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -67,4 +145,15 @@ public class Notify {
|
||||
public static void showNotify(Activity activity, int resId, Style style) throws Resources.NotFoundException {
|
||||
showNotify(activity, activity.getResources().getText(resId), style);
|
||||
}
|
||||
|
||||
public interface Showable {
|
||||
public void show();
|
||||
|
||||
}
|
||||
|
||||
public interface ActionListener {
|
||||
public void onAction();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -24,7 +24,7 @@ import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
@ -40,9 +40,9 @@ import java.io.File;
|
||||
public class ExportHelper {
|
||||
protected File mExportFile;
|
||||
|
||||
ActionBarActivity mActivity;
|
||||
FragmentActivity mActivity;
|
||||
|
||||
public ExportHelper(ActionBarActivity activity) {
|
||||
public ExportHelper(FragmentActivity activity) {
|
||||
super();
|
||||
this.mActivity = activity;
|
||||
}
|
||||
|
@ -399,7 +399,7 @@
|
||||
<string name="import_qr_code_text">"Place your camera over the QR Code!"</string>
|
||||
|
||||
<!-- Generic result toast -->
|
||||
<string name="view_log">"View Log"</string>
|
||||
<string name="view_log">"Details"</string>
|
||||
<string name="with_warnings">", with warnings"</string>
|
||||
<string name="with_cancelled">", until cancelled"</string>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user