Skip to content

Instantly share code, notes, and snippets.

# Copyright (c) 2013 Embark Mobile
# Modified to work with Eclipse HIPP instance by David Carver
# Licensed under the MIT License.
# https://github.com/embarkmobile/android-sdk-installer
set +e
#detecting os
os=linux
if [[ `uname` == 'Darwin' ]]; then
@kingargyle
kingargyle / pixel2dpi.java
Created March 21, 2013 18:46
Get the DPI size to use based on Screen Density and the Pixel size. This allows for calculation of image width and image height based on the pixel width and pixel height. Pass in the pixel size and it returns the dpi size to be used in Layouts.
/**
* Takes a value in pixels and converts it to a dpi value. It adjusts
* the dpi size based on the screen density that is returned by
* android.
*
* @param originalHeight
* @param context The activity context
* @return
*/
public static int getDPI(int pixelsize, Activity context) {
@kingargyle
kingargyle / linkrepo.sh
Created March 24, 2013 14:48
Profile for deploying a p2 repo, to a specified directory and providing a symbolic link for the most current version deployed. Run this as part of a release profile with your maven tycho build.
<profiles>
<profile>
<id>release-profile</id>
<properties>
<p2repo-dir>${basedir}/target/deployed-repository</p2repo-dir>
<buildNumber>${project.version}.${maven.build.timestamp}</buildNumber>
</properties>
<build>
<plugins>
<plugin>
<?xml version="1.0" encoding="ISO-8859-1"?>
<opml version="2.0">
<head>
<title>TWiT.tv</title>
<dateModified>Thu, 25 Apr 2013 23:35:52 GMT</dateModified>
</head>
<body>
<outline text="TWiT.tv">
<outline text="Tech News Today" type="rss" xmlUrl="http://feeds.twit.tv/tnt_video_hd" />
<outline text="This Week in Tech" type="rss" xmlUrl="http://feeds.twit.tv/twit_video_hd" />
@kingargyle
kingargyle / p2-example
Last active December 17, 2015 03:09
Example of using the p2-maven-plugin to create a p2 repo with source bundles from maven central or any maven repository.
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.kingargyle</groupId>
<artifactId>p2-orbit-repo-example</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<build>
@kingargyle
kingargyle / VerifyRunOnUiThread
Created August 20, 2014 18:11
Verify that activity runOnUiThread is called using Robolectric and Mockito
/*
* Verifies that an activities runOnUiThread method is called and that
* appropriate class is called. In most cases we don't care about
* actually executing the runOnUiThread, just that it got called.
* By mocking out the Activity, we can use Mockito's verify method to
* make sure the method was called, with the expected Runnable class implementation
* passed into it.
*
* By doing this we avoid having to pause Robolectrics's UIScheduler and BackgroundSchedulers
* and then kick off the task. Since in this case it isn't actually necessary to run the code as it
@kingargyle
kingargyle / RobolectricLoggingRule.java
Last active May 9, 2016 13:53
A Junit 4 Rule to easily access the Log Output from Robolectric.
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.rules.ExternalResource;
import org.robolectric.shadows.ShadowLog;
public class RobolectricLoggingRule extends ExternalResource {
PrintStream loggingStream;
ByteArrayOutputStream loggingOutputStream;
PrintStream defaultStream;
@kingargyle
kingargyle / ShadowSupportFragment.java
Created June 3, 2016 13:44
ShadowSupportFragment implementation for Robolectric
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadows.ShadowApplication;
@kingargyle
kingargyle / ShadowTextInputLayout.java
Created May 31, 2016 17:08
A bare bones Shadow for Robolectric and TextInputLayout from the design library
import android.support.design.widget.TextInputLayout;
import org.robolectric.annotation.Implements;
import org.robolectric.annotation.RealObject;
import org.robolectric.shadows.ShadowViewGroup;
@Implements(TextInputLayout.class)
public class ShadowTextInputLayout extends ShadowViewGroup {
@RealObject private TextInputLayout realTextInputLayout;
@kingargyle
kingargyle / getActivityFromContextWrapper.java
Created September 21, 2016 13:48
Retrieve an Activity from a ContextWrapper
private Activity getActivity() {
Context context = getContext();
while (context instanceof ContextWrapper) {
if (context instanceof Activity) {
return (Activity)context;
}
context = ((ContextWrapper)context).getBaseContext();
}
return null;
}