Commit 908f58f7 authored by Lukas Fülling's avatar Lukas Fülling

first take on adding complications

parent 1f77cac3
......@@ -5,7 +5,7 @@ android {
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "io.lerk.vaporface"
minSdkVersion 22
minSdkVersion 24
targetSdkVersion 26
versionCode 1
versionName "1.0"
......@@ -21,10 +21,10 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.support:wearable:2.0.2'
implementation 'com.google.android.gms:play-services-wearable:10.2.6'
implementation 'com.google.android.support:wearable:2.0.3'
implementation 'com.google.android.gms:play-services-wearable:11.0.0'
implementation 'com.android.support:percent:26.0.0'
implementation 'com.android.support:support-v4:26.0.0'
implementation 'com.android.support:recyclerview-v7:26.0.0'
compileOnly 'com.google.android.wearable:wearable:2.0.2'
compileOnly 'com.google.android.wearable:wearable:2.0.3'
}
......@@ -5,7 +5,9 @@
<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="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
......@@ -17,6 +19,9 @@
<meta-data
android:name="com.google.android.wearable.standalone"
android:value="true" />
<uses-library
android:name="com.google.android.wearable"
android:required="false"/>
<service
android:name=".VaporFace"
......@@ -30,7 +35,11 @@
android:resource="@drawable/preview_digital" />
<meta-data
android:name="com.google.android.wearable.watchface.preview_circular"
android:resource="@drawable/preview_digital_circular" />
android:resource="@drawable/preview_digital" />
<meta-data
android:name="com.google.android.wearable.watchface.wearableConfigurationAction"
android:value="io.lerk.android.wearable.watchface.CONFIG_COMPLICATION"/>
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
......@@ -39,6 +48,18 @@
</intent-filter>
</service>
<activity android:name="android.support.wearable.complications.ComplicationHelperActivity"/>
<activity
android:name=".VaporFaceConfigActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="io.lerk.android.wearable.watchface.CONFIG_COMPLICATION"/>
<category android:name="com.google.android.wearable.watchface.category.WEARABLE_CONFIGURATION"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
......
package io.lerk.vaporface;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.wearable.complications.ComplicationHelperActivity;
import android.support.wearable.complications.ComplicationProviderInfo;
import android.support.wearable.complications.ProviderChooserIntent;
import android.support.wearable.complications.ProviderInfoRetriever;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import java.util.concurrent.Executors;
/**
* Copied from the codelabs example, modified. So it's Apache2.
*
* @author Lukas Fülling (lukas@k40s.net)
*/
public class VaporFaceConfigActivity extends Activity implements View.OnClickListener {
private static final String TAG = "ConfigActivity";
static final int COMPLICATION_CONFIG_REQUEST_CODE = 1001;
public enum ComplicationLocation {
BOTTOM
}
private int bottomComplicationId;
// Selected complication id by user.
private int selectedComplicationId;
// ComponentName used to identify a specific service that renders the watch face.
private ComponentName watchFaceComponentName;
// Required to retrieve complication data from watch face for preview.
private ProviderInfoRetriever providerInfoRetriever;
private ImageView bottomComplicationBackground;
private ImageButton bottomComplication;
private Drawable defaultAddComplicationDrawable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_config);
defaultAddComplicationDrawable = getDrawable(R.drawable.add_complication);
selectedComplicationId = -1;
bottomComplicationId =
VaporFace.getComplicationId(ComplicationLocation.BOTTOM);
watchFaceComponentName =
new ComponentName(getApplicationContext(), VaporFace.class);
// Sets up bottom complication preview.
bottomComplicationBackground = findViewById(R.id.bottom_complication_background);
bottomComplication = findViewById(R.id.bottom_complication);
bottomComplication.setOnClickListener(this);
// Sets default as "Add Complication" icon.
bottomComplication.setImageDrawable(defaultAddComplicationDrawable);
bottomComplicationBackground.setVisibility(View.INVISIBLE);
// Initialization of code to retrieve active complication data for the watch face.
providerInfoRetriever =
new ProviderInfoRetriever(getApplicationContext(), Executors.newCachedThreadPool());
providerInfoRetriever.init();
retrieveInitialComplicationsData();
}
@Override
protected void onDestroy() {
super.onDestroy();
providerInfoRetriever.release();
}
public void retrieveInitialComplicationsData() {
final int[] complicationIds = VaporFace.getComplicationIds();
providerInfoRetriever.retrieveProviderInfo(
new ProviderInfoRetriever.OnProviderInfoReceivedCallback() {
@Override
public void onProviderInfoReceived(
int watchFaceComplicationId,
@Nullable ComplicationProviderInfo complicationProviderInfo) {
Log.d(TAG, "onProviderInfoReceived: " + complicationProviderInfo);
updateComplicationViews(watchFaceComplicationId, complicationProviderInfo);
}
}, watchFaceComponentName, complicationIds);
}
@Override
public void onClick(View view) {
if (view.equals(bottomComplication)) {
Log.d(TAG, "Bottom Complication click()");
launchComplicationHelperActivity(ComplicationLocation.BOTTOM);
}
}
// Verifies the watch face supports the complication location, then launches the helper
// class, so user can choose their complication data provider.
private void launchComplicationHelperActivity(ComplicationLocation complicationLocation) {
selectedComplicationId = VaporFace.getComplicationId(complicationLocation);
if (selectedComplicationId >= 0) {
int[] supportedTypes =
VaporFace.getSupportedComplicationTypes(complicationLocation);
startActivityForResult(
ComplicationHelperActivity.createProviderChooserHelperIntent(
getApplicationContext(),
watchFaceComponentName,
selectedComplicationId,
supportedTypes),
VaporFaceConfigActivity.COMPLICATION_CONFIG_REQUEST_CODE);
} else {
Log.d(TAG, "Complication not supported by watch face.");
}
}
public void updateComplicationViews(
int watchFaceComplicationId, ComplicationProviderInfo complicationProviderInfo) {
Log.d(TAG, "updateComplicationViews(): id: " + watchFaceComplicationId);
Log.d(TAG, "\tinfo: " + complicationProviderInfo);
if (watchFaceComplicationId == bottomComplicationId) {
if (complicationProviderInfo != null) {
bottomComplication.setImageIcon(complicationProviderInfo.providerIcon);
bottomComplicationBackground.setVisibility(View.VISIBLE);
} else {
bottomComplication.setImageDrawable(defaultAddComplicationDrawable);
bottomComplicationBackground.setVisibility(View.INVISIBLE);
}
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == COMPLICATION_CONFIG_REQUEST_CODE && resultCode == RESULT_OK) {
// Retrieves information for selected Complication provider.
ComplicationProviderInfo complicationProviderInfo =
data.getParcelableExtra(ProviderChooserIntent.EXTRA_PROVIDER_INFO);
Log.d(TAG, "Provider: " + complicationProviderInfo);
if (selectedComplicationId >= 0) {
updateComplicationViews(selectedComplicationId, complicationProviderInfo);
}
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2017 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<drawable
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
class="android.support.wearable.complications.rendering.ComplicationDrawable"
app:backgroundColor="@android:color/transparent"
app:borderColor="@color/white"
app:borderDashGap="4dp"
app:borderDashWidth="1dp"
app:borderRadius="50dp"
app:borderStyle="dashed"
app:borderWidth="3dp"
app:highlightColor="@color/white"
app:iconColor="@color/white"
app:rangedValuePrimaryColor="@color/white"
app:rangedValueRingWidth="1dp"
app:rangedValueSecondaryColor="@color/white"
app:textColor="@color/white"
app:textSize="12sp"
app:textTypeface="sans-serif-condensed"
app:titleColor="@color/white"
app:titleSize="10sp"
app:titleTypeface="sans-serif">
<ambient
app:highlightColor="@color/white"
app:iconColor="@color/white"
app:rangedValuePrimaryColor="@color/white"
app:titleColor="@color/white"
app:borderColor="@android:color/transparent"
app:rangedValueSecondaryColor="@android:color/transparent"/>
</drawable>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (C) 2017 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/watch_face_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/preview_digital" />
<ImageView
android:id="@+id/bottom_complication_background"
style="?android:borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/watch_face_background"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/complication_margin_bottom"
android:background="@android:color/transparent"
android:src="@drawable/added_complication" />
<ImageButton
android:id="@+id/bottom_complication"
style="?android:borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignTop="@+id/bottom_complication_background"
android:background="@android:color/transparent" />
</RelativeLayout>
\ No newline at end of file
......@@ -3,4 +3,5 @@
<color name="background">#000000</color>
<color name="digital_text">#ffffff</color>
<color name="ambient_mode_text_secondary">#080808</color>
</resources>
......@@ -4,4 +4,6 @@
<dimen name="digital_text_size_round">45dp</dimen>
<dimen name="digital_y_offset">90dp</dimen>
<dimen name="settings_preview_size">180dp</dimen>
<dimen name="complication_margin_bottom">16dp</dimen>
</resources>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment