added temp (10sec) password visibility and extra content

This commit is contained in:
Zeapo 2014-08-02 17:52:08 +01:00
parent c19191a3d5
commit 280e662fc3
5 changed files with 190 additions and 64 deletions

View file

@ -3,12 +3,16 @@ package com.zeapo.pwdstore;
import android.app.Activity; import android.app.Activity;
import android.app.FragmentManager; import android.app.FragmentManager;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;
import com.zeapo.pwdstore.crypto.PgpHandler; import com.zeapo.pwdstore.crypto.PgpHandler;
import com.zeapo.pwdstore.utils.PasswordItem; import com.zeapo.pwdstore.utils.PasswordItem;
@ -25,6 +29,7 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
private Stack<Integer> scrollPositions; private Stack<Integer> scrollPositions;
/** if we leave the activity to do something, do not add any other fragment */ /** if we leave the activity to do something, do not add any other fragment */
private boolean leftActivity = false; private boolean leftActivity = false;
private File currentDir;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -148,6 +153,7 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
} }
this.leftActivity = false; this.leftActivity = false;
this.currentDir = localDir;
} }
/** Stack the positions the different fragments were at */ /** Stack the positions the different fragments were at */
@ -184,4 +190,7 @@ public class PasswordStore extends Activity implements ToCloneOrNot.OnFragmentI
} }
} }
public void createPassword(View v) {
System.out.println("Adding file to : " + this.currentDir.getAbsolutePath());
}
} }

View file

@ -5,17 +5,23 @@ import android.app.PendingIntent;
import android.content.Intent; import android.content.Intent;
import android.content.IntentSender; import android.content.IntentSender;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.SystemClock;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.zeapo.pwdstore.R; import com.zeapo.pwdstore.R;
import com.zeapo.pwdstore.UserPreference;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpError;
@ -52,32 +58,25 @@ public class PgpHandler extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pgp_handler); setContentView(R.layout.activity_pgp_handler);
// Setup action buttons
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
Bundle extra = getIntent().getExtras(); Bundle extra = getIntent().getExtras();
((TextView) findViewById(R.id.crypto_handler_name)).setText(extra.getString("NAME")); ((TextView) findViewById(R.id.crypto_password_file)).setText(extra.getString("NAME"));
// some persistance // some persistance
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
String providerPackageName = settings.getString("openpgp_provider_list", ""); String providerPackageName = settings.getString("openpgp_provider_list", "");
String accountName = settings.getString("openpgp_account_name", ""); String accountName = settings.getString("openpgp_account_name", "");
if (accountName.isEmpty()) {
((TextView) findViewById(R.id.crypto_account_name)).setText("No account selected");
}
if (TextUtils.isEmpty(providerPackageName)) { if (TextUtils.isEmpty(providerPackageName)) {
Toast.makeText(this, "No OpenPGP Provider selected!", Toast.LENGTH_LONG).show(); Toast.makeText(this, "No OpenPGP Provider selected!", Toast.LENGTH_LONG).show();
finish(); Intent intent = new Intent(this, UserPreference.class);
} else { startActivity(intent);
}
// bind to service // bind to service
mServiceConnection = new OpenPgpServiceConnection( mServiceConnection = new OpenPgpServiceConnection(
PgpHandler.this, providerPackageName); PgpHandler.this, providerPackageName);
mServiceConnection.bindToService(); mServiceConnection.bindToService();
} }
}
@Override @Override
@ -130,6 +129,52 @@ public class PgpHandler extends Activity {
}); });
} }
public class DelayShow extends AsyncTask<Void, Integer, Boolean> {
int count = 0;
final int SHOW_TIME = 10;
ProgressBar pb;
@Override
protected void onPreExecute() {
((LinearLayout) findViewById(R.id.crypto_password_show_layout)).setVisibility(View.VISIBLE);
TextView extraText = (TextView) findViewById(R.id.crypto_extra_show);
if (extraText.getText().length() != 0)
((LinearLayout) findViewById(R.id.crypto_extra_show_layout)).setVisibility(View.VISIBLE);
this.pb = (ProgressBar) findViewById(R.id.pbLoading);
this.pb.setVisibility(ProgressBar.VISIBLE);
this.pb.setMax(SHOW_TIME);
}
@Override
protected Boolean doInBackground(Void... params) {
while (this.count < SHOW_TIME) {
SystemClock.sleep(1000); this.count++;
publishProgress(this.count);
}
return true;
}
@Override
protected void onPostExecute(Boolean b) {
//clear password
((TextView) findViewById(R.id.crypto_password_show)).setText("");
((LinearLayout) findViewById(R.id.crypto_password_show_layout)).setVisibility(View.INVISIBLE);
((LinearLayout) findViewById(R.id.crypto_extra_show_layout)).setVisibility(View.INVISIBLE);
// run a background job and once complete
this.pb.setVisibility(ProgressBar.INVISIBLE);
}
@Override
protected void onProgressUpdate(Integer... values) {
this.pb.setProgress(values[0]);
}
}
private class MyCallback implements OpenPgpApi.IOpenPgpCallback { private class MyCallback implements OpenPgpApi.IOpenPgpCallback {
boolean returnToCiphertextField; boolean returnToCiphertextField;
ByteArrayOutputStream os; ByteArrayOutputStream os;
@ -152,11 +197,19 @@ public class PgpHandler extends Activity {
try { try {
Log.d(OpenPgpApi.TAG, "result: " + os.toByteArray().length Log.d(OpenPgpApi.TAG, "result: " + os.toByteArray().length
+ " str=" + os.toString("UTF-8")); + " str=" + os.toString("UTF-8"));
showToast(os.toString("UTF-8"));
if (returnToCiphertextField) { if (returnToCiphertextField) {
// mCiphertext.setText(os.toString("UTF-8")); String[] passContent = os.toString("UTF-8").split("\n");
((TextView) findViewById(R.id.crypto_password_show))
.setText(passContent[0]);
String extraContent = os.toString("UTF-8").replaceFirst(".*\n","");
if (extraContent.length() != 0) {
((TextView) findViewById(R.id.crypto_extra_show))
.setText(extraContent);
}
new DelayShow().execute();
} else { } else {
// mMessage.setText(os.toString("UTF-8")); showToast(os.toString());
} }
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
Log.e(Constants.TAG, "UnsupportedEncodingException", e); Log.e(Constants.TAG, "UnsupportedEncodingException", e);
@ -216,7 +269,7 @@ public class PgpHandler extends Activity {
ByteArrayOutputStream os = new ByteArrayOutputStream(); ByteArrayOutputStream os = new ByteArrayOutputStream();
OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService()); OpenPgpApi api = new OpenPgpApi(this, mServiceConnection.getService());
api.executeApiAsync(data, is, os, new MyCallback(false, os, REQUEST_CODE_DECRYPT_AND_VERIFY)); api.executeApiAsync(data, is, os, new MyCallback(true, os, REQUEST_CODE_DECRYPT_AND_VERIFY));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View file

@ -1,4 +1,4 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -6,58 +6,90 @@
android:paddingRight="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.zeapo.pwdstore.crypto.PgpHandler"> tools:context="com.zeapo.pwdstore.crypto.PgpHandler"
android:orientation="vertical"
<LinearLayout android:background="#eee">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<GridLayout <GridLayout
android:layout_width="fill_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:orientation="horizontal">
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="@android:color/holo_orange_dark"
android:text="Large Text" android:text="Large Text"
android:id="@+id/crypto_account_name" android:id="@+id/crypto_password_file"
android:layout_row="0" android:layout_gravity="center_vertical"
android:layout_column="0" /> android:layout_column="0"/>
<Button <ImageButton
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Change account" android:layout_column="2"
android:id="@+id/button" android:src="@android:drawable/ic_input_get"
android:layout_row="0" android:background="@android:drawable/screen_background_light_transparent"
android:layout_column="2" /> android:layout_gravity="center_vertical"
android:onClick="decrypt"/>
</GridLayout> </GridLayout>
<View <LinearLayout
android:layout_width="fill_parent" android:id="@+id/crypto_password_show_layout"
android:layout_marginBottom="4dp" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="wrap_content"
android:background="@android:color/darker_gray"/> android:visibility="invisible"
android:orientation="vertical"
android:background="@drawable/rectangle">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Password: "/>
<TextView
android:id="@+id/crypto_password_show"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:typeface="monospace"
android:layout_column="2"/>
</GridLayout>
<ProgressBar
android:id="@+id/pbLoading"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
style="?android:attr/progressBarStyleHorizontal"/>
</LinearLayout>
<LinearLayout
android:id="@+id/crypto_extra_show_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/rectangle"
android:orientation="vertical"
android:visibility="invisible">
<TextView <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Extra content: "/>
<TextView
android:id="@+id/crypto_extra_show"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="New Text" android:typeface="monospace"/>
android:id="@+id/crypto_handler_name"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select Key-id"
android:onClick="getKeyID"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Show password"
android:onClick="decrypt"/>
</LinearLayout> </LinearLayout>
</RelativeLayout> </LinearLayout>

View file

@ -1,4 +1,4 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -7,12 +7,42 @@
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin"
android:background="#eee" android:background="#eee"
tools:context=".pwdstore"> tools:context=".pwdstore"
android:orientation="vertical">
<LinearLayout <LinearLayout
android:id="@+id/main_layout" android:id="@+id/main_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical"></LinearLayout> android:orientation="vertical"
android:layout_row="0"></LinearLayout>
</RelativeLayout> <GridLayout
android:id="@+id/bottom_layout"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_row="2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/holo_orange_dark"
android:layout_gravity="center_vertical"
android:text="Large Text"
android:id="@+id/crypto_password_file"
android:background="#fff"
android:layout_marginBottom="@dimen/activity_vertical_margin"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_input_add"
android:background="@drawable/rectangle"
android:layout_gravity="center_vertical"
android:onClick="createPassword"
android:layout_column="2"/>
</GridLayout>
</GridLayout>

View file

@ -13,11 +13,13 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="8dp" android:padding="8dp"
android:textStyle="bold" android:textStyle="bold"
android:layout_gravity="center_vertical"
/> />
<TextView <TextView
android:id="@+id/label" android:id="@+id/label"
android:text="FILE_NAME" android:text="FILE_NAME"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="8dp"/> android:padding="8dp"/>
</GridLayout> </GridLayout>