Upgrade to Pro — share decks privately, control downloads, hide ads and more …

既存AndroidアプリでKotlin導入を考える

 既存AndroidアプリでKotlin導入を考える

関モバ #8での発表

Naoki Morioka

December 07, 2015
Tweet

More Decks by Naoki Morioka

Other Decks in Technology

Transcript

  1. roadmap • May 29, 2015 M12 release • September 16,

    2015 M13 release • October 1, 2015 M14 release • October 22, 2015 Beta Candidate relase • November 1, 2015 1.0 Beta release • November 16, 2015 1.0 Beta2 release
  2. Java Code import android.content.Context;
 import android.graphics.Color;
 import android.support.annotation.ColorRes;
 import android.support.annotation.IntRange;


    
 public class ColorUtils {
 
 public static int resourceColorAlpha(Context context, @ColorRes int colorResource, @IntRange(from = 0, to = 255) int alphaDecimal) {
 int color = context.getResources().getColor(colorResource);
 int red = Color.red(color);
 int green = Color.green(color);
 int blue = Color.blue(color);
 return Color.parseColor("#" + Integer.toHexString(Color.argb(alphaDecimal, red, green, blue)));
 }
 }
  3. Kotlin Code import android.content.Context
 import android.graphics.Color
 import android.support.annotation.ColorRes
 import android.support.annotation.IntRange


    
 object ColorUtils {
 fun resourceColorAlpha(context: Context, @ColorRes colorResource: Int, @IntRange(from = 0, to = 255) alphaDecimal: Int): Int {
 val color = context.resources.getColor(colorResource)
 val red = Color.red(color)
 val green = Color.green(color)
 val blue = Color.blue(color)
 return Color.parseColor("#" + Integer.toHexString(Color.argb(alphaDecimal, red, green, blue)))
 }
 }
  4. kapt • JSR 269 Annotation Processing ͷkotlin൛ Kotlin Annotaion Processing

    Tool • Ξϊςʔγϣϯهड़͔ΒJavaίʔυΛੜ੒͢ Δ࢓૊Έ • Kotlin M12 ~
  5. build.gradle dependencies {
 compile fileTree(dir: 'libs', include: ['*.jar'])
 testCompile 'junit:junit:4.12'


    compile 'com.android.support:appcompat-v7:23.1.1'
 compile 'com.android.support:design:23.1.1'
 
 // Kotlin
 compile 'org.jetbrains.kotlin:kotlin-stdlib:1.0.0- beta-2423'
 
 //Dagger2
 compile 'com.google.dagger:dagger:2.0.2'
 kapt 'com.google.dagger:dagger-compiler:2.0.2'
 provided 'org.glassfish:javax.annotation:10.0-b28'
 }