Exemplo n.º 1
0
  public void logoutUser() {
    AsyncHttpClient client = new AsyncHttpClient();
    String token = ApiHelper.getSessionToken(context);
    client.addHeader("Authorization", token);

    client.delete(
        this.getApplicationContext(),
        ApiHelper.getLocalUrlForApi(getResources()) + "sessions",
        new AsyncHttpResponseHandler() {

          @Override
          public void onStart() {}

          @Override
          public void onSuccess(int statusCode, Header[] headers, byte[] response) {
            Intent intent = new Intent(MainActivity.this.context, LoginActivity.class);
            startActivity(intent);
            finish();

            Toast toast = Toast.makeText(MainActivity.this.context, "Goodbye.", Toast.LENGTH_LONG);
            toast.show();
          }

          @Override
          public void onFailure(
              int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
            String responseText = null;

            try {
              if (!ErrorHandle.isNetworkConnected(errorResponse)) {
                ErrorHandle.displayNetworkErrorModal(MainActivity.this);

              } else {
                responseText = new JSONObject(new String(errorResponse)).getString("reason");
                if (ErrorHandle.isTokenExpired(responseText)) {
                  ErrorHandle.displayTokenModal(MainActivity.this);
                }
              }
            } catch (JSONException j) {

            }
          }

          @Override
          public void onRetry(int retryNo) {}
        });
  }
 public static Notification createNotification(
     Context context,
     int iconId,
     int tickerTextResId,
     int contentTextResId,
     PendingIntent pendingIntent) {
   String tickerText = context.getString(tickerTextResId);
   String contentText = context.getString(contentTextResId);
   if (ApiHelper.getAPILevel() < 11) {
     Notification notification = new Notification();
     notification.tickerText = tickerText;
     notification.when = System.currentTimeMillis();
     //noinspection deprecation
     notification.icon = iconId;
     notification.contentIntent = pendingIntent;
     // Google removed setLatestEventInfo in sdk 23.
     //noinspection TryWithIdenticalCatches
     try {
       Method method =
           Notification.class.getMethod(
               "setLatestEventInfo",
               Context.class,
               CharSequence.class,
               CharSequence.class,
               PendingIntent.class);
       method.invoke(notification, context, tickerText, contentText, pendingIntent);
     } catch (NoSuchMethodException e) {
       Log.v(TAG, e.getMessage(), e);
     } catch (IllegalAccessException e) {
       Log.v(TAG, e.getMessage(), e);
     } catch (InvocationTargetException e) {
       Log.v(TAG, e.getMessage(), e);
     }
     return notification;
   } else if (ApiHelper.getAPILevel() < 16) {
     return Api11Helper.createNotification(
         context, iconId, tickerText, contentText, pendingIntent);
   } else {
     return Api16Helper.createNotification(
         context, iconId, tickerText, contentText, pendingIntent);
   }
 }
 public static BasicMessage<VideoSrc> getVideoSrc(int av) {
   String url = ApiHelper.getHTML5Url(String.valueOf(av));
   return ApiHelper.getSimpleUrlResult(url, VideoSrc.class);
 }