コード例 #1
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    that = this;

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    this.getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    container = new RelativeLayout(this);
    RelativeLayout.LayoutParams topLayoutParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    container.setLayoutParams(topLayoutParams);
    setContentView(container);

    mWebView = new WebView(this);
    RelativeLayout.LayoutParams webviewLayoutParams =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    mWebView.setLayoutParams(webviewLayoutParams);

    container.addView(mWebView);
  }
コード例 #2
0
  /**
   * 显示窗口,重新加载url,重新定义窗口大小,设置背景透明度
   *
   * @param position 点击列表位置
   */
  private void showPopWindow(int position) {
    try {
      Bitmap screenBitmap = ScreenShortCutUtil.getShortScreen(getActivity());
      if (screenBitmap != null) {
        FastBlur.blur(getActivity(), screenBitmap, popView);
        screenBitmap.recycle();
      }

    } catch (Exception ex) {

    }

    int baseHight = 0;
    baseHight = Math.round(baseWidth / screenWByH);
    if (mList.get(position).getIsDianZan() == 0) {
      popHotPoint.setBackgroundResource(R.mipmap.love);
    } else {
      popHotPoint.setBackgroundResource(R.mipmap.loved);
    }
    ViewGroup.LayoutParams params = popContainer.getLayoutParams();
    params.width = Math.round(baseWidth);
    params.height = baseHight;
    popContainer.setLayoutParams(params);
    ViewGroup.LayoutParams layoutParams = mWebView.getLayoutParams();
    layoutParams.width = Math.round(baseWidth);
    layoutParams.height = baseHight;
    mWebView.setLayoutParams(layoutParams);
    //        mWebView.setVisibility(View.GONE);

    mWebView.loadUrl(mList.get(position).getShowPath());

    popTitle.setText(mList.get(position).getTitle());
    popAuthor.setText(mList.get(position).getAuthor().getNickname());
    popupWindow.showAtLocation(layView, Gravity.CENTER, 0, 0);
  }
コード例 #3
0
 private void setUpWebView() {
   mWebView = new WebView(getContext());
   mWebView.setVerticalScrollBarEnabled(false);
   mWebView.setHorizontalScrollBarEnabled(false);
   mWebView.setWebViewClient(new FbDialog.FbWebViewClient());
   mWebView.getSettings().setJavaScriptEnabled(true);
   mWebView.loadUrl(mUrl);
   mWebView.setLayoutParams(FILL);
   mContent.addView(mWebView);
 }
コード例 #4
0
ファイル: TwitterDialog.java プロジェクト: dzlab/LaPoste
  private void setUpWebView(LinearLayout layout) {
    webView = new WebView(getContext());

    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    webView.setWebViewClient(new TwitterWebViewClient());
    webView.getSettings().setJavaScriptEnabled(true);
    webView.loadUrl(url);
    webView.setLayoutParams(FILL);

    layout.addView(webView);
  }
コード例 #5
0
 private void setUpWebView() {
   webView = new WebView(getContext());
   webView.setVerticalScrollBarEnabled(false);
   webView.setHorizontalScrollBarEnabled(false);
   webView.getSettings().setJavaScriptEnabled(true);
   webView.setWebViewClient(new RenrenDialog.RenrenWebViewClient());
   webView.loadUrl(mUrl);
   FrameLayout.LayoutParams fill =
       new FrameLayout.LayoutParams(
           ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
   webView.setLayoutParams(fill);
   content.addView(webView);
 }
コード例 #6
0
ファイル: FbDialog.java プロジェクト: carlrice/maven
  private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    mWebView = new WebView(getContext());
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.setWebViewClient(new FbDialog.FbWebViewClient());
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl(mUrl);
    mWebView.setLayoutParams(FILL);
    mWebView.setVisibility(View.INVISIBLE);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(mWebView);
    mContent.addView(webViewContainer);
  }
