daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.firstinspires.ftc.robotcontroller.internal;
  2.  
  3. import android.app.Activity;
  4. import android.content.Context;
  5. import android.content.SharedPreferences;
  6. import android.media.MediaPlayer;
  7. import android.os.Bundle;
  8. import android.preference.EditTextPreference;
  9. import android.preference.PreferenceManager;
  10. import android.util.Log;
  11. import android.view.View;
  12. import android.widget.AdapterView;
  13. import android.widget.ArrayAdapter;
  14. import android.widget.Button;
  15. import android.widget.EditText;
  16. import android.widget.Spinner;
  17. import android.widget.TextView;
  18.  
  19. import com.qualcomm.ftcrobotcontroller.R;
  20.  
  21. import java.io.File;
  22. import java.io.FileInputStream;
  23. import java.io.IOException;
  24. import java.util.ArrayList;
  25. import java.util.List;
  26.  
  27.  
  28. /**
  29.  * Autonomous Options - Related to additonal functionality added to RC - Distance, red or blue alliance
  30.  */
  31.  
  32. public class Autonomous_Options extends Activity implements AdapterView.OnItemSelectedListener  {
  33.  
  34.     SharedPreferences internalPreferences;
  35.     EditText distance;
  36.     TextView distance_text;
  37.  
  38.     Spinner alliance_colour_selector;
  39.     ArrayAdapter<String> alliance_colour_adapter;
  40.     List<String> alliance_colour_list = new ArrayList<>();
  41.     EditText alliance_colour_edit;
  42.     String alliance_colour;
  43.  
  44.     Spinner knockball_selector;
  45.     ArrayAdapter<String> knockball_adapter;
  46.     List<String> knockball_list = new ArrayList<>();
  47.     EditText knockball_edit;
  48.     String knockball_str;
  49.  
  50.     Spinner alliance_member_spin;
  51.     ArrayAdapter<String> alliance_member_adapter;
  52.     List<String> alliance_member_list = new ArrayList<>();
  53.     int alliance_member_int;
  54.  
  55.     Spinner team_spin;
  56.     ArrayAdapter<String> team_spin_adapter;
  57.     List<String> team_list = new ArrayList<>();
  58.     String team_str;
  59.  
  60.  
  61.  
  62.  
  63.     Button btn_save;
  64.  
  65.     double distance_val;
  66.  
  67.     @Override
  68.     protected void onCreate(Bundle savedInstanceState) {
  69.         super.onCreate(savedInstanceState);
  70.         setContentView(R.layout.autonomous_menu);
  71.         internalPreferences = this.getSharedPreferences("org.firstinspires.ftc.robotcontroller", Context.MODE_PRIVATE);
  72.         //open_settings();
  73.  
  74.         MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.startup_windows);
  75.         mp.start();
  76.         alliance_member_list.add("1");
  77.         alliance_member_list.add("2");
  78.  
  79.         alliance_colour_list.add("Red");
  80.         alliance_colour_list.add("Blue");
  81.  
  82.         knockball_list.add("Yes");
  83.         knockball_list.add("No");
  84.  
  85.         team_list.add("7840");
  86.         team_list.add("3666");
  87.  
  88.  
  89.         setupAllianceSelector();
  90.         setupAllianceMemberSpinner();
  91.         setupDistance();
  92.         setupKnockball();
  93.         btn_save = (Button) findViewById(R.id.save_btn);
  94.  
  95.     }
  96.  
  97.     public void saveAndExit(View v)
  98.     {
  99.         //commit changes
  100.         internalPreferences.edit().putFloat("Distance Travel", ((float) distance_val)).commit();
  101.         internalPreferences.edit().putString("Alliance Colour", alliance_colour).commit();
  102.         internalPreferences.edit().putString("Knock Ball", knockball_str).commit();
  103.         internalPreferences.edit().putInt("Alliance Member", alliance_member_int).commit();
  104.         save_settings();
  105.         MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.startup_windows);
  106.         mp.start();
  107.         finish();
  108.     }
  109.  
  110.     public void setupTeamSpinner()
  111.     {
  112.         team_spin = (Spinner) findViewById(R.id.team_spinner);
  113.         team_spin_adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, team_list);
  114.         team_spin_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  115.         team_spin.setAdapter(team_spin_adapter);
  116.         team_spin.setOnItemSelectedListener(this);
  117.         team_spin.setSelection(team_spin_adapter.getPosition(internalPreferences.getString("Team","")));
  118.  
  119.     }
  120.  
  121.     public void setupAllianceMemberSpinner()
  122.     {
  123.         alliance_member_spin = (Spinner) findViewById(R.id.alliance_member_spinner);
  124.         alliance_member_adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, alliance_member_list);
  125.         alliance_member_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  126.         alliance_member_spin.setAdapter(alliance_member_adapter);
  127.         alliance_member_spin.setOnItemSelectedListener(this);
  128.         alliance_member_spin.setSelection(alliance_member_adapter.getPosition(Integer.toString(internalPreferences.getInt("Alliance Member",0))));
  129.     }
  130.  
  131.  
  132.     public void setupAllianceSelector()
  133.     {
  134.         alliance_colour_selector = (Spinner) findViewById(R.id.alliance_selector);
  135.  
  136.         alliance_colour_adapter = new ArrayAdapter<>(this,android.R.layout.simple_spinner_item, alliance_colour_list);
  137.  
  138.         alliance_colour_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  139.  
  140.         alliance_colour_selector.setAdapter(alliance_colour_adapter);
  141.  
  142.         alliance_colour_selector.setOnItemSelectedListener(this);
  143.  
  144.         alliance_colour_selector.setSelection(alliance_colour_adapter.getPosition(internalPreferences.getString("Alliance Colour","")));
  145.  
  146.     }
  147.  
  148.     public void setupDistance()
  149.     {
  150.         distance = (EditText) findViewById(R.id.dist_value);
  151.         distance_text = (TextView) findViewById(R.id.dist_name);
  152.  
  153.     }
  154.  
  155.     public void setupKnockball()
  156.     {
  157.         knockball_selector = (Spinner) findViewById(R.id.knockball_spinner);
  158.  
  159.         knockball_adapter = new ArrayAdapter<>(this,android.R.layout.simple_spinner_item, knockball_list);
  160.  
  161.         knockball_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  162.  
  163.         knockball_selector.setAdapter(knockball_adapter);
  164.  
  165.         knockball_selector.setOnItemSelectedListener(this);
  166.  
  167.         knockball_selector.setSelection(knockball_adapter.getPosition(internalPreferences.getString("Knock Ball","")));
  168.  
  169.  
  170.     }
  171.  
  172.     @Deprecated
  173.     public void updateSettingsFromPrefs()
  174.     {
  175.  
  176.         Log.i("CREATION","I am in the updatePrefs");
  177.  
  178.        internalPreferences.getString("Alliance Colour", alliance_colour);
  179.         if (alliance_colour != null) {
  180.             if (alliance_colour.equals("Red")) {
  181.                 alliance_colour_selector.setSelection(0);
  182.             } else if (alliance_colour.equals("Blue")) {
  183.                 alliance_colour_selector.setSelection(1);
  184.             }
  185.         }
  186.         internalPreferences.getFloat("Distance Travel",(float) distance_val);
  187.         Log.i("CREATION","Distance Val"+ distance_val);
  188.         if (distance_val !=0)
  189.         {
  190.             Log.i("CREATION","I am in the updatePrefs-Distance");
  191.             distance.setText(Double.toString(distance_val));
  192.         }
  193.  
  194.     }
  195.  
  196.     public void save_settings() {
  197.  
  198.         //Merge Changes
  199.         SharedPreferences globalPrefs = PreferenceManager.getDefaultSharedPreferences(this);
  200.         SharedPreferences.Editor editor = globalPrefs.edit();
  201.         editor.putFloat("Distance Travel", ((float) distance_val));
  202.         editor.putString("Alliance Colour", internalPreferences.getString("Alliance Colour",""));
  203.         editor.putString("Knock Ball", internalPreferences.getString("Knock Ball",""));
  204.         editor.putInt("Alliance Member", internalPreferences.getInt("Alliance Member",0));
  205.         editor.apply();
  206.  
  207.     }
  208.  
  209.     @Override
  210.     public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
  211.  
  212.         if (parent.getId() == R.id.alliance_selector)
  213.         {
  214.             alliance_colour = parent.getItemAtPosition(position).toString();
  215.         }
  216.  
  217.         if (parent.getId() == R.id.knockball_spinner)
  218.         {
  219.             knockball_str = parent.getItemAtPosition(position).toString();
  220.         }
  221.  
  222.         if (parent.getId() == R.id.alliance_member_spinner)
  223.         {
  224.             alliance_member_int = Integer.parseInt(parent.getItemAtPosition(position).toString());
  225.         }
  226.     }
  227.  
  228.     @Override
  229.     public void onNothingSelected(AdapterView<?> parent) {
  230.  
  231.     }
  232. }
RAW Paste Data
Top