示例#1
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.graphs);

    // init example series data
    exampleSeries1 =
        new GraphViewSeries(
            new GraphViewData[] {
              new GraphViewData(1, 2.0d),
              new GraphViewData(2, 1.5d),
              new GraphViewData(2.5, 3.0d) // another frequency
              ,
              new GraphViewData(3, 2.5d),
              new GraphViewData(4, 1.0d),
              new GraphViewData(5, 3.0d)
            });

    // graph with dynamically genereated horizontal and vertical labels
    if (getIntent().getStringExtra("type").equals("bar")) {
      graphView =
          new BarGraphView(
              this // context
              ,
              "GraphViewDemo" // heading
              );
    } else {
      graphView =
          new LineGraphView(
              this // context
              ,
              "GraphViewDemo" // heading
              );
    }
    graphView.addSeries(exampleSeries1); // data

    LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);
    layout.addView(graphView);

    // ----------
    exampleSeries2 =
        new GraphViewSeries(
            new GraphViewData[] {
              new GraphViewData(1, 2.0d),
              new GraphViewData(2, 1.5d),
              new GraphViewData(2.5, 3.0d) // another frequency
              ,
              new GraphViewData(3, 2.5d),
              new GraphViewData(4, 1.0d),
              new GraphViewData(5, 3.0d)
            });

    // graph with custom labels and drawBackground
    if (getIntent().getStringExtra("type").equals("bar")) {
      graphView = new BarGraphView(this, "GraphViewDemo");
    } else {
      graphView = new LineGraphView(this, "GraphViewDemo");
      ((LineGraphView) graphView).setDrawBackground(true);
    }
    graphView.addSeries(exampleSeries2); // data
    graphView.setViewPort(1, 4);
    graphView.setScalable(true);

    layout = (LinearLayout) findViewById(R.id.graph2);
    layout.addView(graphView);
  }
示例#2
0
    protected void onPostExecute(Void unused) {

      Dialog.dismiss();

      if (Error != null) {

        uiUpdate.setText("Output : " + Error);

      } else {

        // uiUpdate.setText("Output : "+Content);
        // String OutputData="";

        JSONObject jsonResponse1;
        JSONObject jsonResponse2;
        JSONObject jsonResponse3;
        JSONObject jsonResponse5;
        JSONObject jsonResponse6;
        JSONObject jsonResponse7;
        JSONObject jsonResponse8;
        JSONObject jsonResponse9;
        JSONObject jsonResponse10;

        JSONObject jsonResponse11;
        JSONObject jsonResponse12;
        JSONObject jsonResponse13;
        JSONObject jsonResponse14;
        JSONObject jsonResponse15;
        JSONObject jsonResponse16;
        JSONObject jsonResponse17;
        try {
          jsonResponse1 = new JSONObject(Content);

          jsonResponse15 = jsonResponse1.optJSONObject("demand_supply");
          jsonResponse16 = jsonResponse15.optJSONObject("buy");
          jsonResponse17 = jsonResponse15.optJSONObject("rent");
          JSONObject jsonChildNode6 = jsonResponse16.getJSONObject("demand");
          JSONObject jsonChildNode7 = jsonResponse16.getJSONObject("supply");
          int demand_4BHK = jsonChildNode6.optInt("3+ BHK", 0);
          int supply_4BHK = jsonChildNode7.optInt("3+ BHK", 0);
          int demand_3BHK = jsonChildNode6.optInt("3 BHK", 0);
          int supply_3BHK = jsonChildNode7.optInt("3 BHK", 0);
          int demand_2BHK = jsonChildNode6.optInt("2 BHK", 0);
          int supply_2BHK = jsonChildNode7.optInt("2 BHK", 0);
          int demand_1BHK = jsonChildNode6.optInt("1 BHK", 0);
          int supply_1BHK = jsonChildNode7.optInt("1 BHK", 0);
          int demand_1RK = jsonChildNode6.optInt("1 RK", 0);
          int supply_1RK = jsonChildNode7.optInt("1 RK", 0);
          OutputData1 += "\n" + "Demand and Supply for Buy" + "\n\n";
          OutputData1 += "3+ BHK: " + demand_4BHK + " " + supply_4BHK + "\n";
          OutputData1 += "3 BHK: " + demand_3BHK + " " + supply_3BHK + "\n";
          OutputData1 += "2 BHK: " + demand_2BHK + " " + supply_2BHK + "\n";
          OutputData1 += "1 BHK: " + demand_1BHK + " " + supply_1BHK + "\n";
          OutputData1 += "1 RK: " + demand_1RK + " " + supply_1RK + "\n\n\n";

          JSONObject jsonChildNode8 = jsonResponse17.getJSONObject("demand");
          JSONObject jsonChildNode9 = jsonResponse17.getJSONObject("supply");
          int demand_4BHK1 = jsonChildNode8.optInt("3+ BHK", 0);
          int supply_4BHK1 = jsonChildNode9.optInt("3+ BHK", 0);
          int demand_3BHK1 = jsonChildNode8.optInt("3 BHK", 0);
          int supply_3BHK1 = jsonChildNode9.optInt("3 BHK", 0);
          int demand_2BHK1 = jsonChildNode8.optInt("2 BHK", 0);
          int supply_2BHK1 = jsonChildNode9.optInt("2 BHK", 0);
          int demand_1BHK1 = jsonChildNode8.optInt("1 BHK", 0);
          int supply_1BHK1 = jsonChildNode9.optInt("1 BHK", 0);
          int demand_1RK1 = jsonChildNode8.optInt("1 RK", 0);
          int supply_1RK1 = jsonChildNode9.optInt("1 RK", 0);
          OutputData2 += "\n" + "Demand and Supply for Rent" + "\n\n";
          OutputData2 += "3+ BHK: " + demand_4BHK1 + " " + supply_4BHK1 + "\n";
          OutputData2 += "3 BHK: " + demand_3BHK1 + " " + supply_3BHK1 + "\n";
          OutputData2 += "2 BHK: " + demand_2BHK1 + " " + supply_2BHK1 + "\n";
          OutputData2 += "1 BHK: " + demand_1BHK1 + " " + supply_1BHK1 + "\n";
          OutputData2 += "1 RK: " + demand_1RK1 + " " + supply_1RK1 + "\n\n\n";

          jsonResponse2 = jsonResponse1.optJSONObject("peripheral");
          jsonResponse3 = jsonResponse2.optJSONObject("places_to_see");
          JSONArray jsonMainNode = jsonResponse3.optJSONArray("results");
          int lengthJsonArr = jsonMainNode.length();
          OutputData3 += "Peripherals" + "\n\n";
          OutputData3 += "Good Places to See" + "\n";
          for (int i = 0; i < lengthJsonArr; i++) {
            JSONObject jsonChildNode = jsonMainNode.getJSONObject(i);
            String name = jsonChildNode.optString("name").toString();
            double latitude = jsonChildNode.getDouble("latitude");
            double longitude = jsonChildNode.getDouble("longitude");
            OutputData3 += "\n" + name + "  " + latitude + "," + longitude + "\n";
          }
          // jsonResponse4 =new JSONObject(Content);
          jsonResponse5 = jsonResponse2.optJSONObject("theaters");
          jsonResponse6 = jsonResponse5.optJSONObject("results");
          int num_theters = jsonResponse6.getInt("num_theaters");
          JSONArray jsonMainNode1 = jsonResponse6.optJSONArray("top_theaters");
          int lengthJsonArr1 = jsonMainNode1.length();
          OutputData3 += "\n\n" + "Top Theaters" + "\n\n";
          OutputData3 += "Number of Top Theatres: " + num_theters + "\n";
          for (int i = 0; i < lengthJsonArr1; i++) {
            JSONObject jsonChildNode1 = jsonMainNode1.getJSONObject(i);
            String name1 = jsonChildNode1.optString("name").toString();
            double latitude1 = jsonChildNode1.getDouble("latitude");
            double longitude1 = jsonChildNode1.getDouble("longitude");
            OutputData3 += "\n" + name1 + "  " + latitude1 + "," + longitude1 + "\n";
          }
          jsonResponse7 = jsonResponse2.optJSONObject("restaurants");
          jsonResponse8 = jsonResponse7.optJSONObject("results");
          int num_restaurants = jsonResponse8.getInt("num_restaurants");
          JSONArray jsonMainNode2 = jsonResponse8.optJSONArray("top_restaurants");
          int lengthJsonArr2 = jsonMainNode2.length();
          OutputData3 += "\n\n" + "Top Restaurants" + "\n\n";
          OutputData3 += "Number of Restaurants: " + num_restaurants + "\n";
          for (int i = 0; i < lengthJsonArr2; i++) {
            JSONObject jsonChildNode2 = jsonMainNode2.getJSONObject(i);
            String name2 = jsonChildNode2.optString("name").toString();
            double score = jsonChildNode2.getDouble("score");
            double latitude2 = jsonChildNode2.getDouble("latitude");
            double longitude2 = jsonChildNode2.getDouble("longitude");
            OutputData3 += "\n" + name2 + "  " + score + "  " + latitude2 + "," + longitude2 + "\n";
          }

          jsonResponse11 = jsonResponse1.optJSONObject("transport");
          jsonResponse12 = jsonResponse11.optJSONObject("local_train");
          OutputData4 += "\n\n" + "Transport" + "\n\n";
          JSONObject jsonChildNode3 = jsonResponse12.getJSONObject("results");
          String station_name = jsonChildNode3.getString("station_name");
          double distance = jsonChildNode3.getDouble("distance");
          String network_name = jsonChildNode3.getString("network_name");
          String line_name = jsonChildNode3.getString("line_name");
          OutputData4 +=
              "\n"
                  + "Nearby Local Train Station: "
                  + station_name
                  + "  "
                  + distance
                  + "  "
                  + network_name
                  + "  "
                  + line_name
                  + "\n";

          jsonResponse13 = jsonResponse11.optJSONObject("airport");
          JSONObject jsonChildNode4 = jsonResponse13.getJSONObject("results");
          String airport_name = jsonChildNode4.getString("name");
          double airport_distance = jsonChildNode4.getDouble("distance");
          OutputData4 += "\n" + "Nearby Airport: " + airport_name + "  " + airport_distance + "\n";

          jsonResponse14 = jsonResponse11.optJSONObject("interstate_train");
          JSONObject jsonChildNode5 = jsonResponse14.getJSONObject("results");
          String interstate_name = jsonChildNode5.getString("name");
          double interstate_distance = jsonChildNode5.getDouble("distance");
          OutputData4 +=
              "\n"
                  + "Nearby Interstate Train Station: "
                  + interstate_name
                  + "  "
                  + interstate_distance
                  + "\n";

          jsonResponse9 = jsonResponse1.optJSONObject("price_trend");
          jsonResponse10 = jsonResponse9.optJSONObject("results");
          String start_date = jsonResponse10.getString("start_date");
          OutputData5 += "\n\n" + "Starting Date for Graph Data: " + start_date + "\n\n";
          JSONArray jsonMainNode3 = jsonResponse10.optJSONArray("max");
          int lengthJsonArr3 = jsonMainNode3.length();
          max = new double[lengthJsonArr3];
          // OutputData+="\n"+"Maximum Price"+"\n";
          for (int i = 0; i < lengthJsonArr3; i++) {
            double price = jsonMainNode3.getDouble(i);
            // OutputData+="\n"+price+"\n";
            max[i] = price;
          }

          JSONArray jsonMainNode4 = jsonResponse10.optJSONArray("min");
          int lengthJsonArr4 = jsonMainNode4.length();
          min = new double[lengthJsonArr4];
          // OutputData+="\n"+"Minimum Price"+"\n";
          for (int i = 0; i < lengthJsonArr4; i++) {
            double price = jsonMainNode4.getDouble(i);
            // OutputData+="\n"+price+"\n";
            min[i] = price;
          }

          JSONArray jsonMainNode5 = jsonResponse10.optJSONArray("avg");
          int lengthJsonArr5 = jsonMainNode5.length();
          avg = new double[lengthJsonArr5];
          // OutputData+="\n"+"Average Price"+"\n";
          for (int i = 0; i < lengthJsonArr5; i++) {
            double price = jsonMainNode5.getDouble(i);
            // OutputData+="\n"+price+"\n";
            avg[i] = price;
          }

          /*
           * Editor editor = sharedpreferences.edit();
           * editor.putString(Etext, OutputData); editor.commit();
           * uiUpdate.setText(OutputData);
           */

          values = new String[] {OutputData1, OutputData2, OutputData3, OutputData4, OutputData5};

          GraphViewDataInterface[] data = new GraphViewData[lengthJsonArr3];
          for (int i = 0; i < lengthJsonArr3; i++) {
            data[i] = new GraphViewData(i + 1, max[i]);
          }

          GraphViewDataInterface[] data1 = new GraphViewData[lengthJsonArr4];
          for (int i = 0; i < lengthJsonArr4; i++) {
            data1[i] = new GraphViewData(i + 1, min[i]);
          }

          GraphViewDataInterface[] data2 = new GraphViewData[lengthJsonArr5];
          for (int i = 0; i < lengthJsonArr5; i++) {
            data2[i] = new GraphViewData(i + 1, avg[i]);
          }
          // GraphViewSeriesStyle   color1=new GraphViewStyle(Color.GREEN,3,0);
          GraphViewSeries Series1 =
              new GraphViewSeries("Maximum Price", new GraphViewSeriesStyle(Color.CYAN, 3), data);
          GraphViewSeries Series2 =
              new GraphViewSeries("Minimum Price", new GraphViewSeriesStyle(Color.GREEN, 3), data1);
          GraphViewSeries Series3 =
              new GraphViewSeries(
                  "Average Price", new GraphViewSeriesStyle(Color.MAGENTA, 3), data2);
          ((LineGraphView) graphView).setDrawDataPoints(true);
          ((LineGraphView) graphView).setDataPointsRadius(5f);
          graphView.addSeries(Series1);
          graphView.addSeries(Series2);
          graphView.addSeries(Series3);
          graphView.setShowLegend(true);
          Editor editor = sharedpreferences.edit();
          editor.putString(Etext, OutputData);
          editor.commit();
          // uiUpdate.setText(OutputData5);

          graphView.getGraphViewStyle().setHorizontalLabelsColor(Color.BLACK);
          graphView.getGraphViewStyle().setVerticalLabelsColor(Color.BLACK);
          graphView.getGraphViewStyle().setTextSize(10);
          graphView.getGraphViewStyle().setNumVerticalLabels(15);
          graphView.getGraphViewStyle().setNumHorizontalLabels(21);
          // graphView.getGraphViewStyle().setGridColor(12);
          // graphView.setScrollable(true);

          RelativeLayout layout = (RelativeLayout) footer.findViewById(R.id.trendsGraph);

          AbsListView.LayoutParams params =
              new AbsListView.LayoutParams(getWindowManager().getDefaultDisplay().getWidth(), 700);
          layout.setLayoutParams(params);
          layout.addView(graphView);

          listView.addFooterView(layout);
          /*
           * LinearLayout layout=new LinearLayout(this);
           *
           * RelativeLayout.LayoutParams params = new
           * RelativeLayout.LayoutParams(
           * getWindowManager().getDefaultDisplay().getWidth(), 400);
           * params.addRule(RelativeLayout.BELOW, R.id.listView1);
           * layout.setLayoutParams(params);
           * layout.addView(graphView);
           */

          // OutputData1 = "jegueububwbuegbuobg";
          // OutputData2 = "rnhonowranhwroinioan";
          // OutputData3 = "jegunegoineoin[nnon";
          // OutputData4 = "aonfoinmmoijfq ieoei";
          // OutputData5 = "dmgniwognoingonnwgono";

          adapter =
              new ArrayAdapter<String>(
                  MainActivity.this,
                  android.R.layout.simple_list_item_1,
                  android.R.id.text1,
                  values);

          listView.setAdapter(adapter);
        }

        /*	listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        		public void onItemClick(AdapterView<?> parent,
        				View view, int position, long id) {

        			int itemPosition = position;
        			String itemValue = (String) listView
        					.getItemAtPosition(position);
        			Toast.makeText(
        					getApplicationContext(),
        					"Position :" + itemPosition
        							+ "  ListItem : " + itemValue,
        					Toast.LENGTH_LONG).show();

        		}

        	});

        }*/

        catch (JSONException e) {
          e.printStackTrace();
        }
      }
    }