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

Commit d741180

Browse files
Implemented function to save URL in SharedPreferences
1 parent d3939b5 commit d741180

4 files changed

Lines changed: 23 additions & 31 deletions

File tree

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</intent-filter>
2929
</activity>
3030

31-
<activity android:name=".SettingsActivity"></activity>
31+
<activity android:name=".SettingsActivity" />
3232
</application>
3333

3434
</manifest>

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class KioskActivity extends Activity {
3030
private final Context context = this;
3131
private WebView webView;
3232
private static String password = "1234";
33-
private static String URL = "https://naibaben.github.io/";
33+
private static String URL = "";
3434

3535
private final List blockedKeys = new ArrayList(Arrays.asList(KeyEvent.KEYCODE_VOLUME_DOWN,
3636
KeyEvent.KEYCODE_VOLUME_UP, KeyEvent.KEYCODE_BACK, KeyEvent.KEYCODE_HOME, KeyEvent.KEYCODE_POWER, KeyEvent.KEYCODE_APP_SWITCH));
@@ -71,6 +71,11 @@ protected void onCreate(Bundle savedInstanceState) {
7171

7272
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
7373

74+
prefs = this.getSharedPreferences(
75+
"com.coderbunker.kioskapp", Context.MODE_PRIVATE);
76+
77+
URL = prefs.getString("url", "https://naibaben.github.io/");
78+
7479
//Get the webView and load the URL
7580
webView = findViewById(R.id.webview);
7681
webView.setWebViewClient(new KioskWebviewClient());
@@ -93,9 +98,6 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
9398
}
9499
});
95100

96-
prefs = this.getSharedPreferences(
97-
"com.coderbunker.kioskapp", Context.MODE_PRIVATE);
98-
99101
TimerTask lock = new TimerTask() {
100102
@Override
101103
public void run() {

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

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.graphics.Color;
88
import android.support.v7.app.AppCompatActivity;
99
import android.os.Bundle;
10+
import android.view.KeyEvent;
1011
import android.view.View;
1112
import android.webkit.URLUtil;
1213
import android.widget.Button;
@@ -27,7 +28,7 @@ public class SettingsActivity extends Activity {
2728

2829
private Context context = this;
2930
private EditText editURL;
30-
private Button saveChanges;
31+
private SharedPreferences prefs;
3132

3233
private ImageView imgQRCode;
3334

@@ -38,34 +39,31 @@ protected void onCreate(Bundle savedInstanceState) {
3839
super.onCreate(savedInstanceState);
3940
setContentView(R.layout.activity_settings);
4041

41-
SharedPreferences prefs = this.getSharedPreferences(
42+
prefs = this.getSharedPreferences(
4243
"com.coderbunker.kioskapp", Context.MODE_PRIVATE);
4344

4445
imgQRCode = findViewById(R.id.imgQRCode);
4546
editURL = findViewById(R.id.editText_URL);
4647

47-
saveChanges = findViewById(R.id.button_save);
48-
saveChanges.setOnClickListener(new View.OnClickListener() {
4948

50-
@Override
51-
public void onClick(View view) {
49+
/* TODO Save after button press or change listener
5250
53-
boolean changed = false;
54-
String url = editURL.getText().toString();
51+
boolean changed = false;
52+
String url = editURL.getText().toString();
5553
56-
if (url != "" && URLUtil.isValidUrl(url)) {
57-
KioskActivity.setURL(editURL.getText().toString());
58-
changed = true;
59-
}
60-
61-
if (changed)
62-
Toast.makeText(context, "Changes saved!", LENGTH_LONG).show();
54+
if (url != "" && URLUtil.isValidUrl(url)) {
55+
prefs.edit().putString("url", url).apply();
56+
changed = true;
57+
}
6358
64-
finish();
65-
}
66-
});
59+
if (changed)
60+
Toast.makeText(context, "Changes saved!", LENGTH_LONG).show();*/
6761

6862
String otp = prefs.getString("otp", null);
63+
String url = prefs.getString("url", "https://naibaben.github.io/");
64+
65+
editURL.setText(url);
66+
6967
if (otp == null) {
7068

7169
byte key_1 = (byte) Math.floor(Math.random() * 10);

app/src/main/res/layout/activity_settings.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,6 @@
4646
android:inputType="textUri"
4747
android:hint="Enter the URL here..."/>
4848

49-
<Button
50-
android:id="@+id/button_save"
51-
android:layout_width="wrap_content"
52-
android:layout_height="wrap_content"
53-
android:layout_gravity="center_horizontal"
54-
android:layout_marginTop="50dp"
55-
android:text="Save changes" />
56-
5749

5850
</LinearLayout>
5951

0 commit comments

Comments
 (0)