Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - lower amount of external dependencies (#10268)
Browse files Browse the repository at this point in the history
  • Loading branch information
zugaldia authored and tobrun committed Nov 7, 2017
1 parent 4b11ad2 commit 823a6a0
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 28 deletions.
4 changes: 2 additions & 2 deletions platform/android/MapboxGLAndroidSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ apply plugin: 'com.android.library'

dependencies {
compile rootProject.ext.dep.supportAnnotations
compile rootProject.ext.dep.supportV4
compile rootProject.ext.dep.supportDesign
compile rootProject.ext.dep.supportFragmentV4
compile rootProject.ext.dep.timber
compile rootProject.ext.dep.okhttp3
provided rootProject.ext.dep.lost
Expand All @@ -18,6 +17,7 @@ dependencies {
// Mapbox Android Services (Telemetry support)
compile(rootProject.ext.dep.mapboxAndroidTelemetry) {
transitive = true
exclude group: 'com.android.support'
}

compile(rootProject.ext.dep.mapboxAndroidCore)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.mapbox.mapboxsdk.maps;

import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
Expand Down Expand Up @@ -56,7 +56,7 @@ public void onClick(View view) {

private void showAttributionDialog() {
attributionKeys = attributionMap.keySet().toArray(new String[attributionMap.size()]);
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.mapbox_AlertDialogStyle);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.mapbox_attributionsDialogTitle);
builder.setAdapter(new ArrayAdapter<>(context, R.layout.mapbox_attribution_list_item, attributionKeys), this);
builder.show();
Expand All @@ -77,7 +77,7 @@ private boolean isLatestEntry(int attributionKeyIndex) {
}

private void showTelemetryDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.mapbox_AlertDialogStyle);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.mapbox_attributionTelemetryTitle);
builder.setMessage(R.string.mapbox_attributionTelemetryMessage);
builder.setPositiveButton(R.string.mapbox_attributionTelemetryPositive, new DialogInterface.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorCompat;
import android.support.v4.view.ViewPropertyAnimatorListenerAdapter;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.mapbox.mapboxsdk.maps.MapboxMap;

Expand All @@ -22,7 +22,7 @@
* use {@link com.mapbox.mapboxsdk.maps.UiSettings}.
* </p>
*/
public final class CompassView extends AppCompatImageView implements Runnable {
public final class CompassView extends ImageView implements Runnable {

public static final long TIME_WAIT_IDLE = 500;
public static final long TIME_MAP_NORTH_ANIMATION = 150;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.v4.graphics.drawable.DrawableCompat;
Expand All @@ -30,10 +31,15 @@ public class ColorUtils {
*/
@ColorInt
public static int getPrimaryColor(@NonNull Context context) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.colorPrimary, typedValue, true);
return typedValue.data;
try {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
int id = context.getResources().getIdentifier("colorPrimary", "attrs", context.getPackageName());
theme.resolveAttribute(id, typedValue, true);
return typedValue.data;
} catch (Exception exception) {
return getColorCompat(context, R.color.mapbox_blue);
}
}

/**
Expand All @@ -44,10 +50,15 @@ public static int getPrimaryColor(@NonNull Context context) {
*/
@ColorInt
public static int getPrimaryDarkColor(@NonNull Context context) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
return typedValue.data;
try {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
int id = context.getResources().getIdentifier("colorPrimaryDark", "attrs", context.getPackageName());
theme.resolveAttribute(id, typedValue, true);
return typedValue.data;
} catch (Exception exception) {
return getColorCompat(context, R.color.mapbox_blue);
}
}

/**
Expand All @@ -58,10 +69,15 @@ public static int getPrimaryDarkColor(@NonNull Context context) {
*/
@ColorInt
public static int getAccentColor(@NonNull Context context) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.colorAccent, typedValue, true);
return typedValue.data;
try {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
int id = context.getResources().getIdentifier("colorAccent", "attrs", context.getPackageName());
theme.resolveAttribute(id, typedValue, true);
return typedValue.data;
} catch (Exception exception) {
return getColorCompat(context, R.color.mapbox_gray);
}
}

/**
Expand Down Expand Up @@ -122,4 +138,12 @@ public static int rgbaToColor(String value) {
throw new ConversionException("Not a valid rgb/rgba value");
}
}

private static int getColorCompat(Context context, int id) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return context.getResources().getColor(id, context.getTheme());
} else {
return context.getResources().getColor(id);
}
}
}

This file was deleted.

1 change: 1 addition & 0 deletions platform/android/MapboxGLAndroidSDKTestApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ dependencies {
// Support libraries
compile rootProject.ext.dep.supportAppcompatV7
compile rootProject.ext.dep.supportRecyclerView
compile rootProject.ext.dep.supportDesign

// Leak Canary
debugCompile rootProject.ext.dep.leakCanaryDebug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public void onCameraMoveStarted(int reason) {
@Override
public void onClick(View view) {
Context context = view.getContext();

final View dialogContent = LayoutInflater.from(context).inflate(R.layout.dialog_camera_position, null);
AlertDialog.Builder builder = new AlertDialog.Builder(
context, com.mapbox.mapboxsdk.R.style.mapbox_AlertDialogStyle);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.dialog_camera_position);
builder.setView(onInflateDialogContent(dialogContent));
builder.setPositiveButton("Animate", new DialogInterface.OnClickListener() {
Expand Down
2 changes: 1 addition & 1 deletion platform/android/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ext {
// support
supportAnnotations : "com.android.support:support-annotations:${supportLibVersion}",
supportAppcompatV7 : "com.android.support:appcompat-v7:${supportLibVersion}",
supportV4 : "com.android.support:support-v4:${supportLibVersion}",
supportFragmentV4 : "com.android.support:support-fragment:${supportLibVersion}",
supportDesign : "com.android.support:design:${supportLibVersion}",
supportRecyclerView : "com.android.support:recyclerview-v7:${supportLibVersion}",

Expand Down

0 comments on commit 823a6a0

Please sign in to comment.