├── Android Code
├── .gitignore
├── app
│ ├── .gitignore
│ ├── build.gradle
│ ├── proguard-rules.pro
│ └── src
│ │ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── hellohasan
│ │ │ └── networkcallwithretrofit
│ │ │ └── ExampleInstrumentedTest.java
│ │ ├── main
│ │ ├── AndroidManifest.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── hellohasan
│ │ │ │ └── networkcallwithretrofit
│ │ │ │ ├── Activity
│ │ │ │ └── MainActivity.java
│ │ │ │ ├── Interface
│ │ │ │ └── ApiInterface.java
│ │ │ │ ├── Model
│ │ │ │ ├── ServerResponse.java
│ │ │ │ └── User.java
│ │ │ │ └── Retrofit
│ │ │ │ └── RetrofitApiClient.java
│ │ └── res
│ │ │ ├── layout
│ │ │ └── activity_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-w820dp
│ │ │ └── dimens.xml
│ │ │ └── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ │ └── test
│ │ └── java
│ │ └── com
│ │ └── hellohasan
│ │ └── networkcallwithretrofit
│ │ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
├── PHP Code
└── server_side_code.php
├── README.md
└── Retrofit-Simple-Get-Request
├── .gitignore
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── hellohasan
│ │ └── retrofitsimplegetrequest
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── hellohasan
│ │ │ └── retrofitsimplegetrequest
│ │ │ ├── MainActivity.java
│ │ │ ├── ServerResponse.java
│ │ │ └── network
│ │ │ ├── ApiInterface.java
│ │ │ └── RetrofitApiClient.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── hellohasan
│ └── retrofitsimplegetrequest
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/Android Code/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/Android Code/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Android Code/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.hellohasan.networkcallwithretrofit"
7 | minSdkVersion 14
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
24 | exclude group: 'com.android.support', module: 'support-annotations'
25 | })
26 | implementation 'androidx.appcompat:appcompat:1.1.0'
27 | testImplementation 'junit:junit:4.12'
28 |
29 | // for Retrofit and GSON library
30 | implementation 'com.squareup.retrofit2:retrofit:2.5.0'
31 | implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
32 | }
33 |
--------------------------------------------------------------------------------
/Android Code/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 /home/hasan/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 |
--------------------------------------------------------------------------------
/Android Code/app/src/androidTest/java/com/hellohasan/networkcallwithretrofit/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.networkcallwithretrofit;
2 |
3 | import android.content.Context;
4 | import androidx.test.platform.app.InstrumentationRegistry;
5 | import androidx.test.ext.junit.runners.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.hellohasan.loginandregistrationwithretrofit", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Android Code/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Android Code/app/src/main/java/com/hellohasan/networkcallwithretrofit/Activity/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.networkcallwithretrofit.Activity;
2 |
3 | import androidx.annotation.NonNull;
4 | import androidx.appcompat.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.util.Log;
7 | import android.view.View;
8 | import android.widget.EditText;
9 | import android.widget.TextView;
10 | import android.widget.Toast;
11 |
12 | import com.hellohasan.networkcallwithretrofit.Interface.ApiInterface;
13 | import com.hellohasan.networkcallwithretrofit.Model.User;
14 | import com.hellohasan.networkcallwithretrofit.Model.ServerResponse;
15 | import com.hellohasan.networkcallwithretrofit.R;
16 | import com.hellohasan.networkcallwithretrofit.Retrofit.RetrofitApiClient;
17 |
18 |
19 | import retrofit2.Call;
20 | import retrofit2.Callback;
21 | import retrofit2.Response;
22 |
23 | public class MainActivity extends AppCompatActivity {
24 |
25 | private static final String TAG = MainActivity.class.getSimpleName();
26 | private ApiInterface apiInterface;
27 | private EditText userIdEditText;
28 | private EditText passwordEditText;
29 | private EditText jokeUserIdEditText;
30 | private TextView jokeTextView;
31 |
32 | @Override
33 | protected void onCreate(Bundle savedInstanceState) {
34 | super.onCreate(savedInstanceState);
35 | setContentView(R.layout.activity_main);
36 |
37 | //Create an instance of Interface
38 | apiInterface = RetrofitApiClient.getClient().create(ApiInterface.class);
39 |
40 | //Initialize the view like EditText, TextView
41 | viewInitialization();
42 | }
43 |
44 | // Login button event
45 | public void buttonClickEvent(View view){
46 |
47 | if(view.getId()==R.id.login_button){
48 | String userId;
49 | String password;
50 | User user = new User();
51 |
52 | userId = userIdEditText.getText().toString();
53 | password = passwordEditText.getText().toString();
54 |
55 | user.setUserId(userId);
56 | user.setPassword(password);
57 |
58 | checkUserValidity(user);
59 | } else {
60 | String userId;
61 |
62 | userId = jokeUserIdEditText.getText().toString();
63 |
64 | getJokeFromServer(userId);
65 | }
66 |
67 | }
68 |
69 | // GET method to get a Joke from remote server
70 | private void getJokeFromServer(String userId) {
71 |
72 | Call call = apiInterface.getJoke(userId);
73 |
74 | call.enqueue(new Callback() {
75 | @Override
76 | public void onResponse(@NonNull Call call, @NonNull Response response) {
77 | ServerResponse validity = response.body();
78 | if (validity != null)
79 | jokeTextView.setText(validity.getMessage());
80 | else
81 | jokeTextView.setText("Server response is null");
82 | }
83 |
84 | @Override
85 | public void onFailure(@NonNull Call call, @NonNull Throwable t) {
86 | Log.e(TAG, t.toString());
87 | }
88 | });
89 | }
90 |
91 | // POST method to determine user validity
92 | private void checkUserValidity(User userCredential){
93 |
94 | Call call = apiInterface.getUserValidity(userCredential);
95 |
96 | call.enqueue(new Callback() {
97 |
98 | @Override
99 | public void onResponse(@NonNull Call call, @NonNull Response response) {
100 |
101 | ServerResponse validity = response.body();
102 |
103 | if (validity != null)
104 | Toast.makeText(getApplicationContext(), validity.getMessage(), Toast.LENGTH_LONG).show();
105 | else
106 | Toast.makeText(getApplicationContext(), "Server response is null", Toast.LENGTH_LONG).show();
107 | }
108 |
109 | @Override
110 | public void onFailure(@NonNull Call call, @NonNull Throwable t) {
111 | Log.e(TAG, t.toString());
112 | }
113 | });
114 | }
115 |
116 | private void viewInitialization() {
117 | userIdEditText = findViewById(R.id.login_id);
118 | passwordEditText = findViewById(R.id.login_password);
119 | jokeUserIdEditText = findViewById(R.id.user_id_for_joke);
120 | jokeTextView = findViewById(R.id.jokeTextView);
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/Android Code/app/src/main/java/com/hellohasan/networkcallwithretrofit/Interface/ApiInterface.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.networkcallwithretrofit.Interface;
2 |
3 | import com.hellohasan.networkcallwithretrofit.Model.User;
4 | import com.hellohasan.networkcallwithretrofit.Model.ServerResponse;
5 |
6 | import retrofit2.Call;
7 | import retrofit2.http.Body;
8 | import retrofit2.http.GET;
9 | import retrofit2.http.POST;
10 | import retrofit2.http.Query;
11 |
12 | public interface ApiInterface {
13 |
14 | @POST("/retrofit_get_post/server_side_code.php")
15 | Call getUserValidity(@Body User userLoginCredential);
16 |
17 | @GET("/retrofit_get_post/server_side_code.php")
18 | Call getJoke(@Query("user_id") String userId);
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/Android Code/app/src/main/java/com/hellohasan/networkcallwithretrofit/Model/ServerResponse.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.networkcallwithretrofit.Model;
2 |
3 |
4 | import com.google.gson.annotations.SerializedName;
5 |
6 | public class ServerResponse {
7 |
8 | @SerializedName("status")
9 | boolean statusString;
10 | @SerializedName("message")
11 | String messageString;
12 |
13 | public boolean isSuccess(){
14 | return statusString;
15 | }
16 |
17 | public String getMessage() {
18 | return messageString;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/Android Code/app/src/main/java/com/hellohasan/networkcallwithretrofit/Model/User.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.networkcallwithretrofit.Model;
2 |
3 | import com.google.gson.annotations.SerializedName;
4 |
5 | public class User {
6 |
7 | @SerializedName("user_id")
8 | private String userId;
9 | @SerializedName("password")
10 | private String password;
11 |
12 | public User(){}
13 |
14 | public void setUserId(String userId) {
15 | this.userId = userId;
16 | }
17 |
18 | public void setPassword(String password) {
19 | this.password = password;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/Android Code/app/src/main/java/com/hellohasan/networkcallwithretrofit/Retrofit/RetrofitApiClient.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.networkcallwithretrofit.Retrofit;
2 |
3 | import com.google.gson.Gson;
4 | import com.google.gson.GsonBuilder;
5 | import retrofit2.Retrofit;
6 | import retrofit2.converter.gson.GsonConverterFactory;
7 |
8 | public class RetrofitApiClient {
9 |
10 | private static final String BASE_URL = "http://192.168.0.104"; //address of your remote server. Here I used localhost
11 | private static Retrofit retrofit = null;
12 |
13 | private static Gson gson = new GsonBuilder()
14 | .setLenient()
15 | .create();
16 |
17 | private RetrofitApiClient() {} // So that nobody can create an object with constructor
18 |
19 | public static synchronized Retrofit getClient() {
20 | if (retrofit==null) {
21 | retrofit = new Retrofit.Builder()
22 | .baseUrl(BASE_URL)
23 | .addConverterFactory(GsonConverterFactory.create(gson))
24 | .build();
25 | }
26 | return retrofit;
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/Android Code/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
28 |
29 |
35 |
36 |
42 |
43 |
49 |
50 |
56 |
57 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/Android Code/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Android Code/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android Code/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Android Code/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android Code/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Android Code/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android Code/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Android Code/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android Code/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Android Code/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Android Code/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/Android Code/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/Android Code/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/Android Code/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Network Call with Retrofit
3 | User ID: hasan, Password: 123
4 | Give User ID for a joke
5 | Get a Joke
6 | User ID
7 | Password
8 | Log In
9 |
10 |
--------------------------------------------------------------------------------
/Android Code/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Android Code/app/src/test/java/com/hellohasan/networkcallwithretrofit/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.networkcallwithretrofit;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/Android Code/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 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.5.1'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | google()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/Android Code/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 | android.enableJetifier=true
13 | android.useAndroidX=true
14 | org.gradle.jvmargs=-Xmx1536m
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
20 |
--------------------------------------------------------------------------------
/Android Code/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Android Code/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Android Code/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Oct 31 12:01:59 BDT 2019
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-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/Android Code/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 |
--------------------------------------------------------------------------------
/Android Code/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 |
--------------------------------------------------------------------------------
/Android Code/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/PHP Code/server_side_code.php:
--------------------------------------------------------------------------------
1 | false, 'message' => 'Invalid Values');
12 | }
13 | else
14 | {
15 | if($json_data['user_id']=='hasan' && $json_data['password']==123)
16 | $response = array('status' => true, 'message' => 'Wow! You are a valid user!');
17 | else
18 | $response = array('status' => false, 'message' => 'User ID or password is not valid');
19 | }
20 |
21 | echo json_encode($response);
22 | }
23 | else if($_SERVER['REQUEST_METHOD'] === 'GET')
24 | {
25 | if (empty($_GET['user_id']))
26 | {
27 | $response = array('status' => false, 'message' => 'Invalid Values');
28 | }
29 | else
30 | {
31 | if($_GET['user_id']=='hasan')
32 | $response = array('status' => true, 'message' => 'Just read that 4,153,237 people got married last year, not to cause any trouble but shouldn\'t that be an even number?');
33 | else
34 | $response = array('status' => false, 'message' => 'User ID is not valid');
35 | }
36 |
37 | echo json_encode($response);
38 | }
39 |
40 | ?>
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Network call (GET and POST method) with Retrofit Library
2 |
3 | Have any suggestion? Any advice for good practice? Please send me a pull request.
4 |
5 | ### Quick Links of this Repository:
6 | - [Retrofit Simple GET Request Android Project](https://github.com/hasancse91/retrofit-implementation/tree/master/Retrofit-Simple-Get-Request)
7 | - [All Android Packages](https://github.com/hasancse91/retrofit-implementation/tree/master/Android%20Code/app/src/main/java/com/hellohasan/networkcallwithretrofit)
8 | - [PHP server side code](https://github.com/hasancse91/retrofit-implementation/tree/master/PHP%20Code)
9 |
10 | ## Does this implementation make sense? Go for best practice...
11 | I created [different-network-layer](https://github.com/hasancse91/retrofit-implementation/tree/different-network-layer) branch in this repository for a better implementation. In `master` branch I called `Retrofit` methods from my `Activity` class. But the network related implementation should in a different **network layer** not in **view layer**. You'll find an abstraction layer in this implementation. Click [**here**](https://github.com/hasancse91/retrofit-implementation/tree/different-network-layer) for full source code.
12 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 27
5 | defaultConfig {
6 | applicationId "com.hellohasan.retrofitsimplegetrequest"
7 | minSdkVersion 15
8 | targetSdkVersion 27
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | implementation fileTree(dir: 'libs', include: ['*.jar'])
23 | implementation 'com.android.support:appcompat-v7:27.1.1'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.2'
25 | testImplementation 'junit:junit:4.12'
26 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
27 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
28 |
29 | // for Retrofit and GSON library
30 | implementation 'com.squareup.retrofit2:retrofit:2.4.0'
31 | implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
32 | }
33 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/androidTest/java/com/hellohasan/retrofitsimplegetrequest/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.retrofitsimplegetrequest;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.hellohasan.retrofitsimplegetrequest", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/java/com/hellohasan/retrofitsimplegetrequest/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.retrofitsimplegetrequest;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.ProgressBar;
8 | import android.widget.TextView;
9 |
10 | import com.hellohasan.retrofitsimplegetrequest.network.ApiInterface;
11 | import com.hellohasan.retrofitsimplegetrequest.network.RetrofitApiClient;
12 |
13 | import retrofit2.Call;
14 | import retrofit2.Callback;
15 | import retrofit2.Response;
16 |
17 | public class MainActivity extends AppCompatActivity {
18 |
19 | private TextView ipAddressTextView;
20 | private TextView cityTextView;
21 | private TextView countryTextView;
22 | private ProgressBar progressBar;
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | setContentView(R.layout.activity_main);
28 |
29 | ipAddressTextView = findViewById(R.id.ip_address_textView);
30 | cityTextView = findViewById(R.id.city_textView);
31 | countryTextView = findViewById(R.id.country_textView);
32 | progressBar = findViewById(R.id.progressBar);
33 | }
34 |
35 | public void showMyIp(View view) {
36 |
37 | progressBar.setVisibility(View.VISIBLE); //network call will start. So, show progress bar
38 |
39 | ApiInterface apiInterface = RetrofitApiClient.getClient().create(ApiInterface.class);
40 |
41 | Call call = apiInterface.getMyIp();
42 | call.enqueue(new Callback() {
43 | @Override
44 | public void onResponse(@NonNull Call call, @NonNull Response response) {
45 | progressBar.setVisibility(View.GONE); //network call success. So hide progress bar
46 |
47 | ServerResponse serverResponse = response.body();
48 |
49 | if (response.code()==200 && serverResponse!=null) { //response code 200 means server call successful
50 | //data found. So place the data into TextView
51 | ipAddressTextView.setText(serverResponse.getIp());
52 | cityTextView.setText(serverResponse.getCity());
53 | countryTextView.setText(serverResponse.getCountry());
54 | } else {
55 | //somehow data not found. So error message showing in first TextView
56 | ipAddressTextView.setText(response.message());
57 | cityTextView.setText("");
58 | countryTextView.setText("");
59 | }
60 | }
61 |
62 | @Override
63 | public void onFailure(@NonNull Call call, @NonNull Throwable t) {
64 | progressBar.setVisibility(View.GONE); //network call failed. So hide progress bar
65 |
66 | //network call failed due to disconnect internet connection or server error
67 | ipAddressTextView.setText(t.getMessage());
68 | cityTextView.setText("");
69 | countryTextView.setText("");
70 | }
71 | });
72 | }
73 | }
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/java/com/hellohasan/retrofitsimplegetrequest/ServerResponse.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.retrofitsimplegetrequest;
2 |
3 | import java.io.Serializable;
4 |
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | /**
8 | * For this JSON format: https://ifconfig.co/json
9 | * This POJO class is generated by www.jsonschema2pojo.org
10 | */
11 | public class ServerResponse implements Serializable {
12 |
13 | @SerializedName("ip")
14 | private String ip;
15 | @SerializedName("ip_decimal")
16 | private Integer ipDecimal;
17 | @SerializedName("country")
18 | private String country;
19 | @SerializedName("country_iso")
20 | private String countryIso;
21 | @SerializedName("city")
22 | private String city;
23 |
24 | public String getIp() {
25 | return ip;
26 | }
27 |
28 | public void setIp(String ip) {
29 | this.ip = ip;
30 | }
31 |
32 | public Integer getIpDecimal() {
33 | return ipDecimal;
34 | }
35 |
36 | public void setIpDecimal(Integer ipDecimal) {
37 | this.ipDecimal = ipDecimal;
38 | }
39 |
40 | public String getCountry() {
41 | return country;
42 | }
43 |
44 | public void setCountry(String country) {
45 | this.country = country;
46 | }
47 |
48 | public String getCountryIso() {
49 | return countryIso;
50 | }
51 |
52 | public void setCountryIso(String countryIso) {
53 | this.countryIso = countryIso;
54 | }
55 |
56 | public String getCity() {
57 | return city;
58 | }
59 |
60 | public void setCity(String city) {
61 | this.city = city;
62 | }
63 | }
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/java/com/hellohasan/retrofitsimplegetrequest/network/ApiInterface.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.retrofitsimplegetrequest.network;
2 |
3 |
4 | import com.hellohasan.retrofitsimplegetrequest.ServerResponse;
5 |
6 | import retrofit2.Call;
7 | import retrofit2.http.GET;
8 |
9 | public interface ApiInterface {
10 |
11 | @GET("/json") //Here, `json` is the PATH PARAMETER
12 | Call getMyIp();
13 | }
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/java/com/hellohasan/retrofitsimplegetrequest/network/RetrofitApiClient.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.retrofitsimplegetrequest.network;
2 |
3 | import com.google.gson.Gson;
4 | import com.google.gson.GsonBuilder;
5 |
6 | import retrofit2.Retrofit;
7 | import retrofit2.converter.gson.GsonConverterFactory;
8 |
9 | public class RetrofitApiClient {
10 |
11 | private static final String BASE_URL = "https://ifconfig.co";
12 | private static Retrofit retrofit = null;
13 |
14 | private static Gson gson = new GsonBuilder()
15 | .setLenient()
16 | .create();
17 |
18 | private RetrofitApiClient() {
19 | /*
20 | This is a Private Constructor
21 | So that nobody can create an object with this constructor, from outside of this class.
22 | We will achieve Singleton
23 | */
24 | }
25 |
26 | public static Retrofit getClient() {
27 | if (retrofit == null) {
28 | synchronized (RetrofitApiClient.class) { //thread safe Singleton implementation
29 | if (retrofit == null) {
30 | retrofit = new Retrofit.Builder()
31 | .baseUrl(BASE_URL)
32 | .addConverterFactory(GsonConverterFactory.create(gson))
33 | .build();
34 | }
35 | }
36 | }
37 |
38 | return retrofit;
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
31 |
32 |
46 |
47 |
56 |
57 |
66 |
67 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Retrofit-Simple-Get-Request/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Retrofit Simple Get Request
3 | Show My IP Address
4 | IP Address
5 |
6 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/app/src/test/java/com/hellohasan/retrofitsimplegetrequest/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.hellohasan.retrofitsimplegetrequest;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 |
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.1.4'
11 |
12 |
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 | }
23 | }
24 |
25 | task clean(type: Delete) {
26 | delete rootProject.buildDir
27 | }
28 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hasancse91/retrofit-implementation/599a6e9d9f1bdcef8d2bbf8d669d11de35bfb038/Retrofit-Simple-Get-Request/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Aug 15 15:41:07 BDT 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.4-all.zip
7 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/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 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
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 Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/Retrofit-Simple-Get-Request/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------