android.support.v4.util.LongSparseArray Java Examples

The following examples show how to use android.support.v4.util.LongSparseArray. 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: AppFragment.java    From orWall with GNU General Public License v3.0 6 votes vote down vote up
/**
 * List all disabled application. Meaning: installed app requiring Internet, but NOT in NatRules.
 * It also filters out special apps like orbot and i2p.
 *
 * @return List of AppRule
 */
private List<AppRule> listDisabledApps(LongSparseArray<AppRule> index) {
    PackageManager packageManager = this.getActivity().getPackageManager();
    List<AppRule> pkgList = new ArrayList<>();

    List<PackageInfo> pkgInstalled = packageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);

    for (PackageInfo pkgInfo : pkgInstalled) {
        if (needInternet(pkgInfo) && !isReservedApp(pkgInfo)) {
            if (index.indexOfKey((long) pkgInfo.applicationInfo.uid) < 0) {
                AppRule app = new AppRule(false, pkgInfo.packageName, (long) pkgInfo.applicationInfo.uid, Constants.DB_ONION_TYPE_NONE, false, false);
                app.setAppName(packageManager.getApplicationLabel(pkgInfo.applicationInfo).toString());
                pkgList.add(app);
            }
        }
    }
    return pkgList;
}
 
Example #2
Source File: TileCoverHelperActivity.java    From android-map-sdk with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_map_fragment);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(true);
    }

    MapFragment mapFragment = (MapFragment)getSupportFragmentManager().findFragmentById(R.id.map_fragment);
    if (mapFragment == null) {
        mapFragment = MapFragment.newInstance();
        getSupportFragmentManager().beginTransaction().add(R.id.map_fragment, mapFragment).commit();
    }
    mapFragment.getMapAsync(this);

    overlays = new LongSparseArray<>();
}
 
Example #3
Source File: AbsHListView.java    From Klyph with MIT License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setAdapter( ListAdapter adapter ) {
	if ( adapter != null ) {
		mAdapterHasStableIds = mAdapter.hasStableIds();
		if ( mChoiceMode != ListView.CHOICE_MODE_NONE && mAdapterHasStableIds &&
				mCheckedIdStates == null ) {
			mCheckedIdStates = new LongSparseArray<Integer>();
		}
	}

	if ( mCheckStates != null ) {
		mCheckStates.clear();
	}

	if ( mCheckedIdStates != null ) {
		mCheckedIdStates.clear();
	}
}
 
Example #4
Source File: LottieComposition.java    From atlas with Apache License 2.0 6 votes vote down vote up
private static void parsePrecomps(
    @Nullable JSONArray assetsJson, LottieComposition composition) {
  if (assetsJson == null) {
    return;
  }
  int length = assetsJson.length();
  for (int i = 0; i < length; i++) {
    JSONObject assetJson = assetsJson.optJSONObject(i);
    JSONArray layersJson = assetJson.optJSONArray("layers");
    if (layersJson == null) {
      continue;
    }
    List<Layer> layers = new ArrayList<>(layersJson.length());
    LongSparseArray<Layer> layerMap = new LongSparseArray<>();
    for (int j = 0; j < layersJson.length(); j++) {
      Layer layer = Layer.Factory.newInstance(layersJson.optJSONObject(j), composition);
      layerMap.put(layer.getId(), layer);
      layers.add(layer);
    }
    String id = assetJson.optString("id");
    composition.precomps.put(id, layers);
  }
}
 
Example #5
Source File: AbsHListView.java    From Klyph with MIT License 6 votes vote down vote up
/**
 * Returns the set of checked items ids. The result is only valid if the choice mode has not been set to
 * {@link #CHOICE_MODE_NONE} and the adapter has stable IDs. ({@link ListAdapter#hasStableIds()} == {@code true})
 * 
 * @return A new array which contains the id of each checked item in the list.
 */