コード例 #7
0
ファイル: TwitterDialog.java プロジェクト: vsvictor/ShhutApp
  @SuppressLint("SetJavaScriptEnabled")
  private void setUpWebView(int margin) {
    LinearLayout webViewContainer = new LinearLayout(getContext());
    browser = new WebView(getContext());
    browser.setVerticalScrollBarEnabled(false);
    browser.setHorizontalScrollBarEnabled(false);
    browser.setWebViewClient(new TwitterDialog.TwWebViewClient());
    browser.getSettings().setJavaScriptEnabled(true);
    browser.addJavascriptInterface(new MyJavaScriptInterface(), "HTMLOUT");
    browser.setLayoutParams(FILL);

    webViewContainer.setPadding(margin, margin, margin, margin);
    webViewContainer.addView(browser);
    content.addView(webViewContainer);
  }
コード例 #8
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mContext = this;

    // Lookup R.layout.main
    mLayout = (LinearLayout) findViewById(R.id.linearLayout);

    mWebView = new WebView(AndroidWebActivity.this);
    mWebView.setWebViewClient(new myWebViewClient());
    mWebView.loadUrl(CommonUtils.PATH_ASSESTS_WWW + "index.html");
    mWebView.setLayoutParams(mLayout.getLayoutParams());
    mWebView.setScrollBarStyle(WebView.SCROLLBARS_INSIDE_OVERLAY);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mLayout.addView(mWebView);
  }
コード例 #9
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.boring_activity_layout);

    TitleBar titleBar = (TitleBar) findViewById(R.id.boringLayoutTitleBar);
    titleBar.setTitle("Introduction to MIT");

    LinearLayout mRoot = (LinearLayout) findViewById(R.id.boringLayoutRoot);

    WebView contentView = new WebView(this);
    contentView.setLayoutParams(
        new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
    contentView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    mRoot.addView(contentView);
    contentView.loadUrl("file:///android_asset/tour/intro_to_mit.html");
  }
コード例 #10
0
 @SuppressLint({"SetJavaScriptEnabled"})
 private void setUpWebView(int paramInt)
 {
   LinearLayout localLinearLayout = new LinearLayout(getContext());
   webView = new WebDialog.3(this, getContext());
   webView.setVerticalScrollBarEnabled(false);
   webView.setHorizontalScrollBarEnabled(false);
   webView.setWebViewClient(new WebDialog.DialogWebViewClient(this, null));
   webView.getSettings().setJavaScriptEnabled(true);
   webView.loadUrl(url);
   webView.setLayoutParams(new FrameLayout.LayoutParams(-1, -1));
   webView.setVisibility(4);
   webView.getSettings().setSavePassword(false);
   webView.getSettings().setSaveFormData(false);
   localLinearLayout.setPadding(paramInt, paramInt, paramInt, paramInt);
   localLinearLayout.addView(webView);
   localLinearLayout.setBackgroundColor(-872415232);
   contentFrameLayout.addView(localLinearLayout);
 }
コード例 #11
0
  @SuppressWarnings("deprecation")
  @SuppressLint("SetJavaScriptEnabled")
  @Override
  /** When the dialog is created, we add the webview and load the authorize url. */
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    requestWindowFeature(Window.FEATURE_NO_TITLE);

    mProgress = new ProgressDialog(getContext());
    mProgress.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mProgress.setMessage("Loading...");

    mLayout = new LinearLayout(getContext());
    mLayout.setOrientation(LinearLayout.VERTICAL);

    mWebView = new WebView(getContext());
    mWebView.setVerticalScrollBarEnabled(false);
    mWebView.setHorizontalScrollBarEnabled(false);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.getSettings().setSupportZoom(false);
    mWebView.setLayoutParams(MATCH);

    mWebView.setWebViewClient(new OAuthWebViewClient());
    mWebView.setWebChromeClient(new WebChromeClient());

    mWebView.loadUrl(mUrl);
    mLayout.addView(mWebView);

    Display display = getWindow().getWindowManager().getDefaultDisplay();
    addContentView(
        mLayout, new FrameLayout.LayoutParams(display.getWidth() - 20, display.getHeight() - 20));
    CookieSyncManager.createInstance(getContext());
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
  }
コード例 #12
0
  /**
   * 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();
  }
コード例 #13
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate()");
    super.onCreate(savedInstanceState);

    getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    if (fullescreen) {
      getWindow()
          .setFlags(
              WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {
      getWindow()
          .setFlags(
              WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }

    // This builds the view. We could probably get away with NOT having a
    // LinearLayout, but I like having a bucket!
    // Display display = getWindowManager().getDefaultDisplay();
    // int width = display.getWidth();
    // int height = display.getHeight();

    LinearLayout.LayoutParams containerParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0F);

    LinearLayout.LayoutParams webviewParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0F);

    root = new LinearLayout(this);
    root.setOrientation(LinearLayout.VERTICAL);
    root.setBackgroundColor(Color.BLACK);
    root.setLayoutParams(containerParams);

    appView = new WebView(this);
    appView.setLayoutParams(webviewParams);

    WebViewReflect.checkCompatibility();

    /*
     * This changes the setWebChromeClient to log alerts to LogCat!
     * Important for Javascript Debugging
     */
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ECLAIR) {
      appView.setWebChromeClient(new AppWebChromeClient());
    }
    appView.setWebViewClient(new AppWebViewClient());

    appView.setInitialScale(100);
    appView.setVerticalScrollBarEnabled(false);

    WebSettings settings = appView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    Package pack = this.getClass().getPackage();
    String appPackage = pack.getName();

    WebViewReflect.setStorage(settings, true, "/data/data/" + appPackage + "/app_database/");

    /* Bind the appView object to the gap class methods */
    buildWebView(appView);

    root.addView(appView);
    setContentView(root);

    // If url was passed in to intent, then init webview, which will load
    // the url
    Bundle bundle = this.getIntent().getExtras();
    if (bundle != null) {
      String path = bundle.getString("path");
      if (path != null) {
        this.initPath = path;
      }
      String surl = bundle.getString("serverUrl");
      if (surl != null && surl.length() > 0) {
        bindServerUrl(surl);
      }
    }
    // Setup the hardware volume controls to handle volume control
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
  }
コード例 #14
0
ファイル: DroidGap.java プロジェクト: j0ton/phonegap-android
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    // This builds the view.  We could probably get away with NOT having a LinearLayout, but I like
    // having a bucket!

    LinearLayout.LayoutParams containerParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 0.0F);

    LinearLayout.LayoutParams webviewParams =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, 1.0F);

    root = new LinearLayout(this);
    root.setOrientation(LinearLayout.VERTICAL);
    root.setBackgroundColor(Color.BLACK);
    root.setLayoutParams(containerParams);

    appView = new WebView(this);
    appView.setLayoutParams(webviewParams);

    WebViewReflect.checkCompatibility();

    if (android.os.Build.VERSION.RELEASE.startsWith("2."))
      appView.setWebChromeClient(new EclairClient(this));
    else {
      appView.setWebChromeClient(new GapClient(this));
    }

    appView.setInitialScale(100);
    appView.setVerticalScrollBarEnabled(false);

    WebSettings settings = appView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);

    Package pack = this.getClass().getPackage();
    String appPackage = pack.getName();

    WebViewReflect.setStorage(settings, true, "/data/data/" + appPackage + "/app_database/");

    // Disable cookies
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.setAcceptCookie(false);

    // Turn on DOM storage!
    WebViewReflect.setDomStorage(settings);
    // Turn off native geolocation object in browser - we use our own :)
    WebViewReflect.setGeolocationEnabled(settings, true);
    /* Bind the appView object to the gap class methods */
    bindBrowser(appView);
    if (cupcakeStorage != null) cupcakeStorage.setStorage(appPackage);

    root.addView(appView);

    setContentView(root);
  }
コード例 #15
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LOG.Log(Module.GUI, "onCreate");

    // GUI initialization code
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    getWindow()
        .setFlags(
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

    disableThumbnails = checkUnityProperty("Unity_DisableThumbnails");

    // security reasons; don't allow screen shots while this window is displayed
    /* not valid for builds under level 14 */
    if (disableThumbnails && Build.VERSION.SDK_INT >= 14) {
      getWindow()
          .setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    }

    appView = new WebView(this);
    appView.enablePlatformNotifications();
    setGlobalProxy();

    appView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    appView.setId(APPVIEW_ID);
    appView.setWebViewClient(new UnityWebViewClient());
    appView.getSettings().setJavaScriptEnabled(true);
    appView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    appView.getSettings().setAllowFileAccess(true);
    appView.getSettings().setSupportZoom(false);
    appView.getSettings().setAppCacheEnabled(false);
    appView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
    appView.getSettings().setAppCacheMaxSize(0);
    appView.getSettings().setSavePassword(false);
    appView.getSettings().setSaveFormData(false);
    appView.getSettings().setDefaultTextEncodingName("UTF-8");
    appView.getSettings().setGeolocationEnabled(true);
    appView.getSettings().setLightTouchEnabled(true);
    appView.getSettings().setRenderPriority(RenderPriority.HIGH);
    appView.getSettings().setDomStorageEnabled(true); // [MOBPLAT-129] enable HTML5 local storage

    appView.setVerticalScrollBarEnabled(false);

    // Required settings to enable HTML5 database storage
    appView.getSettings().setDatabaseEnabled(true);
    String databasePath =
        this.getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
    appView.getSettings().setDatabasePath(databasePath);

    webChromeClient =
        new WebChromeClient() {

          // Required settings to enable HTML5 database storage
          @Override
          public void onExceededDatabaseQuota(
              String url,
              String databaseIdentifier,
              long currentQuota,
              long estimatedSize,
              long totalUsedQuota,
              WebStorage.QuotaUpdater quotaUpdater) {
            quotaUpdater.updateQuota(estimatedSize * 2);
          };

          @Override
          public void onReachedMaxAppCacheSize(
              long spaceNeeded,
              long totalUsedQuota,
              android.webkit.WebStorage.QuotaUpdater quotaUpdater) {
            quotaUpdater.updateQuota(0);
          };

          @Override
          public boolean onConsoleMessage(ConsoleMessage cm) {
            LOG.Log(
                Module.GUI,
                cm.message() + " -- From line " + cm.lineNumber() + " of " + cm.sourceId());
            return true;
          }
        };

    appView.setWebChromeClient(webChromeClient);

    // create the application logger
    LogManager.setDelegate(new AndroidLoggerDelegate());

    // save the context for further access
    AndroidServiceLocator.setContext(this);

    // initialize the service locator
    activityManager = new AndroidActivityManager(this, appView);

    // killing previous background processes from the same package
    activityManager.killBackgroundProcesses();

    AndroidServiceLocator serviceLocator =
        (AndroidServiceLocator) AndroidServiceLocator.GetInstance();
    serviceLocator.RegisterService(
        this.getAssets(), AndroidServiceLocator.SERVICE_ANDROID_ASSET_MANAGER);
    serviceLocator.RegisterService(
        activityManager, AndroidServiceLocator.SERVICE_ANDROID_ACTIVITY_MANAGER);
    startServer();

    /* THIS COULD NOT BE CHECKED ON API LEVEL < 11; NO suchmethodexception
    boolean hwAccelerated = appView.isHardwareAccelerated();
    if(hwAccelerated)
    	LOG.Log(Module.GUI,"Application View is HARDWARE ACCELERATED");
    else
    	LOG.Log(Module.GUI,"Application View is NOT hardware accelerated");
    */

    final IntentFilter actionFilter = new IntentFilter();
    actionFilter.addAction(android.net.ConnectivityManager.CONNECTIVITY_ACTION);
    // actionFilter.addAction("android.intent.action.SERVICE_STATE");
    registerReceiver(new AndroidNetworkReceiver(appView), actionFilter);

    final Activity currentContext = this;
    new Thread(
            new Runnable() {
              public void run() {
                currentContext.runOnUiThread(
                    new Runnable() {
                      public void run() {
                        appView.loadUrl(WEBVIEW_MAIN_URL);
                      }
                    });
              }
            })
        .start();

    holdSplashScreenOnStartup = checkUnityProperty("Unity_HoldSplashScreenOnStartup");
    hasSplash = activityManager.showSplashScreen(appView);
    RemoteNotificationIntentService.loadNotificationOptions(getResources(), appView, this);
    LocalNotificationReceiver.initialize(appView, this);
  }
