Java Code Examples for android.webkit.WebView#restoreState()

The following examples show how to use android.webkit.WebView#restoreState() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginActivity.java    From utexas-utilities with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setupActionBar();
    webView = new WebView(this);

    LoginWebViewClient wvlc = new LoginWebViewClient(this, getIntent().getStringExtra(
            "activity"));
    webView.setWebViewClient(wvlc);
    if (savedInstanceState != null) {
        webView.restoreState(savedInstanceState);
    } else {
        webView.getSettings().setJavaScriptEnabled(true);
        webView.loadUrl("https://login.utexas.edu/login/UI/Login");
        actionBar.setSubtitle("UTLogin");
    }
    setContentView(webView);
}
 
Example 2
Source File: HelpActivity.java    From android-discourse with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.activity_help);

    webView = (WebView) findViewById(R.id.help_contents);

    String page = getIntent().getStringExtra(Utils.EXTRA_URL);
    if (TextUtils.isEmpty(page)) {
        page = "faq.html";
    }
    if (page.equals("login.html")) {
        setTitle(R.string.title_get_password);
    }

    if (icicle == null) {
        webView.loadUrl(BASE_URL + page);
    } else {
        webView.restoreState(icicle);
    }
    setupActionBar();
}
 
Example 3
Source File: HelpActivity.java    From reacteu-app with MIT License 5 votes vote down vote up
@Override
 protected void onCreate(Bundle icicle) {
   super.onCreate(icicle);

fakeR = new FakeR(this);

   setContentView(fakeR.getId("layout", "help"));

   webView = (WebView)findViewById(fakeR.getId("id", "help_contents"));
   webView.setWebViewClient(new HelpClient());

   // Froyo has a bug with calling onCreate() twice in a row, which causes the What's New page
   // that's auto-loaded on first run to appear blank. As a workaround we only call restoreState()
   // if a valid URL was loaded at the time the previous activity was torn down.
   Intent intent = getIntent();
   if (icicle != null && icicle.getBoolean(WEBVIEW_STATE_PRESENT, false)) {
     webView.restoreState(icicle);
   } else if (intent != null) {
     String page = intent.getStringExtra(REQUESTED_PAGE_KEY);
     if (page != null && page.length() > 0) {
       webView.loadUrl(BASE_URL + page);
     } else {
       webView.loadUrl(BASE_URL + DEFAULT_PAGE);
     }
   } else {
     webView.loadUrl(BASE_URL + DEFAULT_PAGE);
   }

   backButton = (Button) findViewById(fakeR.getId("id", "back_button"));
   backButton.setOnClickListener(backListener);
   View doneButton = findViewById(fakeR.getId("id", "done_button"));
   doneButton.setOnClickListener(doneListener);
 }
 
Example 4
Source File: EvernoteOAuthActivity.java    From EverMemo-EverNote with MIT License 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  //Show web loading progress
  getWindow().requestFeature(Window.FEATURE_PROGRESS);

  setContentView(R.layout.esdk__webview);
  mActivity = this;

  mWebView = (WebView) findViewById(R.id.esdk__webview);
  mWebView.setWebViewClient(mWebViewClient);
  mWebView.setWebChromeClient(mWebChromeClient);
  mWebView.getSettings().setJavaScriptEnabled(true);

  if (savedInstanceState != null) {
    mEvernoteService = savedInstanceState.getParcelable(EXTRA_EVERNOTE_SERVICE);
    mConsumerKey = savedInstanceState.getString(EXTRA_CONSUMER_KEY);
    mConsumerSecret = savedInstanceState.getString(EXTRA_CONSUMER_SECRET);
    mRequestToken = savedInstanceState.getString(EXTRA_REQUEST_TOKEN);
    mRequestTokenSecret = savedInstanceState.getString(EXTRA_REQUEST_TOKEN_SECRET);
    mSelectedBootstrapProfile = (BootstrapProfile) savedInstanceState.getSerializable(EXTRA_BOOTSTRAP_SELECTED_PROFILE);
    mSelectedBootstrapProfilePos = savedInstanceState.getInt(EXTRA_BOOTSTRAP_SELECTED_PROFILE_POS);
    mBootstrapProfiles = (ArrayList<BootstrapProfile>) savedInstanceState.getSerializable(EXTRA_BOOTSTRAP_SELECTED_PROFILES);
    mWebView.restoreState(savedInstanceState);

  } else {
    Intent intent = getIntent();
    mEvernoteService = intent.getParcelableExtra(EXTRA_EVERNOTE_SERVICE);
    mConsumerKey = intent.getStringExtra(EXTRA_CONSUMER_KEY);
    mConsumerSecret = intent.getStringExtra(EXTRA_CONSUMER_SECRET);
  }
}
 
Example 5
Source File: HelpActivity.java    From zxingfragmentlib with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.help);

  webView = (WebView) findViewById(R.id.help_contents);

  if (icicle == null) {
    webView.loadUrl(BASE_URL + "index.html");
  } else {
    webView.restoreState(icicle);
  }
}
 
Example 6
Source File: MainFragment.java    From chromium-webview-samples with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get reference of WebView from layout/activity_main.xml
    mWebView = (WebView) rootView.findViewById(R.id.fragment_main_webview);

    // Add Javascript Interface, this will expose "window.NotificationBind"
    // in Javascript
    mWebView.addJavascriptInterface(
            new NotificationBindObject(getActivity().getApplicationContext()),
            "NotificationBind");

    setUpWebViewDefaults(mWebView);

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        // Restore the previous URL and history stack
        mWebView.restoreState(savedInstanceState);
    }

    // Prepare the WebView and get the appropriate URL
    String url = prepareWebView(mWebView.getUrl());

    // Load the local index.html file
    if(mWebView.getUrl() == null) {
        mWebView.loadUrl(url);
    }

    return rootView;
}
 
Example 7
Source File: NewsWebViewActivity.java    From SimpleNews with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_news_web_view);
    mWebView = (WebView) findViewById(R.id.web_view);
    setUpWebViewDefaults();

    if (savedInstanceState == null) {
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            mEntry = null;
        } else {
            mEntry = (Entry) getIntent().getSerializableExtra(ENTRY_KEY);
        }
    } else {
        mWebView.restoreState(savedInstanceState);
        mEntry = (Entry) savedInstanceState.getSerializable(ENTRY_KEY);
        isLoading = savedInstanceState.getBoolean(LOADING_KEY);
        invalidateOptionsMenu();
        setRefreshActionButtonState(isLoading);
    }
    if (mEntry != null) {
        loadPage();

        String formattedDate = "";
        if (mEntry.getDate() != null) {
            long current = Math.min(new Date().getTime(), mEntry.getDate());
            formattedDate = new PrettyTime().format(new Date(current));
        }

        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setTitle(mEntry.getTitle());
            actionBar.setSubtitle(String.format("%s - %s", mEntry.getSrcName(), formattedDate));
        }
    }
}
 
Example 8
Source File: HelpActivity.java    From android-apps with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.help);

  webView = (WebView)findViewById(R.id.help_contents);
  webView.setWebViewClient(new HelpClient());

  // Froyo has a bug with calling onCreate() twice in a row, which causes the What's New page
  // that's auto-loaded on first run to appear blank. As a workaround we only call restoreState()
  // if a valid URL was loaded at the time the previous activity was torn down.
  Intent intent = getIntent();
  if (icicle != null && icicle.getBoolean(WEBVIEW_STATE_PRESENT, false)) {
    webView.restoreState(icicle);
  } else if (intent != null) {
    String page = intent.getStringExtra(REQUESTED_PAGE_KEY);
    if (page != null && page.length() > 0) {
      webView.loadUrl(BASE_URL + page);
    } else {
      webView.loadUrl(BASE_URL + DEFAULT_PAGE);
    }
  } else {
    webView.loadUrl(BASE_URL + DEFAULT_PAGE);
  }

  backButton = (Button) findViewById(R.id.back_button);
  backButton.setOnClickListener(backListener);
  View doneButton = findViewById(R.id.done_button);
  doneButton.setOnClickListener(doneListener);
}
 
Example 9
Source File: HelpActivity.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.help);

  webView = (WebView) findViewById(R.id.help_contents);

  if (icicle == null) {
    webView.loadUrl(BASE_URL + "index.html");
  } else {
    webView.restoreState(icicle);
  }
}
 
Example 10
Source File: WebActivity.java    From droidddle with Apache License 2.0 5 votes vote down vote up
@Override
protected void onMyCreate(Bundle icicle) {
    setContentView(R.layout.activity_web);
    ButterKnife.inject(this);
    webView = (WebView) findViewById(R.id.web);

    if (icicle == null) {
        String url = getIntent().getStringExtra(UiUtils.ARG_URL);
        webView.loadUrl(url);
    } else {
        webView.restoreState(icicle);
    }
}
 
Example 11
Source File: HelpActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.help);

  webView = (WebView) findViewById(R.id.help_contents);

  if (icicle == null) {
    webView.loadUrl(BASE_URL + "index.html");
  } else {
    webView.restoreState(icicle);
  }
}
 
