Java Code Examples for android.util.SparseIntArray#put()

The following examples show how to use android.util.SparseIntArray#put() . 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: ObservableListView.java    From WayHoo with Apache License 2.0 6 votes vote down vote up
/**
 * Called by CREATOR.
 */
private SavedState(Parcel in) {
    super(in);
    prevFirstVisiblePosition = in.readInt();
    prevFirstVisibleChildHeight = in.readInt();
    prevScrolledChildrenHeight = in.readInt();
    prevScrollY = in.readInt();
    scrollY = in.readInt();
    childrenHeights = new SparseIntArray();
    final int numOfChildren = in.readInt();
    if (0 < numOfChildren) {
        for (int i = 0; i < numOfChildren; i++) {
            final int key = in.readInt();
            final int value = in.readInt();
            childrenHeights.put(key, value);
        }
    }
}
 
Example 2
Source File: EaseContactAdapter.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
@Override
public Object[] getSections() {
    positionOfSection = new SparseIntArray();
    sectionOfPosition = new SparseIntArray();
    int count = getCount();
    list = new ArrayList<String>();
    list.add(getContext().getString(R.string.search_header));
    positionOfSection.put(0, 0);
    sectionOfPosition.put(0, 0);
    for (int i = 1; i < count; i++) {

        String letter = getItem(i).getInitialLetter();
        int section = list.size() - 1;
        if (list.get(section) != null && !list.get(section).equals(letter)) {
            list.add(letter);
            section++;
            positionOfSection.put(section, i);
        }
        sectionOfPosition.put(i, section);
    }
    return list.toArray(new String[list.size()]);
}
 
Example 3
Source File: GenericThemeEntry.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
private GenericThemeEntry(Parcel in) {
    this.themeId = in.readInt();
    this.fontSizeStyleId = in.readInt();
    int n = in.readInt();
    if (n == -1) {
        this.customAttrs = null;
    } else {
        SparseIntArray attrs = new SparseIntArray();
        for (int i=0; i<n; ++i) {
            int key = in.readInt();
            int value = in.readInt();
            attrs.put(key, value);
        }
        this.customAttrs = attrs;
    }
}
 
Example 4
Source File: NetworkManagementService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private boolean updateFirewallUidRuleLocked(int chain, int uid, int rule) {
    synchronized (mRulesLock) {
        SparseIntArray uidFirewallRules = getUidFirewallRulesLR(chain);

        final int oldUidFirewallRule = uidFirewallRules.get(uid, FIREWALL_RULE_DEFAULT);
        if (DBG) {
            Slog.d(TAG, "oldRule = " + oldUidFirewallRule
                    + ", newRule=" + rule + " for uid=" + uid + " on chain " + chain);
        }
        if (oldUidFirewallRule == rule) {
            if (DBG) Slog.d(TAG, "!!!!! Skipping change");
            // TODO: eventually consider throwing
            return false;
        }

        String ruleName = getFirewallRuleName(chain, rule);
        String oldRuleName = getFirewallRuleName(chain, oldUidFirewallRule);

        if (rule == NetworkPolicyManager.FIREWALL_RULE_DEFAULT) {
            uidFirewallRules.delete(uid);
        } else {
            uidFirewallRules.put(uid, rule);
        }
        return !ruleName.equals(oldRuleName);
    }
}
 
Example 5
Source File: BidiInfoActivity.java    From Tehreer-Android with Apache License 2.0 6 votes vote down vote up
private void writeLineText(SpannableStringBuilder builder, BidiLine line) {
    SparseIntArray visualMap = new SparseIntArray();

    int counter = 1;
    for (BidiRun bidiRun : line.getVisualRuns()) {
        visualMap.put(bidiRun.charStart, counter);
        counter++;
    }

    int runCount = visualMap.size();
    if (runCount > 0) {
        appendText(builder, "Visual Order\n", spansSecondHeading());

        for (int i = 0; i < runCount; i++) {
            int runIndex = visualMap.valueAt(i);
            appendText(builder, "<Run " + runIndex + ">", spansInlineHeading());
            appendText(builder, " ");
        }

        appendText(builder, "\n\n");
    }
}
 
