Skip to content

Instantly share code, notes, and snippets.

View Richie97's full-sized avatar

Eric Richardson Richie97

View GitHub Profile
@Richie97
Richie97 / MapFragment BlackBoxes
Created January 14, 2013 22:55
Map Fragment Black Box Fix
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB){
FrameLayout frameLayout = new FrameLayout(getActivity());
frameLayout.setBackgroundColor(getResources().getColor(android.R.color.transparent));
((ViewGroup) v).addView(frameLayout,
new ViewGroup.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT));
}
@Richie97
Richie97 / gist:4675709
Created January 30, 2013 18:55
Enabling Activites, DayDreams, ETC
getApplicationContext().getPackageManager().setComponentEnabledSetting(new ComponentName(AboutActivity.this, VergeDaydream.class), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
public String introduction(){
return getString(R.string.hello_world);
}
@Richie97
Richie97 / gist:5373818
Created April 12, 2013 17:49
Gson Array parsing test
String json = "[{\"id\":5,\"name\":\"Action\"},{\"id\":6,\"name\":\"Adventure\"}]";
@Test
public void testJsonArray() throws Exception {
parseJson();
}
void parseJson(){
Type t = new TypeToken<List<Result>>(){}.getType();
List<Result> result = new Gson().fromJson(json, t);
Assert.assertEquals(2, result.size());
SpannableString s = new SpannableString(title);
s.setSpan(new FontTypefaceSpan(this, "Roboto-Light.ttf"), 0, s.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
@Richie97
Richie97 / gist:7226214
Created October 30, 2013 02:17
Pager that peeks on either side
int pagerWidth = size.x - getResources().getDimensionPixelSize(R.dimen.hero_pager_margins);
pager.setLayoutParams(new RelativeLayout.LayoutParams(Math.max(pagerWidth, 1), getResources().getDimensionPixelSize(R.dimen.hero_pager_height)));
pager.setClipChildren(false);
pager.setPageMargin(-getResources().getDimensionPixelSize(R.dimen.hero_pager_margins));
OkHttpClient providesOkHttpClient() {
OkHttpClient httpClient = new OkHttpClient();
SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, null);
} catch (GeneralSecurityException e) {
throw new AssertionError(); // The system has no TLS. Just give up.
}
httpClient.setSslSocketFactory(sslContext.getSocketFactory());
@Richie97
Richie97 / gist:8221724
Created January 2, 2014 16:22
AsyncTaskLoader Fun.
public class SampleLoader extends AsyncTaskLoader<List<SampleItem>> {
// We hold a reference to the Loader’s data here.
private List<SampleItem> mData;
public SampleLoader(Context ctx) {
// Loaders may be used across multiple Activitys (assuming they aren't
// bound to the LoaderManager), so NEVER hold a reference to the context
// directly. Doing so will cause you to leak an entire Activity's context.
// The superclass constructor will store a reference to the Application
<oak.widget.TextViewWithFont
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:oak="http://oak/oak/schema"
oak:font="Font.ttf"/>
<oak.widget.TextViewWithFont
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:res="http://schemas.android.com/apk/res-auto"
res:oakFont="Font.ttf"/>