use of mpicbg.trakem2.util.Pair in project streamline by hortonworks.
the class StormServiceRegistrar method createStormUIServerComponent.
private Pair<Component, List<ComponentProcess>> createStormUIServerComponent(Config config, Map<String, String> flattenConfigMap) {
if (!config.contains(PARAM_UI_HOST)) {
throw new IllegalArgumentException("Required parameter " + PARAM_UI_HOST + " not present.");
}
if (!config.contains(PARAM_UI_PORT)) {
throw new IllegalArgumentException("Required parameter " + PARAM_UI_PORT + " not present.");
}
String stormUiServerHost;
try {
stormUiServerHost = config.getString(PARAM_UI_HOST);
} catch (ClassCastException e) {
throw new IllegalArgumentException("Required parameter " + PARAM_UI_HOST + " should be a string.");
}
Number stormUiServerPort = readNumberFromConfig(config, PARAM_UI_PORT);
Component stormUiServer = new Component();
stormUiServer.setName(COMPONENT_STORM_UI_SERVER);
ComponentProcess uiProcess = new ComponentProcess();
uiProcess.setHost(stormUiServerHost);
uiProcess.setPort(stormUiServerPort.intValue());
return new Pair<>(stormUiServer, Collections.singletonList(uiProcess));
}
use of mpicbg.trakem2.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 mpicbg.trakem2.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 mpicbg.trakem2.util.Pair in project android_packages_apps_Dialer by LineageOS.
the class CopyAndResizeImageWorker method doInBackground.
/**
* @param input The filepath where the image is located.
* @return a Pair where the File contains the resized image, and the String is the result File's
* MIME type.
*/
@Nullable
@Override
public Pair<File, String> doInBackground(@Nullable Uri input) throws Throwable {
// BitmapFactory.decodeStream strips exif data, so we need to save it here and apply it later.
int rotation = 0;
try {
rotation = new ExifInterface(input.getPath()).getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
} catch (Exception ignored) {
// Couldn't get exif tags, not the end of the world
}
try (InputStream inputStream = context.getContentResolver().openInputStream(input)) {
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
bitmap = BitmapResizer.resizeForEnrichedCalling(bitmap, exifToDegrees(rotation));
File outputFile = DialerUtils.createShareableFile(context);
try (OutputStream outputStream = new FileOutputStream(outputFile)) {
// Encode images to jpeg as it is better for camera pictures which we expect to be sending
bitmap.compress(CompressFormat.JPEG, 80, outputStream);
return new Pair<>(outputFile, MIME_TYPE);
}
}
}
use of mpicbg.trakem2.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);
}
});
}
Aggregations