Java Code Examples for android.os.Bundle.size()

The following are Jave code examples for showing how to use size() of the android.os.Bundle class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: JobSchedulerCompat   File: PersistableBundle.java   View Source Code Vote up 6 votes
public PersistableBundle(Bundle bundle) {
    map = new HashMap<>(bundle.size());
    for (String key : bundle.keySet()) {
        Object value = bundle.get(key);
        if (value == null || value instanceof String || value instanceof Integer || value instanceof Long
                || value instanceof Double || value instanceof Boolean || value instanceof String[]
                || value instanceof int[] || value instanceof long[] || value instanceof double[]
                || value instanceof boolean[]) {
            map.put(key, value);
        } else if (value instanceof Bundle) {
            map.put(key, new PersistableBundle((Bundle) value));
        } else {
            throw new IllegalArgumentException("Unsupported value type key=" + key + " value=" + value);
        }
    }
}
 
Example 2
Project: letv   File: HttpUtils.java   View Source Code Vote up 6 votes
public static String encodePostBody(Bundle bundle, String str) {
    if (bundle == null) {
        return "";
    }
    StringBuilder stringBuilder = new StringBuilder();
    int size = bundle.size();
    int i = -1;
    for (String str2 : bundle.keySet()) {
        int i2 = i + 1;
        Object obj = bundle.get(str2);
        if (obj instanceof String) {
            stringBuilder.append("Content-Disposition: form-data; name=\"" + str2 + "\"" + "\r\n" + "\r\n" + ((String) obj));
            if (i2 < size - 1) {
                stringBuilder.append("\r\n--" + str + "\r\n");
            }
            i = i2;
        } else {
            i = i2;
        }
    }
    return stringBuilder.toString();
}
 
Example 3
Project: letv   File: Util.java   View Source Code Vote up 6 votes
public static String encodePostBody(Bundle bundle, String str) {
    if (bundle == null) {
        return "";
    }
    StringBuilder stringBuilder = new StringBuilder();
    int size = bundle.size();
    int i = -1;
    for (String str2 : bundle.keySet()) {
        int i2 = i + 1;
        Object obj = bundle.get(str2);
        if (obj instanceof String) {
            stringBuilder.append("Content-Disposition: form-data; name=\"" + str2 + "\"" + "\r\n" + "\r\n" + ((String) obj));
            if (i2 < size - 1) {
                stringBuilder.append("\r\n--" + str + "\r\n");
            }
            i = i2;
        } else {
            i = i2;
        }
    }
    return stringBuilder.toString();
}
 
Example 4
Project: IslamicLibraryAndroid   File: DownloadInfo.java   View Source Code Vote up 6 votes
@Nullable
@Override
public Object getChangePayload(int oldItemPosition, int newItemPosition) {
    DownloadInfo newDownload = mNewList.get(newItemPosition);
    DownloadInfo oldDownload = mOldList.get(oldItemPosition);
    Bundle diffBundle = new Bundle();
    if (newDownload.getProgressPercent() != oldDownload.getProgressPercent()) {
        diffBundle.putInt(KEY_PROGRESS_PERCENT_FROM, oldDownload.getProgressPercent());
        diffBundle.putInt(KEY_PROGRESS_PERCENT_TO, newDownload.getProgressPercent());
    }
    if (newDownload.bytesDownloadedSoFar != oldDownload.bytesDownloadedSoFar) {
        diffBundle.putLong(KEY_DOWNLOADED_BYTES, newDownload.bytesDownloadedSoFar);
    }
    if (newDownload.status != oldDownload.status) {
        diffBundle.putInt(KEY_STATUS_RES_ID, newDownload.getStatusTextResId());
        if (newDownload.reason != oldDownload.reason) {
            diffBundle.putInt(KEY_REASON_RES_ID, newDownload.getStatusTextResId());
        }
    }

    if (diffBundle.size() == 0) return null;
    return diffBundle;
}
 
Example 5
Project: toolargetool   File: TooLargeTool.java   View Source Code Vote up 6 votes
/**
 * Measure the sizes of all the values in a typed {@link Bundle} when written to a
 * {@link Parcel}. Returns a map from keys to the sizes, in bytes, of the associated values in
 * the Bundle.
 *
 * @param bundle to measure
 * @return a map from keys to value sizes in bytes
 */
public static Map<String, Integer> valueSizes(@NonNull Bundle bundle) {
    Map<String, Integer> result = new HashMap<>(bundle.size());
    // We measure the size of each value by measuring the total size of the bundle before and
    // after removing that value and calculating the difference. We make a copy of the original
    // bundle so we can put all the original values back at the end. It's not possible to
    // carry out the measurements on the copy because of the way Android parcelables work
    // under the hood where certain objects are actually stored as references.
    Bundle copy = new Bundle(bundle);
    try {
        int bundleSize = sizeAsParcel(bundle);
        // Iterate over copy's keys because we're removing those of the original bundle
        for (String key : copy.keySet()) {
            bundle.remove(key);
            int newBundleSize = sizeAsParcel(bundle);
            int valueSize = bundleSize - newBundleSize;
            result.put(key, valueSize);
            bundleSize = newBundleSize;
        }
        return result;
    } finally {
        // Put everything back into original bundle
        bundle.putAll(copy);
    }
}
 
Example 6
Project: fast-list   File: User.java   View Source Code Vote up 6 votes
public static Object getChangePayload(User oldUser, User newUser) {
  Bundle bundle = new Bundle();
  if (!TextUtils.equals(oldUser.getAvatar(), newUser.getAvatar())) {
    bundle.putString(KEY_AVATAR, newUser.getAvatar());
  }
  if (!TextUtils.equals(oldUser.getName(), newUser.getName())) {
    bundle.putString(KEY_NAME, newUser.getName());
  }
  if (!TextUtils.equals(oldUser.getDesc(), newUser.getDesc())) {
    bundle.putString(KEY_DESC, newUser.getDesc());
  }
  if (bundle.size() == 0) {
    return null;
  }
  Timber.d("getChangePayload | size: %d", bundle.size());
  return bundle;
}
 
Example 7
Project: gmlrva   File: GmlrvaDiffCallback.java   View Source Code Vote up 6 votes
/** {@inheritDoc} */
@Nullable
@Override
public Object getChangePayload(@IntRange(from = 0) final int oldItemPosition,
                               @IntRange(from = 0) final int newItemPosition) {
    final IGenericRecyclerViewLayout oldItem = mOldList.get(oldItemPosition);
    final IGenericRecyclerViewLayout newItem = mNewList.get(newItemPosition);
    final Bundle diffBundle = new Bundle();

    if (!newItem.getTag().equals(oldItem.getTag())) {
        diffBundle.putSerializable(GenericPayload.UPDATE_ITEM, newItem);
    }

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

    return diffBundle;
}
 
Example 8
Project: boohee_v5.6   File: HttpUtils.java   View Source Code Vote up 6 votes
public static String encodePostBody(Bundle bundle, String str) {
    if (bundle == null) {
        return "";
    }
    StringBuilder stringBuilder = new StringBuilder();
    int size = bundle.size();
    int i = -1;
    for (String str2 : bundle.keySet()) {
        int i2 = i + 1;
        Object obj = bundle.get(str2);
        if (obj instanceof String) {
            stringBuilder.append("Content-Disposition: form-data; name=\"" + str2 + com
                    .alipay.sdk.sys.a.e + "\r\n" + "\r\n" + ((String) obj));
            if (i2 < size - 1) {
                stringBuilder.append("\r\n--" + str + "\r\n");
            }
            i = i2;
        } else {
            i = i2;
        }
    }
    return stringBuilder.toString();
}
 
Example 9
Project: boohee_v5.6   File: AppCompatDelegateImplV7.java   View Source Code Vote up 6 votes
private void doInvalidatePanelMenu(int featureId) {
    PanelFeatureState st = getPanelState(featureId, true);
    if (st.menu != null) {
        Bundle savedActionViewStates = new Bundle();
        st.menu.saveActionViewStates(savedActionViewStates);
        if (savedActionViewStates.size() > 0) {
            st.frozenActionViewState = savedActionViewStates;
        }
        st.menu.stopDispatchingItemsChanged();
        st.menu.clear();
    }
    st.refreshMenuContent = true;
    st.refreshDecorView = true;
    if ((featureId == 108 || featureId == 0) && this.mDecorContentParent != null) {
        st = getPanelState(0, false);
        if (st != null) {
            st.isPrepared = false;
            preparePanel(st, null);
        }
    }
}
 
Example 10
Project: TPlayer   File: VSyncRecord.java   View Source Code Vote up 6 votes
public static boolean equals(Bundle a, Bundle b, boolean sameSize) {
    if (a == b) {
        return true;
    }
    if (sameSize && a.size() != b.size()) {
        return false;
    }
    if (a.size() <= b.size()) {
        Bundle smaller = a;
        a = b;
        b = smaller;
    }
    for (String key : a.keySet()) {
        if (sameSize || !isIgnoredKey(key)) {
            if (!b.containsKey(key)) {
                return false;
            }
            //noinspection ConstantConditions
            if (!a.get(key).equals(b.get(key))) {
                return false;
            }
        }
    }
    return true;
}
 
Example 11
Project: q-mail   File: PgpMessageBuilderTest.java   View Source Code Vote up 5 votes
private static void assertIntentEqualsActionAndExtras(Intent expected, Intent actual) {
    Assert.assertEquals(expected.getAction(), actual.getAction());

    Bundle expectedExtras = expected.getExtras();
    Bundle intentExtras = actual.getExtras();

    if (expectedExtras.size() != intentExtras.size()) {
        Assert.assertEquals(expectedExtras.size(), intentExtras.size());
    }

    for (String key : expectedExtras.keySet()) {
        Object intentExtra = intentExtras.get(key);
        Object expectedExtra = expectedExtras.get(key);
        if (intentExtra == null) {
            if (expectedExtra == null) {
                continue;
            }
            Assert.fail("found null for an expected non-null extra: " + key);
        }
        if (intentExtra instanceof long[]) {
            if (!Arrays.equals((long[]) intentExtra, (long[]) expectedExtra)) {
                Assert.assertArrayEquals("error in " + key, (long[]) expectedExtra, (long[]) intentExtra);
            }
        } else {
            if (!intentExtra.equals(expectedExtra)) {
                Assert.assertEquals("error in " + key, expectedExtra, intentExtra);
            }
        }
    }
}
 
Example 12
Project: MedicationReminder   File: BaseFragment.java   View Source Code Vote up 5 votes
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle bundle = getArguments();
    if (bundle != null && bundle.size() > 0) {
        initVariables(bundle);
    }
}
 
Example 13
Project: cordova-plugin-firebase-sdk   File: MessagingComponent.java   View Source Code Vote up 5 votes
public static void initialize(Bundle bundle) {
    Log.i(TAG, "Initializing");
    if ((bundle != null) && (bundle.size() > 1)) {
        if (MessagingComponent.notificationStack == null) {
            MessagingComponent.notificationStack = new ArrayList<Bundle>();
        }
        if (bundle.containsKey("google.message_id")) {
            bundle.putBoolean("tap", true);
            notificationStack.add(bundle);
        }
    }
}
 
Example 14
Project: letv   File: Util.java   View Source Code Vote up 5 votes
public static Statistic upload(Context context, String str, Bundle bundle) throws MalformedURLException, IOException, NetworkUnavailableException, HttpStatusException {
    int size;
    int i;
    byte[] byteArray;
    if (context != null) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
        if (connectivityManager != null) {
            NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            if (activeNetworkInfo == null || !activeNetworkInfo.isAvailable()) {
                throw new NetworkUnavailableException(NetworkUnavailableException.ERROR_INFO);
            }
        }
    }
    Bundle bundle2 = new Bundle(bundle);
    String str2 = "";
    str2 = bundle2.getString("appid_for_getting_config");
    bundle2.remove("appid_for_getting_config");
    HttpClient httpClient = HttpUtils.getHttpClient(context, str2, str);
    HttpUriRequest httpPost = new HttpPost(str);
    Bundle bundle3 = new Bundle();
    for (String str22 : bundle2.keySet()) {
        Object obj = bundle2.get(str22);
        if (obj instanceof byte[]) {
            bundle3.putByteArray(str22, (byte[]) obj);
        }
    }
    httpPost.setHeader(HttpRequest.HEADER_CONTENT_TYPE, "multipart/form-data; boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f");
    httpPost.setHeader("Connection", "Keep-Alive");
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    byteArrayOutputStream.write(getBytesUTF8("--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
    byteArrayOutputStream.write(getBytesUTF8(encodePostBody(bundle2, "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f")));
    if (!bundle3.isEmpty()) {
        size = bundle3.size();
        byteArrayOutputStream.write(getBytesUTF8("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
        i = -1;
        for (String str222 : bundle3.keySet()) {
            i++;
            byteArrayOutputStream.write(getBytesUTF8("Content-Disposition: form-data; name=\"" + str222 + "\"; filename=\"" + "value.file" + "\"" + "\r\n"));
            byteArrayOutputStream.write(getBytesUTF8("Content-Type: application/octet-stream\r\n\r\n"));
            byteArray = bundle3.getByteArray(str222);
            if (byteArray != null) {
                byteArrayOutputStream.write(byteArray);
            }
            if (i < size - 1) {
                byteArrayOutputStream.write(getBytesUTF8("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
            }
        }
    }
    byteArrayOutputStream.write(getBytesUTF8("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f--\r\n"));
    byteArray = byteArrayOutputStream.toByteArray();
    i = byteArray.length + 0;
    byteArrayOutputStream.close();
    httpPost.setEntity(new ByteArrayEntity(byteArray));
    HttpResponse execute = httpClient.execute(httpPost);
    size = execute.getStatusLine().getStatusCode();
    if (size == 200) {
        return new Statistic(a(execute), i);
    }
    throw new HttpStatusException(HttpStatusException.ERROR_INFO + size);
}
 
Example 15
Project: aos-Video   File: VideoInfoShowScraperFragment.java   View Source Code Vote up 5 votes
private HashMap<String, EpisodeTags> toMap(Bundle b) {
    int size = b != null ? b.size() : 0;
    HashMap<String, EpisodeTags> result = new HashMap<String, EpisodeTags>(size);
    if (b != null) {
        b.setClassLoader(BaseTags.class.getClassLoader());
        for (String key : b.keySet()) {
            result.put(key, b.<EpisodeTags>getParcelable(key));
        }
    }
    return result;
}
 
Example 16
Project: aos-Video   File: ManualShowScrappingSearchFragment.java   View Source Code Vote up 5 votes
private HashMap<String, EpisodeTags> toMap(Bundle b) {
    int size = (b!=null) ? b.size() : 0;
    HashMap<String, EpisodeTags> result = new HashMap<String, EpisodeTags>(size);
    if (b != null) {
        b.setClassLoader(BaseTags.class.getClassLoader());
        for (String key : b.keySet()) {
            result.put(key, b.<EpisodeTags>getParcelable(key));
        }
    }
    return result;
}
 
Example 17
Project: android-study   File: DiffUtilUI.java   View Source Code Vote up 5 votes
/**
 * areItemsTheSame()返回true而areContentsTheSame()返回false,也就是说两个对象代表的数据是一条,但是内容更新了。
 */
@Nullable @Override public Object getChangePayload(int oldItemPosition, int newItemPosition) {
  String oldItem = mOldDatas.get(oldItemPosition).getName();
  String newItem = mNewDatas.get(newItemPosition).getName();
  Bundle bundle = new Bundle();
  if (!oldItem.equals(newItem)) {
    bundle.putString("name", newItem);
  }

  if (bundle.size() == 0) {
    return null;
  }
  Log.d("lgq", "getChangePayload");
  return bundle;
}
 
Example 18
Project: AndroidActorModel   File: MessengersMapFromBundle.java   View Source Code Vote up 5 votes
private Map<Class<?>, Messenger> messengersMap(Bundle bundle) throws ClassNotFoundException {
    Map<Class<?>, Messenger> result = new LinkedHashMap<>(bundle.size());
    for (String key : bundle.keySet()) {
        result.put(Class.forName(key), (Messenger) bundle.getParcelable(key));
    }
    return result;
}
 
Example 19
Project: GitHub   File: DiffCallBack.java   View Source Code Vote up 4 votes
/**
 * When {@link #areItemsTheSame(int, int)} returns {@code true} for two items and
 * {@link #areContentsTheSame(int, int)} returns false for them, DiffUtil
 * calls this method to get a payload about the change.
 * <p>
 * 当{@link #areItemsTheSame(int, int)} 返回true,且{@link #areContentsTheSame(int, int)} 返回false时,DiffUtils会回调此方法,
 * 去得到这个Item(有哪些)改变的payload。
 * <p>
 * For example, if you are using DiffUtil with {@link RecyclerView}, you can return the
 * particular field that changed in the item and your
 * {@link android.support.v7.widget.RecyclerView.ItemAnimator ItemAnimator} can use that
 * information to run the correct animation.
 * <p>
 * 例如,如果你用RecyclerView配合DiffUtils,你可以返回  这个Item改变的那些字段,
 * {@link android.support.v7.widget.RecyclerView.ItemAnimator ItemAnimator} 可以用那些信息去执行正确的动画
 * <p>
 * Default implementation returns {@code null}.\
 * 默认的实现是返回null
 *
 * @param oldItemPosition The position of the item in the old list
 * @param newItemPosition The position of the item in the new list
 * @return A payload object that represents the change between the two items.
 * 返回 一个 代表着新老item的改变内容的 payload对象,
 */
@Nullable
@Override
public Object getChangePayload(int oldItemPosition, int newItemPosition) {
    //实现这个方法 就能成为文艺青年中的文艺青年
    // 定向刷新中的部分更新
    // 效率最高
    //只是没有了ItemChange的白光一闪动画,(反正我也觉得不太重要)
    TestBean oldBean = mOldDatas.get(oldItemPosition);
    TestBean newBean = mNewDatas.get(newItemPosition);

    //这里就不用比较核心字段了,一定相等
    Bundle payload = new Bundle();
    if (!oldBean.getDesc().equals(newBean.getDesc())) {
        payload.putString("KEY_DESC", newBean.getDesc());
    }
    if (oldBean.getPic() != newBean.getPic()) {
        payload.putInt("KEY_PIC", newBean.getPic());
    }

    if (payload.size() == 0)//如果没有变化 就传空
        return null;
    return payload;//
}
 
Example 20
Project: boohee_v5.6   File: Util.java   View Source Code Vote up 4 votes
public static Statistic upload(Context context, String str, Bundle bundle) throws
        MalformedURLException, IOException, NetworkUnavailableException, HttpStatusException {
    int size;
    int i;
    byte[] byteArray;
    if (context != null) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService("connectivity");
        if (connectivityManager != null) {
            NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            if (activeNetworkInfo == null || !activeNetworkInfo.isAvailable()) {
                throw new NetworkUnavailableException(NetworkUnavailableException.ERROR_INFO);
            }
        }
    }
    Bundle bundle2 = new Bundle(bundle);
    String str2 = "";
    str2 = bundle2.getString("appid_for_getting_config");
    bundle2.remove("appid_for_getting_config");
    HttpClient httpClient = HttpUtils.getHttpClient(context, str2, str);
    HttpUriRequest httpPost = new HttpPost(str);
    Bundle bundle3 = new Bundle();
    for (String str22 : bundle2.keySet()) {
        Object obj = bundle2.get(str22);
        if (obj instanceof byte[]) {
            bundle3.putByteArray(str22, (byte[]) obj);
        }
    }
    httpPost.setHeader("Content-Type", "multipart/form-data; " +
            "boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f");
    httpPost.setHeader("Connection", "Keep-Alive");
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    byteArrayOutputStream.write(getBytesUTF8("--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
    byteArrayOutputStream.write(getBytesUTF8(encodePostBody(bundle2,
            "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f")));
    if (!bundle3.isEmpty()) {
        size = bundle3.size();
        byteArrayOutputStream.write(getBytesUTF8
                ("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
        i = -1;
        for (String str222 : bundle3.keySet()) {
            i++;
            byteArrayOutputStream.write(getBytesUTF8("Content-Disposition: form-data; " +
                    "name=\"" + str222 + "\"; filename=\"" + "value.file" + a.e + "\r\n"));
            byteArrayOutputStream.write(getBytesUTF8("Content-Type: " +
                    "application/octet-stream\r\n\r\n"));
            byteArray = bundle3.getByteArray(str222);
            if (byteArray != null) {
                byteArrayOutputStream.write(byteArray);
            }
            if (i < size - 1) {
                byteArrayOutputStream.write(getBytesUTF8
                        ("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
            }
        }
    }
    byteArrayOutputStream.write(getBytesUTF8
            ("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f--\r\n"));
    byteArray = byteArrayOutputStream.toByteArray();
    i = byteArray.length + 0;
    byteArrayOutputStream.close();
    httpPost.setEntity(new ByteArrayEntity(byteArray));
    HttpResponse execute = httpClient.execute(httpPost);
    size = execute.getStatusLine().getStatusCode();
    if (size == 200) {
        return new Statistic(a(execute), i);
    }
    throw new HttpStatusException(HttpStatusException.ERROR_INFO + size);
}