import-log: work on log fragment ui

This commit is contained in:
Vincent Breitmoser 2014-06-10 20:06:28 +02:00
parent f38556cab1
commit 3895c10a58
6 changed files with 113 additions and 21 deletions

View File

@ -553,8 +553,8 @@ public class ProviderHelper {
mIndent -= 1; mIndent -= 1;
} }
log(LogLevel.OK, LogType.MSG_IP_SUCCESS);
mIndent -= 1; mIndent -= 1;
log(LogLevel.OK, LogType.MSG_IP_SUCCESS);
return new SaveKeyringResult(result, mLog); return new SaveKeyringResult(result, mLog);
} }

View File

@ -173,12 +173,12 @@ public class OperationResultParcel implements Parcelable {
/** Enumeration of possible log levels. */ /** Enumeration of possible log levels. */
public static enum LogLevel { 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, DEBUG,
INFO, INFO,
WARN, 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 @Override

View File

@ -1,7 +1,11 @@
package org.sufficientlysecure.keychain.ui; package org.sufficientlysecure.keychain.ui;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;

View File

@ -5,22 +5,40 @@ import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.ListFragment; import android.support.v4.app.ListFragment;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.MotionEventCompat;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.service.OperationResultParcel; import org.sufficientlysecure.keychain.service.OperationResultParcel;
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogEntryParcel; 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.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; LogAdapter mAdapter;
LogLevel mLevel = LogLevel.DEBUG;
OperationResultParcel mResult;
GestureDetector mDetector;
public static final String EXTRA_RESULT = "log"; public static final String EXTRA_RESULT = "log";
@ -34,15 +52,68 @@ public class LogDisplayFragment extends ListFragment {
return; return;
} }
OperationResultParcel result = intent.<OperationResultParcel>getParcelableExtra(EXTRA_RESULT); mResult = intent.<OperationResultParcel>getParcelableExtra(EXTRA_RESULT);
if (result == null) { if (mResult == null) {
getActivity().finish(); getActivity().finish();
return; return;
} }
mAdapter = new LogAdapter(getActivity(), result.getLog()); mAdapter = new LogAdapter(getActivity(), mResult.getLog(), LogLevel.DEBUG);
mAdapters.put(LogLevel.DEBUG, mAdapter);
setListAdapter(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> { private class LogAdapter extends ArrayAdapter<LogEntryParcel> {
@ -50,12 +121,18 @@ public class LogDisplayFragment extends ListFragment {
private LayoutInflater mInflater; private LayoutInflater mInflater;
private int dipFactor; private int dipFactor;
public LogAdapter(Context context, ArrayList<LogEntryParcel> log) { public LogAdapter(Context context, ArrayList<LogEntryParcel> log, LogLevel level) {
super(context, R.layout.log_display_item, log); super(context, R.layout.log_display_item);
mInflater = LayoutInflater.from(getContext()); mInflater = LayoutInflater.from(getContext());
dipFactor = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 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 @Override
@ -69,15 +146,18 @@ public class LogDisplayFragment extends ListFragment {
} else { } else {
text = (TextView) convertView.getTag(); 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.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) { switch (entry.mLevel) {
case OK: text.setTextColor(Color.GREEN); break; case DEBUG: img.setBackgroundColor(Color.GRAY); break;
case DEBUG: text.setTextColor(Color.GRAY); break; case INFO: img.setBackgroundColor(Color.BLACK); break;
case INFO: text.setTextColor(Color.BLACK); break; case WARN: img.setBackgroundColor(Color.YELLOW); break;
case WARN: text.setTextColor(Color.YELLOW); break; case ERROR: img.setBackgroundColor(Color.RED); break;
case ERROR: text.setTextColor(Color.RED); break; case START: img.setBackgroundColor(Color.GREEN); break;
case OK: img.setBackgroundColor(Color.GREEN); break;
} }
return convertView; return convertView;

View File

@ -4,11 +4,19 @@
android:orientation="horizontal" android:layout_width="match_parent" android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="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 <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Log Entry Text" android:text="Log Entry Text"
android:id="@+id/log_text" android:id="@+id/log_text"
android:layout_marginTop="4dp" android:layout_marginTop="4dp"
android:layout_marginBottom="4dp" /> android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp" />
</LinearLayout> </LinearLayout>

View File

@ -530,7 +530,7 @@
<string name="msg_ip_subkey_flags_xxs">Subkey flags: sign</string> <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_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_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_reinsert_secret">Re-inserting secret key</string>
<string name="msg_ip_trust_retrieve">Retrieving trusted keys</string> <string name="msg_ip_trust_retrieve">Retrieving trusted keys</string>
<string name="msg_ip_trust_using">Using %s 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_nonexistent">Subkey %s unavailable in public key</string>
<string name="msg_is_subkey_ok">Marked %s as available</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_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 --> <!-- Keyring Canonicalization log entries -->
<string name="msg_kc">Canonicalizing keyring %s</string> <string name="msg_kc">Canonicalizing keyring %s</string>