static {
   try {
     sYtIntent = Intent.parseUri("http://youtube.com/", Intent.URI_INTENT_SCHEME);
     sMoblieYtIntent = Intent.parseUri("http://m.youtube.com/", Intent.URI_INTENT_SCHEME);
     sFooIntent = Intent.parseUri("http://foo.com/", Intent.URI_INTENT_SCHEME);
   } catch (URISyntaxException ue) {
     // Ignore exception.
   }
 }
Beispiel #2
1
  @Override
  public synchronized void loadUrl(String url) {
    if (url == null || url.trim().isEmpty()) {
      NinjaToast.show(context, R.string.toast_load_error);
      return;
    }

    url = BrowserUnit.queryWrapper(context, url.trim());
    if (url.startsWith(BrowserUnit.URL_SCHEME_MAIL_TO)) {
      Intent intent = IntentUnit.getEmailIntent(MailTo.parse(url));
      context.startActivity(intent);
      reload();

      return;
    } else if (url.startsWith(BrowserUnit.URL_SCHEME_INTENT)) {
      Intent intent;
      try {
        intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
        context.startActivity(intent);
      } catch (URISyntaxException u) {
      }

      return;
    }

    webViewClient.updateWhite(adBlock.isWhite(url));
    super.loadUrl(url);
    if (browserController != null && foreground) {
      browserController.updateBookmarks();
    }
  }
    private boolean addUriShortcut(SQLiteDatabase db, ContentValues values, TypedArray a) {
      Resources r = mContext.getResources();

      final int iconResId = a.getResourceId(R.styleable.Favorite_icon, 0);
      final int titleResId = a.getResourceId(R.styleable.Favorite_title, 0);

      Intent intent;
      String uri = null;
      try {
        uri = a.getString(R.styleable.Favorite_uri);
        intent = Intent.parseUri(uri, 0);
      } catch (URISyntaxException e) {
        Log.w(TAG, "Shortcut has malformed uri: " + uri);
        return false; // Oh well
      }

      if (iconResId == 0 || titleResId == 0) {
        Log.w(TAG, "Shortcut is missing title or icon resource ID");
        return false;
      }

      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      values.put(Favorites.INTENT, intent.toUri(0));
      values.put(Favorites.TITLE, r.getString(titleResId));
      values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_SHORTCUT);
      values.put(Favorites.SPANX, 1);
      values.put(Favorites.SPANY, 1);
      values.put(Favorites.ICON_TYPE, Favorites.ICON_TYPE_RESOURCE);
      values.put(Favorites.ICON_PACKAGE, mContext.getPackageName());
      values.put(Favorites.ICON_RESOURCE, r.getResourceName(iconResId));

      db.insert(TABLE_FAVORITES, null, values);

      return true;
    }
 @Override
 public boolean shouldOverrideUrlLoading(WebView view, String url) {
   Intent intent;
   // Perform generic parsing of the URI to turn it into an Intent.
   try {
     intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
   } catch (URISyntaxException ex) {
     Log.w(TAG, "Bad URI " + url + ": " + ex.getMessage());
     return false;
   }
   // Sanitize the Intent, ensuring web pages can not bypass browser
   // security (only access to BROWSABLE activities).
   intent.addCategory(Intent.CATEGORY_BROWSABLE);
   intent.setComponent(null);
   Intent selector = intent.getSelector();
   if (selector != null) {
     selector.addCategory(Intent.CATEGORY_BROWSABLE);
     selector.setComponent(null);
   }
   // Pass the package name as application ID so that the intent from the
   // same application can be opened in the same tab.
   intent.putExtra(Browser.EXTRA_APPLICATION_ID, view.getContext().getPackageName());
   try {
     view.getContext().startActivity(intent);
   } catch (ActivityNotFoundException ex) {
     Log.w(TAG, "No application can handle " + url);
     return false;
   }
   return true;
 }
  // ##date:2013/11/28 ##author:hongxing.whx
  // backup restore functionality support
  private void handleRestore() {
    if (BackupManager.getRestoreFlag(this)) {
      // set in restore flag, so that other part can use it to judge if homeshell
      // is in restore mode
      Log.d(TAG, "Set homeshell inRestore flag");
      BackupManager.getInstance().setIsInRestore(true);
      //            BackupManager.setRestoreFlag(this, false);

      /*YUNOS BEGIN*/
      // ##date:2013/12/20 ##author:hao.liuhaolh ##BugID: 75596
      // restore app isn't in folder if restore failed and reload.
      Cursor c = null;
      File restoreDBfile =
          new File(getApplicationContext().getFilesDir() + "/backup/" + RESTORE_DB_FILE);
      if (restoreDBfile.exists() == true) {
        Log.d(TAG, "handleRestore read data from restore db");
        SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(restoreDBfile, null);
        c = db.query("favorites", null, null, null, null, null, null);
        // convertDBToBackupSet will close cursor, so we don't need to close it
        mBackupRecordMap = BackupUitil.convertDBToBackupSet(c);
        db.close();
      } else {
        Log.d(TAG, "handleRestore read data from homeshell db");
        final ContentResolver contentResolver = getApplicationContext().getContentResolver();
        c = contentResolver.query(Favorites.CONTENT_URI, null, null, null, null);
        // convertDBToBackupSet will close cursor, so we don't need to close it
        mBackupRecordMap = BackupUitil.convertDBToBackupSet(c);
      }
      /*YUNOS END*/

      for (Entry<String, BackupRecord> r : LauncherApplication.mBackupRecordMap.entrySet()) {
        Log.d(TAG, r.getValue().getField(Favorites._ID));
        String intentStr = r.getValue().getField(Favorites.INTENT);
        if (TextUtils.isEmpty(intentStr)) {
          continue;
        }
        try {
          Intent intent = Intent.parseUri(intentStr, 0);
          final ComponentName name = intent.getComponent();
          if (name == null) {
            Log.e(TAG, "ComponentName == Null");
            Log.i(TAG, "intent = " + intent.toString());
            continue;
          }
          Log.d(
              TAG,
              "onCreate() mBackupRecordMap getPackageName()="
                  + intent.getComponent().getPackageName());
        } catch (Exception e) {
          e.printStackTrace();
        }
      }
    }
  }
  public void onReceive(Context context, Intent data) {
    if (!ACTION_UNINSTALL_SHORTCUT.equals(data.getAction())) {
      return;
    }

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);

    if (intent != null && name != null) {
      final ContentResolver cr = context.getContentResolver();
      Cursor c =
          cr.query(
              LauncherSettings.Favorites.CONTENT_URI,
              new String[] {LauncherSettings.Favorites._ID, LauncherSettings.Favorites.INTENT},
              LauncherSettings.Favorites.TITLE + "=?",
              new String[] {name},
              null);

      final int intentIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites.INTENT);
      final int idIndex = c.getColumnIndexOrThrow(LauncherSettings.Favorites._ID);

      boolean changed = false;

      try {
        while (c.moveToNext()) {
          try {
            if (intent.filterEquals(Intent.parseUri(c.getString(intentIndex), 0))) {
              final long id = c.getLong(idIndex);
              final Uri uri = LauncherSettings.Favorites.getContentUri(id, false);
              cr.delete(uri, null, null);
              changed = true;
              if (!duplicate) {
                break;
              }
            }
          } catch (URISyntaxException e) {
            // Ignore
          }
        }
      } finally {
        c.close();
      }

      if (changed) {
        cr.notifyChange(LauncherSettings.Favorites.CONTENT_URI, null);
        Toast.makeText(
                context, context.getString(R.string.shortcut_uninstalled, name), Toast.LENGTH_SHORT)
            .show();
      }
    }
  }
  @SmallTest
  public void testInitialIntent() throws URISyntaxException {
    TabRedirectHandler redirectHandler = new TabRedirectHandler(new TestContext());
    Intent ytIntent = Intent.parseUri("http://youtube.com/", Intent.URI_INTENT_SCHEME);
    Intent fooIntent = Intent.parseUri("http://foo.com/", Intent.URI_INTENT_SCHEME);
    int transTypeLinkFromIntent = PageTransition.LINK | PageTransition.FROM_API;

    // Ignore if url is redirected, transition type is IncomingIntent and a new intent doesn't
    // have any new resolver.
    redirectHandler.updateIntent(ytIntent);
    redirectHandler.updateNewUrlLoading(transTypeLinkFromIntent, false, false, 0, 0);
    redirectHandler.updateNewUrlLoading(transTypeLinkFromIntent, true, false, 0, 0);
    check(
        "http://m.youtube.com/",
        null, /* referrer */
        false, /* incognito */
        transTypeLinkFromIntent,
        REDIRECT,
        true,
        false,
        redirectHandler,
        OverrideUrlLoadingResult.NO_OVERRIDE,
        IGNORE);
    // Do not ignore if a new intent has any new resolver.
    redirectHandler.updateIntent(fooIntent);
    redirectHandler.updateNewUrlLoading(transTypeLinkFromIntent, false, false, 0, 0);
    redirectHandler.updateNewUrlLoading(transTypeLinkFromIntent, true, false, 0, 0);
    check(
        "http://m.youtube.com/",
        null, /* referrer */
        false, /* incognito */
        transTypeLinkFromIntent,
        REDIRECT,
        true,
        false,
        redirectHandler,
        OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT,
        START_ACTIVITY);
  }
 private Drawable getNavbarIconImage(String uri) {
   if (uri == null) uri = AwesomeConstant.ACTION_NULL.value();
   if (uri.startsWith("**")) {
     return AwesomeConstants.getActionIcon(mContext, uri);
   } else {
     try {
       return mPackMan.getActivityIcon(Intent.parseUri(uri, 0));
     } catch (NameNotFoundException e) {
       e.printStackTrace();
     } catch (URISyntaxException e) {
       e.printStackTrace();
     }
   }
   return mResources.getDrawable(R.drawable.ic_sysbar_null);
 }
  void shareToBaidu() {
    String uriString =
        String.format(
            "intent://map/direction?origin=latlng:%s,%s|name:%s&destination=%s&mode=driving&src=口袋停|口袋停#Intent;scheme=bdapp;package=com.baidu.BaiduMap;end",
            parking.getParking_latitude(),
            parking.getParking_longitude(),
            "我的位置",
            parking.getParking_name());

    try {
      Intent intent = Intent.parseUri(uriString, 0);
      startActivity(intent); // 启动调用
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
  }
 void shareToAutoNavi() {
   String uriString =
       String.format(
           "androidamap://navi?sourceApplication=%s&poiname=%s&lat=%s&lon=%s&dev=1&style=2",
           "口袋停",
           parking.getParking_name(),
           parking.getParking_latitude(),
           parking.getParking_longitude());
   try {
     Intent intent = Intent.parseUri(uriString, 0);
     intent.setPackage("com.autonavi.minimap");
     startActivity(intent);
   } catch (URISyntaxException e) {
     e.printStackTrace();
   }
 }
  private String getCustomText() {
    String mCustomURI =
        Settings.System.getString(
            mContext.getContentResolver(), Settings.System.QUICK_SETTINGS_CUSTOM);
    String text = "";
    try {
      text =
          "Custom ("
              + mPm.resolveActivity(Intent.parseUri(mCustomURI, 0), 0).activityInfo.loadLabel(mPm)
              + ")";
    } catch (Exception e) {
      return "Custom";
    }

    return text;
  }
  public String getFriendlyNameForUri(String uri) {
    if (uri == null) {
      return null;
    }

    try {
      Intent intent = Intent.parseUri(uri, 0);
      if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        return getFriendlyActivityName(intent, false);
      }
      return getFriendlyShortcutName(intent);
    } catch (URISyntaxException e) {
    }

    return uri;
  }
  private Drawable getCustomDrawable() {
    String mCustomURI =
        Settings.System.getString(
            mContext.getContentResolver(), Settings.System.QUICK_SETTINGS_CUSTOM);
    Drawable customIcon = null;
    try {
      customIcon = CustomIconUtil.getInstance(mContext).loadFromFile();
      if (customIcon == null) {
        customIcon = mPm.getActivityIcon(Intent.parseUri(mCustomURI, 0));
      }
    } catch (Exception e) {
      e.printStackTrace();
      return getIconDrawable("");
    }

    return customIcon;
  }
  private static PendingInstallShortcutInfo decode(String encoded, Context context) {
    try {
      JSONObject object = (JSONObject) new JSONTokener(encoded).nextValue();
      Intent launcherIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);

      if (object.optBoolean(APP_SHORTCUT_TYPE_KEY)) {
        // The is an internal launcher target shortcut.
        UserHandleCompat user =
            UserManagerCompat.getInstance(context)
                .getUserForSerialNumber(object.getLong(USER_HANDLE_KEY));
        if (user == null) {
          return null;
        }

        LauncherActivityInfoCompat info =
            LauncherAppsCompat.getInstance(context).resolveActivity(launcherIntent, user);
        return info == null ? null : new PendingInstallShortcutInfo(info, context);
      }

      Intent data = new Intent();
      data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent);
      data.putExtra(Intent.EXTRA_SHORTCUT_NAME, object.getString(NAME_KEY));

      String iconBase64 = object.optString(ICON_KEY);
      String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY);
      String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY);
      if (iconBase64 != null && !iconBase64.isEmpty()) {
        byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT);
        Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length);
        data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b);
      } else if (iconResourceName != null && !iconResourceName.isEmpty()) {
        Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource();
        iconResource.resourceName = iconResourceName;
        iconResource.packageName = iconResourcePackageName;
        data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
      }

      return new PendingInstallShortcutInfo(data, context);
    } catch (JSONException e) {
      Log.d(TAG, "Exception reading shortcut to add: " + e);
    } catch (URISyntaxException e) {
      Log.d(TAG, "Exception reading shortcut to add: " + e);
    }
    return null;
  }
    /**
     * Used by: plugin FireReceiver
     *
     * <p>Tell the host that the plugin has finished execution.
     *
     * <p>This should only be used if RESULT_CODE_PENDING was returned by FireReceiver.onReceive().
     *
     * @param originalFireIntent the intent received from the host (via onReceive())
     * @param resultCode level of success in performing the settings
     * @param vars any variables that the plugin wants to set in the host
     * @see #hostSupportsSynchronousExecution(Bundle)
     */
    public static boolean signalFinish(
        Context context, Intent originalFireIntent, int resultCode, Bundle vars) {

      String errorPrefix = "signalFinish: ";

      boolean okFlag = false;

      String completionIntentString =
          (String)
              getExtraValueSafe(
                  originalFireIntent,
                  Setting.EXTRA_PLUGIN_COMPLETION_INTENT,
                  String.class,
                  "signalFinish");

      if (completionIntentString != null) {
        Uri completionIntentUri = null;
        try {
          completionIntentUri = Uri.parse(completionIntentString);
        }
        // 	should only throw NullPointer but don't particularly trust it
        catch (Exception e) {
          Log.w(TAG, errorPrefix + "couldn't parse " + completionIntentString);
        }

        if (completionIntentUri != null) {
          try {
            Intent completionIntent =
                Intent.parseUri(completionIntentString, Intent.URI_INTENT_SCHEME);

            completionIntent.putExtra(EXTRA_RESULT_CODE, resultCode);

            if (vars != null) completionIntent.putExtra(EXTRA_VARIABLES_BUNDLE, vars);

            context.sendBroadcast(completionIntent);

            okFlag = true;
          } catch (URISyntaxException e) {
            Log.w(TAG, errorPrefix + "bad URI: " + completionIntentUri);
          }
        }
      }

      return okFlag;
    }
    public View getView(int position, View convertView, ViewGroup parent) {
      final View v;
      if (convertView == null) {
        v = mInflater.inflate(R.layout.list_item_image_text_image, null);
      } else {
        v = convertView;
      }

      ActivityInfo ai = null;
      try {
        ai =
            mPackageManager.getActivityInfo(
                Intent.parseUri(mIntents.get(position), 0).resolveActivity(mPackageManager), 0);
      } catch (Exception e) {
        e.printStackTrace();
      }

      IntentAdapter local = this;
      final ViewHolder vh;

      if (v.getTag() == null) {
        vh = new ViewHolder(local);
      } else {
        vh = (ViewHolder) v.getTag();
      }

      vh.line1 = (TextView) v.findViewById(R.id.txt_1x1);
      vh.icon = (ImageView) v.findViewById(R.id.img_1x1);
      v.findViewById(R.id.img_indicator).setVisibility(View.GONE);

      vh.line1.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
      vh.line1.setText(
          ai == null
              ? (mIntents.size() <= 1 && position == 0)
                  ? getString(R.string.warning_none_set)
                  : getString(R.string.warning_problem_shortcut)
              : ai.loadLabel(mPackageManager));

      vh.icon.setImageDrawable(ai == null ? null : ai.loadIcon(mPackageManager));
      vh.icon.setVisibility(ai == null ? View.GONE : View.VISIBLE);

      v.setTag(vh);

      return v;
    }
Beispiel #17
1
 private static Intent loadIntent(Context context, String uri, MotionEvent event) {
   Intent intent = null;
   try {
     intent = Intent.parseUri(uri, 0);
   } catch (URISyntaxException e) {
     Context mod = getModContext(context);
     Toast.makeText(mod, R.string.not_found, Toast.LENGTH_SHORT).show();
   }
   if (intent != null) {
     intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE))
         .getDefaultDisplay()
         .getRealSize(mDisplaySize);
     intent.putExtra(EXTRA_FRACTION_X, event.getX() / mDisplaySize.x);
     intent.putExtra(EXTRA_FRACTION_Y, event.getY() / mDisplaySize.y);
   }
   return intent;
 }
Beispiel #18
1
 private static void a(Intent intent)
 {
     if (intent == null)
     {
         throw new IllegalArgumentException("Callback cannot be null.");
     }
     intent = intent.toUri(1);
     try
     {
         Intent.parseUri(intent, 1);
         return;
     }
     // Misplaced declaration of an exception variable
     catch (Intent intent)
     {
         throw new IllegalArgumentException("Parameter callback contains invalid data. It must be serializable using toUri() and parseUri().");
     }
 }
 @Override
 public void shortcutPicked(String uri, String friendlyName, boolean isApplication) {
   try {
     Intent i = Intent.parseUri(uri, 0);
     PackageManager pm = mActivity.getPackageManager();
     ActivityInfo aInfo = i.resolveActivityInfo(pm, PackageManager.GET_ACTIVITIES);
     Drawable icon = null;
     if (aInfo != null) {
       icon = aInfo.loadIcon(pm).mutate();
     } else {
       icon = mResources.getDrawable(android.R.drawable.sym_def_app_icon);
     }
     mDialogLabel.setText(friendlyName);
     mDialogLabel.setTag(uri);
     mDialogIcon.setImageDrawable(resizeForDialog(icon));
     mDialogIcon.setTag(null);
   } catch (Exception e) {
   }
 }
