Skip to content

Instantly share code, notes, and snippets.

final class TokenRequest extends StringRequest {
TokenRequest(int method, String url, Listener<String> listener,
ErrorListener errorListener) {
super(method, url, listener, errorListener);
}
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("grant_type", "client_credentials");
public class TweetsRequest extends JsonObjectRequest {
public TweetsRequest(String url, Listener<JSONObject> listener,
ErrorListener errorListener, List<NameValuePair> params) {
super(url + "?" + URLEncodedUtils.format(params, "UTF-8"),
null, listener, errorListener);
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
@smaspe
smaspe / GetFile.java
Created June 10, 2013 09:37
File download 1-liner
new DefaultHttpClient().execute(new HttpGet("http://www.example.com/somefile.ext"))
.getEntity().writeTo(
new FileOutputStream(new File(root,"Video.mp4")));
public abstract class LoginableActivity extends Activity {
private static final int LOGIN = 42;
public static boolean loggedIn = false;
public void login(View target) {
startActivityForResult(new Intent(this, LoginActivity.class), LOGIN);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
public class RestrictedActivity extends LoginableActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (!loggedIn) {
login(null);
} else {
startup();
public class LoginActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
}
public void login(View target) {
// 30% chances to be logged in !
public class ExtendedImageLoader extends ImageLoader {
/** ... */
/** Creator of Image Requests */
private ImageRequestFactory mImageRequestFactory;
/** ... */
public interface ImageRequestFactory {
public Request<?> getImageRequest(String url, Listener<Bitmap> listener,
int maxWidth, int maxHeight, Config config, ErrorListener errorListener);
}
return new ImageRequest(url, listener, maxWidth, maxHeight, config, errorListener);
public class DelegatingRequest<T> extends Request<T> {
Listener<T> listener;
NewtorkResponseParser<T> parser;
Map<String, String> headers = new HashMap<String, String>();
byte[] customBody = null;
Map<String, String> params = new HashMap<String, String>();
private String customBodyContentType = null;
public DelegatingRequest(int method, String url, NewtorkResponseParser<T> parser, Listener<T> listener, ErrorListener errorListener) {