Merge remote-tracking branch 'origin/t/snackbar' into development

Conflicts:
	OpenKeychain/build.gradle
This commit is contained in:
Dominik Schürmann 2015-01-29 09:55:09 +01:00
commit 5564f65a69
11 changed files with 370 additions and 214 deletions

View File

@ -27,6 +27,7 @@ dependencies {
compile 'com.google.zxing:core:3.0.1' compile 'com.google.zxing:core:3.0.1'
compile 'com.jpardogo.materialtabstrip:library:1.0.8' compile 'com.jpardogo.materialtabstrip:library:1.0.8'
compile 'it.neokree:MaterialNavigationDrawer:1.3' compile 'it.neokree:MaterialNavigationDrawer:1.3'
compile 'com.nispok:snackbar:2.7.4'
} }
android { android {

View File

@ -75,7 +75,7 @@
android:theme="@style/KeychainTheme" android:theme="@style/KeychainTheme"
android:label="@string/app_name"> android:label="@string/app_name">
<activity <activity
android:name=".ui.KeyListActivity" android:name=".ui.MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard" android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTop"> android:launchMode="singleTop">
@ -85,6 +85,11 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".ui.KeyListActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
android:label="@string/app_name"
android:windowSoftInputMode="stateAlwaysHidden" />
<activity <activity
android:name=".ui.FirstTimeActivity" android:name=".ui.FirstTimeActivity"
android:configChanges="orientation|screenSize|keyboardHidden|keyboard" android:configChanges="orientation|screenSize|keyboardHidden|keyboard"

View File

@ -21,18 +21,14 @@ package org.sufficientlysecure.keychain.operations.results;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Parcel; 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.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity; import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment; 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 { 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(); int resultType = getResult();
String str; String str;
int duration, color; int duration;
Style style;
// Not an overall failure // Not an overall failure
if ((resultType & OperationResult.RESULT_ERROR) == 0) { if ((resultType & OperationResult.RESULT_ERROR) == 0) {
String withWarnings; String withWarnings;
duration = Duration.EXTRA_LONG; duration = Notify.LENGTH_LONG;
color = Style.GREEN; style = Style.OK;
withWarnings = ""; withWarnings = "";
// Any warnings? // Any warnings?
if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) {
duration = 0; duration = 0;
color = Style.ORANGE; style = Style.WARN;
withWarnings += activity.getString(R.string.with_warnings); withWarnings += activity.getString(R.string.with_warnings);
} }
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
duration = 0; duration = 0;
color = Style.ORANGE; style = Style.WARN;
withWarnings += activity.getString(R.string.with_cancelled); withWarnings += activity.getString(R.string.with_cancelled);
} }
@ -111,46 +108,27 @@ public class CertifyResult extends OperationResult {
if (mCertifyError > 0) { if (mCertifyError > 0) {
// definitely switch to warning-style message in this case! // definitely switch to warning-style message in this case!
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
str += " " + activity.getResources().getQuantityString( str += " " + activity.getResources().getQuantityString(
R.plurals.certify_keys_with_errors, mCertifyError, mCertifyError); R.plurals.certify_keys_with_errors, mCertifyError, mCertifyError);
} }
} else { } else {
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
str = activity.getResources().getQuantityString(R.plurals.certify_error, str = activity.getResources().getQuantityString(R.plurals.certify_error,
mCertifyError, mCertifyError); mCertifyError, mCertifyError);
} }
boolean button = getLog() != null && !getLog().isEmpty(); return Notify.createNotify(activity, str, duration, style, new ActionListener() {
SuperCardToast toast = new SuperCardToast(activity, @Override
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, public void onAction() {
Style.getStyle(color, SuperToast.Animations.POPUP)); Intent intent = new Intent(
toast.setText(str); activity, LogDisplayActivity.class);
toast.setDuration(duration); intent.putExtra(LogDisplayFragment.EXTRA_RESULT, CertifyResult.this);
toast.setIndeterminate(duration == 0); activity.startActivity(intent);
toast.setSwipeToDismiss(true); }
// If we have a log and it's non-empty, show a View Log button }, R.string.view_log);
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() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, CertifyResult.this);
activity.startActivity(intent);
}
}
));
}
return toast;
} }

View File