Example 6
Source File: PagerActivity.java    From UltraViewPager with MIT License 5 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    if (buttonView == loopCheckBox) {
        ultraViewPager.setInfiniteLoop(isChecked);
    }
    if (buttonView == autoScrollCheckBox) {
        if (isChecked) {
            SparseIntArray special = new SparseIntArray();
            special.put(0, 5000);
            special.put(1, 1500);
            ultraViewPager.setAutoScroll(2000, special);
        } else
            ultraViewPager.disableAutoScroll();
    }
}
 
Example 7
Source File: SubGroupAdapter.java    From Android-nRF-Mesh-Library with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private SparseArray<SparseIntArray> groupModelsBasedOnAppKeys() {
    final SparseArray<SparseIntArray> groupedKeyModels = new SparseArray<>();
    for (MeshModel model : mModels) {
        for (Integer keyIndex : model.getBoundAppKeyIndexes()) {
            final SparseIntArray sparseIntArr = groupedKeyModels.get(keyIndex, new SparseIntArray());
            final int modelIdCount = sparseIntArr.get(model.getModelId(), 0);
            sparseIntArr.put(model.getModelId(), modelIdCount + 1);
            groupedKeyModels.put(keyIndex, sparseIntArr);
        }
    }
    return groupedKeyModels;
}
 
Example 8
Source File: UDBaseRecyclerView.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 初始化spanCount,并保存
 *
 * @param maxSpanCount
 */
void initSpanSize(int maxSpanCount) {
    mSpanSize = new SparseIntArray();
    int totalCount = getTotalCount();
    for (int i = 0; i < totalCount; i++) {
        int[] size = callCellSize(LuaValue.NIL, i);
        int spanSize = Math.max(0, Math.min(maxSpanCount, size[0]));//0 <= spanSize <= maxSpanCount
        mSpanSize.put(i, spanSize);
    }
}
 
Example 9
Source File: RecyclerObjectPool.java    From Storm with Apache License 2.0 5 votes vote down vote up
protected void moveItems(int fromPosition, int toPosition, int count) {
    final SparseIntArray positions = getPositions();
    int index;
    int value;
    for (int i = fromPosition, delta = 0; i < fromPosition + count; i++, delta++) {
        index = positions.indexOfKey(i);
        if (index >= 0) {
            value = positions.valueAt(index);
            positions.removeAt(index);
            positions.put(toPosition + delta, value);
        }
    }
}
 
Example 10
Source File: GenericByteArrayPoolTest.java    From fresco with MIT License 5 votes vote down vote up
@Before
public void setup() {
  final SparseIntArray bucketSizes = new SparseIntArray();
  bucketSizes.put(32, 2);
  bucketSizes.put(64, 1);
  bucketSizes.put(128, 1);
  mPool =
      new GenericByteArrayPool(
          mock(MemoryTrimmableRegistry.class),
          new PoolParams(128, bucketSizes),
          mock(PoolStatsTracker.class));
}
 
Example 11
Source File: FakeNativeMemoryChunkPool.java    From fresco with MIT License 5 votes vote down vote up
private static SparseIntArray getBucketSizes() {
  final SparseIntArray bucketSizes = new SparseIntArray();
  bucketSizes.put(4, 10);
  bucketSizes.put(8, 10);
  bucketSizes.put(16, 10);
  bucketSizes.put(32, 10);
  return bucketSizes;
}
 
Example 12
Source File: SimpleTest.java    From unmock-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSparseIntArray() {
    SparseIntArray sia = new SparseIntArray();
    sia.put(12, 999);
    sia.put(99, 12);

    assertEquals(999, sia.get(12));
}
 
Example 13
Source File: ChatListAdapter.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
@Override
protected SparseIntArray getLayoutIdMap() {
    SparseIntArray sparseArray = new SparseIntArray();
    sparseArray.put(ChatBean.TYPE_LEFT, R.layout.item_activity_chat_list_left);
    sparseArray.put(ChatBean.TYPE_RIGHT, R.layout.item_activity_chat_list_right);
    return sparseArray;
}
 
