本文整理汇总了Java中android.util.LongSparseArray.put方法的典型用法代码示例。如果您正苦于以下问题:Java LongSparseArray.put方法的具体用法?Java LongSparseArray.put怎么用?Java LongSparseArray.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.util.LongSparseArray
的用法示例。
在下文中一共展示了LongSparseArray.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: walkroundActionMenuTextColor
import android.util.LongSparseArray; //导入方法依赖的package包/类
public static void walkroundActionMenuTextColor(Resources res){
try {
if (Build.VERSION.SDK_INT>=16 && Build.VERSION.SDK_INT <= 19) {
final long key = (((long) -1) << 32) | 0x7f010082;
if(walkroundStateList==null) {
walkroundStateList = ColorStateList.valueOf(Color.rgb(0, 0, 0));
}
Field mColorStateListCacheField = AndroidHack.findField(res, "mColorStateListCache");
mColorStateListCacheField.setAccessible(true);
LongSparseArray mColorStateListCache = (LongSparseArray) mColorStateListCacheField.get(res);
mColorStateListCache.put(key,new WeakReference<>(walkroundStateList));
}
}catch(Throwable e){
e.printStackTrace();
}
}
示例2: buildChannelMap
import android.util.LongSparseArray; //导入方法依赖的package包/类
public static LongSparseArray<XmlTvParser.XmlTvChannel> buildChannelMap(
ContentResolver resolver, String inputId, List<XmlTvParser.XmlTvChannel> channels) {
Uri uri = TvContract.buildChannelsUriForInput(inputId);
String[] projection = {
TvContract.Channels._ID,
TvContract.Channels.COLUMN_DISPLAY_NUMBER
};
LongSparseArray<XmlTvParser.XmlTvChannel> channelMap = new LongSparseArray<>();
try (Cursor cursor = resolver.query(uri, projection, null, null, null)) {
if (cursor == null || cursor.getCount() == 0) {
return null;
}
while (cursor.moveToNext()) {
long channelId = cursor.getLong(0);
String channelNumber = cursor.getString(1);
channelMap.put(channelId, getChannelByNumber(channelNumber, channels));
}
} catch (Exception e) {
Log.d(TAG, "Content provider query: " + Arrays.toString(e.getStackTrace()));
return null;
}
return channelMap;
}
示例3: read
import android.util.LongSparseArray; //导入方法依赖的package包/类
@Override
public LongSparseArray<T> read(JsonReader jsonReader) throws IOException {
if (jsonReader.peek() == JsonToken.NULL) {
jsonReader.nextNull();
return null;
}
LongSparseArray<Object> temp = gson.fromJson(jsonReader, typeOfLongSparseArrayOfObject);
LongSparseArray<T> result = new LongSparseArray<>(temp.size());
long key;
JsonElement tElement;
for (int i = 0, size = temp.size(); i < size; ++i) {
key = temp.keyAt(i);
tElement = gson.toJsonTree(temp.get(key));
result.put(key, (T) JSONUtils.jsonToSimpleObject(tElement.toString(), typeOfT));
}
return result;
}
示例4: load
import android.util.LongSparseArray; //导入方法依赖的package包/类
public static void load(LongSparseArray<SwitchRadiusInfo[]> weirdBendedSwitchesInfo) {
if (weirdBendedSwitchesInfo.size() == 0) {
try {
InputStream is = CurvesDB.class.getResourceAsStream("/curves.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "utf-8"));
CurvesJson.Curves[] curves = new Gson().fromJson(reader, CurvesJson.class).curves;
int pointsCount = 0;
for (CurvesJson.Curves curve : curves) {
SwitchRadiusInfo[] values = new SwitchRadiusInfo[curve.values.length / 2];
for (int i = 0; i < curve.values.length; i += 2) {
values[i / 2] = new SwitchRadiusInfo(curve.values[i], curve.values[i + 1]);
}
pointsCount += curve.values.length / 2;
weirdBendedSwitchesInfo.put(curve.key, values);
}
System.out.println("Loaded " + curves.length + " curves, " + pointsCount + " points.");
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例5: importWorkspace
import android.util.LongSparseArray; //导入方法依赖的package包/类
private boolean importWorkspace() throws Exception {
ArrayList<Long> allScreens = LauncherDbUtils.getScreenIdsFromCursor(
mContext.getContentResolver().query(mOtherScreensUri, null, null, null,
LauncherSettings.WorkspaceScreens.SCREEN_RANK));
// During import we reset the screen IDs to 0-indexed values.
if (allScreens.isEmpty()) {
// No thing to migrate
return false;
}
mHotseatSize = mMaxGridSizeX = mMaxGridSizeY = 0;
// Build screen update
ArrayList<ContentProviderOperation> screenOps = new ArrayList<>();
int count = allScreens.size();
LongSparseArray<Long> screenIdMap = new LongSparseArray<>(count);
for (int i = 0; i < count; i++) {
ContentValues v = new ContentValues();
v.put(LauncherSettings.WorkspaceScreens._ID, i);
v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i);
screenIdMap.put(allScreens.get(i), (long) i);
screenOps.add(ContentProviderOperation.newInsert(
LauncherSettings.WorkspaceScreens.CONTENT_URI).withValues(v).build());
}
mContext.getContentResolver().applyBatch(ProviderConfig.AUTHORITY, screenOps);
importWorkspaceItems(allScreens.get(0), screenIdMap);
GridSizeMigrationTask.markForMigration(mContext, mMaxGridSizeX, mMaxGridSizeY, mHotseatSize);
// Create empty DB flag.
LauncherSettings.Settings.call(mContext.getContentResolver(),
LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG);
return true;
}
示例6: readSparseLongArrayInternal
import android.util.LongSparseArray; //导入方法依赖的package包/类
private void readSparseLongArrayInternal(
LongSparseArray<Integer> outVal, Parcel in, int N) {
while (N > 0) {
final long key = in.readLong();
final int value = in.readInt();
if (LOG_ENABLED) {
Log.i(TAG, "Unmarshalling key=" + key + " value=" + value);
}
outVal.put(key, value);
N--;
}
}
示例7: importWorkspace
import android.util.LongSparseArray; //导入方法依赖的package包/类
public boolean importWorkspace() throws Exception {
ArrayList<Long> allScreens = LauncherDbUtils.getScreenIdsFromCursor(
mContext.getContentResolver().query(mOtherScreensUri, null, null, null,
LauncherSettings.WorkspaceScreens.SCREEN_RANK));
// During import we reset the screen IDs to 0-indexed values.
if (allScreens.isEmpty()) {
// No thing to migrate
return false;
}
mHotseatSize = mMaxGridSizeX = mMaxGridSizeY = 0;
// Build screen update
ArrayList<ContentProviderOperation> screenOps = new ArrayList<>();
int count = allScreens.size();
LongSparseArray<Long> screenIdMap = new LongSparseArray<>(count);
for (int i = 0; i < count; i++) {
ContentValues v = new ContentValues();
v.put(LauncherSettings.WorkspaceScreens._ID, i);
v.put(LauncherSettings.WorkspaceScreens.SCREEN_RANK, i);
screenIdMap.put(allScreens.get(i), (long) i);
screenOps.add(ContentProviderOperation.newInsert(
LauncherSettings.WorkspaceScreens.CONTENT_URI).withValues(v).build());
}
mContext.getContentResolver().applyBatch(ProviderConfig.AUTHORITY, screenOps);
importWorkspaceItems(allScreens.get(0), screenIdMap);
GridSizeMigrationTask.markForMigration(mContext, mMaxGridSizeX, mMaxGridSizeY, mHotseatSize);
// Create empty DB flag.
LauncherSettings.Settings.call(mContext.getContentResolver(),
LauncherSettings.Settings.METHOD_CLEAR_EMPTY_DB_FLAG);
return true;
}
示例8: testWay
import android.util.LongSparseArray; //导入方法依赖的package包/类
public void testWay()
{
OsmLatLon[] p = new OsmLatLon[2];
p[0] = new OsmLatLon(1,2);
p[1] = new OsmLatLon(3,4);
String xml =
"<way id='8' version='1' >\n" +
" <nd ref='2' lat='" + p[0].getLatitude() + "' lon='"+p[0].getLongitude()+"' />\n" +
" <nd ref='3' lat='" + p[1].getLatitude() + "' lon='"+p[1].getLongitude()+"' />\n" +
"</way>";
LongSparseArray<List<LatLon>> expectedGeometry = new LongSparseArray<>();
expectedGeometry.put(8, new ArrayList<>(Arrays.asList(p)));
Element e = parseOne(xml, expectedGeometry);
assertTrue(e instanceof Way);
Way way = (Way) e;
assertEquals(8, way.getId());
assertEquals(1, way.getVersion());
assertEquals(2, way.getNodeIds().size());
assertEquals(2, (long) way.getNodeIds().get(0));
assertEquals(3, (long) way.getNodeIds().get(1));
}
示例9: buildChannelMap
import android.util.LongSparseArray; //导入方法依赖的package包/类
public static LongSparseArray<Channel> buildChannelMap(ContentResolver resolver,
String inputId, List<Channel> channels) {
Uri uri = TvContract.buildChannelsUriForInput(inputId);
String[] projection = {
TvContract.Channels._ID,
TvContract.Channels.COLUMN_DISPLAY_NUMBER
};
LongSparseArray<Channel> channelMap = new LongSparseArray<>();
Cursor cursor = null;
try {
cursor = resolver.query(uri, projection, null, null, null);
if (cursor == null || cursor.getCount() == 0) {
return null;
}
while (cursor.moveToNext()) {
long channelId = cursor.getLong(0);
Log.d(TAG, "BUILD CHANNELS FOR "+channelId);
String channelNumber = cursor.getString(1);
channelMap.put(channelId, getChannelByNumber(channelNumber, channels));
}
} catch (Exception e) {
Log.d(TAG, "Content provider query: " + e.getStackTrace());
return null;
} finally {
if (cursor != null) {
cursor.close();
}
}
return channelMap;
}
示例10: recordEventParams
import android.util.LongSparseArray; //导入方法依赖的package包/类
private static void recordEventParams(final long timeDeltaMs,
final LongSparseArray<List<InputEventParams>> mapping,
@Nullable final InputEventParams newParams) {
final List<InputEventParams> allParams = mapping.get(timeDeltaMs);
if (allParams == null) {
final List<InputEventParams> params = new ArrayList<>();
if (newParams != null) {
params.add(newParams);
}
mapping.put(timeDeltaMs, params);
} else if (newParams != null) {
allParams.add(newParams);
}
}
示例11: buildChannelMap
import android.util.LongSparseArray; //导入方法依赖的package包/类
/**
* Builds a map of available channels.
*
* @param resolver Application's ContentResolver.
* @param inputId The ID of the TV input service that provides this TV channel.
* @return LongSparseArray mapping each channel's {@link TvContract.Channels#_ID} to the
* Channel object.
* @hide
*/
public static LongSparseArray<Channel> buildChannelMap(@NonNull ContentResolver resolver,
@NonNull String inputId) {
Uri uri = TvContract.buildChannelsUriForInput(inputId);
LongSparseArray<Channel> channelMap = new LongSparseArray<>();
Cursor cursor = null;
try {
cursor = resolver.query(uri, Channel.PROJECTION, null, null, null);
if (cursor == null || cursor.getCount() == 0) {
if (DEBUG) {
Log.d(TAG, "Cursor is null or found no results");
}
return null;
}
while (cursor.moveToNext()) {
Channel nextChannel = Channel.fromCursor(cursor);
channelMap.put(nextChannel.getId(), nextChannel);
}
} catch (Exception e) {
Log.d(TAG, "Content provider query: " + Arrays.toString(e.getStackTrace()));
return null;
} finally {
if (cursor != null) {
cursor.close();
}
}
return channelMap;
}
示例12: fetch
import android.util.LongSparseArray; //导入方法依赖的package包/类
private void fetch (ObservableEmitter emitter) {
LongSparseArray<Contact> contacts = new LongSparseArray<>();
Cursor cursor = createCursor();
cursor.moveToFirst();
int idColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts._ID);
int inVisibleGroupColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.IN_VISIBLE_GROUP);
int displayNamePrimaryColumnIndex = cursor.getColumnIndex(DISPLAY_NAME);
int starredColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.STARRED);
int photoColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_URI);
int thumbnailColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI);
while (!cursor.isAfterLast()) {
long id = cursor.getLong(idColumnIndex);
Contact contact = contacts.get(id, null);
if (contact == null) {
contact = new Contact(id);
ColumnMapper.mapInVisibleGroup(cursor, contact, inVisibleGroupColumnIndex);
ColumnMapper.mapDisplayName(cursor, contact, displayNamePrimaryColumnIndex);
ColumnMapper.mapStarred(cursor, contact, starredColumnIndex);
ColumnMapper.mapPhoto(cursor, contact, photoColumnIndex);
ColumnMapper.mapThumbnail(cursor, contact, thumbnailColumnIndex);
Cursor emailCursor = mResolver.query(EMAIL_CONTENT_URI, EMAIL_PROJECTION,
ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", new String[]{String.valueOf(id)}, null);
if(emailCursor != null) {
emailCursor.moveToFirst();
int emailDataColumnIndex = emailCursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA);
while (!emailCursor.isAfterLast()) {
ColumnMapper.mapEmail(emailCursor, contact, emailDataColumnIndex);
emailCursor.moveToNext();
}
emailCursor.close();
}
int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex(HAS_PHONE_NUMBER)));
if (hasPhoneNumber > 0) {
Cursor phoneCursor = mResolver.query(PHONE_CONTENT_URI, NUMBER_PROJECTION,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[]{String.valueOf(id)}, null);
if (phoneCursor != null) {
phoneCursor.moveToFirst();
int phoneNumberColumnIndex = phoneCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
while (!phoneCursor.isAfterLast()) {
ColumnMapper.mapPhoneNumber(phoneCursor, contact, phoneNumberColumnIndex);
phoneCursor.moveToNext();
}
phoneCursor.close();
}
}
contacts.put(id, contact);
}
cursor.moveToNext();
//noinspection unchecked
emitter.onNext(contact);
}
cursor.close();
/*for (int i = 0; i < contacts.size(); i++) {
//noinspection unchecked
emitter.onNext(contacts.valueAt(i));
}*/
emitter.onComplete();
}
示例13: testRelation
import android.util.LongSparseArray; //导入方法依赖的package包/类
public void testRelation()
{
OsmLatLon[] p = new OsmLatLon[5];
p[0] = new OsmLatLon(1,2);
p[1] = new OsmLatLon(3,4);
p[2] = new OsmLatLon(5,6);
p[3] = new OsmLatLon(7,8);
p[4] = new OsmLatLon(9,10);
String xml =
"<relation id='10' version='1'>\n" +
" <member type='relation' ref='4' role=''/>\n" +
" <member type='way' ref='1' role='outer'>\n" +
" <nd lat='" + p[0].getLatitude() + "' lon='"+p[0].getLongitude()+"'/>\n" +
" <nd lat='" + p[1].getLatitude() + "' lon='"+p[1].getLongitude()+"'/>\n" +
" </member>\n" +
" <member type='way' ref='2' role='inner'>\n" +
" <nd lat='" + p[2].getLatitude() + "' lon='"+p[2].getLongitude()+"'/>\n" +
" <nd lat='" + p[3].getLatitude() + "' lon='"+p[3].getLongitude()+"'/>\n" +
" </member>\n" +
" <member type='node' ref='3' role='point'>\n" +
" <nd lat='" + p[4].getLatitude() + "' lon='"+p[4].getLongitude()+"'/>\n" +
" </member>\n" +
"</relation>";
LongSparseArray<List<LatLon>> expectedGeometry = new LongSparseArray<>();
expectedGeometry.put(1, new ArrayList<>(Arrays.asList(new OsmLatLon[]{p[0], p[1]})));
expectedGeometry.put(2, new ArrayList<>(Arrays.asList(new OsmLatLon[]{p[2], p[3]})));
Element e = parseOne(xml, expectedGeometry);
assertTrue(e instanceof Relation);
Relation relation = (Relation) e;
assertEquals(10, relation.getId());
assertEquals(1, relation.getVersion());
assertEquals(4, relation.getMembers().size());
RelationMember rm[] = new RelationMember[relation.getMembers().size()];
relation.getMembers().toArray(rm);
assertEquals(4, rm[0].getRef());
assertEquals(Element.Type.RELATION, rm[0].getType());
assertEquals("", rm[0].getRole());
assertEquals(1, rm[1].getRef());
assertEquals(Element.Type.WAY, rm[1].getType());
assertEquals("outer", rm[1].getRole());
assertEquals(2, rm[2].getRef());
assertEquals(Element.Type.WAY, rm[2].getType());
assertEquals("inner", rm[2].getRole());
assertEquals(3, rm[3].getRef());
assertEquals(Element.Type.NODE, rm[3].getType());
assertEquals("point", rm[3].getRole());
assertNull(relation.getTags());
}
示例14: fetch
import android.util.LongSparseArray; //导入方法依赖的package包/类
private void fetch (Subscriber<? super Contact> subscriber) {
LongSparseArray<Contact> contacts = new LongSparseArray<>();
// Create a new cursor and go to the first position
Cursor cursor = createCursor();
cursor.moveToFirst();
// Get the column indexes
int idxId = cursor.getColumnIndex(ContactsContract.Data.CONTACT_ID);
int idxInVisibleGroup = cursor.getColumnIndex(ContactsContract.Data.IN_VISIBLE_GROUP);
int idxDisplayNamePrimary = cursor.getColumnIndex(ContactsContract.Data.DISPLAY_NAME_PRIMARY);
int idxStarred = cursor.getColumnIndex(ContactsContract.Data.STARRED);
int idxPhoto = cursor.getColumnIndex(ContactsContract.Data.PHOTO_URI);
int idxThumbnail = cursor.getColumnIndex(ContactsContract.Data.PHOTO_THUMBNAIL_URI);
int idxMimetype = cursor.getColumnIndex(ContactsContract.Data.MIMETYPE);
int idxData1 = cursor.getColumnIndex(ContactsContract.Data.DATA1);
// Map the columns to the fields of the contact
while (!cursor.isAfterLast()) {
// Get the id and the contact for this id. The contact may be a null.
long id = cursor.getLong(idxId);
Contact contact = contacts.get(id, null);
if (contact == null) {
// Create a new contact
contact = new Contact(id);
// Map the non collection attributes
mapInVisibleGroup(cursor, contact, idxInVisibleGroup);
mapDisplayName(cursor, contact, idxDisplayNamePrimary);
mapStarred(cursor, contact, idxStarred);
mapPhoto(cursor, contact, idxPhoto);
mapThumbnail(cursor, contact, idxThumbnail);
// Add the contact to the collection
contacts.put(id, contact);
}
// map phone number or email address
String mimetype = cursor.getString(idxMimetype);
switch (mimetype) {
case ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE: {
mapEmail(cursor, contact, idxData1);
break;
}
case ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE: {
mapPhoneNumber(cursor, contact, idxData1);
break;
}
}
cursor.moveToNext();
}
// Close the cursor
cursor.close();
// Emit the contacts
for (int i = 0; i < contacts.size(); i++) {
subscriber.onNext(contacts.valueAt(i));
}
subscriber.onCompleted();
}
示例15: putInto
import android.util.LongSparseArray; //导入方法依赖的package包/类
@Override
public LongSparseArrayIterable<V> putInto(final LongSparseArray<V> other) {
for (final LongSparseArrayEntry<V> entry : this) {
other.put(entry.getKey(), entry.getValue());
}
return this;
}