1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
| import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
public class Logiciel extends ListActivity {
public enum DISPLAYMODE{ ABSOLUTE, RELATIVE; }
private final DISPLAYMODE displayMode = DISPLAYMODE.RELATIVE;
private List<AffichageListText> directoryEntries = new ArrayList<AffichageListText>();
private File currentDirectory = new File("");
public boolean can_su;
public String su_bin_file;
public Logiciel() {
this.can_su = true;
this.su_bin_file = "/system/xbin/su";
if (this.Run("echo"))
return;
this.su_bin_file = "/system/bin/su";
if (this.Run("echo"))
return;
this.su_bin_file = "";
this.can_su = false;
}
public boolean Run(String command) {
DataOutputStream os = null;
try {
Process process = Runtime.getRuntime().exec(this.su_bin_file);
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(command + "\n");
os.flush();
os.writeBytes("exit\n");
os.flush();
process.waitFor();
return true;
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return false;
}
public void onCreate(Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
registerForContextMenu(getListView());
browseToRoot();
}
private void browseToRoot() {
browseTo(new File("/"));
}
private void upOneLevel(){
if(this.currentDirectory.getParent() != null)
this.browseTo(this.currentDirectory.getParentFile());
}
private void browseTo(final File dir){
if(this.displayMode == DISPLAYMODE.RELATIVE)
this.setTitle(dir.getAbsolutePath());
if (dir.isDirectory()){
this.currentDirectory = dir;
fill(dir.listFiles());
}else{
OnClickListener okButtonListener = new OnClickListener(){
public void onClick(DialogInterface arg0, int arg1) {
Logiciel.this.openFile(dir);
}
};
OnClickListener cancelButtonListener = new OnClickListener(){
public void onClick(DialogInterface arg0, int arg1) {
}
};
new AlertDialog.Builder(this)
.setTitle("Question")
.setMessage("Voulez-vous ouvrir ce fichier ?")
.setPositiveButton("OK", okButtonListener)
.setNegativeButton("Annuler", cancelButtonListener)
.show();
}
}
private void openFile(File f)
{
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
String type = getMIMEType(f);
intent.setDataAndType(Uri.fromFile(f), type);
startActivity(intent);
}
private String getMIMEType(File f)
{
String end = f.getName().substring(f.getName().lastIndexOf(".")+1, f.getName().length()).toLowerCase();
String type = "";
if(end.equals("mp3") || end.equals("wma") || end.equals("ogg")) type = "audio";
else if(end.equals("avi") || end.equals("divx") || end.equals("mkv") || end.equals("mp4") || end.equals("mpeg") || end.equals("wav") || end.equals("flv") || end.equals("wmv") || end.equals("3gp")) type = "video";
else if(end.equals("jpg") || end.equals("gif") || end.equals("png") || end.equals("jpeg") || end.equals("bmp")) type = "image";
else if(end.equals("txt") || end.equals("php") || end.equals("html")) type = "text";
else if(end.equals("apk") || end.equals("pdf") || end.equals("rtf") || end.equals("jar")|| end.equals("zip") || end.equals("rar") || end.equals("torrent")) type = "application";
type += "/*";
return type;
}
private void fill(File[] files) {
this.directoryEntries.clear();
if(this.currentDirectory.getParent() != null)
this.directoryEntries.add(new AffichageListText(getString(R.string.retour),getResources().getDrawable(R.drawable.retour)));
Drawable currentIcon = null;
for (File currentFile : files){
if (currentFile.isDirectory()) {
currentIcon = getResources().getDrawable(R.drawable.folder);
}else{
String fileName = currentFile.getName();
// Icônes des fichiers Images...
if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingImagePNG))){
currentIcon = getResources().getDrawable(R.drawable.png);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingImageJPEG))){
currentIcon = getResources().getDrawable(R.drawable.jpeg);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingImageJPG))){
currentIcon = getResources().getDrawable(R.drawable.jpg);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingImageBMP))){
currentIcon = getResources().getDrawable(R.drawable.bmp);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingImageGIF))){
currentIcon = getResources().getDrawable(R.drawable.gif);
// Icônes des fichiers WEB...
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingWebTextPDF))){
currentIcon = getResources().getDrawable(R.drawable.pdf);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingWebTextHTML))){
currentIcon = getResources().getDrawable(R.drawable.html);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingWebTextPHP))){
currentIcon = getResources().getDrawable(R.drawable.php);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingWebTextTORRENT))){
currentIcon = getResources().getDrawable(R.drawable.torrent);
// Icônes des fichiers Archives...
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingPackageRAR))){
currentIcon = getResources().getDrawable(R.drawable.rar);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingPackageZIP))){
currentIcon = getResources().getDrawable(R.drawable.zip);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingPackageISO))){
currentIcon = getResources().getDrawable(R.drawable.iso);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingPackageJAR))){
currentIcon = getResources().getDrawable(R.drawable.jar);
// Icônes des fichiers Audios...
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingAudioMP3))){
currentIcon = getResources().getDrawable(R.drawable.mp3);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingAudioWMA))){
currentIcon = getResources().getDrawable(R.drawable.wma);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingAudioOGG))){
currentIcon = getResources().getDrawable(R.drawable.ogg);
// Icônes des fichiers Vidéos...
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoAVI))){
currentIcon = getResources().getDrawable(R.drawable.avi);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoDIVX))){
currentIcon = getResources().getDrawable(R.drawable.divx);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoMKV))){
currentIcon = getResources().getDrawable(R.drawable.mkv);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoMP4))){
currentIcon = getResources().getDrawable(R.drawable.mp4);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoMPEG))){
currentIcon = getResources().getDrawable(R.drawable.mpeg);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoWAV))){
currentIcon = getResources().getDrawable(R.drawable.wav);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoFLV))){
currentIcon = getResources().getDrawable(R.drawable.flv);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideoWMV))){
currentIcon = getResources().getDrawable(R.drawable.wmv);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingVideo3GP))){
currentIcon = getResources().getDrawable(R.drawable.gp3);
// Icônes des fichiers Textes...
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingTextRTF))){
currentIcon = getResources().getDrawable(R.drawable.rtf);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingTextTXT))){
currentIcon = getResources().getDrawable(R.drawable.txt);
}else if(checkEndsWithInStringArray(fileName, getResources().getStringArray(R.array.fileEndingTextAPK))){
currentIcon = getResources().getDrawable(R.drawable.apk);
}else{
currentIcon = getResources().getDrawable(R.drawable.unknow);
}
}
switch (this.displayMode) {
case ABSOLUTE:
this.directoryEntries.add(new AffichageListText(currentFile.getPath(), currentIcon));
break;
case RELATIVE:
int currentPathStringLenght = this.currentDirectory.getAbsolutePath().length();
this.directoryEntries.add(new AffichageListText(currentFile.getAbsolutePath().substring(currentPathStringLenght),currentIcon));
break;
}
}
Collections.sort(this.directoryEntries);
AffichageListAdapter itla = new AffichageListAdapter(this);
itla.setListItems(this.directoryEntries);
this.setListAdapter(itla);
}
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
String selectedFileString = this.directoryEntries.get(position).getText();
if (selectedFileString.equals(getString(R.string.current_dir))) {
this.browseTo(this.currentDirectory);
} else if (selectedFileString.equals(getString(R.string.retour))) {
this.upOneLevel();
} else {
File clickedFile = null;
switch (this.displayMode) {
case RELATIVE:
clickedFile = new File(this.currentDirectory
.getAbsolutePath()
+ this.directoryEntries.get(position).getText());
break;
case ABSOLUTE:
clickedFile = new File(this.directoryEntries.get(position).getText());
break;
}
if (clickedFile != null)
Log.d("Hadès Files Explorer", "File " + clickedFile + " exists? " +
clickedFile.exists());
this.browseTo(clickedFile);
}
}
private boolean checkEndsWithInStringArray(String checkItsEnd,
String[] fileEndings){
for(String aEnd : fileEndings){
if(checkItsEnd.endsWith(aEnd))
return true;
}
return false;
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menugeneral, menu);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.quitter:
Toast.makeText(Logiciel.this, "Quitter", Toast.LENGTH_SHORT).show();
finish();
return true;
case R.id.plus:
Toast.makeText(Logiciel.this, "Plus", Toast.LENGTH_SHORT).show();
return true;
case R.id.apropos:
LayoutInflater factory = LayoutInflater.from(this);
final View alertDialogView = factory.inflate(R.layout.alert_apropos, null);
final AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setView(alertDialogView);
adb.setTitle("A Propos");
adb.setIcon(R.drawable.hfe1);
adb.setNeutralButton("Fermer", null); {
adb.show();
};
return true;
case R.id.favoris:
return true;
case R.id.rafraichir:
return true;
case R.id.preferences:
startActivity(new Intent(this, MesPreferences.class));
Toast.makeText(Logiciel.this, "Préférences", Toast.LENGTH_SHORT).show();
return true;
case R.id.option:
Toast.makeText(Logiciel.this, "Options", Toast.LENGTH_SHORT).show();
return true;
case R.id.applicationsinstallees:
startActivity(new Intent(this, ListeAppInstall.class));
return true;
case R.id.sdexterne:
startActivity(new Intent(this, SDExterne.class));
return true;
case R.id.nouveau:
Toast.makeText(Logiciel.this, "Nouveau", Toast.LENGTH_SHORT).show();
return true;
case R.id.dossier:
return true;
case R.id.fichier:
return true;
}
{
return false;
}
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menucontextuel, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.couper:
return true;
case R.id.copier:
return true;
case R.id.coller:
return true;
case R.id.renommer:
LayoutInflater factory = LayoutInflater.from(this);
final View alertDialogView = factory.inflate(R.layout.alert_renommer, null);
AlertDialog.Builder adb = new AlertDialog.Builder(this);
adb.setView(alertDialogView);
adb.setTitle("Renommer");
adb.setIcon(R.drawable.hfe1);
adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
EditText et = (EditText)alertDialogView.findViewById(R.id.EditText1);
Toast.makeText(Logiciel.this, et.getText(), Toast.LENGTH_SHORT).show();
} });
adb.setNegativeButton("Annuler", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
} });
adb.show();
return false;
case R.id.supprimer:
new AlertDialog.Builder(this)
.setIcon(R.drawable.hfe1)
.setTitle("Confirmation")
.setMessage("Voulez-vous vraiment supprimer ?")
.setPositiveButton("OK", null)
.setNegativeButton("Annuler",null)
.show();
return true;
case R.id.proprietes:
return true;
default:
return super.onContextItemSelected(item);
}
}
} |
Partager