Senin, 29 Oktober 2018

Marker Maps Fr Json Database On Click

package com.example.komunitas;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;

public class Maps extends FragmentActivity{
   private Marker previousMarker = null;
   int jd=0;
   private SupportMapFragment mapFragment;
   String tkode="",tnama="",tmail="",thp="",tlati="",tlongi="",talamat="",tangkatan="",tstatus="",tgambar="";
   String skodelogin="",snamalogin="",smaillogin="";
   String myLati="-6.352953";
   String myLongi="106.831389";
   String myPosisi="UI";
private ProgressDialog pDialog;
JSONParser jParser = new JSONParser();
JSONArray myJSON = null;
String ip="";
ArrayList<HashMap<String, String>> arrayList;
private static final String TAG_SUKSES = "sukses";
private static final String TAG_record = "record";

String[]arkode_anggota;
String[]artgl;
String[]aralamat;
String[]arlatitude;
String[]arlongitude;
String[]arjam;



   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.maps);
       Intent i= this.getIntent();
      myLati= i.getStringExtra("myLati");
      myLongi= i.getStringExtra("myLongi");
      myPosisi= i.getStringExtra("myPosisi");

      skodelogin= i.getStringExtra("skodelogin");
      snamalogin= i.getStringExtra("snamalogin");
      smaillogin= i.getStringExtra("smaillogin");
        
        arrayList = new ArrayList<HashMap<String, String>>();
      ip=jParser.getIP();
         
      new load().execute();
      
      
   }
   class load extends AsyncTask<String, String, String> {
      @Override      protected void onPreExecute() {
         super.onPreExecute();
         pDialog = new ProgressDialog(Maps.this);
         pDialog.setMessage("Load data. Silahkan Tunggu...");
         pDialog.setIndeterminate(false);
         pDialog.setCancelable(false);
         pDialog.show();
      }
      protected String doInBackground(String... args) {
         List<NameValuePair> params = new ArrayList<NameValuePair>();
         JSONObject json = jParser.makeHttpRequest(ip+"lokasi/lokasi_show.php", "GET", params);
         Log.d("show: ", json.toString());
         try {
            int sukses = json.getInt(TAG_SUKSES);
            if (sukses == 1) {
               myJSON = json.getJSONArray(TAG_record);
               jd=myJSON.length();

arkode_anggota=new String[jd];
artgl=new String[jd];
aralamat=new String[jd];
arlatitude=new String[jd];
arlongitude=new String[jd];
arjam=new String[jd];


               for (int i = 0; i < jd; i++) {
                  JSONObject c = myJSON.getJSONObject(i);
                  
                  arkode_anggota[i]= c.getString("nama_anggota");
                  artgl[i]= c.getString("tgl");
                  aralamat[i]= c.getString("alamat");
                  arlatitude[i]= c.getString("latitude");
                  arlongitude[i]= c.getString("longitude");
                  arjam[i]= c.getString("jam");
                  
                  
               }
            } 
         } 
         catch (JSONException e) {e.printStackTrace();}
         return null;
      }

      protected void onPostExecute(String file_url) {
         pDialog.dismiss();
         runOnUiThread(new Runnable() {
            public void run() {
                setupMap();
            }
         });}
   }
   private void setupMap(){
         mapFragment = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.maps));

            mapFragment.getMapAsync(new OnMapReadyCallback() {
               @Override               public void onMapReady(GoogleMap map) {
                  double lat=-6.352953;
                  double lon=106.831389;
                  try{
                     lat=Double.parseDouble(myLati);
                     lon=Double.parseDouble(myLongi);
                  }
                  catch(Exception e){
                     lat=-6.352953;
                     lon=106.831389;
                  }
                  map.addMarker(new MarkerOptions().position(new LatLng(lat, lon)).title("Posisi Anda").snippet(myPosisi));
                  map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat,lon),10));

                  for(int i=0;i<jd;i++){
                      lat=-6.352953;
                      lon=106.831389;
                     try{
                        lat=Double.parseDouble(arlatitude[i]);
                        lon=Double.parseDouble(arlongitude[i]);
                     }
                     catch(Exception e){
                        lat=-6.352953;
                        lon=106.831389;
                     }
                     map.addMarker(new MarkerOptions().position(new LatLng(lat, lon)).title(arkode_anggota[i]).snippet(artgl[i]+" "+arjam[i]+" wib "+aralamat[i]));

                  }
