Android Open Source - timestatistic Calendar Setup Dialog Fragment






From Project

Back to project page timestatistic.

License

The source code is released under:

GNU General Public License

If you think the Android project timestatistic listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package maximsblog.blogspot.com.timestatistic;
/*  w  w w .java2 s. c o  m*/
import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CalendarContract;
import android.support.v4.app.DialogFragment;

public class CalendarSetupDialogFragment extends DialogFragment implements OnClickListener {
  
  private ICalendarSetupDialog mListener;
  
  public interface ICalendarSetupDialog {
    void setupCalendar(String id, String name);
  }
  public void setCalendarSetupDialog(ICalendarSetupDialog listener) {
    mListener = listener;
  }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
      GetGcalendars();
      String id = getArguments().getString("calendar_id");
      int selectedCalendarIndex = calIDs.indexOf(id);
      CharSequence[] calendarNames = new CharSequence[calnames.size()];
      for(int i=0;i<calnames.size(); i++){
        calendarNames[i] = calnames.get(i);
      }
      
        return new AlertDialog.Builder(getActivity())
            .setTitle(R.string.select_gcalendar)
            .setSingleChoiceItems(calendarNames, selectedCalendarIndex , this)
            .create();
    }
  
  
  private ArrayList<String> calnames;
  private ArrayList<String> calIDs;
  
  @SuppressLint("NewApi")
  public boolean GetGcalendars() {

    calnames = new ArrayList<String>();
    calIDs = new ArrayList<String>();
    String[] CALENDAR_QUERY_COLUMNS = { CalendarContract.Calendars._ID,
        CalendarContract.Calendars.NAME,
        CalendarContract.Calendars.VISIBLE,
        CalendarContract.Calendars.OWNER_ACCOUNT };

    ContentResolver contentResolver = getActivity().getContentResolver();
    final Cursor cursor = contentResolver.query(
        CalendarContract.Calendars.CONTENT_URI, CALENDAR_QUERY_COLUMNS,
        null, null, null);
    if (cursor != null && cursor.getCount() > 0) {
      while (cursor.moveToNext()) {
        final String calID = cursor.getString(0);
        final String calName = cursor.getString(1);
        final Boolean selected = !cursor.getString(2).equals("0");
        final String accountName = cursor.getString(3);
        if (calName != null) {
          calnames.add(calName);
          calIDs.add(calID);
        }
      }
      cursor.close();
    }
    return calIDs.size() > 0;

  }
  @Override
  public void onClick(DialogInterface dialog, int which) {
    this.dismiss();
    mListener.setupCalendar(calIDs.get(which), calnames.get(which));
  }
}




Java Source Code List

maximsblog.blogspot.com.timestatistic.AboutActivity.java
maximsblog.blogspot.com.timestatistic.AboutFragment.java
maximsblog.blogspot.com.timestatistic.AlarmManagerBroadcastReceiver.java
maximsblog.blogspot.com.timestatistic.AreYouSureResetAllDialogFragment.java
maximsblog.blogspot.com.timestatistic.AreYouSureResetAllDialog.java
maximsblog.blogspot.com.timestatistic.BootUpReceiver.java
maximsblog.blogspot.com.timestatistic.CalendarSetupDialogFragment.java
maximsblog.blogspot.com.timestatistic.ColorPickerDialogFragment.java
maximsblog.blogspot.com.timestatistic.ColorPickerDialog.java
maximsblog.blogspot.com.timestatistic.CounterEditorDialogFragment.java
maximsblog.blogspot.com.timestatistic.CountersCursorAdapter.java
maximsblog.blogspot.com.timestatistic.CountersFragment.java
maximsblog.blogspot.com.timestatistic.CountersPeriodSetupDialogFragment.java
maximsblog.blogspot.com.timestatistic.CustomDateTimePicker.java
maximsblog.blogspot.com.timestatistic.DiagramFragment.java
maximsblog.blogspot.com.timestatistic.DiaryCursorAdapter.java
maximsblog.blogspot.com.timestatistic.DiaryEditorDialogFragment.java
maximsblog.blogspot.com.timestatistic.DiaryFragment.java
maximsblog.blogspot.com.timestatistic.ExportImportBackupActivity.java
maximsblog.blogspot.com.timestatistic.ExportToCSVActivity.java
maximsblog.blogspot.com.timestatistic.ExportToCSVService.java
maximsblog.blogspot.com.timestatistic.ExportToGoogleCalendarActivity.java
maximsblog.blogspot.com.timestatistic.ExportToGoogleCalendarService.java
maximsblog.blogspot.com.timestatistic.FileDialog.java
maximsblog.blogspot.com.timestatistic.FilterDateOption.java
maximsblog.blogspot.com.timestatistic.FilterDateSetDialogFragment.java
maximsblog.blogspot.com.timestatistic.FilterDialogFragment.java
maximsblog.blogspot.com.timestatistic.GdriveUpload.java
maximsblog.blogspot.com.timestatistic.HelpActivity.java
maximsblog.blogspot.com.timestatistic.HistoryFragment.java
maximsblog.blogspot.com.timestatistic.ICustomDateTimeListener.java
maximsblog.blogspot.com.timestatistic.IRecordDialog.java
maximsblog.blogspot.com.timestatistic.IdateChange.java
maximsblog.blogspot.com.timestatistic.Item.java
maximsblog.blogspot.com.timestatistic.MainActivity.java
maximsblog.blogspot.com.timestatistic.OpenHelper.java
maximsblog.blogspot.com.timestatistic.PeriodAnalyseActivity.java
maximsblog.blogspot.com.timestatistic.PeriodAnalyseFragment.java
maximsblog.blogspot.com.timestatistic.PeriodData.java
maximsblog.blogspot.com.timestatistic.PeriodSetupDialogFragment.java
maximsblog.blogspot.com.timestatistic.RecordsDbHelper.java
maximsblog.blogspot.com.timestatistic.SelectionMode.java
maximsblog.blogspot.com.timestatistic.SettingsActivity.java
maximsblog.blogspot.com.timestatistic.SplitRecordDialogFragment.java
maximsblog.blogspot.com.timestatistic.TimeRecordsFragment.java
maximsblog.blogspot.com.timestatistic.TimesCursorAdapter.java
maximsblog.blogspot.com.timestatistic.TopicActivity.java
maximsblog.blogspot.com.timestatistic.UnionRecordDialogFragment.java
maximsblog.blogspot.com.timestatistic.XYMultipleSeriesDatasetLoader.java
maximsblog.blogspot.com.timestatistic.app.java