Example usage for android.webkit URLUtil isValidUrl

List of usage examples for android.webkit URLUtil isValidUrl

Introduction

In this page you can find the example usage for android.webkit URLUtil isValidUrl.

Prototype

public static boolean isValidUrl(String url) 

Source Link

Usage

From source file:fr.s13d.photobackup.preferences.PBPreferenceFragment.java

private boolean validatePreferences() {
    String serverUrl = preferences.getString(PBServerPreferenceFragment.PREF_SERVER_URL, "");
    if (!URLUtil.isValidUrl(serverUrl) || serverUrl.isEmpty()) {
        Toast.makeText(getActivity(), R.string.toast_urisyntaxexception, Toast.LENGTH_LONG).show();
        return false;
    }/*from  w  w w .  j a  v  a 2s  . c o  m*/

    String serverPassHash = preferences.getString(PBServerPreferenceFragment.PREF_SERVER_PASS_HASH, "");
    if (serverPassHash.isEmpty()) {
        Toast.makeText(getActivity(), R.string.toast_serverpassempty, Toast.LENGTH_LONG).show();
        return false;
    }

    return true;
}

From source file:com.none.tom.simplerssreader.opml.OPMLParser.java

private static String validateUrl(final XmlPullParser parser, final String element, final int mode)
        throws OPMLParserException {
    final String url = StringEscapeUtils.unescapeXml(parser.getAttributeValue(null, element));

    if (!TextUtils.isEmpty(url)) {
        if (!URLUtil.isValidUrl(url)) {
            throw new OPMLParserException(parser);
        }//  w w  w  .j  a  v a  2 s .c om
    }

    return url;
}

From source file:com.dm.wallpaper.board.activities.WallpaperBoardActivity.java

private void initNavigationViewHeader() {
    String imageUrl = getResources().getString(R.string.navigation_view_header);
    String titleText = getResources().getString(R.string.navigation_view_header_title);
    View header = mNavigationView.getHeaderView(0);
    HeaderView image = ButterKnife.findById(header, R.id.header_image);
    LinearLayout container = ButterKnife.findById(header, R.id.header_title_container);
    TextView title = ButterKnife.findById(header, R.id.header_title);
    TextView version = ButterKnife.findById(header, R.id.header_version);

    Point point = getNavigationViewHeaderStyle(getResources().getString(R.string.navigation_view_header_style));
    image.setRatio(point.x, point.y);/*w  ww  . ja va2  s. c  o  m*/

    if (titleText.length() == 0) {
        container.setVisibility(View.GONE);
    } else {
        title.setText(titleText);
        try {
            String versionText = "v" + getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
            version.setText(versionText);
        } catch (Exception ignored) {
        }
    }

    if (ColorHelper.isValidColor(imageUrl)) {
        image.setBackgroundColor(Color.parseColor(imageUrl));
        return;
    }

    if (!URLUtil.isValidUrl(imageUrl)) {
        imageUrl = "drawable://" + DrawableHelper.getResourceId(this, imageUrl);
    }

    ImageLoader.getInstance().displayImage(imageUrl, new ImageViewAware(image),
            ImageConfig.getDefaultImageOptions(), new ImageSize(720, 720), null, null);
}

From source file:org.dvbviewer.controller.ui.fragments.ChannelEpg.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    if (getUserVisibleHint()) {
        super.onCreateContextMenu(menu, v, menuInfo);
        getActivity().getMenuInflater().inflate(R.menu.context_menu_epg, menu);
        MenuItem switchItem = menu.findItem(R.id.menuSwitch)
                .setVisible(URLUtil.isValidUrl(ServerConsts.DVBVIEWER_URL));
        switchItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {

            @Override/* w ww. ja va  2  s . c  om*/
            public boolean onMenuItemClick(MenuItem item) {
                if (getUserVisibleHint()) {
                    String switchRequest = ServerConsts.URL_SWITCH_COMMAND + mCHannel.getPosition();
                    DVBViewerCommand command = new DVBViewerCommand(switchRequest);
                    Thread exexuterTHread = new Thread(command);
                    exexuterTHread.start();
                    return true;
                }
                return false;
            }
        });
        /**
         * Damn Hack for Tablets, onContextItemSelected is not called,
         * But the Dialog appears...
         */
        if (UIUtils.isTablet(getActivity())) {
            menu.findItem(R.id.menuTimer).setOnMenuItemClickListener(new OnMenuItemClickListener() {

                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    if (getUserVisibleHint()) {
                        Cursor c = mAdapter.getCursor();
                        c.moveToPosition(selectedPosition);
                        Timer timer = cursorToTimer(c);
                        TimerDetails timerdetails = TimerDetails.newInstance();
                        Bundle args = new Bundle();
                        args.putString(TimerDetails.EXTRA_TITLE, timer.getTitle());
                        args.putString(TimerDetails.EXTRA_CHANNEL_NAME, timer.getChannelName());
                        args.putLong(TimerDetails.EXTRA_CHANNEL_ID, timer.getChannelId());
                        args.putLong(TimerDetails.EXTRA_START, timer.getStart().getTime());
                        args.putLong(TimerDetails.EXTRA_END, timer.getEnd().getTime());
                        timerdetails.setArguments(args);
                        timerdetails.show(getSherlockActivity().getSupportFragmentManager(),
                                TimerDetails.class.getName());
                        return true;
                    }
                    return false;
                }
            });
        }
    }
}

From source file:org.dvbviewer.controller.ui.fragments.ChannelList.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    getActivity().getMenuInflater().inflate(R.menu.context_menu_channellist, menu);
    menu.findItem(R.id.menuSwitch).setVisible(URLUtil.isValidUrl(ServerConsts.DVBVIEWER_URL));
}

From source file:de.electricdynamite.pasty.ClipboardFragment.java

@SuppressLint("NewApi")
public boolean onContextItemSelected(android.view.MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int menuItemIndex = item.getItemId();
    ClipboardItem Item = mItems.get(info.position);
    switch (menuItemIndex) {
    case PastySharedStatics.ITEM_CONTEXTMENU_COPY_ID:
        // Copy without exit selected
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSherlockActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            Item.copyToClipboard(clipboard);
            clipboard = null;// w w  w .  ja  v  a  2s.  c  om
        } else {
            ClipboardManager clipboard = (ClipboardManager) getSherlockActivity()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            Item.copyToClipboard(clipboard);
            clipboard = null;
        }
        Toast.makeText(getSherlockActivity().getApplicationContext(), getString(R.string.item_copied),
                Toast.LENGTH_LONG).show();

        break;
    case PastySharedStatics.ITEM_CONTEXTMENU_SHARE_ID:
        // Share to another app
        Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, Item.getText());
        startActivity(Intent.createChooser(shareIntent, getString(R.string.app_share_from_pasty)));
        break;
    case PastySharedStatics.ITEM_CONTEXTMENU_DELETE_ID:
        // Delete selected
        mAdapter.delete(info.position);
        break;
    case PastySharedStatics.ITEM_CONTEXTMENU_OPEN_ID:
        /* If the clicked item was originally linkified, we
        * fire an ACTION_VIEW intent.
        */
        String url = Item.getText();
        if (!URLUtil.isValidUrl(url))
            url = "http://" + url;
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
        break;
    }
    return true;
}

From source file:com.dm.material.dashboard.candybar.activities.CandyBarMainActivity.java

private void initNavigationViewHeader() {
    String imageUrl = getResources().getString(R.string.navigation_view_header);
    String titleText = getResources().getString(R.string.navigation_view_header_title);
    View header = mNavigationView.getHeaderView(0);
    ImageView image = (ImageView) header.findViewById(R.id.header_image);
    LinearLayout container = (LinearLayout) header.findViewById(R.id.header_title_container);
    TextView title = (TextView) header.findViewById(R.id.header_title);
    TextView version = (TextView) header.findViewById(R.id.header_version);

    if (titleText.length() == 0) {
        container.setVisibility(View.GONE);
    } else {/*  ww w .j  a v  a2  s .c o  m*/
        title.setText(titleText);
        try {
            String versionText = "v" + getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
            version.setText(versionText);
        } catch (Exception ignored) {
        }
    }

    if (ColorHelper.isValidColor(imageUrl)) {
        image.setBackgroundColor(Color.parseColor(imageUrl));
        return;
    }

    if (!URLUtil.isValidUrl(imageUrl)) {
        imageUrl = "drawable://" + DrawableHelper.getResourceId(this, imageUrl);
    }

    ImageLoader.getInstance().displayImage(imageUrl, new ImageViewAware(image),
            ImageConfig.getDefaultImageOptions(true), new ImageSize(720, 720), null, null);
}

From source file:de.vanita5.twittnuker.fragment.support.StatusFragment.java

@Override
public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
    final int start = mTextView.getSelectionStart(), end = mTextView.getSelectionEnd();
    final SpannableString string = SpannableString.valueOf(mTextView.getText());
    final URLSpan[] spans = string.getSpans(start, end, URLSpan.class);
    final boolean avail = spans != null && spans.length == 1 && URLUtil.isValidUrl(spans[0].getURL());
    Utils.setMenuItemAvailability(menu, android.R.id.copyUrl, avail);
    return false;
}

From source file:self.philbrown.droidQuery.AjaxOptions.java

/**
 * Construct with JSON string. To support versions 0.1.0-0.1.3, this method can also accept a URL.
 * @param json JSON options//from  ww w  .  ja  v a  2 s .  c om
 * @throws JSONException 
 */
public AjaxOptions(String json) throws JSONException {
    this();
    if (URLUtil.isValidUrl(json)) {
        this.url = json;
    } else {
        handleJSONOptions(new JSONObject(json));
    }
}

From source file:com.inmobi.rendering.RenderView.java

public void m1962c(String str, String str2, String str3) {
    if (str3 == null || (str3.startsWith("http") && !URLUtil.isValidUrl(str3))) {
        Logger.m1744a(InternalLogLevel.INTERNAL, f1748a, str + " called with invalid url (" + str3 + ")");
        m1949a(str2, "Invalid URL", str);
    } else if (!str3.startsWith("http") || str3.contains("play.google.com")
            || str3.contains("market.android.com") || str3.contains("market%3A%2F%2F")) {
        m1956b(str, str2, str3);//  w  ww  .  j av  a  2  s.c o m
    } else {
        m1939w();
        InMobiAdActivity.m1893b(this);
        Intent intent = new Intent(getContext(), InMobiAdActivity.class);
        intent.putExtra("com.inmobi.rendering.InMobiAdActivity.EXTRA_AD_ACTIVITY_TYPE", 100);
        if (!(getContext() instanceof Activity)) {
            intent.setFlags(268435456);
        }
        intent.putExtra("com.inmobi.rendering.InMobiAdActivity.IN_APP_BROWSER_URL", str3);
        getContext().startActivity(intent);
        m1946a(str2, "broadcastEvent('" + str + "Successful','" + str3 + "');");
    }
}