//==============
                  map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
                     @Override                     public boolean onMarkerClick(Marker marker) {
                        String locAddress = marker.getTitle();
                        //fillTextViews(locAddress);                        if (previousMarker != null) {
                           previousMarker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED));
                        }
                        marker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
                        previousMarker = marker;


                        if(locAddress.equalsIgnoreCase("Posisi Anda")){}
                        else{
                           Intent i = new Intent(getApplicationContext(), Detail_anggota.class);
                           i.putExtra("pk", locAddress);
                           i.putExtra("myLati", myLati);
                           i.putExtra("myLongi", myLongi);
                           i.putExtra("myPosisi", myPosisi);
                           i.putExtra("skodelogin", skodelogin);
                           i.putExtra("snamalogin", snamalogin);
                           i.putExtra("smaillogin", smaillogin);
                           startActivityForResult(i, 100);


                        }
                        return true;
                     }
                  });
//==============               }
            });

         }

}


//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

<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"    >

    <fragment        android:id="@+id/maps"        android:layout_width="match_parent"        android:layout_height="match_parent"        class="com.google.android.gms.maps.SupportMapFragment"/>

</RelativeLayout>

Gradle.APP
apply plugin: 'com.android.application'
android {
    compileSdkVersion 28    defaultConfig {
        multiDexEnabled true        applicationId "com.example.komunitas"        minSdkVersion 19        targetSdkVersion 28        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }
    buildTypes {
        release {
            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }
    }
    useLibrary 'org.apache.http.legacy'}

dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
//        implementation 'com.android.support:support-v4:28.0.0'        implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'        implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'        implementation 'com.android.support:cardview-v7:28.0.0-alpha1'        implementation 'com.android.support.constraint:constraint-layout:1.1.3'        testImplementation 'junit:junit:4.12'        androidTestImplementation 'com.android.support.test:runner:1.0.2'        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
        implementation 'com.android.support:design:28.0.0-alpha1'        implementation 'com.android.support:multidex:1.0.1'        implementation 'com.jjoe64:graphview:4.2.2'

    //IMAGE LOAD    implementation 'com.github.bumptech.glide:glide:3.7.0'
    //CHAT UI    implementation 'hani.momanii.supernova_emoji_library:supernova-emoji-library:0.0.2'
    // AUTH    implementation 'com.google.android.gms:play-services-auth:9.2.0'    implementation 'com.google.firebase:firebase-auth:9.2.0'
    //DATABASE FIREBASE,UI    implementation 'com.google.firebase:firebase-database:9.2.0'    implementation 'com.firebaseui:firebase-ui-database:0.4.1'
    //STORAGE FIREBASE    implementation 'com.google.firebase:firebase-storage:9.2.0'
    //Places SERVICES    implementation 'com.google.android.gms:play-services-places:9.2.0'    implementation 'com.google.android.gms:play-services:9.2.0'

}
apply plugin: 'com.google.gms.google-services'


Jumat, 26 Oktober 2018

Gradle 28

Settingan Gradle terbaru:

APP

apply plugin: 'com.android.application'
android {
    compileSdkVersion 28    defaultConfig {
        multiDexEnabled true        applicationId "com.example.komunitas"        minSdkVersion 15        targetSdkVersion 28        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"    }
    buildTypes {
        release {
            minifyEnabled false            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'        }
    }
    useLibrary 'org.apache.http.legacy'}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:support-v4:28.0.0'    implementation 'com.android.support:appcompat-v7:28.0.0'    implementation 'com.android.support:recyclerview-v7:28.0.0'    implementation 'com.android.support:cardview-v7:28.0.0'    implementation 'com.android.support.constraint:constraint-layout:1.1.3'    testImplementation 'junit:junit:4.12'    androidTestImplementation 'com.android.support.test:runner:1.0.2'    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'    implementation 'com.google.android.gms:play-services:4.0.30'    implementation 'com.android.support:design:28.0.0'    implementation 'com.android.support:multidex:1.0.1'    implementation 'com.jjoe64:graphview:4.2.2'

}


Project

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.2'        
        // NOTE: Do not place your application dependencies here; they belong        // in the individual module build.gradle files    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}



+++++++++++++++++++++++++++
YAITU:
Add multiDexEnabled true to your build.gradle
android {
    compileSdkVersion 26
    defaultConfig {
      ...
        minSdkVersion 15
        targetSdkVersion 26
        multiDexEnabled true
     ...
    }
}
and add the dependency
dependencies {
    compile 'com.android.support:multidex:1.0.1'}
It may the first one works for u and so on but it really depends on the nature of your problem for me for example
I got the error once I have added this library
implementation 'com.jjoe64:graphview:4.2.2'
and later I discovered that I have to check that and I have to add the same version of the support libraries. So I have to try another version
compile 'com.jjoe64:graphview:4.2.1'
and it fixes the problem
it's better to use implementation or api rather compile
just replace compile with implementationdebugCompile with debugImplementationtestCompile with testImplementation and androidtestcompile with androidTestImplementation
For example: Instead of this
compile 'com.android.support:appcompat-v7:26.0.2'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.github.bumptech.glide:glide:4.0.0'
use like this
implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.github.bumptech.glide:glide:4.0.0'
SO:
  • Delete all the build folders and the gradle cache.
  • From the Build menu, press the Clean Project button.
  • After task completed, press the Rebuild Project button from the Build menu.




Rabu, 03 Oktober 2018

Android to NOX




1.Download NOX 
2.Install dan lacak pathnya ....(klo saya di D:\Program Files\Nox)

3.Setting adb nya
nox_adb.exe connect 127.0.0.1:62001


Ref: Konfigurasi Nox Lanjut


Senin, 06 Agustus 2018

Membuat Notifikasi

package tes.com.NIPSAlert;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.AsyncTask;
import android.support.v4.app.NotificationCompat;
import android.content.Context;
import android.util.Log;

import org.json.JSONException;

public class Menu_utama extends AppCompatActivity {
    String ip="",kategori="",PESAN="";
    JSONParser jParser = new JSONParser();
    JSONArray myJSON = null;
    int adabaru=0;
    Handler mHandler;
    private static final String TAG_SUKSES = "sukses";
    private static final String TAG_record = "record";

    String id="", name_user,email;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu_utama);
        ip=jParser.getIP();

        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(Menu_utama.this);
        Boolean Registered = sharedPref.getBoolean("Registered", false);
        if (!Registered){
            finish();
        }else {
            id= sharedPref.getString("id", "");
            name_user= sharedPref.getString("name_user", "");
            email = sharedPref.getString("email", "");
        }

        this.mHandler = new Handler();
        m_Runnable.run();
    }

    private final Runnable m_Runnable = new Runnable()    {
        public void run()  {
        //    Toast.makeText(Menu_utama.this,"cek in runnable",Toast.LENGTH_SHORT).show();
            // addNotification();
            new load().execute();
            Menu_utama.this.mHandler.postDelayed(m_Runnable,5000);
        }
    };

    private void addNotification1() {
        Toast.makeText(Menu_utama.this,"Info "+PESAN,Toast.LENGTH_SHORT).show();
        NotificationCompat.Builder builder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_warning2)
                        .setContentTitle("WARNING, Ada Serangan ! ")
                        .setContentText(PESAN);

        Intent notificationIntent = new Intent(this, Notif.class);//eventList
        notificationIntent.putExtra("kategori", kategori);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(contentIntent);
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(0, builder.build());

    }


    private void addNotification2() {
        Toast.makeText(Menu_utama.this,"Info "+PESAN,Toast.LENGTH_SHORT).show();
        NotificationCompat.Builder builder =
                new NotificationCompat.Builder(this)
                        .setSmallIcon(R.drawable.ic_kontak)
                        .setContentTitle("SELAMAT, Syukurillah! ")
                        .setContentText(PESAN);

        Intent notificationIntent = new Intent(this, Notif.class);//eventList
        notificationIntent.putExtra("kategori", "Info ok");

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT);
        builder.setContentIntent(contentIntent);
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(0, builder.build());

    }


    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(0, 0, 0, "Logout");//.setIcon(R.drawable.ic_launcher_background);
