Skip to content

Instantly share code, notes, and snippets.

View josh-burton's full-sized avatar
👋

Josh Burton josh-burton

👋
View GitHub Profile
@josh-burton
josh-burton / gist:88021de7ec712e1a3371
Created July 12, 2014 06:09
Android Wear Watchface Background listener
private final BroadcastReceiver mBackgroundReceiver = new BroadcastReceiver() {
public void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent) {
if (paramAnonymousIntent.hasExtra("card_location")) {
mListener.onCardLocation(
Rect.unflattenFromString(paramAnonymousIntent.getStringExtra("card_location")));
}
if (paramAnonymousIntent.hasExtra("card_progress_enabled")) {
mListener.onCardProgressEnabled(paramAnonymousIntent.getBooleanExtra("card_progress_enabled", false));
}
if (paramAnonymousIntent.hasExtra("card_progress")) {
@josh-burton
josh-burton / gist:e6c71859d28027fe1a83
Created July 12, 2014 06:10
Android Wear Watchface Tick Receiver
IntentFilter timeTickIntentFilter = new IntentFilter("com.google.android.wearable.home.action.WEARABLE_TIME_TICK");
listener.registerReceiver(mTimeTickReceiver, timeTickIntentFilter);
public final BroadcastReceiver mTimeTickReceiver = new BroadcastReceiver() {
public void onReceive(Context context, Intent intent) {
//ontick
}
};
public class WatchFaceAluminum
extends WatchFace
{
protected WatchFaceStyle buildStyle()
{
WatchFaceStyle.Builder localBuilder = WatchFaceStyle.Builder.forActivity(this).setCardPeekMode(1).setPeekOpacityMode(1).setCardProgressMode(0).setBackgroundVisibility(0).setViewProtection(0).setShowSystemUiTime(false);
if (isRound()) {
localBuilder.setHotwordIndicatorGravity(81).setStatusBarGravity(49);
}
for (;;)
@josh-burton
josh-burton / MergeRecyclerAdapter
Created August 26, 2014 20:38
A Merge Adapter for the RecyclerView. Based on CommonsWare cwac-merge and the MergedAdapter in the android sdk.
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
@josh-burton
josh-burton / MapStyleManager.java
Created September 22, 2016 04:56
MapStyleManager - Google Map Styles per zoom level
public final class MapStyleManager implements GoogleMap.OnCameraMoveListener {
private final Context context;
private final GoogleMap map;
private final GoogleMap.OnCameraMoveListener onCameraMoveListener;
private final TreeMap<Float, Integer> styleMap = new TreeMap<>();
@RawRes
private int currentMapStyleRes = 0;
@josh-burton
josh-burton / Building the Graph
Created April 25, 2017 07:24
Context with @BindsInstance
DaggerApplicationComponent.builder().context(applicationContext).build().inject(this);
@josh-burton
josh-burton / androidmanifest.xml
Created May 3, 2017 02:07
Prevent TouchWiz from surrounding your app icon in a frame
<!-- Prevents TouchWiz from surrounding your app icon in a frame -->
<!-- Add to your manifest inside the application tag -->
<meta-data
android:name="com.samsung.android.icon_container.has_icon_container"
android:value="true"/>
@josh-burton
josh-burton / mapme.kt
Created September 7, 2017 02:32
MapMe Kotlin Adapter
class MapsAdapter(context: Context, private val markers: List<MarkerData>) : GoogleMapMeAdapter(context) {
fun onCreateAnnotation(factory: AnnotationFactory, position: Int, annotationType: Int): MapAnnotation {
val item = this.markers[position]
return factory.createMarker(item.getLatLng(), null, item.getTitle())
}
fun onBindAnnotation(annotation: MapAnnotation, position: Int, payload: Any) {
if (annotation is MarkerAnnotation) {
val item = this.markers[position]
@josh-burton
josh-burton / mapme-setup.kt
Created September 7, 2017 02:36
MapMe setup
val adapter: MapMeAdapter = GoogleMapMeAdapter(context, items)
adapter.setOnAnnotationClickListener(this)
mapView.getMapAsync { googleMap ->
//Attach the adapter to the map view once it's initialized
adapter.attach(mapView, googleMap)
}
@josh-burton
josh-burton / mapme-additems.kt
Created September 7, 2017 02:39
MapMe - add items
// add new data and tell the adapter about it
items.addAll(myData)
adapter.notifyDataSetChanged()
// or with DiffUtil
val diff = DiffUtil.calculateDiff(myDiffCallback)
diff.dispatchUpdatesTo(adapter)