Skip to content

Instantly share code, notes, and snippets.

@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 {
@cyrilmottier
cyrilmottier / ResourcesAdditions.java
Last active January 12, 2024 17:55
Lightweight key-value pairs resources for Android applications.
package com.cyrilmottier.android.resourcesadditions;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.os.Bundle;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
/**
* @author Cyril Mottier
@cyrilmottier
cyrilmottier / LicensesActivity.java
Created November 21, 2012 11:10
"Open source licenses" screen
package com.cyrilmottier.android.citybikes;
import android.os.Bundle;
import com.cyrilmottier.android.avelov.R;
import com.cyrilmottier.android.citybikes.app.BaseActivity;
public class LicensesActivity extends BaseActivity {
private WebView mWebView;
@cyrilmottier
cyrilmottier / AndroidManifest.xml
Last active January 30, 2023 00:04
Android example of how to add a custom logo to the ActionBar and ensure the best possible matching starting Window.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cyrilmottier.android.anapp">
<!-- ... -->
<application
android:icon="@drawable/ic_launcher"
android:label="@string/config_app_name"
android:theme="@style/Theme.AnApp" >
@cyrilmottier
cyrilmottier / gist:2367432
Created April 12, 2012 13:49
View#onConfigurationChanged(Configuration) on API < 8
package com.cyrilmottier.android.androidtips;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
@cyrilmottier
cyrilmottier / _app_avelibRelease_res_values_config.xml
Last active November 20, 2020 11:27
Using the new Gradle-based Android build system: an example
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="config_app_name">AVélib</string>
<string name="config_authority">com.cyrilmottier.android.avelib.citybikes</string>
<string name="config_com.google.android.maps.v2.api_key">XXX</string>
</resources>
val colorCount = RAINBOW_COLORS.size
val colors = IntArray(colorCount * 2)
val stops = FloatArray(colorCount * 2)
for (i in 0 until colorCount) {
colors[i * 2] = ContextCompat.getColor(context, RAINBOW_COLORS[i])
colors[i * 2 + 1] = colors[i * 2]
stops[i * 2] = (i / colorCount.toFloat() + RAINBOW_EPSILON).coerceAtLeast(0f)
stops[i * 2 + 1] = ((i + 1) / colorCount.toFloat() - RAINBOW_EPSILON).coerceAtMost(1f)
}
return object : Drawable() {
private val paint = Paint()
init {
val scaledWidth = RAINBOW_WIDTH * context.resources.displayMetrics.density
val y1 = (Math.sin(2 * RAINBOW_ANGLE) / 2 * scaledWidth).toFloat()
val x1 = (scaledWidth - Math.tan(RAINBOW_ANGLE) * y1).toFloat()
paint.shader = LinearGradient(
0f, 0f,
x1, y1,
val colorCount = RAINBOW_COLORS.size
val colors = IntArray(colorCount * 2)
val stops = FloatArray(colorCount * 2)
for (i in 0 until colorCount) {
colors[i * 2] = ContextCompat.getColor(context, RAINBOW_COLORS[i])
colors[i * 2 + 1] = colors[i * 2]
stops[i * 2] = i / colorCount.toFloat()
stops[i * 2 + 1] = (i + 1) / colorCount.toFloat()
}
@ColorRes
private val RAINBOW_COLORS = intArrayOf(
R.color.pink,
R.color.orange,
R.color.yellow,
R.color.green,
R.color.emerald_green,
R.color.azur_blue,
R.color.blue,
R.color.cerulean_blue,