diff --git a/platform/android/.gitignore b/platform/android/.gitignore index 5ede06a83..b0e8cceb4 100644 --- a/platform/android/.gitignore +++ b/platform/android/.gitignore @@ -21,6 +21,7 @@ local.properties # Token file MapboxGLAndroidSDKTestApp/src/main/res/values/developer-config.xml +MapboxGLAndroidSDKWearTestApp/src/main/res/values/developer-config.xml # Twitter Fabric / Crashlytics fabric.properties diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/build.gradle b/platform/android/MapboxGLAndroidSDKWearTestApp/build.gradle new file mode 100644 index 000000000..6fbab3a32 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/build.gradle @@ -0,0 +1,56 @@ +apply plugin: 'com.android.application' + +task accessToken { + def tokenFile = new File("MapboxGLAndroidSDKWearTestApp/src/main/res/values/developer-config.xml") + if (!tokenFile.exists()) { + String tokenFileContents = "\n" + + "\n" + + " " + "$System.env.MAPBOX_ACCESS_TOKEN" + "\n" + + "" + + if (tokenFileContents == null) { + throw new InvalidUserDataException("You must set the MAPBOX_ACCESS_TOKEN environment variable.") + } + tokenFile.write(tokenFileContents) + } +} + +gradle.projectsEvaluated { + preBuild.dependsOn('accessToken') +} + +android { + compileSdkVersion 24 + buildToolsVersion "24.0.2" + + defaultConfig { + applicationId "com.mapbox.mapboxsdk.testapp" + minSdkVersion 21 + targetSdkVersion 24 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile(project(':MapboxGLAndroidSDK')) { + transitive = true + } + + // Leak Canary + androidTestCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' + debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2' + releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2' + + compile fileTree(dir: 'libs', include: ['*.jar']) + compile 'com.google.android.support:wearable:2.0.0-alpha3' + provided 'com.google.android.wearable:wearable:2.0.0-alpha3' +} + +apply from: '../checkstyle.gradle' \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/proguard-rules.pro b/platform/android/MapboxGLAndroidSDKWearTestApp/proguard-rules.pro new file mode 100644 index 000000000..362685b17 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/cameron/Library/Android/sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# 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 *; +#} diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/AndroidManifest.xml b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/AndroidManifest.xml new file mode 100644 index 000000000..22c44f972 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/AndroidManifest.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/MapboxApplication.java b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/MapboxApplication.java new file mode 100644 index 000000000..390c7370c --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/MapboxApplication.java @@ -0,0 +1,28 @@ +package com.mapbox.weartestapp; + +import android.app.Application; +import android.os.StrictMode; + +import com.mapbox.mapboxsdk.MapboxAccountManager; +import com.squareup.leakcanary.LeakCanary; + +public class MapboxApplication extends Application { + + @Override + public void onCreate() { + super.onCreate(); + MapboxAccountManager.start(getApplicationContext(), getString(R.string.mapbox_access_token)); + LeakCanary.install(this); + StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() + .detectDiskReads() + .detectDiskWrites() + .detectNetwork() // or .detectAll() for all detectable problems + .penaltyLog() + .build()); + StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() + .detectLeakedSqlLiteObjects() + .penaltyLog() + .penaltyDeath() + .build()); + } +} diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/activity/FeatureOverviewActivity.java b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/activity/FeatureOverviewActivity.java new file mode 100644 index 000000000..7f2caa4d6 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/activity/FeatureOverviewActivity.java @@ -0,0 +1,47 @@ +package com.mapbox.weartestapp.activity; + +import android.content.Intent; +import android.os.Bundle; +import android.support.wearable.activity.WearableActivity; +import android.support.wearable.view.WearableRecyclerView; + +import com.mapbox.weartestapp.R; +import com.mapbox.weartestapp.adapter.FeatureAdapter; +import com.mapbox.weartestapp.model.Feature; +import com.mapbox.weartestapp.utils.OffsettingHelper; + +import java.util.ArrayList; +import java.util.List; + +public class FeatureOverviewActivity extends WearableActivity implements FeatureAdapter.ItemSelectedListener { + + private static final String TAG = "MainActivity"; + private WearableRecyclerView wearableRecyclerView; + private List exampleItemModels; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_feature_overview); + + wearableRecyclerView = (WearableRecyclerView) findViewById(R.id.recycler_launcher_view); + wearableRecyclerView.setHasFixedSize(true); + + OffsettingHelper offsettingHelper = new OffsettingHelper(); + + wearableRecyclerView.setOffsettingHelper(offsettingHelper); + + exampleItemModels = new ArrayList<>(); + exampleItemModels.add(new Feature(R.string.activity_simple_mapview_title, new Intent(FeatureOverviewActivity.this, SimpleMapViewActivity.class))); + + FeatureAdapter exampleAdapter = new FeatureAdapter(FeatureOverviewActivity.this, exampleItemModels); + wearableRecyclerView.setAdapter(exampleAdapter); + + exampleAdapter.setListener(this); + } + + @Override + public void onItemSelected(int position) { + startActivity(exampleItemModels.get(position).getActivity()); + } +} diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/activity/SimpleMapViewActivity.java b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/activity/SimpleMapViewActivity.java new file mode 100644 index 000000000..d6f3ccd41 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/activity/SimpleMapViewActivity.java @@ -0,0 +1,60 @@ +package com.mapbox.weartestapp.activity; + +import android.os.Bundle; +import android.support.wearable.activity.WearableActivity; + +import com.mapbox.mapboxsdk.maps.MapView; +import com.mapbox.mapboxsdk.maps.MapboxMap; +import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; +import com.mapbox.weartestapp.R; + +public class SimpleMapViewActivity extends WearableActivity { + + private MapView mapView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_simple_mapview); + + mapView = (MapView) findViewById(R.id.mapView); + mapView.onCreate(savedInstanceState); + mapView.getMapAsync(new OnMapReadyCallback() { + @Override + public void onMapReady(MapboxMap mapboxMap) { + + // Customize map with markers, polylines, etc. + } + }); + } + + @Override + public void onResume() { + super.onResume(); + mapView.onResume(); + } + + @Override + public void onPause() { + super.onPause(); + mapView.onPause(); + } + + @Override + public void onLowMemory() { + super.onLowMemory(); + mapView.onLowMemory(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + mapView.onDestroy(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + mapView.onSaveInstanceState(outState); + } +} diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/adapter/FeatureAdapter.java b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/adapter/FeatureAdapter.java new file mode 100644 index 000000000..7539a84d6 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/adapter/FeatureAdapter.java @@ -0,0 +1,78 @@ +package com.mapbox.weartestapp.adapter; + +import android.content.Context; +import android.support.v7.widget.RecyclerView; +import android.support.wearable.view.WearableRecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import com.mapbox.weartestapp.R; +import com.mapbox.weartestapp.model.Feature; + +import java.util.List; + +public class FeatureAdapter extends WearableRecyclerView.Adapter { + + private List data; + private Context context; + private ItemSelectedListener itemSelectedListener; + + public FeatureAdapter(Context context, List data) { + this.context = context; + this.data = data; + } + + static class ViewHolder extends RecyclerView.ViewHolder { + + private TextView textView; + + ViewHolder(View view) { + super(view); + textView = (TextView) view.findViewById(R.id.text_item); + } + + void bind(final int position, final ItemSelectedListener listener) { + + itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (listener != null) { + listener.onItemSelected(position); + } + } + }); + } + } + + public void setListener(ItemSelectedListener itemSelectedListener) { + this.itemSelectedListener = itemSelectedListener; + } + + @Override + public FeatureAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + return new ViewHolder(LayoutInflater.from(parent.getContext()) + .inflate(R.layout.item_curved_layout, parent, false)); + } + + @Override + public void onBindViewHolder(FeatureAdapter.ViewHolder holder, final int position) { + if (data != null && !data.isEmpty()) { + holder.textView.setText(data.get(position).getTitle()); + holder.bind(position, itemSelectedListener); + } + } + + @Override + public int getItemCount() { + if (data != null && !data.isEmpty()) { + return data.size(); + } + return 0; + } + + public interface ItemSelectedListener { + void onItemSelected(int position); + } +} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/model/Feature.java b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/model/Feature.java new file mode 100644 index 000000000..65954ec27 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/model/Feature.java @@ -0,0 +1,30 @@ +package com.mapbox.weartestapp.model; + +import android.content.Intent; + +public class Feature { + + public int title; + public Intent activity; + + public int getTitle() { + return title; + } + + public void setTitle(int title) { + this.title = title; + } + + public Intent getActivity() { + return activity; + } + + public void setActivity(Intent activity) { + this.activity = activity; + } + + public Feature(int title, Intent activity) { + this.title = title; + this.activity = activity; + } +} diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/utils/OffsettingHelper.java b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/utils/OffsettingHelper.java new file mode 100644 index 000000000..5b5d512c4 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/java/com/mapbox/weartestapp/utils/OffsettingHelper.java @@ -0,0 +1,40 @@ +package com.mapbox.weartestapp.utils; + +import android.support.wearable.view.DefaultOffsettingHelper; +import android.support.wearable.view.WearableRecyclerView; +import android.view.View; + +public class OffsettingHelper extends DefaultOffsettingHelper { + + /** + * How much should we scale the icon at most. + */ + private static final float MAX_ICON_PROGRESS = 0.65f; + + private float progressToCenter; + + public OffsettingHelper() { + } + + @Override + public void updateChild(View child, WearableRecyclerView parent) { + super.updateChild(child, parent); + + // Figure out % progress from top to bottom + float centerOffset = ((float) child.getHeight() / 2.0f) / (float) parent.getHeight(); + float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset; + + // Normalize for center + progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset); + // Adjust to the maximum scale + progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS); + + child.setScaleX(1 - progressToCenter); + child.setScaleY(1 - progressToCenter); + } + + @Override + protected void adjustAnchorOffsetXY(View child, float[] anchorOffsetXY) { + anchorOffsetXY[0] = child.getHeight() / 2.0f; + } +} diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/layout/activity_feature_overview.xml b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/layout/activity_feature_overview.xml new file mode 100644 index 000000000..07cfcd3c5 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/layout/activity_feature_overview.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/layout/activity_simple_mapview.xml b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/layout/activity_simple_mapview.xml new file mode 100644 index 000000000..2c1e5fe2e --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/layout/activity_simple_mapview.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/layout/item_curved_layout.xml b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/layout/item_curved_layout.xml new file mode 100644 index 000000000..e3a9b476a --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/layout/item_curved_layout.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-hdpi/ic_launcher.png b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..ac2ea61c7 Binary files /dev/null and b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-mdpi/ic_launcher.png b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..99eed7146 Binary files /dev/null and b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-xhdpi/ic_launcher.png b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..9b084daf9 Binary files /dev/null and b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-xxhdpi/ic_launcher.png b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..6fa714b47 Binary files /dev/null and b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/values/colors.xml b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/values/colors.xml new file mode 100644 index 000000000..1c40e40e1 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/values/colors.xml @@ -0,0 +1,31 @@ + + + + + @color/mapboxBlue + @color/mapboxBlueDark + @color/mapboxRed + + #F5F5F5 + #DFDFDF + + #ffffff + #3BB2D0 + #56B881 + #3887BE + #1F6EA5 + #8A8ACB + #7171b2 + #A4A4E5 + + #50667F + #41AFA5 + #F9886C + #E55E5E + #ED6498 + #f1f075 + #FBB03B + #28353D + #222B30 + + \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/values/strings.xml b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/values/strings.xml new file mode 100644 index 000000000..e6a10ad30 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDKWearTestApp/src/main/res/values/strings.xml @@ -0,0 +1,6 @@ + + MapboxGLAndroidSDKWearTestApp + + + A simple map view + diff --git a/platform/android/settings.gradle b/platform/android/settings.gradle index 71a8f1a9a..9be29f4bd 100644 --- a/platform/android/settings.gradle +++ b/platform/android/settings.gradle @@ -1,2 +1,3 @@ include ':MapboxGLAndroidSDK' include ':MapboxGLAndroidSDKTestApp' +include ':MapboxGLAndroidSDKWearTestApp'