//        menu.add(0, 1, 0, "Back");//.setIcon(R.drawable.ic_launcher);
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case 0:
             keluarYN();
                return true;

//            case 1:
//                finish();
//                return true;
        }
        return false;
    }

    public void keluar(){
        new AlertDialog.Builder(this)
                .setTitle("Menutup Aplikasi")
                .setMessage("Terimakasih... Anda Telah Menggunakan Aplikasi Ini")
                .setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dlg, int sumthin) {
                        finish();
                    }})
                .show();
    }
    public void keluarYN(){
        AlertDialog.Builder ad=new AlertDialog.Builder(Menu_utama.this);
        ad.setTitle("Konfirmasi");
        ad.setMessage("Apakah benar ingin keluar?");

        ad.setPositiveButton("OK",new DialogInterface.OnClickListener(){
            @Override
            public void onClick(DialogInterface dialog, int which) {
                keluar();
            }});

        ad.setNegativeButton("No",new DialogInterface.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);
    }

    class load extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }
        protected String doInBackground(String... args) {
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            JSONObject json = jParser.makeHttpRequest(ip+"cek.php", "GET", params);
            Log.d("show: ", json.toString());
            try {
                adabaru= json.getInt("sukses");
                if(adabaru==1){
                    JSONArray myObj = json.getJSONArray(TAG_record); // JSON Array
                    final JSONObject myJSON = myObj.getJSONObject(0);
                    runOnUiThread(new Runnable() {
                        public void run() {
                            try {
                                PESAN=myJSON.getString("PESAN");
                                kategori="TCP";
                                if(PESAN.indexOf("UDP")>=0){kategori="UDP";}
                                else if(PESAN.indexOf("ICMP")>=0){kategori="ICMP";}
                            }
                            catch (JSONException e) {e.printStackTrace();}
                        }});

                }

            }
            catch (JSONException e) {e.printStackTrace();}
            return null;
        }

        protected void onPostExecute(String file_url) {
            runOnUiThread(new Runnable() {
                public void run() {
                    //Log.v("BACA0", "CEK DATA.....BARU");
                    if (adabaru==1){
                        adabaru=0;
                        //Log.v("BACA", "ADA DATA.....BARU:"+PESAN);
                        if(PESAN.indexOf("Aman")>0) {
                            addNotification2();

                            MediaPlayer mp = MediaPlayer.create(Menu_utama.this, R.raw.notif);
                            if(!mp.isPlaying()) {
                                mp.start();
                                //mp.setLooping(true);
                            }
                        }
                        else{
                            addNotification1();

                            MediaPlayer mp = MediaPlayer.create(Menu_utama.this, R.raw.notif);
                            if(!mp.isPlaying()) {
                                mp.start();
                                //mp.setLooping(true);
                            }
                        }

                        Toast.makeText(Menu_utama.this,"Ada Data Baru="+PESAN,Toast.LENGTH_SHORT).show();
                    }

                }
            });}
    }