Example 12
Source File: HelpActivity.java    From mytracks with Apache License 2.0 5 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  String subtitle = getString(R.string.my_tracks_app_name) + " v"
      + SystemUtils.getMyTracksVersion(this);
  ApiAdapterFactory.getApiAdapter()
      .setTitleAndSubtitle(this, getString(R.string.menu_help), subtitle);

  webView = (WebView) findViewById(R.id.help_webview);
  webView.getSettings().setJavaScriptEnabled(true);
  webView.setWebViewClient(new WebViewClient());

  if (savedInstanceState == null) {
    String language = Locale.getDefault().getLanguage();
    if (language == null || language.equals("")) {
      language = "en";
    }
    webView.loadUrl(getString(R.string.my_tracks_help_url, language));
  } else {
    webView.restoreState(savedInstanceState);
  }

  Button feedback = (Button) findViewById(R.id.help_feedback);
  boolean showFeedback = ApiAdapterFactory.getApiAdapter().isGoogleFeedbackAvailable();
  feedback.setVisibility(showFeedback ? View.VISIBLE : View.GONE);
  if (showFeedback) {
    feedback.setOnClickListener(new View.OnClickListener() {
        @Override
      public void onClick(View v) {
        GoogleFeedbackUtils.bindFeedback(HelpActivity.this);
      }
    });
  }
}
 
Example 13
Source File: HelpActivity.java    From weex with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.help);

  webView = (WebView) findViewById(R.id.help_contents);

  if (icicle == null) {
    webView.loadUrl(BASE_URL + "index.html");
  } else {
    webView.restoreState(icicle);
  }
}
 
Example 14
Source File: HelpActivity.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.help);

  webView = (WebView) findViewById(R.id.help_contents);

  if (icicle == null) {
    webView.loadUrl(BASE_URL + "index.html");
  } else {
    webView.restoreState(icicle);
  }
}
 
Example 15
Source File: HelpActivity.java    From ZXing-Standalone-library with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.help);

  webView = (WebView) findViewById(R.id.help_contents);

  if (icicle == null) {
    webView.loadUrl(BASE_URL + "index.html");
  } else {
    webView.restoreState(icicle);
  }
}
 
Example 16
Source File: UnitedWebFragment.java    From United4 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Restore web view state
 * @param savedInstanceState state to be restored
 */
@Override
public void onViewStateRestored(Bundle savedInstanceState) {
    super.onViewStateRestored(savedInstanceState);
    if (getView() != null && savedInstanceState != null) {
        WebView webview = getView().findViewById(R.id.main_webkit);
        webview.restoreState(savedInstanceState);
    }
}
 
Example 17
Source File: HelpActivity.java    From android-mrz-reader with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle icicle) {
  super.onCreate(icicle);
  setContentView(R.layout.help);

  webView = (WebView)findViewById(R.id.help_contents);
  webView.setWebViewClient(new HelpClient(this));

  Intent intent = getIntent();
  String page = intent.getStringExtra(REQUESTED_PAGE_KEY);

  // Show an OK button.
  View doneButton = findViewById(R.id.done_button);
  doneButton.setOnClickListener(doneListener);

  if (page.equals(DEFAULT_PAGE)) {
    doneButton.setVisibility(View.VISIBLE);
  } else {
    doneButton.setVisibility(View.GONE);
  }

  // Froyo has a bug with calling onCreate() twice in a row, which causes the What's New page
  // that's auto-loaded on first run to appear blank. As a workaround we only call restoreState()
  // if a valid URL was loaded at the time the previous activity was torn down.
  if (icicle != null && icicle.getBoolean(WEBVIEW_STATE_PRESENT, false)) {
    webView.restoreState(icicle);
  } else if (intent != null && page != null && page.length() > 0) {
    webView.loadUrl(BASE_URL + page);
  } else {
    webView.loadUrl(BASE_URL + DEFAULT_PAGE);
  }
}
 
Example 18
Source File: WebViewFallbackActivity.java    From android-browser-helper with Apache License 2.0 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.mLaunchUrl = this.getIntent().getParcelableExtra(KEY_LAUNCH_URI);
    if (!"https".equals(this.mLaunchUrl.getScheme())) {
        throw new IllegalArgumentException("launchUrl scheme must be 'https'");
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (getIntent().hasExtra(KEY_NAVIGATION_BAR_COLOR)) {
            int navigationBarColor = this.getIntent().getIntExtra(KEY_NAVIGATION_BAR_COLOR, 0);
            getWindow().setNavigationBarColor(navigationBarColor);
        }
    }

    if (getIntent().hasExtra(KEY_STATUS_BAR_COLOR)) {
        mStatusBarColor = this.getIntent().getIntExtra(KEY_STATUS_BAR_COLOR, 0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            getWindow().setStatusBarColor(mStatusBarColor);
        }
    } else {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mStatusBarColor = getWindow().getStatusBarColor();
        } else {
            mStatusBarColor = Color.WHITE;
        }
    }

    if (getIntent().hasExtra(KEY_EXTRA_ORIGINS)) {
        List<String> extraOrigins = getIntent().getStringArrayListExtra(KEY_EXTRA_ORIGINS);
        if (extraOrigins != null) {
            for (String extraOrigin : extraOrigins) {
                Uri extraOriginUri = Uri.parse(extraOrigin);
                if (!"https".equalsIgnoreCase(extraOriginUri.getScheme())) {
                    Log.w(TAG, "Only 'https' origins are accepted. Ignoring extra origin: "
                            + extraOrigin);
                    continue;
                }
                mExtraOrigins.add(extraOriginUri);
            }
        }
    }

    mWebView = new WebView(this);
    mWebView.setWebViewClient(createWebViewClient());

    WebSettings webSettings = mWebView.getSettings();
    setupWebSettings(webSettings);

    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    setContentView(mWebView,layoutParams);
    if (savedInstanceState != null) {
        mWebView.restoreState(savedInstanceState);
        return;
    }
    mWebView.loadUrl(mLaunchUrl.toString());
}
 
