Skip to content

Commit

Permalink
added java sample.
Browse files Browse the repository at this point in the history
upgraded libs.
  • Loading branch information
humazed committed Aug 25, 2017
1 parent ab63fbc commit ed8e9ef
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
kotlin_version = '1.1.3-2'
kotlin_version = '1.1.4-2'
anko_version = '0.10.0'
arch_version = "1.0.0-alpha8"
arch_version = "1.0.0-alpha9"
support_version = "26.0.1"
}

Expand All @@ -12,7 +12,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta2'
classpath 'com.android.tools.build:gradle:3.0.0-beta3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Wed Aug 02 02:35:59 EET 2017
#Fri Aug 25 18:12:12 EET 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-rc-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.12'
androidTestImplementation ('com.android.support.test.espresso:espresso-core:2.2.2', {
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
Expand Down
2 changes: 2 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".JavaActivity">
</activity>
</application>

</manifest>
82 changes: 82 additions & 0 deletions sample/src/main/java/com/huma/roomforasset/JavaActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.huma.roomforasset;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.huma.room_for_asset.RoomAsset;
import com.jakewharton.fliptables.FlipTableConverters;

import java.util.List;

public class JavaActivity extends AppCompatActivity {
private static final String TAG = JavaActivity.class.getSimpleName();

private Button employeesButton;
private Button customersButton;
private TextView resultTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_java);
initView();

final AppDatabase db = RoomAsset.databaseBuilder(
getApplicationContext(), AppDatabase.class, "chinook.db").build();


employeesButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
public void run() {
final List<Employees> employees = db.chinookDao().getEmployees();

runOnUiThread(new Runnable() {
@Override
public void run() {
resultTextView.setText(
FlipTableConverters.fromIterable(employees, Employees.class));
}
});

Log.d(TAG, "employees = " + employees);
}
}).start();
}
});

customersButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
public void run() {
final List<Customers> customers = db.chinookDao().getCustomers();

runOnUiThread(new Runnable() {
@Override
public void run() {
resultTextView.setText(
FlipTableConverters.fromIterable(customers, Customers.class));
}
});
Log.d(TAG, "customers = " + customers);
}
}).start();

}
});
}

private void initView() {
employeesButton = findViewById(R.id.employeesButton);
customersButton = findViewById(R.id.customersButton);
resultTextView = findViewById(R.id.resultTextView);
}
}
19 changes: 18 additions & 1 deletion sample/src/main/java/com/huma/roomforasset/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.huma.roomforasset

import android.database.sqlite.SQLiteOpenHelper
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import com.huma.room_for_asset.RoomAsset
import com.jakewharton.fliptables.FlipTableConverters
import kotlinx.android.synthetic.main.activity_main.*
Expand Down Expand Up @@ -45,4 +47,19 @@ class MainActivity : AppCompatActivity(), AnkoLogger {
}

}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main_activity, menu)
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
R.id.action_open_java_activity -> {
startActivity(Intent(this, MainActivity::class.java))
true
}
else -> super.onOptionsItemSelected(item)
}
}
}
57 changes: 57 additions & 0 deletions sample/src/main/res/layout/activity_java.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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">

<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.constraint.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="com.huma.roomasset.MainActivity">

<Button
android:id="@+id/employeesButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="152dp"
android:layout_marginStart="152dp"
android:text="employees"
app:layout_constraintBaseline_toBaselineOf="@+id/customersButton"
app:layout_constraintStart_toEndOf="@+id/customersButton"/>

<Button
android:id="@+id/customersButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="customers"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>

<TextView
android:id="@+id/resultTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="100dp"
android:text="Result"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"/>

</android.support.constraint.ConstraintLayout>
</HorizontalScrollView>
</ScrollView>
8 changes: 8 additions & 0 deletions sample/src/main/res/menu/menu_main_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_open_java_activity"
android:title="Open Java Activity"
app:showAsAction="ifRoom"/>
</menu>

0 comments on commit ed8e9ef

Please sign in to comment.