本文整理汇总了Java中android.webkit.URLUtil.isValidUrl方法的典型用法代码示例。如果您正苦于以下问题:Java URLUtil.isValidUrl方法的具体用法?Java URLUtil.isValidUrl怎么用?Java URLUtil.isValidUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.webkit.URLUtil
的用法示例。
在下文中一共展示了URLUtil.isValidUrl方法的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: 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());
}
}
示例4: 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);
}
示例5: 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;
}
示例6: 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());
}
}
示例7: 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;
}
}
示例8: saveMediaItem
import android.webkit.URLUtil; //导入方法依赖的package包/类
private boolean saveMediaItem() {
if (etMediaName.getText().toString().length() < MIN_TITLE_LENGTH) {
Toast.makeText(getActivity(), getString(R.string.title_too_short), Toast.LENGTH_SHORT).show();
return false;
} else if (!URLUtil.isValidUrl(etMediaUrl.getText().toString())) {
Toast.makeText(getActivity(), getString(R.string.url_not_correct), Toast.LENGTH_SHORT).show();
return false;
}
if (mediaItemType == MediaItemType.RADIO) {
StreamUrl streamUrl = new StreamUrl(etMediaUrl.getText().toString());
RadioItem radioItem = new RadioItem(etMediaName.getText().toString(), streamUrl, "");
ProfileManager.getInstance().addSubscribedMediaItem(radioItem);
Toast.makeText(getActivity(), getString(R.string.radio_added), Toast.LENGTH_SHORT).show();
} else if (mediaItemType == MediaItemType.PODCAST) {
Podcast podcast = new Podcast(etMediaName.getText().toString(), etMediaUrl.getText().toString());
ProfileManager.getInstance().addSubscribedMediaItem(podcast);
Toast.makeText(getActivity(), getString(R.string.podcast_added), Toast.LENGTH_SHORT).show();
}
return true;
}
示例9: setRedditItem
import android.webkit.URLUtil; //导入方法依赖的package包/类
public void setRedditItem(RedditItem redditItem, Picasso picasso) {
title.setText(redditItem.title);
description.setText(redditItem.selftext);
upVotes.setText(String.format("%s", redditItem.score));
subreddit.setText(redditItem.subreddit);
if (redditItem.selftext != null) {
description.setVisibility(View.VISIBLE);
description.setText(redditItem.selftext);
} else {
description.setVisibility(View.GONE);
}
if (URLUtil.isValidUrl(redditItem.thumbnail)) {
postImage.setVisibility(View.VISIBLE);
picasso.load(redditItem.thumbnail)
.centerCrop().placeholder(R.drawable.ic_image).fit().into(postImage);
} else {
postImage.setVisibility(View.GONE);
}
}
示例10: getBitmapFromImgUrlSync
import android.webkit.URLUtil; //导入方法依赖的package包/类
/**
* Synchronously download image and return its bitmap
*
* @param imgUrl - url of image
* @return bitmap of downloaded image or null
*/
@WorkerThread
public static @Nullable
Bitmap getBitmapFromImgUrlSync(@Nullable String imgUrl) {
if (!URLUtil.isValidUrl(imgUrl)) {
return null;
}
Bitmap bitmap = null;
try {
bitmap = PICASSO
.load(imgUrl)
.get();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
示例11: doInBackground
import android.webkit.URLUtil; //导入方法依赖的package包/类
protected String doInBackground(Void... args) {
String url = start_url;
int ttl = max_ttl;
int type = NONE;
if ( url != null && url.length() != 0 && URLUtil.isValidUrl(url) ) {
type = playlistType(url);
} else {
url = null;
}
if (url != null && type != NONE ) {
ttl -= 1;
url = selectUrlFromPlaylist(url,type);
}
if (ttl == 0)
url = null;
return url;
}
示例12: chooseUrl
import android.webkit.URLUtil; //导入方法依赖的package包/类
private String chooseUrl() {
// Handle intents
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action) && type != null) {
if (URLUtil.isValidUrl(intent.getStringExtra(Intent.EXTRA_TEXT))) {
try {
Log.v(Helpers.LogTag, "Shared URL Intent");
return "https://mbasic.facebook.com/composer/?text=" + URLEncoder.encode(intent.getStringExtra(Intent.EXTRA_TEXT), "utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
} else if (Intent.ACTION_VIEW.equals(action) && intent.getData() != null && URLUtil.isValidUrl(intent.getData().toString())) {
// If there is a intent containing a facebook link, go there
Log.v(Helpers.LogTag, "Opened URL Intent");
return intent.getData().toString();
}
// If nothing has happened at this point, we want the default url
return FACEBOOK_URL_BASE;
}
示例13: addUrlSchemeIfNeeded
import android.webkit.URLUtil; //导入方法依赖的package包/类
/**
* Add scheme prefix to an URL. This method must be called on all user entered or server fetched URLs to ensure
* http client will work as expected.
*
* @param url url entered by the user or fetched from a server
* @param isHTTPS true will make the url starts with https;//
* @return transformed url prefixed by its http;// or https;// scheme
*/
public static String addUrlSchemeIfNeeded(String url, boolean isHTTPS) {
if (url == null) {
return null;
}
// Remove leading double slash (eg. //example.com), needed for some wporg instances configured to
// switch between http or https
url = removeLeadingDoubleSlash(url, (isHTTPS ? "https" : "http") + "://");
if (!URLUtil.isValidUrl(url)) {
if (!(url.toLowerCase().startsWith("http://")) && !(url.toLowerCase().startsWith("https://"))) {
url = (isHTTPS ? "https" : "http") + "://" + url;
}
}
return url;
}
示例14: setURL
import android.webkit.URLUtil; //导入方法依赖的package包/类
public void setURL(String url, String username) throws URLInvalid
{
// check whether the URL is valid... otherwise there is no use going on....
if (!URLUtil.isValidUrl(url) || !URLUtil.isHttpUrl(url))
{
throw new URLInvalid(url);
}
if (this.url.contentEquals(url) && this.username.contentEquals(username) && !username.isEmpty())
{
return;
}
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(url)
.setClient(new HueConnectionClient())
//.setLogLevel(RestAdapter.LogLevel.FULL)
.build();
hueRestInterface = restAdapter.create(HueRestInterface.class);
this.url = url;
connectionGood = false;
lights = null;
this.username = username;
isConnected = false;
}
示例15: openWebPage
import android.webkit.URLUtil; //导入方法依赖的package包/类
public static void openWebPage(MainActivity activity, String URL) {
if (URLUtil.isValidUrl(URL)) {
if (PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("use_custom_tabs", true)) {
activity.tabsHelper.openURL(activity, URL);
} else {
Uri webPage = Uri.parse(URL);
Intent intent = new Intent(Intent.ACTION_VIEW, webPage);
PackageManager packageManager = activity.getPackageManager();
List activities = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
if (activities.size() > 0) {
activity.startActivity(intent);
}
}
}
}