diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..2acf1e6 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,27 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.3" + + defaultConfig { + applicationId "top.resonlei.popmenu" + minSdkVersion 15 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:23.3.0' + compile project(path: ':popmenuview') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..8d8ccb8 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in D:\Users\Administrator\AppData\Local\Android\sdk1/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/app/src/androidTest/java/top/resonlei/popmenu/ApplicationTest.java b/app/src/androidTest/java/top/resonlei/popmenu/ApplicationTest.java new file mode 100644 index 0000000..a540b00 --- /dev/null +++ b/app/src/androidTest/java/top/resonlei/popmenu/ApplicationTest.java @@ -0,0 +1,13 @@ +package top.resonlei.popmenu; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..f0012d2 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/top/resonlei/popmenu/MainActivity.java b/app/src/main/java/top/resonlei/popmenu/MainActivity.java new file mode 100644 index 0000000..568fd4d --- /dev/null +++ b/app/src/main/java/top/resonlei/popmenu/MainActivity.java @@ -0,0 +1,63 @@ +package top.resonlei.popmenu; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.widget.Toast; + +import java.util.ArrayList; +import java.util.List; + +import resonlei.top.popmenuview.PopMenu; + +public class MainActivity extends AppCompatActivity { + private PopMenu mPopupMenu; + private ListView mListView; + private List mStringList; + + public MainActivity() { + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + mStringList = new ArrayList<>(); + for (int i = 0; i < 300; i++) { + mStringList.add(i+""); + } + + mPopupMenu = (PopMenu) findViewById(R.id.popmenu); + mListView = (ListView) findViewById(R.id.listview); + + mListView.setAdapter(new ArrayAdapter<>(this,android.R.layout.simple_list_item_1,mStringList)); +// ImageView imageView = new ImageView(this); +// imageView.setImageResource(R.mipmap.item_screen); +// imageView.setTag("screen"); +// +// mPopupMenu.addView(imageView); + //动态设置布局 + mPopupMenu.setMenu(R.mipmap.item_del) + .setItem(R.mipmap.ic_launcher,"android1") + .setItem(R.mipmap.ic_launcher,"android2") + .setItem(R.mipmap.ic_launcher,"android3") + .setItem(R.mipmap.ic_launcher,"android4") + .setItem(R.mipmap.ic_launcher,"android5"); + + + mPopupMenu.setOnMenuItemClickListener(new PopMenu.OnMenuItemClickListener() { + @Override + public void onClick(View view, int pos) { + Toast.makeText(MainActivity.this,view.getTag().toString(),Toast.LENGTH_SHORT).show(); + } + }); + + } + + public void a(View v){ + Log.e("button","onClick"); + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..506235c --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..aee44e1 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/item_about.png b/app/src/main/res/mipmap-xxxhdpi/item_about.png new file mode 100644 index 0000000..fceb0a6 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/item_about.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/item_add.png b/app/src/main/res/mipmap-xxxhdpi/item_add.png new file mode 100644 index 0000000..b5a25ed Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/item_add.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/item_del.png b/app/src/main/res/mipmap-xxxhdpi/item_del.png new file mode 100644 index 0000000..51da152 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/item_del.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/item_screen.png b/app/src/main/res/mipmap-xxxhdpi/item_screen.png new file mode 100644 index 0000000..95179f0 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/item_screen.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/item_settime.png b/app/src/main/res/mipmap-xxxhdpi/item_settime.png new file mode 100644 index 0000000..ac9da62 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/item_settime.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/menu.png b/app/src/main/res/mipmap-xxxhdpi/menu.png new file mode 100644 index 0000000..0c649a8 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/menu.png differ diff --git a/app/src/main/res/values-w820dp/dimens.xml b/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..3ab3e9c --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..47c8224 --- /dev/null +++ b/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..8bf17e0 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + PopMenu + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..5885930 --- /dev/null +++ b/app/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/app/src/test/java/top/resonlei/popmenu/ExampleUnitTest.java b/app/src/test/java/top/resonlei/popmenu/ExampleUnitTest.java new file mode 100644 index 0000000..7323b02 --- /dev/null +++ b/app/src/test/java/top/resonlei/popmenu/ExampleUnitTest.java @@ -0,0 +1,15 @@ +package top.resonlei.popmenu; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * To work on unit tests, switch the Test Artifact in the Build Variants view. + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..03bced9 --- /dev/null +++ b/build.gradle @@ -0,0 +1,23 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:2.1.0' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/build/generated/mockable-android-23.jar b/build/generated/mockable-android-23.jar new file mode 100644 index 0000000..7e96741 Binary files /dev/null and b/build/generated/mockable-android-23.jar differ diff --git a/build/intermediates/dex-cache/cache.xml b/build/intermediates/dex-cache/cache.xml new file mode 100644 index 0000000..a52bc0f --- /dev/null +++ b/build/intermediates/dex-cache/cache.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..1d3591c --- /dev/null +++ b/gradle.properties @@ -0,0 +1,18 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..13372ae Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..122a0dc --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Mon Dec 28 10:00:20 PST 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..9d82f78 --- /dev/null +++ b/gradlew @@ -0,0 +1,160 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/popmenuview/.gitignore b/popmenuview/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/popmenuview/.gitignore @@ -0,0 +1 @@ +/build diff --git a/popmenuview/build.gradle b/popmenuview/build.gradle new file mode 100644 index 0000000..1a09cbc --- /dev/null +++ b/popmenuview/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.3" + + defaultConfig { + minSdkVersion 15 + targetSdkVersion 23 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:23.3.0' +} diff --git a/popmenuview/proguard-rules.pro b/popmenuview/proguard-rules.pro new file mode 100644 index 0000000..8d8ccb8 --- /dev/null +++ b/popmenuview/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in D:\Users\Administrator\AppData\Local\Android\sdk1/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/popmenuview/src/androidTest/java/resonlei/top/popmenuview/ApplicationTest.java b/popmenuview/src/androidTest/java/resonlei/top/popmenuview/ApplicationTest.java new file mode 100644 index 0000000..51d8011 --- /dev/null +++ b/popmenuview/src/androidTest/java/resonlei/top/popmenuview/ApplicationTest.java @@ -0,0 +1,13 @@ +package resonlei.top.popmenuview; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/popmenuview/src/main/AndroidManifest.xml b/popmenuview/src/main/AndroidManifest.xml new file mode 100644 index 0000000..182321c --- /dev/null +++ b/popmenuview/src/main/AndroidManifest.xml @@ -0,0 +1,11 @@ + + + + + + + diff --git a/popmenuview/src/main/java/resonlei/top/popmenuview/IllegalSetException.java b/popmenuview/src/main/java/resonlei/top/popmenuview/IllegalSetException.java new file mode 100644 index 0000000..bcc4054 --- /dev/null +++ b/popmenuview/src/main/java/resonlei/top/popmenuview/IllegalSetException.java @@ -0,0 +1,10 @@ +package resonlei.top.popmenuview; + +/** + * Created by Administrator on 2017/3/17. + */ +public class IllegalSetException extends IllegalArgumentException { + public IllegalSetException(String detailMessage) { + super(detailMessage); + } +} diff --git a/popmenuview/src/main/java/resonlei/top/popmenuview/PopMenu.java b/popmenuview/src/main/java/resonlei/top/popmenuview/PopMenu.java new file mode 100644 index 0000000..61ef65c --- /dev/null +++ b/popmenuview/src/main/java/resonlei/top/popmenuview/PopMenu.java @@ -0,0 +1,502 @@ +package resonlei.top.popmenuview; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.util.Log; +import android.util.TypedValue; +import android.view.MotionEvent; +import android.view.View; +import android.view.ViewGroup; +import android.view.animation.AlphaAnimation; +import android.view.animation.Animation; +import android.view.animation.AnimationSet; +import android.view.animation.OvershootInterpolator; +import android.view.animation.RotateAnimation; +import android.view.animation.ScaleAnimation; +import android.view.animation.TranslateAnimation; +import android.widget.ImageView; + + +/** + * Created by Administrator on 2017/3/17. + */ +public class PopMenu extends ViewGroup implements View.OnClickListener { + public interface OnMenuItemClickListener + { + void onClick(View view, int pos); + } + + /** + * 回调接口 + */ + private OnMenuItemClickListener onMenuItemClickListener; + + private static final String TAG = "PopMenu"; + /** + * 菜单的显示位置 + */ + private Position mPosition = Position.BOTTOM_LEFT; + + /** + * 菜单显示的半径,默认100dp + */ + private int mRadius = 100; + /** + * 用户点击的按钮 + */ + private View mButton; + /** + * 当前PopMenu的状态 + */ + private Status mCurrentStatus = Status.CLOSE; + + /** + * 状态的枚举类 + */ + public enum Status{ + OPEN,CLOSE + } + + /** + * 设置菜单现实的位置,四选1,默认右下 + * + * @author zhy + */ + public enum Position + { + TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTON_RIGHT; + } + + + public PopMenu(Context context) { + this(context,null); + } + + public PopMenu(Context context, AttributeSet attrs) { + this(context, attrs,0); + } + + public PopMenu(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + //获取用户设置的半径, + mRadius = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, + mRadius, getResources().getDisplayMetrics()); + TypedArray a = context.getTheme() + .obtainStyledAttributes(attrs, R.styleable.PopMenu, defStyleAttr, 0); + + //处理自定义属性 + int n = a.getIndexCount(); + for (int i = 0; i < n; i++) { + int attr = a.getIndex(i); + if (attr == R.styleable.PopMenu_position) { + int val = a.getInt(attr, 0); + switch (val) { + case 0: + mPosition = Position.TOP_LEFT; + break; + case 1: + mPosition = Position.TOP_RIGHT; + break; + case 2: + mPosition = Position.BOTTOM_LEFT; + break; + case 3: + mPosition = Position.BOTTON_RIGHT; + break; + } + + } else if (attr == R.styleable.PopMenu_radius) {// dp convert to px + mRadius = a.getDimensionPixelSize(attr, (int) TypedValue + .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100f, + getResources().getDisplayMetrics())); + + } + } + a.recycle(); + + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int count = getChildCount(); + for (int i = 0; i < count; i++) { + getChildAt(i).measure(MeasureSpec.UNSPECIFIED, + MeasureSpec.UNSPECIFIED); + } + + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + if (changed) + { + + layoutButton(); + int count = getChildCount(); + /** + * 设置所有孩子的位置 例如(第一个为按钮): 左上时,从左到右 ] 第2个:mRadius(sin0 , cos0) + * 第3个:mRadius(sina ,cosa) 注:[a = Math.PI / 2 * (cCount - 1)] + * 第4个:mRadius(sin2a ,cos2a) 第5个:mRadius(sin3a , cos3a) ... + */ + for (int i = 0; i < count - 1; i++) + { + View child = getChildAt(i + 1); + child.setVisibility(View.GONE); + + int cl = (int) (mRadius * Math.sin(Math.PI / 2 / (count - 2) + * i)); + int ct = (int) (mRadius * Math.cos(Math.PI / 2 / (count - 2) + * i)); + + //TODO 处理异常,在只有一个item的时候,防止计算错误 + if (count == 2){ + cl = (int) (mRadius * Math.sin(Math.PI/4)); + ct = (int) (mRadius * Math.sin(Math.PI/4)); + } + Log.e(TAG,cl+":"+ct); + + + + // childview width + int cWidth = child.getMeasuredWidth(); + // childview height + int cHeight = child.getMeasuredHeight(); + + // 右上,右下 + if (mPosition == Position.BOTTOM_LEFT + || mPosition == Position.BOTTON_RIGHT) + { + ct = getMeasuredHeight() - cHeight - ct; + } + // 右上,右下 + if (mPosition == Position.TOP_RIGHT + || mPosition == Position.BOTTON_RIGHT) + { + cl = getMeasuredWidth() - cWidth - cl; + } + + Log.e(TAG, cl + " , " + ct); + child.layout(cl, ct, cl + cWidth, ct + cHeight); + + } + } + } + + private void layoutButton() { + View cButton = getChildAt(0); + + cButton.setOnClickListener(this); + + int l = 0; + int t = 0; + int width = cButton.getMeasuredWidth(); + int height = cButton.getMeasuredHeight(); + switch (mPosition) + { + case TOP_LEFT: + l = 0; + t = 0; + break; + case BOTTOM_LEFT: + l = 0; + t = getMeasuredHeight() - height; + break; + case TOP_RIGHT: + l = getMeasuredWidth() - width; + t = 0; + break; + case BOTTON_RIGHT: + l = getMeasuredWidth() - width; + t = getMeasuredHeight() - height; + break; + + } + Log.e(TAG, l + " , " + t + " , " + (l + width) + " , " + (t + height)); + cButton.layout(l, t, l + width, t + height); + } + + /** + * 主菜单按钮的点击事件 + */ + @Override + public void onClick(View v) + { +// mButton = findViewById(R.id.id_button); +// if (mButton == null) +// { +// mButton = getChildAt(0); +// } +// +// rotateView(mButton, 0f, 360f, 300); +// toggleMenu(300); + + mButton = getChildAt(0); + if (mButton == null){ + return; + } + rotateView(mButton, 0f, 360f, 300); + toggleMenu(300); + } + + /** + * 按钮的旋转动画 + * + * @param view + * @param fromDegrees + * @param toDegrees + * @param durationMillis + */ + public static void rotateView(View view, float fromDegrees, + float toDegrees, int durationMillis) + { + RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees, + Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, + 0.5f); + rotate.setDuration(durationMillis); + rotate.setFillAfter(true); + view.startAnimation(rotate); + } + + /** + * menu菜单的开关 + * @param durationMillis + */ + public void toggleMenu(int durationMillis) + { + int count = getChildCount(); + for (int i = 0; i < count - 1; i++) + { + final View childView = getChildAt(i + 1); + childView.setVisibility(View.VISIBLE); + + int xflag = 1; + int yflag = 1; + + if (mPosition == Position.TOP_LEFT + || mPosition == Position.BOTTOM_LEFT) + xflag = -1; + if (mPosition == Position.TOP_LEFT + || mPosition == Position.TOP_RIGHT) + yflag = -1; + + // child left + int cl = (int) (mRadius * Math.sin(Math.PI / 2 / (count - 2) * i)); + // child top + int ct = (int) (mRadius * Math.cos(Math.PI / 2 / (count - 2) * i)); + + //TODO 处理异常,在只有一个item的时候,防止计算错误 + if (count == 2){ + cl = (int) (mRadius * Math.sin(Math.PI/4)); + ct = (int) (mRadius * Math.sin(Math.PI/4)); + } + Log.e(TAG,cl+":"+ct); + + AnimationSet animset = new AnimationSet(true); + Animation animation = null; + if (mCurrentStatus == Status.CLOSE) + {// to open + animset.setInterpolator(new OvershootInterpolator(2F)); + animation = new TranslateAnimation(xflag * cl, 0, yflag * ct, 0); + childView.setClickable(true); + childView.setFocusable(true); + } else + {// to close + animation = new TranslateAnimation(0f, xflag * cl, 0f, yflag + * ct); + childView.setClickable(false); + childView.setFocusable(false); + } + animation.setAnimationListener(new Animation.AnimationListener() + { + public void onAnimationStart(Animation animation) + { + } + + public void onAnimationRepeat(Animation animation) + { + } + + public void onAnimationEnd(Animation animation) + { + if (mCurrentStatus == Status.CLOSE) + childView.setVisibility(View.GONE); + + } + }); + + animation.setFillAfter(true); + animation.setDuration(durationMillis); + // 为动画设置一个开始延迟时间,纯属好看,可以不设 + animation.setStartOffset((i * 100) / (count - 1)); + RotateAnimation rotate = new RotateAnimation(0, 720, + Animation.RELATIVE_TO_SELF, 0.5f, + Animation.RELATIVE_TO_SELF, 0.5f); + rotate.setDuration(durationMillis); + rotate.setFillAfter(true); + animset.addAnimation(rotate); + animset.addAnimation(animation); + childView.startAnimation(animset); + final int index = i + 1; + childView.setOnClickListener(new OnClickListener() + { + @Override + public void onClick(View v) + { + if (onMenuItemClickListener != null) + onMenuItemClickListener.onClick(childView, index - 1); + menuItemAnin(index - 1); + changeStatus(); + + } + }); + + } + changeStatus(); + Log.e(TAG, mCurrentStatus.name() +""); + } + + /** + * 更改菜单关闭还是打开状态 + */ + private void changeStatus() { + mCurrentStatus = (mCurrentStatus == Status.CLOSE? Status.OPEN: Status.CLOSE); + } + + /** + * 开始菜单动画,点击的MenuItem放大消失,其他的缩小消失 + * @param item + */ + private void menuItemAnin(int item){ + for (int i = 0; i < getChildCount() - 1; i++) + { + View childView = getChildAt(i + 1); + if (i == item) + { + childView.startAnimation(scaleBigAnim(300)); + } else + { + childView.startAnimation(scaleSmallAnim(300)); + } + childView.setClickable(false); + childView.setFocusable(false); + + } + + } + + /** + * 缩小消失动画 + * @param durationMillis + * @return + */ + private Animation scaleSmallAnim(int durationMillis){ + Animation anim = new ScaleAnimation(1.0f, 0f, 1.0f, 0f, + Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, + 0.5f); + anim.setDuration(durationMillis); + anim.setFillAfter(true); + return anim; + } + /** + * 放大,透明度降低 + * @param durationMillis + * @return + */ + private Animation scaleBigAnim(int durationMillis){ + AnimationSet animationset = new AnimationSet(true); + + Animation anim = new ScaleAnimation(1.0f, 4.0f, 1.0f, 4.0f, + Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, + 0.5f); + Animation alphaAnimation = new AlphaAnimation(1, 0); + animationset.addAnimation(anim); + animationset.addAnimation(alphaAnimation); + animationset.setDuration(durationMillis); + animationset.setFillAfter(true); + animationset.setAnimationListener(new Animation.AnimationListener() { + @Override + public void onAnimationStart(Animation animation) { + + } + + @Override + public void onAnimationEnd(Animation animation) { + toggleItemVisible(View.GONE); + } + + @Override + public void onAnimationRepeat(Animation animation) { + + } + }); + return animationset; + } + + /** + * 设置item的GONE跟VIsiBLE状态 + * @param status + */ + private void toggleItemVisible(int status) { + if (status != View.GONE && status != View.VISIBLE){ + throw new IllegalArgumentException("status should be View.VISIBLE or View.GONE"); + } + int count = getChildCount(); + for (int i = 1; i < count; i++) { + getChildAt(i).setVisibility(status); + } + } + + /** + * item的点击事件 + * @param onMenuItemClickListener + */ + public void setOnMenuItemClickListener(OnMenuItemClickListener onMenuItemClickListener){ + this.onMenuItemClickListener = onMenuItemClickListener; + } + + /** + * 动态设置主菜单 + * @return + */ + public PopMenu setMenu(int iconRes){ + if (getChildCount() > 0){ + //throw new IllegalArgumentException("xml文件已经设置,请不要重复设置"); + Log.e(TAG,"xml文件已经设置,请不要重复设置"); + }else{ + ImageView imageView = new ImageView(getContext()); + imageView.setImageResource(iconRes); + imageView.setTag("menu"); + this.addView(imageView,0); + } + return this; + } + + /** + * 动态设置主菜单项目 + * @param iconRes + * @param tag + * @return + */ + public PopMenu setItem(int iconRes,String tag) { + if (getChildCount() == 0){ + throw new IllegalSetException("menu not exist,please use setMenu to set!"); + }else{ + ImageView imageView = new ImageView(getContext()); + imageView.setImageResource(iconRes); + imageView.setTag(tag); + this.addView(imageView); + } + + return this; + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + if (mCurrentStatus == Status.OPEN) + toggleMenu(300); + Log.e(TAG,"onTOuchEvent"); + return false; + } +} diff --git a/popmenuview/src/main/res/values/atts.xml b/popmenuview/src/main/res/values/atts.xml new file mode 100644 index 0000000..9308231 --- /dev/null +++ b/popmenuview/src/main/res/values/atts.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/popmenuview/src/main/res/values/strings.xml b/popmenuview/src/main/res/values/strings.xml new file mode 100644 index 0000000..56a602d --- /dev/null +++ b/popmenuview/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + PopMenuView + diff --git a/popmenuview/src/test/java/resonlei/top/popmenuview/ExampleUnitTest.java b/popmenuview/src/test/java/resonlei/top/popmenuview/ExampleUnitTest.java new file mode 100644 index 0000000..0edfb8b --- /dev/null +++ b/popmenuview/src/test/java/resonlei/top/popmenuview/ExampleUnitTest.java @@ -0,0 +1,15 @@ +package resonlei.top.popmenuview; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * To work on unit tests, switch the Test Artifact in the Build Variants view. + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..a5e3be4 --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +include ':app', ':popmenuview'