use of net.imglib2.util.Pair in project krypton-android by kryptco.
the class ApprovalDialog method showApprovalDialog.
public static void showApprovalDialog(final Activity activity, final String requestID) {
Pair<Pairing, Request> pendingRequestAndPairing = Policy.getPendingRequestAndPairing(requestID);
if (pendingRequestAndPairing == null) {
Log.e(TAG, "user clicked notification for unknown request");
return;
}
Pairing pairing = pendingRequestAndPairing.first;
Request request = pendingRequestAndPairing.second;
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setIcon(R.mipmap.ic_launcher);
// setPositiveButton: right button
// setNeutralButton: left button
// setNegativeButton: middle button
long temporaryApprovalSeconds = Policy.temporaryApprovalSeconds(activity, request);
boolean temporaryApprovalEnabled = temporaryApprovalSeconds > 0;
String temporaryApprovalDuration = Policy.temporaryApprovalDuration(activity, request);
request.body.visit(new RequestBody.Visitor<Void, RuntimeException>() {
@Override
public Void visit(MeRequest meRequest) throws RuntimeException {
return null;
}
@Override
public Void visit(SignRequest signRequest) throws RuntimeException {
builder.setPositiveButton("Once", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
if (temporaryApprovalEnabled) {
builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
if (signRequest.hostNameVerified) {
builder.setNegativeButton("This host for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_THIS_TEMPORARILY));
}
}
return null;
}
@Override
public Void visit(GitSignRequest gitSignRequest) throws RuntimeException {
builder.setPositiveButton("Once", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
if (temporaryApprovalEnabled) {
builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
}
return null;
}
@Override
public Void visit(UnpairRequest unpairRequest) throws RuntimeException {
return null;
}
@Override
public Void visit(HostsRequest hostsRequest) throws RuntimeException {
builder.setPositiveButton("Allow", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
if (temporaryApprovalEnabled) {
builder.setNeutralButton("All for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
}
return null;
}
@Override
public Void visit(ReadTeamRequest readTeamRequest) throws RuntimeException {
builder.setPositiveButton("Allow for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
return null;
}
@Override
public Void visit(LogDecryptionRequest logDecryptionRequest) throws RuntimeException {
builder.setPositiveButton("Allow for " + temporaryApprovalDuration, (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ALL_TEMPORARILY));
return null;
}
@Override
public Void visit(TeamOperationRequest teamOperationRequest) throws RuntimeException {
builder.setPositiveButton("Allow", (dialog, id) -> Policy.onAction(activity.getApplicationContext(), requestID, Policy.APPROVE_ONCE));
return null;
}
});
builder.setOnDismissListener(dialogInterface -> {
Policy.onAction(activity.getApplicationContext(), requestID, Policy.REJECT);
});
View requestView = activity.getLayoutInflater().inflate(R.layout.request, null);
TextView workstationNameText = (TextView) requestView.findViewById(R.id.workstationName);
workstationNameText.setText(pairing.workstationName);
ConstraintLayout content = (ConstraintLayout) requestView.findViewById(R.id.content);
request.fillView(content);
builder.setView(requestView);
builder.create().show();
}
use of net.imglib2.util.Pair in project krypton-android by kryptco.
the class RSASSHKeyPair method getSignerAndPrepareData.
public Pair<Signature, byte[]> getSignerAndPrepareData(String digest, byte[] data) throws CryptoException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
KeyFactory factory = KeyFactory.getInstance(keyPair.getPrivate().getAlgorithm(), "AndroidKeyStore");
KeyInfo keyInfo;
keyInfo = factory.getKeySpec(keyPair.getPrivate(), KeyInfo.class);
Signature signer;
if (Arrays.asList(keyInfo.getDigests()).contains(digest)) {
switch(digest) {
case KeyProperties.DIGEST_SHA1:
signer = Signature.getInstance("SHA1withRSA");
break;
case KeyProperties.DIGEST_SHA256:
signer = Signature.getInstance("SHA256withRSA");
break;
case KeyProperties.DIGEST_SHA512:
signer = Signature.getInstance("SHA512withRSA");
break;
default:
throw new CryptoException("Unsupported digest: " + digest);
}
} else {
// fall back to NONEwithRSA for backwards compatibility
signer = Signature.getInstance("NONEwithRSA");
switch(digest) {
case KeyProperties.DIGEST_SHA1:
data = SHA1.digestPrependingOID(data);
break;
case KeyProperties.DIGEST_SHA256:
data = SHA256.digestPrependingOID(data);
break;
case KeyProperties.DIGEST_SHA512:
data = SHA512.digestPrependingOID(data);
break;
default:
throw new CryptoException("Unsupported digest: " + digest);
}
}
return new Pair<>(signer, data);
}
use of net.imglib2.util.Pair in project Tusky by tuskyapp.
the class TimelineFragment method onReblog.
@Override
public void onReblog(final boolean reblog, final int position) {
final Status status = statuses.get(position).getAsRight();
timelineCases.reblogWithCallback(status, reblog, new Callback<Status>() {
@Override
public void onResponse(@NonNull Call<Status> call, @NonNull Response<Status> response) {
if (response.isSuccessful()) {
status.setReblogged(reblog);
if (status.getReblog() != null) {
status.getReblog().setReblogged(reblog);
}
Pair<StatusViewData.Concrete, Integer> actual = findStatusAndPosition(position, status);
if (actual == null)
return;
StatusViewData newViewData = new StatusViewData.Builder(actual.first).setReblogged(reblog).createStatusViewData();
statuses.setPairedItem(actual.second, newViewData);
adapter.changeItem(actual.second, newViewData, false);
}
}
@Override
public void onFailure(@NonNull Call<Status> call, @NonNull Throwable t) {
Log.d(TAG, "Failed to reblog status " + status.getId(), t);
}
});
}
use of net.imglib2.util.Pair in project Tusky by tuskyapp.
the class TimelineFragment method findStatusAndPosition.
@Nullable
private Pair<StatusViewData.Concrete, Integer> findStatusAndPosition(int position, Status status) {
StatusViewData.Concrete statusToUpdate;
int positionToUpdate;
StatusViewData someOldViewData = statuses.getPairedItem(position);
// Unlikely, but data could change between the request and response
if ((someOldViewData instanceof StatusViewData.Placeholder) || !((StatusViewData.Concrete) someOldViewData).getId().equals(status.getId())) {
// try to find the status we need to update
int foundPos = statuses.indexOf(Either.<Placeholder, Status>right(status));
// okay, it's hopeless, give up
if (foundPos < 0)
return null;
statusToUpdate = ((StatusViewData.Concrete) statuses.getPairedItem(foundPos));
positionToUpdate = position;
} else {
statusToUpdate = (StatusViewData.Concrete) someOldViewData;
positionToUpdate = position;
}
return new Pair<>(statusToUpdate, positionToUpdate);
}
use of net.imglib2.util.Pair in project LibreraReader by foobnix.
the class CacheZipUtils method isSingleAndSupportEntry.
public static Pair<Boolean, String> isSingleAndSupportEntry(InputStream is) {
if (is == null) {
return new Pair<Boolean, String>(false, "");
}
String name = "";
try {
ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(is, "cp1251");
boolean find = false;
ZipArchiveEntry nextEntry = null;
while ((nextEntry = zipInputStream.getNextZipEntry()) != null) {
name = nextEntry.getName();
if (find) {
zipInputStream.close();
is.close();
return new Pair<Boolean, String>(false, "");
}
find = true;
}
zipInputStream.close();
is.close();
} catch (Exception e) {
LOG.e(e);
}
return new Pair<Boolean, String>(BookType.isSupportedExtByPath(name), name);
}
Aggregations