use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class AppsAdapter method showPopup.
private void showPopup(View v, final AppDataParcelable rowItem) {
v.setOnClickListener(view -> {
PopupMenu popupMenu = new PopupMenu(app.getActivity(), view);
popupMenu.setOnMenuItemClickListener(item -> {
int colorAccent = themedActivity.getColorPreference().getColor(ColorUsage.ACCENT);
switch(item.getItemId()) {
case R.id.open:
Intent i1 = app.getActivity().getPackageManager().getLaunchIntentForPackage(rowItem.packageName);
if (i1 != null)
app.startActivity(i1);
else
Toast.makeText(app.getActivity(), app.getResources().getString(R.string.not_allowed), Toast.LENGTH_LONG).show();
return true;
case R.id.share:
ArrayList<File> arrayList2 = new ArrayList<File>();
arrayList2.add(new File(rowItem.path));
themedActivity.getColorPreference();
FileUtils.shareFiles(arrayList2, app.getActivity(), utilsProvider.getAppTheme(), colorAccent);
return true;
case R.id.unins:
final HybridFileParcelable f1 = new HybridFileParcelable(rowItem.path);
f1.setMode(OpenMode.ROOT);
if ((Integer.valueOf(rowItem.data.substring(0, rowItem.data.indexOf("_"))) & ApplicationInfo.FLAG_SYSTEM) != 0) {
// system package
if (app.Sp.getBoolean(PreferencesConstants.PREFERENCE_ROOTMODE, false)) {
MaterialDialog.Builder builder1 = new MaterialDialog.Builder(app.getActivity());
builder1.theme(utilsProvider.getAppTheme().getMaterialDialogTheme()).content(app.getResources().getString(R.string.unin_system_apk)).title(app.getResources().getString(R.string.warning)).negativeColor(colorAccent).positiveColor(colorAccent).negativeText(app.getResources().getString(R.string.no)).positiveText(app.getResources().getString(R.string.yes)).callback(new MaterialDialog.ButtonCallback() {
@Override
public void onNegative(MaterialDialog materialDialog) {
materialDialog.cancel();
}
@Override
public void onPositive(MaterialDialog materialDialog) {
ArrayList<HybridFileParcelable> files = new ArrayList<>();
if (Build.VERSION.SDK_INT >= 21) {
String parent = f1.getParent();
if (!parent.equals("app") && !parent.equals("priv-app")) {
HybridFileParcelable baseFile = new HybridFileParcelable(f1.getParent());
baseFile.setMode(OpenMode.ROOT);
files.add(baseFile);
} else
files.add(f1);
} else {
files.add(f1);
}
new DeleteTask(app.getActivity().getContentResolver(), app.getActivity()).execute((files));
}
}).build().show();
} else {
Toast.makeText(app.getActivity(), app.getResources().getString(R.string.enablerootmde), Toast.LENGTH_SHORT).show();
}
} else {
app.unin(rowItem.packageName);
}
return true;
case R.id.play:
Intent intent1 = new Intent(Intent.ACTION_VIEW);
intent1.setData(Uri.parse("market://details?id=" + rowItem.packageName));
app.startActivity(intent1);
return true;
case R.id.properties:
app.startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS, Uri.parse("package:" + rowItem.packageName)));
return true;
case R.id.backup:
Toast.makeText(app.getActivity(), app.getResources().getString(R.string.copyingapk) + Environment.getExternalStorageDirectory().getPath() + "/app_backup", Toast.LENGTH_LONG).show();
File f = new File(rowItem.path);
ArrayList<HybridFileParcelable> ab = new ArrayList<>();
File dst = new File(Environment.getExternalStorageDirectory().getPath() + "/app_backup");
if (!dst.exists() || !dst.isDirectory())
dst.mkdirs();
Intent intent = new Intent(app.getActivity(), CopyService.class);
HybridFileParcelable baseFile = RootHelper.generateBaseFile(f, true);
baseFile.setName(rowItem.label + "_" + rowItem.packageName.substring(rowItem.packageName.indexOf("_") + 1) + ".apk");
ab.add(baseFile);
intent.putParcelableArrayListExtra(CopyService.TAG_COPY_SOURCES, ab);
intent.putExtra(CopyService.TAG_COPY_TARGET, dst.getPath());
intent.putExtra(CopyService.TAG_COPY_OPEN_MODE, 0);
ServiceWatcherUtil.runService(app.getActivity(), intent);
return true;
}
return false;
});
popupMenu.inflate(R.menu.app_options);
popupMenu.show();
});
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class LoadFilesListTask method listaudio.
private ArrayList<LayoutElementParcelable> listaudio() {
String selection = MediaStore.Audio.Media.IS_MUSIC + " != 0";
String[] projection = { MediaStore.Audio.Media.DATA };
Cursor cursor = c.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);
ArrayList<LayoutElementParcelable> songs = new ArrayList<>();
if (cursor.getCount() > 0 && cursor.moveToFirst()) {
do {
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
HybridFileParcelable strings = RootHelper.generateBaseFile(new File(path), showHiddenFiles);
if (strings != null) {
LayoutElementParcelable parcelable = createListParcelables(strings);
if (parcelable != null)
songs.add(parcelable);
}
} while (cursor.moveToNext());
}
cursor.close();
return songs;
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class LoadFilesListTask method listRecentFiles.
private ArrayList<LayoutElementParcelable> listRecentFiles() {
ArrayList<LayoutElementParcelable> songs = new ArrayList<>();
final String[] projection = { MediaStore.Files.FileColumns.DATA, MediaStore.Files.FileColumns.DATE_MODIFIED };
Calendar c = Calendar.getInstance();
c.set(Calendar.DAY_OF_YEAR, c.get(Calendar.DAY_OF_YEAR) - 2);
Date d = c.getTime();
Cursor cursor = this.c.getContentResolver().query(MediaStore.Files.getContentUri("external"), projection, null, null, null);
if (cursor == null)
return songs;
if (cursor.getCount() > 0 && cursor.moveToFirst()) {
do {
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
File f = new File(path);
if (d.compareTo(new Date(f.lastModified())) != 1 && !f.isDirectory()) {
HybridFileParcelable strings = RootHelper.generateBaseFile(new File(path), showHiddenFiles);
if (strings != null) {
LayoutElementParcelable parcelable = createListParcelables(strings);
if (parcelable != null)
songs.add(parcelable);
}
}
} while (cursor.moveToNext());
}
cursor.close();
Collections.sort(songs, (lhs, rhs) -> -1 * Long.valueOf(lhs.date).compareTo(rhs.date));
if (songs.size() > 20)
for (int i = songs.size() - 1; i > 20; i--) {
songs.remove(i);
}
return songs;
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class LoadFilesListTask method doInBackground.
@Override
protected Pair<OpenMode, ArrayList<LayoutElementParcelable>> doInBackground(Void... p) {
HybridFile hFile = null;
if (openmode == OpenMode.UNKNOWN) {
hFile = new HybridFile(OpenMode.UNKNOWN, path);
hFile.generateMode(ma.getActivity());
openmode = hFile.getMode();
if (hFile.isSmb()) {
ma.smbPath = path;
} else if (android.util.Patterns.EMAIL_ADDRESS.matcher(path).matches()) {
openmode = OpenMode.ROOT;
}
}
if (isCancelled())
return null;
ma.folder_count = 0;
ma.file_count = 0;
final ArrayList<LayoutElementParcelable> list;
switch(openmode) {
case SMB:
if (hFile == null) {
hFile = new HybridFile(OpenMode.SMB, path);
}
try {
SmbFile[] smbFile = hFile.getSmbFile(5000).listFiles();
list = ma.addToSmb(smbFile, path);
openmode = OpenMode.SMB;
} catch (SmbAuthException e) {
if (!e.getMessage().toLowerCase().contains("denied")) {
ma.reauthenticateSmb();
}
return null;
} catch (SmbException | NullPointerException e) {
e.printStackTrace();
return null;
}
break;
case SFTP:
HybridFile sftpHFile = new HybridFile(OpenMode.SFTP, path);
list = new ArrayList<LayoutElementParcelable>();
sftpHFile.forEachChildrenFile(c, false, file -> {
LayoutElementParcelable elem = createListParcelables(file);
if (elem != null)
list.add(elem);
});
break;
case CUSTOM:
switch(Integer.parseInt(path)) {
case 0:
list = listImages();
break;
case 1:
list = listVideos();
break;
case 2:
list = listaudio();
break;
case 3:
list = listDocs();
break;
case 4:
list = listApks();
break;
case 5:
list = listRecent();
break;
case 6:
list = listRecentFiles();
break;
default:
throw new IllegalStateException();
}
break;
case OTG:
list = new ArrayList<>();
listOtg(path, new OnFileFound() {
@Override
public void onFileFound(HybridFileParcelable file) {
LayoutElementParcelable elem = createListParcelables(file);
if (elem != null)
list.add(elem);
}
});
openmode = OpenMode.OTG;
break;
case DROPBOX:
case BOX:
case GDRIVE:
case ONEDRIVE:
CloudStorage cloudStorage = dataUtils.getAccount(openmode);
list = new ArrayList<>();
try {
listCloud(path, cloudStorage, openmode, new OnFileFound() {
@Override
public void onFileFound(HybridFileParcelable file) {
LayoutElementParcelable elem = createListParcelables(file);
if (elem != null)
list.add(elem);
}
});
} catch (CloudPluginException e) {
e.printStackTrace();
AppConfig.toast(c, c.getResources().getString(R.string.failed_no_connection));
return new Pair<>(openmode, list);
}
break;
default:
// we're neither in OTG not in SMB, load the list based on root/general filesystem
list = new ArrayList<>();
RootHelper.getFiles(path, ma.getMainActivity().isRootExplorer(), showHiddenFiles, new RootHelper.GetModeCallBack() {
@Override
public void getMode(OpenMode mode) {
openmode = mode;
}
}, new OnFileFound() {
@Override
public void onFileFound(HybridFileParcelable file) {
LayoutElementParcelable elem = createListParcelables(file);
if (elem != null)
list.add(elem);
}
});
break;
}
if (list != null && !(openmode == OpenMode.CUSTOM && ((path).equals("5") || (path).equals("6")))) {
Collections.sort(list, new FileListSorter(ma.dsort, ma.sortby, ma.asc));
}
return new Pair<>(openmode, list);
}
use of com.amaze.filemanager.filesystem.HybridFileParcelable in project AmazeFileManager by TeamAmaze.
the class LoadFilesListTask method listImages.
private ArrayList<LayoutElementParcelable> listImages() {
ArrayList<LayoutElementParcelable> songs = new ArrayList<>();
final String[] projection = { MediaStore.Images.Media.DATA };
final Cursor cursor = c.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, null, null, null);
if (cursor.getCount() > 0 && cursor.moveToFirst()) {
do {
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
HybridFileParcelable strings = RootHelper.generateBaseFile(new File(path), showHiddenFiles);
if (strings != null) {
LayoutElementParcelable parcelable = createListParcelables(strings);
if (parcelable != null)
songs.add(parcelable);
}
} while (cursor.moveToNext());
}
cursor.close();
return songs;
}
Aggregations