Esempio n. 1
0
 public static InputStream replaceHost(InputStream is, String srcUrl, String dstUrl) {
   if (is == null || !URLUtil.isValidUrl(srcUrl) || !URLUtil.isValidUrl(dstUrl)) {
     return null;
   }
   String srcHost = Uri.parse(srcUrl).getHost();
   Log.d("longer", "src:" + srcHost);
   String dstHost = Uri.parse(dstUrl).getHost();
   Log.d("longer", "dst:" + dstHost);
   BufferedReader br = new BufferedReader(new InputStreamReader(is));
   StringBuilder sb = new StringBuilder();
   String t;
   try {
     while ((t = br.readLine()) != null) {
       if (t.contains(srcHost)) {
         sb.append(t.replace(srcHost, dstHost)).append("\r\n");
       } else {
         sb.append(t).append("\r\n");
       }
     }
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     try {
       br.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   Log.d("longer", sb.toString());
   return new ByteArrayInputStream(sb.toString().getBytes());
 }
  private boolean IsFormValid() {
    CheckBoxPreference chkEnabled = (CheckBoxPreference) findPreference("opengts_enabled");
    EditTextPreference txtOpenGTSServer = (EditTextPreference) findPreference("opengts_server");
    EditTextPreference txtOpenGTSServerPort =
        (EditTextPreference) findPreference("opengts_server_port");
    ListPreference txtOpenGTSCommunicationMethod =
        (ListPreference) findPreference("opengts_server_communication_method");
    EditTextPreference txtOpenGTSServerPath =
        (EditTextPreference) findPreference("autoopengts_server_path");
    EditTextPreference txtOpenGTSDeviceId =
        (EditTextPreference) findPreference("opengts_device_id");

    return !chkEnabled.isChecked()
        || txtOpenGTSServer.getText() != null
            && txtOpenGTSServer.getText().length() > 0
            && txtOpenGTSServerPort.getText() != null
            && isNumeric(txtOpenGTSServerPort.getText())
            && txtOpenGTSCommunicationMethod.getValue() != null
            && txtOpenGTSCommunicationMethod.getValue().length() > 0
            && txtOpenGTSDeviceId.getText() != null
            && txtOpenGTSDeviceId.getText().length() > 0
            && URLUtil.isValidUrl(
                "http://"
                    + txtOpenGTSServer.getText()
                    + ":"
                    + txtOpenGTSServerPort.getText()
                    + txtOpenGTSServerPath.getText());
  }
Esempio n. 3
0
 /**
  * 根据服务器给过来的url启动Activity
  *
  * @param context
  * @param url
  */
 public static void startActivity(Context context, String url) {
   if (!TextUtils.isEmpty(url)) {
     Intent intent;
     if (url.contains(SCHEME)) {
       // 跳转内部页面
       // 事件统计
       String event = Uri.parse(url).getQueryParameter("event");
       if (!TextUtils.isEmpty(event)) {
         //                    UmengClickAgent.onEvent(context, event);
       }
       intent = SchemeUtil.getIntent(context, url);
     } else {
       if (URLUtil.isValidUrl(url)) {
         intent =
             new Intent(
                 SystemUtil.getApplicationPackageName(context) + BaseConstant.ACTION_WEB_VIEW);
         intent.putExtra(WebViewFragment.EXTRA_URL, url);
       } else {
         intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
       }
     }
     if (!(context instanceof Activity)) {
       intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     }
     try {
       context.startActivity(intent);
     } catch (ActivityNotFoundException e) { // // TODO: 跳转到首页
       //                context.startActivity(new Intent(Intent.ACTION_VIEW,
       // Uri.parse(getUri(context, R.string.path_main))));
       //                context.startActivity(new
       // Intent(SystemUtil.getApplicationPackageName(context) + BaseConstant.ACTION_MAIN));
       //                LogUtils.e("bacy->" + e);
     }
   }
 }
Esempio n. 4
0
    public String getFileName() {
      if (fileName == null) {
        // 设置默认的文件名
        // eg.http://example.com/a/b/c.png
        // -->目录/a/b/c.png
        // eg.http://example.com/a/b/c
        // -->目录/a/b/c.png
        if (URLUtil.isValidUrl(url)) {
          URL encodeUrl = null;
          try {
            encodeUrl = new URL(url);
          } catch (MalformedURLException e) {
            e.printStackTrace();
          }
          String path = encodeUrl.getPath();
          Log.e(TAG, "url path is " + path);
          if (path != null && !path.equals("")) {
            // 判断后缀是否有.png
            int dotPos = path.lastIndexOf(".");
            if (dotPos != -1) {

              String suffix = path.substring(dotPos);
              if (!suffix.equals(".png")) {
                path += ".png";
              }
            } else {
              path += ".png";
            }
          }
          fileName = path;
        }
      }
      return fileName;
    }
Esempio n. 5
0
 /**
  * Construct with JSON string. To support versions 0.1.0-0.1.3, this method can also accept a URL.
  *
  * @param json JSON options
  * @throws JSONException
  */
 public AjaxOptions(String json) throws JSONException {
   this();
   if (URLUtil.isValidUrl(json)) {
     this.url = json;
   } else {
     handleJSONOptions(new JSONObject(json));
   }
 }
Esempio n. 6
0
  /** Upgrading device firmware over the air (OTA). */
  public void upgradeFirmware(boolean isStatusCheck) {
    Log.i(TAG, "An upgrade has been requested");
    Context context = this.getApplicationContext();
    Preference.putBoolean(
        context,
        context.getResources().getString(R.string.firmware_status_check_in_progress),
        isStatusCheck);
    Preference.putString(
        context,
        context.getResources().getString(R.string.firmware_download_progress),
        String.valueOf(DEFAULT_STATE_INFO_CODE));
    Preference.putInt(
        context, context.getResources().getString(R.string.operation_id), operationId);

    String schedule = null;
    String server;
    if (command != null && !command.trim().isEmpty()) {
      try {
        JSONObject upgradeData = new JSONObject(command);
        if (!upgradeData.isNull(context.getResources().getString(R.string.alarm_schedule))) {
          schedule =
              (String) upgradeData.get(context.getResources().getString(R.string.alarm_schedule));
        }

        if (!upgradeData.isNull(context.getResources().getString(R.string.firmware_server))) {
          server =
              (String) upgradeData.get(context.getResources().getString(R.string.firmware_server));
          if (URLUtil.isValidUrl(server)) {
            Preference.putString(
                context, context.getResources().getString(R.string.firmware_server), server);
          }
        }
      } catch (JSONException e) {
        Log.e(TAG, "Firmware upgrade payload parsing failed." + e);
      }
    }
    if (schedule != null && !schedule.trim().isEmpty()) {
      Log.i(TAG, "Upgrade has been scheduled to " + schedule);
      Preference.putString(
          context, context.getResources().getString(R.string.alarm_schedule), schedule);
      try {
        AlarmUtils.setOneTimeAlarm(context, schedule, Constants.Operation.UPGRADE_FIRMWARE, null);
      } catch (ParseException e) {
        Log.e(TAG, "One time alarm time string parsing failed." + e);
      }
    } else {
      if (isStatusCheck) {
        Log.i(TAG, "Firmware status check is initiated by admin.");
      } else {
        Log.i(TAG, "Upgrade request initiated by admin.");
      }
      // Prepare for upgrade
      OTADownload otaDownload = new OTADownload(context);
      otaDownload.startOTA();
    }
  }
Esempio n. 7
0
 public static String getFileNameFromURL(String url) {
   String fileNameWithExtension = null;
   String fileNameWithoutExtension = null;
   if (URLUtil.isValidUrl(url)) {
     fileNameWithExtension = URLUtil.guessFileName(url, null, null);
     if (fileNameWithExtension != null && !fileNameWithExtension.isEmpty()) {
       String[] f = fileNameWithExtension.split(".");
       if (f != null & f.length > 1) {
         fileNameWithoutExtension = f[0];
       }
     }
   }
   return fileNameWithExtension;
 }
Esempio n. 8
0
  public void doNav() {

    String url = urlField.getText().toString();

    if (URLUtil.isValidUrl(url) == false) {
      url = "http://" + url;
    }

    urlField.setText(url);

    webView.requestFocus();

    webView.loadUrl(url);

    navbar.startAnimation(slideUp);
  }
  // Attempts to retrieve the xmlrpc url for a self-hosted site, in this order:
  // 1: Try to retrieve it by finding the ?rsd url in the site's header
  // 2: Take whatever URL the user entered to see if that returns a correct response
  // 3: Finally, just guess as to what the xmlrpc url should be
  private String getSelfHostedXmlrpcUrl(String url) {
    String xmlrpcUrl;

    // Convert IDN names to punycode if necessary
    url = UrlUtils.convertUrlToPunycodeIfNeeded(url);

    // Add http to the beginning of the URL if needed
    url = UrlUtils.addUrlSchemeIfNeeded(url, false);

    if (!URLUtil.isValidUrl(url)) {
      mErrorMsgId = org.wordpress.android.R.string.invalid_url_message;
      return null;
    }

    // Attempt to get the XMLRPC URL via RSD
    String rsdUrl;
    try {
      rsdUrl = UrlUtils.addUrlSchemeIfNeeded(getRsdUrl(url), false);
    } catch (SSLHandshakeException e) {
      if (!UrlUtils.getDomainFromUrl(url).endsWith("wordpress.com")) {
        mErroneousSslCertificate = true;
      }
      AppLog.w(T.NUX, "SSLHandshakeException failed. Erroneous SSL certificate detected.");
      return null;
    }

    try {
      if (rsdUrl != null) {
        xmlrpcUrl = UrlUtils.addUrlSchemeIfNeeded(ApiHelper.getXMLRPCUrl(rsdUrl), false);
        if (xmlrpcUrl == null) {
          xmlrpcUrl = UrlUtils.addUrlSchemeIfNeeded(rsdUrl.replace("?rsd", ""), false);
        }
      } else {
        xmlrpcUrl = UrlUtils.addUrlSchemeIfNeeded(getXmlrpcByUserEnteredPath(url), false);
      }
    } catch (SSLHandshakeException e) {
      if (!UrlUtils.getDomainFromUrl(url).endsWith("wordpress.com")) {
        mErroneousSslCertificate = true;
      }
      AppLog.w(T.NUX, "SSLHandshakeException failed. Erroneous SSL certificate detected.");
      return null;
    }

    return xmlrpcUrl;
  }
  private String findFirstUrl(@Nullable CharSequence text) {
    if (text == null) {
      return null;
    }

    final Matcher matcher =
        Pattern.compile(
                "\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))",
                Pattern.CASE_INSENSITIVE)
            .matcher(text);
    while (matcher.find()) {
      final String url = matcher.group();
      if (URLUtil.isValidUrl(url)) {
        return url;
      }
    }
    return null;
  }
 public void playAudioImpl(Bundle bundle, Activity activity) {
   PlayerProperties playerProperties =
       (PlayerProperties) bundle.getParcelable(IMWebView.PLAYER_PROPERTIES);
   String string = bundle.getString(IMWebView.EXPAND_URL);
   if (string == null) {
     string = AdTrackerConstants.BLANK;
   }
   if (!a(playerProperties.id, string, activity)) {
     return;
   }
   if ((string.length() != 0 && !URLUtil.isValidUrl(string))
       || (string.length() == 0 && !this.audioPlayerList.containsKey(playerProperties.id))) {
     this.a.raiseError("Request must specify a valid URL", "playAudio");
   } else if (this.audioplayer != null) {
     if (string.length() != 0) {
       this.audioplayer.setPlayData(playerProperties, string);
     }
     this.audioPlayerList.put(playerProperties.id, this.audioplayer);
     FrameLayout frameLayout = (FrameLayout) activity.findViewById(16908290);
     if (playerProperties.isFullScreen()) {
       LayoutParams layoutParams =
           new RelativeLayout.LayoutParams(
               WrapperFunctions.getParamFillParent(), WrapperFunctions.getParamFillParent());
       layoutParams.addRule(R.styleable.MapAttrs_zOrderOnTop);
       this.audioplayer.setLayoutParams(layoutParams);
       View relativeLayout = new RelativeLayout(activity);
       relativeLayout.setOnTouchListener(new g());
       relativeLayout.setBackgroundColor(-16777216);
       frameLayout.addView(
           relativeLayout,
           new RelativeLayout.LayoutParams(
               WrapperFunctions.getParamFillParent(), WrapperFunctions.getParamFillParent()));
       relativeLayout.addView(this.audioplayer);
       this.audioplayer.setBackGroundLayout(relativeLayout);
       this.audioplayer.requestFocus();
       this.audioplayer.setOnKeyListener(new c());
     } else {
       this.audioplayer.setLayoutParams(new LayoutParams(1, 1));
       frameLayout.addView(this.audioplayer);
     }
     this.audioplayer.setListener(new a(playerProperties));
     this.audioplayer.play();
   }
 }
 private boolean a(String str, String str2, Activity activity, Dimensions dimensions) {
   if (this.videoPlayer == null || !str.equalsIgnoreCase(this.videoPlayer.getPropertyID())) {
     return b(str, str2, activity);
   }
   playerState state = this.videoPlayer.getState();
   if (str.equalsIgnoreCase(this.videoPlayer.getPropertyID())) {
     String mediaURL = this.videoPlayer.getMediaURL();
     if (str2.length() == 0 || str2.equalsIgnoreCase(mediaURL)) {
       switch (d.a[state.ordinal()]) {
         case GoogleScorer.CLIENT_GAMES:
           this.videoPlayer.start();
           a(this.videoPlayer, dimensions);
           return false;
         case GoogleScorer.CLIENT_PLUS:
           a(this.videoPlayer, dimensions);
           return false;
         case IabHelper.BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE:
           if (!this.videoPlayer.getProperties().doLoop()) {
             this.videoPlayer.start();
           }
           a(this.videoPlayer, dimensions);
           return false;
         case GoogleScorer.CLIENT_APPSTATE:
           if (this.videoPlayer.isPrepared()) {
             this.videoPlayer.start();
           } else {
             this.videoPlayer.setAutoPlay(true);
           }
           a(this.videoPlayer, dimensions);
           return false;
         default:
           return false;
       }
     } else if (URLUtil.isValidUrl(str2)) {
       this.videoPlayer.releasePlayer(false);
       this.videoPlayer = new AVPlayer(activity, this.a);
     } else {
       this.a.raiseError("Request must specify a valid URL", "playVideo");
       return false;
     }
   }
   return true;
 }
 private boolean b(String str, String str2, Activity activity) {
   if ((str2.length() == 0 || URLUtil.isValidUrl(str2))
       && (str2.length() != 0 || this.videoPlayerList.containsKey(str))) {
     if (this.videoPlayer != null) {
       this.videoPlayer.hide();
       this.videoPlayerList.put(this.videoPlayer.getPropertyID(), this.videoPlayer);
     }
     AVPlayer a = a(str);
     if (a == null) {
       this.videoPlayer = new AVPlayer(activity, this.a);
     } else {
       this.videoPlayer = a;
     }
     if (str2.length() == 0) {
       this.videoPlayer.setPlayData(a.getProperties(), a.getMediaURL());
       this.videoPlayer.setPlayDimensions(a.getPlayDimensions());
     }
     this.videoPlayerList.remove(str);
     return true;
   } else {
     this.a.raiseError("Request must specify a valid URL", "playVideo");
     return false;
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see
  * android.support.v4.app.Fragment#onCreateContextMenu(android.view.ContextMenu
  * , android.view.View, android.view.ContextMenu.ContextMenuInfo)
  */
 @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));
 }