Esempio n. 1
0
  @Test
  public void testSplit() {
    // empty
    assertThat(TextUtils.split("", ",").length, equalTo(0));

    // one value
    assertArrayEquals(TextUtils.split("abc", ","), new String[] {"abc"});

    // two values
    assertArrayEquals(TextUtils.split("abc,def", ","), new String[] {"abc", "def"});

    // two values with space
    assertArrayEquals(TextUtils.split("abc, def", ","), new String[] {"abc", " def"});
  }
  public PersistentCookieStore() {
    cookiePrefs = OkGo.getContext().getSharedPreferences(COOKIE_PREFS, Context.MODE_PRIVATE);
    cookies = new HashMap<>();

    // 将持久化的cookies缓存到内存中,数据结构为 Map<Url.host, Map<Cookie.name, Cookie>>
    Map<String, ?> prefsMap = cookiePrefs.getAll();
    for (Map.Entry<String, ?> entry : prefsMap.entrySet()) {
      if ((entry.getValue()) != null && !entry.getKey().startsWith(COOKIE_NAME_PREFIX)) {
        // 获取url对应的所有cookie的key,用","分割
        String[] cookieNames = TextUtils.split((String) entry.getValue(), ",");
        for (String name : cookieNames) {
          // 根据对应cookie的Key,从xml中获取cookie的真实值
          String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
          if (encodedCookie != null) {
            Cookie decodedCookie = decodeCookie(encodedCookie);
            if (decodedCookie != null) {
              if (!cookies.containsKey(entry.getKey()))
                cookies.put(entry.getKey(), new ConcurrentHashMap<String, Cookie>());
              cookies.get(entry.getKey()).put(name, decodedCookie);
            }
          }
        }
      }
    }
  }
Esempio n. 3
0
 public PreferencesCookieStore(Context paramContext) {
   this.cookiePrefs = paramContext.getSharedPreferences("CookiePrefsFile", 0);
   this.cookies = new ConcurrentHashMap();
   String str1 = this.cookiePrefs.getString("names", null);
   String[] arrayOfString;
   int j;
   if (str1 != null) {
     arrayOfString = TextUtils.split(str1, ",");
     j = arrayOfString.length;
   }
   for (; ; ) {
     if (i >= j) {
       clearExpired(new Date());
       return;
     }
     String str2 = arrayOfString[i];
     String str3 = this.cookiePrefs.getString("cookie_" + str2, null);
     if (str3 != null) {
       Cookie localCookie = decodeCookie(str3);
       if (localCookie != null) {
         this.cookies.put(str2, localCookie);
       }
     }
     i++;
   }
 }
 public int[] getWordWidths() {
   final CharSequence text = getText();
   final Paint p = getPaint();
   final String[] words = TextUtils.split((String) text, " ");
   final int[] widths = new int[words.length];
   for (int i = 0; i < words.length; i++) {
     widths[i] = (int) p.measureText(words[i]);
   }
   return widths;
 }
