use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class BottomBar method showButtons.
public void showButtons(final BottomBarButtonPath buttonPathInterface) {
final String path = buttonPathInterface.getPath();
if (buttons.getVisibility() == View.VISIBLE) {
lastUsedArrowButton = 0;
lastUsedFolderButton = 0;
buttons.removeAllViews();
buttons.setMinimumHeight(pathLayout.getHeight());
buttonRoot.setImageDrawable(mainActivity.getResources().getDrawable(buttonPathInterface.getRootDrawable()));
String[] names = FileUtils.getFolderNamesInPath(path);
final String[] paths = FileUtils.getPathsInPath(path);
View view = new View(mainActivity);
LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(appbar.getToolbar().getContentInsetLeft(), LinearLayout.LayoutParams.WRAP_CONTENT);
view.setLayoutParams(params1);
buttons.addView(view);
for (int i = 0; i < names.length; i++) {
final int k = i;
if (i == 0) {
buttonRoot.setOnClickListener(p1 -> {
if (paths.length != 0) {
buttonPathInterface.changePath(paths[k]);
timer.cancel();
timer.start();
}
});
buttons.addView(buttonRoot);
} else if (FileUtils.isStorage(paths[i])) {
buttonStorage.setOnClickListener(p1 -> {
buttonPathInterface.changePath(paths[k]);
timer.cancel();
timer.start();
});
buttons.addView(buttonStorage);
} else {
Button button = createFolderButton(names[i]);
button.setOnClickListener(p1 -> {
buttonPathInterface.changePath(paths[k]);
timer.cancel();
timer.start();
});
buttons.addView(button);
}
if (names.length - i != 1) {
buttons.addView(createArrow());
}
}
scroll.post(() -> {
sendScroll(scroll);
sendScroll(pathScroll);
});
if (buttons.getVisibility() == View.VISIBLE) {
timer.cancel();
timer.start();
}
}
}
use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class AppConfigTest method testGetScreenUtils.
@Test
public void testGetScreenUtils() {
assertNull(AppConfig.getInstance().getScreenUtils());
MainActivity mock = mock(MainActivity.class);
AppConfig.getInstance().setMainActivityContext(mock);
assertNotNull(AppConfig.getInstance().getScreenUtils());
}
use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class SmbSearchDialog method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
MaterialDialog.Builder builder = new MaterialDialog.Builder(getActivity());
builder.title(R.string.searching_devices);
builder.negativeColor(accentColor);
builder.negativeText(R.string.cancel);
builder.onNegative((dialog, which) -> {
if (subnetScanner != null)
subnetScanner.cancel(true);
dismiss();
});
builder.onPositive((dialog, which) -> {
if (subnetScanner != null)
subnetScanner.cancel(true);
if (getActivity() != null && getActivity() instanceof MainActivity) {
dismiss();
MainActivity mainActivity = (MainActivity) getActivity();
mainActivity.showSMBDialog("", "", false);
}
});
builder.positiveText(R.string.use_custom_ip);
builder.positiveColor(accentColor);
computers.add(new ComputerParcelable("-1", "-1"));
listViewAdapter = new ListViewAdapter(getActivity(), computers);
subnetScanner = new SubnetScanner(getActivity());
subnetScanner.setObserver(new SubnetScanner.ScanObserver() {
@Override
public void computerFound(final ComputerParcelable computer) {
if (getActivity() != null)
getActivity().runOnUiThread(() -> {
if (!computers.contains(computer))
computers.add(computer);
listViewAdapter.notifyDataSetChanged();
});
}
@Override
public void searchFinished() {
if (getActivity() != null) {
getActivity().runOnUiThread(() -> {
if (computers.size() == 1) {
dismiss();
Toast.makeText(getActivity(), getString(R.string.no_device_found), Toast.LENGTH_SHORT).show();
MainActivity mainActivity = (MainActivity) getActivity();
mainActivity.showSMBDialog("", "", false);
return;
}
computers.remove(computers.size() - 1);
listViewAdapter.notifyDataSetChanged();
});
}
}
});
subnetScanner.execute();
builder.adapter(listViewAdapter, null);
return builder.build();
}
use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class GeneralDialogCreation method showSignInWithGoogleDialog.
public static void showSignInWithGoogleDialog(@NonNull MainActivity mainActivity) {
View customView = DialogSigninWithGoogleBinding.inflate(LayoutInflater.from(mainActivity)).getRoot();
int accentColor = mainActivity.getAccent();
MaterialDialog dialog = new MaterialDialog.Builder(mainActivity).customView(customView, false).title(R.string.signin_with_google_title).negativeText(android.R.string.cancel).negativeColor(accentColor).onNegative((dlg, which) -> dlg.dismiss()).build();
customView.findViewById(R.id.signin_with_google).setOnClickListener(v -> {
mainActivity.addConnection(OpenMode.GDRIVE);
dialog.dismiss();
});
dialog.show();
}
use of com.amaze.filemanager.ui.activities.MainActivity in project AmazeFileManager by TeamAmaze.
the class GeneralDialogCreation method deleteFilesDialog.
@SuppressWarnings("ConstantConditions")
public static void deleteFilesDialog(@NonNull final Context context, @NonNull final MainActivity mainActivity, @NonNull final List<LayoutElementParcelable> positions, @NonNull AppTheme appTheme) {
final ArrayList<HybridFileParcelable> itemsToDelete = new ArrayList<>();
int accentColor = mainActivity.getAccent();
// Build dialog with custom view layout and accent color.
MaterialDialog dialog = new MaterialDialog.Builder(context).title(context.getString(R.string.dialog_delete_title)).customView(R.layout.dialog_delete, true).theme(appTheme.getMaterialDialogTheme()).negativeText(context.getString(R.string.cancel).toUpperCase()).positiveText(context.getString(R.string.delete).toUpperCase()).positiveColor(accentColor).negativeColor(accentColor).onPositive((dialog1, which) -> {
Toast.makeText(context, context.getString(R.string.deleting), Toast.LENGTH_SHORT).show();
mainActivity.mainActivityHelper.deleteFiles(itemsToDelete);
}).build();
// Get views from custom layout to set text values.
final TextView categoryDirectories = dialog.getCustomView().findViewById(R.id.category_directories);
final TextView categoryFiles = dialog.getCustomView().findViewById(R.id.category_files);
final TextView listDirectories = dialog.getCustomView().findViewById(R.id.list_directories);
final TextView listFiles = dialog.getCustomView().findViewById(R.id.list_files);
final TextView total = dialog.getCustomView().findViewById(R.id.total);
// Parse items to delete.
new AsyncTask<Void, Object, Void>() {
long sizeTotal = 0;
StringBuilder files = new StringBuilder();
StringBuilder directories = new StringBuilder();
int counterDirectories = 0;
int counterFiles = 0;
@Override
protected void onPreExecute() {
super.onPreExecute();
listFiles.setText(context.getString(R.string.loading));
listDirectories.setText(context.getString(R.string.loading));
total.setText(context.getString(R.string.loading));
}
@Override
protected Void doInBackground(Void... params) {
for (int i = 0; i < positions.size(); i++) {
final LayoutElementParcelable layoutElement = positions.get(i);
itemsToDelete.add(layoutElement.generateBaseFile());
// Build list of directories to delete.
if (layoutElement.isDirectory) {
// Don't add newline between category and list.
if (counterDirectories != 0) {
directories.append("\n");
}
long sizeDirectory = layoutElement.generateBaseFile().folderSize(context);
directories.append(++counterDirectories).append(". ").append(layoutElement.title).append(" (").append(Formatter.formatFileSize(context, sizeDirectory)).append(")");
sizeTotal += sizeDirectory;
// Build list of files to delete.
} else {
// Don't add newline between category and list.
if (counterFiles != 0) {
files.append("\n");
}
files.append(++counterFiles).append(". ").append(layoutElement.title).append(" (").append(layoutElement.size).append(")");
sizeTotal += layoutElement.longSize;
}
publishProgress(sizeTotal, counterFiles, counterDirectories, files, directories);
}
return null;
}
@Override
protected void onProgressUpdate(Object... result) {
super.onProgressUpdate(result);
int tempCounterFiles = (int) result[1];
int tempCounterDirectories = (int) result[2];
long tempSizeTotal = (long) result[0];
StringBuilder tempFilesStringBuilder = (StringBuilder) result[3];
StringBuilder tempDirectoriesStringBuilder = (StringBuilder) result[4];
updateViews(tempSizeTotal, tempFilesStringBuilder, tempDirectoriesStringBuilder, tempCounterFiles, tempCounterDirectories);
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
updateViews(sizeTotal, files, directories, counterFiles, counterDirectories);
}
private void updateViews(long tempSizeTotal, StringBuilder filesStringBuilder, StringBuilder directoriesStringBuilder, int... values) {
int tempCounterFiles = values[0];
int tempCounterDirectories = values[1];
// Hide category and list for directories when zero.
if (tempCounterDirectories == 0) {
if (tempCounterDirectories == 0) {
categoryDirectories.setVisibility(View.GONE);
listDirectories.setVisibility(View.GONE);
}
// Hide category and list for files when zero.
}
if (tempCounterFiles == 0) {
categoryFiles.setVisibility(View.GONE);
listFiles.setVisibility(View.GONE);
}
if (tempCounterDirectories != 0 || tempCounterFiles != 0) {
listDirectories.setText(directoriesStringBuilder);
if (listDirectories.getVisibility() != View.VISIBLE && tempCounterDirectories != 0)
listDirectories.setVisibility(View.VISIBLE);
listFiles.setText(filesStringBuilder);
if (listFiles.getVisibility() != View.VISIBLE && tempCounterFiles != 0)
listFiles.setVisibility(View.VISIBLE);
if (categoryDirectories.getVisibility() != View.VISIBLE && tempCounterDirectories != 0)
categoryDirectories.setVisibility(View.VISIBLE);
if (categoryFiles.getVisibility() != View.VISIBLE && tempCounterFiles != 0)
categoryFiles.setVisibility(View.VISIBLE);
}
// Show total size with at least one directory or file and size is not zero.
if (tempCounterFiles + tempCounterDirectories > 1 && tempSizeTotal > 0) {
StringBuilder builderTotal = new StringBuilder().append(context.getString(R.string.total)).append(" ").append(Formatter.formatFileSize(context, tempSizeTotal));
total.setText(builderTotal);
if (total.getVisibility() != View.VISIBLE)
total.setVisibility(View.VISIBLE);
} else {
total.setVisibility(View.GONE);
}
}
}.execute();
// Set category text color for Jelly Bean (API 16) and later.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
categoryDirectories.setTextColor(accentColor);
categoryFiles.setTextColor(accentColor);
}
// Show dialog on screen.
dialog.show();
}
Aggregations