diff --git a/CardScrollView/.gitignore b/CardScrollView/.gitignore new file mode 100644 index 0000000..9c4de58 --- /dev/null +++ b/CardScrollView/.gitignore @@ -0,0 +1,7 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/CardScrollView/app/.gitignore b/CardScrollView/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/CardScrollView/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/CardScrollView/app/build.gradle b/CardScrollView/app/build.gradle new file mode 100644 index 0000000..c5987cb --- /dev/null +++ b/CardScrollView/app/build.gradle @@ -0,0 +1,26 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + applicationId "com.example.mukul.cardscrollview" + minSdkVersion 10 + 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']) + compile 'com.android.support:appcompat-v7:23.0.1' + compile 'com.android.support:design:23.0.1' +} diff --git a/CardScrollView/app/libs/gdk.jar b/CardScrollView/app/libs/gdk.jar new file mode 100644 index 0000000..428d1f5 Binary files /dev/null and b/CardScrollView/app/libs/gdk.jar differ diff --git a/CardScrollView/app/proguard-rules.pro b/CardScrollView/app/proguard-rules.pro new file mode 100644 index 0000000..d5579da --- /dev/null +++ b/CardScrollView/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 C:\Users\mukul\AppData\Local\Android\sdk/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/CardScrollView/app/src/androidTest/java/com/example/mukul/cardscrollview/ApplicationTest.java b/CardScrollView/app/src/androidTest/java/com/example/mukul/cardscrollview/ApplicationTest.java new file mode 100644 index 0000000..f47325d --- /dev/null +++ b/CardScrollView/app/src/androidTest/java/com/example/mukul/cardscrollview/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.example.mukul.cardscrollview; + +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/CardScrollView/app/src/main/AndroidManifest.xml b/CardScrollView/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..b369dda --- /dev/null +++ b/CardScrollView/app/src/main/AndroidManifest.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/CardScrollView/app/src/main/java/com/example/mukul/cardscrollview/MainActivity.java b/CardScrollView/app/src/main/java/com/example/mukul/cardscrollview/MainActivity.java new file mode 100644 index 0000000..391e3bc --- /dev/null +++ b/CardScrollView/app/src/main/java/com/example/mukul/cardscrollview/MainActivity.java @@ -0,0 +1,71 @@ +package com.example.mukul.cardscrollview; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + +import java.util.ArrayList; +import java.util.List; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; + +import com.google.android.glass.app.Card.ImageLayout; +import com.google.android.glass.widget.CardScrollView; + +import info.androidhive.cardscrollview.R; + + +public class MainActivity extends Activity { + + private List mCards; + private CardScrollView mCardScrollView; + private Context context; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + context = this; + + prepareMovieCards(); + + mCardScrollView = new CardScrollView(this); + MovieCardsAdapter adapter = new MovieCardsAdapter(context, mCards); + mCardScrollView.setAdapter(adapter); + mCardScrollView.activate(); + setContentView(mCardScrollView); + } + + private void prepareMovieCards() { + mCards = new ArrayList(); + + // Card with no background image + MovieCard mc = new MovieCard("I don't know. But who cares! Ha ha!", + "Wait! What does that mean?", ImageLayout.FULL, new int[] {}); + mCards.add(mc); + + // Card with full background image + mc = new MovieCard("I wanna go home. Does anyone know where my dad is?", + "Pet store?", ImageLayout.FULL, + new int[] { R.drawable.card_full }); + mCards.add(mc); + + // Card with full background of 3 images + mc = new MovieCard("Dude? Dude? Focus dude... Dude?", + "Oh, he lives. Hey, dude!", ImageLayout.FULL, new int[] { + R.drawable.card_bottom_left, + R.drawable.card_bottom_right, R.drawable.card_top }); + mCards.add(mc); + + // Card with left aligned images + mc = new MovieCard("Just keep swimming.", + "I'm sorry, Dory. But I... do", ImageLayout.LEFT, new int[] { + R.drawable.card_bottom_left, + R.drawable.card_bottom_right, R.drawable.card_top }); + mCards.add(mc); + + } +} \ No newline at end of file diff --git a/CardScrollView/app/src/main/java/com/example/mukul/cardscrollview/MovieCard.java b/CardScrollView/app/src/main/java/com/example/mukul/cardscrollview/MovieCard.java new file mode 100644 index 0000000..3fdc0ac --- /dev/null +++ b/CardScrollView/app/src/main/java/com/example/mukul/cardscrollview/MovieCard.java @@ -0,0 +1,59 @@ +package com.example.mukul.cardscrollview; + +/** + * Created by mukul on 10/21/2015. + */ + +import com.google.android.glass.app.Card.ImageLayout; + +public class MovieCard { + + private String text; + private String footerText; + private ImageLayout imgLayout; + private int[] images; + + public MovieCard() { + } + + public MovieCard(String text, String footerText, + ImageLayout imgLayout, int[] images) { + this.text = text; + this.footerText = footerText; + this.imgLayout = imgLayout; + this.images = images; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getFooterText() { + return footerText; + } + + public void setFooterText(String footerText) { + this.footerText = footerText; + } + + public ImageLayout getImgLayout() { + return imgLayout; + } + + public void setImgLayout(ImageLayout imgLayout) { + this.imgLayout = imgLayout; + } + + public int[] getImages() { + return images; + } + + public void setImages(int[] images) { + this.images = images; + } + +} \ No newline at end of file diff --git a/CardScrollView/app/src/main/java/com/example/mukul/cardscrollview/MovieCardsAdapter.java b/CardScrollView/app/src/main/java/com/example/mukul/cardscrollview/MovieCardsAdapter.java new file mode 100644 index 0000000..3aeabf5 --- /dev/null +++ b/CardScrollView/app/src/main/java/com/example/mukul/cardscrollview/MovieCardsAdapter.java @@ -0,0 +1,83 @@ +package com.example.mukul.cardscrollview; + +/** + * Created by mukul on 10/21/2015. + */ + + + + + import java.util.List; + + import android.content.Context; + import android.view.View; + import android.view.ViewGroup; + + import com.google.android.glass.app.Card; + import com.google.android.glass.widget.CardScrollAdapter; + +// import com.google.android.glass.app.Card; + // import com.google.android.glass.widget.CardScrollAdapter; + +public class MovieCardsAdapter extends CardScrollAdapter { + private List mCards; + private Context context; + + public MovieCardsAdapter(Context context, List mCards) { + this.context = context; + this.mCards = mCards; + } + + + public int getPosition(Object item) { + return mCards.indexOf(item); + } + + + public int getCount() { + return mCards.size(); + } + + @Override + public Object getItem(int position) { + return mCards.get(position); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + Card card = new Card(context); + + MovieCard mc = mCards.get(position); + + // Card text + if (mc.getText() != null) + card.setText(mc.getText()); + + // Card footer note + if (mc.getFooterText() != null) + card.setFootnote(mc.getFooterText()); + + // Set image layout + if (mc.getImgLayout() != null) + card.setImageLayout(mc.getImgLayout()); + + // loop and set card images + for(int img : mc.getImages()){ + card.addImage(img); + } + + return card.toView(); + } + + @Override + public int findIdPosition(Object o) { + return 0; + } + + @Override + public int findItemPosition(Object o) { + return 0; + } + + +} diff --git a/CardScrollView/app/src/main/res/drawable/app_icon.png b/CardScrollView/app/src/main/res/drawable/app_icon.png new file mode 100644 index 0000000..d472823 Binary files /dev/null and b/CardScrollView/app/src/main/res/drawable/app_icon.png differ diff --git a/CardScrollView/app/src/main/res/drawable/card_bottom_left.png b/CardScrollView/app/src/main/res/drawable/card_bottom_left.png new file mode 100644 index 0000000..694b51b Binary files /dev/null and b/CardScrollView/app/src/main/res/drawable/card_bottom_left.png differ diff --git a/CardScrollView/app/src/main/res/drawable/card_bottom_right.png b/CardScrollView/app/src/main/res/drawable/card_bottom_right.png new file mode 100644 index 0000000..0bbbcb0 Binary files /dev/null and b/CardScrollView/app/src/main/res/drawable/card_bottom_right.png differ diff --git a/CardScrollView/app/src/main/res/drawable/card_full.png b/CardScrollView/app/src/main/res/drawable/card_full.png new file mode 100644 index 0000000..1343d65 Binary files /dev/null and b/CardScrollView/app/src/main/res/drawable/card_full.png differ diff --git a/CardScrollView/app/src/main/res/drawable/card_top.png b/CardScrollView/app/src/main/res/drawable/card_top.png new file mode 100644 index 0000000..ed2aab9 Binary files /dev/null and b/CardScrollView/app/src/main/res/drawable/card_top.png differ diff --git a/CardScrollView/app/src/main/res/layout/activity_main.xml b/CardScrollView/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..f7158b8 --- /dev/null +++ b/CardScrollView/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/CardScrollView/app/src/main/res/menu/menu_main.xml b/CardScrollView/app/src/main/res/menu/menu_main.xml new file mode 100644 index 0000000..b1cb908 --- /dev/null +++ b/CardScrollView/app/src/main/res/menu/menu_main.xml @@ -0,0 +1,6 @@ + + + diff --git a/CardScrollView/app/src/main/res/mipmap-hdpi/ic_launcher.png b/CardScrollView/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..cde69bc Binary files /dev/null and b/CardScrollView/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/CardScrollView/app/src/main/res/mipmap-mdpi/ic_launcher.png b/CardScrollView/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..c133a0c Binary files /dev/null and b/CardScrollView/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/CardScrollView/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/CardScrollView/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..bfa42f0 Binary files /dev/null and b/CardScrollView/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/CardScrollView/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/CardScrollView/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..324e72c Binary files /dev/null and b/CardScrollView/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/CardScrollView/app/src/main/res/values-w820dp/dimens.xml b/CardScrollView/app/src/main/res/values-w820dp/dimens.xml new file mode 100644 index 0000000..63fc816 --- /dev/null +++ b/CardScrollView/app/src/main/res/values-w820dp/dimens.xml @@ -0,0 +1,6 @@ + + + 64dp + diff --git a/CardScrollView/app/src/main/res/values/dimens.xml b/CardScrollView/app/src/main/res/values/dimens.xml new file mode 100644 index 0000000..47c8224 --- /dev/null +++ b/CardScrollView/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/CardScrollView/app/src/main/res/values/strings.xml b/CardScrollView/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..7174f41 --- /dev/null +++ b/CardScrollView/app/src/main/res/values/strings.xml @@ -0,0 +1,11 @@ + + CardScrollView + + Hello world! + Settings + + + + Movie Cards + + diff --git a/CardScrollView/app/src/main/res/values/styles.xml b/CardScrollView/app/src/main/res/values/styles.xml new file mode 100644 index 0000000..766ab99 --- /dev/null +++ b/CardScrollView/app/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/CardScrollView/app/src/main/res/xml/voice_trigger_start.xml b/CardScrollView/app/src/main/res/xml/voice_trigger_start.xml new file mode 100644 index 0000000..aa0d479 --- /dev/null +++ b/CardScrollView/app/src/main/res/xml/voice_trigger_start.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/CardScrollView/build.gradle b/CardScrollView/build.gradle new file mode 100644 index 0000000..1b7886d --- /dev/null +++ b/CardScrollView/build.gradle @@ -0,0 +1,19 @@ +// 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:1.3.0' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} diff --git a/CardScrollView/gradle.properties b/CardScrollView/gradle.properties new file mode 100644 index 0000000..1d3591c --- /dev/null +++ b/CardScrollView/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/CardScrollView/gradle/wrapper/gradle-wrapper.jar b/CardScrollView/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..8c0fb64 Binary files /dev/null and b/CardScrollView/gradle/wrapper/gradle-wrapper.jar differ diff --git a/CardScrollView/gradle/wrapper/gradle-wrapper.properties b/CardScrollView/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..f2b220a --- /dev/null +++ b/CardScrollView/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Oct 21 22:03:06 IST 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip diff --git a/CardScrollView/gradlew b/CardScrollView/gradlew new file mode 100644 index 0000000..91a7e26 --- /dev/null +++ b/CardScrollView/gradlew @@ -0,0 +1,164 @@ +#!/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 + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# 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\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +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"` + + # 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/CardScrollView/gradlew.bat b/CardScrollView/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/CardScrollView/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/CardScrollView/settings.gradle b/CardScrollView/settings.gradle new file mode 100644 index 0000000..e7b4def --- /dev/null +++ b/CardScrollView/settings.gradle @@ -0,0 +1 @@ +include ':app' diff --git a/FloatingText b/FloatingText new file mode 160000 index 0000000..c151e5e --- /dev/null +++ b/FloatingText @@ -0,0 +1 @@ +Subproject commit c151e5ecf1a98b133062d6fc75c0030aa0266e2b diff --git a/LICENSE b/LICENSE deleted file mode 100644 index e06d208..0000000 --- a/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - diff --git a/MaterialDesign b/MaterialDesign new file mode 160000 index 0000000..0c18c61 --- /dev/null +++ b/MaterialDesign @@ -0,0 +1 @@ +Subproject commit 0c18c61c1e2530de3a2ed2fdd15790c6c5bad842 diff --git a/Snackbar b/Snackbar new file mode 160000 index 0000000..190d979 --- /dev/null +++ b/Snackbar @@ -0,0 +1 @@ +Subproject commit 190d979f03c1e026ecb8159eafeebe9222a37dcb diff --git a/Uploading/.gitignore b/Uploading/.gitignore new file mode 100644 index 0000000..9c4de58 --- /dev/null +++ b/Uploading/.gitignore @@ -0,0 +1,7 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/Uploading/app/.gitignore b/Uploading/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/Uploading/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/Uploading/app/build.gradle b/Uploading/app/build.gradle new file mode 100644 index 0000000..6ebd455 --- /dev/null +++ b/Uploading/app/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 23 + buildToolsVersion "23.0.1" + + defaultConfig { + applicationId "com.example.mukul.uploading" + minSdkVersion 10 + 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']) + compile 'com.android.support:appcompat-v7:23.0.1' +} diff --git a/Uploading/app/proguard-rules.pro b/Uploading/app/proguard-rules.pro new file mode 100644 index 0000000..d5579da --- /dev/null +++ b/Uploading/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 C:\Users\mukul\AppData\Local\Android\sdk/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/Uploading/app/src/androidTest/java/com/example/mukul/uploading/ApplicationTest.java b/Uploading/app/src/androidTest/java/com/example/mukul/uploading/ApplicationTest.java new file mode 100644 index 0000000..5d0189f --- /dev/null +++ b/Uploading/app/src/androidTest/java/com/example/mukul/uploading/ApplicationTest.java @@ -0,0 +1,13 @@ +package com.example.mukul.uploading; + +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/Uploading/app/src/main/AndroidManifest.xml b/Uploading/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..047f90e --- /dev/null +++ b/Uploading/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + diff --git a/Uploading/app/src/main/java/com/example/mukul/uploading/AndroidMultiPartEntity.java b/Uploading/app/src/main/java/com/example/mukul/uploading/AndroidMultiPartEntity.java new file mode 100644 index 0000000..6d3270b --- /dev/null +++ b/Uploading/app/src/main/java/com/example/mukul/uploading/AndroidMultiPartEntity.java @@ -0,0 +1,72 @@ +package com.example.mukul.uploading; + +/** + * Created by mukul on 10/22/2015. + */ + +import java.io.FilterOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.charset.Charset; + +import org.apache.http.entity.mime.HttpMultipartMode; +import org.apache.http.entity.mime.MultipartEntity; + +@SuppressWarnings("deprecation") +public class AndroidMultiPartEntity extends MultipartEntity + +{ + + private final ProgressListener listener; + + public AndroidMultiPartEntity(final ProgressListener listener) { + super(); + this.listener = listener; + } + + public AndroidMultiPartEntity(final HttpMultipartMode mode, + final ProgressListener listener) { + super(mode); + this.listener = listener; + } + + public AndroidMultiPartEntity(HttpMultipartMode mode, final String boundary, + final Charset charset, final ProgressListener listener) { + super(mode, boundary, charset); + this.listener = listener; + } + + @Override + public void writeTo(final OutputStream outstream) throws IOException { + super.writeTo(new CountingOutputStream(outstream, this.listener)); + } + + public static interface ProgressListener { + void transferred(long num); + } + + public static class CountingOutputStream extends FilterOutputStream { + + private final ProgressListener listener; + private long transferred; + + public CountingOutputStream(final OutputStream out, + final ProgressListener listener) { + super(out); + this.listener = listener; + this.transferred = 0; + } + + public void write(byte[] b, int off, int len) throws IOException { + out.write(b, off, len); + this.transferred += len; + this.listener.transferred(this.transferred); + } + + public void write(int b) throws IOException { + out.write(b); + this.transferred++; + this.listener.transferred(this.transferred); + } + } +} \ No newline at end of file diff --git a/Uploading/app/src/main/java/com/example/mukul/uploading/Config.java b/Uploading/app/src/main/java/com/example/mukul/uploading/Config.java new file mode 100644 index 0000000..3598821 --- /dev/null +++ b/Uploading/app/src/main/java/com/example/mukul/uploading/Config.java @@ -0,0 +1,13 @@ +package com.example.mukul.uploading; + +/** + * Created by mukul on 10/22/2015. + */ + +public class Config { + // File upload url (replace the ip with your server address) + public static final String FILE_UPLOAD_URL = "http://192.168.0.104/AndroidFileUpload/fileUpload.php"; + + // Directory name to store captured images and videos + public static final String IMAGE_DIRECTORY_NAME = "Android File Upload"; +} \ No newline at end of file diff --git a/Uploading/app/src/main/java/com/example/mukul/uploading/MainActivity.java b/Uploading/app/src/main/java/com/example/mukul/uploading/MainActivity.java new file mode 100644 index 0000000..4fdb1f9 --- /dev/null +++ b/Uploading/app/src/main/java/com/example/mukul/uploading/MainActivity.java @@ -0,0 +1,265 @@ +package com.example.mukul.uploading; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; + + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Locale; + +import android.app.Activity; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.net.Uri; +import android.os.Bundle; +import android.os.Environment; +import android.provider.MediaStore; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; + +public class MainActivity extends Activity { + + // LogCat tag + private static final String TAG = MainActivity.class.getSimpleName(); + + + // Camera activity request codes + private static final int CAMERA_CAPTURE_IMAGE_REQUEST_CODE = 100; + private static final int CAMERA_CAPTURE_VIDEO_REQUEST_CODE = 200; + + public static final int MEDIA_TYPE_IMAGE = 1; + public static final int MEDIA_TYPE_VIDEO = 2; + + private Uri fileUri; // file url to store image/video + + private Button btnCapturePicture, btnRecordVideo; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + // Changing action bar background color + // These two lines are not needed + getActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(getResources().getString(R.color.action_bar)))); + + btnCapturePicture = (Button) findViewById(R.id.btnCapturePicture); + btnRecordVideo = (Button) findViewById(R.id.btnRecordVideo); + + /** + * Capture image button click event + */ + btnCapturePicture.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + // capture picture + captureImage(); + } + }); + + /** + * Record video button click event + */ + btnRecordVideo.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + // record video + recordVideo(); + } + }); + + // Checking camera availability + if (!isDeviceSupportCamera()) { + Toast.makeText(getApplicationContext(), + "Sorry! Your device doesn't support camera", + Toast.LENGTH_LONG).show(); + // will close the app if the device does't have camera + finish(); + } + } + + /** + * Checking device has camera hardware or not + * */ + private boolean isDeviceSupportCamera() { + if (getApplicationContext().getPackageManager().hasSystemFeature( + PackageManager.FEATURE_CAMERA)) { + // this device has a camera + return true; + } else { + // no camera on this device + return false; + } + } + + /** + * Launching camera app to capture image + */ + private void captureImage() { + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + + fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); + + intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); + + // start the image capture Intent + startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE); + } + + /** + * Launching camera app to record video + */ + private void recordVideo() { + Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); + + fileUri = getOutputMediaFileUri(MEDIA_TYPE_VIDEO); + + // set video quality + intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1); + + intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file + // name + + // start the video capture Intent + startActivityForResult(intent, CAMERA_CAPTURE_VIDEO_REQUEST_CODE); + } + + /** + * Here we store the file url as it will be null after returning from camera + * app + */ + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + // save file url in bundle as it will be null on screen orientation + // changes + outState.putParcelable("file_uri", fileUri); + } + + @Override + protected void onRestoreInstanceState(Bundle savedInstanceState) { + super.onRestoreInstanceState(savedInstanceState); + + // get the file url + fileUri = savedInstanceState.getParcelable("file_uri"); + } + + + + /** + * Receiving activity result method will be called after closing the camera + * */ + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + // if the result is capturing Image + if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) { + if (resultCode == RESULT_OK) { + + // successfully captured the image + // launching upload activity + launchUploadActivity(true); + + + } else if (resultCode == RESULT_CANCELED) { + + // user cancelled Image capture + Toast.makeText(getApplicationContext(), + "User cancelled image capture", Toast.LENGTH_SHORT) + .show(); + + } else { + // failed to capture image + Toast.makeText(getApplicationContext(), + "Sorry! Failed to capture image", Toast.LENGTH_SHORT) + .show(); + } + + } else if (requestCode == CAMERA_CAPTURE_VIDEO_REQUEST_CODE) { + if (resultCode == RESULT_OK) { + + // video successfully recorded + // launching upload activity + launchUploadActivity(false); + + } else if (resultCode == RESULT_CANCELED) { + + // user cancelled recording + Toast.makeText(getApplicationContext(), + "User cancelled video recording", Toast.LENGTH_SHORT) + .show(); + + } else { + // failed to record video + Toast.makeText(getApplicationContext(), + "Sorry! Failed to record video", Toast.LENGTH_SHORT) + .show(); + } + } + } + + private void launchUploadActivity(boolean isImage){ + Intent i = new Intent(MainActivity.this, UploadActivity.class); + i.putExtra("filePath", fileUri.getPath()); + i.putExtra("isImage", isImage); + startActivity(i); + } + + /** + * ------------ Helper Methods ---------------------- + * */ + + /** + * Creating file uri to store image/video + */ + public Uri getOutputMediaFileUri(int type) { + return Uri.fromFile(getOutputMediaFile(type)); + } + + /** + * returning image / video + */ + private static File getOutputMediaFile(int type) { + + // External sdcard location + File mediaStorageDir = new File( + Environment + .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), + Config.IMAGE_DIRECTORY_NAME); + + // Create the storage directory if it does not exist + if (!mediaStorageDir.exists()) { + if (!mediaStorageDir.mkdirs()) { + Log.d(TAG, "Oops! Failed create " + + Config.IMAGE_DIRECTORY_NAME + " directory"); + return null; + } + } + + // Create a media file name + String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", + Locale.getDefault()).format(new Date()); + File mediaFile; + if (type == MEDIA_TYPE_IMAGE) { + mediaFile = new File(mediaStorageDir.getPath() + File.separator + + "IMG_" + timeStamp + ".jpg"); + } else if (type == MEDIA_TYPE_VIDEO) { + mediaFile = new File(mediaStorageDir.getPath() + File.separator + + "VID_" + timeStamp + ".mp4"); + } else { + return null; + } + + return mediaFile; + } +} \ No newline at end of file diff --git a/Uploading/app/src/main/java/com/example/mukul/uploading/UploadActivity.java b/Uploading/app/src/main/java/com/example/mukul/uploading/UploadActivity.java new file mode 100644 index 0000000..c4f6759 --- /dev/null +++ b/Uploading/app/src/main/java/com/example/mukul/uploading/UploadActivity.java @@ -0,0 +1,233 @@ +package com.example.mukul.uploading; + +/** + * Created by mukul on 10/22/2015. + */ + +//import info.androidhive.camerafileupload.AndroidMultiPartEntity.ProgressListener; +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; +import android.os.AsyncTask; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; +import android.widget.VideoView; + +import com.example.mukul.uploading.AndroidMultiPartEntity.ProgressListener; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.mime.content.FileBody; +import org.apache.http.entity.mime.content.StringBody; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.util.EntityUtils; + +import java.io.File; +import java.io.IOException; + +public class UploadActivity extends Activity { + // LogCat tag + private static final String TAG = MainActivity.class.getSimpleName(); + + private ProgressBar progressBar; + private String filePath = null; + private TextView txtPercentage; + private ImageView imgPreview; + private VideoView vidPreview; + private Button btnUpload; + long totalSize = 0; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_upload); + txtPercentage = (TextView) findViewById(R.id.txtPercentage); + btnUpload = (Button) findViewById(R.id.btnUpload); + progressBar = (ProgressBar) findViewById(R.id.progressBar); + imgPreview = (ImageView) findViewById(R.id.imgPreview); + vidPreview = (VideoView) findViewById(R.id.videoPreview); + + // Changing action bar background color + getActionBar().setBackgroundDrawable( + new ColorDrawable(Color.parseColor(getResources().getString( + R.color.action_bar)))); + + // Receiving the data from previous activity + Intent i = getIntent(); + + // image or video path that is captured in previous activity + filePath = i.getStringExtra("filePath"); + + // boolean flag to identify the media type, image or video + boolean isImage = i.getBooleanExtra("isImage", true); + + if (filePath != null) { + // Displaying the image or video on the screen + previewMedia(isImage); + } else { + Toast.makeText(getApplicationContext(), + "Sorry, file path is missing!", Toast.LENGTH_LONG).show(); + } + + btnUpload.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View v) { + // uploading the file to server + new UploadFileToServer().execute(); + } + }); + + } + + /** + * Displaying captured image/video on the screen + * */ + private void previewMedia(boolean isImage) { + // Checking whether captured media is image or video + if (isImage) { + imgPreview.setVisibility(View.VISIBLE); + vidPreview.setVisibility(View.GONE); + // bimatp factory + BitmapFactory.Options options = new BitmapFactory.Options(); + + // down sizing image as it throws OutOfMemory Exception for larger + // images + options.inSampleSize = 8; + + final Bitmap bitmap = BitmapFactory.decodeFile(filePath, options); + + imgPreview.setImageBitmap(bitmap); + } else { + imgPreview.setVisibility(View.GONE); + vidPreview.setVisibility(View.VISIBLE); + vidPreview.setVideoPath(filePath); + // start playing + vidPreview.start(); + } + } + + /** + * Uploading the file to server + * */ + private class UploadFileToServer extends AsyncTask { + @Override + protected void onPreExecute() { + // setting progress bar to zero + progressBar.setProgress(0); + super.onPreExecute(); + } + + @Override + protected void onProgressUpdate(Integer... progress) { + // Making progress bar visible + progressBar.setVisibility(View.VISIBLE); + + // updating progress bar value + progressBar.setProgress(progress[0]); + + // updating percentage value + txtPercentage.setText(String.valueOf(progress[0]) + "%"); + } + + @Override + protected String doInBackground(Void... params) { + return uploadFile(); + } + + @SuppressWarnings("deprecation") + private String uploadFile() { + String responseString = null; + + HttpClient httpclient = new DefaultHttpClient(); + HttpPost httppost = new HttpPost(Config.FILE_UPLOAD_URL); + + try { + AndroidMultiPartEntity entity = new AndroidMultiPartEntity( + new ProgressListener() { + + + public void transferred(long num) { + publishProgress((int) ((num / (float) totalSize) * 100)); + } + }); + + File sourceFile = new File(filePath); + + // Adding file data to http body + entity.addPart("image", new FileBody(sourceFile)); + + // Extra parameters if you want to pass to server + entity.addPart("website", + new StringBody("www.androidhive.info")); + entity.addPart("email", new StringBody("abc@gmail.com")); + + totalSize = entity.getContentLength(); + httppost.setEntity(entity); + + // Making server call + HttpResponse response = httpclient.execute(httppost); + HttpEntity r_entity = response.getEntity(); + + int statusCode = response.getStatusLine().getStatusCode(); + if (statusCode == 200) { + // Server response + responseString = EntityUtils.toString(r_entity); + } else { + responseString = "Error occurred! Http Status Code: " + + statusCode; + } + + } catch (ClientProtocolException e) { + responseString = e.toString(); + } catch (IOException e) { + responseString = e.toString(); + } + + return responseString; + + } + + @Override + protected void onPostExecute(String result) { + Log.e(TAG, "Response from server: " + result); + + // showing the server response in an alert dialog + showAlert(result); + + super.onPostExecute(result); + } + + } + + /** + * Method to show alert dialog + * */ + private void showAlert(String message) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setMessage(message).setTitle("Response from Servers") + .setCancelable(false) + .setPositiveButton("OK", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + // do nothing + } + }); + AlertDialog alert = builder.create(); + alert.show(); + } + +} diff --git a/Uploading/app/src/main/res/layout/activity_main.xml b/Uploading/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..7066dac --- /dev/null +++ b/Uploading/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,51 @@ + + + + + + + +