Skip to content

Commit

Permalink
Merge pull request #157 from yashk2000/autoFill
Browse files Browse the repository at this point in the history
Fix #147 Add feature to autofill the survey
  • Loading branch information
yashk2000 authored Aug 8, 2020
2 parents 9883a42 + e99fb82 commit 5bdef41
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class ComputerVisionActivity : AppCompatActivity(), ComputerVisionMVPView {

val labelList: MutableList<String> = ArrayList()

companion object {
@JvmStatic var finalLabels: MutableList<List<String>> = ArrayList()
}

lateinit var localModel: LocalModel
lateinit var customImageLabelerOptions: CustomImageLabelerOptions
lateinit var imageLabeler: ImageLabeler

var finalLabels: MutableList<List<String>> = ArrayList()
var counter = 0
var imageNos = 0

Expand Down Expand Up @@ -109,13 +111,13 @@ class ComputerVisionActivity : AppCompatActivity(), ComputerVisionMVPView {
override fun fetchFromGallery() {
try {
if (ActivityCompat.checkSelfPermission(
this@ComputerVisionActivity,
Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
this@ComputerVisionActivity,
Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED
) {
ActivityCompat.requestPermissions(
this@ComputerVisionActivity,
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE),
PICK_FROM_GALLERY
this@ComputerVisionActivity,
arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE),
PICK_FROM_GALLERY
)
} else {
val intent = Intent()
Expand Down Expand Up @@ -148,6 +150,7 @@ class ComputerVisionActivity : AppCompatActivity(), ComputerVisionMVPView {
}

override fun analyzeImages() {
res_list.adapter = null
for (image in images) {
detect(image!!)
}
Expand Down Expand Up @@ -219,7 +222,7 @@ class ComputerVisionActivity : AppCompatActivity(), ComputerVisionMVPView {
PICK_FROM_GALLERY ->
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
val galleryIntent =
Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
startActivityForResult(galleryIntent, PICK_FROM_GALLERY)
} else {
showToastMessage(getString(R.string.cant_open_gallery))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.mifos.visionppi.ui.new_survey

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import android.widget.Toast
import androidx.fragment.app.Fragment
Expand All @@ -22,6 +23,7 @@ class NewPPISurveyActivity : FragmentActivity(), NewSurveyMVPView {
private lateinit var mPager: ViewPager
var mNewSurveyPresenter : NewSurveyPresenter = NewSurveyPresenter()
lateinit var mPPISurvey: PPISurvey
var list: MutableList<List<String>> = ArrayList()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -39,6 +41,16 @@ class NewPPISurveyActivity : FragmentActivity(), NewSurveyMVPView {
}
}

override fun onResume() {
super.onResume()
Log.d("NewPPISurveyActivity", ComputerVisionActivity.finalLabels.toString())
if (ComputerVisionActivity.finalLabels.isNotEmpty()) {
list = ComputerVisionActivity.finalLabels
val s: String = mPPISurvey.questionDatas.get(mPager.currentItem).text
Log.d("NewPPISurveyActivity", s)
}
}

fun launchCVActivity(v: View) {
val intent = Intent(applicationContext, ComputerVisionActivity::class.java)
startActivity(intent)
Expand All @@ -59,7 +71,7 @@ class NewPPISurveyActivity : FragmentActivity(), NewSurveyMVPView {
private inner class ScreenSlidePagerAdapter(fm: FragmentManager) : FragmentStatePagerAdapter(fm) {
override fun getCount(): Int = mPPISurvey.questionDatas.size

override fun getItem(position: Int): Fragment = PPIQuestionFragment(mPPISurvey.questionDatas.get(position), applicationContext) { response: Response -> onResponseClicked(response) }
override fun getItem(position: Int): Fragment = PPIQuestionFragment(mPPISurvey.questionDatas.get(position), applicationContext, list) { response: Response -> onResponseClicked(response) }
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.mifos.visionppi.ui.new_survey

import android.content.Context
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
Expand All @@ -14,12 +15,81 @@ import org.mifos.visionppi.objects.Question
import org.mifos.visionppi.objects.Response


class PPIQuestionFragment( var questionData: Question, val mContext: Context, val responseClick :(response : Response) -> Unit) : Fragment() {
class PPIQuestionFragment(var questionData: Question, val mContext: Context, val list: MutableList<List<String>>, val responseClick: (response: Response) -> Unit) : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
val view = inflater.inflate(R.layout.ppi_question_layout, container, false)
view.question.text = questionData.text
view.responses.layoutManager = LinearLayoutManager(context)
if (!list.isNullOrEmpty()) {
var s: String = ""
var c: Int = 0
var thatch = false
var sc = false
var fridge = false
var washer = false
var tv = false
var player = false
var mh = false
list.forEach {
it.forEach {
if (it.contains("thatch", ignoreCase = true)) {
thatch = true
} else if (it.contains("mobile home", ignoreCase = true) || it.contains("patio", ignoreCase = true)) {
mh = true
} else if (it.contains("studio couch", ignoreCase = true)) {
sc = true
} else if (it.contains("refrigerator", ignoreCase = true)) {
fridge = true
} else if (it.contains("washer", ignoreCase = true)) {
washer = true
} else if (it.contains("television", ignoreCase = true) || it.contains("entertainment center", ignoreCase = true) || it.contains("home theater", ignoreCase = true)) {
tv = true
} else if (it.contains("cassette player", ignoreCase = true) || it.contains("CD player", ignoreCase = true) || it.contains("tape player", ignoreCase = true)) {
player = true
} else if (it.contains("cellular telephone", ignoreCase = true) || it.contains("dial telephone", ignoreCase = true)) {
++c;
}
}
}

if (questionData.text.contains("construction materials", ignoreCase = true)) {
if (thatch && !mh) {
s = "The outer walls are made up of predominantly light materials"
} else {
s = "The outer walls are made of predominantly strong or strong materials"
}
} else if (questionData.text.contains("sala sets", ignoreCase = true)) {
if (sc) {
s = "There is atleast 1 salsa set present"
} else {
s = "There is no salsa set"
}
} else if (questionData.text.contains("washing machine", ignoreCase = true)) {
if (fridge && !washer) {
s = "Only a refrigerator is present"
} else if (washer && !fridge) {
s = "Only a washing machine is present"
} else if (washer && fridge) {
s = "Both are present"
} else {
s = "Neither are present"
}
} else if (questionData.text.contains("television", ignoreCase = true)) {
if (tv && !player) {
s = "Only television is present"
} else if (player && !tv) {
s = "A VTR/VHS/VCD/DVD Player is present"
} else if (!tv && !player) {
s = "Neither is pres"
}
} else if (questionData.text.contains("telephones", ignoreCase = true)) {
s = "There are $c telephones detected"
}

view.res.text = s
view.res.visibility = View.VISIBLE
}
view.responses.adapter = ResponseAdapter(questionData.responseDatas, mContext, responseClick)
return view
}
Expand Down
16 changes: 14 additions & 2 deletions visionppi/app/src/main/res/layout/ppi_question_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,27 @@
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="fill_parent">
android:layout_height="wrap_content">


<androidx.recyclerview.widget.RecyclerView
android:id="@+id/responses"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1000"
android:layout_margin="@dimen/ll_margin"/>

<TextView
android:id="@+id/res"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
android:layout_weight="1"
android:layout_margin="16sp"
android:textSize="@dimen/text_size"
android:textAlignment="center"
android:text=""/>

<Button
android:text="@string/submit_survey"
android:layout_width="match_parent"
Expand Down

0 comments on commit 5bdef41

Please sign in to comment.