Advertisement
sandi_s

MainActivity.java

Feb 17th, 2018
1,453
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.99 KB | None | 0 0
  1. package lokadin.sandy.example.com.lokadin;
  2. import android.app.AlertDialog;
  3. import android.content.DialogInterface;
  4. import android.content.Intent;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.os.Bundle;
  7. import android.view.Menu;
  8. import android.view.MenuItem;
  9. import android.view.View;
  10. import android.widget.Toast;
  11. public class MainActivity extends AppCompatActivity {
  12.     boolean isKonek = false;
  13.     Pendeteksi_koneksi pk;
  14.     @Override
  15.     protected void onCreate(Bundle savedInstanceState) {
  16.         super.onCreate(savedInstanceState);
  17.         setContentView(R.layout.activity_main);
  18.         pk = new Pendeteksi_koneksi(getApplicationContext());
  19.         isKonek = pk.isConnectingToInternet();
  20.         if (isKonek){
  21.             Toast.makeText(this, "terhubung ke internet", Toast.LENGTH_SHORT).show();
  22.         }else{
  23.             Toast.makeText(this, "tidak ada koneksi internet", Toast.LENGTH_SHORT).show();
  24.             //this.finish();
  25.         }
  26.     }
  27.     public void klikTombolMenu(View v){
  28.         Intent intent;
  29.         switch (v.getId()) {
  30.             case R.id.tombolmaps:
  31.                 intent = new Intent (this, MapsActifity.class);
  32.                 startActivity(intent);
  33.                 break;
  34.             case R.id.tombolhome:
  35.                 intent = new Intent(this,HomeItem.class);
  36.                 startActivity(intent);
  37.                 break;
  38.             case R.id.tombolabout:
  39.                 intent = new Intent(this,AboutActivitfty.class);
  40.                 startActivity(intent);
  41.                 break;
  42.             case R.id.tombolversi:
  43.                 intent = new Intent(this, VersiFragment.class);
  44.                 startActivity(intent);
  45.                 break;
  46.         }
  47.     }
  48.     @Override
  49.     public boolean onOptionsItemSelected(MenuItem item) {
  50.         // Handle action bar item clicks here. The action bar will
  51.         // automatically handle clicks on the Home/Up button, so long
  52.         // as you specify a parent activity in AndroidManifest.xml.
  53.         int id = item.getItemId();
  54.         //noinspection SimplifiableIfStatement
  55.         if (id == R.id.action_settings) {
  56.             android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(this);
  57.             builder.setMessage("Anda yakin keluar dari Aplikasi?")
  58.                     .setCancelable(false).setPositiveButton("Ya",
  59.                     new DialogInterface.OnClickListener() {
  60.                         public void onClick(DialogInterface dialog, int id) {
  61.                             MainActivity.this.finish();
  62.                         }
  63.                     }).setNegativeButton("Tidak",
  64.                     new DialogInterface.OnClickListener() {
  65.                         public void onClick(DialogInterface dialog, int id) {
  66.                             dialog.cancel();
  67.                         }
  68.                     }).show();
  69.         }
  70.         return super.onOptionsItemSelected(item);
  71.     }
  72.     @Override
  73.     public void onBackPressed() {
  74.         // TODO Auto-generated method stub
  75.         AlertDialog.Builder dialog = new AlertDialog.Builder(this);
  76.         dialog.setMessage("apakah anda yakin ingin keluar")
  77.                 .setCancelable(false);
  78.         dialog.setPositiveButton("Ya", new DialogInterface.OnClickListener() {
  79.             public void onClick(DialogInterface arg0, int arg1) {
  80.                 // TODO Auto-generated method stub
  81.                 MainActivity.this.finish();
  82.             }
  83.         });
  84.         dialog.setNegativeButton("Tidak",
  85.                 new DialogInterface.OnClickListener() {
  86.  
  87.                     public void onClick(DialogInterface arg0, int arg1) {
  88.                         arg0.cancel();
  89.                     }
  90.                 });
  91.         dialog.show();
  92.     }
  93.     @Override
  94.     public boolean onCreateOptionsMenu(Menu menu) {
  95.         // Inflate the menu; this adds items to the action bar if it is present.
  96.         getMenuInflater().inflate(R.menu.activity_main, menu);
  97.         return true;
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement