com.androidquery.callback.AjaxCallback Java Examples

The following examples show how to use com.androidquery.callback.AjaxCallback. 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: UpdateUtils.java    From freemp with Apache License 2.0 6 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    Activity activity = activityContainer.get();
    if (null == activity) {
        return "";
    }
    try {
        versionCode = activity.getPackageManager()
                .getPackageInfo(activity.getPackageName(), 0).versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    locale = activity.getResources().getConfiguration().locale.toString();//Locale.getDefault().toString();
    AQUtility.debug("locale", locale);
    String response = "";

    AjaxCallback<String> cb = new AjaxCallback<String>();
    cb.url(MESSAGEURL).type(String.class).timeout(1);

    aq.sync(cb);

    response = cb.getResult();
    return response;
}
 
Example #2
Source File: TaskGetArtwork.java    From IdealMedia with Apache License 2.0 4 votes vote down vote up
public void getArtwork(Track track) {
    final String currentArtist = "" + track.getArtist();

    if (currentArtist.equals(""))
        return;

    if (MediaUtils.getArtworkQuick(context, track, 300, 300) != null)
        return;

    if (activeTasks.size() > 2)
        return;

    if (activeTasks.containsKey(currentArtist))
        return;

    activeTasks.put(currentArtist, this);

    AQuery aq = new AQuery(context);
    String url = String.format("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&api_key=683548928700d0cdc664691b862a8d21&artist=%s&format=json", Uri.encode(currentArtist));
    AjaxCallback<JSONObject> cb = new AjaxCallback<JSONObject>();
    cb.url(url).type(JSONObject.class).fileCache(true).expire(3600 * 60 * 1000);
    aq.sync(cb);
    JSONObject result = cb.getResult();

    if (result != null) {
        JSONObject jsonObject = null;
        String albumArtImageLink = null;
        try {
            if (!result.has("artist"))
                return;

            jsonObject = result.getJSONObject("artist");
            JSONArray image = jsonObject.getJSONArray("image");
            for (int i=0;i<image.length();i++) {
                jsonObject = image.getJSONObject(i);
                if (jsonObject.getString("size").equals("extralarge")) {
                    albumArtImageLink = Uri.decode(jsonObject.getString("#text"));
                }
            }
            if (!(albumArtImageLink != null && albumArtImageLink.equals(""))) {
                String path = MediaUtils.getArtistPath(track);
                if (path != null) {
                    File file = new File(path);

                    AjaxCallback<File> cbFile = new AjaxCallback<File>();
                    cbFile.url(albumArtImageLink).type(File.class).targetFile(file);
                    aq.sync(cbFile);

                    AjaxStatus status = cbFile.getStatus();
                    if (status.getCode() == 200) {
                        if (listener != null)
                            listener.onNewArtwork();
                    } else {
                        file.delete();
                    }
                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }
    activeTasks.remove(currentArtist);
}