Example 14
Source File: IntentUtils.java    From speechutils with Apache License 2.0 5 votes vote down vote up
/**
 * @return table that maps SpeechRecognizer error codes to RecognizerIntent error codes
 */
public static SparseIntArray createErrorCodesServiceToIntent() {
    SparseIntArray errorCodes = new SparseIntArray();
    errorCodes.put(SpeechRecognizer.ERROR_AUDIO, RecognizerIntent.RESULT_AUDIO_ERROR);
    errorCodes.put(SpeechRecognizer.ERROR_CLIENT, RecognizerIntent.RESULT_CLIENT_ERROR);
    errorCodes.put(SpeechRecognizer.ERROR_INSUFFICIENT_PERMISSIONS, RecognizerIntent.RESULT_CLIENT_ERROR);
    errorCodes.put(SpeechRecognizer.ERROR_NETWORK, RecognizerIntent.RESULT_NETWORK_ERROR);
    errorCodes.put(SpeechRecognizer.ERROR_NETWORK_TIMEOUT, RecognizerIntent.RESULT_NETWORK_ERROR);
    errorCodes.put(SpeechRecognizer.ERROR_NO_MATCH, RecognizerIntent.RESULT_NO_MATCH);
    errorCodes.put(SpeechRecognizer.ERROR_RECOGNIZER_BUSY, RecognizerIntent.RESULT_SERVER_ERROR);
    errorCodes.put(SpeechRecognizer.ERROR_SERVER, RecognizerIntent.RESULT_SERVER_ERROR);
    errorCodes.put(SpeechRecognizer.ERROR_SPEECH_TIMEOUT, RecognizerIntent.RESULT_NO_MATCH);
    return errorCodes;
}
 
Example 15
Source File: CursorAdapterX.java    From xdroid with Apache License 2.0 4 votes vote down vote up
private void init() {
    mLayoutId = new SparseIntArray();
    mLayoutId.put(0, android.R.layout.simple_list_item_1);
}
 
Example 16
Source File: TabPersistentStore.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void restoreTab(
        TabRestoreDetails tabToRestore, TabState tabState, boolean setAsActive) {
    // If we don't have enough information about the Tab, bail out.
    boolean isIncognito = isIncognitoTabBeingRestored(tabToRestore, tabState);
    if (tabState == null) {
        if (tabToRestore.isIncognito == null) {
            Log.w(TAG, "Failed to restore tab: not enough info about its type was available.");
            return;
        } else if (isIncognito) {
            Log.i(TAG, "Failed to restore Incognito tab: its TabState could not be restored.");
            return;
        }
    }

    TabModel model = mTabModelSelector.getModel(isIncognito);
    SparseIntArray restoredTabs = isIncognito ? mIncognitoTabsRestored : mNormalTabsRestored;
    int restoredIndex = 0;
    if (tabToRestore.fromMerge) {
        // Put any tabs being merged into this list at the end.
        restoredIndex = mTabModelSelector.getModel(isIncognito).getCount();
    } else if (restoredTabs.size() > 0
            && tabToRestore.originalIndex > restoredTabs.keyAt(restoredTabs.size() - 1)) {
        // If the tab's index is too large, restore it at the end of the list.
        restoredIndex = restoredTabs.size();
    } else {
         // Otherwise try to find the tab we should restore before, if any.
        for (int i = 0; i < restoredTabs.size(); i++) {
            if (restoredTabs.keyAt(i) > tabToRestore.originalIndex) {
                Tab nextTabByIndex = TabModelUtils.getTabById(model, restoredTabs.valueAt(i));
                restoredIndex = nextTabByIndex != null ? model.indexOf(nextTabByIndex) : -1;
                break;
            }
        }
    }

    int tabId = tabToRestore.id;
    if (tabState != null) {
        mTabCreatorManager.getTabCreator(isIncognito).createFrozenTab(
                tabState, tabToRestore.id, restoredIndex);
    } else {
        Log.w(TAG, "Failed to restore TabState; creating Tab with last known URL.");
        Tab fallbackTab = mTabCreatorManager.getTabCreator(isIncognito).createNewTab(
                new LoadUrlParams(tabToRestore.url), TabModel.TabLaunchType.FROM_RESTORE, null);
        tabId = fallbackTab.getId();
        model.moveTab(tabId, restoredIndex);
    }

    // If the tab is being restored from a merge and its index is 0, then the model being
    // merged into doesn't contain any tabs. Select the first tab to avoid having no tab
    // selected. TODO(twellington): The first tab will always be selected. Instead, the tab that
    // was selected in the other model before the merge should be selected after the merge.
    if (setAsActive || (tabToRestore.fromMerge && restoredIndex == 0)) {
        boolean wasIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();
        int selectedModelTabCount = mTabModelSelector.getCurrentModel().getCount();

        TabModelUtils.setIndex(model, TabModelUtils.getTabIndexById(model, tabId));
        boolean isIncognitoTabModelSelected = mTabModelSelector.isIncognitoSelected();

        // Setting the index will cause the tab's model to be selected. Set it back to the model
        // that was selected before setting the index if the index is being set during a merge
        // unless the previously selected model is empty (e.g. showing the empty background
        // view on tablets).
        if (tabToRestore.fromMerge
                && wasIncognitoTabModelSelected != isIncognitoTabModelSelected
                && selectedModelTabCount != 0) {
            mTabModelSelector.selectModel(wasIncognitoTabModelSelected);
        }
    }
    restoredTabs.put(tabToRestore.originalIndex, tabId);
}
 
