Missed Call Notifications
@ -1,190 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.calls;
|
||||
|
||||
import android.content.ContentUris;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.todoroo.andlib.utility.AndroidUtilities;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.service.StartupService;
|
||||
import com.todoroo.astrid.service.TaskService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.tasks.R;
|
||||
import org.tasks.dialogs.DialogBuilder;
|
||||
import org.tasks.injection.InjectingAppCompatActivity;
|
||||
import org.tasks.intents.TaskIntents;
|
||||
import org.tasks.preferences.ActivityPreferences;
|
||||
import org.tasks.preferences.BasicPreferences;
|
||||
import org.tasks.preferences.ResourceResolver;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class MissedCallActivity extends InjectingAppCompatActivity {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MissedCallActivity.class);
|
||||
|
||||
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_CONTACT_ID = "contactId"; //$NON-NLS-1$
|
||||
|
||||
private static final String PREF_IGNORE_PRESSES = "missedCallsIgnored"; //$NON-NLS-1$
|
||||
|
||||
// Prompt user to ignore all missed calls after this many ignore presses
|
||||
private static final int IGNORE_PROMPT_COUNT = 3;
|
||||
|
||||
@Inject StartupService startupService;
|
||||
@Inject TaskService taskService;
|
||||
@Inject ActivityPreferences preferences;
|
||||
@Inject ResourceResolver resourceResolver;
|
||||
@Inject DialogBuilder dialogBuilder;
|
||||
|
||||
private final OnClickListener dismissListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
finish();
|
||||
AndroidUtilities.callOverridePendingTransition(MissedCallActivity.this, 0, android.R.anim.fade_out);
|
||||
}
|
||||
};
|
||||
|
||||
private final OnClickListener ignoreListener = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(final View v) {
|
||||
// Check for number of ignore presses
|
||||
int ignorePresses = preferences.getInt(PREF_IGNORE_PRESSES, 0);
|
||||
ignorePresses++;
|
||||
if (ignorePresses == IGNORE_PROMPT_COUNT) {
|
||||
dialogBuilder.newMessageDialog(R.string.MCA_ignore_body)
|
||||
.setPositiveButton(R.string.MCA_ignore_all, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
preferences.setBoolean(R.string.p_field_missed_calls, false);
|
||||
dismissListener.onClick(v);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.MCA_ignore_this, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dismissListener.onClick(v);
|
||||
}
|
||||
})
|
||||
.show();
|
||||
} else {
|
||||
dismissListener.onClick(v);
|
||||
}
|
||||
preferences.setInt(PREF_IGNORE_PRESSES, ignorePresses);
|
||||
}
|
||||
};
|
||||
|
||||
private String name;
|
||||
private String number;
|
||||
|
||||
private TextView returnCallButton;
|
||||
private TextView callLaterButton;
|
||||
private TextView ignoreButton;
|
||||
private View ignoreSettingsButton;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
startupService.onStartupApplication(this);
|
||||
|
||||
setContentView(R.layout.missed_call_activity);
|
||||
|
||||
Intent intent = getIntent();
|
||||
|
||||
name = intent.getStringExtra(EXTRA_NAME);
|
||||
number = intent.getStringExtra(EXTRA_NUMBER);
|
||||
String timeString = intent.getStringExtra(EXTRA_TIME);
|
||||
long contactId = intent.getExtras().getLong(EXTRA_CONTACT_ID);
|
||||
|
||||
int color = resourceResolver.getData(R.attr.asThemeTextColor);
|
||||
|
||||
returnCallButton = (TextView) findViewById(R.id.call_now);
|
||||
callLaterButton = (TextView) findViewById(R.id.call_later);
|
||||
ignoreButton = (TextView) findViewById(R.id.call_ignore);
|
||||
ignoreSettingsButton = findViewById(R.id.ignore_settings);
|
||||
((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 (contactId >= 0) {
|
||||
Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI, contactId);
|
||||
InputStream input = ContactsContract.Contacts.openContactPhotoInputStream(getContentResolver(), uri);
|
||||
Bitmap b = null;
|
||||
try {
|
||||
b = BitmapFactory.decodeStream(input);
|
||||
} catch (OutOfMemoryError e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
if (b != null) {
|
||||
pictureView.setImageBitmap(b);
|
||||
pictureView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
returnCallButton.setBackgroundColor(color);
|
||||
callLaterButton.setBackgroundColor(color);
|
||||
|
||||
addListeners();
|
||||
}
|
||||
|
||||
private void addListeners() {
|
||||
ignoreButton.setOnClickListener(ignoreListener);
|
||||
|
||||
ignoreSettingsButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent editPreferences = new Intent(MissedCallActivity.this, BasicPreferences.class);
|
||||
startActivity(editPreferences);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
returnCallButton.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent call = new Intent(Intent.ACTION_VIEW);
|
||||
call.setData(Uri.parse("tel:" + number)); //$NON-NLS-1$
|
||||
startActivity(call);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
callLaterButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Task task = new Task() {{
|
||||
setTitle(TextUtils.isEmpty(name)
|
||||
? getString(R.string.MCA_task_title_no_name, number)
|
||||
: getString(R.string.MCA_task_title_name, name, number));
|
||||
}};
|
||||
taskService.save(task);
|
||||
TaskIntents
|
||||
.getEditTaskStack(MissedCallActivity.this, null, task.getId())
|
||||
.startActivities();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package org.tasks.reminders;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.service.TaskService;
|
||||
|
||||
import org.tasks.R;
|
||||
import org.tasks.injection.InjectingAppCompatActivity;
|
||||
import org.tasks.intents.TaskIntents;
|
||||
import org.tasks.notifications.NotificationManager;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class MissedCallActivity extends InjectingAppCompatActivity implements DialogInterface.OnDismissListener, MissedCallDialog.MissedCallHandler {
|
||||
|
||||
private static final String FRAG_TAG_MISSED_CALL_FRAGMENT = "frag_tag_missed_call_fragment";
|
||||
|
||||
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_TITLE = "extra_title";
|
||||
public static final String EXTRA_CALL_NOW = "extra_call_now";
|
||||
public static final String EXTRA_CALL_LATER = "extra_call_later";
|
||||
|
||||
@Inject TaskService taskService;
|
||||
@Inject NotificationManager notificationManager;
|
||||
|
||||
private String name;
|
||||
private String number;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Intent intent = getIntent();
|
||||
|
||||
name = intent.getStringExtra(EXTRA_NAME);
|
||||
number = intent.getStringExtra(EXTRA_NUMBER);
|
||||
|
||||
if (intent.getBooleanExtra(EXTRA_CALL_NOW, false)) {
|
||||
callNow();
|
||||
} else if (intent.getBooleanExtra(EXTRA_CALL_LATER, false)) {
|
||||
callLater();
|
||||
} else {
|
||||
FragmentManager supportFragmentManager = getSupportFragmentManager();
|
||||
MissedCallDialog fragment = (MissedCallDialog) supportFragmentManager.findFragmentByTag(FRAG_TAG_MISSED_CALL_FRAGMENT);
|
||||
if (fragment == null) {
|
||||
fragment = new MissedCallDialog();
|
||||
fragment.setTitle(intent.getStringExtra(EXTRA_TITLE));
|
||||
fragment.show(supportFragmentManager, FRAG_TAG_MISSED_CALL_FRAGMENT);
|
||||
}
|
||||
fragment.setOnDismissListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callNow() {
|
||||
Intent call = new Intent(Intent.ACTION_VIEW);
|
||||
call.setData(Uri.parse("tel:" + number)); //$NON-NLS-1$
|
||||
startActivity(call);
|
||||
cancelNotificationAndFinish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callLater() {
|
||||
Task task = new Task() {{
|
||||
setTitle(TextUtils.isEmpty(name)
|
||||
? getString(R.string.MCA_task_title_no_name, number)
|
||||
: getString(R.string.MCA_task_title_name, name, number));
|
||||
}};
|
||||
taskService.save(task);
|
||||
TaskIntents
|
||||
.getEditTaskStack(this, null, task.getId())
|
||||
.startActivities();
|
||||
cancelNotificationAndFinish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void ignore() {
|
||||
cancelNotificationAndFinish();
|
||||
}
|
||||
|
||||
private void cancelNotificationAndFinish() {
|
||||
notificationManager.cancel(number.hashCode());
|
||||
finish();
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
package org.tasks.reminders;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.tasks.R;
|
||||
import org.tasks.dialogs.DialogBuilder;
|
||||
import org.tasks.injection.InjectingDialogFragment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
public class MissedCallDialog extends InjectingDialogFragment {
|
||||
|
||||
public interface MissedCallHandler {
|
||||
void callNow();
|
||||
|
||||
void callLater();
|
||||
|
||||
void ignore();
|
||||
}
|
||||
|
||||
@Inject DialogBuilder dialogBuilder;
|
||||
|
||||
private DialogInterface.OnDismissListener onDismissListener;
|
||||
private String title;
|
||||
|
||||
MissedCallHandler handler;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
List<String> actions = asList(
|
||||
getString(R.string.MCA_return_call),
|
||||
getString(R.string.MCA_add_task),
|
||||
getString(R.string.MCA_ignore));
|
||||
|
||||
handler = (MissedCallHandler) getActivity();
|
||||
|
||||
return dialogBuilder.newDialog()
|
||||
.setTitle(title)
|
||||
.setItems(actions.toArray(new String[actions.size()]), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case 0:
|
||||
handler.callNow();
|
||||
break;
|
||||
case 1:
|
||||
handler.callLater();
|
||||
break;
|
||||
default:
|
||||
handler.ignore();
|
||||
}
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
public void setOnDismissListener(DialogInterface.OnDismissListener onDismissListener) {
|
||||
this.onDismissListener = onDismissListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (onDismissListener != null) {
|
||||
onDismissListener.onDismiss(dialog);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 326 B |
After Width: | Height: | Size: 340 B |
After Width: | Height: | Size: 408 B |
After Width: | Height: | Size: 420 B |
After Width: | Height: | Size: 574 B |
After Width: | Height: | Size: 597 B |
After Width: | Height: | Size: 244 B |
After Width: | Height: | Size: 246 B |
@ -1,94 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/reminder_root"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:layout_marginTop="5dip"
|
||||
android:layout_marginRight="5dip"
|
||||
android:layout_marginBottom="15dip"
|
||||
android:layout_marginLeft="10dip">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/contact_picture"
|
||||
android:layout_marginTop="5dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:visibility="gone"
|
||||
android:layout_width="51dip"
|
||||
android:layout_height="51dip"
|
||||
android:scaleType="fitCenter" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/reminder_title"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="1dip"
|
||||
android:textSize="24sp"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/MCA_title"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/call_now"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="24sp"
|
||||
android:gravity="center"
|
||||
android:text="@string/MCA_return_call"/>
|
||||
<TextView
|
||||
android:id="@+id/call_later"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="24sp"
|
||||
android:gravity="center"
|
||||
android:text="@string/MCA_add_task"/>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dip"
|
||||
android:layout_marginRight="10dip"
|
||||
android:layout_marginBottom="10dip">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/call_ignore"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="35dip"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="24sp"
|
||||
android:gravity="center"
|
||||
android:text="@string/MCA_ignore"
|
||||
android:background="#707070"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ignore_settings"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_width="35dip"
|
||||
android:layout_height="35dip"
|
||||
android:padding="4dip"
|
||||
android:background="@android:color/transparent"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@drawable/ic_settings_white_24dp"/>
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|