Experiments with fragments in decrypt activity

This commit is contained in:
Dominik Schürmann 2014-03-29 00:11:07 +01:00
parent 224e8a7554
commit 4cec2194e0
9 changed files with 602 additions and 250 deletions

View File

@ -25,12 +25,17 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Messenger;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AnimationUtils;
import android.widget.*;
import com.beardedhen.androidbootstrap.BootstrapButton;
import com.devspark.appmsg.AppMsg;
import org.openintents.openpgp.OpenPgpSignatureResult;
import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.sufficientlysecure.keychain.Constants;
@ -49,6 +54,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
import org.sufficientlysecure.keychain.ui.adapter.PageTabStripAdapter;
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.FileDialogFragment;
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
@ -57,7 +63,7 @@ import org.sufficientlysecure.keychain.util.Log;
import java.io.*;
import java.util.regex.Matcher;
@SuppressLint("NewApi")
//@SuppressLint("NewApi")
public class DecryptActivity extends DrawerActivity {
/* Intents */
@ -67,28 +73,30 @@ public class DecryptActivity extends DrawerActivity {
/* EXTRA keys for input */
public static final String EXTRA_TEXT = "text";
public static final String EXTRA_SELECTED_TAB = "selected_tab";
private static final int RESULT_CODE_LOOKUP_KEY = 0x00007006;
private static final int RESULT_CODE_FILE = 0x00007003;
private long mSignatureKeyId = 0;
private boolean mReturnResult = false;
// private boolean mReturnResult = false;
// TODO: replace signed only checks with something more intelligent
// PgpDecryptVerify should handle all automatically!!!
private boolean mSignedOnly = false;
private boolean mAssumeSymmetricEncryption = false;
private EditText mMessage = null;
// private EditText mMessage = null;
private RelativeLayout mSignatureLayout = null;
private ImageView mSignatureStatusImage = null;
private TextView mUserId = null;
private TextView mUserIdRest = null;
private ViewFlipper mSource = null;
private TextView mSourceLabel = null;
private ImageView mSourcePrevious = null;
private ImageView mSourceNext = null;
// private ViewFlipper mSource = null;
// private TextView mSourceLabel = null;
// private ImageView mSourcePrevious = null;
// private ImageView mSourceNext = null;
private int mDecryptTarget;
@ -107,45 +115,50 @@ public class DecryptActivity extends DrawerActivity {
private FileDialogFragment mFileDialog;
private boolean mDecryptImmediately = false;
// private boolean mDecryptImmediately = false;
private BootstrapButton mDecryptButton;
ViewPager mViewPager;
PagerTabStrip mPagerTabStrip;
PageTabStripAdapter mTabsAdapter;
DecryptMessageFragment mMessageFragment;
DecryptFileFragment mFileFragment;
private void initView() {
mSource = (ViewFlipper) findViewById(R.id.source);
mSourceLabel = (TextView) findViewById(R.id.sourceLabel);
mSourcePrevious = (ImageView) findViewById(R.id.sourcePrevious);
mSourceNext = (ImageView) findViewById(R.id.sourceNext);
// mSource = (ViewFlipper) findViewById(R.id.source);
// mSourceLabel = (TextView) findViewById(R.id.sourceLabel);
// mSourcePrevious = (ImageView) findViewById(R.id.sourcePrevious);
// mSourceNext = (ImageView) findViewById(R.id.sourceNext);
//
// mSourcePrevious.setClickable(true);
// mSourcePrevious.setOnClickListener(new OnClickListener() {
// public void onClick(View v) {
// mSource.setInAnimation(AnimationUtils.loadAnimation(DecryptActivity.this,
// R.anim.push_right_in));
// mSource.setOutAnimation(AnimationUtils.loadAnimation(DecryptActivity.this,
// R.anim.push_right_out));
// mSource.showPrevious();
// updateSource();
// }
// });
//
// mSourceNext.setClickable(true);
// OnClickListener nextSourceClickListener = new OnClickListener() {
// public void onClick(View v) {
// mSource.setInAnimation(AnimationUtils.loadAnimation(DecryptActivity.this,
// R.anim.push_left_in));
// mSource.setOutAnimation(AnimationUtils.loadAnimation(DecryptActivity.this,
// R.anim.push_left_out));
// mSource.showNext();
// updateSource();
// }
// };
// mSourceNext.setOnClickListener(nextSourceClickListener);
//
// mSourceLabel.setClickable(true);
// mSourceLabel.setOnClickListener(nextSourceClickListener);
mSourcePrevious.setClickable(true);
mSourcePrevious.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mSource.setInAnimation(AnimationUtils.loadAnimation(DecryptActivity.this,
R.anim.push_right_in));
mSource.setOutAnimation(AnimationUtils.loadAnimation(DecryptActivity.this,
R.anim.push_right_out));
mSource.showPrevious();
updateSource();
}
});
mSourceNext.setClickable(true);
OnClickListener nextSourceClickListener = new OnClickListener() {
public void onClick(View v) {
mSource.setInAnimation(AnimationUtils.loadAnimation(DecryptActivity.this,
R.anim.push_left_in));
mSource.setOutAnimation(AnimationUtils.loadAnimation(DecryptActivity.this,
R.anim.push_left_out));
mSource.showNext();
updateSource();
}
};
mSourceNext.setOnClickListener(nextSourceClickListener);
mSourceLabel.setClickable(true);
mSourceLabel.setOnClickListener(nextSourceClickListener);
mMessage = (EditText) findViewById(R.id.message);
mSignatureLayout = (RelativeLayout) findViewById(R.id.signature);
mSignatureStatusImage = (ImageView) findViewById(R.id.ic_signature_status);
mUserId = (TextView) findViewById(R.id.mainUserId);
@ -153,10 +166,10 @@ public class DecryptActivity extends DrawerActivity {
// measure the height of the source_file view and set the message view's min height to that,
// so it fills mSource fully... bit of a hack.
View tmp = findViewById(R.id.sourceFile);
tmp.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
int height = tmp.getMeasuredHeight();
mMessage.setMinimumHeight(height);
// View tmp = findViewById(R.id.sourceFile);
// tmp.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
// int height = tmp.getMeasuredHeight();
// mMessage.setMinimumHeight(height);
mFilename = (EditText) findViewById(R.id.filename);
mBrowse = (BootstrapButton) findViewById(R.id.btn_browse);
@ -178,11 +191,11 @@ public class DecryptActivity extends DrawerActivity {
mDeleteAfter = (CheckBox) findViewById(R.id.deleteAfterDecryption);
// default: message source
mSource.setInAnimation(null);
mSource.setOutAnimation(null);
while (mSource.getCurrentView().getId() != R.id.sourceMessage) {
mSource.showNext();
}
// mSource.setInAnimation(null);
// mSource.setOutAnimation(null);
// while (mSource.getCurrentView().getId() != R.id.sourceMessage) {
// mSource.showNext();
// }
mDecryptButton = (BootstrapButton) findViewById(R.id.action_decrypt);
mDecryptButton.setOnClickListener(new OnClickListener() {
@ -191,6 +204,49 @@ public class DecryptActivity extends DrawerActivity {
decryptClicked();
}
});
mViewPager = (ViewPager) findViewById(R.id.decrypt_pager);
mPagerTabStrip = (PagerTabStrip) findViewById(R.id.decrypt_pager_tab_strip);
initPager();
}
private static final int PAGER_TAB_MESSAGE = 0;
private static final int PAGER_TAB_FILE = 1;
private void initPager() {
mTabsAdapter = new PageTabStripAdapter(this);
mViewPager.setAdapter(mTabsAdapter);
Bundle messageBundle = new Bundle();
mTabsAdapter.addTab(DecryptMessageFragment.class, messageBundle, getString(R.string.label_message));
Bundle fileBundle = new Bundle();
mTabsAdapter.addTab(DecryptFileFragment.class, fileBundle, getString(R.string.label_file));
// mPagerTabStrip.
getSupportFragmentManager().executePendingTransactions();
// for (Fragment f : getSupportFragmentManager().getFragments()) {
// Log.d(Constants.TAG, "f: "+f.getTag());
// }
DecryptMessageFragment messageFragment = (DecryptMessageFragment) getFragmentByPosition(PAGER_TAB_MESSAGE);
// mFileFragment = (DecryptFileFragment) getFragmentByPosition(PAGER_TAB_FILE);
// Log.d(Constants.TAG, fr.getTag());
//
}
/**
* find fragment
*
* @param pos
* @return
*/
public Fragment getFragmentByPosition(int pos) {
// based on FragmentPagerAdapter.makeFragmentName()
String tag = "android:switcher:" + mViewPager.getId() + ":" + pos;
Log.d(Constants.TAG, "findFragmentByTag: "+tag);
return getSupportFragmentManager().findFragmentByTag(tag);
}
@Override
@ -209,25 +265,25 @@ public class DecryptActivity extends DrawerActivity {
// Handle intent actions
handleActions(getIntent());
if (mSource.getCurrentView().getId() == R.id.sourceMessage
&& mMessage.getText().length() == 0) {
CharSequence clipboardText = ClipboardReflection.getClipboardText(this);
String data = "";
if (clipboardText != null) {
Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(clipboardText);
if (!matcher.matches()) {
matcher = PgpHelper.PGP_SIGNED_MESSAGE.matcher(clipboardText);
}
if (matcher.matches()) {
data = matcher.group(1);
mMessage.setText(data);
AppMsg.makeText(this, R.string.using_clipboard_content, AppMsg.STYLE_INFO)
.show();
}
}
}
// if (mSource.getCurrentView().getId() == R.id.sourceMessage
// && mMessage.getText().length() == 0) {
//
// CharSequence clipboardText = ClipboardReflection.getClipboardText(this);
//
// String data = "";
// if (clipboardText != null) {
// Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(clipboardText);
// if (!matcher.matches()) {
// matcher = PgpHelper.PGP_SIGNED_MESSAGE.matcher(clipboardText);
// }
// if (matcher.matches()) {
// data = matcher.group(1);
// mMessage.setText(data);
// AppMsg.makeText(this, R.string.using_clipboard_content, AppMsg.STYLE_INFO)
// .show();
// }
// }
// }
mSignatureLayout.setVisibility(View.GONE);
mSignatureLayout.setOnClickListener(new OnClickListener() {
@ -246,28 +302,29 @@ public class DecryptActivity extends DrawerActivity {
}
});
if (mReturnResult) {
mSourcePrevious.setClickable(false);
mSourcePrevious.setEnabled(false);
mSourcePrevious.setVisibility(View.INVISIBLE);
// if (mReturnResult) {
// mSourcePrevious.setClickable(false);
// mSourcePrevious.setEnabled(false);
// mSourcePrevious.setVisibility(View.INVISIBLE);
//
// mSourceNext.setClickable(false);
// mSourceNext.setEnabled(false);
// mSourceNext.setVisibility(View.INVISIBLE);
//
// mSourceLabel.setClickable(false);
// mSourceLabel.setEnabled(false);
// }
//
// updateSource();
mSourceNext.setClickable(false);
mSourceNext.setEnabled(false);
mSourceNext.setVisibility(View.INVISIBLE);
mSourceLabel.setClickable(false);
mSourceLabel.setEnabled(false);
}
updateSource();
if (mDecryptImmediately
|| (mSource.getCurrentView().getId() == R.id.sourceMessage && (mMessage.getText()
.length() > 0 || mContentUri != null))) {
decryptClicked();
}
// if (mDecryptImmediately
// || (mSource.getCurrentView().getId() == R.id.sourceMessage && (mMessage.getText()
// .length() > 0 || mContentUri != null))) {
// decryptClicked();
// }
}
/**
* Handles all actions with this intent
*
@ -316,14 +373,17 @@ public class DecryptActivity extends DrawerActivity {
* Main Actions
*/
if (ACTION_DECRYPT.equals(action) && textData != null) {
Log.d(Constants.TAG, "textData null, matching text ...");
Log.d(Constants.TAG, "textData not null, matching text ...");
Matcher matcher = PgpHelper.PGP_MESSAGE.matcher(textData);
if (matcher.matches()) {
Log.d(Constants.TAG, "PGP_MESSAGE matched");
textData = matcher.group(1);
// replace non breakable spaces
textData = textData.replaceAll("\\xa0", " ");
mMessage.setText(textData);
mViewPager.setCurrentItem(PAGER_TAB_MESSAGE, false);
mMessageFragment.setText(textData);
// mMessage.setText(textData);
} else {
matcher = PgpHelper.PGP_SIGNED_MESSAGE.matcher(textData);
if (matcher.matches()) {
@ -331,7 +391,10 @@ public class DecryptActivity extends DrawerActivity {
textData = matcher.group(1);
// replace non breakable spaces
textData = textData.replaceAll("\\xa0", " ");
mMessage.setText(textData);
// mMessage.setText(textData);
mViewPager.setCurrentItem(PAGER_TAB_MESSAGE, false);
mMessageFragment = (DecryptMessageFragment) getFragmentByPosition(mViewPager.getCurrentItem());
mMessageFragment.setText(textData);
} else {
Log.d(Constants.TAG, "Nothing matched!");
}
@ -344,14 +407,14 @@ public class DecryptActivity extends DrawerActivity {
mInputFilename = path;
mFilename.setText(mInputFilename);
guessOutputFilename();
mSource.setInAnimation(null);
mSource.setOutAnimation(null);
while (mSource.getCurrentView().getId() != R.id.sourceFile) {
mSource.showNext();
}
// mSource.setInAnimation(null);
// mSource.setOutAnimation(null);
// while (mSource.getCurrentView().getId() != R.id.sourceFile) {
// mSource.showNext();
// }
} else {
Log.e(Constants.TAG,
"Direct binary data without actual file in filesystem is not supported. Please use the Remote Service API!");
"Direct binary data without actual file in filesystem is not supported. Please use the Remote Service API!");
Toast.makeText(this, R.string.error_only_files_are_supported, Toast.LENGTH_LONG)
.show();
// end activity
@ -373,28 +436,28 @@ public class DecryptActivity extends DrawerActivity {
mOutputFilename = Constants.Path.APP_DIR + "/" + filename;
}
private void updateSource() {
switch (mSource.getCurrentView().getId()) {
case R.id.sourceFile: {
mSourceLabel.setText(R.string.label_file);
mDecryptButton.setText(getString(R.string.btn_decrypt));
break;
}
case R.id.sourceMessage: {
mSourceLabel.setText(R.string.label_message);
mDecryptButton.setText(getString(R.string.btn_decrypt));
break;
}
default: {
break;
}
}
}
// private void updateSource() {
// switch (mSource.getCurrentView().getId()) {
// case R.id.sourceFile: {
// mSourceLabel.setText(R.string.label_file);
// mDecryptButton.setText(getString(R.string.btn_decrypt));
// break;
// }
//
// case R.id.sourceMessage: {
// mSourceLabel.setText(R.string.label_message);
// mDecryptButton.setText(getString(R.string.btn_decrypt));
// break;
// }
//
// default: {
// break;
// }
// }
// }
private void decryptClicked() {
if (mSource.getCurrentView().getId() == R.id.sourceFile) {
if (mViewPager.getCurrentItem() == PAGER_TAB_FILE) {
mDecryptTarget = Id.target.file;
} else {
mDecryptTarget = Id.target.message;
@ -428,13 +491,13 @@ public class DecryptActivity extends DrawerActivity {
}
if (mDecryptTarget == Id.target.message) {
String messageData = mMessage.getText().toString();
Matcher matcher = PgpHelper.PGP_SIGNED_MESSAGE.matcher(messageData);
if (matcher.matches()) {
mSignedOnly = true;
decryptStart();
return;
}
// String messageData = mMessage.getText().toString();
// Matcher matcher = PgpHelper.PGP_SIGNED_MESSAGE.matcher(messageData);
// if (matcher.matches()) {
// mSignedOnly = true;
// decryptStart();
// return;
// }
}
// else treat it as an decrypted message/file
@ -519,7 +582,8 @@ public class DecryptActivity extends DrawerActivity {
AppMsg.STYLE_ALERT).show();
}
} else {
inStream = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
// inStream = new ByteArrayInputStream(mMessage.getText().toString().getBytes());
}
// get decryption key for this inStream
@ -551,18 +615,6 @@ public class DecryptActivity extends DrawerActivity {
}
}
private void replyClicked() {
Intent intent = new Intent(this, EncryptActivity.class);
intent.setAction(EncryptActivity.ACTION_ENCRYPT);
String data = mMessage.getText().toString();
data = data.replaceAll("(?m)^", "> ");
data = "\n\n" + data;
intent.putExtra(EncryptActivity.EXTRA_TEXT, data);
intent.putExtra(EncryptActivity.EXTRA_SIGNATURE_KEY_ID, mSecretKeyId);
intent.putExtra(EncryptActivity.EXTRA_ENCRYPTION_KEY_IDS, new long[]{mSignatureKeyId});
startActivity(intent);
}
private void askForOutputFilename() {
// Message is received after passphrase is cached
Handler returnHandler = new Handler() {
@ -620,8 +672,8 @@ public class DecryptActivity extends DrawerActivity {
} else {
data.putInt(KeychainIntentService.TARGET, KeychainIntentService.TARGET_BYTES);
String message = mMessage.getText().toString();
data.putByteArray(KeychainIntentService.DECRYPT_CIPHERTEXT_BYTES, message.getBytes());
// String message = mMessage.getText().toString();
// data.putByteArray(KeychainIntentService.DECRYPT_CIPHERTEXT_BYTES, message.getBytes());
}
data.putLong(KeychainIntentService.ENCRYPT_SECRET_KEY_ID, mSecretKeyId);
@ -647,20 +699,20 @@ public class DecryptActivity extends DrawerActivity {
AppMsg.makeText(DecryptActivity.this, R.string.decryption_successful,
AppMsg.STYLE_INFO).show();
if (mReturnResult) {
Intent intent = new Intent();
intent.putExtras(returnData);
setResult(RESULT_OK, intent);
finish();
return;
}
// if (mReturnResult) {
// Intent intent = new Intent();
// intent.putExtras(returnData);
// setResult(RESULT_OK, intent);
// finish();
// return;
// }
switch (mDecryptTarget) {
case Id.target.message:
String decryptedMessage = returnData
.getString(KeychainIntentService.RESULT_DECRYPTED_STRING);
mMessage.setText(decryptedMessage);
mMessage.setHorizontallyScrolling(false);
// mMessage.setText(decryptedMessage);
// mMessage.setHorizontallyScrolling(false);
break;

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import org.sufficientlysecure.keychain.R;
public class DecryptFileFragment extends Fragment {
private EditText mMessage;
/**
* Creates new instance of this fragment
*/
public static DecryptFileFragment newInstance() {
DecryptFileFragment frag = new DecryptFileFragment();
Bundle args = new Bundle();
frag.setArguments(args);
return frag;
}
/**
* Inflate the layout for this fragment
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.decrypt_file_fragment, container, false);
mMessage = (EditText) view.findViewById(R.id.message);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}

View File

@ -0,0 +1,78 @@
/*
* Copyright (C) 2013 Dominik Schürmann <dominik@dominikschuermann.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.EditText;
import com.beardedhen.androidbootstrap.BootstrapButton;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.util.Log;
public class DecryptMessageFragment extends Fragment {
private EditText mMessage;
/**
* Creates new instance of this fragment
*/
public static DecryptMessageFragment newInstance() {
DecryptMessageFragment frag = new DecryptMessageFragment();
Bundle args = new Bundle();
frag.setArguments(args);
return frag;
}
/**
* Inflate the layout for this fragment
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.decrypt_message_fragment, container, false);
mMessage = (EditText) view.findViewById(R.id.message);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Log.d(Constants.TAG, "tag: " + getTag());
}
public String getText() {
return mMessage.getText().toString();
}
public void setText(String message) {
mMessage.setText(message);
}
}

View File

@ -0,0 +1,74 @@
/*
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui.adapter;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
import java.util.ArrayList;
public class PageTabStripAdapter extends FragmentPagerAdapter {
private final Context mContext;
private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
static final class TabInfo {
private final Class<?> clss;
private final Bundle args;
private final String title;
TabInfo(Class<?> clss, Bundle args, String title) {
this.clss = clss;
this.args = args;
this.title = title;
}
}
public PageTabStripAdapter(ActionBarActivity activity) {
super(activity.getSupportFragmentManager());
mContext = activity;
}
public void addTab(Class<?> clss, Bundle args, String title) {
TabInfo info = new TabInfo(clss, args, title);
mTabs.add(info);
notifyDataSetChanged();
}
@Override
public int getCount() {
return mTabs.size();
}
@Override
public Fragment getItem(int position) {
TabInfo info = mTabs.get(position);
return Fragment.instantiate(mContext, info.clss.getName(), info.args);
}
@Override
public CharSequence getPageTitle(int position) {
return mTabs.get(position).title;
}
}

View File

@ -36,12 +36,12 @@ public class TabsAdapter extends FragmentStatePagerAdapter implements ActionBar.
private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();
static final class TabInfo {
private final Class<?> mClss;
private final Bundle mArgs;
private final Class<?> clss;
private final Bundle args;
TabInfo(Class<?> mClss, Bundle mArgs) {
this.mClss = mClss;
this.mArgs = mArgs;
TabInfo(Class<?> clss, Bundle args) {
this.clss = clss;
this.args = args;
}
}
@ -71,7 +71,7 @@ public class TabsAdapter extends FragmentStatePagerAdapter implements ActionBar.
@Override
public Fragment getItem(int position) {
TabInfo info = mTabs.get(position);
return Fragment.instantiate(mContext, info.mClss.getName(), info.mArgs);
return Fragment.instantiate(mContext, info.clss.getName(), info.args);
}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

View File

@ -1,6 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/decrypt_pager"
android:layout_width="match_parent"
android:layout_height="220dp">
<android.support.v4.view.PagerTabStrip
android:id="@+id/decrypt_pager_tab_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="@color/emphasis"
android:textColor="#fff" />
</android.support.v4.view.ViewPager>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
android:id="@+id/content_frame"
android:layout_marginLeft="@dimen/drawer_content_padding"
@ -9,7 +28,7 @@
android:fillViewport="true"
android:orientation="vertical">
<LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
@ -17,80 +36,20 @@
android:paddingLeft="10dp"
android:paddingRight="10dp">
<RelativeLayout
android:id="@+id/signature"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="horizontal"
android:padding="4dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<include layout="@layout/decrypt_signature_include" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout">
<ImageView
android:id="@+id/ic_signature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/signed_large"/>
<ImageView
android:id="@+id/ic_signature_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/overlay_error"/>
</RelativeLayout>
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/lookup_key"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:padding="4dp"
android:text="@string/btn_lookup_key"
bootstrapbutton:bb_icon_left="fa-download"
bootstrapbutton:bb_type="info"
bootstrapbutton:bb_size="small"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
<TextView
android:id="@+id/mainUserId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/label_main_user_id"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_toRightOf="@+id/relativeLayout"/>
<TextView
android:id="@+id/mainUserIdRest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Main User Id Rest"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_below="@+id/mainUserId"
android:layout_toRightOf="@+id/relativeLayout"/>
</RelativeLayout>
<LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
<ImageView
android:id="@+id/sourcePrevious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_previous"/>
android:src="@drawable/ic_previous" />
<TextView
<TextView
android:id="@+id/sourceLabel"
style="@style/SectionHeader"
android:layout_width="0dip"
@ -98,50 +57,50 @@
android:layout_weight="1"
android:gravity="center_horizontal|center_vertical"
android:text="@string/label_message"
android:textAppearance="?android:attr/textAppearanceMedium"/>
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
<ImageView
android:id="@+id/sourceNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_next"/>
</LinearLayout>
android:src="@drawable/ic_next" />
</LinearLayout>
<ViewFlipper
<ViewFlipper
android:id="@+id/source"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1">
<LinearLayout
<LinearLayout
android:id="@+id/sourceMessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="4dp">
<EditText
<EditText
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:inputType="text|textCapSentences|textMultiLine|textLongMessage"
android:scrollHorizontally="true"/>
</LinearLayout>
android:scrollHorizontally="true" />
</LinearLayout>
<LinearLayout
<LinearLayout
android:id="@+id/sourceFile"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="4dp">
<LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
<EditText
android:id="@+id/filename"
android:layout_width="0dip"
android:layout_height="wrap_content"
@ -151,9 +110,9 @@
android:lines="4"
android:maxLines="10"
android:minLines="2"
android:scrollbars="vertical"/>
android:scrollbars="vertical" />
<com.beardedhen.androidbootstrap.BootstrapButton
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/btn_browse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
@ -161,45 +120,46 @@
bootstrapbutton:bb_icon_left="fa-folder-open"
bootstrapbutton:bb_roundedCorners="true"
bootstrapbutton:bb_size="default"
bootstrapbutton:bb_type="default"/>
</LinearLayout>
bootstrapbutton:bb_type="default" />
</LinearLayout>
<LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
<CheckBox
android:id="@+id/deleteAfterDecryption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/label_delete_after_decryption"/>
android:text="@string/label_delete_after_decryption" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ViewFlipper>
</ViewFlipper>
<TextView
<TextView
style="@style/SectionHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:text="@string/section_decrypt_verify"/>
android:text="@string/section_decrypt_verify" />
<LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp">
<com.beardedhen.androidbootstrap.BootstrapButton
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/action_decrypt"
android:layout_width="match_parent"
android:layout_height="60dp"
android:padding="4dp"
android:text="@string/btn_decrypt_verify"
bootstrapbutton:bb_icon_left="fa-unlock"
bootstrapbutton:bb_type="info"/>
bootstrapbutton:bb_type="info" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</ScrollView>
</LinearLayout>

View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="@+id/filename"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="top|left"
android:inputType="textMultiLine|textUri"
android:lines="4"
android:maxLines="10"
android:minLines="2"
android:scrollbars="vertical" />
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/btn_browse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
bootstrapbutton:bb_icon_left="fa-folder-open"
bootstrapbutton:bb_roundedCorners="true"
bootstrapbutton:bb_size="default"
bootstrapbutton:bb_type="default" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<CheckBox
android:id="@+id/deleteAfterDecryption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/label_delete_after_decryption" />
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top"
android:inputType="text|textCapSentences|textMultiLine|textLongMessage"
android:scrollHorizontally="true" />
</LinearLayout>

View File

@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:bootstrapbutton="http://schemas.android.com/apk/res-auto"
android:id="@+id/signature"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="horizontal"
android:padding="4dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/relativeLayout">
<ImageView
android:id="@+id/ic_signature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/signed_large" />
<ImageView
android:id="@+id/ic_signature_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/overlay_error" />
</RelativeLayout>
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/lookup_key"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:padding="4dp"
android:text="@string/btn_lookup_key"
bootstrapbutton:bb_icon_left="fa-download"
bootstrapbutton:bb_type="info"
bootstrapbutton:bb_size="small"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/mainUserId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="@string/label_main_user_id"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_toRightOf="@+id/relativeLayout" />
<TextView
android:id="@+id/mainUserIdRest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="Main User Id Rest"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_below="@+id/mainUserId"
android:layout_toRightOf="@+id/relativeLayout" />
</RelativeLayout>