Skip to content

Instantly share code, notes, and snippets.

Pierre Degand pdegand

View GitHub Profile
@pdegand
pdegand / MainActivity.kt
Last active Aug 1, 2019
Weird Race condition with Channels and ViewModel/LiveData
View MainActivity.kt
class MainActivity : AppCompatActivity(R.layout.activity_main) {
private val viewModel by viewModels<MainViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel.liveData.observe(this, Observer {
Log.d("MAIN", "Display $it in view")
@pdegand
pdegand / GridSpacingItemDecoration.java
Created Apr 19, 2016
A RecyclerView.ItemDecoration that you can apply on grids to have spacing between cells without using ugly margins on the cell layout. Feel free to use either the Kotlin version or the Java version.
View GridSpacingItemDecoration.java
/* The MIT License (MIT)
Copyright (c) 2016 Pierre Degand
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
@pdegand
pdegand / ShinnyTextView.java
Last active Nov 9, 2018
Shinny TextView that glows like the "slide to unlock" text on iOS 7+
View ShinnyTextView.java
/*
* Copyright 2014 Pierre Degand
*
* 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
View :mobile - build.gradle
output.assemble << { // Clean the assets folder of all apk
ant.delete(includeEmptyDirs: 'true') {
fileset(dir: file('./src/main/assets/'), includes: '*.apk')
}
}
View :mobile - build.gradle
variant.outputs.each { output ->
task("handle${variant.name.capitalize()}WearDesc") << {
def apkFileName = "wear-${variant.flavorName}-${variant.buildType.name}.apk"
File wearDescFile = file("${output.processResources.resDir}/xml/wear_desc.xml")
String content = wearDescFile.getText('UTF-8')
content = content.replaceAll(/APPICATION_ID/, "${variant.mergedFlavor.applicationId}")
content = content.replaceAll(/VERSION_CODE/, "${variant.mergedFlavor.versionCode}")
content = content.replaceAll(/VERSION_NAME/, "${variant.mergedFlavor.versionName}")
content = content.replaceAll(/WEAR_BUILD/, apkFileName)
wearDescFile.write(content, 'UTF-8')
View :mobile - main wear_dex.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is filled automatically at build time -->
<wearableApp package="APPICATION_ID">
<versionCode>VERSION_CODE</versionCode>
<versionName>VERSION_NAME</versionName>
<path>WEAR_BUILD</path>
</wearableApp>
View :mobile - build.gradle
project.afterEvaluate {
android.applicationVariants.all { variant ->
if (variant.buildType.name == 'release') {
tasks["generate${variant.name.capitalize()}Assets"]
.dependsOn(":wear:assemble${variant.name.capitalize()}")
}
}
}
View :wear - build.gradle
android.applicationVariants.all { variant ->
if (variant.buildType.name == 'release') {
variant.outputs.each { output ->
output.assemble << {
println "Copying Wear APK inside mobile"
copy {
from output.outputFile.path
into "../mobile/src/main/assets"
}
View :mobile & :wear - build.gradle
android {
...
defaultConfig {
...
versionCode appVersionCode
versionName appVersionName
}
...
}
View :parent - build.gradle
ext {
appVersionCode = 1
appVersionName = "1.0"
}
You can’t perform that action at this time.