Java Code Examples for android.webkit.URLUtil

The following examples show how to use android.webkit.URLUtil. These examples are extracted from open source projects. 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 Project: AntennaPodSP   Source File: DownloadRequester.java    License: MIT License 6 votes vote down vote up
public String getMediafilename(FeedMedia media) {
    String filename;
    String titleBaseFilename = "";

    // Try to generate the filename by the item title
    if (media.getItem() != null && media.getItem().getTitle() != null) {
        String title = media.getItem().getTitle();
        // Delete reserved characters
        titleBaseFilename = title.replaceAll("[\\\\/%\\?\\*:|<>\"\\p{Cntrl}]", "");
        titleBaseFilename = titleBaseFilename.trim();
    }

    String URLBaseFilename = URLUtil.guessFileName(media.getDownload_url(),
            null, media.getMime_type());
    ;

    if (titleBaseFilename != "") {
        // Append extension
        filename = titleBaseFilename + FilenameUtils.EXTENSION_SEPARATOR +
                FilenameUtils.getExtension(URLBaseFilename);
    } else {
        // Fall back on URL file name
        filename = URLBaseFilename;
    }
    return filename;
}
 
Example 2
Source Project: Ninja   Source File: NinjaDownloadListener.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onDownloadStart(final String url, String userAgent, final String contentDisposition, final String mimeType, long contentLength) {
    final Context holder = IntentUnit.getContext();
    if (holder == null || !(holder instanceof Activity)) {
        BrowserUnit.download(context, url, contentDisposition, mimeType);
        return;
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(holder);
    builder.setCancelable(false);

    builder.setTitle(R.string.dialog_title_download);
    builder.setMessage(URLUtil.guessFileName(url, contentDisposition, mimeType));

    builder.setPositiveButton(R.string.dialog_button_positive, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            BrowserUnit.download(holder, url, contentDisposition, mimeType);
        }
    });

    builder.setNegativeButton(R.string.dialog_button_negative, null);
    builder.create().show();
}
 
Example 3
Source Project: JumpGo   Source File: GeneralSettingsFragment.java    License: Mozilla Public License 2.0 6 votes vote down vote up
private void homePicker() {
    String currentHomepage;
    mHomepage = mPreferenceManager.getHomepage();
    if (!URLUtil.isAboutUrl(mHomepage)) {
        currentHomepage = mHomepage;
    } else {
        currentHomepage = "https://www.google.com";
    }

    BrowserDialog.showEditText(mActivity,
        R.string.title_custom_homepage,
        R.string.title_custom_homepage,
        currentHomepage,
        R.string.action_ok,
        new BrowserDialog.EditorListener() {
            @Override
            public void onClick(String text) {
                mPreferenceManager.setHomepage(text);
                home.setSummary(text);
            }
        });
}
 
Example 4
Source Project: FirefoxReality   Source File: WindowViewModel.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void onChanged(ObservableBoolean o) {
    String aUrl = url.getValue().toString();
    isUrlBarButtonsVisible.postValue(new ObservableBoolean(
            !isFocused.getValue().get() &&
                    !isLibraryVisible.getValue().get() &&
                    !UrlUtils.isContentFeed(getApplication(), aUrl) &&
                    !UrlUtils.isPrivateAboutPage(getApplication(), aUrl) &&
                    (URLUtil.isHttpUrl(aUrl) || URLUtil.isHttpsUrl(aUrl)) &&
                    (
                            (SettingsStore.getInstance(getApplication()).getTrackingProtectionLevel() != ContentBlocking.EtpLevel.NONE) ||
                            isPopUpAvailable.getValue().get() ||
                            isDrmUsed.getValue().get() ||
                            isWebXRUsed.getValue().get()
                    )
    ));
}
 
Example 5
Source Project: NewFastFrame   Source File: QQVideoDetailPresenter.java    License: Apache License 2.0 6 votes vote down vote up
private Observable<String> getDetailDataForTwo(String url) {
    return Observable.just(url).subscribeOn(Schedulers.io())
            .flatMap(new Function<String, ObservableSource<String>>() {
                @Override
                public ObservableSource<String> apply(String s) throws Exception {
                    StringBuilder stringBuilder = new StringBuilder("http://all.baiyug.cn:2021/QQQ/index.php").append("?url=")
                            .append(s);
                    Document document = Jsoup.connect(stringBuilder.toString()).header("Referer", "http://app.baiyug.cn").get();
                    String content = document.outerHtml();
                    String start = "url:";
                    int startIndex = content.indexOf(start);
                    String end = "pic: pic";
                    String url1 = content.substring(startIndex + start.length(), content.lastIndexOf(end)).trim();
                    String realUrl = url1.substring(1, url1.length() - 2);
                    if (URLUtil.isValidUrl(realUrl)) {
                        return Observable.just(realUrl);
                    } else {
                        return getDetailDataForThree(url);
                    }
                }
            });
}
 
Example 6
Source Project: NewFastFrame   Source File: QQVideoDetailPresenter.java    License: Apache License 2.0 6 votes vote down vote up
public Observable<String> getDetailDataForFour(String url) {
    return Observable.just(url).subscribeOn(Schedulers.io())
            .flatMap((Function<String, ObservableSource<String>>) s -> {
                StringBuilder stringBuilder = new StringBuilder("http://all.baiyug.cn:2021/QQ/index.php").append("?url=")
                        .append(s);
                Document document = Jsoup.connect(stringBuilder.toString()).header("Referer", "http://app.baiyug.cn").get();
                String content = document.outerHtml();
                String start = "url:";
                int startIndex = content.indexOf(start);
                String end = "pic: pic";
                String url1 = content.substring(startIndex + start.length(), content.lastIndexOf(end)).trim();
                String realUrl = url1.substring(1, url1.length() - 2);
                if (URLUtil.isValidUrl(realUrl)) {
                    return Observable.just(realUrl);
                } else {
                    return getDetailDataForThree(url);
                }
            });
}
 
Example 7
Source Project: EFRConnect-android   Source File: UriBeacon.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates the Uri string with embedded expansion codes.
 *
 * @param uri to be encoded
 * @return the Uri string with expansion codes.
 */
public static byte[] encodeUri(String uri) {
    if (uri.length() == 0) {
        return new byte[0];
    }
    ByteBuffer bb = ByteBuffer.allocate(uri.length());
    // UUIDs are ordered as byte array, which means most significant first
    bb.order(ByteOrder.BIG_ENDIAN);
    int position = 0;

    // Add the byte code for the scheme or return null if none
    Byte schemeCode = encodeUriScheme(uri);
    if (schemeCode == null) {
        return null;
    }
    String scheme = URI_SCHEMES.get(schemeCode);
    bb.put(schemeCode);
    position += scheme.length();

    if (URLUtil.isNetworkUrl(scheme)) {
        return encodeUrl(uri, position, bb);
    } else if ("urn:uuid:".equals(scheme)) {
        return encodeUrnUuid(uri, position, bb);
    }
    return null;
}
 
Example 8
Source Project: travelguide   Source File: ArticleInfoDetailFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
  if (URLUtil.isNetworkUrl(url))
  {
    final Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    if (getActivity().getPackageManager().resolveActivity(i, 0) != null)
      startActivity(i);

    return true;
  }
  else if (url.startsWith("mapswithme://"))
  {
    final PendingIntent pi = ArticleInfoListActivity.createPendingIntent(getActivity());

    // TODO: Decided to use 11 as default scale, but MapsWithMe has bug with scales,
    // so do pass 13 as a compromise.
    MapsWithMeApi.showMapsWithMeUrl(getActivity(), pi, 13, url);

    return true;
  }

  return super.shouldOverrideUrlLoading(view, url);
}
 
Example 9
Source Project: travelguide   Source File: ArticleInfoDetailFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon)
{
  super.onPageStarted(view, url, favicon);

  // Fix java.lang.NullPointerException at:
  // android.view.animation.AnimationUtils.loadAnimation(AnimationUtils.java:71)
  final Context context = getActivity();
  if (shouldAnimate(url, context))
  {
    Utils.fadeOut(context, mWebView);
    Utils.fadeIn(context, mProgressContainer);
  }

  if (URLUtil.isFileUrl(url) && url.endsWith(".html"))
  {
    final String strippedUrl = url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.'));
    mTitle.setText(getStorage().getArticleInfoByUrl(strippedUrl).getName());
  }
}
 
Example 10
Source Project: edx-app-android   Source File: WebViewDiscoverFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setWebViewActionListener();
    // Check for search query in extras
    String searchQueryExtra = null;
    String searchUrl = null;

    if (savedInstanceState != null) {
        searchUrl = savedInstanceState.getString(INSTANCE_CURRENT_DISCOVER_URL, null);
    }
    if (searchUrl == null && getArguments() != null) {
        searchQueryExtra = getArguments().getString(Router.EXTRA_SEARCH_QUERY);
    }

    if (searchQueryExtra != null) {
        initSearch(searchQueryExtra);
    } else {
        loadUrl(searchUrl == null || !URLUtil.isValidUrl(searchUrl) ? getInitialUrl() : searchUrl);
    }
    if (!EventBus.getDefault().isRegistered(this)) {
        EventBus.getDefault().register(this);
    }
}
 
Example 11
Source Project: HtmlNative   Source File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 12
Source Project: wallpaperboard   Source File: AboutAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@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());
    }
}
 
Example 13
Source Project: Xndroid   Source File: LightningWebClient.java    License: GNU General Public License v3.0 6 votes vote down vote up
private boolean shouldOverrideLoading(@NonNull WebView view, @NonNull String url) {
    // Check if configured proxy is available
    if (!mProxyUtils.isProxyReady(mActivity)) {
        // User has been notified
        return true;
    }

    Map<String, String> headers = mLightningView.getRequestHeaders();

    if (mLightningView.isIncognito()) {
        // If we are in incognito, immediately load, we don't want the url to leave the app
        return continueLoadingUrl(view, url, headers);
    }
    if (URLUtil.isAboutUrl(url)) {
        // If this is an about page, immediately load, we don't need to leave the app
        return continueLoadingUrl(view, url, headers);
    }

    if (isMailOrIntent(url, view) || mIntentUtils.startActivityForUrl(view, url)) {
        // If it was a mailto: link, or an intent, or could be launched elsewhere, do that
        return true;
    }

    // If none of the special conditions was met, continue with loading the url
    return continueLoadingUrl(view, url, headers);
}
 
Example 14
private void homePicker() {
    String currentHomepage;
    mHomepage = mPreferenceManager.getHomepage();
    if (!URLUtil.isAboutUrl(mHomepage)) {
        currentHomepage = mHomepage;
    } else {
        currentHomepage = "https://www.google.com";
    }

    BrowserDialog.showEditText(mActivity,
        R.string.title_custom_homepage,
        R.string.title_custom_homepage,
        currentHomepage,
        R.string.action_ok,
        new BrowserDialog.EditorListener() {
            @Override
            public void onClick(String text) {
                mPreferenceManager.setHomepage(text);
                home.setSummary(text);
            }
        });
}
 
Example 15
public static String decodeUri(final byte[] serviceData, final int start, final int length) {
    if (start < 0 || serviceData.length < start + length)
        return null;

    final StringBuilder uriBuilder = new StringBuilder();
    int offset = 0;
    if (offset < length) {
        byte b = serviceData[start + offset++];
        String scheme = URI_SCHEMES.get(b);
        if (scheme != null) {
            uriBuilder.append(scheme);
            if (URLUtil.isNetworkUrl(scheme)) {
                return decodeUrl(serviceData, start + offset, length - 1, uriBuilder);
            } else if ("urn:uuid:".equals(scheme)) {
                return decodeUrnUuid(serviceData, start + offset, uriBuilder);
            }
        }
        Log.w(TAG, "decodeUri unknown Uri scheme code=" + b);
    }
    return null;
}
 
Example 16
Source Project: uPods-android   Source File: DialogFragmentAddMediaItem.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 17
Source Project: android-sdk   Source File: ActionFactory.java    License: MIT License 6 votes vote down vote up
/**
 * Gets URL parameter from JSON and validates it.
 *
 * @param jsonElement - JsonElement that contains the url string.
 * @param messageType - Message type.
 * @return - Returns the verified URI string. If not valid or empty will return an empty string.
 */
public static String getUriFromJson(JsonElement jsonElement, int messageType) {
    String urlToCheck = jsonElement == null || jsonElement.isJsonNull() ? "" : jsonElement.getAsString();
    String returnUrl = "";

    //we allow deep links for in app actions and URL messages; we enforce valid network URLs
    // for the visit website action
    if ((messageType == ServerType.IN_APP && validatedUrl(urlToCheck))
            || (messageType == ServerType.URL_MESSAGE && validatedUrl(urlToCheck))
            || URLUtil.isNetworkUrl(urlToCheck)) {
        returnUrl = urlToCheck;
    }

    if (returnUrl.isEmpty()) {
        Logger.log.logError("URL is invalid, please change in the campaign settings.");
    }

    return returnUrl;
}
 
Example 18
Source Project: Yahala-Messenger   Source File: ConnectActivity.java    License: MIT License 6 votes vote down vote up
private boolean validateUrl(String url) {
     if (URLUtil.isHttpsUrl(url) || URLUtil.isHttpUrl(url)) {
         return true;
     }
     FileLog.e(TAG + ": " + getText(R.string.invalid_url_title), getString(R.string.invalid_url_text, url));
/* 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;
 }
 
Example 19
Source Project: Yahala-Messenger   Source File: WebRtcPhone.java    License: MIT License 6 votes vote down vote up
private boolean validateUrl(String url) {

        if (URLUtil.isHttpsUrl(url) || URLUtil.isHttpUrl(url)) {
            return true;
        }

        FileLog.e(TAG + ": " + ApplicationLoader.applicationContext.getText(R.string.invalid_url_title), ApplicationLoader.applicationContext.getString(R.string.invalid_url_text, url));

        /* 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;
    }
 
Example 20
Source Project: candybar   Source File: OtherAppsAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
    ViewHolder holder;
    if (view == null) {
        view = View.inflate(mContext, R.layout.fragment_other_apps_item_list, null);
        holder = new ViewHolder(view);
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    CandyBarApplication.OtherApp otherApp = mOtherApps.get(position);
    String uri = otherApp.getIcon();
    if (!URLUtil.isValidUrl(uri)) {
        uri = "drawable://" + DrawableHelper.getResourceId(mContext, uri);
    }

    ImageLoader.getInstance().displayImage(
            uri, holder.image, ImageConfig.getDefaultImageOptions(true));
    holder.title.setText(otherApp.getTitle());

    if (otherApp.getDescription() == null || otherApp.getDescription().length() == 0) {
        holder.desc.setVisibility(View.GONE);
    } else {
        holder.desc.setText(otherApp.getDescription());
        holder.desc.setVisibility(View.VISIBLE);
    }

    holder.container.setOnClickListener(v -> {
        if (!URLUtil.isValidUrl(otherApp.getUrl())) return;

        try {
            mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(otherApp.getUrl())));
        } catch (ActivityNotFoundException e) {
            LogUtil.e(Log.getStackTraceString(e));
        }
    });
    return view;
}
 
Example 21
Source Project: candybar   Source File: CreditsAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
    ViewHolder holder;
    if (view == null) {
        view = View.inflate(mContext, R.layout.fragment_credits_item_list, null);
        holder = new ViewHolder(view);
        view.setTag(holder);
    } else {
        holder = (ViewHolder) view.getTag();
    }

    Credit credit = mCredits.get(position);
    holder.title.setText(credit.getName());
    holder.subtitle.setText(credit.getContribution());
    holder.container.setOnClickListener(view1 -> {
        String link = credit.getLink();
        if (URLUtil.isValidUrl(link)) {
            try {
                mContext.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
            } catch (ActivityNotFoundException e) {
                LogUtil.e(Log.getStackTraceString(e));
            }
        }
    });

    if (credit.getContribution().length() == 0) {
        holder.subtitle.setVisibility(View.GONE);
    } else {
        holder.subtitle.setVisibility(View.VISIBLE);
    }

    ImageLoader.getInstance().displayImage(credit.getImage(),
            new ImageViewAware(holder.image), mOptions.build(),
            new ImageSize(144, 144), null, null);
    return view;
}
 
Example 22
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.activity_download_from_url, container, false);
    context = getActivity();
    download = view.findViewById(R.id.download);
    edt_url = view.findViewById(R.id.edt_url);
    adContainer = view.findViewById(R.id.adContainer);
    open_instagram = view.findViewById(R.id.open_instagram);
    showBannerAd();
    download.setOnClickListener(v -> {

        if (TextUtils.isEmpty(edt_url.getText().toString())) {
            ToastUtils.ErrorToast(context, "Url field can't be empty");
        } else if (!URLUtil.isValidUrl(edt_url.getText().toString())) {
            ToastUtils.ErrorToast(context, "Url is not valid url");
        } else if (checkURL(edt_url.getText().toString())) {
            new ValidateFileFromURL().execute(edt_url.getText().toString());
        } else {
            ToastUtils.ErrorToast(context, "Url is not valid url");
        }


    });

    open_instagram.setOnClickListener(v -> {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://www.instagram.com/"));
        startActivity(intent);

    });

    return view;
}
 
Example 23
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.activity_download_igtv_from_url, container, false);


    download = view.findViewById(R.id.download);
    url = view.findViewById(R.id.edt_url);
    adContainer = view.findViewById(R.id.adContainer);
    open_instagram = view.findViewById(R.id.open_instagram);
    showBannerAd();
    download.setOnClickListener(v -> {

        if (TextUtils.isEmpty(url.getText().toString())) {
            ToastUtils.ErrorToast(context, "Url field can't be empty");
        } else if (!URLUtil.isValidUrl(url.getText().toString())) {
            ToastUtils.ErrorToast(context, "Url is not valid url");
        } else if (checkURL(url.getText().toString())) {

            new ValidateFileFromURL().execute(url.getText().toString());
        } else {
            ToastUtils.ErrorToast(context, "Url is not valid url");
        }


    });

    open_instagram.setOnClickListener(v -> {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("https://www.instagram.com/explore/tags/igtv/"));
        startActivity(intent);

    });


    return view;
}
 
Example 24
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_download_from_url);
    context = this;
    download = findViewById(R.id.download);
    url = findViewById(R.id.edt_url);



    download.setOnClickListener(v -> {

        if (TextUtils.isEmpty(url.getText().toString())) {
            ToastUtils.ErrorToast(context, "Url field can't be empty");
        } else if (URLUtil.isValidUrl(url.getText().toString())) {
            ToastUtils.ErrorToast(context, "Url is not valid url");
        } else if (URLUtil.isFileUrl(url.getText().toString())) {
            String _url = url.getText().toString();
            if (_url.endsWith(".jpg")) {
                new saveImage(_url).execute();
            } else {
                new saveVideo(_url).execute(new String[0]);
            }
        }


    });


}
 
Example 25
@Override
protected void onCreate(Bundle savedInstanceState) {
    setContentView(R.layout.activity_update);
    super.onCreate(savedInstanceState);

    // Get default user.
    user = new Accounts(this).getDefaultUser();

    layout = findViewById(R.id.update_root);
    url = findViewById(R.id.url);
    postStatus = findViewById(R.id.postStatus);
    title = findViewById(R.id.title);
    body = findViewById(R.id.body);

    // Set listener.
    VolleyRequestListener(this);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {

        String status = extras.getString("status");
        if (status != null && status.equals("draft")) {
            postStatus.setChecked(false);
        }

        String urlToUpdate = extras.getString("url");
        if (urlToUpdate != null && urlToUpdate.length() > 0) {
            if (URLUtil.isValidUrl(urlToUpdate)) {
                url.setText(urlToUpdate);
                getPostFromServer(urlToUpdate);
            }
        }

    }
}
 
Example 26
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case RequestCode.SELECT_JSON_FILE:
                selectedFilePath = data.getData();
                rlJsonUp.setVisibility(View.GONE);
                rlJsonPath.setVisibility(View.VISIBLE);
                tlJsonPwd.setVisibility(View.VISIBLE);
                if (selectedFilePath != null) {
                    btnRestore.setEnabled(true);
                    String fileName = URLUtil.guessFileName(selectedFilePath.getLastPathSegment(), null, null);
                    tvJsonPath.setText(fileName);
                } else {
                    Toast.makeText(getApplicationContext(), getString(R.string.restore_backup_wrong_file_name), Toast.LENGTH_LONG).show();
                }
                break;
            case RequestCode.QR_CODE_REQUEST_CODE:
                String result = data.getStringExtra(Extras.QR_CODE_RESULT);
                if (!result.isEmpty()) {
                    String address = filterAddress(result);
                    etBackupPhrase.setText(address);
                }
                break;
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example 27
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case RequestCode.SELECT_JSON_FILE:
                selectedFilePath = data.getData();
                rlJsonUp.setVisibility(View.GONE);
                rlJsonPath.setVisibility(View.VISIBLE);
                tlJsonPwd.setVisibility(View.VISIBLE);
                if (selectedFilePath != null) {
                    btnRestore.setEnabled(true);
                    String fileName = URLUtil.guessFileName(selectedFilePath.getLastPathSegment(), null, null);
                    tvJsonPath.setText(fileName);
                } else {
                    Toast.makeText(getApplicationContext(), getString(R.string.restore_backup_wrong_file_name), Toast.LENGTH_LONG).show();
                }
                break;
            case RequestCode.QR_CODE_REQUEST_CODE:
                String result = data.getStringExtra(Extras.QR_CODE_RESULT);
                if (!result.isEmpty()) {
                    String address = filterAddress(result);
                    etBackupPhrase.setText(address);
                }
                break;
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example 28
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    if (resultCode == RESULT_OK) {
        switch (requestCode) {
            case RequestCode.SELECT_JSON_FILE:
                selectedFilePath = data.getData();
                rlJsonUp.setVisibility(View.GONE);
                rlJsonPath.setVisibility(View.VISIBLE);
                tlJsonPwd.setVisibility(View.VISIBLE);
                if (selectedFilePath != null) {
                    btnRestore.setEnabled(true);
                    String fileName = URLUtil.guessFileName(selectedFilePath.getLastPathSegment(), null, null);
                    tvJsonPath.setText(fileName);
                } else {
                    Toast.makeText(getApplicationContext(), getString(R.string.restore_backup_wrong_file_name), Toast.LENGTH_LONG).show();
                }
                break;
            case RequestCode.QR_CODE_REQUEST_CODE:
                String result = data.getStringExtra(Extras.QR_CODE_RESULT);
                if (!result.isEmpty()) {
                    String address = filterAddress(result);
                    etBackupPhrase.setText(address);
                }
                break;
        }
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example 29
Source Project: 365browser   Source File: DataReductionProxySettings.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * If the given URL is a WebLite URL and should be overridden because the Data
 * Reduction Proxy is on, the user is in the Lo-Fi previews experiment, and the scheme of the
 * lite_url param is HTTP, returns the URL contained in the lite_url param. Otherwise returns
 * the given URL.
 *
 * @param url The URL to evaluate.
 * @return The URL to be used. Returns null if the URL param is null.
 */
public String maybeRewriteWebliteUrl(String url) {
    if (url == null || !URLUtil.isValidUrl(url) || !areLoFiPreviewsEnabled()
            || !isDataReductionProxyEnabled()) {
        return url;
    }
    String rewritten = extractUrlFromWebliteQueryParams(url);
    if (rewritten == null
            || !TextUtils.equals(Uri.parse(rewritten).getScheme(),
                    UrlConstants.HTTP_SCHEME)) {
        return url;
    }

    return rewritten;
}
 
Example 30
/**
 * loads a custom url from the url bar
 * @param v
 * @param actionId
 * @return
 */
@OnEditorAction(R.id.website_input)
boolean onEditorAction(TextView v, int actionId){

    if (URLUtil.isValidUrl(v.getText().toString()))
        webView.loadUrl(v.getText().toString());
    else
        Toast.makeText(getActivity(),getString(R.string.web_error_toast), Toast.LENGTH_SHORT).show();
    Util.hideKeyboard(websiteInput, getActivity());
    return true;
}