Skip to content

Commit d450353

Browse files
committed
Add mandatory new terms agreement screen
1 parent 60c9d8c commit d450353

File tree

79 files changed

+4228
-3372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+4228
-3372
lines changed

OpenScienceJournal/whistlepunk_library/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@
221221
android:name=".accounts.OnboardingActivity"
222222
android:exported="false"
223223
android:theme="@style/AppTheme.Onboarding" />
224+
<activity
225+
android:name=".accounts.NewTermsActivity"
226+
android:exported="false"
227+
android:theme="@style/AppTheme.Arduino" />
224228
<activity
225229
android:name=".signin.ArduinoAuthActivity"
226230
android:exported="false"

OpenScienceJournal/whistlepunk_library/src/main/java/com/google/android/apps/forscience/whistlepunk/ActivityRequestCodes.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ public final class ActivityRequestCodes {
1212

1313
public static final int REQUEST_ARDUINO_SIGN_IN = 9;
1414

15+
public static final int REQUEST_NEW_TERMS_ACTIVITY = 10;
16+
1517
private ActivityRequestCodes() {}
1618
}

OpenScienceJournal/whistlepunk_library/src/main/java/com/google/android/apps/forscience/whistlepunk/MainActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import com.caverock.androidsvg.SVG;
4747
import com.google.android.apps.forscience.whistlepunk.accounts.AccountsProvider;
4848
import com.google.android.apps.forscience.whistlepunk.accounts.AppAccount;
49+
import com.google.android.apps.forscience.whistlepunk.accounts.NewTermsActivity;
4950
import com.google.android.apps.forscience.whistlepunk.accounts.NonSignedInAccount;
5051
import com.google.android.apps.forscience.whistlepunk.accounts.OnboardingActivity;
5152
import com.google.android.apps.forscience.whistlepunk.analytics.TrackerConstants;
@@ -389,6 +390,12 @@ private boolean showRequiredScreensIfNeeded() {
389390
return false;
390391
}
391392

393+
if (NewTermsActivity.shouldLaunch(this)) {
394+
Intent intent = new Intent(this, NewTermsActivity.class);
395+
startActivityForResult(intent, ActivityRequestCodes.REQUEST_NEW_TERMS_ACTIVITY);
396+
return true;
397+
}
398+
392399
if (OnboardingActivity.shouldLaunch(this)) {
393400
Intent intent = new Intent(this, OnboardingActivity.class);
394401
startActivityForResult(intent, ActivityRequestCodes.REQUEST_ONBOARDING_ACTIVITY);
@@ -593,6 +600,7 @@ public static Intent launchIntent(Context context, int id, boolean usePanes) {
593600
public void onActivityResult(int requestCode, int resultCode, Intent data) {
594601
super.onActivityResult(requestCode, resultCode, data);
595602
switch (requestCode) {
603+
case ActivityRequestCodes.REQUEST_NEW_TERMS_ACTIVITY:
596604
case ActivityRequestCodes.REQUEST_ONBOARDING_ACTIVITY:
597605
case ActivityRequestCodes.REQUEST_SIGN_IN_ACTIVITY:
598606
if (resultCode == RESULT_CANCELED) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package com.google.android.apps.forscience.whistlepunk.accounts;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.graphics.Typeface;
7+
import android.os.Bundle;
8+
import android.preference.PreferenceManager;
9+
import android.text.Spannable;
10+
import android.text.SpannableString;
11+
import android.text.TextPaint;
12+
import android.text.method.LinkMovementMethod;
13+
import android.text.style.ClickableSpan;
14+
import android.text.style.ForegroundColorSpan;
15+
import android.text.style.StyleSpan;
16+
import android.view.View;
17+
import android.widget.TextView;
18+
19+
import androidx.annotation.NonNull;
20+
import androidx.annotation.Nullable;
21+
import androidx.appcompat.app.AppCompatActivity;
22+
23+
import com.google.android.apps.forscience.whistlepunk.R;
24+
import com.google.android.apps.forscience.whistlepunk.signin.WebActivity;
25+
26+
public class NewTermsActivity extends AppCompatActivity {
27+
28+
private static final String KEY_SHOULD_LAUNCH = "key_should_launch_new_terms_activity";
29+
30+
public static boolean shouldLaunch(Context context) {
31+
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(KEY_SHOULD_LAUNCH, true);
32+
}
33+
34+
@SuppressWarnings("SameParameterValue")
35+
static void setShouldLaunch(Context context, boolean shouldLaunch) {
36+
PreferenceManager.getDefaultSharedPreferences(context)
37+
.edit()
38+
.putBoolean(KEY_SHOULD_LAUNCH, shouldLaunch)
39+
.apply();
40+
}
41+
42+
@Override
43+
protected void onCreate(@Nullable Bundle savedInstanceState) {
44+
super.onCreate(savedInstanceState);
45+
46+
setContentView(R.layout.activity_new_terms);
47+
48+
TextView description = findViewById(R.id.new_terms_description);
49+
description.setMovementMethod(LinkMovementMethod.getInstance());
50+
description.setText(getDescriptionTextWithLinks());
51+
52+
TextView agreeButton = findViewById(R.id.new_terms_btn_agree);
53+
agreeButton.setOnClickListener(v -> onClose());
54+
}
55+
56+
private Spannable getDescriptionTextWithLinks() {
57+
final String text = getString(R.string.arduino_terms_agreement);
58+
final SpannableString spannable = new SpannableString(text);
59+
final int color = getResources().getColor(R.color.arduino_teal_3);
60+
final String linkLabel = getString(R.string.arduino_terms_agreement__link_label);
61+
final int linkIndex = text.indexOf(linkLabel);
62+
if (linkIndex > 0) {
63+
spannable.setSpan(new ForegroundColorSpan(color), linkIndex, linkIndex + linkLabel.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
64+
spannable.setSpan(new StyleSpan(Typeface.BOLD), linkIndex, linkIndex + linkLabel.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
65+
spannable.setSpan(new NewTermsActivity.NoUnderlineClickableSpan() {
66+
@Override
67+
public void onClick(@NonNull View widget) {
68+
openTermsPage();
69+
}
70+
}, linkIndex, linkIndex + linkLabel.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
71+
}
72+
73+
return spannable;
74+
}
75+
76+
private void openTermsPage() {
77+
final Intent intent = new Intent(this, WebActivity.class);
78+
intent.putExtra(WebActivity.EXTRA_KEY_TITLE, getString(R.string.terms));
79+
intent.putExtra(WebActivity.EXTRA_KEY_URL, getString(R.string.config_auth_terms));
80+
startActivity(intent);
81+
}
82+
83+
private void onClose() {
84+
setShouldLaunch(this, false);
85+
setResult(Activity.RESULT_OK);
86+
finish();
87+
}
88+
89+
private abstract static class NoUnderlineClickableSpan extends ClickableSpan {
90+
91+
@Override
92+
public void updateDrawState(TextPaint ds) {
93+
ds.setUnderlineText(false);
94+
}
95+
96+
}
97+
}

OpenScienceJournal/whistlepunk_library/src/main/java/com/google/android/apps/forscience/whistlepunk/accounts/SignInFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private void learnMoreClicked() {
169169
WhistlePunkApplication.getUsageTracker(getActivity())
170170
.trackEvent(TrackerConstants.CATEGORY_SIGN_IN, TrackerConstants.ACTION_LEARN_MORE, null, 0);
171171
startActivity(
172-
new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.sign_in_learn_more_url))));
172+
new Intent(Intent.ACTION_VIEW, Uri.parse("https://support.google.com/sciencejournal/answer/9176370")));
173173
}
174174

175175
private void continueWithoutSigningInClicked() {
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:app="http://schemas.android.com/apk/res-auto"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:background="@color/arduino_clouds"
7+
tools:context="com.google.android.apps.forscience.whistlepunk.gdrivesync.GDriveSyncSetupActivity">
8+
9+
<androidx.constraintlayout.widget.ConstraintLayout
10+
android:id="@+id/new_terms_header"
11+
android:layout_width="0dp"
12+
android:layout_height="wrap_content"
13+
android:clipChildren="false"
14+
android:paddingTop="20dp"
15+
app:layout_constraintEnd_toEndOf="parent"
16+
app:layout_constraintStart_toStartOf="parent"
17+
app:layout_constraintTop_toTopOf="parent">
18+
19+
<TextView
20+
style="@style/ArduinoAuth_Text.Header"
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content"
23+
android:contentDescription="@null"
24+
android:text="@string/arduino_terms_agreement_title"
25+
app:layout_constraintBottom_toBottomOf="parent"
26+
app:layout_constraintEnd_toStartOf="parent"
27+
app:layout_constraintStart_toEndOf="parent"
28+
app:layout_constraintTop_toTopOf="parent" />
29+
30+
</androidx.constraintlayout.widget.ConstraintLayout>
31+
32+
<TextView
33+
android:id="@+id/new_terms_description"
34+
style="@style/ArduinoAuth_Text"
35+
android:layout_width="wrap_content"
36+
android:layout_height="wrap_content"
37+
android:layout_marginTop="48dp"
38+
android:gravity="center"
39+
android:maxWidth="360dp"
40+
android:paddingStart="20dp"
41+
android:paddingEnd="20dp"
42+
android:text=""
43+
android:clickable="true"
44+
app:layout_constraintEnd_toEndOf="parent"
45+
app:layout_constraintStart_toStartOf="parent"
46+
app:layout_constraintTop_toBottomOf="@id/new_terms_header" />
47+
48+
<TextView
49+
android:id="@+id/new_terms_btn_agree"
50+
style="@style/ArduinoAuth_Button"
51+
android:layout_width="wrap_content"
52+
android:layout_height="wrap_content"
53+
android:layout_marginTop="50dp"
54+
android:layout_marginBottom="40dp"
55+
android:paddingStart="30dp"
56+
android:paddingEnd="30dp"
57+
android:text="@string/arduino_terms_agreement_cta"
58+
app:layout_constraintEnd_toEndOf="parent"
59+
app:layout_constraintStart_toStartOf="parent"
60+
app:layout_constraintBottom_toBottomOf="parent" />
61+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)