mmayoub

MathApp, SettingsActivity.java

Sep 11th, 2021 (edited)
1,038
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.71 KB | None | 0 0
  1. package com.example.mathapplication;
  2.  
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.widget.CheckBox;
  6. import android.widget.SeekBar;
  7. import android.widget.TextView;
  8. import android.widget.Toast;
  9.  
  10. import androidx.appcompat.app.AppCompatActivity;
  11.  
  12. public class SettingsActivity extends AppCompatActivity {
  13.     SeekBar skbMin, skbMax;
  14.     TextView tvMin, tvMax;
  15.     CheckBox chkAdd, chkSub, chkMul, chkDiv;
  16.  
  17.     @Override
  18.     protected void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.activity_settings);
  21.  
  22.         skbMin = findViewById(R.id.skbMin);
  23.         skbMax = findViewById(R.id.skbMax);
  24.         tvMin = findViewById(R.id.tvMin);
  25.         tvMax = findViewById(R.id.tvMax);
  26.         chkAdd = findViewById(R.id.chkAdd);
  27.         chkSub = findViewById(R.id.chkSub);
  28.         chkMul = findViewById(R.id.chkMul);
  29.         chkDiv = findViewById(R.id.chkDiv);
  30.  
  31.         skbMin.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
  32.             @Override
  33.             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
  34.                 tvMin.setText("min = " + progress);
  35.             }
  36.  
  37.             @Override
  38.             public void onStartTrackingTouch(SeekBar seekBar) {
  39.  
  40.             }
  41.  
  42.             @Override
  43.             public void onStopTrackingTouch(SeekBar seekBar) {
  44.  
  45.             }
  46.         });
  47.  
  48.         skbMax.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
  49.             @Override
  50.             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
  51.                 tvMax.setText("max = " + progress);
  52.             }
  53.  
  54.             @Override
  55.             public void onStartTrackingTouch(SeekBar seekBar) {
  56.  
  57.             }
  58.  
  59.             @Override
  60.             public void onStopTrackingTouch(SeekBar seekBar) {
  61.  
  62.             }
  63.         });
  64.         skbMin.setProgress(Settings.min);
  65.         skbMax.setProgress(Settings.max);
  66.  
  67.         chkAdd.setChecked(Settings.add);
  68.         chkSub.setChecked(Settings.sub);
  69.         chkMul.setChecked(Settings.mul);
  70.         chkDiv.setChecked(Settings.div);
  71.     }
  72.  
  73.     public void saveSettingsCLicked(View view) {
  74.         Settings.min = skbMin.getProgress();
  75.         Settings.max = skbMax.getProgress();
  76.         Settings.add = chkAdd.isChecked();
  77.         Settings.sub = chkSub.isChecked();
  78.         Settings.mul = chkMul.isChecked();
  79.         Settings.div = chkDiv.isChecked();
  80.  
  81.         Settings.saveSettings(this);
  82.         Toast.makeText(this, "Settings saved successfully !!!", Toast.LENGTH_LONG).show();
  83.         finish();
  84.     }
  85.  
  86.     public void cancelClicked(View view) {
  87.         finish();
  88.     }
  89. }
Add Comment
Please, Sign In to add comment