Example 17
Source File: Nature.java    From emoji-keyboard with Apache License 2.0 4 votes vote down vote up
public static void bindSoftBankEmojis(SparseIntArray map) {
    map.put(0xe030, R.drawable.emoji_1f338);
    map.put(0xe031, R.drawable.emoji_1f531);
    map.put(0xe032, R.drawable.emoji_1f339);
    map.put(0xe033, R.drawable.emoji_1f384);
    map.put(0xe019, R.drawable.emoji_1f3a3);
    map.put(0xe01a, R.drawable.emoji_1f434);
    map.put(0xe048, R.drawable.emoji_26c4);
    map.put(0xe049, R.drawable.emoji_2601);
    map.put(0xe04a, R.drawable.emoji_2600);
    map.put(0xe04b, R.drawable.emoji_2614);
    map.put(0xe04c, R.drawable.emoji_1f313);
    map.put(0xe04d, R.drawable.emoji_1f304);
    map.put(0xe04f, R.drawable.emoji_1f431);
    map.put(0xe050, R.drawable.emoji_1f42f);
    map.put(0xe051, R.drawable.emoji_1f43b);
    map.put(0xe052, R.drawable.emoji_1f429);
    map.put(0xe053, R.drawable.emoji_1f42d);
    map.put(0xe054, R.drawable.emoji_1f433);
    map.put(0xe055, R.drawable.emoji_1f427);
    map.put(0xe10a, R.drawable.emoji_1f419);
    map.put(0xe10b, R.drawable.emoji_1f437);
    map.put(0xe10c, R.drawable.emoji_1f47d);
    map.put(0xe110, R.drawable.emoji_1f331);
    map.put(0xe111, R.drawable.emoji_1f48f);
    map.put(0xe117, R.drawable.emoji_1f386);
    map.put(0xe118, R.drawable.emoji_1f341);
    map.put(0xe119, R.drawable.emoji_1f342);
    map.put(0xe304, R.drawable.emoji_1f337);
    map.put(0xe305, R.drawable.emoji_1f33b);
    map.put(0xe306, R.drawable.emoji_1f490);
    map.put(0xe307, R.drawable.emoji_1f334);
    map.put(0xe308, R.drawable.emoji_1f335);
    map.put(0xe520, R.drawable.emoji_1f42c);
    map.put(0xe521, R.drawable.emoji_1f426);
    map.put(0xe522, R.drawable.emoji_1f420);
    map.put(0xe523, R.drawable.emoji_1f423);
    map.put(0xe524, R.drawable.emoji_1f439);
    map.put(0xe525, R.drawable.emoji_1f41b);
    map.put(0xe526, R.drawable.emoji_1f418);
    map.put(0xe527, R.drawable.emoji_1f428);
    map.put(0xe528, R.drawable.emoji_1f412);
    map.put(0xe529, R.drawable.emoji_1f411);
    map.put(0xe52a, R.drawable.emoji_1f43a);
    map.put(0xe52b, R.drawable.emoji_1f42e);
    map.put(0xe52c, R.drawable.emoji_1f430);
    map.put(0xe52d, R.drawable.emoji_1f40d);
    map.put(0xe52e, R.drawable.emoji_1f414);
    map.put(0xe52f, R.drawable.emoji_1f417);
    map.put(0xe530, R.drawable.emoji_1f42b);
    map.put(0xe531, R.drawable.emoji_1f438);
    map.put(0xe440, R.drawable.emoji_1f387);
    map.put(0xe441, R.drawable.emoji_1f41a);
    map.put(0xe442, R.drawable.emoji_1f390);
    map.put(0xe443, R.drawable.emoji_1f300);
    map.put(0xe444, R.drawable.emoji_1f33e);
    map.put(0xe445, R.drawable.emoji_1f383);
    map.put(0xe446, R.drawable.emoji_1f391);
    map.put(0xe447, R.drawable.emoji_1f343);
}
 
