本文整理汇总了Java中android.util.ArrayMap.put方法的典型用法代码示例。如果您正苦于以下问题:Java ArrayMap.put方法的具体用法?Java ArrayMap.put怎么用?Java ArrayMap.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.util.ArrayMap
的用法示例。
在下文中一共展示了ArrayMap.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readThisArrayMapXml
import android.util.ArrayMap; //导入方法依赖的package包/类
/**
* Like {@link #readThisMapXml}, but returns an ArrayMap instead of HashMap.
* @hide
*/
public static final ArrayMap<String, ?> readThisArrayMapXml(XmlPullParser parser, String endTag,
String[] name, ReadMapCallback callback)
throws XmlPullParserException, java.io.IOException
{
ArrayMap<String, Object> map = new ArrayMap<>();
int eventType = parser.getEventType();
do {
if (eventType == parser.START_TAG) {
Object val = readThisValueXml(parser, name, callback, true);
map.put(name[0], val);
} else if (eventType == parser.END_TAG) {
if (parser.getName().equals(endTag)) {
return map;
}
throw new XmlPullParserException(
"Expected " + endTag + " end tag at: " + parser.getName());
}
eventType = parser.next();
} while (eventType != parser.END_DOCUMENT);
throw new XmlPullParserException(
"Document ended before " + endTag + " end tag");
}
示例2: addFilter
import android.util.ArrayMap; //导入方法依赖的package包/类
private final void addFilter(ArrayMap<String, F[]> map, String name, F filter) {
F[] array = map.get(name);
if (array == null) {
array = newArray(2);
map.put(name, array);
array[0] = filter;
} else {
final int N = array.length;
int i = N;
while (i > 0 && array[i-1] == null) {
i--;
}
if (i < N) {
array[i] = filter;
} else {
F[] newa = newArray((N*3)/2);
System.arraycopy(array, 0, newa, 0, N);
newa[N] = filter;
map.put(name, newa);
}
}
}
示例3: getBatteryReading
import android.util.ArrayMap; //导入方法依赖的package包/类
public void getBatteryReading(SensorDataListener listener){
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
Intent batteryStatus = context.registerReceiver(null, intentFilter);
int batteryStatusIntExtra = batteryStatus.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
boolean isCharging = batteryStatusIntExtra == BatteryManager.BATTERY_STATUS_CHARGING ||
batteryStatusIntExtra == BatteryManager.BATTERY_STATUS_FULL;
int chargePlug = batteryStatus.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1);
boolean usbCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_USB;
boolean acCharge = chargePlug == BatteryManager.BATTERY_PLUGGED_AC;
int level = batteryStatus.getIntExtra(BatteryManager.EXTRA_LEVEL, -1);
int scale = batteryStatus.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
float batteryPct = level / (float)scale;
Log.i(TAG, "AC connected: "+acCharge);
Log.i(TAG, "USB connected: "+usbCharge);
Log.i(TAG, "Battery charging: "+ isCharging);
Log.i(TAG, "Battery Level: "+ batteryPct);
ArrayMap<String, String> map = new ArrayMap<>(3);
map.put(SENSOR, "Battery");
map.put(VALUE, Integer.toString(level));
map.put(UNIT, BATTERYSENSOR_UNIT);
map.put("charging", Boolean.toString(isCharging));
map.put("acPlugged", Boolean.toString(acCharge));
map.put("usbPlugged", Boolean.toString(usbCharge));
listener.sensorData(map);
}
示例4: readThisArrayMapXml
import android.util.ArrayMap; //导入方法依赖的package包/类
/**
* Like {@link #readThisMapXml}, but returns an ArrayMap instead of HashMap.
* @hide
*/
@TargetApi(Build.VERSION_CODES.KITKAT)
public static final ArrayMap<String, ?> readThisArrayMapXml(XmlPullParser parser, String endTag,
String[] name, ReadMapCallback callback)
throws XmlPullParserException, IOException
{
ArrayMap<String, Object> map = new ArrayMap<>();
int eventType = parser.getEventType();
do {
if (eventType == parser.START_TAG) {
Object val = readThisValueXml(parser, name, callback, true);
map.put(name[0], val);
} else if (eventType == parser.END_TAG) {
if (parser.getName().equals(endTag)) {
return map;
}
throw new XmlPullParserException(
"Expected " + endTag + " end tag at: " + parser.getName());
}
eventType = parser.next();
} while (eventType != parser.END_DOCUMENT);
throw new XmlPullParserException(
"Document ended before " + endTag + " end tag");
}
示例5: updateResourceKeys
import android.util.ArrayMap; //导入方法依赖的package包/类
@TargetApi(NOUGAT)
private static void updateResourceKeys(Context context, String originalResourcePath)
throws InvocationTargetException, IllegalAccessException, NoSuchFieldException, IOException {
List<String> exoResourcePaths = getExoPaths(context);
if (exoResourcePaths.isEmpty()) {
return;
}
String resDir = exoResourcePaths.get(0);
String[] splitResDirs =
exoResourcePaths
.subList(1, exoResourcePaths.size())
.toArray(new String[exoResourcePaths.size() - 1]);
ArrayMap<?, ?> resourceImpls = ResourcesManagerInternal.getInstance().getResourceImpls();
ArrayMap<Object, Object> newResourceImpls = new ArrayMap<>(resourceImpls.size());
for (Map.Entry<?, ?> entry : resourceImpls.entrySet()) {
Object key = entry.getKey();
ResourcesKeyInternal keyInternal = new ResourcesKeyInternal(key);
if (keyInternal.getResDir().equals(originalResourcePath)) {
keyInternal.setResDir(resDir);
keyInternal.setSplitResDirs(splitResDirs);
newResourceImpls.put(key, entry.getValue());
}
}
ResourcesManagerInternal.getInstance().setResourceImpls(newResourceImpls);
}
示例6: unZipAll
import android.util.ArrayMap; //导入方法依赖的package包/类
public void unZipAll(File outPath) throws FileNotFoundException, IOException {
FileInputStream fis= new FileInputStream(zipFile);
CheckedInputStream cos = new CheckedInputStream(fis, checksum);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(cos));
ArrayMap<String,File> files=new ArrayMap<>();
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
String entryName=entry.getName();
files.put(entryName, new File(outPath, entryName));
}
zis.close();
unZip(files);
}
示例7: addFileToMap
import android.util.ArrayMap; //导入方法依赖的package包/类
private void addFileToMap(ArrayMap<String,File> size, String namePerfix, File dir) {
for (File f:dir.listFiles()) {
String fname=f.getName();
if (f.isFile()) {
size.put(namePerfix + fname, f);
} else if (f.isDirectory()) {
size.put(namePerfix + fname + "/", f);
addFileToMap(size, namePerfix + fname + "/", f);
}
}
}
示例8: remove_all_objects
import android.util.ArrayMap; //导入方法依赖的package包/类
private final void remove_all_objects(ArrayMap<String, F[]> map, String name,
Object object) {
F[] array = map.get(name);
if (array != null) {
int LAST = array.length-1;
while (LAST >= 0 && array[LAST] == null) {
LAST--;
}
for (int idx=LAST; idx>=0; idx--) {
if (array[idx] == object) {
final int remain = LAST - idx;
if (remain > 0) {
System.arraycopy(array, idx+1, array, idx, remain);
}
array[LAST] = null;
LAST--;
}
}
if (LAST < 0) {
map.remove(name);
} else if (LAST < (array.length/2)) {
F[] newa = newArray(LAST+2);
System.arraycopy(array, 0, newa, 0, LAST+1);
map.put(name, newa);
}
}
}
示例9: makeTransportable
import android.util.ArrayMap; //导入方法依赖的package包/类
public static TransportableSensorOptions makeTransportable(ReadableSensorOptions fromThis) {
ArrayMap<String, String> values = new ArrayMap<>();
for (String key : fromThis.getWrittenKeys()) {
values.put(key, fromThis.getString(key, null));
}
return new TransportableSensorOptions(values);
}
示例10: readArrayMapInternal
import android.util.ArrayMap; //导入方法依赖的package包/类
@SuppressLint("NewApi")
public static <T> void readArrayMapInternal(Parcel parcel, ArrayMap<String, T> outVal, int N, ClassLoader loader) {
while (N > 0) {
String key = parcel.readString();
@SuppressWarnings("unchecked") T value = (T) parcel.readValue(loader);
outVal.put(key, value);
N--;
}
}
示例11: testGetFieldsAsDictionary
import android.util.ArrayMap; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.KITKAT)
@Test
public void testGetFieldsAsDictionary() {
Article article = new Article();
article.setTitle("title");
article.setPublicStatus(true);
ArrayList<String> tags = new ArrayList<String>();
tags.add("tag1");
article.setTags(tags);
ArrayMap<String, String> testmap = new ArrayMap<>();
testmap.put("key", "value");
article.setMap(testmap);
article.setVersion(1);
article.setPrice(1.0);
Map<String, Object> checkMap = new HashMap<>();
checkMap.put("price", 1.0);
checkMap.put("public", "true");
checkMap.put("title", "title");
checkMap.put("map", testmap);
checkMap.put("version", 1);
checkMap.put("tags", tags);
Map<String, Object> map = serializer.getFieldsAsDictionary(article);
assertNotNull(map);
assertEquals(checkMap.toString(), map.toString());
}
示例12: remove_all_objects
import android.util.ArrayMap; //导入方法依赖的package包/类
private final void remove_all_objects(ArrayMap<String, F[]> map, String name,
Object object) {
F[] array = map.get(name);
if (array != null) {
int LAST = array.length-1;
while (LAST >= 0 && array[LAST] == null) {
LAST--;
}
for (int idx=LAST; idx>=0; idx--) {
if (array[idx] == object) {
final int remain = LAST - idx;
if (remain > 0) {
System.arraycopy(array, idx+1, array, idx, remain);
}
array[LAST] = null;
LAST--;
}
}
if (LAST < 0) {
map.remove(name);
} else if (LAST < (array.length/2)) {
F[] newa = newArray(LAST+2);
System.arraycopy(array, 0, newa, 0, LAST+1);
map.put(name, newa);
}
}
}
示例13: unZip
import android.util.ArrayMap; //导入方法依赖的package包/类
public void unZip(String name, File outFile) throws IOException {
ArrayMap<String,File> files=new ArrayMap<>();
files.put(name, outFile);
unZip(files);
}
示例14: UsageStatsAdapter
import android.util.ArrayMap; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
UsageStatsAdapter() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_WEEK, -1);
System.out.println("**Today****cal.getTime()*****" + cal.getTime() + "***getTimeMillis()***" + cal.getTimeInMillis());
System.out.println("**Today**System.currentTimeMillis()**** " + System.currentTimeMillis());
//final List<UsageStats>
stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, cal.getTimeInMillis(), System.currentTimeMillis());
System.out.println("---------------------" + stats);
for (UsageStats usg : stats) {
/* System.out.println("***stats count "+stats.size());
System.out.println("********************");
System.out.println("" + usg.getPackageName());
// System.out.println("First time: " + usg.getFirstTimeStamp());*/
//System.out.println("Last time :" + usg.getLastTimeStamp());
// System.out.println("Total Time: " + usg.getTotalTimeInForeground());
//System.out.println(usg.getLastTimeUsed());
System.out.println("********************");
}
if (stats == null) {
return;
}
ArrayMap<String, UsageStats> map = new ArrayMap<>();
final int statCount = stats.size();
for (int i = 0; i < statCount; i++) {
final UsageStats pkgStats = stats.get(i);
// load application labels for each application
try {
ApplicationInfo appInfo = mPm.getApplicationInfo(pkgStats.getPackageName(), 0);
String label = appInfo.loadLabel(mPm).toString();
mAppLabelMap.put(pkgStats.getPackageName(), label);
UsageStats existingStats = map.get(pkgStats.getPackageName());
/*for(int j=0;j<getSavedApps.size();j++){
System.out.println("**********4");
System.out.println("*****getSavedApps.get(i)*****"+getSavedApps.get(i).toString());
System.out.println("*****pkgStats.getPackageName()*****"+pkgStats.getPackageName().toString());*/
if (getSavedApps.contains(pkgStats.getPackageName().toString())) {
//System.out.println("*** adding to map "+getSavedApps.get(j)+" & "+pkgStats.getPackageName());
if (existingStats == null) {
map.put(pkgStats.getPackageName(), pkgStats);
} else {
existingStats.add(pkgStats);
}
} else System.out.println("****no match found");
} catch (PackageManager.NameNotFoundException e) {
// This package may be gone.
}
}
mPackageStats.addAll(map.values());
// Sort list
mAppLabelComparator = new AppNameComparator(mAppLabelMap);
sortList();
}
示例15: UsageStatsAdapter
import android.util.ArrayMap; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
UsageStatsAdapter() {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DAY_OF_WEEK, -1);
System.out.println("**Yday****cal.getTime()*****" + cal.getTime() + "***getTimeMillis()***" + cal.getTimeInMillis());
System.out.println("**Yday**System.currentTimeMillis()**** " + System.currentTimeMillis());
//final List<UsageStats>
stats = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,
cal.getTimeInMillis(), System.currentTimeMillis());
//System.out.println("---------------------"+stats);
for (UsageStats usg : stats) {
// System.out.println("***stats count "+stats.size());
// System.out.println("********************");
// System.out.println("" + usg.getPackageName());
// System.out.println("First time: " + usg.getFirstTimeStamp());
// System.out.println("Last time :" + usg.getLastTimeStamp());
// System.out.println("Total Time: " + usg.getTotalTimeInForeground());
// System.out.println(usg.getLastTimeUsed());
// System.out.println("********************");
//mPieChart.addPieSlice(new PieModel("", usg.getTotalTimeInForeground(), Color.parseColor(color)));
}
//mPieChart.startAnimation();
if (stats == null) {
return;
}
ArrayMap<String, UsageStats> map = new ArrayMap<>();
final int statCount = stats.size();
for (int i = 0; i < statCount; i++) {
final UsageStats pkgStats = stats.get(i);
// load application labels for each application
try {
ApplicationInfo appInfo = mPm.getApplicationInfo(pkgStats.getPackageName(), 0);
String label = appInfo.loadLabel(mPm).toString();
mAppLabelMap.put(pkgStats.getPackageName(), label);
UsageStats existingStats = map.get(pkgStats.getPackageName());
/*for(int j=0;j<getSavedApps.size();j++){
System.out.println("**********4");
System.out.println("*****getSavedApps.get(i)*****"+getSavedApps.get(i).toString());
System.out.println("*****pkgStats.getPackageName()*****"+pkgStats.getPackageName().toString());*/
if (getSavedApps.contains(pkgStats.getPackageName().toString())) {
//System.out.println("*** adding to map "+getSavedApps.get(j)+" & "+pkgStats.getPackageName());
if (existingStats == null) {
map.put(pkgStats.getPackageName(), pkgStats);
} else {
existingStats.add(pkgStats);
}
} else System.out.println("****no match found");
//}
/*if (existingStats == null) {
map.put(pkgStats.getPackageName(), pkgStats);
} else {
existingStats.add(pkgStats);
}*/
} catch (PackageManager.NameNotFoundException e) {
// This package may be gone.
}
}
mPackageStats.addAll(map.values());
// Sort list
mAppLabelComparator = new AppNameComparator(mAppLabelMap);
sortList();
}