This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repository @Inject constructor() | |
class BisonWorker @AssistedInject constructor( | |
@Assisted private val appContext: Context, | |
@Assisted private val params: WorkerParameters, | |
private val repository: Repository | |
) : Worker(appContext, params) { | |
override fun doWork(): Result { | |
Log.d(TAG, "$repository is injected") | |
return Result.success() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BisonApplication : Application() { | |
@SuppressLint("SimpleDateFormat", "HardwareIds") | |
override fun onCreate() { | |
super.onCreate() | |
val factory: AppWorkerFactory = DaggerBisonAppComponent.create().factory() | |
WorkManager.initialize(this, Configuration.Builder().setWorkerFactory(factory).build()) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component(modules = [AppAssistedInjectModule::class, WorkerBindingModule::class]) | |
interface BisonAppComponent { | |
fun factory(): AppWorkerFactory | |
} | |
@Module(includes = [AssistedInject_AppAssistedInjectModule::class]) | |
@AssistedModule | |
abstract class AppAssistedInjectModule {} | |
@MapKey |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Repository @Inject constructor() | |
class BisonWorker @AssistedInject constructor( | |
@Assisted private val appContext: Context, | |
@Assisted private val params: WorkerParameters, | |
private val repository: Repository | |
) : Worker(appContext, params) { | |
override fun doWork(): Result { | |
return Result.success() | |
} | |
@AssistedInject.Factory |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ChildWorkerFactory { | |
fun create(appContext: Context, params: WorkerParameters): ListenableWorker | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AppWorkerFactory @Inject constructor( | |
private val workerFactories: Map<Class<out ListenableWorker>, | |
@JvmSuppressWildcards Provider<ChildWorkerFactory>> | |
) : WorkerFactory() { | |
override fun createWorker( | |
appContext: Context, | |
workerClassName: String, | |
workerParameters: WorkerParameters | |
): ListenableWorker? { | |
val foundEntry = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
def dagger_version = "2.22.1" | |
implementation "com.google.dagger:dagger:$dagger_version" annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version" | |
implementation "com.google.dagger:dagger-android:$dagger_version" | |
implementation "com.google.dagger:dagger-android-support:$dagger_version" | |
annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version" | |
kapt "com.google.dagger:dagger-compiler:$dagger_version" | |
def work_version = "2.0.0" | |
implementation "androidx.work:work-runtime:$work_version" | |
implementation "androidx.work:work-runtime-ktx:$work_version" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun startBackgroundThread() { | |
backgroundThread = HandlerThread(HANDLE_THREAD_NAME) | |
backgroundThread!!.start() | |
backgroundHandler = Handler(backgroundThread!!.looper) | |
synchronized(lock) { | |
runClassifier = true | |
} | |
backgroundHandler!!.post(periodicClassify) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun classifyFrame() { | |
// Get a bitmap with requested width and height. | |
// Also, this bitmap uses ARGB_8888 format. | |
val bitmap = textureView!!.getBitmap(classifier!!.imageSizeX, classifier!!.imageSizeY) | |
// This classifier's function internally has the byte data converted from this bitmap. | |
classifier!!.classifyFrame(bitmap) | |
bitmap.recycle() | |
// mPrintPointArray is the output(results) of inference from input(byte data above) | |
drawView!!.setDrawPoint(classifier!!.mPrintPointArray!!, 0.5f) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun create( | |
activity: Activity, | |
imageSizeX: Int = 192, | |
imageSizeY: Int = 192, | |
outputW: Int = 96, | |
outputH: Int = 96, | |
modelPath: String = "model.tflite", | |
numBytesPerChannel: Int = 4 | |
): ImageClassifierFloatInception = | |
ImageClassifierFloatInception( |