Example #1
0
  /**
   * Creates a new WebViewer component.
   *
   * @param container container the component will be placed in
   */
  public WebViewer(ComponentContainer container) {
    super(container);

    webview = new WebView(container.$context());
    webview.setWebViewClient(new WebViewerClient());
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setFocusable(true);
    // enable pinch zooming and zoom controls
    webview.getSettings().setBuiltInZoomControls(true);
    container.$add(this);

    webview.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                  v.requestFocus();
                }
                break;
            }
            return false;
          }
        });

    // set the initial default properties.  Height and Width
    // will be fill-parent, which will be the default for the web viewer.

    followLinks = true;
    HomeUrl("");
    Width(LENGTH_FILL_PARENT);
    Height(LENGTH_FILL_PARENT);
  }
Example #2
0
 @Override
 public void setActiveTab(final Tab tab) {
   mHandler.removeMessages(MSG_HIDE_TITLEBAR);
   if ((tab != mActiveTab) && (mActiveTab != null)) {
     removeTabFromContentView(mActiveTab);
     WebView web = mActiveTab.getWebView();
     if (web != null) {
       web.setOnTouchListener(null);
     }
   }
   mActiveTab = tab;
   WebView web = mActiveTab.getWebView();
   updateUrlBarAutoShowManagerTarget();
   attachTabToContentView(tab);
   setShouldShowErrorConsole(tab, mUiController.shouldShowErrorConsole());
   onTabDataChanged(tab);
   onProgressChanged(tab);
   mNavigationBar.setIncognitoMode(tab.isPrivateBrowsingEnabled());
   updateAutoLogin(tab, false);
   if (web != null
       && web.getVisibleTitleHeight() != mTitleBar.getEmbeddedHeight()
       && !mUseQuickControls) {
     showTitleBarForDuration();
   }
 }
Example #3
0
  @Override
  public void onActivityCreated(Bundle saved) {
    super.onActivityCreated(saved);
    view = (WebView) getView().findViewById(R.id.Viewport);

    // enable JavaScript for cool things to happen!
    view.getSettings().setJavaScriptEnabled(true);

    // ----- SWIPE PAGE
    view.setOnTouchListener(
        new OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {

            if (state == ViewStateEnum.books) swipePage(v, event, 0);

            WebView view = (WebView) v;
            return view.onTouchEvent(event);
          }
        });

    // ----- NOTE & LINK
    view.setOnLongClickListener(
        new OnLongClickListener() {
          @Override
          public boolean onLongClick(View v) {
            Message msg = new Message();
            msg.setTarget(
                new Handler() {
                  @Override
                  public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    String url = msg.getData().getString(getString(R.string.url));
                    if (url != null) navigator.setNote(url, index);
                  }
                });
            view.requestFocusNodeHref(msg);

            return false;
          }
        });

    view.setWebViewClient(
        new WebViewClient() {
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            try {
              navigator.setBookPage(url, index);
            } catch (Exception e) {
              errorMessage(getString(R.string.error_LoadPage));
            }
            return true;
          }
        });

    loadPage(viewedPage);
  }
 @SuppressLint("SetJavaScriptEnabled")
 private void setup() {
   mScale = mActivity.getResources().getDisplayMetrics().density;
   mWebView.setOnLongClickListener(this);
   mWebView.setOnTouchListener(this);
   final WebSettings settings = mWebView.getSettings();
   settings.setJavaScriptEnabled(true);
   settings.setJavaScriptCanOpenWindowsAutomatically(true);
   mSelectionController = new TextSelectionController(this);
   mWebView.addJavascriptInterface(mSelectionController, TextSelectionController.INTERFACE_NAME);
   createSelectionLayer(mActivity);
 }
  private void initView() {
    // To change body of created methods use File | Settings | File Templates.

    webView = (WebView) findViewById(R.id.webView);
    WebSettings webSettings = webView.getSettings();
    webSettings.setSavePassword(false);
    webSettings.setSaveFormData(false);
    webSettings.setJavaScriptEnabled(true);
    webSettings.setSupportZoom(true);
    webView.setOnTouchListener(this);

    if (mNavLeftButton == null) {
      mNavLeftButton = (ImageView) findViewById(R.id.nav_left_image);
    }
    mNavLeftButton.setVisibility(View.VISIBLE);
    mNavLeftButton.setOnClickListener(this);

    loadData();
  }
  private void renderView() {
    // reference
    final WebView webView = (WebView) mRootView.findViewById(R.id.fragment_main_webview);
    final AdView adView = (AdView) mRootView.findViewById(R.id.fragment_main_adview);

    // webview settings
    webView.getSettings().setBuiltInZoomControls(false);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setBackgroundColor(getResources().getColor(R.color.global_bg_front));
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); // fixes scrollbar on Froyo
    webView.setWebChromeClient(
        new WebChromeClient() {
          public void openFileChooser(ValueCallback<Uri> filePathCallback) {
            mFilePathCallback4 = filePathCallback;
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("*/*");
            startActivityForResult(
                Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER);
          }

          public void openFileChooser(ValueCallback filePathCallback, String acceptType) {
            mFilePathCallback4 = filePathCallback;
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("*/*");
            startActivityForResult(
                Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER);
          }

          public void openFileChooser(
              ValueCallback<Uri> filePathCallback, String acceptType, String capture) {
            mFilePathCallback4 = filePathCallback;
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("*/*");
            startActivityForResult(
                Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER);
          }

          @Override
          public boolean onShowFileChooser(
              WebView webView,
              ValueCallback<Uri[]> filePathCallback,
              WebChromeClient.FileChooserParams fileChooserParams) {
            mFilePathCallback5 = filePathCallback;
            Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_OPENABLE);
            intent.setType("*/*");
            startActivityForResult(
                Intent.createChooser(intent, "File Chooser"), REQUEST_FILE_PICKER);
            return true;
          }
        });
    webView.setWebViewClient(
        new WebViewClient() {
          private boolean mSuccess = true;

          @Override
          public void onPageFinished(final WebView view, final String url) {
            runTaskCallback(
                new Runnable() {
                  public void run() {
                    if (getActivity() != null && mSuccess) {
                      showContent(
                          500); // hide progress bar with delay to show webview content smoothly
                      showActionBarProgress(false);
                    }
                  }
                });
          }

          @Override
          public void onReceivedError(
              final WebView view,
              final int errorCode,
              final String description,
              final String failingUrl) {
            runTaskCallback(
                new Runnable() {
                  public void run() {
                    if (getActivity() != null) {
                      mSuccess = false;
                      showEmpty();
                      showActionBarProgress(false);
                    }
                  }
                });
          }

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (DownloadUtility.isDownloadableFile(url)) {
              Toast.makeText(getActivity(), R.string.fragment_main_downloading, Toast.LENGTH_LONG)
                  .show();
              DownloadUtility.downloadFile(getActivity(), url, DownloadUtility.getFileName(url));
              return true;
            } else if (url != null && (url.startsWith("http://") || url.startsWith("https://"))) {
              // determine for opening the link externally or internally
              boolean external = isLinkExternal(url);
              boolean internal = isLinkInternal(url);
              if (!external && !internal) {
                external = WebViewAppConfig.OPEN_LINKS_IN_EXTERNAL_BROWSER;
              }

              // open the link
              if (external) {
                startWebActivity(url);
                return true;
              } else {
                showActionBarProgress(true);
                return false;
              }
            } else if (url != null && url.startsWith("mailto:")) {
              MailTo mailTo = MailTo.parse(url);
              startEmailActivity(mailTo.getTo(), mailTo.getSubject(), mailTo.getBody());
              return true;
            } else if (url != null && url.startsWith("tel:")) {
              startCallActivity(url);
              return true;
            } else if (url != null && url.startsWith("sms:")) {
              startSmsActivity(url);
              return true;
            } else if (url != null && url.startsWith("geo:")) {
              startMapSearchActivity(url);
              return true;
            } else {
              return false;
            }
          }
        });
    webView.setOnKeyListener(
        new View.OnKeyListener() {
          @Override
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
              WebView webView = (WebView) v;

              switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                  if (webView.canGoBack()) {
                    webView.goBack();
                    return true;
                  }
                  break;
              }
            }

            return false;
          }
        });
    webView.requestFocus(
        View
            .FOCUS_DOWN); // http://android24hours.blogspot.cz/2011/12/android-soft-keyboard-not-showing-on.html
    webView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                  v.requestFocus();
                }
                break;
            }

            return false;
          }
        });

    // admob
    if (WebViewAppConfig.ADMOB && NetworkManager.isOnline(getActivity())) {
      AdRequest adRequest =
          new AdRequest.Builder()
              .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
              .addTestDevice(getString(R.string.admob_test_device_id))
              .build();
      adView.loadAd(adRequest);
      adView.setVisibility(View.VISIBLE);
    } else {
      adView.setVisibility(View.GONE);
    }
  }
Example #7
0
    @Override
    protected void onPostExecute(Boolean result) {
      mIsPostTaskRunning = false;

      if (!result) {
        /*
         * post couldn't be loaded (?)
         */
        txtTitle.setText(R.string.reader_title_err_unable_to_load_post);
        txtSource.setVisibility(View.GONE);
        imgAvatar.setImageResource(R.drawable.ic_error);
        return;
      }

      // likes appears above the webView so force the like layout to take up space before loading
      // them in refreshLikes() - this way the webView won't appear and then be pushed down the
      // page once likes are loaded
      if (mPost.numLikes > 0 && mLayoutLikes.getVisibility() == View.GONE)
        mLayoutLikes.setVisibility(View.INVISIBLE);

      if (mPost.hasTitle()) {
        txtTitle.setText(mPost.getTitle());
      } else {
        txtTitle.setText(R.string.reader_untitled_post);
      }

      // tapping title layout opens post in browser
      layoutTitle.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              ReaderActivityLauncher.openUrl(ReaderPostDetailActivity.this, mPost.getUrl());
            }
          });

      // blog name / author name / date
      txtSource.setText(mPost.getSource());

      if (mPost.hasPostAvatar()) {
        int avatarSz = getResources().getDimensionPixelSize(R.dimen.reader_avatar_sz_medium);
        imgAvatar.setImageUrl(
            mPost.getPostAvatarForDisplay(avatarSz), WPNetworkImageView.ImageType.AVATAR);
        imgAvatar.setVisibility(View.VISIBLE);
      } else {
        imgAvatar.setVisibility(View.GONE);
      }

      // enable reblogging wp posts
      btnReblog.setVisibility(mPost.isWP() ? View.VISIBLE : View.GONE);
      btnReblog.setSelected(mPost.isRebloggedByCurrentUser);
      if (mPost.isWP()) {
        btnReblog.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                doPostReblog(btnReblog, mPost);
              }
            });
      }

      // enable adding a comment if comments are open on this post
      if (mPost.isWP() && mPost.isCommentsOpen) {
        btnComment.setVisibility(View.VISIBLE);
        btnComment.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                toggleShowAddCommentBox();
              }
            });
      } else {
        btnComment.setVisibility(View.GONE);
      }

      // webView settings must be configured on main thread - note that while JavaScript is
      // required for embedded videos, it's disabled since it's a security risk:
      //    http://developer.android.com/training/articles/security-tips.html#WebView
      // note: even with JavaScript enabled video embeds are unreliable (some work, some don't)
      webView.getSettings().setJavaScriptEnabled(false);
      webView.getSettings().setUserAgentString(Constants.USER_AGENT);
      webView
          .getSettings()
          .setLayoutAlgorithm(
              WebSettings.LayoutAlgorithm.NARROW_COLUMNS); // <-- not sure this is necessary

      // webView is hidden at design time, don't show it until the page finishes loading so it
      // has time to layout the post before it appears...
      webView.setWebViewClient(
          new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
              if (webView.getVisibility() != View.VISIBLE) webView.setVisibility(View.VISIBLE);
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
              // open clicked urls in default browser or else urls will open in this webView,
              // but only do this when webView has loaded (is visible) - have seen some posts
              // containing iframes automatically try to open urls (without being clicked)
              // before the page has loaded
              if (view.getVisibility() == View.VISIBLE) {
                ReaderActivityLauncher.openUrl(ReaderPostDetailActivity.this, url);
                return true;
              } else {
                return false;
              }
            }
          });

      // ...but force it to appear after a few seconds to ensure user never has to be faced
      // with a blank post for too long (very important on slow connections)
      new Handler()
          .postDelayed(
              new Runnable() {
                @Override
                public void run() {
                  if (webView.getVisibility() != View.VISIBLE) {
                    webView.setVisibility(View.VISIBLE);
                    ReaderLog.w("forced webView to appear before page finished");
                  }
                }
              },
              2500);

      // detect image taps so we can open images in the photo viewer activity
      webView.setOnTouchListener(
          new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
              if (event.getAction() == MotionEvent.ACTION_UP) {
                HitTestResult hr = ((WebView) v).getHitTestResult();
                if (hr != null
                    && (hr.getType() == HitTestResult.IMAGE_TYPE
                        || hr.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE)) {
                  String imageUrl = hr.getExtra();
                  if (imageUrl == null) return false;
                  // skip if image is a file: reference - this will be the video overlay, ie:
                  // file:///android_res/drawable/ic_reader_video_overlay.png
                  if (imageUrl.startsWith("file:")) return false;
                  // skip if image is a video thumbnail (see processVideos)
                  if (mVideoThumbnailUrls.contains(imageUrl)) return false;
                  // skip if image is a VideoPress thumbnail (anchor around thumbnail will
                  // take user to actual video - see ReaderPost.cleanupVideoPress)
                  if (imageUrl.contains("videos.files.")) return false;
                  showPhotoViewer(imageUrl);
                  return true;
                }
              }
              return false;
            }
          });

      // IMPORTANT: must use loadDataWithBaseURL() rather than loadData() since the latter often
      // fails
      // https://code.google.com/p/android/issues/detail?id=4401
      webView.loadDataWithBaseURL(null, postHtml, "text/html", "UTF-8", null);

      // only show action buttons for WP posts
      mLayoutActions.setVisibility(mPost.isWP() ? View.VISIBLE : View.GONE);

      // make sure the adapter is assigned now that we've retrieved the post and updated views
      if (!hasCommentAdapter()) getListView().setAdapter(getCommentAdapter());

      refreshFollowed();
      refreshLikes();
      refreshComments();

      // get the latest info for this post if we haven't updated it already
      if (!mHasAlreadyUpdatedPost) {
        updatePost();
        mHasAlreadyUpdatedPost = true;
      }

      // show the listView now that post has loaded and views have been updated
      getListView().setVisibility(View.VISIBLE);
    }
  private void bindData() {
    // reference
    final WebView webView = (WebView) mRootView.findViewById(R.id.fragment_example_webview);

    // webview settings
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setSupportZoom(true);
    webView.getSettings().setDefaultZoom(ZoomDensity.MEDIUM);
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.setBackgroundColor(getResources().getColor(R.color.global_bg_front));
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); // fixes scrollbar on Froyo
    webView.setWebChromeClient(
        new WebChromeClient()); // http://stackoverflow.com/questions/8541443/whats-causing-this-nullpointerexception
    webView.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageFinished(WebView view, String url) {
            if (getActivity() != null) {
              Toast.makeText(getActivity(), mUrl, Toast.LENGTH_LONG).show();
              mStatefulLayout.showContent();
            }
          }

          @Override
          public void onReceivedError(
              WebView view, int errorCode, String description, String failingUrl) {
            if (getActivity() != null) {
              webView.loadUrl("about:blank");
              Toast.makeText(getActivity(), errorCode + ": " + description, Toast.LENGTH_LONG)
                  .show();
              mStatefulLayout.showEmpty();
            }
          }

          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (url != null && (url.startsWith("http://") || url.startsWith("https://"))) {
              view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
              return true;
            } else {
              return false;
            }
          }
        });
    webView.setOnKeyListener(
        new OnKeyListener() {
          @Override
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN) {
              WebView webView = (WebView) v;

              switch (keyCode) {
                case KeyEvent.KEYCODE_BACK:
                  if (webView.canGoBack()) {
                    webView.goBack();
                    return true;
                  }
                  break;
              }
            }

            return false;
          }
        });
    webView.requestFocus(
        View
            .FOCUS_DOWN); // http://android24hours.blogspot.cz/2011/12/android-soft-keyboard-not-showing-on.html
    webView.setOnTouchListener(
        new OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                  v.requestFocus();
                }
                break;
            }

            return false;
          }
        });

    // load web url
    mStatefulLayout.showProgress();
    webView.loadUrl(mUrl);
  }
Example #9
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网页的各项设置-------------------------------------------------------

  }
  @SuppressLint("NewApi")
  public void addTextElement(final String val) {
    // todo check for URL
    if (Tools.checkURL(val)) {
      LinearLayout item = new LinearLayout(this);
      item.setBackgroundColor(Color.BLACK);
      item.setLayoutParams(Tools.setMargins());
      item.setBackgroundResource(R.drawable.shape);
      item.setOrientation(LinearLayout.VERTICAL);
      TableRow.LayoutParams item_params =
          new TableRow.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      item_params.setMargins(5, 8, 5, 8);
      item.setLayoutParams(item_params);
      TextView tv = new TextView(this);
      tv.setTextColor(Color.parseColor("#00FFFF"));
      tv.setText(val);

      if (Tools.checkURLType(val)) {
        //          webview ------
        w = new WebView(this);
        WebSettings webSettings = w.getSettings();
        webSettings.setJavaScriptEnabled(true);
        w.setVerticalScrollBarEnabled(false);
        w.setHorizontalScrollBarEnabled(false);
        w.setWebViewClient(
            new WebViewClient() {
              public void onPageFinished(WebView view, String url) {
                Picture picture = view.capturePicture();
                Bitmap b =
                    Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
                Canvas c = new Canvas(b);
                picture.draw(c);
                FileOutputStream fos = null;
                try {
                  fos =
                      new FileOutputStream(
                          Tools.getContextWrapperDir(Notes_Activity.this) + "/temp.jpg");
                  if (fos != null) {
                    b.compress(Bitmap.CompressFormat.JPEG, 100, fos);
                    fos.close();
                  }
                } catch (Exception e) {
                }
              }
            });
        w.setOnTouchListener(
            new View.OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                return (event.getAction() == MotionEvent.ACTION_MOVE);
              }
            });

        w.loadUrl(Tools.checkURLTypeWebView(val));
        item.addView(w, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 600));
      }
      // clickable
      item.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              String url = val;
              Intent i = new Intent(Intent.ACTION_VIEW);
              i.setData(Uri.parse(url));
              startActivity(i);
            }
          });
      // webicew -------------

      item.addView(tv);
      body.addView(item);
      scrollDown();
      addTimeStamp();
    } else {
      LinearLayout item = new LinearLayout(this);
      item.setBackgroundColor(Color.BLACK);
      item.setLayoutParams(Tools.setMargins());
      item.setBackgroundResource(R.drawable.shape);
      TableRow.LayoutParams item_params =
          new TableRow.LayoutParams(
              ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
      //		item_params.gravity =Gravity.LEFT;
      item_params.setMargins(5, 8, 5, 8);
      item.setLayoutParams(item_params);

      TextView tv = new TextView(this);
      tv.setTextColor(Color.WHITE);
      tv.setText(val);
      item.addView(tv);
      body.addView(item);
      scrollDown();
      addTimeStamp();
    }
  }
Example #11
0
  private void setWebView() {
    webSet = web.getSettings();
    webSet.setSavePassword(false);
    webSet.setAllowFileAccess(false);
    webSet.setJavaScriptEnabled(true);
    webSet.setSaveFormData(false);
    webSet.setSupportZoom(true);
    webSet.setBuiltInZoomControls(true);
    webSet.setCacheMode(WebSettings.LOAD_NO_CACHE);
    layout.setScrollBarStyle(SCROLLBARS_OUTSIDE_OVERLAY);

    web.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            v.requestFocus();
            return false;
          }
        });
    web.setWebChromeClient(
        new WebChromeClient() { // 设置网页加载的进度条
          public void onProgressChanged(WebView view, int newProgress) {
            if (dialog_flag == true) {
              _showLoading();
              dialog_flag = false;
            }
            if (newProgress == 100) {
              dismissLoading();
              dialog_flag = true;
            }
          }

          // 设置应用程序的标题
          public void onReceivedTitle(WebView view, String title) {
            super.onReceivedTitle(view, title);
          }
        });
    web.setOnTouchListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            v.requestFocus();
            return false;
          }
        });
    /*
     *
     * URL = ztspeechandroid://OAuthActivity?oauth_token=
     * f11203c98d813b227204254e3c148884&oauth_verifier=871525
     */
    web.setWebViewClient(
        new WebViewClient() {
          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            LogInfo.LogOut(TAG, "WebView onPageStarted...");
            LogInfo.LogOut(TAG, "URL = " + url);
            if (url != null) {
              if (url.indexOf("checkType=verifycode") != -1) {
                int start = url.indexOf("checkType=verifycode&v=") + 23;
                String verifyCode = url.substring(start, start + 6);
                oAuth.setOauthVerifier(verifyCode);
                view.destroyDrawingCache();
                handler.sendMessage(
                    Message.obtain(
                        handler, ZtspeechWeiboManager.CONSTENT_TENCENT_WEIBO_REGIST, oAuth));
              } else if (url.contains("ztspeechandroid")) {
                // handler.sendMessage(Message.obtain(handler,
                // ZtspeechWeiboManager.CONSTENT_SINA_WEIBO_REGIST,
                // url));
              }
            }
            super.onPageStarted(view, url, favicon);
          }
        });
  }
Example #12
0
  /**
   * Creates a new Survey component.
   *
   * @param container container the component will be placed in
   * @throws IOException
   */
  public Survey(ComponentContainer container) throws IOException {
    super(container);
    mainUI = container.$form();
    exportRoot =
        new java.io.File(Environment.getExternalStorageDirectory(), mainUI.getPackageName())
            + java.io.File.separator
            + "export";

    JsonParser parse = new JsonParser();
    webview = new WebView(container.$context());
    webview.getSettings().setJavaScriptEnabled(true);
    webview.setFocusable(true);
    webview.setVerticalScrollBarEnabled(true);

    container.$add(this);

    webview.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                  v.requestFocus();
                }
                break;
            }
            return false;
          }
        });

    // set the initial default properties. Height and Width
    // will be fill-parent, which will be the default for the web viewer.

    Width(LENGTH_FILL_PARENT);
    Height(LENGTH_FILL_PARENT);

    // set default survey style
    style = TEXTBOX; // default style

    // see if the Survey is created by someone tapping on a notification!
    // create the Survey and load it in the webviewer
    /* e.g.
     * value = {
     * "style": "multipleChoice",
     * "question": "What is your favorite food"
     * "options": ["apple", "banana", "strawberry", "orange"],
     * "surveyGroup": "MIT-food-survey"
     * }
     *
     */
    initValues = container.$form().getSurveyStartValues();
    Log.i(TAG, "startVal Suvey:" + initValues.toString());
    if (initValues != "") {

      JsonObject values = (JsonObject) parse.parse(initValues);
      this.style = values.get("style").getAsString();
      this.question = values.get("question").getAsString();
      this.surveyGroup = values.get("surveyGroup").getAsString();
      ArrayList<String> arrOptions = new ArrayList<String>();
      JsonArray _options = values.get("options").getAsJsonArray();
      for (int i = 0; i < _options.size(); i++) {
        arrOptions.add(_options.get(i).getAsString());
      }

      this.options = arrOptions;
      this.styleFromIntent = values.get("style").getAsString();
      Log.i(TAG, "Survey component got created");
    }
  }
Example #13
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d();
    super.onCreateView(inflater, container, savedInstanceState);
    setHasOptionsMenu(true);

    ViewGroup v = (ViewGroup) inflater.inflate(R.layout.browser, null);
    urlBar = (EditText) v.findViewById(R.id.urlbar);

    mProgressBar = (ProgressBar) v.findViewById(R.id.progressbar);

    // Add webview as 3rd child
    // TODO:   I think I did this so it wouldn't be destroyed or state
    // lost, don't really remember.
    RelativeLayout.LayoutParams layoutParams =
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    layoutParams.addRule(RelativeLayout.BELOW, R.id.progressbar);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    v.addView(mVizWebView, 2, layoutParams);

    /*
    if (initialized == false) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
        String defaultUrl = prefs.getString("browser_homepage", "http://vimeo.com");
        Log.d("Got default url: " + defaultUrl);
        urlBar.setText(defaultUrl);
        loadUrlFromUrlBar();
        initialized = true;
    }
    */

    urlBar.setOnEditorActionListener(
        new TextView.OnEditorActionListener() {
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((event != null && event.getAction() == KeyEvent.ACTION_DOWN)
                || actionId == EditorInfo.IME_ACTION_NEXT
                || actionId == EditorInfo.IME_ACTION_DONE) {
              Log.d("onEditorAction(actionId=" + actionId + ", event=" + event + ")");
              Activity activity = getActivity();
              if (activity == null) {
                return false;
              }
              mBrowser.loadUrlFromUrlBar();
              InputMethodManager inputManager =
                  (InputMethodManager)
                      VizApp.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
              inputManager.hideSoftInputFromWindow(
                  activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
              return true;
            }
            return false;
          }
        });

    setCanGoBack();
    // mVizWebView.requestFocus();
    // android issue #7189 (webview text fields not causing virtual
    // keyboard to popup)
    mVizWebView.requestFocus(View.FOCUS_DOWN);
    mVizWebView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
              case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                  v.requestFocus();
                }
                break;
            }
            return false;
          }
        });

    return v;
  }
Example #14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_securo_bot_main);

    t1 = new TTSEngine(this);

    final View controlsView = findViewById(R.id.fullscreen_content_controls);
    // left
    leftEye = (ImageView) findViewById(R.id.leftEye);
    lEResource = R.drawable.blueeyesopenleft;
    leftEye.setImageResource(lEResource);
    // right
    rightEye = (ImageView) findViewById(R.id.rightEye);
    rEResource = R.drawable.blueeyesopenright;
    rightEye.setImageResource(rEResource);
    final View contentView = findViewById(R.id.eyes);

    // Set up an instance of SystemUiHider to control the system UI for
    // this activity.
    mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
    mSystemUiHider.setup();
    mSystemUiHider.setOnVisibilityChangeListener(
        new SystemUiHider.OnVisibilityChangeListener() {
          // Cached values.
          int mControlsHeight;
          int mShortAnimTime;

          @Override
          @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
          public void onVisibilityChange(boolean visible) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
              // If the ViewPropertyAnimator API is available
              // (Honeycomb MR2 and later), use it to animate the
              // in-layout UI controls at the bottom of the
              // screen.
              if (mControlsHeight == 0) {
                mControlsHeight = controlsView.getHeight();
              }
              if (mShortAnimTime == 0) {
                mShortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
              }
              controlsView
                  .animate()
                  .translationY(visible ? 0 : mControlsHeight)
                  .setDuration(mShortAnimTime);
            } else {
              // If the ViewPropertyAnimator APIs aren't
              // available, simply show or hide the in-layout UI
              // controls.
              controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
            }

            if (visible && AUTO_HIDE) {
              // Schedule a hide().
              delayedHide(AUTO_HIDE_DELAY_MILLIS);
            }
          }
        });

    // Set up the user interaction to manually show or hide the system UI.
    contentView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Log.d("TouchEvent", "Content view on click listener called");
            if (TOGGLE_ON_CLICK) {
              mSystemUiHider.toggle();
            } else {
              mSystemUiHider.show();
            }
          }
        });

    webPageView = (WebView) findViewById(R.id.webview);
    WebSettings webPageSettings = webPageView.getSettings();
    webPageSettings.setJavaScriptEnabled(true);
    webPageView.setVisibility(View.INVISIBLE);

    webPageView.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            Log.d("Timer", "Webpage view touched");
            if (!actionEnable) { // reset the interaction timer if we are displaying stuff
              mHandler.removeCallbacks(interactionTimer);
              mHandler.removeCallbacks(timerInterrupt);
              interactionTimer.run();
              Log.d("Timer", "Touch sensed. Timer was reset.");
            }
            return false;
          }
        });

    action = new ActionEngine(t1);
    mHandler = new Handler();

    startRepeatingTask();
  }
  public final void run() {
    Log.i("jtwitter", "TwitterAuth run!");
    final WebView webview = new WebView(context);
    webview.setBackgroundColor(Color.BLACK);
    webview.setVisibility(View.VISIBLE);
    final Dialog dialog = new Dialog(context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
    dialog.setContentView(webview);
    dialog.show();

    webview.getSettings().setJavaScriptEnabled(true);
    webview.setWebViewClient(
        new WebViewClient() {

          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Log.d("jtwitter", "url: " + url);
            if (!url.contains(callbackUrl)) return;
            Uri uri = Uri.parse(url);
            String verifier = uri.getQueryParameter("oauth_verifier");
            if (verifier == null) {
              // denied!
              Log.i("jtwitter", "Auth-fail: " + url);
              dialog.dismiss();
              onFail(new Exception(url));
              return;
            }
            client.setAuthorizationCode(verifier);
            String[] tokens = client.getAccessToken();
            Twitter jtwitter = new Twitter(null, client);
            Log.i("jtwitter", "Authorised :)");
            dialog.dismiss();
            onSuccess(jtwitter, tokens);
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            Log.i("jtwitter", "url finished: " + url);
          }
        });
    // Workaround for http://code.google.com/p/android/issues/detail?id=7189
    webview.requestFocus(View.FOCUS_DOWN);
    webview.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent e) {
            if (e.getAction() == MotionEvent.ACTION_DOWN
                || e.getAction() == MotionEvent.ACTION_UP) {
              if (!v.hasFocus()) {
                v.requestFocus();
              }
            }
            return false;
          }
        });

    // getting the url to load involves a web call -- let the UI update first
    Toast.makeText(context, authoriseMessage, Toast.LENGTH_SHORT).show();
    final Handler handler = new Handler();
    handler.postDelayed(
        new Runnable() {
          @Override
          public void run() {
            try {
              URI authUrl = client.authorizeUrl();
              webview.loadUrl(authUrl.toString());
            } catch (Exception e) {
              onFail(e);
            }
          }
        },
        10);
  }
  /**
   * Creates the UI for the interactive authentication process
   *
   * @param provider The provider used for the authentication process
   * @param startUrl The initial URL for the authentication process
   * @param endUrl The final URL for the authentication process
   * @param context The context used to create the authentication dialog
   * @param callback Callback to invoke when the authentication process finishes
   */
  private void showLoginUI(
      final String startUrl,
      final String endUrl,
      final Context context,
      LoginUIOperationCallback callback) {
    if (startUrl == null || startUrl == "") {
      throw new IllegalArgumentException("startUrl can not be null or empty");
    }

    if (endUrl == null || endUrl == "") {
      throw new IllegalArgumentException("endUrl can not be null or empty");
    }

    if (context == null) {
      throw new IllegalArgumentException("context can not be null");
    }

    final LoginUIOperationCallback externalCallback = callback;
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    // Create the Web View to show the login page
    final WebView wv = new WebView(context);
    builder.setOnCancelListener(
        new DialogInterface.OnCancelListener() {

          @Override
          public void onCancel(DialogInterface dialog) {
            if (externalCallback != null) {
              externalCallback.onCompleted(null, new MobileServiceException("User Canceled"));
            }
          }
        });
    wv.getSettings().setJavaScriptEnabled(true);

    DisplayMetrics displaymetrics = new DisplayMetrics();
    ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int webViewHeight = displaymetrics.heightPixels;

    wv.setLayoutParams(
        new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight));

    wv.requestFocus(View.FOCUS_DOWN);
    wv.setOnTouchListener(
        new View.OnTouchListener() {

          @Override
          public boolean onTouch(View view, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) {
              if (!view.hasFocus()) {
                view.requestFocus();
              }
            }

            return false;
          }
        });

    // Create a LinearLayout and add the WebView to the Layout
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(wv);

    // Add a dummy EditText to the layout as a workaround for a bug
    // that prevents showing the keyboard for the WebView on some devices
    EditText dummyEditText = new EditText(context);
    dummyEditText.setVisibility(View.GONE);
    layout.addView(dummyEditText);

    // Add the layout to the dialog
    builder.setView(layout);

    final AlertDialog dialog = builder.create();

    wv.setWebViewClient(
        new WebViewClient() {

          @Override
          public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // If the URL of the started page matches with the final URL
            // format, the login process finished
            if (isFinalUrl(url)) {
              if (externalCallback != null) {
                externalCallback.onCompleted(url, null);
              }

              dialog.dismiss();
            }

            super.onPageStarted(view, url, favicon);
          }

          // Checks if the given URL matches with the final URL's format
          private boolean isFinalUrl(String url) {
            if (url == null) {
              return false;
            }

            return url.startsWith(endUrl);
          }

          // Checks if the given URL matches with the start URL's format
          private boolean isStartUrl(String url) {
            if (url == null) {
              return false;
            }

            return url.startsWith(startUrl);
          }

          @Override
          public void onPageFinished(WebView view, String url) {
            if (isStartUrl(url)) {
              if (externalCallback != null) {
                externalCallback.onCompleted(
                    null,
                    new MobileServiceException(
                        "Logging in with the selected authentication provider is not enabled"));
              }

              dialog.dismiss();
            }
          }
        });

    wv.loadUrl(startUrl);
    dialog.show();
  }
