Пример #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pie_chart);
    // getActionBar().setDisplayHomeAsUpEnabled(true);

    final Context mContext = this;
    mRenderer.setApplyBackgroundColor(true);
    // mRenderer.setBackgroundColor(Color.argb(100, 80, 80, 50));
    mRenderer.setChartTitleTextSize(15);
    mRenderer.setLabelsTextSize(20);
    mRenderer.setLabelsColor(color.black);
    mRenderer.setDisplayValues(true);
    mRenderer.setLabelsColor(Color.BLACK);
    mRenderer.setLegendTextSize(20);
    mRenderer.setShowLabels(true);
    mRenderer.setMargins(new int[] {20, 30, 15, 0});
    mRenderer.setZoomButtonsVisible(true);
    mRenderer.setStartAngle(180);

    Calendar d = new GregorianCalendar();

    int yr = d.get(Calendar.YEAR);

    if (yr > 99) {
      mdate = d.get(Calendar.DATE) + "/" + d.get(Calendar.MONTH) + "/20" + (yr % 100);
    } else {
      mdate = d.get(Calendar.DATE) + "/" + d.get(Calendar.DAY_OF_MONTH) + "/19" + (yr % 100);
    }
    System.out.println("date is " + mdate);
    drawPieForSpecificDate();
    editText_specificDate = (EditText) this.findViewById(R.id.editText_specificDate);
    editText_specificDate.setCursorVisible(false);
    editText_specificDate.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            // custom dialog
            flag = 1;

            final Calendar c = Calendar.getInstance();
            year = c.get(Calendar.YEAR);
            month = c.get(Calendar.MONTH);
            day = c.get(Calendar.DAY_OF_MONTH);
            DatePickerDialog datePickerDialog =
                new DatePickerDialog(mContext, PieChart_lower.this, year, month, day);

            datePickerDialog.show();
            flag = 1;
          }
        }); // button_specificDate setListener

    if (flag == 1) drawPieForSpecificDate();

    Button button_specificMonth = (Button) this.findViewById(R.id.button_specificMonth);
    alert = new AlertDialog.Builder(this);

    button_specificMonth.setVisibility(View.GONE);
  }
Пример #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_room_detail);

    Bundle Title = getIntent().getExtras();
    if (Title != null) {
      mPlace = Title.getString(Constants.PLACE);
    }

    mRoomNameView = (TextView) findViewById(R.id.detail_roomname);
    mSeatnumbnerView = (TextView) findViewById(R.id.detail_seatnumber);
    mDescriptionView = (TextView) findViewById(R.id.detail_description);
    mImageView = (ImageView) findViewById(R.id.detailed_image);
    mHistoryButton = (Button) findViewById(R.id.history_button);

    mPersistanceManager = new PersistanceManager(this);
    r = mPersistanceManager.getCurrentRoom();

    mRoomNameView.setText(r.getName());
    mSeatnumbnerView.setText(r.getNumberOfSeat());
    mDescriptionView.setText(r.getDescription());

    // set the achartengine pie chart parameters, including color, lable size as well as items shown
    // options
    double taken = Double.parseDouble(r.getFullness());
    double notTaken = 100 - taken;
    double[] PIECHARTVALUES = new double[] {taken, notTaken};

    mRenderer.setApplyBackgroundColor(true);
    mRenderer.setBackgroundColor(Color.argb(100, 50, 50, 50));
    mRenderer.setChartTitleTextSize(20);
    mRenderer.setLabelsTextSize(50);
    mRenderer.setShowLegend(false);
    mRenderer.setShowTickMarks(false);
    mRenderer.setZoomButtonsVisible(true);
    mRenderer.setStartAngle(90);

    // show the percentage
    for (int i = 0; i < PIECHARTVALUES.length; i++) {
      mSeries.add(NAME_LIST[i] + " " + PIECHARTVALUES[i] + "%", PIECHARTVALUES[i]);
      SimpleSeriesRenderer renderer = new SimpleSeriesRenderer();
      renderer.setColor(COLORS[(mSeries.getItemCount() - 1) % COLORS.length]);
      mRenderer.addSeriesRenderer(renderer);
    }

    if (mChartView != null) {
      mChartView.repaint();
    }

    // load the pie chart layout with the parameters in mRenderer and mSeries we set before.
    LinearLayout layout = (LinearLayout) findViewById(R.id.chart);
    mChartView = ChartFactory.getPieChartView(this, mSeries, mRenderer);
    mRenderer.setClickEnabled(true);
    mRenderer.setSelectableBuffer(10);

    layout.addView(
        mChartView,
        new AbsListView.LayoutParams(
            AbsListView.LayoutParams.FILL_PARENT, AbsListView.LayoutParams.FILL_PARENT));

    if (!r.getImage().equals("")) {
      Ion.with(mImageView)
          .load(r.getImage())
          .setCallback(
              new FutureCallback<ImageView>() {
                @Override
                public void onCompleted(Exception e, ImageView result) {
                  if (e == null) {
                    // yay

                  } else {
                    // log the error information , helping to check. Then keep running app without
                    // image
                    Log.d(TAG, "image failed to load " + e.toString());
                  }
                }
              });
    }

    // set the extre before going to history activity, helping to save which building and which room
    // to load.
    mHistoryButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent(getBaseContext(), HistoryActivity.class);
            intent.putExtra(Constants.ROOM, r.getName());
            intent.putExtra(Constants.PLACE, mPlace);
            startActivity(intent);
          }
        });
  }