public long[] getCheckedItemIds() {
	if ( mChoiceMode == ListView.CHOICE_MODE_NONE || mCheckedIdStates == null || mAdapter == null ) {
		return new long[0];
	}

	final LongSparseArray<Integer> idStates = mCheckedIdStates;
	final int count = idStates.size();
	final long[] ids = new long[count];

	for ( int i = 0; i < count; i++ ) {
		ids[i] = idStates.keyAt( i );
	}

	return ids;
}
 
Example #6
Source File: AbsHListView.java    From Klyph with MIT License 6 votes vote down vote up
/**
 * Constructor called from {@link #CREATOR}
 */
private SavedState( Parcel in ) {
	super( in );
	selectedId = in.readLong();
	firstId = in.readLong();
	viewLeft = in.readInt();
	position = in.readInt();
	width = in.readInt();
	filter = in.readString();
	inActionMode = in.readByte() != 0;
	checkedItemCount = in.readInt();
	checkState = in.readSparseBooleanArray();
	final int N = in.readInt();
	if ( N > 0 ) {
		checkIdState = new LongSparseArray<Integer>();
		for ( int i = 0; i < N; i++ ) {
			final long key = in.readLong();
			final int value = in.readInt();
			checkIdState.put( key, value );
		}
	}
}
 
Example #7
Source File: Transition.java    From Transitions-Everywhere with Apache License 2.0 6 votes vote down vote up
/**
 * Match start/end values by Adapter item ID. Adds matched values to mStartValuesList
 * and mEndValuesList and removes them from unmatchedStart and unmatchedEnd, using
 * startItemIds and endItemIds as a guide for which Views have unique item IDs.
 */
private void matchItemIds(@NonNull ArrayMap<View, TransitionValues> unmatchedStart,
                          @NonNull ArrayMap<View, TransitionValues> unmatchedEnd,
                          @NonNull LongSparseArray<View> startItemIds,
                          @NonNull LongSparseArray<View> endItemIds) {
    int numStartIds = startItemIds.size();
    for (int i = 0; i < numStartIds; i++) {
        View startView = startItemIds.valueAt(i);
        if (startView != null && isValidTarget(startView)) {
            View endView = endItemIds.get(startItemIds.keyAt(i));
            if (endView != null && isValidTarget(endView)) {
                TransitionValues startValues = unmatchedStart.get(startView);
                TransitionValues endValues = unmatchedEnd.get(endView);
                if (startValues != null && endValues != null) {
                    mStartValuesList.add(startValues);
                    mEndValuesList.add(endValues);
                    unmatchedStart.remove(startView);
                    unmatchedEnd.remove(endView);
                }
            }
        }
    }
}
 
Example #8
Source File: SkinCompatDrawableManager.java    From Android-skin-support with MIT License 6 votes vote down vote up
private boolean addDrawableToCache(@NonNull final Context context, final long key,
                                   @NonNull final Drawable drawable) {
    final ConstantState cs = drawable.getConstantState();
    if (cs != null) {
        synchronized (mDrawableCacheLock) {
            LongSparseArray<WeakReference<ConstantState>> cache = mDrawableCaches.get(context);
            if (cache == null) {
                cache = new LongSparseArray<>();
                mDrawableCaches.put(context, cache);
            }
            cache.put(key, new WeakReference<ConstantState>(cs));
        }
        return true;
    }
    return false;
}
 
Example #9
Source File: SkinCompatDrawableManager.java    From Android-skin-support with MIT License 6 votes vote down vote up
private Drawable getCachedDrawable(@NonNull final Context context, final long key) {
    synchronized (mDrawableCacheLock) {
        final LongSparseArray<WeakReference<ConstantState>> cache
                = mDrawableCaches.get(context);
        if (cache == null) {
            return null;
        }

        final WeakReference<ConstantState> wr = cache.get(key);
        if (wr != null) {
            // We have the key, and the secret
            ConstantState entry = wr.get();
            if (entry != null) {
                return entry.newDrawable(context.getResources());
            } else {
                // Our entry has been purged
                cache.delete(key);
            }
        }
    }
    return null;
}
 
