示例#1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    if (savedInstanceState != null) {
      mCurrGraphPosX = savedInstanceState.getInt("mCurrGraphPosX");
      mLastVoteTime = savedInstanceState.getLong("mLastVoteTime");
      mSeries = savedInstanceState.getParcelable("mSeries");
    } else {
      mCurrGraphPosX = 20;
      mLastVoteTime = -1;
      mSeries = new LinearSeries();
    }

    final View v = inflater.inflate(R.layout.umeter, container, false);

    // Find the chart view
    mChartView = (ChartView) v.findViewById(R.id.chart_view);
    mChartView.setGridLineColor(Color.LTGRAY);

    // Create the data points
    mSeries.setLineColor(0xFF0099CC);
    mSeries.setLineWidth(
        TypedValue.applyDimension(
            TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()));

    // Add chart view data
    mChartView.addSeries(mSeries);

    mVotedAgoTextView = (TextView) v.findViewById(id.time_ago);
    mVoteBar = (SeekBar) v.findViewById(id.my_understanding);

    mVoteBar.setProgress(50);

    setTimeAgoText();
    setVoteBarListener();

    return v;
  }
示例#2
0
  public void onUnderstandingLoaded(JSONObject json) {
    if (json != null) {
      int understanding = json.optInt("understanding");

      if (mLastVoteTime == -1) {
        mVoteBar.setProgress(json.optInt("deviceUnderstanding"));
        mLastVoteTime =
            json.optString("deviceTimeLastVoted").equals("N/A")
                ? -1
                : json.optLong("deviceTimeLastVoted");
      }

      mSeries.addPoint(
          new LinearSeries.LinearPoint(mCurrGraphPosX, understanding + (int) (Math.random() * 1)));
      mChartView.setRange(mCurrGraphPosX - 20, mCurrGraphPosX, 0, 100);
      mSeries.setRange(mCurrGraphPosX - 20, mCurrGraphPosX, 0, 100);
      mCurrGraphPosX++;
      mChartView.invalidate();

      setTimeAgoText();
    }
    postLoadDelayed(OakConfig.AUTO_REFRESH_UNDERSTANDING_MILLIS);
  }