Commit 8a99eea5 authored by ranthilina99's avatar ranthilina99

update file

parent 4f9212a7
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
This diff is collapsed.
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);
}
});
}
}
}
}
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
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
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
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
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;
}
}
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
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);
}
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment