Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.japati14.ngabsensecurityguaindividual;
- import android.Manifest;
- import android.app.Activity;
- import android.app.AlertDialog;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.content.pm.PackageManager;
- import android.graphics.Bitmap;
- import android.graphics.BitmapFactory;
- import android.net.Uri;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.os.Environment;
- import android.os.StrictMode;
- import android.text.Spannable;
- import android.text.SpannableString;
- import android.util.Log;
- import android.view.MenuItem;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.ArrayAdapter;
- import android.widget.AutoCompleteTextView;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.Toast;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.core.content.ContextCompat;
- import com.android.volley.AuthFailureError;
- import com.android.volley.DefaultRetryPolicy;
- import com.android.volley.Request;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import com.android.volley.VolleyLog;
- import com.android.volley.toolbox.JsonArrayRequest;
- import com.android.volley.toolbox.StringRequest;
- import com.japati14.ngabsensecurityguaindividual.app.AppController;
- import com.japati14.ngabsensecurityguaindividual.data.DataKategoriLaporan;
- import com.japati14.ngabsensecurityguaindividual.data.DataLaporanKLB;
- import com.japati14.ngabsensecurityguaindividual.util.AlertDialogMsg;
- import com.japati14.ngabsensecurityguaindividual.util.RequestPermissionHandler;
- import com.japati14.ngabsensecurityguaindividual.util.Server;
- import com.japati14.ngabsensecurityguaindividual.util.TypefaceSpan;
- import com.kosalgeek.android.photoutil.GalleryPhoto;
- import com.kosalgeek.android.photoutil.ImageBase64;
- import com.kosalgeek.android.photoutil.PhotoLoader;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Locale;
- import java.util.Map;
- import static com.japati14.ngabsensecurityguaindividual.util.Constants.EXTRA_ITEM;
- import static com.japati14.ngabsensecurityguaindividual.util.Constants.TIME_OUT_POST;
- public class LaporanKLB extends AppCompatActivity {
- public static final String mypreference = "mypref";
- SharedPreferences sharedpreferences;
- AlertDialogMsg msg = new AlertDialogMsg();
- private static String url_insert_laporan = Server.URL + "insertLaporanKLB.php";
- private static String url_upload_image = Server.URL + "uploadImage.php";
- private static final String TAG = LaporanKLB.class.getSimpleName();
- String laporanContent,laporanTitle,store_id,path,KategoriLaporanId;
- String Ilaporan_id,Ilaporan_title,Ilaporan_content,Ilaporan_date_created,staf_no,stafPelapor;
- EditText txtLaporanContent,txtLaporanTitle,etStafName,etLaporanDate;
- GalleryPhoto galleryPhoto;
- Uri fileUri;
- final int GALLERY_REQUEST = 1200;
- public final int REQUEST_CAMERA = 0;
- Intent intent;
- LinearLayout linearMain;
- Bitmap bitmap;
- ArrayList<String> imageList = new ArrayList<>();
- ArrayList<String> imageRemove = new ArrayList<>();
- final CharSequence[] items = {"Remove","Cancel"};
- private Button ivGallery;
- private static String URLImage = Server.URL_IMAGE;
- private RequestPermissionHandler mRequestPermissionHandler;
- ArrayList<String> listKategoriLaporan = new ArrayList<String>();
- List<DataKategoriLaporan> dataKategoriLaporan = new ArrayList<>();
- AutoCompleteTextView acKategoriLaporan;
- class GetData extends AsyncTask<String, Void, String> {
- Bitmap bitmap;
- ImageView image = new ImageView(LaporanKLB.this);
- @Override
- protected void onPreExecute() {
- };
- @Override
- protected String doInBackground(String... params) {
- String ImageString = params[0];
- try {
- URL url = new URL(URLImage+ImageString);
- bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
- }catch (MalformedURLException e1) {
- e1.printStackTrace();
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- String imgv = (ImageString.equals("")) ? "null": ImageString;
- return imgv;
- }
- @Override
- protected void onPostExecute(final String result) {
- super.onPostExecute(result);
- final String imageString = result;
- if(!imageString.equals("null")){
- LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
- layoutParams.setMargins(0, 0, 0, 50);
- image.setLayoutParams(layoutParams);
- image.setScaleType(ImageView.ScaleType.FIT_CENTER);
- image.setPadding(10, 10, 10, 10);
- image.setAdjustViewBounds(true);
- image.setBackgroundResource(R.drawable.border_image);
- image.setImageBitmap(bitmap);
- path = URLImage+imageString;
- imageList.add(path);
- linearMain.addView(image);
- Log.e(TAG,"Path : "+path);
- }
- }
- }
- public void getGambarLaporan(String laporan_id){
- String UrlGetGambarLaporan= Server.URL+"getGambarLaporan.php&laporan_id="+laporan_id;
- Log.e(TAG,UrlGetGambarLaporan);
- // membuat request JSON
- JsonArrayRequest jArr = new JsonArrayRequest(UrlGetGambarLaporan, new Response.Listener<JSONArray>() {
- @Override
- public void onResponse(JSONArray response) {
- Log.d(TAG, response.toString());
- if(response.length()<1){
- msg.messageDialog( LaporanKLB.this, "Informasi","Tidak ada gambar", "OK",null, null, null);
- //Log.e(TAG,response.length()+" tidak ada gmbar");
- }else{
- // Parsing json
- for (int i = 0; i < response.length(); i++) {
- try {
- JSONObject obj = response.getJSONObject(i);
- new GetData().execute(obj.getString("img_name"));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- //VolleyLog.d(TAG, "Error: " + error.getMessage());
- Log.e(TAG,error.getMessage());
- msg.messageDialog( LaporanKLB.this, "Informasi","Check your connecton to server", "OK",null, null, null);
- }
- });
- // menambah request ke request queue
- AppController.getInstance().addToRequestQueue(jArr);
- }
- public boolean onOptionsItemSelected(MenuItem item) {
- switch(item.getItemId()) {
- case android.R.id.home:
- finish();
- return true;
- }
- return(super.onOptionsItemSelected(item));
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_laporan_klb);
- SpannableString s = new SpannableString("Ngabsen");
- s.setSpan(new TypefaceSpan(this, "Handycheera.otf"), 0, s.length(),
- Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- androidx.appcompat.app.ActionBar actionBar = getSupportActionBar();
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- getSupportActionBar().setDisplayUseLogoEnabled(true);
- actionBar.setTitle(s);
- sharedpreferences = getSharedPreferences(mypreference, Context.MODE_PRIVATE);
- store_id= sharedpreferences.getString("store_id", "");
- txtLaporanContent = (EditText) findViewById(R.id.txtLaporanContent);
- txtLaporanTitle = (EditText) findViewById(R.id.txtLaporanTitle);
- etStafName = findViewById(R.id.et_staf_name);
- etLaporanDate = findViewById(R.id.et_laporan_date);
- acKategoriLaporan = findViewById(R.id.ac_kategori_laporan);
- Button btnKirim = (Button)findViewById(R.id.btnKirim);
- linearMain = (LinearLayout)findViewById(R.id.linearMain);
- galleryPhoto = new GalleryPhoto(getApplicationContext());
- getListKategoriLaporan();
- btnKirim.setOnClickListener(new Button.OnClickListener(){
- public void onClick(View v){
- sharedpreferences = getSharedPreferences(mypreference,Context.MODE_PRIVATE);
- staf_no = sharedpreferences.getString("staf_no", "");
- KategoriLaporanId = dataKategoriLaporan.get(listKategoriLaporan.indexOf(acKategoriLaporan.getText().toString())).getKategori_klb_id();
- laporanContent = txtLaporanContent.getText().toString();
- laporanTitle = txtLaporanTitle.getText().toString();
- Log.e(TAG, "Laporan Content : " + laporanContent);
- if(laporanContent.equals("") || laporanTitle.equals("")){
- msg.messageDialog(LaporanKLB.this,"Informasi","Judul dan Isi tidak boleh kosong","OK", null, null, null);
- }else{
- Runnable ifTrue = new Runnable() {
- @Override
- public void run() {
- insertLaporan();
- }
- };
- msg.messageDialog(LaporanKLB.this,"Informasi","Anda yakin ingin mengirim laporan ini ?","Ya", "Tidak", ifTrue, null);
- }
- }
- });
- Button ivGallery = (Button) findViewById(R.id.ivGallery);
- ivGallery.setOnClickListener(new Button.OnClickListener() {
- @Override
- public void onClick(View v) {
- final CharSequence[] items = {"Take Photo", "Choose from Library",
- "Cancel"};
- if(imageList.size() >2){
- msg.messageDialog(LaporanKLB.this,"Informasi","Gambar yang boleh dilampirkan maksimal 3","OK", null, null, null);
- }else{
- android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(LaporanKLB.this);
- builder.setTitle("Add Photo");
- builder.setIcon(R.mipmap.ic_launcher);
- builder.setItems(items, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int item) {
- if (items[item].equals("Take Photo")) {
- callCamera();
- } else if (items[item].equals("Choose from Library")) {
- callGalerry();
- } else if (items[item].equals("Cancel")) {
- dialog.dismiss();
- }
- }
- });
- builder.show();
- }
- }
- });
- etStafName.setVisibility(View.GONE);
- etLaporanDate.setVisibility(View.GONE);
- DataLaporanKLB laporanKLB = getIntent().getParcelableExtra(EXTRA_ITEM);
- if(laporanKLB!=null){
- ivGallery.setVisibility(View.GONE);
- btnKirim.setVisibility(View.GONE);
- txtLaporanTitle.setText(laporanKLB.getLaporan_title());
- txtLaporanContent.setText(laporanKLB.getLaporan_content());
- etStafName.setText(laporanKLB.getStafName());
- etLaporanDate.setText(laporanKLB.getLaporan_date_created());
- getGambarLaporan(laporanKLB.getLaporan_id());
- txtLaporanTitle.setEnabled(false);
- txtLaporanContent.setEnabled(false);
- etStafName.setEnabled(false);
- etLaporanDate.setEnabled(false);
- etLaporanDate.setVisibility(View.VISIBLE);
- etStafName.setVisibility(View.VISIBLE);
- etLaporanDate.setVisibility(View.VISIBLE);
- }
- }
- public void insertLaporan(){
- final ProgressDialog progressDialog = new ProgressDialog(LaporanKLB.this, R.style.Theme_AppCompat_Light_Dialog);
- progressDialog.setIndeterminate(true);
- progressDialog.setMessage("Process ...");
- progressDialog.setCancelable(false);
- progressDialog.show();
- StringRequest strReq = new StringRequest(Request.Method.POST, url_insert_laporan, new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- //Log.d(TAG, "Response: " + response.toString());
- try {
- JSONObject jObj = new JSONObject(response);
- int success = jObj.getInt("success");
- Log.e("Response",response);
- // Cek error node pada json
- if (success == 1) {
- final String pesan = jObj.getString("message");
- final String laporan_id = jObj.getString("laporan_id");
- new android.os.Handler().postDelayed(
- new Runnable() {
- public void run() {
- uploadImage(laporan_id);
- Runnable ifTrue = new Runnable() {
- @Override
- public void run() {
- Intent data = new Intent(LaporanKLB.this, DaftarLaporanKLB.class);
- startActivity(data);
- }
- };
- msg.messageDialog(LaporanKLB.this,"Informasi",pesan,"OK", null, ifTrue, null);
- // onLoginFailed();
- progressDialog.dismiss();
- }
- }, 3000);
- } else {
- msg.messageDialog(LaporanKLB.this,"Informasi",jObj.getString("Message"),"OK",null, null, null);
- progressDialog.dismiss();
- }
- } catch (JSONException e) {
- // JSON error
- e.printStackTrace();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Log.e(TAG, "Error: " + error.getMessage());
- msg.messageDialog(LaporanKLB.this,"Informasi","Check your connecton to server "+error.getMessage(),"OK",null, null, null);
- progressDialog.dismiss();
- }
- }) {
- @Override
- protected Map<String, String> getParams() {
- // Posting parameters ke post url
- Map<String, String> params = new HashMap<String, String>();
- params.put("store_id", store_id);
- params.put("laporan_content", laporanContent);
- params.put("laporan_title", laporanTitle);
- params.put("staf_no", staf_no);
- return params;
- }
- };
- strReq.setRetryPolicy(new DefaultRetryPolicy(
- TIME_OUT_POST,
- DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
- DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
- );
- AppController.getInstance().addToRequestQueue(strReq,"json_obj_req");
- }
- public void showImageLog(){
- for(String imagePath: imageList){
- //Log.e(TAG,"List Array image : "+imagePath);
- }
- for(String remove: imageRemove){
- //Log.e(TAG,"List array Remove : "+String.valueOf(Integer.parseInt(remove)-1));
- }
- }
- public void cekarray(String bit,String index){
- //Log.e(TAG,"Bitmap Yang dihapus : "+bit);
- imageList.remove(bit);
- if(!index.equals("")){
- imageRemove.add(index);
- showImageLog();
- }
- }
- public void uploadImage(final String laporan_id){
- //Log.e(TAG,"detail_scoring_id : "+detail_scoring_id);
- for(String imagePath: imageList){
- if(imagePath.contains("http")){
- //Log.e(TAG,"from URL : "+no_urut);
- }else{
- //Log.e(TAG,"from Local : "+no_urut);
- actUploadImage(imagePath,laporan_id);
- }
- }
- }
- public void actUploadImage(String imagePath,final String laporan_id){
- try {
- final String fileName;
- bitmap = PhotoLoader.init().from(imagePath).requestSize(300, 300).getBitmap();
- bitmap = getResizedBitmap(bitmap ,500);
- File file = new File(imagePath);
- fileName = file.getName();
- //Log.e(TAG,"fromLocal : "+imagePath);
- //Log.e(TAG,String.valueOf(bitmap));
- final String encodedString = ImageBase64.encode(bitmap);
- //final String nama_file =detail_scoring_id+"_IMG_"+no_urut+".jpeg";
- //Log.e(TAG,"Nama File : "+fileName);
- StringRequest strReq = new StringRequest(Request.Method.POST, url_upload_image, new Response.Listener<String>() {
- @Override
- public void onResponse(String response) {
- //Toast.makeText(getApplicationContext(), response, Toast.LENGTH_SHORT).show();
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- //Toast.makeText(getApplicationContext(), "Error while uploading image", Toast.LENGTH_SHORT).show();
- }
- }){
- @Override
- protected Map<String, String> getParams() throws AuthFailureError {
- Map<String, String> params = new HashMap<>();
- //Log.e(TAG,"no urut : "+urut);
- params.put("image", encodedString);
- params.put("laporan_id",laporan_id);
- params.put("nama_file",fileName);
- return params;
- }
- };
- AppController.getInstance().addToRequestQueue(strReq, "json_obj_req");
- } catch (Exception e) {
- System.out.println(e.getMessage());
- Toast.makeText(getApplicationContext(), "Error while loading image", Toast.LENGTH_SHORT).show();
- }
- }
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (resultCode == Activity.RESULT_OK) {
- final ImageView imageView = new ImageView(getApplicationContext());
- LinearLayout.LayoutParams layoutParams =
- new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
- layoutParams.setMargins(0, 0, 0, 50);
- if (requestCode == GALLERY_REQUEST) {
- try {
- galleryPhoto.setPhotoUri(data.getData());
- final String photoPath = galleryPhoto.getPath();
- //Log.e(TAG,"Alamat Photo : "+photoPath);
- bitmap = PhotoLoader.init().from(photoPath).requestSize(512, 512).getBitmap();
- imageView.setLayoutParams(layoutParams);
- imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
- imageView.setPadding(10, 10, 10, 10);
- imageView.setAdjustViewBounds(true);
- imageView.setBackgroundResource(R.drawable.border_image);
- imageView.setImageBitmap(bitmap);
- linearMain.addView(imageView);
- if (imageRemove.size() < 1) {
- imageList.add(photoPath);
- } else {
- for (int i = 0; i < 1; i++) {
- //Log.e(TAG,"Set ke index : "+String.valueOf(Integer.parseInt(imageRemove.get(i))-1));
- imageList.add(Integer.parseInt(imageRemove.get(i)) - 1, photoPath);
- imageRemove.remove(i);
- }
- showImageLog();
- }
- imageView.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- AlertDialog.Builder builder = new AlertDialog.Builder(LaporanKLB.this);
- builder.setTitle("Add Photo");
- builder.setIcon(R.mipmap.ic_launcher);
- builder.setItems(items, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int item) {
- if (items[item].equals("Take Photo")) {
- callCamera();
- } else if (items[item].equals("Choose from Library")) {
- callGalerry();
- } else if (items[item].equals("Remove")) {
- linearMain.removeView(imageView);
- cekarray(photoPath, "");
- } else if (items[item].equals("Cancel")) {
- dialog.dismiss();
- }
- }
- });
- builder.show();
- }
- });
- } catch (FileNotFoundException e) {
- Toast.makeText(getApplicationContext(), "Error while loading image", Toast.LENGTH_SHORT).show();
- }
- } else {
- try {
- //Log.e("CAMERA", fileUri.getPath());
- final String photoPath = fileUri.getPath();
- bitmap = PhotoLoader.init().from(photoPath).requestSize(512, 512).getBitmap();
- imageView.setLayoutParams(layoutParams);
- imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
- imageView.setPadding(10, 10, 10, 10);
- imageView.setAdjustViewBounds(true);
- imageView.setBackgroundResource(R.drawable.border_image);
- imageView.setImageBitmap(bitmap);
- linearMain.addView(imageView);
- //imageList.add(photoPath);
- if (imageRemove.size() < 1) {
- imageList.add(photoPath);
- } else {
- for (int i = 0; i < 1; i++) {
- //Log.e(TAG,"Set ke index : "+String.valueOf(Integer.parseInt(imageRemove.get(i))-1));
- imageList.add(Integer.parseInt(imageRemove.get(i)) - 1, photoPath);
- imageRemove.remove(i);
- }
- showImageLog();
- }
- imageView.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- AlertDialog.Builder builder = new AlertDialog.Builder(LaporanKLB.this);
- builder.setTitle("Add Photo");
- builder.setIcon(R.mipmap.ic_launcher);
- builder.setItems(items, new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int item) {
- if (items[item].equals("Take Photo")) {
- callCamera();
- } else if (items[item].equals("Choose from Library")) {
- callGalerry();
- } else if (items[item].equals("Remove")) {
- linearMain.removeView(imageView);
- cekarray(photoPath, "");
- } else if (items[item].equals("Cancel")) {
- dialog.dismiss();
- }
- }
- });
- builder.show();
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
- // Untuk resize bitmap
- public Bitmap getResizedBitmap(Bitmap image, int maxSize) {
- int width = image.getWidth();
- int height = image.getHeight();
- float bitmapRatio = (float) width / (float) height;
- if (bitmapRatio > 1) {
- width = maxSize;
- height = (int) (width / bitmapRatio);
- } else {
- height = maxSize;
- width = (int) (height * bitmapRatio);
- }
- return Bitmap.createScaledBitmap(image, width, height, true);
- }
- public Uri getOutputMediaFileUri() {
- return Uri.fromFile(getOutputMediaFile());
- /*return FileProvider.getUriForFile(LaporanKLB.this, BuildConfig.APPLICATION_ID, getOutputMediaFile());
- return FileProvider.getUriForFile(getApplicationContext(), "com.example.asd", getOutputMediaFile());*/
- }
- private static File getOutputMediaFile() {
- // External sdcard location
- File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Ngabsen");
- // Create the storage directory if it does not exist
- if (!mediaStorageDir.exists()) {
- if (!mediaStorageDir.mkdirs()) {
- Log.e("Monitoring", "Oops! Failed create Monitoring directory");
- return null;
- }
- }
- // Create a media file name
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
- File mediaFile;
- mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_Ngabsen_" + timeStamp + ".jpg");
- return mediaFile;
- }
- public void callGalerry(){
- int result = ContextCompat.checkSelfPermission(LaporanKLB.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
- if (result == PackageManager.PERMISSION_GRANTED) {
- Intent in = galleryPhoto.openGalleryIntent();
- startActivityForResult(in, GALLERY_REQUEST);
- } else {
- //Requested permission.
- mRequestPermissionHandler = new RequestPermissionHandler();
- handleButtonClicked();
- }
- }
- public void callCamera(){
- int result = ContextCompat.checkSelfPermission(LaporanKLB.this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
- if (result == PackageManager.PERMISSION_GRANTED) {
- StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
- StrictMode.setVmPolicy(builder.build());
- intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
- fileUri = getOutputMediaFileUri();
- intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, fileUri);
- startActivityForResult(intent, REQUEST_CAMERA);
- } else {
- //Requested permission.
- mRequestPermissionHandler = new RequestPermissionHandler();
- handleButtonClicked();
- }
- }
- public void handleButtonClicked(){
- mRequestPermissionHandler.requestPermission(this, new String[] {
- android.Manifest.permission.ACCESS_FINE_LOCATION,android.Manifest.permission.CAMERA, android.Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE
- }, 123, new RequestPermissionHandler.RequestPermissionListener() {
- @Override
- public void onSuccess() {
- //Toast.makeText(Login.this, "request permission success", Toast.LENGTH_SHORT).show();
- }
- @Override
- public void onFailed() {
- //Toast.makeText(Login.this, "request permission failed", Toast.LENGTH_SHORT).show();
- }
- });
- }
- @Override
- public void onRequestPermissionsResult(int requestCode,String[] permissions,
- int[] grantResults) {
- super.onRequestPermissionsResult(requestCode, permissions, grantResults);
- mRequestPermissionHandler.onRequestPermissionsResult(requestCode, permissions,
- grantResults);
- }
- private void getListKategoriLaporan() {
- final String urlKategoriLaporan = Server.URL+"getKategoriLaporanKLB.php";
- JsonArrayRequest jArr = new JsonArrayRequest(urlKategoriLaporan, new Response.Listener<JSONArray>() {
- @Override
- public void onResponse(JSONArray response) {
- listKategoriLaporan.clear();
- if (response.length() < 1) {
- AlertDialogMsg.messageDialog( LaporanKLB.this, "Informasi","Data Tidak Tersedia", "OK",null, null, null);
- } else {
- for (int i = 0; i < response.length(); i++) {
- try {
- JSONObject obj = response.getJSONObject(i);
- DataKategoriLaporan item = new DataKategoriLaporan();
- item.setKategori_klb_id(obj.getString("kategori_klb_id"));
- item.setKategori_klb_name(obj.getString("kategori_klb_name"));
- // menambah item ke array
- dataKategoriLaporan.add(item);
- listKategoriLaporan.add(obj.getString("kategori_klb_name"));
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- }
- ArrayAdapter<String> listKategori = new ArrayAdapter<String>
- (LaporanKLB.this, android.R.layout.simple_dropdown_item_1line, listKategoriLaporan);
- acKategoriLaporan.setThreshold(2);
- acKategoriLaporan.setAdapter(listKategori);
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Log.e(TAG, "Error.Response" + error.getMessage());
- }
- });
- // menambah request ke request queue
- jArr.setRetryPolicy(new DefaultRetryPolicy(
- TIME_OUT_POST,
- DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
- DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
- );
- AppController.getInstance().addToRequestQueue(jArr);
- }
- }
Add Comment
Please, Sign In to add comment