コード例 #16
0
  @SuppressLint("SetJavaScriptEnabled")
  private void init(Context context) {
    this.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    int nBtnSize = Global.ScaleSize(27);

    /** create option bar */
    RelativeLayout rlLayout = new RelativeLayout(context);
    rlLayout.setId(ID_OPTION_BAR);
    RelativeLayout.LayoutParams layoutParams =
        new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, Global.ScaleSize(44));
    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    rlLayout.setLayoutParams(layoutParams);
    rlLayout.setBackgroundColor(Color.parseColor("#f4f4f4f2"));
    rlLayout.setPadding(
        Global.ScaleSize(30), Global.ScaleSize(7), Global.ScaleSize(30), Global.ScaleSize(10));
    this.addView(rlLayout);

    webView = new WebView(context);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient());
    webView.setInitialScale(1);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setUseWideViewPort(true);

    RelativeLayout.LayoutParams webLayoutParams =
        new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    webLayoutParams.addRule(RelativeLayout.BELOW, rlLayout.getId());
    webView.setLayoutParams(webLayoutParams);
    webView.setWebViewClient(new myWebViewClient());
    this.addView(webView);

    ImageView imageReflash = new ImageView(context);
    ImageView imageBack = new ImageView(context);
    ImageView imagePrePage = new ImageView(context);
    ImageView imageNextPage = new ImageView(context);

    RelativeLayout.LayoutParams reflashLayoutParams =
        new RelativeLayout.LayoutParams(nBtnSize, nBtnSize);
    reflashLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    imageReflash.setId(ID_FLASH);
    imageReflash.setLayoutParams(reflashLayoutParams);
    imageReflash.setImageResource(Global.getResourceId(context, "reflash_normal", "drawable"));
    imageReflash.setScaleType(ScaleType.CENTER_INSIDE);
    rlLayout.addView(imageReflash);

    RelativeLayout.LayoutParams backLayoutParams =
        new RelativeLayout.LayoutParams(nBtnSize, nBtnSize);
    backLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    imageBack.setId(ID_BACK);
    imageBack.setLayoutParams(backLayoutParams);
    imageBack.setImageResource(Global.getResourceId(context, "exit_normal", "drawable"));
    imageBack.setScaleType(ScaleType.CENTER_INSIDE);
    rlLayout.addView(imageBack);

    RelativeLayout.LayoutParams nextPageLayoutParams =
        new RelativeLayout.LayoutParams(nBtnSize, nBtnSize);
    nextPageLayoutParams.addRule(RelativeLayout.LEFT_OF, imageReflash.getId());
    nextPageLayoutParams.setMargins(0, 0, Global.ScaleSize(65), 0);
    imageNextPage.setId(ID_NEXT_PAGE);
    imageNextPage.setLayoutParams(nextPageLayoutParams);
    imageNextPage.setImageResource(Global.getResourceId(context, "back_normal", "drawable"));
    imageNextPage.setScaleType(ScaleType.CENTER_INSIDE);
    rlLayout.addView(imageNextPage);

    RelativeLayout.LayoutParams prePageLayoutParams =
        new RelativeLayout.LayoutParams(nBtnSize, nBtnSize);
    prePageLayoutParams.addRule(RelativeLayout.LEFT_OF, imageNextPage.getId());
    prePageLayoutParams.setMargins(0, 0, Global.ScaleSize(50), 0);
    imagePrePage.setId(ID_PRE_PAGE);
    imagePrePage.setLayoutParams(prePageLayoutParams);
    imagePrePage.setImageResource(Global.getResourceId(context, "forward_normal", "drawable"));
    imagePrePage.setScaleType(ScaleType.CENTER_INSIDE);
    rlLayout.addView(imagePrePage);

    imageReflash.setOnTouchListener(onTouchListener);
    imageBack.setOnTouchListener(onTouchListener);
    imagePrePage.setOnTouchListener(onTouchListener);
    imageNextPage.setOnTouchListener(onTouchListener);

    progressBar = new ProgressBar(getContext());
    RelativeLayout.LayoutParams progressParams = new RelativeLayout.LayoutParams(80, 80);
    progressParams.addRule(RelativeLayout.CENTER_IN_PARENT);
    progressBar.setLayoutParams(progressParams);
    progressBar
        .getIndeterminateDrawable()
        .setColorFilter(0xFF309FD6, android.graphics.PorterDuff.Mode.MULTIPLY);
  }