Search in sources :

Example 1 with Javascript

use of de.baumann.browser.Browser.Javascript in project browser by scoute-dich.

the class Whitelist_Javascript method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
    switch(menuItem.getItemId()) {
        case android.R.id.home:
            finish();
            break;
        case R.id.whitelist_menu_clear:
            final BottomSheetDialog dialog = new BottomSheetDialog(Whitelist_Javascript.this);
            View dialogView = View.inflate(Whitelist_Javascript.this, R.layout.dialog_action, null);
            TextView textView = dialogView.findViewById(R.id.dialog_text);
            textView.setText(R.string.toast_clear);
            Button action_ok = dialogView.findViewById(R.id.action_ok);
            action_ok.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    Javascript javaScript = new Javascript(Whitelist_Javascript.this);
                    javaScript.clearDomains();
                    list.clear();
                    adapter.notifyDataSetChanged();
                    dialog.cancel();
                }
            });
            Button action_cancel = dialogView.findViewById(R.id.action_cancel);
            action_cancel.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    dialog.cancel();
                }
            });
            dialog.setContentView(dialogView);
            dialog.show();
            break;
        default:
            break;
    }
    return true;
}
Also used : BottomSheetDialog(android.support.design.widget.BottomSheetDialog) Button(android.widget.Button) Adapter_Javascript(de.baumann.browser.View.Adapter_Javascript) Javascript(de.baumann.browser.Browser.Javascript) TextView(android.widget.TextView) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView)

Example 2 with Javascript

use of de.baumann.browser.Browser.Javascript in project browser by scoute-dich.

the class Whitelist_Javascript 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.listDomainsJS();
    action.close();
    ListView listView = findViewById(R.id.whitelist);
    listView.setEmptyView(findViewById(R.id.whitelist_empty));
    adapter = new Adapter_Javascript(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_Javascript.this, R.string.toast_input_empty);
            } else if (!BrowserUnit.isURL(domain)) {
                NinjaToast.show(Whitelist_Javascript.this, R.string.toast_invalid_domain);
            } else {
                RecordAction action = new RecordAction(Whitelist_Javascript.this);
                action.open(true);
                if (action.checkDomainJS(domain)) {
                    NinjaToast.show(Whitelist_Javascript.this, R.string.toast_domain_already_exists);
                } else {
                    Javascript adBlock = new Javascript(Whitelist_Javascript.this);
                    adBlock.addDomain(domain.trim());
                    list.add(0, domain.trim());
                    adapter.notifyDataSetChanged();
                    NinjaToast.show(Whitelist_Javascript.this, R.string.toast_add_whitelist_successful);
                }
                action.close();
            }
        }
    });
}
Also used : EditText(android.widget.EditText) ListView(android.widget.ListView) Adapter_Javascript(de.baumann.browser.View.Adapter_Javascript) Button(android.widget.Button) Adapter_Javascript(de.baumann.browser.View.Adapter_Javascript) Javascript(de.baumann.browser.Browser.Javascript) RecordAction(de.baumann.browser.Database.RecordAction) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with Javascript

use of de.baumann.browser.Browser.Javascript in project browser by scoute-dich.

the class BrowserUnit method importWhitelistJS.

public static int importWhitelistJS(Context context) {
    String filename = context.getString(R.string.export_whitelistJS);
    File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), "browser_backup//" + filename + SUFFIX_TXT);
    Javascript js = new Javascript(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.checkDomainJS(line)) {
                js.addDomain(line);
                count++;
            }
        }
        reader.close();
        action.close();
    } catch (Exception e) {
        Log.w("Browser", "Error reading file", e);
    }
    return count;
}
Also used : Javascript(de.baumann.browser.Browser.Javascript) BufferedReader(java.io.BufferedReader) RecordAction(de.baumann.browser.Database.RecordAction) FileReader(java.io.FileReader) File(java.io.File) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 4 with Javascript

use of de.baumann.browser.Browser.Javascript in project browser by scoute-dich.

the class Adapter_Javascript 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) {
            Javascript Javascript = new Javascript(context);
            Javascript.removeDomain(list.get(position));
            list.remove(position);
            notifyDataSetChanged();
            NinjaToast.show(context, R.string.toast_delete_successful);
        }
    });
    return view;
}
Also used : Javascript(de.baumann.browser.Browser.Javascript) TextView(android.widget.TextView) View(android.view.View) NonNull(android.support.annotation.NonNull)

Example 5 with Javascript

use of de.baumann.browser.Browser.Javascript 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;
}
Also used : SwitcherPanel(de.baumann.browser.View.SwitcherPanel) StrictMode(android.os.StrictMode) ImageButton(android.widget.ImageButton) Random(java.util.Random) PackageManager(android.content.pm.PackageManager) Javascript(de.baumann.browser.Browser.Javascript) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ViewTreeObserver(android.view.ViewTreeObserver) Cookie(de.baumann.browser.Browser.Cookie) AdBlock(de.baumann.browser.Browser.AdBlock) PackageInfo(android.content.pm.PackageInfo) Handler(android.os.Handler) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) NinjaWebView(de.baumann.browser.View.NinjaWebView) AutoCompleteTextView(android.widget.AutoCompleteTextView) DynamicGridView(org.askerov.dynamicgrid.DynamicGridView) View(android.view.View) AdapterView(android.widget.AdapterView) WebView(android.webkit.WebView) TextView(android.widget.TextView) ListView(android.widget.ListView) VideoView(android.widget.VideoView) Paint(android.graphics.Paint) BottomSheetDialog(android.support.design.widget.BottomSheetDialog)

Aggregations

Javascript (de.baumann.browser.Browser.Javascript)6 View (android.view.View)5 TextView (android.widget.TextView)5 ListView (android.widget.ListView)4 BottomSheetDialog (android.support.design.widget.BottomSheetDialog)3 Button (android.widget.Button)3 WebView (android.webkit.WebView)2 AdapterView (android.widget.AdapterView)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 HorizontalScrollView (android.widget.HorizontalScrollView)2 ImageButton (android.widget.ImageButton)2 ImageView (android.widget.ImageView)2 VideoView (android.widget.VideoView)2 AdBlock (de.baumann.browser.Browser.AdBlock)2 Cookie (de.baumann.browser.Browser.Cookie)2 RecordAction (de.baumann.browser.Database.RecordAction)2 Adapter_Javascript (de.baumann.browser.View.Adapter_Javascript)2 NinjaWebView (de.baumann.browser.View.NinjaWebView)2 DynamicGridView (org.askerov.dynamicgrid.DynamicGridView)2 PendingIntent (android.app.PendingIntent)1