@Override
  public void onResume() {
    super.onResume();
    Intent intent = getIntent();
    String scheme = intent.getScheme();
    OAuth savedToken = getOAuthToken();
    if (CALLBACK_SCHEME.equals(scheme) && (savedToken == null || savedToken.getUser() == null)) {
      Uri uri = intent.getData();
      String query = uri.getQuery();
      logger.debug("Returned Query: {}", query); // $NON-NLS-1$
      String[] data = query.split("&"); // $NON-NLS-1$
      if (data != null && data.length == 2) {
        String oauthToken = data[0].substring(data[0].indexOf("=") + 1); // $NON-NLS-1$
        String oauthVerifier = data[1].substring(data[1].indexOf("=") + 1); // $NON-NLS-1$
        logger.debug(
            "OAuth Token: {}; OAuth Verifier: {}", oauthToken, oauthVerifier); // $NON-NLS-1$

        OAuth oauth = getOAuthToken();
        if (oauth != null
            && oauth.getToken() != null
            && oauth.getToken().getOauthTokenSecret() != null) {
          GetOAuthTokenTask task = new GetOAuthTokenTask(this);
          task.execute(oauthToken, oauth.getToken().getOauthTokenSecret(), oauthVerifier);
        }
      }
    }
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    context = this;

    setContentView(R.layout.main);

    editText = (EditText) findViewById(R.id.input);
    editTextTitlePost = null;
    editTextDescriptionPost = null;

    /** --- From ShareVia Intent */
    if (getIntent().getExtras() != null) {
      String shareVia = (String) getIntent().getExtras().get(Intent.EXTRA_TEXT);
      if (shareVia != null) {
        editText.setText(shareVia);
      }
    }
    if (getIntent().getAction() == Intent.ACTION_VIEW) {
      Uri data = getIntent().getData();
      String scheme = data.getScheme();
      String host = data.getHost();
      List<String> params = data.getPathSegments();
      String builded = scheme + "://" + host + "/";

      for (String string : params) {
        builded += string + "/";
      }

      if (data.getQuery() != null && !data.getQuery().equals("")) {
        builded = builded.substring(0, builded.length() - 1);
        builded += "?" + data.getQuery();
      }

      System.out.println(builded);

      editText.setText(builded);
    }
    /** --- */
    submitButton = (Button) findViewById(R.id.action_go);
    randomButton = (Button) findViewById(R.id.random);
    postButton = (Button) findViewById(R.id.post);

    previewAreaTitle = (TextView) findViewById(R.id.preview_area);
    postAreaTitle = (TextView) findViewById(R.id.post_area);

    /** Where the previews will be dropped */
    dropPreview = (ViewGroup) findViewById(R.id.drop_preview);

    /** Where the previews will be dropped */
    dropPost = (ViewGroup) findViewById(R.id.drop_post);

    textCrawler = new TextCrawler();

    initSubmitButton();
    initRandomButton();
  }
  private static String createDynamicCall(Uri uri) {
    // Uri is: gxapp://<package-name>/<object-name>?<parameters>
    // TODO: We should also support parameters in extras, in case they are big.
    String objectName = uri.getPath();
    if (objectName != null && objectName.startsWith("/")) objectName = objectName.substring(1);

    if (isValidObject(objectName)) {
      if (Strings.hasValue(uri.getQuery())) return objectName + "?" + uri.getQuery();
      else return objectName;
    } else return null;
  }
 /**
  * Constructs a new UriBuilder from the given Uri.
  *
  * @return a new Uri Builder based off the given Uri.
  */
 public static UriBuilder newInstance(Uri uri) {
   return new UriBuilder()
       .scheme(uri.getScheme())
       .host(uri.getHost())
       .path(uri.getPath())
       .query(uri.getQuery());
 }
 public static void forward(Context context, RouterAction action) {
   // parser uri params
   Uri uri = Uri.parse(action.url);
   queryParames = new UrlParser().parse(uri.getQuery());
   // rule
   RuleProperties ruleProperties = new RuleProperties(XApplication.getInstance());
   ZRuler.createRule(ruleProperties).rule(context, action, action.url, queryParames);
 }
  @Override
  public Cursor query(
      @NonNull Uri uri,
      String[] projection,
      String selection,
      String[] selectionArgs,
      String sortOrder) {
    int match = uriMatcher.match(uri);
    String table;
    String useSelection = selection;
    String[] useSelectionArgs = selectionArgs;
    switch (match) {
      case ALL_ROWS:
        table = uri.getLastPathSegment();
        break;
      case ROW_BY_ID:
        List<String> segments = uri.getPathSegments();
        table = segments.get(TABLE_SEGMENT);
        useSelection = WHERE_MATCHES_ID;
        useSelectionArgs = new String[] {segments.get(ID_SEGMENT)};
        break;
      default:
        throw new UnsupportedOperationException("Unknown uri: " + uri);
    }

    boolean distinct = false;
    String limit = null;

    // If have query parameters, see if any exist interested in.
    if (!TextUtils.isEmpty(uri.getQuery())) {
      distinct = uri.getBooleanQueryParameter(DISTINCT_PARAMETER, false);
      limit = uri.getQueryParameter(LIMIT_PARAMETER);
    }

    SQLiteDatabase db = dbHelper.getReadableDatabase();
    db.acquireReference();

    try {
      Cursor cursor =
          db.query(
              distinct,
              table,
              projection,
              useSelection,
              useSelectionArgs,
              null,
              null,
              sortOrder,
              limit);
      // Register the cursor with the requested URI so the caller will receive
      // future database change notifications. Useful for "loaders" which take advantage
      // of this concept.
      cursor.setNotificationUri(getContext().getContentResolver(), uri);
      return cursor;
    } finally {
      db.releaseReference();
    }
  }
Example #7
0
  private void handleFlickrCallback(Intent intent) {
    Uri uri = intent.getData();
    String query = uri.getQuery();
    String[] data = query.split("&");

    if (data == null || data.length != 2) {
      Log.w(TAG, "Invalid callback query");
      return;
    }

    new OAuthFinishAuthenticationTask().execute(getDataValue(data[0]), getDataValue(data[1]));
  }
 @Override
 public Cursor query(
     Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
   String action = uri.getLastPathSegment();
   String resource = uri.getQuery();
   if (GET_RESOURCE_REQUEST_COUNT.equals(action)) {
     return new ProviderStateCursor(
         mResourceRequestCount.containsKey(resource) ? mResourceRequestCount.get(resource) : 0);
   } else if (RESET_RESOURCE_REQUEST_COUNT.equals(action)) {
     mResourceRequestCount.put(resource, 0);
   }
   return null;
 }
Example #9
0
  /**
   * Get a file path from a Uri.
   *
   * <p>from https://github.com/iPaulPro/aFileChooser/blob/master/aFileChooser/src/com/ipaulpro/
   * afilechooser/utils/FileUtils.java
   *
   * @param context
   * @param uri
   * @return
   * @author paulburke
   */
  public static String getPath(Context context, Uri uri) {

    Log.d(
        Constants.TAG + " File -",
        "Authority: "
            + uri.getAuthority()
            + ", Fragment: "
            + uri.getFragment()
            + ", Port: "
            + uri.getPort()
            + ", Query: "
            + uri.getQuery()
            + ", Scheme: "
            + uri.getScheme()
            + ", Host: "
            + uri.getHost()
            + ", Segments: "
            + uri.getPathSegments().toString());

    if ("content".equalsIgnoreCase(uri.getScheme())) {
      String[] projection = {"_data"};
      Cursor cursor = null;

      try {
        cursor = context.getContentResolver().query(uri, projection, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow("_data");
        if (cursor.moveToFirst()) {
          return cursor.getString(column_index);
        }
      } catch (Exception e) {
        // Eat it
      }
    } else if ("file".equalsIgnoreCase(uri.getScheme())) {
      return uri.getPath();
    }

    return null;
  }
Example #10
0
  private void parseMessage(String message) {
    if (!message.startsWith(JS_BRIDGE_PROTOCOL_SCHEMA)) {
      return;
    }
    // ------->
    // rock://LoginHandler:8888/Add?{msg:'我是小三',data:{userName:'******',passWord:'******'}}
    Uri uri = Uri.parse(message);
    mClassName = uri.getHost();
    mPort = String.valueOf(uri.getPort());

    String path = uri.getPath();
    if (!TextUtils.isEmpty(path)) {
      mMethodName = path.replace("/", "");
    } else {
      mMethodName = "";
    }

    try {
      mParams = new JSONObject(uri.getQuery());
    } catch (JSONException e) {
      e.printStackTrace();
      mParams = new JSONObject();
    }
  }
Example #11
0
    public static final DataSet create(Uri uri) {
      if (!uri.getScheme().equals(SCHEME)) {
        return null;
      }
      if (!uri.getHost().equals(HOST)) {
        return null;
      }
      DataSet data = new DataSet();
      {
        String an = uri.getPath();
        if (SLASH == an.charAt(0)) {
          an = an.substring(1);
        }
        if (SLASH == an.charAt(an.length() - 1)) {
          an = an.substring(0, an.length() - 1);
        }
        data.setActivityName(an);
      }

      final String q = uri.getQuery();
      final int q_l = null != q ? q.length() : -1;
      int q_e = -1;
      while (q_e < q_l) {
        int q_b = q_e + 1; // next term
        q_e = q.indexOf(AMPER, q_b);
        if (0 == q_e) {
          // single seperator
          continue;
        }
        if (0 > q_e) {
          // end
          q_e = q_l;
        }
        // n-part
        final String part = q.substring(q_b, q_e);
        final int assignment = part.indexOf(ASSIG);
        if (0 < assignment) {
          // assignment
          final String k = part.substring(0, assignment);
          final String v = part.substring(assignment + 1);
          if (k.equals(PKG)) {
            if (v.length() == 0) {
              throw new IllegalArgumentException(
                  "Empty package name: part <" + part + ">, query <" + q + "> of " + uri);
            }
            data.addPackage(v);
          } else {
            data.setProperty(k, v);
          }
        } else {
          // property key only
          if (part.equals(PKG)) {
            throw new IllegalArgumentException(
                "Empty package name: part <" + part + ">, query <" + q + "> of " + uri);
          }
          data.setProperty(part, EMPTY);
        }
      }
      data.validate();
      return data;
    }
Example #12
0
 @SuppressLint("NewApi")
 @Override
 public boolean shouldOverrideUrlLoading(WebView view, String url) {
   Activity activity = (Activity) view.getContext();
   if (url.startsWith("tel:")) {
     try {
       Intent intent = new Intent(Intent.ACTION_DIAL);
       intent.setData(Uri.parse(url));
       activity.startActivity(intent);
     } catch (Exception e) {
       e.printStackTrace();
     }
     return true;
   } else if (url.startsWith("geo:")) {
     try {
       Intent intent = new Intent(Intent.ACTION_VIEW);
       intent.setData(Uri.parse(url));
       activity.startActivity(intent);
     } catch (Exception e) {
       e.printStackTrace();
     }
     return true;
   } else if (url.startsWith("mailto:")) {
     try {
       Intent intent = new Intent(Intent.ACTION_VIEW);
       intent.setData(Uri.parse(url));
       activity.startActivity(intent);
     } catch (Exception e) {
       e.printStackTrace();
     }
     return true;
   } else if (url.startsWith("sms:")) {
     try {
       Intent intent = new Intent(Intent.ACTION_VIEW);
       String address = null;
       int parmIndex = url.indexOf('?');
       if (parmIndex == -1) {
         address = url.substring(4);
       } else {
         address = url.substring(4, parmIndex);
         Uri uri = Uri.parse(url);
         String query = uri.getQuery();
         if ((query != null) && (query.startsWith("body="))) {
           intent.putExtra("sms_body", query.substring(5));
         }
       }
       intent.setData(Uri.parse("sms:" + address));
       intent.putExtra("address", address);
       intent.setType("vnd.android-dir/mms-sms");
       activity.startActivity(intent);
     } catch (Exception e) {
       e.printStackTrace();
     }
     return true;
   }
   boolean isUrl = url.startsWith("file") || url.startsWith("http");
   if (!isUrl) {
     return true;
   }
   EBrowserView target = (EBrowserView) view;
   if (target.isObfuscation()) {
     target.updateObfuscationHistroy(url, EBrowserHistory.UPDATE_STEP_ADD, false);
   }
   if (target.shouldOpenInSystem()) {
     Intent intent = new Intent(Intent.ACTION_VIEW);
     intent.setData(Uri.parse(url));
     activity.startActivity(intent);
     return true;
   }
   int sdkVersion = Build.VERSION.SDK_INT;
   if (sdkVersion >= 11) {
     if (url.startsWith("file")) {
       int index = url.indexOf("?");
       if (index > 0) {
         mParms = url.substring(index + 1);
         url = url.substring(0, index);
       }
     }
   }
   String cUrl = view.getOriginalUrl();
   if (null != cUrl && url.startsWith("http") && sdkVersion >= 8) {
     Map<String, String> headers = new HashMap<String, String>();
     headers.put("Referer", cUrl);
     view.loadUrl(url, headers);
   } else {
     view.loadUrl(url);
   }
   return true;
 }
Example #13
0
  String getAdditionInfo(String url) {
    String s = "";
    if (url.contains("bongda")) {
      try {
        HtmlCleaner cleaner = new HtmlCleaner();
        String id = url.substring(url.lastIndexOf("/"));
        id = id.substring(1, id.indexOf("."));
        Uri ss = Uri.parse("http://m.bongdaplus.vn/Story.aspx?sid=" + id);

        URI fine =
            new URI(
                ss.getScheme(),
                ss.getUserInfo(),
                ss.getHost(),
                ss.getPort(),
                ss.getPath(),
                ss.getQuery(),
                ss.getFragment());
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BEST_MATCH);
        HttpGet httpget = new HttpGet(fine);
        httpget.addHeader(
            "user-agent", "Mozilla/5.0 (Linux; U; Android 2.3.3) Gecko/20100101 Firefox/8.0");
        httpget.addHeader("accept-language", "en-us,en;q=0.5");
        HttpResponse response = httpclient.execute(httpget);
        InputStream binaryreader = new BufferedInputStream(response.getEntity().getContent());
        BufferedReader buf = new BufferedReader(new InputStreamReader(binaryreader));
        String sss;
        StringBuilder sb = new StringBuilder();
        while ((sss = buf.readLine()) != null) {
          sb.append(sss);
        }

        //	    		URL u = new URL(ss.getScheme(), ss.getHost(), ss.getPort(), ss.getPath());
        TagNode root = cleaner.clean(sb.toString());
        TagNode div = root.findElementByAttValue("class", "story-body", true, false);
        TagNode[] child = div.getElementsByName("strong", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("class", "listing", true, false);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("ul", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("img", true);
        for (int i = 0; i < child.length; i++)
          child[i].setAttribute("style", "width: 100%; height: auto;");
        s = cleaner.getInnerHtml(div);
        if (s.indexOf("VideoPlaying(") > 0) {
          int x = s.indexOf("VideoPlaying(");
          int st = s.indexOf("'", x);
          int en = s.indexOf("'", st + 1);
          String urlvideo = "http://bongdaplus.vn" + s.substring(st + 1, en);
          s = s + "<a href=\"" + urlvideo + "\"> Video </a></br></br>";
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (url.contains("teamtalk")) {
      try {
        HtmlCleaner cleaner = new HtmlCleaner();
        Uri ss = Uri.parse(url);
        URL u = new URL(ss.getScheme(), ss.getHost(), ss.getPort(), ss.getPath());
        TagNode root = cleaner.clean(u);
        TagNode div = root.findElementByAttValue("class", "tt-article-text", true, false);
        TagNode[] child = div.getElementsByName("p", true);
        for (int i = 0; i < child.length; i++)
          if (child[i].hasAttribute("class") || child[i].hasAttribute("style"))
            child[i].removeFromTree();
        child = div.getElementsByName("img", true);
        for (int i = 0; i < child.length; i++)
          child[i].setAttribute("style", "max-width: 80%; height: auto;");
        s = cleaner.getInnerHtml(div);
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else if (url.contains("licheuro")) {
      try {
        HtmlCleaner cleaner = new HtmlCleaner();
        Uri ss = Uri.parse(url);
        URL u = new URL(ss.getScheme(), ss.getHost(), ss.getPort(), ss.getPath());
        TagNode root = cleaner.clean(u);
        TagNode div = root.findElementByAttValue("class", "entry", true, false);

        TagNode[] child = div.getElementsByName("span", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("strong", true);
        for (int i = 0; i < child.length; i++) {
          child[i].getParent().addChildren(child[i].getChildren());
          child[i].getParent().addChild(child[i].getText());
          child[i].removeFromTree();
        }
        child = div.getElementsByName("h1", true);
        for (int i = 0; i < child.length; i++) {
          child[i].getParent().addChildren(child[i].getChildren());
          child[i].getParent().addChild(child[i].getText());
          child[i].removeFromTree();
        }
        child = div.getElementsByAttValue("class", "boxpost", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("class", "ratingblock ", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("iframe", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("blockqoute", true);
        for (int i = 0; i < child.length; i++) {
          child[i].getParent().addChildren(child[i].getChildren());
          child[i].removeFromTree();
        }

        child = div.getElementsByAttValue("class", "dd_outer", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("id", "fb-root", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("id", "fbSEOComments", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByAttValue("id", "ajax_comments_wrapper", true, true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("table", true);
        for (int i = 0; i < child.length; i++) {
          child[i].setAttribute("style", "max-width: 100%; height: auto;");
          child[i].setAttribute("width", "100%");
        }
        child = div.getElementsByName("script", true);
        for (int i = 0; i < child.length; i++) child[i].removeFromTree();
        child = div.getElementsByName("img", true);
        for (int i = 0; i < child.length; i++)
          child[i].setAttribute("style", "max-width: 80%; height: auto;");
        s = cleaner.getInnerHtml(div);
        if (s.indexOf("\"file\":") > 0) {
          int x = s.indexOf("\"file\":");
          int st = s.indexOf("http", x);
          int en = s.indexOf("\"", st + 1);
          String urlvideo = s.substring(st, en);
          s = s + "<a href=\"" + urlvideo + "\"> Video </a></br></br>";
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    System.out.println(s);
    return s;
  }
 @Override
 public String getType(Uri uri) {
   // If the mimetype is not appended to the uri, then return an empty string
   String mimetype = uri.getQuery();
   return mimetype == null ? "" : mimetype;
 }
Example #15
0
  /**
   * Get a file path from a Uri. This will get the the path for Storage Access Framework Documents,
   * as well as the _data field for the MediaStore and other file-based ContentProviders.<br>
   * <br>
   * Callers should only use this for display purposes and not for accessing the file directly via
   * the file system
   *
   * @param context The context.
   * @param uri The Uri to query.
   * @see #isLocal(String)
   * @see #getFile(Context, Uri)
   * @author paulburke
   */
  @TargetApi(Build.VERSION_CODES.KITKAT)
  public static String getPath(final Context context, final Uri uri) {

    if (DEBUG)
      Log.d(
          TAG + " File -",
          "Authority: "
              + uri.getAuthority()
              + ", Fragment: "
              + uri.getFragment()
              + ", Port: "
              + uri.getPort()
              + ", Query: "
              + uri.getQuery()
              + ", Scheme: "
              + uri.getScheme()
              + ", Host: "
              + uri.getHost()
              + ", Segments: "
              + uri.getPathSegments().toString());

    // DocumentProvider
    if (isDocumentUri(context, uri)) {
      // ExternalStorageProvider
      if (isExternalStorageDocument(uri)) {
        final String docId = DocumentsContract.getDocumentId(uri);
        final String[] split = docId.split(":");
        final String type = split[0];

        if ("primary".equalsIgnoreCase(type)) {
          String path = Environment.getExternalStorageDirectory().getPath();
          if (split.length > 1) {
            path += "/" + split[1];
          }
          return path;
        }
        // there is no documented way of returning a path to a file on non primary storage.
        // so what we do is displaying the documentId to the user which is better than just null
        return docId;
      }
      // DownloadsProvider
      else if (isDownloadsDocument(uri)) {

        final String id = DocumentsContract.getDocumentId(uri);
        final Uri contentUri =
            ContentUris.withAppendedId(
                Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

        return getDataColumn(context, contentUri, null, null);
      }
      // MediaProvider
      else if (isMediaDocument(uri)) {
        final String docId = DocumentsContract.getDocumentId(uri);
        final String[] split = docId.split(":");
        final String type = split[0];

        Uri contentUri = null;
        if ("image".equals(type)) {
          contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
        } else if ("video".equals(type)) {
          contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
        } else if ("audio".equals(type)) {
          contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
        }

        final String selection = "_id=?";
        final String[] selectionArgs = new String[] {split[1]};

        return getDataColumn(context, contentUri, selection, selectionArgs);
      }
    }
    // MediaStore (and general)
    else if ("content".equalsIgnoreCase(uri.getScheme())) {

      // Return the remote address
      if (isGooglePhotosUri(uri)) return uri.getLastPathSegment();

      return getDataColumn(context, uri, null, null);
    }
    // File
    else if ("file".equalsIgnoreCase(uri.getScheme())) {
      return uri.getPath();
    }

    return null;
  }
  /**
   * Give the host application a chance to take over the control when a new url is about to be
   * loaded in the current WebView.
   *
   * @param view The WebView that is initiating the callback.
   * @param url The url to be loaded.
   * @return true to override, false for default behavior
   */
  @Override
  public boolean shouldOverrideUrlLoading(WebView view, String url) {

    // First give any plugins the chance to handle the url themselves
    if (this.ctx.pluginManager.onOverrideUrlLoading(url)) {
    }

    // If dialing phone (tel:5551212)
    else if (url.startsWith(WebView.SCHEME_TEL)) {
      try {
        Intent intent = new Intent(Intent.ACTION_DIAL);
        intent.setData(Uri.parse(url));
        ctx.startActivity(intent);
      } catch (android.content.ActivityNotFoundException e) {
        LOG.e(TAG, "Error dialing " + url + ": " + e.toString());
      }
    }

    // If displaying map (geo:0,0?q=address)
    else if (url.startsWith("geo:")) {
      try {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        ctx.startActivity(intent);
      } catch (android.content.ActivityNotFoundException e) {
        LOG.e(TAG, "Error showing map " + url + ": " + e.toString());
      }
    }

    // If sending email (mailto:[email protected])
    else if (url.startsWith(WebView.SCHEME_MAILTO)) {
      try {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(url));
        ctx.startActivity(intent);
      } catch (android.content.ActivityNotFoundException e) {
        LOG.e(TAG, "Error sending email " + url + ": " + e.toString());
      }
    }

    // If sms:5551212?body=This is the message
    else if (url.startsWith("sms:")) {
      try {
        Intent intent = new Intent(Intent.ACTION_VIEW);

        // Get address
        String address = null;
        int parmIndex = url.indexOf('?');
        if (parmIndex == -1) {
          address = url.substring(4);
        } else {
          address = url.substring(4, parmIndex);

          // If body, then set sms body
          Uri uri = Uri.parse(url);
          String query = uri.getQuery();
          if (query != null) {
            if (query.startsWith("body=")) {
              intent.putExtra("sms_body", query.substring(5));
            }
          }
        }
        intent.setData(Uri.parse("sms:" + address));
        intent.putExtra("address", address);
        intent.setType("vnd.android-dir/mms-sms");
        ctx.startActivity(intent);
      } catch (android.content.ActivityNotFoundException e) {
        LOG.e(TAG, "Error sending sms " + url + ":" + e.toString());
      }
    }

    // All else
    else {

      // If our app or file:, then load into a new phonegap webview
      // container by starting a new instance of our activity.
      // Our app continues to run. When BACK is pressed, our app is
      // redisplayed.
      if (url.startsWith("file://")
          || url.indexOf(this.ctx.getBaseUrl()) == 0
          || ctx.isUrlWhiteListed(url)) {
        this.ctx.loadUrl(url);
      }

      // If not our application, let default viewer handle
      else {
        try {
          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setData(Uri.parse(url));
          ctx.startActivity(intent);
        } catch (android.content.ActivityNotFoundException e) {
          LOG.e(TAG, "Error loading url " + url, e);
        }
      }
    }
    return true;
  }
Example #17
0
    /**
     * Notify the host application that a page has started loading.
     *
     * @param view The webview initiating the callback.
     * @param url The url of the page.
     */
    @Override
    public void onPageStarted(AmazonWebView view, String url, Bitmap favicon) {
      super.onPageStarted(view, url, favicon);
      String newloc = "";
      if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) {
        newloc = url;
      }
      // If dialing phone (tel:5551212)
      else if (url.startsWith(AmazonWebView.SCHEME_TEL)) {
        try {
          Intent intent = new Intent(Intent.ACTION_DIAL);
          intent.setData(Uri.parse(url));
          cordova.getActivity().startActivity(intent);
        } catch (android.content.ActivityNotFoundException e) {
          LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
        }
      } else if (url.startsWith("geo:")
          || url.startsWith(AmazonWebView.SCHEME_MAILTO)
          || url.startsWith("market:")) {
        try {
          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setData(Uri.parse(url));
          cordova.getActivity().startActivity(intent);
        } catch (android.content.ActivityNotFoundException e) {
          LOG.e(LOG_TAG, "Error with " + url + ": " + e.toString());
        }
      }
      // If sms:5551212?body=This is the message
      else if (url.startsWith("sms:")) {
        try {
          Intent intent = new Intent(Intent.ACTION_VIEW);

          // Get address
          String address = null;
          int parmIndex = url.indexOf('?');
          if (parmIndex == -1) {
            address = url.substring(4);
          } else {
            address = url.substring(4, parmIndex);

            // If body, then set sms body
            Uri uri = Uri.parse(url);
            String query = uri.getQuery();
            if (query != null) {
              if (query.startsWith("body=")) {
                intent.putExtra("sms_body", query.substring(5));
              }
            }
          }
          intent.setData(Uri.parse("sms:" + address));
          intent.putExtra("address", address);
          intent.setType("vnd.android-dir/mms-sms");
          cordova.getActivity().startActivity(intent);
        } catch (android.content.ActivityNotFoundException e) {
          LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
        }
      } else {
        newloc = "http://" + url;
      }

      if (!newloc.equals(edittext.getText().toString())) {
        edittext.setText(newloc);
      }

      try {
        JSONObject obj = new JSONObject();
        obj.put("type", LOAD_START_EVENT);
        obj.put("url", newloc);

        sendUpdate(obj, true);
      } catch (JSONException ex) {
        Log.d(LOG_TAG, "Should never happen");
      }
    }