Beispiel #20
1
  public static ComponentName[] loadNavigates(Launcher launcher) {
    String[] mHotseatConfig = null;
    ArrayList<ComponentName> componentNames = null;
    if (mHotseatConfig == null) {
      mHotseatConfig = launcher.getResources().getStringArray(R.array.iphone_navigate);
      if (mHotseatConfig.length > 0) {
        componentNames = new ArrayList<ComponentName>();
      }
    }
    for (int i = 0; i < mHotseatConfig.length; i++) {
      Intent intent = null;
      try {
        intent = Intent.parseUri(mHotseatConfig[i], 0);
        componentNames.add(intent.getComponent());
      } catch (java.net.URISyntaxException ex) {

      }
    }
    return componentNames.toArray(new ComponentName[componentNames.size()]);
  }
Beispiel #21
1
  /**
   * Parses serialized Intents from the query string of the given URI, assuming the parameter key of
   * DepedencyManagerContract.QUERY_PARAM_INTENT. Returns null if no intents are found in the Uri.
   */
  public static List<Intent> parseIntents(Uri uri) {
    List<String> values = uri.getQueryParameters(DependencyManagerContract.QUERY_PARAM_INTENT);
    if (null == values) {
      return null;
    }

    LinkedList<Intent> results = new LinkedList<Intent>();
    for (String v : values) {
      try {
        results.add(Intent.parseUri(v, Intent.URI_INTENT_SCHEME));
      } catch (java.net.URISyntaxException ex) {
        // pass
      }
    }

    if (0 >= results.size()) {
      return null;
    }

    return results;
  }
