正在查看: fieldd v4.2.4 应用的 LocationContentProvider.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: fieldd v4.2.4 应用的 LocationContentProvider.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.marianhello.bgloc.data.provider;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import com.marianhello.bgloc.ResourceResolver;
import com.marianhello.bgloc.data.sqlite.SQLiteOpenHelper;
public class LocationContentProvider extends ContentProvider {
private static final int ALL_ITEMS = 10;
private static final int ONE_ITEM = 20;
private static final UriMatcher sUriMatcher = new UriMatcher(-1);
private SQLiteOpenHelper mDatabaseHelper;
@Override
public String getType(Uri uri) {
return null;
}
private static void initialize(String str) {
UriMatcher uriMatcher = sUriMatcher;
uriMatcher.addURI(str, "location", 10);
uriMatcher.addURI(str, "location/#", 20);
}
@Override
public boolean onCreate() {
Context context = getContext();
initialize(ResourceResolver.newInstance(getContext()).getAuthority());
this.mDatabaseHelper = new SQLiteOpenHelper(context);
return true;
}
@Override
public Cursor query(Uri uri, String[] strArr, String str, String[] strArr2, String str2) {
int match = sUriMatcher.match(uri);
SQLiteDatabase writableDatabase = this.mDatabaseHelper.getWritableDatabase();
SQLiteQueryBuilder sQLiteQueryBuilder = new SQLiteQueryBuilder();
if (match == 10) {
sQLiteQueryBuilder.setTables("location");
if (TextUtils.isEmpty(str2)) {
str2 = "time ASC";
}
} else if (match == 20) {
sQLiteQueryBuilder.setTables("location");
sQLiteQueryBuilder.appendWhere("_id = " + uri.getLastPathSegment());
} else {
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
Cursor query = sQLiteQueryBuilder.query(writableDatabase, strArr, str, strArr2, null, null, str2);
query.setNotificationUri(getContext().getContentResolver(), uri);
return query;
}
@Override
public Uri insert(Uri uri, ContentValues contentValues) {
if (sUriMatcher.match(uri) == 10) {
long insert = this.mDatabaseHelper.getWritableDatabase().insert("location", null, contentValues);
if (insert > 0) {
Uri withAppendedId = ContentUris.withAppendedId(uri, insert);
notifyAllListeners(withAppendedId);
return withAppendedId;
}
throw new SQLException("Error inserting for URI " + uri + " result:" + insert);
}
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
@Override
public int delete(Uri uri, String str, String[] strArr) {
int delete;
int match = sUriMatcher.match(uri);
SQLiteDatabase writableDatabase = this.mDatabaseHelper.getWritableDatabase();
if (match == 10) {
delete = writableDatabase.delete("location", str, strArr);
} else if (match == 20) {
String str2 = "_id = " + uri.getLastPathSegment();
if (!TextUtils.isEmpty(str)) {
str2 = str2 + " AND " + str;
}
delete = writableDatabase.delete("location", str2, strArr);
} else {
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
if (delete > 0) {
notifyAllListeners(uri);
}
return delete;
}
@Override
public int update(Uri uri, ContentValues contentValues, String str, String[] strArr) {
int update;
int match = sUriMatcher.match(uri);
SQLiteDatabase writableDatabase = this.mDatabaseHelper.getWritableDatabase();
if (match == 10) {
update = writableDatabase.update("location", contentValues, str, strArr);
} else if (match == 20) {
String str2 = "_id = " + uri.getLastPathSegment();
if (!TextUtils.isEmpty(str)) {
str2 = str2 + " AND " + str;
}
update = writableDatabase.update("location", contentValues, str2, strArr);
} else {
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
if (update > 0) {
notifyAllListeners(uri);
}
return update;
}
private void notifyAllListeners(Uri uri) {
ContentResolver contentResolver = getContext().getContentResolver();
if (contentResolver != null) {
contentResolver.notifyChange(uri, null);
}
}
public static Uri getBaseContentUri(String str) {
return Uri.parse("content://" + str);
}
public static Uri getContentUri(String str) {
return getBaseContentUri(str).buildUpon().appendPath("location").build();
}
public static Uri buildUriWithId(String str, long j) {
return getContentUri(str).buildUpon().appendPath(Long.toString(j)).build();
}
}