diff options
| -rw-r--r-- | res/drawable/pubkey.xml | 4 | ||||
| -rw-r--r-- | res/layout/item_pubkey.xml | 2 | ||||
| -rw-r--r-- | res/values/strings.xml | 2 | ||||
| -rw-r--r-- | src/org/connectbot/PubkeyListActivity.java | 106 | 
4 files changed, 52 insertions, 62 deletions
| diff --git a/res/drawable/pubkey.xml b/res/drawable/pubkey.xml new file mode 100644 index 0000000..a77e97a --- /dev/null +++ b/res/drawable/pubkey.xml @@ -0,0 +1,4 @@ +<selector xmlns:android="http://schemas.android.com/apk/res/android"> +	<item android:state_checked="true" android:drawable="@drawable/pubkey_locked" /> +	<item android:drawable="@drawable/pubkey_unlocked" /> +</selector>
\ No newline at end of file diff --git a/res/layout/item_pubkey.xml b/res/layout/item_pubkey.xml index 7678982..218b57c 100644 --- a/res/layout/item_pubkey.xml +++ b/res/layout/item_pubkey.xml @@ -51,7 +51,7 @@  		android:id="@android:id/icon1"  		android:layout_width="wrap_content"  		android:layout_height="wrap_content" -		android:src="@drawable/pubkey_locked" +		android:src="@drawable/pubkey"  		android:layout_gravity="right"  		/> diff --git a/res/values/strings.xml b/res/values/strings.xml index 6f08626..fed7924 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -29,7 +29,7 @@      <string name="pubkey_copy_clipboard">Copy to clipboard for OpenSSH</string>      <string name="pubkey_list_empty">Press "Menu" to create public keys.</string>      <string name="pubkey_unknown_format">Unknown format</string> -    <string name="pubkey_change_password">Change Psassword</string> +    <string name="pubkey_change_password">Change Password</string>      <string name="prompt_old_password">Old password:</string>      <string name="prompt_password">Password:</string> diff --git a/src/org/connectbot/PubkeyListActivity.java b/src/org/connectbot/PubkeyListActivity.java index 3330572..095a1d8 100644 --- a/src/org/connectbot/PubkeyListActivity.java +++ b/src/org/connectbot/PubkeyListActivity.java @@ -25,7 +25,6 @@ import org.connectbot.util.PubkeyDatabase;  import org.connectbot.util.PubkeyUtils;  import android.app.AlertDialog; -import android.app.Dialog;  import android.app.ListActivity;  import android.content.Context;  import android.content.DialogInterface; @@ -41,16 +40,15 @@ import android.view.LayoutInflater;  import android.view.Menu;  import android.view.MenuItem;  import android.view.View; -import android.view.ViewGroup;  import android.view.MenuItem.OnMenuItemClickListener;  import android.widget.AdapterView; -import android.widget.CursorAdapter;  import android.widget.EditText;  import android.widget.ImageView; -import android.widget.LinearLayout;  import android.widget.ListView; +import android.widget.SimpleCursorAdapter;  import android.widget.TableRow;  import android.widget.TextView; +import android.widget.SimpleCursorAdapter.ViewBinder;  public class PubkeyListActivity extends ListActivity implements EventListener {  	public final static String TAG = PubkeyListActivity.class.toString(); @@ -64,8 +62,6 @@ public class PubkeyListActivity extends ListActivity implements EventListener {  	protected LayoutInflater inflater = null; -	protected Dialog changePasswordDialog; -  	@Override      public void onStart() {  		super.onStart(); @@ -78,6 +74,14 @@ public class PubkeyListActivity extends ListActivity implements EventListener {  	}  	@Override +    public void onStop() { +		super.onStop(); +	 +		if(this.pubkeydb != null) +			this.pubkeydb.close(); +	} +	 +	@Override  	public void onCreate(Bundle icicle) {  		super.onCreate(icicle);  		setContentView(R.layout.act_pubkeylist); @@ -219,68 +223,50 @@ public class PubkeyListActivity extends ListActivity implements EventListener {  	};  	protected void updateCursor() { -		/*  		if (this.pubkeys != null)  			pubkeys.requery(); -		*/ -		// refresh cursor because of possible sorting change -		if(this.pubkeys != null) -			this.pubkeys.close(); -		if(this.pubkeydb == null) return; + +		if (this.pubkeydb == null) return;  		this.pubkeys = this.pubkeydb.allPubkeys(); -		this.setListAdapter(new PubkeyCursorAdapter(this, this.pubkeys)); -		//this.startManagingCursor(pubkeys); -	} -	 -	class PubkeyCursorAdapter extends CursorAdapter { -		private final LayoutInflater mInflater; -		private final int mNickname; -		private final int mPubkey; -		private final int mKeyType; -		private final int mEncrypted; -		public PubkeyCursorAdapter(Context context, Cursor c) { -			super(context, c); -			 -            mInflater = LayoutInflater.from(context); -            mNickname = c.getColumnIndexOrThrow(PubkeyDatabase.FIELD_PUBKEY_NICKNAME); -            mPubkey = c.getColumnIndexOrThrow(PubkeyDatabase.FIELD_PUBKEY_PUBLIC); -            mEncrypted = c.getColumnIndexOrThrow(PubkeyDatabase.FIELD_PUBKEY_ENCRYPTED); -            mKeyType = c.getColumnIndexOrThrow(PubkeyDatabase.FIELD_PUBKEY_TYPE); -		} - -		@Override -		public void bindView(View view, Context context, Cursor cursor) { -			TextView text1 = (TextView) view.findViewById(android.R.id.text1); -			TextView text2 = (TextView) view.findViewById(android.R.id.text2); -			ImageView icon1 = (ImageView) view.findViewById(android.R.id.icon1); -			 -			text1.setText(cursor.getString(mNickname)); +		SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item_pubkey, this.pubkeys, +				new String[] { PubkeyDatabase.FIELD_PUBKEY_NICKNAME, PubkeyDatabase.FIELD_PUBKEY_TYPE, PubkeyDatabase.FIELD_PUBKEY_ENCRYPTED }, +				new int[] { android.R.id.text1, android.R.id.text2, android.R.id.icon1 }); +		adapter.setViewBinder(new PubkeyBinder()); +		this.setListAdapter(adapter); -			String keyType = cursor.getString(mKeyType); -			int encrypted = cursor.getInt(mEncrypted); -			PublicKey pk; -			try { -				pk = PubkeyUtils.decodePublic(cursor.getBlob(mPubkey), keyType); -				text2.setText(PubkeyUtils.describeKey(pk, encrypted)); -			} catch (Exception e) { -				e.printStackTrace(); +		this.startManagingCursor(pubkeys); +	} +	 +	class PubkeyBinder implements ViewBinder { +		public boolean setViewValue(View view, Cursor cursor, int columnIndex) {			 +			switch (view.getId()) { +			case android.R.id.text2: +				int encrypted = cursor.getInt(cursor.getColumnIndexOrThrow(PubkeyDatabase.FIELD_PUBKEY_ENCRYPTED)); +				 +				PublicKey pub; +				try { +					pub = PubkeyUtils.decodePublic(cursor.getBlob(cursor.getColumnIndexOrThrow(PubkeyDatabase.FIELD_PUBKEY_PUBLIC)), +							cursor.getString(columnIndex)); +					((TextView)view).setText(PubkeyUtils.describeKey(pub, encrypted)); +				} catch (Exception e) { +					e.printStackTrace(); +					 +					((TextView)view).setText(R.string.pubkey_unknown_format); +					Log.e(TAG, "Error decoding public key at " + cursor.toString()); +				} +				return true; -				text2.setText(R.string.pubkey_unknown_format); -				Log.e(TAG, "Error decoding public key at " + cursor.toString()); +			case android.R.id.icon1: +				if (cursor.getInt(columnIndex) != 0) +					((ImageView)view).setImageState(new int[] { android.R.attr.state_checked }, true); +				else +					((ImageView)view).setImageState(new int[] {  }, true); +				return true;  			} -			if (encrypted == 0) -				icon1.setImageResource(R.drawable.pubkey_unlocked); -		} - -		@Override -		public View newView(Context context, Cursor cursor, ViewGroup parent) { -            final LinearLayout view = (LinearLayout) mInflater.inflate( -                    R.layout.item_pubkey, parent, false); -            return view; -		} +			return false; +		}	  	} -  } | 
