MessageGenerator(Context context, Address userAddress, AddressStyle addressStyle, HeaderGenerator headerGenerator, PersonLookup personLookup, boolean mailSubjectPrefix, @Nullable ContactGroupIds contactsToBackup, MmsSupport mmsSupport, CallLogTypes callLogTypes, DataTypePreferences dataTypePreferences) { this.headerGenerator = headerGenerator; this.userAddress = userAddress; this.addressStyle = addressStyle; this.context = context; this.personLookup = personLookup; this.prefix = mailSubjectPrefix; this.contactGroupIds = contactsToBackup; this.callFormatter = new CallFormatter(this.context.getResources()); this.mmsSupport = mmsSupport; this.dataTypePreferences = dataTypePreferences; this.callLogTypes = callLogTypes; }
public String format(int callType, String number, int duration) { final StringBuilder text = new StringBuilder(); if (callType != CallLog.Calls.MISSED_TYPE && callType != CallLog.Calls.REJECTED_TYPE) { text.append(duration) .append("s") .append(" (").append(formattedCallDuration(duration)).append(")") .append("\n"); } text.append(number) .append(" (").append(callTypeString(callType, null)).append(")"); return text.toString(); }
public void syncCalendar(ConversionResult result) { enableSync(); if (result.type != DataType.CALLLOG) return; for (Map<String, String> m : result.getMapList()) { try { final int duration = Integer.parseInt(m.get(CallLog.Calls.DURATION)); final int callType = Integer.parseInt(m.get(CallLog.Calls.TYPE)); final String number = m.get(CallLog.Calls.NUMBER); final Date then = new Date(Long.valueOf(m.get(CallLog.Calls.DATE))); final PersonRecord record = personLookup.lookupPerson(number); // insert into calendar calendarAccessor.addEntry( calendarId, then, duration, callFormatter.callTypeString(callType, record.getName()), callFormatter.formatForCalendar(callType, record.getNumber(), duration)); } catch (NumberFormatException e) { Log.w(TAG, "error", e); } } }
public String callTypeString(int callType, String name) { if (name == null) { return resources.getString(mapCallType(callType)); } else { return resources.getString(mapTextCallType(callType), name); } }
@Test public void shouldFormatOutgoing() throws Exception { assertThat(formatter.format(CallLog.Calls.OUTGOING_TYPE, "Foo", 100)) .isEqualTo("100s (00:01:40)\n" + "Foo (outgoing call)"); }
@Test public void shouldFormatForCalendarIncoming() throws Exception { assertThat(formatter.formatForCalendar(CallLog.Calls.INCOMING_TYPE, "Foo", 100)) .isEqualTo("Number: Foo (incoming call)\n" + "Duration: 00:01:40"); }
@Test public void shouldFormatCallIncoming() throws Exception { assertThat(formatter.callTypeString(CallLog.Calls.INCOMING_TYPE, "Foo")).isEqualTo("Call from Foo"); }
@Test public void shouldFormatCallDuration() throws Exception { assertThat(formatter.formattedCallDuration(1242)).isEqualTo("00:20:42"); }
@Test public void shouldFormatVoicemail() throws Exception { assertThat(formatter.format(CallLog.Calls.VOICEMAIL_TYPE, "Foo", 100)) .isEqualTo("100s (00:01:40)\n" + "Foo (incoming call, voicemail)"); }
@Test public void shouldFormatForCalendarOutgoing() throws Exception { assertThat(formatter.formatForCalendar(CallLog.Calls.OUTGOING_TYPE, "Foo", 100)) .isEqualTo("Number: Foo (outgoing call)\n" + "Duration: 00:01:40"); }
@Test public void shouldFormatCallOutgoing() throws Exception { assertThat(formatter.callTypeString(CallLog.Calls.OUTGOING_TYPE, "Foo")).isEqualTo("Called Foo"); }
public String formatForCalendar(int callType, String number, int duration) { StringBuilder description = new StringBuilder(); description.append(resources.getString(R.string.call_number_field, number)) .append(" (") .append(callTypeString(callType, null)) .append(")") .append("\n"); if (callType != CallLog.Calls.MISSED_TYPE) { description.append(resources.getString(R.string.call_duration_field, formattedCallDuration(duration))); } return description.toString(); }
@Test public void shouldSyncCalendar() throws Exception { ConversionResult result = new ConversionResult(DataType.CALLLOG); final String NUMBER = "12345"; final String NAME = "Foo"; final int DURATION = 10; final int TYPE = 1; Date callTime = new Date(); result.add(new MimeMessage(), message(DURATION, TYPE, NUMBER, callTime)); result.add(new MimeMessage(), message(DURATION, TYPE, NUMBER, callTime)); when(callFormatter.callTypeString(TYPE, NAME)).thenReturn("title1"); when(callFormatter.formatForCalendar(TYPE, NUMBER, DURATION)).thenReturn("title2"); when(personLookup.lookupPerson(NUMBER)).thenReturn(new PersonRecord(1, NAME, "foo@bar", NUMBER)); syncer.syncCalendar(result); verify(accessor, times(2)).addEntry(eq(CALENDAR_ID), eq(callTime), eq(DURATION), eq("title1"), eq("title2")); }
@Test public void shouldFormatIncoming() throws Exception { assertThat(formatter.format(CallLog.Calls.INCOMING_TYPE, "Foo", 100)) .isEqualTo("100s (00:01:40)\n" + "Foo (incoming call)"); }
@Test public void shouldFormatForCalendarMissed() throws Exception { assertThat(formatter.formatForCalendar(CallLog.Calls.MISSED_TYPE, "Foo", 100)) .isEqualTo("Number: Foo (missed call)\n"); } }
@Test public void shouldFormatCallMissed() throws Exception { assertThat(formatter.callTypeString(CallLog.Calls.MISSED_TYPE, "Foo")).isEqualTo("Missed call from Foo"); }
@Before public void before() { formatter = new CallFormatter(RuntimeEnvironment.application.getResources()); }
@Test public void shouldFormatRejected() throws Exception { assertThat(formatter.format(CallLog.Calls.REJECTED_TYPE, "Foo", 0)) .isEqualTo("Foo (incoming call, rejected)"); }
BackupTask(@NonNull SmsBackupService service) { final Context context = service.getApplicationContext(); this.service = service; this.authPreferences = service.getAuthPreferences(); this.preferences = service.getPreferences(); this.fetcher = new BackupItemsFetcher( context.getContentResolver(), new BackupQueryBuilder(preferences.getDataTypePreferences())); PersonLookup personLookup = new PersonLookup(service.getContentResolver()); this.contactAccessor = new ContactAccessor(); this.converter = new MessageConverter(context, service.getPreferences(), authPreferences.getUserEmail(), personLookup, contactAccessor); if (preferences.isCallLogCalendarSyncEnabled()) { calendarSyncer = new CalendarSyncer( CalendarAccessor.Get.instance(service.getContentResolver()), preferences.getCallLogCalendarId(), personLookup, new CallFormatter(context.getResources()) ); } else { calendarSyncer = null; } this.tokenRefresher = new TokenRefresher(service, new OAuth2Client(authPreferences.getOAuth2ClientId()), authPreferences); }
@Test public void shouldFormatMissing() throws Exception { assertThat(formatter.format(CallLog.Calls.MISSED_TYPE, "Foo", 100)) .isEqualTo("Foo (missed call)"); }