Skip to content
This repository was archived by the owner on Sep 13, 2024. It is now read-only.

Commit 72cdea6

Browse files
Fixed bug with saving URL and implemented function to prevent home button click
1 parent d741180 commit 72cdea6

5 files changed

Lines changed: 99 additions & 72 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@
88

99

1010
<application
11-
android:allowBackup="true"
11+
android:allowBackup="false"
1212
android:icon="@mipmap/ic_launcher"
1313
android:label="@string/app_name"
14+
android:launchMode="singleTask"
1415
android:roundIcon="@mipmap/ic_launcher_round"
15-
android:supportsRtl="true"
16-
android:theme="@style/AppTheme">
16+
android:stateNotNeeded="true"
17+
android:supportsRtl="true">
1718
<activity android:name=".MainActivity">
18-
<intent-filter>
19-
<action android:name="android.intent.action.MAIN" />
2019

21-
<category android:name="android.intent.category.LAUNCHER" />
22-
</intent-filter>
2320
</activity>
2421
<activity android:name=".KioskActivity">
2522
<intent-filter>
23+
<action android:name="android.intent.action.MAIN" />
24+
25+
<category android:name="android.intent.category.LAUNCHER" />
2626
<category android:name="android.intent.category.HOME" />
2727
<category android:name="android.intent.category.DEFAULT" />
2828
</intent-filter>