Beispiel #22
1
  public void bindView(View view, Context context, Cursor cursor) {
    final ViewHolder holder = (ViewHolder) view.getTag();

    holder.id = cursor.getLong(holder.idIndex);
    final Drawable icon = loadIcon(context, cursor, holder);

    holder.name.setText(cursor.getString(holder.nameIndex));

    if (!mIsList) {
      holder.name.setCompoundDrawablesWithIntrinsicBounds(null, icon, null, null);
    } else {
      final boolean hasIcon = icon != null;
      holder.icon.setVisibility(hasIcon ? View.VISIBLE : View.GONE);
      if (hasIcon) holder.icon.setImageDrawable(icon);

      if (holder.descriptionIndex != -1) {
        final String description = cursor.getString(holder.descriptionIndex);
        if (description != null) {
          holder.description.setText(description);
          holder.description.setVisibility(View.VISIBLE);
        } else {
          holder.description.setVisibility(View.GONE);
        }
      } else {
        holder.description.setVisibility(View.GONE);
      }
    }

    if (holder.intentIndex != -1) {
      try {
        holder.intent = Intent.parseUri(cursor.getString(holder.intentIndex), 0);
      } catch (URISyntaxException e) {
        // Ignore
      }
    } else {
      holder.useBaseIntent = true;
    }
  }
 /** Save targets to settings provider */
 private void saveAll() {
   StringBuilder targetLayout = new StringBuilder();
   ArrayList<String> existingImages = new ArrayList<String>();
   final int maxTargets =
       mIsScreenLarge ? GlowPadView.MAX_TABLET_TARGETS : GlowPadView.MAX_PHONE_TARGETS;
   for (int i = mTargetOffset + 1; i <= mTargetOffset + maxTargets; i++) {
     String uri = mTargetStore.get(i).uri;
     String type = mTargetStore.get(i).iconType;
     String source = mTargetStore.get(i).iconSource;
     existingImages.add(source);
     if (!uri.equals(GlowPadView.EMPTY_TARGET) && type != null) {
       try {
         Intent in = Intent.parseUri(uri, 0);
         in.putExtra(type, source);
         String pkgName = mTargetStore.get(i).pkgName;
         if (pkgName != null) {
           in.putExtra(GlowPadView.ICON_PACKAGE, mTargetStore.get(i).pkgName);
         } else {
           in.removeExtra(GlowPadView.ICON_PACKAGE);
         }
         uri = in.toUri(0);
       } catch (URISyntaxException e) {
       }
     }
     targetLayout.append(uri);
     targetLayout.append("|");
   }
   targetLayout.deleteCharAt(targetLayout.length() - 1);
   Settings.System.putString(
       mActivity.getContentResolver(),
       Settings.System.LOCKSCREEN_TARGETS,
       targetLayout.toString());
   for (File pic : mActivity.getFilesDir().listFiles()) {
     if (pic.getName().startsWith("lockscreen_") && !existingImages.contains(pic.toString())) {
       pic.delete();
     }
   }
 }
  private Drawable setIcon(String uri, String action) {
    if (uri != null && uri.length() > 0) {
      File f = new File(Uri.parse(uri).getPath());
      if (f.exists()) return resize(new BitmapDrawable(mResources, f.getAbsolutePath()));
    }
    if (uri != null && !uri.equals("") && uri.startsWith("file")) {
      // it's an icon the user chose from the gallery here
      File icon = new File(Uri.parse(uri).getPath());
      if (icon.exists()) return resize(new BitmapDrawable(mResources, icon.getAbsolutePath()));

    } else if (uri != null && !uri.equals("")) {
      // here they chose another app icon
      try {
        return resize(mPackMan.getActivityIcon(Intent.parseUri(uri, 0)));
      } catch (NameNotFoundException e) {
        e.printStackTrace();
      } catch (URISyntaxException e) {
        e.printStackTrace();
      }
      // ok use default icons here
    }
    return resize(getNavbarIconImage(action));
  }