Example 18
Source File: LoginActivity.java    From CC with Apache License 2.0 4 votes vote down vote up
private void sendLoginResult() {
    if (resultSent) {
        return;
    }
    resultSent = true;
    //判断是否为CC调用打开本页面
    if (callId != null) {
        CCResult result;
        if (UserStateManager.getLoginUser() == null) {
            result = CCResult.error("login canceled");
        } else {
            //演示跨app传递自定义类型及各种集合类型
            List<User> list = new ArrayList<>();
            list.add(new User(1, "aaa"));
            list.add(new User(3, "ccc"));
            SparseArray<User> userSparseArray = new SparseArray<>();
            userSparseArray.put(1, new User(1, "a"));
            userSparseArray.put(10, new User(10, "a"));
            userSparseArray.put(30, new User(30, "a"));
            User[][] userArray = new User[5][2];
            SparseIntArray sparseIntArray = new SparseIntArray();
            sparseIntArray.put(1, 111);
            sparseIntArray.put(2, 222);
            Map<String, User> map = new HashMap<>();
            map.put("user1", new User(1, "111"));
            map.put("user2", new User(2, "222"));

            result = CCResult.success(UserStateManager.KEY_USER, UserStateManager.getLoginUser()) //User
                    .addData("list", list) // List<User>
                    .addData("nullObject", null) //null
                    .addData("sparseArray", userSparseArray) //SparseArray<User>
                    .addData("sparseIntArray", sparseIntArray) //SparseIntArray/SparseLongArray
                    .addData("user2Array", userArray) // User[][]
                    .addData("untypedArray", list.toArray()) // Object[]
                    .addData("typedArray", list.toArray(new User[]{})) // User[]
                    .addData("map", map) // Map
            ;
        }
        //为确保不管登录成功与否都会调用CC.sendCCResult,在onDestroy方法中调用
        CC.sendCCResult(callId, result);
    }
}
 
Example 19
Source File: SdlRouterServiceTests.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Test sending UAI to an app whose session id is the same as a removed app
 * but is indeed a different app
 *
 * @see SdlRouterService#sendPacketToRegisteredApp(SdlPacket)
 */