@ -24,15 +24,13 @@ import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.view.View; 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.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity; import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment; 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 { 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(); int resultType = getResult();
String str; String str;
int duration, color; int duration;
Style style;
// Not an overall failure // Not an overall failure
if ((resultType & OperationResult.RESULT_ERROR) == 0) { if ((resultType & OperationResult.RESULT_ERROR) == 0) {
String untilCancelled; String untilCancelled;
duration = Duration.EXTRA_LONG; duration = Notify.LENGTH_LONG;
color = Style.GREEN; style = Style.OK;
untilCancelled = ""; untilCancelled = "";
// Any warnings? // Any warnings?
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
duration = 0; duration = 0;
color = Style.ORANGE; style = Style.WARN;
untilCancelled += activity.getString(R.string.with_cancelled); untilCancelled += activity.getString(R.string.with_cancelled);
} }
// New and updated keys // New and updated keys
if (mOk > 0 && mFail > 0) { if (mOk > 0 && mFail > 0) {
color = Style.ORANGE; style = Style.WARN;
duration = 0; duration = 0;
str = activity.getResources().getQuantityString( str = activity.getResources().getQuantityString(
R.plurals.delete_ok_but_fail_1, mOk, mOk); 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); str = activity.getString(R.string.delete_cancelled);
} else { } else {
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
str = "internal error"; str = "internal error";
} }
} else { } else {
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
if (mFail == 0) { if (mFail == 0) {
str = activity.getString(R.string.delete_nothing); str = activity.getString(R.string.delete_nothing);
} else { } else {
@ -119,34 +118,15 @@ public class DeleteResult extends OperationResult {
} }
} }
boolean button = getLog() != null && !getLog().isEmpty(); return Notify.createNotify(activity, str, duration, style, new ActionListener() {
SuperCardToast toast = new SuperCardToast(activity, @Override
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, public void onAction() {
Style.getStyle(color, SuperToast.Animations.POPUP)); Intent intent = new Intent(
toast.setText(str); activity, LogDisplayActivity.class);
toast.setDuration(duration); intent.putExtra(LogDisplayFragment.EXTRA_RESULT, DeleteResult.this);
toast.setIndeterminate(duration == 0); activity.startActivity(intent);
toast.setSwipeToDismiss(true); }
// If we have a log and it's non-empty, show a View Log button }, R.string.view_log);
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() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, DeleteResult.this);
activity.startActivity(intent);
}
}
));
}
return toast;
} }

View File

@ -21,18 +21,14 @@ package org.sufficientlysecure.keychain.operations.results;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Parcel; 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.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity; import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment; 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 { 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(); int resultType = getResult();
String str; String str;
int duration, color; int duration;
Style style;
// Not an overall failure // Not an overall failure
if ((resultType & OperationResult.RESULT_ERROR) == 0) { if ((resultType & OperationResult.RESULT_ERROR) == 0) {
String withWarnings; String withWarnings;
duration = Duration.EXTRA_LONG; duration = Notify.LENGTH_LONG;
color = Style.GREEN; style = Style.OK;
withWarnings = ""; withWarnings = "";
// Any warnings? // Any warnings?
if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) {
duration = 0; duration = 0;
color = Style.ORANGE; style = Style.WARN;
withWarnings += activity.getString(R.string.with_warnings); withWarnings += activity.getString(R.string.with_warnings);
} }
if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) {
duration = 0; duration = 0;
color = Style.ORANGE; style = Style.WARN;
withWarnings += activity.getString(R.string.with_cancelled); withWarnings += activity.getString(R.string.with_cancelled);
} }
@ -159,20 +156,20 @@ public class ImportKeyResult extends OperationResult {
R.plurals.import_keys_added, mNewKeys, mNewKeys, withWarnings); R.plurals.import_keys_added, mNewKeys, mNewKeys, withWarnings);
} else { } else {
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
str = "internal error"; str = "internal error";
} }
if (isOkWithErrors()) { if (isOkWithErrors()) {
// definitely switch to warning-style message in this case! // definitely switch to warning-style message in this case!
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
str += " " + activity.getResources().getQuantityString( str += " " + activity.getResources().getQuantityString(
R.plurals.import_keys_with_errors, mBadKeys, mBadKeys); R.plurals.import_keys_with_errors, mBadKeys, mBadKeys);
} }
} else { } else {
duration = 0; duration = 0;
color = Style.RED; style = Style.ERROR;
if (isFailNothing()) { if (isFailNothing()) {
str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0 str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0
? R.string.import_error_nothing_cancelled ? R.string.import_error_nothing_cancelled
@ -182,34 +179,15 @@ public class ImportKeyResult extends OperationResult {
} }
} }
boolean button = getLog() != null && !getLog().isEmpty(); return Notify.createNotify(activity, str, duration, style, new ActionListener() {
SuperCardToast toast = new SuperCardToast(activity, @Override
button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, public void onAction() {
Style.getStyle(color, SuperToast.Animations.POPUP)); Intent intent = new Intent(
toast.setText(str); activity, LogDisplayActivity.class);
toast.setDuration(duration); intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this);
toast.setIndeterminate(duration == 0); activity.startActivity(intent);
toast.setSwipeToDismiss(true); }
// If we have a log and it's non-empty, show a View Log button }, R.string.view_log);
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() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, ImportKeyResult.this);
activity.startActivity(intent);
}
}
));
}
return toast;
} }

