當前位置: 首頁>>代碼示例>>Java>>正文


Java SparseArray類代碼示例

本文整理匯總了Java中android.util.SparseArray的典型用法代碼示例。如果您正苦於以下問題:Java SparseArray類的具體用法?Java SparseArray怎麽用?Java SparseArray使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SparseArray類屬於android.util包,在下文中一共展示了SparseArray類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractUrlAndPlay

import android.util.SparseArray; //導入依賴的package包/類
/**
 * Extracts link from youtube video ID, so mediaPlayer can play it
 */
private void extractUrlAndPlay() {
    String youtubeLink = Config.YOUTUBE_BASE_URL + videoItem.getId();
    deviceBandwidthSampler.startSampling();

    new YouTubeExtractor(this) {
        @Override
        protected void onExtractionComplete(SparseArray<YtFile> ytFiles, VideoMeta videoMeta) {
            if (ytFiles == null) {
                // Something went wrong we got no urls. Always check this.
                Toast.makeText(YTApplication.getAppContext(), R.string.failed_playback,
                        Toast.LENGTH_SHORT).show();
                extractUrlAndPlay();

            } else {
                deviceBandwidthSampler.stopSampling();
                YtFile ytFile = getBestStream(ytFiles);
                try {
                    if (mMediaPlayer != null) {
                        mMediaPlayer.reset();
                        mMediaPlayer.setDataSource(ytFile.getUrl());
                        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
                        mMediaPlayer.prepare();
                        mMediaPlayer.start();
                        handleSeekBarChange(videoItem.getId());
                        sendBroadcast(videoItem.getDuration());
                    }
                } catch (IOException io) {
                    io.printStackTrace();
                }
            }
        }
    }.execute(youtubeLink);
}
 
開發者ID:pawelpaszki,項目名稱:youtube_background_android,代碼行數:37,代碼來源:BackgroundAudioService.java

示例2: receiveDetections

import android.util.SparseArray; //導入依賴的package包/類
/**
 * Called by the detector to deliver detection results.
 * If your application called for it, this could be a place to check for
 * equivalent detections by tracking TextBlocks that are similar in location and content from
 * previous frames, or reduce noise by eliminating TextBlocks that have not persisted through
 * multiple detections.
 */
@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
    mGraphicOverlay.clear();
    SparseArray<TextBlock> items = detections.getDetectedItems();
    for (int i = 0; i < items.size(); ++i) {
        TextBlock item = items.valueAt(i);
        if (item != null && item.getValue() != null) {
            if (item.getValue().contains("INSTITUTO FEDERAL ELECTORAL")) {
                documentIdentifier.setType(Constants.IFEB);
            } else if (item.getValue().contains("INSTITUTO NACIONAL ELECTORAL")) {
                Log.d("OcrDetectorProcessor", "INE E " + item.getValue());
                documentIdentifier.setType(Constants.IFEE);
            }
        }
        //OcrGraphic graphic = new OcrGraphic(mGraphicOverlay, item);
        //mGraphicOverlay.add(graphic);
    }
}
 
開發者ID:BrandonVargas,項目名稱:AndroidOCRFforID,代碼行數:26,代碼來源:OcrDetectorProcessor.java

示例3: setSource

import android.util.SparseArray; //導入依賴的package包/類
/**
 * Register an indefinite number of sources that will be asynchronously asked for Elements.
 * This will throw {@code IllegalArgumentException} if any circular dependency is detected.
 * @see ElementSource#dependsOn(ElementSource)
 *
 * @param sources one or more ElementSource.
 */
public void setSource(ElementSource... sources) {
    int count = sources.length;
    allSources = Arrays.asList(sources);
    sourceIdMap = new SparseArray<>(count);
    dependencyMap = new SparseArray<>(count);
    reverseDependencyMap = new SparseArray<>(count);
    groups = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        // Assign a unique id to each source, based on its position in the input array.
        sourceIdMap.put(i, sources[i]);
        // Allocate maps for dependencies.
        dependencyMap.put(i, new HashSet<Integer>());
        reverseDependencyMap.put(i, new HashSet<Integer>());
    }

    // Initialize ordered lists.
    computeDependencies();
    computeGroups();
}
 
