aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/top/trumeet/redirectstorage/simple/MainActivity.java
blob: adb493f626baf531450d7660d26ad7ed3b110b01 (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
package top.trumeet.redirectstorage.simple;

import android.app.Activity;
import android.os.Bundle;
import android.os.Environment;
import android.text.Html;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;

import java.io.File;

import top.trumeet.redirectstorage.PathCallback;
import top.trumeet.redirectstorage.RedirectStorage;

public class MainActivity extends Activity {

    private TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = findViewById(R.id.text);
        updateText();
        Switch s = findViewById(R.id.switch_widget);
        s.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if (b) {
                    RedirectStorage.enable(new PathCallback() {
                        @Override
                        public File onModify(File original) {
                            return getFilesDir();
                        }
                    });
                } else {
                    RedirectStorage.disable();
                }
                updateText();
            }
        });
    }

    private void updateText () {
        textView.setText(Html.fromHtml(getString(R.string.text,
                Environment.getExternalStorageDirectory().getAbsolutePath(),
                String.valueOf(RedirectStorage.isEnable()),
                RedirectStorage.getRealPath())));
    }
}