Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.appdroid;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.support.v7.app.ActionBar;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.Toolbar;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.ArrayAdapter;
- import android.widget.EditText;
- import android.widget.ListView;
- import android.widget.TextView;
- import static com.example.appdroid.R.id.action_settings;
- import static com.example.appdroid.R.id.toolbar;
- public class Settings_activity extends AppCompatActivity
- {
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_settings_activity);
- Toolbar tb = (Toolbar) findViewById(toolbar);
- if(tb != null)
- {
- setSupportActionBar(tb);
- ActionBar actionBar = getSupportActionBar();
- if (actionBar != null)
- {
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setDisplayShowHomeEnabled(true);
- getSupportActionBar().setTitle("Settings");
- }
- final ListView listView = (ListView) findViewById(R.id.list);
- String[] values = new String[]{"Diapazone", "Theme", "About"};
- ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
- android.R.layout.simple_list_item_1, android.R.id.text1, values);
- listView.setAdapter(adapter);
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
- {
- @Override
- public void onItemClick(AdapterView<?> adapterView, View view, int i, long l)
- {
- switch (i)
- {
- case 0: setDiapazoneDialog();
- break;
- case 1: setThemeDialog();
- break;
- case 2: setAboutDialog();
- break;
- }
- }
- });
- }
- }
- private void setDiapazoneDialog()
- {
- AlertDialog.Builder builder = new AlertDialog.Builder(Settings_activity.this);
- builder.setView(R.layout.dialog_diapason);
- builder
- .setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- EditText textView1 = (EditText) findViewById(R.id.min_value);
- EditText textView2 = (EditText) findViewById(R.id.max_value);
- SharedPreferences sharedPref = Settings_activity.this.getPreferences(Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = sharedPref.edit();
- editor.putInt("min_value", Integer.parseInt(textView1.getText().toString()));
- editor.putInt("max_value", Integer.parseInt(textView2.getText().toString()));
- editor.apply();
- }
- })
- .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- // User cancelled the dialog
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- }
- private void setThemeDialog()
- {
- AlertDialog.Builder builder = new AlertDialog.Builder(Settings_activity.this);
- builder.setItems(R.array.theme_colors, new DialogInterface.OnClickListener()
- {
- public void onClick(DialogInterface dialog, int which)
- {
- switch (which)
- {
- case 0: setTheme(R.style.RedTheme);
- break;
- case 1: setTheme(R.style.BlueTheme);
- break;
- case 2:
- break;
- }
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- }
- private void setAboutDialog()
- {
- AlertDialog.Builder builder = new AlertDialog.Builder(Settings_activity.this);
- //builder.setTitle("Random App");
- //builder.setMessage(R.string.about_message);
- builder.setView(R.layout.about_dialog);
- builder.setPositiveButton(R.string.okay, new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- }
- });
- AlertDialog dialog = builder.create();
- dialog.show();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement