From e19fa0819c7e64c143a986db4cde07cacf4d73d5 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 27 Apr 2012 18:02:02 -0700 Subject: [PATCH] More awesomeness. All that's left is the snooze scheduling --- astrid/AndroidManifest.xml | 1 + .../astrid/calls/MissedCallActivity.java | 56 ++++++++++++++++--- .../calls/PhoneStateChangedReceiver.java | 6 ++ astrid/res/layout/astrid_missed_call_view.xml | 4 +- astrid/res/values/strings-core.xml | 11 +++- 5 files changed, 66 insertions(+), 12 deletions(-) diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index b51db00b3..d2098a98e 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -34,6 +34,7 @@ + diff --git a/astrid/plugin-src/com/todoroo/astrid/calls/MissedCallActivity.java b/astrid/plugin-src/com/todoroo/astrid/calls/MissedCallActivity.java index 11be3fee3..fd1844ec4 100644 --- a/astrid/plugin-src/com/todoroo/astrid/calls/MissedCallActivity.java +++ b/astrid/plugin-src/com/todoroo/astrid/calls/MissedCallActivity.java @@ -1,8 +1,11 @@ package com.todoroo.astrid.calls; import android.app.Activity; +import android.content.Intent; import android.content.res.Resources; +import android.net.Uri; import android.os.Bundle; +import android.text.TextUtils; import android.view.View; import android.view.View.OnClickListener; import android.widget.TextView; @@ -14,6 +17,7 @@ import com.todoroo.astrid.service.ThemeService; 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$ private final OnClickListener dismissListener = new OnClickListener() { @Override @@ -23,25 +27,63 @@ public class MissedCallActivity extends Activity { } }; + private String name; + private String number; + + private TextView returnCallButton; + private TextView callLaterButton; + private TextView ignoreButton; + private View dismissButton; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.missed_call_activity); + + Intent intent = getIntent(); + + name = intent.getStringExtra(EXTRA_NAME); + number = intent.getStringExtra(EXTRA_NUMBER); + int color = ThemeService.getThemeColor(); - TextView returnCallButton = (TextView) findViewById(R.id.call_return); - TextView addTaskButton = (TextView) findViewById(R.id.call_add); - TextView ignoreButton = (TextView) findViewById(R.id.call_ignore); - View dismissView = findViewById(R.id.dismiss); + returnCallButton = (TextView) findViewById(R.id.call_now); + callLaterButton = (TextView) findViewById(R.id.call_later); + ignoreButton = (TextView) findViewById(R.id.call_ignore); + dismissButton = findViewById(R.id.dismiss); Resources r = getResources(); returnCallButton.setBackgroundColor(r.getColor(color)); - addTaskButton.setBackgroundColor(r.getColor(color)); + callLaterButton.setBackgroundColor(r.getColor(color)); + + addListeners(); + String dialog; + + if (TextUtils.isEmpty(name)) { + dialog = getString(R.string.MCA_dialog_without_name, number); + } else { + dialog = getString(R.string.MCA_dialog_with_name, name); + } + + TextView dialogView = (TextView) findViewById(R.id.reminder_message); + dialogView.setText(dialog); + } + + private void addListeners() { ignoreButton.setOnClickListener(dismissListener); - dismissView.setOnClickListener(dismissListener); + dismissButton.setOnClickListener(dismissListener); + + returnCallButton.setOnClickListener(new OnClickListener() { - System.err.println("Should display notification for number: " + getIntent().getStringExtra(EXTRA_NUMBER)); + @Override + public void onClick(View v) { + Intent call = new Intent(Intent.ACTION_CALL); + call.setData(Uri.parse("tel:" + number)); //$NON-NLS-1$ + startActivity(call); + finish(); + } + }); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java b/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java index 2930bfc71..5deaf6737 100644 --- a/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java +++ b/astrid/plugin-src/com/todoroo/astrid/calls/PhoneStateChangedReceiver.java @@ -42,8 +42,14 @@ public class PhoneStateChangedReceiver extends BroadcastReceiver { try { if (calls.getCount() > 0) { + calls.moveToFirst(); + int nameIndex = calls.getColumnIndex(Calls.CACHED_NAME); + String name = ""; + if (nameIndex > -1) + name = calls.getString(nameIndex); Intent missedCallIntent = new Intent(context, MissedCallActivity.class); missedCallIntent.putExtra(MissedCallActivity.EXTRA_NUMBER, lastNumber); + missedCallIntent.putExtra(MissedCallActivity.EXTRA_NAME, name); missedCallIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(missedCallIntent); } diff --git a/astrid/res/layout/astrid_missed_call_view.xml b/astrid/res/layout/astrid_missed_call_view.xml index ec29b3c5f..bbd6570ae 100644 --- a/astrid/res/layout/astrid_missed_call_view.xml +++ b/astrid/res/layout/astrid_missed_call_view.xml @@ -37,7 +37,7 @@ Missed call! - Call back + Call now - Add to task list + Call later Ignore - + + + %s just called you! + + + Someone just called you from %s.