Skip to content

Instantly share code, notes, and snippets.

View yfujiki's full-sized avatar
💭
Moving around

Yuichi Fujiki yfujiki

💭
Moving around
  • Athlee Ltd
  • Japan
View GitHub Profile
@yfujiki
yfujiki / CallAnimatableDrawable.kt
Last active February 28, 2019 14:15
Calling animation
var drawable = AnimatablePathDrawable(INITIAL_PATH.toMutableList(),
activity!!.applicationContext)
view.pathCanvas.background = drawable
// Assume that the final path on the normalized map rectangle ((0,0),(0,1),(1,1),(1,0))
// is something like this.
drawable.startAnimating(listOf(
NormalizedPoint(0.1f, 0.74f),
NormalizedPoint(0.15f, 0.68f),
NormalizedPoint(0.26f, 0.69f),
@yfujiki
yfujiki / 1_AnimatablePathDrawable_configureStartEndPoints.kt
Last active February 28, 2019 13:52
Calculate start/endpoints from each other
class AnimatablePathDrawable(points: MutableList<NormalizedPoint>, context: Context)
: PathDrawable(points, context), ValueAnimator.AnimatorUpdateListener {
...
// The main method to be explained here. It configures startPoints/endPoints
private fun configureStartEndPoints(fromStartPoints: List<NormalizedPoint>,
toEndPoints: List<NormalizedPoint>) {
// The first part of the explanation above.
// Projecting vertices on the start/end path onto the straight line.
val projectedMergedPoints = projectedMergedPoints(fromStartPoints, toEndPoints)
@yfujiki
yfujiki / AnimatablePathDrawable.kt
Last active February 28, 2019 14:13
AnimatablePathDrawable
class AnimatablePathDrawable(points: MutableList<NormalizedPoint>,
context: Context)
: PathDrawable(points, context),
ValueAnimator.AnimatorUpdateListener {
// Blue points in the illustration
private val startPoints: MutableList<NormalizedPoint> = mutableListOf()
// Red points in the illustration
private val endPoints: MutableList<NormalizedPoint> = mutableListOf()
@yfujiki
yfujiki / 1_SharedElementTransition.xml
Last active February 24, 2019 00:04
Shared Element Transition
<View
android:id="@+id/pathCanvas"
...
android:transitionName="PathCanvasTransition"
/>
@yfujiki
yfujiki / UsePathDrawable.kt
Created February 23, 2019 23:41
How to use PathDrawable instance.
val INITIAL_PATH = listOf(
NormalizedPoint(0.2f, 0.5f),
NormalizedPoint(0.8f, 0.5f)
)
// In MainFragment/MapFragment
// ...
val drawable = PathDrawable(INITIAL_PATH.toMutableList(), activity!!.applicationContext)
view.pathCanvas.background = drawable
@yfujiki
yfujiki / PathDrawable.kt
Created February 23, 2019 23:39
Implementation of PathDrawable
// x and y are normalized value which are in 0~1.
// It doesn't necessarily need to be like this, but I valued the merit that
// I don't need to consider the actual size of the path depending on the layout.
data class NormalizedPoint(val x: Float, val y: Float)
open class PathDrawable(val points: MutableList<NormalizedPoint>, val context: Context) : Drawable() {
protected val path: Path = {
val p = Path()
p
@yfujiki
yfujiki / finalUILabelExtension.swift
Created February 10, 2019 23:52
UILabel extension with regular/bold font that works
extension UILabel {
@objc var substituteFontName: String {
get {
return font.fontName
}
set {
// Set custom font unless the original font is a bold font.
if font.fontName.range(of: "Medium") == nil {
font = UIFont(name: newValue, size: font.pointSize)
}
@yfujiki
yfujiki / naiiveUILabelExtensionWithBold.swift
Last active February 10, 2019 23:45
Another naiive UILabel extension to change font globally
extension UILabel {
@objc var substituteFontName: String {
get {
return font.fontName
}
set {
// Called at every UILabel initialization
font = UIFont(name: newValue, size: font.pointSize)
}
}
@yfujiki
yfujiki / callSubstituteFileName.swift
Created February 10, 2019 23:26
Calling substituteFontName
class AppDelegate: UIResponder, UIApplicationDelegate {
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey: Any]?) -> Bool {
...
UILabel.appearance().substituteFontName = "Gills Sans"
...
return true
@yfujiki
yfujiki / naiiveUILabelExtension.swift
Last active February 10, 2019 23:23
Naive UILabel Extension to change font globally
extension UILabel {
@objc var substituteFontName: String {
get {
return font.fontName
}
set {
font = UIFont(name: newValue, size: font.pointSize)
}
}
}