Search in sources :

Example 1 with ImageGetRequest

use of com.nutomic.syncthingandroid.http.ImageGetRequest in project syncthing-android by syncthing.

the class DrawerFragment method showQrCode.

/**
 * Gets QRCode and displays it in a Dialog.
 */
private void showQrCode() {
    RestApi restApi = mActivity.getApi();
    if (restApi == null) {
        Toast.makeText(mActivity, R.string.syncthing_terminated, Toast.LENGTH_SHORT).show();
        return;
    }
    try {
        String apiKey = restApi.getGui().apiKey;
        String deviceId = restApi.getLocalDevice().deviceID;
        URL url = restApi.getUrl();
        // The QRCode request takes one paramteer called "text", which is the text to be converted to a QRCode.
        new ImageGetRequest(mActivity, url, ImageGetRequest.QR_CODE_GENERATOR, apiKey, ImmutableMap.of("text", deviceId), qrCodeBitmap -> {
            mActivity.showQrCodeDialog(deviceId, qrCodeBitmap);
            mActivity.closeDrawer();
        }, error -> Toast.makeText(mActivity, R.string.could_not_access_deviceid, Toast.LENGTH_SHORT).show());
    } catch (Exception e) {
        Log.e(TAG, "showQrCode", e);
    }
}
Also used : ImageGetRequest(com.nutomic.syncthingandroid.http.ImageGetRequest) RestApi(com.nutomic.syncthingandroid.service.RestApi) URL(java.net.URL)

Aggregations

ImageGetRequest (com.nutomic.syncthingandroid.http.ImageGetRequest)1 RestApi (com.nutomic.syncthingandroid.service.RestApi)1 URL (java.net.URL)1