Esempio n. 5
0
 public static String getLastwords(String srcText, String p) {
   try {
     String[] array = TextUtils.split(srcText, p);
     int index = (array.length - 1 < 0) ? 0 : array.length - 1;
     return array[index];
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
 @Override
 void readSelectionFromBundle(Bundle inBundle, String key) {
   if (inBundle != null) {
     String ids = inBundle.getString(key);
     if (ids != null) {
       String[] splitIds = TextUtils.split(ids, ",");
       selectedIds.clear();
       Collections.addAll(selectedIds, splitIds);
     }
   }
 }
Esempio n. 7
0
  protected static void loadData(Context context, int resId, Map<String, String> map) {
    String[] lines = context.getResources().getStringArray(resId);
    for (String line : lines) {
      String[] fields = TextUtils.split(line, "=");
      if (fields == null || fields.length != 2) {
        continue;
      }

      map.put(fields[0], fields[1]);
    }
  }
  public static String getSearchQueryFeedFullText(String urlTemplate, String query) {
    String[] words = TextUtils.split(query.trim(), "\\s+");

    for (int i = 0; i < words.length; i++) {
      words[i] = "contains ('" + words[i] + "')";
    }

    String condition = TextUtils.join(" AND ", words);

    return getSearchQueryFeedCmisQuery(
        urlTemplate, "SELECT * FROM cmis:document WHERE " + condition);
  }
Esempio n. 9
0
 public static boolean isPositioningViaWifiEnabled(Context context) {
   ContentResolver cr = context.getContentResolver();
   String enabledProviders =
       Settings.Secure.getString(cr, Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
   if (!TextUtils.isEmpty(enabledProviders)) {
     // not the fastest way to do that :)
     String[] providersList = TextUtils.split(enabledProviders, ",");
     for (String provider : providersList) {
       if (LocationManager.NETWORK_PROVIDER.equals(provider)) {
         return true;
       }
     }
   }
   return false;
 }
  /**
   * Appends the given query string on to the existing UriBuilder's query parameters.
   *
   * <p>(e.g., UriBuilder's queryString k1=v1&k2=v2 and given queryString k3=v3&k4=v4, results in
   * k1=v1&k2=v2&k3=v3&k4=v4).
   *
   * @param queryString Key-Value pairs separated by & and = (e.g., k1=v1&k2=v2&k3=k3).
   * @return this UriBuilder object. Useful for chaining.
   */
  public UriBuilder appendQueryString(String queryString) {
    if (queryString == null) {
      return this;
    }

    String[] pairs = TextUtils.split(queryString, UriBuilder.AMPERSAND);
    for (String pair : pairs) {
      String[] splitPair = TextUtils.split(pair, UriBuilder.EQUAL);
      if (splitPair.length == 2) {
        String key = splitPair[0];
        String value = splitPair[1];

        this.queryParameters.add(new QueryParameter(key, value));
      } else if (splitPair.length == 1) {
        String key = splitPair[0];

        this.queryParameters.add(new QueryParameter(key));
      } else {
        Log.w("com.microsoft.live.auth.UriBuilder", "Invalid query parameter: " + pair);
      }
    }

    return this;
  }
  /*
     Get purchased items from local storage
  */
  public static ArrayList<StoreItem> readPurchasedItems(ArrayList<StoreItem> items, Context c) {
    SharedPreferences settings = c.getSharedPreferences(PREFS_NAME, 0);
    String storedItems = settings.getString(PURCHASED_ITEMS_KEYS, "");

    String[] pItems = TextUtils.split(storedItems, "");

    for (int i = 0, j = pItems.length; i < j; i++) {
      for (StoreItem item : items) {
        if (item.googleSKU != null && item.googleSKU.compareTo(pItems[i]) == 0) {
          item.isPurchased = true;
        }
      }
    }

    return items;
  }
 /**
  * load list from SharedPreferences
  *
  * @param context current context
  * @param preKey key
  * @return
  */
 public static <T> ArrayList<T> loadListFromSharedPreferences(Context context, String preKey) {
   ArrayList<T> temp = newArrayList();
   try {
     String serialized =
         PreferenceManager.getDefaultSharedPreferences(context).getString(preKey, "");
     // Changing this one to linkedlist should solve the java.lang.UnsupportedOperationException
     // problem
     LinkedList myList = new LinkedList(Arrays.asList(TextUtils.split(serialized, ",")));
     for (Object s : myList) {
       temp.add((T) s);
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
   return temp;
 }
 /**
  * Get the x-positions of each word in a string.
  *
  * @param text CharSequence to measure.
  * @param offset Distance from left edge of screen. If 0, positions returned are relative to the
  *     left edge of the actual drawn text rather than the screen, or text view.
  * @return Word positions. Even indices are words, the odd being the space positions dividing the
  *     words.
  */
 public float[] getWordPositions(float offset) {
   final CharSequence text = getText();
   final Paint p = getPaint();
   final String[] words = TextUtils.split((String) text, " ");
   final float[] positions = new float[2 * words.length];
   final float spaceWidth = p.measureText(" ");
   // Measure each word, accumulate values to get the left position.
   for (int i = 0; i < words.length; i++) {
     // Add word position.
     positions[2 * i] = offset;
     offset += p.measureText(words[i]);
     // Add space between words.
     positions[2 * i + 1] = offset;
     offset += spaceWidth;
   }
   return positions;
 }
Esempio n. 14
0
 public PersistentCookieStore(Context paramContext) {
   this.mContext = paramContext.getApplicationContext();
   this.mCookiePrefs = paramContext.getSharedPreferences("CookiePrefsFile2", 0);
   this.mCookies = new ConcurrentHashMap();
   CookieSyncManager.createInstance(paramContext);
   String str1 = this.mCookiePrefs.getString("names", null);
   if (str1 != null) {
     for (String str2 : TextUtils.split(str1, ",")) {
       String str3 = this.mCookiePrefs.getString("cookie_" + str2, null);
       if (str3 == null) continue;
       Cookie localCookie = decodeCookie(str3);
       if (localCookie == null) continue;
       this.mCookies.put(str2, localCookie);
     }
     clearExpired(new Date());
   }
 }
 public static void createDbFromSqlStatements(android.content.Context paramContext, String paramString1, SQLiteDatabase.LockedDevice paramLockedDevice, String paramString2, SQLiteDatabase.Arithmetic paramArithmetic, int paramInt, String paramString3)
 {
   int i = 0;
   paramContext = com.tencent.kingkong.support.Context.openOrCreateDatabase(paramContext, paramString1, paramLockedDevice, paramString2, paramArithmetic, 0, null, false);
   paramString1 = TextUtils.split(paramString3, ";\n");
   int j = paramString1.length;
   while (i < j)
   {
     paramLockedDevice = paramString1[i];
     if (!TextUtils.isEmpty(paramLockedDevice)) {
       paramContext.execSQL(paramLockedDevice);
     }
     i += 1;
   }
   paramContext.setVersion(paramInt);
   paramContext.close();
 }
 /**
  * Override to store the given sentence and pass through its mangled representation to the base
  * type.
  */
 @Override
 public void setText(CharSequence text, BufferType type) {
   sentence = (String) text;
   buffType = type;
   currword = -1;
   words = new Vector<String>();
   // strip empty strings
   for (String word : TextUtils.split(text.toString(), " ")) {
     if (!TextUtils.isEmpty(word)) {
       words.add(word);
     }
   }
   super.setText(getMangledSentence(), type);
   // wordPositions = getWordPositions(getTextLeftXCoord(getX()));
   // charPositions = getCharPositions(getTextLeftXCoord(getX()));
   // sentenceRightXPos = getTextLeftXCoord(getX()) +
   // getPaint().measureText((String) text);
   // sentenceLeftXPos = getTextLeftXCoord(getX());
 }
Esempio n. 17
0
    private void loadWords() throws IOException {

      final Resources resources = mHelperContext.getResources();
      InputStream inputStream = resources.openRawResource(R.raw.definitions);
      BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

      try {
        String line;
        while ((line = reader.readLine()) != null) {
          String[] strings = TextUtils.split(line, "-");
          if (strings.length < 2) continue;
          long id = addWord(strings[0].trim(), strings[1].trim());
          if (id < 0) {
            Log.e(TAG, "unable to add word: " + strings[0].trim());
          }
        }
      } finally {
        reader.close();
      }
    }
 public PersistentCookieStore(Context context) {
   int i = 0;
   this.cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, 0);
   this.cookies = new ConcurrentHashMap();
   String string = this.cookiePrefs.getString(COOKIE_NAME_STORE, null);
   if (string != null) {
     String[] split = TextUtils.split(string, ",");
     int length = split.length;
     while (i < length) {
       String str = split[i];
       String string2 = this.cookiePrefs.getString(COOKIE_NAME_PREFIX + str, null);
       if (string2 != null) {
         Cookie decodeCookie = decodeCookie(string2);
         if (decodeCookie != null) {
           this.cookies.put(str, decodeCookie);
         }
       }
       i++;
     }
     clearExpired(new Date());
   }
 }
  /** Construct a persistent cookie store. */
  public PersistentCookieStore(Context context) {
    cookiePrefs = context.getSharedPreferences(COOKIE_PREFS, 0);
    cookies = new ConcurrentHashMap<String, Cookie>();

    // Load any previously stored cookies into the store
    String storedCookieNames = cookiePrefs.getString(COOKIE_NAME_STORE, null);
    if (storedCookieNames != null) {
      String[] cookieNames = TextUtils.split(storedCookieNames, ",");
      for (String name : cookieNames) {
        String encodedCookie = cookiePrefs.getString(COOKIE_NAME_PREFIX + name, null);
        if (encodedCookie != null) {
          Cookie decodedCookie = decodeCookie(encodedCookie);
          if (decodedCookie != null) {
            cookies.put(name, decodedCookie);
          }
        }
      }

      // Clear out expired cookies
      clearExpired(new Date());
    }
  }
Esempio n. 20
0
 public Set zzjE()
 {
     String s = (String)zzy.zzNz.get();
     if (zzMP == null || zzMO == null || !zzMO.equals(s))
     {
         String as[] = TextUtils.split(s, ",");
         HashSet hashset = new HashSet();
         int j = as.length;
         int i = 0;
         while (i < j) 
         {
             String s1 = as[i];
             try
             {
                 hashset.add(Integer.valueOf(Integer.parseInt(s1)));
             }
             catch (NumberFormatException numberformatexception) { }
             i++;
         }
         zzMO = s;
         zzMP = hashset;
     }
     return zzMP;
 }
 public dvt(Context paramContext, Cursor paramCursor, String paramString1, String paramString2, cfm paramcfm, String paramString3, String[] paramArrayOfString)
 {
   super(paramCursor, paramArrayOfString);
   d = paramString1;
   e = paramString2;
   f = paramcfm;
   g = paramContext;
   h = paramString3;
   i = paramCursor.getColumnIndexOrThrow("_id");
   j = paramCursor.getColumnIndexOrThrow("messageId");
   k = paramCursor.getColumnIndexOrThrow("conversation");
   l = paramCursor.getColumnIndexOrThrow("subject");
   m = paramCursor.getColumnIndexOrThrow("snippet");
   n = paramCursor.getColumnIndexOrThrow("fromAddress");
   o = paramCursor.getColumnIndexOrThrow("customFromAddress");
   p = paramCursor.getColumnIndexOrThrow("toAddresses");
   q = paramCursor.getColumnIndexOrThrow("ccAddresses");
   r = paramCursor.getColumnIndexOrThrow("bccAddresses");
   s = paramCursor.getColumnIndexOrThrow("replyToAddresses");
   t = paramCursor.getColumnIndexOrThrow("dateReceivedMs");
   u = paramCursor.getColumnIndexOrThrow("body");
   v = paramCursor.getColumnIndexOrThrow("stylesheet");
   w = paramCursor.getColumnIndexOrThrow("stylesheetRestrictor");
   x = paramCursor.getColumnIndexOrThrow("bodyEmbedsExternalResources");
   y = paramCursor.getColumnIndexOrThrow("labelIds");
   z = paramCursor.getColumnIndexOrThrow("refMessageId");
   A = paramCursor.getColumnIndexOrThrow("isDraft");
   B = paramCursor.getColumnIndexOrThrow("forward");
   C = paramCursor.getColumnIndexOrThrow("joinedAttachmentInfos");
   D = paramCursor.getColumnIndexOrThrow("isUnread");
   E = paramCursor.getColumnIndexOrThrow("isStarred");
   F = paramCursor.getColumnIndexOrThrow("isInOutbox");
   G = paramCursor.getColumnIndexOrThrow("isInSending");
   H = paramCursor.getColumnIndexOrThrow("isInFailed");
   I = paramCursor.getColumnIndexOrThrow("quoteStartPos");
   J = paramCursor.getColumnIndexOrThrow("spamDisplayedReasonType");
   K = paramCursor.getColumnIndexOrThrow("clipped");
   L = paramCursor.getColumnIndexOrThrow("permalink");
   N = paramCursor.getColumnIndexOrThrow("unsubscribeSenderIdentifier");
   M = paramCursor.getColumnIndexOrThrow("isSenderUnsubscribed");
   O = 0;
   P = 0;
   Q = 0;
   T = 0;
   R = 0;
   S = 0;
   U = 0;
   V = paramCursor.getColumnIndexOrThrow("hasEvent");
   W = paramCursor.getColumnIndexOrThrow("eventTitle");
   X = paramCursor.getColumnIndexOrThrow("startTime");
   Y = paramCursor.getColumnIndexOrThrow("endTime");
   Z = paramCursor.getColumnIndexOrThrow("allDay");
   aa = paramCursor.getColumnIndexOrThrow("location");
   ab = paramCursor.getColumnIndexOrThrow("organizer");
   ac = paramCursor.getColumnIndexOrThrow("attendees");
   ad = paramCursor.getColumnIndexOrThrow("icalMethod");
   ae = paramCursor.getColumnIndexOrThrow("responder");
   af = paramCursor.getColumnIndexOrThrow("responseStatus");
   ag = paramCursor.getColumnIndexOrThrow("eventId");
   ah = paramCursor.getColumnIndexOrThrow("showUnauthWarning");
   ai = paramCursor.getColumnIndexOrThrow("isLateReclassified");
   paramContext = super.getExtras();
   paramCursor = new Bundle();
   int i1 = i2;
   if (paramContext.containsKey("status"))
   {
     int i3 = paramContext.getInt("status");
     i1 = i2;
     if (a.get(i3) != null) {
       i1 = ((Integer)a.get(i3)).intValue();
     }
   }
   paramCursor.putInt("cursor_status", i1);
   aq = paramCursor;
   ar = TextUtils.split(ghz.a(g.getContentResolver(), "gmail_senders_excluded_from_block_option", "*****@*****.**"), ",");
 }
 private final String[] b(int paramInt)
 {
   return TextUtils.split(a(paramInt), dpy.b);
 }
Esempio n. 23
0
 public final String[] getSubpathComponents() {
   return TextUtils.split(subpath, SUBPATH_DELIMITER);
 }
  /*
   * 正则获取当前 DataCount,未获取到值则返回原数值
   */
  private int getDataCount(String keyName, String urlString) throws JSONException, IOException {
    /*
     * 1. 定时器链接添加标志 platform=android&auto_timer=30&user_device_id=#{user_device_id}
     * 2. 读取本地缓存头文件
     */
    Map<String, String> headers = ApiHelper.checkResponseHeader(urlString, mAssetsPath);

    String extraParams =
        String.format(
            "platform=android&auto_timer=%d&user_device_id=%d",
            K.kTimerInterval, userJSON.getInt(K.kUserDeviceId));
    String urlSplit = (urlString.contains("?") ? "&" : "?");
    String urlStringWithExtraParams = String.format("%s%s%s", urlString, urlSplit, extraParams);
    Map<String, String> response = HttpUtil.httpGet(urlStringWithExtraParams, headers);

    String keyLastName = keyName + "_last";
    if (!notificationJSON.has(keyName)) {
      notificationJSON.put(keyName, -1);
    }
    if (!notificationJSON.has(keyLastName)) {
      notificationJSON.put(keyLastName, -1);
    }

    int lastCount = notificationJSON.getInt(keyLastName);

    if (response.get(URLs.kCode).equals("200")) {
      /*
       * 1. 缓存头文件信息
       * 2. 服务器响应信息写入本地
       */
      String htmlName = HttpUtil.UrlToFileName(urlString);
      String htmlPath = String.format("%s/%s", mAssetsPath, htmlName);
      String urlKey = urlString.contains("?") ? TextUtils.split(urlString, "?")[0] : urlString;
      ApiHelper.storeResponseHeader(urlKey, mAssetsPath, response);
      String htmlContent = response.get(URLs.kBody);
      htmlContent =
          htmlContent.replace(
              "/javascripts/", String.format("%s/javascripts/", mRelativeAssetsPath));
      htmlContent =
          htmlContent.replace(
              "/stylesheets/", String.format("%s/stylesheets/", mRelativeAssetsPath));
      htmlContent =
          htmlContent.replace("/images/", String.format("%s/images/", mRelativeAssetsPath));
      FileUtil.writeFile(htmlPath, htmlContent);

      String strRegex = "\\bMobileBridge.setDashboardDataCount.+";
      String countRegex = "\\d+";
      Pattern patternString = Pattern.compile(strRegex);
      Pattern patternCount = Pattern.compile(countRegex);
      Matcher matcherString = patternString.matcher(htmlContent);
      matcherString.find();
      String str = matcherString.group();
      Matcher matcherCount = patternCount.matcher(str);
      if (matcherCount.find()) {
        int dataCount = Integer.parseInt(matcherCount.group());
        /*
         * 如果tab_*_last 的值为 -1,表示第一次加载
         */
        if (lastCount == -1) {
          notificationJSON.put(keyLastName, dataCount);
          notificationJSON.put(keyName, 1);
          FileUtil.writeFile(notificationPath, notificationJSON.toString());
        }
        return dataCount;
      } else {
        Log.i("notification", "未匹配到数值");
        return lastCount;
      }
    } else if (response.get("code").equals("304")) {
      Log.i("notification", "当前无通知");
      return lastCount;
    } else {
      Log.i("notification", "网络请求失败");
      return lastCount;
    }
  }