diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..aa724b77 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..aca94c8a --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +USTH Weather \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 00000000..fb7f4a8a --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml new file mode 100644 index 00000000..23b97d6f --- /dev/null +++ b/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 00000000..526b4c25 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..5c08e8b7 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index b9e3010b..c5bbeb70 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,10 @@ USTH ICT 2022 Android Application Development ===================================================== -Students are expected to: - -* Fork this repository to your github account -* Update student name and ID to this README file -* Push your commits regularly, with proper commit messages - Student Info ======================= -* Name: *YourNameHere* -* ID: *YourIdHere* -* Group ID: *Your Group ID here* +* Name: *Le Viet Anh* +* ID: *BI9-035* +* Group ID: *3* diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 00000000..dadabde2 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,44 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdk 28 + + defaultConfig { + applicationId "vn.edu.usth.weather" + minSdk 21 + targetSdk 28 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + buildFeatures { + viewBinding true + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.3.1' + implementation 'com.google.android.material:material:1.4.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.1' + implementation 'androidx.navigation:navigation-fragment:2.3.5' + implementation 'androidx.navigation:navigation-ui:2.3.5' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/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 \ No newline at end of file diff --git a/app/src/androidTest/java/vn/edu/usth/weather/ExampleInstrumentedTest.java b/app/src/androidTest/java/vn/edu/usth/weather/ExampleInstrumentedTest.java new file mode 100644 index 00000000..90bca95f --- /dev/null +++ b/app/src/androidTest/java/vn/edu/usth/weather/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package vn.edu.usth.weather; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.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.getInstrumentation().getTargetContext(); + assertEquals("vn.edu.usth.weather", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..df1cb5f4 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/vn/edu/usth/weather/Constants.java b/app/src/main/java/vn/edu/usth/weather/Constants.java new file mode 100644 index 00000000..a08d36c8 --- /dev/null +++ b/app/src/main/java/vn/edu/usth/weather/Constants.java @@ -0,0 +1,8 @@ +package vn.edu.usth.weather; + +public class Constants { + public static final int FRAGMENT_HANOI = 0; + public static final int FRAGMENT_PARIS = 1; + public static final int FRAGMENT_TOULOUSE = 2; + +} diff --git a/app/src/main/java/vn/edu/usth/weather/ForecastFragment.java b/app/src/main/java/vn/edu/usth/weather/ForecastFragment.java new file mode 100644 index 00000000..448ee4ac --- /dev/null +++ b/app/src/main/java/vn/edu/usth/weather/ForecastFragment.java @@ -0,0 +1,68 @@ +package vn.edu.usth.weather; + +import android.graphics.Color; +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link ForecastFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class ForecastFragment extends Fragment { + + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + + // TODO: Rename and change types of parameters + private String mParam1; + private String mParam2; + + public ForecastFragment() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment ForecastFragment. + */ + // TODO: Rename and change types and number of parameters + public static ForecastFragment newInstance(String param1, String param2) { + ForecastFragment fragment = new ForecastFragment(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View v = inflater.inflate(R.layout.fragment_forecast, container, false); +// int bg_color = Color.parseColor("#fff"); + v.setBackgroundColor(Color.WHITE); + return v; + } +} \ No newline at end of file diff --git a/app/src/main/java/vn/edu/usth/weather/ViewPagerAdapter.java b/app/src/main/java/vn/edu/usth/weather/ViewPagerAdapter.java new file mode 100644 index 00000000..c12140fe --- /dev/null +++ b/app/src/main/java/vn/edu/usth/weather/ViewPagerAdapter.java @@ -0,0 +1,42 @@ +package vn.edu.usth.weather; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; +import androidx.lifecycle.Lifecycle; +import androidx.viewpager2.adapter.FragmentStateAdapter; + +public class ViewPagerAdapter extends FragmentStateAdapter { + public ViewPagerAdapter(@NonNull FragmentActivity fragmentActivity) { + super(fragmentActivity); + } + + public ViewPagerAdapter(@NonNull Fragment fragment) { + super(fragment); + } + + public ViewPagerAdapter(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle) { + super(fragmentManager, lifecycle); + } + + @NonNull + @Override + public Fragment createFragment(int position) { + switch (position) + { + case Constants.FRAGMENT_HANOI: + return new WeatherAndForecastFragment(); + case Constants.FRAGMENT_PARIS: + return new WeatherAndForecastFragment(); + case Constants.FRAGMENT_TOULOUSE: + return new WeatherAndForecastFragment(); + } + return new WeatherAndForecastFragment(); + } + + @Override + public int getItemCount() { + return 3; + } +} diff --git a/app/src/main/java/vn/edu/usth/weather/WeatherActivity.java b/app/src/main/java/vn/edu/usth/weather/WeatherActivity.java new file mode 100644 index 00000000..7baec1b9 --- /dev/null +++ b/app/src/main/java/vn/edu/usth/weather/WeatherActivity.java @@ -0,0 +1,84 @@ +package vn.edu.usth.weather; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.fragment.app.FragmentManager; +import androidx.viewpager2.widget.ViewPager2; + +import android.os.Bundle; +import android.util.Log; + +import com.google.android.material.tabs.TabLayout; +import com.google.android.material.tabs.TabLayoutMediator; + + +public class WeatherActivity extends AppCompatActivity { + private static final String TAG = "WeatherActivity"; + private TabLayout mTabLayout; + private ViewPagerAdapter mViewPagerAdapter; + private ViewPager2 mViewPager2; + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_weather); +// WeatherAndForecastFragment wff = new WeatherAndForecastFragment(); +// getSupportFragmentManager().beginTransaction().add(R.id.activity_weather, wff).commit(); + + FragmentManager fm = getSupportFragmentManager(); + mViewPager2 = findViewById(R.id.view_pager_2); + TabLayout mTabLayout = findViewById(R.id.sliding_tabs); + mViewPagerAdapter = new ViewPagerAdapter(fm, getLifecycle()); + mViewPager2.setAdapter(mViewPagerAdapter); + + + new TabLayoutMediator(mTabLayout, mViewPager2, new TabLayoutMediator.TabConfigurationStrategy() { + @Override + public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) { + switch (position) { + case Constants.FRAGMENT_HANOI: + tab.setText(getString(R.string.hanoi)); + break; + case Constants.FRAGMENT_PARIS: + tab.setText(getString(R.string.paris)); + break; + case Constants.FRAGMENT_TOULOUSE: + tab.setText(getString(R.string.toulouse)); + break; + } + } + }).attach(); + mTabLayout.setTabGravity(TabLayout.GRAVITY_FILL); + Log.i(TAG, "onCreate()"); + } + @Override + public void onStart(){ + super.onStart(); + Log.i(TAG, "onStart()"); + }; + @Override + public void onRestart(){ + super.onRestart(); + Log.i(TAG, "onRestart()"); + }; + @Override + public void onResume(){ + super.onResume(); + Log.i(TAG, "onResume()"); + }; + @Override + public void onPause(){ + super.onPause(); + Log.i(TAG, "onPause()"); + }; + @Override + public void onStop(){ + super.onStop(); + Log.i(TAG, "onStop()"); + }; + @Override + public void onDestroy(){ + super.onDestroy(); + Log.i(TAG, "onDestroy()"); + }; + +} \ No newline at end of file diff --git a/app/src/main/java/vn/edu/usth/weather/WeatherAndForecastFragment.java b/app/src/main/java/vn/edu/usth/weather/WeatherAndForecastFragment.java new file mode 100644 index 00000000..f6192c14 --- /dev/null +++ b/app/src/main/java/vn/edu/usth/weather/WeatherAndForecastFragment.java @@ -0,0 +1,69 @@ +package vn.edu.usth.weather; + +import android.graphics.Color; +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link WeatherAndForecastFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class WeatherAndForecastFragment extends Fragment { + + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + + // TODO: Rename and change types of parameters + private String mParam1; + private String mParam2; + + public WeatherAndForecastFragment() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment WeatherForecastFragment. + */ + // TODO: Rename and change types and number of parameters + public static WeatherAndForecastFragment newInstance(String param1, String param2) { + WeatherAndForecastFragment fragment = new WeatherAndForecastFragment(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment +// return inflater.inflate(R.layout.fragment_weather_forecast, container, false); + View v = inflater.inflate(R.layout.fragment_weather_and_forecast, container, false); + int light_green = Color.parseColor("#acdfa4"); + v.setBackgroundColor(light_green); + return v; + } +} \ No newline at end of file diff --git a/app/src/main/java/vn/edu/usth/weather/WeatherFragment.java b/app/src/main/java/vn/edu/usth/weather/WeatherFragment.java new file mode 100644 index 00000000..99c52ca7 --- /dev/null +++ b/app/src/main/java/vn/edu/usth/weather/WeatherFragment.java @@ -0,0 +1,64 @@ +package vn.edu.usth.weather; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +/** + * A simple {@link Fragment} subclass. + * Use the {@link WeatherFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class WeatherFragment extends Fragment { + + // TODO: Rename parameter arguments, choose names that match + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_PARAM1 = "param1"; + private static final String ARG_PARAM2 = "param2"; + + // TODO: Rename and change types of parameters + private String mParam1; + private String mParam2; + + public WeatherFragment() { + // Required empty public constructor + } + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param param1 Parameter 1. + * @param param2 Parameter 2. + * @return A new instance of fragment WeatherFragment. + */ + // TODO: Rename and change types and number of parameters + public static WeatherFragment newInstance(String param1, String param2) { + WeatherFragment fragment = new WeatherFragment(); + Bundle args = new Bundle(); + args.putString(ARG_PARAM1, param1); + args.putString(ARG_PARAM2, param2); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + mParam1 = getArguments().getString(ARG_PARAM1); + mParam2 = getArguments().getString(ARG_PARAM2); + } + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_weather, container, false); + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-hdpi/cloud.png b/app/src/main/res/drawable-hdpi/cloud.png new file mode 100644 index 00000000..fb4426ce Binary files /dev/null and b/app/src/main/res/drawable-hdpi/cloud.png differ diff --git a/app/src/main/res/drawable-hdpi/cloudy.png b/app/src/main/res/drawable-hdpi/cloudy.png new file mode 100644 index 00000000..31dc9bee Binary files /dev/null and b/app/src/main/res/drawable-hdpi/cloudy.png differ diff --git a/app/src/main/res/drawable-hdpi/rain.png b/app/src/main/res/drawable-hdpi/rain.png new file mode 100644 index 00000000..03d27c84 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/rain.png differ diff --git a/app/src/main/res/drawable-hdpi/sun.png b/app/src/main/res/drawable-hdpi/sun.png new file mode 100644 index 00000000..64e9653f Binary files /dev/null and b/app/src/main/res/drawable-hdpi/sun.png differ diff --git a/app/src/main/res/drawable-hdpi/weather.png b/app/src/main/res/drawable-hdpi/weather.png new file mode 100644 index 00000000..2aca49c8 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/weather.png differ diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 00000000..2b068d11 --- /dev/null +++ b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/cloudy.png b/app/src/main/res/drawable/cloudy.png new file mode 100644 index 00000000..31dc9bee Binary files /dev/null and b/app/src/main/res/drawable/cloudy.png differ diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..07d5da9c --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/rain.png b/app/src/main/res/drawable/rain.png new file mode 100644 index 00000000..03d27c84 Binary files /dev/null and b/app/src/main/res/drawable/rain.png differ diff --git a/app/src/main/res/layout/activity_weather.xml b/app/src/main/res/layout/activity_weather.xml new file mode 100644 index 00000000..ef642939 --- /dev/null +++ b/app/src/main/res/layout/activity_weather.xml @@ -0,0 +1,24 @@ + + + + + + + diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml new file mode 100644 index 00000000..4fd40f26 --- /dev/null +++ b/app/src/main/res/layout/content_main.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_first.xml b/app/src/main/res/layout/fragment_first.xml new file mode 100644 index 00000000..fb44a3d9 --- /dev/null +++ b/app/src/main/res/layout/fragment_first.xml @@ -0,0 +1,28 @@ + + + + + +