Skip to content

Instantly share code, notes, and snippets.

@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 / disable-kvm.sh
Created June 11, 2013 15:00
A set of shell scripts that allow toggling between KVM and Virtualbox. Useful when you need to use the Android emulator but also need to use Virtual Box on Linux as well.
#!/bin/bash
sudo /sbin/rmmod kvm_intel
sudo /sbin/rmmod kvm
sudo /etc/init.d/vboxdrv start
@kingargyle
kingargyle / DBTestCase
Created February 24, 2014 20:07
Update of the DBUnit Test Case to work with JUnit 4 instead of relying on JUnit 3.
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.dbunit.IDatabaseTester;
import org.dbunit.PropertiesBasedJdbcDatabaseTester;
import org.dbunit.database.IDatabaseConnection;
import org.junit.Assert;
/**
* Base testCase for database testing.<br>
* Subclasses may override {@link #newDatabaseTester()} to plug-in a different
@kingargyle
kingargyle / pom.xml
Created March 23, 2014 15:58
Mirror Eclipse ADT Plugins to a real P2 repository.
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copy the old update site for ADT plugins into a p2 repository that can be used as part of a tycho build or to handle
cases where Eclipse complains about the external site not being available. This will create a new P2 repository instead
of the old site.xml based repository which is deprecated.
The p2 repository will be in the target/site/p2 directory when finished. You can then use as a local p2 repository in
Eclipse or deploy it to a web server and use it company wide.
-->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.LinearGradient;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffXfermode;
import android.graphics.Shader.TileMode;
import android.util.AttributeSet;
@kingargyle
kingargyle / ShadowCookieManager
Created June 11, 2014 14:25
Extension of Robolectric ShadowCookieManager that implements setAcceptFileSchemeCookies and allowFileSchemeCookies
@Implements(value = CookieManager.class, inheritImplementationMethods = true)
public class ShadowCookieManager extends org.robolectric.shadows.ShadowCookieManager {
private static boolean acceptsFileSchemeCookies = false;
@Implementation
public static void setAcceptFileSchemeCookies(boolean fileSchemeCookies) {
acceptsFileSchemeCookies = fileSchemeCookies;
}
@kingargyle
kingargyle / disableGoogleAnalytics
Created June 24, 2014 18:02
Disable Google Analytics with Robolectric
// Place this in the setup method for any test that is failing to keep it from trying to start
ShadowApplication shadowApplication = Robolectric.shadowOf(Robolectric.application);
shadowApplication.declareActionUnbindable("com.google.android.gms.analytics.service.START");