diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 80aed2b..48bd6fb 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -24,15 +24,22 @@ android:label="@string/application_long" android:theme="@style/Theme.AppCompat.Light"> + android:name=".StartActivity" + android:theme="@style/Theme.AppCompat.Light.NoActionBar" + android:exported="true" + android:label="@string/application_long" + android:launchMode="singleTask"> + + @@ -50,4 +57,4 @@ - \ No newline at end of file + diff --git a/android/app/src/main/java/com/maptology/android/app/StartActivity.java b/android/app/src/main/java/com/maptology/android/app/StartActivity.java new file mode 100644 index 0000000..ff8852d --- /dev/null +++ b/android/app/src/main/java/com/maptology/android/app/StartActivity.java @@ -0,0 +1,66 @@ +package com.maptology.android.app; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.os.Handler; +import android.support.v4.app.FragmentTransaction; +import android.support.v7.app.AppCompatActivity; +import com.maptology.android.app.fragment.LogoFragment; +import com.maptology.android.app.fragment.TermsFragment; + +/** + * Activity displayed at app start, shows maptology logo and asks for research permission. + * + * @author sarah + */ +public class StartActivity extends AppCompatActivity { + /** + * A tag for the fragment. + */ + private static final String TAG = "StartActivity"; + + /** + * Tag to get shared preferences. + */ + private final String prefsTag = "TERMS_SHOWN"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_start); + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + LogoFragment logoFragment = new LogoFragment(); + ft.replace(R.id.start_content, logoFragment, TAG); + + // wait while showing maptology logo + Handler handler = new Handler(); + handler.postDelayed(new Runnable() { + public void run() { + continue_execution(); + } + }, 2000); + + ft.commit(); + } + + /** + * Method to continue app execution, shows terms & conditions or starts app directly. + */ + private void continue_execution() { + // get whether T&Cs were already shown + SharedPreferences preferences = getApplicationContext().getSharedPreferences(prefsTag, Context.MODE_PRIVATE); + boolean termsShown = preferences.getBoolean(prefsTag, false); + + if (!termsShown) { + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + TermsFragment termsFragment = new TermsFragment(); + ft.replace(R.id.start_content, termsFragment, TAG); + ft.commit(); + } else { + Intent intent = new Intent(getBaseContext(), MainActivity.class); + this.startActivity(intent); + } + } +} diff --git a/android/app/src/main/java/com/maptology/android/app/fragment/LogoFragment.java b/android/app/src/main/java/com/maptology/android/app/fragment/LogoFragment.java new file mode 100644 index 0000000..431e202 --- /dev/null +++ b/android/app/src/main/java/com/maptology/android/app/fragment/LogoFragment.java @@ -0,0 +1,26 @@ +package com.maptology.android.app.fragment; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import com.maptology.android.app.R; + +/** + * Fragment to display maptology logo. + * + * @author sarah + */ +public class LogoFragment extends AbstractFragment { + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_logo, container, false); + return view; + } +} diff --git a/android/app/src/main/java/com/maptology/android/app/fragment/TermsFragment.java b/android/app/src/main/java/com/maptology/android/app/fragment/TermsFragment.java new file mode 100644 index 0000000..e781238 --- /dev/null +++ b/android/app/src/main/java/com/maptology/android/app/fragment/TermsFragment.java @@ -0,0 +1,74 @@ +package com.maptology.android.app.fragment; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.WebView; +import android.widget.Button; +import android.widget.CheckBox; +import com.maptology.android.app.MainActivity; +import com.maptology.android.app.R; + +/** + * Fragment to display terms & conditions and ask for research permission. + * + * @author sarah + */ +public class TermsFragment extends AbstractFragment { + /** + * Tag to get shared preferences. + */ + private final String prefsTag = "TERMS_SHOWN"; + + /** + * Store whether permission to use location for research was given. + */ + boolean permissionGiven; + + @Override + public void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View view = inflater.inflate(R.layout.fragment_terms, container, false); + + // set up web view + // TODO: change to actual terms & conditions website + WebView webView = (WebView) view.findViewById(R.id.web_view); + webView.loadUrl("https://www.google.com"); + + // set up chekbox and store allowance in shared prefs (via repository) + final CheckBox checkBox = (CheckBox) view.findViewById(R.id.permission_checkbox_start); + permissionGiven = checkBox.isChecked(); + checkBox.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + permissionGiven = checkBox.isChecked(); + } + }); + + // set up accept & continue button, store whether T&Cs shown in shared prefs + Button button_continue = (Button) view.findViewById(R.id.start_button_continue); + button_continue.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences preferences = getContext().getSharedPreferences(prefsTag, Context.MODE_PRIVATE); + preferences.edit().putBoolean(prefsTag, true).apply(); + + getRepository().setResearchAllowed(getContext(), permissionGiven); + + Intent intent = new Intent(getActivity(), MainActivity.class); + startActivity(intent); + } + }); + + return view; + } +} diff --git a/android/app/src/main/res/layout/activity_start.xml b/android/app/src/main/res/layout/activity_start.xml new file mode 100644 index 0000000..3731543 --- /dev/null +++ b/android/app/src/main/res/layout/activity_start.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/android/app/src/main/res/layout/fragment_logo.xml b/android/app/src/main/res/layout/fragment_logo.xml new file mode 100644 index 0000000..00a189b --- /dev/null +++ b/android/app/src/main/res/layout/fragment_logo.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/android/app/src/main/res/layout/fragment_terms.xml b/android/app/src/main/res/layout/fragment_terms.xml new file mode 100644 index 0000000..6fe7a74 --- /dev/null +++ b/android/app/src/main/res/layout/fragment_terms.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + +