// used in the web dialog popup /res/layout/web_menu_popup.xml public void webviewActionClicked(View v) { switch (v.getId()) { case R.id.saveimage: dismissDialog(); String url = ((LinearLayout) v.getParent()).getTag().toString(); Tools.DownloadAsyncTask download = new Tools.DownloadAsyncTask(url); download.execute(url); break; case R.id.openinnewtab: dismissDialog(); webWindows.add(new CustomWebView(MainActivity.this, null, null)); ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).removeAllViews(); webWindows .get(webWindows.size() - 1) .loadUrl(((LinearLayout) v.getParent()).getTag().toString()); ((ViewGroup) webLayout.findViewById(R.id.webviewholder)) .addView(webWindows.get(webWindows.size() - 1)); ((EditText) bar.findViewById(R.id.browser_searchbar)).setText(""); browserListViewAdapter.notifyDataSetChanged(); break; case R.id.copyurl: dismissDialog(); String url2 = ((LinearLayout) v.getParent()).getTag().toString(); // Gets a handle to the Clipboard Manager ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ClipData clip = ClipData.newPlainText("Copied URL", url2); clipboard.setPrimaryClip(clip); break; } }
public void closeCurrentTab(View v) { int pos = (Integer) v.getTag(); ProgressBar PB = (ProgressBar) MainActivity.webLayout.findViewById(R.id.webpgbar); ImageButton BookmarkButton = (ImageButton) MainActivity.bar.findViewById(R.id.browser_bookmark); ImageButton refreshButton = (ImageButton) MainActivity.bar.findViewById(R.id.browser_refresh); if ((pos) <= (webWindows.size() - 1)) { webWindows.get(pos).loadUrl("about:blank"); if (webLayout.findViewById(R.id.browser_page) == webWindows.get(pos)) { if ((pos - 1) >= 0) { ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).removeAllViews(); ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).addView(webWindows.get(pos - 1)); if (((TextView) bar.findViewById(R.id.browser_searchbar)) != null && webWindows.get(pos - 1).getUrl() != null) { webWindows.get(pos - 1).setUrlBarText(webWindows.get(pos - 1).getUrl()); } if (webWindows.get(pos - 1).getProgress() < 100) { PB.setVisibility(View.VISIBLE); refreshButton.setImageResource(R.drawable.btn_toolbar_stop_loading_normal); } else { PB.setVisibility(View.INVISIBLE); refreshButton.setImageResource(R.drawable.btn_toolbar_reload_normal); } System.out.println("CLOSED" + webWindows.get(pos - 1).getProgress()); // Find out if already a bookmark String bookmarkName = null; if (webWindows.get(pos - 1) != null && webWindows.get(pos - 1).getUrl() != null) { bookmarkName = BookmarksActivity.bookmarksMgr.root.containsBookmarkDeep( webWindows.get(pos - 1).getUrl()); } if (bookmarkName != null) { BookmarkButton.setImageResource(R.drawable.btn_omnibox_bookmark_selected_normal); } else { BookmarkButton.setImageResource(R.drawable.btn_omnibox_bookmark_normal); } } else { ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).removeAllViews(); if (((TextView) bar.findViewById(R.id.browser_searchbar)) != null) ((TextView) bar.findViewById(R.id.browser_searchbar)).setText(""); ImageView IV = new ImageView(ctxt); IV.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); IV.setScaleType(ImageView.ScaleType.CENTER); IV.setImageResource(R.drawable.web_logo); ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).addView(IV); PB.setVisibility(View.INVISIBLE); BookmarkButton.setImageResource(R.drawable.btn_omnibox_bookmark_normal); refreshButton.setImageResource(R.drawable.btn_toolbar_reload_normal); } } webWindows.remove(pos); } browserListViewAdapter.notifyDataSetChanged(); }
public static void openURLInNewTab(String url) { if (url != null) { webWindows.add(new CustomWebView(MainActivity.activity, null, url)); ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).removeAllViews(); ((ViewGroup) webLayout.findViewById(R.id.webviewholder)) .addView(webWindows.get(webWindows.size() - 1)); ((EditText) bar.findViewById(R.id.browser_searchbar)).setText(url); browserListViewAdapter.notifyDataSetChanged(); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; ctxt = getApplicationContext(); mPrefs = getSharedPreferences("pref", 0); mGlobalPrefs = PreferenceManager.getDefaultSharedPreferences(ctxt); inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); bar = new RelativeLayout(this); webLayout = (WebLayoutView) inflater.inflate(R.layout.page_web, null); browserListViewAdapter = new BrowserImageAdapter(this); webWindows = new Vector<CustomWebView>(); // Initialize BookmarksManager if (BookmarksActivity.bookmarksMgr == null) { BookmarksManager loadedBookmarksMgr = BookmarksManager.loadBookmarksManager(); if (loadedBookmarksMgr == null) { Log.d("LB", "BookmarksActivity.bookmarksMgr is null. Making new one"); BookmarksActivity.bookmarksMgr = new BookmarksManager(); } else { Log.d("LB", "BookmarksActivity.bookmarksMgr loaded"); BookmarksActivity.bookmarksMgr = loadedBookmarksMgr; } } else { Log.d("LB", "BookmarksActivity.bookmarksMgr is not null"); } // THIS IS TEMPORARY CODE TO TRANSFER FROM THE OLD BOOKMARKS SYSTEM TO THE NEW ONE int numBookmarksToTransfer = mPrefs.getInt("numbookmarkedpages", 0); Log.d("LB", numBookmarksToTransfer + " bookmarks need to transfer"); for (int book = 0; book < numBookmarksToTransfer; book++) { String url = mPrefs.getString("bookmark" + book, null); String title = mPrefs.getString("bookmarktitle" + book, null); ; if (url != null) { Bookmark newBookmark = new Bookmark(url, title); try { URL curUrl = new URL(url); File imageFile = new File(getApplicationInfo().dataDir + "/icons/" + curUrl.getHost()); if (imageFile.exists()) newBookmark.setPathToFavicon(imageFile.getAbsolutePath()); } catch (Exception e) { } ; BookmarksActivity.bookmarksMgr.root.addBookmark(newBookmark); } mPrefs.edit().remove("bookmarktitle" + book).remove("bookmark" + book).commit(); Log.d("LB", "bookmark" + book + " " + url + " transfered"); } if (numBookmarksToTransfer != 0) { mPrefs.edit().remove("numbookmarkedpages").commit(); BookmarksActivity.bookmarksMgr.saveBookmarksManager(); } // ALL BOOKMARKS SHOULD NOW BE TRANSFERED TO THE NEW SYSTEM Point screenSize = new Point(); screenSize.x = getWindow().getWindowManager().getDefaultDisplay().getWidth(); screenSize.y = getWindow().getWindowManager().getDefaultDisplay().getHeight(); if (Math.min(screenSize.x, screenSize.y) < 510) // px //may need to be adjusted assetHomePage = "file:///android_asset/home_small.html"; else assetHomePage = "file:///android_asset/home.html"; Properties.update_preferences(); if (Properties.sidebarProp.swapLayout) contentView = (DrawerLayout) inflater.inflate(R.layout.main_swapped, null); else contentView = (DrawerLayout) inflater.inflate(R.layout.main, null); contentFrame = ((FrameLayout) contentView.findViewById(R.id.content_frame)); browserListView = (ListView) contentView.findViewById(R.id.right_drawer); toolbar = (Toolbar) contentView.findViewById(R.id.toolbar); contentFrame.addView(webLayout, 0); setSupportActionBar(toolbar); actionBar = getSupportActionBar(); actionBarControls = new ActionBarControls(actionBar); setContentView(contentView); if (Properties.appProp.fullscreen) getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); int id = getResources().getIdentifier("config_enableTranslucentDecor", "bool", "android"); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) if (Properties.appProp.transparentNav || Properties.appProp.TransparentStatus) if (id == 0) { // transparency is not supported Properties.appProp.transparentNav = false; Properties.appProp.TransparentStatus = false; } tintManager = new SystemBarTintManager(activity); // if (Properties.appProp.transparentNav || Properties.appProp.TransparentStatus) // if (id != 0) { // if (Properties.appProp.transparentNav) // getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, // WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); // if (Properties.appProp.TransparentStatus) // getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, // WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); // if (Properties.appProp.fullscreen && Properties.appProp.transparentNav){ // if (Tools.hasSoftNavigation(activity)) // NavMargine= Tools.getNavBarHeight(getResources()); // }else if (Properties.appProp.transparentNav){ // if (Tools.hasSoftNavigation(activity)) // NavMargine= Tools.getNavBarHeight(getResources()); // } // // if (Properties.appProp.TransparentStatus){ // tintManager = new SystemBarTintManager(this); // tintManager.setStatusBarTintEnabled(true); // tintManager.setStatusBarTintColor(Properties.appProp.actionBarColor); // if (Properties.appProp.fullscreen) // tintManager.setTintAlpha(0.0f); // // } // } SetupLayouts.setuplayouts(); Intent intent = getIntent(); SharedPreferences savedInstancePreferences = getSharedPreferences("state", 0); int numSavedTabs = savedInstancePreferences.getInt("numtabs", 0); if (numSavedTabs > 0) { System.out.println("RESTORING STATE"); String[] urls = new String[numSavedTabs]; for (int I = 0; I < numSavedTabs; I++) urls[I] = savedInstancePreferences.getString("URL" + I, "http://www.google.com/"); int tabNumber = savedInstancePreferences.getInt("tabNumber", 0); for (int I = 0; I < urls.length; I++) { webWindows.add(new CustomWebView(MainActivity.this, null, urls[I])); browserListViewAdapter.notifyDataSetChanged(); } ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).addView(webWindows.get(tabNumber)); savedInstancePreferences.edit().clear().commit(); savedInstancePreferences = null; } else { // If no InstanceState is found, just add a single page if (intent.getAction() != Intent.ACTION_WEB_SEARCH && intent.getAction() != Intent .ACTION_VIEW) { // if page was requested from a different app, do not load home // page webWindows.add(new CustomWebView(MainActivity.this, null, null)); ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).addView(webWindows.get(0)); browserListViewAdapter.notifyDataSetChanged(); } } // detect if app was opened from a different app to open a site if (intent.getAction() == Intent.ACTION_WEB_SEARCH || intent.getAction() == Intent.ACTION_VIEW) { if (intent.getDataString() != null) { webWindows.add(new CustomWebView(MainActivity.this, null, intent.getDataString())); ((ViewGroup) webLayout.findViewById(R.id.webviewholder)).removeAllViews(); ((ViewGroup) webLayout.findViewById(R.id.webviewholder)) .addView(webWindows.get(webWindows.size() - 1)); ((EditText) bar.findViewById(R.id.browser_searchbar)).setText(intent.getDataString()); browserListViewAdapter.notifyDataSetChanged(); } } if (Properties.appProp.systemPersistent) { Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_location_web_site) .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) .setOngoing(true) .setContentIntent(contentIntent) .setPriority(2) .setContentTitle(getResources().getString(R.string.label)); mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(1, mBuilder.build()); } View decorView = getWindow().getDecorView(); decorView.setOnSystemUiVisibilityChangeListener( new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { if (tintManager != null && Properties.appProp.TransparentStatus) tintManager.setStatusBarTintEnabled(true); // Properties.appProp.fullscreen = true; } else { if (tintManager != null && Properties.appProp.TransparentStatus) tintManager.setStatusBarTintEnabled(false); // Properties.appProp.fullscreen = false; } } }); }