開發者ID:natario1,項目名稱:Elements,代碼行數:27,代碼來源:ElementAdapter.java

示例4: printActive

import android.util.SparseArray; //導入依賴的package包/類
private void printActive(){
    try {
        Field field = getFragmentManager().getClass().getDeclaredField("mActive");
        field.setAccessible(true);
        SparseArray<Fragment>  active = (SparseArray<Fragment>) field.get(getFragmentManager());
        System.out.println();


        Method method = getFragmentManager().getClass().getDeclaredMethod("getActiveFragments");
        method.setAccessible(true);
        List<Fragment> fragments = (List<Fragment>) method.invoke(getFragmentManager());
        Log.p("mActive", Utils.joinCollections(fragments, ", "));
    } catch (Exception e){

    }
}
 
開發者ID:myl2ning,項目名稱:fragmentnav,代碼行數:17,代碼來源:FmEnter.java

示例5: beginTransition

import android.util.SparseArray; //導入依賴的package包/類
private TransitionState beginTransition(SparseArray<Fragment> firstOutFragments, SparseArray<Fragment> lastInFragments, boolean isBack) {
    int i;
    ensureFragmentsAreInitialized(lastInFragments);
    TransitionState state = new TransitionState();
    state.nonExistentView = new View(this.mManager.mHost.getContext());
    boolean anyTransitionStarted = false;
    for (i = 0; i < firstOutFragments.size(); i++) {
        if (configureTransitions(firstOutFragments.keyAt(i), state, isBack, firstOutFragments, lastInFragments)) {
            anyTransitionStarted = true;
        }
    }
    for (i = 0; i < lastInFragments.size(); i++) {
        int containerId = lastInFragments.keyAt(i);
        if (firstOutFragments.get(containerId) == null && configureTransitions(containerId, state, isBack, firstOutFragments, lastInFragments)) {
            anyTransitionStarted = true;
        }
    }
    if (anyTransitionStarted) {
        return state;
    }
    return null;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:23,代碼來源:BackStackRecord.java

示例6: deleteTimer

import android.util.SparseArray; //導入依賴的package包/類
@ReactMethod
public void deleteTimer(ExecutorToken executorToken, int timerId) {
  synchronized (mTimerGuard) {
    SparseArray<Timer> timersForContext = mTimerIdsToTimers.get(executorToken);
    if (timersForContext == null) {
      return;
    }
    Timer timer = timersForContext.get(timerId);
    if (timer == null) {
      return;
    }
    // We may have already called/removed it
    timersForContext.remove(timerId);
    if (timersForContext.size() == 0) {
      mTimerIdsToTimers.remove(executorToken);
    }
    mTimers.remove(timer);
  }
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:20,代碼來源:Timing.java

示例7: retrieveFromScrap

import android.util.SparseArray; //導入依賴的package包/類
static View retrieveFromScrap(SparseArray<View> scrapViews, int position) {
  int size = scrapViews.size();
  if (size > 0) {
    // See if we still have a view for this position.
    for (int i = 0; i < size; i++) {
      int fromPosition = scrapViews.keyAt(i);
      View view = scrapViews.get(fromPosition);
      if (fromPosition == position) {
        scrapViews.remove(fromPosition);
        return view;
      }
    }
    int index = size - 1;
    View r = scrapViews.valueAt(index);
    scrapViews.remove(scrapViews.keyAt(index));
    return r;
  } else {
    return null;
  }
}
 
開發者ID:LineChen,項目名稱:Week_Calendar,代碼行數:21,代碼來源:RecycleBin.java

示例8: BadgeRenderer

import android.util.SparseArray; //導入依賴的package包/類
public BadgeRenderer(Context context, int iconSizePx) {
    mContext = context;

    Resources res = context.getResources();
    mSize = (int) (SIZE_PERCENTAGE * iconSizePx);
    mCharSize = (int) (CHAR_SIZE_PERCENTAGE * iconSizePx);
    mOffset = (int) (OFFSET_PERCENTAGE * iconSizePx);
    mStackOffsetX = (int) (STACK_OFFSET_PERCENTAGE_X * iconSizePx);
    mStackOffsetY = (int) (STACK_OFFSET_PERCENTAGE_Y * iconSizePx);
    mTextPaint.setTextSize(iconSizePx * TEXT_SIZE_PERCENTAGE);
    mTextPaint.setTextAlign(Paint.Align.CENTER);
    mLargeIconDrawer = new IconDrawer(res.getDimensionPixelSize(R.dimen.badge_small_padding));
    mSmallIconDrawer = new IconDrawer(res.getDimensionPixelSize(R.dimen.badge_large_padding));
    // Measure the text height.
    Rect tempTextHeight = new Rect();
    mTextPaint.getTextBounds("0", 0, 1, tempTextHeight);
    mTextHeight = tempTextHeight.height();

    mBackgroundsWithShadow = new SparseArray<>(3);
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:21,代碼來源:BadgeRenderer.java

示例9: didAddedNewTask

import android.util.SparseArray; //導入依賴的package包/類
public void didAddedNewTask(final int minDate, final SparseArray<ArrayList<Integer>> mids) {
    Utilities.stageQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            if (currentDeletingTaskMids == null && !gettingNewDeleteTask || currentDeletingTaskTime != 0 && minDate < currentDeletingTaskTime) {
                getNewDeleteTask(null);
            }
        }
    });
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            NotificationCenter.getInstance().postNotificationName(NotificationCenter.didCreatedNewDeleteTask, mids);
        }
    });
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:17,代碼來源:MessagesController.java

