From 3ae8982fa1a851918fe5d902b42905ce0ceda87c Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Mon, 22 Sep 2014 13:29:34 +1000 Subject: Add a spinner for CPUs, plus some clean up. --- src/net/onefang/toyboxInstaller/MainActivity.java | 48 ++++++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'src/net') diff --git a/src/net/onefang/toyboxInstaller/MainActivity.java b/src/net/onefang/toyboxInstaller/MainActivity.java index 4186c2b..27051bf 100644 --- a/src/net/onefang/toyboxInstaller/MainActivity.java +++ b/src/net/onefang/toyboxInstaller/MainActivity.java @@ -9,19 +9,27 @@ import android.speech.*; public class MainActivity extends Activity implements AdapterView.OnItemSelectedListener { + private String requstedVersion = "latest"; + private String requestedCPU = ""; + private String requestedPath = ""; + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); + requestedCPU = java.lang.System.getProperty("os.arch"); TextView version = (TextView) findViewById(R.id.version); String VERSION = getString(R.string.version); Spinner versions = (Spinner) findViewById(R.id.versions); ArrayAdapter VERSIONS = ArrayAdapter.createFromResource(this, R.array.versions, android.R.layout.simple_spinner_item); - TextView cpu = (TextView) findViewById(R.id.cpu); - String CPU = getString(R.string.cpu); + TextView cpu = (TextView) findViewById(R.id.cpusPrompt); + String CPU = getString(R.string.cpusPrompt); + String CPU2 = getString(R.string.cpusPrompt2); + Spinner cpus = (Spinner) findViewById(R.id.cpus); + ArrayAdapter CPUS = ArrayAdapter.createFromResource(this, R.array.cpus, android.R.layout.simple_spinner_item); TextView path = (TextView) findViewById(R.id.path); String PATH = getString(R.string.path); Spinner paths = (Spinner) findViewById(R.id.paths); @@ -38,9 +46,13 @@ public class MainActivity extends Activity implements AdapterView.OnItemSelected VERSIONS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); versions.setAdapter(VERSIONS); versions.setOnItemSelectedListener(this); - cpu.setText(CPU + " " + java.lang.System.getProperty("os.arch") + ".\n"); - PATHS = new ArrayAdapter(this, android.R.layout.simple_spinner_item, - java.lang.System.getenv("PATH").split("\\" + pathSep)); + cpu.setText(CPU + " " + requestedCPU + " " + CPU2 + "\n"); + CPUS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + cpus.setAdapter(CPUS); + cpus.setSelection(CPUS.getPosition(requestedCPU)); + cpus.setOnItemSelectedListener(this); + PATHS = new ArrayAdapter(this, android.R.layout.simple_spinner_item, + java.lang.System.getenv("PATH").split("\\" + pathSep)); PATHS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); paths.setAdapter(PATHS); paths.setOnItemSelectedListener(this); @@ -53,25 +65,31 @@ public class MainActivity extends Activity implements AdapterView.OnItemSelected public void onItemSelected(AdapterView parent, View view, int pos, long id) { String s = (String) parent.getItemAtPosition(pos); - + TextView source = (TextView) findViewById(R.id.source); + String SOURCE = getString(R.string.source); + TextView destination = (TextView) findViewById(R.id.destination); + String DESTINATION = getString(R.string.destination); + switch (parent.getId()) { case R.id.versions : { - TextView source = (TextView) findViewById(R.id.source); - String SOURCE = getString(R.string.source); - - source.setText(SOURCE + " http://landley.net/code/toybox/downloads/binaries/" + s + "/toybox-\n"); + requstedVersion = s; break; } - case R.id.paths: + case R.id.cpus : + { + requestedCPU = s; + break; + } + case R.id.paths: { - TextView destination = (TextView) findViewById(R.id.destination); - String DESTINATION = getString(R.string.destination); - - destination.setText(DESTINATION + " " + s + "\n"); + requestedPath = s; + break; } } + source.setText(SOURCE + " http://landley.net/code/toybox/downloads/binaries/" + requstedVersion + "/toybox-" + requestedCPU + "\n"); + destination.setText(DESTINATION + " " + requestedPath + "\n"); } @Override -- cgit v1.1