Minggu, 14 Juli 2019

Tablelayout



<TableLayout android:id="@+id/TableLayout01"    android:layout_gravity="center"    android:layout_width="wrap_content"    android:layout_marginTop="10dip"    android:layout_height="fill_parent"    xmlns:android="http://schemas.android.com/apk/res/android"    android:background="#fff">


    <TableRow        android:id="@+id/TableRow00"        android:layout_width="wrap_content"        android:layout_height="wrap_content">

        <Button            android:id="@+id/btnTambah"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="@color/yello"            android:text="Tambah Chef"            android:textColor="#ffffff"            android:textStyle="bold" />


        <Button            android:id="@+id/btnproses"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="@color/yello"            android:textColor="#ffffff"            android:layout_marginLeft="5dip"            android:textStyle="bold"            android:text="PROSES SMART" />

        <Button            android:id="@+id/btnhapus"            android:layout_marginLeft="5dip"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:background="@color/yello"            android:text="RESET DATA"            android:textColor="#ffffff"            android:textStyle="bold" />
</TableRow>
</TableLayout>
++++++++++++++++++++++++++++++




<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#000"    android:orientation="vertical"    android:stretchColumns="1">
    <ImageView        android:id="@+id/myGambar"        android:layout_width="220px"        android:layout_height="220px"        android:layout_gravity="center_horizontal"        android:src="@drawable/c" />
    <TableRow android:padding="5dip">

        <TextView            android:layout_height="wrap_content"            android:layout_marginBottom="20dp"            android:layout_span="2"            android:gravity="center_horizontal"            android:text="Otentikasi Data"            android:textColor="#0ff"            android:textSize="25sp"            android:textStyle="bold" />
    </TableRow>

    <TableRow>

        <TextView            android:layout_height="wrap_content"            android:layout_column="0"            android:layout_marginLeft="10dp"            android:text="Username"            android:textColor="#fff"            android:textSize="16sp" />

        <EditText            android:id="@+id/txtusername"            android:layout_height="wrap_content"            android:layout_column="1"            android:layout_marginLeft="10dp"            android:background="#fff"            android:hint="Username"            android:padding="5dp"            android:textColor="#000" />
    </TableRow>

    <TableRow>

        <TextView            android:layout_height="wrap_content"            android:layout_column="0"            android:layout_marginLeft="10dp"            android:layout_marginTop="20dp"            android:text="Password"            android:textColor="#fff"            android:textSize="16sp" />

        <EditText            android:id="@+id/txtpassword"            android:layout_height="wrap_content"            android:layout_column="1"            android:layout_marginLeft="10dp"            android:layout_marginTop="20dp"            android:background="#fff"            android:hint="Password"            android:padding="5dp"            android:textColor="#000" />
    </TableRow>


    <TableRow android:layout_marginTop="20dp">

        <Button            android:id="@+id/btnbatal"            android:layout_height="wrap_content"            android:background="#0ff"            android:text="BATAL"            android:textColor="#000"            android:textSize="20sp"            android:textStyle="bold" />

        <Button            android:layout_marginLeft="10dp"            android:id="@+id/btnlogin"            android:layout_height="wrap_content"            android:background="#0ff"            android:text="LOGIN NOW"            android:textColor="#000"            android:textSize="20sp"            android:textStyle="bold" />



    </TableRow>
</TableLayout>

Sabtu, 13 Juli 2019

RadioGroup Data






<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="@drawable/bg"  >

    <LinearLayout        xmlns:android="http://schemas.android.com/apk/res/android"        xmlns:app="http://schemas.android.com/apk/res-auto"        xmlns:tools="http://schemas.android.com/tools"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical"        android:padding="10dip" >
        <!--  View Title Label -->        <TextView            android:id="@+id/txtMarquee"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text=""            android:textSize="14sp"            android:typeface="sans"            android:textColor="#ffffff"            android:background="#000000"            android:singleLine="true"            android:ellipsize="marquee"            android:marqueeRepeatLimit="marquee_forever">
        </TextView>


        <ImageView            android:id="@+id/myGambar"            android:layout_width="fill_parent"            android:layout_height="220px"            android:layout_gravity="center_horizontal"            android:src="@drawable/c" />

    <LinearLayout        android:background="@color/white"        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical"        android:padding="10dip" >
        <!--  Name Label -->
        <TextView            android:id="@+id/txtid_pengujian0"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="ID Pengujian"            android:textColor="#000000"            android:textSize="20sp"            android:textStyle="bold"/>

        <!--  telepon TextField -->        <EditText            android:id="@+id/txtid_pengujian"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:textColor="#000000" />
        <TextView            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="Nama Chef"            android:textColor="#000000"            android:textSize="20sp"            android:textStyle="bold"/>

        <Spinner android:id="@+id/spin" android:drawSelectorOnTop="true" android:layout_width="wrap_content" android:layout_height="wrap_content" />
        <!--  telepon Label -->        <TextView            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="Jarak"            android:textColor="#000000"            android:textSize="20sp"            android:textStyle="bold"/>

        <RadioGroup android:id="@+id/radA"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:orientation="vertical">
            <RadioButton android:id="@+id/radA1"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Dekat"                android:checked="true" />
            <RadioButton android:id="@+id/radA2"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Sedang" />
            <RadioButton android:id="@+id/radA3"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Jauh" />
            <RadioButton android:id="@+id/radA4"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Sangat Jauh" />

        </RadioGroup>



        <TextView            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="Skill"            android:textColor="#000000"            android:textSize="20sp"            android:textStyle="bold"/>

        <RadioGroup android:id="@+id/radB"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:orientation="vertical">
            <RadioButton android:id="@+id/radB1"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Sangat Handal"                android:checked="true" />
            <RadioButton android:id="@+id/radB2"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Handal" />
            <RadioButton android:id="@+id/radB3"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Cukup Handal" />
            <RadioButton android:id="@+id/radB4"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Kurang Handal" />

        </RadioGroup>

        <TextView            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="Paket"            android:textColor="#000000"            android:textSize="20sp"            android:textStyle="bold"/>
        <RadioGroup android:id="@+id/radC"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:orientation="vertical">
            <RadioButton android:id="@+id/radC1"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Paket Kilat"                android:checked="true" />
            <RadioButton android:id="@+id/radC2"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Paket Praktek" />
            <RadioButton android:id="@+id/radC3"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Paket sampai bisa" />

        </RadioGroup>

            <TextView            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="Pengalaman"            android:textColor="#000000"            android:textSize="20sp"            android:textStyle="bold"/>

        <RadioGroup android:id="@+id/radD"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:orientation="vertical">
            <RadioButton android:id="@+id/radD1"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Sudah Lama"                android:checked="true" />
            <RadioButton android:id="@+id/radD2"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Lama" />
            <RadioButton android:id="@+id/radD3"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Cukup Lama" />
            <RadioButton android:id="@+id/radD4"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Baru" />

        </RadioGroup>

            <TextView            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="Tempat Usaha"            android:textColor="#000000"            android:textSize="20sp"            android:textStyle="bold"/>

        <RadioGroup android:id="@+id/radE"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:orientation="vertical">
            <RadioButton android:id="@+id/radE1"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Sangat Besar"                android:checked="true" />
            <RadioButton android:id="@+id/radE2"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Besar" />
            <RadioButton android:id="@+id/radE3"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Cukup Besar" />
            <RadioButton android:id="@+id/radE4"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="Kecil" />

        </RadioGroup>

            <TextView            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:text="Catatan"            android:textColor="#000000"            android:textSize="20sp"            android:textStyle="bold"/>

        <!--  telepon TextField -->        <EditText            android:id="@+id/txtcatatan"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:textColor="#000000" />



        <!--  Link to Login Screen -->        <Button            android:id="@+id/btnproses"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_marginTop="40dip"            android:textColor="#ffffff"            android:background="@color/yello"            android:textStyle="bold"            android:text="Pilih" />

        <Button            android:id="@+id/btnhapus"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_marginTop="10dip"            android:text="Simpan"            android:textColor="#ffffff"            android:background="@color/yello"            android:textStyle="bold" />

    </LinearLayout>
    </LinearLayout>

</ScrollView>


++++

package com.example.win10.cooking;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

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

public class cDetailADD extends Activity {
   String ip="",id="",nama="";
   String id_pengujian;
   String id_detail;
   String id_detail0="";

   EditText txtid_pengujian;
   TextView txtid_pengujian0;

   Spinner txtid_chef;
   RadioGroup txtc1;
   RadioGroup txtc2;
   RadioGroup txtc3;
   RadioGroup txtc4;
   RadioGroup txtc5;
   EditText txtcatatan;

String[]arID;
   String[]arNama;
int jd=0;

   Button btnProses;
   Button btnHapus;
   JSONParser jParser = new JSONParser();
   JSONArray myJSON = null;
   private ProgressDialog pDialog;
   JSONParser jsonParser = new JSONParser();

   private static final String TAG_SUKSES = "sukses";
   private static final String TAG_record = "record";

   private static final String TAG_id_pengujian = "id_pengujian";
   private static final String TAG_id_chef = "id_chef";
   private static final String TAG_c1 = "c1";
   private static final String TAG_c2 = "c2";
   private static final String TAG_c3 = "c3";
   private static final String TAG_c4 = "c4";
   private static final String TAG_c5 = "c5";
   private static final String TAG_catatan = "catatan";

   @Override   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.cdetailadd);


      SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(cDetailADD.this);
      Boolean Registered = sharedPref.getBoolean("Registered", false);
      if (!Registered) {
         //finish();      } else {
         id = sharedPref.getString("id", "");
         nama= sharedPref.getString("nama", "");
         id_pengujian= sharedPref.getString("id_pengujian", "");
      }

      ip=jsonParser.getIP();
      callMarquee();
      txtid_pengujian0= (TextView) findViewById(R.id.txtid_pengujian0);
      txtid_pengujian= (EditText) findViewById(R.id.txtid_pengujian);
      txtid_chef= (Spinner) findViewById(R.id.spin);
      txtc1= (RadioGroup) findViewById(R.id.radA);
      txtc2 = (RadioGroup) findViewById(R.id.radB);
      txtc3= (RadioGroup) findViewById(R.id.radC);
      txtc4= (RadioGroup) findViewById(R.id.radD);
      txtc5 = (RadioGroup) findViewById(R.id.radE);
      txtcatatan= (EditText) findViewById(R.id.txtcatatan);

      btnProses= (Button) findViewById(R.id.btnproses);
      btnHapus = (Button) findViewById(R.id.btnhapus);


      Intent i = getIntent();
      id_detail0 = i.getStringExtra("pk");id_detail=id_detail0;
      id_pengujian = i.getStringExtra("id_pengujian");

      if(id_pengujian.length()<3){
         txtid_pengujian0.setVisibility(View.GONE);
         txtid_pengujian.setVisibility(View.GONE);
      }
      else{
         txtid_pengujian0.setVisibility(View.VISIBLE);
         txtid_pengujian.setVisibility(View.VISIBLE);
         txtid_pengujian0.setText("IDPengujian");
         txtid_pengujian.setText(id_pengujian);
      }


      btnProses.setOnClickListener(new View.OnClickListener() {
         @Override         public void onClick(View arg0) {
            int pilA= txtc1.getCheckedRadioButtonId();
            RadioButton rA = (RadioButton) findViewById(txtc1.getCheckedRadioButtonId());
              String c1=rA.getText().toString();

            RadioButton rB= (RadioButton) findViewById(txtc2.getCheckedRadioButtonId());
            String c2=rB.getText().toString();

            RadioButton rC = (RadioButton) findViewById(txtc3.getCheckedRadioButtonId());
            String c3=rC.getText().toString();

            RadioButton rD = (RadioButton) findViewById(txtc4.getCheckedRadioButtonId());
            String c4=rD.getText().toString();

            RadioButton rE = (RadioButton) findViewById(txtc5.getCheckedRadioButtonId());
            String c5=rE.getText().toString();

            String lid_chef= txtid_chef.getSelectedItem().toString();
         if(lid_chef.length()<1){lengkapi("CHEF");}
            else if(c1.length()<1){lengkapi("Jarak");}
            else if(c2.length()<1){lengkapi("Skill");}
            else if(c3.length()<1){lengkapi("Paket");}
            else if(c4.length()<1){lengkapi("Pengalaman");}
            else if(c5.length()<1){lengkapi("Tempat Usaha");}
            else{
            new save().execute();
            }//else
         }});

      btnHapus.setText("Kembali");
      btnHapus.setOnClickListener(new View.OnClickListener() {
         @Override         public void onClick(View arg0) {
            finish();
            //new del().execute();         }});

        new getchef().execute();
   }

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



   class getchef extends AsyncTask<String, String, String> {
      @Override      protected void onPreExecute() {
         super.onPreExecute();
         pDialog = new ProgressDialog(cDetailADD.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+"chef/chef_show.php", "GET", params);
         Log.d("show: ", json.toString());
         try {
            int sukses = json.getInt(TAG_SUKSES);
//          id_pengujian = json.getString("id_pengujian");            if (sukses == 1) {
               myJSON = json.getJSONArray(TAG_record);

               jd=myJSON.length();
               arID=new String[jd];
               arNama=new String[jd];

               for (int i = 0; i < jd; i++) {
                  JSONObject c = myJSON.getJSONObject(i);
                  String id_chef= c.getString(TAG_id_chef);
                  String nama_chef = c.getString("nama_chef");
                  arID[i]=id_chef;
                  arNama[i]=nama_chef;

               }
            } else {
               // Toast.makeText(ChefList.this,"Data Tidak Tersedia",Toast.LENGTH_LONG);            }
         }
         catch (JSONException e) {e.printStackTrace();}
         return null;
      }

      protected void onPostExecute(String file_url) {
         pDialog.dismiss();
         runOnUiThread(new Runnable() {
            public void run() {

   tambahkan();
//             ArrayAdapter<String> adapter = new ArrayAdapter<String>(cDetailADD.this,android.R.layout.simple_spinner_item, arNama);//             txtid_chef.setAdapter(adapter);
            }
         });}
   }


void tambahkan(){
   final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(cDetailADD.this);
   SharedPreferences.Editor editor = sharedPref.edit();
   editor.putString("id_pengujian", id_pengujian);
   editor.apply();

   ArrayAdapter<String> adapter = new ArrayAdapter<String>(cDetailADD.this,android.R.layout.simple_spinner_item, arNama);
   txtid_chef.setAdapter(adapter);

}


   class save extends AsyncTask<String, String, String> {
      @Override      protected void onPreExecute() {
         super.onPreExecute();
         pDialog = new ProgressDialog(cDetailADD.this);
         pDialog.setMessage("Menyimpan data ...");
         pDialog.setIndeterminate(false);
         pDialog.setCancelable(true);
         pDialog.show();
      }
      protected String doInBackground(String... args) {
         String catatan=txtcatatan.getText().toString();
         int pilA= txtc1.getCheckedRadioButtonId();
         RadioButton rA = (RadioButton) findViewById(txtc1.getCheckedRadioButtonId());
         String c1=rA.getText().toString();

         RadioButton rB= (RadioButton) findViewById(txtc2.getCheckedRadioButtonId());
         String c2=rB.getText().toString();

         RadioButton rC = (RadioButton) findViewById(txtc3.getCheckedRadioButtonId());
         String c3=rC.getText().toString();

         RadioButton rD = (RadioButton) findViewById(txtc4.getCheckedRadioButtonId());
         String c4=rD.getText().toString();

         RadioButton rE = (RadioButton) findViewById(txtc5.getCheckedRadioButtonId());
         String c5=rE.getText().toString();

         String lid_chef= txtid_chef.getSelectedItem().toString();


         List<NameValuePair> params = new ArrayList<NameValuePair>();
         params.add(new BasicNameValuePair("id_pengujian", id_pengujian));
         params.add(new BasicNameValuePair("id_chef", lid_chef));
         params.add(new BasicNameValuePair("id", id));
         params.add(new BasicNameValuePair("c1", c1));
         params.add(new BasicNameValuePair("c2", c2));
         params.add(new BasicNameValuePair("c3", c3));
         params.add(new BasicNameValuePair("c4", c4));
         params.add(new BasicNameValuePair("c5", c5));
         params.add(new BasicNameValuePair("catatan", catatan));

         String url=ip+"detail/detail_add.php";
         Log.v("ADD",url+"?id_pengujian="+id_pengujian+"&id="+id+"&id_chef="+lid_chef+"&c1="+c1+"&c2="+c2+"&c3="+c3+"&c4="+c4+"&c5="+c5+"&catatan="+catatan);
         JSONObject json = jsonParser.makeHttpRequest(url,"POST", params);
         Log.d("add", json.toString());
         try {
            int sukses = json.getInt(TAG_SUKSES);
            if (sukses == 1) {
               id_pengujian= json.getString("id_pengujian");
            } else {
               // gagal update data            }
         } catch (JSONException e) {
            e.printStackTrace();
         }
         return null;
      }

      protected void onPostExecute(String file_url) {pDialog.dismiss();


         final SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(cDetailADD.this);
         SharedPreferences.Editor editor = sharedPref.edit();
         editor.putString("id_pengujian", id_pengujian);
         editor.apply();



         String lid_chef= txtid_chef.getSelectedItem().toString();
         sukses(lid_chef);
      }
   }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++   
   public void lengkapi(String item){
      new AlertDialog.Builder(this)
            .setTitle("Lengkapi Data")
            .setMessage("Silakan lengkapi data "+item +" !")
            .setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dlg, int sumthin) {
                  finish();
               }}).show();
   }

   public void sukses(String item){
      new AlertDialog.Builder(this)
            .setTitle("Pemilihan Chef Berhasil")
            .setMessage("Terimakasih Anda telah memilih "+item +" pada "+id_pengujian)
            .setNeutralButton("Tutup", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dlg, int sumthin) {
                  finish();
               }}).show();
   }

   void callMarquee(){
      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);

      TextView  txtMarquee=(TextView)findViewById(R.id.txtMarquee);
      txtMarquee.setSelected(true);
      String kata="Selamat Datang di Aplikasi Android LP2MARAY  "+stgl+"/"+sjam+" #";
      String kalimat=String.format("%1$s",TextUtils.htmlEncode(kata));
      txtMarquee.setText(Html.fromHtml(kalimat+kalimat+kalimat));
   }

   public boolean onKeyDown(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK) {
         finish();
         return true;
      }
      return super.onKeyDown(keyCode, event);
   }

}