Skip to content

Commit

Permalink
Androidx migration (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
grandstaish authored Jun 2, 2019
1 parent 83edce4 commit e369a10
Show file tree
Hide file tree
Showing 37 changed files with 235 additions and 205 deletions.
45 changes: 22 additions & 23 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ allprojects {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.0.0'
classpath 'org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.8'
classpath 'org.jetbrains.dokka:dokka-android-gradle-plugin:0.9.16'
}
}
}
Expand All @@ -35,9 +35,9 @@ subprojects {
}

ext {
minSdkVersion = 9
targetSdkVersion = 27
compileSdkVersion = 27
minSdkVersion = 14
targetSdkVersion = 28
compileSdkVersion = 28
buildToolsVersion = '28.0.3'
sourceCompatibilityVersion = JavaVersion.VERSION_1_7
targetCompatibilityVersion = JavaVersion.VERSION_1_7
Expand All @@ -56,29 +56,28 @@ project.plugins.whenPluginAdded { plugin ->
}
}

def androidSupportVersion = '27.0.1'
def androidxVersion = '1.0.0-beta01'
def gradleIncapHelperVersion = '0.2'
def autoserviceVersion = '1.0-rc5'

ext.deps = [
android : 'com.google.android:android:4.1.1.4',
supportAnnotations : "com.android.support:support-annotations:$androidSupportVersion",
appCompat : "com.android.support:appcompat-v7:$androidSupportVersion",
design : "com.android.support:design:$androidSupportVersion",
supportTestRunner : 'com.android.support.test:runner:0.5',
javapoet : 'com.squareup:javapoet:1.8.0',
autovalueProcessor : 'com.google.auto.value:auto-value:1.6.5',
autovalueApi : 'com.google.auto.value:auto-value-annotations:1.6.3',
autocommon : 'com.google.auto:auto-common:0.8',
autoserviceProcessor : "com.google.auto.service:auto-service:$autoserviceVersion",
autoserviceApi : "com.google.auto.service:auto-service-annotations:$autoserviceVersion",
javaFormat : 'com.google.googlejavaformat:google-java-format:1.1',
junit : 'junit:junit:4.12',
truth : 'com.google.truth:truth:0.30',
compiletesting : 'com.google.testing.compile:compile-testing:0.10',
lombok : "org.projectlombok:lombok:1.16.16",
gradleIncapHelperApi : "net.ltgt.gradle.incap:incap:$gradleIncapHelperVersion",
gradleIncapHelperProcessor: "net.ltgt.gradle.incap:incap-processor:$gradleIncapHelperVersion"
android: 'com.google.android:android:4.1.1.4',
supportAnnotations: "androidx.annotation:annotation:$androidxVersion",
appCompat: "androidx.appcompat:appcompat:$androidxVersion",
supportTestRunner: 'com.android.support.test:runner:0.5',
javapoet: 'com.squareup:javapoet:1.8.0',
autovalueProcessor: 'com.google.auto.value:auto-value:1.6.5',
autovalueApi: 'com.google.auto.value:auto-value-annotations:1.6.3',
autocommon: 'com.google.auto:auto-common:0.8',
autoserviceProcessor: "com.google.auto.service:auto-service:$autoserviceVersion",
autoserviceApi: "com.google.auto.service:auto-service-annotations:$autoserviceVersion",
javaFormat: 'com.google.googlejavaformat:google-java-format:1.1',
junit: 'junit:junit:4.12',
truth: 'com.google.truth:truth:0.30',
compiletesting: 'com.google.testing.compile:compile-testing:0.10',
lombok: "org.projectlombok:lombok:1.16.16",
gradleIncapHelperApi: "net.ltgt.gradle.incap:incap:$gradleIncapHelperVersion",
gradleIncapHelperProcessor: "net.ltgt.gradle.incap:incap-processor:$gradleIncapHelperVersion"
]

