SettingsActivity.java
1    package com.asimplesock.chatistics;
2    
3    import android.content.SharedPreferences;
4    import android.os.Bundle;
5    import android.view.MotionEvent;
6    import android.view.View;
7    import android.widget.Button;
8    import android.widget.CompoundButton;
9    import android.widget.ImageView;
10   import android.widget.Switch;
11   import android.widget.TextView;
12   import android.widget.Toast;
13   
14   import androidx.appcompat.app.AppCompatActivity;
15   import androidx.constraintlayout.widget.ConstraintLayout;
16   
17   import com.apandroid.colorwheel.ColorWheel;
18   import com.apandroid.colorwheel.gradientseekbar.GradientSeekBar;
19   
20   public class SettingsActivity extends AppCompatActivity {
21   
22       @Override
23       protected void onCreate(Bundle savedInstanceState) {
24           super.onCreate(savedInstanceState);
25           setContentView(R.layout.activity_settings);
26           Switch forcedGroupSwitch = findViewById(R.id.force_group_switch);
27           Switch singleSwitch = findViewById(R.id.single_switch);
28           final ColorWheel colorWheelOne = findViewById(R.id.colorWheelOne);
29           final ColorWheel colorWheelTwo = findViewById(R.id.colorWheelTwo);
30           final SharedPreferences sharedPreferences = getSharedPreferences("data", MODE_PRIVATE);
31           boolean forceGroup = sharedPreferences.getBoolean("forceGroup", false);
32           boolean single = sharedPreferences.getBoolean("single", true);
33           final int[] color_one = {sharedPreferences.getInt("color_one", getColor(R.color.cyan))};
34           final int[] color_two = {sharedPreferences.getInt("color_two", getColor(R.color.pinkie))};
35           final int[] back_color = {sharedPreferences.getInt("back_color", getColor(R.color.colorPrimary))};
36           final TextView colorOne = findViewById(R.id.color_one);
37           final TextView colorTwo = findViewById(R.id.color_two);
38           final TextView textView104 = findViewById(R.id.textView104);
39           final Button apply = findViewById(R.id.button_apply);
40           final GradientSeekBar gradientSeekBar = findViewById(R.id.gradient_seek_bar);
41           final ConstraintLayout constraintLayout = findViewById(R.id.root_settings);
42           ImageView reset_colors = findViewById(R.id.reset_colors);
43   
44   
45           colorWheelOne.setRgb(color_one[0]);
46           colorWheelTwo.setRgb(color_two[0]);
47           colorOne.setBackgroundColor(color_one[0]);
48           colorTwo.setBackgroundColor(color_two[0]);
49           textView104.setBackgroundColor(color_one[0]);
50           gradientSeekBar.setThumbColor(back_color[0]);
51           constraintLayout.setBackgroundColor(back_color[0]);
52   
53           reset_colors.setOnClickListener(new View.OnClickListener() {
54               @Override
55               public void onClick(View v) {
56                   color_one[0] = getColor(R.color.cyan);
57                   color_two[0] = getColor(R.color.pinkie);
58                   back_color[0] = getColor(R.color.colorPrimary);
59                   SharedPreferences sharedPreferences = getSharedPreferences("data", MODE_PRIVATE);
60                   SharedPreferences.Editor editor = sharedPreferences.edit();
61                   editor.putInt("color_one", color_one[0]);
62                   editor.putInt("color_two", color_two[0]);
63                   editor.putInt("back_color", back_color[0]);
64                   colorOne.setBackgroundColor(color_one[0]);
65                   colorTwo.setBackgroundColor(color_two[0]);
66                   colorWheelOne.setRgb(color_one[0]);
67                   colorWheelTwo.setRgb(color_two[0]);
68                   constraintLayout.setBackgroundColor(back_color[0]);
69                   editor.apply();
70               }
71           });
72   
73           gradientSeekBar.setOnTouchListener(new View.OnTouchListener() {
74               @Override
75               public boolean onTouch(View v, MotionEvent event) {
76                   int back_color = gradientSeekBar.getArgb();
77                   constraintLayout.setBackgroundColor(back_color);
78                   return false;
79               }
80           });
81   
82           forcedGroupSwitch.setChecked(forceGroup);
83           forcedGroupSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
84               public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
85                   SharedPreferences sharedPreferences = getSharedPreferences("data", MODE_PRIVATE);
86                   SharedPreferences.Editor editor = sharedPreferences.edit();
87                   editor.putBoolean("forceGroup", isChecked);
88                   editor.apply();
89                   //Toast.makeText(SettingsActivity.this,""+isChecked,Toast.LENGTH_SHORT).show();
90               }
91           });
92   
93           singleSwitch.setChecked(single);
94           singleSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
95               @Override
96               public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
97                   SharedPreferences sharedPreferences = getSharedPreferences("data", MODE_PRIVATE);
98                   SharedPreferences.Editor editor = sharedPreferences.edit();
99                   editor.putBoolean("single", isChecked);
100                  editor.apply();
101              }
102          });
103  
104          colorWheelOne.setOnTouchListener(new View.OnTouchListener() {
105              @Override
106              public boolean onTouch(View v, MotionEvent event) {
107                  int color_one = colorWheelOne.getRgb();
108                  colorOne.setBackgroundColor(color_one);
109                  textView104.setBackgroundColor(color_one);
110                  return false;
111              }
112          });
113  
114          colorWheelTwo.setOnTouchListener(new View.OnTouchListener() {
115              @Override
116              public boolean onTouch(View v, MotionEvent event) {
117                  int color_two = colorWheelTwo.getRgb();
118                  colorTwo.setBackgroundColor(color_two);
119                  return false;
120              }
121          });
122  
123  
124          apply.setOnClickListener(new View.OnClickListener() {
125              @Override
126              public void onClick(View v) {
127                  int color_one = colorWheelOne.getRgb();
128                  int color_two = colorWheelTwo.getRgb();
129                  int back_color = gradientSeekBar.getArgb();
130                  SharedPreferences sharedPreferences = getSharedPreferences("data", MODE_PRIVATE);
131                  SharedPreferences.Editor editor = sharedPreferences.edit();
132                  editor.putInt("color_one", color_one);
133                  editor.putInt("color_two", color_two);
134                  editor.putInt("back_color", back_color);
135                  colorOne.setBackgroundColor(color_one);
136                  colorTwo.setBackgroundColor(color_two);
137                  editor.apply();
138                  Toast.makeText(SettingsActivity.this, "Applied", Toast.LENGTH_SHORT).show();
139              }
140          });
141  
142  
143  
144      }
145  }