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


Java FutureCallback类代码示例

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


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

示例1: flagPost

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
/**
 * Send a call to the api to flag given post with a given reason.
 *
 * @param postUuid uuid for the post
 * @param reason   reason for flag
 */
public void flagPost(final Context context, String postUuid, String reason) {
    String uri = apiUrl + "/post/" + postUuid + "/flag";
    JsonObject json = new JsonObject();
    json.addProperty("reason", reason);
    Ion.with(context)
        .load(uri)
        .setTimeout(5000)
        .setJsonObjectBody(json)
        .asString()
        .setCallback(new FutureCallback<String>() {
            @Override
            public void onCompleted(Exception e, String result) {

                if (e == null) {
                    Toast.makeText(context, R.string.flag_response, Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(context, R.string.flag_error_response, Toast.LENGTH_SHORT).show();
                }
            }
        });
}
 
开发者ID:BakkerTom,项目名称:happy-news,代码行数:28,代码来源:PostManager.java

示例2: bindType

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
/**
 * Bind a {@link Post} to this view.
 *
 * @param post The post to bind.
 */
public void bindType(Post post) {
    super.bindType(post);

    tweetTextView.setText(post.getContentText());
    timeTextView.setText(relativeTimeSpan(post.getPublishedAt()));
    twitterUsernameTextView.setText(post.getAuthor());

    Ion.with(imageView)
        .load(post.getImageUrls().get(0))
        .setCallback(new FutureCallback<ImageView>() {
            @Override
            public void onCompleted(Exception e, ImageView result) {
                progressBar.setVisibility(View.GONE);
            }
        });

    popupMenuImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showPopupMenu(v, getAdapterPosition());
        }
    });
}
 
开发者ID:BakkerTom,项目名称:happy-news,代码行数:29,代码来源:PostTweetImageHolder.java

示例3: requestAPIGET

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
public static void requestAPIGET(Context c, String endpoint, final FutureCallback<String> callback) {
    String auth = "Basic ".concat(Base64.encodeToString(username.concat(":").concat(password).getBytes(), Base64.NO_WRAP));

    Ion.with(c)
    .load(host.concat(endpoint))
    .setHeader("Authorization", auth)                // set the header
    .asString()
    .setCallback(new FutureCallback<String>() {
        @Override
        public void onCompleted(Exception e, String result) {
            if (e == null && JSONUtils.isJSONObject(result)) {
                try {
                    JSONObject o = new JSONObject(result);
                    if (o.getString("message").equals("Current user is not logged in")) {
                        callback.onCompleted(new Exception("401"), null);
                        return;
                    }
                } catch (JSONException e1) {

                }
            }

            callback.onCompleted(e, result);
        }
    });
}
 
开发者ID:nextcloud,项目名称:passman-android,代码行数:27,代码来源:Core.java

示例4: getVault

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
public static void getVault(Context c, String guid, final FutureCallback<Vault> cb) {
    Vault.requestAPIGET(c, "vaults/".concat(guid),new FutureCallback<String>() {
        @Override
        public void onCompleted(Exception e, String result) {
            if (e != null) {
                cb.onCompleted(e, null);
                return;
            }

            try {
                JSONObject data = new JSONObject(result);

                Vault v = Vault.fromJSON(data);

                cb.onCompleted(e, v);
            }
            catch (JSONException ex) {
                cb.onCompleted(ex, null);
            }
        }
    });
}
 
开发者ID:nextcloud,项目名称:passman-android,代码行数:23,代码来源:Vault.java

示例5: retrieveAccessTokenfromServer

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
private void retrieveAccessTokenfromServer() {
    Ion.with(this)
            .load(String.format("%s?identity=%s", ACCESS_TOKEN_SERVER,
                    UUID.randomUUID().toString()))
            .asString()
            .setCallback(new FutureCallback<String>() {
                @Override
                public void onCompleted(Exception e, String token) {
                    if (e == null) {
                        VideoActivity.this.accessToken = token;
                    } else {
                        Toast.makeText(VideoActivity.this,
                                R.string.error_retrieving_access_token, Toast.LENGTH_LONG)
                                .show();
                    }
                }
            });
}
 
开发者ID:twilio,项目名称:video-quickstart-android,代码行数:19,代码来源:VideoActivity.java

