Skip to content

Instantly share code, notes, and snippets.

View timrijckaert's full-sized avatar

Tim Rijckaert timrijckaert

View GitHub Profile
@timrijckaert
timrijckaert / AndroidManifest.xml
Last active May 2, 2020 19:32
Test rule that disables animations and softkeyboard before any test. Easy access function to control demo modus on API 23 and up devices
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="be.rijckaert.tim.disableanimations">
<!-- Place this permission in your debug folder -->
<uses-permission android:name="android.permission.SET_ANIMATION_SCALE"/>
</manifest>
@timrijckaert
timrijckaert / GravitySnapHelper.java
Created October 4, 2016 21:51
A snap helper that has a notion of Gravity and will snap accordingly
package be.tim.rijckaert.snaprecyclerview;
import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.LinearSnapHelper;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.LayoutManager;
private fun createBigContentView(text: String, bigImage: Bitmap, pill: Bitmap) =
RemoteViews(context.packageName, R.layout.notification_big_content_view).apply {
setImageViewBitmap(R.id.notification_background_image, bigImage)
setImageViewBitmap(R.id.notification_pill, pill)
setTextViewText(R.id.notification_text, text)
}
private fun createNotification(channelId: String, text: String, title: String, id: String, url: String, bigImage: Bitmap, pillImage: Bitmap): Notification {
return NotificationCompat.Builder(context, channelId)
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(R.drawable.ic_notification)
.setContentIntent(createPendingIntent(id, url))
.setAutoCancel(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSound(soundHelper.vrtNwsNotificationSound)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE)
PillView(context).run {
bind(pillViewModel)
measure(
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
)
val bitmap = Bitmap.createBitmap(measuredWidth, measuredHeight, Bitmap.Config.ARGB_4444)
val canvas = Canvas(bitmap)
layout(0, 0, measuredWidth, measuredHeight)
draw(canvas)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="270"
android:startColor="#55000000"
android:centerColor="#33000000"
android:endColor="#AA000000"
android:type="linear"/>
</shape>
@timrijckaert
timrijckaert / notificationBuilder.kt
Created April 9, 2019 15:34
NotificationBuilder
private fun createNotification(channelId: String, text: String, title: String, id: String, url: String, bitmap: Bitmap): Notification {
return NotificationCompat.Builder(context, channelId)
.setContentTitle(title)
.setContentText(text)
.setSmallIcon(R.drawable.ic_notification)
.setContentIntent(createPendingIntent(id, url))
.setAutoCancel(true)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setSound(soundHelper.vrtNwsNotificationSound)
.setDefaults(NotificationCompat.DEFAULT_VIBRATE)
@timrijckaert
timrijckaert / output.json
Created December 6, 2018 20:50
Scrapes the contents from the maven.google site in an easier to read JSON format. Open developer console and paste following code.
[
[
{
"android.arch.core":{
"common":[
"1.0.0-alpha4",
"1.0.0-alpha5",
"1.0.0-alpha6",
"1.0.0-alpha7",
"1.0.0-alpha8",
@timrijckaert
timrijckaert / ImmediateSchedulersRule.java
Created March 5, 2017 22:35
RxJava2 Rule to change the Schedulers to immediate one. (https://www.infoq.com/articles/Testing-RxJava2)
private static class ImmediateSchedulersRule implements TestRule {
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
RxJavaPlugins.setIoSchedulerHandler(scheduler ->
Schedulers.trampoline());
RxJavaPlugins.setComputationSchedulerHandler(scheduler ->
Schedulers.trampoline());
APK_NAME = "test-butler-app-1.2.0.apk"
def install_test_butler(device_id):
is_emulator = device_id.startswith("emulator")
if is_emulator:
install_cmd = "adb -s %s install -r %s" % (device_id, APK_NAME)
subprocess.Popen(install_cmd, shell=True, stdout=subprocess.PIPE).stdout.read()
print "TestButler was installed on device with id: %s" % device_id