Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ksni.roots.ngsales.domain;
- import android.app.ProgressDialog;
- import android.net.Uri;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.util.Base64;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.app.Fragment;
- import android.widget.ListAdapter;
- import android.widget.ListView;
- import android.widget.SimpleAdapter;
- import android.widget.Toast;
- import com.ksni.roots.ngsales.R;
- import com.ksni.roots.ngsales.util.validator.konfigurasi;
- import org.json.JSONException;
- import org.json.JSONObject;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.HashMap;
- /**
- * A simple {@link Fragment} subclass.
- * Activities that contain this fragment must implement the
- * {@link InventoryPlant.OnFragmentInteractionListener} interface
- * to handle interaction events.
- * Use the {@link InventoryPlant#newInstance} factory method to
- * create an instance of this fragment.
- */
- public class InventoryPlant extends Fragment {
- // TODO: Rename parameter arguments, choose names that match
- // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
- private static final String ARG_PARAM1 = "param1";
- private static final String ARG_PARAM2 = "param2";
- // TODO: Rename and change types of parameters
- private String mParam1;
- private String mParam2;
- private ListView listView;
- private String JSON_STRING;
- private OnFragmentInteractionListener mListener;
- private String teeest;
- private String strBildc,strArktx;
- /**
- * Use this factory method to create a new instance of
- * this fragment using the provided parameters.
- *
- * @param param1 Parameter 1.
- * @param param2 Parameter 2.
- * @return A new instance of fragment InventoryPlant.
- */
- // TODO: Rename and change types and number of parameters
- public static InventoryPlant newInstance(String param1, String param2) {
- InventoryPlant fragment = new InventoryPlant();
- Bundle args = new Bundle();
- args.putString(ARG_PARAM1, param1);
- args.putString(ARG_PARAM2, param2);
- fragment.setArguments(args);
- return fragment;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // getBil();]
- new AsyncFetchDetailBilling().execute();
- if (getArguments() != null) {
- mParam1 = getArguments().getString(ARG_PARAM1);
- mParam2 = getArguments().getString(ARG_PARAM2);
- }
- }
- private class AsyncFetchDetailBilling extends AsyncTask<String, String, Void> {
- ProgressDialog pdLoading = new ProgressDialog(getActivity());
- HttpURLConnection conn;
- String urel = null;
- String userName = "sfasys";
- String passWord = "sfa321";
- @Override
- protected void onPreExecute(){
- super.onPreExecute();
- pdLoading.setMessage("Loading...");
- pdLoading.setCancelable(false);
- pdLoading.show();
- }
- @Override
- protected Void doInBackground(String... params){
- try {
- urel = "https://prd.nabatigroup.com/sap/opu/odata/sap/ZPRJ_SD0002_SRV/RKHv04ASet";
- URL myURL = new URL(urel);
- HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
- String userCredentials = "username:password";
- String basicAuth = "Basic " + new String(Base64.getEncoder().encode(userCredentials.getBytes()));
- myURLConnection.setRequestProperty ("Authorization", basicAuth);
- myURLConnection.setRequestMethod("POST");
- myURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- myURLConnection.setRequestProperty("Content-Length", "" + postData.getBytes().length);
- myURLConnection.setRequestProperty("Content-Language", "en-US");
- myURLConnection.setUseCaches(false);
- myURLConnection.setDoInput(true);
- myURLConnection.setDoOutput(true);
- if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) {
- StringBuffer responseMsg = new StringBuffer();
- InputStream dis = conn.getInputStream();
- int chr;
- while ((chr = dis.read()) != -1) {
- responseMsg.append((char) chr);
- }
- // return new GetRecentContextCall.Response(urlConn.getResponseCode(),
- // urlConn.getResponseMessage(),
- // responseMsg.toString());
- int response_code = conn.getResponseCode();
- Log.d("URL", String.valueOf(conn));
- Log.d("ResponseCodeBill", String.valueOf(response_code));
- //
- }
- // int response_code = urlConn.getResponseCode();
- Log.d("ResponseMessageBill", conn.getResponseMessage());
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- if (conn != null) {
- conn.disconnect();
- }
- }
- // try{
- // url = new URL("https://sfasys:sfa321@prd.nabatigroup.com/sap/opu/odata/sap/ZPRJ_SD0002_SRV/RKHv04ASet");
- // Log.d("NEWURL", "NEWURL: "+url);
- // }
- // catch (MalformedURLException e){
- // e.printStackTrace();
- // return e.toString();
- // }
- //
- // try {
- // conn = (HttpURLConnection) url.openConnection();
- // conn.setReadTimeout(10000);
- // conn.setConnectTimeout(15000);
- // conn.setUseCaches(false);
- // conn.setDoOutput(true);
- //// conn.setDoInput(true);
- //// conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- // conn.setRequestProperty("Accept","application/json");
- // conn.setRequestProperty("charset","utf-8");
- // conn.setRequestMethod("GET");
- //
- // }catch (IOException e1){
- // e1.printStackTrace();
- // return e1.toString();
- // }
- //
- // try {
- // int response_code = conn.getResponseCode();
- // Log.d("ResponseCodeBill", String.valueOf(conn.getResponseCode()));
- //
- // if (response_code == HttpURLConnection.HTTP_OK){
- // InputStream input = conn.getInputStream();
- // BufferedReader reader = new BufferedReader(new InputStreamReader(input));
- // StringBuilder result = new StringBuilder();
- // String line;
- // while ((line = reader.readLine()) != null){
- // result.append(line);
- // }
- // return (result.toString());
- // } else{
- // return (String.valueOf(response_code));
- // }
- // }catch (IOException e2){
- // e2.printStackTrace();
- // return e2.toString();
- // }finally {
- // conn.disconnect();
- // }
- return null;
- }
- @Override
- protected void onPostExecute(Void result){
- ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();
- try {
- JSONObject json = new JSONObject(String.valueOf(result)).getJSONObject("results");
- Log.d("NEWJSON", "onPostExecute: "+json);
- strBildc = json.getString("Bildc");
- strArktx = json.getString("Arktx");
- ListAdapter adapter = new SimpleAdapter(
- getActivity(),list,R.layout.fragment_inventory_plant,
- new String[]{strBildc,strArktx},
- new int[]{R.id.nobil,R.id.pid});
- listView.setAdapter(adapter);
- Log.d("showbil", "showBil: "+konfigurasi.TAG_NOBIL);
- }catch (JSONException e){
- Toast.makeText(getActivity(),e.toString()+result,Toast.LENGTH_LONG).show();
- }
- }
- }
- // private void getBil(){
- // class GetBill extends AsyncTask<Void,Void,String >{
- // @Override
- // protected void onPreExecute(){
- // super.onPreExecute();
- // }
- // @Override
- // protected void onPostExecute(String s){
- // super.onPostExecute(s);
- // JSON_STRING = s;
- // showBil();
- // }
- // @Override
- // protected String doInBackground(Void... params){
- // String urel = "https://sfasys:sfa321@prd.nabatigroup.com/sap/opu/odata/sap/ZPRJ_SD0002_SRV/RKHv04ASet?$filter=Pgidt%20eq%20datetime%272019-01-16T00:00:00%27%20and%20Slsorg%20eq%20%27PID1%27";
- // RequestHandler rh = new RequestHandler();
- // String s = rh.sendGetRequest(urel);
- // Log.d("sendRequest", "doInBackground: "+s);
- // return s;
- // }
- // }
- //
- // GetBill ge = new GetBill();
- // ge.execute();
- // }
- //
- // private void showBil(){
- //
- // JSONObject jsonObject = null;
- // ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String, String>>();
- // try{
- // jsonObject = new JSONObject("d");
- // JSONArray result = jsonObject.getJSONArray("results");
- // Log.d("NewResults", "NewResults: "+result);
- //
- // for (int i = 0; i<result.length(); i++){
- // JSONObject jo = result.getJSONObject(i);
- // String nobil = jo.getString(konfigurasi.TAG_NOBIL);
- // String pid = jo.getString(konfigurasi.TAG_PID);
- //
- // HashMap<String,String> billing = new HashMap<>();
- // billing.put(konfigurasi.TAG_NOBIL,nobil);
- // billing.put(konfigurasi.TAG_PID,pid);
- // list.add(billing);
- // }
- // }
- // catch (JSONException e){
- // e.printStackTrace();
- // }
- //
- // ListAdapter adapter = new SimpleAdapter(
- // getActivity(),list,R.layout.fragment_inventory_plant,
- // new String[]{konfigurasi.TAG_NOBIL,konfigurasi.TAG_PID},
- // new int[]{R.id.nobil,R.id.pid});
- // listView.setAdapter(adapter);
- // Log.d("showbil", "showBil: "+konfigurasi.TAG_NOBIL);
- // }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- View rv = inflater.inflate(R.layout.fragment_inventory_plant, container, false);
- listView = rv.findViewById(R.id.listInventory);
- return rv;
- }
- // TODO: Rename method, update argument and hook method into UI event
- public void onButtonPressed(Uri uri) {
- if (mListener != null) {
- mListener.onFragmentInteraction(uri);
- }
- }
- // @Override
- // public void onAttach(Context context) {
- // super.onAttach(context);
- // if (context instanceof OnFragmentInteractionListener) {
- // mListener = (OnFragmentInteractionListener) context;
- // } else {
- // throw new RuntimeException(context.toString()
- // + " must implement OnFragmentInteractionListener");
- // }
- // }
- @Override
- public void onDetach() {
- super.onDetach();
- mListener = null;
- }
- public interface OnFragmentInteractionListener {
- // TODO: Update argument type and name
- void onFragmentInteraction(Uri uri);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement