Welcome to mirror list, hosted at ThFree Co, Russian Federation.

MainActivity.java « sonyheadphonescontrol « clusterrr « com « java « main « src « app - github.com/ClusterM/sony-headphones-control.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ceb4e16fc8615a4f073bf0ad99ced26f504ca350 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package com.clusterrr.sonyheadphonescontrol;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.SeekBar;
import android.widget.Switch;

import com.twofortyfouram.spackle.bundle.BundleScrubber;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, SeekBar.OnSeekBarChangeListener, CompoundButton.OnCheckedChangeListener {
    int mode = 0;
    int volume = 20;
    boolean voice = false;

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

        Intent intent = getIntent();
        Bundle bundle = null;
        if (intent != null) {
            BundleScrubber.scrub(intent);
            bundle = intent.getBundleExtra(TaskerFireReceiver.EXTRA_BUNDLE);
        }
        if (bundle != null) {
            BundleScrubber.scrub(bundle);
            int mode = bundle.getInt(TaskerFireReceiver.EXTRA_STRING_MODE, 0);
            switch (mode) {
                case 0:
                    ((RadioButton) findViewById(R.id.radioButtonDisable)).setChecked(true);
                    break;
                case 1:
                    ((RadioButton) findViewById(R.id.radioButtonNoiseCancelling)).setChecked(true);
                    break;
                case 2:
                    ((RadioButton) findViewById(R.id.radioButtonWindCancelling)).setChecked(true);
                    break;
                case 3:
                    int volume = bundle.getInt(TaskerFireReceiver.EXTRA_STRING_VOLUME, 20);
                    boolean voice = bundle.getBoolean(TaskerFireReceiver.EXTRA_STRING_VOICE, false);
                    ((RadioButton) findViewById(R.id.radioButtonAmbientSound)).setChecked(true);
                    ((SeekBar) findViewById(R.id.seekBarVolume)).setProgress(volume);
                    ((Switch) findViewById(R.id.switchVoiceOptimized)).setChecked(voice);
            }
        }

        ((RadioButton) findViewById(R.id.radioButtonDisable)).setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radioButtonNoiseCancelling)).setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radioButtonWindCancelling)).setOnCheckedChangeListener(this);
        ((RadioButton) findViewById(R.id.radioButtonAmbientSound)).setOnCheckedChangeListener(this);
        ((SeekBar) findViewById(R.id.seekBarVolume)).setOnSeekBarChangeListener(this);
        ((Switch) findViewById(R.id.switchVoiceOptimized)).setOnCheckedChangeListener(this);

        ((Button) findViewById(R.id.buttonTest)).setOnClickListener(this);
        ((Button) findViewById(R.id.buttonSave)).setOnClickListener(this);

        saveSettings();
    }

    void saveSettings() {
        String blurb = "";

        if (((RadioButton) findViewById(R.id.radioButtonDisable)).isChecked()) {
            mode = 0;
            blurb = ((RadioButton) findViewById(R.id.radioButtonDisable)).getText().toString();
        } else if (((RadioButton) findViewById(R.id.radioButtonNoiseCancelling)).isChecked()) {
            mode = 1;
            blurb = ((RadioButton) findViewById(R.id.radioButtonNoiseCancelling)).getText().toString();
        } else if (((RadioButton) findViewById(R.id.radioButtonWindCancelling)).isChecked()) {
            mode = 2;
            blurb = ((RadioButton) findViewById(R.id.radioButtonWindCancelling)).getText().toString();
        } else if (((RadioButton) findViewById(R.id.radioButtonAmbientSound)).isChecked()) {
            mode = 3;
            volume = ((SeekBar) findViewById(R.id.seekBarVolume)).getProgress();
            voice = ((Switch) findViewById(R.id.switchVoiceOptimized)).isChecked();
            blurb = ((RadioButton) findViewById(R.id.radioButtonAmbientSound)).getText().toString() +
                    ", volume=" + volume + (voice ? ", voice optimized" : "");
        }

        Intent resultIntent = new Intent();
        final Bundle resultBundle = new Bundle();
        resultBundle.putInt(TaskerFireReceiver.EXTRA_STRING_MODE, mode);
        resultBundle.putInt(TaskerFireReceiver.EXTRA_STRING_VOLUME, volume);
        resultBundle.putBoolean(TaskerFireReceiver.EXTRA_STRING_VOICE, voice);
        resultIntent.putExtra(TaskerFireReceiver.EXTRA_BUNDLE, resultBundle);
        resultIntent.putExtra(TaskerFireReceiver.EXTRA_STRING_BLURB, blurb);
        setResult(RESULT_OK, resultIntent);

        ((SeekBar) findViewById(R.id.seekBarVolume)).setEnabled(mode == 3);
        ((Switch) findViewById(R.id.switchVoiceOptimized)).setEnabled(mode == 3);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.buttonTest:
                TaskerFireReceiver.execute(this, null, mode, volume, voice);
                break;
            case R.id.buttonSave:
                finish();
                break;
        }
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        saveSettings();
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        saveSettings();
    }
}