From 752cdfa8d6267f2be4dfa60a2775b06af3d66ea1 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Thu, 17 Sep 2020 17:30:28 +0200 Subject: [PATCH] Implement wear module base. --- .idea/compiler.xml | 1 + .../pl/szczodrzynski/edziennik/Extensions.kt | 2 +- .../edziennik/ui/modules/home/HomeFragment.kt | 3 +- build.gradle | 2 + settings.gradle | 2 + wear/.gitignore | 1 + wear/build.gradle | 48 +++-- wear/proguard-rules.pro | 21 +++ .../edziennik/ExampleInstrumentedTest.kt | 26 +++ wear/src/main/AndroidManifest.xml | 37 ++-- .../szczodrzynski/edziennik/MainActivity.java | 153 --------------- .../szczodrzynski/edziennik/MainActivity.kt | 47 +++++ .../drawable-v24/ic_launcher_foreground.xml | 34 ++++ .../res/drawable/ic_launcher_background.xml | 174 ++++++++++++++++++ wear/src/main/res/layout/activity_main.xml | 56 ++---- .../res/mipmap-anydpi-v26/ic_launcher.xml | 9 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 9 + wear/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 2963 -> 3593 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5339 bytes wear/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 2060 -> 2636 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 3388 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 4490 -> 4926 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7472 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 6387 -> 7909 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 11873 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 10652 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 16570 bytes wear/src/main/res/values-night/themes.xml | 20 ++ wear/src/main/res/values-round/strings.xml | 4 + wear/src/main/res/values/colors.xml | 17 +- wear/src/main/res/values/dimens.xml | 4 + wear/src/main/res/values/strings.xml | 4 + wear/src/main/res/values/styles.xml | 9 - wear/src/main/res/values/themes.xml | 20 ++ wear/src/main/res/values/wear.xml | 6 - .../edziennik/ExampleUnitTest.kt | 20 ++ 36 files changed, 481 insertions(+), 248 deletions(-) create mode 100644 wear/.gitignore create mode 100644 wear/proguard-rules.pro create mode 100644 wear/src/androidTest/java/pl/szczodrzynski/edziennik/ExampleInstrumentedTest.kt delete mode 100644 wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.java create mode 100644 wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt create mode 100644 wear/src/main/res/drawable-v24/ic_launcher_foreground.xml create mode 100644 wear/src/main/res/drawable/ic_launcher_background.xml create mode 100644 wear/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 wear/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 wear/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 wear/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 wear/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 wear/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 wear/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 wear/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 wear/src/main/res/values-night/themes.xml delete mode 100644 wear/src/main/res/values/styles.xml create mode 100644 wear/src/main/res/values/themes.xml delete mode 100644 wear/src/main/res/values/wear.xml create mode 100644 wear/src/test/java/pl/szczodrzynski/edziennik/ExampleUnitTest.kt diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 733f463f..12871fc6 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -11,6 +11,7 @@ + \ No newline at end of file diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt index 7306109a..d7fb13de 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt @@ -299,7 +299,7 @@ fun colorFromCssName(name: String): Int { "orange" -> 0xffffa500 "black" -> 0xff000000 "white" -> 0xffffffff - else -> -1 + else -> -1L }.toInt() } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt index 1b53e826..8afd7c04 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/home/HomeFragment.kt @@ -152,13 +152,14 @@ class HomeFragment : Fragment(), CoroutineScope { val items = mutableListOf() cards.mapNotNullTo(items) { + @Suppress("USELESS_CAST") when (it.cardId) { HomeCard.CARD_LUCKY_NUMBER -> HomeLuckyNumberCard(it.cardId, app, activity, this, app.profile) HomeCard.CARD_TIMETABLE -> HomeTimetableCard(it.cardId, app, activity, this, app.profile) HomeCard.CARD_GRADES -> HomeGradesCard(it.cardId, app, activity, this, app.profile) HomeCard.CARD_EVENTS -> HomeEventsCard(it.cardId, app, activity, this, app.profile) else -> null - } + } as HomeCard? } //if (App.devMode) // items += HomeDebugCard(100, app, activity, this, app.profile) diff --git a/build.gradle b/build.gradle index 43dc3e9f..6ef45518 100644 --- a/build.gradle +++ b/build.gradle @@ -53,6 +53,8 @@ buildscript { retrofit : "2.6.4" ] + versions.kotlin = '1.4.0' + versions.kotlin = '1.4.0' } repositories { diff --git a/settings.gradle b/settings.gradle index 3625fac9..b43e4d66 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,5 @@ +include ':wear' +include ':wear' include ':codegen' include ':annotation' rootProject.name='Szkolny.eu' diff --git a/wear/.gitignore b/wear/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/wear/.gitignore @@ -0,0 +1 @@ +/build diff --git a/wear/build.gradle b/wear/build.gradle index 6e4aa162..5b531ae4 100644 --- a/wear/build.gradle +++ b/wear/build.gradle @@ -1,37 +1,53 @@ -apply plugin: 'com.android.application' +/* + * Copyright (c) Kacper Ziubryniewicz 2020-9-17 + */ + +plugins { + id 'com.android.application' + id 'kotlin-android' +} android { - compileSdkVersion 28 - + compileSdkVersion 29 + buildToolsVersion "29.0.3" defaultConfig { applicationId "pl.szczodrzynski.edziennik" minSdkVersion 23 - targetSdkVersion 28 + targetSdkVersion 29 versionCode 1 versionName "1.0" - multiDexEnabled true + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } + buildTypes { release { minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { - sourceCompatibility = '1.8' - targetCompatibility = '1.8' + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' } } dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation "org.jetbrains.kotlin:kotlin-stdlib:${versions.kotlin}" + implementation 'androidx.core:core-ktx:1.3.1' + implementation 'androidx.appcompat:appcompat:1.2.0' + implementation 'com.google.android.material:material:1.2.1' + testImplementation 'junit:junit:4.13' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - implementation 'com.google.android.support:wearable:2.4.0' - implementation 'com.google.android.gms:play-services-wearable:16.0.1' - implementation 'androidx.percentlayout:percentlayout:1.0.0-beta01' - implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01' - implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01' - implementation 'androidx.wear:wear:1.0.0-beta01' - compileOnly 'com.google.android.wearable:wearable:2.4.0' + implementation 'androidx.wear:wear:1.0.0' + implementation 'com.google.android.support:wearable:2.7.0' + compileOnly 'com.google.android.wearable:wearable:2.7.0' + + implementation "com.google.android.gms:play-services-wearable:${versions.play_services}" } diff --git a/wear/proguard-rules.pro b/wear/proguard-rules.pro new file mode 100644 index 00000000..f1b42451 --- /dev/null +++ b/wear/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/wear/src/androidTest/java/pl/szczodrzynski/edziennik/ExampleInstrumentedTest.kt b/wear/src/androidTest/java/pl/szczodrzynski/edziennik/ExampleInstrumentedTest.kt new file mode 100644 index 00000000..84289796 --- /dev/null +++ b/wear/src/androidTest/java/pl/szczodrzynski/edziennik/ExampleInstrumentedTest.kt @@ -0,0 +1,26 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-9-17 + */ + +package pl.szczodrzynski.edziennik + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.assertEquals +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("pl.szczodrzynski.edziennik", appContext.packageName) + } +} diff --git a/wear/src/main/AndroidManifest.xml b/wear/src/main/AndroidManifest.xml index 8148e132..803bc28d 100644 --- a/wear/src/main/AndroidManifest.xml +++ b/wear/src/main/AndroidManifest.xml @@ -1,44 +1,43 @@ + + - + - - - + - - - + android:theme="@style/Theme.Szkolnyeu"> + + + + android:label="@string/app_name"> - - - - \ No newline at end of file + diff --git a/wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.java b/wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.java deleted file mode 100644 index b96fff96..00000000 --- a/wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.java +++ /dev/null @@ -1,153 +0,0 @@ -package pl.szczodrzynski.edziennik; - -import android.app.Activity; -import android.graphics.drawable.Drawable; -import android.os.Bundle; -import androidx.wear.widget.drawer.WearableDrawerLayout; -import androidx.wear.widget.drawer.WearableDrawerView; -import androidx.wear.widget.drawer.WearableNavigationDrawerView; -import android.support.wearable.activity.WearableActivity; -import android.util.Log; -import android.view.View; -import android.widget.ProgressBar; - -import com.google.android.gms.tasks.Task; -import com.google.android.gms.wearable.CapabilityClient; -import com.google.android.gms.wearable.CapabilityInfo; -import com.google.android.gms.wearable.DataEvent; -import com.google.android.gms.wearable.DataItem; -import com.google.android.gms.wearable.Node; -import com.google.android.gms.wearable.PutDataMapRequest; -import com.google.android.gms.wearable.PutDataRequest; -import com.google.android.gms.wearable.Wearable; - -import java.util.Arrays; -import java.util.Set; - -public class MainActivity extends WearableActivity { - - private static final String TAG = "MainActivity"; - private ProgressBar progressBar; - private WearableDrawerLayout wearableDrawerLayout; - private WearableNavigationDrawerView mWearableNavigationDrawer; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - // Enables Always-on - setAmbientEnabled(); - - progressBar = findViewById(R.id.progressBar); - - wearableDrawerLayout = findViewById(R.id.drawer_layout); - wearableDrawerLayout.setDrawerStateCallback(new WearableDrawerLayout.DrawerStateCallback() { - @Override - public void onDrawerOpened(WearableDrawerLayout layout, WearableDrawerView drawerView) { - super.onDrawerOpened(layout, drawerView); - } - - @Override - public void onDrawerClosed(WearableDrawerLayout layout, WearableDrawerView drawerView) { - super.onDrawerClosed(layout, drawerView); - progressBar.setVisibility(View.GONE); - } - }); - - mWearableNavigationDrawer = (WearableNavigationDrawerView) findViewById(R.id.top_navigation_drawer); - WearableNavigationDrawerView.WearableNavigationDrawerAdapter navigationDrawerAdapter = new NavigationDrawerAdapter(this); - mWearableNavigationDrawer.setAdapter(navigationDrawerAdapter); - mWearableNavigationDrawer.addOnItemSelectedListener(new WearableNavigationDrawerView.OnItemSelectedListener() { - @Override - public void onItemSelected(int i) { - //Toast.makeText(MainActivity.this, "Selected item "+i, Toast.LENGTH_SHORT).show(); - progressBar.setVisibility(View.VISIBLE); - } - }); - // Peeks navigation drawer on the top. - mWearableNavigationDrawer.getController().peekDrawer(); - - Wearable.getMessageClient(this).addListener(messageEvent -> { - Log.d(TAG, messageEvent.getPath()+" :: "+ Arrays.toString(messageEvent.getData())); - }); - - Task capabilityInfoTask = - Wearable.getCapabilityClient(this) - .getCapability("edziennik_phone_app", CapabilityClient.FILTER_REACHABLE); - capabilityInfoTask.addOnCompleteListener((task) -> { - if (task.isSuccessful()) { - CapabilityInfo capabilityInfo = task.getResult(); - assert capabilityInfo != null; - Set nodes; - nodes = capabilityInfo.getNodes(); - Log.d(TAG, "Nodes "+nodes); - } else { - Log.d(TAG, "Capability request failed to return any results."); - } - }); - - Wearable.getDataClient(this).addListener(dataEventBuffer -> { - Log.d(TAG, "onDataChanged(): " + dataEventBuffer); - - for (DataEvent event : dataEventBuffer) { - if (event.getType() == DataEvent.TYPE_CHANGED) { - String path = event.getDataItem().getUri().getPath(); - Log.d(TAG, "Data "+path+ " :: "+Arrays.toString(event.getDataItem().getData())); - } - } - }); - - findViewById(R.id.test).setOnClickListener((v -> { - PutDataMapRequest putDataMapRequest = PutDataMapRequest.create("/ping"); - putDataMapRequest.getDataMap().putLong("millis", System.currentTimeMillis()); - - PutDataRequest request = putDataMapRequest.asPutDataRequest(); - request.setData("Hello".getBytes()); - request.setUrgent(); - - Log.d(TAG, "Generating DataItem: " + request); - - Task dataItemTask = - Wearable.getDataClient(getApplicationContext()).putDataItem(request); - dataItemTask.addOnCompleteListener(task -> { - if (task.isSuccessful()) { - - Log.d(TAG, "success"); - } else { - Log.d(TAG, "Capability request failed to return any results."); - } - }); - })); - - - - // Block on a task and get the result synchronously (because this is on a background - // thread). - //DataItem dataItem = dataItemTask.getResult(); - - //Log.d(TAG, "DataItem saved: " + dataItem); - - } - - - private class NavigationDrawerAdapter extends WearableNavigationDrawerView.WearableNavigationDrawerAdapter { - public NavigationDrawerAdapter(Activity activity) { - - } - - @Override - public CharSequence getItemText(int i) { - return "Item "+i; - } - - @Override - public Drawable getItemDrawable(int i) { - return null; - } - - @Override - public int getCount() { - return 5; - } - } -} diff --git a/wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt b/wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt new file mode 100644 index 00000000..ed694372 --- /dev/null +++ b/wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.kt @@ -0,0 +1,47 @@ +/* + * Copyright (c) Kacper Ziubryniewicz 2020-9-17 + */ + +package pl.szczodrzynski.edziennik + +import android.os.Bundle +import android.support.wearable.activity.WearableActivity +import com.google.android.gms.wearable.* + +class MainActivity : WearableActivity(), DataClient.OnDataChangedListener { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + // Enables Always-on + setAmbientEnabled() + } + + override fun onDataChanged(dataEvents: DataEventBuffer) { + dataEvents.forEach { event -> + if (event.type == DataEvent.TYPE_CHANGED) { + event.dataItem.also { item -> + if (item?.uri?.path?.compareTo("/test") == 0) { + DataMapItem.fromDataItem(item).dataMap.apply { + getInt("test") + } + } + } + } else if (event.type == DataEvent.TYPE_DELETED) { + // DataItem deleted + } + + } + } + + override fun onResume() { + super.onResume() + Wearable.getDataClient(this).addListener(this) + } + + override fun onPause() { + super.onPause() + Wearable.getDataClient(this).removeListener(this) + } +} diff --git a/wear/src/main/res/drawable-v24/ic_launcher_foreground.xml b/wear/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..d36dec1a --- /dev/null +++ b/wear/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/wear/src/main/res/drawable/ic_launcher_background.xml b/wear/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..f14b2240 --- /dev/null +++ b/wear/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,174 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wear/src/main/res/layout/activity_main.xml b/wear/src/main/res/layout/activity_main.xml index 83b1a1ef..8d270149 100644 --- a/wear/src/main/res/layout/activity_main.xml +++ b/wear/src/main/res/layout/activity_main.xml @@ -1,47 +1,29 @@ - - + + + android:layout_height="match_parent" + android:background="@color/white" + android:padding="@dimen/box_inset_layout_padding" + tools:context=".MainActivity" + tools:deviceIds="wear"> + android:layout_height="match_parent" + android:padding="@dimen/inner_frame_layout_padding" + app:boxedEdges="all" + tools:ignore="MissingPrefix"> - - - -