use of de.baumann.browser.Browser.Cookie in project browser by scoute-dich.
the class BrowserUnit method importWhitelistCookie.
public static int importWhitelistCookie(Context context) {
String filename = context.getString(R.string.export_whitelistCookie);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "browser_backup//" + filename + SUFFIX_TXT);
Cookie cookie = new Cookie(context);
int count = 0;
try {
RecordAction action = new RecordAction(context);
action.open(true);
BufferedReader reader = new BufferedReader(new FileReader(file));
String line;
while ((line = reader.readLine()) != null) {
if (!action.checkDomainCookie(line)) {
cookie.addDomain(line);
count++;
}
}
reader.close();
action.close();
} catch (Exception e) {
Log.w("Browser", "Error reading file", e);
}
return count;
}
use of de.baumann.browser.Browser.Cookie in project browser by scoute-dich.
the class Whitelist_Cookie method onCreate.
@SuppressWarnings("ConstantConditions")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
helper_main.setTheme(this);
setContentView(R.layout.whitelist);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
RecordAction action = new RecordAction(this);
action.open(false);
list = action.listDomainsCookie();
action.close();
ListView listView = findViewById(R.id.whitelist);
listView.setEmptyView(findViewById(R.id.whitelist_empty));
adapter = new Adapter_Cookie(this, list);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
Button button = findViewById(R.id.whitelist_add);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText editText = findViewById(R.id.whitelist_edit);
String domain = editText.getText().toString().trim();
if (domain.isEmpty()) {
NinjaToast.show(Whitelist_Cookie.this, R.string.toast_input_empty);
} else if (!BrowserUnit.isURL(domain)) {
NinjaToast.show(Whitelist_Cookie.this, R.string.toast_invalid_domain);
} else {
RecordAction action = new RecordAction(Whitelist_Cookie.this);
action.open(true);
if (action.checkDomainCookie(domain)) {
NinjaToast.show(Whitelist_Cookie.this, R.string.toast_domain_already_exists);
} else {
Cookie cookie = new Cookie(Whitelist_Cookie.this);
cookie.addDomain(domain.trim());
list.add(0, domain.trim());
adapter.notifyDataSetChanged();
NinjaToast.show(Whitelist_Cookie.this, R.string.toast_add_whitelist_successful);
}
action.close();
}
}
});
}
use of de.baumann.browser.Browser.Cookie in project browser by scoute-dich.
the class Adapter_Cookie method getView.
@NonNull
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
Holder holder;
View view = convertView;
if (view == null) {
view = LayoutInflater.from(context).inflate(layoutResId, parent, false);
holder = new Holder();
holder.domain = view.findViewById(R.id.whitelist_item_domain);
holder.cancel = view.findViewById(R.id.whitelist_item_cancel);
view.setTag(holder);
} else {
holder = (Holder) view.getTag();
}
holder.domain.setText(list.get(position));
holder.cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Cookie cookie = new Cookie(context);
cookie.removeDomain(list.get(position));
list.remove(position);
notifyDataSetChanged();
NinjaToast.show(context, R.string.toast_delete_successful);
}
});
return view;
}
use of de.baumann.browser.Browser.Cookie in project browser by scoute-dich.
the class BrowserActivity method onCreate.
// Overrides
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView.enableSlowWholeDocumentDraw();
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
helper_main.grantPermissionsStorage(this);
helper_main.setTheme(this);
setContentView(R.layout.main);
sp = PreferenceManager.getDefaultSharedPreferences(this);
if (sp.getString("start_tab", "0").equals("0")) {
start_tab = BrowserUnit.FLAG_HOME;
} else if (sp.getString("start_tab", "0").equals("1")) {
start_tab = BrowserUnit.FLAG_FILES;
} else if (sp.getString("start_tab", "0").equals("2")) {
start_tab = BrowserUnit.FLAG_PASS;
} else if (sp.getString("start_tab", "0").equals("3")) {
start_tab = BrowserUnit.FLAG_BOOKMARKS;
} else {
start_tab = BrowserUnit.FLAG_HISTORY;
}
if (sp.getString("saved_key_ok", "no").equals("no")) {
char[] chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!ยง$%&/()=?;:_-.,+#*<>".toCharArray();
StringBuilder sb = new StringBuilder();
Random random = new Random();
for (int i = 0; i < 25; i++) {
char c = chars[random.nextInt(chars.length)];
sb.append(c);
}
if (Locale.getDefault().getLanguage().equals("zh")) {
sp.edit().putString(getString(R.string.sp_search_engine), "4").apply();
}
sp.edit().putString("saved_key", sb.toString()).apply();
sp.edit().putString("saved_key_ok", "yes").apply();
sp.edit().putBoolean(getString(R.string.sp_location), false).apply();
}
sp.edit().putInt("restart_changed", 0).apply();
try {
mahEncryptor = MAHEncryptor.newInstance(sp.getString("saved_key", ""));
} catch (Exception e) {
e.printStackTrace();
}
contentFrame = findViewById(R.id.main_content);
create = true;
shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
switcherPanel = findViewById(R.id.switcher_panel);
switcherPanel.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDiff = switcherPanel.getRootView().getHeight() - switcherPanel.getHeight();
if (currentAlbumController != null) {
if (heightDiff > 100) {
omniboxTitle.setVisibility(View.GONE);
} else {
omniboxTitle.setVisibility(View.VISIBLE);
}
}
}
});
switcherPanel.setStatusListener(new SwitcherPanel.StatusListener() {
@Override
public void onCollapsed() {
inputBox.clearFocus();
}
});
dimen156dp = getResources().getDimensionPixelSize(R.dimen.layout_width_156dp);
dimen144dp = getResources().getDimensionPixelSize(R.dimen.layout_width_144dp);
dimen117dp = getResources().getDimensionPixelSize(R.dimen.layout_height_117dp);
dimen108dp = getResources().getDimensionPixelSize(R.dimen.layout_height_108dp);
dimen16dp = getResources().getDimensionPixelOffset(R.dimen.layout_margin_16dp);
initSwitcherView();
initOmnibox();
initSearchPanel();
relayoutOK = findViewById(R.id.main_relayout_ok);
// For AdBlock cold boot
new AdBlock(this);
new Javascript(BrowserActivity.this);
try {
new Cookie(BrowserActivity.this);
} catch (Exception e) {
e.printStackTrace();
deleteDatabase("Ninja4.db");
recreate();
}
dispatchIntent(getIntent());
try {
PackageInfo pInfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
final String versionName = pInfo.versionName;
String oldVersionName = sp.getString("oldVersionName", "0.0");
if (!oldVersionName.equals(versionName)) {
bottomSheetDialog = new BottomSheetDialog(this);
View dialogView = View.inflate(this, R.layout.dialog_text, null);
TextView dialog_title = dialogView.findViewById(R.id.dialog_title);
dialog_title.setText(R.string.changelog_title);
TextView dialog_text = dialogView.findViewById(R.id.dialog_text);
dialog_text.setText(helper_main.textSpannable(getString(R.string.changelog_dialog)));
dialog_text.setMovementMethod(LinkMovementMethod.getInstance());
ImageButton fab = dialogView.findViewById(R.id.floatButton_ok);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sp.edit().putString("oldVersionName", versionName).apply();
bottomSheetDialog.cancel();
}
});
ImageButton fab_help = dialogView.findViewById(R.id.floatButton_help);
fab_help.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showHelpDialog();
}
});
ImageButton fab_settings = dialogView.findViewById(R.id.floatButton_settings);
fab_settings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(BrowserActivity.this, Settings_Activity.class);
startActivity(intent);
bottomSheetDialog.cancel();
}
});
bottomSheetDialog.setContentView(dialogView);
bottomSheetDialog.show();
}
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
new Handler().postDelayed(new Runnable() {
public void run() {
searchBox.requestFocus();
}
}, 500);
hide_toolbar = 1;
}
use of de.baumann.browser.Browser.Cookie in project browser by scoute-dich.
the class BrowserActivity method showSwitcher.
private void showSwitcher() {
bottomSheetDialog = new BottomSheetDialog(BrowserActivity.this);
View dialogView = View.inflate(BrowserActivity.this, R.layout.dialog_toggle, null);
CheckBox sw_java = dialogView.findViewById(R.id.switch_js);
final ImageButton whiteList_js = dialogView.findViewById(R.id.imageButton_js);
CheckBox sw_adBlock = dialogView.findViewById(R.id.switch_adBlock);
final ImageButton whiteList_ab = dialogView.findViewById(R.id.imageButton_ab);
CheckBox sw_image = dialogView.findViewById(R.id.switch_images);
CheckBox sw_cookie = dialogView.findViewById(R.id.switch_cookie);
final ImageButton whitelist_cookie = dialogView.findViewById(R.id.imageButton_cookie);
CheckBox sw_location = dialogView.findViewById(R.id.switch_location);
CheckBox sw_invert = dialogView.findViewById(R.id.switch_invert);
CheckBox sw_history = dialogView.findViewById(R.id.switch_history);
CheckBox sw_desktop = dialogView.findViewById(R.id.switch_desktop);
javaHosts = new Javascript(BrowserActivity.this);
javaHosts = getJavaHosts();
cookieHosts = new Cookie(BrowserActivity.this);
cookieHosts = getCookieHosts();
adBlock = new AdBlock(BrowserActivity.this);
adBlock = getAdBlock();
ninjaWebView = (NinjaWebView) currentAlbumController;
final String url = ninjaWebView.getUrl();
if (javaHosts.isWhite(url)) {
whiteList_js.setImageResource(R.drawable.check_green);
} else {
whiteList_js.setImageResource(R.drawable.ic_action_close_red);
}
if (cookieHosts.isWhite(url)) {
whitelist_cookie.setImageResource(R.drawable.check_green);
} else {
whitelist_cookie.setImageResource(R.drawable.ic_action_close_red);
}
if (sp.getBoolean(getString(R.string.sp_javascript), true)) {
sw_java.setChecked(true);
} else {
sw_java.setChecked(false);
}
whiteList_js.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (javaHosts.isWhite(ninjaWebView.getUrl())) {
whiteList_js.setImageResource(R.drawable.ic_action_close_red);
javaHosts.removeDomain(Uri.parse(url).getHost().replace("www.", "").trim());
} else {
whiteList_js.setImageResource(R.drawable.check_green);
javaHosts.addDomain(Uri.parse(url).getHost().replace("www.", "").trim());
}
}
});
whitelist_cookie.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (cookieHosts.isWhite(ninjaWebView.getUrl())) {
whitelist_cookie.setImageResource(R.drawable.ic_action_close_red);
cookieHosts.removeDomain(Uri.parse(url).getHost().replace("www.", "").trim());
} else {
whitelist_cookie.setImageResource(R.drawable.check_green);
cookieHosts.addDomain(Uri.parse(url).getHost().replace("www.", "").trim());
}
}
});
sw_java.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
sp.edit().putBoolean(getString(R.string.sp_javascript), true).commit();
IntentUnit.setSPChange(true);
} else {
sp.edit().putBoolean(getString(R.string.sp_javascript), false).commit();
IntentUnit.setSPChange(true);
}
}
});
if (adBlock.isWhite(url)) {
whiteList_ab.setImageResource(R.drawable.check_green);
} else {
whiteList_ab.setImageResource(R.drawable.ic_action_close_red);
}
if (sp.getBoolean(getString(R.string.sp_ad_block), true)) {
sw_adBlock.setChecked(true);
} else {
sw_adBlock.setChecked(false);
}
whiteList_ab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (adBlock.isWhite(ninjaWebView.getUrl())) {
whiteList_ab.setImageResource(R.drawable.ic_action_close_red);
adBlock.removeDomain(Uri.parse(url).getHost().replace("www.", "").trim());
} else {
whiteList_ab.setImageResource(R.drawable.check_green);
adBlock.addDomain(Uri.parse(url).getHost().replace("www.", "").trim());
}
}
});
sw_adBlock.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
sp.edit().putBoolean(getString(R.string.sp_ad_block), true).commit();
IntentUnit.setSPChange(true);
} else {
sp.edit().putBoolean(getString(R.string.sp_ad_block), false).commit();
IntentUnit.setSPChange(true);
}
}
});
if (sp.getBoolean(getString(R.string.sp_images), true)) {
sw_image.setChecked(true);
} else {
sw_image.setChecked(false);
}
sw_image.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
sp.edit().putBoolean(getString(R.string.sp_images), true).commit();
IntentUnit.setSPChange(true);
} else {
sp.edit().putBoolean(getString(R.string.sp_images), false).commit();
IntentUnit.setSPChange(true);
}
}
});
if (sp.getBoolean(getString(R.string.sp_cookies), true)) {
sw_cookie.setChecked(true);
} else {
sw_cookie.setChecked(false);
}
sw_cookie.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
sp.edit().putBoolean(getString(R.string.sp_cookies), true).commit();
IntentUnit.setSPChange(true);
} else {
sp.edit().putBoolean(getString(R.string.sp_cookies), false).commit();
IntentUnit.setSPChange(false);
}
}
});
if (sp.getBoolean("saveHistory", true)) {
sw_history.setChecked(true);
} else {
sw_history.setChecked(false);
}
sw_history.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
sp.edit().putBoolean("saveHistory", true).commit();
} else {
sp.edit().putBoolean("saveHistory", false).commit();
}
}
});
if (!sp.getBoolean(getString(R.string.sp_location), true)) {
sw_location.setChecked(false);
} else {
sw_location.setChecked(true);
}
sw_location.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
sp.edit().putBoolean(getString(R.string.sp_location), true).commit();
IntentUnit.setSPChange(true);
} else {
sp.edit().putBoolean(getString(R.string.sp_location), false).commit();
IntentUnit.setSPChange(true);
}
}
});
if (!sp.getBoolean("sp_invert", false)) {
sw_invert.setChecked(false);
} else {
sw_invert.setChecked(true);
}
sw_invert.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
sp.edit().putBoolean("sp_invert", true).commit();
initRendering(contentFrame);
} else {
sp.edit().putBoolean("sp_invert", false).commit();
initRendering(contentFrame);
}
}
});
if ((sp.getString(getString(R.string.sp_user_agent), "0").equals("1"))) {
sw_desktop.setChecked(true);
} else {
sw_desktop.setChecked(false);
}
sw_desktop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
sp.edit().putString(getString(R.string.sp_user_agent), "1").commit();
} else {
sp.edit().putString(getString(R.string.sp_user_agent), "0").commit();
}
}
});
final TextView font_text = dialogView.findViewById(R.id.font_text);
font_text.setText(sp.getString("sp_fontSize", "100"));
ImageButton font_minus = dialogView.findViewById(R.id.font_minus);
font_minus.setImageResource(R.drawable.icon_minus);
font_minus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (sp.getString("sp_fontSize", "100").equals("100")) {
Log.i(TAG, "Can not change font size");
} else if (sp.getString("sp_fontSize", "100").equals("125")) {
sp.edit().putString("sp_fontSize", "100").commit();
} else if (sp.getString("sp_fontSize", "100").equals("150")) {
sp.edit().putString("sp_fontSize", "125").commit();
} else if (sp.getString("sp_fontSize", "100").equals("175")) {
sp.edit().putString("sp_fontSize", "150").commit();
}
font_text.setText(sp.getString("sp_fontSize", "100"));
}
});
ImageButton font_plus = dialogView.findViewById(R.id.font_plus);
font_plus.setImageResource(R.drawable.icon_plus);
font_plus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (sp.getString("sp_fontSize", "100").equals("100")) {
sp.edit().putString("sp_fontSize", "125").commit();
} else if (sp.getString("sp_fontSize", "100").equals("125")) {
sp.edit().putString("sp_fontSize", "150").commit();
} else if (sp.getString("sp_fontSize", "100").equals("150")) {
sp.edit().putString("sp_fontSize", "175").commit();
} else if (sp.getString("sp_fontSize", "100").equals("175")) {
Log.i(TAG, "Can not change font size");
}
font_text.setText(sp.getString("sp_fontSize", "100"));
}
});
Button but_OK = dialogView.findViewById(R.id.action_ok);
but_OK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (ninjaWebView != null) {
bottomSheetDialog.cancel();
String url = ninjaWebView.getUrl();
removeAlbum(currentAlbumController);
addAlbum(getString(R.string.album_untitled), url, true, null);
}
}
});
Button action_cancel = dialogView.findViewById(R.id.action_cancel);
action_cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
bottomSheetDialog.cancel();
}
});
bottomSheetDialog.setContentView(dialogView);
bottomSheetDialog.show();
}
Aggregations