Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-81
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-81
2022-81
Commits
8a99eea5
Commit
8a99eea5
authored
Oct 07, 2022
by
ranthilina99
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update file
parent
4f9212a7
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
1142 additions
and
0 deletions
+1142
-0
app/src/main/java/com/example/eketha/Admin.java
app/src/main/java/com/example/eketha/Admin.java
+14
-0
app/src/main/java/com/example/eketha/Growth.java
app/src/main/java/com/example/eketha/Growth.java
+315
-0
app/src/main/java/com/example/eketha/GrowthDetect.java
app/src/main/java/com/example/eketha/GrowthDetect.java
+112
-0
app/src/main/java/com/example/eketha/GrowthHeight.java
app/src/main/java/com/example/eketha/GrowthHeight.java
+139
-0
app/src/main/java/com/example/eketha/GrowthThreatment.java
app/src/main/java/com/example/eketha/GrowthThreatment.java
+32
-0
app/src/main/java/com/example/eketha/Login.java
app/src/main/java/com/example/eketha/Login.java
+185
-0
app/src/main/java/com/example/eketha/MainActivity.java
app/src/main/java/com/example/eketha/MainActivity.java
+70
-0
app/src/main/java/com/example/eketha/NetworkClient.java
app/src/main/java/com/example/eketha/NetworkClient.java
+18
-0
app/src/main/java/com/example/eketha/Register.java
app/src/main/java/com/example/eketha/Register.java
+205
-0
app/src/main/java/com/example/eketha/UploadApis.java
app/src/main/java/com/example/eketha/UploadApis.java
+15
-0
app/src/main/java/com/example/eketha/growthHome.java
app/src/main/java/com/example/eketha/growthHome.java
+37
-0
No files found.
app/src/main/java/com/example/eketha/Admin.java
0 → 100644
View file @
8a99eea5
package
com.example.eketha
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.os.Bundle
;
public
class
Admin
extends
AppCompatActivity
{
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_admin
);
}
}
\ No newline at end of file
app/src/main/java/com/example/eketha/Growth.java
0 → 100644
View file @
8a99eea5
package
com.example.eketha
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.core.content.FileProvider
;
import
android.Manifest
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.content.res.AssetFileDescriptor
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.media.ThumbnailUtils
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.provider.MediaStore
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
org.tensorflow.lite.DataType
;
import
org.tensorflow.lite.Interpreter
;
import
org.tensorflow.lite.support.common.FileUtil
;
import
org.tensorflow.lite.support.common.TensorOperator
;
import
org.tensorflow.lite.support.common.TensorProcessor
;
import
org.tensorflow.lite.support.common.ops.NormalizeOp
;
import
org.tensorflow.lite.support.image.ImageProcessor
;
import
org.tensorflow.lite.support.image.TensorImage
;
import
org.tensorflow.lite.support.image.ops.ResizeOp
;
import
org.tensorflow.lite.support.image.ops.ResizeWithCropOrPadOp
;
import
org.tensorflow.lite.support.label.TensorLabel
;
import
org.tensorflow.lite.support.tensorbuffer.TensorBuffer
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.nio.MappedByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.text.SimpleDateFormat
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
okhttp3.MediaType
;
import
okhttp3.MultipartBody
;
import
okhttp3.RequestBody
;
import
retrofit2.Call
;
import
retrofit2.Callback
;
import
retrofit2.Response
;
import
retrofit2.Retrofit
;
import
static
android
.
os
.
Environment
.
getExternalStoragePublicDirectory
;
public
class
Growth
extends
AppCompatActivity
{
protected
Interpreter
tflite
;
private
MappedByteBuffer
tfliteModel
;
private
TensorImage
inputImageBuffer
;
private
int
imageSizeX
;
private
int
imageSizeY
;
private
TensorBuffer
outputProbabilityBuffer
;
private
TensorProcessor
probabilityProcessor
;
private
static
final
float
IMAGE_MEAN
=
0.0f
;
private
static
final
float
IMAGE_STD
=
1.0f
;
private
static
final
float
PROBABILITY_MEAN
=
0.0f
;
private
static
final
float
PROBABILITY_STD
=
255.0f
;
private
Bitmap
bitmap
,
outputImage
;
private
List
<
String
>
labels
;
private
Context
context
;
private
Button
btnTakePic
,
btnOpenCam
,
btnConfirm
;
private
ImageView
imageView
;
private
String
pathToFile
;
private
static
final
int
PICK_IMAGE
=
100
;
private
Uri
imageUri
;
private
TextView
classitext
,
treattext
;
private
String
filepath
=
""
;
private
int
imageSize
=
32
;
private
Bitmap
bitmapImage
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_growth
);
btnTakePic
=
findViewById
(
R
.
id
.
btnTakePic
);
imageView
=
findViewById
(
R
.
id
.
image
);
btnOpenCam
=
findViewById
(
R
.
id
.
btnOpenCam
);
btnConfirm
=
findViewById
(
R
.
id
.
btnConfirm
);
classitext
=
findViewById
(
R
.
id
.
classitext
);
if
(
Build
.
VERSION
.
SDK_INT
>=
23
)
{
requestPermissions
(
new
String
[]
{
Manifest
.
permission
.
CAMERA
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
},
2
);
}
btnTakePic
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
M
)
@Override
public
void
onClick
(
View
view
)
{
if
(
checkSelfPermission
(
Manifest
.
permission
.
CAMERA
)
==
PackageManager
.
PERMISSION_GRANTED
)
{
Intent
cameraIntent
=
new
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
);
startActivityForResult
(
cameraIntent
,
3
);
}
else
{
requestPermissions
(
new
String
[]{
Manifest
.
permission
.
CAMERA
},
100
);
}
}
});
btnOpenCam
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
Intent
cameraIntent
=
new
Intent
(
Intent
.
ACTION_PICK
,
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
);
startActivityForResult
(
cameraIntent
,
1
);
}
});
imageView
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
Intent
intent
=
new
Intent
();
intent
.
setType
(
"image/"
);
intent
.
setAction
(
Intent
.
ACTION_GET_CONTENT
);
startActivityForResult
(
Intent
.
createChooser
(
intent
,
"Select Picture"
),
1
);
}
});
btnConfirm
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
int
imageTensorIndex
=
0
;
int
[]
imageShape
=
tflite
.
getInputTensor
(
imageTensorIndex
).
shape
();
// {1, height, width, 3}
imageSizeY
=
imageShape
[
1
];
imageSizeX
=
imageShape
[
2
];
DataType
imageDataType
=
tflite
.
getInputTensor
(
imageTensorIndex
).
dataType
();
int
probabilityTensorIndex
=
0
;
int
[]
probabilityShape
=
tflite
.
getOutputTensor
(
probabilityTensorIndex
).
shape
();
// {1, NUM_CLASSES}
DataType
probabilityDataType
=
tflite
.
getOutputTensor
(
probabilityTensorIndex
).
dataType
();
inputImageBuffer
=
new
TensorImage
(
imageDataType
);
outputProbabilityBuffer
=
TensorBuffer
.
createFixedSize
(
probabilityShape
,
probabilityDataType
);
probabilityProcessor
=
new
TensorProcessor
.
Builder
().
add
(
getPostprocessNormalizeOp
()).
build
();
inputImageBuffer
=
loadImage
(
bitmap
);
tflite
.
run
(
inputImageBuffer
.
getBuffer
(),
outputProbabilityBuffer
.
getBuffer
().
rewind
());
showResult
();
String
result
=
classitext
.
getText
().
toString
();
String
details
=
""
;
String
treatment2
=
""
;
if
(
result
.
equals
(
"Rice"
)){
details
=
"Rice"
;
System
.
out
.
println
(
result
);
}
else
if
(
result
.
equals
(
"Weed"
)){
details
=
getResources
().
getString
(
R
.
string
.
detail1
);
System
.
out
.
println
(
result
);
}
BitmapDrawable
drawable
=
(
BitmapDrawable
)
imageView
.
getDrawable
();
outputImage
=
drawable
.
getBitmap
();
try
{
//Write file
String
filename
=
"bitmap.png"
;
FileOutputStream
stream
=
openFileOutput
(
filename
,
Context
.
MODE_PRIVATE
);
outputImage
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
100
,
stream
);
//Cleanup
stream
.
close
();
outputImage
.
recycle
();
//Pop intent
Intent
intent
=
new
Intent
(
Growth
.
this
,
GrowthDetect
.
class
);
intent
.
putExtra
(
"results"
,
result
);
intent
.
putExtra
(
"details"
,
details
);
if
(
result
.
equals
(
"rice"
)){
intent
.
putExtra
(
"button"
,
"Height Measurement"
);
}
else
if
(
result
.
equals
(
"weed"
)){
intent
.
putExtra
(
"button"
,
"Weed Identification"
);
}
intent
.
putExtra
(
"image"
,
filename
);
startActivity
(
intent
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
});
// First we must create the tflite object, loaded from the model file
try
{
tflite
=
new
Interpreter
(
loadmodelfile
(
this
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
private
void
openGallery
()
{
Intent
gallery
=
new
Intent
(
Intent
.
ACTION_PICK
,
MediaStore
.
Images
.
Media
.
INTERNAL_CONTENT_URI
);
startActivityForResult
(
gallery
,
PICK_IMAGE
);
}
private
void
uploadImage
()
{
File
file
=
new
File
(
filepath
);
Retrofit
retrofit
=
NetworkClient
.
getRetrofit
();
RequestBody
requestBody
=
RequestBody
.
create
(
MediaType
.
parse
(
"image/"
),
file
);
MultipartBody
.
Part
parts
=
MultipartBody
.
Part
.
createFormData
(
"newimage"
,
file
.
getName
(),
requestBody
);
RequestBody
someData
=
RequestBody
.
create
(
MediaType
.
parse
(
"text/plain"
),
"This is a new Image"
);
UploadApis
uploadApis
=
retrofit
.
create
(
UploadApis
.
class
);
Call
call
=
uploadApis
.
uploadImage
(
parts
,
someData
);
call
.
enqueue
(
new
Callback
()
{
@Override
public
void
onResponse
(
Call
call
,
Response
response
)
{
}
@Override
public
void
onFailure
(
Call
call
,
Throwable
t
)
{
}
}
);
}
private
TensorImage
loadImage
(
Bitmap
bitmap
)
{
// Loads bitmap into a TensorImage.
bitmap
=
((
BitmapDrawable
)
imageView
.
getDrawable
()).
getBitmap
();
inputImageBuffer
.
load
(
bitmap
);
// Creates processor for the TensorImage.
int
cropSize
=
Math
.
min
(
bitmap
.
getWidth
(),
bitmap
.
getHeight
());
// TODO(b/143564309): Fuse ops inside ImageProcessor.
ImageProcessor
imageProcessor
=
new
ImageProcessor
.
Builder
()
.
add
(
new
ResizeWithCropOrPadOp
(
cropSize
,
cropSize
))
.
add
(
new
ResizeOp
(
imageSizeX
,
imageSizeY
,
ResizeOp
.
ResizeMethod
.
NEAREST_NEIGHBOR
))
.
add
(
getPreprocessNormalizeOp
())
.
build
();
return
imageProcessor
.
process
(
inputImageBuffer
);
}
private
MappedByteBuffer
loadmodelfile
(
Activity
activity
)
throws
IOException
{
// Open the model using an input stream and memory map it to load
AssetFileDescriptor
fileDescriptor
=
activity
.
getAssets
().
openFd
(
"model.tflite"
);
FileInputStream
inputStream
=
new
FileInputStream
(
fileDescriptor
.
getFileDescriptor
());
FileChannel
fileChannel
=
inputStream
.
getChannel
();
long
startoffset
=
fileDescriptor
.
getStartOffset
();
long
declaredLength
=
fileDescriptor
.
getDeclaredLength
();
return
fileChannel
.
map
(
FileChannel
.
MapMode
.
READ_ONLY
,
startoffset
,
declaredLength
);
}
private
TensorOperator
getPreprocessNormalizeOp
()
{
return
new
NormalizeOp
(
IMAGE_MEAN
,
IMAGE_STD
);
}
private
TensorOperator
getPostprocessNormalizeOp
(){
return
new
NormalizeOp
(
PROBABILITY_MEAN
,
PROBABILITY_STD
);
}
private
void
showResult
(){
try
{
labels
=
FileUtil
.
loadLabels
(
this
,
"dictT.txt"
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
Map
<
String
,
Float
>
labeledProbability
=
new
TensorLabel
(
labels
,
probabilityProcessor
.
process
(
outputProbabilityBuffer
))
.
getMapWithFloatValue
();
float
maxValueInMap
=(
Collections
.
max
(
labeledProbability
.
values
()));
for
(
Map
.
Entry
<
String
,
Float
>
entry
:
labeledProbability
.
entrySet
())
{
if
(
entry
.
getValue
()==
maxValueInMap
)
{
classitext
.
setText
(
entry
.
getKey
());
}
}
}
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
if
(
resultCode
==
RESULT_OK
){
if
(
requestCode
==
3
){
Bitmap
image
=
(
Bitmap
)
data
.
getExtras
().
get
(
"data"
);
bitmapImage
=
image
;
int
dimension
=
Math
.
min
(
image
.
getWidth
(),
image
.
getHeight
());
image
=
ThumbnailUtils
.
extractThumbnail
(
image
,
dimension
,
dimension
);
imageView
.
setImageBitmap
(
image
);
}
else
{
Uri
dat
=
data
.
getData
();
Bitmap
image
=
null
;
try
{
image
=
MediaStore
.
Images
.
Media
.
getBitmap
(
this
.
getContentResolver
(),
dat
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
imageView
.
setImageBitmap
(
image
);
}
}
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
}
}
\ No newline at end of file
app/src/main/java/com/example/eketha/GrowthDetect.java
0 → 100644
View file @
8a99eea5
package
com.example.eketha
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
org.tensorflow.lite.support.common.TensorProcessor
;
import
org.tensorflow.lite.support.tensorbuffer.TensorBuffer
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.util.List
;
public
class
GrowthDetect
extends
AppCompatActivity
{
private
TensorBuffer
outputProbabilityBuffer
;
private
TensorProcessor
probabilityProcessor
;
private
Bitmap
bitmap
,
inputImage
,
outputImage
,
outputImage1
;
private
List
<
String
>
labels
;
private
TextView
resulttext
,
resulttext2
;
private
Button
btnTreatment
,
btn
;
private
ImageView
imageView1
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_growth_detect
);
imageView1
=
findViewById
(
R
.
id
.
image2
);
btnTreatment
=
findViewById
(
R
.
id
.
btnTreatment
);
resulttext
=
findViewById
(
R
.
id
.
resulttext
);
resulttext2
=
findViewById
(
R
.
id
.
resulttext2
);
String
result
=
getIntent
().
getStringExtra
(
"results"
);
resulttext
.
setText
(
result
);
String
det
=
getIntent
().
getStringExtra
(
"details"
);
resulttext2
.
setText
(
det
);
String
button
=
getIntent
().
getStringExtra
(
"button"
);
btnTreatment
.
setText
(
button
);
String
filename
=
getIntent
().
getStringExtra
(
"image"
);
try
{
FileInputStream
is
=
this
.
openFileInput
(
filename
);
inputImage
=
BitmapFactory
.
decodeStream
(
is
);
imageView1
.
setImageBitmap
(
inputImage
);
is
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
if
(
button
.
equals
(
"Height Measurement"
)){
btnTreatment
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
String
result2
=
resulttext
.
getText
().
toString
();
String
treatment
=
""
;
if
(
result2
.
equals
(
"Rice"
)){
treatment
=
"Rice"
;
System
.
out
.
println
(
result2
);
}
else
if
(
result2
.
equals
(
"Weed"
)){
treatment
=
getResources
().
getString
(
R
.
string
.
treatment1
);
System
.
out
.
println
(
result2
);
}
BitmapDrawable
drawable
=
(
BitmapDrawable
)
imageView1
.
getDrawable
();
outputImage
=
drawable
.
getBitmap
();
try
{
//Write file
String
filename
=
"bitmap.png"
;
FileOutputStream
stream
=
openFileOutput
(
filename
,
Context
.
MODE_PRIVATE
);
outputImage
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
100
,
stream
);
//Cleanup
stream
.
close
();
outputImage
.
recycle
();
Intent
intent2
=
new
Intent
(
GrowthDetect
.
this
,
GrowthHeight
.
class
);
intent2
.
putExtra
(
"results2"
,
result2
);
intent2
.
putExtra
(
"image"
,
filename
);
startActivity
(
intent2
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
});
}
else
if
(
button
.
equals
(
"Weed Identification"
))
{
{
btnTreatment
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
// Intent intent2 = new Intent(GrowthDetect.this, Weeds.class);
// startActivity(intent2);
}
});
}
}
}
}
app/src/main/java/com/example/eketha/GrowthHeight.java
0 → 100644
View file @
8a99eea5
package
com.example.eketha
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.graphics.drawable.BitmapDrawable
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.util.Base64
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.ImageView
;
import
com.chaquo.python.PyObject
;
import
com.chaquo.python.Python
;
import
com.chaquo.python.android.AndroidPlatform
;
import
java.io.ByteArrayOutputStream
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
public
class
GrowthHeight
extends
AppCompatActivity
{
private
Handler
handler
=
null
;
private
Bitmap
inputImage
,
newImage
,
bitmap
,
outputImage
,
outputImage1
;
private
Button
btnHeight
,
btnThreatment
;
private
ImageView
imageView1
;
private
BitmapDrawable
drawable
;
private
String
imageString
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_growth_height
);
imageView1
=
findViewById
(
R
.
id
.
imageHeightView
);
btnHeight
=
findViewById
(
R
.
id
.
button3
);
btnThreatment
=
findViewById
(
R
.
id
.
button2
);
if
(!
Python
.
isStarted
())
{
Python
.
start
(
new
AndroidPlatform
(
this
));
}
String
filename
=
getIntent
().
getStringExtra
(
"image"
);
try
{
FileInputStream
is
=
this
.
openFileInput
(
filename
);
inputImage
=
BitmapFactory
.
decodeStream
(
is
);
imageView1
.
setImageBitmap
(
inputImage
);
is
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
btnThreatment
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
BitmapDrawable
drawable
=
(
BitmapDrawable
)
imageView1
.
getDrawable
();
outputImage1
=
drawable
.
getBitmap
();
try
{
//Write file
String
filename
=
"bitmap.png"
;
FileOutputStream
stream
=
openFileOutput
(
filename
,
Context
.
MODE_PRIVATE
);
outputImage1
.
compress
(
Bitmap
.
CompressFormat
.
PNG
,
100
,
stream
);
//Cleanup
stream
.
close
();
outputImage1
.
recycle
();
//Pop intent
Intent
intent
=
new
Intent
(
GrowthHeight
.
this
,
GrowthThreatment
.
class
);
intent
.
putExtra
(
"image"
,
filename
);
startActivity
(
intent
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
});
btnHeight
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
autoDenoiseImage
();
}
});
}
private
void
autoDenoiseImage
()
{
new
Thread
()
{
public
void
run
()
{
startMeasuring
();
newImage
=
outputImage
;
handler
.
sendEmptyMessage
(
0
);
}
}.
start
();
handler
=
new
Handler
()
{
public
void
handleMessage
(
android
.
os
.
Message
msg
)
{
imageView1
.
setImageBitmap
(
outputImage
);
}
;
};
}
public
void
heightImage
(
View
v
)
{
autoDenoiseImage
();
imageView1
.
setImageBitmap
(
newImage
);
}
private
String
getStringImage
(
Bitmap
bitmap
)
{
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
100
,
byteArrayOutputStream
);
byte
[]
imageBytes
=
byteArrayOutputStream
.
toByteArray
();
String
encodedImage
=
Base64
.
encodeToString
(
imageBytes
,
Base64
.
DEFAULT
);
return
encodedImage
;
}
public
void
startMeasuring
()
{
final
Python
py
=
Python
.
getInstance
();
imageString
=
getStringImage
(
inputImage
);
PyObject
pyo
=
py
.
getModule
(
"height"
);
PyObject
obj
=
pyo
.
callAttr
(
"main"
,
imageString
);
String
str
=
obj
.
toString
();
byte
data
[]
=
Base64
.
decode
(
str
,
Base64
.
DEFAULT
);
Bitmap
bmp
=
BitmapFactory
.
decodeByteArray
(
data
,
0
,
data
.
length
);
outputImage
=
bmp
;
}
}
\ No newline at end of file
app/src/main/java/com/example/eketha/GrowthThreatment.java
0 → 100644
View file @
8a99eea5
package
com.example.eketha
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.os.Bundle
;
import
android.widget.ImageView
;
import
java.io.FileInputStream
;
public
class
GrowthThreatment
extends
AppCompatActivity
{
private
Bitmap
inputImage
;
private
ImageView
imageView1
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_growth_threatment
);
imageView1
=
findViewById
(
R
.
id
.
treatImg
);
String
filename
=
getIntent
().
getStringExtra
(
"image"
);
try
{
FileInputStream
is
=
this
.
openFileInput
(
filename
);
inputImage
=
BitmapFactory
.
decodeStream
(
is
);
imageView1
.
setImageBitmap
(
inputImage
);
is
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
\ No newline at end of file
app/src/main/java/com/example/eketha/Login.java
0 → 100644
View file @
8a99eea5
package
com.example.eketha
;
import
androidx.annotation.NonNull
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.os.Bundle
;
import
android.text.InputType
;
import
android.util.Log
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.CheckBox
;
import
android.widget.EditText
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.google.android.gms.tasks.OnFailureListener
;
import
com.google.android.gms.tasks.OnSuccessListener
;
import
com.google.firebase.auth.AuthResult
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.firestore.DocumentReference
;
import
com.google.firebase.firestore.DocumentSnapshot
;
import
com.google.firebase.firestore.FirebaseFirestore
;
public
class
Login
extends
AppCompatActivity
{
EditText
Email
,
password
;
Button
login
;
boolean
valid
;
FirebaseAuth
fAuth
;
FirebaseFirestore
fStore
;
TextView
text2
;
CheckBox
remember
;
SharedPreferences
sharedPreferences
;
SharedPreferences
.
Editor
editor
;
Boolean
saveLogin
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_login
);
Email
=
findViewById
(
R
.
id
.
loginemail
);
password
=
findViewById
(
R
.
id
.
loginpassword
);
login
=
findViewById
(
R
.
id
.
btnlogin
);
text2
=
findViewById
(
R
.
id
.
txtdonthaveacc
);
fAuth
=
FirebaseAuth
.
getInstance
();
fStore
=
FirebaseFirestore
.
getInstance
();
remember
=
findViewById
(
R
.
id
.
rememmber_me
);
password
.
setInputType
(
InputType
.
TYPE_CLASS_TEXT
|
InputType
.
TYPE_TEXT_VARIATION_PASSWORD
);
//remember me---------------------------------------------------------------------------------------------------------------------------
sharedPreferences
=
getSharedPreferences
(
"PRESS_NAME"
,
MODE_PRIVATE
);
editor
=
sharedPreferences
.
edit
();
saveLogin
=
sharedPreferences
.
getBoolean
(
"SaveLogin"
,
true
);
if
(
saveLogin
=
true
)
{
Email
.
setText
(
sharedPreferences
.
getString
(
"Email"
,
null
));
password
.
setText
(
sharedPreferences
.
getString
(
"password"
,
null
));
}
//click the signUp button----------------------------------------------------------------------------------------------------------
text2
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
startActivity
(
new
Intent
(
getApplicationContext
(),
Register
.
class
));
}
});
//-----------------------------------------------------------------------------------------------------------------------------------
//Click the login button------------------------------------------------------------------------------------------------------------
login
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
checkField
(
Email
);
checkField
(
password
);
if
(
valid
)
{
fAuth
.
signInWithEmailAndPassword
(
Email
.
getText
().
toString
(),
password
.
getText
().
toString
()).
addOnSuccessListener
(
new
OnSuccessListener
<
AuthResult
>()
{
@Override
public
void
onSuccess
(
AuthResult
authResult
)
{
Toast
.
makeText
(
Login
.
this
,
"Logging Successfully"
,
Toast
.
LENGTH_SHORT
).
show
();
checkUserAccessLevel
(
authResult
.
getUser
().
getUid
());
//check the remember me checked------------------------------------------------------------------------------------------
if
(
remember
.
isChecked
()){
editor
.
putBoolean
(
"SaveLogin"
,
true
);
editor
.
putString
(
"Email"
,
Email
.
getText
().
toString
());
editor
.
putString
(
"password"
,
password
.
getText
().
toString
());
editor
.
commit
();
Toast
.
makeText
(
Login
.
this
,
"Save Email and password"
,
Toast
.
LENGTH_SHORT
).
show
();
}
else
{
//Toast.makeText(Login.this, "Remember Not Save Email and password", Toast.LENGTH_SHORT).show();
}
//---------------------------------------------------------------------------------------------------------------------
}
}).
addOnFailureListener
(
new
OnFailureListener
()
{
@Override
public
void
onFailure
(
@NonNull
Exception
e
)
{
Toast
.
makeText
(
Login
.
this
,
"Logging Failed"
,
Toast
.
LENGTH_SHORT
).
show
();
}
});
}
}
});
//------------------------------------------------------------------------------------------------------------------------------------------
}
//end the main-------------------------------------------------------------------------------------------------------------------------------
//Define the user roles user and admin-------------------------------------------------------------------------------------------------------
private
void
checkUserAccessLevel
(
String
uid
)
{
DocumentReference
df
=
fStore
.
collection
(
"Users"
).
document
(
uid
);
//extract data from the users
df
.
get
().
addOnSuccessListener
(
new
OnSuccessListener
<
DocumentSnapshot
>()
{
@Override
public
void
onSuccess
(
DocumentSnapshot
documentSnapshot
)
{
Log
.
d
(
"TAG"
,
"onSuccess"
+
documentSnapshot
.
getData
());
//identity user access level
if
(
documentSnapshot
.
getString
(
"isAdmin"
)
!=
null
)
{
//user admin
startActivity
(
new
Intent
(
getApplicationContext
(),
Admin
.
class
));
finish
();
}
if
(
documentSnapshot
.
getString
(
"isUser"
)
!=
null
)
{
//user users
Intent
i
=
new
Intent
(
getApplicationContext
(),
MainActivity
.
class
);
startActivity
(
i
);
finish
();
}
}
});
}
//end user role-----
//check the validation------------------------------------------------------------------------------------------------------------------------
public
boolean
checkField
(
EditText
textFiled
)
{
if
(
textFiled
==
Email
)
{
String
val
=
Email
.
getText
().
toString
();
String
emailPattern
=
"[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+"
;
if
(
val
.
isEmpty
())
{
Email
.
setError
(
"Field cannot be empty"
);
valid
=
false
;
}
else
if
(!
val
.
matches
(
emailPattern
))
{
Email
.
setError
(
"Invalid email address"
);
valid
=
false
;
}
else
{
Email
.
setError
(
null
);
valid
=
true
;
}
return
valid
;
}
else
if
(
textFiled
==
password
){
String
val
=
password
.
getText
().
toString
();
if
(
val
.
isEmpty
())
{
password
.
setError
(
"Field cannot be empty"
);
valid
=
false
;
}
else
if
(
val
.
length
()<
6
)
{
password
.
setError
(
"At least 6 characters"
);
valid
=
false
;
}
else
{
password
.
setError
(
null
);
valid
=
true
;
}
return
valid
;
}
return
valid
;
}
@Override
protected
void
onStart
()
{
super
.
onStart
();
if
(
FirebaseAuth
.
getInstance
().
getCurrentUser
()
!=
null
)
{
startActivity
(
new
Intent
(
getApplicationContext
(),
MainActivity
.
class
));
finish
();
}
}
//end validation
}
\ No newline at end of file
app/src/main/java/com/example/eketha/MainActivity.java
0 → 100644
View file @
8a99eea5
package
com.example.eketha
;
import
androidx.appcompat.app.AppCompatActivity
;
import
androidx.cardview.widget.CardView
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.ImageButton
;
import
com.google.firebase.auth.FirebaseAuth
;
public
class
MainActivity
extends
AppCompatActivity
{
private
CardView
cardView1
,
cardView2
,
cardView3
,
cardView4
;
private
ImageButton
logout
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
cardView1
=
findViewById
(
R
.
id
.
card1
);
cardView2
=
findViewById
(
R
.
id
.
card2
);
cardView3
=
findViewById
(
R
.
id
.
card3
);
cardView4
=
findViewById
(
R
.
id
.
card4
);
logout
=
findViewById
(
R
.
id
.
btnalogout
);
logout
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
FirebaseAuth
.
getInstance
().
signOut
();
startActivity
(
new
Intent
(
getApplicationContext
(),
Login
.
class
));
finish
();
}
});
// cardView1.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// Intent intent = new Intent(getApplicationContext(),pdHome.class);
// startActivity(intent);
// }
// });
//
// cardView2.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// Intent intent = new Intent(getApplicationContext(),weedHome.class);
// startActivity(intent);
// }
// });
//
// cardView3.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// Intent intent = new Intent(getApplicationContext(),fertilizerHome.class);
// startActivity(intent);
// }
// });
cardView4
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
Intent
intent
=
new
Intent
(
getApplicationContext
(),
growthHome
.
class
);
startActivity
(
intent
);
}
});
}
}
\ No newline at end of file
app/src/main/java/com/example/eketha/NetworkClient.java
0 → 100644
View file @
8a99eea5
package
com.example.eketha
;
import
okhttp3.OkHttpClient
;
import
retrofit2.Retrofit
;
import
retrofit2.converter.gson.GsonConverterFactory
;
public
class
NetworkClient
{
private
static
Retrofit
retrofit
;
private
static
String
BASE_URL
=
"www.abc.com/"
;
public
static
Retrofit
getRetrofit
()
{
OkHttpClient
okHttpClient
=
new
OkHttpClient
.
Builder
().
build
();
if
(
retrofit
==
null
)
{
retrofit
=
new
Retrofit
.
Builder
().
baseUrl
(
BASE_URL
).
addConverterFactory
(
GsonConverterFactory
.
create
()).
client
(
okHttpClient
).
build
();
}
return
retrofit
;
}
}
app/src/main/java/com/example/eketha/Register.java
0 → 100644
View file @
8a99eea5
package
com.example.eketha
;
import
androidx.annotation.NonNull
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.google.android.gms.tasks.OnFailureListener
;
import
com.google.android.gms.tasks.OnSuccessListener
;
import
com.google.firebase.auth.AuthResult
;
import
com.google.firebase.auth.FirebaseAuth
;
import
com.google.firebase.auth.FirebaseUser
;
import
com.google.firebase.firestore.DocumentReference
;
import
com.google.firebase.firestore.FirebaseFirestore
;
import
java.util.HashMap
;
import
java.util.Map
;
public
class
Register
extends
AppCompatActivity
{
EditText
fullName
,
password
,
retypePassword
,
Email
,
mobile
;
Button
createAccount
;
boolean
valid
=
true
;
TextView
text
;
FirebaseAuth
fAuth
;
FirebaseFirestore
fStory
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_register
);
fAuth
=
FirebaseAuth
.
getInstance
();
fStory
=
FirebaseFirestore
.
getInstance
();
fullName
=
findViewById
(
R
.
id
.
registerfullName
);
Email
=
findViewById
(
R
.
id
.
registeremail
);
mobile
=
findViewById
(
R
.
id
.
registermobile
);
password
=
findViewById
(
R
.
id
.
registerpassword
);
retypePassword
=
findViewById
(
R
.
id
.
registerretypepassowrd
);
createAccount
=
findViewById
(
R
.
id
.
btnregcreateaccount
);
text
=
findViewById
(
R
.
id
.
txtsigiin
);
createAccount
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
//Validation check-----------------------------------------------------------------------------------------------------------------------
checkField
(
fullName
);
checkField
(
Email
);
checkField
(
mobile
);
checkField
(
password
);
checkField
(
retypePassword
);
//database input--------------------------------------------------------------------------------------------------------------------------
if
(
valid
)
{
fAuth
.
createUserWithEmailAndPassword
(
Email
.
getText
().
toString
(),
password
.
getText
().
toString
()).
addOnSuccessListener
(
new
OnSuccessListener
<
AuthResult
>()
{
@Override
public
void
onSuccess
(
AuthResult
authResult
)
{
FirebaseUser
user
=
fAuth
.
getCurrentUser
();
Toast
.
makeText
(
Register
.
this
,
"Account Created"
,
Toast
.
LENGTH_SHORT
).
show
();
DocumentReference
df
=
fStory
.
collection
(
"Users"
).
document
(
user
.
getUid
());
Map
<
String
,
Object
>
userInfo
=
new
HashMap
<>();
userInfo
.
put
(
"FullName"
,
fullName
.
getText
().
toString
());
userInfo
.
put
(
"Email"
,
Email
.
getText
().
toString
());
userInfo
.
put
(
"Mobile"
,
mobile
.
getText
().
toString
());
userInfo
.
put
(
"Password"
,
password
.
getText
().
toString
());
//specify if the user is admin//
userInfo
.
put
(
"isUser"
,
"1"
);
df
.
set
(
userInfo
);
FirebaseAuth
.
getInstance
().
signOut
();
//startActivity(new Intent(getApplicationContext(), MainActivity.class));
finish
();
}
}).
addOnFailureListener
(
new
OnFailureListener
()
{
@Override
public
void
onFailure
(
@NonNull
Exception
e
)
{
Toast
.
makeText
(
Register
.
this
,
"Failed to Create Account"
,
Toast
.
LENGTH_LONG
).
show
();
}
});
}
}
});
text
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
startActivity
(
new
Intent
(
getApplicationContext
(),
Login
.
class
));
}
});
}
//-----------------------------------------------validation-------------------------------------------------------------------------
public
boolean
checkField
(
EditText
textFiled
)
{
if
(
textFiled
==
fullName
)
{
String
val
=
fullName
.
getText
().
toString
();
if
(
val
.
isEmpty
())
{
fullName
.
setError
(
"Field cannot be empty"
);
valid
=
false
;
}
else
{
fullName
.
setError
(
null
);
valid
=
true
;
}
return
valid
;
}
else
if
(
textFiled
==
Email
)
{
String
val
=
Email
.
getText
().
toString
();
String
emailPattern
=
"[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+"
;
if
(
val
.
isEmpty
())
{
Email
.
setError
(
"Field cannot be empty"
);
valid
=
false
;
}
else
if
(!
val
.
matches
(
emailPattern
))
{
Email
.
setError
(
"Invalid email address"
);
valid
=
false
;
}
else
{
Email
.
setError
(
null
);
valid
=
true
;
}
return
valid
;
}
else
if
(
textFiled
==
mobile
)
{
String
val
=
mobile
.
getText
().
toString
();
String
MobilePattern
=
"[0-9]{10}"
;
if
(
val
.
isEmpty
())
{
mobile
.
setError
(
"Field cannot be empty"
);
valid
=
false
;
}
else
if
(!
val
.
matches
(
MobilePattern
))
{
mobile
.
setError
(
"Invalid 10 digit mobile no "
);
valid
=
false
;
}
else
if
(
val
.
length
()<
10
)
{
mobile
.
setError
(
"Invalid 10 digit no"
);
valid
=
false
;
}
else
{
mobile
.
setError
(
null
);
valid
=
true
;
}
return
valid
;
}
else
if
(
textFiled
==
password
)
{
String
val
=
password
.
getText
().
toString
();
String
passwordVal
=
"^"
+
//"(?=.*[0-9])" + //at least 1 digit
//"(?=.*[a-z])" + //at least 1 lower case letter
//"(?=.*[A-Z])" + //at least 1 upper case letter
"(?=.*[a-zA-Z])"
+
//any letter
"(?=.*[@#$%^&+=])"
+
//at least 1 special character
"(?=\\S+$)"
+
//no white spaces
".{4,}"
+
//at least 4 characters
"$"
;
if
(
val
.
isEmpty
())
{
password
.
setError
(
"Field cannot be empty"
);
valid
=
false
;
}
else
if
(!
val
.
matches
(
passwordVal
))
{
password
.
setError
(
"Password is too weak"
);
valid
=
false
;
}
else
if
(
val
.
length
()
<
6
)
{
password
.
setError
(
"At least 6 characters"
);
valid
=
false
;
}
else
{
password
.
setError
(
null
);
valid
=
true
;
}
return
valid
;
}
else
if
(
textFiled
==
retypePassword
)
{
String
val
=
retypePassword
.
getText
().
toString
();
String
val2
=
password
.
getText
().
toString
();
String
passwordVal
=
"^"
+
//"(?=.*[0-9])" + //at least 1 digit
//"(?=.*[a-z])" + //at least 1 lower case letter
//"(?=.*[A-Z])" + //at least 1 upper case letter
"(?=.*[a-zA-Z])"
+
//any letter
"(?=.*[@#$%^&+=])"
+
//at least 1 special character
"(?=\\S+$)"
+
//no white spaces
".{4,}"
+
//at least 4 characters
"$"
;
if
(
val
.
isEmpty
())
{
retypePassword
.
setError
(
"Field cannot be empty"
);
valid
=
false
;
}
else
if
(!
val
.
matches
(
passwordVal
))
{
retypePassword
.
setError
(
"Password is too weak"
);
valid
=
false
;
}
else
if
(
val
.
charAt
(
0
)==
'0'
)
{
retypePassword
.
setError
(
"At first 0 characters"
);
valid
=
false
;
}
else
if
(!
val2
.
equals
(
val
))
{
retypePassword
.
setError
(
"Does to match the password"
);
valid
=
false
;
}
else
{
retypePassword
.
setError
(
null
);
valid
=
true
;
}
return
valid
;
}
return
valid
;
}
}
\ No newline at end of file
app/src/main/java/com/example/eketha/UploadApis.java
0 → 100644
View file @
8a99eea5
package
com.example.eketha
;
import
okhttp3.MultipartBody
;
import
okhttp3.RequestBody
;
import
retrofit2.Call
;
import
retrofit2.http.Multipart
;
import
retrofit2.http.POST
;
import
retrofit2.http.Part
;
public
interface
UploadApis
{
@Multipart
@POST
(
"upload"
)
Call
<
RequestBody
>
uploadImage
(
@Part
MultipartBody
.
Part
part
,
@Part
(
"somedata"
)
RequestBody
requestBody
);
}
app/src/main/java/com/example/eketha/growthHome.java
0 → 100644
View file @
8a99eea5
package
com.example.eketha
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.LinearLayout
;
public
class
growthHome
extends
AppCompatActivity
{
private
LinearLayout
layer1
,
layer2
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_growth_home
);
layer1
=
findViewById
(
R
.
id
.
layer2
);
//layer2 = findViewById(R.id.layer3);
layer1
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
Intent
intent
=
new
Intent
(
getApplicationContext
(),
Growth
.
class
);
startActivity
(
intent
);
}
});
// layer2.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// Intent intent = new Intent(getApplicationContext(),Fertilizer.class);
// startActivity(intent);
// }
// });
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment