From 29555b08a43dd67551823dd59b00d8dba3c7d42f Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 30 Apr 2012 19:23:15 -0700 Subject: [PATCH] Picture in missed call view, polish close button --- astrid/AndroidManifest.xml | 1 - .../astrid/calls/MissedCallActivity.java | 13 ++++- .../calls/PhoneStateChangedReceiver.java | 46 ++++++++++++++++-- .../res/drawable-hdpi/close_clear_cancel.png | Bin 0 -> 1391 bytes astrid/res/drawable/close_clear_cancel.png | Bin 0 -> 1391 bytes .../res/layout-land/astrid_reminder_view.xml | 2 +- astrid/res/layout/astrid_missed_call_view.xml | 10 +++- astrid/res/layout/astrid_reminder_view.xml | 2 +- .../layout/astrid_reminder_view_portrait.xml | 2 +- astrid/res/layout/tag_settings_activity.xml | 2 +- astrid/res/layout/task_edit_activity.xml | 2 +- astrid/res/values/strings-core.xml | 4 +- .../astrid/activity/TaskEditFragment.java | 2 +- .../astrid/service/UpgradeService.java | 2 + .../astrid/service/abtesting/ABTests.java | 7 ++- .../astrid/utility/AstridPreferences.java | 4 +- 16 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 astrid/res/drawable-hdpi/close_clear_cancel.png create mode 100644 astrid/res/drawable/close_clear_cancel.png diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index d2098a98e..b51db00b3 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -34,7 +34,6 @@ - diff --git a/astrid/plugin-src/com/todoroo/astrid/calls/MissedCallActivity.java b/astrid/plugin-src/com/todoroo/astrid/calls/MissedCallActivity.java index d6f8e0593..2079e3190 100644 --- a/astrid/plugin-src/com/todoroo/astrid/calls/MissedCallActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/calls/MissedCallActivity.java @@ -10,6 +10,7 @@ import android.os.Bundle; import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; +import android.widget.ImageView; import android.widget.TextView; import com.timsu.astrid.R; @@ -29,6 +30,7 @@ public class MissedCallActivity extends Activity { public static final String EXTRA_NUMBER = "number"; //$NON-NLS-1$ public static final String EXTRA_NAME = "name"; //$NON-NLS-1$ public static final String EXTRA_TIME = "time"; //$NON-NLS-1$ + public static final String EXTRA_PHOTO = "photo"; //$NON-NLS-1$ private static final String PREF_IGNORE_PRESSES = "missedCallsIgnored"; //$NON-NLS-1$ @@ -96,6 +98,7 @@ public class MissedCallActivity extends Activity { name = intent.getStringExtra(EXTRA_NAME); number = intent.getStringExtra(EXTRA_NUMBER); timeString = intent.getStringExtra(EXTRA_TIME); + String picture = intent.getStringExtra(EXTRA_PHOTO); int color = ThemeService.getThemeColor(); @@ -103,7 +106,15 @@ public class MissedCallActivity extends Activity { callLaterButton = (TextView) findViewById(R.id.call_later); ignoreButton = (TextView) findViewById(R.id.call_ignore); dismissButton = findViewById(R.id.dismiss); - ((TextView) findViewById(R.id.reminder_title)).setText(getString(R.string.MCA_title, timeString)); + ((TextView) findViewById(R.id.reminder_title)) + .setText(getString(R.string.MCA_title, + TextUtils.isEmpty(name) ? number : name, timeString)); + + ImageView pictureView = ((ImageView) findViewById(R.id.contact_picture)); + if (TextUtils.isEmpty(picture)) + pictureView.setImageDrawable(getResources().getDrawable(R.drawable.none)); + else + pictureView.setImageURI(Uri.parse(picture)); Resources r = getResources(); returnCallButton.setBackgroundColor(r.getColor(color)); diff --git a/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java b/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java index 9d686bb13..7fe0d8c4a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java +++ b/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java @@ -6,7 +6,9 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.database.Cursor; +import android.net.Uri; import android.provider.CallLog.Calls; +import android.provider.ContactsContract; import android.telephony.TelephonyManager; import android.text.TextUtils; @@ -49,9 +51,7 @@ public class PhoneStateChangedReceiver extends BroadcastReceiver { ); try { - if (calls.getCount() > 0) { - calls.moveToFirst(); - + if (calls.moveToFirst()) { int numberIndex = calls.getColumnIndex(Calls.NUMBER); String number = calls.getString(numberIndex); @@ -65,7 +65,7 @@ public class PhoneStateChangedReceiver extends BroadcastReceiver { // and will be processed again. int dateIndex = calls.getColumnIndex(Calls.DATE); long date = calls.getLong(dateIndex); - if (DateUtilities.now() - date > 2 * DateUtilities.ONE_MINUTE) + if (DateUtilities.now() - date < 2 * DateUtilities.ONE_MINUTE) return; int nameIndex = calls.getColumnIndex(Calls.CACHED_NAME); @@ -75,11 +75,13 @@ public class PhoneStateChangedReceiver extends BroadcastReceiver { long time = calls.getLong(timeIndex); String timeString = DateUtilities.getTimeString(context, new Date(time)); + String photo = getContactPhotoFromNumber(context, number); Intent missedCallIntent = new Intent(context, MissedCallActivity.class); missedCallIntent.putExtra(MissedCallActivity.EXTRA_NUMBER, number); missedCallIntent.putExtra(MissedCallActivity.EXTRA_NAME, name); missedCallIntent.putExtra(MissedCallActivity.EXTRA_TIME, timeString); + missedCallIntent.putExtra(MissedCallActivity.EXTRA_PHOTO, photo); missedCallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); context.startActivity(missedCallIntent); } @@ -101,4 +103,40 @@ public class PhoneStateChangedReceiver extends BroadcastReceiver { return builder.toString(); } + private String getContactPhotoFromNumber(Context context, String number) { + return getPhotoForContactId(context, getContactIdFromNumber(context, number)); + } + + private long getContactIdFromNumber(Context context, String number) { + Uri contactUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number)); + Cursor c = context.getContentResolver().query(contactUri, new String[] { ContactsContract.PhoneLookup._ID }, null, null, null); + + try { + if (c.moveToFirst()) { + long id = c.getLong(c.getColumnIndex(ContactsContract.PhoneLookup._ID)); + return id; + } + } finally { + c.close(); + } + return -1; + } + + private String getPhotoForContactId(Context context, long contactId) { + if (contactId < 0) + return ""; + Cursor c = context.getContentResolver().query(ContactsContract.Contacts.CONTENT_FILTER_URI, + new String[] { ContactsContract.Contacts.PHOTO_URI }, + ContactsContract.Contacts._ID + " = ?", new String[] { Long.toString(contactId) }, null); + try { + if (c.moveToFirst()) { + String uri = c.getString(c.getColumnIndex(ContactsContract.Contacts.PHOTO_URI)); + return uri; + } + } finally { + c.close(); + } + return ""; + } + } diff --git a/astrid/res/drawable-hdpi/close_clear_cancel.png b/astrid/res/drawable-hdpi/close_clear_cancel.png new file mode 100644 index 0000000000000000000000000000000000000000..778c7f0812d8d59d7ec939c631119a902e589ee9 GIT binary patch literal 1391 zcmV-#1(5oQP)ngbTigy2`#dwm3%KVlF_q@R2XQu99UR~Y{iNA92xyBdQg3wFtt;Wn+d{~AT70AA z6Rc+}Is%Re;5fdzgwx{dO1BC?0R94b(Z;l{QUe?j2bHF%P1ej_K94Q{$oP!7uH+L= z&scOsc=n@fpeEs~}xje{fNpwX0WNw(R~=TO4a#lsmdu~%jz znValoWc4cmaA5%x+%hea)~RNIBMhKgO1GqS^AGOAhLTILSTZs!91*~z_w|`$>;)|N zTxTBufD7~3%Wcz=Qe}uEW>{M6W3gmpNH`*Z@8C#InT=*T*(G25DgX}=uSA45aIMub zw(W;=%1k74lzm>szA6B~gCvSp`z2b-*FUjqQ(LKgdqRp?p_91(*? z`V{pp=0wr{82hY-eN8|Kf=q>VEe0G6hye!$CvYgQ%(i5nU?11CuLJN9%lyMzt2n7O zQUeO$f(++j)C|r%bY-sad>#ABVdo~A&D>-wZfi+*ZzGoZTfPV%fPzfCzQaC= zBRORzlIdo1C}BTeGc75lYb6MqT&RNZ37n(wwz5=WUyPGX2fKs?;ldpDa@(|})K*@o zG(~OqjRhA%!0G`wEWw&lh>t}_1lzJdoax>g$S%xdKVLI#;vtwYu(@GUCz4pGA2VU9!75dQ8`Dn5!SRmwG zXK2YwtMWK;A?u}{ln&FTm;}5%_yy*F-_^4v#1^92#^)N|zw=5yaP`5jvI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