当前位置: 首页>>代码示例>>Java>>正文


Java Shared类代码示例

本文整理汇总了Java中ru.ok.android.sdk.Shared的典型用法代码示例。如果您正苦于以下问题:Java Shared类的具体用法?Java Shared怎么用?Java Shared使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Shared类属于ru.ok.android.sdk包,在下文中一共展示了Shared类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: login

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
@ReactMethod
public void login(final ReadableArray scope, final Promise promise) {
    int scopeSize = scope.size();
    final String[] scopeArray = new String[scopeSize];
    for (int i = 0; i < scopeSize; i++) {
        scopeArray[i] = scope.getString(i);
    }
    loginPromise = promise;
    odnoklassniki.checkValidTokens(new OkListener() {
        @Override
        public void onSuccess(JSONObject json) {
            Log.d(LOG, "Check valid token success");
            resolveWithCurrentUser(json.optString(Shared.PARAM_ACCESS_TOKEN), json.optString(Shared.PARAM_SESSION_SECRET_KEY));
        }

        @Override
        public void onError(String error) {
            Log.d(LOG, "Valid token wasn't found at login, requesting authorization");
            odnoklassniki.requestAuthorization(getCurrentActivity(), redirectUri, OkAuthType.ANY, scopeArray);
        }
    });
}
 
开发者ID:doomsower,项目名称:react-native-odnoklassniki-login,代码行数:23,代码来源:RNOdnoklassnikiModule.java

示例2: fromJson

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
private List<Transaction> fromJson(String source) {
    List<Transaction> transactions = new ArrayList<>();

    if (source != null && !source.isEmpty()) {
        try {
            JSONArray json = new JSONArray(source);
            for (int i = 0; i < json.length(); i++) {
                JSONObject obj = json.getJSONObject(i);
                Transaction trx = new Transaction();

                trx.id = obj.getString(TRX_ID);
                trx.amount = obj.getString(AMOUNT);
                trx.currency = obj.getString(CURRENCY);
                trx.tries = obj.optInt(TRIES);

                transactions.add(trx);
            }
        } catch (JSONException e) {
            Log.e(Shared.LOG_TAG, "Reading TRX queue from " + source + ": " + e.getMessage(), e);
        }
    }
    return transactions;
}
 
开发者ID:odnoklassniki,项目名称:ok-android-sdk,代码行数:24,代码来源:OkPayment.java

示例3: getAuthListener

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
@NonNull
private OkListener getAuthListener() {
    return new OkListener() {
        @Override
        public void onSuccess(final JSONObject json) {
            Log.d(LOG, "Activity auth success");
            resolveWithCurrentUser(json.optString(Shared.PARAM_ACCESS_TOKEN), json.optString(Shared.PARAM_SESSION_SECRET_KEY));
        }

        @Override
        public void onError(String error) {
            Log.d(LOG, "OK Oauth error " + error);
            loginPromise.reject(E_LOGIN_ERROR, error);
        }
    };
}
 
开发者ID:doomsower,项目名称:react-native-odnoklassniki-login,代码行数:17,代码来源:RNOdnoklassnikiModule.java

示例4: resolveWithCurrentUser

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
private void resolveWithCurrentUser(final String accessToken, final String sessionSecretKey){
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                String userStr = odnoklassniki.request("users.getCurrentUser", "get");
                JSONObject user = new JSONObject(userStr);
                WritableMap result = Arguments.createMap();
                result.putString(Shared.PARAM_ACCESS_TOKEN, accessToken);
                result.putString(Shared.PARAM_SESSION_SECRET_KEY, sessionSecretKey);
                result.putMap("user", JSONUtil.convertMap(user));
                loginPromise.resolve(result);
            } catch (Exception e) {
                loginPromise.reject(E_GET_USER_FAILED, "users.getLoggedInUser failed: " + e.getLocalizedMessage());
            }
        }
    }).start();
}
 
开发者ID:doomsower,项目名称:react-native-odnoklassniki-login,代码行数:19,代码来源:RNOdnoklassnikiModule.java

示例5: toJson

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
private String toJson() {
    JSONArray json = new JSONArray();
    try {
        for (Transaction trx : queue) {
            JSONObject obj = new JSONObject();

            obj.put(TRX_ID, trx.id);
            obj.put(AMOUNT, trx.amount);
            obj.put(CURRENCY, trx.currency);
            if (trx.tries > 0) {
                obj.put(TRIES, trx.tries);
            }

            json.put(obj);
        }
    } catch (JSONException e) {
        Log.e(Shared.LOG_TAG, "Writing transactions queue: " + e.getMessage(), e);
    }
    return json.toString();
}
 
开发者ID:odnoklassniki,项目名称:ok-android-sdk,代码行数:21,代码来源:OkPayment.java

示例6: inputStreamToString

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
private static String inputStreamToString(final InputStream is, int contentLength) throws IOException {
    final StringBuilder sb = new StringBuilder(Math.max(contentLength, 128));
    final char[] buffer = new char[0x1000];
    final Reader in = new InputStreamReader(is, Shared.ENCODING);
    try {
        int read;
        do {
            read = in.read(buffer, 0, buffer.length);
            if (read > 0) {
                sb.append(buffer, 0, read);
            }
        } while (read >= 0);
    } finally {
        closeSilently(in);
    }
    return sb.toString();
}
 
