mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-01-31 23:20:20 -05:00
add OnKeyChangedListener to KeySpinner
This commit is contained in:
parent
9fab740aad
commit
07d6a26778
@ -101,15 +101,10 @@ public class EncryptAsymmetricFragment extends Fragment implements EncryptActivi
|
|||||||
View view = inflater.inflate(R.layout.encrypt_asymmetric_fragment, container, false);
|
View view = inflater.inflate(R.layout.encrypt_asymmetric_fragment, container, false);
|
||||||
|
|
||||||
mSign = (KeySpinner) view.findViewById(R.id.sign);
|
mSign = (KeySpinner) view.findViewById(R.id.sign);
|
||||||
mSign.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
mSign.setOnKeyChangedListener(new KeySpinner.OnKeyChangedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onKeyChanged(long masterKeyId) {
|
||||||
setSignatureKeyId(parent.getAdapter().getItemId(position));
|
setSignatureKeyId(masterKeyId);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNothingSelected(AdapterView<?> parent) {
|
|
||||||
setSignatureKeyId(Constants.key.none);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mEncryptKeyView = (EncryptKeyCompletionView) view.findViewById(R.id.recipient_list);
|
mEncryptKeyView = (EncryptKeyCompletionView) view.findViewById(R.id.recipient_list);
|
||||||
|
@ -10,6 +10,7 @@ import android.support.v4.widget.CursorAdapter;
|
|||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.SpinnerAdapter;
|
import android.widget.SpinnerAdapter;
|
||||||
@ -23,27 +24,62 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
|
|||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public abstract class KeySpinner extends Spinner {
|
public abstract class KeySpinner extends Spinner {
|
||||||
|
public interface OnKeyChangedListener {
|
||||||
|
public void onKeyChanged(long masterKeyId);
|
||||||
|
}
|
||||||
|
|
||||||
private long mSelectedKeyId;
|
private long mSelectedKeyId;
|
||||||
private SelectKeyAdapter mAdapter = new SelectKeyAdapter();
|
private SelectKeyAdapter mAdapter = new SelectKeyAdapter();
|
||||||
|
private OnKeyChangedListener mListener;
|
||||||
|
|
||||||
public KeySpinner(Context context) {
|
public KeySpinner(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeySpinner(Context context, AttributeSet attrs) {
|
public KeySpinner(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeySpinner(Context context, AttributeSet attrs, int defStyle) {
|
public KeySpinner(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, 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();
|
public abstract Loader<Cursor> onCreateLoader();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOnItemSelectedListener(OnItemSelectedListener listener) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnKeyChangedListener(OnKeyChangedListener listener) {
|
||||||
|
mListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAttachedToWindow() {
|
protected void onAttachedToWindow() {
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
setAdapter(mAdapter);
|
|
||||||
if (getContext() instanceof FragmentActivity) {
|
if (getContext() instanceof FragmentActivity) {
|
||||||
((FragmentActivity) getContext()).getSupportLoaderManager().initLoader(hashCode(), null, new LoaderManager.LoaderCallbacks<Cursor>() {
|
((FragmentActivity) getContext()).getSupportLoaderManager().initLoader(hashCode(), null, new LoaderManager.LoaderCallbacks<Cursor>() {
|
||||||
@Override
|
@Override
|
||||||
@ -97,8 +133,7 @@ public abstract class KeySpinner extends Spinner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position) {
|
public long getItemId(int position) {
|
||||||
mCursor.moveToPosition(position);
|
return ((Cursor) getItem(position)).getLong(mIndexMasterKeyId);
|
||||||
return mCursor.getLong(mIndexMasterKeyId);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user