Commit 0746eb16a33f1985b080d147660def5de0e911a5
1 parent
72c88077
Exists in
master
iniciando os modulos de projetos e da camara
Showing
11 changed files
with
883 additions
and
0 deletions
Show diff stats
app/src/main/java/com/monitorabrasil/monitoralegislativo/CamaraActivity.java
0 → 100644
| ... | ... | @@ -0,0 +1,62 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo; | |
| 2 | + | |
| 3 | +import android.support.v4.app.FragmentTransaction; | |
| 4 | +import android.support.v7.app.ActionBarActivity; | |
| 5 | +import android.os.Bundle; | |
| 6 | +import android.support.v7.app.AppCompatActivity; | |
| 7 | +import android.support.v7.widget.Toolbar; | |
| 8 | +import android.view.Menu; | |
| 9 | +import android.view.MenuItem; | |
| 10 | + | |
| 11 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 12 | +import com.monitorabrasil.monitoralegislativo.fragments.GastosCamaraFragment; | |
| 13 | + | |
| 14 | +public class CamaraActivity extends AppCompatActivity { | |
| 15 | + | |
| 16 | + @Override | |
| 17 | + protected void onCreate(Bundle savedInstanceState) { | |
| 18 | + super.onCreate(savedInstanceState); | |
| 19 | + setContentView(R.layout.activity_camara); | |
| 20 | + | |
| 21 | + GastosCamaraFragment frag = (GastosCamaraFragment) getSupportFragmentManager().findFragmentByTag("gastosCamaraFrag"); | |
| 22 | + if(frag == null) { | |
| 23 | + frag = new GastosCamaraFragment(); | |
| 24 | + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); | |
| 25 | + ft.replace(R.id.rl_fragment_container, frag, "gastosCamaraFrag"); | |
| 26 | + ft.commit(); | |
| 27 | + } | |
| 28 | + | |
| 29 | + Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
| 30 | + setSupportActionBar(toolbar); | |
| 31 | + // toolbar.setNavigationIcon(R.drawable.ic_good); | |
| 32 | + toolbar.setTitle("Despesas e Receitas"); | |
| 33 | + toolbar.setSubtitle("Ouro Branco - MG"); | |
| 34 | + | |
| 35 | + toolbar.setTitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 36 | + toolbar.setSubtitleTextColor(getResources().getColor(R.color.md_white_1000)); | |
| 37 | + setSupportActionBar(toolbar); | |
| 38 | + getSupportActionBar().setDisplayHomeAsUpEnabled(true); | |
| 39 | + } | |
| 40 | + | |
| 41 | + @Override | |
| 42 | + public boolean onCreateOptionsMenu(Menu menu) { | |
| 43 | + // Inflate the menu; this adds items to the action bar if it is present. | |
| 44 | + getMenuInflater().inflate(R.menu.menu_camara, menu); | |
| 45 | + return true; | |
| 46 | + } | |
| 47 | + | |
| 48 | + @Override | |
| 49 | + public boolean onOptionsItemSelected(MenuItem item) { | |
| 50 | + // Handle action bar item clicks here. The action bar will | |
| 51 | + // automatically handle clicks on the Home/Up button, so long | |
| 52 | + // as you specify a parent activity in AndroidManifest.xml. | |
| 53 | + int id = item.getItemId(); | |
| 54 | + | |
| 55 | + //noinspection SimplifiableIfStatement | |
| 56 | + if (id == R.id.action_settings) { | |
| 57 | + return true; | |
| 58 | + } | |
| 59 | + | |
| 60 | + return super.onOptionsItemSelected(item); | |
| 61 | + } | |
| 62 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/fragments/GastosCamaraFragment.java
0 → 100644
| ... | ... | @@ -0,0 +1,404 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.fragments; | |
| 2 | + | |
| 3 | +import android.app.Activity; | |
| 4 | +import android.net.Uri; | |
| 5 | +import android.os.Bundle; | |
| 6 | +import android.support.v4.app.Fragment; | |
| 7 | +import android.support.v7.widget.LinearLayoutManager; | |
| 8 | +import android.support.v7.widget.RecyclerView; | |
| 9 | +import android.view.LayoutInflater; | |
| 10 | +import android.view.View; | |
| 11 | +import android.view.ViewGroup; | |
| 12 | +import android.widget.ProgressBar; | |
| 13 | + | |
| 14 | +import com.crashlytics.android.Crashlytics; | |
| 15 | +import com.github.mikephil.charting.animation.Easing; | |
| 16 | +import com.github.mikephil.charting.charts.BarChart; | |
| 17 | +import com.github.mikephil.charting.components.Legend; | |
| 18 | +import com.github.mikephil.charting.components.XAxis; | |
| 19 | +import com.github.mikephil.charting.components.YAxis; | |
| 20 | +import com.github.mikephil.charting.data.BarData; | |
| 21 | +import com.github.mikephil.charting.data.BarDataSet; | |
| 22 | +import com.github.mikephil.charting.data.BarEntry; | |
| 23 | +import com.github.mikephil.charting.utils.ValueFormatter; | |
| 24 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 25 | +import com.monitorabrasil.monitoralegislativo.adapters.GastoAdapter; | |
| 26 | +import com.monitorabrasil.monitoralegislativo.classes.Grafico; | |
| 27 | +import com.monitorabrasil.monitoralegislativo.util.MyValueFormatter; | |
| 28 | +import com.parse.FindCallback; | |
| 29 | +import com.parse.ParseException; | |
| 30 | +import com.parse.ParseObject; | |
| 31 | +import com.parse.ParseQuery; | |
| 32 | + | |
| 33 | +import java.util.ArrayList; | |
| 34 | +import java.util.HashMap; | |
| 35 | +import java.util.Iterator; | |
| 36 | +import java.util.List; | |
| 37 | +import java.util.Set; | |
| 38 | + | |
| 39 | +/** | |
| 40 | + * A simple {@link Fragment} subclass. | |
| 41 | + * Activities that contain this fragment must implement the | |
| 42 | + * {@link GastosCamaraFragment.OnFragmentInteractionListener} interface | |
| 43 | + * to handle interaction events. | |
| 44 | + * Use the {@link GastosCamaraFragment#newInstance} factory method to | |
| 45 | + * create an instance of this fragment. | |
| 46 | + */ | |
| 47 | +public class GastosCamaraFragment extends Fragment { | |
| 48 | + | |
| 49 | + | |
| 50 | + protected BarChart mChart; | |
| 51 | + private View mView; | |
| 52 | + private HashMap<String,HashMap<String,Float>> dataset = new HashMap<String,HashMap<String,Float>>(); | |
| 53 | + private HashMap<String,Float> valorTotal = new HashMap<String,Float>(); | |
| 54 | + ArrayList<String> xVals = new ArrayList<String>(); | |
| 55 | + ArrayList<BarEntry> yVals1 = new ArrayList<BarEntry>(); | |
| 56 | + private RecyclerView mRecyclerView; | |
| 57 | + private GastoAdapter mAdapter; | |
| 58 | + List<Grafico> myDataset=new ArrayList<Grafico>(); | |
| 59 | + List<String> tipos = new ArrayList<String>(); | |
| 60 | + int[] cores = new int[]{R.color.cor1, R.color.cor2,R.color.cor3, R.color.cor4,R.color.cor5, R.color.cor6, | |
| 61 | + R.color.cor7, R.color.cor8,R.color.cor9, R.color.cor10}; | |
| 62 | + | |
| 63 | + private ProgressBar pb; | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + private OnFragmentInteractionListener mListener; | |
| 68 | + | |
| 69 | + /** | |
| 70 | + * Use this factory method to create a new instance of | |
| 71 | + * this fragment using the provided parameters. | |
| 72 | + * | |
| 73 | + * @param param1 Parameter 1. | |
| 74 | + * @param param2 Parameter 2. | |
| 75 | + * @return A new instance of fragment GastosCamaraFragment. | |
| 76 | + */ | |
| 77 | + // TODO: Rename and change types and number of parameters | |
| 78 | + public static GastosCamaraFragment newInstance(String param1, String param2) { | |
| 79 | + GastosCamaraFragment fragment = new GastosCamaraFragment(); | |
| 80 | + Bundle args = new Bundle(); | |
| 81 | +// args.putString(ARG_PARAM1, param1); | |
| 82 | +// args.putString(ARG_PARAM2, param2); | |
| 83 | + fragment.setArguments(args); | |
| 84 | + return fragment; | |
| 85 | + } | |
| 86 | + | |
| 87 | + public GastosCamaraFragment() { | |
| 88 | + // Required empty public constructor | |
| 89 | + } | |
| 90 | + | |
| 91 | + @Override | |
| 92 | + public void onCreate(Bundle savedInstanceState) { | |
| 93 | + super.onCreate(savedInstanceState); | |
| 94 | + if (getArguments() != null) { | |
| 95 | +// mParam1 = getArguments().getString(ARG_PARAM1); | |
| 96 | +// mParam2 = getArguments().getString(ARG_PARAM2); | |
| 97 | + } | |
| 98 | + } | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + @Override | |
| 103 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, | |
| 104 | + Bundle savedInstanceState) { | |
| 105 | + // Inflate the layout for this fragment | |
| 106 | + View view =inflater.inflate(R.layout.fragment_lista_projetos, container, false); | |
| 107 | + pb = (ProgressBar) view.findViewById(R.id.progressBar); | |
| 108 | +// pb.setVisibility(View.VISIBLE); | |
| 109 | + mView=view; | |
| 110 | +// mChart = (BarChart) view.findViewById(R.id.chart1); | |
| 111 | +// mChart.setVisibility(View.GONE); | |
| 112 | +// buildGraph(); | |
| 113 | + | |
| 114 | + //tableview | |
| 115 | + mRecyclerView = (RecyclerView) view.findViewById(R.id.my_recycler_view); | |
| 116 | + | |
| 117 | + // use this setting to improve performance if you know that changes | |
| 118 | + // in content do not change the layout size of the RecyclerView | |
| 119 | + mRecyclerView.setHasFixedSize(true); | |
| 120 | + | |
| 121 | + LinearLayoutManager llm = new LinearLayoutManager(getActivity()); | |
| 122 | + llm.setOrientation(LinearLayoutManager.VERTICAL); | |
| 123 | + mRecyclerView.setLayoutManager(llm); | |
| 124 | + buscaGastos(); | |
| 125 | + return view; | |
| 126 | + } | |
| 127 | + | |
| 128 | + private ParseObject buscaGastos() { | |
| 129 | + | |
| 130 | + | |
| 131 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("DespesaCamara"); | |
| 132 | + query.setLimit(200); | |
| 133 | + //query.whereEqualTo("politico",politico); | |
| 134 | + | |
| 135 | + query.addAscendingOrder("mes_numero"); | |
| 136 | + query.findInBackground(new FindCallback<ParseObject>() { | |
| 137 | + public void done(List<ParseObject> gastos, ParseException e) { | |
| 138 | + | |
| 139 | + Iterator<ParseObject> gastoIt = gastos.iterator(); | |
| 140 | + | |
| 141 | + while (gastoIt.hasNext()) { | |
| 142 | + | |
| 143 | + ParseObject g = gastoIt.next(); | |
| 144 | + String mes = g.getString("mes"); | |
| 145 | + Float novoValor = Float.valueOf(g.getString("valor")); | |
| 146 | + | |
| 147 | + String tipo = g.getString("tipo"); | |
| 148 | + if(!tipos.contains(tipo)){ | |
| 149 | + tipos.add(tipo); | |
| 150 | + } | |
| 151 | + //verifica tipo | |
| 152 | + HashMap<String,Float> data = dataset.get(tipo); | |
| 153 | + if(data != null){ | |
| 154 | + //verifica se tem o valor por mes | |
| 155 | + Float valorMesTipo = data.get(mes); | |
| 156 | + if(valorMesTipo != null){ | |
| 157 | + valorMesTipo = valorMesTipo +novoValor; | |
| 158 | + data.remove(mes); | |
| 159 | + data.put(mes, valorMesTipo); | |
| 160 | + }else{ | |
| 161 | + data.put(mes,novoValor); | |
| 162 | + } | |
| 163 | + | |
| 164 | + | |
| 165 | + }else{ | |
| 166 | + data = new HashMap<String, Float>(); | |
| 167 | + data.put(mes,novoValor); | |
| 168 | + dataset.put(tipo,data); | |
| 169 | + } | |
| 170 | + | |
| 171 | + | |
| 172 | + Float valor = valorTotal.get(mes); | |
| 173 | + if (valor != null) { | |
| 174 | + valor = valor + novoValor; | |
| 175 | + valorTotal.remove(mes); | |
| 176 | + valorTotal.put(mes, valor); | |
| 177 | + } else { | |
| 178 | + valorTotal.put(mes, novoValor); | |
| 179 | + } | |
| 180 | + if (!xVals.contains(mes)) { | |
| 181 | + xVals.add(mes); | |
| 182 | + } | |
| 183 | + | |
| 184 | + // | |
| 185 | + | |
| 186 | + | |
| 187 | + } | |
| 188 | + for (int j = 0; j < xVals.size(); j++) { | |
| 189 | + Float val = valorTotal.get(xVals.get(j)); | |
| 190 | + yVals1.add(new BarEntry(val, j)); | |
| 191 | + } | |
| 192 | + Grafico grafico = new Grafico("Todos", yVals1, xVals, R.color.cor10); | |
| 193 | + myDataset.add(grafico); | |
| 194 | + | |
| 195 | + //adicionar os outros graficos | |
| 196 | + for(int i=0; i < tipos.size();i++ ){ | |
| 197 | + HashMap<String,Float> temp = dataset.get(tipos.get(i)); | |
| 198 | + ArrayList<String> x = new ArrayList<String>(); | |
| 199 | + for ( int k=0; k < temp.size(); k++ ) { | |
| 200 | + x.add(k,""); | |
| 201 | + } | |
| 202 | + ArrayList<BarEntry> y = new ArrayList<BarEntry>(); | |
| 203 | + for ( String mes : temp.keySet() ) { | |
| 204 | + if(!x.contains(mes)){ | |
| 205 | + int pos = buscaPosicao(mes); | |
| 206 | + x.remove(pos); | |
| 207 | + x.add(pos, mes); | |
| 208 | + } | |
| 209 | + Float val = temp.get(mes); | |
| 210 | + y.add(new BarEntry(val, x.indexOf(mes))); | |
| 211 | + } | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + myDataset.add(new Grafico(tipos.get(i),y,x,cores[i])); | |
| 216 | + } | |
| 217 | + | |
| 218 | + carregaList(); | |
| 219 | + pb.setVisibility(View.INVISIBLE); | |
| 220 | + | |
| 221 | + // setData(); | |
| 222 | + | |
| 223 | + } | |
| 224 | + }); | |
| 225 | + | |
| 226 | + | |
| 227 | + return null; | |
| 228 | + } | |
| 229 | + | |
| 230 | + private int buscaPosicao(String mes) { | |
| 231 | + int ret=0; | |
| 232 | + switch (mes){ | |
| 233 | + case "JAN": | |
| 234 | + ret=0; | |
| 235 | + break; | |
| 236 | + case "FEV": | |
| 237 | + ret=1; | |
| 238 | + break; | |
| 239 | + case "MAR": | |
| 240 | + ret=2; | |
| 241 | + break; | |
| 242 | + case "ABR": | |
| 243 | + ret=3; | |
| 244 | + break; | |
| 245 | + case "MAI": | |
| 246 | + ret=4; | |
| 247 | + break; | |
| 248 | + | |
| 249 | + } | |
| 250 | + return ret; | |
| 251 | + } | |
| 252 | + | |
| 253 | + public void carregaList(){ | |
| 254 | + mAdapter = new GastoAdapter(myDataset); | |
| 255 | +// mAdapter.setRecyclerViewOnClickListenerHack(this); | |
| 256 | + mRecyclerView.setAdapter(mAdapter); | |
| 257 | +// pb.setVisibility(View.INVISIBLE); | |
| 258 | + } | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + private void buildGraph() { | |
| 263 | + | |
| 264 | +// mChart.set | |
| 265 | + | |
| 266 | + mChart.setDrawBarShadow(false); | |
| 267 | + mChart.setDrawValueAboveBar(true); | |
| 268 | + | |
| 269 | + mChart.setDescription(""); | |
| 270 | + | |
| 271 | + // if more than 60 entries are displayed in the chart, no values will be | |
| 272 | + // drawn | |
| 273 | + mChart.setMaxVisibleValueCount(60); | |
| 274 | + | |
| 275 | + // scaling can now only be done on x- and y-axis separately | |
| 276 | + mChart.setPinchZoom(false); | |
| 277 | + | |
| 278 | + // draw shadows for each bar that show the maximum value | |
| 279 | + // mChart.setDrawBarShadow(true); | |
| 280 | + | |
| 281 | + // mChart.setDrawXLabels(false); | |
| 282 | + | |
| 283 | + mChart.setDrawGridBackground(false); | |
| 284 | + // mChart.setDrawYLabels(false); | |
| 285 | + | |
| 286 | +// mTf = Typeface.createFromAsset(getAssets(), "OpenSans-Regular.ttf"); | |
| 287 | + | |
| 288 | + XAxis xAxis = mChart.getXAxis(); | |
| 289 | + xAxis.setPosition(XAxis.XAxisPosition.BOTTOM); | |
| 290 | +// xAxis.setTypeface(mTf); | |
| 291 | + xAxis.setDrawGridLines(false); | |
| 292 | + xAxis.setSpaceBetweenLabels(2); | |
| 293 | + | |
| 294 | + ValueFormatter custom = new MyValueFormatter(); | |
| 295 | + | |
| 296 | + YAxis leftAxis = mChart.getAxisLeft(); | |
| 297 | +// leftAxis.setTypeface(mTf); | |
| 298 | + leftAxis.setLabelCount(8); | |
| 299 | + leftAxis.setValueFormatter(custom); | |
| 300 | + leftAxis.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART); | |
| 301 | + leftAxis.setSpaceTop(15f); | |
| 302 | + | |
| 303 | + mChart.getAxisRight().setEnabled(false); | |
| 304 | + YAxis rightAxis = mChart.getAxisRight(); | |
| 305 | + rightAxis.setDrawGridLines(false); | |
| 306 | +// rightAxis.setTypeface(mTf); | |
| 307 | + rightAxis.setLabelCount(8); | |
| 308 | + rightAxis.setValueFormatter(custom); | |
| 309 | + rightAxis.setSpaceTop(15f); | |
| 310 | + | |
| 311 | + Legend l = mChart.getLegend(); | |
| 312 | + l.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT); | |
| 313 | + l.setForm(Legend.LegendForm.SQUARE); | |
| 314 | + l.setFormSize(9f); | |
| 315 | + l.setTextSize(11f); | |
| 316 | + l.setXEntrySpace(4f); | |
| 317 | + // l.setExtra(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", | |
| 318 | + // "def", "ghj", "ikl", "mno" }); | |
| 319 | + // l.setCustom(ColorTemplate.VORDIPLOM_COLORS, new String[] { "abc", | |
| 320 | + // "def", "ghj", "ikl", "mno" }); | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + // setting data | |
| 325 | +// mSeekBarY.setProgress(50); | |
| 326 | +// mSeekBarX.setProgress(12); | |
| 327 | +// | |
| 328 | +// mSeekBarY.setOnSeekBarChangeListener(this); | |
| 329 | +// mSeekBarX.setOnSeekBarChangeListener(this); | |
| 330 | + | |
| 331 | + // mChart.setDrawLegend(false); | |
| 332 | + | |
| 333 | + } | |
| 334 | + | |
| 335 | + private void setData() { | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + BarDataSet set1 = new BarDataSet(yVals1, "Gastos Totais"); | |
| 340 | + set1.setBarSpacePercent(35f); | |
| 341 | + | |
| 342 | + ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>(); | |
| 343 | + dataSets.add(set1); | |
| 344 | + try{ | |
| 345 | + set1.setColor(getActivity().getResources().getColor(R.color.colorPrimaryLight)); | |
| 346 | + | |
| 347 | + BarData data = new BarData(xVals, dataSets); | |
| 348 | + // data.setValueFormatter(new MyValueFormatter()); | |
| 349 | + data.setValueTextSize(10f); | |
| 350 | +// data.setValueTypeface(mTf); | |
| 351 | + | |
| 352 | + mChart.setData(data); | |
| 353 | + mChart.animateX(2500, Easing.EasingOption.EaseInOutQuart); | |
| 354 | + mChart.notifyDataSetChanged(); | |
| 355 | + | |
| 356 | +// pb.setVisibility(View.GONE); | |
| 357 | + mChart.setVisibility(View.VISIBLE); | |
| 358 | + }catch (Exception e){ | |
| 359 | + Crashlytics.log("GastosCamaraFragment "+e.toString()); | |
| 360 | + } | |
| 361 | + | |
| 362 | + } | |
| 363 | + | |
| 364 | + | |
| 365 | + // TODO: Rename method, update argument and hook method into UI event | |
| 366 | + public void onButtonPressed(Uri uri) { | |
| 367 | + if (mListener != null) { | |
| 368 | + mListener.onFragmentInteraction(uri); | |
| 369 | + } | |
| 370 | + } | |
| 371 | + | |
| 372 | + @Override | |
| 373 | + public void onAttach(Activity activity) { | |
| 374 | + super.onAttach(activity); | |
| 375 | +// try { | |
| 376 | +// mListener = (OnFragmentInteractionListener) activity; | |
| 377 | +// } catch (ClassCastException e) { | |
| 378 | +// throw new ClassCastException(activity.toString() | |
| 379 | +// + " must implement OnFragmentInteractionListener"); | |
| 380 | +// } | |
| 381 | + } | |
| 382 | + | |
| 383 | + @Override | |
| 384 | + public void onDetach() { | |
| 385 | + super.onDetach(); | |
| 386 | + mListener = null; | |
| 387 | + } | |
| 388 | + | |
| 389 | + /** | |
| 390 | + * This interface must be implemented by activities that contain this | |
| 391 | + * fragment to allow an interaction in this fragment to be communicated | |
| 392 | + * to the activity and potentially other fragments contained in that | |
| 393 | + * activity. | |
| 394 | + * <p/> | |
| 395 | + * See the Android Training lesson <a href= | |
| 396 | + * "http://developer.android.com/training/basics/fragments/communicating.html" | |
| 397 | + * >Communicating with Other Fragments</a> for more information. | |
| 398 | + */ | |
| 399 | + public interface OnFragmentInteractionListener { | |
| 400 | + // TODO: Update argument type and name | |
| 401 | + public void onFragmentInteraction(Uri uri); | |
| 402 | + } | |
| 403 | + | |
| 404 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/fragments/GastosFragment.java
0 → 100644
| ... | ... | @@ -0,0 +1,214 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.fragments; | |
| 2 | + | |
| 3 | +import android.graphics.Color; | |
| 4 | +import android.os.Bundle; | |
| 5 | +import android.support.v4.app.Fragment; | |
| 6 | +import android.util.Log; | |
| 7 | +import android.view.LayoutInflater; | |
| 8 | +import android.view.View; | |
| 9 | +import android.view.ViewGroup; | |
| 10 | + | |
| 11 | +import com.github.mikephil.charting.animation.Easing; | |
| 12 | +import com.github.mikephil.charting.charts.LineChart; | |
| 13 | +import com.github.mikephil.charting.components.Legend; | |
| 14 | +import com.github.mikephil.charting.components.LimitLine; | |
| 15 | +import com.github.mikephil.charting.components.YAxis; | |
| 16 | +import com.github.mikephil.charting.data.Entry; | |
| 17 | +import com.github.mikephil.charting.data.LineData; | |
| 18 | +import com.github.mikephil.charting.data.LineDataSet; | |
| 19 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 20 | +import com.monitorabrasil.monitoralegislativo.classes.Grafico; | |
| 21 | +import com.parse.FindCallback; | |
| 22 | +import com.parse.ParseException; | |
| 23 | +import com.parse.ParseObject; | |
| 24 | +import com.parse.ParseQuery; | |
| 25 | +import com.parse.ParseUser; | |
| 26 | + | |
| 27 | +import java.lang.reflect.Array; | |
| 28 | +import java.util.ArrayList; | |
| 29 | +import java.util.Iterator; | |
| 30 | +import java.util.List; | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * Created by geral_000 on 20/06/2015. | |
| 34 | + */ | |
| 35 | +public class GastosFragment extends Fragment { | |
| 36 | + | |
| 37 | + private LineChart mChart; | |
| 38 | + private ParseObject politico; | |
| 39 | + float maximo = 0f, minimo = 0f; | |
| 40 | + View mView; | |
| 41 | + ArrayList<String> xVals = new ArrayList<String>(); | |
| 42 | + ArrayList<Entry> yVals = new ArrayList<Entry>(); | |
| 43 | + private ArrayList<Grafico> graficos =new ArrayList<Grafico>(); | |
| 44 | + | |
| 45 | + public View onCreateView(LayoutInflater inflater, | |
| 46 | + ViewGroup container, | |
| 47 | + Bundle savedInstanceState) { | |
| 48 | + View view = inflater.inflate(R.layout.fragment_politico_gastos, container, false); | |
| 49 | + | |
| 50 | + Bundle bundle = getArguments(); | |
| 51 | + politico = buscaGastos(bundle.getString("politico")) ; | |
| 52 | + | |
| 53 | + mView=view; | |
| 54 | + | |
| 55 | + return view; | |
| 56 | + } | |
| 57 | + | |
| 58 | + private void buildGraph(){ | |
| 59 | + mChart = (LineChart)mView.findViewById(R.id.chart1); | |
| 60 | + | |
| 61 | + mChart.setDrawGridBackground(false); | |
| 62 | + | |
| 63 | + | |
| 64 | + mChart.setDescription(""); | |
| 65 | + mChart.setNoDataTextDescription("You need to provide data for the chart."); | |
| 66 | + | |
| 67 | + // enable value highlighting | |
| 68 | + mChart.setHighlightEnabled(true); | |
| 69 | + | |
| 70 | + // enable touch gestures | |
| 71 | + mChart.setTouchEnabled(true); | |
| 72 | + | |
| 73 | + // enable scaling and dragging | |
| 74 | + mChart.setDragEnabled(true); | |
| 75 | + mChart.setScaleEnabled(true); | |
| 76 | + // mChart.setScaleXEnabled(true); | |
| 77 | + // mChart.setScaleYEnabled(true); | |
| 78 | + | |
| 79 | + // if disabled, scaling can be done on x- and y-axis separately | |
| 80 | + mChart.setPinchZoom(true); | |
| 81 | + | |
| 82 | + // enable/disable highlight indicators (the lines that indicate the | |
| 83 | + // highlighted Entry) | |
| 84 | + mChart.setHighlightEnabled(false); | |
| 85 | + | |
| 86 | + LimitLine ll1 = new LimitLine(130f, "Upper Limit"); | |
| 87 | + ll1.setLineWidth(4f); | |
| 88 | + ll1.enableDashedLine(10f, 10f, 0f); | |
| 89 | + ll1.setLabelPosition(LimitLine.LimitLabelPosition.POS_RIGHT); | |
| 90 | + ll1.setTextSize(10f); | |
| 91 | + | |
| 92 | + LimitLine ll2 = new LimitLine(-30f, "Lower Limit"); | |
| 93 | + ll2.setLineWidth(4f); | |
| 94 | + ll2.enableDashedLine(10f, 10f, 0f); | |
| 95 | + ll2.setLabelPosition(LimitLine.LimitLabelPosition.POS_RIGHT); | |
| 96 | + ll2.setTextSize(10f); | |
| 97 | + | |
| 98 | + YAxis leftAxis = mChart.getAxisLeft(); | |
| 99 | + leftAxis.removeAllLimitLines(); // reset all limit lines to avoid overlapping lines | |
| 100 | + //leftAxis.addLimitLine(ll1); | |
| 101 | + //leftAxis.addLimitLine(ll2); | |
| 102 | + leftAxis.setAxisMaxValue(maximo + 200); | |
| 103 | + minimo = minimo-200; | |
| 104 | + if(minimo < 0f){ | |
| 105 | + minimo=0f; | |
| 106 | + } | |
| 107 | + leftAxis.setAxisMinValue(minimo); | |
| 108 | + leftAxis.setStartAtZero(false); | |
| 109 | + //leftAxis.setYOffset(20f); | |
| 110 | + leftAxis.enableGridDashedLine(10f, 10f, 0f); | |
| 111 | + | |
| 112 | + // limit lines are drawn behind data (and not on top) | |
| 113 | + leftAxis.setDrawLimitLinesBehindData(true); | |
| 114 | + | |
| 115 | + mChart.getAxisRight().setEnabled(false); | |
| 116 | + | |
| 117 | + // add data | |
| 118 | + setData(); | |
| 119 | + | |
| 120 | +// mChart.setVisibleXRange(20); | |
| 121 | +// mChart.setVisibleYRange(20f, AxisDependency.LEFT); | |
| 122 | +// mChart.centerViewTo(20, 50, AxisDependency.LEFT); | |
| 123 | + | |
| 124 | + mChart.animateX(2500, Easing.EasingOption.EaseInOutQuart); | |
| 125 | +// mChart.invalidate(); | |
| 126 | + | |
| 127 | + // get the legend (only possible after setting data) | |
| 128 | + Legend l = mChart.getLegend(); | |
| 129 | + | |
| 130 | + // modify the legend ... | |
| 131 | + // l.setPosition(LegendPosition.LEFT_OF_CHART); | |
| 132 | + l.setForm(Legend.LegendForm.LINE); | |
| 133 | + } | |
| 134 | + | |
| 135 | + private ParseObject buscaGastos(String id) { | |
| 136 | + | |
| 137 | + ParseObject politico = buscaPolitico(id); | |
| 138 | + xVals =new ArrayList<String>(); | |
| 139 | + yVals = new ArrayList<Entry>(); | |
| 140 | + maximo = 0f; | |
| 141 | + minimo = 0f; | |
| 142 | + | |
| 143 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Verba"); | |
| 144 | + query.whereEqualTo("politico",politico); | |
| 145 | + query.findInBackground(new FindCallback<ParseObject>() { | |
| 146 | + public void done(List<ParseObject> gastos, ParseException e) { | |
| 147 | + Iterator<ParseObject> gastoIt = gastos.iterator(); | |
| 148 | + int i=0; | |
| 149 | + while (gastoIt.hasNext()) { | |
| 150 | + ParseObject g = gastoIt.next(); | |
| 151 | + float possivelMaximo = Float.valueOf(g.getString("valor")); | |
| 152 | + if(possivelMaximo > maximo ){ | |
| 153 | + maximo = possivelMaximo; | |
| 154 | + } | |
| 155 | + if(minimo > possivelMaximo || i==0){ | |
| 156 | + minimo=possivelMaximo; | |
| 157 | + } | |
| 158 | + xVals.add(g.getString("mes").substring(0,3)+" "+g.getString("ano")); | |
| 159 | + yVals.add(new Entry(possivelMaximo, i)); | |
| 160 | + i++; | |
| 161 | + } | |
| 162 | + buildGraph(); | |
| 163 | + } | |
| 164 | + }); | |
| 165 | + | |
| 166 | + return null; | |
| 167 | + } | |
| 168 | + | |
| 169 | + private ParseObject buscaPolitico(String id) { | |
| 170 | + | |
| 171 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 172 | + query.fromLocalDatastore(); | |
| 173 | + try { | |
| 174 | + return query.get(id); | |
| 175 | + } catch (com.parse.ParseException e) { | |
| 176 | + e.printStackTrace(); | |
| 177 | + } | |
| 178 | + return null; | |
| 179 | + } | |
| 180 | + | |
| 181 | + private void setData() { | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + // create a dataset and give it a type | |
| 186 | + LineDataSet set1 = new LineDataSet(yVals, "Verba idenizatoria"); | |
| 187 | + set1.setFillAlpha(110); | |
| 188 | + set1.setFillColor(Color.RED); | |
| 189 | + | |
| 190 | + // set the line to be drawn like this "- - - - - -" | |
| 191 | + set1.enableDashedLine(10f, 5f, 0f); | |
| 192 | + set1.setColor(Color.BLACK); | |
| 193 | + set1.setCircleColor(Color.BLACK); | |
| 194 | + set1.setLineWidth(1f); | |
| 195 | + set1.setCircleSize(3f); | |
| 196 | + set1.setDrawCircleHole(false); | |
| 197 | + set1.setValueTextSize(9f); | |
| 198 | + set1.setFillAlpha(65); | |
| 199 | + set1.setFillColor(Color.BLACK); | |
| 200 | +// set1.setDrawFilled(true); | |
| 201 | + // set1.setShader(new LinearGradient(0, 0, 0, mChart.getHeight(), | |
| 202 | + // Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR)); | |
| 203 | + | |
| 204 | + ArrayList<LineDataSet> dataSets = new ArrayList<LineDataSet>(); | |
| 205 | + dataSets.add(set1); // add the datasets | |
| 206 | + | |
| 207 | + // create a data object with the datasets | |
| 208 | + LineData data = new LineData(xVals, dataSets); | |
| 209 | + | |
| 210 | + // set data | |
| 211 | + mChart.setData(data); | |
| 212 | + } | |
| 213 | +} | |
| 214 | + | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/fragments/PoliticoFichaFragment.java
0 → 100644
| ... | ... | @@ -0,0 +1,75 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.fragments; | |
| 2 | + | |
| 3 | +import android.os.Bundle; | |
| 4 | +import android.support.v4.app.Fragment; | |
| 5 | +import android.util.Log; | |
| 6 | +import android.view.LayoutInflater; | |
| 7 | +import android.view.View; | |
| 8 | +import android.view.ViewGroup; | |
| 9 | +import android.widget.TextView; | |
| 10 | + | |
| 11 | +import com.monitorabrasil.monitoralegislativo.R; | |
| 12 | +import com.parse.ParseObject; | |
| 13 | +import com.parse.ParseQuery; | |
| 14 | + | |
| 15 | +/** | |
| 16 | + * Created by geral_000 on 20/06/2015. | |
| 17 | + */ | |
| 18 | +public class PoliticoFichaFragment extends Fragment { | |
| 19 | + | |
| 20 | + | |
| 21 | + private ParseObject politico; | |
| 22 | + View mView; | |
| 23 | + public View onCreateView(LayoutInflater inflater, | |
| 24 | + ViewGroup container, | |
| 25 | + Bundle savedInstanceState) { | |
| 26 | + View view = inflater.inflate(R.layout.fragment_politico_detalhe, container, false); | |
| 27 | + mView=view; | |
| 28 | + | |
| 29 | + Bundle bundle = getArguments(); | |
| 30 | + politico = buscaPolitico(bundle.getString("politico")) ; | |
| 31 | + //nome | |
| 32 | + TextView txtNome = (TextView) view.findViewById(R.id.txtNome); | |
| 33 | + txtNome.setText(politico.get("nome").toString()); | |
| 34 | + | |
| 35 | + //telefone | |
| 36 | + TextView telefone = (TextView) view.findViewById(R.id.txtTelefone); | |
| 37 | + telefone.setText(politico.get("telefone").toString()); | |
| 38 | + //telefone | |
| 39 | + TextView txtPartido = (TextView) view.findViewById(R.id.txtPartido); | |
| 40 | + txtPartido.setText(politico.get("partido").toString()); | |
| 41 | ||
| 42 | + TextView email = (TextView) view.findViewById(R.id.email); | |
| 43 | + email.setText(politico.get("email").toString()); | |
| 44 | ||
| 45 | + TextView facebook = (TextView) view.findViewById(R.id.facebook); | |
| 46 | + facebook.setText(politico.get("facebook").toString()); | |
| 47 | + //gastos | |
| 48 | + TextView gastos = (TextView) view.findViewById(R.id.gastos); | |
| 49 | + gastos.setText(politico.get("gasto_campanha").toString()); | |
| 50 | + //bens declarados | |
| 51 | + TextView bens = (TextView) view.findViewById(R.id.bens); | |
| 52 | + bens.setText(politico.get("bens_declarados").toString()); | |
| 53 | + | |
| 54 | + return view; | |
| 55 | + } | |
| 56 | + | |
| 57 | + @Override | |
| 58 | + public void onResume() { | |
| 59 | + Log.e("DEBUG", "onResume of HomeFragment"); | |
| 60 | + super.onResume(); | |
| 61 | + } | |
| 62 | + | |
| 63 | + | |
| 64 | + private ParseObject buscaPolitico(String id) { | |
| 65 | + | |
| 66 | + ParseQuery<ParseObject> query = ParseQuery.getQuery("Politico"); | |
| 67 | + query.fromLocalDatastore(); | |
| 68 | + try { | |
| 69 | + return query.get(id); | |
| 70 | + } catch (com.parse.ParseException e) { | |
| 71 | + e.printStackTrace(); | |
| 72 | + } | |
| 73 | + return null; | |
| 74 | + } | |
| 75 | +} | ... | ... |
app/src/main/java/com/monitorabrasil/monitoralegislativo/util/MyValueFormatter.java
0 → 100644
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +package com.monitorabrasil.monitoralegislativo.util; | |
| 2 | + | |
| 3 | +import com.github.mikephil.charting.utils.ValueFormatter; | |
| 4 | + | |
| 5 | +import java.text.DecimalFormat; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Created by geral_000 on 21/06/2015. | |
| 9 | + */ | |
| 10 | +public class MyValueFormatter implements ValueFormatter { | |
| 11 | + | |
| 12 | + private DecimalFormat mFormat; | |
| 13 | + | |
| 14 | + public MyValueFormatter() { | |
| 15 | + mFormat = new DecimalFormat("###,###,###,##0.0"); | |
| 16 | + } | |
| 17 | + | |
| 18 | + @Override | |
| 19 | + public String getFormattedValue(float value) { | |
| 20 | + return "R$" + mFormat.format(value) ; | |
| 21 | + } | |
| 22 | + | |
| 23 | +} | ... | ... |
297 Bytes
| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 2 | + xmlns:tools="http://schemas.android.com/tools" | |
| 3 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 4 | + android:layout_width="match_parent" | |
| 5 | + android:layout_height="match_parent" | |
| 6 | + android:paddingTop="@dimen/activity_horizontal_margin" | |
| 7 | + android:background="@color/grey" | |
| 8 | + android:orientation="vertical" | |
| 9 | + tools:context="com.monitorabrasil.monitoralegislativo.CamaraActivity"> | |
| 10 | + | |
| 11 | + <android.support.v7.widget.Toolbar | |
| 12 | + android:id="@+id/toolbar" | |
| 13 | + android:elevation="0dp" | |
| 14 | + android:layout_height="?attr/actionBarSize" | |
| 15 | + android:layout_width="match_parent" | |
| 16 | + android:minHeight="?attr/actionBarSize" | |
| 17 | + android:layout_alignParentLeft="true" | |
| 18 | + android:navigationIcon="@style/DrawerArrowStyle" | |
| 19 | + android:background="?attr/colorPrimary" | |
| 20 | + | |
| 21 | + /> | |
| 22 | + <RelativeLayout | |
| 23 | + android:id="@+id/rl_fragment_container" | |
| 24 | + android:layout_width="match_parent" | |
| 25 | + android:layout_height="match_parent"> | |
| 26 | + | |
| 27 | + </RelativeLayout> | |
| 28 | +</LinearLayout> | |
| 29 | + | |
| 30 | + | ... | ... |
| ... | ... | @@ -0,0 +1,26 @@ |
| 1 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 2 | + android:orientation="vertical" android:layout_width="match_parent" | |
| 3 | + android:paddingTop="50dp" | |
| 4 | + android:layout_height="match_parent"> | |
| 5 | + | |
| 6 | + <TextView | |
| 7 | + android:layout_width="wrap_content" | |
| 8 | + android:layout_height="wrap_content" | |
| 9 | + android:textAppearance="?android:attr/textAppearanceLarge" | |
| 10 | + android:text="Gastos Totais" | |
| 11 | + android:id="@+id/textView" | |
| 12 | + android:layout_gravity="center_horizontal" /> | |
| 13 | + | |
| 14 | + <ProgressBar | |
| 15 | + android:layout_width="wrap_content" | |
| 16 | + android:layout_height="wrap_content" | |
| 17 | + android:id="@+id/progressBar2" | |
| 18 | + android:layout_gravity="center_horizontal" | |
| 19 | + android:indeterminate="false" /> | |
| 20 | + | |
| 21 | + <com.github.mikephil.charting.charts.BarChart | |
| 22 | + android:id="@+id/chart1" | |
| 23 | + android:layout_width="match_parent" | |
| 24 | + android:layout_height="match_parent" /> | |
| 25 | + | |
| 26 | +</LinearLayout> | ... | ... |
| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + android:orientation="vertical" android:layout_width="match_parent" | |
| 4 | + android:paddingTop="50dp" | |
| 5 | + android:layout_height="match_parent"> | |
| 6 | + | |
| 7 | + <com.github.mikephil.charting.charts.LineChart | |
| 8 | + android:id="@+id/chart1" | |
| 9 | + android:layout_width="match_parent" | |
| 10 | + android:layout_height="match_parent" /> | |
| 11 | + | |
| 12 | +</LinearLayout> | |
| 0 | 13 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | +<?xml version="1.0" encoding="utf-8"?> | |
| 2 | +<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| 3 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 4 | + android:id="@+id/main_content" | |
| 5 | + android:layout_width="match_parent" | |
| 6 | + android:layout_height="match_parent"> | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + <android.support.design.widget.TabLayout | |
| 11 | + android:id="@+id/tabs" | |
| 12 | + android:layout_width="match_parent" | |
| 13 | + android:layout_height="wrap_content" /> | |
| 14 | + | |
| 15 | + | |
| 16 | + <android.support.v4.view.ViewPager | |
| 17 | + android:id="@+id/viewpager" | |
| 18 | + android:layout_width="match_parent" | |
| 19 | + android:layout_height="match_parent" | |
| 20 | + app:layout_behavior="@string/appbar_scrolling_view_behavior" /> | |
| 21 | + | |
| 22 | + <android.support.design.widget.FloatingActionButton | |
| 23 | + android:id="@+id/fab" | |
| 24 | + android:layout_width="wrap_content" | |
| 25 | + android:layout_height="wrap_content" | |
| 26 | + android:layout_gravity="end|bottom" | |
| 27 | + android:layout_margin="@dimen/fab_margin" | |
| 28 | + android:src="@drawable/ic_done" /> | |
| 29 | + | |
| 30 | +</android.support.design.widget.CoordinatorLayout> | |
| 0 | 31 | \ No newline at end of file | ... | ... |
| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | +<menu xmlns:android="http://schemas.android.com/apk/res/android" | |
| 2 | + xmlns:app="http://schemas.android.com/apk/res-auto" | |
| 3 | + xmlns:tools="http://schemas.android.com/tools" | |
| 4 | + tools:context="com.monitorabrasil.monitoralegislativo.CamaraActivity"> | |
| 5 | + <item android:id="@+id/action_settings" android:title="@string/action_settings" | |
| 6 | + android:orderInCategory="100" app:showAsAction="never" /> | |
| 7 | +</menu> | ... | ... |