mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
import-log: work on log fragment ui
This commit is contained in:
parent
f38556cab1
commit
3895c10a58
@ -553,8 +553,8 @@ public class ProviderHelper {
|
||||
mIndent -= 1;
|
||||
}
|
||||
|
||||
log(LogLevel.OK, LogType.MSG_IP_SUCCESS);
|
||||
mIndent -= 1;
|
||||
log(LogLevel.OK, LogType.MSG_IP_SUCCESS);
|
||||
return new SaveKeyringResult(result, mLog);
|
||||
|
||||
}
|
||||
|
@ -173,12 +173,12 @@ public class OperationResultParcel implements Parcelable {
|
||||
|
||||
/** Enumeration of possible log levels. */
|
||||
public static enum LogLevel {
|
||||
START, // should occur once at the start of each independent operation
|
||||
OK, // should occur once at the end of a successful operation
|
||||
ERROR, // should occur once at the end of a failed operation
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR, // should occur once at the end of a failed operation
|
||||
START, // should occur once at the start of each independent operation
|
||||
OK, // should occur once at the end of a successful operation
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,11 @@
|
||||
package org.sufficientlysecure.keychain.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.view.GestureDetectorCompat;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.GestureDetector.SimpleOnGestureListener;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
|
||||
|
@ -5,22 +5,40 @@ import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.support.v4.view.GestureDetectorCompat;
|
||||
import android.support.v4.view.MotionEventCompat;
|
||||
import android.util.TypedValue;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.GestureDetector.SimpleOnGestureListener;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.service.OperationResultParcel;
|
||||
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogEntryParcel;
|
||||
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class LogDisplayFragment extends ListFragment {
|
||||
public class LogDisplayFragment extends ListFragment implements OnTouchListener {
|
||||
|
||||
HashMap<LogLevel,LogAdapter> mAdapters = new HashMap<LogLevel, LogAdapter>();
|
||||
LogAdapter mAdapter;
|
||||
LogLevel mLevel = LogLevel.DEBUG;
|
||||
|
||||
OperationResultParcel mResult;
|
||||
|
||||
GestureDetector mDetector;
|
||||
|
||||
public static final String EXTRA_RESULT = "log";
|
||||
|
||||
@ -34,15 +52,68 @@ public class LogDisplayFragment extends ListFragment {
|
||||
return;
|
||||
}
|
||||
|
||||
OperationResultParcel result = intent.<OperationResultParcel>getParcelableExtra(EXTRA_RESULT);
|
||||
if (result == null) {
|
||||
mResult = intent.<OperationResultParcel>getParcelableExtra(EXTRA_RESULT);
|
||||
if (mResult == null) {
|
||||
getActivity().finish();
|
||||
return;
|
||||
}
|
||||
|
||||
mAdapter = new LogAdapter(getActivity(), result.getLog());
|
||||
mAdapter = new LogAdapter(getActivity(), mResult.getLog(), LogLevel.DEBUG);
|
||||
mAdapters.put(LogLevel.DEBUG, mAdapter);
|
||||
setListAdapter(mAdapter);
|
||||
|
||||
mDetector = new GestureDetector(getActivity(), new SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onFling(MotionEvent e1, MotionEvent e2, float vx, float vy) {
|
||||
Log.d(Constants.TAG, "x: " + vx + ", y: " + vy);
|
||||
if (vx < -2000) {
|
||||
decreaseLogLevel();
|
||||
} else if (vx > 2000) {
|
||||
increaseLogLevel();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void decreaseLogLevel() {
|
||||
switch (mLevel) {
|
||||
case DEBUG: mLevel = LogLevel.INFO; break;
|
||||
case INFO: mLevel = LogLevel.WARN; break;
|
||||
}
|
||||
refreshLevel();
|
||||
}
|
||||
|
||||
public void increaseLogLevel() {
|
||||
switch (mLevel) {
|
||||
case INFO: mLevel = LogLevel.DEBUG; break;
|
||||
case WARN: mLevel = LogLevel.INFO; break;
|
||||
}
|
||||
refreshLevel();
|
||||
}
|
||||
|
||||
private void refreshLevel() {
|
||||
/* TODO not sure if this is a good idea
|
||||
if (!mAdapters.containsKey(mLevel)) {
|
||||
mAdapters.put(mLevel, new LogAdapter(getActivity(), mResult.getLog(), mLevel));
|
||||
}
|
||||
mAdapter = mAdapters.get(mLevel);
|
||||
setListAdapter(mAdapter);
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
getListView().setDividerHeight(0);
|
||||
getListView().setOnTouchListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
mDetector.onTouchEvent(event);
|
||||
return false;
|
||||
}
|
||||
|
||||
private class LogAdapter extends ArrayAdapter<LogEntryParcel> {
|
||||
@ -50,12 +121,18 @@ public class LogDisplayFragment extends ListFragment {
|
||||
private LayoutInflater mInflater;
|
||||
private int dipFactor;
|
||||
|
||||
public LogAdapter(Context context, ArrayList<LogEntryParcel> log) {
|
||||
super(context, R.layout.log_display_item, log);
|
||||
public LogAdapter(Context context, ArrayList<LogEntryParcel> log, LogLevel level) {
|
||||
super(context, R.layout.log_display_item);
|
||||
mInflater = LayoutInflater.from(getContext());
|
||||
dipFactor = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
|
||||
(float) 10, getResources().getDisplayMetrics());
|
||||
|
||||
(float) 8, getResources().getDisplayMetrics());
|
||||
// we can't use addAll for a LogLevel.DEBUG shortcut here, unfortunately :(
|
||||
for (LogEntryParcel e : log) {
|
||||
if (e.mLevel.ordinal() >= level.ordinal()) {
|
||||
add(e);
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,15 +146,18 @@ public class LogDisplayFragment extends ListFragment {
|
||||
} else {
|
||||
text = (TextView) convertView.getTag();
|
||||
}
|
||||
ImageView img = (ImageView) convertView.findViewById(R.id.log_img);
|
||||
|
||||
text.setPadding(entry.mIndent*dipFactor, 0, 0, 0);
|
||||
text.setText(getResources().getString(entry.mType.getMsgId(), (Object[]) entry.mParameters));
|
||||
text.setTextColor(entry.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK);
|
||||
convertView.setPadding((entry.mIndent) * dipFactor, 0, 0, 0);
|
||||
switch (entry.mLevel) {
|
||||
case OK: text.setTextColor(Color.GREEN); break;
|
||||
case DEBUG: text.setTextColor(Color.GRAY); break;
|
||||
case INFO: text.setTextColor(Color.BLACK); break;
|
||||
case WARN: text.setTextColor(Color.YELLOW); break;
|
||||
case ERROR: text.setTextColor(Color.RED); break;
|
||||
case DEBUG: img.setBackgroundColor(Color.GRAY); break;
|
||||
case INFO: img.setBackgroundColor(Color.BLACK); break;
|
||||
case WARN: img.setBackgroundColor(Color.YELLOW); break;
|
||||
case ERROR: img.setBackgroundColor(Color.RED); break;
|
||||
case START: img.setBackgroundColor(Color.GREEN); break;
|
||||
case OK: img.setBackgroundColor(Color.GREEN); break;
|
||||
}
|
||||
|
||||
return convertView;
|
||||
|
@ -4,11 +4,19 @@
|
||||
android:orientation="horizontal" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/log_img"
|
||||
android:minWidth="10dp"
|
||||
android:background="@color/bg_gray" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Log Entry Text"
|
||||
android:id="@+id/log_text"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="4dp" />
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginLeft="8dp" />
|
||||
</LinearLayout>
|
@ -530,7 +530,7 @@
|
||||
<string name="msg_ip_subkey_flags_xxs">Subkey flags: sign</string>
|
||||
<string name="msg_ip_subkey_flags_xxx">Subkey flags: none</string>
|
||||
<string name="msg_ip_subkey_future">Subkey creation date lies in the future! (%s)</string>
|
||||
<string name="msg_ip_success">Successfully inserted public keyring</string>
|
||||
<string name="msg_ip_success">Successfully imported public keyring</string>
|
||||
<string name="msg_ip_reinsert_secret">Re-inserting secret key</string>
|
||||
<string name="msg_ip_trust_retrieve">Retrieving trusted keys</string>
|
||||
<string name="msg_ip_trust_using">Using %s trusted keys</string>
|
||||
@ -556,7 +556,7 @@
|
||||
<string name="msg_is_subkey_nonexistent">Subkey %s unavailable in public key</string>
|
||||
<string name="msg_is_subkey_ok">Marked %s as available</string>
|
||||
<string name="msg_is_subkey_stripped">Marked %s as stripped</string>
|
||||
<string name="msg_is_success">Successfully inserted secret keyring</string>
|
||||
<string name="msg_is_success">Successfully imported secret keyring</string>
|
||||
|
||||
<!-- Keyring Canonicalization log entries -->
|
||||
<string name="msg_kc">Canonicalizing keyring %s</string>
|
||||
|
Loading…
Reference in New Issue
Block a user