forked from
lass.pds.lassul.us/superconfig
This repository has no description
1.6 kB
57 lines
1package us.lassul.assist;
2
3import android.app.Activity;
4import android.app.KeyguardManager;
5import android.content.Intent;
6import android.os.Bundle;
7
8/**
9 * Entry point (launcher, assist gesture, headset VOICE_COMMAND): unlocks if needed and opens the
10 * voice page, which starts listening at once (?listen).
11 */
12public class AssistActivity extends Activity {
13 private boolean launched;
14
15 @Override
16 protected void onCreate(Bundle state) {
17 super.onCreate(state);
18 KeyguardManager keyguard = getSystemService(KeyguardManager.class);
19 if (!keyguard.isKeyguardLocked()) {
20 open();
21 return;
22 }
23 // Started over the lock screen (showWhenLocked): the browser cannot show there.
24 keyguard.requestDismissKeyguard(this, new KeyguardManager.KeyguardDismissCallback() {
25 @Override
26 public void onDismissSucceeded() {
27 open();
28 }
29
30 @Override
31 public void onDismissCancelled() {
32 finish();
33 }
34
35 @Override
36 public void onDismissError() {
37 finish();
38 }
39 });
40 }
41
42 private void open() {
43 launched = true;
44 // Started now, while this activity is in front: from the background Android refuses it.
45 startForegroundService(new Intent(this, CallService.class));
46 Link.open(this);
47 }
48
49 // Back from the page: this activity only sits below it in the task.
50 @Override
51 protected void onRestart() {
52 super.onRestart();
53 if (launched) {
54 finish();
55 }
56 }
57}