View File

@ -20,19 +20,24 @@ package org.sufficientlysecure.keychain.operations.results;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.view.View; import android.view.View;
import com.github.johnpersano.supertoasts.SuperCardToast; import com.nispok.snackbar.Snackbar;
import com.github.johnpersano.supertoasts.SuperToast; import com.nispok.snackbar.Snackbar.SnackbarDuration;
import com.github.johnpersano.supertoasts.util.OnClickWrapper; import com.nispok.snackbar.SnackbarManager;
import com.github.johnpersano.supertoasts.util.Style; import com.nispok.snackbar.listeners.ActionClickListener;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.ui.LogDisplayActivity; import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
import org.sufficientlysecure.keychain.ui.LogDisplayFragment; 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.IterableIterator;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@ -195,58 +200,44 @@ public abstract class OperationResult implements Parcelable {
} }
public SuperCardToast createNotify(final Activity activity) { public Showable createNotify(final Activity activity) {
int color;
Log.d(Constants.TAG, "mLog.getLast()"+mLog.getLast()); 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"+mLog.getLast().mType);
Log.d(Constants.TAG, "mLog.getLast().mType.getMsgId()"+mLog.getLast().mType.getMsgId()); Log.d(Constants.TAG, "mLog.getLast().mType.getMsgId()"+mLog.getLast().mType.getMsgId());
// Take the last message as string // 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 // Not an overall failure
if (cancelled()) { if (cancelled()) {
color = Style.RED; style = Style.ERROR;
} else if (success()) { } else if (success()) {
if (getLog().containsWarnings()) { if (getLog().containsWarnings()) {
color = Style.ORANGE; style = Style.WARN;
} else { } else {
color = Style.GREEN; style = Style.OK;
} }
} else { } else {
color = Style.RED; style = Style.ERROR;
} }
boolean button = getLog() != null && !getLog().isEmpty(); if (getLog() == null || getLog().isEmpty()) {
SuperCardToast toast = new SuperCardToast(activity, return Notify.createNotify(activity, msgId, Notify.LENGTH_LONG, style);
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() {
@Override
public void onClick(View view, Parcelable token) {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResult.this);
activity.startActivity(intent);
}
}
));
} }
return toast; return Notify.createNotify(activity, msgId, Notify.LENGTH_LONG, style,
new ActionListener() {
@Override
public void onAction() {
Intent intent = new Intent(
activity, LogDisplayActivity.class);
intent.putExtra(LogDisplayFragment.EXTRA_RESULT, OperationResult.this);
activity.startActivity(intent);
}
}, R.string.view_log);
} }

View File

@ -40,35 +40,6 @@ public class SingletonResult extends OperationResult {
mLog.add(reason, 0); 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 @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags); super.writeToParcel(dest, flags);

View File

