) = with(StringBuilder()) {
25 | result.forEach {
26 | append("Landmark id: ${it.entityId}")
27 |
28 | val confidenceProbability = it.confidence * 100
29 | append("Probability of confidence: $confidenceProbability")
30 |
31 | val landmark = it.landmark
32 | append("The landmark is called $landmark")
33 |
34 | it.locations.forEach {
35 | append("Location(${it.latitude}, ${it.longitude})")
36 | }
37 | }
38 |
39 | if (this.isBlank()) {
40 | return RESULT_TITLE + EMPTY_RESULT_MESSAGE
41 | }
42 |
43 | RESULT_TITLE + toString()
44 | }
45 |
46 | override fun onDetectionFailure(exception: Exception): String {
47 | return ERROR_MESSAGE + exception.message
48 | }
49 |
50 | companion object {
51 | private const val RESULT_TITLE = "Landmark detection results\n\n"
52 |
53 | private const val EMPTY_RESULT_MESSAGE = "Failed to detect landmarks in the provided image."
54 |
55 | private const val ERROR_MESSAGE = "An error occurred while trying to detect landmarks in the provided image.\n\nCause: "
56 | }
57 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/core/api/MLKitApi.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.core.api
2 |
3 | import com.google.android.gms.tasks.Task
4 | import com.google.firebase.ml.vision.FirebaseVision
5 |
6 |
7 | abstract class MLKitApi {
8 |
9 | protected val firebaseVisionInstance = FirebaseVision.getInstance()
10 |
11 | protected abstract val processor: P
12 |
13 | protected abstract fun detectInImage(image: String, onSuccess: (String) -> Unit, onFailure: (String) -> Unit): Task
14 |
15 | protected abstract fun onDetectionSuccess(result: T): String
16 |
17 | protected abstract fun onDetectionFailure(exception: Exception): String
18 |
19 | fun process(image: String, onSuccess: (String) -> Unit, onFailure: (String) -> Unit) {
20 | detectInImage(image, onSuccess, onFailure)
21 | .addOnSuccessListener { onSuccess(onDetectionSuccess(it)) }
22 | .addOnFailureListener { onFailure(onDetectionFailure(it)) }
23 | }
24 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/core/api/MLkitApiFactory.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.core.api
2 |
3 | import io.husaynhakeem.mlkit_sample.core.model.MLKitApiType
4 | import io.husaynhakeem.mlkit_sample.core.model.MLKitApiType.*
5 | import java.util.*
6 |
7 |
8 | object MLkitApiFactory {
9 |
10 | private val apis = EnumMap>(MLKitApiType::class.java)
11 |
12 | fun get(type: MLKitApiType): MLKitApi<*, *> = when (type) {
13 | BARCODE_DETECTOR -> apis.getOrPut(BARCODE_DETECTOR, { BarcodeDetector() })
14 | FACE_DETECTOR -> apis.getOrPut(FACE_DETECTOR, { FaceDetector() })
15 | IMAGE_LABELER -> apis.getOrPut(IMAGE_LABELER, { ImageLabeler() })
16 | LANDMARK_DETECTOR -> apis.getOrPut(LANDMARK_DETECTOR, { LandmarkDetector() })
17 | TEXT_DETECTOR -> apis.getOrPut(TEXT_DETECTOR, { TextDetector() })
18 | }
19 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/core/api/TextDetector.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.core.api
2 |
3 | import com.google.android.gms.tasks.Task
4 | import com.google.firebase.ml.vision.text.FirebaseVisionText
5 | import com.google.firebase.ml.vision.text.FirebaseVisionTextDetector
6 | import io.husaynhakeem.mlkit_sample.core.visionimage.BitmapVisionImageGenerator
7 |
8 |
9 | class TextDetector : MLKitApi() {
10 |
11 | override val processor: FirebaseVisionTextDetector
12 | get() = firebaseVisionInstance.visionTextDetector
13 |
14 | override fun detectInImage(image: String, onSuccess: (String) -> Unit, onFailure: (String) -> Unit): Task {
15 | return processor.detectInImage(BitmapVisionImageGenerator(image).get())
16 | }
17 |
18 | override fun onDetectionSuccess(result: FirebaseVisionText): String {
19 | val stringResult = recognizedTextAsBlocks(result)
20 | if (stringResult.isBlank()) {
21 | return RESULT_TITLE + EMPTY_RESULT_MESSAGE
22 | }
23 | return RESULT_TITLE + stringResult
24 | }
25 |
26 | private fun recognizedTextAsSingleLine(text: FirebaseVisionText): String = with(StringBuilder()) {
27 | text.blocks.forEach {
28 | it.lines.forEach {
29 | it.elements.forEach {
30 | append(it.text).append(" ")
31 | }
32 | }
33 | }
34 | toString()
35 | }
36 |
37 | private fun recognizedTextAsBlocks(text: FirebaseVisionText): String = with(StringBuilder()) {
38 |
39 | text.blocks.forEach {
40 | append(it.text).append(" ")
41 | }
42 |
43 | toString()
44 | }
45 |
46 | override fun onDetectionFailure(exception: Exception): String {
47 | return ERROR_MESSAGE + exception.message
48 | }
49 |
50 | companion object {
51 | private const val RESULT_TITLE = "Text detection results\n\n"
52 |
53 | private const val EMPTY_RESULT_MESSAGE = "Failed to detect text in the provided image."
54 |
55 | private const val ERROR_MESSAGE = "An error occurred while trying to detect text in the provided image.\n\nCause: "
56 | }
57 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/core/model/MLKitApiType.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.core.model
2 |
3 |
4 | enum class MLKitApiType {
5 | BARCODE_DETECTOR,
6 | FACE_DETECTOR,
7 | IMAGE_LABELER,
8 | LANDMARK_DETECTOR,
9 | TEXT_DETECTOR
10 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/core/model/OptionModels.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.core.model
2 |
3 | import androidx.annotation.DrawableRes
4 | import androidx.annotation.StringRes
5 |
6 | open class UserOption(
7 | @DrawableRes open val iconResId: Int,
8 | @StringRes open val title: Int,
9 | @StringRes open val body: Int)
10 |
11 | data class MLKitApiOption(
12 | @DrawableRes override val iconResId: Int,
13 | @StringRes override val title: Int,
14 | @StringRes override val body: Int,
15 | val type: MLKitApiType,
16 | val isEnabled: Boolean) : UserOption(iconResId, title, body)
17 |
18 | data class NewImageOption(
19 | @DrawableRes override val iconResId: Int,
20 | @StringRes override val title: Int,
21 | @StringRes override val body: Int) : UserOption(iconResId, title, body)
22 |
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/core/ui/CenteredHorizontalLayoutManager.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.core.ui
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import androidx.recyclerview.widget.LinearLayoutManager
5 | import io.husaynhakeem.mlkit_sample.R
6 |
7 |
8 | class CenteredHorizontalLayoutManager(context: AppCompatActivity) :
9 | LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) {
10 |
11 | private val windowWidth = context.windowManager.defaultDisplay.width
12 | private val itemViewWidth = context.resources.getDimension(R.dimen.user_option_imageview_size)
13 |
14 | override fun getPaddingLeft(): Int {
15 | return ((windowWidth / 2) - (itemViewWidth / 2)).toInt()
16 | }
17 |
18 | override fun getPaddingRight(): Int {
19 | return paddingLeft
20 | }
21 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/core/visionimage/BitmapVisionImageGenerator.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.core.visionimage
2 |
3 | import android.graphics.BitmapFactory
4 | import com.google.firebase.ml.vision.common.FirebaseVisionImage
5 |
6 |
7 | class BitmapVisionImageGenerator(private val imagePath: String) : FirebaseVisionImageGenerator {
8 |
9 | override fun get(): FirebaseVisionImage = FirebaseVisionImage.fromBitmap(BitmapFactory.decodeFile(imagePath))
10 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/core/visionimage/FileVisionImageGenerator.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.core.visionimage
2 |
3 | import android.content.Context
4 | import android.net.Uri
5 | import com.google.firebase.ml.vision.common.FirebaseVisionImage
6 |
7 |
8 | class FileVisionImageGenerator(
9 | private val context: Context,
10 | private val imagePath: String) : FirebaseVisionImageGenerator {
11 |
12 | override fun get(): FirebaseVisionImage =
13 | FirebaseVisionImage.fromFilePath(context, Uri.parse(URI_FILE_PREFIX + imagePath))
14 |
15 | companion object {
16 | private const val URI_FILE_PREFIX = "file://"
17 | }
18 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/core/visionimage/FirebaseVisionImageGenerator.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.core.visionimage
2 |
3 | import com.google.firebase.ml.vision.common.FirebaseVisionImage
4 |
5 |
6 | interface FirebaseVisionImageGenerator {
7 |
8 | fun get() : FirebaseVisionImage
9 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/core/wrapper/SharedPreferencesWrapper.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.core.wrapper
2 |
3 | import android.content.Context.MODE_PRIVATE
4 | import io.husaynhakeem.mlkit_sample.MLKitApplication
5 | import io.husaynhakeem.mlkit_sample.R
6 |
7 |
8 | object SharedPreferencesWrapper {
9 |
10 | private val preferences by lazy {
11 | with(MLKitApplication.instance.applicationContext) {
12 | this.getSharedPreferences(this.getString(R.string.preferences_file), MODE_PRIVATE)
13 | }
14 | }
15 |
16 | fun put(key: String, value: Any) {
17 | when (value) {
18 | is Int -> preferences.edit().putInt(key, value).apply()
19 | is Long -> preferences.edit().putLong(key, value).apply()
20 | is Boolean -> preferences.edit().putBoolean(key, value).apply()
21 | is Float -> preferences.edit().putFloat(key, value).apply()
22 | is String -> preferences.edit().putString(key, value).apply()
23 | }
24 | }
25 |
26 | fun getBoolean(key: String) = preferences.getBoolean(key, true)
27 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/ui/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.ui
2 |
3 | import android.content.Intent
4 | import android.graphics.BitmapFactory
5 | import android.net.Uri
6 | import android.os.Bundle
7 | import android.view.Menu
8 | import android.view.MenuItem
9 | import android.view.View
10 | import androidx.appcompat.app.AppCompatActivity
11 | import androidx.lifecycle.Observer
12 | import androidx.lifecycle.ViewModelProviders
13 | import androidx.recyclerview.widget.LinearSnapHelper
14 | import com.esafirm.imagepicker.features.ImagePicker
15 | import io.husaynhakeem.mlkit_sample.R
16 | import io.husaynhakeem.mlkit_sample.core.model.MLKitApiOption
17 | import io.husaynhakeem.mlkit_sample.core.model.NewImageOption
18 | import io.husaynhakeem.mlkit_sample.core.model.UserOption
19 | import io.husaynhakeem.mlkit_sample.core.ui.CenteredHorizontalLayoutManager
20 | import io.husaynhakeem.mlkit_sample.ui.dialog.ImagePickerDialog
21 | import io.husaynhakeem.mlkit_sample.ui.dialog.MLKitApiAboutDialog
22 | import io.husaynhakeem.mlkit_sample.ui.recycler.UserOptionsAdapter
23 | import kotlinx.android.synthetic.main.activity_main.*
24 |
25 | class MainActivity : AppCompatActivity(), ImagePickerDialog.Listener, MLKitApiAboutDialog.Listener {
26 |
27 | private lateinit var viewModel: MainViewModel
28 |
29 | override fun onCreate(savedInstanceState: Bundle?) {
30 | super.onCreate(savedInstanceState)
31 | setContentView(R.layout.activity_main)
32 | setUpViewModel()
33 | setupBackgroundClickListener()
34 | }
35 |
36 | private fun setUpViewModel() {
37 | viewModel = ViewModelProviders.of(this).get(MainViewModel::class.java)
38 | viewModel.viewState.observe(this, Observer {
39 | if (it == null) {
40 | return@Observer
41 | }
42 | renderUserOptions(it.userOptions)
43 | renderLoading(it.isLoading)
44 | renderSelectedImage(it.imagePath)
45 | renderResult(it.result)
46 | renderError(it.error)
47 | renderMLKitApiAboutDialog(it.displayAboutDialog, it.mlKitApiOption)
48 | })
49 | }
50 |
51 | //======================================================
52 | //region UI rendering
53 | //======================================================
54 | private fun renderUserOptions(options: Array) {
55 | if (userOptionsRecyclerView.adapter == null) {
56 | userOptionsRecyclerView.layoutManager = CenteredHorizontalLayoutManager(this@MainActivity)
57 | LinearSnapHelper().attachToRecyclerView(userOptionsRecyclerView)
58 | userOptionsRecyclerView.adapter = UserOptionsAdapter(options, { onUserOptionClicked(it) })
59 | }
60 | }
61 |
62 | private fun renderLoading(isLoading: Boolean) {
63 | progressLoader.visibility = if (isLoading) View.VISIBLE else View.GONE
64 | }
65 |
66 | private fun renderSelectedImage(imagePath: String) {
67 | if (imagePath.isBlank()) {
68 | showImagePicker(false)
69 | } else {
70 | selectedImageImageView.setImageBitmap(BitmapFactory.decodeFile(imagePath))
71 | }
72 | }
73 |
74 | private fun showImagePicker(isCancelable: Boolean) {
75 | if (supportFragmentManager.findFragmentByTag(ImagePickerDialog.TAG) == null) {
76 | val imagePickerDialog = ImagePickerDialog()
77 | imagePickerDialog.isCancelable = isCancelable
78 | imagePickerDialog.show(supportFragmentManager, ImagePickerDialog.TAG)
79 | }
80 | }
81 |
82 | private fun onUserOptionClicked(userOption: UserOption) {
83 | when (userOption) {
84 | is NewImageOption -> showImagePicker(true)
85 | is MLKitApiOption -> viewModel.onMLKitApiOptionSelected(userOption)
86 | }
87 | }
88 |
89 | private fun renderResult(result: String) {
90 | if (result.isNotBlank())
91 | resultTextView.text = result
92 | }
93 |
94 | private fun renderError(error: String) {
95 | if (error.isNotBlank())
96 | resultTextView.text = error
97 | }
98 |
99 | private fun renderMLKitApiAboutDialog(displayAboutDialog: Boolean, option: MLKitApiOption) {
100 | if (displayAboutDialog)
101 | showMLKitAboutDialog(option)
102 | }
103 |
104 | private fun showMLKitAboutDialog(option: MLKitApiOption) {
105 | if (supportFragmentManager.findFragmentByTag(MLKitApiAboutDialog.TAG) == null) {
106 | val dialog = MLKitApiAboutDialog()
107 | val bundle = Bundle()
108 | bundle.putInt(MLKitApiAboutDialog.KEY_TITLE, option.title)
109 | bundle.putInt(MLKitApiAboutDialog.KEY_BODY, option.body)
110 | dialog.arguments = bundle
111 | dialog.show(supportFragmentManager, MLKitApiAboutDialog.TAG)
112 | }
113 | }
114 | //endregion
115 |
116 | private fun setupBackgroundClickListener() {
117 | resultTextView.setOnClickListener {
118 | userOptionsRecyclerView.visibility =
119 | if (userOptionsRecyclerView.visibility == View.VISIBLE) View.GONE else View.VISIBLE
120 | }
121 | }
122 |
123 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
124 | super.onActivityResult(requestCode, resultCode, data)
125 | if (ImagePicker.shouldHandle(requestCode, resultCode, data)) {
126 | val image = ImagePicker.getFirstImageOrNull(data)
127 | if (image != null) {
128 | viewModel.onImageSelected(image.path)
129 | }
130 | }
131 | }
132 |
133 | //======================================================
134 | //region ImagePickerDialog.Listener
135 | //======================================================
136 | override fun onCameraSelected() {
137 | ImagePicker.cameraOnly().start(this)
138 | }
139 |
140 | override fun onGallerySelected() {
141 | ImagePicker.create(this)
142 | .showCamera(false)
143 | .theme(R.style.CameraPickerTheme)
144 | .start()
145 | }
146 | //endregion
147 |
148 | //======================================================
149 | //region MLKitApiAboutDialog.Listener
150 | //======================================================
151 | override fun onDismissed() {
152 | viewModel.onMLKitAboutDialogDismissed()
153 | }
154 | //endregion
155 |
156 | //======================================================
157 | //region Menu
158 | //======================================================
159 | override fun onCreateOptionsMenu(menu: Menu?): Boolean {
160 | menuInflater.inflate(R.menu.menu_main, menu)
161 | return true
162 | }
163 |
164 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
165 | return when (item.itemId) {
166 | R.id.menuItemGithub -> {
167 | openGithubProfile()
168 | true
169 | }
170 | else -> false
171 | }
172 | }
173 |
174 | private fun openGithubProfile() {
175 | val intent = Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.github_profile_url)))
176 | startActivity(intent)
177 | }
178 | //endregion
179 | }
180 |
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/ui/MainViewModel.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.ui
2 |
3 | import androidx.lifecycle.MutableLiveData
4 | import androidx.lifecycle.ViewModel
5 | import io.husaynhakeem.mlkit_sample.core.api.MLkitApiFactory
6 | import io.husaynhakeem.mlkit_sample.core.model.MLKitApiOption
7 | import io.husaynhakeem.mlkit_sample.ui.usecase.DisplayMLKitAboutDialogUseCase
8 |
9 | class MainViewModel : ViewModel() {
10 |
11 | val viewState: MutableLiveData by lazy {
12 | MutableLiveData().apply {
13 | value = MainViewState()
14 | }
15 | }
16 |
17 | fun onImageSelected(imagePath: String) {
18 | viewState.value = viewState.value?.copy(imagePath = imagePath)
19 | processImage()
20 | }
21 |
22 | private fun processImage() {
23 | viewState.value?.let {
24 | processImageWithMLKitApiOption(it.imagePath, it.mlKitApiOption)
25 | }
26 | }
27 |
28 | private fun processImageWithMLKitApiOption(image: String, mlKitApiOption: MLKitApiOption) {
29 | if (!mlKitApiOption.isEnabled) {
30 | return
31 | }
32 | viewState.value = viewState.value?.copy(isLoading = true)
33 | MLkitApiFactory.get(mlKitApiOption.type).process(
34 | image,
35 | { viewState.value = viewState.value?.copy(isLoading = false, result = it, error = "") },
36 | { viewState.value = viewState.value?.copy(isLoading = false, result = "", error = it) })
37 | }
38 |
39 | fun onMLKitApiOptionSelected(option: MLKitApiOption) {
40 | viewState.value?.mlKitApiOption = option
41 | showAboutDialogForMLKitApi(option)
42 | processImage()
43 | }
44 |
45 | private fun showAboutDialogForMLKitApi(option: MLKitApiOption) {
46 | if (DisplayMLKitAboutDialogUseCase.shouldShowAboutDialogFor(option)) {
47 | viewState.value = viewState.value?.copy(displayAboutDialog = true)
48 | }
49 | }
50 |
51 | fun onMLKitAboutDialogDismissed() {
52 | viewState.value = viewState.value?.copy(displayAboutDialog = false)
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/ui/MainViewState.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.ui
2 |
3 | import io.husaynhakeem.mlkit_sample.core.model.MLKitApiOption
4 | import io.husaynhakeem.mlkit_sample.core.model.UserOption
5 | import io.husaynhakeem.mlkit_sample.ui.data.UserOptionsRepository
6 |
7 |
8 | data class MainViewState(
9 | val userOptions: Array = UserOptionsRepository.options,
10 | var isLoading: Boolean = false,
11 | var imagePath: String = "",
12 | var result: String = "",
13 | var error: String = "",
14 | var mlKitApiOption: MLKitApiOption = UserOptionsRepository.firstMLKitApiOption,
15 | var displayAboutDialog: Boolean = false
16 | )
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/ui/data/UserOptionsRepository.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.ui.data
2 |
3 | import io.husaynhakeem.mlkit_sample.R
4 | import io.husaynhakeem.mlkit_sample.core.model.MLKitApiOption
5 | import io.husaynhakeem.mlkit_sample.core.model.MLKitApiType.*
6 | import io.husaynhakeem.mlkit_sample.core.model.NewImageOption
7 | import io.husaynhakeem.mlkit_sample.core.model.UserOption
8 |
9 |
10 | object UserOptionsRepository {
11 |
12 | val options: Array by lazy {
13 | arrayOf(
14 | NewImageOption(
15 | R.drawable.ic_new_image,
16 | R.string.new_image_title,
17 | R.string.new_image_body),
18 | MLKitApiOption(
19 | R.drawable.ic_barcode_detector,
20 | R.string.barcode_detector_title,
21 | R.string.barcode_detector_body,
22 | BARCODE_DETECTOR,
23 | true),
24 | MLKitApiOption(
25 | R.drawable.ic_face_detector,
26 | R.string.face_detector_title,
27 | R.string.face_detector_body,
28 | FACE_DETECTOR,
29 | true),
30 | MLKitApiOption(
31 | R.drawable.ic_image_labeler,
32 | R.string.image_labeler_title,
33 | R.string.image_labeler_body,
34 | IMAGE_LABELER,
35 | true),
36 | MLKitApiOption(
37 | R.drawable.ic_landmark_detector,
38 | R.string.landmark_detector_title,
39 | R.string.landmark_detector_body,
40 | LANDMARK_DETECTOR,
41 | false),
42 | MLKitApiOption(
43 | R.drawable.ic_text_detector,
44 | R.string.text_detector_title,
45 | R.string.text_detector_body,
46 | TEXT_DETECTOR,
47 | true))
48 | }
49 |
50 | val firstMLKitApiOption: MLKitApiOption = options[1] as MLKitApiOption
51 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/ui/dialog/ImagePickerDialog.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.ui.dialog
2 |
3 | import android.app.Dialog
4 | import android.content.Context
5 | import android.os.Bundle
6 | import androidx.appcompat.app.AlertDialog
7 | import androidx.fragment.app.DialogFragment
8 | import io.husaynhakeem.mlkit_sample.R
9 |
10 |
11 | class ImagePickerDialog : DialogFragment() {
12 |
13 | private var listener: Listener? = null
14 |
15 | override fun onAttach(context: Context?) {
16 | super.onAttach(context)
17 | if (context is Listener) {
18 | listener = context
19 | }
20 | }
21 |
22 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
23 | return AlertDialog.Builder(context!!)
24 | .setTitle(R.string.image_picker_dialog_title)
25 | .setMessage(R.string.image_picker_dialog_message)
26 | .setPositiveButton(R.string.image_picker_dialog_button_camera, { _, _ ->
27 | listener?.onCameraSelected()
28 | })
29 | .setNegativeButton(R.string.image_picker_dialog_button_gallery, { _, _ ->
30 | listener?.onGallerySelected()
31 | })
32 | .create()
33 | }
34 |
35 | companion object {
36 | val TAG = ImagePickerDialog::class.java.simpleName
37 | }
38 |
39 | interface Listener {
40 | fun onCameraSelected()
41 | fun onGallerySelected()
42 | }
43 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/ui/dialog/MLKitApiAboutDialog.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.ui.dialog
2 |
3 | import android.app.Dialog
4 | import android.content.Context
5 | import android.os.Bundle
6 | import androidx.appcompat.app.AlertDialog
7 | import androidx.fragment.app.DialogFragment
8 | import io.husaynhakeem.mlkit_sample.R
9 |
10 |
11 | class MLKitApiAboutDialog : DialogFragment() {
12 |
13 | private var listener: Listener? = null
14 |
15 | override fun onAttach(context: Context?) {
16 | super.onAttach(context)
17 | if (context is Listener) {
18 | listener = context
19 | }
20 | }
21 |
22 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
23 | val title = arguments?.getInt(KEY_TITLE) ?: 0
24 | val body = arguments?.getInt(KEY_BODY) ?: 0
25 | return AlertDialog.Builder(context!!)
26 | .setTitle(title)
27 | .setMessage(body)
28 | .setPositiveButton(R.string.definition_dialog_button_label, { _, _ -> listener?.onDismissed() })
29 | .create()
30 | }
31 |
32 | companion object {
33 | val TAG = MLKitApiAboutDialog::class.java.simpleName
34 | const val KEY_TITLE = "key_title"
35 | const val KEY_BODY = "key_body"
36 | }
37 |
38 | interface Listener {
39 | fun onDismissed()
40 | }
41 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/ui/recycler/UserOptionViewHolder.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.ui.recycler
2 |
3 | import android.view.LayoutInflater
4 | import android.view.ViewGroup
5 | import androidx.recyclerview.widget.RecyclerView
6 | import io.husaynhakeem.mlkit_sample.R
7 | import io.husaynhakeem.mlkit_sample.core.model.UserOption
8 | import kotlinx.android.synthetic.main.item_user_option.view.*
9 |
10 | class UserOptionViewHolder(parent: ViewGroup, private val onItemClickListener: (UserOption) -> Unit) :
11 | RecyclerView.ViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_user_option, parent, false)) {
12 |
13 | fun bind(option: UserOption) {
14 | itemView.userOptionImageView.setImageResource(option.iconResId)
15 | itemView.setOnClickListener { onItemClickListener.invoke(option) }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/ui/recycler/UserOptionsAdapter.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.ui.recycler
2 |
3 | import android.view.ViewGroup
4 | import androidx.recyclerview.widget.RecyclerView
5 | import io.husaynhakeem.mlkit_sample.core.model.UserOption
6 |
7 | class UserOptionsAdapter(
8 | private val options: Array,
9 | private val onItemClickListener: (UserOption) -> Unit) : RecyclerView.Adapter() {
10 |
11 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = UserOptionViewHolder(parent, onItemClickListener)
12 |
13 | override fun onBindViewHolder(holder: UserOptionViewHolder, position: Int) {
14 | holder.bind(options[position])
15 | }
16 |
17 | override fun getItemCount() = options.size
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/io/husaynhakeem/mlkit_sample/ui/usecase/DisplayMLKitAboutDialogUseCase.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample.ui.usecase
2 |
3 | import io.husaynhakeem.mlkit_sample.core.model.MLKitApiOption
4 | import io.husaynhakeem.mlkit_sample.core.wrapper.SharedPreferencesWrapper
5 |
6 |
7 | object DisplayMLKitAboutDialogUseCase {
8 |
9 | fun shouldShowAboutDialogFor(option: MLKitApiOption): Boolean {
10 | val isOptionFirstCall = SharedPreferencesWrapper.getBoolean(option.type.name)
11 | if (isOptionFirstCall) {
12 | SharedPreferencesWrapper.put(option.type.name, false)
13 | }
14 | return isOptionFirstCall || !option.isEnabled
15 | }
16 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_barcode_detector.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/drawable/ic_barcode_detector.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_face_detector.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/drawable/ic_face_detector.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_github.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/drawable/ic_github.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_image_labeler.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/drawable/ic_image_labeler.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_landmark_detector.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/drawable/ic_landmark_detector.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_new_image.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_text_detector.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/drawable/ic_text_detector.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/white_rounded_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
19 |
20 |
24 |
25 |
36 |
37 |
38 |
45 |
46 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_user_option.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #4688F1
4 | #4688F1
5 | #D81B60
6 |
7 | #90000000
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 70dp
5 | 16dp
6 |
7 | 12dp
8 | 24dp
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Machine Learning Kit - Sample
3 | mlkit_preferences
4 |
5 | Select an image
6 | Select an image using the
7 | Camera
8 | Gallery
9 | Got it!
10 |
11 |
12 | Choose a new image
13 |
14 | Barcode Detector
15 | With ML Kit\'s barcode scanning API, you can read data encoded using most standard barcode formats.
16 |
17 | Face detector
18 | With ML Kit\'s face detection API, you can detect faces in an image and identify key facial features.
19 |
20 | Image Labeler
21 | With ML Kit\'s image labeling APIs, you can recognize entities in an image without having to provide any additional contextual metadata, using either an on-device API or a cloud-based API.
22 |
23 | Landmark Detector (Disabled)
24 | With ML Kit\'s landmark recognition API, you can recognize well-known landmarks in an image.
25 |
26 | Text Detector
27 | With ML Kit\'s text recognition APIs, you can recognize text in any Latin-based language (and more, with Cloud-based text recognition).
28 |
29 | Github
30 | https://github.com/husaynhakeem
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/test/java/io/husaynhakeem/mlkit_sample/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package io.husaynhakeem.mlkit_sample
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.2.41'
5 | repositories {
6 | google()
7 | jcenter()
8 | }
9 | dependencies {
10 | classpath 'com.android.tools.build:gradle:3.2.0-alpha14'
11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
12 | classpath 'com.google.gms:google-services:3.3.1'
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | jcenter()
20 | maven { url "https://jitpack.io" }
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
28 | ext {
29 | supportLibraryVersion = '27.1.1'
30 | constraintLayoutVersion = '1.1.0'
31 | firebaseCoreVersion = '15.0.2'
32 | firebaseMLKitVersion = '15.0.0'
33 | navigationVersion = '1.0.0-alpha01'
34 | materialVersion = '1.0.0-alpha1'
35 | imagePickerVersion = '1.12.0'
36 | }
37 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | android.enableJetifier=true
10 | android.useAndroidX=true
11 | org.gradle.jvmargs=-Xmx1536m
12 | # When configured, Gradle will run in incubating parallel mode.
13 | # This option should only be used with decoupled projects. More details, visit
14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
15 | # org.gradle.parallel=true
16 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/husaynhakeem/Android-ML-Kit-Sample/8e8f3766da920ace0f5e9f0e83d95679cb98f935/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------