Minggu, 19 Mei 2019

Navigationdrawer



FIRST

public class Login extends Activity {


session.createLoginSession(id_warga,nama_warga,jabatan);
Intent i = new Intent(getApplicationContext(),MainActivity.class);
i.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();


}


Pada class createLoginSession

public void createLoginSession(String skode1, String skode2, String skode3){
    editor.putBoolean(IS_LOGIN, true);
    editor.putString(KEY_P1, skode1);
    editor.putString(KEY_P2, skode2);
    editor.putString(KEY_P3, skode3);
    editor.commit();
}


public void checkLogin(){
    if(!this.isLoggedIn()){
        Intent i = new Intent(_context, Loginas.class);
        i.addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP);
        i.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK);
        _context.startActivity(i);
    }

}

public HashMap<String, String> getUserDetails(){
    HashMap<String, String> user = new HashMap<String, String>();
    user.put(KEY_P1, pref.getString(KEY_P1, null));
    user.put(KEY_P2, pref.getString(KEY_P2, null));
    user.put(KEY_P3, pref.getString(KEY_P3, null));

    return user;
}
++++++++++++++++++++++++++++++++

class MainActivity 
public class MainActivity extends AppCompatActivity implements NavMenuAdapter.MenuItemClickListener{
    SessionManager session;
    String P1,P2,P3;
    @Override    
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);

       session = new SessionManager(getApplicationContext());
       session.checkLogin();

        session.getUserDetails();
        HashMap map=session.getUserDetails();

        Set keys = map.keySet();
        Iterator itr = keys.iterator();

        while(itr.hasNext()) {
            String key = (String) itr.next();
            if (key.equals("P1")) {
                P1 =(String)map.get(key);//id_warga
            }
            else if (key.equals("P2")) {
                P2 =(String)map.get(key);//nama_warga
            }
            else if (key.equals("P3")) {
                P3 =(String)map.get(key);//jabatan
            }
        }
        Log.v("PI23",P1+"#"+P2+"#"+P3);




}


@Overridepublic void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.main_layout);
    if (drawer.isDrawerOpen( GravityCompat.START)) {
        drawer.closeDrawer( GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}

public boolean onKeyDown(int keyCode, KeyEvent event) {  
    if (keyCode == KeyEvent.KEYCODE_BACK) {

        BerandaFragment beranda= new BerandaFragment();
        this.getSupportFragmentManager().beginTransaction()
                .replace(R.id.main_content, beranda.newInstance(""))
                .addToBackStack(null)
                .commit();

        return true;
    }
    return super.onKeyDown(keyCode, event);
}

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(MainActivity.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();
}
++++++++++++++++++++++++++++

btnComment.setOnClickListener(new View.OnClickListener() {
    @Override    public void onClick(View arg0) {
        //new del().execute();        //getActivity().onBackPressed();
        Add_comen add_comen= new  Add_comen();
        getActivity().getSupportFragmentManager().beginTransaction()
                .replace(R.id.main_content, add_comen.newInstance(id_laporan))
                .addToBackStack(null)
                .commit();

    }});
+++++++++++++++++++++++++++++



Tidak ada komentar:

Posting Komentar