[android] added wearable module (#6702)
* added wearable module * fixed spacing in feature list * fixed tobruns suggestions and added checkstyle plugin
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mapbox.weartestapp">
|
||||
|
||||
<uses-feature android:name="android.hardware.type.watch"/>
|
||||
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:name=".MapboxApplication"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@android:style/Theme.DeviceDefault">
|
||||
<uses-library
|
||||
android:name="com.google.android.wearable"
|
||||
android:required="false"/>
|
||||
|
||||
<activity
|
||||
android:name="com.mapbox.weartestapp.activity.FeatureOverviewActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activity.SimpleMapViewActivity"
|
||||
android:label="@string/activity_simple_mapview_title">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".activity.FeatureOverviewActivity"/>
|
||||
</activity>
|
||||
|
||||
<service android:name="com.mapbox.mapboxsdk.telemetry.TelemetryService"/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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<Feature> 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());
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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<FeatureAdapter.ViewHolder> {
|
||||
|
||||
private List<Feature> data;
|
||||
private Context context;
|
||||
private ItemSelectedListener itemSelectedListener;
|
||||
|
||||
public FeatureAdapter(Context context, List<Feature> 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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.wearable.view.BoxInsetLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.FeatureOverviewActivity"
|
||||
tools:deviceIds="wear">
|
||||
|
||||
<android.support.wearable.view.WearableRecyclerView
|
||||
android:id="@+id/recycler_launcher_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical" />
|
||||
|
||||
</android.support.wearable.view.BoxInsetLayout>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.SimpleMapViewActivity"
|
||||
tools:deviceIds="wear">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
mapbox:center_latitude="40.73581"
|
||||
mapbox:center_longitude="-73.99155"
|
||||
mapbox:style_url="mapbox://styles/mapbox/streets-v9"
|
||||
mapbox:zoom="11"
|
||||
mapbox:zoom_controls_enabled="false"/>
|
||||
|
||||
</FrameLayout>
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/layout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:clickable="true"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_item"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:textColor="@color/mapboxWhite"
|
||||
android:textSize="14sp"/>
|
||||
|
||||
</LinearLayout>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 11 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<!-- Mapbox colors -->
|
||||
<color name="colorPrimary">@color/mapboxBlue</color>
|
||||
<color name="colorPrimaryDark">@color/mapboxBlueDark</color>
|
||||
<color name="colorAccent">@color/mapboxRed</color>
|
||||
|
||||
<color name="materialGrey">#F5F5F5</color>
|
||||
<color name="materialDarkGrey">#DFDFDF</color>
|
||||
|
||||
<color name="mapboxWhite">#ffffff</color>
|
||||
<color name="mapboxCyan">#3BB2D0</color>
|
||||
<color name="mapboxGreen">#56B881</color>
|
||||
<color name="mapboxBlue">#3887BE</color>
|
||||
<color name="mapboxBlueDark">#1F6EA5</color>
|
||||
<color name="mapboxPurple">#8A8ACB</color>
|
||||
<color name="mapboxPurpleDark">#7171b2</color>
|
||||
<color name="mapboxPurpleLight">#A4A4E5</color>
|
||||
|
||||
<color name="mapboxDenim">#50667F</color>
|
||||
<color name="mapboxTeal">#41AFA5</color>
|
||||
<color name="mapboxOrange">#F9886C</color>
|
||||
<color name="mapboxRed">#E55E5E</color>
|
||||
<color name="mapboxPink">#ED6498</color>
|
||||
<color name="mapboxYellow">#f1f075</color>
|
||||
<color name="mapboxMustard">#FBB03B</color>
|
||||
<color name="mapboxNavy">#28353D</color>
|
||||
<color name="mapboxNavyDark">#222B30</color>
|
||||
|
||||
</resources>
|
||||
@@ -0,0 +1,6 @@
|
||||
<resources>
|
||||
<string name="app_name">MapboxGLAndroidSDKWearTestApp</string>
|
||||
|
||||
<!-- Feature Titles -->
|
||||
<string name="activity_simple_mapview_title">A simple map view</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user