use of zipkin2.Callback in project mapbox-events-android by mapbox.
the class TelemetryClientTest method receivesNoBodyPostingAnEventSuccessfully.
@Test
public void receivesNoBodyPostingAnEventSuccessfully() throws Exception {
Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
MapboxTelemetry.applicationContext = mockedContext;
TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent");
List<Event> theEvent = obtainAnEvent();
Callback mockedCallback = mock(Callback.class);
enqueueMockNoResponse(204);
telemetryClient.sendEvents(theEvent, mockedCallback);
assertResponseBodyEquals(null);
}
use of zipkin2.Callback in project mapbox-events-android by mapbox.
the class TelemetryClientTest method parsesInvalidMessageBodyResponseProperlyPostingAnEvent.
@Test
public void parsesInvalidMessageBodyResponseProperlyPostingAnEvent() throws Exception {
Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
MapboxTelemetry.applicationContext = mockedContext;
TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent");
List<Event> theEvent = obtainAnEvent();
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<String> bodyRef = new AtomicReference<>();
final AtomicBoolean failureRef = new AtomicBoolean();
Callback aCallback = provideACallback(latch, bodyRef, failureRef);
enqueueMockResponse(422, "invalidMessageBodyResponse.json");
telemetryClient.sendEvents(theEvent, aCallback);
latch.await();
assertTelemetryResponseEquals(bodyRef.get(), "Invalid message body, check the types and required properties of " + "the events you sent");
assertFalse(failureRef.get());
}
use of zipkin2.Callback in project mapbox-events-android by mapbox.
the class TelemetryClientTest method sendsUserAgentHeader.
@Test
public void sendsUserAgentHeader() throws Exception {
Context mockedContext = mock(Context.class, RETURNS_DEEP_STUBS);
MapboxTelemetry.applicationContext = mockedContext;
TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "theUserAgent");
List<Event> mockedEvent = obtainAnEvent();
Callback mockedCallback = mock(Callback.class);
enqueueMockResponse();
telemetryClient.sendEvents(mockedEvent, mockedCallback);
assertRequestContainsHeader("User-Agent", "theUserAgent");
}
use of zipkin2.Callback in project Alphago by Onedelay.
the class SendImageActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_send_image);
imageFile = (File) getIntent().getSerializableExtra("sendImage");
cropImageView = findViewById(R.id.cropImageView);
cropImageView.setImageUriAsync(Uri.fromFile(imageFile));
cropImageView.setAspectRatio(1, 1);
cropImageView.setFixedAspectRatio(true);
cropImageView.setCropShape(CropImageView.CropShape.RECTANGLE);
cropImageView.setAutoZoomEnabled(false);
cropImageView.setCropRect(new Rect(1000, 1000, 1000, 1000));
cropImageView.setOnCropImageCompleteListener(new CropImageView.OnCropImageCompleteListener() {
@Override
public void onCropImageComplete(CropImageView view, CropImageView.CropResult result) {
Bitmap bitmap = result.getBitmap();
if (bitmap != null) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
byte[] bitmapData = bos.toByteArray();
FileOutputStream fos = new FileOutputStream(imageFile);
fos.write(bitmapData);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
// onComplete(imageFile);
// new BitmapToFileTask(imageFile, SendImageActivity.this)
// .execute(bitmap);
AlphagoServer.getInstance().sendImage(getBaseContext(), imageFile, new Callback<ResponeImageLabel>() {
@Override
public void onResponse(Call<ResponeImageLabel> call, Response<ResponeImageLabel> response) {
if (response.body() != null) {
category = response.body().getCategory();
max_label = response.body().getResponseLabel();
ID = response.body().getID();
cate_ID = response.body().getCate_ID();
Intent intent = new Intent(getBaseContext(), ImageRecognitionActivity.class);
intent.putExtra("imageFile", imageFile);
intent.putExtra("category", category);
intent.putExtra("max_label", max_label);
intent.putExtra("ID", ID);
intent.putExtra("cate_ID", cate_ID);
frameLoading.setVisibility(View.GONE);
startActivity(intent);
finish();
}
}
@Override
public void onFailure(Call<ResponeImageLabel> call, Throwable t) {
frameLoading.setVisibility(View.GONE);
Toast.makeText(SendImageActivity.this, "서버 연결 안됨", Toast.LENGTH_SHORT).show();
t.printStackTrace();
}
});
}
});
findViewById(R.id.crop_image_menu_rotate_right).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cropImageView.rotateImage(90);
}
});
findViewById(R.id.btn_retry).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ImageSelectionMethodDialog().show(getSupportFragmentManager(), "dialog");
}
});
findViewById(R.id.btn_send).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
frameLoading.setVisibility(View.VISIBLE);
cropImageView.getCroppedImageAsync();
}
});
frameLoading = (FrameLayout) findViewById(R.id.frame_loading);
}
use of zipkin2.Callback in project runelite by runelite.
the class FeedPanel method addItemToPanel.
private void addItemToPanel(FeedItem item) {
JPanel avatarAndRight = new JPanel(new BorderLayout());
avatarAndRight.setPreferredSize(new Dimension(0, 56));
JLabel avatar = new JLabel();
// width = 48+4 to compensate for the border
avatar.setPreferredSize(new Dimension(52, 48));
avatar.setBorder(new EmptyBorder(0, 4, 0, 0));
switch(item.getType()) {
case TWEET:
try {
Request request = new Request.Builder().url(item.getAvatar()).build();
RuneLiteAPI.CLIENT.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
log.warn(null, e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
try (ResponseBody responseBody = response.body()) {
if (!response.isSuccessful()) {
log.warn("Failed to download image " + item.getAvatar());
return;
}
BufferedImage icon;
synchronized (ImageIO.class) {
icon = ImageIO.read(responseBody.byteStream());
}
avatar.setIcon(new ImageIcon(icon));
}
}
});
} catch (IllegalArgumentException | NullPointerException e) {
log.warn(null, e);
}
avatarAndRight.setBackground(TWEET_BACKGROUND);
break;
case OSRS_NEWS:
if (OSRS_ICON != null) {
avatar.setIcon(new ImageIcon(OSRS_ICON));
}
avatarAndRight.setBackground(OSRS_NEWS_BACKGROUND);
break;
default:
if (RUNELITE_ICON != null) {
avatar.setIcon(new ImageIcon(RUNELITE_ICON));
}
avatarAndRight.setBackground(BLOG_POST_BACKGROUND);
break;
}
JPanel upAndContent = new JPanel();
upAndContent.setLayout(new BoxLayout(upAndContent, BoxLayout.Y_AXIS));
upAndContent.setBorder(new EmptyBorder(4, 8, 4, 4));
upAndContent.setBackground(null);
JPanel titleAndTime = new JPanel();
titleAndTime.setLayout(new BorderLayout());
titleAndTime.setBackground(null);
Color darkerForeground = UIManager.getColor("Label.foreground").darker();
JLabel titleLabel = new JLabel(item.getTitle());
titleLabel.setFont(FontManager.getRunescapeSmallFont());
titleLabel.setBackground(null);
titleLabel.setForeground(darkerForeground);
titleLabel.setPreferredSize(new Dimension(CONTENT_WIDTH - TIME_WIDTH, 0));
Duration duration = Duration.between(Instant.ofEpochMilli(item.getTimestamp()), Instant.now());
JLabel timeLabel = new JLabel(durationToString(duration));
timeLabel.setFont(FontManager.getRunescapeSmallFont());
timeLabel.setForeground(darkerForeground);
titleAndTime.add(titleLabel, BorderLayout.WEST);
titleAndTime.add(timeLabel, BorderLayout.EAST);
JPanel content = new JPanel(new BorderLayout());
content.setBackground(null);
JLabel contentLabel = new JLabel(lineBreakText(item.getContent(), FontManager.getRunescapeSmallFont()));
contentLabel.setBorder(new EmptyBorder(2, 0, 0, 0));
contentLabel.setFont(FontManager.getRunescapeSmallFont());
contentLabel.setForeground(darkerForeground);
content.add(contentLabel, BorderLayout.CENTER);
upAndContent.add(titleAndTime);
upAndContent.add(content);
upAndContent.add(new Box.Filler(new Dimension(0, 0), new Dimension(0, Short.MAX_VALUE), new Dimension(0, Short.MAX_VALUE)));
avatarAndRight.add(avatar, BorderLayout.WEST);
avatarAndRight.add(upAndContent, BorderLayout.CENTER);
Color backgroundColor = avatarAndRight.getBackground();
Color hoverColor = backgroundColor.brighter().brighter();
Color pressedColor = hoverColor.brighter();
avatarAndRight.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
avatarAndRight.setBackground(hoverColor);
}
@Override
public void mouseExited(MouseEvent e) {
avatarAndRight.setBackground(backgroundColor);
}
@Override
public void mousePressed(MouseEvent e) {
avatarAndRight.setBackground(pressedColor);
}
@Override
public void mouseReleased(MouseEvent e) {
avatarAndRight.setBackground(hoverColor);
LinkBrowser.browse(item.getUrl());
}
});
add(avatarAndRight);
}
Aggregations