diff --git a/MyCity/app/build.gradle b/MyCity/app/build.gradle index 5f6b4eb..f10314f 100644 --- a/MyCity/app/build.gradle +++ b/MyCity/app/build.gradle @@ -10,6 +10,7 @@ android { versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" android.defaultConfig.vectorDrawables.useSupportLibrary = true + multiDexEnabled true } buildTypes { release { @@ -20,8 +21,11 @@ android { } dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') api 'cz.msebera.android:httpclient:4.4.1.2' + implementation 'com.github.chathuralakmal:AndroidImagePopup:1.2.1' + implementation 'com.journeyapps:zxing-android-embedded:3.6.0' implementation 'com.jjoe64:graphview:4.2.2' implementation 'com.android.support:design:27.1.1' implementation 'com.android.support:appcompat-v7:27.0.0' diff --git a/MyCity/app/src/main/AndroidManifest.xml b/MyCity/app/src/main/AndroidManifest.xml index 49ce08d..100719a 100644 --- a/MyCity/app/src/main/AndroidManifest.xml +++ b/MyCity/app/src/main/AndroidManifest.xml @@ -1,8 +1,14 @@ - - + + + + + + + + + + + android:screenOrientation="portrait" + android:theme="@style/AppTheme.NoActionBar"> diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/DenunciationFragment.java b/MyCity/app/src/main/java/gq/yigit/mycity/DenunciationFragment.java index 6044b01..1830869 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/DenunciationFragment.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/DenunciationFragment.java @@ -2,6 +2,7 @@ package gq.yigit.mycity; import android.Manifest; import android.app.Dialog; +import android.content.ContentResolver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; @@ -28,6 +29,7 @@ import org.json.JSONObject; import java.io.ByteArrayOutputStream; import java.io.File; +import java.net.URI; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -49,7 +51,9 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons private EditText note; private Bitmap img; private ImageButton img_button; - private static final int CAMERA_REQUEST = 1888; + private static final int CAMERA_REQUEST = 100; + + private Uri mImageUri; public DenunciationFragment() { } @@ -72,23 +76,25 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons + + View rootView = inflater.inflate(R.layout.fragment_denunciation, container, false); FileActions file_manager = new FileActions(); url = file_manager.readFromFile(getContext(),"server.config").trim(); activity=this; - - submit = rootView.findViewById(R.id.denunciation_submit); note = (EditText) rootView.findViewById(R.id.denunciation_text); img_button= rootView.findViewById(R.id.denunciation_photo); spinner = rootView.findViewById(R.id.denunciation_spinner); if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { - img_button.setEnabled(false); ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); } + + + submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -117,14 +123,27 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons request.execute(); } }); - img_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - - Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); - startActivityForResult(cameraIntent, CAMERA_REQUEST); - + File photo; + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + + try + { + // place where to store camera taken picture + photo = createTemporaryFile("picture", ".jpg"); + photo.delete(); + Uri mImageUri = Uri.fromFile(photo); + } + catch(Exception e) + { + Log.v("[ERROR]", "Can't create file to take picture!"); + Toast.makeText(getContext(), "Please check SD card! Image shot is impossible!", Toast.LENGTH_LONG); + } + intent.putExtra(MediaStore.EXTRA_OUTPUT, mImageUri); + //start camera intent + activity.startActivityForResult(intent, CAMERA_REQUEST); } }); @@ -158,6 +177,17 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons } } + private File createTemporaryFile(String part, String ext) throws Exception + { + File tempDir= Environment.getExternalStorageDirectory(); + tempDir=new File(tempDir.getAbsolutePath()+"/.temp/"); + if(!tempDir.exists()) + { + tempDir.mkdirs(); + } + return File.createTempFile(part, ext, tempDir); + } + @Override public void onAttach(Context context) { super.onAttach(context); @@ -232,6 +262,20 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons } + //called after camera intent finished + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) + { + //MenuShootImage is user defined menu option to shoot image + if(requestCode==CAMERA_REQUEST && resultCode==RESULT_OK) + { + Bitmap photo = (Bitmap) data.getExtras().get("data"); + img = photo; + } + super.onActivityResult(requestCode, resultCode, data); + } + + @Override public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (requestCode == 0) { @@ -242,8 +286,4 @@ public class DenunciationFragment extends Fragment implements WebRequest.respons } } - - - - } diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java b/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java index ea5a9e8..cb6c4d0 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java @@ -4,10 +4,12 @@ import android.Manifest; import android.app.Activity; import android.content.Context; import android.content.DialogInterface; +import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.design.widget.NavigationView.OnNavigationItemSelectedListener; import android.support.v4.app.ActivityCompat; import android.support.v4.app.FragmentManager; @@ -50,6 +52,7 @@ public class MainActivity extends AppCompatActivity RateFragment.OnFragmentInteractionListener, UtilityMain.OnFragmentInteractionListener, TransitFragment.OnFragmentInteractionListener, + QRFragment.OnFragmentInteractionListener, OnFragmentInteractionListener, responseListener, imageListener { @@ -101,6 +104,7 @@ public class MainActivity extends AppCompatActivity transaction.replace(R.id.app_bar_main, fragment); transaction.addToBackStack(null); transaction.commit(); + Log.d("[BOOKMARK]","Done with main"); } @@ -189,6 +193,10 @@ public class MainActivity extends AppCompatActivity fragmentTransaction.replace(R.id.app_bar_main, fragment); fragmentTransaction.commit(); fragmentTransaction.addToBackStack(null); + }else if (id == R.id.qr_code){ + QRFragment fragment= new QRFragment(); + fragmentTransaction.replace(R.id.app_bar_main, fragment); + fragmentTransaction.commit(); } @@ -242,4 +250,6 @@ public class MainActivity extends AppCompatActivity Log.e("[ERROR]","Cannot set avatar!"); } } + + } diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/QRFragment.java b/MyCity/app/src/main/java/gq/yigit/mycity/QRFragment.java new file mode 100644 index 0000000..afd6d0f --- /dev/null +++ b/MyCity/app/src/main/java/gq/yigit/mycity/QRFragment.java @@ -0,0 +1,88 @@ +package gq.yigit.mycity; + +import android.content.Context; +import android.graphics.Bitmap; +import android.net.Uri; +import android.os.Bundle; +import android.support.annotation.RequiresPermission; +import android.support.v4.app.Fragment; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + + +import com.google.zxing.WriterException; +import org.json.JSONException; + +import gq.yigit.mycity.tools.QRCodeGenerator; + +public class QRFragment extends Fragment { + + + private OnFragmentInteractionListener mListener; + private ImageView qr_view; + private Bitmap qr_img; + public QRFragment() { + } + + + + public static QRFragment newInstance(String param1, String param2) { + QRFragment fragment = new QRFragment(); + + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_qr, container, false); + qr_view = rootView.findViewById(R.id.qr_image); + + try { + qr_img = QRCodeGenerator.Generate(MainActivity.userData.getString("id"),1080,1080); + qr_view.setImageBitmap(qr_img); + }catch(JSONException e){ + Log.e("[ERROR]","JSON error occured while generating qr code!"); + }catch (WriterException e){ + Log.e("[ERROR]","An error occured while generating qr code!"); + } + return rootView; + } + + 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); + } +} diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java b/MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java index 6af38eb..f4a70e3 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/RateFragment.java @@ -120,16 +120,10 @@ public class RateFragment extends Fragment implements WebRequest.responseListene } } }); + - if ( ContextCompat.checkSelfPermission( cntxt, Manifest.permission.ACCESS_FINE_LOCATION ) != PackageManager.PERMISSION_GRANTED ) { - ActivityCompat.requestPermissions(MainActivity.mainActivity, new String[] { Manifest.permission.ACCESS_FINE_LOCATION },1); - } - - LocationManager locationManager = (LocationManager) - getContext().getSystemService(cntxt.LOCATION_SERVICE); - Location loc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); - String longitude = String.valueOf(loc.getLongitude()); - String latitude = String.valueOf(loc.getLatitude()); + String latitude = "39.9127897"; + String longitude = "32.8073577"; FileActions file_manager = new FileActions(); url = file_manager.readFromFile(cntxt,"server.config").trim(); @@ -223,7 +217,7 @@ public class RateFragment extends Fragment implements WebRequest.responseListene private void downloadImg(int i) throws JSONException { ImageDownload downloader = new ImageDownload(); downloader.addListener(this); - downloader.execute(url + ((JSONObject) ratings.get(i)).get("type")); + downloader.execute(url + ((JSONObject) ratings.get(i)).get("img")); } diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/TakePhoto.java b/MyCity/app/src/main/java/gq/yigit/mycity/TakePhoto.java new file mode 100644 index 0000000..766b739 --- /dev/null +++ b/MyCity/app/src/main/java/gq/yigit/mycity/TakePhoto.java @@ -0,0 +1,67 @@ +package gq.yigit.mycity; + +import android.Manifest; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.net.Uri; +import android.provider.MediaStore; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; + +public class TakePhoto extends AppCompatActivity { + + + private Button takePictureButton; + private ImageView imageView; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_take_photo); + + takePictureButton = (Button) findViewById(R.id.button_image); + imageView = (ImageView) findViewById(R.id.imageview); + + if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { + takePictureButton.setEnabled(false); + ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE }, 0); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { + if (requestCode == 0) { + if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED + && grantResults[1] == PackageManager.PERMISSION_GRANTED) { + takePictureButton.setEnabled(true); + } + } + } + + public void takePicture(View view) { + Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + + startActivityForResult(intent, 100); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == 100) { + Log.d("[BOOKMARK]","Actvitity resulted"); + if (resultCode == RESULT_OK) { + if (data == null) { + Log.d("[BOOKMARK]","Received image"); + // TODO Do something with the full image stored + // in outputFileUri. Perhaps copying it to the app folder + } + } + } + } + +} diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/navigation/TransitFragment.java b/MyCity/app/src/main/java/gq/yigit/mycity/navigation/TransitFragment.java index 780b87d..88854aa 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/navigation/TransitFragment.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/navigation/TransitFragment.java @@ -102,7 +102,7 @@ public class TransitFragment extends Fragment implements WebRequest.responseList place_name = rootView.findViewById(R.id.place_name); recyclerView = rootView.findViewById(R.id.route_view); try { - latitude = "39.9127897"; + latitude = "39.9127897"; longitude = "32.8073577"; }catch (SecurityException e){ diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/tools/QRCodeGenerator.java b/MyCity/app/src/main/java/gq/yigit/mycity/tools/QRCodeGenerator.java new file mode 100644 index 0000000..44bc4fa --- /dev/null +++ b/MyCity/app/src/main/java/gq/yigit/mycity/tools/QRCodeGenerator.java @@ -0,0 +1,44 @@ +package gq.yigit.mycity.tools; + +import android.graphics.Bitmap; +import android.graphics.Color; +import android.net.Uri; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.WriterException; +import com.google.zxing.common.BitMatrix; + + +import java.util.Arrays; + +import static android.graphics.Color.BLACK; +import static android.graphics.Color.WHITE; + +public class QRCodeGenerator { + public static Bitmap Generate(String data, int height,int width) throws WriterException { + + BitMatrix result; + try { + result = new MultiFormatWriter().encode(data, + BarcodeFormat.QR_CODE, width, height, null); + } catch (IllegalArgumentException iae) { + // Unsupported format + return null; + } + + int w = result.getWidth(); + int h = result.getHeight(); + int[] pixels = new int[w * h]; + for (int y = 0; y < h; y++) { + int offset = y * w; + for (int x = 0; x < w; x++) { + pixels[offset + x] = result.get(x, y) ? BLACK : WHITE; + } + } + + Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); + bitmap.setPixels(pixels, 0, w, 0, 0, w, h); + return bitmap; + } +} + diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityElectricity.java b/MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityElectricity.java index 32f7ca9..df47478 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityElectricity.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityElectricity.java @@ -1,7 +1,9 @@ package gq.yigit.mycity.utility; import android.content.Context; +import android.graphics.Bitmap; import android.graphics.Color; +import android.graphics.drawable.BitmapDrawable; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -10,6 +12,11 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; +import com.ceylonlabs.imageviewpopup.ImagePopup; +import com.google.zxing.WriterException; import com.jjoe64.graphview.GraphView; import com.jjoe64.graphview.helper.StaticLabelsFormatter; import com.jjoe64.graphview.series.DataPoint; @@ -17,6 +24,7 @@ import com.jjoe64.graphview.series.LineGraphSeries; import gq.yigit.mycity.MainActivity; import gq.yigit.mycity.R; import gq.yigit.mycity.tools.FileActions; +import gq.yigit.mycity.tools.QRCodeGenerator; import gq.yigit.mycity.tools.WebRequest; import org.json.JSONException; import org.json.JSONObject; @@ -29,6 +37,14 @@ public class UtilityElectricity extends Fragment implements WebRequest.responseL private JSONObject electricityUsage; private GraphView graph; + private TextView bill; + private TextView points; + private TextView efficiency; + + private Button qr_view; + private Button pay_bill; + + private OnFragmentInteractionListener mListener; public UtilityElectricity() { @@ -54,6 +70,44 @@ public class UtilityElectricity extends Fragment implements WebRequest.responseL View rootView = inflater.inflate(R.layout.fragment_utility_electricity, container, false);; graph = (GraphView) rootView.findViewById(R.id.utility_graph); + points = rootView.findViewById(R.id.points_utility_electricity); + bill = rootView.findViewById(R.id.bill_utility_electricity); + efficiency = rootView.findViewById(R.id.efficiency_utility_electricity); + + pay_bill = rootView.findViewById(R.id.pay_bill_electricity); + qr_view = rootView.findViewById(R.id.use_point_electricity); + + pay_bill.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(getContext(),"Bills paid successfully!",Toast.LENGTH_LONG).show(); + } + }); + + + + final ImagePopup imagePopup = new ImagePopup(getContext()); + imagePopup.setWindowHeight(712); // Optional + imagePopup.setWindowWidth(712); // Optional + imagePopup.setBackgroundColor(Color.WHITE); // Optional + imagePopup.setFullScreen(true); // Optional + imagePopup.setImageOnClickClose(true); // Optional + try { + imagePopup.initiatePopup(new BitmapDrawable(QRCodeGenerator.Generate(MainActivity.userData.getString("id"), 712, 712))); + }catch (JSONException e){ + Log.e("[ERROR]","Cannot get user id"); + }catch (WriterException e){ + Log.e("[ERROR]","Writer exception occured"); + } + + qr_view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + imagePopup.viewPopup(); + + } + }); + StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph); staticLabelsFormatter.setHorizontalLabels(new String[] {"0", "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "22", "24"}); @@ -130,6 +184,10 @@ public class UtilityElectricity extends Fragment implements WebRequest.responseL graph.addSeries(series); graph.addSeries(series2); + points.setText(String.valueOf(((Double)electricityUsage.get("points")).intValue())); + bill.setText(String.valueOf(((Double)electricityUsage.get("bill")).intValue())); + efficiency.setText(String.valueOf(((Double)electricityUsage.get("efficiency")).intValue())); + }catch (JSONException e){ Log.e("[ERROR]","Cannot interpret response from electric service"); } diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityWater.java b/MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityWater.java index b36f963..a6ed684 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityWater.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/utility/UtilityWater.java @@ -1,32 +1,49 @@ package gq.yigit.mycity.utility; import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.Color; +import android.graphics.drawable.BitmapDrawable; import android.net.Uri; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; +import android.widget.TextView; +import android.widget.Toast; +import com.ceylonlabs.imageviewpopup.ImagePopup; +import com.google.zxing.WriterException; +import com.jjoe64.graphview.GraphView; +import com.jjoe64.graphview.helper.StaticLabelsFormatter; +import com.jjoe64.graphview.series.DataPoint; +import com.jjoe64.graphview.series.LineGraphSeries; +import gq.yigit.mycity.MainActivity; import gq.yigit.mycity.R; +import gq.yigit.mycity.tools.FileActions; +import gq.yigit.mycity.tools.QRCodeGenerator; +import gq.yigit.mycity.tools.WebRequest; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.HashMap; + + +public class UtilityWater extends Fragment implements WebRequest.responseListener { + + private JSONObject waterUsage; + private GraphView graph; + + private TextView bill; + private TextView points; + private TextView efficiency; + + private Button qr_view; + private Button pay_bill; -/** - * A simple {@link Fragment} subclass. - * Activities that contain this fragment must implement the - * {@link UtilityWater.OnFragmentInteractionListener} interface - * to handle interaction events. - * Use the {@link UtilityWater#newInstance} factory method to - * create an instance of this fragment. - */ -public class UtilityWater 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 OnFragmentInteractionListener mListener; @@ -34,38 +51,83 @@ public class UtilityWater extends Fragment { // Required empty public constructor } - /** - * 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 UtilityWater. - */ - // TODO: Rename and change types and number of parameters + public static UtilityWater newInstance(String param1, String param2) { UtilityWater fragment = new UtilityWater(); - 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); - if (getArguments() != null) { - mParam1 = getArguments().getString(ARG_PARAM1); - mParam2 = getArguments().getString(ARG_PARAM2); - } + } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, - Bundle savedInstanceState) { + Bundle savedInstanceState) { // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_utility_water, container, false); + View rootView = inflater.inflate(R.layout.fragment_utility_water, container, false);; + graph = (GraphView) rootView.findViewById(R.id.utility_graph); + + points = rootView.findViewById(R.id.points_utility_water); + bill = rootView.findViewById(R.id.bill_utility_water); + efficiency = rootView.findViewById(R.id.efficiency_utility_water); + + pay_bill = rootView.findViewById(R.id.pay_bill_water); + qr_view = rootView.findViewById(R.id.use_point_water); + + pay_bill.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(getContext(),"Bills paid successfully!",Toast.LENGTH_LONG).show(); + } + }); + + final ImagePopup imagePopup = new ImagePopup(getContext()); + imagePopup.setWindowHeight(712); // Optional + imagePopup.setWindowWidth(712); // Optional + imagePopup.setBackgroundColor(Color.WHITE); // Optional + imagePopup.setFullScreen(true); // Optional + imagePopup.setImageOnClickClose(true); // Optional + try { + imagePopup.initiatePopup(new BitmapDrawable(QRCodeGenerator.Generate(MainActivity.userData.getString("id"), 712, 712))); + }catch (JSONException e){ + Log.e("[ERROR]","Cannot get user id"); + }catch (WriterException e){ + Log.e("[ERROR]","Writer exception occured"); + } + + qr_view.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + imagePopup.viewPopup(); + + } + }); + + + + StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph); + staticLabelsFormatter.setHorizontalLabels(new String[] {"0", "2", "4", "6", "8", "10", "12", "14", "16", "18", "20", "22", "24"}); + staticLabelsFormatter.setVerticalLabels(new String[] {"0", "5", "10","15","20"}); + graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter); + + FileActions file_manager = new FileActions(); + String url = file_manager.readFromFile(getContext(),"server.config").trim(); + HashMap request = new HashMap<>(); + try { + request.put("user_id", MainActivity.userData.getString("id")); + }catch (JSONException e){ + Log.e("[ERROR]","User data not correct"); + } + request.put("type","water"); + WebRequest login_manager = new WebRequest(url + "/resources/",false,request,0); + login_manager.addListener(this); + login_manager.execute(); + + + return rootView; } // TODO: Rename method, update argument and hook method into UI event @@ -91,18 +153,44 @@ public class UtilityWater extends Fragment { mListener = null; } - /** - * This interface must be implemented by activities that contain this - * fragment to allow an interaction in this fragment to be communicated - * to the activity and potentially other fragments contained in that - * activity. - *

- * See the Android Training lesson Communicating with Other Fragments for more information. - */ + public interface OnFragmentInteractionListener { // TODO: Update argument type and name void onFragmentInteraction(Uri uri); } + + public void receivedResponse(boolean success, String result,int reqid){ + if(success){ + try{ + waterUsage = new JSONObject(result); + LineGraphSeries series = new LineGraphSeries<>(new DataPoint[] {}); + LineGraphSeries series2 = new LineGraphSeries<>(new DataPoint[] {}); + for(int i = 0;i < waterUsage.getJSONArray("daily_water_usage").length();i++){ + series.appendData(new DataPoint(i,waterUsage.getJSONArray("daily_water_usage").getInt(i)), + true, + 100); + } + + for(int i = 0;i < waterUsage.getJSONArray("ideal_water_usage").length();i++){ + series2.appendData(new DataPoint(i,waterUsage.getJSONArray("ideal_water_usage").getInt(i)), + true, + 100); + } + + series.setTitle("ideal"); + series.setColor(Color.BLUE); + series2.setTitle("usage"); + series2.setColor(Color.RED); + graph.addSeries(series); + graph.addSeries(series2); + + points.setText(String.valueOf(((Double)waterUsage.get("points")).intValue())); + bill.setText(String.valueOf(((Double)waterUsage.get("bill")).intValue())); + efficiency.setText(String.valueOf(((Double)waterUsage.get("efficiency")).intValue())); + + }catch (JSONException e){ + Log.e("[ERROR]","Cannot interpret response from water service"); + } + } + } } diff --git a/MyCity/app/src/main/res/drawable-v21/qr_code.xml b/MyCity/app/src/main/res/drawable-v21/qr_code.xml new file mode 100644 index 0000000..ca14294 --- /dev/null +++ b/MyCity/app/src/main/res/drawable-v21/qr_code.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/MyCity/app/src/main/res/layout/activity_take_photo.xml b/MyCity/app/src/main/res/layout/activity_take_photo.xml new file mode 100644 index 0000000..6ca7d93 --- /dev/null +++ b/MyCity/app/src/main/res/layout/activity_take_photo.xml @@ -0,0 +1,29 @@ + + + + + + +