Example #10
Source File: SparseArrayUtils.java    From standardlib with Apache License 2.0 5 votes vote down vote up
public static <T> List<T> asList(LongSparseArray<T> sparseArray) {
    if (sparseArray == null) {
        return null;
    }

    ArrayList<T> list = new ArrayList<>(sparseArray.size());
    for (int i = 0; i < sparseArray.size(); i++) {
        list.add(sparseArray.valueAt(i));
    }
    return list;
}
 
Example #11
Source File: AppFragment.java    From orWall with GNU General Public License v3.0 5 votes vote down vote up
private List<AppRule> listSpecialApps(LongSparseArray<AppRule> index) {
    List<AppRule> pkgList = new ArrayList<>();
    Map<String,PackageInfoData> specialApps = PackageInfoData.specialApps();

    for (PackageInfoData pkgInfo: specialApps.values()) {
        if (index.indexOfKey(pkgInfo.getUid()) < 0) {
            AppRule app = new AppRule(false, pkgInfo.getPkgName(), pkgInfo.getUid(), Constants.DB_ONION_TYPE_NONE, false, false);
            app.setAppName(pkgInfo.getName());
            pkgList.add(app);
        }
    }

    return pkgList;
}
 
Example #12
Source File: CategorySelectionTest.java    From BrainPhaser with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets up fake returns for the data sources
 */
public void setUp() {
    mTestAppComponent.inject(this);

    // Fake categories
    mFakeCategories = Arrays.asList(
        new Category(1L, "Englisch", "Verbessere deine Englischkenntnisse und dein Wissen über Englischsprachige Länder. Lerne nützliche Phrasen und Umgangsformen.", "@drawable/englisch"),
        new Category(2L, "Architektur", "Verbessere dein Wissen über berühmte Gebäude, Bauarten und Architekturepochen..", "@drawable/architektur"),
        new Category(3L, "Computer", "Lerne neue, coole Fakten über Computer und Informationstechnologie. Du wirst mit Fragen zu Netzwerken, Hardware, Software, Programmiersprachen und Softwareprojekten getestet.", "@drawable/computer"),
        new Category(4L, "Geographie", "Länder, Kulturen und Traditionen.", "@drawable/englisch")
    );
    Mockito.when(mockCategoryDataSource.getAll()).thenReturn(
        mFakeCategories
    );

    // How many due challenges in above categories
    LongSparseArray<Integer> fakeCounts = new LongSparseArray<>();
    fakeCounts.put(1, 10);
    fakeCounts.put(2, 0);
    fakeCounts.put(3, 11);
    fakeCounts.put(4, 3);
    mockDueChallengeLogic = Mockito.mock(DueChallengeLogic.class);
    Mockito.when(mockDueChallengeLogic.getDueChallengeCounts(Mockito.anyListOf(Category.class))).thenReturn(
        fakeCounts
    );

    Mockito.when(mockLogicFactory.createDueChallengeLogic(org.mockito.Matchers.any(User.class)))
        .thenReturn(mockDueChallengeLogic);

    // Which category should be at which position (pos -> categoryId)
    mPositions.put(4, mFakeCategories.get(1));
    mPositions.put(3, mFakeCategories.get(3));
    mPositions.put(2, mFakeCategories.get(0));
    mPositions.put(1, mFakeCategories.get(2));
}
 
Example #13
Source File: DueChallengeLogic.java    From BrainPhaser with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the amount of due challenges for each category id.
 *
 * @param categories the list of categories
 * @return array that maps category counts to category ids. (Key = CategoryId, Value = Count)
 */
public LongSparseArray<Integer> getDueChallengeCounts(List<Category> categories) {
    LongSparseArray<Integer> dueChallengeCounts = new LongSparseArray<>();
    for (Category category : categories) {
        int challengesDueCount = getDueChallenges(category.getId()).size();
        dueChallengeCounts.put(category.getId(), challengesDueCount);
    }
    return dueChallengeCounts;
}
 
Example #14
Source File: CategoryAdapter.java    From BrainPhaser with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adapter for Listing Categories in a recycler view
 * @param categories list of categories to show
 * @param dueChallengeCounts an SparseArray that maps category ids to their due challenge count.
 * @param listener listener that is notified when a category is clicked.
 */
public CategoryAdapter(List<Category> categories, LongSparseArray<Integer> dueChallengeCounts, SelectionListener listener) {
    mListener = listener;
    mCategories = categories;
    mDueChallengeCounts = dueChallengeCounts;

    setHasStableIds(true);
}
 
Example #15
Source File: LocalLyricsFragment.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
public LongSparseArray<Integer> collectTopPositions() {
    final LongSparseArray<Integer> itemIdTopMap = new LongSparseArray<>();
    int firstVisiblePosition = megaListView.getFirstVisiblePosition();
    for (int i = 0; i < megaListView.getChildCount(); ++i) {
        View child = megaListView.getChildAt(i);
        int position = firstVisiblePosition + i;
        long itemId = megaListView.getAdapter().getItemId(position);
        itemIdTopMap.put(itemId, child.getTop());
    }
    return itemIdTopMap;
}
 
Example #16
Source File: LollipopDrawablesCompat.java    From RippleDrawable with MIT License 5 votes vote down vote up
private static Drawable getCachedDrawable(LongSparseArray<WeakReference<Drawable.ConstantState>> cache,
                                          long key, Resources res) {
    synchronized (mAccessLock) {
        WeakReference<Drawable.ConstantState> wr = cache.get(key);
        if (wr != null) {
            Drawable.ConstantState entry = wr.get();
            if (entry != null) {
                return entry.newDrawable(res);
            } else {
                cache.delete(key);
            }
        }
    }
    return null;
}
 
Example #17
Source File: SkinCompatDrawableManager.java    From Android-skin-support with MIT License 5 votes vote down vote up
public void onConfigurationChanged(@NonNull Context context) {
    synchronized (mDrawableCacheLock) {
        LongSparseArray<WeakReference<ConstantState>> cache = mDrawableCaches.get(context);
        if (cache != null) {
            // Crude, but we'll just clear the cache when the configuration changes
            cache.clear();
        }
    }
}
 
Example #18
Source File: AbsHListView.java    From letv with Apache License 2.0 5 votes vote down vote up
@TargetApi(11)
public void setChoiceMode(int choiceMode) {
    this.mChoiceMode = choiceMode;
    if (VERSION.SDK_INT >= 11 && this.mChoiceActionMode != null) {
        if (VERSION.SDK_INT >= 11) {
            ((ActionMode) this.mChoiceActionMode).finish();
        }
        this.mChoiceActionMode = null;
    }
    if (this.mChoiceMode != 0) {
        if (this.mCheckStates == null) {
            this.mCheckStates = new SparseArrayCompat();
        }
        if (this.mCheckedIdStates == null && this.mAdapter != null && this.mAdapter.hasStableIds()) {
            this.mCheckedIdStates = new LongSparseArray();
        }
        if (VERSION.SDK_INT >= 11 && this.mChoiceMode == 3) {
            clearChoices();
            setLongClickable(true);
        }
    }
}
 
Example #19
Source File: AbsHListView.java    From letv with Apache License 2.0 5 votes vote down vote up
public long[] getCheckedItemIds() {
    if (this.mChoiceMode == 0 || this.mCheckedIdStates == null || this.mAdapter == null) {
        return new long[0];
    }
    LongSparseArray<Integer> idStates = this.mCheckedIdStates;
    int count = idStates.size();
    long[] ids = new long[count];
    for (int i = 0; i < count; i++) {
        ids[i] = idStates.keyAt(i);
    }
    return ids;
}
 
Example #20
Source File: AbsHListView.java    From letv with Apache License 2.0 5 votes vote down vote up
public void setAdapter(ListAdapter adapter) {
    if (adapter != null) {
        this.mAdapterHasStableIds = this.mAdapter.hasStableIds();
        if (this.mChoiceMode != 0 && this.mAdapterHasStableIds && this.mCheckedIdStates == null) {
            this.mCheckedIdStates = new LongSparseArray();
        }
    }
    if (this.mCheckStates != null) {
        this.mCheckStates.clear();
    }
    if (this.mCheckedIdStates != null) {
        this.mCheckedIdStates.clear();
    }
}
 
Example #21
Source File: CompositionLayer.java    From atlas with Apache License 2.0 5 votes vote down vote up
CompositionLayer(LottieDrawable lottieDrawable, Layer layerModel, List<Layer> layerModels,
    LottieComposition composition) {
  super(lottieDrawable, layerModel);

  LongSparseArray<BaseLayer> layerMap =
      new LongSparseArray<>(composition.getLayers().size());

  BaseLayer mattedLayer = null;
  for (int i = layerModels.size() - 1; i >= 0; i--) {
    Layer lm = layerModels.get(i);
    BaseLayer layer = BaseLayer.forModel(lm, lottieDrawable, composition);
    layerMap.put(layer.getLayerModel().getId(), layer);
    if (mattedLayer != null) {
      mattedLayer.setMatteLayer(layer);
      mattedLayer = null;
    } else {
      layers.add(0, layer);
      switch (lm.getMatteType()) {
        case Add:
        case Invert:
          mattedLayer = layer;
          break;
      }
    }
  }

  for (int i = 0; i < layerMap.size(); i++) {
    long key = layerMap.keyAt(i);
    BaseLayer layerView = layerMap.get(key);
    BaseLayer parentLayer = layerMap.get(layerView.getLayerModel().getParentId());
    if (parentLayer != null) {
      layerView.setParentLayer(parentLayer);
    }
  }
}
 
Example #22
Source File: LollipopDrawablesCompat.java    From RippleDrawable with MIT License 5 votes vote down vote up
private static void cacheDrawable(TypedValue value, Resources resources, Resources.Theme theme, boolean isColorDrawable, long key, Drawable drawable, LongSparseArray<WeakReference<Drawable.ConstantState>> caches) {

        Drawable.ConstantState cs = drawable.getConstantState();
        if (cs == null) {
            return;
        }

        synchronized (mAccessLock) {
            caches.put(key, new WeakReference<>(cs));
        }
    }
 
Example #23
Source File: GetContactsFragment.java    From BlackList with Apache License 2.0 5 votes vote down vote up
@Override
protected void addContacts(List<Contact> contacts, LongSparseArray<ContactNumber> singleContactNumbers) {
    // prepare returning arguments - data of the chosen contacts
    ArrayList<String> names = new ArrayList<>();
    ArrayList<String> numbers = new ArrayList<>();
    ArrayList<Integer> types = new ArrayList<>();
    for (Contact contact : contacts) {
        ContactNumber contactNumber = singleContactNumbers.get(contact.id);
        if (contactNumber != null) {
            // add single number of the contact
            names.add(contact.name);
            numbers.add(contactNumber.number);
            types.add(contactNumber.type);
        } else {
            // all numbers of the contact
            for (ContactNumber _contactNumber : contact.numbers) {
                names.add(contact.name);
                numbers.add(_contactNumber.number);
                types.add(_contactNumber.type);
            }
        }
    }

    // return arguments
    Intent intent = new Intent();
    intent.putStringArrayListExtra(CONTACT_NAMES, names);
    intent.putStringArrayListExtra(CONTACT_NUMBERS, numbers);
    intent.putIntegerArrayListExtra(CONTACT_NUMBER_TYPES, types);
    getActivity().setResult(Activity.RESULT_OK, intent);
    getActivity().finish();
}
 
Example #24
Source File: AddContactsFragment.java    From BlackList with Apache License 2.0 5 votes vote down vote up
protected void addContacts(List<Contact> contacts, LongSparseArray<ContactNumber> singleContactNumbers) {
    // if permission is granted
    if (!Permissions.notifyIfNotGranted(getContext(), Permissions.WRITE_EXTERNAL_STORAGE)) {
        ContactsWriter writer = new ContactsWriter(contactType, contacts, singleContactNumbers.clone());
        writer.execute();
    }
}
 
