Skip to content

Commit

Permalink
Add warning dialog on AR use (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
ning-y committed Aug 18, 2019
1 parent d751193 commit 1d098ff
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
// AR Required apps must declare minSdkVersion >= 24.
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName "1.0.0"
versionCode 2
versionName "1.0.1"
ndk {
/*
* Sceneform is available for the following ABIs:
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/java/io/ningyuan/palantir/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package io.ningyuan.palantir;

import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ProgressBar;
import android.widget.TextView;

Expand Down Expand Up @@ -45,6 +50,8 @@ protected void onCreate(Bundle savedInstanceState) {

sceneformFragment = (SceneformFragment) getSupportFragmentManager().findFragmentById(R.id.ux_fragment);
sceneformFragment.setParentActivity(this);

setWarningDialog();
}

public void doRender(String pdbId) {
Expand All @@ -65,4 +72,27 @@ public void updateModelRenderable(String name, File glbFile) {
public void showAbout() {
aboutView.show();
}

private void setWarningDialog() {
SharedPreferences preferences = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor preferenceEditor = preferences.edit();

View warningDialogLayout = getLayoutInflater().inflate(R.layout.warning_dialog, null);
CheckBox warningDialogCheckbox = warningDialogLayout.findViewById(R.id.warning_dialog_checkbox);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(warningDialogLayout)
.setPositiveButton("OK.", (DialogInterface di, int which) -> {
preferenceEditor.putBoolean(
getString(R.string.should_show_warning),
!warningDialogCheckbox.isChecked()
);
preferenceEditor.commit();
di.dismiss();
});

boolean shouldShowWarning = preferences.getBoolean(getString(R.string.should_show_warning), true);
if (shouldShowWarning) {
builder.create().show();
}
}
}
19 changes: 19 additions & 0 deletions app/src/main/res/layout/warning_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="@string/warning_dialog_content"/>

<CheckBox
android:id="@+id/warning_dialog_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/warning_dialog_checkbox"/>

</LinearLayout>
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
<!-- If app name changes, also do a grep/find for other occurrences in this file -->
<string name="app_name">Palantir</string>

<string name="should_show_warning">SHOULD_SHOW_WARNING</string>
<string name="warning_dialog_content">
Be aware of your surroundings when you use augmented reality!
If you are unsure of how to use this application safely, please find guidance from a responsible adult.
</string>
<string name="warning_dialog_checkbox">Don\'t show this warning again.</string>

<string name="about_title">
<![CDATA[
<h1>About</h1>
Expand Down

0 comments on commit 1d098ff

Please sign in to comment.