コード例 #1
1
  @Override
  protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    Log.d("LB", "onNewIntent");
    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT)
        != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) {
      contentView.closeDrawers();
    }

    if (intent.getAction() == Intent.ACTION_WEB_SEARCH
        || intent.getAction() == Intent.ACTION_VIEW) {
      if (intent.getDataString() != null) {
        int tabNumber =
            intent.getIntExtra("tabNumber", -1); // used if intent is coming from Lucid Browser

        if (tabNumber != -1 && tabNumber < webWindows.size()) {
          webWindows.get(tabNumber).loadUrl(intent.getDataString());
        } else tabNumber = -1;

        if (tabNumber == -1) {
          openURLInNewTab(intent.getDataString());
        }
      }
    }
  }
コード例 #2
0
  @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;
            }
          }
        });
  }
コード例 #3
0
 @Override
 public void onStop() {
   super.onStop();
   saveState();
   if (isFinishing()) clearAllTabsForExit();
 }
コード例 #4
0
 @Override
 public void onPause() {
   // BookmarksActivity.bookmarksMgr.saveBookmarksManager();
   super.onPause();
 }
コード例 #5
0
 @Override
 public void onSaveInstanceState(Bundle savedInstanceState) {
   super.onSaveInstanceState(savedInstanceState);
   saveState();
 }