Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.IRE.toolbox;
- import java.io.DataOutputStream;
- import java.io.File;
- import java.io.IOException;
- import java.net.URISyntaxException;
- import java.util.ArrayList;
- import java.util.List;
- import android.app.AlertDialog;
- import android.app.ListActivity;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.DialogInterface.OnClickListener;
- import android.os.Bundle;
- import android.os.Environment;
- import android.util.Log;
- import android.view.Menu;
- import android.view.MenuInflater;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.ArrayAdapter;
- import android.widget.ListView;
- public class FileBrowser extends ListActivity {
- private enum DISPLAYMODE{ ABSOLUTE, RELATIVE; }
- private final DISPLAYMODE displayMode = DISPLAYMODE.ABSOLUTE;
- private List<String> directoryEntries = new ArrayList<String>();
- private File currentDirectory = new File("/");
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.menu_button_infile, menu);
- return true;
- }
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle item selection
- switch (item.getItemId()){
- case R.id.Main:
- Intent myIntent = new Intent(getApplicationContext(), Controller.class);
- startActivityForResult(myIntent, 0);
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
- @Override
- public void onCreate(Bundle savedInstanceState){
- super.onCreate(savedInstanceState);
- browseToIreFoler();
- }
- private void browseToIreFoler() {
- File sdCard = Environment.getExternalStorageDirectory();
- File dir = new File(sdCard.getAbsolutePath() +"/IRE/Downloads");
- browseTo(dir);
- }
- private void browseTo(final File aDirectory){
- if (aDirectory.isDirectory()){
- this.currentDirectory = aDirectory;
- fill(aDirectory.listFiles());
- }
- }
- private void fill(File[] files) {
- this.directoryEntries.clear();
- // Add the "." == "current directory"
- // and the ".." == 'Up one level'
- this.directoryEntries.add(getString(R.string.current_dir));
- if(this.currentDirectory.getParent() != null)
- this.directoryEntries.add(getString(R.string.up_one_level));
- switch(this.displayMode){
- case ABSOLUTE:
- for (File file : files){
- this.directoryEntries.add(file.getPath());
- }
- break;
- case RELATIVE: // On relative Mode, we have to add the current-path to the beginning
- int currentPathStringLenght = this.currentDirectory.getAbsolutePath().length();
- for (File file : files){
- this.directoryEntries.add(file.getAbsolutePath().substring(currentPathStringLenght));
- }
- break;
- }
- ArrayAdapter<String> directoryList = new ArrayAdapter<String>(this,
- R.layout.file_row, this.directoryEntries);
- this.setListAdapter(directoryList);
- }
- private void upOneLevel(){
- if(this.currentDirectory.getParent() != null)
- this.browseTo(this.currentDirectory.getParentFile());
- }
- @Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- int selectionRowID = (int) this.getSelectedItemId();
- String selectedFileString = this.directoryEntries.get(selectionRowID);
- if (selectedFileString.equals(".")) {
- // Refresh
- this.browseTo(this.currentDirectory);
- } else if(selectedFileString.equals("..")){
- this.upOneLevel();
- } else {
- File clickedFile = null;
- switch(this.displayMode){
- case RELATIVE:
- clickedFile = new File(this.currentDirectory.getAbsolutePath()
- + this.directoryEntries.get(selectionRowID));
- break;
- case ABSOLUTE:
- clickedFile = new File(this.directoryEntries.get(selectionRowID));
- break;
- }
- if(clickedFile != null){
- String end = clickedFile.getName().substring(clickedFile.getName().lastIndexOf(".")+1, clickedFile.getName().length()).toLowerCase();
- // this.browseTo(clickedFile)
- Log.d("CLICKED_FILE", clickedFile.toString());
- Log.d("CLICKED_FILE", end);
- if(end.equalsIgnoreCase("zip")){
- Runtime run = Runtime.getRuntime();
- Process p = null;
- DataOutputStream out = null;
- try{
- p = run.exec("su");
- out = new DataOutputStream(p.getOutputStream());
- out.writeBytes("echo install_zip SDCARD:" +clickedFile.toString() +" > /cache/recovery/extendedcommand\n");
- out.writeBytes("reboot recovery\n"); // testing
- out.flush();
- }catch(Exception e){
- Log.e("FLASH", "Unable to reboot into recovery mode:", e);
- e.printStackTrace();
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement