aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/main/java/mygram/droid/LockActivity.java
blob: dd9591512144ef07bc656b654838308026fbbdd4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * mygram-droid: Android TV client for Foldergram.
 * Copyright (C) 2026 Danilo M. <danix@danix.xyz>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 * for more details.
 */

package mygram.droid;

import android.app.Activity;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

/** Splash with the logo and a PIN prompt; App shows it while the app is locked. */
public final class LockActivity extends Activity {
	@Override
	protected void onCreate(Bundle state) {
		super.onCreate(state);
		LinearLayout box = Ui.column(this);
		ImageView logo = new ImageView(this);
		logo.setImageResource(R.drawable.ic_launcher);
		logo.setContentDescription("mygram");
		int s = Ui.dp(this, 96);
		LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(s, s);
		lp.bottomMargin = Ui.dp(this, 24);
		box.addView(logo, lp);
		EditText pin = Ui.field(this, "PIN", InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
		box.addView(pin);
		View ok = Ui.iconButton(this, R.drawable.ic_check, "Unlock", v -> {
			if (Prefs.checkPin(pin.getText().toString())) {
				App.locked = false;
				finish();
			} else {
				pin.setText("");
				Toast.makeText(this, "Wrong PIN", Toast.LENGTH_SHORT).show();
			}
		});
		box.addView(ok);
		// The keyboard's done key unlocks; the D-pad cannot leave the keyboard.
		pin.setOnEditorActionListener((v, action, event) -> ok.performClick());
		setContentView(box);
		pin.requestFocus();
	}

	/** Back leaves the app instead of revealing the screen underneath. */
	@Override
	@SuppressWarnings("deprecation") // no predictive back on this TV; onBackPressed still fires
	public void onBackPressed() {
		finishAffinity();
	}
}