Skip to content

Commit

Permalink
Fixed Google Pixel panel orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
feelfreelinux committed Mar 1, 2018
1 parent 8fbe6f6 commit 9d834d3
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down
28 changes: 18 additions & 10 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand All @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions library/src/main/java/com/r0adkll/slidr/Slidr.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
51 changes: 51 additions & 0 deletions library/src/main/java/com/r0adkll/slidr/util/Utils.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 10 additions & 6 deletions library/src/main/java/com/r0adkll/slidr/widget/SliderPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -33,6 +35,7 @@ public class SliderPanel extends FrameLayout {
private boolean isEdgeTouched = false;
private int edgePosition;

private int softKeySize;
private SlidrConfig config;


Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand All @@ -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){
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -711,6 +714,7 @@ private void init(){
@Override
public void run() {
screenHeight = getHeight();
screenWidth = getWidth();
}
});

Expand Down

0 comments on commit 9d834d3

Please sign in to comment.