Search in sources :

Example 1 with QrGenAsyncTask

use of org.fdroid.fdroid.QrGenAsyncTask in project fdroidclient by f-droid.

the class WifiQrView method setUIFromWifi.

private void setUIFromWifi() {
    if (TextUtils.isEmpty(FDroidApp.repo.address)) {
        return;
    }
    String scheme = Preferences.get().isLocalRepoHttpsEnabled() ? "https://" : "http://";
    // the fingerprint is not useful on the button label
    String buttonLabel = scheme + FDroidApp.ipAddressString + ":" + FDroidApp.port;
    TextView ipAddressView = (TextView) findViewById(R.id.device_ip_address);
    ipAddressView.setText(buttonLabel);
    Uri sharingUri = Utils.getSharingUri(FDroidApp.repo);
    String qrUriString = scheme + sharingUri.getHost();
    if (sharingUri.getPort() != 80) {
        qrUriString += ":" + sharingUri.getPort();
    }
    qrUriString += sharingUri.getPath();
    boolean first = true;
    // Andorid provides an API for getting the query parameters and iterating over them:
    // Uri.getQueryParameterNames()
    // But it is only available on later Android versions. As such we use URLEncodedUtils instead.
    List<NameValuePair> parameters = URLEncodedUtils.parse(URI.create(sharingUri.toString()), "UTF-8");
    for (NameValuePair parameter : parameters) {
        if (!"ssid".equals(parameter.getName())) {
            if (first) {
                qrUriString += "?";
                first = false;
            } else {
                qrUriString += "&";
            }
            qrUriString += parameter.getName().toUpperCase(Locale.ENGLISH) + "=" + parameter.getValue().toUpperCase(Locale.ENGLISH);
        }
    }
    Utils.debugLog(TAG, "Encoded swap URI in QR Code: " + qrUriString);
    new QrGenAsyncTask(getActivity(), R.id.wifi_qr_code).execute(qrUriString);
}
Also used : NameValuePair(org.apache.http.NameValuePair) TextView(android.widget.TextView) Uri(android.net.Uri) QrGenAsyncTask(org.fdroid.fdroid.QrGenAsyncTask)

Aggregations

Uri (android.net.Uri)1 TextView (android.widget.TextView)1 NameValuePair (org.apache.http.NameValuePair)1 QrGenAsyncTask (org.fdroid.fdroid.QrGenAsyncTask)1