From 518fc2a310942809d77b2577276d0f855ff403e3 Mon Sep 17 00:00:00 2001 From: Dominik Date: Mon, 12 Mar 2012 15:10:26 +0100 Subject: [PATCH] help activity --- org_apg/AndroidManifest.xml | 3 + org_apg/res/layout/decrypt.xml | 27 +------ org_apg/res/layout/encrypt.xml | 17 ++++- org_apg/res/layout/help_activity.xml | 14 ++++ org_apg/res/raw/help.html | 16 +++++ org_apg/res/values/strings.xml | 3 +- org_apg/src/org/apg/Id.java | 2 +- org_apg/src/org/apg/ui/DecryptActivity.java | 64 +++++++++++------ org_apg/src/org/apg/ui/HelpActivity.java | 79 +++++++++++++++++++++ org_apg/src/org/apg/ui/MainActivity.java | 3 +- org_apg/src/org/apg/util/Utils.java | 54 ++++++++++++++ 11 files changed, 231 insertions(+), 51 deletions(-) create mode 100644 org_apg/res/layout/help_activity.xml create mode 100644 org_apg/res/raw/help.html create mode 100644 org_apg/src/org/apg/ui/HelpActivity.java create mode 100644 org_apg/src/org/apg/util/Utils.java diff --git a/org_apg/AndroidManifest.xml b/org_apg/AndroidManifest.xml index 9ea2ac9d5..b96c442fe 100644 --- a/org_apg/AndroidManifest.xml +++ b/org_apg/AndroidManifest.xml @@ -206,6 +206,9 @@ android:excludeFromRecents="true" android:label="@string/title_about" android:theme="@style/Theme.Sherlock.Light.Dialog" /> + + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:src="@drawable/ic_menu_filebrowser" /> - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/org_apg/res/layout/encrypt.xml b/org_apg/res/layout/encrypt.xml index 7750ab129..9fc3da676 100644 --- a/org_apg/res/layout/encrypt.xml +++ b/org_apg/res/layout/encrypt.xml @@ -1,5 +1,19 @@ - + diff --git a/org_apg/res/layout/help_activity.xml b/org_apg/res/layout/help_activity.xml new file mode 100644 index 000000000..12ac366d7 --- /dev/null +++ b/org_apg/res/layout/help_activity.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/org_apg/res/raw/help.html b/org_apg/res/raw/help.html new file mode 100644 index 000000000..aff1b0179 --- /dev/null +++ b/org_apg/res/raw/help.html @@ -0,0 +1,16 @@ + + + + + +

Beta software

+

This is beta software. It contains many remaining bugs!

+

APG+

+

Android Privacy Guard (APG) is a OpenPGP implementation for Android. +
APG+ is a fork based on the original APG to introduce more features and a new user interface.

+

I found a bug in APG+!

+

Please report it in the issue tracker of APG+.

