Advertisement
dartwlad

Untitled

Jan 8th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.97 KB | None | 0 0
  1. package com.example.appdroid;
  2.  
  3. import android.content.Context;
  4. import android.content.DialogInterface;
  5. import android.content.SharedPreferences;
  6. import android.os.Bundle;
  7. import android.support.v7.app.ActionBar;
  8. import android.support.v7.app.AlertDialog;
  9. import android.support.v7.app.AppCompatActivity;
  10. import android.support.v7.widget.Toolbar;
  11. import android.view.View;
  12. import android.widget.AdapterView;
  13. import android.widget.ArrayAdapter;
  14. import android.widget.EditText;
  15. import android.widget.ListView;
  16. import android.widget.TextView;
  17.  
  18. import static com.example.appdroid.R.id.action_settings;
  19. import static com.example.appdroid.R.id.toolbar;
  20.  
  21.  
  22.  
  23. public class Settings_activity extends AppCompatActivity
  24. {
  25.  
  26.     @Override
  27.     protected void onCreate(Bundle savedInstanceState)
  28.     {
  29.         super.onCreate(savedInstanceState);
  30.         setContentView(R.layout.activity_settings_activity);
  31.  
  32.         Toolbar tb = (Toolbar) findViewById(toolbar);
  33.         if(tb != null)
  34.         {
  35.             setSupportActionBar(tb);
  36.             ActionBar actionBar = getSupportActionBar();
  37.             if (actionBar != null)
  38.             {
  39.                 getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  40.                 getSupportActionBar().setDisplayShowHomeEnabled(true);
  41.                 getSupportActionBar().setTitle("Settings");
  42.             }
  43.  
  44.             final ListView listView = (ListView) findViewById(R.id.list);
  45.             String[] values = new String[]{"Diapazone", "Theme", "About"};
  46.  
  47.  
  48.             ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
  49.                     android.R.layout.simple_list_item_1, android.R.id.text1, values);
  50.  
  51.             listView.setAdapter(adapter);
  52.  
  53.  
  54.  
  55.             listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
  56.             {
  57.                 @Override
  58.                 public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
  59.                 {
  60.                     switch (i)
  61.                     {
  62.                         case 0: setDiapazoneDialog();
  63.                             break;
  64.                         case 1: setThemeDialog();
  65.                             break;
  66.                         case 2: setAboutDialog();
  67.                             break;
  68.  
  69.                     }
  70.  
  71.  
  72.                 }
  73.             });
  74.  
  75.         }
  76.  
  77.     }
  78.  
  79.  
  80.  
  81.  
  82.     private void setDiapazoneDialog()
  83.     {
  84.         AlertDialog.Builder builder = new AlertDialog.Builder(Settings_activity.this);
  85.         builder.setView(R.layout.dialog_diapason);
  86.         builder
  87.                 .setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() {
  88.                     public void onClick(DialogInterface dialog, int id) {
  89.                         EditText textView1 = (EditText) findViewById(R.id.min_value);
  90.                         EditText textView2 = (EditText) findViewById(R.id.max_value);
  91.                         SharedPreferences sharedPref = Settings_activity.this.getPreferences(Context.MODE_PRIVATE);
  92.                         SharedPreferences.Editor editor = sharedPref.edit();
  93.                         editor.putInt("min_value", Integer.parseInt(textView1.getText().toString()));
  94.                         editor.putInt("max_value", Integer.parseInt(textView2.getText().toString()));
  95.                         editor.apply();
  96.  
  97.  
  98.                     }
  99.                 })
  100.                 .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
  101.                     public void onClick(DialogInterface dialog, int id) {
  102.                         // User cancelled the dialog
  103.                     }
  104.                 });
  105.         AlertDialog dialog = builder.create();
  106.         dialog.show();
  107.     }
  108.  
  109.  
  110.  
  111.     private void setThemeDialog()
  112.     {
  113.         AlertDialog.Builder builder = new AlertDialog.Builder(Settings_activity.this);
  114.         builder.setItems(R.array.theme_colors, new DialogInterface.OnClickListener()
  115.         {
  116.             public void onClick(DialogInterface dialog, int which)
  117.             {
  118.                 switch (which)
  119.                 {
  120.                     case 0: setTheme(R.style.RedTheme);
  121.                         break;
  122.                     case 1: setTheme(R.style.BlueTheme);
  123.                         break;
  124.                     case 2:
  125.                         break;
  126.                 }
  127.  
  128.             }
  129.         });
  130.         AlertDialog dialog = builder.create();
  131.         dialog.show();
  132.     }
  133.     private void setAboutDialog()
  134.     {
  135.         AlertDialog.Builder builder = new AlertDialog.Builder(Settings_activity.this);
  136.         //builder.setTitle("Random App");
  137.         //builder.setMessage(R.string.about_message);
  138.         builder.setView(R.layout.about_dialog);
  139.         builder.setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() {
  140.                     public void onClick(DialogInterface dialog, int id) {
  141.  
  142.                     }
  143.                 });
  144.  
  145.  
  146.  
  147.         AlertDialog dialog = builder.create();
  148.         dialog.show();
  149.  
  150.     }
  151.  
  152.  
  153.  
  154. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement