├── .gitignore
├── .idea
├── .name
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── .travis.yml
├── LICENSE.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── androidfung
│ │ └── openweathermap
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── ic_launcher-web.png
│ ├── java
│ │ └── com
│ │ │ └── androidfung
│ │ │ └── openweathermap
│ │ │ ├── MainActivity.java
│ │ │ └── MainActivityFragment.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── content_main.xml
│ │ └── fragment_main.xml
│ │ ├── menu
│ │ └── menu_main.xml
│ │ ├── mipmap-hdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-mdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxhdpi
│ │ └── ic_launcher.png
│ │ ├── mipmap-xxxhdpi
│ │ └── ic_launcher.png
│ │ ├── values-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── androidfung
│ └── openweathermap
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── androidfung
│ │ └── weather
│ │ └── ApplicationTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── androidfung
│ │ │ └── weather
│ │ │ ├── OpenWeatherMapApiHelper.java
│ │ │ ├── model
│ │ │ ├── WeatherRecord.java
│ │ │ └── WeatherResponseModel.java
│ │ │ └── network
│ │ │ ├── CustomGsonObjectRequest.java
│ │ │ ├── GsonRequest.java
│ │ │ └── MultipartRequest.java
│ └── res
│ │ └── values
│ │ ├── secrets.xml
│ │ └── strings.xml
│ └── test
│ └── java
│ └── com
│ └── androidfung
│ └── weather
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | OpenWeatherMap
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
25 |
26 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 | Android
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 | 1.8
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 | jdk: oraclejdk8
3 | sudo: false
4 | android:
5 | components:
6 | # Uncomment the lines below if you want to
7 | # use the latest revision of Android SDK Tools
8 | - platform-tools
9 | - tools
10 |
11 | # The BuildTools version used by your project
12 | - build-tools-25.0.2
13 |
14 | # The SDK version used to compile your project
15 | - android-25
16 |
17 | # Additional components
18 | #- extra-google-google_play_services
19 | - extra-google-m2repository
20 | - extra-android-m2repository
21 | - extra-android-support
22 |
23 | # Specify at least one system image,
24 | # if you need to run emulator(s) during your tests
25 | - sys-img-armeabi-v7a-android-22
26 | # - sys-img-armeabi-v7a-android-17
27 |
28 | licenses:
29 | - 'android-sdk-preview-license-.+'
30 | - 'android-sdk-license-.+'
31 | - 'google-gdk-license-.+'
32 |
33 | before_script:
34 | - echo no | android create avd --force -n test -t android-21 --abi armeabi-v7a
35 | - emulator -avd test -no-skin -no-audio -no-window &
36 | - android-wait-for-emulator
37 | - adb shell input keyevent 82 &
38 |
39 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Fung LAM
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### Welcome to OpenWeatherMap-Android
2 | This is a wrapper of [OpenWeatherMap](http://openweathermap.org) for Android platform using Volley.
3 |
4 | ### Sample Application
5 | Sample Application is included in [app](https://github.com/seventhmoon/OpenWeatherMap-Android/tree/master/app)
6 |
7 | ### How to use
8 | OpenWeatherMapApiHelper helper = new OpenWeatherMapApiHelper(getContext());
9 | helper.getWeather(22.25, 114.1667, new Response.Listener() {
10 | @Override
11 | public void onResponse(WeatherResponseModel response) {
12 | WeatherRecord record = response.getWeatherRecord();
13 | textViewMessage.setText("Temperature: " + record.getTemperature() + "\nHumidity: " + record.getHumidity());
14 | }
15 | }, new Response.ErrorListener() {
16 | @Override
17 | public void onErrorResponse(VolleyError error) {
18 | textViewMessage.setText(error.toString());
19 | }
20 | });
21 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion "27.0.3"
6 |
7 | defaultConfig {
8 | applicationId "com.androidfung.openweathermap"
9 | minSdkVersion 21
10 | targetSdkVersion 27
11 | versionCode 1
12 | versionName "1.0"
13 | dataBinding {
14 | enabled = false
15 | }
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | compileOptions {
24 | sourceCompatibility JavaVersion.VERSION_1_8
25 | targetCompatibility JavaVersion.VERSION_1_8
26 | }
27 | packagingOptions {
28 | exclude 'META-INF/LICENSE'
29 | exclude 'META-INF/LICENSE-FIREBASE.txt'
30 | exclude 'META-INF/NOTICE'
31 | }
32 | }
33 |
34 | dependencies {
35 | compile fileTree(include: ['*.jar'], dir: 'libs')
36 | testCompile 'junit:junit:4.12'
37 | implementation 'com.android.support:appcompat-v7:27.0.2'
38 | implementation 'com.android.support:design:27.0.2'
39 | implementation 'com.android.volley:volley:1.1.0'
40 | compile project(':library')
41 | }
42 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\fung\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/androidfung/openweathermap/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.openweathermap;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
14 |
15 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seventhmoon/OpenWeatherMap-Android/c82a1fdfd233d93f12a4dd046d0c25d76e704e65/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/main/java/com/androidfung/openweathermap/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.openweathermap;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.Toolbar;
6 | import android.view.Menu;
7 | import android.view.MenuItem;
8 |
9 | public class MainActivity extends AppCompatActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | super.onCreate(savedInstanceState);
14 | setContentView(R.layout.activity_main);
15 | Toolbar toolbar = findViewById(R.id.toolbar);
16 | setSupportActionBar(toolbar);
17 |
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/app/src/main/java/com/androidfung/openweathermap/MainActivityFragment.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.openweathermap;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 | import android.support.v4.app.Fragment;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.TextView;
10 |
11 | import com.android.volley.Response;
12 | import com.android.volley.VolleyError;
13 | import com.androidfung.weather.OpenWeatherMapApiHelper;
14 | import com.androidfung.weather.model.WeatherRecord;
15 | import com.androidfung.weather.model.WeatherResponseModel;
16 |
17 | import org.w3c.dom.Text;
18 |
19 | /**
20 | * A placeholder fragment containing a simple view.
21 | */
22 | public class MainActivityFragment extends Fragment {
23 |
24 | private TextView mTextViewMessage;
25 |
26 | public MainActivityFragment() {
27 | }
28 |
29 | @Override
30 | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
31 | Bundle savedInstanceState) {
32 |
33 | View rootView = inflater.inflate(R.layout.fragment_main, container, false);
34 | mTextViewMessage = rootView.findViewById(R.id.textview_message);
35 |
36 | OpenWeatherMapApiHelper helper = new OpenWeatherMapApiHelper(getActivity(), "API_KEY_HERE");
37 | helper.getWeather(22.25, 114.1667,
38 | this::showInformation,
39 | this::showError
40 | );
41 |
42 | return rootView;
43 | }
44 |
45 | private void showInformation(WeatherResponseModel response){
46 | mTextViewMessage.setText(getString(R.string.Result, response.getWeatherRecord().getTemperature(),response.getWeatherRecord().getHumidity()));
47 | }
48 |
49 | private void showError(VolleyError error){
50 | mTextViewMessage.setText(error.toString());
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seventhmoon/OpenWeatherMap-Android/c82a1fdfd233d93f12a4dd046d0c25d76e704e65/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seventhmoon/OpenWeatherMap-Android/c82a1fdfd233d93f12a4dd046d0c25d76e704e65/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seventhmoon/OpenWeatherMap-Android/c82a1fdfd233d93f12a4dd046d0c25d76e704e65/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seventhmoon/OpenWeatherMap-Android/c82a1fdfd233d93f12a4dd046d0c25d76e704e65/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seventhmoon/OpenWeatherMap-Android/c82a1fdfd233d93f12a4dd046d0c25d76e704e65/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | OpenWeatherMap
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/com/androidfung/openweathermap/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.openweathermap;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | maven {
7 | url 'https://maven.google.com/'
8 | name 'Google'
9 | }
10 | }
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:3.0.1'
13 |
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | jcenter()
22 | google()
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 | org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m
15 |
16 | # When configured, Gradle will run in incubating parallel mode.
17 | # This option should only be used with decoupled projects. More details, visit
18 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
19 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/seventhmoon/OpenWeatherMap-Android/c82a1fdfd233d93f12a4dd046d0c25d76e704e65/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Feb 13 09:38:05 CST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 27
5 | buildToolsVersion "27.0.3"
6 |
7 | defaultConfig {
8 | minSdkVersion 19
9 | targetSdkVersion 27
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | compileOptions {
20 | sourceCompatibility JavaVersion.VERSION_1_8
21 | targetCompatibility JavaVersion.VERSION_1_8
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(include: ['*.jar'], dir: 'libs')
27 | testCompile 'junit:junit:4.12'
28 | implementation 'com.android.volley:volley:1.1.0'
29 | implementation 'com.google.code.gson:gson:2.8.1'
30 | implementation 'com.android.support:support-annotations:27.0.2'
31 | }
32 |
--------------------------------------------------------------------------------
/library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\fung\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/library/src/androidTest/java/com/androidfung/weather/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.weather;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/library/src/main/java/com/androidfung/weather/OpenWeatherMapApiHelper.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.weather;
2 |
3 | import android.content.Context;
4 | import android.support.annotation.NonNull;
5 |
6 | import com.android.volley.Request;
7 | import com.android.volley.RequestQueue;
8 | import com.android.volley.Response;
9 | import com.android.volley.toolbox.Volley;
10 | import com.androidfung.weather.model.WeatherResponseModel;
11 | import com.androidfung.weather.network.CustomGsonObjectRequest;
12 | import com.example.android.sunshine.app.R;
13 | import com.google.gson.reflect.TypeToken;
14 |
15 | import java.io.UnsupportedEncodingException;
16 | import java.lang.reflect.Type;
17 | import java.net.URLEncoder;
18 | import java.util.Map;
19 | import java.util.TreeMap;
20 |
21 | /**
22 | * Created by fung.lam on 09/09/2015.
23 | * API Helper for Open Weather Map API
24 | */
25 | public class OpenWeatherMapApiHelper {
26 |
27 | private static final String HOST = "http://api.openweathermap.org";
28 | private static final String GET_WEATHER_ENDPOINT = "/data/2.5/weather";
29 |
30 | private RequestQueue mRequestQueue;
31 | private String mAppId;
32 |
33 |
34 | // public OpenWeatherMapApiHelper(@NonNull RequestQueue requestQueue) {
35 | // mRequestQueue = requestQueue;
36 | // }
37 |
38 | public OpenWeatherMapApiHelper(@NonNull Context context){
39 | mRequestQueue = Volley.newRequestQueue(context);
40 | mAppId = context.getResources().getString(R.string.api_key);
41 | }
42 |
43 | public OpenWeatherMapApiHelper(@NonNull Context context, @NonNull String appId){
44 | mRequestQueue = Volley.newRequestQueue(context);
45 | mAppId = appId;
46 | }
47 |
48 | public OpenWeatherMapApiHelper(@NonNull RequestQueue requestQueue, @NonNull String appId) {
49 | mRequestQueue = requestQueue;
50 | mAppId = appId;
51 | }
52 |
53 | //convert the map of params to "key1=value1&key2=value2" style
54 | private static String toUrlParams(@NonNull Map params) {
55 | StringBuilder sb = new StringBuilder();
56 | for (String key : params.keySet()) {
57 | try {
58 | sb.append("&").append(key).append("=").append(URLEncoder.encode(params.get(key).toString(), "utf-8"));
59 |
60 | } catch (UnsupportedEncodingException e) {
61 | e.printStackTrace();
62 | }
63 | }
64 | return sb.toString().substring(1); //removing the heading '&'
65 | }
66 |
67 | /**
68 | * Send the Get Weather API request
69 | * @param listener what to do if success
70 | * @param errorListener what to do if failed
71 | * @return volley request
72 | */
73 | public Request getWeather(@NonNull Response.Listener listener, @NonNull Response.ErrorListener errorListener) {
74 | TreeMap params = new TreeMap<>();
75 | params.put("units", "metric");
76 | params.put("appid", mAppId);
77 |
78 | String url = HOST + GET_WEATHER_ENDPOINT + "?" + toUrlParams(params);
79 |
80 | Type type = new TypeToken() {
81 | }.getType();
82 |
83 | CustomGsonObjectRequest gsonReq = new CustomGsonObjectRequest<>(Request.Method.GET,
84 | url, type, null, listener, errorListener);
85 |
86 |
87 | // Adding request to request queue
88 | return mRequestQueue.add(gsonReq);
89 |
90 | }
91 |
92 | /**
93 | * Send the Get Weather API request
94 | * @param latitude latitude of location
95 | * @param longitude longitude of location
96 | * @param listener what to do if success
97 | * @param errorListener what to do if failed
98 | * @return volley request
99 | */
100 | public Request getWeather(double latitude, double longitude, @NonNull Response.Listener listener, @NonNull Response.ErrorListener errorListener) {
101 | TreeMap params = new TreeMap<>();
102 | params.put("units", "metric");
103 | params.put("lat", latitude);
104 | params.put("lon", longitude);
105 | params.put("appid", mAppId);
106 |
107 | String url = HOST + GET_WEATHER_ENDPOINT + "?" + toUrlParams(params);
108 |
109 | Type type = new TypeToken() {
110 | }.getType();
111 |
112 | CustomGsonObjectRequest gsonReq = new CustomGsonObjectRequest<>(Request.Method.GET,
113 | url, type, null, listener, errorListener);
114 |
115 |
116 | // Adding request to request queue
117 | return mRequestQueue.add(gsonReq);
118 |
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/library/src/main/java/com/androidfung/weather/model/WeatherRecord.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.weather.model;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | /**
6 | * Created by fung.lam on 02/09/2015.
7 | * for openweathermap webservice call
8 | */
9 | public class WeatherRecord {
10 |
11 | @SerializedName("temp")
12 | float temperature;
13 | @SerializedName("pressure")
14 | int pressure;
15 | @SerializedName("humidity")
16 | float humidity;
17 | @SerializedName("temp_min")
18 | float minimumTemperature;
19 | @SerializedName("temp_max")
20 | float maximunTemperature;
21 |
22 | public float getTemperature() {
23 | return temperature;
24 | }
25 |
26 | public int getPressure() {
27 | return pressure;
28 | }
29 |
30 | public float getHumidity() {
31 | return humidity;
32 | }
33 |
34 | public float getMinimumTemperature() {
35 | return minimumTemperature;
36 | }
37 |
38 | public float getMaximunTemperature() {
39 | return maximunTemperature;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/library/src/main/java/com/androidfung/weather/model/WeatherResponseModel.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.weather.model;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | /**
6 | * Created by fung.lam on 02/09/2015.
7 | * for openweathermap webservice call
8 | */
9 | public class WeatherResponseModel {
10 |
11 | // @SerializedName("coord")
12 | // Coordaniate coordaniate;
13 | //
14 | // @SerializedName("weather")
15 | // Weather weather;
16 |
17 | // @SerializedName("base")
18 | // String base;
19 |
20 | @SerializedName("main")
21 | WeatherRecord weatherRecord;
22 |
23 | public WeatherRecord getWeatherRecord() {
24 | return weatherRecord;
25 | }
26 | // @SerializedName("visibility")
27 | // long visibility;
28 |
29 |
30 |
31 |
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/library/src/main/java/com/androidfung/weather/network/CustomGsonObjectRequest.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.weather.network;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.annotation.Nullable;
5 | import android.util.Log;
6 |
7 | import com.android.volley.NetworkResponse;
8 | import com.android.volley.ParseError;
9 | import com.android.volley.Response;
10 | import com.android.volley.toolbox.HttpHeaderParser;
11 | import com.google.gson.Gson;
12 | import com.google.gson.JsonSyntaxException;
13 |
14 | import java.io.UnsupportedEncodingException;
15 | import java.lang.reflect.Type;
16 | import java.util.Map;
17 |
18 | /**
19 | * Created by fung.lam on 31/03/2015.
20 | * for parsing the json return by gson
21 | */
22 | public class CustomGsonObjectRequest extends GsonRequest {
23 |
24 | // private final Gson gson = new GsonBuilder()
25 | // .setDateFormat("yyyy/MM/dd HH:mm:ss aa").create();
26 | private final Gson gson = super.getGson();
27 | // private final Class clazz;
28 | private final Type mTypeToken;
29 |
30 | /**
31 | * Make a request and return a parsed object from JSON.
32 | *
33 | * @param method POST or GET
34 | * @param url URL of the request to make
35 | * @param typeToken Relevant class object, for Gson's reflection
36 | * @param formData the form data to be sent
37 | * @param listener what to do when success
38 | * @param errorListener what to do when error
39 | */
40 | public CustomGsonObjectRequest(int method, @NonNull String url, @NonNull Type typeToken, @Nullable Map formData, @NonNull Response.Listener listener, @NonNull Response.ErrorListener errorListener) {
41 | super(method, url, formData, listener, errorListener);
42 | mTypeToken = typeToken;
43 |
44 | }
45 |
46 | @Override
47 | protected Response parseNetworkResponse(NetworkResponse response) {
48 | try {
49 | String json = new String(
50 | response.data,
51 | HttpHeaderParser.parseCharset(response.headers));
52 |
53 | Log.d(TAG, json);
54 |
55 | // String formattedJson = StringEscapeUtils.unescapeJson(json);
56 | // if (formattedJson.startsWith("\"")) {
57 | // formattedJson = formattedJson.substring(1, formattedJson.length() - 1);
58 | // if (formattedJson.startsWith("[")) {
59 | // formattedJson = formattedJson.substring(1, formattedJson.length() - 1);
60 | // }
61 | // }
62 | //
63 | // Log.d("Gson", formattedJson);
64 |
65 | return Response.success((T) gson.fromJson(json, mTypeToken),
66 | HttpHeaderParser.parseCacheHeaders(response));
67 | } catch (UnsupportedEncodingException e) {
68 | return Response.error(new ParseError(e));
69 | } catch (JsonSyntaxException e) {
70 | return Response.error(new ParseError(e));
71 | }
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/library/src/main/java/com/androidfung/weather/network/GsonRequest.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.weather.network;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.annotation.Nullable;
5 | import android.util.Log;
6 |
7 | import com.android.volley.NetworkResponse;
8 | import com.android.volley.Response;
9 | import com.android.volley.toolbox.JsonRequest;
10 | import com.google.gson.Gson;
11 | import com.google.gson.GsonBuilder;
12 | import com.google.gson.JsonDeserializationContext;
13 | import com.google.gson.JsonDeserializer;
14 | import com.google.gson.JsonElement;
15 | import com.google.gson.JsonParseException;
16 | import com.google.gson.JsonPrimitive;
17 | import com.google.gson.JsonSerializationContext;
18 | import com.google.gson.JsonSerializer;
19 |
20 | import java.lang.reflect.Type;
21 | import java.text.ParseException;
22 | import java.text.SimpleDateFormat;
23 | import java.util.Date;
24 | import java.util.Locale;
25 | import java.util.Map;
26 |
27 |
28 | /**
29 | * @param Gson data model
30 | * @author fung.lam
31 | */
32 | public abstract class GsonRequest extends JsonRequest {
33 |
34 | protected static final String PROTOCOL_CHARSET = "utf-8";
35 |
36 | /**
37 | * Content type for request.
38 | */
39 | // private static final String PROTOCOL_CONTENT_TYPE =
40 | // String.format("text/plain; charset=%s", PROTOCOL_CHARSET);
41 |
42 | private static final String PROTOCOL_CONTENT_TYPE =
43 | String.format("application/x-www-form-urlencoded");
44 |
45 |
46 | public static final String TAG = GsonRequest.class.getSimpleName();
47 |
48 | protected Gson getGson() {
49 | return gson;
50 | }
51 |
52 | private final Gson gson = new GsonBuilder()
53 | // .setDateFormat("M/d/yyyy h:mm:ss aa")
54 | .registerTypeAdapter(Date.class, new DateSerializer())
55 | // .registerTypeAdapter(Boolean.class, new BooleanSerializer())
56 | // .registerTypeAdapter(boolean.class, new BooleanSerializer())
57 | .create();
58 | // private final Class clazz;
59 | // private final Response.Listener mListener;
60 | // private final Map mFormData;
61 |
62 |
63 | /**
64 | * Make a request and return a parsed object
65 | *
66 | * @param url URL of the request to make
67 | * @param formData map contains the parameters
68 | */
69 | public GsonRequest(int method, @NonNull String url, @Nullable Map formData,
70 | @NonNull Response.Listener listener, @NonNull Response.ErrorListener errorListener) {
71 | super(method, url, getFormDataString(formData), listener, errorListener);
72 |
73 | // this.mListener = listener;
74 | // this.mFormData = formData;
75 |
76 |
77 | // Log.d(TAG, "formData: " + formData.toString());
78 | }
79 |
80 | /**
81 | * Make a request and return a parsed object
82 | *
83 | * @param url URL of the request to make
84 | * @param formData map contains the parameters
85 | */
86 | public GsonRequest(int method, @NonNull String url, @Nullable String formData,
87 | @NonNull Response.Listener listener, @NonNull Response.ErrorListener errorListener) {
88 |
89 |
90 | super(method, url, formData, listener, errorListener);
91 |
92 | // this.mListener = listener;
93 | // this.mFormData = formData;
94 |
95 |
96 | // Log.d(TAG, "formData: " + formData.toString());
97 | }
98 |
99 |
100 | // @Override
101 | // protected void deliverResponse(T response) {
102 | // mListener.onResponse(response);
103 | // }
104 |
105 | @Override
106 | protected abstract Response parseNetworkResponse(NetworkResponse response);
107 |
108 |
109 | @Override
110 | public String getBodyContentType() {
111 | return PROTOCOL_CONTENT_TYPE;
112 | }
113 |
114 | private static String getFormDataString(Map formData){
115 |
116 | StringBuilder params = new StringBuilder();
117 | if (formData != null) {
118 | for (String key : formData.keySet()) {
119 | params.append("&").append(key).append("=").append(formData.get(key));
120 | }
121 |
122 | return params.toString().substring(1);
123 | }else {
124 | return null;
125 | }
126 |
127 |
128 |
129 | // try {
130 | // String encodedBody = URLEncoder.encode(body, "utf-8");
131 | //
132 | // Log.d(TAG, "getBody(): " + encodedBody);
133 | //
134 | //
135 | // return encodedBody;
136 | // } catch (UnsupportedEncodingException uee) {
137 | // Log.wtf("Volley", String.format("Unsupported Encoding while trying to get the bytes of %s using %s",
138 | // body, PROTOCOL_CHARSET));
139 | // return null;
140 | // }
141 | }
142 |
143 |
144 |
145 | public class BooleanSerializer implements JsonSerializer, JsonDeserializer {
146 |
147 | @Override
148 | public JsonElement serialize(Boolean arg0, Type arg1, JsonSerializationContext arg2) {
149 | return new JsonPrimitive(arg0 ? 1 : 0);
150 | }
151 |
152 | @Override
153 | public Boolean deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
154 | return arg0.getAsInt() == 1 || arg0.getAsString().equals("1");
155 | }
156 | }
157 |
158 | public class DateSerializer implements JsonDeserializer {
159 |
160 | SimpleDateFormat df = new SimpleDateFormat("M/d/yyyy h:mm:ss a", Locale.ENGLISH);
161 |
162 | @Override
163 | public Date deserialize(JsonElement arg0, Type arg1, JsonDeserializationContext arg2) throws JsonParseException {
164 |
165 | try {
166 | return df.parse(arg0.getAsString());
167 | } catch (ParseException e) {
168 | Log.d("Error", e.toString());
169 | return null;
170 | }
171 |
172 | }
173 | }
174 | }
--------------------------------------------------------------------------------
/library/src/main/java/com/androidfung/weather/network/MultipartRequest.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.weather.network;
2 |
3 | import com.android.volley.NetworkResponse;
4 | import com.android.volley.Request;
5 | import com.android.volley.Response;
6 |
7 | /*
8 | import org.apache.http.HttpEntity;
9 | import org.apache.http.entity.mime.HttpMultipartMode;
10 | import org.apache.http.entity.mime.MultipartEntityBuilder;
11 | import org.apache.http.entity.mime.content.FileBody;
12 | */
13 |
14 | /**
15 | * @author http://qiita.com/tomoima525/items/8e77c4cfe51339974545
16 | */
17 | public class MultipartRequest extends Request {
18 | public MultipartRequest(String url, Response.ErrorListener listener) {
19 | super(url, listener);
20 | }
21 |
22 | @Override
23 | protected Response parseNetworkResponse(NetworkResponse response) {
24 | return null;
25 | }
26 |
27 | @Override
28 | protected void deliverResponse(String response) {
29 |
30 | }
31 | /*
32 | MultipartEntityBuilder entity = MultipartEntityBuilder.create();
33 | HttpEntity httpEntitiy;
34 | private final Response.Listener mListener;
35 | private final Map mStringParts;
36 | private final Map mFileParts;
37 |
38 | public MultipartRequest(String url, Response.Listener listener,
39 | Response.ErrorListener errorListener,
40 | Map stringParts, Map fileParts) {
41 | super(Method.POST, url, errorListener);
42 |
43 | mListener = listener;
44 | mStringParts = stringParts;
45 | mFileParts = fileParts;
46 | buildMultipartEntity();
47 | }
48 |
49 | private void buildMultipartEntity() {
50 | entity.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
51 | //送信するリクエストを設定する
52 | //StringData
53 | for (Map.Entry entry : mStringParts.entrySet()) {
54 | entity.addTextBody(entry.getKey(), entry.getValue());
55 |
56 | }
57 | //File Data
58 | for (Map.Entry entry : mFileParts.entrySet()) {
59 | entity.addPart(entry.getKey(), new FileBody(entry.getValue()));
60 | }
61 | httpEntitiy = entity.build();
62 | }
63 |
64 | @Override
65 | public String getBodyContentType() {
66 | return httpEntitiy.getContentType().getValue();
67 | }
68 |
69 | public HttpEntity getEntity() {
70 | return httpEntitiy;
71 | }
72 |
73 |
74 | @Override
75 | protected Response parseNetworkResponse(NetworkResponse response) {
76 | return Response.success("Uploaded", getCacheEntry());
77 |
78 | }
79 |
80 | //リスナーにレスポンスを返す
81 | @Override
82 | protected void deliverResponse(String response) {
83 | mListener.onResponse(response);
84 | }
85 | */
86 | }
--------------------------------------------------------------------------------
/library/src/main/res/values/secrets.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | YOUR_API_KEY_HERE
4 |
5 |
--------------------------------------------------------------------------------
/library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | WeatherApi
3 |
4 |
5 |
--------------------------------------------------------------------------------
/library/src/test/java/com/androidfung/weather/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.androidfung.weather;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app',':library'
2 |
--------------------------------------------------------------------------------