add support for second line in log view

This commit is contained in:
Vincent Breitmoser 2014-10-05 11:10:40 +02:00
parent 7fedde2638
commit 6699917279
4 changed files with 112 additions and 33 deletions

View File

@ -121,6 +121,7 @@ public class PgpCertifyOperation {
log.add(LogType.MSG_CRT_SAVE, 2,
KeyFormattingUtils.convertKeyIdToHex(certifiedKey.getMasterKeyId()));
// store the signed key in our local cache
mProviderHelper.clearLog();
SaveKeyringResult result = mProviderHelper.savePublicKeyRing(certifiedKey);
if (result.success()) {
@ -129,6 +130,8 @@ public class PgpCertifyOperation {
log.add(LogType.MSG_CRT_WARN_SAVE_FAILED, 3);
}
log.add(result, 2);
// TODO do something with import results
}

View File

@ -133,6 +133,12 @@ public class ProviderHelper {
}
}
public void clearLog() {
if (mLog != null) {
mLog.clear();
}
}
// If we ever switch to api level 11, we can ditch this whole mess!
public static final int FIELD_TYPE_NULL = 1;
// this is called integer to stay coherent with the constants in Cursor (api level 11)

View File

@ -163,12 +163,16 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener,
}
private class ItemHolder {
final TextView mText;
final ImageView mImg, mSub;
public ItemHolder(TextView text, ImageView image, ImageView sub) {
final View mSecond;
final TextView mText, mSecondText;
final ImageView mImg, mSecondImg, mSub;
public ItemHolder(TextView text, ImageView image, ImageView sub, View second, TextView secondText, ImageView secondImg) {
mText = text;
mImg = image;
mSub = sub;
mSecond = second;
mSecondText = secondText;
mSecondImg = secondImg;
}
}
@ -181,7 +185,10 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener,
ih = new ItemHolder(
(TextView) convertView.findViewById(R.id.log_text),
(ImageView) convertView.findViewById(R.id.log_img),
(ImageView) convertView.findViewById(R.id.log_sub)
(ImageView) convertView.findViewById(R.id.log_sub),
convertView.findViewById(R.id.log_second),
(TextView) convertView.findViewById(R.id.log_second_text),
(ImageView) convertView.findViewById(R.id.log_second_img)
);
convertView.setTag(ih);
} else {
@ -191,8 +198,38 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener,
if (entry instanceof SubLogEntryParcel) {
ih.mSub.setVisibility(View.VISIBLE);
convertView.setClickable(false);
OperationResult result = ((SubLogEntryParcel) entry).getSubResult();
LogEntryParcel subEntry = result.getLog().getLast();
if (subEntry != null) {
ih.mSecond.setVisibility(View.VISIBLE);
// special case: first parameter may be a quantity
if (subEntry.mParameters != null && subEntry.mParameters.length > 0
&& subEntry.mParameters[0] instanceof Integer) {
ih.mSecondText.setText(getResources().getQuantityString(subEntry.mType.getMsgId(),
(Integer) subEntry.mParameters[0],
subEntry.mParameters));
} else {
ih.mSecondText.setText(getResources().getString(subEntry.mType.getMsgId(),
subEntry.mParameters));
}
ih.mSecondText.setTextColor(subEntry.mType.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK);
switch (subEntry.mType.mLevel) {
case DEBUG: ih.mSecondImg.setBackgroundColor(Color.GRAY); break;
case INFO: ih.mSecondImg.setBackgroundColor(Color.BLACK); break;
case WARN: ih.mSecondImg.setBackgroundColor(Color.YELLOW); break;
case ERROR: ih.mSecondImg.setBackgroundColor(Color.RED); break;
case START: ih.mSecondImg.setBackgroundColor(getResources().getColor(R.color.emphasis)); break;
case OK: ih.mSecondImg.setBackgroundColor(Color.GREEN); break;
case CANCELLED: ih.mSecondImg.setBackgroundColor(Color.RED); break;
}
} else {
ih.mSecond.setVisibility(View.GONE);
}
} else {
ih.mSub.setVisibility(View.GONE);
ih.mSecond.setVisibility(View.GONE);
convertView.setClickable(true);
}
@ -206,14 +243,14 @@ public class LogDisplayFragment extends ListFragment implements OnTouchListener,
ih.mText.setText(getResources().getString(entry.mType.getMsgId(),
entry.mParameters));
}
ih.mText.setTextColor(entry.mType.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK);
convertView.setPadding((entry.mIndent) * dipFactor, 0, 0, 0);
ih.mText.setTextColor(entry.mType.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK);
switch (entry.mType.mLevel) {
case DEBUG: ih.mImg.setBackgroundColor(Color.GRAY); break;
case INFO: ih.mImg.setBackgroundColor(Color.BLACK); break;
case WARN: ih.mImg.setBackgroundColor(Color.YELLOW); break;
case ERROR: ih.mImg.setBackgroundColor(Color.RED); break;
case START: ih.mImg.setBackgroundColor(Color.GREEN); break;
case START: ih.mImg.setBackgroundColor(getResources().getColor(R.color.emphasis)); break;
case OK: ih.mImg.setBackgroundColor(Color.GREEN); break;
case CANCELLED: ih.mImg.setBackgroundColor(Color.RED); break;
}

View File

@ -1,37 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/log_img"
android:minWidth="10dp"
android:background="@color/bg_gray" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
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_marginLeft="8dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/log_img"
android:minWidth="10dp"
android:background="@color/bg_gray" />
<ImageView
android:layout_width="wrap_content"
<TextView
android:layout_width="0dp"
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_marginLeft="8dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/log_sub"
android:src="@drawable/ic_action_view_as_list"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical"
android:layout_marginTop="4dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/log_sub"
android:minWidth="10dp"
android:background="@drawable/ic_action_view_as_list"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:gravity="center_vertical" />
android:id="@+id/log_second"
android:layout_marginLeft="8dip">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/log_second_img"
android:minWidth="10dp"
android:background="@color/bg_gray" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Log Entry Text"
android:id="@+id/log_second_text"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="8dp"
android:layout_weight="1"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>