ADD week 5
This commit is contained in:
		
							
								
								
									
										224
									
								
								02-Easy5/E5/sources/androidx/loader/content/AsyncTaskLoader.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										224
									
								
								02-Easy5/E5/sources/androidx/loader/content/AsyncTaskLoader.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,224 @@ | ||||
| package androidx.loader.content; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.os.Handler; | ||||
| import android.os.SystemClock; | ||||
| import androidx.core.os.OperationCanceledException; | ||||
| import androidx.core.util.TimeUtils; | ||||
| import java.io.FileDescriptor; | ||||
| import java.io.PrintWriter; | ||||
| import java.util.concurrent.CountDownLatch; | ||||
| import java.util.concurrent.Executor; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| public abstract class AsyncTaskLoader<D> extends Loader<D> { | ||||
|     static final boolean DEBUG = false; | ||||
|     static final String TAG = "AsyncTaskLoader"; | ||||
|     volatile AsyncTaskLoader<D>.LoadTask mCancellingTask; | ||||
|     private final Executor mExecutor; | ||||
|     Handler mHandler; | ||||
|     long mLastLoadCompleteTime; | ||||
|     volatile AsyncTaskLoader<D>.LoadTask mTask; | ||||
|     long mUpdateThrottle; | ||||
|  | ||||
|     public void cancelLoadInBackground() { | ||||
|     } | ||||
|  | ||||
|     public boolean isLoadInBackgroundCanceled() { | ||||
|         return this.mCancellingTask != null; | ||||
|     } | ||||
|  | ||||
|     public abstract D loadInBackground(); | ||||
|  | ||||
|     public void onCanceled(D d) { | ||||
|     } | ||||
|  | ||||
|     final class LoadTask extends ModernAsyncTask<Void, Void, D> implements Runnable { | ||||
|         private final CountDownLatch mDone = new CountDownLatch(1); | ||||
|         boolean waiting; | ||||
|  | ||||
|         LoadTask() { | ||||
|         } | ||||
|  | ||||
|         /* JADX INFO: Access modifiers changed from: protected */ | ||||
|         @Override // androidx.loader.content.ModernAsyncTask | ||||
|         public D doInBackground(Void... voidArr) { | ||||
|             try { | ||||
|                 return (D) AsyncTaskLoader.this.onLoadInBackground(); | ||||
|             } catch (OperationCanceledException e) { | ||||
|                 if (isCancelled()) { | ||||
|                     return null; | ||||
|                 } | ||||
|                 throw e; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         @Override // androidx.loader.content.ModernAsyncTask | ||||
|         protected void onPostExecute(D d) { | ||||
|             try { | ||||
|                 AsyncTaskLoader.this.dispatchOnLoadComplete(this, d); | ||||
|             } finally { | ||||
|                 this.mDone.countDown(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         @Override // androidx.loader.content.ModernAsyncTask | ||||
|         protected void onCancelled(D d) { | ||||
|             try { | ||||
|                 AsyncTaskLoader.this.dispatchOnCancelled(this, d); | ||||
|             } finally { | ||||
|                 this.mDone.countDown(); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         @Override // java.lang.Runnable | ||||
|         public void run() { | ||||
|             this.waiting = false; | ||||
|             AsyncTaskLoader.this.executePendingTask(); | ||||
|         } | ||||
|  | ||||
|         public void waitForLoader() { | ||||
|             try { | ||||
|                 this.mDone.await(); | ||||
|             } catch (InterruptedException unused) { | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public AsyncTaskLoader(Context context) { | ||||
|         this(context, ModernAsyncTask.THREAD_POOL_EXECUTOR); | ||||
|     } | ||||
|  | ||||
|     private AsyncTaskLoader(Context context, Executor executor) { | ||||
|         super(context); | ||||
|         this.mLastLoadCompleteTime = -10000L; | ||||
|         this.mExecutor = executor; | ||||
|     } | ||||
|  | ||||
|     public void setUpdateThrottle(long j) { | ||||
|         this.mUpdateThrottle = j; | ||||
|         if (j != 0) { | ||||
|             this.mHandler = new Handler(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.loader.content.Loader | ||||
|     protected void onForceLoad() { | ||||
|         super.onForceLoad(); | ||||
|         cancelLoad(); | ||||
|         this.mTask = new LoadTask(); | ||||
|         executePendingTask(); | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.loader.content.Loader | ||||
|     protected boolean onCancelLoad() { | ||||
|         if (this.mTask == null) { | ||||
|             return false; | ||||
|         } | ||||
|         if (!this.mStarted) { | ||||
|             this.mContentChanged = true; | ||||
|         } | ||||
|         if (this.mCancellingTask != null) { | ||||
|             if (this.mTask.waiting) { | ||||
|                 this.mTask.waiting = false; | ||||
|                 this.mHandler.removeCallbacks(this.mTask); | ||||
|             } | ||||
|             this.mTask = null; | ||||
|             return false; | ||||
|         } | ||||
|         if (this.mTask.waiting) { | ||||
|             this.mTask.waiting = false; | ||||
|             this.mHandler.removeCallbacks(this.mTask); | ||||
|             this.mTask = null; | ||||
|             return false; | ||||
|         } | ||||
|         boolean cancel = this.mTask.cancel(false); | ||||
|         if (cancel) { | ||||
|             this.mCancellingTask = this.mTask; | ||||
|             cancelLoadInBackground(); | ||||
|         } | ||||
|         this.mTask = null; | ||||
|         return cancel; | ||||
|     } | ||||
|  | ||||
|     void executePendingTask() { | ||||
|         if (this.mCancellingTask != null || this.mTask == null) { | ||||
|             return; | ||||
|         } | ||||
|         if (this.mTask.waiting) { | ||||
|             this.mTask.waiting = false; | ||||
|             this.mHandler.removeCallbacks(this.mTask); | ||||
|         } | ||||
|         if (this.mUpdateThrottle > 0 && SystemClock.uptimeMillis() < this.mLastLoadCompleteTime + this.mUpdateThrottle) { | ||||
|             this.mTask.waiting = true; | ||||
|             this.mHandler.postAtTime(this.mTask, this.mLastLoadCompleteTime + this.mUpdateThrottle); | ||||
|         } else { | ||||
|             this.mTask.executeOnExecutor(this.mExecutor, null); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     void dispatchOnCancelled(AsyncTaskLoader<D>.LoadTask loadTask, D d) { | ||||
|         onCanceled(d); | ||||
|         if (this.mCancellingTask == loadTask) { | ||||
|             rollbackContentChanged(); | ||||
|             this.mLastLoadCompleteTime = SystemClock.uptimeMillis(); | ||||
|             this.mCancellingTask = null; | ||||
|             deliverCancellation(); | ||||
|             executePendingTask(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     void dispatchOnLoadComplete(AsyncTaskLoader<D>.LoadTask loadTask, D d) { | ||||
|         if (this.mTask != loadTask) { | ||||
|             dispatchOnCancelled(loadTask, d); | ||||
|             return; | ||||
|         } | ||||
|         if (isAbandoned()) { | ||||
|             onCanceled(d); | ||||
|             return; | ||||
|         } | ||||
|         commitContentChanged(); | ||||
|         this.mLastLoadCompleteTime = SystemClock.uptimeMillis(); | ||||
|         this.mTask = null; | ||||
|         deliverResult(d); | ||||
|     } | ||||
|  | ||||
|     protected D onLoadInBackground() { | ||||
|         return loadInBackground(); | ||||
|     } | ||||
|  | ||||
|     public void waitForLoader() { | ||||
|         AsyncTaskLoader<D>.LoadTask loadTask = this.mTask; | ||||
|         if (loadTask != null) { | ||||
|             loadTask.waitForLoader(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.loader.content.Loader | ||||
|     @Deprecated | ||||
|     public void dump(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) { | ||||
|         super.dump(str, fileDescriptor, printWriter, strArr); | ||||
|         if (this.mTask != null) { | ||||
|             printWriter.print(str); | ||||
|             printWriter.print("mTask="); | ||||
|             printWriter.print(this.mTask); | ||||
|             printWriter.print(" waiting="); | ||||
|             printWriter.println(this.mTask.waiting); | ||||
|         } | ||||
|         if (this.mCancellingTask != null) { | ||||
|             printWriter.print(str); | ||||
|             printWriter.print("mCancellingTask="); | ||||
|             printWriter.print(this.mCancellingTask); | ||||
|             printWriter.print(" waiting="); | ||||
|             printWriter.println(this.mCancellingTask.waiting); | ||||
|         } | ||||
|         if (this.mUpdateThrottle != 0) { | ||||
|             printWriter.print(str); | ||||
|             printWriter.print("mUpdateThrottle="); | ||||
|             TimeUtils.formatDuration(this.mUpdateThrottle, printWriter); | ||||
|             printWriter.print(" mLastLoadCompleteTime="); | ||||
|             TimeUtils.formatDuration(this.mLastLoadCompleteTime, SystemClock.uptimeMillis(), printWriter); | ||||
|             printWriter.println(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										204
									
								
								02-Easy5/E5/sources/androidx/loader/content/CursorLoader.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										204
									
								
								02-Easy5/E5/sources/androidx/loader/content/CursorLoader.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,204 @@ | ||||
| package androidx.loader.content; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.database.Cursor; | ||||
| import android.net.Uri; | ||||
| import androidx.core.content.ContentResolverCompat; | ||||
| import androidx.core.os.CancellationSignal; | ||||
| import androidx.core.os.OperationCanceledException; | ||||
| import androidx.loader.content.Loader; | ||||
| import java.io.FileDescriptor; | ||||
| import java.io.PrintWriter; | ||||
| import java.util.Arrays; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| public class CursorLoader extends AsyncTaskLoader<Cursor> { | ||||
|     CancellationSignal mCancellationSignal; | ||||
|     Cursor mCursor; | ||||
|     final Loader<Cursor>.ForceLoadContentObserver mObserver; | ||||
|     String[] mProjection; | ||||
|     String mSelection; | ||||
|     String[] mSelectionArgs; | ||||
|     String mSortOrder; | ||||
|     Uri mUri; | ||||
|  | ||||
|     public String[] getProjection() { | ||||
|         return this.mProjection; | ||||
|     } | ||||
|  | ||||
|     public String getSelection() { | ||||
|         return this.mSelection; | ||||
|     } | ||||
|  | ||||
|     public String[] getSelectionArgs() { | ||||
|         return this.mSelectionArgs; | ||||
|     } | ||||
|  | ||||
|     public String getSortOrder() { | ||||
|         return this.mSortOrder; | ||||
|     } | ||||
|  | ||||
|     public Uri getUri() { | ||||
|         return this.mUri; | ||||
|     } | ||||
|  | ||||
|     public void setProjection(String[] strArr) { | ||||
|         this.mProjection = strArr; | ||||
|     } | ||||
|  | ||||
|     public void setSelection(String str) { | ||||
|         this.mSelection = str; | ||||
|     } | ||||
|  | ||||
|     public void setSelectionArgs(String[] strArr) { | ||||
|         this.mSelectionArgs = strArr; | ||||
|     } | ||||
|  | ||||
|     public void setSortOrder(String str) { | ||||
|         this.mSortOrder = str; | ||||
|     } | ||||
|  | ||||
|     public void setUri(Uri uri) { | ||||
|         this.mUri = uri; | ||||
|     } | ||||
|  | ||||
|     /* JADX WARN: Can't rename method to resolve collision */ | ||||
|     @Override // androidx.loader.content.AsyncTaskLoader | ||||
|     public Cursor loadInBackground() { | ||||
|         synchronized (this) { | ||||
|             if (isLoadInBackgroundCanceled()) { | ||||
|                 throw new OperationCanceledException(); | ||||
|             } | ||||
|             this.mCancellationSignal = new CancellationSignal(); | ||||
|         } | ||||
|         try { | ||||
|             Cursor query = ContentResolverCompat.query(getContext().getContentResolver(), this.mUri, this.mProjection, this.mSelection, this.mSelectionArgs, this.mSortOrder, this.mCancellationSignal); | ||||
|             if (query != null) { | ||||
|                 try { | ||||
|                     query.getCount(); | ||||
|                     query.registerContentObserver(this.mObserver); | ||||
|                 } catch (RuntimeException e) { | ||||
|                     query.close(); | ||||
|                     throw e; | ||||
|                 } | ||||
|             } | ||||
|             synchronized (this) { | ||||
|                 this.mCancellationSignal = null; | ||||
|             } | ||||
|             return query; | ||||
|         } catch (Throwable th) { | ||||
|             synchronized (this) { | ||||
|                 this.mCancellationSignal = null; | ||||
|                 throw th; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.loader.content.AsyncTaskLoader | ||||
|     public void cancelLoadInBackground() { | ||||
|         super.cancelLoadInBackground(); | ||||
|         synchronized (this) { | ||||
|             CancellationSignal cancellationSignal = this.mCancellationSignal; | ||||
|             if (cancellationSignal != null) { | ||||
|                 cancellationSignal.cancel(); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.loader.content.Loader | ||||
|     public void deliverResult(Cursor cursor) { | ||||
|         if (isReset()) { | ||||
|             if (cursor != null) { | ||||
|                 cursor.close(); | ||||
|                 return; | ||||
|             } | ||||
|             return; | ||||
|         } | ||||
|         Cursor cursor2 = this.mCursor; | ||||
|         this.mCursor = cursor; | ||||
|         if (isStarted()) { | ||||
|             super.deliverResult((CursorLoader) cursor); | ||||
|         } | ||||
|         if (cursor2 == null || cursor2 == cursor || cursor2.isClosed()) { | ||||
|             return; | ||||
|         } | ||||
|         cursor2.close(); | ||||
|     } | ||||
|  | ||||
|     public CursorLoader(Context context) { | ||||
|         super(context); | ||||
|         this.mObserver = new Loader.ForceLoadContentObserver(); | ||||
|     } | ||||
|  | ||||
|     public CursorLoader(Context context, Uri uri, String[] strArr, String str, String[] strArr2, String str2) { | ||||
|         super(context); | ||||
|         this.mObserver = new Loader.ForceLoadContentObserver(); | ||||
|         this.mUri = uri; | ||||
|         this.mProjection = strArr; | ||||
|         this.mSelection = str; | ||||
|         this.mSelectionArgs = strArr2; | ||||
|         this.mSortOrder = str2; | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.loader.content.Loader | ||||
|     protected void onStartLoading() { | ||||
|         Cursor cursor = this.mCursor; | ||||
|         if (cursor != null) { | ||||
|             deliverResult(cursor); | ||||
|         } | ||||
|         if (takeContentChanged() || this.mCursor == null) { | ||||
|             forceLoad(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.loader.content.Loader | ||||
|     protected void onStopLoading() { | ||||
|         cancelLoad(); | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.loader.content.AsyncTaskLoader | ||||
|     public void onCanceled(Cursor cursor) { | ||||
|         if (cursor == null || cursor.isClosed()) { | ||||
|             return; | ||||
|         } | ||||
|         cursor.close(); | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.loader.content.Loader | ||||
|     protected void onReset() { | ||||
|         super.onReset(); | ||||
|         onStopLoading(); | ||||
|         Cursor cursor = this.mCursor; | ||||
|         if (cursor != null && !cursor.isClosed()) { | ||||
|             this.mCursor.close(); | ||||
|         } | ||||
|         this.mCursor = null; | ||||
|     } | ||||
|  | ||||
|     @Override // androidx.loader.content.AsyncTaskLoader, androidx.loader.content.Loader | ||||
|     @Deprecated | ||||
|     public void dump(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) { | ||||
|         super.dump(str, fileDescriptor, printWriter, strArr); | ||||
|         printWriter.print(str); | ||||
|         printWriter.print("mUri="); | ||||
|         printWriter.println(this.mUri); | ||||
|         printWriter.print(str); | ||||
|         printWriter.print("mProjection="); | ||||
|         printWriter.println(Arrays.toString(this.mProjection)); | ||||
|         printWriter.print(str); | ||||
|         printWriter.print("mSelection="); | ||||
|         printWriter.println(this.mSelection); | ||||
|         printWriter.print(str); | ||||
|         printWriter.print("mSelectionArgs="); | ||||
|         printWriter.println(Arrays.toString(this.mSelectionArgs)); | ||||
|         printWriter.print(str); | ||||
|         printWriter.print("mSortOrder="); | ||||
|         printWriter.println(this.mSortOrder); | ||||
|         printWriter.print(str); | ||||
|         printWriter.print("mCursor="); | ||||
|         printWriter.println(this.mCursor); | ||||
|         printWriter.print(str); | ||||
|         printWriter.print("mContentChanged="); | ||||
|         printWriter.println(this.mContentChanged); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										239
									
								
								02-Easy5/E5/sources/androidx/loader/content/Loader.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										239
									
								
								02-Easy5/E5/sources/androidx/loader/content/Loader.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,239 @@ | ||||
| package androidx.loader.content; | ||||
|  | ||||
| import android.content.Context; | ||||
| import android.database.ContentObserver; | ||||
| import android.os.Handler; | ||||
| import androidx.core.util.DebugUtils; | ||||
| import java.io.FileDescriptor; | ||||
| import java.io.PrintWriter; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| public class Loader<D> { | ||||
|     Context mContext; | ||||
|     int mId; | ||||
|     OnLoadCompleteListener<D> mListener; | ||||
|     OnLoadCanceledListener<D> mOnLoadCanceledListener; | ||||
|     boolean mStarted = false; | ||||
|     boolean mAbandoned = false; | ||||
|     boolean mReset = true; | ||||
|     boolean mContentChanged = false; | ||||
|     boolean mProcessingChange = false; | ||||
|  | ||||
|     public interface OnLoadCanceledListener<D> { | ||||
|         void onLoadCanceled(Loader<D> loader); | ||||
|     } | ||||
|  | ||||
|     public interface OnLoadCompleteListener<D> { | ||||
|         void onLoadComplete(Loader<D> loader, D d); | ||||
|     } | ||||
|  | ||||
|     public void commitContentChanged() { | ||||
|         this.mProcessingChange = false; | ||||
|     } | ||||
|  | ||||
|     public Context getContext() { | ||||
|         return this.mContext; | ||||
|     } | ||||
|  | ||||
|     public int getId() { | ||||
|         return this.mId; | ||||
|     } | ||||
|  | ||||
|     public boolean isAbandoned() { | ||||
|         return this.mAbandoned; | ||||
|     } | ||||
|  | ||||
|     public boolean isReset() { | ||||
|         return this.mReset; | ||||
|     } | ||||
|  | ||||
|     public boolean isStarted() { | ||||
|         return this.mStarted; | ||||
|     } | ||||
|  | ||||
|     protected void onAbandon() { | ||||
|     } | ||||
|  | ||||
|     protected boolean onCancelLoad() { | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     protected void onForceLoad() { | ||||
|     } | ||||
|  | ||||
|     protected void onReset() { | ||||
|     } | ||||
|  | ||||
|     protected void onStartLoading() { | ||||
|     } | ||||
|  | ||||
|     protected void onStopLoading() { | ||||
|     } | ||||
|  | ||||
|     public boolean takeContentChanged() { | ||||
|         boolean z = this.mContentChanged; | ||||
|         this.mContentChanged = false; | ||||
|         this.mProcessingChange |= z; | ||||
|         return z; | ||||
|     } | ||||
|  | ||||
|     public final class ForceLoadContentObserver extends ContentObserver { | ||||
|         @Override // android.database.ContentObserver | ||||
|         public boolean deliverSelfNotifications() { | ||||
|             return true; | ||||
|         } | ||||
|  | ||||
|         public ForceLoadContentObserver() { | ||||
|             super(new Handler()); | ||||
|         } | ||||
|  | ||||
|         @Override // android.database.ContentObserver | ||||
|         public void onChange(boolean z) { | ||||
|             Loader.this.onContentChanged(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public Loader(Context context) { | ||||
|         this.mContext = context.getApplicationContext(); | ||||
|     } | ||||
|  | ||||
|     public void deliverResult(D d) { | ||||
|         OnLoadCompleteListener<D> onLoadCompleteListener = this.mListener; | ||||
|         if (onLoadCompleteListener != null) { | ||||
|             onLoadCompleteListener.onLoadComplete(this, d); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void deliverCancellation() { | ||||
|         OnLoadCanceledListener<D> onLoadCanceledListener = this.mOnLoadCanceledListener; | ||||
|         if (onLoadCanceledListener != null) { | ||||
|             onLoadCanceledListener.onLoadCanceled(this); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void registerListener(int i, OnLoadCompleteListener<D> onLoadCompleteListener) { | ||||
|         if (this.mListener != null) { | ||||
|             throw new IllegalStateException("There is already a listener registered"); | ||||
|         } | ||||
|         this.mListener = onLoadCompleteListener; | ||||
|         this.mId = i; | ||||
|     } | ||||
|  | ||||
|     public void unregisterListener(OnLoadCompleteListener<D> onLoadCompleteListener) { | ||||
|         OnLoadCompleteListener<D> onLoadCompleteListener2 = this.mListener; | ||||
|         if (onLoadCompleteListener2 == null) { | ||||
|             throw new IllegalStateException("No listener register"); | ||||
|         } | ||||
|         if (onLoadCompleteListener2 != onLoadCompleteListener) { | ||||
|             throw new IllegalArgumentException("Attempting to unregister the wrong listener"); | ||||
|         } | ||||
|         this.mListener = null; | ||||
|     } | ||||
|  | ||||
|     public void registerOnLoadCanceledListener(OnLoadCanceledListener<D> onLoadCanceledListener) { | ||||
|         if (this.mOnLoadCanceledListener != null) { | ||||
|             throw new IllegalStateException("There is already a listener registered"); | ||||
|         } | ||||
|         this.mOnLoadCanceledListener = onLoadCanceledListener; | ||||
|     } | ||||
|  | ||||
|     public void unregisterOnLoadCanceledListener(OnLoadCanceledListener<D> onLoadCanceledListener) { | ||||
|         OnLoadCanceledListener<D> onLoadCanceledListener2 = this.mOnLoadCanceledListener; | ||||
|         if (onLoadCanceledListener2 == null) { | ||||
|             throw new IllegalStateException("No listener register"); | ||||
|         } | ||||
|         if (onLoadCanceledListener2 != onLoadCanceledListener) { | ||||
|             throw new IllegalArgumentException("Attempting to unregister the wrong listener"); | ||||
|         } | ||||
|         this.mOnLoadCanceledListener = null; | ||||
|     } | ||||
|  | ||||
|     public final void startLoading() { | ||||
|         this.mStarted = true; | ||||
|         this.mReset = false; | ||||
|         this.mAbandoned = false; | ||||
|         onStartLoading(); | ||||
|     } | ||||
|  | ||||
|     public boolean cancelLoad() { | ||||
|         return onCancelLoad(); | ||||
|     } | ||||
|  | ||||
|     public void forceLoad() { | ||||
|         onForceLoad(); | ||||
|     } | ||||
|  | ||||
|     public void stopLoading() { | ||||
|         this.mStarted = false; | ||||
|         onStopLoading(); | ||||
|     } | ||||
|  | ||||
|     public void abandon() { | ||||
|         this.mAbandoned = true; | ||||
|         onAbandon(); | ||||
|     } | ||||
|  | ||||
|     public void reset() { | ||||
|         onReset(); | ||||
|         this.mReset = true; | ||||
|         this.mStarted = false; | ||||
|         this.mAbandoned = false; | ||||
|         this.mContentChanged = false; | ||||
|         this.mProcessingChange = false; | ||||
|     } | ||||
|  | ||||
|     public void rollbackContentChanged() { | ||||
|         if (this.mProcessingChange) { | ||||
|             onContentChanged(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void onContentChanged() { | ||||
|         if (this.mStarted) { | ||||
|             forceLoad(); | ||||
|         } else { | ||||
|             this.mContentChanged = true; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public String dataToString(D d) { | ||||
|         StringBuilder sb = new StringBuilder(64); | ||||
|         DebugUtils.buildShortClassTag(d, sb); | ||||
|         sb.append("}"); | ||||
|         return sb.toString(); | ||||
|     } | ||||
|  | ||||
|     public String toString() { | ||||
|         StringBuilder sb = new StringBuilder(64); | ||||
|         DebugUtils.buildShortClassTag(this, sb); | ||||
|         sb.append(" id="); | ||||
|         sb.append(this.mId); | ||||
|         sb.append("}"); | ||||
|         return sb.toString(); | ||||
|     } | ||||
|  | ||||
|     @Deprecated | ||||
|     public void dump(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) { | ||||
|         printWriter.print(str); | ||||
|         printWriter.print("mId="); | ||||
|         printWriter.print(this.mId); | ||||
|         printWriter.print(" mListener="); | ||||
|         printWriter.println(this.mListener); | ||||
|         if (this.mStarted || this.mContentChanged || this.mProcessingChange) { | ||||
|             printWriter.print(str); | ||||
|             printWriter.print("mStarted="); | ||||
|             printWriter.print(this.mStarted); | ||||
|             printWriter.print(" mContentChanged="); | ||||
|             printWriter.print(this.mContentChanged); | ||||
|             printWriter.print(" mProcessingChange="); | ||||
|             printWriter.println(this.mProcessingChange); | ||||
|         } | ||||
|         if (this.mAbandoned || this.mReset) { | ||||
|             printWriter.print(str); | ||||
|             printWriter.print("mAbandoned="); | ||||
|             printWriter.print(this.mAbandoned); | ||||
|             printWriter.print(" mReset="); | ||||
|             printWriter.println(this.mReset); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										262
									
								
								02-Easy5/E5/sources/androidx/loader/content/ModernAsyncTask.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										262
									
								
								02-Easy5/E5/sources/androidx/loader/content/ModernAsyncTask.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,262 @@ | ||||
| package androidx.loader.content; | ||||
|  | ||||
| import android.os.Binder; | ||||
| import android.os.Handler; | ||||
| import android.os.Looper; | ||||
| import android.os.Message; | ||||
| import android.os.Process; | ||||
| import android.util.Log; | ||||
| import java.util.concurrent.BlockingQueue; | ||||
| import java.util.concurrent.Callable; | ||||
| import java.util.concurrent.CancellationException; | ||||
| import java.util.concurrent.ExecutionException; | ||||
| import java.util.concurrent.Executor; | ||||
| import java.util.concurrent.FutureTask; | ||||
| import java.util.concurrent.LinkedBlockingQueue; | ||||
| import java.util.concurrent.ThreadFactory; | ||||
| import java.util.concurrent.ThreadPoolExecutor; | ||||
| import java.util.concurrent.TimeUnit; | ||||
| import java.util.concurrent.TimeoutException; | ||||
| import java.util.concurrent.atomic.AtomicBoolean; | ||||
| import java.util.concurrent.atomic.AtomicInteger; | ||||
|  | ||||
| /* loaded from: classes.dex */ | ||||
| abstract class ModernAsyncTask<Params, Progress, Result> { | ||||
|     private static final int CORE_POOL_SIZE = 5; | ||||
|     private static final int KEEP_ALIVE = 1; | ||||
|     private static final String LOG_TAG = "AsyncTask"; | ||||
|     private static final int MAXIMUM_POOL_SIZE = 128; | ||||
|     private static final int MESSAGE_POST_PROGRESS = 2; | ||||
|     private static final int MESSAGE_POST_RESULT = 1; | ||||
|     public static final Executor THREAD_POOL_EXECUTOR; | ||||
|     private static volatile Executor sDefaultExecutor; | ||||
|     private static InternalHandler sHandler; | ||||
|     private static final BlockingQueue<Runnable> sPoolWorkQueue; | ||||
|     private static final ThreadFactory sThreadFactory; | ||||
|     private final FutureTask<Result> mFuture; | ||||
|     private final WorkerRunnable<Params, Result> mWorker; | ||||
|     private volatile Status mStatus = Status.PENDING; | ||||
|     final AtomicBoolean mCancelled = new AtomicBoolean(); | ||||
|     final AtomicBoolean mTaskInvoked = new AtomicBoolean(); | ||||
|  | ||||
|     public enum Status { | ||||
|         PENDING, | ||||
|         RUNNING, | ||||
|         FINISHED | ||||
|     } | ||||
|  | ||||
|     public static void setDefaultExecutor(Executor executor) { | ||||
|         sDefaultExecutor = executor; | ||||
|     } | ||||
|  | ||||
|     protected abstract Result doInBackground(Params... paramsArr); | ||||
|  | ||||
|     public final Status getStatus() { | ||||
|         return this.mStatus; | ||||
|     } | ||||
|  | ||||
|     protected void onCancelled() { | ||||
|     } | ||||
|  | ||||
|     protected void onPostExecute(Result result) { | ||||
|     } | ||||
|  | ||||
|     protected void onPreExecute() { | ||||
|     } | ||||
|  | ||||
|     protected void onProgressUpdate(Progress... progressArr) { | ||||
|     } | ||||
|  | ||||
|     static { | ||||
|         ThreadFactory threadFactory = new ThreadFactory() { // from class: androidx.loader.content.ModernAsyncTask.1 | ||||
|             private final AtomicInteger mCount = new AtomicInteger(1); | ||||
|  | ||||
|             @Override // java.util.concurrent.ThreadFactory | ||||
|             public Thread newThread(Runnable runnable) { | ||||
|                 return new Thread(runnable, "ModernAsyncTask #" + this.mCount.getAndIncrement()); | ||||
|             } | ||||
|         }; | ||||
|         sThreadFactory = threadFactory; | ||||
|         LinkedBlockingQueue linkedBlockingQueue = new LinkedBlockingQueue(10); | ||||
|         sPoolWorkQueue = linkedBlockingQueue; | ||||
|         ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5, 128, 1L, TimeUnit.SECONDS, linkedBlockingQueue, threadFactory); | ||||
|         THREAD_POOL_EXECUTOR = threadPoolExecutor; | ||||
|         sDefaultExecutor = threadPoolExecutor; | ||||
|     } | ||||
|  | ||||
|     private static Handler getHandler() { | ||||
|         InternalHandler internalHandler; | ||||
|         synchronized (ModernAsyncTask.class) { | ||||
|             if (sHandler == null) { | ||||
|                 sHandler = new InternalHandler(); | ||||
|             } | ||||
|             internalHandler = sHandler; | ||||
|         } | ||||
|         return internalHandler; | ||||
|     } | ||||
|  | ||||
|     ModernAsyncTask() { | ||||
|         WorkerRunnable<Params, Result> workerRunnable = new WorkerRunnable<Params, Result>() { // from class: androidx.loader.content.ModernAsyncTask.2 | ||||
|             @Override // java.util.concurrent.Callable | ||||
|             public Result call() throws Exception { | ||||
|                 ModernAsyncTask.this.mTaskInvoked.set(true); | ||||
|                 Result result = null; | ||||
|                 try { | ||||
|                     Process.setThreadPriority(10); | ||||
|                     result = (Result) ModernAsyncTask.this.doInBackground(this.mParams); | ||||
|                     Binder.flushPendingCommands(); | ||||
|                     return result; | ||||
|                 } finally { | ||||
|                 } | ||||
|             } | ||||
|         }; | ||||
|         this.mWorker = workerRunnable; | ||||
|         this.mFuture = new FutureTask<Result>(workerRunnable) { // from class: androidx.loader.content.ModernAsyncTask.3 | ||||
|             @Override // java.util.concurrent.FutureTask | ||||
|             protected void done() { | ||||
|                 try { | ||||
|                     ModernAsyncTask.this.postResultIfNotInvoked(get()); | ||||
|                 } catch (InterruptedException e) { | ||||
|                     Log.w(ModernAsyncTask.LOG_TAG, e); | ||||
|                 } catch (CancellationException unused) { | ||||
|                     ModernAsyncTask.this.postResultIfNotInvoked(null); | ||||
|                 } catch (ExecutionException e2) { | ||||
|                     throw new RuntimeException("An error occurred while executing doInBackground()", e2.getCause()); | ||||
|                 } catch (Throwable th) { | ||||
|                     throw new RuntimeException("An error occurred while executing doInBackground()", th); | ||||
|                 } | ||||
|             } | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     void postResultIfNotInvoked(Result result) { | ||||
|         if (this.mTaskInvoked.get()) { | ||||
|             return; | ||||
|         } | ||||
|         postResult(result); | ||||
|     } | ||||
|  | ||||
|     Result postResult(Result result) { | ||||
|         getHandler().obtainMessage(1, new AsyncTaskResult(this, result)).sendToTarget(); | ||||
|         return result; | ||||
|     } | ||||
|  | ||||
|     protected void onCancelled(Result result) { | ||||
|         onCancelled(); | ||||
|     } | ||||
|  | ||||
|     public final boolean isCancelled() { | ||||
|         return this.mCancelled.get(); | ||||
|     } | ||||
|  | ||||
|     public final boolean cancel(boolean z) { | ||||
|         this.mCancelled.set(true); | ||||
|         return this.mFuture.cancel(z); | ||||
|     } | ||||
|  | ||||
|     public final Result get() throws InterruptedException, ExecutionException { | ||||
|         return this.mFuture.get(); | ||||
|     } | ||||
|  | ||||
|     public final Result get(long j, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException { | ||||
|         return this.mFuture.get(j, timeUnit); | ||||
|     } | ||||
|  | ||||
|     public final ModernAsyncTask<Params, Progress, Result> execute(Params... paramsArr) { | ||||
|         return executeOnExecutor(sDefaultExecutor, paramsArr); | ||||
|     } | ||||
|  | ||||
|     /* renamed from: androidx.loader.content.ModernAsyncTask$4, reason: invalid class name */ | ||||
|     static /* synthetic */ class AnonymousClass4 { | ||||
|         static final /* synthetic */ int[] $SwitchMap$androidx$loader$content$ModernAsyncTask$Status; | ||||
|  | ||||
|         static { | ||||
|             int[] iArr = new int[Status.values().length]; | ||||
|             $SwitchMap$androidx$loader$content$ModernAsyncTask$Status = iArr; | ||||
|             try { | ||||
|                 iArr[Status.RUNNING.ordinal()] = 1; | ||||
|             } catch (NoSuchFieldError unused) { | ||||
|             } | ||||
|             try { | ||||
|                 $SwitchMap$androidx$loader$content$ModernAsyncTask$Status[Status.FINISHED.ordinal()] = 2; | ||||
|             } catch (NoSuchFieldError unused2) { | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public final ModernAsyncTask<Params, Progress, Result> executeOnExecutor(Executor executor, Params... paramsArr) { | ||||
|         if (this.mStatus != Status.PENDING) { | ||||
|             int i = AnonymousClass4.$SwitchMap$androidx$loader$content$ModernAsyncTask$Status[this.mStatus.ordinal()]; | ||||
|             if (i == 1) { | ||||
|                 throw new IllegalStateException("Cannot execute task: the task is already running."); | ||||
|             } | ||||
|             if (i == 2) { | ||||
|                 throw new IllegalStateException("Cannot execute task: the task has already been executed (a task can be executed only once)"); | ||||
|             } | ||||
|             throw new IllegalStateException("We should never reach this state"); | ||||
|         } | ||||
|         this.mStatus = Status.RUNNING; | ||||
|         onPreExecute(); | ||||
|         this.mWorker.mParams = paramsArr; | ||||
|         executor.execute(this.mFuture); | ||||
|         return this; | ||||
|     } | ||||
|  | ||||
|     public static void execute(Runnable runnable) { | ||||
|         sDefaultExecutor.execute(runnable); | ||||
|     } | ||||
|  | ||||
|     protected final void publishProgress(Progress... progressArr) { | ||||
|         if (isCancelled()) { | ||||
|             return; | ||||
|         } | ||||
|         getHandler().obtainMessage(2, new AsyncTaskResult(this, progressArr)).sendToTarget(); | ||||
|     } | ||||
|  | ||||
|     void finish(Result result) { | ||||
|         if (isCancelled()) { | ||||
|             onCancelled(result); | ||||
|         } else { | ||||
|             onPostExecute(result); | ||||
|         } | ||||
|         this.mStatus = Status.FINISHED; | ||||
|     } | ||||
|  | ||||
|     private static class InternalHandler extends Handler { | ||||
|         InternalHandler() { | ||||
|             super(Looper.getMainLooper()); | ||||
|         } | ||||
|  | ||||
|         /* JADX WARN: Multi-variable type inference failed */ | ||||
|         @Override // android.os.Handler | ||||
|         public void handleMessage(Message message) { | ||||
|             AsyncTaskResult asyncTaskResult = (AsyncTaskResult) message.obj; | ||||
|             int i = message.what; | ||||
|             if (i == 1) { | ||||
|                 asyncTaskResult.mTask.finish(asyncTaskResult.mData[0]); | ||||
|             } else { | ||||
|                 if (i != 2) { | ||||
|                     return; | ||||
|                 } | ||||
|                 asyncTaskResult.mTask.onProgressUpdate(asyncTaskResult.mData); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static abstract class WorkerRunnable<Params, Result> implements Callable<Result> { | ||||
|         Params[] mParams; | ||||
|  | ||||
|         WorkerRunnable() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static class AsyncTaskResult<Data> { | ||||
|         final Data[] mData; | ||||
|         final ModernAsyncTask mTask; | ||||
|  | ||||
|         AsyncTaskResult(ModernAsyncTask modernAsyncTask, Data... dataArr) { | ||||
|             this.mTask = modernAsyncTask; | ||||
|             this.mData = dataArr; | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user