com.koushikdutta.async.future.FutureCallback Java Examples
The following examples show how to use
com.koushikdutta.async.future.FutureCallback.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Core.java From passman-android with GNU General Public License v3.0 | 6 votes |
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); } }); }
Example #2
Source File: Vault.java From passman-android with GNU General Public License v3.0 | 6 votes |
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); } } }); }
Example #3
Source File: NetworkHelper.java From Ouroboros with GNU General Public License v3.0 | 6 votes |
private void getDnsblCaptcha(final Context context, final View view){ Ion.with(context) .load(ChanUrls.getDnsblUrl()) .asString() .setCallback(new FutureCallback<String>() { @Override public void onCompleted(Exception e, String rawHTML) { if (e != null){ Snackbar.make(view, "Error retrieving DNSBL CAPTCHA", Snackbar.LENGTH_LONG).show(); return; } ImageView captchaImage = (ImageView) ((Activity) context).findViewById(R.id.post_comment_captcha_image); //messy captchaImage.setVisibility(View.VISIBLE); Document dnsblHtml = Jsoup.parse(rawHTML); captchaImage.setTag(dnsblHtml.select("body > form > input.captcha_cookie").attr("value")); String strBase64Image = dnsblHtml.select("body > form > img").attr("src"); String strBase64ImageBytes = strBase64Image.substring(strBase64Image.indexOf(",") + 1); byte[] decodedbytes = Base64.decode(strBase64ImageBytes, Base64.DEFAULT); Bitmap decodeImage = BitmapFactory.decodeByteArray(decodedbytes, 0, decodedbytes.length); captchaImage.setImageBitmap(decodeImage); } }); }
Example #4
Source File: MainActivity.java From CircularImageView with MIT License | 6 votes |
private void loadWebImage(final CircularImageView imgNetwork) { final String URL = "http://i.imgur.com/LrwApXg.png"; // Using Picasso... //Picasso.with(this).load(URL).placeholder(R.drawable.default_avatar).error(R.drawable.grumpy_cat).transform(new PicassoRoundTransform()).into(imgNetwork); // Using Glide... //Glide.with(this).load(URL).placeholder(R.drawable.default_avatar).error(R.drawable.grumpy_cat).into(imgNetwork); // Using ION... Ion.with(this).load(URL).asBitmap().setCallback(new FutureCallback<Bitmap>() { @Override public void onCompleted(Exception e, Bitmap result) { if(e == null) { // Success imgNetwork.setImageBitmap(result); } else { // Error imgNetwork.setImageResource(R.drawable.grumpy_cat); } } }); }
Example #5
Source File: Core.java From passman-android with GNU General Public License v3.0 | 5 votes |
public static void getAPIVersion(final Context c, FutureCallback<Integer> cb) { if (version_number != 0) { cb.onCompleted(null, version_number); return; } requestAPIGET(c, "version", new FutureCallback<String>() { @Override public void onCompleted(Exception e, String result) { Log.d("getApiVersion", result); } }); }
Example #6
Source File: Vault.java From passman-android with GNU General Public License v3.0 | 5 votes |
public static void getVaults(Context c, final FutureCallback<HashMap<String, Vault>> cb) { Vault.requestAPIGET(c, "vaults",new FutureCallback<String>() { @Override public void onCompleted(Exception e, String result) { if (e != null) { cb.onCompleted(e, null); return; } // Log.e(Vault.LOG_TAG, result); // cb.onCompleted(e, null); try { JSONArray data = new JSONArray(result); HashMap<String, Vault> l = new HashMap<String, Vault>(); for (int i = 0; i < data.length(); i++) { Vault v = Vault.fromJSON(data.getJSONObject(i)); l.put(v.guid, v); } cb.onCompleted(e, l); } catch (JSONException ex) { cb.onCompleted(ex, null); } } }); }
Example #7
Source File: NetworkHelper.java From Ouroboros with GNU General Public License v3.0 | 5 votes |
private void getCaptcha(final Context context, final View view) { Ion.with(context) .load(ChanUrls.getCaptchaEntrypoint()) .asString() .setCallback(new FutureCallback<String>() { @Override public void onCompleted(Exception e, String rawHTML) { if (e != null){ Snackbar.make(view, "Error retrieving CAPTCHA", Snackbar.LENGTH_LONG).show(); return; } ImageView captchaImage = (ImageView) ((Activity) context).findViewById(R.id.post_comment_captcha_image); //messy captchaImage.setVisibility(View.VISIBLE); Document captchaHtml = Jsoup.parse(rawHTML); Pattern cookieIdPattern = Pattern.compile("CAPTCHA ID: (?:(?!<).)*"); Matcher matcher = cookieIdPattern.matcher(rawHTML); captchaImage.setTag(matcher.find() ? matcher.group(0).substring(12) : ""); String strBase64Image = captchaHtml.select("body > img").attr("src"); String strBase64ImageBytes = strBase64Image.substring(strBase64Image.indexOf(",") + 1); byte[] decodedbytes = Base64.decode(strBase64ImageBytes, Base64.DEFAULT); Bitmap decodeImage = BitmapFactory.decodeByteArray(decodedbytes, 0, decodedbytes.length); captchaImage.setImageBitmap(decodeImage); } }); }
Example #8
Source File: ThreadFragment.java From Ouroboros with GNU General Public License v3.0 | 5 votes |
private void getThreadJson(final Context context, final String boardName, final String threadNumber){ progressBar.setVisibility(View.VISIBLE); final String threadJsonUrl = ChanUrls.getThreadUrl(boardName, threadNumber); Ion.with(context) .load(threadJsonUrl) .setLogging(LOG_TAG, Log.DEBUG) .asJsonObject() .setCallback(new FutureCallback<JsonObject>() { @Override public void onCompleted(Exception e, JsonObject jsonObject) { if (getActivity() != null){ if (e == null) { if (jsonObject.toString().equals(oldJsonString)) { pollingInterval = pollingInterval + pollingInterval / 2; progressBar.setVisibility(View.INVISIBLE); } else { restartStatusCheck(); oldJsonString = jsonObject.toString(); networkFragment.beginTask(jsonObject, infiniteDbHelper, boardName, resto, threadPosition, firstRequest, recyclerView, threadAdapter); } } else { progressBar.setVisibility(View.INVISIBLE); Snackbar.make(getView(), "Error retrieving thread", Snackbar.LENGTH_LONG).show(); } } firstRequest = false; } }); }
Example #9
Source File: PasswordList.java From passman-android with GNU General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_password_list); settings = PreferenceManager.getDefaultSharedPreferences(this); ton = SingleTon.getTon(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } }); fab.hide(); if (running) return; // @TODO: Display loading screen while checking credentials! final AppCompatActivity self = this; Core.checkLogin(this, false, new FutureCallback<Boolean>() { @Override public void onCompleted(Exception e, Boolean result) { if (result) { showVaults(); return; } // If not logged in, show login form! LoginActivity.launch(self, new ICallback() { @Override public void onTaskFinished() { showVaults(); } }); } }); running = true; }
Example #10
Source File: PasswordList.java From passman-android with GNU General Public License v3.0 | 4 votes |
public void showActiveVault() { Vault vault = (Vault) ton.getExtra(SettingValues.ACTIVE_VAULT.toString()); if (vault.getCredentials() != null) { if (vault.is_unlocked()) { getSupportFragmentManager() .beginTransaction() .setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left, R.anim.slide_in_left, R.anim.slide_out_right) .replace(R.id.content_password_list, new CredentialItemFragment(), "vault") .addToBackStack(null) .commit(); } else { showUnlockVault(); } } else { Vault.getVault(this, vault.guid, new FutureCallback<Vault>() { @Override public void onCompleted(Exception e, Vault result) { if (e != null) { // Not logged in, restart activity if (e.getMessage() != null && e.getMessage().equals("401")) { recreate(); } Log.e(Tag.CREATOR.toString(), "Unknown network error", e); Toast.makeText(getApplicationContext(), getString(R.string.net_error), Toast.LENGTH_LONG).show(); new android.os.Handler().postDelayed(new Runnable() { @Override public void run() { showVaults(); } }, 30000); return; } // Update the vault record to avoid future loads ((HashMap<String, Vault>)ton.getExtra(SettingValues.VAULTS.toString())).put(result.guid, result); ton.addExtra(SettingValues.ACTIVE_VAULT.toString(), result); showActiveVault(); } }); } }
Example #11
Source File: Core.java From passman-android with GNU General Public License v3.0 | 4 votes |
/** * Check if the user has logged in, also sets up the API * @param c The context where this should be run * @param toast Whether we want or not a toast! Yum! * @param cb The callback */ public static void checkLogin(final Context c, final boolean toast, final FutureCallback<Boolean> cb) { SingleTon ton = SingleTon.getTon(); if (ton.getString(SettingValues.HOST.toString()) == null) { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(c); String url = settings.getString(SettingValues.HOST.toString(), null); // If the url is null app has not yet been configured! if (url == null) { cb.onCompleted(null, false); return; } // Load the server settings ton.addString(SettingValues.HOST.toString(), url); ton.addString(SettingValues.USER.toString(), settings.getString(SettingValues.USER.toString(), "")); ton.addString(SettingValues.PASSWORD.toString(), settings.getString(SettingValues.PASSWORD.toString(), "")); } String host = ton.getString(SettingValues.HOST.toString()); String user = ton.getString(SettingValues.USER.toString()); String pass = ton.getString(SettingValues.PASSWORD.toString()); Toast.makeText(c, host, Toast.LENGTH_LONG).show(); Log.d(LOG_TAG, "Host: " + host); Log.d(LOG_TAG, "User: " + user); Log.d(LOG_TAG, "Pass: " + pass); Vault.setUpAPI(host, user, pass); Vault.getVaults(c, new FutureCallback<HashMap<String, Vault>>() { @Override public void onCompleted(Exception e, HashMap<String, Vault> result) { boolean ret = true; if (e != null) { if (e.getMessage().equals("401")) { if (toast) Toast.makeText(c, c.getString(R.string.wrongNCSettings), Toast.LENGTH_LONG).show(); ret = false; } else if (e.getMessage().contains("Unable to resolve host") || e.getMessage().contains("Invalid URI")) { if (toast) Toast.makeText(c, c.getString(R.string.wrongNCUrl), Toast.LENGTH_LONG).show(); ret = false; } else { Log.e(LOG_TAG, "Error: " + e.getMessage(), e); if (toast) Toast.makeText(c, c.getString(R.string.net_error) + ": " + e.getMessage(), Toast.LENGTH_LONG).show(); ret = false; } } cb.onCompleted(e, ret); } }); }
Example #12
Source File: CatalogFragment.java From Ouroboros with GNU General Public License v3.0 | 4 votes |
private void getCatalogJson(final Context context, final String boardName) { String catalogJsonUrl = ChanUrls.getCatalogUrl(boardName); progressBar.setVisibility(View.VISIBLE); currentCatalogRequest = Ion.with(context) .load(catalogJsonUrl) .asJsonArray(); currentCatalogRequest.setCallback(new FutureCallback<JsonArray>() { @Override public void onCompleted(Exception e, JsonArray jsonArray) { if (e == null) { networkFragment.beginTask(jsonArray, infiniteDbHelper, boardName, catalogAdapter); } else { progressBar.setVisibility(View.INVISIBLE); swipeRefreshLayout.setRefreshing(false); if (getActivity() != null){ // The View can be null when requests are cancelled. View view = getView(); if (view != null) { Snackbar.make( view, "Error retrieving catalog", Snackbar.LENGTH_LONG ).show(); } } } if (getActivity() != null) { catalogAdapter.changeCursor(getSortedCursor()); } // Clear the reference to the current request, now // that it is complete. currentCatalogRequest = null; } }); }
Example #13
Source File: DeepZoomFragment.java From Ouroboros with GNU General Public License v3.0 | 4 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_deepzoom, container, false); setHasOptionsMenu(true); final LinearLayout deepzoomContainer = (LinearLayout) rootView.findViewById(R.id.deepzoom_container); photoView = (PhotoView) rootView.findViewById(R.id.deepzoom_photoview); photoView.setMaximumScale(24); mediaPlayButton = (ImageView) rootView.findViewById(R.id.deepzoom_media_play_button); mediaPlayButton.setVisibility(View.GONE); progressBar = (ProgressBar) rootView.findViewById(R.id.progress_bar); progressBar.setVisibility(View.VISIBLE); Ion.with(photoView) .load(ChanUrls.getThumbnailUrl( boardName, mediaItem.fileName, mediaItem.ext )) .withBitmapInfo() .setCallback(new FutureCallback<ImageViewBitmapInfo>() { @Override public void onCompleted(Exception e, ImageViewBitmapInfo result) { if (e != null) { return; } progressBar.setVisibility(View.INVISIBLE); if (result.getException() == null){ Util.setSwatch(deepzoomContainer, result); } if (mediaItem.ext.equals(".webm") || mediaItem.ext.equals(".mp4")) { return; } Ion.with(photoView) .crossfade(true) .deepZoom() .load(ChanUrls.getImageUrl( boardName, mediaItem.fileName, mediaItem.ext )) .withBitmapInfo(); } }); return rootView; }