protected override async void OnHandleIntent (Intent intent) { mGoogleApiClient.BlockingConnect (Constants.CONNECTION_TIME_OUT_MS, TimeUnit.Milliseconds); // Query calendar events in the next 24 hours Time time = new Time (); time.SetToNow (); long beginTime = time.ToMillis (true); time.MonthDay++; time.Normalize (true); long endTime = time.Normalize (true); List<Event> events = QueryEvents(this, beginTime, endTime); foreach (Event ev in events) { PutDataMapRequest putDataMapRequest = ev.ToPutDataMapRequest (); if (mGoogleApiClient.IsConnected) { await WearableClass.DataApi.PutDataItemAsync (mGoogleApiClient, putDataMapRequest.AsPutDataRequest ()); } else { Log.Error (Constants.TAG, "Failed to send data item: " + putDataMapRequest + " - Client disconnected from Google Play Services"); } } mGoogleApiClient.Disconnect (); }
private string Validation() { _year = _yearGot.Text; _km = _kmGot.Text; Time now = new Time(); now.SetToNow(); int numValueyear; int numValuekm; int yearNow = now.Year; var got = int.TryParse(_year, out numValueyear); var value = int.TryParse(_km,out numValuekm); if (got && value) { if (numValuekm < 0 || numValueyear < 1910 || numValueyear > yearNow) { _calKmMax = 0; _calKmMin = 0; return "wrong input"; } var yearDiff = yearNow - numValueyear; _calKmMin = 10000 * yearDiff; _calKmMax = 20000 * yearDiff; if (_calKmMin < numValuekm && _calKmMax > numValuekm) return "within reasonale range"; return numValuekm <= _calKmMin ? "too low" : "too high"; } return "wrong"; }
/** * Return the vertical offset (in pixels) for a requested time (in * milliseconds since epoch). */ public int GetTimeVerticalOffset (long timeMillis) { Time time = new Time (UIUtils.ConferenceTimeZone.ID); time.Set (timeMillis); int minutes = ((time.Hour - mStartHour) * 60) + time.Minute; return (minutes * mHourHeight) / 60; }
public override void finishSync(bool refresh) { // delete leftover local notes NoteManager.purgeDeletedNotes(activity); Time now = new Time(); now.SetToNow(); string nowstring = now.Format3339(false); Preferences.putstring(Preferences.Key.LATEST_SYNC_DATE, nowstring); setSyncProgress(100); if (refresh) SendMessage(PARSING_COMPLETE); }
public override void OnCreate(ISurfaceHolder surfaceHolder) { this.SetWatchFaceStyle (new WatchFaceStyle.Builder (this.NFLWatchService) .SetCardPeekMode (WatchFaceStyle.PeekModeShort) .SetBackgroundVisibility (WatchFaceStyle.BackgroundVisibilityInterruptive) .SetShowSystemUiTime (false) .Build () ); base.OnCreate (surfaceHolder); // Define backgroundImage in analogue surface - Here you can give your custom background image from resource. //Eventually you can update it from datamap or configuration setting var backgroundDrawable = NFLWatchService.Resources.GetDrawable (Resource.Drawable.sea); backgroundBitmap = (backgroundDrawable as BitmapDrawable).Bitmap; //Draw hour niddle hourPaint = new Paint (); hourPaint.SetARGB(255, 123, 195, 66); hourPaint.StrokeWidth = 5.0f; hourPaint.AntiAlias = true; hourPaint.StrokeCap = Paint.Cap.Round; //Draw minute Niddle minutePaint = new Paint (); minutePaint.SetARGB(255, 123, 195, 66); minutePaint.StrokeWidth = 3.0f; minutePaint.AntiAlias = true; minutePaint.StrokeCap = Paint.Cap.Round; // Draw second niddle secondPaint = new Paint (); secondPaint.SetARGB (255, 255, 0, 0); secondPaint.StrokeWidth = 2.0f; secondPaint.AntiAlias = true; secondPaint.StrokeCap = Paint.Cap.Round; // Draw dial tickPaint = new Paint (); tickPaint.SetARGB(255, 123, 195, 66); tickPaint.StrokeWidth = 3.0f; tickPaint.AntiAlias = true; time = new Time (); }
public override void OnCreate(ISurfaceHolder holder) { this.SetWatchFaceStyle (new WatchFaceStyle.Builder (this.owner) .SetCardPeekMode (WatchFaceStyle.PeekModeShort) .SetBackgroundVisibility (WatchFaceStyle.BackgroundVisibilityInterruptive) .SetShowSystemUiTime (false) .Build () ); base.OnCreate (holder); var backgroundDrawable = owner.Resources.GetDrawable (Resource.Drawable.XamarinWatchFaceBackground); backgroundBitmap = (backgroundDrawable as BitmapDrawable).Bitmap; hourPaint = new Paint (); hourPaint.SetARGB (255, 200, 200, 200); hourPaint.StrokeWidth = 5.0f; hourPaint.AntiAlias = true; hourPaint.StrokeCap = Paint.Cap.Round; minutePaint = new Paint (); minutePaint.SetARGB (255, 200, 200, 200); minutePaint.StrokeWidth = 3.0f; minutePaint.AntiAlias = true; minutePaint.StrokeCap = Paint.Cap.Round; secondPaint = new Paint (); secondPaint.SetARGB (255, 255, 0, 0); secondPaint.StrokeWidth = 2.0f; secondPaint.AntiAlias = true; secondPaint.StrokeCap = Paint.Cap.Round; tickPaint = new Paint (); tickPaint.SetARGB (100, 200, 200, 200); tickPaint.StrokeWidth = 2.0f; tickPaint.AntiAlias = true; time = new Time (); }
protected void onChooseNote(string title, string content, bool choseLocal) { title = NoteManager.validateNoteTitle(this, title, localNote.getGuid()); Time now = new Time(); now.SetToNow(); string time = now.Format3339(false); localNote.setTitle(title); localNote.setXmlContent(content); localNote.setLastChangeDate(time); // doing a title difference if(differentNotes) { if(choseLocal) { // chose to keep local, delete remote, push local pullNote(localNote); remoteNote.addTag("system:deleted"); if(noRemote) { finishForResult(new Intent()); return; } pushNote(localNote); // add for pushing pushNote(remoteNote); // add for deletion } else { // chose to keep remote, delete local, add remote, push remote back deleteNote(localNote); remoteNote.setTitle(title); remoteNote.setXmlContent(content); remoteNote.setLastChangeDate(time); pullNote(remoteNote); if(!noRemote) pushNote(remoteNote); } } else { // just readd and push modified localNote pullNote(localNote); if(!noRemote) pushNote(localNote); } finishForResult(new Intent()); }
/// <summary> /// Collects crash data. /// </summary> /// <param name="context"><see cref="Context"/> for the application being reported.</param> /// <param name="reportFields"><see cref="Array"/> of <see cref="ReportField"/> to include in report</param> /// <param name="appStartDate"><see cref="Time"/> of application start</param> /// <param name="initialConfiguration">Application initial configuration</param> /// <param name="th"><see cref="Java.Lang.Throwable"/> that caused the crash.</param> /// <param name="isSilentReport">Whether to report this report as being sent silently.</param> /// <returns>Builded report data</returns> public static ReportData BuildReportData(Context context, ReportField[] reportFields, Time appStartDate, string initialConfiguration, Java.Lang.Throwable th, bool isSilentReport) { var crashReportData = new ReportData(); try { crashReportData.Add(ReportField.StackTrace, th.StackTrace); crashReportData.Add(ReportField.UserAppStartDate, appStartDate.Format3339(false)); if (isSilentReport) { crashReportData.Add(ReportField.IsSilent, "true"); } if (reportFields.Contains(ReportField.ReportID)) { crashReportData.Add(ReportField.ReportID, Guid.NewGuid().ToString()); } if (reportFields.Contains(ReportField.InstallationID)) { crashReportData.Add(ReportField.InstallationID, Installation.Id(context)); } if (reportFields.Contains(ReportField.InitialConfiguration)) { crashReportData.Add(ReportField.InitialConfiguration, initialConfiguration); } if (reportFields.Contains(ReportField.CrashConfiguration)) { crashReportData.Add(ReportField.CrashConfiguration, ReportUtils.GetCrashConfiguration(context)); } if (reportFields.Contains(ReportField.DumpsysMeminfo)) { crashReportData.Add(ReportField.DumpsysMeminfo, DumpSysCollector.CollectMemInfo()); } if (reportFields.Contains(ReportField.PackageName)) { crashReportData.Add(ReportField.PackageName, context.PackageName); } if (reportFields.Contains(ReportField.Build)) { crashReportData.Add(ReportField.Build, ReflectionCollector.CollectStaticProperties(typeof(Build))); } if (reportFields.Contains(ReportField.PhoneModel)) { crashReportData.Add(ReportField.PhoneModel, Build.Model); } if (reportFields.Contains(ReportField.AndroidVersion)) { crashReportData.Add(ReportField.AndroidVersion, Build.VERSION.Release); } if (reportFields.Contains(ReportField.Brand)) { crashReportData.Add(ReportField.Brand, Build.Brand); } if (reportFields.Contains(ReportField.Product)) { crashReportData.Add(ReportField.Product, Build.Product); } if (reportFields.Contains(ReportField.TotalMemSize)) { crashReportData.Add(ReportField.TotalMemSize, ReportUtils.TotalInternalMemorySize.ToString()); } if (reportFields.Contains(ReportField.AvailableMemSize)) { crashReportData.Add(ReportField.AvailableMemSize, ReportUtils.AvailableInternalMemorySize.ToString()); } if (reportFields.Contains(ReportField.FilePath)) { crashReportData.Add(ReportField.FilePath, ReportUtils.GetApplicationFilePath(context)); } if (reportFields.Contains(ReportField.Display)) { crashReportData.Add(ReportField.Display, ReportUtils.GetDisplayDetails(context)); } if (reportFields.Contains(ReportField.UserCrashDate)) { var curDate = new Time(); curDate.SetToNow(); crashReportData.Add(ReportField.UserCrashDate, curDate.Format3339(false)); } if (reportFields.Contains(ReportField.DeviceFeatures)) { crashReportData.Add(ReportField.DeviceFeatures, DeviceFeaturesCollector.GetFeatures(context)); } if (reportFields.Contains(ReportField.Environment)) { crashReportData.Add(ReportField.Environment, ReflectionCollector.CollectStaticProperties(typeof(Environment))); } if (reportFields.Contains(ReportField.SettingsSystem)) { crashReportData.Add(ReportField.SettingsSystem, SettingsCollector.CollectSystemSettings(context)); } if (reportFields.Contains(ReportField.SettingsSecure)) { crashReportData.Add(ReportField.SettingsSecure, SettingsCollector.CollectSecureSettings(context)); } if (reportFields.Contains(ReportField.SharedPreferences)) { crashReportData.Add(ReportField.SharedPreferences, SharedPreferencesCollector.Collect(context)); } var pm = new PackageManagerWrapper(context); var pi = pm.GetPackageInfo(); if (pi != null) { if (reportFields.Contains(ReportField.AppVersionCode)) { crashReportData.Add(ReportField.AppVersionCode, pi.VersionCode.ToString()); } if (reportFields.Contains(ReportField.AppVersionName)) { crashReportData.Add(ReportField.AppVersionName, pi.VersionName ?? "not set"); } } else { crashReportData.Add(ReportField.AppVersionName, "Package info unavailable"); } if (reportFields.Contains(ReportField.DeviceID) && pm.HasPermission(Manifest.Permission.ReadPhoneState)) { var deviceId = ReportUtils.GetDeviceId(context); if (deviceId != null) { crashReportData.Add(ReportField.DeviceID, deviceId); } } if (pm.HasPermission(Manifest.Permission.ReadLogs)) { Log.Info(Constants.LOG_TAG, "READ_LOGS granted! Crasher can include LogCat and DropBox data."); if (reportFields.Contains(ReportField.Logcat)) { crashReportData.Add(ReportField.Logcat, LogCatCollector.CollectLogCat(null)); } if (reportFields.Contains(ReportField.Eventslog)) { crashReportData.Add(ReportField.Eventslog, LogCatCollector.CollectLogCat("events")); } if (reportFields.Contains(ReportField.Radiolog)) { crashReportData.Add(ReportField.Radiolog, LogCatCollector.CollectLogCat("radio")); } } else { Log.Info(Constants.LOG_TAG, "READ_LOGS not allowed. Crasher will not include LogCat and DropBox data."); } } catch (Java.Lang.RuntimeException e) { Log.Error(Constants.LOG_TAG, e, "Error while retrieving crash data"); } return crashReportData; }
private void saveNote() { TLog.v(TAG, "saving note"); bool updated = updateNoteContent(xmlOn); if(!updated) { Toast.MakeText(this, Resources.GetString(Resource.String.messageErrorParsingXML),ToastLength.Short).Show(); return; } string validTitle = NoteManager.validateNoteTitle(this, title.Text, note.getGuid()); title.SetText(validTitle); note.setTitle(validTitle); Time now = new Time(); now.SetToNow(); string time = now.Format3339(false); note.setLastChangeDate(time); NoteManager.putNote( this, note); if(!SyncManager.getInstance().getCurrentService().needsLocation() && Preferences.GetBoolean(Preferences.Key.AUTO_BACKUP_NOTES)) { TLog.v(TAG, "backing note up"); SdCardSyncService.backupNote(note); } textChanged = false; NewNote.neverSaved = false; Toast.MakeText(this, Resources.GetString(Resource.String.messageNoteSaved), ToastLength.Short).Show(); TLog.v(TAG, "note saved"); }
// syncing with remote changes protected void prepareSyncableNotes(List<Note> notesList) { remoteGuids = new List<string>(); pushableNotes = new List<Note>(); pullableNotes = new List<Note>(); comparableNotes = new List<Note[]>(); deleteableNotes = new List<Note>(); conflictingNotes = new List<Note[]>(); // check if remote notes are already in local foreach(Note remoteNote in notesList) { Note localNote = NoteManager.getNoteByGuid(activity,remoteNote.getGuid()); remoteGuids.Add(remoteNote.getGuid()); if(localNote == null) { // check to make sure there is no note with this title, otherwise show conflict dialogue ICursor cursor = NoteManager.getTitles(activity); if (!(cursor == null || cursor.Count == 0)) { cursor.MoveToFirst(); do { string atitle = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.TITLE)); if(atitle.Equals(remoteNote.getTitle())) { string aguid = cursor.GetString(cursor.GetColumnIndexOrThrow(Note.GUID)); localNote = NoteManager.getNoteByGuid(activity, aguid); break; } } while (cursor.MoveToNext()); } cursor.Close(); if(localNote == null) pullableNotes.Add(remoteNote); else { // compare two different notes with same title remoteGuids.Add(localNote.getGuid()); // add to avoid catching it below Note[] compNotes = {localNote, remoteNote}; comparableNotes.Add(compNotes); } } else { Note[] compNotes = {localNote, remoteNote}; comparableNotes.Add(compNotes); } } if(cancelled) { doCancel(); return; } // get non-remote notes; if newer than last sync, push, otherwise delete ICursor localGuids = NoteManager.getGuids(this.activity); if (!(localGuids == null || localGuids.Count == 0)) { string localGuid; localGuids.MoveToFirst(); do { localGuid = localGuids.GetString(localGuids.GetColumnIndexOrThrow(Note.GUID)); if(!remoteGuids.Contains(localGuid)) { Note note = NoteManager.getNoteByGuid(this.activity, localGuid); string syncDatestring = Preferences.GetString(Preferences.Key.LATEST_SYNC_DATE); Time syncDate = new Time(); syncDate.Parse3339(syncDatestring); int compareSync = Time.Compare(syncDate, note.getLastChangeDate()); if(compareSync > 0) // older than last sync, means it's been deleted from server deleteableNotes.Add(note); else if(!note.getTags().Contains("system:template")) // don't push templates TODO: find out what's wrong with this, if anything pushableNotes.Add(note); } } while (localGuids.MoveToNext()); } TLog.d(TAG, "Notes to pull: {0}, Notes to push: {1}, Notes to delete: {2}, Notes to compare: {3}",pullableNotes.Count,pushableNotes.Count,deleteableNotes.Count,comparableNotes.Count); if(cancelled) { doCancel(); return; } // deal with notes in both - compare and push, pull or diff syncDatestring = Preferences.GetString(Preferences.Key.LATEST_SYNC_DATE); syncDate = new Time(); syncDate.Parse3339(syncDatestring); foreach (var notes in comparableNotes) { Note localNote = notes[0]; Note remoteNote = notes[1]; // if different guids, means conflicting titles if(!remoteNote.getGuid().Equals(localNote.getGuid())) { TLog.i(TAG, "adding conflict of two different notes with same title"); conflictingNotes.Add(notes); continue; } if(cancelled) { doCancel(); return; } int compareSyncLocal = Time.Compare(syncDate, localNote.getLastChangeDate()); int compareSyncRemote = Time.Compare(syncDate, remoteNote.getLastChangeDate()); int compareBoth = Time.Compare(localNote.getLastChangeDate(), remoteNote.getLastChangeDate()); // if not two-way and not same date, overwrite the local version if(!push && compareBoth != 0) { TLog.i(TAG, "Different note dates, overwriting local note"); pullableNotes.Add(remoteNote); continue; } // begin compare if(cancelled) { doCancel(); return; } // check date difference TLog.v(TAG, "compare both: {0}, compare local: {1}, compare remote: {2}", compareBoth, compareSyncLocal, compareSyncRemote); if(compareBoth != 0) TLog.v(TAG, "Different note dates"); if((compareSyncLocal < 0 && compareSyncRemote < 0) || (compareSyncLocal > 0 && compareSyncRemote > 0)) TLog.v(TAG, "both either older or newer"); if(compareBoth != 0 && ((compareSyncLocal < 0 && compareSyncRemote < 0) || (compareSyncLocal > 0 && compareSyncRemote > 0))) { // sync conflict! both are older or newer than last sync TLog.i(TAG, "Note Conflict: TITLE:{0} GUID:{1}", localNote.getTitle(), localNote.getGuid()); conflictingNotes.Add(notes); } else if(compareBoth > 0) // local newer, bundle in pushable pushableNotes.Add(localNote); else if(compareBoth < 0) { // local older, pull immediately, no need to bundle TLog.i(TAG, "Local note is older, updating in content provider TITLE:{0} GUID:{1}", localNote.getTitle(), localNote.getGuid()); pullableNotes.Add(remoteNote); } else { // both same date if(localNote.getTags().Contains("system:deleted") && push) { // deleted, bundle for remote deletion TLog.i(TAG, "Notes are same date, deleted, deleting remote: TITLE:{0} GUID:{1}", localNote.getTitle(), localNote.getGuid()); pushableNotes.Add(localNote); } else { // do nothing TLog.i(TAG, "Notes are same date, doing nothing: TITLE:{0} GUID:{1}", localNote.getTitle(), localNote.getGuid()); // NoteManager.putNote(activity, remoteNote); } } } if(conflictingNotes.IsEmpty()) doSyncNotes(); else fixConflictingNotes(); }
private void populateFields(View v, Cursor c) { int nameCol = c.getColumnIndex(Note.TITLE); int modifiedCol = c.getColumnIndex(Note.MODIFIED_DATE); int tagCol = c.getColumnIndex(Note.TAGS); string title = c.GetString(nameCol); string tags = c.GetString(tagCol); //Format last modified dates to be similar to desktop Tomboy //TODO this is messy - must be a better way than having 3 separate date types Time lastModified = new Time(); lastModified.parse3339(c.GetString(modifiedCol)); Long lastModifiedMillis = lastModified.toMillis(false); Date lastModifiedDate = new Date(lastModifiedMillis); string strModified = this.context.GetString(Resource.String.textModified)+" "; //TODO this is very inefficient if (DateUtils.isToday(lastModifiedMillis)){ strModified += this.context.GetString(Resource.String.textToday) +", " + localeTimeFormat.format(lastModifiedDate); } else { // Add a day to the last modified date - if the date is now today, it means the note was edited yesterday Time yesterdayTest = lastModified; yesterdayTest.monthDay += 1; if (DateUtils.isToday(yesterdayTest.toMillis(false))){ strModified += this.context.GetString(Resource.String.textYexterday) +", " + localeTimeFormat.format(lastModifiedDate); } else { strModified += localeDateFormat.format(lastModifiedDate) + ", " + localeTimeFormat.format(lastModifiedDate); } } /** * Next set the name of the entry. */ TextView note_title = (TextView) v.FindViewById(Resource.Id.note_title); if (note_title != null) { note_title.SetText(title); if(tags.contains("system:deleted")) note_title.setPaintFlags(note_title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); else note_title.setPaintFlags(note_title.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); } TextView note_modified = (TextView) v.FindViewById(Resource.Id.note_date); if (note_modified != null) { note_modified.SetText(strModified); } }
public void setLastChangeDate(Time lastChangeDateTime) { this.lastChangeDate = lastChangeDateTime.Format3339(false); }
// sets change date to now public void setLastChangeDate() { Time now = new Time(); now.SetToNow(); String time = now.Format3339(false); setLastChangeDate(time); }
public Time getLastChangeDate() { Time time = new Time(); time.Parse3339(lastChangeDate); return time; }
// this function removes a "deleted" tag public static void undeleteNote(Activity activity, Note note) { note.removeTag("system:deleted"); Time now = new Time(); now.SetToNow(); note.setLastChangeDate(now); putNote(activity,note); }