mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-06-10 04:35:52 +02:00
you've been waiting for this moment for so long
This commit is contained in:
37
wear/build.gradle
Normal file
37
wear/build.gradle
Normal file
@ -0,0 +1,37 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
|
||||
defaultConfig {
|
||||
applicationId "pl.szczodrzynski.edziennik"
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
multiDexEnabled true
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
sourceCompatibility = '1.8'
|
||||
targetCompatibility = '1.8'
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
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'
|
||||
}
|
44
wear/src/main/AndroidManifest.xml
Normal file
44
wear/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="pl.szczodrzynski.edziennik">
|
||||
|
||||
<uses-feature android:name="android.hardware.type.watch" />
|
||||
|
||||
<!-- Required to act as a custom watch face. -->
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" /> <!-- Required for complications to receive complication data and open the provider chooser. -->
|
||||
<uses-permission android:name="com.google.android.wearable.permission.RECEIVE_COMPLICATION_DATA" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@android:style/Theme.DeviceDefault">
|
||||
<meta-data
|
||||
android:name="com.google.android.wearable.standalone"
|
||||
android:value="false" />
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version" />
|
||||
|
||||
<uses-library
|
||||
android:name="com.google.android.wearable"
|
||||
android:required="true" />
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppThemeDark">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="android.support.wearable.activity.ConfirmationActivity">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
153
wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.java
Normal file
153
wear/src/main/java/pl/szczodrzynski/edziennik/MainActivity.java
Normal file
@ -0,0 +1,153 @@
|
||||
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<CapabilityInfo> 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<Node> 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<DataItem> 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;
|
||||
}
|
||||
}
|
||||
}
|
47
wear/src/main/res/layout/activity_main.xml
Normal file
47
wear/src/main/res/layout/activity_main.xml
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.wear.widget.drawer.WearableDrawerLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ScrollView
|
||||
android:id="@+id/content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:nestedScrollingEnabled="true">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/linear_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<Button
|
||||
android:id="@+id/test"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Send"/>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<androidx.wear.widget.drawer.WearableNavigationDrawerView
|
||||
android:id="@+id/top_navigation_drawer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/colorPrimary"
|
||||
app:navigationStyle="multiPage"/>
|
||||
</androidx.wear.widget.drawer.WearableDrawerLayout>
|
BIN
wear/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
BIN
wear/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
BIN
wear/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
BIN
wear/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
BIN
wear/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
BIN
wear/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
BIN
wear/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
BIN
wear/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
3
wear/src/main/res/values-round/strings.xml
Normal file
3
wear/src/main/res/values-round/strings.xml
Normal file
@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="hello_world">Hello Round World!</string>
|
||||
</resources>
|
9
wear/src/main/res/values/colors.xml
Normal file
9
wear/src/main/res/values/colors.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="colorPrimary">#2196F3</color>
|
||||
<color name="colorPrimaryDark">#1976D2</color>
|
||||
<color name="colorAccent">#FF5722</color>
|
||||
<color name="colorSection">#4CAF50</color>
|
||||
<color name="background">#000000</color>
|
||||
<color name="digital_text">#ffffff</color>
|
||||
</resources>
|
15
wear/src/main/res/values/dimens.xml
Normal file
15
wear/src/main/res/values/dimens.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!--
|
||||
Because the window insets on round devices are larger than 15dp, this padding only applies
|
||||
to square screens.
|
||||
-->
|
||||
<dimen name="box_inset_layout_padding">0dp</dimen>
|
||||
|
||||
<!--
|
||||
This padding applies to both square and round screens. The total padding between the buttons
|
||||
and the window insets is box_inset_layout_padding (above variable) on square screens and
|
||||
inner_frame_layout_padding (below variable) on round screens.
|
||||
-->
|
||||
<dimen name="inner_frame_layout_padding">5dp</dimen>
|
||||
</resources>
|
8
wear/src/main/res/values/strings.xml
Normal file
8
wear/src/main/res/values/strings.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<resources>
|
||||
<string name="app_name">Szkolny.eu</string>
|
||||
<!--
|
||||
This string is used for square devices and overridden by hello_world in
|
||||
values-round/strings.xml for round devices.
|
||||
-->
|
||||
<string name="hello_world">Hello Square World!</string>
|
||||
</resources>
|
9
wear/src/main/res/values/styles.xml
Normal file
9
wear/src/main/res/values/styles.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="AppThemeDark" parent="android:Theme.Material.NoActionBar" >
|
||||
<item name="android:colorPrimary">@color/colorPrimary</item>
|
||||
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="android:colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
</resources>
|
6
wear/src/main/res/values/wear.xml
Normal file
6
wear/src/main/res/values/wear.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="android_wear_capabilities">
|
||||
<item>edziennik_wear_app</item>
|
||||
</string-array>
|
||||
</resources>
|
Reference in New Issue
Block a user