Java Code Examples for android.util.SparseArray#append()

The following examples show how to use android.util.SparseArray#append() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InstantAdapterCore.java    From adapter-kit with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new view by inflating the associated XML layout.
 * 
 * @param context The {@link Context} to use.
 * @param parent The inflated view's parent.
 * @return The {@link View} that was inflated from the layout.
 */
public final View createNewView(final Context context, final ViewGroup parent) {
    View view = mLayoutInflater.inflate(mLayoutResourceId, parent, false);
    SparseArray<Holder> holders = new SparseArray<Holder>();

    int size = mViewIdsAndMetaCache.size();
    for (int i = 0; i < size; i++) {
        int viewId = mViewIdsAndMetaCache.keyAt(i);
        Meta meta = mViewIdsAndMetaCache.get(viewId);
        View viewFromLayout = view.findViewById(viewId);
        if (viewFromLayout == null) {
            String message = String.format("Cannot find View, check the 'viewId' " +
                    "attribute on method %s.%s()",
                        mDataType.getName(), meta.method.getName());
            throw new IllegalStateException(message);
        }
        holders.append(viewId, new Holder(viewFromLayout, meta));
        mAnnotatedViewIds.add(viewId);
    }
    view.setTag(mLayoutResourceId, holders);

    return view;
}
 
Example 2
Source File: CommentsTimeLinePagerAdapter.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public CommentsTimeLinePagerAdapter(CommentsTimeLineFragment fragment, ViewPager viewPager, FragmentManager fm,
                                    SparseArray<Fragment> fragmentList) {
    super(fm);
    this.fragmentList = fragmentList;
    fragmentList.append(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION,
            fragment.getCommentsToMeTimeLineFragment());
    fragmentList.append(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION,
            fragment.getCommentsByMeTimeLineFragment());
    FragmentTransaction transaction = fragment.getChildFragmentManager().beginTransaction();
    if (!fragmentList.get(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION).isAdded())
        transaction.add(viewPager.getId(), fragmentList.get(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION),
                CommentsToMeTimeLineFragment.class.getName());
    if (!fragmentList.get(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION).isAdded())
        transaction.add(viewPager.getId(), fragmentList.get(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION),
                CommentsByMeTimeLineFragment.class.getName());
    if (!transaction.isEmpty()) {
        transaction.commit();
        fragment.getChildFragmentManager().executePendingTransactions();
    }
}
 
Example 3
Source File: Utils.java    From Myna with Apache License 2.0 6 votes vote down vote up
public static SparseArray<File> getDataFiles(final String folderSubPath){
    if(folderSubPath == null || folderSubPath.trim().isEmpty()){
        return null;
    }
    SparseArray<File> files = new SparseArray<>();
    File file = new File(Environment.getExternalStorageDirectory() + folderSubPath);
    if(!file.exists() || !file.isDirectory())
        return null;

    File[] tempFiles = file.listFiles();
    if(tempFiles == null)
        return null;
    int count = 0;
    for(File tempFile : tempFiles){
        if(!tempFile.isDirectory()){
            files.append(count++, tempFile);
        }
    }
    return files;
}
 
Example 4
Source File: InstantAdapterCore.java    From adapter-kit with Apache License 2.0 6 votes vote down vote up
private void executeViewHandlers(final SparseArray<Holder> holders,
        final View parent, final View view, final T instance, final int position) {
    int nViewHandlers = mViewHandlers.size();
    for (int i = 0; i < nViewHandlers; i++) {
        int viewId = mViewHandlers.keyAt(i);
        ViewHandler<T> viewHandler = mViewHandlers.get(viewId);

        if (viewHandler == null) continue;

        if (viewId == mLayoutResourceId) {
            viewHandler.handleView(mAdapter, parent, view, instance, position);
        } else {
            Holder holder = holders.get(viewId);
            View viewWithId = null;
            if (holder != null) {
                viewWithId = holder.view;
            } else {
                viewWithId = view.findViewById(viewId);
                holders.append(viewId, new Holder(viewWithId, null));
            }
            viewHandler.handleView(mAdapter, view, viewWithId, instance, position);
        }
    }
}
 
Example 5
Source File: MapStore.java    From intra42 with Apache License 2.0 6 votes vote down vote up
@NonNull
public Location require(int x, int y, Cluster cluster) {
    if (x < 0 || y < 0)
        throw new ArrayIndexOutOfBoundsException("x= " + String.valueOf(x) + " ; y= " + String.valueOf(y));

    SparseArray<Location> col = super.get(x);
    if (col == null) {
        col = new SparseArray<>(cluster.height);
        super.append(x, col);
        col.append(y, new Location());
        return col.get(y);
    }

    Location cel = col.get(y);
    if (cel == null) {
        cel = new Location();
        col.append(y, cel);
    }
    return cel;
}
 
Example 6
Source File: AndroidPermissionRequester.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private static SparseArray<String[]> generatePermissionsMapping(
        WindowAndroid windowAndroid, int[] contentSettingsTypes) {
    SparseArray<String[]> permissionsToRequest = new SparseArray<>();
    for (int i = 0; i < contentSettingsTypes.length; i++) {
        String[] permissions = PrefServiceBridge.getAndroidPermissionsForContentSetting(
                contentSettingsTypes[i]);
        if (permissions == null) continue;
        List<String> missingPermissions = new ArrayList<>();
        for (int j = 0; j < permissions.length; j++) {
            String permission = permissions[j];
            if (!windowAndroid.hasPermission(permission)) missingPermissions.add(permission);
        }
        if (!missingPermissions.isEmpty()) {
            permissionsToRequest.append(contentSettingsTypes[i],
                    missingPermissions.toArray(new String[missingPermissions.size()]));
        }
    }
    return permissionsToRequest;
}
 
Example 7
Source File: ManagerTest.java    From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test(expected = InvalidFeatureBitMaskException.class)
public void addInvalidFeatureMask() throws InvalidFeatureBitMaskException{
    SparseArray<Class<? extends Feature>> invalidMask = new SparseArray<>(1);
    invalidMask.append(3, Feature.class); //not a power of 2

    Manager.addFeatureToNode((byte) 0x00, invalidMask);
}
 
Example 8
Source File: DefaultBandwidthMeter.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static SparseArray<Long> getInitialBitrateEstimatesForCountry(String countryCode) {
  int[] groupIndices = getCountryGroupIndices(countryCode);
  SparseArray<Long> result = new SparseArray<>(/* initialCapacity= */ 6);
  result.append(C.NETWORK_TYPE_UNKNOWN, DEFAULT_INITIAL_BITRATE_ESTIMATE);
  result.append(C.NETWORK_TYPE_WIFI, DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI[groupIndices[0]]);
  result.append(C.NETWORK_TYPE_2G, DEFAULT_INITIAL_BITRATE_ESTIMATES_2G[groupIndices[1]]);
  result.append(C.NETWORK_TYPE_3G, DEFAULT_INITIAL_BITRATE_ESTIMATES_3G[groupIndices[2]]);
  result.append(C.NETWORK_TYPE_4G, DEFAULT_INITIAL_BITRATE_ESTIMATES_4G[groupIndices[3]]);
  // Assume default Wifi bitrate for Ethernet to prevent using the slower fallback bitrate.
  result.append(
      C.NETWORK_TYPE_ETHERNET, DEFAULT_INITIAL_BITRATE_ESTIMATES_WIFI[groupIndices[0]]);
  return result;
}
 
Example 9
Source File: ViewStatePagerAdapter.java    From ViewStatePagerAdapter with Apache License 2.0 5 votes vote down vote up
static SparseArray<Parcelable> readSparseArray(Parcel in, ClassLoader loader) {
  int size = in.readInt();
  if (size == -1) {
    return null;
  }
  SparseArray<Parcelable> map = new SparseArray<>(size);
  while (size != 0) {
    int key = in.readInt();
    Parcelable value = in.readParcelable(loader);
    map.append(key, value);
    size--;
  }
  return map;
}
 
Example 10
Source File: DocumentDetector.java    From CVScanner with GNU General Public License v3.0 5 votes vote down vote up
@Override
public SparseArray<Document> detect(Frame frame) {
    SparseArray<Document> detections = new SparseArray<>();
    if(frame.getBitmap() != null) {
        Document doc = detectDocument(frame);

        if (doc != null) detections.append(frame.getMetadata().getId(), doc);
    }

    return detections;
}
 
Example 11
Source File: USBMonitor.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * インターフェースを取得する
 * @param interface_id
 * @param altsetting
 * @return
 * @throws IllegalStateException
 */
@SuppressLint("NewApi")
public synchronized UsbInterface getInterface(final int interface_id, final int altsetting)
	throws IllegalStateException {

	checkConnection();
	SparseArray<UsbInterface> intfs = mInterfaces.get(interface_id);
	if (intfs == null) {
		intfs = new SparseArray<UsbInterface>();
		mInterfaces.put(interface_id, intfs);
	}
	UsbInterface intf = intfs.get(altsetting);
	if (intf == null) {
		final UsbDevice device = mWeakDevice.get();
		final int n = device.getInterfaceCount();
		for (int i = 0; i < n; i++) {
			final UsbInterface temp = device.getInterface(i);
			if ((temp.getId() == interface_id) && (temp.getAlternateSetting() == altsetting)) {
				intf = temp;
				break;
			}
		}
		if (intf != null) {
			intfs.append(altsetting, intf);
		}
	}
	return intf;
}
 
Example 12
Source File: ClusterMapContributeEditActivity.java    From intra42 with Apache License 2.0 5 votes vote down vote up
private void setColumnScale(int x, float scale) {
    SparseArray<Location> col = cluster.map.require(x, cluster);
    for (int i = 0; i < cluster.height; i++) {
        Location cel = col.get(i);
        if (cel == null) {
            cel = new Location();
            col.append(i, cel);
        }
        cel.sizeX = scale;
    }
}
 
Example 13
Source File: Calendar.java    From intra42 with Apache License 2.0 5 votes vote down vote up
public static SparseArray<String> getCalendarList(Context context) {

        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
            return null;
        }

        SparseArray<String> calendar = new SparseArray<>();

        final String[] EVENT_PROJECTION = new String[]{
                CalendarContract.Calendars._ID,
                CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
                CalendarContract.Calendars.CALENDAR_COLOR,
                CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL
        };

        final ContentResolver cr = context.getContentResolver();
        final Uri uri = CalendarContract.Calendars.CONTENT_URI;

        Cursor cur = cr.query(uri, EVENT_PROJECTION, null, null, null);
        if (cur == null)
            return null;

        while (cur.moveToNext()) {

            if (cur.getInt(3) < 300)
                continue;

            Long id = cur.getLong(0);
            String name = cur.getString(1);
            calendar.append(id.intValue(), name);
        }

        cur.close();

        return calendar;
    }
 
Example 14
Source File: Manager.java    From BlueSTSDK_Android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * register a new device id or add feature to an already defined device
 * <p>the change will affect only the node discover after this call</p>
 * @param deviceId device type that will use the feature, it can be a new device id
 * @param features array of feature that we will add, the index of the feature will be used
 *                 as feature mask. the feature mask must have only one bit to 1
 * @throws InvalidFeatureBitMaskException throw when a feature is a position that is not a
 * power of 2
 */
public static void addFeatureToNode(byte deviceId,SparseArray<Class<? extends Feature>> features)
        throws InvalidFeatureBitMaskException {
    SparseArray<Class<? extends Feature>> updateMe;
    if(!sFeatureMapDecoder.containsKey(deviceId)){
        updateMe = BLENodeDefines.FeatureCharacteristics.DEFAULT_MASK_TO_FEATURE.clone();
        sFeatureMapDecoder.put(deviceId,updateMe);
    }else{
        updateMe = sFeatureMapDecoder.get(deviceId);
    }//if-else

    SparseArray<Class<? extends Feature>> addMe = features.clone();

    long mask=1;
    //we test all the 32bit of the feature mask
    for(int i=0; i<32; i++ ){
        Class<? extends Feature> featureClass = addMe.get((int)mask);
        if (featureClass != null) {
            updateMe.append((int) mask, featureClass);
            addMe.remove((int)mask);
        }
        mask=mask<<1;
    }//for

    if(addMe.size()!=0)
        throw new InvalidFeatureBitMaskException("Not all elements have a single bit in " +
                "as key");
}
 
Example 15
Source File: SkinCompatDrawableManager.java    From Android-skin-support with MIT License 5 votes vote down vote up
private void addTintListToCache(@NonNull Context context, @DrawableRes int resId,
                                @NonNull ColorStateList tintList) {
    if (mTintLists == null) {
        mTintLists = new WeakHashMap<>();
    }
    SparseArray<ColorStateList> themeTints = mTintLists.get(context);
    if (themeTints == null) {
        themeTints = new SparseArray<>();
        mTintLists.put(context, themeTints);
    }
    themeTints.append(resId, tintList);
}
 
Example 16
Source File: SkinCompatDrawableManager.java    From Android-skin-support with MIT License 5 votes vote down vote up
private void addTintListToCache(@NonNull Context context, @DrawableRes int resId,
                                @NonNull ColorStateList tintList) {
    if (mTintLists == null) {
        mTintLists = new WeakHashMap<>();
    }
    SparseArray<ColorStateList> themeTints = mTintLists.get(context);
    if (themeTints == null) {
        themeTints = new SparseArray<>();
        mTintLists.put(context, themeTints);
    }
    themeTints.append(resId, tintList);
}
 
Example 17
Source File: NonParcelTest.java    From parceler with Apache License 2.0 5 votes vote down vote up
@Test
public void testSparseArray(){

    SparseArray<SubParcel> input = new SparseArray<SubParcel>();

    input.append(1, new SubParcel("name"));
    input.append(2, null);

    SparseArray<SubParcel> exampleSparseArray = Parcels.unwrap(ParcelsTestUtil.wrap(input));
    assertEquals(2, exampleSparseArray.size());

    SubParcel output = exampleSparseArray.get(1);
    assertEquals("name", output.getName());
    assertNull(exampleSparseArray.get(2));
}
 
Example 18
Source File: CommentsTimeLinePagerAdapter.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected String getTag(int position) {
    SparseArray<String> tagList = new SparseArray<String>();
    tagList.append(CommentsTimeLineFragment.COMMENTS_TO_ME_CHILD_POSITION, CommentsToMeTimeLineFragment.class.getName());
    tagList.append(CommentsTimeLineFragment.COMMENTS_BY_ME_CHILD_POSITION, CommentsByMeTimeLineFragment.class.getName());

    return tagList.get(position);
}
 
Example 19
Source File: Calendar.java    From intra42 with Apache License 2.0 4 votes vote down vote up
public static SparseArray<String> getCalendarListPrimary(Context context) {

        if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
            return null;
        }


        SparseArray<String> calendar = new SparseArray<>();

        final String[] EVENT_PROJECTION;
        EVENT_PROJECTION = new String[]{
                CalendarContract.Calendars._ID,
                CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
                CalendarContract.Calendars.CALENDAR_COLOR,
                CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL,
                CalendarContract.Calendars.IS_PRIMARY
        };

        final ContentResolver cr = context.getContentResolver();
        final Uri uri = CalendarContract.Calendars.CONTENT_URI;

        Cursor cur = cr.query(uri, EVENT_PROJECTION, null, null, null);

        while (cur.moveToNext()) {

            if (cur.getInt(3) < 300)
                continue;

            if (cur.getInt(4) != 1)
                continue;


            Long id = cur.getLong(0);
            String name = cur.getString(1);
            calendar.append(id.intValue(), name);
        }

        cur.close();

        return calendar;
    }
 
Example 20
Source File: CameraMetricsCollector.java    From Battery-Metrics with MIT License 4 votes vote down vote up
private static synchronized void startRecord(int hash, SparseArray<Long> container) {
  long startTimeMs = SystemClock.uptimeMillis();
  if (container.get(hash) == null) {
    container.append(hash, startTimeMs);
  }
}