Example #25
Source File: ReactNativeDownloadManagerModule.java    From react-native-simple-download-manager with MIT License 5 votes vote down vote up
public ReactNativeDownloadManagerModule(ReactApplicationContext reactContext) {
    super(reactContext);
    downloader = new Downloader(reactContext);
    appDownloads = new LongSparseArray<>();
    IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE);
    reactContext.registerReceiver(downloadReceiver, filter);
}
 
Example #26
Source File: LocalLyricsFragment.java    From QuickLyric with GNU General Public License v3.0 4 votes vote down vote up
public void addObserver(final LongSparseArray<Integer> itemIdTopMap) {
        final boolean[] firstAnimation = {true};
        final ViewTreeObserver observer = megaListView.getViewTreeObserver();
        observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            public boolean onPreDraw() {
                observer.removeOnPreDrawListener(this);
                firstAnimation[0] = true;
                int firstVisiblePosition = megaListView.getFirstVisiblePosition();
                boolean staticOldViewFound = false;
                boolean descendingViewFound = false;
                int newViewsCounter = 0;
                for (int i = megaListView.getChildCount() - 1; i >= 0; i--) {
                    final View child = megaListView.getChildAt(i);
                    int position = firstVisiblePosition + i;
                    long itemId = getListView().getAdapter().getItemId(position);
                    Integer formerTop = itemIdTopMap.get(itemId);
                    int newTop = child.getTop();
                    int MOVE_DURATION = 500;
                    if (formerTop != null) {
                        if (formerTop != newTop) {
                            int translationY = formerTop - newTop;
                            if (translationY < 0)
                                descendingViewFound = true;
                            child.setTranslationY(translationY);
                            child.animate().setDuration(MOVE_DURATION).translationY(0)
                                    .setListener(firstAnimation[0] ? new AnimatorActionListener(() -> {
                                        mSwiping = false;
                                        getListView().setEnabled(true);
                                    }, AnimatorActionListener.ActionType.END) : null);
                            if (firstAnimation[0]) {
                                firstAnimation[0] = false;
                            }
                        } else if (!staticOldViewFound)
                            staticOldViewFound = true;
                    } else {
                        // Animate new views along with the others. The catch is that they did not
                        // exist in the start state, so we must calculate their starting position
                        // based on neighboring views.
                        int childHeight = child.getHeight() + megaListView.getDividerHeight();
                        boolean isFurthest = true;
                        for (int j = 0; j < itemIdTopMap.size(); j++) {
                            Integer top = itemIdTopMap.valueAt(j);
                            if (top - childHeight > newTop) {
                                isFurthest = false;
                                break;
                            }
                        }
                        formerTop = getViewByPosition(megaListView.getLastVisiblePosition()).getBottom() + (newViewsCounter++ * childHeight);
                        if (descendingViewFound || (staticOldViewFound || (!isFurthest && formerTop < megaListView.getBottom()))) { // if undone
//                            int translationX = formerTop > childHeight ?
//                                    child.getWidth() : 0;
//                            if (translationX == 0 || formerTop < megaListView.getBottom()) {
//                                translationX = 0;
//                                child.setTranslationY(delta);
//                            }
                            child.setTranslationX(child.getWidth());
                            child.animate().setDuration(MOVE_DURATION).translationX(0);
                        } else {
                            child.setTranslationY(formerTop - newTop);
                            child.animate().setDuration(MOVE_DURATION).translationY(0);
                        }
                        if (firstAnimation[0]) {
                            child.animate().setListener(new AnimatorActionListener(() -> {
                                getListView().setEnabled(true);
                                mSwiping = false;
                            }, AnimatorActionListener.ActionType.END));
                            firstAnimation[0] = false;
                        }
                    }
                }
                if (firstAnimation[0]) {
                    mSwiping = false;
                    getListView().setEnabled(true);
                    firstAnimation[0] = false;
                }
                itemIdTopMap.clear();
                return true;
            }
        });
    }
 