开发者ID:odnoklassniki,项目名称:ok-android-sdk,代码行数:18,代码来源:OkRequestUtil.java

示例7: doInBackground

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
@Override
protected String doInBackground(final Void... params) {
    try {
        OKRestHelper helper = new OKRestHelper(odnoklassniki);
        if (!helper.sdkInit(MainActivity.this)) {
            Toast.makeText(MainActivity.this, "sdk.sendNote: no sdk token available", Toast.LENGTH_SHORT).show();
            return null;
        }
        JSONObject note = new JSONObject();
        note.put("uid", "12345678");
        note.put("image", "http://domain.tld/img.png");
        note.put("message", "Hello World from Android SDK!");
        note.put("payload", "SGVsbG8gd29ybGQhISE=");
        helper.sdkSendNote(note, new OkListener() {
            @Override
            public void onSuccess(JSONObject json) {
                String text = json == null ? null : json.toString();
                Toast.makeText(MainActivity.this, "sdk.sendNote: OK " + text, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onError(String error) {
                Toast.makeText(MainActivity.this, "sdk.sendNote: ERROR " + error, Toast.LENGTH_SHORT).show();
            }
        });
    } catch (Exception e) {
        Log.e(Shared.LOG_TAG, "sdk.sendNote " + e.getMessage(), e);
    }
    return null;
}
 
开发者ID:odnoklassniki,项目名称:ok-android-sdk,代码行数:31,代码来源:MainActivity.java

示例8: doInBackground

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... params) {
    Map<String, String> map = new HashMap<>();
    Transaction trx;

    while ((trx = queue.peek()) != null) {
        map.clear();
        map.put("trx_id", trx.id);
        map.put("amount", trx.amount);
        map.put("currency", trx.currency);

        try {
            String response = Odnoklassniki.getInstance().request("sdk.reportPayment",
                    map, EnumSet.of(OkRequestMode.SIGNED));
            JSONObject json = new JSONObject(response);
            if (json.optBoolean("result")) {
                queue.remove();
                persist();
                continue;
            }

        } catch (IOException | JSONException e) {
            Log.d(Shared.LOG_TAG, "Failed to report TRX " + map + ", retry queued: " + e.getMessage(), e);
        }

        trx.tries++;
        if (trx.tries > MAX_RETRY_COUNT) {
            Log.w(Shared.LOG_TAG, "Reporting TRX " + map + " failed " + trx.tries + " times, cancelling");
            queue.remove();
            persist();
            continue;
        }
        persist();

        break;
    }
    return null;
}
 
开发者ID:odnoklassniki,项目名称:ok-android-sdk,代码行数:39,代码来源:OkPayment.java

示例9: encode

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
public static final String encode(String str) {
    try {
        return URLEncoder.encode(str, Shared.ENCODING);
    } catch (UnsupportedEncodingException e) {
        //should never be called
        Log.e(Shared.LOG_TAG, e.getLocalizedMessage());
    }
    return null;
}
 
开发者ID:odnoklassniki,项目名称:ok-android-sdk,代码行数:10,代码来源:OkRequestUtil.java

示例10: executeRequest

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
public static final String executeRequest(Map<String, String> params) throws IOException {
    if (params == null ||
            !params.containsKey(Shared.PARAM_METHOD) ||
            !params.containsKey(Shared.PARAM_APP_KEY)) {
        return null;
    }

    return new Request(params).execute();
}
 
开发者ID:odnoklassniki,项目名称:ok-android-sdk,代码行数:10,代码来源:OkRequestUtil.java

示例11: execute

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
String execute() throws IOException {
    URL url = new URL(Odnoklassniki.getInstance().getApiBaseUrl() + "fb.do");
    final HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setReadTimeout(timeout);
    connection.setConnectTimeout(timeout + 5000);
    connection.setRequestMethod("POST");
    connection.setUseCaches(false);
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setRequestProperty("Connection", "Keep-Alive");

    final ArrayList<String> queryParameters = new ArrayList<>(params.size());
    for (Pair<String, String> pair : params) {
        if (pair.first == null || pair.second == null) {
            continue;
        }
        queryParameters.add(String.format("%s=%s", URLEncoder.encode(pair.first, Shared.ENCODING), URLEncoder.encode(pair.second, Shared.ENCODING)));
    }

    final String query = TextUtils.join("&", queryParameters);
    if (query.length() > 0) {
        final OutputStream os = connection.getOutputStream();
        final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, Shared.ENCODING));

        writer.write(query);
        writer.flush();

        writer.close();
        os.close();
    }

    return inputStreamToString(connection.getInputStream(), connection.getContentLength());
}
 
开发者ID:odnoklassniki,项目名称:ok-android-sdk,代码行数:34,代码来源:OkRequestUtil.java

示例12: encode

import ru.ok.android.sdk.Shared; //导入依赖的package包/类
public static final String encode(String str) {
    try {
        return URLEncoder.encode(str, DEFAULT_ENCODING);
    } catch (UnsupportedEncodingException e) {
        //should never be called
        Log.e(Shared.LOG_TAG, e.getLocalizedMessage());
    }
    return null;
}
 
开发者ID:DrMoriarty,项目名称:cordova-social-ok,代码行数:10,代码来源:OkRequestUtil.java


注:本文中的ru.ok.android.sdk.Shared类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。