Skip to content

Commit

Permalink
refactor(welcome):redesign the welcome page
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCShou committed Dec 4, 2022
1 parent db727d3 commit 497dfd4
Show file tree
Hide file tree
Showing 6 changed files with 249 additions and 96 deletions.
6 changes: 2 additions & 4 deletions app/src/main/java/com/zcshou/gogogo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@
import com.zcshou.utils.GoUtils;
import com.zcshou.utils.MapUtils;

import static android.view.View.GONE;

import com.elvishew.xlog.XLog;

import io.noties.markwon.Markwon;
Expand Down Expand Up @@ -581,15 +579,15 @@ private void showProtocolDialog() {
Window window = alertDialog.getWindow();
if (window != null) {
window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); // 防止出现闪屏
window.setContentView(R.layout.user_protocol);
window.setContentView(R.layout.user_agreement);
window.setGravity(Gravity.CENTER);
window.setWindowAnimations(R.style.DialogAnimFadeInFadeOut);

TextView tvContent = window.findViewById(R.id.tv_content);
Button tvCancel = window.findViewById(R.id.tv_cancel);
Button tvAgree = window.findViewById(R.id.tv_agree);
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(getResources().getString(R.string.app_protocol));
ssb.append(getResources().getString(R.string.app_agreement));

tvContent.setMovementMethod(LinkMovementMethod.getInstance());
tvContent.setText(ssb, TextView.BufferType.SPANNABLE);
Expand Down
143 changes: 117 additions & 26 deletions app/src/main/java/com/zcshou/gogogo/WelcomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
Expand All @@ -25,12 +29,15 @@
public class WelcomeActivity extends AppCompatActivity {
private static SharedPreferences preferences;
private static final String KEY_ACCEPT_AGREEMENT = "KEY_ACCEPT_AGREEMENT";
private static final String KEY_ACCEPT_PRIVACY = "KEY_ACCEPT_PRIVACY";

private static boolean isPermission = false;
private static final int SDK_PERMISSION_REQUEST = 127;
private static final ArrayList<String> ReqPermissions = new ArrayList<>();

private CheckBox checkBox;
private Boolean mAgreement;
private Boolean mPrivacy;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -44,13 +51,7 @@ protected void onCreate(Bundle savedInstanceState) {
Button startBtn = findViewById(R.id.startButton);
startBtn.setOnClickListener(v -> startMainActivity());

checkBox = findViewById(R.id.check_agreement);
checkBox.setOnClickListener(v -> showProtocolDialog());
preferences = getSharedPreferences(KEY_ACCEPT_AGREEMENT, MODE_PRIVATE);
checkBox.setChecked(preferences.getBoolean(KEY_ACCEPT_AGREEMENT, false));
if (checkBox.isChecked()) {
checkDefaultPermissions();
}
checkAgreementAndPrivacy();
}

@Override
Expand Down Expand Up @@ -146,52 +147,142 @@ private void startMainActivity() {
}
}

private void showProtocolDialog() {
private void doAccetion() {
if (mAgreement && mPrivacy) {
checkBox.setChecked(true);
checkDefaultPermissions();
} else {
checkBox.setChecked(false);
}
//实例化Editor对象
SharedPreferences.Editor editor = preferences.edit();
//存入数据
editor.putBoolean(KEY_ACCEPT_AGREEMENT, mAgreement);
editor.putBoolean(KEY_ACCEPT_PRIVACY, mPrivacy);
//提交修改
editor.apply();
}

private void showAgreementDialog() {
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.show();
alertDialog.setCancelable(false);
Window window = alertDialog.getWindow();
if (window != null) {
window.setContentView(R.layout.user_protocol);
window.setContentView(R.layout.user_agreement);
window.setGravity(Gravity.CENTER);
window.setWindowAnimations(R.style.DialogAnimFadeInFadeOut);

TextView tvContent = window.findViewById(R.id.tv_content);
Button tvCancel = window.findViewById(R.id.tv_cancel);
Button tvAgree = window.findViewById(R.id.tv_agree);
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(getResources().getString(R.string.app_protocol));
ssb.append(getResources().getString(R.string.app_agreement_content));
tvContent.setMovementMethod(LinkMovementMethod.getInstance());
tvContent.setText(ssb, TextView.BufferType.SPANNABLE);

tvCancel.setOnClickListener(v -> {
mAgreement = false;

checkBox.setChecked(false);

//实例化Editor对象
SharedPreferences.Editor editor = preferences.edit();
//存入数据
editor.putBoolean(KEY_ACCEPT_AGREEMENT, false);
//提交修改
editor.apply();
doAccetion();

alertDialog.cancel();
});

tvAgree.setOnClickListener(v -> {
checkBox.setChecked(true);
mAgreement = true;

doAccetion();

//实例化Editor对象
SharedPreferences.Editor editor = preferences.edit();
//存入数据
editor.putBoolean(KEY_ACCEPT_AGREEMENT, true);
//提交修改
editor.apply();
alertDialog.cancel();
});
}
}

checkDefaultPermissions();
private void showPrivacyDialog() {
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.show();
alertDialog.setCancelable(false);
Window window = alertDialog.getWindow();
if (window != null) {
window.setContentView(R.layout.user_privacy);
window.setGravity(Gravity.CENTER);
window.setWindowAnimations(R.style.DialogAnimFadeInFadeOut);

TextView tvContent = window.findViewById(R.id.tv_content);
Button tvCancel = window.findViewById(R.id.tv_cancel);
Button tvAgree = window.findViewById(R.id.tv_agree);
SpannableStringBuilder ssb = new SpannableStringBuilder();
ssb.append(getResources().getString(R.string.app_privacy_content));
tvContent.setMovementMethod(LinkMovementMethod.getInstance());
tvContent.setText(ssb, TextView.BufferType.SPANNABLE);

tvCancel.setOnClickListener(v -> {
mPrivacy = false;

doAccetion();

alertDialog.cancel();
});

tvAgree.setOnClickListener(v -> {
mPrivacy = true;

doAccetion();

alertDialog.cancel();
});
}
}

private void checkAgreementAndPrivacy() {
preferences = getSharedPreferences(KEY_ACCEPT_AGREEMENT, MODE_PRIVATE);
mPrivacy = preferences.getBoolean(KEY_ACCEPT_PRIVACY, false);
mAgreement = preferences.getBoolean(KEY_ACCEPT_AGREEMENT, false);

checkBox = findViewById(R.id.check_agreement);

String str = getString(R.string.app_agreement_privacy);
SpannableStringBuilder builder = new SpannableStringBuilder(str);
ClickableSpan clickSpanAgreement = new ClickableSpan() {
@Override
public void onClick( View widget) {
showAgreementDialog();
}

@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(getResources().getColor(R.color.colorPrimary, WelcomeActivity.this.getTheme()));
ds.setUnderlineText(false);
}
};
int agreement_start = str.indexOf("《");
int agreement_end = str.indexOf("》") + 1;
builder.setSpan(clickSpanAgreement, agreement_start,agreement_end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ClickableSpan clickSpanPrivacy = new ClickableSpan() {
@Override
public void onClick( View widget) {
showPrivacyDialog();
}

@Override
public void updateDrawState(TextPaint ds) {
ds.setColor(getResources().getColor(R.color.colorPrimary, WelcomeActivity.this.getTheme()));
ds.setUnderlineText(false);
}
};
int privacy_start = str.indexOf("《", agreement_end);
int privacy_end = str.indexOf("》", agreement_end) + 1;
builder.setSpan(clickSpanPrivacy, privacy_start, privacy_end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

checkBox.setText(builder);
checkBox.setMovementMethod(LinkMovementMethod.getInstance());

if (mPrivacy && mAgreement) {
checkBox.setChecked(true);
checkDefaultPermissions();
} else {
checkBox.setChecked(false);
}
}
}
6 changes: 4 additions & 2 deletions app/src/main/res/layout/activity_welcome.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:gravity="center"
android:text="@string/app_agreement_tips" />

android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="@string/app_agreement_privacy" />
</merge>
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="@string/app_protocol_title"
android:textColor="#282828"
android:textSize="20sp"
android:textStyle="bold" />

<ScrollView
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:layout_height="400dp">

<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:lineSpacingMultiplier="1.2"
android:textColor="#282828"
android:textSize="15sp" />
</ScrollView>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">

<Button
android:id="@+id/tv_cancel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/app_protocol_disagree"/>

<Space
android:layout_width="60dp"
android:layout_height="match_parent"/>

<Button
android:id="@+id/tv_agree"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/app_protocol_agree"/>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:text="@string/app_agreement"
android:textColor="#282828"
android:textSize="20sp"
android:textStyle="bold" />

<ScrollView
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:layout_height="400dp">

<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:lineSpacingMultiplier="1.2"
android:textColor="#282828"
android:textSize="15sp" />
</ScrollView>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">

<Button
android:id="@+id/tv_cancel"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/app_btn_disagree"/>

<Space
android:layout_width="60dp"
android:layout_height="match_parent"/>

<Button
android:id="@+id/tv_agree"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="@string/app_btn_agree"/>
</LinearLayout>
</LinearLayout>
Loading

0 comments on commit 497dfd4

Please sign in to comment.