app/src/main/java/com/coderbunker/kioskapp/KioskActivity.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.app.Dialog;
55
import android.content.Context;
66
import android.content.DialogInterface;
7+
import android.content.Intent;
78
import android.content.SharedPreferences;
89
import android.content.pm.ActivityInfo;
910
import android.os.Bundle;
@@ -81,6 +82,7 @@ protected void onCreate(Bundle savedInstanceState) {
8182
webView.setWebViewClient(new KioskWebviewClient());
8283
webView.getSettings().setJavaScriptEnabled(true);
8384
webView.loadUrl(URL);
85+
Toast.makeText(this, "Loading " + URL, Toast.LENGTH_SHORT).show();
8486

8587
webView.setOnTouchListener(new View.OnTouchListener() {
8688

@@ -190,28 +192,38 @@ public void enterNumber(String number) {
190192

191193
}
192194

195+
private void launchHome() {
196+
Intent intent = new Intent(KioskActivity.this, MainActivity.class);
197+
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TOP);
198+
startActivity(intent);
199+
finish();
200+
}
201+
193202
private void checkPwd() {
194203
String otp = prefs.getString("otp", null);
195-
String pwd = b1.getText().toString() + b2.getText().toString() + b3.getText().toString() + b4.getText().toString() + b5.getText().toString() + b6.getText().toString();
196-
String generated_number = TOTP.generateCurrentNumber(otp, System.currentTimeMillis());
197-
String previous_generated_number = TOTP.generateCurrentNumber(otp, System.currentTimeMillis() - 30000);
198-
199-
if (pwd.equals(generated_number) || pwd.equals(previous_generated_number)) {
200-
Toast.makeText(context, "PIN correct", Toast.LENGTH_SHORT).show();
201-
finish();
204+
if (otp == null) {
205+
Toast.makeText(context, "Please go to the settings and create a password", Toast.LENGTH_SHORT).show();
206+
launchHome();
202207
} else {
203-
dialog.dismiss();
204-
dialogPrompted = false;
205-
Toast.makeText(context, "Wrong PIN", Toast.LENGTH_SHORT).show();
208+
String pwd = b1.getText().toString() + b2.getText().toString() + b3.getText().toString() + b4.getText().toString() + b5.getText().toString() + b6.getText().toString();
209+
String generated_number = TOTP.generateCurrentNumber(otp, System.currentTimeMillis());
210+
String previous_generated_number = TOTP.generateCurrentNumber(otp, System.currentTimeMillis() - 30000);
211+
212+
if (pwd.equals(generated_number) || pwd.equals(previous_generated_number)) {
213+
Toast.makeText(context, "PIN correct", Toast.LENGTH_SHORT).show();
214+
launchHome();
215+
} else {
216+
dialog.dismiss();
217+
dialogPrompted = false;
218+
Toast.makeText(context, "Wrong PIN", Toast.LENGTH_SHORT).show();
219+
}
206220
}
207221

208222
cptPwd = 0;
209223
}
210224

211225
@Override
212226
public boolean dispatchKeyEvent(KeyEvent event) {
213-
214-
215227
if (blockedKeys.contains(event.getKeyCode())) {
216228
return true;
217229
} else {

app/src/main/java/com/coderbunker/kioskapp/KioskWebviewClient.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
import android.webkit.SslErrorHandler;
55
import android.webkit.WebView;
66
import android.webkit.WebViewClient;
7+
import android.widget.Toast;
78

89
class KioskWebviewClient extends WebViewClient {
910

10-
private String URL = "https://naibaben.github.io/";
11-
1211
@Override
1312
public boolean shouldOverrideUrlLoading(WebView view, String url) {
14-
15-
if(url.contains(url)) {
13+
if (url.contains(url)) {
1614
view.loadUrl(url);
1715
}
1816
return true;

app/src/main/java/com/coderbunker/kioskapp/SettingsActivity.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ public class SettingsActivity extends Activity {
2828

2929
private Context context = this;
3030
private EditText editURL;
31-
private SharedPreferences prefs;
32-
3331
private ImageView imgQRCode;
32+
private Button btnSave;
33+
34+
private SharedPreferences prefs;
3435

3536
private String otp_uri;
3637

@@ -44,20 +45,24 @@ protected void onCreate(Bundle savedInstanceState) {
4445

4546
imgQRCode = findViewById(R.id.imgQRCode);
4647
editURL = findViewById(R.id.editText_URL);
48+
btnSave = findViewById(R.id.btnSave);
4749

4850

49-
/* TODO Save after button press or change listener
51+
btnSave.setOnClickListener(new View.OnClickListener() {
52+
@Override
53+
public void onClick(View v) {
54+
boolean changed = false;
55+
String url = editURL.getText().toString();
5056

51-
boolean changed = false;
52-
String url = editURL.getText().toString();
53-
54-
if (url != "" && URLUtil.isValidUrl(url)) {
55-
prefs.edit().putString("url", url).apply();
56-
changed = true;
57-
}
57+
if (url != "" && URLUtil.isValidUrl(url)) {
58+
prefs.edit().putString("url", url).apply();
59+
changed = true;
60+
}
5861

59-
if (changed)
60-
Toast.makeText(context, "Changes saved!", LENGTH_LONG).show();*/
62+
if (changed)
63+
Toast.makeText(context, "Changes saved!", LENGTH_LONG).show();
64+
}
65+
});
6166

6267
String otp = prefs.getString("otp", null);
6368
String url = prefs.getString("url", "https://naibaben.github.io/");
Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,64 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
xmlns:tools="http://schemas.android.com/tools"
5+
android:id="@+id/root"
56
android:layout_width="match_parent"
67
android:layout_height="match_parent"
78
android:orientation="vertical"
89
tools:context=".SettingsActivity">
910

10-
<LinearLayout
11+
<ScrollView
12+
android:id="@+id/scrollView"
1113
android:layout_width="match_parent"
12-
android:layout_height="match_parent"
13-
android:orientation="vertical">
14+
android:layout_height="match_parent">
1415

15-
16-
<TextView
17-
android:id="@+id/textView_otp"
18-
android:layout_width="match_parent"
19-
android:layout_height="wrap_content"
20-
android:gravity="center_horizontal"
21-
android:paddingVertical="20dp"
22-
android:text="OTP"
23-
android:textColor="@android:color/black"
24-
android:textSize="22dp" />
25-
26-
<ImageView
27-
android:id="@+id/imgQRCode"
16+
<LinearLayout
2817
android:layout_width="match_parent"
29-
android:layout_height="wrap_content"
30-
android:src="@drawable/ic_launcher_background" />
18+
android:layout_height="match_parent"
19+
android:orientation="vertical">
3120

32-
<TextView
33-
android:id="@+id/textView_URL"
34-
android:layout_width="match_parent"
35-
android:layout_height="wrap_content"
36-
android:textColor="@android:color/black"
37-
android:textSize="22dp"
38-
android:gravity="center_horizontal"
39-
android:paddingVertical="20dp"
40-
android:text="URL" />
41-
42-
<EditText
43-
android:id="@+id/editText_URL"
44-
android:layout_width="match_parent"
45-
android:layout_height="wrap_content"
46-
android:inputType="textUri"
47-
android:hint="Enter the URL here..."/>
4821

22+
<TextView
23+
android:id="@+id/textView_otp"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:gravity="center_horizontal"
27+
android:paddingVertical="20dp"
28+
android:text="TOTP"
29+
android:textColor="@android:color/black"
30+
android:textSize="22dp" />
31+
32+
<ImageView
33+
android:id="@+id/imgQRCode"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
android:src="@drawable/ic_launcher_background" />
37+
38+
<TextView
39+
android:id="@+id/textView_URL"
40+
android:layout_width="match_parent"
41+
android:layout_height="wrap_content"
42+
android:gravity="center_horizontal"
43+
android:paddingVertical="20dp"
44+
android:text="URL"
45+
android:textColor="@android:color/black"
46+
android:textSize="22dp" />
47+
48+
<EditText
49+
android:id="@+id/editText_URL"
50+
android:layout_width="match_parent"
51+
android:layout_height="wrap_content"
52+
android:hint="Enter the URL here..."
53+
android:inputType="textUri" />
54+
55+
<Button
56+
android:id="@+id/btnSave"
57+
android:layout_width="match_parent"
58+
android:layout_height="wrap_content"
59+
android:text="Save" />
4960

50-
</LinearLayout>
5161

52-
</LinearLayout>
62+
</LinearLayout>
63+
</ScrollView>
64+
</RelativeLayout>

0 commit comments

Comments
 (0)