Jumat, 15 Februari 2019
Android Kriptograph RSA+AES
Pada Menu Login:
Kode Login:
Button btnLogin= (Button) findViewById(R.id.btnLogin);
btnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String user=txtusername.getText().toString();
String pass=txtpassword.getText().toString();
if(user.length()<1){lengkapi("Username");}
else if(pass.length()<1){lengkapi("Password");}
else{
int index=-1;
if(pilih.equalsIgnoreCase("Karyawan")){
for(int i=0;i<jd;i++){
if(user.equalsIgnoreCase(arNik[i]) && pass.equalsIgnoreCase(arNik[i])){
index=i;
break;
}
}
if(index<0){
gagal();
}
else{
key=arPrivate[index]+"#"+arN[index]+"#"+arNama[index]+"#"+arNik[index]+"#";
sukses("Karyawan "+arNama[index]);//
}
}
else{
if(user.equalsIgnoreCase("admin") && pass.equalsIgnoreCase("admin")){sukses("Admin");}
else if(user.equalsIgnoreCase("hrd") && pass.equalsIgnoreCase("hrd")){sukses("HRD");}
else{gagal();}
}
}
}
});
Jadi jika sebagai admin atau hrd akan menuju ke halaman Enkrip dan Pengujian
dan jika sebagai karyawan akan menuju ke halaman Dekrip dan Buka Dokumen
di halaman Index juga tersedia initialisasi dataUji yaitu daftar nama nama karyawan yang bisa menggunakan aplikasi ini (sample contoh):
Inisialisasi dataUji:
void loadkar(){
jd=5;
arNik=new String[jd];
arNama=new String[jd];
arNik[0]="50815317";
arNama[0]="Geum Jan Di";
arNik[1]="24117371";
arNama[1]="Gu Jun Pyo";
arNik[2]="10616173";
arNama[2]="Yoon Ji Hoo";
arNik[3]="19515731";
arNama[3]="Song Woo Bin";
arNik[4]="70114713";
arNama[4]="So Yi Jung";
}
Pada Menu utama Admin/HRD
Kode Saat memilih dokumen (Open file):
txtnama.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
try {
Intent gintent = new Intent();
Uri mydir = Uri.parse(mypath);
gintent.setDataAndType(mydir, "*/*");
gintent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(gintent, "Select Data"),PICK_IMAGE);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
}
Kode Saat Button Proses ditekan:
Tergantung Option radiobutton yang dipilih sebelumnya:
btnProcess.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
cetak(filePath);
if( statusbaca.equalsIgnoreCase("Encrypt")){
enkrip();
Toast.makeText(Aplikasi.this, "Proses Encrypt "+filePath, Toast.LENGTH_SHORT).show();
}
else if( statusbaca.equalsIgnoreCase("Decrypt")){
dekrip();
Toast.makeText(Aplikasi.this, "Proses Decrypt "+filePath, Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(Aplikasi.this, "Load Path "+filePath, Toast.LENGTH_SHORT).show();
File x=new File(filePath);
openFile(x);
}
SBB adalah kode Open File sesuai extensi file ybs:
private void openFile(File url) {
Intent intent = new Intent(Intent.ACTION_VIEW);
try {
Uri uri = Uri.fromFile(url);
if (url.toString().contains(".doc") || url.toString().contains(".docx")) {
// Word document
intent.setDataAndType(uri, "application/msword");
} else if (url.toString().contains(".pdf")) {
// PDF file
intent.setDataAndType(uri, "application/pdf");
} else if (url.toString().contains(".ppt") || url.toString().contains(".pptx")) {
// Powerpoint file
intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
} else if (url.toString().contains(".xls") || url.toString().contains(".xlsx")) {
// Excel file
intent.setDataAndType(uri, "application/vnd.ms-excel");
} else if (url.toString().contains(".zip") || url.toString().contains(".rar")) {
// WAV audio file
intent.setDataAndType(uri, "application/x-wav");
} else if (url.toString().contains(".rtf")) {
// RTF file
intent.setDataAndType(uri, "application/rtf");
} else if (url.toString().contains(".wav") || url.toString().contains(".mp3")) {
// WAV audio file
intent.setDataAndType(uri, "audio/x-wav");
} else if (url.toString().contains(".gif")) {
// GIF file
intent.setDataAndType(uri, "image/gif");
} else if (url.toString().contains(".jpg") || url.toString().contains(".jpeg") || url.toString().contains(".png")) {
// JPG file
intent.setDataAndType(uri, "image/jpeg");
} else if (url.toString().contains(".txt")) {
// Text file
intent.setDataAndType(uri, "text/plain");
} else if (url.toString().contains(".3gp") || url.toString().contains(".mpg") ||
url.toString().contains(".mpeg") || url.toString().contains(".mpe") || url.toString().contains(".mp4") || url.toString().contains(".avi")) {
// Video files
intent.setDataAndType(uri, "video/*");
} else {
intent.setDataAndType(uri, "*/*");
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No application found which can open the file", Toast.LENGTH_SHORT).show();
}
}
Proses Enkrip:
1.Membuat File menjadi byte
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(nf);
} catch (IOException e) {
e.printStackTrace();
}
byte[] buffer = new byte[1024];//8192
int bytesRead=0;
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
while ((bytesRead = inputStream.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
} catch (IOException e) {
e.printStackTrace();
}
byte bytePath[] = output.toByteArray();
2.data Byte array yang didapatkan di RSA KAN
byte []data=bytePath;
String[] data1 = new String[data.length];
for(int i=0; i < data.length; i++) {
data1[i] = String.valueOf(data[i] & 0xff); //unsigned integer
}
BigInteger[] data2 = new BigInteger[data1.length];
for (int i = 0; i < data1.length; i++) {
data2[i] = (new BigInteger(data1[i])).pow(this.e);
data2[i] = data2[i].mod(this.n);
}
String[] x = new String[data2.length];
for(int i = 0; i < data2.length; i++) {
x[i] = String.valueOf(data2[i]);
}
String data5 = StringUtils.join(x, " ");
3.String data hasil RSA di AES kan
AES128 aes128 = new AES128();
String cipherText = aes128.encrypt(data5,256,passAES);
4.hasil Chipertext RSA+AES ahir disimpan ke dalam file hasil dekrip
try {
String content = dataEncrypt;
File file = new File(this.fileNameEncrypt);
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
5.Hasil File bisa di open untuk melihat hasilnya menggunaan kode open file berdasarkan extensi di atas
PROSES DEKRIP:
1.Membuat File menjadi deretan String
BufferedReader be = null;
String current;
String data = "";
be = new BufferedReader(new FileReader(fileName));
while ((current = be.readLine()) != null) {
data += current;
}
2.String data adalah isi daripada file Enkripsi sebelumnya selanjutnya melakukan proses Dekripsi
pertama data String tersebut di dekrip AES
AES128 aes128 = new AES128();
String plainText = aes128.decrypt(data, 256, passAES);
3.String Dekrip AES selanjutnya di Dekrip RSA
String[] data1 = plainText.split(" ");
BigInteger[] data2 = new BigInteger[data1.length];
for (int i=0; i < data1.length; i++){
data2[i] = (new BigInteger(String.valueOf(data1[i]))).pow(this.d);
data2[i] = data2[i].mod(this.n);
}
byte[] data3 = new byte[data2.length];
String[] x = new String[data2.length];
String gab="";
for (int i=0; i < data2.length; i++){
data3[i] = (byte) (data2[i].byteValue());
}
4.Hasil byte array yang di dapat selanjutnay disimpan ke dalam file
File file=new File("Nama File Dekrip");
try {
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(data3);
fileOutputStream.flush();
fileOutputStream.close();
return file.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
}
5.Hasil File bisa di open untuk melihat hasilnya menggunaan kode open file berdasarkan extensi di atas
Sabtu, 09 Februari 2019
Library FIle SDCARD dll
package id.ac.istn.appkripto;
//https://www.dev2qa.com/android-read-write-external-storage-file-example/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.FileChannel;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Build;
public class appSD extends Activity {
private TextView textView;
String TAG="isiq";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.txt1);
bacaFile("/storage/sdcard0/FILEPROJEK/en.uji5.txt");
bacaisiSD();
// bacaFile("/storage/sdcard0/FILEPROJEK/en.uji1.pdf");
// bacaFile("/storage/sdcard0/FILEPROJEK/dec.en.uji1.pdf");
//buatfile();
// bacaFile();
// String pathsd=getPathSD()+File.separator+"myData";
// Log.v("pathsd",pathsd);
// createDirIfNotExists(pathsd);
//
// baca(pathsd+File.separator+"tes.txt");
// bacaFile();
// File folder = new File(Environment.getExternalStorageDirectory().toString()+"\\myDataAPPA");
// folder.mkdirs();
//
// String extStorageDirectory = folder.toString();
// Log.v("extStorageDirectory",extStorageDirectory);
// // bacaisiSD();
// //copyFileOrDirectory("/storage/sdcard0/tes1.txt","/storage/sdcard0/FILEPROJEK/");
// try {
// copy("/storage/sdcard0/tes1.txt","/storage/sdcard0/FILEPROJEK/tes1.txt");
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
void buatfile(){
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
//handle case of no SDCARD present
} else {
String dir = Environment.getExternalStorageDirectory()+File.separator+"ADI";
//create folder
File folder = new File(dir); //folder name
folder.mkdirs();
Log.v("BUAT","Berhasil="+dir);
Toast.makeText(this, dir, Toast.LENGTH_LONG).show();
//create file
File file = new File(dir, "filename.txt");
File files = new File(dir, "out.txt");
FileOutputStream os = null;
try {
os = new FileOutputStream(files);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String datas ="Selamat Pagi Bro kamu OK?";// "This is the content of my file";
try {
os.write(datas.getBytes());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
os.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//++++++++++++++++++++++++++++++
// bacaisiSD();
// bacaFile("/storage/sdcard0/uji1.txt");
// bacaFile("/storage/sdcard0/FILEPROJEK/en.uji1.txt");
// bacaFile("/storage/sdcard0/FILEPROJEK/dec.uji1.txt");
}
}
public void copy(String ssrc, String sdst) throws IOException {
File src=new File(ssrc);
File dst=new File(sdst);
InputStream in = new FileInputStream(src);
try {
OutputStream out = new FileOutputStream(dst);
try {
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} finally {
out.close();
}
} finally {
in.close();
}
}
void bacaisiSD(){
final String state = Environment.getExternalStorageState();
File file = Environment.getExternalStorageDirectory();
String abs=file.getAbsolutePath();
Log.v("isiabs",abs);
if ( Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) ) { // we can read the External Storage...
getAllFilesOfDir(Environment.getExternalStorageDirectory());
}
}
private void getAllFilesOfDir(File directory) {//Streaming.jpg
// //String al="/storage/sdcard0/WhatsApp/Media/WhatsApp Documents/";//directory.getAbsolutePath()+"/FILEPROJEK/";
//
// File mfile = Environment.getExternalStorageDirectory();
//String abs=mfile.getAbsolutePath();
// Log.v("isiabs",abs);
//String al=abs+"/FILEPROJEK/";
// Log.v("isiabs2",al);
// directory=new File(al);
String abs=directory.getAbsolutePath();
Log.v("isiabs",abs);
String al=abs+"/FILEPROJEK/";
directory=new File(al);
Log.d(TAG, "Directory: " + directory.getAbsolutePath() + "\n");
final File[] files = directory.listFiles();
if ( files != null ) {
for ( File file : files ) {
if ( file != null ) {
if ( file.isDirectory() ) { // it is a folder...
getAllFilesOfDir(file);
}
else { // it is a file...
Log.d(TAG, "File: " + file.getAbsolutePath() + "\n");
}
}
}
}
}
void bacaFile(String baca){
String state = Environment.getExternalStorageState();
if (!(state.equals(Environment.MEDIA_MOUNTED))) {
Toast.makeText(this, "There is no any sd card", Toast.LENGTH_LONG).show();
} else {
BufferedReader reader = null;
try {
File file = Environment.getExternalStorageDirectory();
String abs=file.getAbsolutePath();
Log.v("isiabs",abs);
// Toast.makeText(this, "Sd card available "+abs, Toast.LENGTH_LONG).show();
// File textFile = new File(file.getAbsolutePath()+File.separator+ "tes1.txt");
//String abs2=textFile.getAbsolutePath();
// Log.v("isiabs2",abs2);
// Toast.makeText(this, "Sd card available "+abs2, Toast.LENGTH_LONG).show();
//
reader = new BufferedReader(new FileReader(baca));//tes1.txt
StringBuilder textBuilder = new StringBuilder();
String line;
String gab="";
while((line = reader.readLine()) != null) {
gab+=line;
textBuilder.append(line);
textBuilder.append("\n");
}
textView.setText(textBuilder);
Log.v("isi",baca+"="+gab);
} catch (FileNotFoundException e) {
// TODO: handle exception
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
if(reader != null){
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
String getPathSD(){
String abs="";
String state = Environment.getExternalStorageState();
if (!(state.equals(Environment.MEDIA_MOUNTED))) {
Toast.makeText(this, "There is no any sd card", Toast.LENGTH_LONG).show();
} else {
try {
File file = Environment.getExternalStorageDirectory();
abs=file.getAbsolutePath();
Toast.makeText(this, "Sd card available :"+abs, Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
return abs;
}
public static boolean createDirIfNotExists(String path) {
boolean ret = true;
File file = new File(Environment.getExternalStorageDirectory(), path);
if (!file.exists()) {
if (!file.mkdirs()) {
Log.e("TravellerLog :: ", "Problem creating Image folder");
ret = false;
}
}
return ret;
}
public static void copyFileOrDirectory(String srcDir, String dstDir) {
try {
File src = new File(srcDir);
File dst = new File(dstDir, src.getName());
if (src.isDirectory()) {
String files[] = src.list();
int filesLength = files.length;
for (int i = 0; i < filesLength; i++) {
String src1 = (new File(src, files[i]).getPath());
String dst1 = dst.getPath();
copyFileOrDirectory(src1, dst1);
}
} else {
copyFile(src, dst);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void copyFile(File sourceFile, File destFile) throws IOException {
if (!destFile.getParentFile().exists())
destFile.getParentFile().mkdirs();
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
} finally {
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
}
}
//https://www.dev2qa.com/android-read-write-external-storage-file-example/
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.FileChannel;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Build;
public class appSD extends Activity {
private TextView textView;
String TAG="isiq";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.txt1);
bacaFile("/storage/sdcard0/FILEPROJEK/en.uji5.txt");
bacaisiSD();
// bacaFile("/storage/sdcard0/FILEPROJEK/en.uji1.pdf");
// bacaFile("/storage/sdcard0/FILEPROJEK/dec.en.uji1.pdf");
//buatfile();
// bacaFile();
// String pathsd=getPathSD()+File.separator+"myData";
// Log.v("pathsd",pathsd);
// createDirIfNotExists(pathsd);
//
// baca(pathsd+File.separator+"tes.txt");
// bacaFile();
// File folder = new File(Environment.getExternalStorageDirectory().toString()+"\\myDataAPPA");
// folder.mkdirs();
//
// String extStorageDirectory = folder.toString();
// Log.v("extStorageDirectory",extStorageDirectory);
// // bacaisiSD();
// //copyFileOrDirectory("/storage/sdcard0/tes1.txt","/storage/sdcard0/FILEPROJEK/");
// try {
// copy("/storage/sdcard0/tes1.txt","/storage/sdcard0/FILEPROJEK/tes1.txt");
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
void buatfile(){
if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
//handle case of no SDCARD present
} else {
String dir = Environment.getExternalStorageDirectory()+File.separator+"ADI";
//create folder
File folder = new File(dir); //folder name
folder.mkdirs();
Log.v("BUAT","Berhasil="+dir);
Toast.makeText(this, dir, Toast.LENGTH_LONG).show();
//create file
File file = new File(dir, "filename.txt");
File files = new File(dir, "out.txt");
FileOutputStream os = null;
try {
os = new FileOutputStream(files);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String datas ="Selamat Pagi Bro kamu OK?";// "This is the content of my file";
try {
os.write(datas.getBytes());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
os.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//++++++++++++++++++++++++++++++
// bacaisiSD();
// bacaFile("/storage/sdcard0/uji1.txt");
// bacaFile("/storage/sdcard0/FILEPROJEK/en.uji1.txt");
// bacaFile("/storage/sdcard0/FILEPROJEK/dec.uji1.txt");
}
}
public void copy(String ssrc, String sdst) throws IOException {
File src=new File(ssrc);
File dst=new File(sdst);
InputStream in = new FileInputStream(src);
try {
OutputStream out = new FileOutputStream(dst);
try {
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
} finally {
out.close();
}
} finally {
in.close();
}
}
void bacaisiSD(){
final String state = Environment.getExternalStorageState();
File file = Environment.getExternalStorageDirectory();
String abs=file.getAbsolutePath();
Log.v("isiabs",abs);
if ( Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) ) { // we can read the External Storage...
getAllFilesOfDir(Environment.getExternalStorageDirectory());
}
}
private void getAllFilesOfDir(File directory) {//Streaming.jpg
// //String al="/storage/sdcard0/WhatsApp/Media/WhatsApp Documents/";//directory.getAbsolutePath()+"/FILEPROJEK/";
//
// File mfile = Environment.getExternalStorageDirectory();
//String abs=mfile.getAbsolutePath();
// Log.v("isiabs",abs);
//String al=abs+"/FILEPROJEK/";
// Log.v("isiabs2",al);
// directory=new File(al);
String abs=directory.getAbsolutePath();
Log.v("isiabs",abs);
String al=abs+"/FILEPROJEK/";
directory=new File(al);
Log.d(TAG, "Directory: " + directory.getAbsolutePath() + "\n");
final File[] files = directory.listFiles();
if ( files != null ) {
for ( File file : files ) {
if ( file != null ) {
if ( file.isDirectory() ) { // it is a folder...
getAllFilesOfDir(file);
}
else { // it is a file...
Log.d(TAG, "File: " + file.getAbsolutePath() + "\n");
}
}
}
}
}
void bacaFile(String baca){
String state = Environment.getExternalStorageState();
if (!(state.equals(Environment.MEDIA_MOUNTED))) {
Toast.makeText(this, "There is no any sd card", Toast.LENGTH_LONG).show();
} else {
BufferedReader reader = null;
try {
File file = Environment.getExternalStorageDirectory();
String abs=file.getAbsolutePath();
Log.v("isiabs",abs);
// Toast.makeText(this, "Sd card available "+abs, Toast.LENGTH_LONG).show();
// File textFile = new File(file.getAbsolutePath()+File.separator+ "tes1.txt");
//String abs2=textFile.getAbsolutePath();
// Log.v("isiabs2",abs2);
// Toast.makeText(this, "Sd card available "+abs2, Toast.LENGTH_LONG).show();
//
reader = new BufferedReader(new FileReader(baca));//tes1.txt
StringBuilder textBuilder = new StringBuilder();
String line;
String gab="";
while((line = reader.readLine()) != null) {
gab+=line;
textBuilder.append(line);
textBuilder.append("\n");
}
textView.setText(textBuilder);
Log.v("isi",baca+"="+gab);
} catch (FileNotFoundException e) {
// TODO: handle exception
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
if(reader != null){
try {
reader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
String getPathSD(){
String abs="";
String state = Environment.getExternalStorageState();
if (!(state.equals(Environment.MEDIA_MOUNTED))) {
Toast.makeText(this, "There is no any sd card", Toast.LENGTH_LONG).show();
} else {
try {
File file = Environment.getExternalStorageDirectory();
abs=file.getAbsolutePath();
Toast.makeText(this, "Sd card available :"+abs, Toast.LENGTH_LONG).show();
} catch (Exception e) {
e.printStackTrace();
}
}
return abs;
}
public static boolean createDirIfNotExists(String path) {
boolean ret = true;
File file = new File(Environment.getExternalStorageDirectory(), path);
if (!file.exists()) {
if (!file.mkdirs()) {
Log.e("TravellerLog :: ", "Problem creating Image folder");
ret = false;
}
}
return ret;
}
public static void copyFileOrDirectory(String srcDir, String dstDir) {
try {
File src = new File(srcDir);
File dst = new File(dstDir, src.getName());
if (src.isDirectory()) {
String files[] = src.list();
int filesLength = files.length;
for (int i = 0; i < filesLength; i++) {
String src1 = (new File(src, files[i]).getPath());
String dst1 = dst.getPath();
copyFileOrDirectory(src1, dst1);
}
} else {
copyFile(src, dst);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void copyFile(File sourceFile, File destFile) throws IOException {
if (!destFile.getParentFile().exists())
destFile.getParentFile().mkdirs();
if (!destFile.exists()) {
destFile.createNewFile();
}
FileChannel source = null;
FileChannel destination = null;
try {
source = new FileInputStream(sourceFile).getChannel();
destination = new FileOutputStream(destFile).getChannel();
destination.transferFrom(source, 0, source.size());
} finally {
if (source != null) {
source.close();
}
if (destination != null) {
destination.close();
}
}
}
}
Open Assosiatif File Berdasarkan extensi
Button btnOpen=(Button)findViewById(R.id.btnOpen);
btnOpen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String paths=txtPath.getText().toString();
if(paths.indexOf(".pdf")>0){
File file = new File(Environment.getExternalStorageDirectory(), paths);
Uri path = Uri.fromFile(file);
Intent pdfOpenintent = new Intent(Intent.ACTION_VIEW);
pdfOpenintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
pdfOpenintent.setDataAndType(path, "application/pdf");
try {
startActivity(pdfOpenintent);
}
catch (ActivityNotFoundException e) {
}
}
else{
File x=new File(paths);
openFile(x);
}
}});
+++++++++++++++++++++++++++++++++++++++
private void openFile(File url) {
Intent intent = new Intent(Intent.ACTION_VIEW);
try {
Uri uri = Uri.fromFile(url);
if (url.toString().contains(".doc") || url.toString().contains(".docx")) {
// Word document
intent.setDataAndType(uri, "application/msword");
} else if (url.toString().contains(".pdf")) {
// PDF file
intent.setDataAndType(uri, "application/pdf");
} else if (url.toString().contains(".ppt") || url.toString().contains(".pptx")) {
// Powerpoint file
intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
} else if (url.toString().contains(".xls") || url.toString().contains(".xlsx")) {
// Excel file
intent.setDataAndType(uri, "application/vnd.ms-excel");
} else if (url.toString().contains(".zip") || url.toString().contains(".rar")) {
// WAV audio file
intent.setDataAndType(uri, "application/x-wav");
} else if (url.toString().contains(".rtf")) {
// RTF file
intent.setDataAndType(uri, "application/rtf");
} else if (url.toString().contains(".wav") || url.toString().contains(".mp3")) {
// WAV audio file
intent.setDataAndType(uri, "audio/x-wav");
} else if (url.toString().contains(".gif")) {
// GIF file
intent.setDataAndType(uri, "image/gif");
} else if (url.toString().contains(".jpg") || url.toString().contains(".jpeg") || url.toString().contains(".png")) {
// JPG file
intent.setDataAndType(uri, "image/jpeg");
} else if (url.toString().contains(".txt")) {
// Text file
intent.setDataAndType(uri, "text/plain");
} else if (url.toString().contains(".3gp") || url.toString().contains(".mpg") ||
url.toString().contains(".mpeg") || url.toString().contains(".mpe") || url.toString().contains(".mp4") || url.toString().contains(".avi")) {
// Video files
intent.setDataAndType(uri, "video/*");
} else {
intent.setDataAndType(uri, "*/*");
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No application found which can open the file", Toast.LENGTH_SHORT).show();
}
}
btnOpen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String paths=txtPath.getText().toString();
if(paths.indexOf(".pdf")>0){
File file = new File(Environment.getExternalStorageDirectory(), paths);
Uri path = Uri.fromFile(file);
Intent pdfOpenintent = new Intent(Intent.ACTION_VIEW);
pdfOpenintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
pdfOpenintent.setDataAndType(path, "application/pdf");
try {
startActivity(pdfOpenintent);
}
catch (ActivityNotFoundException e) {
}
}
else{
File x=new File(paths);
openFile(x);
}
}});
+++++++++++++++++++++++++++++++++++++++
private void openFile(File url) {
Intent intent = new Intent(Intent.ACTION_VIEW);
try {
Uri uri = Uri.fromFile(url);
if (url.toString().contains(".doc") || url.toString().contains(".docx")) {
// Word document
intent.setDataAndType(uri, "application/msword");
} else if (url.toString().contains(".pdf")) {
// PDF file
intent.setDataAndType(uri, "application/pdf");
} else if (url.toString().contains(".ppt") || url.toString().contains(".pptx")) {
// Powerpoint file
intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
} else if (url.toString().contains(".xls") || url.toString().contains(".xlsx")) {
// Excel file
intent.setDataAndType(uri, "application/vnd.ms-excel");
} else if (url.toString().contains(".zip") || url.toString().contains(".rar")) {
// WAV audio file
intent.setDataAndType(uri, "application/x-wav");
} else if (url.toString().contains(".rtf")) {
// RTF file
intent.setDataAndType(uri, "application/rtf");
} else if (url.toString().contains(".wav") || url.toString().contains(".mp3")) {
// WAV audio file
intent.setDataAndType(uri, "audio/x-wav");
} else if (url.toString().contains(".gif")) {
// GIF file
intent.setDataAndType(uri, "image/gif");
} else if (url.toString().contains(".jpg") || url.toString().contains(".jpeg") || url.toString().contains(".png")) {
// JPG file
intent.setDataAndType(uri, "image/jpeg");
} else if (url.toString().contains(".txt")) {
// Text file
intent.setDataAndType(uri, "text/plain");
} else if (url.toString().contains(".3gp") || url.toString().contains(".mpg") ||
url.toString().contains(".mpeg") || url.toString().contains(".mpe") || url.toString().contains(".mp4") || url.toString().contains(".avi")) {
// Video files
intent.setDataAndType(uri, "video/*");
} else {
intent.setDataAndType(uri, "*/*");
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, "No application found which can open the file", Toast.LENGTH_SHORT).show();
}
}
EditText Load File
//membaca working dinamic directory
// File rootDataDir = Aplikasi.this.getFilesDir();
// Log.v("PATHME", rootDataDir.toString());///data/data/id.ac.istn.appkripto/files
//membaca absolute directory
File file = Environment.getExternalStorageDirectory();
mypath=file.getAbsolutePath();
mypathOut=mypath+"/app_gaji/";//app_gaji
boolean mdir=createDirIfNotExists(mypathOut);
Log.d(TAG,"Status make directory "+mypathOut+":"+mdir);
txtnama=(EditText)findViewById(R.id.txtnama);
txtnama.setText(mypathOut);
txtnama.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
try {
Intent gintent = new Intent();
Uri mydir = Uri.parse(mypathOut);//default address :/storage/sdcard0/app_gaji
gintent.setDataAndType(mydir, "*/*");
//gintent.setType("image/*|application/pdf|audio/*");
//gintent.setType("image/*");//PDF image
gintent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(gintent, "Select Data"),PICK_IMAGE);
} catch (Exception e) {
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
Log.e(e.getClass().getName(), e.getMessage(), e);
}
}
});
+++++++++
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String filePath="";
Uri selectedImageUri = null;
switch (requestCode) {
case PICK_IMAGE:
if (resultCode == Activity.RESULT_OK) { selectedImageUri = data.getData(); }
break;
}
if(selectedImageUri != null){
String A1 = selectedImageUri.getPath();
String B1 = getPath(selectedImageUri);
if (B1 != null) {
filePath = B1;
Log.v("filePath1",filePath);
} else if (A1 != null) {
filePath = A1;
Log.v("filePath2",filePath);
} else {
Toast.makeText(getApplicationContext(), "Unknown path", Toast.LENGTH_LONG).show();
Log.e("filePath", "Unknown path");
}
Log.v("PATHME","A1:"+A1+"#B1:"+B1+"#"+filePath);
if(filePath.indexOf(":")>0 || (filePath+"").length()<4){
txtnama.setText("");
Toast.makeText(getApplicationContext(), "Unknown path :"+filePath, Toast.LENGTH_LONG).show();
}
else{
txtnama.setText(filePath);
txtPath.setText("");
txtTime.setText("");
txtNote.setText("");
}
}
}
maka file akan terbuka dimanapun dia berada
Jangan Lupa permissionnya:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Sabtu, 19 Januari 2019
FC 2
package com.example.siswanto.splashscreenawal;
//nox_adb.exe connect 127.0.0.1:62001
import java.util.Timer;
import java.util.TimerTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Handler.Callback;
import java.util.Calendar;
import android.media.MediaPlayer;
import android.app.Activity;
import android.app.AlertDialog;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
public class Diagnosa extends Activity {
int ER=0;
String masterPola="";
String sudah="";
String sudahNo="";
String dataIndex="";
String pilYes="";
String pilYes2="";
int ike=0;
int index=0;
int indexke=0;
int jp=9;
int jg=23;
int[]jumG;
double[]arBobot;
String[]arPenyakit;
String[]arSolusi;
String[]arPenyebab;
int[]arGB;
String[]arRelasi;
String[]arGejala;
String[]arInit;
String pola="";
RadioButton radA, radB;
// String sNama = "", sUsia = "", sJk = "";
int ke = 0,jumsoal=0;
int jd = 10;
ImageView imgGambar;
TextView txtTanya, txtTanyake;
int gb=R.drawable.tipsbnr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soal_layout);
txtTanya = (TextView) findViewById(R.id.txtTanya);
txtTanyake = (TextView) findViewById(R.id.txtTanyaKe);
imgGambar = (ImageView) findViewById(R.id.myGambar);
radA = (RadioButton) findViewById(R.id.radA);
radA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pilYes=pilYes+dataIndex;
pilYes2=pilYes2+arGejala[ike]+"#";
ke = ke + 1;
indexke=indexke+1;
if (indexke >= jumsoal) {
if(ER>0){
none();
}
else{
selesai();
}
} else {
lihat();
}
}
});
radB = (RadioButton) findViewById(R.id.radB);
radB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sudahNo=sudahNo+dataIndex;
ke = ke + 1;
index=index+1;//pindah Pohon
indexke=0;
if (index >= jp) {
none();
} else {
String polanext=arRelasi[index];
masterPola=polanext;
int p1=sudah.length();
int p2=polanext.length();
int p3=sudahNo.length();
ER=0;
char[]ars=sudahNo.toCharArray();
for(int m=0;m<p3;m++){
String ch=String.valueOf(ars[m]);
if(masterPola.indexOf(ch)>=0){
ER=ER+1;
}
}
if (ER >0) {
index=index+1;//terus ke pohon berikutnyaaa
indexke=0;
if (index >= jp) {
//none();
}
else{
polanext=arRelasi[index];
masterPola=polanext;
}
}
if (index >= jp) {
none();
}
else{
char[]arn=sudah.toCharArray();
for(int m=0;m<p1;m++){
String ch=String.valueOf(arn[m]);
if(polanext.indexOf(ch)>=0){
polanext=polanext.replaceAll(ch, "");
}
pola=polanext;
lihat();
}//else
}
}
}
});
loaddata();
pola=arRelasi[index];
masterPola=pola;
lihat();
}
void loaddata(){
jp=10;
jg=26;
arPenyakit=new String[jp];
arPenyebab=new String[jp];
arSolusi=new String[jp];
arRelasi=new String[jp];
arGejala=new String[jg];
arGB=new int[jg];
arGejala[0]="Gejala serangan pada tanaman yang terserang, kuncupnya mengeluarkan bau busuk";
arGejala[1]="Gejala serangan daun berwarna kecoklatan";
arGejala[2]="Gejala serangan memperlihatkan batang pada ketinggian sekitar 2 m di atas tanah membusuk dan berwarna coklat keabuan";
arGejala[3]="Gejala serangan pada daun yang terserang akan berwarna hijau pucat";
arGejala[4]="Gejala serangan tandan buah membusuk";
arGejala[5]="Gejala serangan pertumbuhan tanaman terlihat tidak normal, daun menguning, keragaan tanaman tidak segar";
arGejala[6]="Gejala serangan daun terdapat bercak-bercak coklat diujung dan tepi daun";
arGejala[7]="Gejala serangan terdapat bercak-bercak pada daun dengan bentuk melonjong warna kuning dan di bagian dalamnya berwarna coklat";
arGejala[8]="Gejala serangan daun bagian tengah sobek";
arGejala[9]="Gejala serangan adanya miselium bewarna putih diantara buah masak atau pangkal pelepah daun";
arGejala[10]="Gejala serangan seluruh tajuk menjadi kekuningan dan pucat karena kekurangan zat hara dan air ";
arGejala[11]="Gejala serangan banyak daun yang membengkok ke bawah di tengah pelepahnya";
arGejala[12]="Gejala serangan seluruh tandan buah telah terserang jamur";
arGejala[13]="Gejala serangan daun tua yang mengering sengkleh";
arGejala[14]="Gejala serangan tanaman akan mati dalam waktu 6 –12 bulan setelah timbul gejala";
arGejala[15]="Gejala serangan terbentuk buah cendawan dari pangkal batang";
arGejala[16]="Gejala serangan kelayuan menyeluruh seperti kurang air dan hara";
arGejala[17]="Gejala serangan benang-benang jamur yang berwarna putih mengkilat meluas di permukaan tandan buah";
arGejala[18]="Gejala serangan kuncup membusuk dan mudah dicabut";
arGejala[19]="Gejala serangan jaringan pada kuncup membusuk";
arGejala[20]="Gejala serangan warna daun yang terbawah berubah dan selanjutnya akan mati";
arGejala[21]="Gejala serangan terinfeksi mengeluarkan getah pada daun yang tua";
arGejala[22]="Gejala serangan pelepah daun bagian bawah patah";
arGejala[23]="Gejala serangan bercak coklat dikelilingi warna kuning dan terlihat sebagai pembatas antara daun yang sehat dengan daun yang tidak sehat/terserang penyakit";
arGejala[24]="Gejala serangan pelepah berukuran abnormal atau kecil-kecil";
arGejala[25]="Gejala serangan akar tanaman yang sakit berwarna coklat atau kemerah-merahan dan membusuk";
for(int i=0;i<jg;i++) {
arGB[i] = R.drawable.tipsbnr;
}
arPenyakit[0]="Penyakit Busuk Titik Tumbuh";
arPenyakit[1]="Penyakit Busuk Kuncup";
arPenyakit[2]="Penyakit Busuk Batang Atas";
arPenyakit[3]="Penyakit Busuk Pangkal Batang";
arPenyakit[4]="Penyakit Busuk Kering Pangkal Batang";
arPenyakit[5]="Penyakit Akar";
arPenyakit[6]="Penyakit Antraknosa";
arPenyakit[7]="Penyakit Garis Kuning";
arPenyakit[8]="Penyakit Tajuk";
arPenyakit[9]="Penyakit Busuk Tandan";
arPenyebab[0]="Penyebab serangan bakteri erwinia";
arPenyebab[1]="Penyebab serangan ini sampai saat ini masih dalam kajian dan belum menemukan penyerang yang pasti";
arPenyebab[2]="Penyebab serangan jamur fomex noxius";
arPenyebab[3]="Penyebab serangan jamur Ganoderma";
arPenyebab[4]="Penyebab serangan jamur Ceratocytis paradoxa";
arPenyebab[5]="Penyebab serangan jamur Rhizoctonia lamellifera";
arPenyebab[6]="Penyebab serangan jamur Melanconium sp, Botryodiplodia palmarum, Glomerella cingulata";
arPenyebab[7]="Penyebab serangan jamur Fusarium oxysporum";
arPenyebab[8]="Penyebabnya biasanya dikarenakan menurunnya sifat genetik indukan";
arPenyebab[9]="Penyebab serangan jamur Marasmius palmivorus";
arSolusi[0]="pengendalian dapat mengaplikasikan bakteri yang berfungsi sebagai pemangsa bagi bakteri erwinia";
arSolusi[1]="Pengendalian yang dilakukan masih sebatas melakukan pemotongan bagian kuncup yang terserang";
arSolusi[2]="pengendalian penanganan dengan cara membuang bagian batang yang terserang dan menutup bekas luka dengan obat luka yang ada. Pada kondisi parah tanaman dibongkar dan dimusnahkan.";
arSolusi[3]="pengendalian dapat melakukan aplikasi dengan menggunakan bahan yang mengandung Tricodherma ( produk CustomBio ), dapat disemprotkan kebagian yang terserang dan penyemprotan pada tanah sekeliling tanaman pokok secara melingkar";
arSolusi[4]="pengendalian untuk tanaman yang sudah terserang secara hebat dengan melakukan pembongkaran dan pemusnahan dengan cara dibakar";
arSolusi[5]="pengendalian dimulai sejak awal kegiatan di dalam pesemaian dengan mempersiapkan media yang tidak terkontaminasi jamur, drainase yang baik agar tidak terjadi kekeringan yang ekstrim pada tanaman";
arSolusi[6]="pengendalian sejak awal mulai dari pemindahan bibit, dimana seluruh media tanah bibit disertakan, jarak tanam, penyiraman dan pemupukan yang dilakukan secara teratur dan berimbang, aplikasi Captan 0.2 % atau Cuman 0.1 %";
arSolusi[7]="pengendalian melakukan proses inokulasi pada bibit dan tanaman muda, atau dengan melakukan aplikasi bahan yang mengandung Tricodherma & Bacillus ( produk CustomBio )";
arSolusi[8]="pengendalian dimulai sejak awal terutama melakukan seleksi indukan yang bersifat karier penyakit ini, sehingga akan didapatkan bibit yang mempunyai sifat-sifat yang sehat.";
arSolusi[9]="pengendalian dengan menjaga sanitasi kebun terutama pada musim penghujan, aplikasi difolatan 0.2 %, melakukan penyerbukan buatan atau kastrasi";
arRelasi[0]="ABS";
arRelasi[1]="BGT";
arRelasi[2]="CIO";
arRelasi[3]="DKP";
arRelasi[4]="ENOPQW";
arRelasi[5]="FPZ";
arRelasi[6]="GTX";
arRelasi[7]="FHN";
arRelasi[8]="ILY";
arRelasi[9]="JMR";
String abj="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char[]ar=abj.toCharArray();
int pj=ar.length;
for(int i=0;i<pj;i++) {
String ch=String.valueOf(ar[i]);//A B C D ...
for(int j=0;j<jp;j++) {
String relasi=arRelasi[j];//ABC
}//j
} //for
}
int getIndex(String ch){
int id=0;
if(ch.equals("A")){id=0;}
else if(ch.equals("B")){id=1;}
else if(ch.equals("C")){id=2;}
else if(ch.equals("D")){id=3;}
else if(ch.equals("E")){id=4;}
else if(ch.equals("F")){id=5;}
else if(ch.equals("G")){id=6;}
else if(ch.equals("H")){id=7;}
else if(ch.equals("I")){id=8;}
else if(ch.equals("J")){id=9;}
else if(ch.equals("K")){id=10;}
else if(ch.equals("L")){id=11;}
else if(ch.equals("M")){id=12;}
else if(ch.equals("N")){id=13;}
else if(ch.equals("O")){id=14;}
else if(ch.equals("P")){id=15;}
else if(ch.equals("Q")){id=16;}
else if(ch.equals("R")){id=17;}
else if(ch.equals("S")){id=18;}
else if(ch.equals("T")){id=19;}
else if(ch.equals("U")){id=20;}
else if(ch.equals("V")){id=21;}
else if(ch.equals("W")){id=22;}
else if(ch.equals("X")){id=23;}
return id;
}
void lihat() {//ABCLUV
radA.setChecked(false);
radB.setChecked(false);
jumsoal=pola.length();
dataIndex=pola.substring(indexke,indexke+1);
sudah=sudah+dataIndex;
ike=getIndex(dataIndex);
txtTanya.setText((ke + 1) + "." + arGejala[ike]);
radA.setText("Ya, Saya Mengalami");
radB.setText("Tidak, Saya Tidak Mengalami");
txtTanyake.setText("");
txtTanyake.setText("#Pertanyaan ke " + (ke + 1) + "#Group:" +index+"#Pola:"+arRelasi[index]+"/Replace:"+ pola+ " "+arPenyakit[index]+"#Y:"+pilYes+"#N:"+sudahNo);
if(ke%6==0){gb=R.drawable.tipsbnr;}
else if(ke%6==1){gb=R.drawable.tipsbnr;}
else if(ke%6==2){gb=R.drawable.tipsbnr;}
else if(ke%6==3){gb=R.drawable.tipsbnr;}
else if(ke%6==4){gb=R.drawable.tipsbnr;}
else if(ke%6==5){gb=R.drawable.tipsbnr;}
imgGambar.setImageResource(gb);
}
public void selesai() {
new AlertDialog.Builder(this).setTitle("Hasil Analisa Kerusakan")
.setMessage("Kelapa Sawit Terdiagnosa "+arPenyakit[index])
.setNeutralButton("Hasil", new OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
Calendar cal = Calendar.getInstance();
int jam = cal.get(Calendar.HOUR);
int menit = cal.get(Calendar.MINUTE);
int detik = cal.get(Calendar.SECOND);
int tgl = cal.get(Calendar.DATE);
int bln = cal.get(Calendar.MONTH)+1;
int thn = cal.get(Calendar.YEAR);
String stgl = String.valueOf(tgl) + "-"
+ String.valueOf(bln) + "-"
+ String.valueOf(thn);
String sjam = String.valueOf(jam) + ":"
+ String.valueOf(menit) + ":"
+ String.valueOf(detik);
Intent i = new Intent(Diagnosa.this,Hasil.class);
i.putExtra("hasil", arPenyakit[index]);
i.putExtra("solusi", arSolusi[index]);
i.putExtra("penyebab", arPenyebab[index]);
i.putExtra("gb", gb);
i.putExtra("keterangan",stgl+ " " + sjam+ "\n"+ "Forward Chaining");
startActivity(i);
finish();
}
}).show();
}
public void none() {
new AlertDialog.Builder(this).setTitle("Hasil Analisa Penyakit")
.setMessage("Kelapa Sawit Gagal Terdiagnosa ")
.setNeutralButton("Hasil", new OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
finish();
}
}).show();
}
public void keluarYN() {
AlertDialog.Builder ad = new AlertDialog.Builder(Diagnosa.this);
ad.setMessage("Apakah anda yakin ingin kembali?");
ad.setPositiveButton("YA", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
ad.setNegativeButton("TIDAK", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
ad.show();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
keluarYN();
;
return true;
}
return super.onKeyDown(keyCode, event);
}
}
+++++++++++++++++++++++++++++++++++++++++++++
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dip"
android:background="#999999" >
<TableLayout
android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff" >
<ImageView
android:id="@+id/myGambar"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerHorizontal="true"
android:src="@drawable/tipsbnr" />
<TableRow
android:id="@+id/TableRow00"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/txtTanya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.Apakah Anda mengalami gejala Pusing2" />
</TableRow>
<RadioGroup
android:id="@+id/RadioGroup01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ya"
android:textColor="#000" >
</RadioButton>
<RadioButton
android:id="@+id/radB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tidak"
android:textColor="#000" >
</RadioButton>
</RadioGroup>
<TableRow
android:id="@+id/TableRow02"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</TableRow>
<TableRow
android:id="@+id/TableRow02s"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</TableRow>
<TableRow
android:id="@+id/TableRow02a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/txtTanyaKe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pertanyaan ke-1" />
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
//nox_adb.exe connect 127.0.0.1:62001
import java.util.Timer;
import java.util.TimerTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Handler.Callback;
import java.util.Calendar;
import android.media.MediaPlayer;
import android.app.Activity;
import android.app.AlertDialog;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
public class Diagnosa extends Activity {
int ER=0;
String masterPola="";
String sudah="";
String sudahNo="";
String dataIndex="";
String pilYes="";
String pilYes2="";
int ike=0;
int index=0;
int indexke=0;
int jp=9;
int jg=23;
int[]jumG;
double[]arBobot;
String[]arPenyakit;
String[]arSolusi;
String[]arPenyebab;
int[]arGB;
String[]arRelasi;
String[]arGejala;
String[]arInit;
String pola="";
RadioButton radA, radB;
// String sNama = "", sUsia = "", sJk = "";
int ke = 0,jumsoal=0;
int jd = 10;
ImageView imgGambar;
TextView txtTanya, txtTanyake;
int gb=R.drawable.tipsbnr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soal_layout);
txtTanya = (TextView) findViewById(R.id.txtTanya);
txtTanyake = (TextView) findViewById(R.id.txtTanyaKe);
imgGambar = (ImageView) findViewById(R.id.myGambar);
radA = (RadioButton) findViewById(R.id.radA);
radA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pilYes=pilYes+dataIndex;
pilYes2=pilYes2+arGejala[ike]+"#";
ke = ke + 1;
indexke=indexke+1;
if (indexke >= jumsoal) {
if(ER>0){
none();
}
else{
selesai();
}
} else {
lihat();
}
}
});
radB = (RadioButton) findViewById(R.id.radB);
radB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sudahNo=sudahNo+dataIndex;
ke = ke + 1;
index=index+1;//pindah Pohon
indexke=0;
if (index >= jp) {
none();
} else {
String polanext=arRelasi[index];
masterPola=polanext;
int p1=sudah.length();
int p2=polanext.length();
int p3=sudahNo.length();
ER=0;
char[]ars=sudahNo.toCharArray();
for(int m=0;m<p3;m++){
String ch=String.valueOf(ars[m]);
if(masterPola.indexOf(ch)>=0){
ER=ER+1;
}
}
if (ER >0) {
index=index+1;//terus ke pohon berikutnyaaa
indexke=0;
if (index >= jp) {
//none();
}
else{
polanext=arRelasi[index];
masterPola=polanext;
}
}
if (index >= jp) {
none();
}
else{
char[]arn=sudah.toCharArray();
for(int m=0;m<p1;m++){
String ch=String.valueOf(arn[m]);
if(polanext.indexOf(ch)>=0){
polanext=polanext.replaceAll(ch, "");
}
pola=polanext;
lihat();
}//else
}
}
}
});
loaddata();
pola=arRelasi[index];
masterPola=pola;
lihat();
}
void loaddata(){
jp=10;
jg=26;
arPenyakit=new String[jp];
arPenyebab=new String[jp];
arSolusi=new String[jp];
arRelasi=new String[jp];
arGejala=new String[jg];
arGB=new int[jg];
arGejala[0]="Gejala serangan pada tanaman yang terserang, kuncupnya mengeluarkan bau busuk";
arGejala[1]="Gejala serangan daun berwarna kecoklatan";
arGejala[2]="Gejala serangan memperlihatkan batang pada ketinggian sekitar 2 m di atas tanah membusuk dan berwarna coklat keabuan";
arGejala[3]="Gejala serangan pada daun yang terserang akan berwarna hijau pucat";
arGejala[4]="Gejala serangan tandan buah membusuk";
arGejala[5]="Gejala serangan pertumbuhan tanaman terlihat tidak normal, daun menguning, keragaan tanaman tidak segar";
arGejala[6]="Gejala serangan daun terdapat bercak-bercak coklat diujung dan tepi daun";
arGejala[7]="Gejala serangan terdapat bercak-bercak pada daun dengan bentuk melonjong warna kuning dan di bagian dalamnya berwarna coklat";
arGejala[8]="Gejala serangan daun bagian tengah sobek";
arGejala[9]="Gejala serangan adanya miselium bewarna putih diantara buah masak atau pangkal pelepah daun";
arGejala[10]="Gejala serangan seluruh tajuk menjadi kekuningan dan pucat karena kekurangan zat hara dan air ";
arGejala[11]="Gejala serangan banyak daun yang membengkok ke bawah di tengah pelepahnya";
arGejala[12]="Gejala serangan seluruh tandan buah telah terserang jamur";
arGejala[13]="Gejala serangan daun tua yang mengering sengkleh";
arGejala[14]="Gejala serangan tanaman akan mati dalam waktu 6 –12 bulan setelah timbul gejala";
arGejala[15]="Gejala serangan terbentuk buah cendawan dari pangkal batang";
arGejala[16]="Gejala serangan kelayuan menyeluruh seperti kurang air dan hara";
arGejala[17]="Gejala serangan benang-benang jamur yang berwarna putih mengkilat meluas di permukaan tandan buah";
arGejala[18]="Gejala serangan kuncup membusuk dan mudah dicabut";
arGejala[19]="Gejala serangan jaringan pada kuncup membusuk";
arGejala[20]="Gejala serangan warna daun yang terbawah berubah dan selanjutnya akan mati";
arGejala[21]="Gejala serangan terinfeksi mengeluarkan getah pada daun yang tua";
arGejala[22]="Gejala serangan pelepah daun bagian bawah patah";
arGejala[23]="Gejala serangan bercak coklat dikelilingi warna kuning dan terlihat sebagai pembatas antara daun yang sehat dengan daun yang tidak sehat/terserang penyakit";
arGejala[24]="Gejala serangan pelepah berukuran abnormal atau kecil-kecil";
arGejala[25]="Gejala serangan akar tanaman yang sakit berwarna coklat atau kemerah-merahan dan membusuk";
for(int i=0;i<jg;i++) {
arGB[i] = R.drawable.tipsbnr;
}
arPenyakit[0]="Penyakit Busuk Titik Tumbuh";
arPenyakit[1]="Penyakit Busuk Kuncup";
arPenyakit[2]="Penyakit Busuk Batang Atas";
arPenyakit[3]="Penyakit Busuk Pangkal Batang";
arPenyakit[4]="Penyakit Busuk Kering Pangkal Batang";
arPenyakit[5]="Penyakit Akar";
arPenyakit[6]="Penyakit Antraknosa";
arPenyakit[7]="Penyakit Garis Kuning";
arPenyakit[8]="Penyakit Tajuk";
arPenyakit[9]="Penyakit Busuk Tandan";
arPenyebab[0]="Penyebab serangan bakteri erwinia";
arPenyebab[1]="Penyebab serangan ini sampai saat ini masih dalam kajian dan belum menemukan penyerang yang pasti";
arPenyebab[2]="Penyebab serangan jamur fomex noxius";
arPenyebab[3]="Penyebab serangan jamur Ganoderma";
arPenyebab[4]="Penyebab serangan jamur Ceratocytis paradoxa";
arPenyebab[5]="Penyebab serangan jamur Rhizoctonia lamellifera";
arPenyebab[6]="Penyebab serangan jamur Melanconium sp, Botryodiplodia palmarum, Glomerella cingulata";
arPenyebab[7]="Penyebab serangan jamur Fusarium oxysporum";
arPenyebab[8]="Penyebabnya biasanya dikarenakan menurunnya sifat genetik indukan";
arPenyebab[9]="Penyebab serangan jamur Marasmius palmivorus";
arSolusi[0]="pengendalian dapat mengaplikasikan bakteri yang berfungsi sebagai pemangsa bagi bakteri erwinia";
arSolusi[1]="Pengendalian yang dilakukan masih sebatas melakukan pemotongan bagian kuncup yang terserang";
arSolusi[2]="pengendalian penanganan dengan cara membuang bagian batang yang terserang dan menutup bekas luka dengan obat luka yang ada. Pada kondisi parah tanaman dibongkar dan dimusnahkan.";
arSolusi[3]="pengendalian dapat melakukan aplikasi dengan menggunakan bahan yang mengandung Tricodherma ( produk CustomBio ), dapat disemprotkan kebagian yang terserang dan penyemprotan pada tanah sekeliling tanaman pokok secara melingkar";
arSolusi[4]="pengendalian untuk tanaman yang sudah terserang secara hebat dengan melakukan pembongkaran dan pemusnahan dengan cara dibakar";
arSolusi[5]="pengendalian dimulai sejak awal kegiatan di dalam pesemaian dengan mempersiapkan media yang tidak terkontaminasi jamur, drainase yang baik agar tidak terjadi kekeringan yang ekstrim pada tanaman";
arSolusi[6]="pengendalian sejak awal mulai dari pemindahan bibit, dimana seluruh media tanah bibit disertakan, jarak tanam, penyiraman dan pemupukan yang dilakukan secara teratur dan berimbang, aplikasi Captan 0.2 % atau Cuman 0.1 %";
arSolusi[7]="pengendalian melakukan proses inokulasi pada bibit dan tanaman muda, atau dengan melakukan aplikasi bahan yang mengandung Tricodherma & Bacillus ( produk CustomBio )";
arSolusi[8]="pengendalian dimulai sejak awal terutama melakukan seleksi indukan yang bersifat karier penyakit ini, sehingga akan didapatkan bibit yang mempunyai sifat-sifat yang sehat.";
arSolusi[9]="pengendalian dengan menjaga sanitasi kebun terutama pada musim penghujan, aplikasi difolatan 0.2 %, melakukan penyerbukan buatan atau kastrasi";
arRelasi[0]="ABS";
arRelasi[1]="BGT";
arRelasi[2]="CIO";
arRelasi[3]="DKP";
arRelasi[4]="ENOPQW";
arRelasi[5]="FPZ";
arRelasi[6]="GTX";
arRelasi[7]="FHN";
arRelasi[8]="ILY";
arRelasi[9]="JMR";
String abj="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char[]ar=abj.toCharArray();
int pj=ar.length;
for(int i=0;i<pj;i++) {
String ch=String.valueOf(ar[i]);//A B C D ...
for(int j=0;j<jp;j++) {
String relasi=arRelasi[j];//ABC
}//j
} //for
}
int getIndex(String ch){
int id=0;
if(ch.equals("A")){id=0;}
else if(ch.equals("B")){id=1;}
else if(ch.equals("C")){id=2;}
else if(ch.equals("D")){id=3;}
else if(ch.equals("E")){id=4;}
else if(ch.equals("F")){id=5;}
else if(ch.equals("G")){id=6;}
else if(ch.equals("H")){id=7;}
else if(ch.equals("I")){id=8;}
else if(ch.equals("J")){id=9;}
else if(ch.equals("K")){id=10;}
else if(ch.equals("L")){id=11;}
else if(ch.equals("M")){id=12;}
else if(ch.equals("N")){id=13;}
else if(ch.equals("O")){id=14;}
else if(ch.equals("P")){id=15;}
else if(ch.equals("Q")){id=16;}
else if(ch.equals("R")){id=17;}
else if(ch.equals("S")){id=18;}
else if(ch.equals("T")){id=19;}
else if(ch.equals("U")){id=20;}
else if(ch.equals("V")){id=21;}
else if(ch.equals("W")){id=22;}
else if(ch.equals("X")){id=23;}
return id;
}
void lihat() {//ABCLUV
radA.setChecked(false);
radB.setChecked(false);
jumsoal=pola.length();
dataIndex=pola.substring(indexke,indexke+1);
sudah=sudah+dataIndex;
ike=getIndex(dataIndex);
txtTanya.setText((ke + 1) + "." + arGejala[ike]);
radA.setText("Ya, Saya Mengalami");
radB.setText("Tidak, Saya Tidak Mengalami");
txtTanyake.setText("");
txtTanyake.setText("#Pertanyaan ke " + (ke + 1) + "#Group:" +index+"#Pola:"+arRelasi[index]+"/Replace:"+ pola+ " "+arPenyakit[index]+"#Y:"+pilYes+"#N:"+sudahNo);
if(ke%6==0){gb=R.drawable.tipsbnr;}
else if(ke%6==1){gb=R.drawable.tipsbnr;}
else if(ke%6==2){gb=R.drawable.tipsbnr;}
else if(ke%6==3){gb=R.drawable.tipsbnr;}
else if(ke%6==4){gb=R.drawable.tipsbnr;}
else if(ke%6==5){gb=R.drawable.tipsbnr;}
imgGambar.setImageResource(gb);
}
public void selesai() {
new AlertDialog.Builder(this).setTitle("Hasil Analisa Kerusakan")
.setMessage("Kelapa Sawit Terdiagnosa "+arPenyakit[index])
.setNeutralButton("Hasil", new OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
Calendar cal = Calendar.getInstance();
int jam = cal.get(Calendar.HOUR);
int menit = cal.get(Calendar.MINUTE);
int detik = cal.get(Calendar.SECOND);
int tgl = cal.get(Calendar.DATE);
int bln = cal.get(Calendar.MONTH)+1;
int thn = cal.get(Calendar.YEAR);
String stgl = String.valueOf(tgl) + "-"
+ String.valueOf(bln) + "-"
+ String.valueOf(thn);
String sjam = String.valueOf(jam) + ":"
+ String.valueOf(menit) + ":"
+ String.valueOf(detik);
Intent i = new Intent(Diagnosa.this,Hasil.class);
i.putExtra("hasil", arPenyakit[index]);
i.putExtra("solusi", arSolusi[index]);
i.putExtra("penyebab", arPenyebab[index]);
i.putExtra("gb", gb);
i.putExtra("keterangan",stgl+ " " + sjam+ "\n"+ "Forward Chaining");
startActivity(i);
finish();
}
}).show();
}
public void none() {
new AlertDialog.Builder(this).setTitle("Hasil Analisa Penyakit")
.setMessage("Kelapa Sawit Gagal Terdiagnosa ")
.setNeutralButton("Hasil", new OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
finish();
}
}).show();
}
public void keluarYN() {
AlertDialog.Builder ad = new AlertDialog.Builder(Diagnosa.this);
ad.setMessage("Apakah anda yakin ingin kembali?");
ad.setPositiveButton("YA", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
ad.setNegativeButton("TIDAK", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
ad.show();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
keluarYN();
;
return true;
}
return super.onKeyDown(keyCode, event);
}
}
+++++++++++++++++++++++++++++++++++++++++++++
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dip"
android:background="#999999" >
<TableLayout
android:id="@+id/TableLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff" >
<ImageView
android:id="@+id/myGambar"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_centerHorizontal="true"
android:src="@drawable/tipsbnr" />
<TableRow
android:id="@+id/TableRow00"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/txtTanya"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1.Apakah Anda mengalami gejala Pusing2" />
</TableRow>
<RadioGroup
android:id="@+id/RadioGroup01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ya"
android:textColor="#000" >
</RadioButton>
<RadioButton
android:id="@+id/radB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tidak"
android:textColor="#000" >
</RadioButton>
</RadioGroup>
<TableRow
android:id="@+id/TableRow02"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</TableRow>
<TableRow
android:id="@+id/TableRow02s"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</TableRow>
<TableRow
android:id="@+id/TableRow02a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/txtTanyaKe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pertanyaan ke-1" />
</TableRow>
</TableLayout>
</ScrollView>
</RelativeLayout>
FC CF
package com.example.lp2maray.splashscreenawal;
//nox_adb.exe connect 127.0.0.1:62001
import android.os.Bundle;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlertDialog;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
public class Diagnosa extends Activity {
dbHasil helper=null;
String[]arH;
double[]arjum;
double[]arada;
double[]araMB;
double[]araCF;
int myindex=0;
double totmax=0;
int jumindex=0;
int ER=0;
String masterPola="";
String sudah="";
String sudahNo="";
String dataIndex="";
String pilYes="";
String pilYes2="";
int ike=0;
int index=0;
int indexke=0;
int jp=10;
int jg=26;
int[]jumG;
double[]arBobot;
String[]arPenyakit;
String[]arSolusi;
String[]arPenyebab;
int[]arGB;
String[]arRelasi;
String[]arGejala;
String[]arInit;
String pola="";
RadioButton radA, radB;
// String sNama = "", sUsia = "", sJk = "";
int ke = 0,jumsoal=0;
int jd = 10;
ImageView imgGambar;
TextView txtTanya, txtTanyake;
int gb=R.drawable.tipsbnr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soal_layout);
helper=new dbHasil(this);
txtTanya = (TextView) findViewById(R.id.txtTanya);
txtTanyake = (TextView) findViewById(R.id.txtTanyaKe);
imgGambar = (ImageView) findViewById(R.id.myGambar);
radA = (RadioButton) findViewById(R.id.radA);
radA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pilYes=pilYes+dataIndex;
pilYes2=pilYes2+arGejala[ike]+"#";
ke = ke + 1;
indexke=indexke+1;
if (indexke >= jumsoal) {
if(ER>0){
none();
}
else{
selesai();
}
} else {
lihat();
}
}
});
radB = (RadioButton) findViewById(R.id.radB);
radB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sudahNo=sudahNo+dataIndex;
ke = ke + 1;
index=index+1;//pindah Pohon
indexke=0;
if (index >= jp) {
none();
} else {
String polanext=arRelasi[index];
masterPola=polanext;
int p1=sudah.length();
int p2=polanext.length();
int p3=sudahNo.length();
ER=0;
char[]ars=sudahNo.toCharArray();
for(int m=0;m<p3;m++){
String ch=String.valueOf(ars[m]);
if(masterPola.indexOf(ch)>=0){
ER=ER+1;
}
}
if (ER >0) {
araCF=new double[jp];
index=index+1;//terus ke pohon berikutnyaaa
indexke=0;
if (index >= jp) {
none();
}
else{
polanext=arRelasi[index];
masterPola=polanext;
}
}
if (index >= jp) {
none();
}
else{
char[]arn=sudah.toCharArray();
for(int m=0;m<p1;m++){
String ch=String.valueOf(arn[m]);
if(polanext.indexOf(ch)>=0){
polanext=polanext.replaceAll(ch, "");
}
pola=polanext;
lihat();
}//else
}
}
}
});
loaddata();
pola=arRelasi[index];
masterPola=pola;
lihat();
}
void loaddata(){
jg=26;
jp=10;
arPenyakit=new String[jp];
arPenyebab=new String[jp];
arSolusi=new String[jp];
arRelasi=new String[jp];
araCF=new double[jp];
for(int i=0;i<jp;i++) {
araCF[i] = 0;
}
arGejala=new String[jg];
arGB=new int[jg];
arGejala[0]="Gejala serangan pada tanaman yang terserang, kuncupnya mengeluarkan bau busuk";
arGejala[1]="Gejala serangan daun berwarna kecoklatan";
arGejala[2]="Gejala serangan memperlihatkan batang pada ketinggian sekitar 2 m di atas tanah membusuk dan berwarna coklat keabuan";
arGejala[3]="Gejala serangan pada daun yang terserang akan berwarna hijau pucat";
arGejala[4]="Gejala serangan tandan buah membusuk";
arGejala[5]="Gejala serangan pertumbuhan tanaman terlihat tidak normal, daun menguning, keragaan tanaman tidak segar";
arGejala[6]="Gejala serangan daun terdapat bercak-bercak coklat diujung dan tepi daun";
arGejala[7]="Gejala serangan terdapat bercak-bercak pada daun dengan bentuk melonjong warna kuning dan di bagian dalamnya berwarna coklat";
arGejala[8]="Gejala serangan daun bagian tengah sobek";
arGejala[9]="Gejala serangan adanya miselium bewarna putih diantara buah masak atau pangkal pelepah daun";
arGejala[10]="Gejala serangan seluruh tajuk menjadi kekuningan dan pucat karena kekurangan zat hara dan air ";
arGejala[11]="Gejala serangan banyak daun yang membengkok ke bawah di tengah pelepahnya";
arGejala[12]="Gejala serangan seluruh tandan buah telah terserang jamur";
arGejala[13]="Gejala serangan daun tua yang mengering sengkleh";
arGejala[14]="Gejala serangan tanaman akan mati dalam waktu 6 –12 bulan setelah timbul gejala";
arGejala[15]="Gejala serangan terbentuk buah cendawan dari pangkal batang";
arGejala[16]="Gejala serangan kelayuan menyeluruh seperti kurang air dan hara";
arGejala[17]="Gejala serangan benang-benang jamur yang berwarna putih mengkilat meluas di permukaan tandan buah";
arGejala[18]="Gejala serangan kuncup membusuk dan mudah dicabut";
arGejala[19]="Gejala serangan jaringan pada kuncup membusuk";
arGejala[20]="Gejala serangan warna daun yang terbawah berubah dan selanjutnya akan mati";
arGejala[21]="Gejala serangan terinfeksi mengeluarkan getah pada daun yang tua";
arGejala[22]="Gejala serangan pelepah daun bagian bawah patah";
arGejala[23]="Gejala serangan bercak coklat dikelilingi warna kuning dan terlihat sebagai pembatas antara daun yang sehat dengan daun yang tidak sehat/terserang penyakit";
arGejala[24]="Gejala serangan pelepah berukuran abnormal atau kecil-kecil";
arGejala[25]="Gejala serangan akar tanaman yang sakit berwarna coklat atau kemerah-merahan dan membusuk";
for(int i=0;i<jg;i++) {
arGB[i] = R.drawable.tipsbnr;
}
arPenyakit[0]="Penyakit Busuk Titik Tumbuh";
arPenyakit[1]="Penyakit Busuk Kuncup";
arPenyakit[2]="Penyakit Busuk Batang Atas";
arPenyakit[3]="Penyakit Busuk Pangkal Batang";
arPenyakit[4]="Penyakit Busuk Kering Pangkal Batang";
arPenyakit[5]="Penyakit Akar";
arPenyakit[6]="Penyakit Antraknosa";
arPenyakit[7]="Penyakit Garis Kuning";
arPenyakit[8]="Penyakit Tajuk";
arPenyakit[9]="Penyakit Busuk Tandan";
arPenyebab[0]="Penyebab serangan bakteri erwinia";
arPenyebab[1]="Penyebab tanaman menjadi tidak normal, tumbuh menjadi kerdil, pertumbuhan menjadi lambat dan tidak akan membentuk buah.Penyebab tanaman menjadi tidak normal, tumbuh menjadi kerdil, pertumbuhan menjadi lambat dan tidak akan membentuk buah.Penyebab tanaman menjadi tidak normal, tumbuh menjadi kerdil, pertumbuhan menjadi lambat dan tidak akan membentuk buah";
arPenyebab[2]="Penyebab serangan jamur fomex noxius";
arPenyebab[3]="Penyebab serangan jamur Ganoderma";
arPenyebab[4]="Penyebab serangan jamur Ceratocytis paradoxa";
arPenyebab[5]="Penyebab serangan jamur Rhizoctonia lamellifera";
arPenyebab[6]="Penyebab serangan jamur Melanconium sp, Botryodiplodia palmarum, Glomerella cingulata";
arPenyebab[7]="Penyebab serangan jamur Fusarium oxysporum";
arPenyebab[8]="Penyebabnya biasanya dikarenakan menurunnya sifat genetik indukan";
arPenyebab[9]="Penyebab serangan jamur Marasmius palmivorus";
arSolusi[0]="pengendalian dapat mengaplikasikan bakteri yang berfungsi sebagai pemangsa bagi bakteri erwinia";
arSolusi[1]="Pengendalian yang dilakukan masih sebatas melakukan pemotongan bagian kuncup yang terserang";
arSolusi[2]="pengendalian penanganan dengan cara membuang bagian batang yang terserang dan menutup bekas luka dengan obat luka yang ada. Pada kondisi parah tanaman dibongkar dan dimusnahkan.";
arSolusi[3]="pengendalian dapat melakukan aplikasi dengan menggunakan bahan yang mengandung Tricodherma ( produk CustomBio ), dapat disemprotkan kebagian yang terserang dan penyemprotan pada tanah sekeliling tanaman pokok secara melingkar";
arSolusi[4]="pengendalian untuk tanaman yang sudah terserang secara hebat dengan melakukan pembongkaran dan pemusnahan dengan cara dibakar";
arSolusi[5]="pengendalian dimulai sejak awal kegiatan di dalam pesemaian dengan mempersiapkan media yang tidak terkontaminasi jamur, drainase yang baik agar tidak terjadi kekeringan yang ekstrim pada tanaman";
arSolusi[6]="pengendalian sejak awal mulai dari pemindahan bibit, dimana seluruh media tanah bibit disertakan, jarak tanam, penyiraman dan pemupukan yang dilakukan secara teratur dan berimbang, aplikasi Captan 0.2 % atau Cuman 0.1 %";
arSolusi[7]="pengendalian melakukan proses inokulasi pada bibit dan tanaman muda, atau dengan melakukan aplikasi bahan yang mengandung Tricodherma & Bacillus ( produk CustomBio )";
arSolusi[8]="pengendalian dimulai sejak awal terutama melakukan seleksi indukan yang bersifat karier penyakit ini, sehingga akan didapatkan bibit yang mempunyai sifat-sifat yang sehat.";
arSolusi[9]="pengendalian dengan menjaga sanitasi kebun terutama pada musim penghujan, aplikasi difolatan 0.2 %, melakukan penyerbukan buatan atau kastrasi";
arRelasi[0]="ABS";
arRelasi[1]="BGT";
arRelasi[2]="CIO";
arRelasi[3]="DKP";
arRelasi[4]="ENOPQW";
arRelasi[5]="FPZ";
arRelasi[6]="GTX";
arRelasi[7]="FHN";
arRelasi[8]="ILY";
arRelasi[9]="JMR";
String abjad="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char[]ar=abjad.toCharArray();
int pa=ar.length;
arjum=new double[pa];
arada=new double[pa];
araMB=new double[pa];
arH=new String[pa];
for(int i=0;i<pa;i++){
araMB[i]=0;
String H=String.valueOf(ar[i]);//A,B,C,D
double ada=0;
double tb=0;
for(int j=0;j<jp;j++) {
if(arRelasi[j].indexOf(H)>=0){
double pj=arRelasi[j].length();//3
double bobot=(1/pj) *100;
ada=ada+1;
tb=tb+bobot;
}//if
}//j
arada[i]=ada;
arjum[i]=tb;
arH[i]=H;
araMB[i]=(tb/ada)/100;
Log.d("BACA",arH[i]+"="+arjum[i]+"="+arada[i]+"="+araMB[i]+"");
}//
}
int getIndex(String ch){
int id=0;
if(ch.equals("A")){id=0;}
else if(ch.equals("B")){id=1;}
else if(ch.equals("C")){id=2;}
else if(ch.equals("D")){id=3;}
else if(ch.equals("E")){id=4;}
else if(ch.equals("F")){id=5;}
else if(ch.equals("G")){id=6;}
else if(ch.equals("H")){id=7;}
else if(ch.equals("I")){id=8;}
else if(ch.equals("J")){id=9;}
else if(ch.equals("K")){id=10;}
else if(ch.equals("L")){id=11;}
else if(ch.equals("M")){id=12;}
else if(ch.equals("N")){id=13;}
else if(ch.equals("O")){id=14;}
else if(ch.equals("P")){id=15;}
else if(ch.equals("Q")){id=16;}
else if(ch.equals("R")){id=17;}
else if(ch.equals("S")){id=18;}
else if(ch.equals("T")){id=19;}
else if(ch.equals("U")){id=20;}
else if(ch.equals("V")){id=21;}
else if(ch.equals("W")){id=22;}
else if(ch.equals("X")){id=23;}
return id;
}
void lihat() {//ABCLUV
radA.setChecked(false);
radB.setChecked(false);
jumsoal=pola.length();
dataIndex=pola.substring(indexke,indexke+1);
sudah=sudah+dataIndex;
ike=getIndex(dataIndex);
txtTanya.setText((ke + 1) + "." + arGejala[ike]);
radA.setText("Ya, Saya Mengalami");
radB.setText("Tidak, Saya Tidak Mengalami");
txtTanyake.setText("");
txtTanyake.setText("#Pertanyaan ke " + (ke + 1) + "#Group:" +index+"#Pola:"+arRelasi[index]+"/Replace:"+ pola+ " "+arPenyakit[index]+"#Y:"+pilYes+"#N:"+sudahNo);
if(ke%6==0){gb=R.drawable.tipsbnr;}
else if(ke%6==1){gb=R.drawable.tipsbnr;}
else if(ke%6==2){gb=R.drawable.tipsbnr;}
else if(ke%6==3){gb=R.drawable.tipsbnr;}
else if(ke%6==4){gb=R.drawable.tipsbnr;}
else if(ke%6==5){gb=R.drawable.tipsbnr;}
imgGambar.setImageResource(gb);
}
public void selesai() {
new AlertDialog.Builder(this).setTitle("Hasil Analisa Penyakit Forward Chaining")
.setMessage("Pohon Sawit Anda Terdiagnosa "+arPenyakit[index])
.setNeutralButton("Hasil", new OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
Calendar cal = Calendar.getInstance();
int jam = cal.get(Calendar.HOUR);
int menit = cal.get(Calendar.MINUTE);
int detik = cal.get(Calendar.SECOND);
int tgl = cal.get(Calendar.DATE);
int bln = cal.get(Calendar.MONTH)+1;
int thn = cal.get(Calendar.YEAR);
String stgl = String.valueOf(tgl) + "-"
+ String.valueOf(bln) + "-"
+ String.valueOf(thn);
String sjam = String.valueOf(jam) + ":"
+ String.valueOf(menit) + ":"
+ String.valueOf(detik);
Intent i = new Intent(Diagnosa.this,Hasil.class);
i.putExtra("hasil", arPenyakit[index]);
i.putExtra("solusi", arSolusi[index]);
i.putExtra("penyebab", arPenyebab[index]);
i.putExtra("gb", gb);
i.putExtra("keterangan",stgl+ " " + sjam+ "\n"+ "Forward Chaining");
startActivity(i);
finish();
}
}).show();
}
public void none() {
myindex=0;
totmax=0;
jumindex=0;
/////=============
int jyes=pilYes.length();
char[]ary=pilYes.toCharArray();//IL
for(int j=0;j<jp;j++){
int start=0;
double totalCF=0;
String kar=arRelasi[j];//ABS
//pilYes
for(int k=0;k<jyes;k++) {
char hh=ary[k];//I
String chh=String.valueOf(hh);//I
if(kar.indexOf(chh)>=0){
//if(chh.indexOf(kar)>=0){
Log.d("CFOK","MB="+chh+"?");
if(start==0){
start=start+1;
int nv=getIndex(chh);
totalCF=araMB[nv];
Log.d("CFOK","MB1="+chh+"="+totalCF+"#tot="+totalCF);
}
else{
start=start+1;
int nv=getIndex(chh);
double nvnow=araMB[nv];
totalCF=totalCF+(nvnow* (1-totalCF));
Log.d("CFOK","MB"+start+"="+chh+"="+nvnow+"#tot="+totalCF);
}
}
}//k
araCF[j]=totalCF;
if(totmax<totalCF){
jumindex=start;
myindex=j;
totmax=totalCF;
}
Log.d("CFOK","CFOK="+j+"."+arRelasi[j]+"="+araCF[j]+"#"+pilYes);
//arPenyakit
}//i jp
//================
if(jumindex>=2){
new AlertDialog.Builder(this).setTitle("Hasil Analisa Penyakit Certainty Factor")
.setMessage("Pohon Sawit Anda Terdiagnosa "+arPenyakit[myindex]+" ("+totmax+")")
.setNeutralButton("OK", new OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
Calendar cal = Calendar.getInstance();
int jam = cal.get(Calendar.HOUR);
int menit = cal.get(Calendar.MINUTE);
int detik = cal.get(Calendar.SECOND);
int tgl = cal.get(Calendar.DATE);
int bln = cal.get(Calendar.MONTH)+1;
int thn = cal.get(Calendar.YEAR);
String stgl = String.valueOf(tgl) + "-"
+ String.valueOf(bln) + "-"
+ String.valueOf(thn);
String sjam = String.valueOf(jam) + ":"
+ String.valueOf(menit) + ":"
+ String.valueOf(detik);
//helper.inserthasil(arPenyakit[myindex], arPenyebab[myindex],arSolusi[myindex],"CF: "+totmax);
Intent i = new Intent(Diagnosa.this,Hasil.class);
i.putExtra("hasil", arPenyakit[myindex]);
i.putExtra("solusi", arSolusi[myindex]);
i.putExtra("penyebab", arPenyebab[myindex]);
i.putExtra("gb", gb);
i.putExtra("keterangan",stgl+ " " + sjam+ "\n"+ "Certainty Factor : "+totmax);
startActivity(i);
finish();
}
}).show();
}
else {
new AlertDialog.Builder(this).setTitle("Hasil Analisa Penyakit")
.setMessage("Pohon Sawit Anda Gagal Terdiagnosa ")
.setNeutralButton("Hasil", new OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
finish();
}
}).show();
}
}
public void keluarYN() {
AlertDialog.Builder ad = new AlertDialog.Builder(Diagnosa.this);
ad.setMessage("Apakah anda yakin ingin kembali?");
ad.setPositiveButton("YA", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
ad.setNegativeButton("TIDAK", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
ad.show();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
keluarYN();
;
return true;
}
return super.onKeyDown(keyCode, event);
}
}
//nox_adb.exe connect 127.0.0.1:62001
import android.os.Bundle;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlertDialog;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
public class Diagnosa extends Activity {
dbHasil helper=null;
String[]arH;
double[]arjum;
double[]arada;
double[]araMB;
double[]araCF;
int myindex=0;
double totmax=0;
int jumindex=0;
int ER=0;
String masterPola="";
String sudah="";
String sudahNo="";
String dataIndex="";
String pilYes="";
String pilYes2="";
int ike=0;
int index=0;
int indexke=0;
int jp=10;
int jg=26;
int[]jumG;
double[]arBobot;
String[]arPenyakit;
String[]arSolusi;
String[]arPenyebab;
int[]arGB;
String[]arRelasi;
String[]arGejala;
String[]arInit;
String pola="";
RadioButton radA, radB;
// String sNama = "", sUsia = "", sJk = "";
int ke = 0,jumsoal=0;
int jd = 10;
ImageView imgGambar;
TextView txtTanya, txtTanyake;
int gb=R.drawable.tipsbnr;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.soal_layout);
helper=new dbHasil(this);
txtTanya = (TextView) findViewById(R.id.txtTanya);
txtTanyake = (TextView) findViewById(R.id.txtTanyaKe);
imgGambar = (ImageView) findViewById(R.id.myGambar);
radA = (RadioButton) findViewById(R.id.radA);
radA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pilYes=pilYes+dataIndex;
pilYes2=pilYes2+arGejala[ike]+"#";
ke = ke + 1;
indexke=indexke+1;
if (indexke >= jumsoal) {
if(ER>0){
none();
}
else{
selesai();
}
} else {
lihat();
}
}
});
radB = (RadioButton) findViewById(R.id.radB);
radB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sudahNo=sudahNo+dataIndex;
ke = ke + 1;
index=index+1;//pindah Pohon
indexke=0;
if (index >= jp) {
none();
} else {
String polanext=arRelasi[index];
masterPola=polanext;
int p1=sudah.length();
int p2=polanext.length();
int p3=sudahNo.length();
ER=0;
char[]ars=sudahNo.toCharArray();
for(int m=0;m<p3;m++){
String ch=String.valueOf(ars[m]);
if(masterPola.indexOf(ch)>=0){
ER=ER+1;
}
}
if (ER >0) {
araCF=new double[jp];
index=index+1;//terus ke pohon berikutnyaaa
indexke=0;
if (index >= jp) {
none();
}
else{
polanext=arRelasi[index];
masterPola=polanext;
}
}
if (index >= jp) {
none();
}
else{
char[]arn=sudah.toCharArray();
for(int m=0;m<p1;m++){
String ch=String.valueOf(arn[m]);
if(polanext.indexOf(ch)>=0){
polanext=polanext.replaceAll(ch, "");
}
pola=polanext;
lihat();
}//else
}
}
}
});
loaddata();
pola=arRelasi[index];
masterPola=pola;
lihat();
}
void loaddata(){
jg=26;
jp=10;
arPenyakit=new String[jp];
arPenyebab=new String[jp];
arSolusi=new String[jp];
arRelasi=new String[jp];
araCF=new double[jp];
for(int i=0;i<jp;i++) {
araCF[i] = 0;
}
arGejala=new String[jg];
arGB=new int[jg];
arGejala[0]="Gejala serangan pada tanaman yang terserang, kuncupnya mengeluarkan bau busuk";
arGejala[1]="Gejala serangan daun berwarna kecoklatan";
arGejala[2]="Gejala serangan memperlihatkan batang pada ketinggian sekitar 2 m di atas tanah membusuk dan berwarna coklat keabuan";
arGejala[3]="Gejala serangan pada daun yang terserang akan berwarna hijau pucat";
arGejala[4]="Gejala serangan tandan buah membusuk";
arGejala[5]="Gejala serangan pertumbuhan tanaman terlihat tidak normal, daun menguning, keragaan tanaman tidak segar";
arGejala[6]="Gejala serangan daun terdapat bercak-bercak coklat diujung dan tepi daun";
arGejala[7]="Gejala serangan terdapat bercak-bercak pada daun dengan bentuk melonjong warna kuning dan di bagian dalamnya berwarna coklat";
arGejala[8]="Gejala serangan daun bagian tengah sobek";
arGejala[9]="Gejala serangan adanya miselium bewarna putih diantara buah masak atau pangkal pelepah daun";
arGejala[10]="Gejala serangan seluruh tajuk menjadi kekuningan dan pucat karena kekurangan zat hara dan air ";
arGejala[11]="Gejala serangan banyak daun yang membengkok ke bawah di tengah pelepahnya";
arGejala[12]="Gejala serangan seluruh tandan buah telah terserang jamur";
arGejala[13]="Gejala serangan daun tua yang mengering sengkleh";
arGejala[14]="Gejala serangan tanaman akan mati dalam waktu 6 –12 bulan setelah timbul gejala";
arGejala[15]="Gejala serangan terbentuk buah cendawan dari pangkal batang";
arGejala[16]="Gejala serangan kelayuan menyeluruh seperti kurang air dan hara";
arGejala[17]="Gejala serangan benang-benang jamur yang berwarna putih mengkilat meluas di permukaan tandan buah";
arGejala[18]="Gejala serangan kuncup membusuk dan mudah dicabut";
arGejala[19]="Gejala serangan jaringan pada kuncup membusuk";
arGejala[20]="Gejala serangan warna daun yang terbawah berubah dan selanjutnya akan mati";
arGejala[21]="Gejala serangan terinfeksi mengeluarkan getah pada daun yang tua";
arGejala[22]="Gejala serangan pelepah daun bagian bawah patah";
arGejala[23]="Gejala serangan bercak coklat dikelilingi warna kuning dan terlihat sebagai pembatas antara daun yang sehat dengan daun yang tidak sehat/terserang penyakit";
arGejala[24]="Gejala serangan pelepah berukuran abnormal atau kecil-kecil";
arGejala[25]="Gejala serangan akar tanaman yang sakit berwarna coklat atau kemerah-merahan dan membusuk";
for(int i=0;i<jg;i++) {
arGB[i] = R.drawable.tipsbnr;
}
arPenyakit[0]="Penyakit Busuk Titik Tumbuh";
arPenyakit[1]="Penyakit Busuk Kuncup";
arPenyakit[2]="Penyakit Busuk Batang Atas";
arPenyakit[3]="Penyakit Busuk Pangkal Batang";
arPenyakit[4]="Penyakit Busuk Kering Pangkal Batang";
arPenyakit[5]="Penyakit Akar";
arPenyakit[6]="Penyakit Antraknosa";
arPenyakit[7]="Penyakit Garis Kuning";
arPenyakit[8]="Penyakit Tajuk";
arPenyakit[9]="Penyakit Busuk Tandan";
arPenyebab[0]="Penyebab serangan bakteri erwinia";
arPenyebab[1]="Penyebab tanaman menjadi tidak normal, tumbuh menjadi kerdil, pertumbuhan menjadi lambat dan tidak akan membentuk buah.Penyebab tanaman menjadi tidak normal, tumbuh menjadi kerdil, pertumbuhan menjadi lambat dan tidak akan membentuk buah.Penyebab tanaman menjadi tidak normal, tumbuh menjadi kerdil, pertumbuhan menjadi lambat dan tidak akan membentuk buah";
arPenyebab[2]="Penyebab serangan jamur fomex noxius";
arPenyebab[3]="Penyebab serangan jamur Ganoderma";
arPenyebab[4]="Penyebab serangan jamur Ceratocytis paradoxa";
arPenyebab[5]="Penyebab serangan jamur Rhizoctonia lamellifera";
arPenyebab[6]="Penyebab serangan jamur Melanconium sp, Botryodiplodia palmarum, Glomerella cingulata";
arPenyebab[7]="Penyebab serangan jamur Fusarium oxysporum";
arPenyebab[8]="Penyebabnya biasanya dikarenakan menurunnya sifat genetik indukan";
arPenyebab[9]="Penyebab serangan jamur Marasmius palmivorus";
arSolusi[0]="pengendalian dapat mengaplikasikan bakteri yang berfungsi sebagai pemangsa bagi bakteri erwinia";
arSolusi[1]="Pengendalian yang dilakukan masih sebatas melakukan pemotongan bagian kuncup yang terserang";
arSolusi[2]="pengendalian penanganan dengan cara membuang bagian batang yang terserang dan menutup bekas luka dengan obat luka yang ada. Pada kondisi parah tanaman dibongkar dan dimusnahkan.";
arSolusi[3]="pengendalian dapat melakukan aplikasi dengan menggunakan bahan yang mengandung Tricodherma ( produk CustomBio ), dapat disemprotkan kebagian yang terserang dan penyemprotan pada tanah sekeliling tanaman pokok secara melingkar";
arSolusi[4]="pengendalian untuk tanaman yang sudah terserang secara hebat dengan melakukan pembongkaran dan pemusnahan dengan cara dibakar";
arSolusi[5]="pengendalian dimulai sejak awal kegiatan di dalam pesemaian dengan mempersiapkan media yang tidak terkontaminasi jamur, drainase yang baik agar tidak terjadi kekeringan yang ekstrim pada tanaman";
arSolusi[6]="pengendalian sejak awal mulai dari pemindahan bibit, dimana seluruh media tanah bibit disertakan, jarak tanam, penyiraman dan pemupukan yang dilakukan secara teratur dan berimbang, aplikasi Captan 0.2 % atau Cuman 0.1 %";
arSolusi[7]="pengendalian melakukan proses inokulasi pada bibit dan tanaman muda, atau dengan melakukan aplikasi bahan yang mengandung Tricodherma & Bacillus ( produk CustomBio )";
arSolusi[8]="pengendalian dimulai sejak awal terutama melakukan seleksi indukan yang bersifat karier penyakit ini, sehingga akan didapatkan bibit yang mempunyai sifat-sifat yang sehat.";
arSolusi[9]="pengendalian dengan menjaga sanitasi kebun terutama pada musim penghujan, aplikasi difolatan 0.2 %, melakukan penyerbukan buatan atau kastrasi";
arRelasi[0]="ABS";
arRelasi[1]="BGT";
arRelasi[2]="CIO";
arRelasi[3]="DKP";
arRelasi[4]="ENOPQW";
arRelasi[5]="FPZ";
arRelasi[6]="GTX";
arRelasi[7]="FHN";
arRelasi[8]="ILY";
arRelasi[9]="JMR";
String abjad="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char[]ar=abjad.toCharArray();
int pa=ar.length;
arjum=new double[pa];
arada=new double[pa];
araMB=new double[pa];
arH=new String[pa];
for(int i=0;i<pa;i++){
araMB[i]=0;
String H=String.valueOf(ar[i]);//A,B,C,D
double ada=0;
double tb=0;
for(int j=0;j<jp;j++) {
if(arRelasi[j].indexOf(H)>=0){
double pj=arRelasi[j].length();//3
double bobot=(1/pj) *100;
ada=ada+1;
tb=tb+bobot;
}//if
}//j
arada[i]=ada;
arjum[i]=tb;
arH[i]=H;
araMB[i]=(tb/ada)/100;
Log.d("BACA",arH[i]+"="+arjum[i]+"="+arada[i]+"="+araMB[i]+"");
}//
}
int getIndex(String ch){
int id=0;
if(ch.equals("A")){id=0;}
else if(ch.equals("B")){id=1;}
else if(ch.equals("C")){id=2;}
else if(ch.equals("D")){id=3;}
else if(ch.equals("E")){id=4;}
else if(ch.equals("F")){id=5;}
else if(ch.equals("G")){id=6;}
else if(ch.equals("H")){id=7;}
else if(ch.equals("I")){id=8;}
else if(ch.equals("J")){id=9;}
else if(ch.equals("K")){id=10;}
else if(ch.equals("L")){id=11;}
else if(ch.equals("M")){id=12;}
else if(ch.equals("N")){id=13;}
else if(ch.equals("O")){id=14;}
else if(ch.equals("P")){id=15;}
else if(ch.equals("Q")){id=16;}
else if(ch.equals("R")){id=17;}
else if(ch.equals("S")){id=18;}
else if(ch.equals("T")){id=19;}
else if(ch.equals("U")){id=20;}
else if(ch.equals("V")){id=21;}
else if(ch.equals("W")){id=22;}
else if(ch.equals("X")){id=23;}
return id;
}
void lihat() {//ABCLUV
radA.setChecked(false);
radB.setChecked(false);
jumsoal=pola.length();
dataIndex=pola.substring(indexke,indexke+1);
sudah=sudah+dataIndex;
ike=getIndex(dataIndex);
txtTanya.setText((ke + 1) + "." + arGejala[ike]);
radA.setText("Ya, Saya Mengalami");
radB.setText("Tidak, Saya Tidak Mengalami");
txtTanyake.setText("");
txtTanyake.setText("#Pertanyaan ke " + (ke + 1) + "#Group:" +index+"#Pola:"+arRelasi[index]+"/Replace:"+ pola+ " "+arPenyakit[index]+"#Y:"+pilYes+"#N:"+sudahNo);
if(ke%6==0){gb=R.drawable.tipsbnr;}
else if(ke%6==1){gb=R.drawable.tipsbnr;}
else if(ke%6==2){gb=R.drawable.tipsbnr;}
else if(ke%6==3){gb=R.drawable.tipsbnr;}
else if(ke%6==4){gb=R.drawable.tipsbnr;}
else if(ke%6==5){gb=R.drawable.tipsbnr;}
imgGambar.setImageResource(gb);
}
public void selesai() {
new AlertDialog.Builder(this).setTitle("Hasil Analisa Penyakit Forward Chaining")
.setMessage("Pohon Sawit Anda Terdiagnosa "+arPenyakit[index])
.setNeutralButton("Hasil", new OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
Calendar cal = Calendar.getInstance();
int jam = cal.get(Calendar.HOUR);
int menit = cal.get(Calendar.MINUTE);
int detik = cal.get(Calendar.SECOND);
int tgl = cal.get(Calendar.DATE);
int bln = cal.get(Calendar.MONTH)+1;
int thn = cal.get(Calendar.YEAR);
String stgl = String.valueOf(tgl) + "-"
+ String.valueOf(bln) + "-"
+ String.valueOf(thn);
String sjam = String.valueOf(jam) + ":"
+ String.valueOf(menit) + ":"
+ String.valueOf(detik);
Intent i = new Intent(Diagnosa.this,Hasil.class);
i.putExtra("hasil", arPenyakit[index]);
i.putExtra("solusi", arSolusi[index]);
i.putExtra("penyebab", arPenyebab[index]);
i.putExtra("gb", gb);
i.putExtra("keterangan",stgl+ " " + sjam+ "\n"+ "Forward Chaining");
startActivity(i);
finish();
}
}).show();
}
public void none() {
myindex=0;
totmax=0;
jumindex=0;
/////=============
int jyes=pilYes.length();
char[]ary=pilYes.toCharArray();//IL
for(int j=0;j<jp;j++){
int start=0;
double totalCF=0;
String kar=arRelasi[j];//ABS
//pilYes
for(int k=0;k<jyes;k++) {
char hh=ary[k];//I
String chh=String.valueOf(hh);//I
if(kar.indexOf(chh)>=0){
//if(chh.indexOf(kar)>=0){
Log.d("CFOK","MB="+chh+"?");
if(start==0){
start=start+1;
int nv=getIndex(chh);
totalCF=araMB[nv];
Log.d("CFOK","MB1="+chh+"="+totalCF+"#tot="+totalCF);
}
else{
start=start+1;
int nv=getIndex(chh);
double nvnow=araMB[nv];
totalCF=totalCF+(nvnow* (1-totalCF));
Log.d("CFOK","MB"+start+"="+chh+"="+nvnow+"#tot="+totalCF);
}
}
}//k
araCF[j]=totalCF;
if(totmax<totalCF){
jumindex=start;
myindex=j;
totmax=totalCF;
}
Log.d("CFOK","CFOK="+j+"."+arRelasi[j]+"="+araCF[j]+"#"+pilYes);
//arPenyakit
}//i jp
//================
if(jumindex>=2){
new AlertDialog.Builder(this).setTitle("Hasil Analisa Penyakit Certainty Factor")
.setMessage("Pohon Sawit Anda Terdiagnosa "+arPenyakit[myindex]+" ("+totmax+")")
.setNeutralButton("OK", new OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
Calendar cal = Calendar.getInstance();
int jam = cal.get(Calendar.HOUR);
int menit = cal.get(Calendar.MINUTE);
int detik = cal.get(Calendar.SECOND);
int tgl = cal.get(Calendar.DATE);
int bln = cal.get(Calendar.MONTH)+1;
int thn = cal.get(Calendar.YEAR);
String stgl = String.valueOf(tgl) + "-"
+ String.valueOf(bln) + "-"
+ String.valueOf(thn);
String sjam = String.valueOf(jam) + ":"
+ String.valueOf(menit) + ":"
+ String.valueOf(detik);
//helper.inserthasil(arPenyakit[myindex], arPenyebab[myindex],arSolusi[myindex],"CF: "+totmax);
Intent i = new Intent(Diagnosa.this,Hasil.class);
i.putExtra("hasil", arPenyakit[myindex]);
i.putExtra("solusi", arSolusi[myindex]);
i.putExtra("penyebab", arPenyebab[myindex]);
i.putExtra("gb", gb);
i.putExtra("keterangan",stgl+ " " + sjam+ "\n"+ "Certainty Factor : "+totmax);
startActivity(i);
finish();
}
}).show();
}
else {
new AlertDialog.Builder(this).setTitle("Hasil Analisa Penyakit")
.setMessage("Pohon Sawit Anda Gagal Terdiagnosa ")
.setNeutralButton("Hasil", new OnClickListener() {
public void onClick(DialogInterface dlg, int sumthin) {
finish();
}
}).show();
}
}
public void keluarYN() {
AlertDialog.Builder ad = new AlertDialog.Builder(Diagnosa.this);
ad.setMessage("Apakah anda yakin ingin kembali?");
ad.setPositiveButton("YA", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
ad.setNegativeButton("TIDAK", new OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
ad.show();
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
keluarYN();
;
return true;
}
return super.onKeyDown(keyCode, event);
}
}
Langganan:
Postingan (Atom)