//
//    public void createNotification(View view) {
//        // Prepare intent which is triggered if the
//        // notification is selected
//        Intent intent = new Intent(this, Notif.class);
//        PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
//
//        // Build notification
//        // Actions are just fake
//        Notification noti = new Notification.Builder(this)
//                .setContentTitle("New mail from " + "test@gmail.com")
//                .setContentText("Subject").setSmallIcon(R.drawable.ic_grafik)
//                .setContentIntent(pIntent)
//                .addAction(R.drawable.icon, "Call", pIntent)
//                .addAction(R.drawable.icon, "More", pIntent)
//                .addAction(R.drawable.icon, "And more", pIntent).build();
//        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//        // hide the notification after its selected
//        noti.flags |= Notification.FLAG_AUTO_CANCEL;
//
//        notificationManager.notify(0, noti);
//
//    }
}
+++++++++++++++++++++++++

cek.php

<?php

require_once"koneksivar.php";

mysql_connect($DBServer, $DBUser, $DBPass);
mysql_select_db($DBName);


$respon = array();


 $sql="select * from `tb_temp` order by `id` desc";
    $q=mysql_query($sql);
    $jum=mysql_num_rows($q);
if($jum > 0){
        $respon["record"] = array(); 
$d=mysql_fetch_array($q);
//Full texts id name date time ip_src ip_dst action note
$sid=$d["id"];
$cid=$d["name"];
$signature=$d["date"];
$sig_name=$d["note"];

$ip_src=$d["ip_src"];
$ip_dst=$d["ip_dst"];
$ip_proto=$d["action"];

$timestamp=$d["date"] ." ". $d["time"];


$ss="select * from tb_temp2";
$qq=mysql_query($ss);
$ds=mysql_fetch_array($qq);
$waktu=$ds["waktu"];

if($waktu==$timestamp){
    $sql="select * from `tb_temp3`";
    $q=mysql_query($sql);
    $jum=mysql_num_rows($q);
if($jum > 0){
        $respon["record"] = array(); 
      $record = array();
        $record["PESAN"] = "Kondisi Aman terjaga....";   
        array_push($respon["record"], $record); 

    $respon["sukses"] = 1;
$respon["pesan"] = "$jum record";
    echo json_encode($respon);
$qq=mysql_query("truncate  tb_temp3");
}
else{

    $respon["record"]="";
    $respon["sukses"] = 0;
    $respon["pesan"] = "0 record";
    echo json_encode($respon);
}
}
else{

      $record = array();
        $record["PESAN"] = "Ada serangan masuk ".$sig_name." dari IP: ".$ip_src;   
        array_push($respon["record"], $record); 

    $respon["sukses"] = 1;
$respon["pesan"] = "$jum record";
    echo json_encode($respon);
$qq=mysql_query("update tb_temp2 set waktu='$timestamp'");
}
}
else {

    $sql="select * from `tb_temp3`";
    $q=mysql_query($sql);
    $jum=mysql_num_rows($q);
if($jum > 0){
        $respon["record"] = array(); 
      $record = array();
        $record["PESAN"] = "Kondisi Aman terjaga....";   
        array_push($respon["record"], $record); 

    $respon["sukses"] = 1;
$respon["pesan"] = "$jum record";
    echo json_encode($respon);
$qq=mysql_query("truncate  tb_temp3");

}
else{
    $respon["record"]="";
    $respon["sukses"] = 0;
    $respon["pesan"] = "0 pesan";
    echo json_encode($respon);
}
}
?>


<?php

function getJum($conn,$sql){
  $rs=$conn->query($sql);
  $jum= $rs->num_rows;
$rs->free();
return $jum;
}

function getData($conn,$sql){
$rs=$conn->query($sql);
$rs->data_seek(0);
$arr = $rs->fetch_all(MYSQLI_ASSOC);
$rs->free();
return $arr;
}
?>