Example #27
Source File: ZrcAbsListView.java    From ZrcListView with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
void addScrapView(View scrap, int position) {
	final LayoutParams lp = (LayoutParams) scrap.getLayoutParams();
	if (lp == null) {
		return;
	}
	lp.scrappedFromPosition = position;
	final int viewType = lp.viewType;
	if (!shouldRecycleViewType(viewType)) {
		return;
	}
	final boolean scrapHasTransientState = Build.VERSION.SDK_INT >= 16 ? scrap
			.hasTransientState() : false;
	if (scrapHasTransientState) {
		if (mAdapter != null && mAdapterHasStableIds) {
			if (mTransientStateViewsById == null) {
				mTransientStateViewsById = new LongSparseArray<View>();
			}
			mTransientStateViewsById.put(lp.itemId, scrap);
		} else if (!mDataChanged) {
			if (mTransientStateViews == null) {
				mTransientStateViews = new SparseArrayCompat<View>();
			}
			mTransientStateViews.put(position, scrap);
		} else {
			if (mSkippedScrap == null) {
				mSkippedScrap = new ArrayList<View>();
			}
			mSkippedScrap.add(scrap);
		}
	} else {
		if (mViewTypeCount == 1) {
			mCurrentScrap.add(scrap);
		} else {
			mScrapViews[viewType].add(scrap);
		}
		if (mRecyclerListener != null) {
			mRecyclerListener.onMovedToScrapHeap(scrap);
		}
	}
}
 
Example #28
Source File: ZrcAbsListView.java    From ZrcListView with MIT License 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
void scrapActiveViews() {
	final View[] activeViews = mActiveViews;
	final boolean hasListener = mRecyclerListener != null;
	final boolean multipleScraps = mViewTypeCount > 1;
	ArrayList<View> scrapViews = mCurrentScrap;
	final int count = activeViews.length;
	for (int i = count - 1; i >= 0; i--) {
		final View victim = activeViews[i];
		if (victim != null) {
			final LayoutParams lp = (LayoutParams) victim
					.getLayoutParams();
			int whichScrap = lp.viewType;
			activeViews[i] = null;
			final boolean scrapHasTransientState = Build.VERSION.SDK_INT >= 16 ? victim
					.hasTransientState() : false;
			if (!shouldRecycleViewType(whichScrap)
					|| scrapHasTransientState) {
				if (whichScrap != ITEM_VIEW_TYPE_HEADER_OR_FOOTER
						&& scrapHasTransientState) {
					removeDetachedView(victim, false);
				}
				if (scrapHasTransientState) {
					if (mAdapter != null && mAdapterHasStableIds) {
						if (mTransientStateViewsById == null) {
							mTransientStateViewsById = new LongSparseArray<View>();
						}
						long id = mAdapter
								.getItemId(mFirstActivePosition + i);
						mTransientStateViewsById.put(id, victim);
					} else {
						if (mTransientStateViews == null) {
							mTransientStateViews = new SparseArrayCompat<View>();
						}
						mTransientStateViews.put(mFirstActivePosition
								+ i, victim);
					}
				}
				continue;
			}
			if (multipleScraps) {
				scrapViews = mScrapViews[whichScrap];
			}
			victim.onStartTemporaryDetach();
			lp.scrappedFromPosition = mFirstActivePosition + i;
			scrapViews.add(victim);
			if (hasListener) {
				mRecyclerListener.onMovedToScrapHeap(victim);
			}
		}
	}
	pruneScrapViews();
}
 
Example #29
Source File: LongSparseArrayAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public LongSparseArrayAssert(LongSparseArray actual) {
  super(actual, LongSparseArrayAssert.class);
}
 
Example #30
Source File: ObjectUtils.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
public static boolean isNotEmpty(final android.util.LongSparseArray obj) {
    return !isEmpty(obj);
}