diff options
author | mar-v-in <github@rvin.mooo.com> | 2014-08-14 15:23:12 +0200 |
---|---|---|
committer | mar-v-in <github@rvin.mooo.com> | 2014-08-14 16:02:27 +0200 |
commit | 07d6a26778b69c5340f5bbf11dcab970c63783d4 (patch) | |
tree | df1d8a890b5ec9ece9a7e6da3d8ab580226ee16e /OpenKeychain/src/main | |
parent | 9fab740aadb76883105b61451c047fc1d4b27f1f (diff) | |
download | open-keychain-07d6a26778b69c5340f5bbf11dcab970c63783d4.tar.gz open-keychain-07d6a26778b69c5340f5bbf11dcab970c63783d4.tar.bz2 open-keychain-07d6a26778b69c5340f5bbf11dcab970c63783d4.zip |
add OnKeyChangedListener to KeySpinner
Diffstat (limited to 'OpenKeychain/src/main')
2 files changed, 41 insertions, 11 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java index 41566cffc..748cbca14 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/EncryptAsymmetricFragment.java @@ -101,15 +101,10 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi View view = inflater.inflate(R.layout.encrypt_asymmetric_fragment, container, false); mSign = (KeySpinner) view.findViewById(R.id.sign); - mSign.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + mSign.setOnKeyChangedListener(new KeySpinner.OnKeyChangedListener() { @Override - public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { - setSignatureKeyId(parent.getAdapter().getItemId(position)); - } - - @Override - public void onNothingSelected(AdapterView<?> parent) { - setSignatureKeyId(Constants.key.none); + public void onKeyChanged(long masterKeyId) { + setSignatureKeyId(masterKeyId); } }); mEncryptKeyView = (EncryptKeyCompletionView) view.findViewById(R.id.recipient_list); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java index b8d83311a..fe3c61197 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/KeySpinner.java @@ -10,6 +10,7 @@ import android.support.v4.widget.CursorAdapter; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.Spinner; import android.widget.SpinnerAdapter; @@ -23,27 +24,62 @@ import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.util.Log; public abstract class KeySpinner extends Spinner { + public interface OnKeyChangedListener { + public void onKeyChanged(long masterKeyId); + } + private long mSelectedKeyId; private SelectKeyAdapter mAdapter = new SelectKeyAdapter(); + private OnKeyChangedListener mListener; public KeySpinner(Context context) { super(context); + initView(); } public KeySpinner(Context context, AttributeSet attrs) { super(context, attrs); + initView(); } public KeySpinner(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + initView(); + } + + private void initView() { + setAdapter(mAdapter); + super.setOnItemSelectedListener(new OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + if (mListener != null) { + mListener.onKeyChanged(id); + } + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + if (mListener != null) { + mListener.onKeyChanged(Constants.key.none); + } + } + }); } public abstract Loader<Cursor> onCreateLoader(); @Override + public void setOnItemSelectedListener(OnItemSelectedListener listener) { + throw new UnsupportedOperationException(); + } + + public void setOnKeyChangedListener(OnKeyChangedListener listener) { + mListener = listener; + } + + @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); - setAdapter(mAdapter); if (getContext() instanceof FragmentActivity) { ((FragmentActivity) getContext()).getSupportLoaderManager().initLoader(hashCode(), null, new LoaderManager.LoaderCallbacks<Cursor>() { @Override @@ -97,8 +133,7 @@ public abstract class KeySpinner extends Spinner { @Override public long getItemId(int position) { - mCursor.moveToPosition(position); - return mCursor.getLong(mIndexMasterKeyId); + return ((Cursor) getItem(position)).getLong(mIndexMasterKeyId); } }; } |