From 7324bfcb536b4975365ab9affa0a71ef29e29b93 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Tue, 10 Jun 2014 01:53:25 +0200 Subject: [PATCH] import-log: add LogDisplay activity --- OpenKeychain/src/main/AndroidManifest.xml | 6 ++ .../keychain/ui/ImportKeysActivity.java | 8 +- .../keychain/ui/LogDisplayActivity.java | 17 ++++ .../keychain/ui/LogDisplayFragment.java | 86 +++++++++++++++++++ .../main/res/layout/import_keys_activity.xml | 37 ++++---- .../main/res/layout/log_display_activity.xml | 46 ++++++++++ .../main/res/layout/log_display_fragment.xml | 11 +++ .../src/main/res/layout/log_display_item.xml | 14 +++ 8 files changed, 204 insertions(+), 21 deletions(-) create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayActivity.java create mode 100644 OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java create mode 100644 OpenKeychain/src/main/res/layout/log_display_activity.xml create mode 100644 OpenKeychain/src/main/res/layout/log_display_fragment.xml create mode 100644 OpenKeychain/src/main/res/layout/log_display_item.xml diff --git a/OpenKeychain/src/main/AndroidManifest.xml b/OpenKeychain/src/main/AndroidManifest.xml index f4007c098..f33886d44 100644 --- a/OpenKeychain/src/main/AndroidManifest.xml +++ b/OpenKeychain/src/main/AndroidManifest.xml @@ -434,6 +434,12 @@ + + diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java index d1869454d..90d772bd1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ImportKeysActivity.java @@ -438,10 +438,10 @@ public class ImportKeysActivity extends ActionBarActivity implements ActionBar.O new SuperToast.OnClickListener() { @Override public void onClick(View view, Parcelable token) { - // Intent intent = new Intent( - // ImportKeysActivity.this, LogDisplayActivity.class); - // intent.putExtra(LogDisplayFragment.EXTRA_RESULT, result); - // startActivity(intent); + Intent intent = new Intent( + ImportKeysActivity.this, LogDisplayActivity.class); + intent.putExtra(LogDisplayFragment.EXTRA_RESULT, result); + startActivity(intent); } })); toast.show(); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayActivity.java new file mode 100644 index 000000000..28c120d01 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayActivity.java @@ -0,0 +1,17 @@ +package org.sufficientlysecure.keychain.ui; + +import android.os.Bundle; +import android.support.v7.app.ActionBarActivity; + +import org.sufficientlysecure.keychain.R; + +public class LogDisplayActivity extends ActionBarActivity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.log_display_activity); + } + +} \ No newline at end of file diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java new file mode 100644 index 000000000..36d3e932e --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java @@ -0,0 +1,86 @@ +package org.sufficientlysecure.keychain.ui; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Color; +import android.os.Bundle; +import android.support.v4.app.ListFragment; +import android.util.TypedValue; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.TextView; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.service.OperationResultParcel; +import org.sufficientlysecure.keychain.service.OperationResultParcel.LogEntryParcel; + +import java.util.ArrayList; + +public class LogDisplayFragment extends ListFragment { + + LogAdapter mAdapter; + + public static final String EXTRA_RESULT = "log"; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + Intent intent = getActivity().getIntent(); + if (intent.getExtras() == null || !intent.getExtras().containsKey(EXTRA_RESULT)) { + getActivity().finish(); + return; + } + + OperationResultParcel result = intent.getParcelableExtra(EXTRA_RESULT); + if (result == null) { + getActivity().finish(); + return; + } + + mAdapter = new LogAdapter(getActivity(), result.getLog()); + setListAdapter(mAdapter); + + } + + private class LogAdapter extends ArrayAdapter { + + private LayoutInflater mInflater; + private int dipFactor; + + public LogAdapter(Context context, ArrayList log) { + super(context, R.layout.log_display_item, log); + mInflater = LayoutInflater.from(getContext()); + dipFactor = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, + (float) 6, getResources().getDisplayMetrics()); + + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + LogEntryParcel entry = getItem(position); + TextView text; + if (convertView == null) { + convertView = mInflater.inflate(R.layout.log_display_item, parent, false); + text = (TextView) convertView.findViewById(R.id.log_text); + convertView.setTag(text); + } else { + text = (TextView) convertView.getTag(); + } + + text.setPadding(entry.mIndent*dipFactor, 0, 0, 0); + text.setText(getResources().getString(entry.mType.getMsgId(), (Object[]) entry.mParameters)); + switch (entry.mLevel) { + 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; + } + + return convertView; + } + + } +} diff --git a/OpenKeychain/src/main/res/layout/import_keys_activity.xml b/OpenKeychain/src/main/res/layout/import_keys_activity.xml index 2a332823e..0486b6bd6 100644 --- a/OpenKeychain/src/main/res/layout/import_keys_activity.xml +++ b/OpenKeychain/src/main/res/layout/import_keys_activity.xml @@ -1,22 +1,37 @@ - + android:layout_height="fill_parent" + android:orientation="vertical"> + + + + @@ -43,16 +58,4 @@ style="@style/SelectableItem" /> - - - \ No newline at end of file + \ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/log_display_activity.xml b/OpenKeychain/src/main/res/layout/log_display_activity.xml new file mode 100644 index 000000000..591e2650c --- /dev/null +++ b/OpenKeychain/src/main/res/layout/log_display_activity.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/log_display_fragment.xml b/OpenKeychain/src/main/res/layout/log_display_fragment.xml new file mode 100644 index 000000000..442e72d09 --- /dev/null +++ b/OpenKeychain/src/main/res/layout/log_display_fragment.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/OpenKeychain/src/main/res/layout/log_display_item.xml b/OpenKeychain/src/main/res/layout/log_display_item.xml new file mode 100644 index 000000000..f0e0e4ecb --- /dev/null +++ b/OpenKeychain/src/main/res/layout/log_display_item.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file