+ + \ No newline at end of file diff --git a/org_apg/res/values/strings.xml b/org_apg/res/values/strings.xml index 4714fe190..724fe5671 100644 --- a/org_apg/res/values/strings.xml +++ b/org_apg/res/values/strings.xml @@ -46,7 +46,8 @@ Import from QR Code Sign Key About - + Help + User IDs Keys diff --git a/org_apg/src/org/apg/Id.java b/org_apg/src/org/apg/Id.java index f64038e48..6b721d3a8 100644 --- a/org_apg/src/org/apg/Id.java +++ b/org_apg/src/org/apg/Id.java @@ -47,7 +47,7 @@ public final class Id { public static final int encrypt = 0x21070013; public static final int encrypt_to_clipboard = 0x21070014; public static final int decrypt = 0x21070015; - public static final int decrypt_to_clipboard = 0x21070016; + public static final int reply = 0x21070016; public static final int cancel = 0x21070017; public static final int save = 0x21070018; diff --git a/org_apg/src/org/apg/ui/DecryptActivity.java b/org_apg/src/org/apg/ui/DecryptActivity.java index 2809a31d5..53df18867 100644 --- a/org_apg/src/org/apg/ui/DecryptActivity.java +++ b/org_apg/src/org/apg/ui/DecryptActivity.java @@ -117,13 +117,13 @@ public class DecryptActivity extends BaseActivity { public boolean onCreateOptionsMenu(Menu menu) { if (mDecryptEnabled) { - menu.add(1, Id.menu.option.encrypt_to_clipboard, 0, mDecryptString) + menu.add(1, Id.menu.option.decrypt, 0, mDecryptString) // .setIcon(R.drawable.ic_menu_encrypt) .setShowAsAction( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); } if (mReplyEnabled) { - menu.add(1, Id.menu.option.encrypt, 1, mReplyString) + menu.add(1, Id.menu.option.reply, 1, mReplyString) // .setIcon(R.drawable.ic_menu_decrypt) .setShowAsAction( MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT); @@ -132,6 +132,26 @@ public class DecryptActivity extends BaseActivity { return true; } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case Id.menu.option.decrypt: { + decryptClicked(); + + return true; + } + case Id.menu.option.reply: { + replyClicked(); + + return true; + } + + default: { + return super.onOptionsItemSelected(item); + } + } + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -171,8 +191,6 @@ public class DecryptActivity extends BaseActivity { mSourceLabel.setOnClickListener(nextSourceClickListener); mMessage = (EditText) findViewById(R.id.message); - // mDecryptButton = (Button) findViewById(R.id.btn_decrypt); - // mReplyButton = (Button) findViewById(R.id.btn_reply); mSignatureLayout = (LinearLayout) findViewById(R.id.signature); mSignatureStatusImage = (ImageView) findViewById(R.id.ic_signature_status); mUserId = (TextView) findViewById(R.id.mainUserId); @@ -258,6 +276,9 @@ public class DecryptActivity extends BaseActivity { mMessage.setText(textData); mDecryptString = getString(R.string.btn_verify); // mDecryptButton.setText(R.string.btn_verify); + + // build new action bar + invalidateOptionsMenu(); } else { Log.d(Constants.TAG, "Nothing matched!"); } @@ -305,7 +326,8 @@ public class DecryptActivity extends BaseActivity { mMessage.setText(data); mDecryptString = getString(R.string.btn_verify); - // mDecryptButton.setText(R.string.btn_verify); + // build new action bar + invalidateOptionsMenu(); } } } @@ -348,21 +370,11 @@ public class DecryptActivity extends BaseActivity { } }); - // mDecryptButton.setOnClickListener(new OnClickListener() { - // public void onClick(View v) { - // decryptClicked(); - // } - // }); - // - // mReplyButton.setOnClickListener(new OnClickListener() { - // public void onClick(View v) { - // replyClicked(); - // } - // }); - // mReplyButton.setVisibility(View.INVISIBLE); - mReplyEnabled = false; + // build new actionbar + invalidateOptionsMenu(); + if (mReturnResult) { mSourcePrevious.setClickable(false); mSourcePrevious.setEnabled(false); @@ -381,6 +393,7 @@ public class DecryptActivity extends BaseActivity { if (mSource.getCurrentView().getId() == R.id.sourceMessage && (mMessage.getText().length() > 0 || mData != null || mContentUri != null)) { // mDecryptButton.performClick(); + // TODO: why was it performClick()??? decryptClicked(); } } @@ -416,16 +429,19 @@ public class DecryptActivity extends BaseActivity { switch (mSource.getCurrentView().getId()) { case R.id.sourceFile: { mSourceLabel.setText(R.string.label_file); - // mDecryptButton.setText(R.string.btn_decrypt); mDecryptString = getString(R.string.btn_decrypt); + + // build new action bar + invalidateOptionsMenu(); break; } case R.id.sourceMessage: { mSourceLabel.setText(R.string.label_message); - // mDecryptButton.setText(R.string.btn_decrypt); mDecryptString = getString(R.string.btn_decrypt); + // build new action bar + invalidateOptionsMenu(); break; } @@ -633,9 +649,11 @@ public class DecryptActivity extends BaseActivity { removeDialog(Id.dialog.decrypting); mSignatureKeyId = 0; mSignatureLayout.setVisibility(View.GONE); - // mReplyButton.setVisibility(View.INVISIBLE); mReplyEnabled = false; + // build new action bar + invalidateOptionsMenu(); + String error = data.getString(Apg.EXTRA_ERROR); if (error != null) { Toast.makeText(this, getString(R.string.errorMessage, error), Toast.LENGTH_SHORT) @@ -657,8 +675,10 @@ public class DecryptActivity extends BaseActivity { String decryptedMessage = data.getString(Apg.EXTRA_DECRYPTED_MESSAGE); mMessage.setText(decryptedMessage); mMessage.setHorizontallyScrolling(false); - // mReplyButton.setVisibility(View.VISIBLE); mReplyEnabled = false; + + // build new action bar + invalidateOptionsMenu(); break; } diff --git a/org_apg/src/org/apg/ui/HelpActivity.java b/org_apg/src/org/apg/ui/HelpActivity.java new file mode 100644 index 000000000..9a4dc7f76 --- /dev/null +++ b/org_apg/src/org/apg/ui/HelpActivity.java @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2012 Dominik Schürmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apg.ui; + +import org.apg.R; +import org.apg.util.Utils; + +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.app.SherlockActivity; +import com.actionbarsherlock.view.MenuItem; + +import android.app.Activity; +import android.content.Intent; +import android.os.Bundle; +import android.text.Html; +import android.text.method.LinkMovementMethod; +import android.widget.TextView; + +public class HelpActivity extends SherlockActivity { + Activity mActivity; + TextView mHelpText; + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + + case android.R.id.home: + startActivity(new Intent(this, MainActivity.class)); + return true; + + default: + break; + + } + return false; + } + + /** + * Instantiate View for this Activity + */ + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + setContentView(R.layout.help_activity); + + final ActionBar actionBar = getSupportActionBar(); + actionBar.setDisplayShowTitleEnabled(true); + actionBar.setDisplayHomeAsUpEnabled(true); + + mActivity = this; + + mHelpText = (TextView) findViewById(R.id.help_text); + + // load html from html file from /res/raw + String helpText = Utils.readContentFromResource(mActivity, R.raw.help); + + // set text from resources with html markup + mHelpText.setText(Html.fromHtml(helpText)); + // make links work + mHelpText.setMovementMethod(LinkMovementMethod.getInstance()); + + } + +} diff --git a/org_apg/src/org/apg/ui/MainActivity.java b/org_apg/src/org/apg/ui/MainActivity.java index e096f477a..f19c76ad7 100644 --- a/org_apg/src/org/apg/ui/MainActivity.java +++ b/org_apg/src/org/apg/ui/MainActivity.java @@ -46,7 +46,6 @@ public class MainActivity extends BaseActivity { public void myKeysOnClick(View view) { startActivity(new Intent(this, SecretKeyListActivity.class)); - } public void encryptOnClick(View view) { @@ -68,7 +67,7 @@ public class MainActivity extends BaseActivity { } public void helpOnClick(View view) { - // TODO: implement help view + startActivity(new Intent(this, HelpActivity.class)); } @Override diff --git a/org_apg/src/org/apg/util/Utils.java b/org_apg/src/org/apg/util/Utils.java new file mode 100644 index 000000000..45b18afd1 --- /dev/null +++ b/org_apg/src/org/apg/util/Utils.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2012 Dominik Schürmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apg.util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import android.content.Context; + +public class Utils { + + /** + * Reads html files from /res/raw/example.html to output them as string. See + * http://www.monocube.com/2011/02/08/android-tutorial-html-file-in-webview/ + * + * @param context + * current context + * @param resourceID + * of html file to read + * @return content of html file with formatting + */ + public static String readContentFromResource(Context context, int resourceID) { + InputStream raw = context.getResources().openRawResource(resourceID); + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + int i; + try { + i = raw.read(); + while (i != -1) { + stream.write(i); + i = raw.read(); + } + raw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + return stream.toString(); + } + +}