@ -19,6 +19,7 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.database.Cursor; import android.database.Cursor;
@ -57,7 +58,12 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; 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.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.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.util.ExportHelper; import org.sufficientlysecure.keychain.util.ExportHelper;
import org.sufficientlysecure.keychain.pgp.KeyRing; 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.ui.util.Highlighter;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify;
import org.sufficientlysecure.keychain.util.Preferences;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
@ -83,6 +91,8 @@ public class KeyListFragment extends LoaderFragment
implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener, implements SearchView.OnQueryTextListener, AdapterView.OnItemClickListener,
LoaderManager.LoaderCallbacks<Cursor> { LoaderManager.LoaderCallbacks<Cursor> {
ExportHelper mExportHelper;
private KeyListAdapter mAdapter; private KeyListAdapter mAdapter;
private StickyListHeadersListView mStickyList; private StickyListHeadersListView mStickyList;
private ListAwareSwipeRefreshLayout mSwipeRefreshLayout; private ListAwareSwipeRefreshLayout mSwipeRefreshLayout;
@ -95,6 +105,14 @@ public class KeyListFragment extends LoaderFragment
private String mQuery; private String mQuery;
private SearchView mSearchView; private SearchView mSearchView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mExportHelper = new ExportHelper(getActivity());
}
/** /**
* Load custom layout with StickyListView from library * Load custom layout with StickyListView from library
*/ */
@ -438,6 +456,15 @@ public class KeyListFragment extends LoaderFragment
@Override @Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) { 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 // Get the searchview
MenuItem searchItem = menu.findItem(R.id.menu_key_list_search); MenuItem searchItem = menu.findItem(R.id.menu_key_list_search);
@ -473,6 +500,71 @@ public class KeyListFragment extends LoaderFragment
super.onCreateOptionsMenu(menu, inflater); 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 @Override
public boolean onQueryTextSubmit(String s) { public boolean onQueryTextSubmit(String s) {
return true; return true;
@ -495,6 +587,77 @@ public class KeyListFragment extends LoaderFragment
return true; 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 * Implements StickyListHeadersAdapter from library
*/ */

View File

@ -19,18 +19,23 @@ package org.sufficientlysecure.keychain.ui.util;
import android.app.Activity; import android.app.Activity;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Color;
import com.github.johnpersano.supertoasts.SuperCardToast; import com.nispok.snackbar.Snackbar;
import com.github.johnpersano.supertoasts.SuperToast; 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 * Notify wrapper which allows a more easy use of different notification libraries
*/ */
public class Notify { public class Notify {
public static enum Style {OK, WARN, INFO, ERROR} 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 * Shows a simple in-layout notification with the CharSequence given as parameter
* @param activity * @param activity
@ -39,21 +44,94 @@ public class Notify {
*/ */
public static void showNotify(Activity activity, CharSequence text, Style style) { public static void showNotify(Activity activity, CharSequence text, Style style) {
SuperCardToast st = new SuperCardToast(activity); Snackbar bar = Snackbar.with(activity)
st.setText(text); .text(text)
st.setDuration(SuperToast.Duration.MEDIUM); .duration(SnackbarDuration.LENGTH_LONG);
switch (style){
switch (style) {
case OK: case OK:
st.setBackground(SuperToast.Background.GREEN);
break; break;
case WARN: case WARN:
st.setBackground(SuperToast.Background.ORANGE); bar.textColor(Color.YELLOW);
break; break;
case ERROR: case ERROR:
st.setBackground(SuperToast.Background.RED); bar.textColor(Color.RED);
break; 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 { public static void showNotify(Activity activity, int resId, Style style) throws Resources.NotFoundException {
showNotify(activity, activity.getResources().getText(resId), style); showNotify(activity, activity.getResources().getText(resId), style);
} }
public interface Showable {
public void show();
}
public interface ActionListener {
public void onAction();
}
} }

View File

@ -24,7 +24,7 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.Messenger; 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.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
@ -40,9 +40,9 @@ import java.io.File;
public class ExportHelper { public class ExportHelper {
protected File mExportFile; protected File mExportFile;
ActionBarActivity mActivity; FragmentActivity mActivity;
public ExportHelper(ActionBarActivity activity) { public ExportHelper(FragmentActivity activity) {
super(); super();
this.mActivity = activity; this.mActivity = activity;
} }

View File

@ -399,7 +399,7 @@
<string name="import_qr_code_text">"Place your camera over the QR Code!"</string> <string name="import_qr_code_text">"Place your camera over the QR Code!"</string>
<!-- Generic result toast --> <!-- 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_warnings">", with warnings"</string>
<string name="with_cancelled">", until cancelled"</string> <string name="with_cancelled">", until cancelled"</string>