tuttelikz

Result Activity [v3] with Max and Min Frequency

Oct 31st, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 10.80 KB | None | 0 0
  1. package com.example.iptea.audio22;
  2.  
  3. import android.content.Intent;
  4. import android.graphics.Color;
  5. import android.graphics.Paint;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.ImageView;
  12.  
  13. import com.github.mikephil.charting.charts.BarChart;
  14. import com.github.mikephil.charting.charts.CandleStickChart;
  15. import com.github.mikephil.charting.charts.HorizontalBarChart;
  16. import com.github.mikephil.charting.components.Legend;
  17. import com.github.mikephil.charting.components.XAxis;
  18. import com.github.mikephil.charting.components.YAxis;
  19. import com.github.mikephil.charting.data.BarData;
  20. import com.github.mikephil.charting.data.BarDataSet;
  21. import com.github.mikephil.charting.data.BarEntry;
  22. import com.github.mikephil.charting.data.CandleData;
  23. import com.github.mikephil.charting.data.CandleDataSet;
  24. import com.github.mikephil.charting.data.CandleEntry;
  25. import com.github.mikephil.charting.utils.ColorTemplate;
  26.  
  27. import java.sql.Array;
  28. import java.sql.Date;
  29. import java.text.ParseException;
  30. import java.text.SimpleDateFormat;
  31. import java.util.ArrayList;
  32. import java.util.Calendar;
  33. import java.util.List;
  34. import java.util.Random;
  35.  
  36. public class ResultActivity extends AppCompatActivity {
  37.     Button btShare;
  38.     /*HorizontalBarChart barChart;*/
  39.     CandleStickChart barChart;
  40.  
  41.     ArrayList<String> dates;
  42.     Random random;
  43.     ArrayList<BarEntry> barEntries;
  44.     int max_frequency;
  45.     int min_frequency;
  46.     String data1;
  47.     String data2;
  48.  
  49.     @Override
  50.     protected void onCreate(Bundle savedInstanceState) {
  51.         super.onCreate(savedInstanceState);
  52.         setContentView(R.layout.activity_result);
  53.         btShare = (Button)findViewById(R.id.shareButton);
  54.         /*barChart = (HorizontalBarChart) findViewById(R.id.barGraph);*/
  55.  
  56.  
  57.  
  58.  
  59. /*        barChart = (CandleStickChart) findViewById(R.id.barGraph);
  60.  
  61.         *//*createRandomBarGraph("2017/10/21", "2017/10/30");*//*
  62.         barChart.setTouchEnabled(true);
  63.         barChart.setDragEnabled(true);
  64.         barChart.setScaleEnabled(true);
  65.  
  66.  
  67.         List<CandleEntry> ceList = new ArrayList<>();
  68.         ceList.add(new CandleEntry(0, 4.62f, 2.02f, 2.70f, 4.13f));
  69.         ceList.add(new CandleEntry(1, 5.50f, 2.70f, 3.35f, 4.96f));
  70.         ceList.add(new CandleEntry(2, 5.25f, 3.02f, 3.50f, 4.50f));
  71.         ceList.add(new CandleEntry(3, 6f,    3.25f, 4.40f, 5.0f));
  72.         ceList.add(new CandleEntry(4, 5.57f, 2f,    2.80f, 4.5f));
  73.  
  74.  
  75.         CandleDataSet cds = new CandleDataSet(ceList, "Entries");
  76.         cds.setColor(Color.rgb(80, 80, 80));
  77.         cds.setShadowColor(Color.DKGRAY);
  78.         cds.setShadowWidth(0.7f);
  79.         cds.setDecreasingColor(Color.RED);
  80.         cds.setDecreasingPaintStyle(Paint.Style.FILL);
  81.         cds.setIncreasingColor(Color.rgb(122, 242, 84));
  82.         cds.setIncreasingPaintStyle(Paint.Style.STROKE);
  83.         cds.setNeutralColor(Color.BLUE);
  84.         cds.setValueTextColor(Color.RED);
  85.         *//*CandleData cd = new CandleData(cds);*//*
  86.         CandleData cd = new CandleDataSet(cds);
  87.         barChart.setData(cd);
  88.         barChart.invalidate();*/
  89.  
  90.  
  91.  
  92.  
  93.         Bundle bundle = getIntent().getExtras();
  94.         if (bundle!= null) {
  95.             data1 = bundle.getString("maxfreq");
  96.             data2 = bundle.getString("minfreq");
  97.  
  98.             max_frequency = Integer.parseInt(data1.toString());
  99.             min_frequency = Integer.parseInt(data2.toString());
  100.             Log.d("ADebugTag", "maxfreq: " + Double.toString(max_frequency));
  101.             Log.d("ADebugTag", "minfreq: " + Double.toString(min_frequency));
  102.         }
  103.  
  104.         Log.d("ADebugTag", "maxfreq: " + Double.toString(max_frequency));
  105.         Log.d("ADebugTag", "minfreq: " + Double.toString(min_frequency));
  106.  
  107.         /*maxfreq*/
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.         CandleStickChart candleStickChart = (CandleStickChart) findViewById(R.id.barGraph);
  115.         candleStickChart.setTouchEnabled(true);
  116.         candleStickChart.setDragEnabled(true);
  117.         candleStickChart.setScaleEnabled(true);
  118.  
  119.         ArrayList<CandleEntry> entries = new ArrayList<>();
  120.  
  121.         /*entries.add(new CandleEntry(0, 4.62f, 2.02f, 2.70f, 4.13f));*/
  122.         entries.add(new CandleEntry(0, max_frequency, min_frequency, min_frequency, max_frequency));
  123. /*        entries.add(new CandleEntry(1, 5.50f, 2.70f, 3.35f, 4.96f));
  124.         entries.add(new CandleEntry(2, 5.25f, 3.02f, 3.50f, 4.50f));
  125.         entries.add(new CandleEntry(3, 6f,    3.25f, 4.40f, 5.0f));
  126.         entries.add(new CandleEntry(4, 5.57f, 2f,    2.80f, 4.5f));*/
  127.  
  128.         CandleDataSet dataset = new CandleDataSet(entries, "Hearing Range");
  129.  
  130.         ArrayList<String> labels = new ArrayList<String>();
  131.         labels.add("January");
  132. /*        labels.add("February");
  133.         labels.add("March");
  134.         labels.add("April");
  135.         labels.add("May");
  136.         labels.add("June");*/
  137.  
  138.         CandleData data = new CandleData(labels, dataset);
  139.  
  140.  
  141.         candleStickChart.setData(data);
  142.         dataset.setColors(ColorTemplate.COLORFUL_COLORS); //
  143.         candleStickChart.setDescription("Radar Chart");
  144.         candleStickChart.animateY(3000);
  145.         dataset.setColor(Color.rgb(255,255,255));
  146.         data.setValueTextColor(Color.rgb(255,255,255));
  147.  
  148.  
  149.         candleStickChart.setDescription("");
  150.         Legend legend = candleStickChart.getLegend();
  151.         legend.setTextColor(Color.rgb(255,255,255));
  152.         legend.setTextSize(14);
  153.  
  154.         XAxis xAxis = candleStickChart.getXAxis();
  155.         xAxis.setTextColor(Color.rgb(255,255,255));
  156.         xAxis.setTextSize(14);
  157.  
  158.         YAxis yAxisLeft = candleStickChart.getAxisLeft();
  159.         yAxisLeft.setTextColor(Color.rgb(255,255,255));
  160.         yAxisLeft.setTextSize(14);
  161.  
  162.         YAxis yAxisRight = candleStickChart.getAxisRight();
  163.         yAxisRight.setTextColor(Color.rgb(255,255,255));
  164.         yAxisRight.setTextSize(14);
  165.  
  166.         yAxisRight.setAxisMaxValue(20000); // start at zero
  167.         yAxisRight.setAxisMinValue(0); // the axis maximum is 100
  168.         yAxisLeft.setAxisMaxValue(20000); // start at zero
  169.         yAxisLeft.setAxisMinValue(0); // the axis maximum is 100
  170.  
  171.         /*createRandomBarGraph(String date1, String date2);*/
  172.  
  173. /*        ArrayList<BarEntry> barEntries = new ArrayList<>();
  174.         barEntries.add(new BarEntry(44f,0));
  175.         barEntries.add(new BarEntry(88f,1));
  176.         barEntries.add(new BarEntry(66f,2));
  177.         barEntries.add(new BarEntry(12f,3));
  178.         barEntries.add(new BarEntry(19f,4));
  179.         barEntries.add(new BarEntry(91f,5));
  180.         BarDataSet barDataSet = new BarDataSet(barEntries,"Dates");
  181.  
  182.         ArrayList<String> theDates = new ArrayList<>();
  183.         theDates.add("April");
  184.         theDates.add("May");
  185.         theDates.add("June");
  186.         theDates.add("July");
  187.         theDates.add("August");
  188.         theDates.add("September");
  189.  
  190.         BarData theData = new BarData(theDates,barDataSet);
  191.         barChart.setData(theData);
  192.         barChart.setTouchEnabled(true);
  193.         barChart.setDragEnabled(true);
  194.         barChart.setScaleEnabled(true);*/
  195.  
  196.  
  197.  
  198.         btShare.setOnClickListener(new View.OnClickListener() {
  199.             @Override
  200.             public void onClick(View view) {
  201.                 Intent myIntent = new Intent(Intent.ACTION_SEND);
  202.                 myIntent.setType("text/plain");
  203.                 String shareBody = "Your body";
  204.                 String shareSub = "Your subject";
  205.                 myIntent.putExtra(Intent.EXTRA_SUBJECT,shareSub);
  206.                 myIntent.putExtra(Intent.EXTRA_SUBJECT,shareBody);
  207.                 startActivity(Intent.createChooser(myIntent,"Share using"));
  208.             }
  209.         });
  210.     }
  211.  
  212.  
  213.     /*public void createRandomBarGraph(String Date1, String Date2){
  214.  
  215.         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
  216.  
  217.         try {
  218.             java.util.Date date1 = simpleDateFormat.parse(Date1);
  219.             java.util.Date date2 = simpleDateFormat.parse(Date2);
  220.  
  221.             Calendar mDate1 = Calendar.getInstance();
  222.             Calendar mDate2 = Calendar.getInstance();
  223.             mDate1.clear();
  224.             mDate2.clear();
  225.  
  226.             mDate1.setTime(date1);
  227.             mDate2.setTime(date2);
  228.  
  229.  
  230.             dates = new ArrayList<>();
  231.             dates = getList(mDate1,mDate2);
  232.  
  233.             barEntries = new ArrayList<>();
  234.             float max = 0f;
  235.             float value = 0f;
  236.             random = new Random();
  237.             for(int j = 0; j< dates.size();j++){
  238.                 //max = 100f;
  239.                 max = 20000f;
  240.                 value = random.nextFloat()*max;
  241.                 barEntries.add(new BarEntry(value,j));
  242.             }
  243.  
  244.         }catch(ParseException e){
  245.             e.printStackTrace();
  246.         }
  247.  
  248.         BarDataSet barDataSet = new BarDataSet(barEntries,"Hearing Range");
  249.         BarData barData = new BarData(dates,barDataSet);
  250.         barDataSet.setColor(Color.rgb(255, 102, 153));
  251.         barDataSet.setValueTextColor(Color.rgb(255,255,255));
  252.         barDataSet.setHighlightEnabled(true);
  253.         barDataSet.setHighLightColor(Color.rgb(255,255,255));
  254.         barDataSet.setValueTextSize(14);
  255.  
  256.         barChart.setData(barData);
  257.         barChart.setDescription("");
  258.         Legend legend = barChart.getLegend();
  259.         legend.setTextColor(Color.rgb(255,255,255));
  260.         legend.setTextSize(14);
  261.  
  262.         XAxis xAxis = barChart.getXAxis();
  263.         xAxis.setTextColor(Color.rgb(255,255,255));
  264.         xAxis.setTextSize(14);
  265.  
  266.         YAxis yAxisUp = barChart.getAxisLeft();
  267.         yAxisUp.setTextColor(Color.rgb(255,255,255));
  268.         yAxisUp.setTextSize(14);
  269.  
  270.         YAxis yAxisBot = barChart.getAxisRight();
  271.         yAxisUp.setTextColor(Color.rgb(255,255,255));
  272.         yAxisUp.setTextSize(14);
  273.  
  274.     }
  275.  
  276.     public ArrayList<String> getList(Calendar startDate, Calendar endDate){
  277.         ArrayList<String> list = new ArrayList<String>();
  278.         while(startDate.compareTo(endDate)<=0){
  279.             list.add(getDate(startDate));
  280.             startDate.add(Calendar.DAY_OF_MONTH,1);
  281.         }
  282.         return list;
  283.     }
  284.  
  285.     public String getDate(Calendar cld){
  286.         *//*String curDate = cld.get(Calendar.YEAR) + "/" + (cld.get(Calendar.MONTH) + 1) + "/"
  287.                 +cld.get(Calendar.DAY_OF_MONTH);*//*
  288.         String curDate = (cld.get(Calendar.MONTH) + 1) + "/"
  289.                 +cld.get(Calendar.DAY_OF_MONTH);
  290.         try{
  291.             *//*java.util.Date date = new SimpleDateFormat("yy/MM/dd").parse(curDate);
  292.             curDate =  new SimpleDateFormat("yy/MM/dd").format(date);*//*
  293.             java.util.Date date = new SimpleDateFormat("MM/dd").parse(curDate);
  294.             curDate =  new SimpleDateFormat("MM/dd").format(date);
  295.         }catch(ParseException e){
  296.             e.printStackTrace();
  297.         }
  298.         return curDate;
  299.     }*/
  300.  
  301. }
Advertisement
Add Comment
Please, Sign In to add comment