本文整理汇总了Java中android.webkit.URLUtil类的典型用法代码示例。如果您正苦于以下问题:Java URLUtil类的具体用法?Java URLUtil怎么用?Java URLUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
URLUtil类属于android.webkit包,在下文中一共展示了URLUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: startServiceConfig
import android.webkit.URLUtil; //导入依赖的package包/类
private void startServiceConfig() {
Log.i(TAG, "Starting service config");
String discoveryEndpoint = app.getString(R.string.discovery_endpoint);
if (discoveryEndpoint.trim().length() == 0 || !URLUtil.isValidUrl(discoveryEndpoint)) {
Log.i(TAG, "Using static service config");
AuthorizationServiceConfiguration serviceConfig =
new AuthorizationServiceConfiguration(
Uri.parse(app.getString(R.string.authorization_endpoint)),
Uri.parse(app.getString(R.string.token_endpoint)));
authState = new AuthState(serviceConfig);
userInfoUrl = app.getString(R.string.user_info_endpoint);
finishServiceConfig();
} else {
Log.i(TAG, "Using discovery service config");
Uri discoveryUri = Uri.parse(discoveryEndpoint);
loginListener.onEvent(AuthRepo.this, AUTH_SERVICE_DISCOVERY_START);
AuthorizationServiceConfiguration.fetchFromUrl(discoveryUri, this::finishServiceDiscovery);
}
}
示例2: createPlayer
import android.webkit.URLUtil; //导入依赖的package包/类
private void createPlayer() {
releasePlayer();
String videoLink = UniversalPlayer.getInstance().getPlayingMediaItem().getAudeoLink();
try {
Logger.printInfo(TAG, "Trying to play video: " + videoLink);
ArrayList<String> options = new ArrayList<String>();
options.add("--aout=opensles");
options.add("--audio-time-stretch"); // time stretching
options.add("-vvv"); // verbosity
libvlc = new LibVLC(options);
shVideoHolder.setKeepScreenOn(true);
// Create media player
mMediaPlayer = new MediaPlayer(libvlc);
mMediaPlayer.setEventListener(this);
// Set up video output
final IVLCVout vout = mMediaPlayer.getVLCVout();
vout.setVideoView(sfVideo);
vout.addCallback(this);
vout.attachViews();
Media m = URLUtil.isValidUrl(videoLink) ? new Media(libvlc, Uri.parse(videoLink)) : new Media(libvlc, videoLink);
mMediaPlayer.setMedia(m);
mMediaPlayer.play();
} catch (Exception e) {
Logger.printInfo(TAG, "Error creating video player: ");
e.printStackTrace();
if (onPlayingFailedCallback != null) {
onPlayingFailedCallback.operationFinished();
}
}
}
示例3: downloadFile
import android.webkit.URLUtil; //导入依赖的package包/类
@AfterPermissionGranted(WRITE_EXTERNAL_REQUEST_CODE)
public void downloadFile(String url, String userAgent, String contentDisposition, String mimetype) {
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimetype);
cookieManager = CookieManager.getInstance();
PersistentConfig persistentConfig = new PersistentConfig(activity.getApplicationContext());
persistentConfig.setCookie(getCookies(Session.getSession(activity.getApplicationContext())));
cookieManager.setCookie(host, persistentConfig.getCookieString());
request.addRequestHeader("Cookie", getCookies(Session.getSession(activity.getApplicationContext())));
request.setDescription("Downloading file...");
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
String fileName = URLUtil.guessFileName(url, contentDisposition, mimetype);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, fileName);
DownloadManager dManager = (DownloadManager) getActivity().getSystemService(DOWNLOAD_SERVICE);
dManager.enqueue(request);
}
示例4: onDownloadStart
import android.webkit.URLUtil; //导入依赖的package包/类
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
listener.onDownloadStart();
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
request.setMimeType(mimetype);
//------------------------COOKIE!!------------------------
CookieManager.getInstance().setCookie(url, getCookie());
String cookiesAlt = CookieManager.getInstance().getCookie(url);
request.addRequestHeader(Constant.COOKIE, cookiesAlt);
//------------------------COOKIE!!------------------------
request.addRequestHeader(Constant.USER_AGENT, userAgent);
request.setDescription(activity.getString(R.string.downloading_file));
request.setTitle(URLUtil.guessFileName(url, contentDisposition, mimetype));
request.allowScanningByMediaScanner();
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, URLUtil.guessFileName(url, contentDisposition, mimetype));
DownloadManager dm = (DownloadManager) activity.getSystemService(activity.DOWNLOAD_SERVICE);
try {
dm.enqueue(request);
activity.showToast(R.string.downloading_file);
} catch (Exception e) {
activity.showToast(R.string.download_failed);
}
}
示例5: fetch
import android.webkit.URLUtil; //导入依赖的package包/类
/**
* 获取多个图片,并在全部完成的时候回调
*
* @param context
* @param urls
* @param callback
*/
public static void fetch(final Context context, final LuaResourceFinder finder, final String[] urls, final LoadCallback callback) {
if (context != null && urls != null && urls.length > 0) {
final AtomicInteger count = new AtomicInteger(urls.length);
final Map<String, Drawable> result = new HashMap<String, Drawable>();
for (final String url : urls) {
if (URLUtil.isNetworkUrl(url)) {//network
final ImageProvider imageProvider = LuaView.getImageProvider();
if (imageProvider != null) {
imageProvider.preload(context, url, new DrawableLoadCallback() {
@Override
public void onLoadResult(Drawable drawable) {
result.put(url, drawable);
callCallback(count, callback, result);
}
});
}
} else {//TODO 优化成异步
if (finder != null) {
result.put(url, finder.findDrawable(url));
callCallback(count, callback, result);
}
}
}
}
}
示例6: onClick
import android.webkit.URLUtil; //导入依赖的package包/类
@Override
public void onClick(View view){
if(view.getId()==R.id.notification_extra_info_tv){
String url = notifications.get(getAdapterPosition()).getExtraUrl();
if(URLUtil.isValidUrl(url)) {
Utils.openLinkInCustomTab(context, url);
}
} else {
if(descTv.getVisibility()==View.GONE){
expandView();
}
else collapseView();
notifyViewToggle(getAdapterPosition());
}
}
示例7: display
import android.webkit.URLUtil; //导入依赖的package包/类
public void display(SimpleDraweeView view, String url, Postprocessor postprocessor) {
if (!TextUtils.isEmpty(url)) {
Uri uri;
if (URLUtil.isNetworkUrl(url)) {
uri = Uri.parse(url);
} else {
uri = Uri.fromFile(new File(url));
}
ImageRequest request = ImageRequestBuilder
.newBuilderWithSource(uri)
.setPostprocessor(postprocessor)
.setProgressiveRenderingEnabled(true)
//.setResizeOptions(new ResizeOptions(100, 100))
.setLocalThumbnailPreviewsEnabled(true)
.setRotationOptions(RotationOptions.autoRotateAtRenderTime())
.build();
controller = Fresco.newDraweeControllerBuilder()
.setImageRequest(request)
.setOldController(view.getController())
.build();
view.setController(controller);
}
}
示例8: onOptionsItemSelected
import android.webkit.URLUtil; //导入依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.layout_example:
Intent i = new Intent(this, ExampleListActivity.class);
startActivity(i);
break;
case R.id.about:
Intent ii = new Intent(this, TestActivity.class);
startActivity(ii);
break;
case R.id.main_in_webview:
String url = mSearch.getText().toString();
if (URLUtil.isValidUrl(url)) {
Intent intent = new Intent(this, WebViewActivity.class);
intent.putExtra(EXTAL_URL, url);
startActivity(intent);
} else {
Toast.makeText(this, "not valid url", Toast.LENGTH_LONG).show();
}
break;
}
return super.onOptionsItemSelected(item);
}
示例9: handleUrlLoading
import android.webkit.URLUtil; //导入依赖的package包/类
private boolean handleUrlLoading(WebView view, String url) {
Log.d(TAG, "handleUrlLoading() called with: " + " url = [" + url + "]");
if (!(view instanceof PagerWebView)) {
return false;
}
if (url.equals(view.getUrl())) {
Log.d(TAG, "handleUrlLoading() is same as old url let webview process it " + url);
return false;
}
mLastRequestTime = System.currentTimeMillis();
// Log.d(TAG, "**getUrl() " + view.getUrl());
// Log.d(TAG, "**getOriginalUrl() " + view.getOriginalUrl());
// Log.d(TAG, "**url " + url);
if (URLUtil.isHttpUrl(url) || URLUtil.isHttpsUrl(url)) {
if (!isUserClick(view)) {
Log.d(TAG, "handleUrlLoading checkIfRedirectRequest is true processed by webview.");
return false;
}
Log.d(TAG, "handleUrlLoading process by pager, create new page.");
pager.loadUrl(url);
return true;
}
return false;
}
示例10: validateUrl
import android.webkit.URLUtil; //导入依赖的package包/类
private boolean validateUrl(String url) {
if (URLUtil.isHttpsUrl(url) || URLUtil.isHttpUrl(url)) {
return true;
}
new AlertDialog.Builder(this)
.setTitle(getText(R.string.invalid_url_title))
.setMessage(getString(R.string.invalid_url_text, url))
.setCancelable(false)
.setNeutralButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.create()
.show();
return false;
}
示例11: validateUrl
import android.webkit.URLUtil; //导入依赖的package包/类
private boolean validateUrl(String url) {
if (URLUtil.isHttpsUrl(url) || URLUtil.isHttpUrl(url)) {
return true;
}
new AlertDialog.Builder(this)
.setTitle(getText(R.string.invalid_url_title))
.setMessage(getString(R.string.invalid_url_text, url))
.setCancelable(false)
.setNeutralButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
.create()
.show();
return false;
}
示例12: checkURL
import android.webkit.URLUtil; //导入依赖的package包/类
public static boolean checkURL(CharSequence input) {
if (TextUtils.isEmpty(input)) {
return false;
}
Pattern URL_PATTERN = Patterns.WEB_URL;
boolean isURL = URL_PATTERN.matcher(input).matches();
if (!isURL) {
String urlString = input + "";
if (URLUtil.isNetworkUrl(urlString)) {
try {
new URL(urlString);
isURL = true;
} catch (Exception e) {
}
}
}
return isURL;
}
示例13: configHasRequiredFields
import android.webkit.URLUtil; //导入依赖的package包/类
public static boolean configHasRequiredFields(LEServiceConfiguration leServiceConfiguration) throws LEServiceException {
boolean result = true;
try {
if (leServiceConfiguration.captureFlowLocale.isEmpty()) result = false;
if (leServiceConfiguration.captureClientId.isEmpty()) result = false;
if (leServiceConfiguration.captureApplicationId.isEmpty()) result = false;
if (leServiceConfiguration.captureFlowVersion.isEmpty()) result = false;
if (leServiceConfiguration.captureFlowName.isEmpty()) result = false;
if (leServiceConfiguration.policyCheckerStage.isEmpty()) result = false;
if (leServiceConfiguration.policyCheckerTenant.isEmpty()) result = false;
if (!URLUtil.isValidUrl(leServiceConfiguration.policyCheckerHost)) result = false;
}catch (Exception ex){
result = false;
}
if(!result) throw new LEServiceException("Invalid LEServiceConfiguration Detected");
return result;
}
示例14: onBindViewHolder
import android.webkit.URLUtil; //导入依赖的package包/类
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder.getItemViewType() == TYPE_HEADER) {
HeaderViewHolder headerViewHolder = (HeaderViewHolder) holder;
String imageUri = mContext.getString(R.string.about_image);
if (ColorHelper.isValidColor(imageUri)) {
headerViewHolder.image.setBackgroundColor(Color.parseColor(imageUri));
} else if (!URLUtil.isValidUrl(imageUri)) {
imageUri = "drawable://" + DrawableHelper.getResourceId(mContext, imageUri);
ImageLoader.getInstance().displayImage(imageUri, headerViewHolder.image,
ImageConfig.getDefaultImageOptions());
} else {
ImageLoader.getInstance().displayImage(imageUri, headerViewHolder.image,
ImageConfig.getDefaultImageOptions());
}
String profileUri = mContext.getResources().getString(R.string.about_profile_image);
if (!URLUtil.isValidUrl(profileUri)) {
profileUri = "drawable://" + DrawableHelper.getResourceId(mContext, profileUri);
}
ImageLoader.getInstance().displayImage(profileUri, headerViewHolder.profile,
ImageConfig.getDefaultImageOptions());
}
}
示例15: onClick
import android.webkit.URLUtil; //导入依赖的package包/类
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_host_add:
if (editUrl.getText().toString().length() > 0 &&
editName.getText().toString().length() > 0 &&
editLogin.getText().toString().length() > 0) {
if (URLUtil.isValidUrl(editUrl.getText().toString())) {
performAdd();
} else {
Toast.makeText(this, getString(R.string.url_invalid),
Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, getString(R.string.fill_fields),
Toast.LENGTH_SHORT).show();
}
break;
}
}