ADD week 5
This commit is contained in:
7
02-Easy5/E5/sources/androidx/cursoradapter/R.java
Normal file
7
02-Easy5/E5/sources/androidx/cursoradapter/R.java
Normal file
@ -0,0 +1,7 @@
|
||||
package androidx.cursoradapter;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class R {
|
||||
private R() {
|
||||
}
|
||||
}
|
@ -0,0 +1,263 @@
|
||||
package androidx.cursoradapter.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.database.Cursor;
|
||||
import android.database.DataSetObserver;
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.Filter;
|
||||
import android.widget.FilterQueryProvider;
|
||||
import android.widget.Filterable;
|
||||
import androidx.cursoradapter.widget.CursorFilter;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class CursorAdapter extends BaseAdapter implements Filterable, CursorFilter.CursorFilterClient {
|
||||
|
||||
@Deprecated
|
||||
public static final int FLAG_AUTO_REQUERY = 1;
|
||||
public static final int FLAG_REGISTER_CONTENT_OBSERVER = 2;
|
||||
protected boolean mAutoRequery;
|
||||
protected ChangeObserver mChangeObserver;
|
||||
protected Context mContext;
|
||||
protected Cursor mCursor;
|
||||
protected CursorFilter mCursorFilter;
|
||||
protected DataSetObserver mDataSetObserver;
|
||||
protected boolean mDataValid;
|
||||
protected FilterQueryProvider mFilterQueryProvider;
|
||||
protected int mRowIDColumn;
|
||||
|
||||
public abstract void bindView(View view, Context context, Cursor cursor);
|
||||
|
||||
@Override // androidx.cursoradapter.widget.CursorFilter.CursorFilterClient
|
||||
public Cursor getCursor() {
|
||||
return this.mCursor;
|
||||
}
|
||||
|
||||
public FilterQueryProvider getFilterQueryProvider() {
|
||||
return this.mFilterQueryProvider;
|
||||
}
|
||||
|
||||
@Override // android.widget.BaseAdapter, android.widget.Adapter
|
||||
public boolean hasStableIds() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public abstract View newView(Context context, Cursor cursor, ViewGroup viewGroup);
|
||||
|
||||
public void setFilterQueryProvider(FilterQueryProvider filterQueryProvider) {
|
||||
this.mFilterQueryProvider = filterQueryProvider;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public CursorAdapter(Context context, Cursor cursor) {
|
||||
init(context, cursor, 1);
|
||||
}
|
||||
|
||||
public CursorAdapter(Context context, Cursor cursor, boolean z) {
|
||||
init(context, cursor, z ? 1 : 2);
|
||||
}
|
||||
|
||||
public CursorAdapter(Context context, Cursor cursor, int i) {
|
||||
init(context, cursor, i);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void init(Context context, Cursor cursor, boolean z) {
|
||||
init(context, cursor, z ? 1 : 2);
|
||||
}
|
||||
|
||||
void init(Context context, Cursor cursor, int i) {
|
||||
if ((i & 1) == 1) {
|
||||
i |= 2;
|
||||
this.mAutoRequery = true;
|
||||
} else {
|
||||
this.mAutoRequery = false;
|
||||
}
|
||||
boolean z = cursor != null;
|
||||
this.mCursor = cursor;
|
||||
this.mDataValid = z;
|
||||
this.mContext = context;
|
||||
this.mRowIDColumn = z ? cursor.getColumnIndexOrThrow("_id") : -1;
|
||||
if ((i & 2) == 2) {
|
||||
this.mChangeObserver = new ChangeObserver();
|
||||
this.mDataSetObserver = new MyDataSetObserver();
|
||||
} else {
|
||||
this.mChangeObserver = null;
|
||||
this.mDataSetObserver = null;
|
||||
}
|
||||
if (z) {
|
||||
ChangeObserver changeObserver = this.mChangeObserver;
|
||||
if (changeObserver != null) {
|
||||
cursor.registerContentObserver(changeObserver);
|
||||
}
|
||||
DataSetObserver dataSetObserver = this.mDataSetObserver;
|
||||
if (dataSetObserver != null) {
|
||||
cursor.registerDataSetObserver(dataSetObserver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // android.widget.Adapter
|
||||
public int getCount() {
|
||||
Cursor cursor;
|
||||
if (!this.mDataValid || (cursor = this.mCursor) == null) {
|
||||
return 0;
|
||||
}
|
||||
return cursor.getCount();
|
||||
}
|
||||
|
||||
@Override // android.widget.Adapter
|
||||
public Object getItem(int i) {
|
||||
Cursor cursor;
|
||||
if (!this.mDataValid || (cursor = this.mCursor) == null) {
|
||||
return null;
|
||||
}
|
||||
cursor.moveToPosition(i);
|
||||
return this.mCursor;
|
||||
}
|
||||
|
||||
@Override // android.widget.Adapter
|
||||
public long getItemId(int i) {
|
||||
Cursor cursor;
|
||||
if (this.mDataValid && (cursor = this.mCursor) != null && cursor.moveToPosition(i)) {
|
||||
return this.mCursor.getLong(this.mRowIDColumn);
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
@Override // android.widget.Adapter
|
||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||
if (!this.mDataValid) {
|
||||
throw new IllegalStateException("this should only be called when the cursor is valid");
|
||||
}
|
||||
if (!this.mCursor.moveToPosition(i)) {
|
||||
throw new IllegalStateException("couldn't move cursor to position " + i);
|
||||
}
|
||||
if (view == null) {
|
||||
view = newView(this.mContext, this.mCursor, viewGroup);
|
||||
}
|
||||
bindView(view, this.mContext, this.mCursor);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override // android.widget.BaseAdapter, android.widget.SpinnerAdapter
|
||||
public View getDropDownView(int i, View view, ViewGroup viewGroup) {
|
||||
if (!this.mDataValid) {
|
||||
return null;
|
||||
}
|
||||
this.mCursor.moveToPosition(i);
|
||||
if (view == null) {
|
||||
view = newDropDownView(this.mContext, this.mCursor, viewGroup);
|
||||
}
|
||||
bindView(view, this.mContext, this.mCursor);
|
||||
return view;
|
||||
}
|
||||
|
||||
public View newDropDownView(Context context, Cursor cursor, ViewGroup viewGroup) {
|
||||
return newView(context, cursor, viewGroup);
|
||||
}
|
||||
|
||||
public void changeCursor(Cursor cursor) {
|
||||
Cursor swapCursor = swapCursor(cursor);
|
||||
if (swapCursor != null) {
|
||||
swapCursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
public Cursor swapCursor(Cursor cursor) {
|
||||
Cursor cursor2 = this.mCursor;
|
||||
if (cursor == cursor2) {
|
||||
return null;
|
||||
}
|
||||
if (cursor2 != null) {
|
||||
ChangeObserver changeObserver = this.mChangeObserver;
|
||||
if (changeObserver != null) {
|
||||
cursor2.unregisterContentObserver(changeObserver);
|
||||
}
|
||||
DataSetObserver dataSetObserver = this.mDataSetObserver;
|
||||
if (dataSetObserver != null) {
|
||||
cursor2.unregisterDataSetObserver(dataSetObserver);
|
||||
}
|
||||
}
|
||||
this.mCursor = cursor;
|
||||
if (cursor != null) {
|
||||
ChangeObserver changeObserver2 = this.mChangeObserver;
|
||||
if (changeObserver2 != null) {
|
||||
cursor.registerContentObserver(changeObserver2);
|
||||
}
|
||||
DataSetObserver dataSetObserver2 = this.mDataSetObserver;
|
||||
if (dataSetObserver2 != null) {
|
||||
cursor.registerDataSetObserver(dataSetObserver2);
|
||||
}
|
||||
this.mRowIDColumn = cursor.getColumnIndexOrThrow("_id");
|
||||
this.mDataValid = true;
|
||||
notifyDataSetChanged();
|
||||
} else {
|
||||
this.mRowIDColumn = -1;
|
||||
this.mDataValid = false;
|
||||
notifyDataSetInvalidated();
|
||||
}
|
||||
return cursor2;
|
||||
}
|
||||
|
||||
public CharSequence convertToString(Cursor cursor) {
|
||||
return cursor == null ? "" : cursor.toString();
|
||||
}
|
||||
|
||||
public Cursor runQueryOnBackgroundThread(CharSequence charSequence) {
|
||||
FilterQueryProvider filterQueryProvider = this.mFilterQueryProvider;
|
||||
return filterQueryProvider != null ? filterQueryProvider.runQuery(charSequence) : this.mCursor;
|
||||
}
|
||||
|
||||
@Override // android.widget.Filterable
|
||||
public Filter getFilter() {
|
||||
if (this.mCursorFilter == null) {
|
||||
this.mCursorFilter = new CursorFilter(this);
|
||||
}
|
||||
return this.mCursorFilter;
|
||||
}
|
||||
|
||||
protected void onContentChanged() {
|
||||
Cursor cursor;
|
||||
if (!this.mAutoRequery || (cursor = this.mCursor) == null || cursor.isClosed()) {
|
||||
return;
|
||||
}
|
||||
this.mDataValid = this.mCursor.requery();
|
||||
}
|
||||
|
||||
private class ChangeObserver extends ContentObserver {
|
||||
@Override // android.database.ContentObserver
|
||||
public boolean deliverSelfNotifications() {
|
||||
return true;
|
||||
}
|
||||
|
||||
ChangeObserver() {
|
||||
super(new Handler());
|
||||
}
|
||||
|
||||
@Override // android.database.ContentObserver
|
||||
public void onChange(boolean z) {
|
||||
CursorAdapter.this.onContentChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private class MyDataSetObserver extends DataSetObserver {
|
||||
MyDataSetObserver() {
|
||||
}
|
||||
|
||||
@Override // android.database.DataSetObserver
|
||||
public void onChanged() {
|
||||
CursorAdapter.this.mDataValid = true;
|
||||
CursorAdapter.this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override // android.database.DataSetObserver
|
||||
public void onInvalidated() {
|
||||
CursorAdapter.this.mDataValid = false;
|
||||
CursorAdapter.this.notifyDataSetInvalidated();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package androidx.cursoradapter.widget;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.widget.Filter;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
class CursorFilter extends Filter {
|
||||
CursorFilterClient mClient;
|
||||
|
||||
interface CursorFilterClient {
|
||||
void changeCursor(Cursor cursor);
|
||||
|
||||
CharSequence convertToString(Cursor cursor);
|
||||
|
||||
Cursor getCursor();
|
||||
|
||||
Cursor runQueryOnBackgroundThread(CharSequence charSequence);
|
||||
}
|
||||
|
||||
CursorFilter(CursorFilterClient cursorFilterClient) {
|
||||
this.mClient = cursorFilterClient;
|
||||
}
|
||||
|
||||
@Override // android.widget.Filter
|
||||
public CharSequence convertResultToString(Object obj) {
|
||||
return this.mClient.convertToString((Cursor) obj);
|
||||
}
|
||||
|
||||
@Override // android.widget.Filter
|
||||
protected Filter.FilterResults performFiltering(CharSequence charSequence) {
|
||||
Cursor runQueryOnBackgroundThread = this.mClient.runQueryOnBackgroundThread(charSequence);
|
||||
Filter.FilterResults filterResults = new Filter.FilterResults();
|
||||
if (runQueryOnBackgroundThread != null) {
|
||||
filterResults.count = runQueryOnBackgroundThread.getCount();
|
||||
filterResults.values = runQueryOnBackgroundThread;
|
||||
} else {
|
||||
filterResults.count = 0;
|
||||
filterResults.values = null;
|
||||
}
|
||||
return filterResults;
|
||||
}
|
||||
|
||||
@Override // android.widget.Filter
|
||||
protected void publishResults(CharSequence charSequence, Filter.FilterResults filterResults) {
|
||||
Cursor cursor = this.mClient.getCursor();
|
||||
if (filterResults.values == null || filterResults.values == cursor) {
|
||||
return;
|
||||
}
|
||||
this.mClient.changeCursor((Cursor) filterResults.values);
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package androidx.cursoradapter.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class ResourceCursorAdapter extends CursorAdapter {
|
||||
private int mDropDownLayout;
|
||||
private LayoutInflater mInflater;
|
||||
private int mLayout;
|
||||
|
||||
public void setDropDownViewResource(int i) {
|
||||
this.mDropDownLayout = i;
|
||||
}
|
||||
|
||||
public void setViewResource(int i) {
|
||||
this.mLayout = i;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ResourceCursorAdapter(Context context, int i, Cursor cursor) {
|
||||
super(context, cursor);
|
||||
this.mDropDownLayout = i;
|
||||
this.mLayout = i;
|
||||
this.mInflater = (LayoutInflater) context.getSystemService("layout_inflater");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ResourceCursorAdapter(Context context, int i, Cursor cursor, boolean z) {
|
||||
super(context, cursor, z);
|
||||
this.mDropDownLayout = i;
|
||||
this.mLayout = i;
|
||||
this.mInflater = (LayoutInflater) context.getSystemService("layout_inflater");
|
||||
}
|
||||
|
||||
public ResourceCursorAdapter(Context context, int i, Cursor cursor, int i2) {
|
||||
super(context, cursor, i2);
|
||||
this.mDropDownLayout = i;
|
||||
this.mLayout = i;
|
||||
this.mInflater = (LayoutInflater) context.getSystemService("layout_inflater");
|
||||
}
|
||||
|
||||
@Override // androidx.cursoradapter.widget.CursorAdapter
|
||||
public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
|
||||
return this.mInflater.inflate(this.mLayout, viewGroup, false);
|
||||
}
|
||||
|
||||
@Override // androidx.cursoradapter.widget.CursorAdapter
|
||||
public View newDropDownView(Context context, Cursor cursor, ViewGroup viewGroup) {
|
||||
return this.mInflater.inflate(this.mDropDownLayout, viewGroup, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,144 @@
|
||||
package androidx.cursoradapter.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class SimpleCursorAdapter extends ResourceCursorAdapter {
|
||||
private CursorToStringConverter mCursorToStringConverter;
|
||||
protected int[] mFrom;
|
||||
String[] mOriginalFrom;
|
||||
private int mStringConversionColumn;
|
||||
protected int[] mTo;
|
||||
private ViewBinder mViewBinder;
|
||||
|
||||
public interface CursorToStringConverter {
|
||||
CharSequence convertToString(Cursor cursor);
|
||||
}
|
||||
|
||||
public interface ViewBinder {
|
||||
boolean setViewValue(View view, Cursor cursor, int i);
|
||||
}
|
||||
|
||||
public CursorToStringConverter getCursorToStringConverter() {
|
||||
return this.mCursorToStringConverter;
|
||||
}
|
||||
|
||||
public int getStringConversionColumn() {
|
||||
return this.mStringConversionColumn;
|
||||
}
|
||||
|
||||
public ViewBinder getViewBinder() {
|
||||
return this.mViewBinder;
|
||||
}
|
||||
|
||||
public void setCursorToStringConverter(CursorToStringConverter cursorToStringConverter) {
|
||||
this.mCursorToStringConverter = cursorToStringConverter;
|
||||
}
|
||||
|
||||
public void setStringConversionColumn(int i) {
|
||||
this.mStringConversionColumn = i;
|
||||
}
|
||||
|
||||
public void setViewBinder(ViewBinder viewBinder) {
|
||||
this.mViewBinder = viewBinder;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SimpleCursorAdapter(Context context, int i, Cursor cursor, String[] strArr, int[] iArr) {
|
||||
super(context, i, cursor);
|
||||
this.mStringConversionColumn = -1;
|
||||
this.mTo = iArr;
|
||||
this.mOriginalFrom = strArr;
|
||||
findColumns(cursor, strArr);
|
||||
}
|
||||
|
||||
public SimpleCursorAdapter(Context context, int i, Cursor cursor, String[] strArr, int[] iArr, int i2) {
|
||||
super(context, i, cursor, i2);
|
||||
this.mStringConversionColumn = -1;
|
||||
this.mTo = iArr;
|
||||
this.mOriginalFrom = strArr;
|
||||
findColumns(cursor, strArr);
|
||||
}
|
||||
|
||||
@Override // androidx.cursoradapter.widget.CursorAdapter
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
ViewBinder viewBinder = this.mViewBinder;
|
||||
int[] iArr = this.mTo;
|
||||
int length = iArr.length;
|
||||
int[] iArr2 = this.mFrom;
|
||||
for (int i = 0; i < length; i++) {
|
||||
View findViewById = view.findViewById(iArr[i]);
|
||||
if (findViewById != null && (viewBinder == null || !viewBinder.setViewValue(findViewById, cursor, iArr2[i]))) {
|
||||
String string = cursor.getString(iArr2[i]);
|
||||
if (string == null) {
|
||||
string = "";
|
||||
}
|
||||
if (findViewById instanceof TextView) {
|
||||
setViewText((TextView) findViewById, string);
|
||||
} else if (findViewById instanceof ImageView) {
|
||||
setViewImage((ImageView) findViewById, string);
|
||||
} else {
|
||||
throw new IllegalStateException(findViewById.getClass().getName() + " is not a view that can be bounds by this SimpleCursorAdapter");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setViewImage(ImageView imageView, String str) {
|
||||
try {
|
||||
imageView.setImageResource(Integer.parseInt(str));
|
||||
} catch (NumberFormatException unused) {
|
||||
imageView.setImageURI(Uri.parse(str));
|
||||
}
|
||||
}
|
||||
|
||||
public void setViewText(TextView textView, String str) {
|
||||
textView.setText(str);
|
||||
}
|
||||
|
||||
@Override // androidx.cursoradapter.widget.CursorAdapter, androidx.cursoradapter.widget.CursorFilter.CursorFilterClient
|
||||
public CharSequence convertToString(Cursor cursor) {
|
||||
CursorToStringConverter cursorToStringConverter = this.mCursorToStringConverter;
|
||||
if (cursorToStringConverter != null) {
|
||||
return cursorToStringConverter.convertToString(cursor);
|
||||
}
|
||||
int i = this.mStringConversionColumn;
|
||||
if (i > -1) {
|
||||
return cursor.getString(i);
|
||||
}
|
||||
return super.convertToString(cursor);
|
||||
}
|
||||
|
||||
private void findColumns(Cursor cursor, String[] strArr) {
|
||||
if (cursor == null) {
|
||||
this.mFrom = null;
|
||||
return;
|
||||
}
|
||||
int length = strArr.length;
|
||||
int[] iArr = this.mFrom;
|
||||
if (iArr == null || iArr.length != length) {
|
||||
this.mFrom = new int[length];
|
||||
}
|
||||
for (int i = 0; i < length; i++) {
|
||||
this.mFrom[i] = cursor.getColumnIndexOrThrow(strArr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // androidx.cursoradapter.widget.CursorAdapter
|
||||
public Cursor swapCursor(Cursor cursor) {
|
||||
findColumns(cursor, this.mOriginalFrom);
|
||||
return super.swapCursor(cursor);
|
||||
}
|
||||
|
||||
public void changeCursorAndColumns(Cursor cursor, String[] strArr, int[] iArr) {
|
||||
this.mOriginalFrom = strArr;
|
||||
this.mTo = iArr;
|
||||
findColumns(cursor, strArr);
|
||||
super.changeCursor(cursor);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user