use of com.android.volley.toolbox.StringRequest in project saga-android by AnandChowdhary.
the class OnClickDialog method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View mView = inflater.inflate(R.layout.dialog_on_click, container, false);
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
final ProgressBar mProgress = (ProgressBar) mView.findViewById(R.id.progress_doc);
mImageLoader.get(url, new ImageLoader.ImageListener() {
@Override
public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
((ImageView) mView.findViewById(R.id.album_iv_doc)).setImageBitmap(response.getBitmap());
}
@Override
public void onErrorResponse(VolleyError error) {
//should get a cache hit
}
});
((TextView) mView.findViewById(R.id.artist_value_tv_doc)).setText(arts);
((TextView) mView.findViewById(R.id.track_value_tv_doc)).setText(title);
ImageButton mDownload = (ImageButton) mView.findViewById(R.id.download_btn_doc);
mDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MusicDownloader.startDownload(getActivity(), title, arts, new MusicDownloader.DownloaderListener() {
@Override
public void showProgressBar() {
mProgress.setVisibility(View.VISIBLE);
}
@Override
public void hideProgressBar() {
mProgress.setVisibility(View.GONE);
}
@Override
public void onSuccess() {
mTracker.send(new HitBuilders.EventBuilder().setCategory("Music Download").setAction("Click").build());
dismiss();
}
});
}
});
ImageButton mShare = (ImageButton) mView.findViewById(R.id.share_btn_doc);
mShare.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mProgress.setVisibility(View.VISIBLE);
String url = null;
try {
url = "http://rhythmsa.ga/api/sharable.php?q=" + URLEncoder.encode(title + " " + arts, "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
mProgress.setVisibility(View.GONE);
Log.d("kthenks", response);
if (Patterns.WEB_URL.matcher(response).matches()) {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_TEXT, "Hey! Check out this amazing song - " + title + " by " + arts + ". " + response + "\nShared via Saga Music app - http://getsa.ga/apk");
try {
startActivity(Intent.createChooser(i, "Share via"));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(getActivity(), "No application available to share song", Toast.LENGTH_SHORT).show();
}
mTracker.send(new HitBuilders.EventBuilder().setCategory("Music Share").setAction("Click").build());
} else
Toast.makeText(getActivity(), "Error in sharing", Toast.LENGTH_SHORT).show();
dismiss();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
mProgress.setVisibility(View.GONE);
VolleyLog.d("kthenks", "Error: " + error.getMessage());
Toast.makeText(getActivity(), "Error connecting to the Internet", Toast.LENGTH_SHORT).show();
dismiss();
}
});
request.setShouldCache(false);
mQueue.add(request);
}
});
return mView;
}
use of com.android.volley.toolbox.StringRequest in project saga-android by AnandChowdhary.
the class MusicDownloader method getSongInfo.
private static void getSongInfo(final Context context, final String filename, final String songName, final String artistName) {
String url = "http://162.243.144.151/everything.php?q=";
url += artistName == null ? filename.replace(" ", "%20") : songName.replace(" ", "%20");
StringRequest request = new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (artistName != null) {
try {
JSONObject jsonObject = new JSONObject(response);
jsonObject.put("track", songName);
jsonObject.put("artist", artistName);
Utils.saveSongInfo(context, filename, jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Utils.saveSongInfo(context, filename, response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("Music download", "Error: " + error.toString());
if (artistName != null) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("track", songName);
jsonObject.put("artist", artistName);
Utils.saveSongInfo(context, filename, jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
request.setShouldCache(false);
VolleySingleton.getInstance(context).getRequestQueue().add(request);
}
use of com.android.volley.toolbox.StringRequest in project qksms by moezbhatti.
the class DialogHelper method showChangelog.
public static void showChangelog(QKActivity context) {
context.showProgressDialog();
String url = "https://qksms-changelog.firebaseio.com/changes.json";
StringRequest request = new StringRequest(url, response -> {
Gson gson = new Gson();
ChangeModel[] changes = gson.fromJson(response, ChangeModel[].class);
// Fill in the localized date strings, and the `Long` time so that we can sort them
SimpleDateFormat dateParser = new SimpleDateFormat("yyyy-MM-dd");
// For multiple updates in a day
SimpleDateFormat dateRevisionParser = new SimpleDateFormat("yyyy-MM-dd-'r'H");
SimpleDateFormat dateFormatter = new SimpleDateFormat("MMMM d, yyyy");
for (ChangeModel change : changes) {
try {
Date date;
if (change.getDate().length() > 11) {
date = dateRevisionParser.parse(change.getDate());
} else {
date = dateParser.parse(change.getDate());
}
change.setDate(dateFormatter.format(date));
change.setDateLong(date.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
}
Arrays.sort(changes, (lhs, rhs) -> Long.valueOf(rhs.getDateLong()).compareTo(lhs.getDateLong()));
// Only show changelogs for current and past versions
boolean currentVersionReached = false;
ArrayList<String> versions = new ArrayList<>();
ArrayList<String> dates = new ArrayList<>();
ArrayList<String> changelists = new ArrayList<>();
for (ChangeModel change : changes) {
if (change.getVersion().equals(BuildConfig.VERSION_NAME)) {
currentVersionReached = true;
}
if (currentVersionReached) {
versions.add(change.getVersion());
dates.add(change.getDate());
String changelist = "";
for (int i = 0; i < change.getChanges().size(); i++) {
String changeItem = change.getChanges().get(i);
changelist += " • ";
changelist += changeItem;
if (i < change.getChanges().size() - 1) {
changelist += "\n";
}
}
changelists.add(changelist);
}
}
context.hideProgressDialog();
new QKDialog().setContext(context).setTitle(R.string.title_changelog).setTripleLineItems(versions.toArray(new String[versions.size()]), dates.toArray(new String[versions.size()]), changelists.toArray(new String[versions.size()]), null).show();
}, error -> {
context.hideProgressDialog();
context.makeToast(R.string.toast_changelog_error);
});
context.getRequestQueue().add(request);
}
use of com.android.volley.toolbox.StringRequest in project FastDev4Android by jiangqqlmj.
the class Fdv_StringRequest method post.
/**
* 根据地址和请求参数 发送POST请求
* @param url 地址服务器地址
* @param listener 数据加载回调接口
* @param params 请求参数
*/
public void post(String url, final Fdv_CallBackListener<String> listener, Map<String, String> params) {
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (listener != null) {
listener.onSuccessResponse(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
if (listener != null) {
listener.onErrorResponse(error);
}
}
});
addRequest(stringRequest, params);
}
use of com.android.volley.toolbox.StringRequest in project AndroidNetworkDemo by dodocat.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
responseContentTextView = (TextView) findViewById(R.id.textViewResponseContent);
StringRequest request = new StringRequest(Request.Method.GET, "https://kyfw.12306.cn/otn/", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
responseContentTextView.setText(response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
responseContentTextView.setText(error.toString());
}
});
RequestManager.getInstance(this).addRequest(request, this);
}
Aggregations