Android Open Source - timestatistic Export To Google Calendar Service






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 .j a va  2 s .  c o  m
import java.util.ArrayList;
import java.util.List;

import com.google.android.gms.internal.cn;

import android.annotation.SuppressLint;
import android.app.Service;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Binder;
import android.os.CancellationSignal;
import android.os.IBinder;
import android.provider.CalendarContract;
import android.support.v4.content.CursorLoader;
import android.text.format.Time;
import android.view.View;
import android.widget.Toast;

public class ExportToGoogleCalendarService extends Service {

  public static final String EXPORT = "export_to_gcalendar_stop";
  public static boolean isRunning;

  private long mSelectStartItem;
  private long mSelectEndItem;
  private int[] mIDs;
  private boolean[] mChecked;
  private int mCalendarID;
  private boolean mExportNotes;
  private boolean mExportOnlyNotes;

  @Override
  public void onCreate() {
    super.onCreate();
  }

  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
    Thread t = new Thread(new Runnable() {
      int i = 0;

      @SuppressLint("NewApi")
      @Override
      public void run() {
        String[] selectionArgs;
        Cursor cursor;
        if(mExportOnlyNotes) {
          selectionArgs = new String[] {
              "",
              String.valueOf(mSelectStartItem),
              String.valueOf(mSelectEndItem) };
          cursor = getContentResolver().query(
              RecordsDbHelper.CONTENT_URI_ALLNOTES, null,
              RecordsDbHelper.STARTTIME + " IS NOT NULL AND "
            + RecordsDbHelper.NOTE + " LIKE ?",
              selectionArgs, null);
        } else {
          selectionArgs = new String[] {
              String.valueOf(mSelectStartItem),
              String.valueOf(mSelectEndItem) };
          cursor = getContentResolver().query(
              RecordsDbHelper.CONTENT_URI_ALLTIMES, null,
              RecordsDbHelper.STARTTIME + " IS NOT NULL ",
              selectionArgs, null);
        }
        
        int i1 = 0;
        ArrayList<Integer> ids = new ArrayList<Integer>();
        for (int i = 0; i < mIDs.length; i++) {
          if (mChecked[i])
            ids.add(mIDs[i]);
        }

        if (cursor.moveToFirst()) {
            if (ids.contains(cursor.getInt(0))) {
              ContentValues event = new ContentValues();
              event.put("calendar_id", mCalendarID); // ID
                                    // ??????????
                                    // ??
                                    // ????????
              // ?????
              event.put(CalendarContract.Events.TITLE,
                  cursor.getString(3)); // ????????? ?????????
              if(mExportOnlyNotes) {
                event.put(CalendarContract.Events.DESCRIPTION, cursor.getString(8));
              } else if(mExportNotes) {
                Cursor c = getContentResolver().query(RecordsDbHelper.CONTENT_URI_NOTES, new String[] { RecordsDbHelper.ID3, RecordsDbHelper.NOTE },RecordsDbHelper.ID3+ "=?" , new String[] { String.valueOf(cursor.getInt(5)) }, null);
                if(c.getCount() == 1) {
                  c.moveToFirst();
                  event.put(CalendarContract.Events.DESCRIPTION, c.getString(1)); // ?????????
                } else
                  event.put(CalendarContract.Events.DESCRIPTION, ""); // ?????????
                c.close();
              } else
                event.put(CalendarContract.Events.DESCRIPTION, ""); // ?????????
                                        // ?????????
              event.put(CalendarContract.Events.EVENT_TIMEZONE,
                  Time.getCurrentTimezone());
              event.put(CalendarContract.Events.DTSTART,
                  Long.toString(cursor.getLong(2))); // ??????
                                    // ??????
              event.put(CalendarContract.Events.DTEND,
                  Long.toString(cursor.getLong(7))); // ??????
                                    // ??????????
              event.put(CalendarContract.Events.HAS_ALARM, 0);// ???????????
              event.put("eventStatus", 1);// ?????? ????????????? ??
                            // ????????
              Uri count = getContentResolver().insert(
                  CalendarContract.Events.CONTENT_URI, event);
            }
            Intent intent = new Intent();
            intent.setAction(EXPORT);
            intent.putExtra("count", cursor.getCount());
            intent.putExtra("progress", i1);
            getApplicationContext().sendBroadcast(intent);
            i1++;
        }
        cursor.close();
        ExportToGoogleCalendarService.this.stopSelf();
        Intent intent3 = new Intent();
        intent3.setAction(EXPORT);
        getApplicationContext().sendBroadcast(intent3);

      }
    });

    isRunning = true;
    mSelectStartItem = intent.getLongExtra("start", mSelectStartItem);
    mSelectEndItem = intent.getLongExtra("stop", mSelectEndItem);
    mIDs = intent.getIntArrayExtra("ids");
    mChecked = intent.getBooleanArrayExtra("checked");
    mCalendarID = Integer.valueOf(intent.getStringExtra("calendar_id"));
    mExportNotes = intent.getBooleanExtra("export_notes", false);
    mExportOnlyNotes = intent.getBooleanExtra("export_only_notes", false);
    t.start();
    Toast.makeText(ExportToGoogleCalendarService.this, R.string.one_record_export, Toast.LENGTH_LONG).show();
    return super.onStartCommand(intent, flags, startId);
  };

  @Override
  public IBinder onBind(Intent intent) {
    return new Binder();
  }

  @Override
  public void onRebind(Intent intent) {
    super.onRebind(intent);
  }

  @Override
  public boolean onUnbind(Intent intent) {
    return super.onUnbind(intent);
  }

  @Override
  public void onDestroy() {
    isRunning = false;
    super.onDestroy();
  }
  

}




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