diff --git a/app/build.gradle b/app/build.gradle index a96291f..75053ee 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -26,7 +26,7 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) testImplementation 'junit:junit:4.12' - implementation 'com.android.support:appcompat-v7:28.0.0' - implementation 'com.android.support:design:28.0.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation 'androidx.appcompat:appcompat:1.0.0' + implementation 'com.google.android.material:material:1.0.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 64804e5..3971ec8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -6,7 +6,7 @@ @@ -22,24 +22,24 @@ android:name=".MainActivity" android:label="@string/app_name" android:launchMode="singleTop" - android:theme="@style/AppTheme.NoActionBar"> - + android:theme="@style/AppTheme.NoActionBar"/> - - + android:parentActivityName=".MainActivity"/> - + android:parentActivityName=".MainActivity"/> - + android:parentActivityName=".MainActivity"/> + \ No newline at end of file diff --git a/app/src/main/java/org/secuso/privacyfriendlydicer/AboutActivity.java b/app/src/main/java/org/secuso/privacyfriendlydicer/AboutActivity.java index 9c798cf..7b1fc17 100644 --- a/app/src/main/java/org/secuso/privacyfriendlydicer/AboutActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlydicer/AboutActivity.java @@ -1,7 +1,7 @@ package org.secuso.privacyfriendlydicer; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; import android.text.method.LinkMovementMethod; import android.widget.TextView; diff --git a/app/src/main/java/org/secuso/privacyfriendlydicer/HelpActivity.java b/app/src/main/java/org/secuso/privacyfriendlydicer/HelpActivity.java index de11553..19953b0 100644 --- a/app/src/main/java/org/secuso/privacyfriendlydicer/HelpActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlydicer/HelpActivity.java @@ -1,7 +1,7 @@ package org.secuso.privacyfriendlydicer; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; /** * Created by yonjuni on 15.06.16. diff --git a/app/src/main/java/org/secuso/privacyfriendlydicer/MainActivity.java b/app/src/main/java/org/secuso/privacyfriendlydicer/MainActivity.java index 124b1f4..30c0302 100644 --- a/app/src/main/java/org/secuso/privacyfriendlydicer/MainActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlydicer/MainActivity.java @@ -1,23 +1,20 @@ package org.secuso.privacyfriendlydicer; -import android.app.AlertDialog; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; -import android.graphics.Point; import android.hardware.Sensor; import android.hardware.SensorManager; import android.os.Bundle; import android.os.Vibrator; import android.preference.PreferenceManager; -import android.support.design.widget.NavigationView; -import android.support.v4.view.GravityCompat; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.ActionBarDrawerToggle; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.Display; +import com.google.android.material.navigation.NavigationView; +import androidx.core.view.GravityCompat; +import androidx.drawerlayout.widget.DrawerLayout; +import androidx.appcompat.app.ActionBarDrawerToggle; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; + import android.view.MenuItem; import android.view.View; import android.view.animation.AlphaAnimation; @@ -54,8 +51,6 @@ protected void onCreate(Bundle savedInstanceState) { drawer.setDrawerListener(toggle); toggle.syncState(); - doFirstRun(); - NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); navigationView.setNavigationItemSelectedListener(this); @@ -271,18 +266,24 @@ public boolean onNavigationItemSelected(MenuItem item) { switch(item.getItemId()) { case R.id.nav_about: intent = new Intent(this, AboutActivity.class); - startActivityForResult(intent, 0); + startActivity(intent); return true; case R.id.nav_help: intent = new Intent(this, HelpActivity.class); - startActivityForResult(intent, 0); + startActivity(intent); return true; case R.id.nav_settimgs: intent = new Intent(this, SettingsActivity.class); - startActivityForResult(intent, 0); + startActivity(intent); + return true; + + case R.id.nav_tutorial: + intent = new Intent(this, TutorialActivity.class); + startActivity(intent); return true; + default: } @@ -290,43 +291,4 @@ public boolean onNavigationItemSelected(MenuItem item) { drawer.closeDrawer(GravityCompat.START); return true; } - - private void doFirstRun() { - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - sharedPreferences.edit().putString("firstShow", "").apply(); - SharedPreferences settings = getSharedPreferences("firstShow", getBaseContext().MODE_PRIVATE); - if (settings.getBoolean("isFirstRun", true)) { - welcomeDialog(); - SharedPreferences.Editor editor = settings.edit(); - editor.putBoolean("isFirstRun", false); - editor.apply(); - } - } - - public void welcomeDialog() { - AlertDialog.Builder alertDialog = new AlertDialog.Builder(this); - - alertDialog.setTitle(R.string.welcome_title); - - alertDialog.setMessage(R.string.welcome_description); - - alertDialog.setIcon(R.mipmap.drawer_icon_dicer); - - alertDialog.setPositiveButton(getString(R.string.confirm_button), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog,int which) { - } - }); - - final Intent intent = new Intent(this, HelpActivity.class); - alertDialog.setNegativeButton(getString(R.string.help_button), new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int which) { - startActivityForResult(intent, 0); - dialog.cancel(); - } - }); - - alertDialog.show(); - } - - } diff --git a/app/src/main/java/org/secuso/privacyfriendlydicer/SettingsActivity.java b/app/src/main/java/org/secuso/privacyfriendlydicer/SettingsActivity.java index cd70d67..f78fc4c 100644 --- a/app/src/main/java/org/secuso/privacyfriendlydicer/SettingsActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlydicer/SettingsActivity.java @@ -1,7 +1,7 @@ package org.secuso.privacyfriendlydicer; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; /** * Created by yonjuni on 15.06.16. diff --git a/app/src/main/java/org/secuso/privacyfriendlydicer/SplashActivity.java b/app/src/main/java/org/secuso/privacyfriendlydicer/SplashActivity.java index aebd780..fda4596 100644 --- a/app/src/main/java/org/secuso/privacyfriendlydicer/SplashActivity.java +++ b/app/src/main/java/org/secuso/privacyfriendlydicer/SplashActivity.java @@ -1,8 +1,9 @@ package org.secuso.privacyfriendlydicer; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatActivity; /** * Created by yonjuni on 22.10.16. @@ -14,10 +15,17 @@ public class SplashActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Intent mainIntent = new Intent(SplashActivity.this, MainActivity.class); - SplashActivity.this.startActivity(mainIntent); - SplashActivity.this.finish(); + SharedPreferences settings = getSharedPreferences("firstShow", getBaseContext().MODE_PRIVATE); + Intent intent; + if (settings.getBoolean("isFirstRun", true)) { + intent = new Intent(SplashActivity.this, TutorialActivity.class); + } else { + intent = new Intent(SplashActivity.this, MainActivity.class); + } + + startActivity(intent); + finish(); } } diff --git a/app/src/main/java/org/secuso/privacyfriendlydicer/TutorialActivity.java b/app/src/main/java/org/secuso/privacyfriendlydicer/TutorialActivity.java new file mode 100644 index 0000000..33fc0a2 --- /dev/null +++ b/app/src/main/java/org/secuso/privacyfriendlydicer/TutorialActivity.java @@ -0,0 +1,196 @@ +package org.secuso.privacyfriendlydicer; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.graphics.Color; +import android.os.Build; +import android.os.Bundle; +import android.preference.PreferenceManager; +import androidx.viewpager.widget.PagerAdapter; +import androidx.viewpager.widget.ViewPager; +import androidx.appcompat.app.AppCompatActivity; +import android.text.Html; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.view.Window; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.LinearLayout; +import android.widget.TextView; + + +/** + * Class structure taken from tutorial at http://www.androidhive.info/2016/05/android-build-intro-slider-app/ + * @author Karola Marky, Christopher Beckmann + * @version 20161214 + */ +public class TutorialActivity extends AppCompatActivity { + + private ViewPager viewPager; + private MyViewPagerAdapter myViewPagerAdapter; + private LinearLayout dotsLayout; + private TextView[] dots; + private int[] layouts; + private Button btnSkip, btnNext; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Making notification bar transparent + if (Build.VERSION.SDK_INT >= 21) { + getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } + + setContentView(R.layout.activity_tutorial); + + viewPager = (ViewPager) findViewById(R.id.view_pager); + dotsLayout = (LinearLayout) findViewById(R.id.layoutDots); + btnSkip = (Button) findViewById(R.id.btn_skip); + btnNext = (Button) findViewById(R.id.btn_next); + + // layouts of all welcome sliders + // add few more layouts if you want + layouts = new int[]{R.layout.tutorial_slide1}; + + // adding bottom dots + addBottomDots(0); + + // making notification bar transparent + changeStatusBarColor(); + + myViewPagerAdapter = new MyViewPagerAdapter(); + viewPager.setAdapter(myViewPagerAdapter); + viewPager.addOnPageChangeListener(viewPagerPageChangeListener); + viewPagerPageChangeListener.onPageSelected(0); + + btnSkip.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + TutorialActivity.this.launchHomeScreen(); + } + }); + + btnNext.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + // checking for last page + // if last page home screen will be launched + int current = TutorialActivity.this.getItem(+1); + if (current < layouts.length) { + // move to next screen + viewPager.setCurrentItem(current); + } else { + TutorialActivity.this.launchHomeScreen(); + } + } + }); + } + + private void addBottomDots(int currentPage) { + dots = new TextView[layouts.length]; + + int[] colorsActive = getResources().getIntArray(R.array.array_dot_active); + int[] colorsInactive = getResources().getIntArray(R.array.array_dot_inactive); + + dotsLayout.removeAllViews(); + for (int i = 0; i < dots.length; i++) { + dots[i] = new TextView(this); + dots[i].setText(Html.fromHtml("•")); + dots[i].setTextSize(35); + dots[i].setTextColor(colorsInactive[currentPage]); + dotsLayout.addView(dots[i]); + } + + if (dots.length > 0) + dots[currentPage].setTextColor(colorsActive[currentPage]); + } + + private int getItem(int i) { + return viewPager.getCurrentItem() + i; + } + + private void launchHomeScreen() { + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); + sharedPreferences.edit().putString("firstShow", "").apply(); + SharedPreferences settings = getSharedPreferences("firstShow", getBaseContext().MODE_PRIVATE); + if (settings.getBoolean("isFirstRun", true)) { + SharedPreferences.Editor editor = settings.edit(); + editor.putBoolean("isFirstRun", false); + editor.apply(); + } + + startActivity(new Intent(TutorialActivity.this, MainActivity.class)); + finish(); + } + + // viewpager change listener + ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() { + @Override public void onPageScrollStateChanged(int i) {} + @Override public void onPageScrolled(int i, float v, int i1) {} + @Override public void onPageSelected(int position) { + addBottomDots(position); + + // changing the next button text 'NEXT' / 'GOT IT' + if (position == layouts.length - 1) { + // last page. make button text to GOT IT + btnNext.setText(getString(R.string.okay)); + btnSkip.setVisibility(View.GONE); + } else { + // still pages are left + btnNext.setText(getString(R.string.next)); + btnSkip.setVisibility(View.VISIBLE); + } + } + }; + + /** + * Making notification bar transparent + */ + private void changeStatusBarColor() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + Window window = getWindow(); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setStatusBarColor(Color.TRANSPARENT); + } + } + + /** + * View pager adapter + */ + public class MyViewPagerAdapter extends PagerAdapter { + private LayoutInflater layoutInflater; + + public MyViewPagerAdapter() { + } + + @Override + public Object instantiateItem(ViewGroup container, int position) { + layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + View view = layoutInflater.inflate(layouts[position], container, false); + container.addView(view); + + return view; + } + + @Override + public int getCount() { + return layouts.length; + } + + @Override + public boolean isViewFromObject(View view, Object obj) { + return view == obj; + } + + + @Override + public void destroyItem(ViewGroup container, int position, Object object) { + View view = (View) object; + container.removeView(view); + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_menu_tutorial.xml b/app/src/main/res/drawable/ic_menu_tutorial.xml new file mode 100644 index 0000000..30d83f8 --- /dev/null +++ b/app/src/main/res/drawable/ic_menu_tutorial.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout-land/content_main.xml b/app/src/main/res/layout-land/content_main.xml index 531ec97..cec4c86 100644 --- a/app/src/main/res/layout-land/content_main.xml +++ b/app/src/main/res/layout-land/content_main.xml @@ -1,5 +1,5 @@ - - - + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index a61d8a6..8e69e22 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - - - + diff --git a/app/src/main/res/layout/activity_tutorial.xml b/app/src/main/res/layout/activity_tutorial.xml new file mode 100644 index 0000000..5735f1a --- /dev/null +++ b/app/src/main/res/layout/activity_tutorial.xml @@ -0,0 +1,56 @@ + + + + + + + + + +