diff --git a/Assignments/PicoCtf_Screenshot.png b/Assignments/PicoCtf_Screenshot.png new file mode 100644 index 0000000..eef0e71 Binary files /dev/null and b/Assignments/PicoCtf_Screenshot.png differ diff --git a/Assignments/Retrofit/.gitignore b/Assignments/Retrofit/.gitignore new file mode 100644 index 0000000..fd45b12 --- /dev/null +++ b/Assignments/Retrofit/.gitignore @@ -0,0 +1,11 @@ +*.iml +.gradle +/local.properties +/.idea/caches/build_file_checksums.ser +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/Assignments/Retrofit/.idea/codeStyles/Project.xml b/Assignments/Retrofit/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..30aa626 --- /dev/null +++ b/Assignments/Retrofit/.idea/codeStyles/Project.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Assignments/Retrofit/.idea/dictionaries/dell.xml b/Assignments/Retrofit/.idea/dictionaries/dell.xml new file mode 100644 index 0000000..2f083fe --- /dev/null +++ b/Assignments/Retrofit/.idea/dictionaries/dell.xml @@ -0,0 +1,7 @@ + + + + apikey + + + \ No newline at end of file diff --git a/Assignments/Retrofit/.idea/gradle.xml b/Assignments/Retrofit/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/Assignments/Retrofit/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/Assignments/Retrofit/.idea/misc.xml b/Assignments/Retrofit/.idea/misc.xml new file mode 100644 index 0000000..dc44dda --- /dev/null +++ b/Assignments/Retrofit/.idea/misc.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Assignments/Retrofit/.idea/runConfigurations.xml b/Assignments/Retrofit/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/Assignments/Retrofit/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/Assignments/Retrofit/.idea/vcs.xml b/Assignments/Retrofit/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/Assignments/Retrofit/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Assignments/Retrofit/README.md b/Assignments/Retrofit/README.md new file mode 100644 index 0000000..60bb546 --- /dev/null +++ b/Assignments/Retrofit/README.md @@ -0,0 +1,9 @@ +# Weather +>Basic weather app to learn android networking and working of rest APIs. + +>Used openweather api, available for free. + +>App gives current weather data of any location by its postal code + + + diff --git a/Assignments/Retrofit/app/.gitignore b/Assignments/Retrofit/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/Assignments/Retrofit/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/Assignments/Retrofit/app/build.gradle b/Assignments/Retrofit/app/build.gradle new file mode 100644 index 0000000..73b549d --- /dev/null +++ b/Assignments/Retrofit/app/build.gradle @@ -0,0 +1,34 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 28 + defaultConfig { + applicationId "com.sachan.prateek.weather" + minSdkVersion 24 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:28.0.0' + implementation 'com.android.support.constraint:constraint-layout:1.1.3' + testImplementation 'junit:junit:4.12' + implementation 'com.squareup.retrofit2:retrofit:2.5.0' + implementation 'com.squareup.retrofit2:converter-gson:2.5.0' + androidTestImplementation 'com.android.support.test:runner:1.0.2' + androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' + implementation 'com.github.bumptech.glide:glide:4.9.0' + annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0' + implementation 'com.android.support:cardview-v7:28.0.0' + implementation 'com.android.support:design:28.0.0' +} diff --git a/Assignments/Retrofit/app/proguard-rules.pro b/Assignments/Retrofit/app/proguard-rules.pro new file mode 100644 index 0000000..f1b4245 --- /dev/null +++ b/Assignments/Retrofit/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/Assignments/Retrofit/app/src/androidTest/java/com/sachan/prateek/weather/ExampleInstrumentedTest.java b/Assignments/Retrofit/app/src/androidTest/java/com/sachan/prateek/weather/ExampleInstrumentedTest.java new file mode 100644 index 0000000..55853c3 --- /dev/null +++ b/Assignments/Retrofit/app/src/androidTest/java/com/sachan/prateek/weather/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.sachan.prateek.weather; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.sachan.prateek.weather", appContext.getPackageName()); + } +} diff --git a/Assignments/Retrofit/app/src/main/AndroidManifest.xml b/Assignments/Retrofit/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..9f60f88 --- /dev/null +++ b/Assignments/Retrofit/app/src/main/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/CloudData.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/CloudData.java new file mode 100644 index 0000000..659e248 --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/CloudData.java @@ -0,0 +1,14 @@ +package com.sachan.prateek.weather.Data; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class CloudData { + @SerializedName("all") + @Expose + private int all; + + public int getAll() { + return all; + } +} diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Coordinates.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Coordinates.java new file mode 100644 index 0000000..0e27dde --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Coordinates.java @@ -0,0 +1,22 @@ +package com.sachan.prateek.weather.Data; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Coordinates { + @SerializedName("lon") + @Expose + private double lon; + @SerializedName("lat") + @Expose + private double lat; + + public double getLon() { + return lon; + } + + public double getLat() { + return lat; + } + +} \ No newline at end of file diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Main.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Main.java new file mode 100644 index 0000000..bbd72e2 --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Main.java @@ -0,0 +1,45 @@ +package com.sachan.prateek.weather.Data; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Main { + + @SerializedName("temp") + + @Expose + private double temp; + @SerializedName("pressure") + @Expose + private double pressure; + @SerializedName("humidity") + @Expose + private double humidity; + @SerializedName("temp_min") + @Expose + private double tempMin; + @SerializedName("temp_max") + @Expose + private double tempMax; + + public double getTemp() { + return temp; + } + + public double getPressure() { + return pressure; + } + + public double getHumidity() { + return humidity; + } + + public double getTempMin() { + return tempMin; + } + + public double getTempMax() { + return tempMax; + } + +} \ No newline at end of file diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Sys.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Sys.java new file mode 100644 index 0000000..19a3b4f --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Sys.java @@ -0,0 +1,52 @@ +package com.sachan.prateek.weather.Data; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Sys { + + @SerializedName("type") + @Expose + private int type; + @SerializedName("id") + @Expose + private int id; + @SerializedName("message") + + @Expose + private double message; + @SerializedName("country") + @Expose + private String country; + @SerializedName("sunrise") + @Expose + private int sunrise; + @SerializedName("sunset") + @Expose + private int sunset; + + public int getType() { + return type; + } + + public int getId() { + return id; + } + + public double getMessage() { + return message; + } + + public String getCountry() { + return country; + } + + public int getSunrise() { + return sunrise; + } + + public int getSunset() { + return sunset; + } + +} \ No newline at end of file diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Weather.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Weather.java new file mode 100644 index 0000000..a47d004 --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Weather.java @@ -0,0 +1,37 @@ +package com.sachan.prateek.weather.Data; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Weather { + + @SerializedName("id") + @Expose + private int id; + @SerializedName("main") + @Expose + private String main; + @SerializedName("description") + @Expose + private String description; + @SerializedName("icon") + @Expose + private String icon; + + public int getId() { + return id; + } + + public String getMain() { + return main; + } + + public String getDescription() { + return description; + } + + public String getIcon() { + return icon; + } + +} \ No newline at end of file diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/WeatherData.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/WeatherData.java new file mode 100644 index 0000000..845618a --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/WeatherData.java @@ -0,0 +1,95 @@ +package com.sachan.prateek.weather.Data; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +public class WeatherData { + + @SerializedName("coord") + @Expose + private Coordinates coord; + @SerializedName("weather") + @Expose + private List weather = null; + @SerializedName("base") + @Expose + private String base; + @SerializedName("main") + @Expose + private Main main; + @SerializedName("visibility") + @Expose + private double visibility; + @SerializedName("wind") + @Expose + private Wind wind; + @SerializedName("clouds") + @Expose + private CloudData clouds; + @SerializedName("dt") + @Expose + private double dt; + @SerializedName("sys") + @Expose + private Sys sys; + @SerializedName("id") + @Expose + private double id; + @SerializedName("name") + @Expose + private String name; + @SerializedName("cod") + @Expose + + private double cod; + + public Coordinates getCoord() { + return coord; + } + + public List getWeather() { + return weather; + } + + public String getBase() { + return base; + } + + public Main getMain() { + return main; + } + + public double getVisibility() { + return visibility; + } + + public Wind getWind() { + return wind; + } + + public CloudData getClouds() { + return clouds; + } + + public double getDt() { + return dt; + } + + public Sys getSys() { + return sys; + } + + public double getId() { + return id; + } + + public String getName() { + return name; + } + + public double getCod() { + return cod; + } +} \ No newline at end of file diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Wind.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Wind.java new file mode 100644 index 0000000..25042f3 --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Data/Wind.java @@ -0,0 +1,23 @@ +package com.sachan.prateek.weather.Data; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class Wind { + + @SerializedName("speed") + @Expose + private double speed; + @SerializedName("deg") + @Expose + private double deg; + + public double getSpeed() { + return speed; + } + + public double getDeg() { + return deg; + } + +} \ No newline at end of file diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/MainActivity.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/MainActivity.java new file mode 100644 index 0000000..fde31a6 --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/MainActivity.java @@ -0,0 +1,125 @@ +package com.sachan.prateek.weather; + +import android.annotation.SuppressLint; +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import com.bumptech.glide.Glide; +import com.sachan.prateek.weather.Data.WeatherData; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +public class MainActivity extends AppCompatActivity { + + private static final String APIKEY = "f308b2139ca9071215ec0fd93173a019"; + private Weather_Service weatherService; + private TextView city,lat,lon,country,temp,press,type,desc,humi,visibility,windSpeed,sunrise,sunset; + private ImageView imageView; + private static WeatherData weatherData; + private EditText editText; + private SimpleDateFormat format; + private Button button; + private Date date; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + android.support.v7.widget.Toolbar toolbar = findViewById(R.id.toolbar); + setSupportActionBar(toolbar); + weatherService = Retrofit_Builder.getRetrofit().create(Weather_Service.class); + instantiate(); + button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + fetchData(editText.getText().toString()); + editText.selectAll(); + editText.clearFocus(); + } + }); + } + + void fetchData(String zipCode) { + weatherService.getWeatherData(APIKEY, zipCode + ",in").enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.body() != null) { + weatherData= response.body(); + city.setText(weatherData.getName()); + lon.setText(String.valueOf(weatherData.getCoord().getLon())); + lat.setText(String.valueOf(weatherData.getCoord().getLat())); + temp.setText(String.valueOf(weatherData.getMain().getTemp())); + press.setText(String.valueOf(weatherData.getMain().getPressure())); + humi.setText(String.valueOf(weatherData.getMain().getHumidity())); + visibility.setText(String.valueOf(weatherData.getVisibility())); + type.setText(weatherData.getWeather().get(0).getMain()); + desc.setText(weatherData.getWeather().get(0).getDescription()); + country.setText(weatherData.getSys().getCountry()); + windSpeed.setText(String.valueOf(weatherData.getWind().getSpeed())); + date=new Date((long)weatherData.getSys().getSunrise()*1000); + sunrise.setText(format.format(date)); + date=new Date((long)weatherData.getSys().getSunset()*1000); + sunset.setText(format.format(date)); + Glide.with(MainActivity.this).load("http://openweathermap.org/img/w/" + response.body().getWeather().get(0).getIcon() + ".png").into(imageView); + } else { + Toast.makeText(MainActivity.this, "Wrong Postal/Zip code", Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + t.printStackTrace(); + } + }); + } + @SuppressLint("SimpleDateFormat") + private void instantiate(){ + imageView = findViewById(R.id.image); + city = findViewById(R.id.text); + lat=findViewById(R.id.lat); + format= new SimpleDateFormat("dd-MM-yyyy HH:mm:ss"); + country=findViewById(R.id.country); + lon=findViewById(R.id.lon); + temp=findViewById(R.id.temp); + humi=findViewById(R.id.hum); + press=findViewById(R.id.press); + type=findViewById(R.id.desc); + desc=findViewById(R.id.weather); + visibility=findViewById(R.id.vis); + windSpeed=findViewById(R.id.wind); + sunrise=findViewById(R.id.sunrise); + sunset=findViewById(R.id.sunset); + editText = findViewById(R.id.edit); + button = findViewById(R.id.bt); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.menu,menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()){ + case R.id.settings: + startActivity(new Intent(this,SettingsActivity.class)); + } + return super.onOptionsItemSelected(item); + } +} diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Retrofit_Builder.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Retrofit_Builder.java new file mode 100644 index 0000000..8da5ea0 --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Retrofit_Builder.java @@ -0,0 +1,16 @@ +package com.sachan.prateek.weather; + +import retrofit2.Retrofit; +import retrofit2.converter.gson.GsonConverterFactory; + +public class Retrofit_Builder { + private static Retrofit retrofit; + private static final String BASEURL="http://api.openweathermap.org"; + static Retrofit getRetrofit() { + if (retrofit==null){ + retrofit=new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create()).baseUrl(BASEURL) + .build(); + } + return retrofit; + } +} diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/SettingsActivity.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/SettingsActivity.java new file mode 100644 index 0000000..3ba245a --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/SettingsActivity.java @@ -0,0 +1,14 @@ +package com.sachan.prateek.weather; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; + +public class SettingsActivity extends AppCompatActivity { + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.settings); + getFragmentManager().beginTransaction().add(R.id.settings_fragment,new Settings_Fragment()).commit(); + } +} diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Settings_Fragment.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Settings_Fragment.java new file mode 100644 index 0000000..6c29b89 --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Settings_Fragment.java @@ -0,0 +1,14 @@ +package com.sachan.prateek.weather; + +import android.os.Bundle; +import android.preference.PreferenceActivity; +import android.preference.PreferenceFragment; +import android.support.annotation.Nullable; + +public class Settings_Fragment extends PreferenceFragment { + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + addPreferencesFromResource(R.xml.preference_fragment); + } +} diff --git a/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Weather_Service.java b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Weather_Service.java new file mode 100644 index 0000000..a43181a --- /dev/null +++ b/Assignments/Retrofit/app/src/main/java/com/sachan/prateek/weather/Weather_Service.java @@ -0,0 +1,12 @@ +package com.sachan.prateek.weather; + +import com.sachan.prateek.weather.Data.WeatherData; + +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Query; + +public interface Weather_Service { + @GET("/data/2.5/weather") + Call getWeatherData(@Query("APPID") String apiKey, @Query("zip") String zip); +} diff --git a/Assignments/Retrofit/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/Assignments/Retrofit/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..1f6bb29 --- /dev/null +++ b/Assignments/Retrofit/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/Assignments/Retrofit/app/src/main/res/drawable-v24/img.jpg b/Assignments/Retrofit/app/src/main/res/drawable-v24/img.jpg new file mode 100644 index 0000000..91a451f Binary files /dev/null and b/Assignments/Retrofit/app/src/main/res/drawable-v24/img.jpg differ diff --git a/Assignments/Retrofit/app/src/main/res/drawable/ic_launcher_background.xml b/Assignments/Retrofit/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..0d025f9 --- /dev/null +++ b/Assignments/Retrofit/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Assignments/Retrofit/app/src/main/res/layout/activity_main.xml b/Assignments/Retrofit/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..d0275f5 --- /dev/null +++ b/Assignments/Retrofit/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,377 @@ + + + + + + + + + + + + + + + + + +