Added start activity that shows logo and asks at first start to accept T&Cs and to allow research.
lbs-gitea/maptology/master This commit looks good

This commit is contained in:
Sarah Theußen
2017-12-19 19:05:51 +01:00
parent 5d517370a2
commit 2d9533d371
8 changed files with 258 additions and 10 deletions
+12 -5
View File
@@ -24,15 +24,22 @@
android:label="@string/application_long"
android:theme="@style/Theme.AppCompat.Light">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/application_long"
android:launchMode="singleTask">
android:name=".StartActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
android:exported="true"
android:label="@string/application_long"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/application_long"
android:launchMode="singleTask">
</activity>
<receiver android:name=".notice.NoticeSyncReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
@@ -50,4 +57,4 @@
</receiver>
</application>
</manifest>
</manifest>
@@ -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);
}
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/start_content"></FrameLayout>
</LinearLayout>
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/icon_launcher"/>
</LinearLayout>
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.7"></WebView>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.3">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:text="@string/app_permission_desc_long"/>
<CheckBox
android:id="@+id/permission_checkbox_start"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:checked="true"/>
</LinearLayout>
<Button
android:id="@+id/start_button_continue"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/accept_continue"/>
</LinearLayout>
</LinearLayout>
+6 -5
View File
@@ -1,7 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- start and settings -->
<string name="accept_continue">Accept &amp; Continue</string>
<string name="app_version_desc">App Version</string>
<string name="app_permission_desc">Do you want to share your location anonymously for research?</string>
<string name="app_permission_desc_long">Do you want to share your location anonymously for research? You can change your decision in the settings at any time.</string>
<!-- map -->
<string name="zoom_angle">Zoom: %1$d Angle: %2$g</string>
<string name="longitude_latitude">Longitude: %1$g Latitude: %2$g</string>
@@ -23,8 +28,4 @@
<string name="drawer_close">Close navigation</string>
<string name="drawer_title">Navigation</string>
<!-- Settings Page -->
<string name="app_version_desc">App Version</string>
<string name="app_permission_desc">Do you want to share your location anonymously for research?</string>
</resources>