import android.content.ContentValues; //导入方法依赖的package包/类
@SuppressWarnings("ConstantConditions")
@SuppressLint("NewApi")
@Override
public Uri insert(@NonNull Uri uri, ContentValues values) {
switch (matcher.match(uri)) {
case MATCH_DATA:
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(getContext().getApplicationContext()).edit();
for (Entry entry : values.valueSet()) {
final Object value = entry.getValue();
final String key = entry.getKey();
if (value == null) {
editor.remove(key);
} else if (value instanceof String)
editor.putString(key, (String) value);
else if (value instanceof Boolean)
editor.putBoolean(key, (Boolean) value);
else if (value instanceof Long)
editor.putLong(key, (Long) value);
else if (value instanceof Integer)
editor.putInt(key, (Integer) value);
else if (value instanceof Float)
editor.putFloat(key, (Float) value);
else {
throw new IllegalArgumentException("Unsupported type " + uri);
}
}
editor.apply();
break;
default:
throw new IllegalArgumentException("Unsupported uri " + uri);
}
return null;
}