use of org.horaapps.liz.ui.ThemedIcon in project LeafPic by HoraApps.
the class ColorsSetting method chooseBaseTheme.
public void chooseBaseTheme() {
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), getActivity().getDialogStyle());
final View dialogLayout = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_base_theme, null);
final TextView dialogTitle = (TextView) dialogLayout.findViewById(R.id.basic_theme_title);
final CardView dialogCardView = (CardView) dialogLayout.findViewById(R.id.basic_theme_card);
/**
* SET OBJ THEME *
*/
dialogTitle.setBackgroundColor(getActivity().getPrimaryColor());
dialogCardView.setCardBackgroundColor(getActivity().getCardBackgroundColor());
dialogBuilder.setView(dialogLayout);
dialogBuilder.setView(dialogLayout);
final AlertDialog dialog = dialogBuilder.show();
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(View view) {
switch(view.getId()) {
case R.id.ll_white_basic_theme:
getActivity().setBaseTheme(LIGHT);
break;
case R.id.ll_dark_basic_theme:
getActivity().setBaseTheme(DARK);
break;
case R.id.ll_dark_amoled_basic_theme:
getActivity().setBaseTheme(AMOLED);
break;
}
getActivity().updateUiElements();
dialog.dismiss();
}
};
((ThemedIcon) dialogLayout.findViewById(R.id.white_basic_theme_icon)).setColor(getActivity().getIconColor());
((ThemedIcon) dialogLayout.findViewById(R.id.dark_basic_theme_icon)).setColor(getActivity().getIconColor());
((ThemedIcon) dialogLayout.findViewById(R.id.dark_amoled_basic_theme_icon)).setColor(getActivity().getIconColor());
dialogLayout.findViewById(R.id.ll_white_basic_theme).setOnClickListener(listener);
dialogLayout.findViewById(R.id.ll_dark_basic_theme).setOnClickListener(listener);
dialogLayout.findViewById(R.id.ll_dark_amoled_basic_theme).setOnClickListener(listener);
}
use of org.horaapps.liz.ui.ThemedIcon in project LeafPic by HoraApps.
the class SinglePhotoSetting method show.
public void show() {
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), getActivity().getDialogStyle());
View dialogLayout = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_media_viewer_theme, null);
final SwitchCompat swApplyTheme = (SwitchCompat) dialogLayout.findViewById(R.id.sw_apply_theme);
((CardView) dialogLayout.findViewById(R.id.dialog_card_)).setCardBackgroundColor(getActivity().getCardBackgroundColor());
dialogLayout.findViewById(R.id.dialog_title).setBackgroundColor(getActivity().getPrimaryColor());
((TextView) dialogLayout.findViewById(R.id.apply_theme)).setTextColor(getActivity().getTextColor());
((TextView) dialogLayout.findViewById(R.id.apply_theme_3thAct_title_Sub)).setTextColor(getActivity().getSubTextColor());
((ThemedIcon) dialogLayout.findViewById(R.id.ll_apply_theme_icon)).setColor(getActivity().getIconColor());
swApplyTheme.setChecked(getActivity().themeOnSingleImgAct());
swApplyTheme.setClickable(false);
dialogLayout.findViewById(R.id.ll_apply_theme).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
swApplyTheme.setChecked(!swApplyTheme.isChecked());
getActivity().setSwitchColor(getActivity().getAccentColor(), swApplyTheme);
}
});
getActivity().setSwitchColor(getActivity().getAccentColor(), swApplyTheme);
final LineColorPicker transparencyColorPicker = (LineColorPicker) dialogLayout.findViewById(R.id.pickerTransparent);
transparencyColorPicker.setColors(ColorPalette.getTransparencyShadows(getActivity().getPrimaryColor()));
transparencyColorPicker.setSelectedColor(ColorPalette.getTransparentColor(getActivity().getPrimaryColor(), 255 - Hawk.get(getActivity().getString(R.string.preference_transparency), 0)));
/**
*TEXT VIEWS*
*/
((TextView) dialogLayout.findViewById(R.id.seek_bar_alpha_title)).setTextColor(getActivity().getTextColor());
((TextView) dialogLayout.findViewById(R.id.seek_bar_alpha_title_Sub)).setTextColor(getActivity().getSubTextColor());
dialogBuilder.setView(dialogLayout);
dialogBuilder.setNeutralButton(getActivity().getString(R.string.cancel).toUpperCase(), null);
dialogBuilder.setPositiveButton(getActivity().getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
boolean applyTheme = swApplyTheme.isChecked();
Hawk.put(getActivity().getString(R.string.preference_apply_theme_pager), applyTheme);
if (applyTheme) {
int c = Color.alpha(transparencyColorPicker.getColor());
Hawk.put(getActivity().getString(R.string.preference_transparency), 255 - c);
}
getActivity().updateTheme();
}
});
dialogBuilder.show();
}
use of org.horaapps.liz.ui.ThemedIcon in project LeafPic by HoraApps.
the class SelectAlbumBuilder method setupDialog.
@Override
public void setupDialog(Dialog dialog, int style) {
super.setupDialog(dialog, style);
View contentView = View.inflate(getContext(), R.layout.select_folder_bottom_sheet, null);
final RecyclerView mRecyclerView = contentView.findViewById(R.id.folders);
final Spinner spinner = contentView.findViewById(R.id.storage_spinner);
currentFolderPath = contentView.findViewById(R.id.bottom_sheet_sub_title);
exploreModePanel = contentView.findViewById(R.id.ll_explore_mode_panel);
imgExploreMode = contentView.findViewById(R.id.toggle_hidden_icon);
theme = ThemeHelper.getInstanceLoaded(getContext());
sdCardPath = StorageHelper.getSdcardPath(getContext());
mRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));
mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(2, Measure.pxToDp(3, getContext()), true));
adapter = new BottomSheetAlbumsAdapter();
mRecyclerView.setAdapter(adapter);
spinner.setAdapter(new VolumeSpinnerAdapter(contentView.getContext()));
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int pos, long l) {
switch(pos) {
case INTERNAL_STORAGE:
displayContentFolder(Environment.getExternalStorageDirectory());
break;
default:
// }
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
/**
*SET UP THEME*
*/
contentView.findViewById(R.id.rl_bottom_sheet_title).setBackgroundColor(theme.getPrimaryColor());
exploreModePanel.setBackgroundColor(theme.getPrimaryColor());
contentView.findViewById(R.id.ll_select_folder).setBackgroundColor(theme.getCardBackgroundColor());
theme.setColorScrollBarDrawable(ContextCompat.getDrawable(dialog.getContext(), R.drawable.ic_scrollbar));
mRecyclerView.setBackgroundColor(theme.getBackgroundColor());
fabDone = contentView.findViewById(R.id.fab_bottomsheet_done);
fabDone.setBackgroundTintList(ColorStateList.valueOf(theme.getAccentColor()));
fabDone.setImageDrawable(new IconicsDrawable(getContext()).icon(GoogleMaterial.Icon.gmd_done).color(Color.WHITE));
fabDone.setVisibility(exploreMode ? View.VISIBLE : View.GONE);
fabDone.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
onFolderSelected.folderSelected(currentFolderPath.getText().toString());
}
});
((TextView) contentView.findViewById(R.id.bottom_sheet_title)).setText(title);
((ThemedIcon) contentView.findViewById(R.id.create_new_folder_icon)).setColor(theme.getIconColor());
contentView.findViewById(R.id.rl_create_new_folder).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final EditText editText = new EditText(getContext());
AlertDialog insertTextDialog = AlertDialogsHelper.getInsertTextDialog(((ThemedActivity) getActivity()), editText, R.string.new_folder);
insertTextDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
File folderPath = new File(currentFolderPath.getText().toString() + File.separator + editText.getText().toString());
if (folderPath.mkdir())
displayContentFolder(folderPath);
}
});
insertTextDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel).toUpperCase(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
insertTextDialog.show();
}
});
contentView.findViewById(R.id.rl_bottom_sheet_title).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!forzed) {
toggleExplorerMode(!exploreMode);
fabDone.setVisibility(exploreMode ? View.VISIBLE : View.GONE);
}
}
});
dialog.setContentView(contentView);
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) ((View) contentView.getParent()).getLayoutParams();
CoordinatorLayout.Behavior behavior = layoutParams.getBehavior();
if (behavior != null && behavior instanceof BottomSheetBehavior) {
((BottomSheetBehavior) behavior).setBottomSheetCallback(mBottomSheetBehaviorCallback);
}
adapter.notifyDataSetChanged();
toggleExplorerMode(exploreMode);
}
use of org.horaapps.liz.ui.ThemedIcon in project LeafPic by HoraApps.
the class RvMediaFragment method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.all_media_filter:
album.setFilterMode(FilterMode.ALL);
item.setChecked(true);
reload();
return true;
case R.id.video_media_filter:
album.setFilterMode(FilterMode.VIDEO);
item.setChecked(true);
reload();
return true;
case R.id.image_media_filter:
album.setFilterMode(FilterMode.IMAGES);
item.setChecked(true);
reload();
return true;
case R.id.gifs_media_filter:
album.setFilterMode(FilterMode.GIF);
item.setChecked(true);
reload();
return true;
case R.id.sharePhotos:
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
HashMap<String, Integer> types = new HashMap<>();
ArrayList<Uri> files = new ArrayList<>();
for (Media f : adapter.getSelected()) {
String mimeType = MimeTypeUtils.getTypeMime(f.getMimeType());
int count = 0;
if (types.containsKey(mimeType)) {
count = types.get(mimeType);
}
types.put(mimeType, count);
files.add(LegacyCompatFileProvider.getUri(getContext(), f.getFile()));
}
Set<String> fileTypes = types.keySet();
if (fileTypes.size() > 1) {
Toast.makeText(getContext(), R.string.waring_share_multiple_file_types, Toast.LENGTH_SHORT).show();
}
int max = -1;
String type = null;
for (String fileType : fileTypes) {
Integer count = types.get(fileType);
if (count > max) {
type = fileType;
}
}
intent.setType(type + "/*");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(intent, getResources().getText(R.string.send_to)));
return true;
case R.id.set_as_cover:
String path = adapter.getFirstSelected().getPath();
album.setCover(path);
db().setCover(album.getPath(), path);
adapter.clearSelected();
return true;
case R.id.action_palette:
Intent paletteIntent = new Intent(getActivity(), PaletteActivity.class);
paletteIntent.setData(adapter.getFirstSelected().getUri());
startActivity(paletteIntent);
return true;
case R.id.rename:
final EditText editTextNewName = new EditText(getActivity());
editTextNewName.setText(StringUtils.getPhotoNameByPath(adapter.getFirstSelected().getPath()));
AlertDialog renameDialog = AlertDialogsHelper.getInsertTextDialog(((ThemedActivity) getActivity()), editTextNewName, R.string.rename_photo_action);
renameDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.ok_action).toUpperCase(), (dialog, which) -> {
if (editTextNewName.length() != 0) {
boolean b = MediaHelper.renameMedia(getActivity(), adapter.getFirstSelected(), editTextNewName.getText().toString());
if (!b) {
StringUtils.showToast(getActivity(), getString(R.string.rename_error));
// adapter.notifyDataSetChanged();
} else
// Deselect media if rename successful
adapter.clearSelected();
} else
StringUtils.showToast(getActivity(), getString(R.string.nothing_changed));
});
renameDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel).toUpperCase(), (dialog, which) -> dialog.dismiss());
renameDialog.show();
return true;
case R.id.select_all:
if (adapter.getSelectedCount() == adapter.getItemCount())
adapter.clearSelected();
else
adapter.selectAll();
return true;
case R.id.name_sort_mode:
adapter.changeSortingMode(SortingMode.NAME);
HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.NAME.getValue());
album.setSortingMode(SortingMode.NAME);
item.setChecked(true);
return true;
case R.id.date_taken_sort_mode:
adapter.changeSortingMode(SortingMode.DATE);
HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.DATE.getValue());
album.setSortingMode(SortingMode.DATE);
item.setChecked(true);
return true;
case R.id.size_sort_mode:
adapter.changeSortingMode(SortingMode.SIZE);
HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.SIZE.getValue());
album.setSortingMode(SortingMode.SIZE);
item.setChecked(true);
return true;
case R.id.numeric_sort_mode:
adapter.changeSortingMode(SortingMode.NUMERIC);
HandlingAlbums.getInstance(getContext()).setSortingMode(album.getPath(), SortingMode.NUMERIC.getValue());
album.setSortingMode(SortingMode.NUMERIC);
item.setChecked(true);
return true;
case R.id.ascending_sort_order:
item.setChecked(!item.isChecked());
SortingOrder sortingOrder = SortingOrder.fromValue(item.isChecked());
adapter.changeSortingOrder(sortingOrder);
HandlingAlbums.getInstance(getContext()).setSortingOrder(album.getPath(), sortingOrder.getValue());
album.setSortingOrder(sortingOrder);
return true;
case R.id.delete:
ProgressAdapter errorsAdapter = new ProgressAdapter(getContext());
ArrayList<Media> selected = adapter.getSelected();
AlertDialog alertDialog = AlertDialogsHelper.getProgressDialogWithErrors(((ThemedActivity) getActivity()), R.string.deleting_images, errorsAdapter, selected.size());
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, this.getString(R.string.cancel).toUpperCase(), (dialog, id) -> {
alertDialog.dismiss();
});
alertDialog.show();
MediaHelper.deleteMedia(getContext(), selected).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(m -> {
adapter.remove(m);
errorsAdapter.add(new ProgressAdapter.ListItem(m.getName()), false);
}, throwable -> {
if (throwable instanceof DeleteException)
errorsAdapter.add(new ProgressAdapter.ListItem((DeleteException) throwable), true);
}, () -> {
if (errorsAdapter.getItemCount() == 0)
alertDialog.dismiss();
adapter.clearSelected();
});
return true;
// TODO: 11/21/16 move away from here
case R.id.affix:
// region Async MediaAffix
class affixMedia extends AsyncTask<Affix.Options, Integer, Void> {
private AlertDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = AlertDialogsHelper.getProgressDialog((ThemedActivity) getActivity(), getString(R.string.affix), getString(R.string.affix_text));
dialog.show();
}
@Override
protected Void doInBackground(Affix.Options... arg0) {
ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
for (int i = 0; i < adapter.getSelectedCount(); i++) {
if (!adapter.getSelected().get(i).isVideo())
bitmapArray.add(adapter.getSelected().get(i).getBitmap());
}
if (bitmapArray.size() > 1)
Affix.AffixBitmapList(getActivity(), bitmapArray, arg0[0]);
else
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getContext(), R.string.affix_error, Toast.LENGTH_SHORT).show();
}
});
return null;
}
@Override
protected void onPostExecute(Void result) {
adapter.clearSelected();
dialog.dismiss();
}
}
// endregion
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), getDialogStyle());
final View dialogLayout = getLayoutInflater().inflate(R.layout.dialog_affix, null);
dialogLayout.findViewById(R.id.affix_title).setBackgroundColor(getPrimaryColor());
((CardView) dialogLayout.findViewById(R.id.affix_card)).setCardBackgroundColor(getCardBackgroundColor());
// ITEMS
final SwitchCompat swVertical = dialogLayout.findViewById(R.id.affix_vertical_switch);
final SwitchCompat swSaveHere = dialogLayout.findViewById(R.id.save_here_switch);
final LinearLayout llSwVertical = dialogLayout.findViewById(R.id.ll_affix_vertical);
final LinearLayout llSwSaveHere = dialogLayout.findViewById(R.id.ll_affix_save_here);
final RadioGroup radioFormatGroup = dialogLayout.findViewById(R.id.radio_format);
final TextView txtQuality = dialogLayout.findViewById(R.id.affix_quality_title);
final SeekBar seekQuality = dialogLayout.findViewById(R.id.seek_bar_quality);
// region Example
final LinearLayout llExample = dialogLayout.findViewById(R.id.affix_example);
llExample.setBackgroundColor(getBackgroundColor());
llExample.setVisibility(Hawk.get("show_tips", true) ? View.VISIBLE : View.GONE);
final LinearLayout llExampleH = dialogLayout.findViewById(R.id.affix_example_horizontal);
// llExampleH.setBackgroundColor(getCardBackgroundColor());
final LinearLayout llExampleV = dialogLayout.findViewById(R.id.affix_example_vertical);
// llExampleV.setBackgroundColor(getCardBackgroundColor());
// endregion
// region THEME STUFF
getThemeHelper().setScrollViewColor(dialogLayout.findViewById(R.id.affix_scrollView));
/**
* TextViews *
*/
int color = getTextColor();
((TextView) dialogLayout.findViewById(R.id.affix_vertical_title)).setTextColor(color);
((TextView) dialogLayout.findViewById(R.id.compression_settings_title)).setTextColor(color);
((TextView) dialogLayout.findViewById(R.id.save_here_title)).setTextColor(color);
// Example Stuff
((TextView) dialogLayout.findViewById(R.id.affix_example_horizontal_txt1)).setTextColor(color);
((TextView) dialogLayout.findViewById(R.id.affix_example_horizontal_txt2)).setTextColor(color);
((TextView) dialogLayout.findViewById(R.id.affix_example_vertical_txt1)).setTextColor(color);
((TextView) dialogLayout.findViewById(R.id.affix_example_vertical_txt2)).setTextColor(color);
/**
* Sub TextViews *
*/
color = getThemeHelper().getSubTextColor();
((TextView) dialogLayout.findViewById(R.id.save_here_sub)).setTextColor(color);
((TextView) dialogLayout.findViewById(R.id.affix_vertical_sub)).setTextColor(color);
((TextView) dialogLayout.findViewById(R.id.affix_format_sub)).setTextColor(color);
txtQuality.setTextColor(color);
/**
* Icons *
*/
color = getIconColor();
((ThemedIcon) dialogLayout.findViewById(R.id.affix_quality_icon)).setColor(color);
((ThemedIcon) dialogLayout.findViewById(R.id.affix_format_icon)).setColor(color);
((ThemedIcon) dialogLayout.findViewById(R.id.affix_vertical_icon)).setColor(color);
((ThemedIcon) dialogLayout.findViewById(R.id.save_here_icon)).setColor(color);
// Example bg
color = getCardBackgroundColor();
dialogLayout.findViewById(R.id.affix_example_horizontal_txt1).setBackgroundColor(color);
dialogLayout.findViewById(R.id.affix_example_horizontal_txt2).setBackgroundColor(color);
dialogLayout.findViewById(R.id.affix_example_vertical_txt1).setBackgroundColor(color);
dialogLayout.findViewById(R.id.affix_example_vertical_txt2).setBackgroundColor(color);
seekQuality.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN));
seekQuality.getThumb().setColorFilter(new PorterDuffColorFilter(getAccentColor(), PorterDuff.Mode.SRC_IN));
getThemeHelper().themeRadioButton(dialogLayout.findViewById(R.id.radio_jpeg));
getThemeHelper().themeRadioButton(dialogLayout.findViewById(R.id.radio_png));
getThemeHelper().themeRadioButton(dialogLayout.findViewById(R.id.radio_webp));
getThemeHelper().setSwitchCompactColor(swSaveHere, getAccentColor());
getThemeHelper().setSwitchCompactColor(swVertical, getAccentColor());
// #endregion
seekQuality.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
txtQuality.setText(StringUtils.html(String.format(Locale.getDefault(), "%s <b>%d</b>", getString(R.string.quality), progress)));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
seekQuality.setProgress(50);
swVertical.setClickable(false);
llSwVertical.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
swVertical.setChecked(!swVertical.isChecked());
getThemeHelper().setSwitchCompactColor(swVertical, getAccentColor());
llExampleH.setVisibility(swVertical.isChecked() ? View.GONE : View.VISIBLE);
llExampleV.setVisibility(swVertical.isChecked() ? View.VISIBLE : View.GONE);
}
});
swSaveHere.setClickable(false);
llSwSaveHere.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
swSaveHere.setChecked(!swSaveHere.isChecked());
getThemeHelper().setSwitchCompactColor(swSaveHere, getAccentColor());
}
});
builder.setView(dialogLayout);
builder.setPositiveButton(this.getString(R.string.ok_action).toUpperCase(), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Bitmap.CompressFormat compressFormat;
switch(radioFormatGroup.getCheckedRadioButtonId()) {
case R.id.radio_jpeg:
default:
compressFormat = Bitmap.CompressFormat.JPEG;
break;
case R.id.radio_png:
compressFormat = Bitmap.CompressFormat.PNG;
break;
case R.id.radio_webp:
compressFormat = Bitmap.CompressFormat.WEBP;
break;
}
Affix.Options options = new Affix.Options(swSaveHere.isChecked() ? adapter.getFirstSelected().getPath() : Affix.getDefaultDirectoryPath(), compressFormat, seekQuality.getProgress(), swVertical.isChecked());
new affixMedia().execute(options);
}
});
builder.setNegativeButton(this.getString(R.string.cancel).toUpperCase(), null);
builder.show();
return true;
}
return super.onOptionsItemSelected(item);
}
use of org.horaapps.liz.ui.ThemedIcon in project LeafPic by HoraApps.
the class Security method authenticateUser.
public static void authenticateUser(final ThemedActivity activity, final AuthCallBack passwordInterface) {
AlertDialog.Builder builder = new AlertDialog.Builder(activity, activity.getDialogStyle());
CancellationSignal mCancellationSignal = new CancellationSignal();
final View view = activity.getLayoutInflater().inflate(org.horaapps.leafpic.R.layout.dialog_password, null);
final TextView passwordDialogTitle = view.findViewById(org.horaapps.leafpic.R.id.password_dialog_title);
final CardView passwordDialogCard = view.findViewById(org.horaapps.leafpic.R.id.password_dialog_card);
final EditText editTextPassword = view.findViewById(org.horaapps.leafpic.R.id.password_edittxt);
final ThemedIcon fingerprintIcon = view.findViewById(R.id.fingerprint_icon);
passwordDialogTitle.setBackgroundColor(activity.getPrimaryColor());
passwordDialogCard.setBackgroundColor(activity.getCardBackgroundColor());
ThemeHelper.setCursorColor(editTextPassword, activity.getTextColor());
editTextPassword.getBackground().mutate().setColorFilter(activity.getTextColor(), PorterDuff.Mode.SRC_ATOP);
editTextPassword.setTextColor(activity.getTextColor());
fingerprintIcon.setColor(activity.getIconColor());
builder.setView(view);
builder.setPositiveButton(activity.getString(R.string.ok_action).toUpperCase(), (dialog, which) -> {
// NOTE: set this empty, later will be overwrite to avoid the dismiss
});
builder.setNegativeButton(activity.getString(R.string.cancel).toUpperCase(), (dialog, which) -> hideKeyboard(activity, editTextPassword.getWindowToken()));
final AlertDialog dialog = builder.create();
dialog.show();
showKeyboard(activity);
editTextPassword.requestFocus();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M && Security.isFingerprintUsed()) {
FingerprintHandler fingerprintHandler = new FingerprintHandler(activity, mCancellationSignal);
if (fingerprintHandler.isFingerprintSupported()) {
fingerprintHandler.setOnFingerprintResult(new FingerprintHandler.CallBack() {
@Override
public void onSuccess() {
hideKeyboard(activity, editTextPassword.getWindowToken());
dialog.dismiss();
passwordInterface.onAuthenticated();
}
@Override
public void onError(String s) {
// TODO: 9/9/17 siplaymessage
}
});
fingerprintHandler.startAuth();
} else {
fingerprintIcon.setVisibility(View.GONE);
}
} else {
fingerprintIcon.setVisibility(View.GONE);
}
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
if (checkPassword(editTextPassword.getText().toString())) {
hideKeyboard(activity, editTextPassword.getWindowToken());
mCancellationSignal.cancel();
dialog.dismiss();
passwordInterface.onAuthenticated();
} else {
editTextPassword.getText().clear();
editTextPassword.requestFocus();
passwordInterface.onError();
}
});
}
Aggregations