示例6: exchangeServerAuthCodeForJWT

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
private void exchangeServerAuthCodeForJWT(String firebaseUserId, String authCode, Set<Scope> grantedScopes, final SimpleCallback<String> jwtCallback) {
    Ion.with(context)
            .load(context.getString(R.string.APP_URL) + "/exchangeServerAuthCodeForJWT")
            .setBodyParameter("serverCode", authCode)
            .setBodyParameter("firebaseUserId", firebaseUserId)
            .setBodyParameter("grantedScopes", android.text.TextUtils.join(",", grantedScopes))
            .asJsonObject()
            .setCallback(new com.koushikdutta.async.future.FutureCallback<JsonObject>() {
                @Override
                public void onCompleted(Exception e, JsonObject result) {
                    if (e != null) {
                        jwtCallback.onError(e);
                        return;
                    }
                    String jwt = result.get("serviceAccessToken").getAsString();
                    AuthHelper.userJwt = jwt;
                    jwtCallback.onComplete(jwt);
                }
            });
}
 
开发者ID:dan-silver,项目名称:cast-dashboard-android-app,代码行数:21,代码来源:AuthHelper.java

示例7: connectSocket

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
public Cancellable connectSocket(final InetSocketAddress remote, final ConnectCallback callback) {
    if (!remote.isUnresolved())
        return connectResolvedInetSocketAddress(remote, callback);

    final SimpleFuture<AsyncNetworkSocket> ret = new SimpleFuture<AsyncNetworkSocket>();

    Future<InetAddress> lookup = getByName(remote.getHostName());
    ret.setParent(lookup);
    lookup
    .setCallback(new FutureCallback<InetAddress>() {
        @Override
        public void onCompleted(Exception e, InetAddress result) {
            if (e != null) {
                callback.onConnectCompleted(e, null);
                ret.setComplete(e);
                return;
            }

            ret.setComplete(connectResolvedInetSocketAddress(new InetSocketAddress(result, remote.getPort()), callback));
        }
    });
    return ret;
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:24,代码来源:AsyncServer.java

示例8: testFileDataEmitter

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
public void testFileDataEmitter() throws Exception {
    final Semaphore semaphore = new Semaphore(0);
    File f = getContext().getFileStreamPath("test.txt");
    StreamUtility.writeFile(f, "hello world");
    FileDataEmitter fdm = new FileDataEmitter(AsyncServer.getDefault(), f);
    final Md5 md5 = Md5.createInstance();
    Future<String> stringBody = new StringParser().parse(fdm)
    .setCallback(new FutureCallback<String>() {
        @Override
        public void onCompleted(Exception e, String result) {
            semaphore.release();
        }
    });
    fdm.resume();

    assertTrue("timeout", semaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS));
    assertEquals("hello world", stringBody.get());
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:19,代码来源:FileTests.java

示例9: get

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
@Override public void get(final Context context, String team, final RecyclerView recyclerView) {
  String urlFull = ApiConstraints.TEAM.concat(team);
  api.getArray(urlFull).setCallback(new FutureCallback<Response<JsonArray>>() {
    @Override public void onCompleted(Exception e, Response<JsonArray> result) {
      if (e != null) {
        return;
      }
      int code = result.getHeaders().code();
      switch (code) {
        case 200:
          Gson gson = new GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).create();
          TypeToken listType = new TypeToken<List<Team>>() {
          };
          List<Team> teams = (List<Team>) gson.fromJson(result.getResult(), listType.getType());
          SearchTeamAdapter teamAdapter = new SearchTeamAdapter(context, teams, teamRepository);
          recyclerView.setAdapter(teamAdapter);
          break;
        case 404:
          break;
      }
    }
  });
}
 
开发者ID:Pierry,项目名称:cartolapp,代码行数:24,代码来源:TeamApi.java

示例10: get

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
@Override public void get(String team) {
  String urlFull = ApiConstraints.TEAM_PLAYERS.concat(team);
  api.getObject(urlFull).setCallback(new FutureCallback<Response<JsonObject>>() {
    @Override public void onCompleted(Exception e, Response<JsonObject> result) {
      if (e == null) {
        return;
      }
      int code = result.getHeaders().code();
      switch (code) {
        case 200:
          // deserialize
          // save
          break;
        case 404:
          break;
      }
    }
  });
}
 
开发者ID:Pierry,项目名称:cartolapp,代码行数:20,代码来源:PlayerApi.java

示例11: getDate

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
private void getDate(String url) {
  Ion.with(getActivity()).load(url).as(new TypeToken<CarNewsTotalBean>(){}).setCallback(new FutureCallback<CarNewsTotalBean>() {
      @Override
      public void onCompleted(Exception e, CarNewsTotalBean result) {
          if(result!=null){
              for (int i=1;i<result.getT1348654060988().size();i++){
                  CarNewsBean carNewsBean=new CarNewsBean();
                  carNewsBean.setTitle(result.getT1348654060988().get(i).getTitle());
                  carNewsBean.setImgsrc(result.getT1348654060988().get(i).getImgsrc());
                  carNewsBean.setUrl(result.getT1348654060988().get(i).getUrl());
                  carNewsBean.setFrom(result.getT1348654060988().get(i).getSource());
                  list1.add(carNewsBean);
              }

          }
          adapter.notifyDataSetChanged();

      }
  });
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:21,代码来源:NewsFragment.java

示例12: retrieveCapabilityToken

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
private void retrieveCapabilityToken(final ClientProfile newClientProfile) {

        // Correlate desired properties of the Device (from ClientProfile) to properties of the Capability Token
        Uri.Builder b = Uri.parse(TOKEN_SERVICE_URL).buildUpon();

        Ion.with(getApplicationContext())
                .load(b.toString())
                .asString()
                .setCallback(new FutureCallback<String>() {
                    @Override
                    public void onCompleted(Exception e, String capabilityToken) {
                        if (e == null) {
                            Log.d(TAG, capabilityToken);

                            // Update the current Client Profile to represent current properties
                          //  ClientActivity.this.clientProfile = newClientProfile;

                            // Create a Device with the Capability Token
                            createDevice(capabilityToken);
                        } else {
                            Log.e(TAG, "Error retrieving token: " + e.toString());
                            Toast.makeText(ClientActivity.this, "Error retrieving token", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
    }
 
开发者ID:ipragmatech,项目名称:android-twilio-voice,代码行数:27,代码来源:ClientActivity.java

示例13: getHashes

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
private void getHashes(){
    Ion.with(getApplicationContext())
            .load(filesURL + "/MD5SUMS").asString()
            .setCallback(new FutureCallback<String>() {
                @Override
                public void onCompleted(Exception e, String r) {
                    final String result = r;
                    runOnUiThread(new Runnable() {
                                      @Override
                                      public void run() {
                                          try {
                                              setHashes(result.split("\\s+"));
                                          }catch(Exception e2){
                                              setHashes(null);
                                          }
                                      }
                                  }
                    );
                }
            });
}
 
开发者ID:LobbyOS,项目名称:android-standalone,代码行数:22,代码来源:PHPInstallActivity.java

示例14: getBusData

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
/**
 * Get the current bus data by the bus station id
 * @param busId bus (station) id
 */
public  void getBusData(int busId)
{
    Ion.with(this).load(String.format("http://h.fs-et.de/api.php?id=%s&limit=5",String.valueOf(busId))).asJsonObject().setCallback(new FutureCallback<JsonObject>() {
        @Override
        public void onCompleted(Exception e, JsonObject result) {

            if(e!= null)
            {
                e.printStackTrace();
                return;
            }
            Type collectionType = new TypeToken<BusData>() {
            }.getType();

            BusData userApiFrame = (BusData)new Gson().fromJson(result,collectionType);
            TextView textView = (TextView)findViewById(R.id.tV_bus_comes_at);
            Departure departure = userApiFrame.getDepartures().get(0);
            busDepart = departure;
            textView.setText(String.format("Bus (%s - %s) kommt um: %s",departure.getLine(),departure.getDirection(),departure.getTimetable()));

        }
    });
}
 
开发者ID:flbbr,项目名称:Run2Stop,代码行数:28,代码来源:MainActivity.java

示例15: onClick

import com.koushikdutta.async.future.FutureCallback; //导入依赖的package包/类
@Override
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.submit:
            File file = new File(Const.getDownloadPath() + "/闪讯wifi助手 " + bean.getVersionName() + ".apk");
            if (file.exists()) {
                installApk(file);
                return;
            }
            MToast.show(context, "正在下载");
            submit.setClickable(false);
            submit.setText("正在下载");
            progressBar.setVisibility(View.VISIBLE);
            Ion.with(context).load(bean.getDownloadURL()).progressBar(progressBar).write(file).setCallback(new FutureCallback<File>() {
                @Override
                public void onCompleted(Exception e, File result) {
                    submit.setClickable(true);
                    submit.setText("安装");
                    installApk(result);
                }
            });
            break;
    }
}
 
开发者ID:WrBug,项目名称:wtshanxun,代码行数:25,代码来源:UpdateDialog.java


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