public void testRegisterAppExistingSessionIDDifferentApp() {
	if (Looper.myLooper() == null) {
		Looper.prepare();
	}
	Method method;
	try {
		// create instance of router service
		SdlRouterService sdlRouterService = new SdlRouterService();

		// We need a registered app for this to work
		Message message = Message.obtain();
		SdlRouterService.RegisteredApp app1 = sdlRouterService.new RegisteredApp("12345",message.replyTo);
		SdlRouterService.RegisteredApp app2 = sdlRouterService.new RegisteredApp("12344",message.replyTo);
		HashMap<String,SdlRouterService.RegisteredApp> registeredApps = new HashMap<>();
		registeredApps.put(app1.getAppId(),app1);
		registeredApps.put(app2.getAppId(),app2);

		// set registered apps array
		Field raf = sdlRouterService.getClass().getDeclaredField("registeredApps");
		raf.setAccessible(true);
		raf.set(sdlRouterService, registeredApps);

		// need a session map too
		SparseArray<String> sessionMap = new SparseArray<String>();
		sessionMap.put(1, "12345");
		Field sessionMapField = sdlRouterService.getClass().getDeclaredField("bluetoothSessionMap");
		sessionMapField.setAccessible(true);
		sessionMapField.set(sdlRouterService, sessionMap);

		// set cleaned session map
		SparseIntArray testCleanedMap = new SparseIntArray();
		testCleanedMap.put(1, 12345);
		Field f = sdlRouterService.getClass().getDeclaredField("cleanedSessionMap");
		f.setAccessible(true);
		f.set(sdlRouterService, testCleanedMap);

		// set session hash id map
		SparseIntArray testHashIdMap = new SparseIntArray();
		testHashIdMap.put(1, 12344);
		Field f2 = sdlRouterService.getClass().getDeclaredField("sessionHashIdMap");
		f2.setAccessible(true);
		f2.set(sdlRouterService, testHashIdMap);

		// make sure maps are set and NOT the same
		Assert.assertNotNull(raf.get(sdlRouterService));
		Assert.assertNotNull(sessionMapField.get(sdlRouterService));
		Assert.assertNotNull(f.get(sdlRouterService));
		Assert.assertNotNull(f2.get(sdlRouterService));

		// make da RPC
		UnregisterAppInterface request = new UnregisterAppInterface();
		request.setCorrelationID(SAMPLE_RPC_CORRELATION_ID);

		// build protocol message
		byte[] msgBytes = JsonRPCMarshaller.marshall(request, (byte) version);
		pm = new ProtocolMessage();
		pm.setData(msgBytes);
		pm.setSessionID((byte) sessionId);
		pm.setMessageType(MessageType.RPC);
		pm.setSessionType(SessionType.RPC);
		pm.setFunctionID(FunctionID.getFunctionId(request.getFunctionName()));
		pm.setCorrID(request.getCorrelationID());

		if (request.getBulkData() != null) {
			pm.setBulkData(request.getBulkData());
		}

		// binary frame header
		byte[] data = new byte[12 + pm.getJsonSize()];
		binFrameHeader = SdlPacketFactory.createBinaryFrameHeader(pm.getRPCType(), pm.getFunctionID(), pm.getCorrID(), pm.getJsonSize());
		System.arraycopy(binFrameHeader.assembleHeaderBytes(), 0, data, 0, 12);
		System.arraycopy(pm.getData(), 0, data, 12, pm.getJsonSize());

		// create packet and invoke sendPacketToRegisteredApp
		SdlPacket packet = new SdlPacket(4, false, SdlPacket.FRAME_TYPE_SINGLE, SdlPacket.SERVICE_TYPE_RPC, 0, sessionId, data.length, 123, data);
		packet.setTransportRecord(new TransportRecord(TransportType.BLUETOOTH,null));
		method = sdlRouterService.getClass().getDeclaredMethod("sendPacketToRegisteredApp", SdlPacket.class);
		Boolean success = (Boolean) method.invoke(sdlRouterService, packet);

		// we do not want the UAI packet to be sent. make sure it is dropped
		Assert.assertFalse(success);

	} catch (Exception e) {
		Assert.fail("Exception in sendPacketToRegisteredApp, " + e);
	}
}
 
Example 20
Source File: KeyboardParams.java    From simple-keyboard with Apache License 2.0 4 votes vote down vote up
private static int updateHistogramCounter(final SparseIntArray histogram, final int key) {
    final int index = histogram.indexOfKey(key);
    final int count = (index >= 0 ? histogram.get(key) : 0) + 1;
    histogram.put(key, count);
    return count;
}