Skip to content

Instantly share code, notes, and snippets.

@myaaaaa-chan
myaaaaa-chan / VolleyGsonRequest.java
Created August 1, 2013 07:07
Volley Gson Request Wrapper
import java.util.HashMap;
import android.app.ProgressDialog;
import com.android.volley.Request.Method;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
/**
* The Class VolleyGsonRequest.
@orip
orip / PicassoUtils.java
Last active July 18, 2018 08:39
Working around https://github.com/square/okhttp/issues/184 for Picasso 2.x (older revisions for Picasso 1.1.1)
package com.example;
import android.content.Context;
import com.squareup.okhttp.HttpResponseCache;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.picasso.OkHttpDownloader;
import com.squareup.picasso.Picasso;
import javax.net.ssl.SSLContext;
import java.io.File;
@imminent
imminent / AndroidCookieStore.java
Created July 5, 2013 16:00
Example of a persistent cookie store that only keeps one cookie around.
package com.example.android.utilities;
import android.content.SharedPreferences;
import android.os.PatternMatcher;
import android.util.Log;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.URI;
import java.util.List;
@myaaaaa-chan
myaaaaa-chan / GsonRequest
Created July 4, 2013 05:28
Volley adapter for JSON requests with POST method that will be parsed into Java objects by Gson @see https://gist.github.com/ficusk/5474673
package jp.i_dig.community.util;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.squareup.okhttp.HttpResponseCache;
import com.squareup.okhttp.OkHttpClient;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.UUID;
@swankjesse
swankjesse / RetrofitCachingExample.java
Created June 29, 2013 03:03
Demonstrate HTTP caching with OkHttp and Retrofit.
/*
* Copyright (C) 2013 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@frankiesardo
frankiesardo / NetworkButton.java
Last active December 18, 2015 18:18
An Android Button that automatically enables itself when the internet connectivity is on and disables when is off.
public class NetworkButton extends Button {
// See Otto's sample application for how BusProvider works. Any mechanism
// for getting a singleton instance will work.
Bus bus = BusProvider.get();
public NetworkButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
@JakeWharton
JakeWharton / OkConnectionFactory.java
Created June 17, 2013 15:04
A connection factory for using OkHttp with Kevin Sawicki's HttpRequest library.
/**
* A {@link HttpRequest.ConnectionFactory connection factory} which uses OkHttp.
* <p/>
* Call {@link HttpRequest#setConnectionFactory(HttpRequest.ConnectionFactory)} with an instance of
* this class to enable.
*/
public class OkConnectionFactory implements HttpRequest.ConnectionFactory {
private final OkHttpClient client;
public OkConnectionFactory() {
@julianshen
julianshen / build.gradle
Created June 15, 2013 15:40
Include native lib in gradle
task copyNativeLibs(type: Copy) {
from fileTree(dir: 'jni', include: '**/*.so' ) into 'build/native-libs'
}
tasks.withType(Compile) { compileTask -> compileTask.dependsOn copyNativeLibs }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniDir file('build/native-libs')
}
@chrislacy
chrislacy / gist:5646240
Last active April 23, 2018 13:57
Icon pack makers wanting to implement 'apply icon pack' functionality for Action Launcher should just include this snippet as appropriate.
Button actionLauncherButton = (Button) findViewById(R.id.action_launcher_button);
actionLauncherButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Check Action Launcher is installed
Intent intent = getPackageManager().getLaunchIntentForPackage("com.actionlauncher.playstore");
if (intent != null) {
// TODO BY YOU: set this package name as appropriate. Eg "kov.theme.stark"
String yourPackageName = ;