diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/net/onefang/toyboxInstaller/MainActivity.java | 182 | 
1 files changed, 97 insertions, 85 deletions
| diff --git a/src/net/onefang/toyboxInstaller/MainActivity.java b/src/net/onefang/toyboxInstaller/MainActivity.java index 27051bf..36b2b5f 100644 --- a/src/net/onefang/toyboxInstaller/MainActivity.java +++ b/src/net/onefang/toyboxInstaller/MainActivity.java | |||
| @@ -5,100 +5,112 @@ import android.os.*; | |||
| 5 | import android.view.*; | 5 | import android.view.*; | 
| 6 | import android.widget.*; | 6 | import android.widget.*; | 
| 7 | import java.lang.System.*; | 7 | import java.lang.System.*; | 
| 8 | import android.net.*; | ||
| 8 | import android.speech.*; | 9 | import android.speech.*; | 
| 9 | 10 | ||
| 10 | public class MainActivity extends Activity implements AdapterView.OnItemSelectedListener | 11 | public class MainActivity extends Activity implements AdapterView.OnItemSelectedListener | 
| 11 | { | 12 | { | 
| 12 | private String requstedVersion = "latest"; | 13 | private String requstedVersion = "latest"; | 
| 13 | private String requestedCPU = ""; | 14 | private String requestedCPU = ""; | 
| 14 | private String requestedPath = ""; | 15 | private String requestedPath = ""; | 
| 15 | 16 | ||
| 16 | /** Called when the activity is first created. */ | 17 | /** Called when the activity is first created. */ | 
| 17 | @Override | 18 | @Override | 
| 18 | public void onCreate(Bundle savedInstanceState) | 19 | public void onCreate(Bundle savedInstanceState) | 
| 19 | { | 20 | { | 
| 20 | super.onCreate(savedInstanceState); | 21 | super.onCreate(savedInstanceState); | 
| 21 | setContentView(R.layout.main); | 22 | setContentView(R.layout.main); | 
| 22 | requestedCPU = java.lang.System.getProperty("os.arch"); | 23 | requestedCPU = java.lang.System.getProperty("os.arch"); | 
| 23 | 24 | ||
| 24 | TextView version = (TextView) findViewById(R.id.version); | 25 | TextView version = (TextView) findViewById(R.id.version); | 
| 25 | String VERSION = getString(R.string.version); | 26 | String VERSION = getString(R.string.version); | 
| 26 | Spinner versions = (Spinner) findViewById(R.id.versions); | 27 | Spinner versions = (Spinner) findViewById(R.id.versions); | 
| 27 | ArrayAdapter<CharSequence> VERSIONS = ArrayAdapter.createFromResource(this, R.array.versions, android.R.layout.simple_spinner_item); | 28 | ArrayAdapter<CharSequence> VERSIONS = ArrayAdapter.createFromResource(this, R.array.versions, android.R.layout.simple_spinner_item); | 
| 28 | TextView cpu = (TextView) findViewById(R.id.cpusPrompt); | 29 | TextView cpu = (TextView) findViewById(R.id.cpusPrompt); | 
| 29 | String CPU = getString(R.string.cpusPrompt); | 30 | String CPU = getString(R.string.cpusPrompt); | 
| 30 | String CPU2 = getString(R.string.cpusPrompt2); | 31 | String CPU2 = getString(R.string.cpusPrompt2); | 
| 31 | Spinner cpus = (Spinner) findViewById(R.id.cpus); | 32 | Spinner cpus = (Spinner) findViewById(R.id.cpus); | 
| 32 | ArrayAdapter<CharSequence> CPUS = ArrayAdapter.createFromResource(this, R.array.cpus, android.R.layout.simple_spinner_item); | 33 | ArrayAdapter<CharSequence> CPUS = ArrayAdapter.createFromResource(this, R.array.cpus, android.R.layout.simple_spinner_item); | 
| 33 | TextView path = (TextView) findViewById(R.id.path); | 34 | TextView path = (TextView) findViewById(R.id.path); | 
| 34 | String PATH = getString(R.string.path); | 35 | String PATH = getString(R.string.path); | 
| 35 | Spinner paths = (Spinner) findViewById(R.id.paths); | 36 | Spinner paths = (Spinner) findViewById(R.id.paths); | 
| 36 | ArrayAdapter<String> PATHS; | 37 | ArrayAdapter<String> PATHS; | 
| 37 | String pathSep = java.lang.System.getProperty("path.separator"); | 38 | String pathSep = java.lang.System.getProperty("path.separator"); | 
| 38 | TextView folder = (TextView) findViewById(R.id.folder); | 39 | TextView folder = (TextView) findViewById(R.id.folder); | 
| 39 | String FOLDER = getString(R.string.folder); | 40 | String FOLDER = getString(R.string.folder); | 
| 40 | TextView source = (TextView) findViewById(R.id.source); | 41 | TextView source = (TextView) findViewById(R.id.source); | 
| 41 | String SOURCE = getString(R.string.source); | 42 | String SOURCE = getString(R.string.source); | 
| 42 | TextView destination = (TextView) findViewById(R.id.destination); | 43 | TextView destination = (TextView) findViewById(R.id.destination); | 
| 43 | String DESTINATION = getString(R.string.destination); | 44 | String DESTINATION = getString(R.string.destination); | 
| 44 | |||
| 45 | version.setText(VERSION + " " + "unknown" + ".\n"); | ||
| 46 | VERSIONS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | ||
| 47 | versions.setAdapter(VERSIONS); | ||
| 48 | versions.setOnItemSelectedListener(this); | ||
| 49 | cpu.setText(CPU + " " + requestedCPU + " " + CPU2 + "\n"); | ||
| 50 | CPUS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | ||
| 51 | cpus.setAdapter(CPUS); | ||
| 52 | cpus.setSelection(CPUS.getPosition(requestedCPU)); | ||
| 53 | cpus.setOnItemSelectedListener(this); | ||
| 54 | PATHS = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, | ||
| 55 | java.lang.System.getenv("PATH").split("\\" + pathSep)); | ||
| 56 | PATHS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | ||
| 57 | paths.setAdapter(PATHS); | ||
| 58 | paths.setOnItemSelectedListener(this); | ||
| 59 | folder.setText(FOLDER + " " + "" + "\n"); | ||
| 60 | source.setText(SOURCE + " " + "" + "\n"); | ||
| 61 | destination.setText(DESTINATION + " " + "" + "\n"); | ||
| 62 | } | ||
| 63 | 45 | ||
| 64 | @Override | 46 | version.setText(VERSION + " " + "unknown" + ".\n"); | 
| 65 | public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) | 47 | VERSIONS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | 
| 66 | { | 48 | versions.setAdapter(VERSIONS); | 
| 67 | String s = (String) parent.getItemAtPosition(pos); | 49 | versions.setOnItemSelectedListener(this); | 
| 68 | TextView source = (TextView) findViewById(R.id.source); | 50 | cpu.setText(CPU + " " + requestedCPU + " " + CPU2 + "\n"); | 
| 69 | String SOURCE = getString(R.string.source); | 51 | CPUS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | 
| 70 | TextView destination = (TextView) findViewById(R.id.destination); | 52 | cpus.setAdapter(CPUS); | 
| 71 | String DESTINATION = getString(R.string.destination); | 53 | cpus.setSelection(CPUS.getPosition(requestedCPU)); | 
| 72 | 54 | cpus.setOnItemSelectedListener(this); | |
| 73 | switch (parent.getId()) | 55 | PATHS = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, | 
| 74 | { | 56 | java.lang.System.getenv("PATH").split("\\" + pathSep)); | 
| 75 | case R.id.versions : | 57 | PATHS.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | 
| 76 | { | 58 | paths.setAdapter(PATHS); | 
| 77 | requstedVersion = s; | 59 | paths.setOnItemSelectedListener(this); | 
| 78 | break; | 60 | folder.setText(FOLDER + " " + "" + "\n"); | 
| 79 | } | 61 | source.setText(SOURCE + " " + "" + "\n"); | 
| 80 | case R.id.cpus : | 62 | destination.setText(DESTINATION + " " + "" + "\n"); | 
| 81 | { | 63 | } | 
| 82 | requestedCPU = s; | ||
| 83 | break; | ||
| 84 | } | ||
| 85 | case R.id.paths: | ||
| 86 | { | ||
| 87 | requestedPath = s; | ||
| 88 | break; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | source.setText(SOURCE + " http://landley.net/code/toybox/downloads/binaries/" + requstedVersion + "/toybox-" + requestedCPU + "\n"); | ||
| 92 | destination.setText(DESTINATION + " " + requestedPath + "\n"); | ||
| 93 | } | ||
| 94 | 64 | ||
| 95 | @Override | 65 | @Override | 
| 96 | public void onNothingSelected(AdapterView<?> parent) | 66 | public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) | 
| 97 | { | 67 | { | 
| 98 | // TODO: Nothing to do here, maybe? | 68 | String s = (String) parent.getItemAtPosition(pos); | 
| 99 | } | 69 | TextView source = (TextView) findViewById(R.id.source); | 
| 70 | String SOURCE = getString(R.string.source); | ||
| 71 | TextView destination = (TextView) findViewById(R.id.destination); | ||
| 72 | String DESTINATION = getString(R.string.destination); | ||
| 100 | 73 | ||
| 101 | public void installToybox(View view) | 74 | switch (parent.getId()) | 
| 102 | { | 75 | { | 
| 76 | case R.id.versions : | ||
| 77 | { | ||
| 78 | requstedVersion = s; | ||
| 79 | break; | ||
| 80 | } | ||
| 81 | |||
| 82 | case R.id.cpus : | ||
| 83 | { | ||
| 84 | requestedCPU = s; | ||
| 85 | break; | ||
| 86 | } | ||
| 87 | |||
| 88 | case R.id.paths: | ||
| 89 | { | ||
| 90 | requestedPath = s; | ||
| 91 | break; | ||
| 92 | } | ||
| 103 | } | 93 | } | 
| 94 | source.setText(SOURCE + " http://landley.net/code/toybox/downloads/binaries/" + requstedVersion + "/toybox-" + requestedCPU + "\n"); | ||
| 95 | destination.setText(DESTINATION + " " + requestedPath + "\n"); | ||
| 96 | } | ||
| 97 | |||
| 98 | @Override | ||
| 99 | public void onNothingSelected(AdapterView<?> parent) | ||
| 100 | { | ||
| 101 | // TODO: Nothing to do here, maybe? | ||
| 102 | } | ||
| 103 | |||
| 104 | public void installToybox(View view) | ||
| 105 | { | ||
| 106 | String url = "http://landley.net/code/toybox/downloads/binaries/" + requstedVersion + "/toybox-" + requestedCPU; | ||
| 107 | DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); | ||
| 108 | DownloadManager manager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); | ||
| 109 | |||
| 110 | request.setDescription("toybox v" + requstedVersion + " for " + requestedCPU); | ||
| 111 | request.setTitle("toybox"); | ||
| 112 | request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); | ||
| 113 | request.setDestinationInExternalFilesDir(this, Environment.DIRECTORY_DOWNLOADS, requstedVersion + "/toybox-" + requestedCPU); | ||
| 114 | manager.enqueue(request); | ||
| 115 | } | ||
| 104 | } | 116 | } | 
