From fe26f534b8acc4963607b0ae941d50724c6e9821 Mon Sep 17 00:00:00 2001 From: branci Date: Thu, 12 Oct 2017 23:39:11 +0200 Subject: [PATCH 1/3] Ukol2 finished --- app/build.gradle | 1 + app/src/main/AndroidManifest.xml | 19 ++++- .../java/cz/muni/fi/pv256/movio2/App.java | 1 + .../pv256/movio2/uco_422678/MainActivity.java | 71 ++++++++++++++++++ app/src/main/res/layout/activity_app.xml | 9 --- app/src/main/res/layout/activity_main.xml | 31 ++++++++ app/src/main/res/layout/content_main.xml | 12 +++ app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 3418 -> 4662 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 4208 -> 6295 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 2206 -> 2629 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 2555 -> 3363 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 4842 -> 5748 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 6114 -> 7606 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 7718 -> 10240 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 10056 -> 13537 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 10486 -> 13252 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 14696 -> 15986 bytes app/src/main/res/values/colors.xml | 3 + app/src/main/res/values/dimens.xml | 3 + app/src/main/res/values/strings.xml | 2 + app/src/main/res/values/styles.xml | 15 ++-- app/src/main/res/values/theme.xml | 17 +++++ 22 files changed, 164 insertions(+), 20 deletions(-) create mode 100644 app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MainActivity.java create mode 100644 app/src/main/res/layout/activity_main.xml create mode 100644 app/src/main/res/layout/content_main.xml create mode 100644 app/src/main/res/values/dimens.xml create mode 100644 app/src/main/res/values/theme.xml diff --git a/app/build.gradle b/app/build.gradle index e3f632e..7a1f8ad 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,6 +26,7 @@ dependencies { }) compile 'com.android.support:appcompat-v7:26.0.2' compile 'com.android.support.constraint:constraint-layout:1.0.2' + compile 'com.android.support:design:26.+' testCompile 'junit:junit:4.12' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0199761..3194cb7 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + package="cz.muni.fi.pv256.movio2"> + android:theme="@style/SecondTheme"> + + + + + + diff --git a/app/src/main/java/cz/muni/fi/pv256/movio2/App.java b/app/src/main/java/cz/muni/fi/pv256/movio2/App.java index 0c93b1c..a34aa74 100644 --- a/app/src/main/java/cz/muni/fi/pv256/movio2/App.java +++ b/app/src/main/java/cz/muni/fi/pv256/movio2/App.java @@ -17,6 +17,7 @@ public void onCreate() { } } + private void initStrictMode() { StrictMode.ThreadPolicy.Builder tpb = new StrictMode.ThreadPolicy.Builder() .detectAll() diff --git a/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MainActivity.java b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MainActivity.java new file mode 100644 index 0000000..3a647dc --- /dev/null +++ b/app/src/main/java/cz/muni/fi/pv256/movio2/uco_422678/MainActivity.java @@ -0,0 +1,71 @@ +package cz.muni.fi.pv256.movio2.uco_422678; + +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.Button; +import android.widget.Switch; + +import cz.muni.fi.pv256.movio2.R; + +public class MainActivity extends AppCompatActivity { + private RecyclerView mRecyclerView; + private RecyclerView.Adapter mAdapter; + private RecyclerView.LayoutManager mLayoutManager; + + private Button mSwitchThemeButton; + + private SharedPreferences myPreferences; + private SharedPreferences.Editor myPreferencesEditor; + private static final String PREFSTRING = "currentTheme"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + myPreferences = getSharedPreferences("movio2preferences", MODE_PRIVATE); + final boolean isCurrentThemeAppTheme = myPreferences.getBoolean(PREFSTRING, false); + if(isCurrentThemeAppTheme){ + setTheme(R.style.AppTheme); + } else { + setTheme(R.style.SecondTheme); + } + myPreferencesEditor = myPreferences.edit(); + + setContentView(R.layout.activity_main); + + mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); + mSwitchThemeButton = (Button) findViewById(R.id.switchtheme_button); + + mSwitchThemeButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + myPreferencesEditor.putBoolean(PREFSTRING, !isCurrentThemeAppTheme); + myPreferencesEditor.apply(); + + Intent intent = new Intent(getApplicationContext() ,MainActivity.class); + startActivity(intent); + finish(); + } + }); + + + //improving performance if changes + //in content do not change the layout size of the RecyclerView + mRecyclerView.setHasFixedSize(true); + + // use a linear layout manager + mLayoutManager = new LinearLayoutManager(this); + mRecyclerView.setLayoutManager(mLayoutManager); + + //TODO: specify an adapter + + } + +} diff --git a/app/src/main/res/layout/activity_app.xml b/app/src/main/res/layout/activity_app.xml index 7cd2a6c..56cb75c 100644 --- a/app/src/main/res/layout/activity_app.xml +++ b/app/src/main/res/layout/activity_app.xml @@ -6,13 +6,4 @@ android:layout_height="match_parent" tools:context="cz.muni.fi.pv256.movio2.App"> - - diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..38c41ff --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,31 @@ + + + + + + + + +