Skip to content

Instantly share code, notes, and snippets.

@swankjesse
swankjesse / PinnedCertificatesGoogleDotCom.java
Created June 8, 2014 23:31
An example of the code generated by SslContextBuilder.
/*
* Copyright (C) 2014 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
@swankjesse
swankjesse / SslContextBuilder.java
Created June 8, 2014 23:30
Execute this java program to generate an SSL context that contains pinned certificates.
/*
* Copyright (C) 2014 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
@cyrilmottier
cyrilmottier / CityBikesContract.java
Last active January 12, 2024 18:04
Using the new Gradle-based Android build system: a second example
package com.cyrilmottier.android.citybikes.provider;
import android.net.Uri;
import com.cyrilmottier.android.avelov.BuildConfig;
/**
* @author Cyril Mottier
*/
public class CityBikesContract {
package tw.plate;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
SSLSocketFactory goodSslSocketFactory(Context context) {
KeyStore trusted = KeyStore.getInstance("BKS");
InputStream in = context.getResources().openRawResource(R.raw.truststore);
trusted.load(in, TRUST_STORE_PASSWORD);
SSLContext sslContext = SSLContext.getInstance("TLS");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trusted);
sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
return sslContext.getSocketFactory();
@orip
orip / build.gradle
Created October 7, 2013 17:52
Define an Android app's versionName and versionCode from git tags. http://orip.org/2013/10/versioning-android-apps-with-git-tags.html
android {
def gitTag = {
def tagMatchOptions
try {
tagMatchOptions = "--match ${tagToBuildFrom}"
} catch (MissingPropertyException) {
tagMatchOptions = ""
}
"git describe --exact HEAD ${tagMatchOptions}".execute().text.trim()
}()
@shakalaca
shakalaca / build.gradle
Created September 13, 2013 14:38
Remove jar in certain build type
dependencies {
compile files('libs/xxxx.jar')
}
android.applicationVariants.all { variant ->
if (variant.buildType.name.equals("release")) {
variant.dex.libraries = variant.dex.libraries - files('libs/xxxx.jar')
}
}
@shakalaca
shakalaca / build.gradle
Last active December 30, 2022 08:34
move & rename APK files
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.6'
}
}
task wrapper(type: Wrapper) {
@shakalaca
shakalaca / build.gradle
Created September 2, 2013 16:28
Rename output apk file
android.applicationVariants.all { variant ->
// replace output apk name to <product>-<version>-<buildtype>-<githash>.apk
def versionSuffix = variant.buildType.versionNameSuffix ? variant.buildType.versionNameSuffix : ""
def versionName = variant.mergedFlavor.versionName + versionSuffix + "-${gitHash}";
if (variant.zipAlign) {
def apkFinal = variant.outputFile;
variant.outputFile = new File(apkFinal.parentFile, apkFinal.name.replace(variant.buildType.name, versionName));
}
@aprock
aprock / RoundedTransformation.java
Created August 12, 2013 18:08
Rounded Corner Image Transformation for square's Picasso
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;
// enables hardware accelerated rounded corners
// original idea here : http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/