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

Commit

Permalink
Merge pull request #861 from mapbox/android-2-3
Browse files Browse the repository at this point in the history
Add support for Android API level 8
  • Loading branch information
Leith Bade committed Feb 12, 2015
2 parents 3a84a7d + 7dff7ac commit b1c2c91
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion android/java/MapboxGLAndroidSDK/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=mapbox
POM_DEVELOPER_NAME=Mapbox

ANDROID_MIN_SDK=14
ANDROID_MIN_SDK=8
ANDROID_BUILD_TARGET_SDK_VERSION=21
ANDROID_BUILD_TOOLS_VERSION=21.1.2
ANDROID_BUILD_SDK_VERSION=21
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mapbox.mapboxgl.lib;

import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -176,7 +177,11 @@ private void initialize(Context context, AttributeSet attrs) {
requestFocus();

// Register the SurfaceHolder callbacks
getHolder().addCallback(new Callbacks());
if (android.os.Build.VERSION.SDK_INT >= 9) {
getHolder().addCallback(new Callbacks2());
} else {
getHolder().addCallback(new Callbacks());
}

// Touch gesture detectors
mGestureDetector = new GestureDetectorCompat(context, new GestureListener());
Expand Down Expand Up @@ -331,7 +336,7 @@ public String getStyleUrl() {

private void validateAccessToken(String accessToken) {

if (accessToken.isEmpty() | (!accessToken.startsWith("pk.") && !accessToken.startsWith("sk."))) {
if (!accessToken.startsWith("pk.") && !accessToken.startsWith("sk.")) {
throw new RuntimeException("Using MapView requires setting a valid access token. See the README.md");
}
}
Expand Down Expand Up @@ -424,11 +429,11 @@ public void onSaveInstanceState(Bundle outState) {
outState.putParcelable(STATE_CENTER_COORDINATE, getCenterCoordinate());
outState.putDouble(STATE_ZOOM_LEVEL, getZoomLevel()); // need to set zoom level first because of limitation on rotating when zoomed out
outState.putDouble(STATE_CENTER_DIRECTION, getDirection());
outState.putBoolean(STATE_ZOOM_ENABLED, isZoomEnabled());
outState.putBoolean(STATE_SCROLL_ENABLED, isScrollEnabled());
outState.putBoolean(STATE_ROTATE_ENABLED, isRotateEnabled());
outState.putBoolean(STATE_ZOOM_ENABLED, mZoomEnabled);
outState.putBoolean(STATE_SCROLL_ENABLED, mScrollEnabled);
outState.putBoolean(STATE_ROTATE_ENABLED, mRotateEnabled);
outState.putBoolean(STATE_DEBUG_ACTIVE, isDebugActive());
outState.putString(STATE_STYLE_URL, getStyleUrl());
outState.putString(STATE_STYLE_URL, mStyleUrl);
outState.putString(STATE_ACCESS_TOKEN, getAccessToken());
outState.putStringArrayList(STATE_CLASSES, new ArrayList<String>(getClasses()));
outState.putLong(STATE_DEFAULT_TRANSITION_DURATION, mNativeMapView.getDefaultTransitionDuration());
Expand Down Expand Up @@ -482,16 +487,7 @@ public void onResume() {
}

// This class handles SurfaceHolder callbacks
private class Callbacks implements SurfaceHolder.Callback2 {

// Called when we need to redraw the view
// This is called before our view is first visible to prevent an initial
// flicker (see Android SDK documentation)
@Override
public void surfaceRedrawNeeded(SurfaceHolder holder) {
Log.v(TAG, "surfaceRedrawNeeded");
mNativeMapView.update();
}
private class Callbacks implements SurfaceHolder.Callback {

// Called when the native surface buffer has been created
// Must do all EGL/GL ES initialization here
Expand Down Expand Up @@ -521,6 +517,19 @@ public void surfaceChanged(SurfaceHolder holder, int format, int width,
}
}

@TargetApi(9)
private class Callbacks2 extends Callbacks implements SurfaceHolder.Callback2 {

// Called when we need to redraw the view
// This is called before our view is first visible to prevent an initial
// flicker (see Android SDK documentation)
@Override
public void surfaceRedrawNeeded(SurfaceHolder holder) {
Log.v(TAG, "surfaceRedrawNeeded");
mNativeMapView.update();
}
}

// TODO examine how GLSurvaceView hadles attach/detach from window

// Called when view is no longer connected
Expand Down Expand Up @@ -576,10 +585,10 @@ private void zoom(boolean zoomIn, float x, float y) {
}

// Called when user touches the screen, all positions are absolute
@Override
@Override @TargetApi(14)
public boolean onTouchEvent(@NonNull MotionEvent event) {
// Check and ignore non touch or left clicks
if ((event.getButtonState() != 0) && (event.getButtonState() != MotionEvent.BUTTON_PRIMARY)) {
if ((android.os.Build.VERSION.SDK_INT >= 14) && (event.getButtonState() != 0) && (event.getButtonState() != MotionEvent.BUTTON_PRIMARY)) {
return false;
}

Expand Down Expand Up @@ -1092,7 +1101,7 @@ public void run() {

// Called for events that don't fit the other handlers
// such as mouse scroll events, mouse moves, joystick, trackpad
@Override
@Override @TargetApi(12)
public boolean onGenericMotionEvent(MotionEvent event) {
// Mouse events
// TODO: SOURCE_TOUCH_NAVIGATION?
Expand Down Expand Up @@ -1130,7 +1139,7 @@ public boolean onGenericMotionEvent(MotionEvent event) {

// Called when the mouse pointer enters or exits the view
// or when it fades in or out due to movement
@Override
@Override @TargetApi(14)
public boolean onHoverEvent(@NonNull MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_HOVER_ENTER:
Expand Down

0 comments on commit b1c2c91

Please sign in to comment.