Skip to content

Commit 2ad1f2c

Browse files
committed
initial commit
0 parents  commit 2ad1f2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1244
-0
lines changed

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx

.idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/Project.xml

+116
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 29
5+
buildToolsVersion "29.0.3"
6+
7+
defaultConfig {
8+
applicationId "com.example.retrofitexample"
9+
minSdkVersion 21
10+
targetSdkVersion 29
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled false
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21+
}
22+
}
23+
}
24+
25+
dependencies {
26+
implementation fileTree(dir: "libs", include: ["*.jar"])
27+
implementation 'androidx.appcompat:appcompat:1.1.0'
28+
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
29+
testImplementation 'junit:junit:4.12'
30+
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
31+
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
32+
implementation 'com.squareup.retrofit2:converter-scalars:2.5.0'
33+
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
34+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
35+
36+
}

app/proguard-rules.pro

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.example.retrofitexample;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.example.retrofitexample", appContext.getPackageName());
25+
}
26+
}

app/src/main/AndroidManifest.xml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.example.retrofitexample">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7+
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:roundIcon="@mipmap/ic_launcher_round"
13+
android:supportsRtl="true"
14+
android:theme="@style/AppTheme">
15+
<activity android:name=".MainActivity">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.example.retrofitexample;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
5+
import android.os.Bundle;
6+
import android.util.Log;
7+
import android.view.View;
8+
import android.widget.Button;
9+
import android.widget.TextView;
10+
11+
import com.example.retrofitexample.model.data;
12+
import com.example.retrofitexample.retrofit.ApiClint;
13+
14+
import retrofit2.Call;
15+
import retrofit2.Callback;
16+
import retrofit2.Response;
17+
18+
public class MainActivity extends AppCompatActivity {
19+
20+
21+
TextView city,temp,weather;
22+
Button button;
23+
24+
@Override
25+
protected void onCreate(Bundle savedInstanceState) {
26+
super.onCreate(savedInstanceState);
27+
setContentView(R.layout.activity_main);
28+
29+
city=findViewById(R.id.city);
30+
temp=findViewById(R.id.temp);
31+
weather=findViewById(R.id.weather);
32+
button=findViewById(R.id.get);
33+
34+
final ApiClint apiClint=new ApiClint();
35+
36+
button.setOnClickListener(new View.OnClickListener() {
37+
@Override
38+
public void onClick(View v) {
39+
40+
41+
Call<data> call=apiClint.getApiinterface().get_data("24.780010","84.981827","38e8b3043b0eda5c4cae704a57a20e93");
42+
43+
call.enqueue(new Callback<data>() {
44+
@Override
45+
public void onResponse(Call<data> call, Response<data> response) {
46+
47+
Log.e("ert",response.body().getName());
48+
49+
city.setText(response.body().getName());
50+
temp.setText(String.valueOf(response.body().getMain().getTemp()));
51+
weather.setText(response.body().getWeather().get(0).getDescription());
52+
53+
}
54+
55+
@Override
56+
public void onFailure(Call<data> call, Throwable t) {
57+
58+
Log.e("error",t.getMessage());
59+
60+
}
61+
});
62+
}
63+
});
64+
65+
66+
}
67+
68+
}

0 commit comments

Comments
 (0)