示例10: findAnotherInfoFromCompare

import android.util.SparseArray; //導入依賴的package包/類
@Test
public void findAnotherInfoFromCompare() {
    final SparseArray<DownloadTask> unStoredTasks = new SparseArray<>();
    final SparseArray<BreakpointInfo> storedInfos = new SparseArray<>();
    storeOnCache = new BreakpointStoreOnCache(storedInfos,
            new HashMap<String, String>(),
            unStoredTasks,
            new ArrayList<Integer>());

    final BreakpointInfo info1 = mock(BreakpointInfo.class);
    final BreakpointInfo info2 = mock(BreakpointInfo.class);
    final DownloadTask task = mock(DownloadTask.class);

    storedInfos.put(insertedId, info1);

    doReturn(true).when(info1).isSameFrom(task);
    doReturn(false).when(info2).isSameFrom(task);

    BreakpointInfo result = storeOnCache.findAnotherInfoFromCompare(task, info1);
    assertThat(result).isNull();
    result = storeOnCache.findAnotherInfoFromCompare(task, info2);
    assertThat(result).isEqualToComparingFieldByField(info1);
}
 
開發者ID:lingochamp,項目名稱:okdownload,代碼行數:24,代碼來源:BreakpointStoreOnCacheTest.java

示例11: BasePool

import android.util.SparseArray; //導入依賴的package包/類
/**
 * Creates a new instance of the pool.
 * @param poolParams pool parameters
 * @param poolStatsTracker
 */
public BasePool(
    MemoryTrimmableRegistry memoryTrimmableRegistry,
    PoolParams poolParams,
    PoolStatsTracker poolStatsTracker) {
  mMemoryTrimmableRegistry = Preconditions.checkNotNull(memoryTrimmableRegistry);
  mPoolParams = Preconditions.checkNotNull(poolParams);
  mPoolStatsTracker = Preconditions.checkNotNull(poolStatsTracker);

  // initialize the buckets
  mBuckets = new SparseArray<Bucket<V>>();
  initBuckets(new SparseIntArray(0));

  mInUseValues = Sets.newIdentityHashSet();

  mFree = new Counter();
  mUsed = new Counter();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:BasePool.java

示例12: ensureCachedScrollSelectorValue

import android.util.SparseArray; //導入依賴的package包/類
private void ensureCachedScrollSelectorValue(int selectorIndex) {
    SparseArray<String> cache = mSelectorIndexToStringCache;
    String scrollSelectorValue = cache.get(selectorIndex);
    if (scrollSelectorValue != null) {
        return;
    }
    if (selectorIndex < mMinValue || selectorIndex > mMaxValue) {
        scrollSelectorValue = "";
    } else {
        if (mDisplayedValues != null) {
            int displayedValueIndex = selectorIndex - mMinValue;
            scrollSelectorValue = mDisplayedValues[displayedValueIndex];
        } else {
            scrollSelectorValue = formatNumber(selectorIndex);
        }
    }
    cache.put(selectorIndex, scrollSelectorValue);
}
 
開發者ID:pooyafaroka,項目名稱:PlusGram,代碼行數:19,代碼來源:NumberPicker.java

示例13: dispatchSaveInstanceState

import android.util.SparseArray; //導入依賴的package包/類
private void dispatchSaveInstanceState(Bundle outState) {
    if (mPresenters.isEmpty()) return;

    SparseArray<Parcelable> presenterStates = new SparseArray<Parcelable>();

    for (WeakReference<MenuPresenter> ref : mPresenters) {
        final MenuPresenter presenter = ref.get();
        if (presenter == null) {
            mPresenters.remove(ref);
        } else {
            final int id = presenter.getId();
            if (id > 0) {
                final Parcelable state = presenter.onSaveInstanceState();
                if (state != null) {
                    presenterStates.put(id, state);
                }
            }
        }
    }

    outState.putSparseParcelableArray(PRESENTER_KEY, presenterStates);
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:23,代碼來源:MenuBuilder.java

示例14: DocumentTabModelImpl

import android.util.SparseArray; //導入依賴的package包/類
/**
 * Construct a DocumentTabModel.
 * @param activityDelegate Delegate to use for accessing the ActivityManager.
 * @param storageDelegate Delegate to use for accessing persistent storage.
 * @param tabCreatorManager Used to create Tabs.
 * @param isIncognito Whether or not the TabList is managing incognito tabs.
 * @param prioritizedTabId ID of the tab to prioritize when loading.
 * @param context Context to use for accessing SharedPreferences.
 */
public DocumentTabModelImpl(ActivityDelegate activityDelegate, StorageDelegate storageDelegate,
        TabCreatorManager tabCreatorManager, boolean isIncognito, int prioritizedTabId,
        Context context) {
    super(isIncognito, false);
    mActivityDelegate = activityDelegate;
    mStorageDelegate = storageDelegate;
    mContext = context;

    mCurrentState = STATE_UNINITIALIZED;
    mTabIdList = new ArrayList<Integer>();
    mEntryMap = new SparseArray<Entry>();
    mHistoricalTabs = new ArrayList<Integer>();

    mLastShownTabId = DocumentUtils.getLastShownTabIdFromPrefs(mContext, isIncognito());

    // Restore the tab list.
    setCurrentState(STATE_READ_RECENT_TASKS_START);
    mStorageDelegate.restoreTabEntries(
            isIncognito, activityDelegate, mEntryMap, mTabIdList, mHistoricalTabs);
    setCurrentState(STATE_READ_RECENT_TASKS_END);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:31,代碼來源:DocumentTabModelImpl.java

示例15: AdRecordStore

import android.util.SparseArray; //導入依賴的package包/類
/**
 * Instantiates a new Bluetooth LE device Ad Record Store.
 *
 * @param adRecords the ad records
 */
public AdRecordStore(final SparseArray<AdRecord> adRecords) {
    mAdRecords = adRecords;

    mLocalNameComplete = AdRecordUtils.getRecordDataAsString(
            mAdRecords.get(AdRecord.TYPE_LOCAL_NAME_COMPLETE));

    mLocalNameShort = AdRecordUtils.getRecordDataAsString(
            mAdRecords.get(AdRecord.TYPE_LOCAL_NAME_SHORT));

}
 
開發者ID:Twelvelines,項目名稱:AndroidMuseumBleManager,代碼行數:16,代碼來源:AdRecordStore.java


注:本文中的android.util.SparseArray類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。