Пример #1
0
 public static void closeVideoViewIfOpen() {
   try {
     CustomWebView WV =
         (CustomWebView) contentView.findViewById(R.id.web_holder).findViewById(R.id.browser_page);
     if (WV != null) if (WV.isVideoPlaying()) WV.getChromeClient().onHideCustomView();
   } catch (Exception e) {
   }
   ;
 }
Пример #2
0
  @Override
  public void setContentView(int layoutResID) {

    DrawerLayout fullLayout =
        (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_base, null);
    FrameLayout frameLayout = (FrameLayout) fullLayout.findViewById(R.id.frame_layout_base);

    getLayoutInflater().inflate(layoutResID, frameLayout, true);

    super.setContentView(fullLayout);
    setView();
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    dLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    dList = (ListView) findViewById(R.id.left_drawer_list);
    List<NavDrawerItem> items = new ArrayList<>();
    for (FragmentName fragmentName : FragmentName.DRAWER_FRAGMENTS) {
      items.add(new NavDrawerItem(getString(fragmentName.getTitle()), fragmentName.getIcon()));
    }

    // notification switch
    Switch notificationSwitch = (Switch) dLayout.findViewById(R.id.switch_notification);
    final SharedPreferences prefs = getSharedPreferences(SETTINGS, MODE_PRIVATE);
    notificationSwitch.setChecked(prefs.getBoolean(NOTIFICATIONS, true));
    notificationSwitch.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (prefs.getBoolean(NOTIFICATIONS, true)) {
              prefs.edit().putBoolean(NOTIFICATIONS, false).apply();
            } else {
              prefs.edit().putBoolean(NOTIFICATIONS, true).apply();
            }
          }
        });

    ListAdapter adapter = new NavDrawerListAdapter(getApplicationContext(), items);
    dList.setAdapter(adapter);
    dList.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> arg0, View v, int position, long id) {
            dLayout.closeDrawers();
            showContent(FragmentName.DRAWER_FRAGMENTS[position]);
          }
        });
    dToggle =
        new ActionBarDrawerToggle(
            this, dLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {

          /** Called when a drawer has settled in a completely closed state. */
          public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }

          /** Called when a drawer has settled in a completely open state. */
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }
        };
    dLayout.setDrawerListener(dToggle);

    if (getActionBar() != null) {
      getActionBar().setDisplayHomeAsUpEnabled(true);
      getActionBar().setHomeButtonEnabled(true);
    }

    showContent(getSectionIdFromExtras());
  }
Пример #4
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;
            }
          }
        });
  }