diff --git a/build.gradle b/build.gradle index d6a22f4..65b85da 100644 --- a/build.gradle +++ b/build.gradle @@ -4,13 +4,13 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:0.9.+' + classpath 'com.android.tools.build:gradle:1.0.0' } } ext.groupId = 'net.simonvt.menudrawer' ext.compileSdkVersion = 19 -ext.buildToolsVersion = "19.0.3" +ext.buildToolsVersion = "20.0.0" ext.minSdkVersion = 7; ext.targetSdkVersion = 19; @@ -19,7 +19,7 @@ allprojects { mavenCentral() } - tasks.withType(Compile) { + tasks.withType(com.sun.org.apache.xalan.internal.xsltc.cmdline.Compile) { options.encoding = "UTF-8" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f517815..ff47536 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-all.zip +distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/menudrawer-samples/src/net/simonvt/menudrawer/samples/TopDrawerSample.java b/menudrawer-samples/src/net/simonvt/menudrawer/samples/TopDrawerSample.java index 1b25573..579e1c8 100644 --- a/menudrawer-samples/src/net/simonvt/menudrawer/samples/TopDrawerSample.java +++ b/menudrawer-samples/src/net/simonvt/menudrawer/samples/TopDrawerSample.java @@ -1,8 +1,5 @@ package net.simonvt.menudrawer.samples; -import net.simonvt.menudrawer.MenuDrawer; -import net.simonvt.menudrawer.Position; - import android.app.Activity; import android.os.Build; import android.os.Bundle; @@ -14,6 +11,9 @@ import android.view.View.OnClickListener; import android.widget.TextView; +import net.simonvt.menudrawer.MenuDrawer; +import net.simonvt.menudrawer.Position; + /** * Sample class illustrating how to add a menu drawer above the content area. */ @@ -32,6 +32,8 @@ protected void onCreate(Bundle inState) { mMenuDrawer.setTouchMode(MenuDrawer.TOUCH_MODE_FULLSCREEN); mMenuDrawer.setContentView(R.layout.activity_topmenu); mMenuDrawer.setMenuView(R.layout.menu_top); + mMenuDrawer.setOffsetMenuRadio(1.0f); + mMenuDrawer.setClickToClose(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { getActionBar().setDisplayHomeAsUpEnabled(true); diff --git a/menudrawer/build.gradle b/menudrawer/build.gradle index 4de1f8a..af35d24 100644 --- a/menudrawer/build.gradle +++ b/menudrawer/build.gradle @@ -30,80 +30,80 @@ signing { } task androidJavadocs(type: Javadoc) { - source = android.sourceSets.main.allJava +// source = android.sourceSets.main.allJava } -task androidJavadocsJar(type: Jar) { - classifier = 'javadoc' - basename = project.artifactId - from androidJavadocs.destinationDir -} - -task androidSourcesJar(type: Jar) { - classifier = 'sources' - basename = project.artifactId - from android.sourceSets.main.allSource -} - -artifacts { - archives androidSourcesJar - archives androidJavadocsJar -} - -uploadArchives { - configuration = configurations.archives - - repositories.mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - repository(url: sonatypeRepo) { - authentication(userName: sonatypeUsername, password: sonatypePassword) - } - - pom.groupId = parent.ext.groupId - pom.artifactId = project.ext.artifactId - pom.version = parent.version - - pom.project { - name 'MenuDrawer' - packaging 'aar' - description 'A menu drawer implementation which allows dragging of both the content, and the entire window.' - url 'https://github.com/SimonVT/android-menudrawer' - - scm { - url 'http://github.com/SimonVT/android-menudrawer/' - connection 'scm:git:git://github.com/SimonVT/android-menudrawer.git' - developerConnection 'scm:git:git@github.com:SimonVT/android-menudrawer.git' - } - - licenses { - license { - name 'Apache License Version 2.0' - url 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution 'repo' - } - } - - issueManagement { - system 'GitHub Issues' - url 'https://github.com/SimonVT/android-menudrawer/issues' - } - - developers { - developer { - id 'simonvt' - name 'Simon Vig Therkildsen' - email 'simonvt@gmail.com' - url 'http://simonvt.net' - timezone '1' - roles { - role 'developer' - } - } - } - } - } -} +//task androidJavadocsJar(type: Jar) { +// classifier = 'javadoc' +// basename = project.artifactId +// from androidJavadocs.destinationDir +//} + +//task androidSourcesJar(type: Jar) { +// classifier = 'sources' +// basename = project.artifactId +//// from android.sourceSets.main.allSource +//} + +//artifacts { +// archives androidSourcesJar +// archives androidJavadocsJar +//} + +//uploadArchives { +// configuration = configurations.archives +// +// repositories.mavenDeployer { +//// beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } +// +// repository(url: sonatypeRepo) { +// authentication(userName: sonatypeUsername, password: sonatypePassword) +// } +// +// pom.groupId = parent.ext.groupId +// pom.artifactId = project.ext.artifactId +// pom.version = parent.version +// +// pom.project { +// name 'MenuDrawer' +// packaging 'aar' +// description 'A menu drawer implementation which allows dragging of both the content, and the entire window.' +// url 'https://github.com/SimonVT/android-menudrawer' +// +// scm { +// url 'http://github.com/SimonVT/android-menudrawer/' +// connection 'scm:git:git://github.com/SimonVT/android-menudrawer.git' +// developerConnection 'scm:git:git@github.com:SimonVT/android-menudrawer.git' +// } +// +// licenses { +// license { +// name 'Apache License Version 2.0' +// url 'http://www.apache.org/licenses/LICENSE-2.0.txt' +// distribution 'repo' +// } +// } +// +// issueManagement { +// system 'GitHub Issues' +// url 'https://github.com/SimonVT/android-menudrawer/issues' +// } +// +// developers { +// developer { +// id 'simonvt' +// name 'Simon Vig Therkildsen' +// email 'simonvt@gmail.com' +// url 'http://simonvt.net' +// timezone '1' +// roles { +// role 'developer' +// } +// } +// } +// } +// } +//} checkstyle { configFile project.file('../checkstyle.xml') diff --git a/menudrawer/src/net/simonvt/menudrawer/DraggableDrawer.java b/menudrawer/src/net/simonvt/menudrawer/DraggableDrawer.java index 5725bc9..3e6a2b3 100644 --- a/menudrawer/src/net/simonvt/menudrawer/DraggableDrawer.java +++ b/menudrawer/src/net/simonvt/menudrawer/DraggableDrawer.java @@ -133,6 +133,11 @@ public void run() { */ protected boolean mOffsetMenu = true; + /** + * Offset value whether the menu should be offset when dragging the drawer. + */ + protected float mOffsetMenuRadio = 0.25f; + /** * Distance in px from closed position from where the drawer is considered closed with regards to touch events. */ @@ -150,6 +155,11 @@ public void run() { */ private Scroller mScroller; + /** + * Indicates whether the menu should be close when content click. + */ + private boolean clickToClose = true; + /** * Indicates whether the current layer type is {@link android.view.View#LAYER_TYPE_HARDWARE}. */ @@ -218,6 +228,14 @@ public boolean getOffsetMenuEnabled() { return mOffsetMenu; } + public void setOffsetMenuRadio(float value) { + this.mOffsetMenuRadio = value; + } + + public float getOffsetMenuRadio() { + return mOffsetMenuRadio; + } + public void peekDrawer() { peekDrawer(DEFAULT_PEEK_START_DELAY, DEFAULT_PEEK_DELAY); } @@ -621,4 +639,14 @@ public void restoreState(Parcelable in) { } mDrawerState = menuOpen ? STATE_OPEN : STATE_CLOSED; } + + + + public boolean isClickToClose() { + return clickToClose; + } + + public void setClickToClose(boolean clickToClose) { + this.clickToClose = clickToClose; + } } diff --git a/menudrawer/src/net/simonvt/menudrawer/MenuDrawer.java b/menudrawer/src/net/simonvt/menudrawer/MenuDrawer.java index 655fcc6..b0b5567 100644 --- a/menudrawer/src/net/simonvt/menudrawer/MenuDrawer.java +++ b/menudrawer/src/net/simonvt/menudrawer/MenuDrawer.java @@ -1,7 +1,7 @@ package net.simonvt.menudrawer; import net.simonvt.menudrawer.compat.ActionBarHelper; - +import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; @@ -868,7 +868,8 @@ protected Position getPosition() { return mPosition; } - @Override + @SuppressLint("NewApi") + @Override public void onRtlPropertiesChanged(int layoutDirection) { super.onRtlPropertiesChanged(layoutDirection); @@ -1088,7 +1089,15 @@ protected void updateTouchAreaSize() { if (mTouchMode == TOUCH_MODE_BEZEL) { mTouchSize = mTouchBezelSize; } else if (mTouchMode == TOUCH_MODE_FULLSCREEN) { - mTouchSize = getMeasuredWidth(); + switch (mPosition){ + case TOP: + case BOTTOM: + mTouchSize = getMeasuredHeight(); + break; + default: + mTouchSize = getMeasuredWidth(); + break; + } } else { mTouchSize = 0; } @@ -1134,6 +1143,33 @@ private void completeAnimatingIndicator() { */ public abstract boolean getOffsetMenuEnabled(); + /** + * Set the offset value when dragging the drawer. + * + * @param offset value in 0-1.0f. Default value is 0.25f. + */ + public abstract void setOffsetMenuRadio(float offsetMenuRadio); + + /** + * Get the offset menu value + * + * @return The offset value. Default value is 0.25f. + */ + public abstract float getOffsetMenuRadio(); + + + /** + * Indicates whether the menu should be closed when the content is closed. + * @return + */ + public abstract boolean isClickToClose(); + + /** + * Enables or disables close the menu when content is click. + * @param b + */ + public abstract void setClickToClose(boolean b); + /** * Get the current state of the drawer. * @@ -1550,7 +1586,8 @@ protected void logDrawerState(int state) { */ public abstract int getTouchBezelSize(); - @Override + @SuppressLint("NewApi") + @Override public void postOnAnimation(Runnable action) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { super.postOnAnimation(action); @@ -1564,8 +1601,7 @@ protected boolean fitSystemWindows(Rect insets) { if (mDragMode == MENU_DRAG_WINDOW && mPosition != Position.BOTTOM) { mMenuContainer.setPadding(0, insets.top, 0, 0); } - return super.fitSystemWindows(insets); - } + return super.fitSystemWindows(insets); } protected void dispatchOnDrawerSlide(float openRatio, int offsetPixels) { if (mOnDrawerStateChangeListener != null) { diff --git a/menudrawer/src/net/simonvt/menudrawer/SlidingDrawer.java b/menudrawer/src/net/simonvt/menudrawer/SlidingDrawer.java index 1d2530d..58463e4 100644 --- a/menudrawer/src/net/simonvt/menudrawer/SlidingDrawer.java +++ b/menudrawer/src/net/simonvt/menudrawer/SlidingDrawer.java @@ -191,7 +191,7 @@ private void offsetMenu(int offsetPixels) { final int menuSize = mMenuSize; final int sign = (int) (mOffsetPixels / Math.abs(mOffsetPixels)); final float openRatio = Math.abs(mOffsetPixels) / menuSize; - final int offset = (int) (-0.25f * ((1.0f - openRatio) * menuSize) * sign); + final int offset = (int) (-mOffsetMenuRadio * ((1.0f - openRatio) * menuSize) * sign); switch (getPosition()) { case LEFT: { @@ -407,7 +407,9 @@ protected void onUpEvent(int x, int y) { // Close the menu when content is clicked while the menu is visible. } else if (mMenuVisible && x > offsetPixels) { - closeMenu(); + if(isClickToClose()){ + closeMenu(); + } } break; } @@ -421,7 +423,9 @@ protected void onUpEvent(int x, int y) { // Close the menu when content is clicked while the menu is visible. } else if (mMenuVisible && y > offsetPixels) { - closeMenu(); + if(isClickToClose()){ + closeMenu(); + } } break; } @@ -437,7 +441,9 @@ protected void onUpEvent(int x, int y) { // Close the menu when content is clicked while the menu is visible. } else if (mMenuVisible && x < width + offsetPixels) { - closeMenu(); + if(isClickToClose()){ + closeMenu(); + } } break; } @@ -451,7 +457,9 @@ protected void onUpEvent(int x, int y) { // Close the menu when content is clicked while the menu is visible. } else if (mMenuVisible && y < getHeight() + offsetPixels) { - closeMenu(); + if(isClickToClose()){ + closeMenu(); + } } break; } diff --git a/menudrawer/src/net/simonvt/menudrawer/StaticDrawer.java b/menudrawer/src/net/simonvt/menudrawer/StaticDrawer.java index bad120b..fe0dd24 100644 --- a/menudrawer/src/net/simonvt/menudrawer/StaticDrawer.java +++ b/menudrawer/src/net/simonvt/menudrawer/StaticDrawer.java @@ -151,6 +151,16 @@ public boolean getOffsetMenuEnabled() { return false; } + @Override + public void setOffsetMenuRadio(float offsetMenuRadio) { + // NO-OP + } + + @Override + public float getOffsetMenuRadio() { + return 0; + } + @Override public void peekDrawer() { // NO-OP @@ -215,4 +225,12 @@ public void setDrawerIndicatorEnabled(boolean enabled) { public boolean isDrawerIndicatorEnabled() { return false; } + + public boolean isClickToClose() { + return false; + } + + public void setClickToClose(boolean clickToClose) { + // NO-OP + } } diff --git a/menudrawer/src/net/simonvt/menudrawer/compat/ActionBarHelperCompat.java b/menudrawer/src/net/simonvt/menudrawer/compat/ActionBarHelperCompat.java index 0b60257..f9db3c9 100644 --- a/menudrawer/src/net/simonvt/menudrawer/compat/ActionBarHelperCompat.java +++ b/menudrawer/src/net/simonvt/menudrawer/compat/ActionBarHelperCompat.java @@ -93,7 +93,7 @@ private static class SetIndicatorInfo { Class supportActivity = activity.getClass(); Method getActionBar = supportActivity.getMethod("getSupportActionBar"); - mActionBar = getActionBar.invoke(activity, null); + mActionBar = getActionBar.invoke(activity); Class supportActionBar = mActionBar.getClass(); mHomeAsUpEnabled = supportActionBar.getMethod("setDisplayHomeAsUpEnabled", Boolean.TYPE);