diff --git a/build.gradle b/build.gradle index 2bd5cdc..6b4933e 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.0-alpha05' + classpath 'com.android.tools.build:gradle:3.1.0-alpha08' } } diff --git a/library/build.gradle b/library/build.gradle index 24a9d8a..1697be6 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -2,12 +2,12 @@ apply plugin: 'com.android.library' apply plugin: 'maven' android { - compileSdkVersion compileSdk - buildToolsVersion buildTools + compileSdkVersion 27 + buildToolsVersion '27.0.2' defaultConfig { - minSdkVersion minSdk - targetSdkVersion targetSdk + minSdkVersion 17 + targetSdkVersion 27 testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } @@ -19,15 +19,23 @@ android { sourceCompatibility JavaVersion.VERSION_1_7 targetCompatibility JavaVersion.VERSION_1_7 } + + packagingOptions { + exclude 'META-INF/rxjava.properties' + } } dependencies { - compile supportDependencies.support - testCompile 'junit:junit:4.12' - testCompile 'org.mockito:mockito-core:1.10.19' - testCompile 'org.hamcrest:hamcrest-library:1.1' - testCompile 'org.powermock:powermock-api-mockito:1.6.2' - testCompile 'org.powermock:powermock-module-junit4:1.6.2' + implementation 'com.android.support:support-v4:27.0.2' + implementation 'com.android.support:appcompat-v7:27.0.2' + implementation 'com.android.support:recyclerview-v7:27.0.2' + implementation 'com.android.support:cardview-v7:27.0.2' + implementation 'com.52inc:52Kit-core:0.5.1' + testImplementation 'junit:junit:4.12' + testImplementation 'org.mockito:mockito-core:1.10.19' + testImplementation 'org.hamcrest:hamcrest-library:1.1' + testImplementation 'org.powermock:powermock-api-mockito:1.6.2' + testImplementation 'org.powermock:powermock-module-junit4:1.6.2' } apply from: '../gradle-mvn-push.gradle' diff --git a/library/src/main/java/com/r0adkll/slidr/Slidr.java b/library/src/main/java/com/r0adkll/slidr/Slidr.java index 2b62d32..836c176 100644 --- a/library/src/main/java/com/r0adkll/slidr/Slidr.java +++ b/library/src/main/java/com/r0adkll/slidr/Slidr.java @@ -2,8 +2,10 @@ import android.app.Activity; +import android.os.Build; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; +import android.util.DisplayMetrics; import android.view.View; import android.view.ViewGroup; diff --git a/library/src/main/java/com/r0adkll/slidr/util/Utils.java b/library/src/main/java/com/r0adkll/slidr/util/Utils.java new file mode 100644 index 0000000..43df934 --- /dev/null +++ b/library/src/main/java/com/r0adkll/slidr/util/Utils.java @@ -0,0 +1,51 @@ +package com.r0adkll.slidr.util; + +import android.content.Context; +import android.graphics.Point; +import android.os.Build; +import android.util.Log; +import android.view.Display; +import android.view.Surface; +import android.view.WindowManager; + +import java.lang.reflect.InvocationTargetException; + +public class Utils { + public static int getNavigationBarSize(Context context) { + WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + Point appUsableSize = getAppUsableScreenSize(windowManager); + Point realScreenSize = getRealScreenSize(windowManager); + + // navigation bar on the right + if (appUsableSize.x < realScreenSize.x && windowManager.getDefaultDisplay().getRotation() == Surface.ROTATION_270) { + Log.v("Test", Integer.toString(realScreenSize.x - appUsableSize.x)); + return realScreenSize.x - appUsableSize.x; + } + + // navigation bar is not present + return 0; + } + + public static Point getAppUsableScreenSize(WindowManager windowManager) { + Display display = windowManager.getDefaultDisplay(); + Point size = new Point(); + display.getSize(size); + return size; + } + + public static Point getRealScreenSize(WindowManager windowManager) { + Display display = windowManager.getDefaultDisplay(); + Point size = new Point(); + + if (Build.VERSION.SDK_INT >= 17) { + display.getRealSize(size); + } else if (Build.VERSION.SDK_INT >= 14) { + try { + size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display); + size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display); + } catch (IllegalAccessException e) {} catch (InvocationTargetException e) {} catch (NoSuchMethodException e) {} + } + + return size; + } +} diff --git a/library/src/main/java/com/r0adkll/slidr/util/ViewDragHelper.java b/library/src/main/java/com/r0adkll/slidr/util/ViewDragHelper.java index 9c3ced9..45bee1e 100644 --- a/library/src/main/java/com/r0adkll/slidr/util/ViewDragHelper.java +++ b/library/src/main/java/com/r0adkll/slidr/util/ViewDragHelper.java @@ -102,6 +102,7 @@ public class ViewDragHelper { private View mCapturedView; private boolean mReleaseInProgress; private final ViewGroup mParentView; + private int navSize; /** * A Callback is used as a communication channel with the ViewDragHelper back to the @@ -344,6 +345,7 @@ private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) { if (cb == null) { throw new IllegalArgumentException("Callback may not be null"); } + navSize = Utils.getNavigationBarSize(context); mParentView = forParent; mCallback = cb; final ViewConfiguration vc = ViewConfiguration.get(context); @@ -1384,7 +1386,8 @@ public View findTopChildUnder(int x, int y) { private int getEdgesTouched(int x, int y) { int result = 0; - if (x < mParentView.getLeft() + mEdgeSize) result |= EDGE_LEFT; + + if (x - navSize < mParentView.getLeft() + mEdgeSize) result |= EDGE_LEFT; if (y < mParentView.getTop() + mEdgeSize) result |= EDGE_TOP; if (x > mParentView.getRight() - mEdgeSize) result |= EDGE_RIGHT; if (y > mParentView.getBottom() - mEdgeSize) result |= EDGE_BOTTOM; diff --git a/library/src/main/java/com/r0adkll/slidr/widget/SliderPanel.java b/library/src/main/java/com/r0adkll/slidr/widget/SliderPanel.java index ad103ab..48fff73 100644 --- a/library/src/main/java/com/r0adkll/slidr/widget/SliderPanel.java +++ b/library/src/main/java/com/r0adkll/slidr/widget/SliderPanel.java @@ -7,11 +7,13 @@ import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewGroupCompat; +import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.widget.FrameLayout; import com.r0adkll.slidr.model.SlidrConfig; +import com.r0adkll.slidr.util.Utils; import com.r0adkll.slidr.util.ViewDragHelper; import com.r0adkll.slidr.model.SlidrInterface; @@ -33,6 +35,7 @@ public class SliderPanel extends FrameLayout { private boolean isEdgeTouched = false; private int edgePosition; + private int softKeySize; private SlidrConfig config; @@ -43,6 +46,7 @@ public SliderPanel(Context context) { public SliderPanel(Context context, View decorView, SlidrConfig config){ super(context); + this.softKeySize = Utils.getNavigationBarSize(context); this.decorView = decorView; this.config = (config == null ? new SlidrConfig.Builder().build() : config); init(); @@ -162,7 +166,7 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) { super.onViewReleased(releasedChild, xvel, yvel); int left = releasedChild.getLeft(); - int settleLeft = 0; + int settleLeft = softKeySize; int leftThreshold = (int) (getWidth() * config.getDistanceThreshold()); boolean isVerticalSwiping = Math.abs(yvel) > config.getVelocityThreshold(); @@ -171,7 +175,7 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) { if(Math.abs(xvel) > config.getVelocityThreshold() && !isVerticalSwiping){ settleLeft = screenWidth; }else if(left > leftThreshold){ - settleLeft = screenWidth; + settleLeft = screenWidth ; } }else if(xvel == 0){ @@ -201,7 +205,7 @@ public void onViewDragStateChanged(int state) { if(listener != null) listener.onStateChanged(state); switch (state){ case ViewDragHelper.STATE_IDLE: - if(decorView.getLeft() == 0){ + if(decorView.getLeft() == softKeySize){ // State Open if(listener != null) listener.onOpened(); }else{ @@ -584,7 +588,7 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) { super.onViewReleased(releasedChild, xvel, yvel); int left = releasedChild.getLeft(); - int settleLeft = 0; + int settleLeft = softKeySize; int leftThreshold = (int) (getWidth() * config.getDistanceThreshold()); boolean isVerticalSwiping = Math.abs(yvel) > config.getVelocityThreshold(); @@ -612,7 +616,7 @@ public void onViewReleased(View releasedChild, float xvel, float yvel) { } } - dragHelper.settleCapturedViewAt(settleLeft, releasedChild.getTop()); + dragHelper.settleCapturedViewAt(settleLeft + softKeySize, releasedChild.getTop()); invalidate(); } @@ -654,7 +658,6 @@ public void onViewDragStateChanged(int state) { private void init(){ setWillNotDraw(false); - screenWidth = getResources().getDisplayMetrics().widthPixels; final float density = getResources().getDisplayMetrics().density; final float minVel = MIN_FLING_VELOCITY * density; @@ -711,6 +714,7 @@ private void init(){ @Override public void run() { screenHeight = getHeight(); + screenWidth = getWidth(); } });