use of com.google.android.material.card.MaterialCardView in project browser by scoute-dich.
the class ProfilesList method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(ContextCompat.getColor(this, R.color.md_theme_light_onBackground));
if (getSupportActionBar() != null)
getSupportActionBar().hide();
HelperUnit.initTheme(this);
setContentView(R.layout.activity_settings_profile_list);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
listToLoad = sp.getString("listToLoad", "standard");
if (listToLoad != null) {
switch(listToLoad) {
case "protected":
setTitle(R.string.setting_title_profiles_protectedList);
break;
case "standard":
setTitle(R.string.setting_title_profiles_standardList);
break;
case "trusted":
setTitle(R.string.setting_title_profiles_trustedList);
break;
}
}
listProtected = new List_protected(this);
listStandard = new List_standard(this);
listTrusted = new List_trusted(this);
RecordAction action = new RecordAction(this);
action.open(false);
switch(listToLoad) {
case "protected":
list = action.listDomains(RecordUnit.TABLE_PROTECTED);
break;
case "standard":
list = action.listDomains(RecordUnit.TABLE_STANDARD);
break;
case "trusted":
list = action.listDomains(RecordUnit.TABLE_TRUSTED);
break;
}
action.close();
ListView listView = findViewById(R.id.whitelist);
listView.setEmptyView(findViewById(R.id.whitelist_empty));
// noinspection NullableProblems
adapter = new AdapterProfileList(this, list) {
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
View v = super.getView(position, convertView, parent);
Button deleteEntry = v.findViewById(R.id.cancelButton);
deleteEntry.setVisibility(View.VISIBLE);
MaterialCardView cardView = v.findViewById(R.id.cardView);
cardView.setVisibility(View.GONE);
deleteEntry.setOnClickListener(v1 -> {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(ProfilesList.this);
builder.setIcon(R.drawable.icon_alert);
builder.setTitle(R.string.menu_delete);
builder.setMessage(R.string.hint_database);
builder.setPositiveButton(R.string.app_ok, (dialog, whichButton) -> {
switch(listToLoad) {
case "protected":
listProtected.removeDomain(list.get(position));
break;
case "standard":
listStandard.removeDomain(list.get(position));
break;
case "trusted":
listTrusted.removeDomain(list.get(position));
break;
}
list.remove(position);
notifyDataSetChanged();
NinjaToast.show(ProfilesList.this, R.string.toast_delete_successful);
});
builder.setNegativeButton(R.string.app_cancel, (dialog, whichButton) -> dialog.cancel());
AlertDialog dialog = builder.create();
dialog.show();
HelperUnit.setupDialog(ProfilesList.this, dialog);
});
return v;
}
};
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
Button button = findViewById(R.id.whitelist_add);
button.setOnClickListener(v -> {
EditText editText = findViewById(R.id.whitelist_edit);
String domain = editText.getText().toString().trim();
if (domain.isEmpty()) {
NinjaToast.show(ProfilesList.this, R.string.toast_input_empty);
} else if (!BrowserUnit.isURL(domain)) {
NinjaToast.show(ProfilesList.this, R.string.toast_invalid_domain);
} else {
RecordAction action1 = new RecordAction(ProfilesList.this);
action1.open(true);
if (action1.checkDomain(domain, RecordUnit.TABLE_PROTECTED)) {
NinjaToast.show(ProfilesList.this, R.string.toast_domain_already_exists);
} else {
switch(listToLoad) {
case "protected":
listProtected.addDomain(domain.trim());
break;
case "standard":
listStandard.addDomain(domain.trim());
break;
case "trusted":
listTrusted.addDomain(domain.trim());
break;
}
list.add(0, domain.trim());
adapter.notifyDataSetChanged();
NinjaToast.show(ProfilesList.this, R.string.toast_add_whitelist_successful);
}
action1.close();
}
});
}
use of com.google.android.material.card.MaterialCardView in project browser by scoute-dich.
the class BrowserActivity method showContextMenuList.
private void showContextMenuList(final String title, final String url, final AdapterRecord adapterRecord, final List<Record> recordList, final int location) {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
View dialogView = View.inflate(context, R.layout.dialog_menu, null);
TextView menuTitle = dialogView.findViewById(R.id.menuTitle);
menuTitle.setText(title);
FaviconHelper.setFavicon(context, dialogView, url, R.id.menu_icon, R.drawable.icon_image_broken);
builder.setView(dialogView);
AlertDialog dialog = builder.create();
dialog.show();
Objects.requireNonNull(dialog.getWindow()).setGravity(Gravity.BOTTOM);
GridItem item_01 = new GridItem(getString(R.string.main_menu_new_tabOpen), 0);
GridItem item_02 = new GridItem(getString(R.string.main_menu_new_tab), 0);
GridItem item_03 = new GridItem(getString(R.string.main_menu_new_tabProfile), 0);
GridItem item_04 = new GridItem(getString(R.string.menu_share_link), 0);
GridItem item_05 = new GridItem(getString(R.string.menu_delete), 0);
GridItem item_06 = new GridItem(getString(R.string.menu_edit), 0);
final List<GridItem> gridList = new LinkedList<>();
if (overViewTab.equals(getString(R.string.album_title_bookmarks)) || overViewTab.equals(getString(R.string.album_title_home))) {
gridList.add(gridList.size(), item_01);
gridList.add(gridList.size(), item_02);
gridList.add(gridList.size(), item_03);
gridList.add(gridList.size(), item_04);
gridList.add(gridList.size(), item_05);
gridList.add(gridList.size(), item_06);
} else {
gridList.add(gridList.size(), item_01);
gridList.add(gridList.size(), item_02);
gridList.add(gridList.size(), item_03);
gridList.add(gridList.size(), item_04);
gridList.add(gridList.size(), item_05);
}
GridView menu_grid = dialogView.findViewById(R.id.menu_grid);
int orientation = this.getResources().getConfiguration().orientation;
if (orientation == Configuration.ORIENTATION_PORTRAIT)
menu_grid.setNumColumns(1);
else
menu_grid.setNumColumns(3);
GridAdapter gridAdapter = new GridAdapter(context, gridList);
menu_grid.setAdapter(gridAdapter);
gridAdapter.notifyDataSetChanged();
menu_grid.setOnItemClickListener((parent, view, position, id) -> {
dialog.cancel();
MaterialAlertDialogBuilder builderSubMenu;
AlertDialog dialogSubMenu;
switch(position) {
case 0:
addAlbum(getString(R.string.app_name), url, true, false, "");
hideOverview();
break;
case 1:
addAlbum(getString(R.string.app_name), url, false, false, "");
break;
case 2:
addAlbum(getString(R.string.app_name), url, true, true, "");
hideOverview();
break;
case 3:
shareLink(title, url);
break;
case 4:
builderSubMenu = new MaterialAlertDialogBuilder(context);
builderSubMenu.setIcon(R.drawable.icon_alert);
builderSubMenu.setTitle(R.string.menu_delete);
builderSubMenu.setMessage(R.string.hint_database);
builderSubMenu.setPositiveButton(R.string.app_ok, (dialog2, whichButton) -> {
Record record = recordList.get(location);
RecordAction action = new RecordAction(context);
action.open(true);
if (overViewTab.equals(getString(R.string.album_title_home)))
action.deleteURL(record.getURL(), RecordUnit.TABLE_START);
else if (overViewTab.equals(getString(R.string.album_title_bookmarks)))
action.deleteURL(record.getURL(), RecordUnit.TABLE_BOOKMARK);
else if (overViewTab.equals(getString(R.string.album_title_history)))
action.deleteURL(record.getURL(), RecordUnit.TABLE_HISTORY);
action.close();
recordList.remove(location);
adapterRecord.notifyDataSetChanged();
});
builderSubMenu.setNegativeButton(R.string.app_cancel, (dialog2, whichButton) -> builderSubMenu.setCancelable(true));
dialogSubMenu = builderSubMenu.create();
dialogSubMenu.show();
HelperUnit.setupDialog(context, dialogSubMenu);
break;
case 5:
builderSubMenu = new MaterialAlertDialogBuilder(context);
View dialogViewSubMenu = View.inflate(context, R.layout.dialog_edit, null);
LinearLayout editButtonsLayout = dialogViewSubMenu.findViewById(R.id.editButtonsLayout);
editButtonsLayout.setVisibility(View.VISIBLE);
TextInputLayout editTopLayout = dialogViewSubMenu.findViewById(R.id.editTopLayout);
editTopLayout.setHint(getString(R.string.dialog_title_hint));
TextInputLayout editBottomLayout = dialogViewSubMenu.findViewById(R.id.editBottomLayout);
editBottomLayout.setHint(getString(R.string.dialog_URL_hint));
EditText editTop = dialogViewSubMenu.findViewById(R.id.editTop);
EditText editBottom = dialogViewSubMenu.findViewById(R.id.editBottom);
editTop.setText(title);
editTop.setHint(getString(R.string.dialog_title_hint));
editBottom.setText(url);
editBottom.setHint(getString(R.string.dialog_URL_hint));
Chip chip_desktopMode = dialogViewSubMenu.findViewById(R.id.editDesktopMode);
chip_desktopMode.setChecked(recordList.get(location).getDesktopMode());
Chip chip_nightMode = dialogViewSubMenu.findViewById(R.id.editNightMode);
chip_nightMode.setChecked(!recordList.get(location).getNightMode());
MaterialCardView ib_icon = dialogViewSubMenu.findViewById(R.id.editIcon);
if (!overViewTab.equals(getString(R.string.album_title_bookmarks)))
ib_icon.setVisibility(View.GONE);
ib_icon.setOnClickListener(v -> {
MaterialAlertDialogBuilder builderFilter = new MaterialAlertDialogBuilder(context);
View dialogViewFilter = View.inflate(context, R.layout.dialog_menu, null);
builderFilter.setView(dialogViewFilter);
AlertDialog dialogFilter = builderFilter.create();
dialogFilter.show();
TextView menuTitleFilter = dialogViewFilter.findViewById(R.id.menuTitle);
menuTitleFilter.setText(R.string.menu_filter);
CardView cardView = dialogViewFilter.findViewById(R.id.cardView);
cardView.setVisibility(View.GONE);
Objects.requireNonNull(dialogFilter.getWindow()).setGravity(Gravity.BOTTOM);
GridView menuEditFilter = dialogViewFilter.findViewById(R.id.menu_grid);
final List<GridItem> menuEditFilterList = new LinkedList<>();
HelperUnit.addFilterItems(activity, menuEditFilterList);
GridAdapter menuEditFilterAdapter = new GridAdapter(context, menuEditFilterList);
menuEditFilter.setNumColumns(2);
menuEditFilter.setHorizontalSpacing(20);
menuEditFilter.setVerticalSpacing(20);
menuEditFilter.setAdapter(menuEditFilterAdapter);
menuEditFilterAdapter.notifyDataSetChanged();
menuEditFilter.setOnItemClickListener((parent2, view2, position2, id2) -> {
newIcon = menuEditFilterList.get(position2).getData();
HelperUnit.setFilterIcons(context, ib_icon, newIcon);
dialogFilter.cancel();
});
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(HelperUnit.convertDpToPixel(20f, context), HelperUnit.convertDpToPixel(10f, context), HelperUnit.convertDpToPixel(20f, context), HelperUnit.convertDpToPixel(10f, context));
menuEditFilter.setLayoutParams(params);
});
newIcon = recordList.get(location).getIconColor();
HelperUnit.setFilterIcons(context, ib_icon, newIcon);
builderSubMenu.setView(dialogViewSubMenu);
builderSubMenu.setTitle(getString(R.string.menu_edit));
dialogSubMenu = builderSubMenu.create();
dialogSubMenu.show();
HelperUnit.setupDialog(context, dialogSubMenu);
Button ib_cancel = dialogViewSubMenu.findViewById(R.id.editCancel);
ib_cancel.setOnClickListener(v -> {
HelperUnit.hideSoftKeyboard(editBottom, context);
dialogSubMenu.cancel();
});
Button ib_ok = dialogViewSubMenu.findViewById(R.id.editOK);
ib_ok.setOnClickListener(v -> {
if (overViewTab.equals(getString(R.string.album_title_bookmarks))) {
RecordAction action = new RecordAction(context);
action.open(true);
action.deleteURL(url, RecordUnit.TABLE_BOOKMARK);
action.addBookmark(new Record(editTop.getText().toString(), editBottom.getText().toString(), 0, 0, BOOKMARK_ITEM, chip_desktopMode.isChecked(), chip_nightMode.isChecked(), newIcon));
action.close();
bottom_navigation.setSelectedItemId(R.id.page_2);
} else {
RecordAction action = new RecordAction(context);
action.open(true);
action.deleteURL(url, RecordUnit.TABLE_START);
int counter = sp.getInt("counter", 0);
counter = counter + 1;
sp.edit().putInt("counter", counter).apply();
action.addStartSite(new Record(editTop.getText().toString(), editBottom.getText().toString(), 0, counter, STARTSITE_ITEM, chip_desktopMode.isChecked(), chip_nightMode.isChecked(), 0));
action.close();
bottom_navigation.setSelectedItemId(R.id.page_1);
}
HelperUnit.hideSoftKeyboard(editBottom, context);
dialogSubMenu.cancel();
});
break;
}
});
}
use of com.google.android.material.card.MaterialCardView in project browser by scoute-dich.
the class BrowserActivity method showDialogFastToggle.
// Dialogs
private void showDialogFastToggle() {
listTrusted = new List_trusted(context);
listStandard = new List_standard(context);
listProtected = new List_protected(context);
ninjaWebView = (NinjaWebView) currentAlbumController;
String url = ninjaWebView.getUrl();
if (url != null) {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context);
View dialogView = View.inflate(context, R.layout.dialog_toggle, null);
builder.setView(dialogView);
Chip chip_profile_standard = dialogView.findViewById(R.id.chip_profile_standard);
Chip chip_profile_trusted = dialogView.findViewById(R.id.chip_profile_trusted);
Chip chip_profile_changed = dialogView.findViewById(R.id.chip_profile_changed);
Chip chip_profile_protected = dialogView.findViewById(R.id.chip_profile_protected);
TextView dialog_warning = dialogView.findViewById(R.id.dialog_titleDomain);
dialog_warning.setText(HelperUnit.domain(url));
FaviconHelper.setFavicon(context, dialogView, url, R.id.menu_icon, R.drawable.icon_image_broken);
TextView dialog_titleProfile = dialogView.findViewById(R.id.dialog_titleProfile);
ninjaWebView.putProfileBoolean("", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
AlertDialog dialog = builder.create();
dialog.show();
Objects.requireNonNull(dialog.getWindow()).setGravity(Gravity.BOTTOM);
// ProfileControl
Chip chip_setProfileTrusted = dialogView.findViewById(R.id.chip_setProfileTrusted);
chip_setProfileTrusted.setChecked(listTrusted.isWhite(url));
chip_setProfileTrusted.setOnClickListener(v -> {
if (listTrusted.isWhite(ninjaWebView.getUrl()))
listTrusted.removeDomain(HelperUnit.domain(url));
else {
listTrusted.addDomain(HelperUnit.domain(url));
listStandard.removeDomain(HelperUnit.domain(url));
listProtected.removeDomain(HelperUnit.domain(url));
}
ninjaWebView.reload();
dialog.cancel();
});
chip_setProfileTrusted.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_profiles_trustedList), Toast.LENGTH_SHORT).show();
return true;
});
Chip chip_setProfileProtected = dialogView.findViewById(R.id.chip_setProfileProtected);
chip_setProfileProtected.setChecked(listProtected.isWhite(url));
chip_setProfileProtected.setOnClickListener(v -> {
if (listProtected.isWhite(ninjaWebView.getUrl()))
listProtected.removeDomain(HelperUnit.domain(url));
else {
listProtected.addDomain(HelperUnit.domain(url));
listTrusted.removeDomain(HelperUnit.domain(url));
listStandard.removeDomain(HelperUnit.domain(url));
}
ninjaWebView.reload();
dialog.cancel();
});
chip_setProfileProtected.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_profiles_protectedList), Toast.LENGTH_SHORT).show();
return true;
});
Chip chip_setProfileStandard = dialogView.findViewById(R.id.chip_setProfileStandard);
chip_setProfileStandard.setChecked(listStandard.isWhite(url));
chip_setProfileStandard.setOnClickListener(v -> {
if (listStandard.isWhite(ninjaWebView.getUrl()))
listStandard.removeDomain(HelperUnit.domain(url));
else {
listStandard.addDomain(HelperUnit.domain(url));
listTrusted.removeDomain(HelperUnit.domain(url));
listProtected.removeDomain(HelperUnit.domain(url));
}
ninjaWebView.reload();
dialog.cancel();
});
chip_setProfileStandard.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_profiles_standardList), Toast.LENGTH_SHORT).show();
return true;
});
chip_profile_trusted.setChecked(Objects.equals(sp.getString("profile", "profileTrusted"), "profileTrusted"));
chip_profile_trusted.setOnClickListener(v -> {
sp.edit().putString("profile", "profileTrusted").apply();
ninjaWebView.reload();
dialog.cancel();
});
chip_profile_trusted.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_profiles_trusted), Toast.LENGTH_SHORT).show();
return true;
});
chip_profile_standard.setChecked(Objects.equals(sp.getString("profile", "profileTrusted"), "profileStandard"));
chip_profile_standard.setOnClickListener(v -> {
sp.edit().putString("profile", "profileStandard").apply();
ninjaWebView.reload();
dialog.cancel();
});
chip_profile_standard.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_profiles_standard), Toast.LENGTH_SHORT).show();
return true;
});
chip_profile_protected.setChecked(Objects.equals(sp.getString("profile", "profileTrusted"), "profileProtected"));
chip_profile_protected.setOnClickListener(v -> {
sp.edit().putString("profile", "profileProtected").apply();
ninjaWebView.reload();
dialog.cancel();
});
chip_profile_protected.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_profiles_protected), Toast.LENGTH_SHORT).show();
return true;
});
chip_profile_changed.setChecked(Objects.equals(sp.getString("profile", "profileTrusted"), "profileChanged"));
chip_profile_changed.setOnClickListener(v -> {
sp.edit().putString("profile", "profileChanged").apply();
ninjaWebView.reload();
dialog.cancel();
});
chip_profile_changed.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_profiles_changed), Toast.LENGTH_SHORT).show();
return true;
});
// CheckBox
Chip chip_image = dialogView.findViewById(R.id.chip_image);
chip_image.setChecked(ninjaWebView.getBoolean("_images"));
chip_image.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_images), Toast.LENGTH_SHORT).show();
return true;
});
chip_image.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_images", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
Chip chip_javaScript = dialogView.findViewById(R.id.chip_javaScript);
chip_javaScript.setChecked(ninjaWebView.getBoolean("_javascript"));
chip_javaScript.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_javascript), Toast.LENGTH_SHORT).show();
return true;
});
chip_javaScript.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_javascript", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
Chip chip_javaScriptPopUp = dialogView.findViewById(R.id.chip_javaScriptPopUp);
chip_javaScriptPopUp.setChecked(ninjaWebView.getBoolean("_javascriptPopUp"));
chip_javaScriptPopUp.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_javascript_popUp), Toast.LENGTH_SHORT).show();
return true;
});
chip_javaScriptPopUp.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_javascriptPopUp", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
Chip chip_cookie = dialogView.findViewById(R.id.chip_cookie);
chip_cookie.setChecked(ninjaWebView.getBoolean("_cookies"));
chip_cookie.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_cookie), Toast.LENGTH_SHORT).show();
return true;
});
chip_cookie.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_cookies", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
Chip chip_fingerprint = dialogView.findViewById(R.id.chip_Fingerprint);
chip_fingerprint.setChecked(ninjaWebView.getBoolean("_fingerPrintProtection"));
chip_fingerprint.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_fingerPrint), Toast.LENGTH_SHORT).show();
return true;
});
chip_fingerprint.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_fingerPrintProtection", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
Chip chip_adBlock = dialogView.findViewById(R.id.chip_adBlock);
chip_adBlock.setChecked(ninjaWebView.getBoolean("_adBlock"));
chip_adBlock.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_adblock), Toast.LENGTH_SHORT).show();
return true;
});
chip_adBlock.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_adBlock", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
Chip chip_saveData = dialogView.findViewById(R.id.chip_saveData);
chip_saveData.setChecked(ninjaWebView.getBoolean("_saveData"));
chip_saveData.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_save_data), Toast.LENGTH_SHORT).show();
return true;
});
chip_saveData.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_saveData", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
Chip chip_history = dialogView.findViewById(R.id.chip_history);
chip_history.setChecked(ninjaWebView.getBoolean("_saveHistory"));
chip_history.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.album_title_history), Toast.LENGTH_SHORT).show();
return true;
});
chip_history.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_saveHistory", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
Chip chip_location = dialogView.findViewById(R.id.chip_location);
chip_location.setChecked(ninjaWebView.getBoolean("_location"));
chip_location.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_location), Toast.LENGTH_SHORT).show();
return true;
});
chip_location.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_location", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
Chip chip_microphone = dialogView.findViewById(R.id.chip_microphone);
chip_microphone.setChecked(ninjaWebView.getBoolean("_microphone"));
chip_microphone.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_microphone), Toast.LENGTH_SHORT).show();
return true;
});
chip_microphone.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_microphone", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
Chip chip_camera = dialogView.findViewById(R.id.chip_camera);
chip_camera.setChecked(ninjaWebView.getBoolean("_camera"));
chip_camera.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_camera), Toast.LENGTH_SHORT).show();
return true;
});
chip_camera.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_camera", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
Chip chip_dom = dialogView.findViewById(R.id.chip_dom);
chip_dom.setChecked(ninjaWebView.getBoolean("_dom"));
chip_dom.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_dom), Toast.LENGTH_SHORT).show();
return true;
});
chip_dom.setOnClickListener(v -> {
ninjaWebView.setProfileChanged();
ninjaWebView.putProfileBoolean("_dom", dialog_titleProfile, chip_profile_trusted, chip_profile_standard, chip_profile_protected, chip_profile_changed);
});
if (listTrusted.isWhite(url) || listStandard.isWhite(url) || listProtected.isWhite(url)) {
TypedValue typedValue = new TypedValue();
Resources.Theme theme = context.getTheme();
theme.resolveAttribute(R.attr.colorError, typedValue, true);
int color = typedValue.data;
MaterialCardView cardView = dialogView.findViewById(R.id.editProfile);
cardView.setVisibility(View.GONE);
dialog_warning.setTextColor(color);
}
Chip chip_toggleNightView = dialogView.findViewById(R.id.chip_toggleNightView);
chip_toggleNightView.setChecked(ninjaWebView.isNightMode());
chip_toggleNightView.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.menu_nightView), Toast.LENGTH_SHORT).show();
return true;
});
chip_toggleNightView.setOnClickListener(v -> {
ninjaWebView.toggleNightMode();
isNightMode = ninjaWebView.isNightMode();
dialog.cancel();
});
Chip chip_toggleDesktop = dialogView.findViewById(R.id.chip_toggleDesktop);
chip_toggleDesktop.setChecked(ninjaWebView.isDesktopMode());
chip_toggleDesktop.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.menu_desktopView), Toast.LENGTH_SHORT).show();
return true;
});
chip_toggleDesktop.setOnClickListener(v -> {
ninjaWebView.toggleDesktopMode(true);
dialog.cancel();
});
Chip chip_toggleScreenOn = dialogView.findViewById(R.id.chip_toggleScreenOn);
chip_toggleScreenOn.setChecked(sp.getBoolean("sp_screenOn", false));
chip_toggleScreenOn.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_screenOn), Toast.LENGTH_SHORT).show();
return true;
});
chip_toggleScreenOn.setOnClickListener(v -> {
sp.edit().putBoolean("sp_screenOn", !sp.getBoolean("sp_screenOn", false)).apply();
saveOpenedTabs();
HelperUnit.triggerRebirth(context);
dialog.cancel();
});
Chip chip_toggleAudioBackground = dialogView.findViewById(R.id.chip_toggleAudioBackground);
chip_toggleAudioBackground.setChecked(sp.getBoolean("sp_audioBackground", false));
chip_toggleAudioBackground.setOnLongClickListener(view -> {
Toast.makeText(context, getString(R.string.setting_title_audioBackground), Toast.LENGTH_SHORT).show();
return true;
});
chip_toggleAudioBackground.setOnClickListener(v -> {
sp.edit().putBoolean("sp_audioBackground", !sp.getBoolean("sp_audioBackground", false)).apply();
dialog.cancel();
});
Button ib_reload = dialogView.findViewById(R.id.ib_reload);
ib_reload.setOnClickListener(view -> {
if (ninjaWebView != null) {
dialog.cancel();
ninjaWebView.reload();
}
});
Button ib_settings = dialogView.findViewById(R.id.ib_settings);
ib_settings.setOnClickListener(view -> {
if (ninjaWebView != null) {
dialog.cancel();
Intent settings = new Intent(BrowserActivity.this, Settings_Activity.class);
startActivity(settings);
}
});
Button button_help = dialogView.findViewById(R.id.button_help);
button_help.setVisibility(View.VISIBLE);
button_help.setOnClickListener(view -> {
dialog.cancel();
Uri webpage = Uri.parse("https://github.com/scoute-dich/browser/wiki/Fast-Toggle-Dialog");
BrowserUnit.intentURL(this, webpage);
});
} else {
NinjaToast.show(context, getString(R.string.app_error));
}
}
use of com.google.android.material.card.MaterialCardView in project AppManager by MuntashirAkon.
the class ScannerActivity method setTrackerInfo.
private void setTrackerInfo() {
String[] trackerNames = StaticDataset.getTrackerNames();
String[] trackerSignatures = StaticDataset.getTrackerCodeSignatures();
int[] signatureCount = new int[trackerSignatures.length];
int totalIteration = 0;
long t_start, t_end;
t_start = System.currentTimeMillis();
// Iterate over all classes
for (String className : model.getClassListAll()) {
if (className.length() > 8 && className.contains(".")) {
// This is a greedy algorithm, only matches the first item
for (int i = 0; i < trackerSignatures.length; i++) {
totalIteration++;
if (className.contains(trackerSignatures[i])) {
trackerClassList.add(className);
signatureCount[i]++;
break;
}
}
}
}
t_end = System.currentTimeMillis();
long totalTimeTaken = t_end - t_start;
Map<String, SpannableStringBuilder> foundTrackerInfoMap = new ArrayMap<>();
foundTrackerInfoMap.putAll(getNativeLibraryInfo(true));
final boolean[] hasSecondDegree = new boolean[] { false };
// Iterate over signatures again but this time list only the found ones.
for (int i = 0; i < trackerSignatures.length; i++) {
if (signatureCount[i] == 0)
continue;
if (foundTrackerInfoMap.get(trackerNames[i]) == null) {
foundTrackerInfoMap.put(trackerNames[i], new SpannableStringBuilder().append(getPrimaryText(this, trackerNames[i])));
}
// noinspection ConstantConditions Never null here
foundTrackerInfoMap.get(trackerNames[i]).append("\n").append(getMonospacedText(trackerSignatures[i])).append(getSmallerText(" (" + signatureCount[i] + ")"));
if (!hasSecondDegree[0]) {
hasSecondDegree[0] = trackerNames[i].startsWith("²");
}
}
Set<String> foundTrackerNames = foundTrackerInfoMap.keySet();
List<Spannable> foundTrackerInfo = new ArrayList<>(foundTrackerInfoMap.values());
Collections.sort(foundTrackerInfo, (o1, o2) -> o1.toString().compareToIgnoreCase(o2.toString()));
Spanned trackerList = getOrderedList(foundTrackerInfo);
SpannableStringBuilder foundTrackerList = new SpannableStringBuilder();
int totalTrackersFound = foundTrackerInfoMap.size();
if (totalTrackersFound > 0) {
foundTrackerList.append(getString(R.string.found_trackers)).append(" ").append(TextUtils.joinSpannable(", ", foundTrackerNames));
}
SpannableStringBuilder builder = new SpannableStringBuilder(getString(R.string.tested_signatures_on_classes_and_time_taken, trackerSignatures.length, classListAll.size(), totalTimeTaken, totalIteration));
if (foundTrackerList.length() > 0) {
builder.append("\n").append(foundTrackerList);
}
// Get summary
CharSequence summary;
if (totalTrackersFound == 0) {
summary = getString(R.string.no_tracker_found);
} else if (totalTrackersFound == 1) {
summary = getResources().getQuantityString(R.plurals.tracker_and_classes, trackerClassList.size(), trackerClassList.size());
} else if (totalTrackersFound == 2) {
summary = getResources().getQuantityString(R.plurals.two_trackers_and_classes, trackerClassList.size(), trackerClassList.size());
} else {
summary = getResources().getQuantityString(R.plurals.other_trackers_and_classes, totalTrackersFound, totalTrackersFound, trackerClassList.size());
}
// Add colours
CharSequence coloredSummary;
if (totalTrackersFound == 0) {
coloredSummary = getColoredText(summary, ContextCompat.getColor(this, R.color.stopped));
} else {
coloredSummary = getColoredText(summary, ContextCompat.getColor(this, R.color.electric_red));
}
runOnUiThread(() -> {
((TextView) findViewById(R.id.tracker_title)).setText(coloredSummary);
((TextView) findViewById(R.id.tracker_description)).setText(builder);
if (totalTrackersFound == 0)
return;
MaterialCardView trackersView = findViewById(R.id.tracker);
trackersView.setOnClickListener(v -> {
DialogTitleBuilder titleBuilder = new DialogTitleBuilder(this).setTitle(R.string.tracker_details).setSubtitle(summary);
if (mPackageName != null) {
titleBuilder.setEndIcon(R.drawable.ic_exodusprivacy, v1 -> {
Uri exodus_link = Uri.parse(String.format("https://reports.exodus-privacy.eu.org/en/reports/%s/latest/", mPackageName));
Intent intent = new Intent(Intent.ACTION_VIEW, exodus_link);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}).setEndIconContentDescription(R.string.exodus_link);
}
new ScrollableDialogBuilder(this, hasSecondDegree[0] ? new SpannableStringBuilder(trackerList).append("\n\n").append(getSmallerText(getText(R.string.second_degree_tracker_note))) : trackerList).setTitle(titleBuilder.build()).enableAnchors().setPositiveButton(R.string.ok, null).setNeutralButton(R.string.copy, (dialog, which, isChecked) -> {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(getString(R.string.signatures), trackerList);
clipboard.setPrimaryClip(clip);
Snackbar.make(trackersView, R.string.copied_to_clipboard, Snackbar.LENGTH_SHORT).show();
}).show();
});
});
}
use of com.google.android.material.card.MaterialCardView in project ods-android by Orange-OpenSource.
the class CardStatesFragment method onCreateDemoView.
@Override
public View onCreateDemoView(LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
View view = layoutInflater.inflate(R.layout.cat_card_states_fragment, viewGroup, false);
RadioGroup radioGroup = view.findViewById(R.id.cat_card_radio_group);
final MaterialCardView card = view.findViewById(R.id.card);
final MaterialCardView checkableCard = view.findViewById(R.id.checkable_card);
checkableCard.setOnLongClickListener(v -> {
checkableCard.setChecked(!checkableCard.isChecked());
return true;
});
radioGroup.setOnCheckedChangeListener((group, checkedId) -> {
card.setHovered(checkedId == R.id.hovered);
card.setPressed(checkedId == R.id.pressed);
checkableCard.setHovered(checkedId == R.id.hovered);
checkableCard.setPressed(checkedId == R.id.pressed);
});
return view;
}
Aggregations