List of usage examples for android.webkit WebView WebView
public WebView(Context context)
From source file:com.nuvolect.securesuite.util.MyWebViewFragment.java
/** * Called to instantiate the view. Creates and returns the WebView. *//*from w w w .j ava 2 s . c o m*/ @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (mWebView != null) { mWebView.destroy(); } mWebView = new WebView(getActivity()); mIsWebViewAvailable = true; return mWebView; }
From source file:com.android.browser.GoogleAccountLogin.java
private GoogleAccountLogin(Activity activity, Account account, Runnable runnable) { mActivity = activity;//from ww w. j a v a 2 s . c o m mAccount = account; mWebView = new WebView(mActivity); mRunnable = runnable; mUserAgent = mWebView.getSettings().getUserAgentString(); // XXX: Doing pre-login causes onResume to skip calling // resumeWebViewTimers. So to avoid problems with timers not running, we // duplicate the work here using the off-screen WebView. CookieSyncManager.getInstance().startSync(); WebViewTimersControl.getInstance().onBrowserActivityResume(mWebView); mWebView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } @Override public void onPageFinished(WebView view, String url) { done(); } }); }
From source file:com.llkj.cm.restfull.network.NetworkConnection.java
/** * By default the user agent is empty. If you want to use the standard Android user agent, call this method before using the * <code>retrieveResponseFromService</code> methods * /* ww w .java 2s .com*/ * @param context The context */ public static void generateDefaultUserAgent(final Context context) { if (sDefaultUserAgent != null) { return; } try { Constructor<WebSettings> constructor = WebSettings.class.getDeclaredConstructor(Context.class, WebView.class); constructor.setAccessible(true); try { WebSettings settings = constructor.newInstance(context, null); sDefaultUserAgent = settings.getUserAgentString(); } finally { constructor.setAccessible(false); } } catch (Exception e) { if (Thread.currentThread().getName().equalsIgnoreCase("main")) { WebView webview = new WebView(context); sDefaultUserAgent = webview.getSettings().getUserAgentString(); } else { Thread thread = new Thread() { @Override public void run() { Looper.prepare(); WebView webview = new WebView(context); sDefaultUserAgent = webview.getSettings().getUserAgentString(); Looper.loop(); } }; thread.start(); } } }
From source file:org.projecthdata.hhub.ui.HDataWebOauthActivity2.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_PROGRESS); getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); webView = new WebView(this); setContentView(webView);//from ww w .j a va2s .co m activity = this; this.hDataConnectionFactory = new HDataConnectionFactory(clientId, clientSecret, "server here"); webView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { activity.setTitle("Loading..."); activity.setProgress(progress * 100); if (progress == 100) { activity.setTitle(R.string.app_name); } } }); webView.setWebViewClient(new MyWebViewClient()); }
From source file:com.nqsky.nest.home.activity.RecyclerGridFragment.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); final RecyclerListAdapter adapter = new RecyclerListAdapter(getActivity(), this) { View view;// w ww. jav a2 s .c o m @Override public ItemViewHolder onCreatViewFristVHoleder(ViewGroup parent, int viewType) { view = new WebView(getActivity()); view.setId(R.id.webview); GridLayoutManager.LayoutParams params = new GridLayoutManager.LayoutParams( GridLayoutManager.LayoutParams.MATCH_PARENT, 800); view.setLayoutParams(params); return new AppItemViewHolder(view, viewType); } @Override public ItemViewHolder onCreatViewItemVHoleder(ViewGroup parent, int viewType) { view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main, null, false); return new AppItemViewHolder(view, viewType); } @Override public ItemViewHolder onCreatViewHeaderVHoleder(ViewGroup parent, int viewType) { view = LayoutInflater.from(parent.getContext()).inflate(R.layout.header, parent, false); return new AppItemViewHolder(view, viewType); } @Override public void onBindViewFristHolder(ItemViewHolder holder, int position) { if (holder instanceof AppItemViewHolder) { ((AppItemViewHolder) holder).webview.loadUrl("http://www.qq.com");//.setText(super.mItems.get(position).getText()); } } @Override public void onBindViewItemHolder(ItemViewHolder holder, int position) { if (holder instanceof AppItemViewHolder) { ((AppItemViewHolder) holder).textView.setText(super.mItems.get(position).getText()); ((AppItemViewHolder) holder).handleView .setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_app)); } } @Override public void onBindViewHeaderHolder(ItemViewHolder holder, int position) { if (holder instanceof AppItemViewHolder) { ((AppItemViewHolder) holder).textView.setText(super.mItems.get(position).getText()); } } }; RecyclerView recyclerView = (RecyclerView) view.findViewById(android.R.id.list); recyclerView.setHasFixedSize(true); recyclerView.setAdapter(adapter); recyclerView.setItemAnimator(new DefaultItemAnimator()); // final int spanCount = getResources().getInteger(R.integer.grid_columns); final GridLayoutManager layoutManager = new GridLayoutManager(getActivity(), 4); recyclerView.setLayoutManager(layoutManager); layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { switch (adapter.getItemViewType(position)) { case RecyclerListAdapter.ITEM_VIEW_TYPE_CUSTOMER: return 4; case RecyclerListAdapter.ITEM_VIEW_TYPE_HEADER: return 4; case RecyclerListAdapter.ITEM_VIEW_TYPE_ITEM: return 1; default: return 4; } } }); ItemTouchHelper.Callback callback = new CJTouchHelperCallback(adapter); mItemTouchHelper = new ItemTouchHelper(callback); mItemTouchHelper.attachToRecyclerView(recyclerView); adapter.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(RecyclerGridFragment.this.getActivity(), "?" + position + "", Toast.LENGTH_SHORT).show(); if (adapter.getItemViewType(position) == RecyclerListAdapter.ITEM_VIEW_TYPE_ITEM) { try { ItemBean bean = new ItemBean(); bean.setText("?" + position + ""); bean.setType(RecyclerListAdapter.ITEM_VIEW_TYPE_ITEM); bean.setId(position / 10 + ""); bean.setpID(adapter.getItemBean(position).getpID()); adapter.addItem(adapter.getItemBean(position).getpID(), bean); } catch (NullPointerException e) { e.printStackTrace(); } } else { adapter.delItem(position + 1); } } }); ItemBean bean; List<ItemBean> list = new ArrayList<ItemBean>(); for (int i = 0; i < 80; i++) { bean = new ItemBean(); if (i % 10 == 0) { bean.setText("" + i / 10); bean.setType(RecyclerListAdapter.ITEM_VIEW_TYPE_HEADER); bean.setId(String.valueOf((i / 10))); } else { bean.setText("Item" + i / 10 + i % 10); bean.setType(RecyclerListAdapter.ITEM_VIEW_TYPE_ITEM); bean.setpID(String.valueOf((i / 10))); bean.setId(String.valueOf((i))); } list.add(bean); } bean = new ItemBean(); bean.setText(""); bean.setType(RecyclerListAdapter.ITEM_VIEW_TYPE_CUSTOMER); bean.setId(String.valueOf((10))); list.add(0, bean); adapter.addItems(list); final com.cjj.MaterialRefreshLayout swipeRefreshLayout; final Handler handler = new Handler(); swipeRefreshLayout = (com.cjj.MaterialRefreshLayout) view.findViewById(R.id.swipe_refresh_widget); swipeRefreshLayout.setWaveColor(0xf90fffff); swipeRefreshLayout.setIsOverLay(true); swipeRefreshLayout.setWaveShow(true); swipeRefreshLayout.setLoadMore(true); swipeRefreshLayout.setMaterialRefreshListener(new MaterialRefreshListener() { @Override public void onRefresh(final MaterialRefreshLayout materialRefreshLayout) { handler.postDelayed(new Runnable() { @Override public void run() { adapter.clear(); ItemBean bean; List<ItemBean> list = new ArrayList<ItemBean>(); for (int i = 0; i < 80; i++) { bean = new ItemBean(); if (i % 10 == 0) { bean.setText("" + i / 10); bean.setType(RecyclerListAdapter.ITEM_VIEW_TYPE_HEADER); bean.setId(String.valueOf((i / 10))); } else { bean.setText("" + i / 10 + i % 10); bean.setType(RecyclerListAdapter.ITEM_VIEW_TYPE_ITEM); bean.setpID(String.valueOf((i / 10))); bean.setId(String.valueOf((i))); } list.add(bean); } bean = new ItemBean(); bean.setText(""); bean.setType(RecyclerListAdapter.ITEM_VIEW_TYPE_CUSTOMER); bean.setId(String.valueOf((10))); list.add(0, bean); adapter.addItems(list); materialRefreshLayout.finishRefresh(); } }, 1000); } @Override public void onRefreshLoadMore(final MaterialRefreshLayout materialRefreshLayout) { super.onRefreshLoadMore(materialRefreshLayout); handler.postDelayed(new Runnable() { @Override public void run() { ArrayList list = new ArrayList<ItemBean>(); for (int i = 60; i < 90; i++) { ItemBean bean = new ItemBean(); if (i % 10 == 0) { bean.setText("" + i / 10); bean.setType(RecyclerListAdapter.ITEM_VIEW_TYPE_HEADER); bean.setId(String.valueOf((i / 10))); } else { bean.setText("" + i / 10 + i % 10); bean.setType(RecyclerListAdapter.ITEM_VIEW_TYPE_ITEM); bean.setpID(String.valueOf((i / 10))); bean.setId(String.valueOf((i))); } list.add(bean); } // bean=new ItemBean(); // bean.setText("" ); // bean.setType(RecyclerListAdapter.ITEM_VIEW_TYPE_CUSTOMER); // bean.setId(String.valueOf((10))); // list.add(0,bean); adapter.addItems(list); materialRefreshLayout.finishRefreshLoadMore(); } }, 1000); } }); }
From source file:com.ntsync.android.sync.activities.ShowLicensesActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SystemHelper.initSystem(this); mWebView = new WebView(this); CharSequence title = getText(R.string.license_activity_title); CharSequence msg = getText(R.string.license_activity_loading); ProgressDialog pd = ProgressDialog.show(this, title, msg, true, false); pd.setProgressStyle(ProgressDialog.STYLE_SPINNER); mSpinnerDlg = pd;/*w w w . j av a 2s . c o m*/ getSupportLoaderManager().initLoader(LOADID_LICENSES, null, this); }
From source file:org.mariotaku.twidere.activity.AuthorizeActivity.java
@Override public void onCreate(final Bundle savedInstanceState) { requestSupportWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); final Bundle extras = getIntent().getExtras(); if (extras == null) { finish();//from w w w. jav a 2s . co m return; } mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); setContentView(mWebView = new WebView(this)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mWebView.setWebViewClient(new AuthorizationWebViewClient()); mWebView.setVerticalScrollBarEnabled(false); mWebSettings = mWebView.getSettings(); mWebSettings.setLoadsImagesAutomatically(true); mWebSettings.setJavaScriptEnabled(true); mWebSettings.setBlockNetworkImage(false); mWebSettings.setSaveFormData(true); mWebSettings.setSavePassword(true); getRequestToken(); }
From source file:com.utopia.thefinestartist.SimpleWebViewFragment.java
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" }) @Override// w w w . j ava 2 s .c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.web_view, container, false); mReload = (FrameLayout) view.findViewById(R.id.web_view_reload); mLbar = (ProgressBar) view.findViewById(R.id.web_view_loading); mPbar = (ProgressBar) view.findViewById(R.id.web_view_progress); mView = (FrameLayout) view.findViewById(R.id.web_view); mView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); mWebview = new WebView(getActivity()); mWebview.setVisibility(View.GONE); mWebview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); if (mUrl != null) { mWebview.setWebViewClient(new MyWebViewClient()); mWebview.setWebChromeClient(new MyWebChromeClient()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) mWebview.getSettings().setPluginState(PluginState.ON); mWebview.getSettings().setUseWideViewPort(false); mWebview.getSettings().setDefaultZoom(ZoomDensity.FAR); mWebview.getSettings().setBuiltInZoomControls(true); mWebview.getSettings().setSupportZoom(true); mWebview.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); mWebview.getSettings().setAllowFileAccess(true); mWebview.getSettings().setDomStorageEnabled(true); mWebview.getSettings().setJavaScriptEnabled(true); mWebview.addJavascriptInterface(new JavaScriptInterface(getActivity()), "Android"); mWebview.getSettings().setAppCacheEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) mWebview.getSettings().setDisplayZoomControls(false); mWebview.loadUrl(mUrl); } mView.addView(mWebview); mReloadBtn = (Button) view.findViewById(R.id.reload_btn); mReloadBtn.setOnClickListener(this); return view; }
From source file:org.ciasaboark.tacere.activity.fragment.TutorialCrashReporterFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { rootView = (ViewGroup) inflater.inflate(layout, container, false); TextView sampleReport = (TextView) rootView.findViewById(R.id.tutorial_report_sample_button); sampleReport.setOnClickListener(new View.OnClickListener() { @Override/*w w w . jav a2s . c o m*/ public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder( new ContextThemeWrapper(getActivity(), android.R.style.Theme_DeviceDefault_Dialog)); builder.setTitle(R.string.tutorial_crash_report_sample_title).setPositiveButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //nothing to do } }); WebView webView = new WebView(getActivity()); webView.loadUrl("file:///android_asset/sample_bug_report.html"); builder.setView(webView); builder.show(); } }); final CheckBox sendReportsCheckbox = (CheckBox) rootView.findViewById(R.id.tutorial_crash_report_checkbox); final CrashReportManager crashReportManager = new CrashReportManager(getActivity()); sendReportsCheckbox.setChecked(crashReportManager.isReportsEnabled()); sendReportsCheckbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean willSendReports = sendReportsCheckbox.isChecked(); crashReportManager.setReportsEnabled(willSendReports); } }); return rootView; }
From source file:cz.imakers.android.divky.SettingsActivity.java
@SuppressWarnings("deprecation") @Override/*from w w w . j ava 2 s . c o m*/ protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); addPreferencesFromResource(R.xml.preferences); Preference restore = findPreference("pref_restore"); Preference about = findPreference("pref_about"); restore.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { AlertDialog.Builder builder = new AlertDialog.Builder(preference.getContext()); builder.setTitle(R.string.restore_title).setMessage(R.string.restore_info) .setIcon(android.R.drawable.ic_dialog_info).setNegativeButton(android.R.string.cancel, null) .setPositiveButton(android.R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { DownloadQueue.getInstance().needRestore = true; dialog.dismiss(); onBackPressed(); } }); builder.create().show(); return true; } }); // Get app version PackageManager pm = getPackageManager(); String packageName = getPackageName(); String versionName; try { PackageInfo info = pm.getPackageInfo(packageName, 0); versionName = info.versionName; } catch (PackageManager.NameNotFoundException e) { versionName = "N/A"; e.printStackTrace(); } about.setSummary(getResources().getString(R.string.app_name) + " ver. " + versionName); about.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { AlertDialog.Builder builder = new AlertDialog.Builder(preference.getContext()); WebView webView = new WebView(preference.getContext()); webView.loadUrl("file:///android_asset/LICENSE.html"); builder.setView(webView).setTitle(R.string.about).setIcon(android.R.drawable.ic_dialog_info) .setNeutralButton(android.R.string.ok, null).create().show(); return true; } }); }