task clean(type: Delete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package nz.bradcampbell.autovalueexample;

import android.os.Parcel;
import android.support.annotation.NonNull;

import java.util.Date;

import androidx.annotation.NonNull;
import paperparcel.TypeAdapter;

public final class DateAdapter implements TypeAdapter<Date> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
package nz.bradcampbell.autovalueexample;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import androidx.annotation.Nullable;

public class MainActivity extends AppCompatActivity {
private static final String STATE_KEY = "state";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package nz.bradcampbell.java7example;

import android.os.Parcel;
import android.support.annotation.NonNull;

import java.util.Date;

import androidx.annotation.NonNull;
import paperparcel.TypeAdapter;

public final class DateAdapter implements TypeAdapter<Date> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
package nz.bradcampbell.java7example;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import androidx.annotation.Nullable;

public class MainActivity extends AppCompatActivity {
private State state = new State(0);
private final DateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package nz.bradcampbell.java7example;

import android.os.Parcel;
import android.support.annotation.NonNull;

import java.util.Date;

import androidx.annotation.NonNull;
import paperparcel.TypeAdapter;

public final class DateAdapter implements TypeAdapter<Date> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@
package nz.bradcampbell.java7example;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import androidx.annotation.Nullable;

public class MainActivity extends AppCompatActivity {
private State state = new State(0);
private final DateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
Expand Down
13 changes: 6 additions & 7 deletions examples/kotlin-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,16 @@ android {
}

dependencies {
compile deps.appCompat
compile deps.design
implementation deps.appCompat

compile project(':paperparcel')
compile project(':paperparcel-kotlin')
implementation project(':paperparcel')
implementation project(':paperparcel-kotlin')
kapt project(':paperparcel-compiler')

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

testCompile deps.junit
testCompile deps.compiletesting
testImplementation deps.junit
testImplementation deps.compiletesting
}

tasks.withType(Test) {
Expand Down
3 changes: 1 addition & 2 deletions examples/kotlin-example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning,UnusedAttribute">

<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,54 @@

package nz.bradcampbell.kotlinexample

import android.annotation.SuppressLint
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import android.view.View
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale

class MainActivity : AppCompatActivity() {
var state = State(0, Date())
val dateFormat = SimpleDateFormat("HH:mm")
private var state = State(0, Date())
private val dateFormat = SimpleDateFormat("HH:mm", Locale.ENGLISH)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

savedInstanceState?.let {
state = it.getParcelable<State>("state")
state = it.getParcelable("state")
}

val toolbar = findViewById(R.id.toolbar) as Toolbar
val toolbar = findViewById<Toolbar>(R.id.toolbar)
setSupportActionBar(toolbar)

val plusButton = findViewById(R.id.add_button)
val plusButton = findViewById<View>(R.id.add_button)
plusButton.setOnClickListener {
state = state.copy(state.count + 1, Date())
state = state.copy(count = state.count + 1, modificationDate = Date())
updateText()
}

val subtractButton = findViewById(R.id.subtract_button)
val subtractButton = findViewById<View>(R.id.subtract_button)
subtractButton.setOnClickListener {
state = state.copy(state.count - 1, Date())
state = state.copy(count = state.count - 1, modificationDate = Date())
updateText()
}

updateText()
}

fun updateText() {
val counter = findViewById(R.id.counter) as TextView
counter.text = state.count.toString() + " (updated at " + dateFormat.format(
state.modificationDate) + ")"
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putParcelable("state", state)
}

@SuppressLint("SetTextI18n")
private fun updateText() {
val counter = findViewById<TextView>(R.id.counter)
counter.text = "${state.count} (updated at ${dateFormat.format(state.modificationDate)})"
}
}
58 changes: 44 additions & 14 deletions examples/kotlin-example/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main"
>

<android.support.design.widget.AppBarLayout
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
>

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
<TextView
android:id="@+id/counter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="0"
/>

<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>

</android.support.design.widget.AppBarLayout>
<Button
android:id="@+id/subtract_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/subtract_button"
/>

<Button
android:id="@+id/add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/add_button"
/>

<include layout="@layout/content_main"/>
</LinearLayout>

</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
42 changes: 0 additions & 42 deletions examples/kotlin-example/src/main/res/layout/content_main.xml

This file was deleted.

Loading

0 comments on commit e369a10

Please sign in to comment.