コード例 #1
0
  public void populateViews() {
    final Venue venue; // Venue of the event
    final String description =
        mEvent.getDescription(); // description of the event, must be more than 50 works
    final Contact contact;

    TextView categoryText = (TextView) findViewById(R.id.categorytext);
    TextView timeText = (TextView) findViewById(R.id.timetext);
    TextView venueText = (TextView) findViewById(R.id.venuetext);
    TextView contactText = (TextView) findViewById(R.id.contacttext);
    TextView descriptionText = (TextView) findViewById(R.id.descriptiontext);
    TextView resultText = (TextView) findViewById(R.id.resulttext);
    categoryText.setText(mEvent.getCategory());

    int shour = mEvent.getStart_time().get(Calendar.HOUR_OF_DAY);
    int min = mEvent.getStart_time().get(Calendar.MINUTE);
    String smin;
    if (min == 0) smin = min + "0";
    else smin = min + "";

    String starttime;

    if (shour > 12) {
      shour = shour - 12;
      starttime = shour + ":" + smin + " PM";
    } else {
      starttime = shour + ":" + smin + " AM";
    }
    int ehour = mEvent.getEnd_time().get(Calendar.HOUR_OF_DAY);
    min = mEvent.getStart_time().get(Calendar.MINUTE);
    String emin;
    if (min == 0) emin = min + "0";
    else emin = min + "";

    String endtime;
    if (ehour > 12) {
      ehour = ehour - 12;
      endtime = ehour + ":" + emin + " PM";
    } else {
      endtime = ehour + ":" + emin + " AM";
    }
    String time = starttime + " to " + endtime;
    timeText.setText(time);
    venueText.setText(mEvent.getVenue().getLocation());
    contactText.setText(mEvent.getContact().getName());
    if (description != null && description.length() > 10) {
      descriptionText.setText(description);
    } else {
      descriptionText.setVisibility(View.GONE);
      LinearLayout temp = (LinearLayout) findViewById(R.id.descriptioncontainer);
      temp.setVisibility(View.GONE);
    }
    databaseAccess = DatabaseAccess.getInstance(this);
    databaseAccess.open();
    String result = databaseAccess.getResult(mEvent.getName());
    databaseAccess.close();

    if (result == null) resultText.setText("results not declared yet");
    else resultText.setText(result);
  }
コード例 #2
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_event_detail);
    Intent intent = getIntent();
    final String EventName = intent.getStringExtra(EXTRA_NAME);
    databaseAccess = DatabaseAccess.getInstance(this);
    databaseAccess.open();
    mEvent = databaseAccess.getParticularEvent(EventName);
    databaseAccess.close();
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // get calendar status
    // Run query
    Cursor cur = null;
    ContentResolver cr = getContentResolver();
    Uri uri = CalendarContract.Calendars.CONTENT_URI;
    String selection = "(" + CalendarContract.Calendars.ACCOUNT_TYPE + " = ?)";
    String[] selectionArgs = new String[] {"com.google"};
    // Submit the query and get a Cursor object back.
    cur = cr.query(uri, EVENT_PROJECTION, selection, selectionArgs, null);
    while (cur.moveToNext()) {
      long calID = 0;
      String displayName = null;
      String accountName = null;
      String ownerName = null;

      // Get the field values
      calID = cur.getLong(PROJECTION_ID_INDEX);
      displayName = cur.getString(PROJECTION_DISPLAY_NAME_INDEX);
      accountName = cur.getString(PROJECTION_ACCOUNT_NAME_INDEX);
      ownerName = cur.getString(PROJECTION_OWNER_ACCOUNT_INDEX);
      if (mGoogleCalendarNumber == -1) {
        mGoogleCalendarNumber = calID;
      }
    }
    cur.close();

    // setup collapsing toolbar
    CollapsingToolbarLayout collapsingToolbar =
        (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle(EventName);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            if (mGoogleCalendarNumber != -1) {
              showReminderSheet();
            } else {
              Calendar beginTime = Calendar.getInstance();
              beginTime.set(
                  2015,
                  mEvent.getStart_time().get(Calendar.MONTH),
                  mEvent.getStart_time().get(Calendar.DATE),
                  mEvent.getStart_time().get(Calendar.HOUR),
                  mEvent.getStart_time().get(Calendar.MINUTE));
              Calendar endTime = Calendar.getInstance();
              endTime.set(
                  2015,
                  mEvent.getEnd_time().get(Calendar.MONTH),
                  mEvent.getEnd_time().get(Calendar.DATE),
                  mEvent.getEnd_time().get(Calendar.HOUR),
                  mEvent.getEnd_time().get(Calendar.MINUTE));
              Intent intent =
                  new Intent(Intent.ACTION_INSERT)
                      .setData(CalendarContract.Events.CONTENT_URI)
                      .putExtra(
                          CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis())
                      .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis())
                      .putExtra(CalendarContract.Events.TITLE, mEvent.getName())
                      .putExtra(CalendarContract.Events.ALLOWED_REMINDERS, 1)
                      .putExtra(CalendarContract.Events.DESCRIPTION, mEvent.getDescription());
              startActivity(intent);
            }
          }
        });
    populateViews();

    loadBackdrop();
  }