Beispiel #25
1
  private static boolean startBrowsingIntent(Context context, String url) {
    Intent intent;
    // Perform generic parsing of the URI to turn it into an Intent.
    try {
      intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
    } catch (Exception ex) {
      Log.w(TAG, "Bad URI %s", url, ex);
      return false;
    }
    // Check for regular URIs that WebView supports by itself, but also
    // check if there is a specialized app that had registered itself
    // for this kind of an intent.
    Matcher m = BROWSER_URI_SCHEMA.matcher(url);
    if (m.matches() && !isSpecializedHandlerAvailable(context, intent)) {
      return false;
    }
    // Sanitize the Intent, ensuring web pages can not bypass browser
    // security (only access to BROWSABLE activities).
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.setComponent(null);
    Intent selector = intent.getSelector();
    if (selector != null) {
      selector.addCategory(Intent.CATEGORY_BROWSABLE);
      selector.setComponent(null);
    }

    // Pass the package name as application ID so that the intent from the
    // same application can be opened in the same tab.
    intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
    try {
      context.startActivity(intent);
      return true;
    } catch (ActivityNotFoundException ex) {
      Log.w(TAG, "No application can handle %s", url);
    }
    return false;
  }
Beispiel #26
1
  public Intent getIntent() {

    if (mIntent != null) {
      return mIntent;
    }
    if (mShortcutUrl != null) {
      try {
        mIntent = Intent.parseUri(mShortcutUrl, 0);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
      } catch (URISyntaxException e) {
        e.printStackTrace();
      }
    } else if (getCategoryComponentName() != null) {
      mIntent = new Intent(Intent.ACTION_MAIN);
      mIntent.setComponent(mComponentName);
      if (!SearchActivity.class.getName().equals(mComponentName.getClassName())) {
        mIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
      } else {
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      }
    }
    return mIntent;
  }
    private boolean updateContactsShortcuts(SQLiteDatabase db) {
      Cursor c = null;
      final String selectWhere =
          buildOrWhereString(Favorites.ITEM_TYPE, new int[] {Favorites.ITEM_TYPE_SHORTCUT});

      db.beginTransaction();
      try {
        // Select and iterate through each matching widget
        c =
            db.query(
                TABLE_FAVORITES,
                new String[] {Favorites._ID, Favorites.INTENT},
                selectWhere,
                null,
                null,
                null,
                null);

        if (LOGD) Log.d(TAG, "found upgrade cursor count=" + c.getCount());

        final ContentValues values = new ContentValues();
        final int idIndex = c.getColumnIndex(Favorites._ID);
        final int intentIndex = c.getColumnIndex(Favorites.INTENT);

        while (c != null && c.moveToNext()) {
          long favoriteId = c.getLong(idIndex);
          final String intentUri = c.getString(intentIndex);
          if (intentUri != null) {
            try {
              Intent intent = Intent.parseUri(intentUri, 0);
              android.util.Log.d("Home", intent.toString());
              final Uri uri = intent.getData();
              final String data = uri.toString();
              if (Intent.ACTION_VIEW.equals(intent.getAction())
                  && (data.startsWith("content://contacts/people/")
                      || data.startsWith("content://com.android.contacts/contacts/lookup/"))) {

                intent = new Intent("com.android.contacts.action.QUICK_CONTACT");
                intent.setFlags(
                    Intent.FLAG_ACTIVITY_NEW_TASK
                        | Intent.FLAG_ACTIVITY_CLEAR_TOP
                        | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

                intent.setData(uri);
                intent.putExtra("mode", 3);
                intent.putExtra("exclude_mimes", (String[]) null);

                values.clear();
                values.put(LauncherSettings.Favorites.INTENT, intent.toUri(0));

                String updateWhere = Favorites._ID + "=" + favoriteId;
                db.update(TABLE_FAVORITES, values, updateWhere, null);
              }
            } catch (RuntimeException ex) {
              Log.e(TAG, "Problem upgrading shortcut", ex);
            } catch (URISyntaxException e) {
              Log.e(TAG, "Problem upgrading shortcut", e);
            }
          }
        }

        db.setTransactionSuccessful();
      } catch (SQLException ex) {
        Log.w(TAG, "Problem while upgrading contacts", ex);
        return false;
      } finally {
        db.endTransaction();
        if (c != null) {
          c.close();
        }
      }

      return true;
    }
Beispiel #28
1
 private k a(C1112s c1112s, boolean z, byte[] bArr) {
   URISyntaxException e;
   Intent intent;
   MalformedURLException malformedURLException;
   k kVar = null;
   try {
     b a = q.a(this.b, c1112s);
     if (a == null) {
       c.c("receiving an un-recognized message. " + c1112s.a);
       return null;
     }
     c.b("receive a message." + a);
     C1094a a2 = c1112s.a();
     c.a("processing a message, action=" + a2);
     List list;
     switch (t.a[a2.ordinal()]) {
       case l.a /*1*/:
         y yVar = (y) a;
         if (yVar.f == 0) {
           m.a(this.b).b(yVar.h, yVar.i);
         }
         if (TextUtils.isEmpty(yVar.h)) {
           list = null;
         } else {
           list = new ArrayList();
           list.add(yVar.h);
         }
         kVar = l.a(f.a, list, yVar.f, yVar.g, null);
         u.a(this.b).d();
         return kVar;
       case a.k /*2*/:
         if (((M) a).f == 0) {
           m.a(this.b).h();
           f.d(this.b);
         }
         PushMessageHandler.a();
         return null;
       case a.l /*3*/:
         if (!m.a(this.b).l() || z) {
           E e2 = (E) a;
           C1096c l = e2.l();
           if (l == null) {
             c.c("receive an empty message without push content, drop it");
             return null;
           }
           if (z) {
             f.a(this.b, l.b(), c1112s.m());
           }
           if (!TextUtils.isEmpty(e2.j()) && f.l(this.b, e2.j()) < 0) {
             f.d(this.b, e2.j());
           } else if (!TextUtils.isEmpty(e2.h()) && f.j(this.b, e2.h()) < 0) {
             f.h(this.b, e2.h());
           }
           String str =
               (c1112s.h == null || c1112s.h.s() == null)
                   ? null
                   : (String) c1112s.h.j.get("jobkey");
           if (TextUtils.isEmpty(str)) {
             str = l.b();
           }
           if (z || !a(this.b, str)) {
             Serializable a3 = l.a(e2, c1112s.m(), z);
             if (a3.m() == 0 && !z && T.a(a3.n())) {
               T.a(this.b, c1112s, bArr);
               return null;
             }
             c.a("receive a message, msgid=" + l.b());
             if (z && a3.n() != null && a3.n().containsKey("notify_effect")) {
               Intent launchIntentForPackage;
               Map n = a3.n();
               String str2 = (String) n.get("notify_effect");
               String str3 =
                   "com.xiaomi.xmsf".equals(this.b.getPackageName())
                       ? (String) n.get("miui_package_name")
                       : null;
               if (d.equals(str2)) {
                 try {
                   PackageManager packageManager = this.b.getPackageManager();
                   if (TextUtils.isEmpty(str3)) {
                     str3 = this.b.getPackageName();
                   }
                   launchIntentForPackage = packageManager.getLaunchIntentForPackage(str3);
                 } catch (Exception e3) {
                   c.c("Cause: " + e3.getMessage());
                   launchIntentForPackage = null;
                 }
               } else {
                 if (e.equals(str2)) {
                   if (n.containsKey("intent_uri")) {
                     str = (String) n.get("intent_uri");
                     if (str != null) {
                       try {
                         launchIntentForPackage = Intent.parseUri(str, 1);
                         try {
                           if (TextUtils.isEmpty(str3)) {
                             str3 = this.b.getPackageName();
                           }
                           launchIntentForPackage.setPackage(str3);
                         } catch (URISyntaxException e4) {
                           e = e4;
                           c.c("Cause: " + e.getMessage());
                           if (launchIntentForPackage == null) {
                             return null;
                           }
                           if (!str2.equals(f)) {
                             launchIntentForPackage.putExtra(l.f, a3);
                           }
                           launchIntentForPackage.addFlags(268435456);
                           try {
                             if (this.b
                                     .getPackageManager()
                                     .resolveActivity(launchIntentForPackage, C0113o.q)
                                 == null) {
                               return null;
                             }
                             this.b.startActivity(launchIntentForPackage);
                             return null;
                           } catch (Exception e5) {
                             c.c("Cause: " + e5.getMessage());
                             return null;
                           }
                         }
                       } catch (URISyntaxException e6) {
                         e = e6;
                         launchIntentForPackage = null;
                         c.c("Cause: " + e.getMessage());
                         if (launchIntentForPackage == null) {
                           return null;
                         }
                         if (str2.equals(f)) {
                           launchIntentForPackage.putExtra(l.f, a3);
                         }
                         launchIntentForPackage.addFlags(268435456);
                         if (this.b
                                 .getPackageManager()
                                 .resolveActivity(launchIntentForPackage, C0113o.q)
                             == null) {
                           return null;
                         }
                         this.b.startActivity(launchIntentForPackage);
                         return null;
                       }
                     }
                     launchIntentForPackage = null;
                   } else if (n.containsKey("class_name")) {
                     str = (String) n.get("class_name");
                     Intent intent2 = new Intent();
                     if (TextUtils.isEmpty(str3)) {
                       str3 = this.b.getPackageName();
                     }
                     intent2.setComponent(new ComponentName(str3, str));
                     try {
                       if (n.containsKey("intent_flag")) {
                         intent2.setFlags(Integer.parseInt((String) n.get("intent_flag")));
                       }
                     } catch (NumberFormatException e7) {
                       c.c("Cause by intent_flag: " + e7.getMessage());
                     }
                     launchIntentForPackage = intent2;
                   }
                 } else if (f.equals(str2)) {
                   str = (String) n.get("web_uri");
                   if (str != null) {
                     str = str.trim().toLowerCase();
                     str3 =
                         (str.startsWith("http://") || str.startsWith("https://"))
                             ? str
                             : "http://" + str;
                     try {
                       str = new URL(str3).getProtocol();
                       if ("http".equals(str) || "https".equals(str)) {
                         launchIntentForPackage = new Intent("android.intent.action.VIEW");
                         try {
                           launchIntentForPackage.setData(Uri.parse(str3));
                         } catch (MalformedURLException e8) {
                           MalformedURLException malformedURLException2 = e8;
                           intent = launchIntentForPackage;
                           malformedURLException = malformedURLException2;
                           c.c("Cause: " + malformedURLException.getMessage());
                           launchIntentForPackage = intent;
                           if (launchIntentForPackage == null) {
                             return null;
                           }
                           if (str2.equals(f)) {
                             launchIntentForPackage.putExtra(l.f, a3);
                           }
                           launchIntentForPackage.addFlags(268435456);
                           if (this.b
                                   .getPackageManager()
                                   .resolveActivity(launchIntentForPackage, C0113o.q)
                               == null) {
                             return null;
                           }
                           this.b.startActivity(launchIntentForPackage);
                           return null;
                         }
                       }
                       launchIntentForPackage = null;
                     } catch (MalformedURLException e9) {
                       malformedURLException = e9;
                       Object obj = null;
                       c.c("Cause: " + malformedURLException.getMessage());
                       launchIntentForPackage = intent;
                       if (launchIntentForPackage == null) {
                         return null;
                       }
                       if (str2.equals(f)) {
                         launchIntentForPackage.putExtra(l.f, a3);
                       }
                       launchIntentForPackage.addFlags(268435456);
                       if (this.b
                               .getPackageManager()
                               .resolveActivity(launchIntentForPackage, C0113o.q)
                           == null) {
                         return null;
                       }
                       this.b.startActivity(launchIntentForPackage);
                       return null;
                     }
                   }
                 }
                 launchIntentForPackage = null;
               }
               if (launchIntentForPackage == null) {
                 return null;
               }
               if (str2.equals(f)) {
                 launchIntentForPackage.putExtra(l.f, a3);
               }
               launchIntentForPackage.addFlags(268435456);
               if (this.b.getPackageManager().resolveActivity(launchIntentForPackage, C0113o.q)
                   == null) {
                 return null;
               }
               this.b.startActivity(launchIntentForPackage);
               return null;
             }
             Serializable serializable = a3;
           } else {
             c.a("drop a duplicate message, key=" + str);
           }
           if (c1112s.m() != null || z) {
             return kVar;
           }
           a(e2, c1112s.m());
           return kVar;
         }
         c.a("receive a message in pause state. drop it");
         return null;
       case a.aQ /*4*/:
         I i = (I) a;
         if (i.f == 0) {
           f.h(this.b, i.h());
         }
         if (TextUtils.isEmpty(i.h())) {
           list = null;
         } else {
           list = new ArrayList();
           list.add(i.h());
         }
         return l.a(f.f, list, i.f, i.g, i.k());
       case a.X /*5*/:
         Q q = (Q) a;
         if (q.f == 0) {
           f.i(this.b, q.h());
         }
         if (TextUtils.isEmpty(q.h())) {
           list = null;
         } else {
           list = new ArrayList();
           list.add(q.h());
         }
         return l.a(f.g, list, q.f, q.g, q.k());
       case a.bt /*6*/:
         C1110q c1110q = (C1110q) a;
         Object e10 = c1110q.e();
         list = c1110q.k();
         if (c1110q.g == 0) {
           if (TextUtils.equals(e10, f.h) && list != null && list.size() > 1) {
             f.h(this.b, (String) list.get(0), (String) list.get(1));
             if ("00:00".equals(list.get(0)) && "00:00".equals(list.get(1))) {
               m.a(this.b).a(true);
             } else {
               m.a(this.b).a(false);
             }
           } else if (TextUtils.equals(e10, f.b) && list != null && list.size() > 0) {
             f.d(this.b, (String) list.get(0));
           } else if (TextUtils.equals(e10, f.c) && list != null && list.size() > 0) {
             f.e(this.b, (String) list.get(0));
           } else if (TextUtils.equals(e10, f.d) && list != null && list.size() > 0) {
             f.f(this.b, (String) list.get(0));
           } else if (TextUtils.equals(e10, f.e) && list != null && list.size() > 0) {
             f.g(this.b, (String) list.get(0));
           }
         }
         return l.a(e10, list, c1110q.g, c1110q.h, c1110q.m());
       case a.bc /*7*/:
         u uVar = (u) a;
         if ("registration id expired".equalsIgnoreCase(uVar.e)) {
           f.e(this.b);
           return null;
         } else if (!"client_info_update_ok".equalsIgnoreCase(uVar.e)
             || uVar.h() == null
             || !uVar.h().containsKey("app_version")) {
           return null;
         } else {
           m.a(this.b).a((String) uVar.h().get("app_version"));
           return null;
         }
       default:
         return null;
     }
   } catch (Throwable e11) {
     c.a(e11);
     c.c("receive a message which action string is not valid. is the reg expired?");
     return null;
   }
 }
 private void initializeView(String input) {
   if (input == null) {
     input = GlowPadView.DEFAULT_TARGETS;
   }
   mTargetStore.clear();
   final int maxTargets =
       mIsScreenLarge ? GlowPadView.MAX_TABLET_TARGETS : GlowPadView.MAX_PHONE_TARGETS;
   final PackageManager packMan = mActivity.getPackageManager();
   final Drawable activeBack =
       mResources.getDrawable(com.android.internal.R.drawable.ic_lockscreen_target_activated);
   final String[] targetStore = input.split("\\|");
   // Shift by 2 targets for phones in landscape
   if (mIsLandscape && !mIsScreenLarge) {
     mTargetStore.add(new TargetInfo(null));
     mTargetStore.add(new TargetInfo(null));
   }
   // Add the unlock icon
   Drawable unlockFront =
       mResources.getDrawable(com.android.internal.R.drawable.ic_lockscreen_unlock_normal);
   Drawable unlockBack =
       mResources.getDrawable(com.android.internal.R.drawable.ic_lockscreen_unlock_activated);
   mTargetStore.add(new TargetInfo(getLayeredDrawable(unlockBack, unlockFront, 0, true)));
   for (int cc = 0; cc < 8 - mTargetOffset - 1; cc++) {
     String uri = GlowPadView.EMPTY_TARGET;
     Drawable front = null;
     Drawable back = activeBack;
     boolean frontBlank = false;
     String iconType = null;
     String iconSource = null;
     int tmpInset = mTargetInset;
     if (cc < targetStore.length && cc < maxTargets) {
       uri = targetStore[cc];
       if (!uri.equals(GlowPadView.EMPTY_TARGET)) {
         try {
           Intent in = Intent.parseUri(uri, 0);
           if (in.hasExtra(GlowPadView.ICON_FILE)) {
             String rSource = in.getStringExtra(GlowPadView.ICON_FILE);
             File fPath = new File(rSource);
             if (fPath != null) {
               if (fPath.exists()) {
                 front = new BitmapDrawable(getResources(), BitmapFactory.decodeFile(rSource));
               }
             }
           } else if (in.hasExtra(GlowPadView.ICON_RESOURCE)) {
             String rSource = in.getStringExtra(GlowPadView.ICON_RESOURCE);
             String rPackage = in.getStringExtra(GlowPadView.ICON_PACKAGE);
             if (rSource != null) {
               if (rPackage != null) {
                 try {
                   Context rContext = mActivity.createPackageContext(rPackage, 0);
                   int id = rContext.getResources().getIdentifier(rSource, "drawable", rPackage);
                   front = rContext.getResources().getDrawable(id);
                   id =
                       rContext
                           .getResources()
                           .getIdentifier(
                               rSource.replaceAll("_normal", "_activated"), "drawable", rPackage);
                   back = rContext.getResources().getDrawable(id);
                   tmpInset = 0;
                   frontBlank = true;
                 } catch (NameNotFoundException e) {
                   e.printStackTrace();
                 } catch (NotFoundException e) {
                   e.printStackTrace();
                 }
               } else {
                 front =
                     mResources.getDrawable(
                         mResources.getIdentifier(rSource, "drawable", "android"));
                 back =
                     mResources.getDrawable(
                         mResources.getIdentifier(
                             rSource.replaceAll("_normal", "_activated"), "drawable", "android"));
                 tmpInset = 0;
                 frontBlank = true;
               }
             }
           }
           if (front == null) {
             ActivityInfo aInfo = in.resolveActivityInfo(packMan, PackageManager.GET_ACTIVITIES);
             if (aInfo != null) {
               front = aInfo.loadIcon(packMan);
             } else {
               front = mResources.getDrawable(android.R.drawable.sym_def_app_icon).mutate();
             }
           }
         } catch (Exception e) {
         }
       }
     } else if (cc >= maxTargets) {
       mTargetStore.add(new TargetInfo(null));
       continue;
     }
     if (back == null || front == null) {
       Drawable emptyIcon = mResources.getDrawable(R.drawable.ic_empty).mutate();
       front = emptyIcon;
     }
     mTargetStore.add(
         new TargetInfo(
             uri,
             getLayeredDrawable(back, front, tmpInset, frontBlank),
             iconType,
             iconSource,
             front.getConstantState().newDrawable().mutate()));
   }
   ArrayList<TargetDrawable> tDraw = new ArrayList<TargetDrawable>();
   for (TargetInfo i : mTargetStore) {
     if (i != null) {
       tDraw.add(new TargetDrawable(mResources, i.icon));
     } else {
       tDraw.add(new TargetDrawable(mResources, null));
     }
   }
   mWaveView.setTargetResources(tDraw);
 }
  boolean startActivityForUrl(Tab tab, String url) {
    Intent intent;
    // perform generic parsing of the URI to turn it into an Intent.
    try {
      intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
    } catch (URISyntaxException ex) {
      Log.w("Browser", "Bad URI " + url + ": " + ex.getMessage());
      return false;
    }

    // check whether the intent can be resolved. If not, we will see
    // whether we can download it from the Market.
    if (mActivity.getPackageManager().resolveActivity(intent, 0) == null) {
      String packagename = intent.getPackage();
      if (packagename != null) {
        intent =
            new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pname:" + packagename));
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        mActivity.startActivity(intent);
        // before leaving BrowserActivity, close the empty child tab.
        // If a new tab is created through JavaScript open to load this
        // url, we would like to close it as we will load this url in a
        // different Activity.
        mController.closeEmptyTab();
        return true;
      } else {
        return false;
      }
    }

    // sanitize the Intent, ensuring web pages can not bypass browser
    // security (only access to BROWSABLE activities).
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.setComponent(null);
    // Re-use the existing tab if the intent comes back to us
    if (tab != null) {
      if (tab.getAppId() == null) {
        tab.setAppId(mActivity.getPackageName() + "-" + tab.getId());
      }
      intent.putExtra(com.stockbrowser.compats.Browser.EXTRA_APPLICATION_ID, tab.getAppId());
    }
    // Make sure webkit can handle it internally before checking for specialized
    // handlers. If webkit can't handle it internally, we need to call
    // startActivityIfNeeded
    Matcher m = UrlUtils.ACCEPTED_URI_SCHEMA.matcher(url);
    if (m.matches() && !isSpecializedHandlerAvailable(intent)) {
      return false;
    }
    try {
      intent.putExtra(BrowserActivity.EXTRA_DISABLE_URL_OVERRIDE, true);
      if (mActivity.startActivityIfNeeded(intent, -1)) {
        // before leaving BrowserActivity, close the empty child tab.
        // If a new tab is created through JavaScript open to load this
        // url, we would like to close it as we will load this url in a
        // different Activity.
        mController.closeEmptyTab();
        return true;
      }
    } catch (ActivityNotFoundException ex) {
      // ignore the error. If no application can handle the URL,
      // eg about:blank, assume the browser can handle it.
    }

    return false;
  }