summaryrefslogtreecommitdiff
path: root/app/java/src/MainActivity.java
blob: 9fd99f635237c94c20d90cac9e1c06309346c94c (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
64
65
66
67
68
package org.pihole.dnsproxy;

import android.app.Activity;
import android.app.AlertDialog;

import android.content.Intent;

import android.net.VpnService;

import android.os.Bundle;

import android.view.TextureView;
import android.view.View;

import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity {

    private Button buttonStart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        this.buttonStart = (Button) findViewById(R.id.button_start);
        this.buttonStart.setText(DNSService.isRunning() ? "Stop" : "Start");
    }

    @Override
    public void onResume() {
        super.onResume();
        this.buttonStart.setText("on RESSSSUME");
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {}

    public void onStartClick(View view) {
        Intent intent = VpnService.prepare(this);
        if (intent != null) {
            startActivityForResult(intent, 0);
        }
        //Intent intent = new Intent(this, DNSService.class);

        if (!DNSService.isRunning()) {
            startService(intent);

            new AlertDialog.Builder(this)
                .setTitle("PROXY START")
                .setMessage("BRRR")
                .show();
            Toast.makeText(this, "service starting", Toast.LENGTH_SHORT).show();
            this.buttonStart.setText("Stop");
        }
        else {
            stopService(intent);

            new AlertDialog.Builder(this)
                .setTitle("PROXY STOP")
                .setMessage("RRRB")
                .show();
            Toast.makeText(this, "service stopping", Toast.LENGTH_SHORT).show();
            this.buttonStart.setText("Start");
        }
    }
}