Search in sources :

Example 71 with Callback

use of retrofit2.Callback in project Gradle-demo by Arisono.

the class testUASApi method addMobileMac.

public static void addMobileMac(String method) {
    //master=USOFTSYS, emcode=U0316, sessionUser=U0316, sessionId=29DB60DE6E40D859B9169FE5013A8520, macAddress=3c:b6:b7:64:a7:ea
    String url = baseurl + "mobile/addMobileMac.action";
    RequestBody formBody = new FormBody.Builder().add("master", master).add("emcode", emcode).add("macAddress", "3c:b6:b7:64:a7:ea").add("sessionId", sessionId).build();
    Request request = new Request.Builder().url(url).header("cookie", "JSESSIONID=" + sessionId).addHeader("sessionUser", emcode).addHeader("content-type", "text/html;charset:utf-8").post(formBody).build();
    OkhttpUtils.client.newCall(request).enqueue(new Callback() {

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            OkhttpUtils.println(OkhttpUtils.getResponseString(response), OkhttpUtils.typeMiddle, method);
            getStringCode("getStringCode");
            return;
        }

        @Override
        public void onFailure(Call call, IOException e) {
            OkhttpUtils.onFailurePrintln(e);
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) FormBody(okhttp3.FormBody) Request(okhttp3.Request) IOException(java.io.IOException) RequestBody(okhttp3.RequestBody)

Example 72 with Callback

use of retrofit2.Callback in project Gradle-demo by Arisono.

the class testUASApi method loginManage.

/**
	 * 登录管理平台
	 * 
	 * @desc: get请求
	 * @param phone
	 * @param password
	 */
public static void loginManage(String phone, String password) {
    //192.168.253.192:8080/platform-manage
    //manage.ubtob.com
    //192.168.253.60:9090/platform-manage
    String url = "http://manage.ubtob.com/public/account?user=" + phone + "&password=" + password;
    url = url + "&_timestamp=" + System.currentTimeMillis();
    url = url + "&_signature=" + HmacUtils.encode(url);
    //OkhttpUtils.println("管理平台登录url:" + url);
    Request request = new Request.Builder().url(url).addHeader("content-type", "text/html;charset:utf-8").build();
    OkhttpUtils.client.newCall(request).enqueue(new Callback() {

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            String json = OkhttpUtils.getResponseString(response);
            //String account=JSON.parseArray(json).getJSONObject(0).getString("account");
            RxBus.getInstance().send("管理平台:" + json);
        //OkhttpUtils.println("管理平台:" + json);
        }

        @Override
        public void onFailure(Call call, IOException e) {
            OkhttpUtils.println("管理平台:异常" + e.getMessage() + " 时间:" + DateFormatUtil.getDateTimeStr());
            OkhttpUtils.onFailurePrintln(e);
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Request(okhttp3.Request) IOException(java.io.IOException)

Example 73 with Callback

use of retrofit2.Callback in project easy by MehdiBenmesa.

the class RegistrationIntentService method registerDeviceProcess.

private void registerDeviceProcess(String deviceName, String deviceId, String registrationId) {
    RequestBody requestBody = new RequestBody();
    requestBody.setDeviceId(deviceId);
    requestBody.setDeviceName(deviceName);
    requestBody.setRegistrationId(registrationId);
    requestBody.setEmail(App.getInstance().getEmail());
    Retrofit retrofit = new Retrofit.Builder().baseUrl(SERVER_URL).addConverterFactory(GsonConverterFactory.create()).build();
    RequestInterface request = retrofit.create(RequestInterface.class);
    Call<ResponseBody> call = request.registerDevice(requestBody);
    call.enqueue(new Callback<ResponseBody>() {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            ResponseBody responseBody = response.body();
            Intent intent = new Intent(App.REGISTRATION_PROCESS);
            intent.putExtra("result", responseBody.getResult());
            intent.putExtra("message", responseBody.getMessage());
            LocalBroadcastManager.getInstance(RegistrationIntentService.this).sendBroadcast(intent);
        }

        @Override
        public void onFailure(Call<ResponseBody> call, Throwable t) {
            Toast.makeText(getApplicationContext(), t.getMessage(), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : Retrofit(retrofit2.Retrofit) Intent(android.content.Intent) RequestBody(dz.easy.androidclient.Model.RequestBody) ResponseBody(dz.easy.androidclient.Model.ResponseBody)

Example 74 with Callback

use of retrofit2.Callback in project Tusky by Vavassor.

the class LoginActivity method onButtonClick.

/**
     * Obtain the oauth client credentials for this app. This is only necessary the first time the
     * app is run on a given server instance. So, after the first authentication, they are
     * saved in SharedPreferences and every subsequent run they are simply fetched from there.
     */
private void onButtonClick(final EditText editText) {
    domain = validateDomain(editText.getText().toString());
    /* Attempt to get client credentials from SharedPreferences, and if not present
         * (such as in the case that the domain has never been accessed before)
         * authenticate with the server and store the received credentials to use next
         * time. */
    String prefClientId = preferences.getString(domain + "/client_id", null);
    String prefClientSecret = preferences.getString(domain + "/client_secret", null);
    if (prefClientId != null && prefClientSecret != null) {
        clientId = prefClientId;
        clientSecret = prefClientSecret;
        redirectUserToAuthorizeAndLogin(editText);
    } else {
        Callback<AppCredentials> callback = new Callback<AppCredentials>() {

            @Override
            public void onResponse(Call<AppCredentials> call, Response<AppCredentials> response) {
                if (!response.isSuccessful()) {
                    editText.setError(getString(R.string.error_failed_app_registration));
                    Log.e(TAG, "App authentication failed. " + response.message());
                    return;
                }
                AppCredentials credentials = response.body();
                clientId = credentials.clientId;
                clientSecret = credentials.clientSecret;
                preferences.edit().putString(domain + "/client_id", clientId).putString(domain + "/client_secret", clientSecret).apply();
                redirectUserToAuthorizeAndLogin(editText);
            }

            @Override
            public void onFailure(Call<AppCredentials> call, Throwable t) {
                editText.setError(getString(R.string.error_failed_app_registration));
                Log.e(TAG, Log.getStackTraceString(t));
            }
        };
        try {
            getApiFor(domain).authenticateApp(getString(R.string.app_name), getOauthRedirectUri(), OAUTH_SCOPES, getString(R.string.app_website)).enqueue(callback);
        } catch (IllegalArgumentException e) {
            editText.setError(getString(R.string.error_invalid_domain));
        }
    }
}
Also used : Response(retrofit2.Response) Call(retrofit2.Call) Callback(retrofit2.Callback) AppCredentials(com.keylesspalace.tusky.entity.AppCredentials)

Example 75 with Callback

use of retrofit2.Callback in project Tusky by Vavassor.

the class MainActivity method setupSearchView.

private void setupSearchView() {
    searchView.attachNavigationDrawerToMenuButton(drawer.getDrawerLayout());
    // Setup content descriptions for the different elements in the search view.
    final View leftAction = searchView.findViewById(R.id.left_action);
    leftAction.setContentDescription(getString(R.string.action_open_drawer));
    searchView.setOnFocusChangeListener(new FloatingSearchView.OnFocusChangeListener() {

        @Override
        public void onFocus() {
            leftAction.setContentDescription(getString(R.string.action_close));
        }

        @Override
        public void onFocusCleared() {
            leftAction.setContentDescription(getString(R.string.action_open_drawer));
        }
    });
    View clearButton = searchView.findViewById(R.id.clear_btn);
    clearButton.setContentDescription(getString(R.string.action_clear));
    searchView.setOnQueryChangeListener(new FloatingSearchView.OnQueryChangeListener() {

        @Override
        public void onSearchTextChanged(String oldQuery, String newQuery) {
            if (!oldQuery.equals("") && newQuery.equals("")) {
                searchView.clearSuggestions();
                return;
            }
            if (newQuery.length() < 3) {
                return;
            }
            searchView.showProgress();
            mastodonAPI.searchAccounts(newQuery, false, 5).enqueue(new Callback<List<Account>>() {

                @Override
                public void onResponse(Call<List<Account>> call, Response<List<Account>> response) {
                    if (response.isSuccessful()) {
                        searchView.swapSuggestions(response.body());
                        searchView.hideProgress();
                    } else {
                        searchView.hideProgress();
                    }
                }

                @Override
                public void onFailure(Call<List<Account>> call, Throwable t) {
                    searchView.hideProgress();
                }
            });
        }
    });
    searchView.setOnSearchListener(new FloatingSearchView.OnSearchListener() {

        @Override
        public void onSuggestionClicked(SearchSuggestion searchSuggestion) {
            Account accountSuggestion = (Account) searchSuggestion;
            Intent intent = new Intent(MainActivity.this, AccountActivity.class);
            intent.putExtra("id", accountSuggestion.id);
            startActivity(intent);
        }

        @Override
        public void onSearchAction(String currentQuery) {
        }
    });
    searchView.setOnBindSuggestionCallback(new SearchSuggestionsAdapter.OnBindSuggestionCallback() {

        @Override
        public void onBindSuggestion(View suggestionView, ImageView leftIcon, TextView textView, SearchSuggestion item, int itemPosition) {
            Account accountSuggestion = ((Account) item);
            Picasso.with(MainActivity.this).load(accountSuggestion.avatar).placeholder(R.drawable.avatar_default).into(leftIcon);
            String searchStr = accountSuggestion.getDisplayName() + " " + accountSuggestion.username;
            final SpannableStringBuilder str = new SpannableStringBuilder(searchStr);
            str.setSpan(new StyleSpan(Typeface.BOLD), 0, accountSuggestion.getDisplayName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            textView.setText(str);
            textView.setMaxLines(1);
            textView.setEllipsize(TextUtils.TruncateAt.END);
        }
    });
}
Also used : Account(com.keylesspalace.tusky.entity.Account) Call(retrofit2.Call) SearchSuggestion(com.arlib.floatingsearchview.suggestions.model.SearchSuggestion) Intent(android.content.Intent) FloatingSearchView(com.arlib.floatingsearchview.FloatingSearchView) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) FloatingSearchView(com.arlib.floatingsearchview.FloatingSearchView) TextView(android.widget.TextView) SearchSuggestionsAdapter(com.arlib.floatingsearchview.suggestions.SearchSuggestionsAdapter) Response(retrofit2.Response) Callback(retrofit2.Callback) StyleSpan(android.text.style.StyleSpan) TextView(android.widget.TextView) ImageView(android.widget.ImageView) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

IOException (java.io.IOException)51 Response (okhttp3.Response)46 Call (okhttp3.Call)44 Callback (okhttp3.Callback)44 Request (okhttp3.Request)41 RequestBody (okhttp3.RequestBody)25 Call (retrofit2.Call)17 Callback (retrofit2.Callback)15 Test (org.junit.Test)14 Response (retrofit2.Response)14 CountDownLatch (java.util.concurrent.CountDownLatch)13 FormBody (okhttp3.FormBody)12 ToStringConverterFactory (retrofit2.helpers.ToStringConverterFactory)12 OkHttpClient (okhttp3.OkHttpClient)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 ResponseBody (okhttp3.ResponseBody)10 MockResponse (okhttp3.mockwebserver.MockResponse)10 Retrofit (retrofit2.Retrofit)9 TextView (android.widget.TextView)6 HttpUrl (okhttp3.HttpUrl)6