예제 #1
0
  @Override
  protected void onDestroy() {
    Controller.getInstance().getAddonManager().unbindAddons();
    WebIconDatabase.getInstance().close();
    PreferenceManager.getDefaultSharedPreferences(this)
        .unregisterOnSharedPreferenceChangeListener(mPreferenceChangeListener);
    unregisterReceiver(mPackagesReceiver);

    super.onDestroy();
  }
예제 #2
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // 去标题
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    // 无状态栏
    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.main);

    // 引入历史数据库的实例
    mySQLiteHelper = new MySQLiteHelper(main.this, "mydb.db", null, 1);

    // 浮动输入栏的总的布局(皮肤)
    skinLayout = (RelativeLayout) findViewById(R.id.skin01);

    // 引入输入框的实例
    myenter01 = (LinearLayout) findViewById(R.id.enter01);
    enterurl01 = (EditText) findViewById(R.id.enterurl01);

    myenter02 = (LinearLayout) findViewById(R.id.enter02);
    enterurl02 = (EditText) findViewById(R.id.enterurl02);
    okImageView = (ImageView) findViewById(R.id.ImageView01);

    // 标题、进度条、图标的实例
    mytitle = (TextView) findViewById(R.id.title01);
    myProgressBar = (ProgressBar) findViewById(R.id.progress_horizontal01);
    myicon = (ImageView) findViewById(R.id.icon);
    // 欲取得网站的图标,必须设置网站数据库的实例
    final WebIconDatabase mydb = WebIconDatabase.getInstance();
    mydb.open(getDir("icons", MODE_PRIVATE).getPath());

    // -----------------------------------
    // SharedPreferences的实例部分:开始
    // -----------------------------------

    // 主页设置
    zhuyesp = main.this.getSharedPreferences("zhuyeset", MODE_PRIVATE);
    zhuyeEditor = zhuyesp.edit();
    // JavaScript设置
    jssp = main.this.getSharedPreferences("jsset", MODE_PRIVATE);
    jsEditor = jssp.edit();
    // 缓存设置
    cachesp = main.this.getSharedPreferences("cacheset", MODE_PRIVATE);
    cacheEditor = cachesp.edit();
    // 皮肤设置
    skinsp = main.this.getSharedPreferences("skinset", MODE_PRIVATE);
    skinEditor = skinsp.edit();
    // 壁纸设置
    bizhisp = main.this.getSharedPreferences("bizhiset", MODE_PRIVATE);
    bizhiEditor = bizhisp.edit();
    // ------------------------------------
    // SharedPreferences的实例部分:结束
    // ------------------------------------
    // ---------begin:查询数据,设置皮肤-------------------------------
    int skinvalue = skinsp.getInt("skin", 0);
    switch (skinvalue) {
      case 0:
        skinLayout.setBackgroundColor(Color.parseColor("#ffd7d7d7"));
        break;
      case 1:
        skinLayout.setBackgroundResource(R.drawable.skin_title_jingdian);
        break;
      case 2:
        skinLayout.setBackgroundResource(R.drawable.skin_title_chitang);
        break;
      case 3:
        skinLayout.setBackgroundResource(R.drawable.skin_title_jijingshouwang);
        break;
      case 4:
        skinLayout.setBackgroundResource(R.drawable.skin_title_kewangfeixiang);
        break;
      case 5:
        skinLayout.setBackgroundResource(R.drawable.skin_title_mengdong);
        break;
      case 6:
        skinLayout.setBackgroundResource(R.drawable.skin_title_xuanlan);
        break;
      case 7:
        skinLayout.setBackgroundResource(R.drawable.skin_title_hetang);
        break;
      case 8:
        skinLayout.setBackgroundResource(R.drawable.skin_title_zhanlantiankong);
        break;
      case 9:
        skinLayout.setBackgroundResource(R.drawable.skin_title_qingchasiyu);
        break;
    }

    // --------end:查询数据,设置皮肤-----------------------------------------------------------
    // -----begin网页部分---------------------------------------------------------
    // 网页视图的实例
    myWebView = (WebView) findViewById(R.id.WebView01);
    // 网页视图的壁纸设置
    int bizhivalue = bizhisp.getInt("bizhi", 0);
    switch (bizhivalue) {
      case 0:
        myWebView.setBackgroundColor(0);
        myWebView.setBackgroundResource(R.drawable.white);
        break;
      case 1:
        myWebView.setBackgroundColor(0);
        myWebView.setBackgroundResource(R.drawable.chuntian);
        break;
      case 2:
        myWebView.setBackgroundColor(0);
        myWebView.setBackgroundResource(R.drawable.xiatian);
        break;
      case 3:
        myWebView.setBackgroundColor(0);
        myWebView.setBackgroundResource(R.drawable.xianhuaduoduo);
        break;
      case 4:
        myWebView.setBackgroundColor(0);
        myWebView.setBackgroundResource(R.drawable.huayu);
        break;
    }

    myWebView.setOnTouchListener(main.this);
    gestureDetector = new GestureDetector(main.this);
    // 网页的覆盖视图的实例
    myRelativeLayout = (RelativeLayout) findViewById(R.id.skin01);

    // 设置网页客户端
    myWebView.setWebViewClient(new WebViewClient() {});

    // 设置网页chrome客户端
    myWebView.setWebChromeClient(
        new WebChromeClient() {
          // 设置标题
          public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
            title = myWebView.getTitle();
            dbString = title;
            mytitle.setText(title);
          }
          // 设置进度条
          public void onProgressChanged(WebView view, int progress) {
            myProgressBar.setProgress(progress);
            if (progress == 100) {
              myProgressBar.setProgress(0);
            }
          }

          // 设置图标
          public void onReceivedIcon(WebView view, Bitmap icon) {
            super.onReceivedIcon(view, icon);
            icon = myWebView.getFavicon();
            myicon.setImageBitmap(icon);
          }
        });

    // ------end网页部分---------------------------------------------------------------------

    // 输入框的点击事件
    enterurl01.setOnClickListener(
        new LinearLayout.OnClickListener() {

          public void onClick(View v) {
            myenter01.setVisibility(View.GONE);
            myenter02.setVisibility(View.VISIBLE);
          }
        });
    // 图片按钮的点击事件
    okImageView.setOnClickListener(
        new ImageView.OnClickListener() {

          public void onClick(View v) {
            myenter02.setVisibility(View.GONE);
            myenter01.setVisibility(View.VISIBLE);
            // 取得网址
            strURL = enterurl02.getText().toString();
            int length = strURL.length();
            if (length == 0) {
              Toast.makeText(main.this, "请输入网址!", Toast.LENGTH_SHORT).show();
            } else {
              strindex = strURL.substring(0, 7);
              boolean bln = strindex.equalsIgnoreCase("http://");
              if (bln == true) {

                if (URLUtil.isNetworkUrl(strURL)) { // 进行网址的合法性判断

                  myWebView.loadUrl(strURL);

                  db = mySQLiteHelper.getReadableDatabase();
                  // 将数据保存到历史数据库中
                  ContentValues cv = new ContentValues();
                  cv.put("title", dbString);
                  cv.put("url", strURL);
                  db.insert("history", null, cv);

                } else {
                  Toast.makeText(main.this, "请输入合法的网址,谢谢!", Toast.LENGTH_SHORT).show();
                }
              } else if (bln == false) {
                strURL = ("http://" + strURL);
                if (URLUtil.isNetworkUrl(strURL)) {
                  myWebView.loadUrl(strURL);

                  db = mySQLiteHelper.getReadableDatabase();
                  // 将数据保存到历史数据库中
                  ContentValues cv = new ContentValues();
                  cv.put("title", dbString);
                  cv.put("url", strURL);
                  db.insert("history", null, cv);
                  // mydb.execSQL("insert into historytable(_id,title,url)
                  // values(1,dbString,strURL);");
                } else {
                  Toast.makeText(main.this, "请输入合法的网址,谢谢!", Toast.LENGTH_SHORT).show();
                }
              }
            }

            enterurl02.setText("");
          }
        });

    // ------begin网页的各项设置-------------------------------------
    webSettings = myWebView.getSettings();
    // JavaScript的设置
    boolean jsbln = jssp.getBoolean("jsbln", false);
    if (jsbln == true) {
      webSettings.setJavaScriptEnabled(true);
    } else if (jsbln == false) {
      webSettings.setJavaScriptEnabled(false);
      // 缓存
      int cachevalue = cachesp.getInt("cache", 1);
      if (cachevalue == 0) {
        webSettings.setAppCacheEnabled(true);
      } else if (cachevalue == 1) {
        webSettings.setAppCacheEnabled(false);
      }
    }

    // ------end网页的各项设置-------------------------------------------------------

  }
예제 #3
0
  /** Initialize the Web icons database. */
  private void initializeWebIconDatabase() {

    final WebIconDatabase db = WebIconDatabase.getInstance();
    db.open(getDir("icons", 0).getPath());
  }