diff --git a/MyCity/app/build.gradle b/MyCity/app/build.gradle index 22557ae..f832618 100644 --- a/MyCity/app/build.gradle +++ b/MyCity/app/build.gradle @@ -21,6 +21,11 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') api 'cz.msebera.android:httpclient:4.4.1.2' + + + implementation 'com.jjoe64:graphview:4.2.2' + + implementation 'com.android.support:design:27.1.1' implementation 'com.android.support:appcompat-v7:27.0.0' implementation 'com.android.support:design:27.0.0' 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 365a747..b5c52c2 100644 --- a/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java +++ b/MyCity/app/src/main/java/gq/yigit/mycity/MainActivity.java @@ -27,6 +27,7 @@ import android.widget.Toast; import gq.yigit.mycity.navigation.MapsFragment; import gq.yigit.mycity.tools.*; import gq.yigit.mycity.tools.WebRequest.responseListener; +import gq.yigit.mycity.utilityFragment.UtilityFragment; import gq.yigit.mycity.votesFragment.VoteFragment; import gq.yigit.mycity.votesFragment.VotesContent; import gq.yigit.mycity.votesFragment.VotesFragment; @@ -46,6 +47,7 @@ public class MainActivity extends AppCompatActivity MainFragment.OnFragmentInteractionListener, RateFragment.OnFragmentInteractionListener, MapsFragment.OnFragmentInteractionListener, + UtilityFragment.OnFragmentInteractionListener, OnFragmentInteractionListener, responseListener, imageListener { @@ -183,7 +185,10 @@ public class MainActivity extends AppCompatActivity fragmentTransaction.commit(); fragmentTransaction.addToBackStack(null); } else if (id == R.id.utilities) { - + UtilityFragment fragment = new UtilityFragment(); + fragmentTransaction.replace(R.id.app_bar_main, fragment); + fragmentTransaction.commit(); + fragmentTransaction.addToBackStack(null); } diff --git a/MyCity/app/src/main/java/gq/yigit/mycity/utilityFragment/UtilityFragment.java b/MyCity/app/src/main/java/gq/yigit/mycity/utilityFragment/UtilityFragment.java new file mode 100644 index 0000000..faee840 --- /dev/null +++ b/MyCity/app/src/main/java/gq/yigit/mycity/utilityFragment/UtilityFragment.java @@ -0,0 +1,159 @@ +package gq.yigit.mycity.utilityFragment; + +import android.content.Context; +import android.graphics.Color; +import android.net.Uri; +import android.os.Bundle; +import android.support.design.widget.TabLayout; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +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.R; + +import java.util.ArrayList; +import java.util.List; + + +public class UtilityFragment extends Fragment { + + + + + private OnFragmentInteractionListener mListener; + + public UtilityFragment() { + } + + + public static UtilityFragment newInstance(String param1, String param2) { + UtilityFragment fragment = new UtilityFragment(); + 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_utility, container, false); + GraphView graph = (GraphView) rootView.findViewById(R.id.utility_graph); + LineGraphSeries series = new LineGraphSeries<>(new DataPoint[] { + new DataPoint(0, 1), + new DataPoint(1, 5), + new DataPoint(2, 3) + }); + LineGraphSeries series2 = new LineGraphSeries<>(new DataPoint[] { + new DataPoint(0, 4), + new DataPoint(1, 1), + new DataPoint(2, 7) + }); + + StaticLabelsFormatter staticLabelsFormatter = new StaticLabelsFormatter(graph); + staticLabelsFormatter.setHorizontalLabels(new String[] {"old", "middle", "new"}); + staticLabelsFormatter.setVerticalLabels(new String[] {"low", "middle", "high"}); + graph.getGridLabelRenderer().setLabelFormatter(staticLabelsFormatter); + + series.setTitle("ideal"); + series.setColor(Color.BLUE); + series2.setTitle("usage"); + series2.setColor(Color.RED); + graph.addSeries(series); + graph.addSeries(series2); + + ViewPager viewPager = (ViewPager) rootView.findViewById(R.id.viewpager); + setupViewPager(viewPager); + + TabLayout tabs = (TabLayout) rootView.findViewById(R.id.result_tabs); + tabs.setupWithViewPager(viewPager); + + return rootView; + } + + public void onButtonPressed(Uri uri) { + if (mListener != null) { + mListener.onFragmentInteraction(uri); + } + } + + private void setupViewPager(ViewPager viewPager) { + + + Adapter adapter = new Adapter(getChildFragmentManager()); + adapter.addFragment(new UtilityFragment(), "Electricity"); + viewPager.setAdapter(adapter); + + + + } + + + @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); + } +} + + +class Adapter extends FragmentPagerAdapter { + private final List mFragmentList = new ArrayList<>(); + private final List mFragmentTitleList = new ArrayList<>(); + + public Adapter(FragmentManager manager) { + super(manager); + } + + @Override + public Fragment getItem(int position) { + return mFragmentList.get(position); + } + + @Override + public int getCount() { + return mFragmentList.size(); + } + + public void addFragment(Fragment fragment, String title) { + mFragmentList.add(fragment); + mFragmentTitleList.add(title); + } + + @Override + public CharSequence getPageTitle(int position) { + return mFragmentTitleList.get(position); + } +} + + + + diff --git a/MyCity/app/src/main/res/drawable/app_icon.xml b/MyCity/app/src/main/res/drawable-v24/app_icon.xml similarity index 100% rename from MyCity/app/src/main/res/drawable/app_icon.xml rename to MyCity/app/src/main/res/drawable-v24/app_icon.xml diff --git a/MyCity/app/src/main/res/drawable-v21/bus.xml b/MyCity/app/src/main/res/drawable-v24/bus.xml similarity index 100% rename from MyCity/app/src/main/res/drawable-v21/bus.xml rename to MyCity/app/src/main/res/drawable-v24/bus.xml diff --git a/MyCity/app/src/main/res/drawable/magnifier.xml b/MyCity/app/src/main/res/drawable-v24/magnifier.xml similarity index 100% rename from MyCity/app/src/main/res/drawable/magnifier.xml rename to MyCity/app/src/main/res/drawable-v24/magnifier.xml diff --git a/MyCity/app/src/main/res/drawable-v21/navigation.xml b/MyCity/app/src/main/res/drawable-v24/navigation.xml similarity index 100% rename from MyCity/app/src/main/res/drawable-v21/navigation.xml rename to MyCity/app/src/main/res/drawable-v24/navigation.xml diff --git a/MyCity/app/src/main/res/drawable-v21/parking.xml b/MyCity/app/src/main/res/drawable-v24/parking.xml similarity index 100% rename from MyCity/app/src/main/res/drawable-v21/parking.xml rename to MyCity/app/src/main/res/drawable-v24/parking.xml diff --git a/MyCity/app/src/main/res/drawable/side_nav_bar.xml b/MyCity/app/src/main/res/drawable-v24/side_nav_bar.xml similarity index 100% rename from MyCity/app/src/main/res/drawable/side_nav_bar.xml rename to MyCity/app/src/main/res/drawable-v24/side_nav_bar.xml diff --git a/MyCity/app/src/main/res/drawable-v21/star.xml b/MyCity/app/src/main/res/drawable-v24/star.xml similarity index 100% rename from MyCity/app/src/main/res/drawable-v21/star.xml rename to MyCity/app/src/main/res/drawable-v24/star.xml diff --git a/MyCity/app/src/main/res/drawable-v21/subway.xml b/MyCity/app/src/main/res/drawable-v24/subway.xml similarity index 100% rename from MyCity/app/src/main/res/drawable-v21/subway.xml rename to MyCity/app/src/main/res/drawable-v24/subway.xml diff --git a/MyCity/app/src/main/res/drawable/user_icon_def.xml b/MyCity/app/src/main/res/drawable-v24/user_icon_def.xml similarity index 100% rename from MyCity/app/src/main/res/drawable/user_icon_def.xml rename to MyCity/app/src/main/res/drawable-v24/user_icon_def.xml diff --git a/MyCity/app/src/main/res/drawable-v21/utility.xml b/MyCity/app/src/main/res/drawable-v24/utility.xml similarity index 100% rename from MyCity/app/src/main/res/drawable-v21/utility.xml rename to MyCity/app/src/main/res/drawable-v24/utility.xml diff --git a/MyCity/app/src/main/res/drawable-v21/vote.xml b/MyCity/app/src/main/res/drawable-v24/vote.xml similarity index 100% rename from MyCity/app/src/main/res/drawable-v21/vote.xml rename to MyCity/app/src/main/res/drawable-v24/vote.xml diff --git a/MyCity/app/src/main/res/drawable/vote_style.xml b/MyCity/app/src/main/res/drawable-v24/vote_style.xml similarity index 100% rename from MyCity/app/src/main/res/drawable/vote_style.xml rename to MyCity/app/src/main/res/drawable-v24/vote_style.xml diff --git a/MyCity/app/src/main/res/layout/fragment_utility.xml b/MyCity/app/src/main/res/layout/fragment_utility.xml new file mode 100644 index 0000000..b47f5c2 --- /dev/null +++ b/MyCity/app/src/main/res/layout/fragment_utility.xml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +