Exemple #1
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    Log.d();
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    mBrowser = this;

    mVizWebViewClient = new VizWebViewClient(this);
    mWebChromeClient = new VizWebChromeClient(this);

    mVizWebView = new WebView(getActivity()); // get attributes?
    mVizWebView.setWebViewClient(mVizWebViewClient);
    mVizWebView.setWebChromeClient(mWebChromeClient);
    if (savedInstanceState != null) {
      Log.d("restoring web view state");
      mVizWebView.restoreState(savedInstanceState);
    }
    WebSettings s = mVizWebView.getSettings();
    s.setJavaScriptEnabled(true);
    s.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
    s.setBuiltInZoomControls(true);
    s.setUseWideViewPort(true);
    s.setLoadWithOverviewMode(true);
    s.setSaveFormData(true);

    mVizWebView.setId(61377); // PhoneWindow complained about no id (focus couldn't be saved)

    // Loading homepage here results in an exception on ICS, not sure why.
    // Update: post-poning until onCreatingView doesn't entirely fix the
    // issue either.
    // mVizWebView.loadUrl(defaultURL);
  }
Exemple #2
0
 @Override
 public void onSaveInstanceState(Bundle outState) {
   super.onSaveInstanceState(outState);
   mVizWebView.saveState(outState);
   outState.putString("bla", "Value1");
   Log.d();
 }
Exemple #3
0
 @Override
 public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
   Log.d();
   super.onCreateOptionsMenu(menu, inflater);
   inflater.inflate(R.menu.browser_menu, menu);
   // setCanGoBack();
 }
Exemple #4
0
 @Override
 public void onDestroyView() {
   Log.d();
   ViewGroup v = (ViewGroup) getActivity().findViewById(R.id.browserRelativeLayout);
   v.removeView(mVizWebView);
   super.onDestroyView();
 }
Exemple #5
0
 @Override
 public void onActivityCreated(Bundle savedInstanceState) {
   Log.d();
   if (savedInstanceState != null) {
     mVizWebView.restoreState(savedInstanceState);
   }
   super.onActivityCreated(savedInstanceState);
 }
Exemple #6
0
 @Override
 public void onPause() {
   Log.d();
   String url = null;
   if (mVizWebView != null) {
     url = mVizWebView.getUrl();
   }
   if (url != null) {
     Log.d("Storing url for later: " + url);
     SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
     SharedPreferences.Editor ed = prefs.edit();
     ed.putString(Preferences.LASTPAGE_LOADED, url);
     ed.commit();
   }
   super.onPause();
 }
Exemple #7
0
 @Override
 public void onStop() {
   super.onStop();
   mVizWebView.stopLoading();
 }
Exemple #8
0
 @Override
 public void onResume() {
   Log.d();
   super.onResume();
   refreshUI();
 }
Exemple #9
0
 @Override
 public void onStart() {
   Log.d();
   super.onStart();
 }
Exemple #10
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;
  }