Example 19
Source File: EvernoteOAuthActivity.java    From EverMemo with MIT License 4 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	// Show web loading progress
	getWindow().requestFeature(Window.FEATURE_PROGRESS);

	setContentView(R.layout.esdk__webview);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setDisplayUseLogoEnabled(false);
	getSupportActionBar().setDisplayShowTitleEnabled(true);
	mActivity = this;

	mWebView = (WebView) findViewById(R.id.esdk__webview);
	mWebView.setWebViewClient(mWebViewClient);
	mWebView.setWebChromeClient(mWebChromeClient);
	mWebView.getSettings().setJavaScriptEnabled(true);

	if (savedInstanceState != null) {
		mEvernoteService = savedInstanceState
				.getParcelable(EXTRA_EVERNOTE_SERVICE);
		mConsumerKey = savedInstanceState.getString(EXTRA_CONSUMER_KEY);
		mConsumerSecret = savedInstanceState
				.getString(EXTRA_CONSUMER_SECRET);
		mRequestToken = savedInstanceState.getString(EXTRA_REQUEST_TOKEN);
		mRequestTokenSecret = savedInstanceState
				.getString(EXTRA_REQUEST_TOKEN_SECRET);
		mSelectedBootstrapProfile = (BootstrapProfile) savedInstanceState
				.getSerializable(EXTRA_BOOTSTRAP_SELECTED_PROFILE);
		mSelectedBootstrapProfilePos = savedInstanceState
				.getInt(EXTRA_BOOTSTRAP_SELECTED_PROFILE_POS);
		mBootstrapProfiles = (ArrayList<BootstrapProfile>) savedInstanceState
				.getSerializable(EXTRA_BOOTSTRAP_SELECTED_PROFILES);
		mWebView.restoreState(savedInstanceState);

	} else {
		Intent intent = getIntent();
		mEvernoteService = intent
				.getParcelableExtra(EXTRA_EVERNOTE_SERVICE);
		mConsumerKey = intent.getStringExtra(EXTRA_CONSUMER_KEY);
		mConsumerSecret = intent.getStringExtra(EXTRA_CONSUMER_SECRET);
	}
}
 
Example 20
Source File: MainFragment.java    From chromium-webview-samples with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    // Get reference of WebView from layout/activity_main.xml
    mWebView = (WebView) rootView.findViewById(R.id.fragment_main_webview);

    setUpWebViewDefaults(mWebView);

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        // Restore the previous URL and history stack
        mWebView.restoreState(savedInstanceState);
    }

    mWebView.setWebChromeClient(new WebChromeClient() {
        public boolean onShowFileChooser(
                WebView webView, ValueCallback<Uri[]> filePathCallback,
                WebChromeClient.FileChooserParams fileChooserParams) {
            if(mFilePathCallback != null) {
                mFilePathCallback.onReceiveValue(null);
            }
            mFilePathCallback = filePathCallback;

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
                // Create the File where the photo should go
                File photoFile = null;
                try {
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                } catch (IOException ex) {
                    // Error occurred while creating the File
                    Log.e(TAG, "Unable to create Image File", ex);
                }

                // Continue only if the File was successfully created
                if (photoFile != null) {
                    mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT,
                            Uri.fromFile(photoFile));
                } else {
                    takePictureIntent = null;
                }
            }

            Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("image/*");

            Intent[] intentArray;
            if(takePictureIntent != null) {
                intentArray = new Intent[]{takePictureIntent};
            } else {
                intentArray = new Intent[0];
            }

            Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
            chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
            chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

            startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

            return true;
        }
    });

    // Load the local index.html file
    if(mWebView.getUrl() == null) {
        mWebView.loadUrl("file:///android_asset/www/index.html");
    }

    return rootView;
}