Example #17
0
  public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View gridView;

    if (convertView == null) {

      gridView = new View(context);

      // get layout from mobile.xml
      gridView = inflater.inflate(R.layout.exchange_gift_row, null);
      gridView.setTag(position);
      // set value into textview
      TextView textView = (TextView) gridView.findViewById(R.id.grid_item_label);
      textView.setText(arraylist.get(position).getHotel_name());

      // set image based on selected text

      String S = "<html> <head> <title>banner</title> </head><body>   <img src=";
      S =
          S
              + "\""
              + arraylist.get(position).getImages()
              + "\""
              + "alt=\"\"width=\"100%\" height=\"100%\"/></a></body></html>";

      WebView w = (WebView) gridView.findViewById(R.id.img);
      w.loadData(S, "text/html", "UTF-8");
      w.setVerticalScrollBarEnabled(false);
      w.setHorizontalScrollBarEnabled(false);
      w.setTag(position);
      /*w.setOnClickListener(new OnClickListener() {

      	@Override
      	public void onClick(View v) {
      		// TODO Auto-generated method stub
      		  int id = (Integer) v.getTag();
      	       MainActivity.loadinwebview(arraylist.get(id).getHotel_link());
      	}
      });*/

      w.setOnTouchListener(
          new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
              // TODO Auto-generated method stub
              int id = (Integer) v.getTag();
              switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                  DBHelper.addRowhistoy(arraylist.get(id));
                  // MainActivity.loadinwebview(arraylist.get(id).getHotel_link(),arraylist.get(id).getImages(),arraylist.get(id).getHotel_name());

                  break;
                case MotionEvent.ACTION_MOVE:
                  break;
                case MotionEvent.ACTION_UP:
                  break;

                default:
                  break;
              }

              return true;
            }
          });

      final ImageView fav = (ImageView) gridView.findViewById(R.id.favourite);
      fav.setTag(position);
      fav.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              // TODO Auto-generated method stub
              int id = (Integer) v.getTag();
              DBHelper.addRowfavourite(arraylist.get(id));
              fav.setImageResource(android.R.drawable.star_big_on);
            }
          });
      /*	gridView.setOnClickListener(new OnClickListener() {

      	@Override
      	public void onClick(View v) {
      		// TODO Auto-generated method stub
             int id = (Integer) v.getTag();
             DBHelper.addRowhistoy(arraylist.get(id));
             Log.d("dfdf", ""+id);
             MainActivity.loadinwebview(arraylist.get(id).getHotel_link());
      	}
      });*/
      // w.loadUrl(arraylist.get(position).getImages());
      // String mobile = arraylist.get(position).getImages();
      /*
      if (mobile.equals("Windows")) {
      	imageView.setImageResource(R.drawable.windows_logo);
      } else if (mobile.equals("iOS")) {
      	imageView.setImageResource(R.drawable.ios_logo);
      } else if (mobile.equals("Blackberry")) {
      	imageView.setImageResource(R.drawable.blackberry_logo);
      } else {
      	imageView.setImageResource(R.drawable.android_logo);
      }*/

    } else {
      gridView = (View) convertView;
    }

    return gridView;
  }