mirror of https://github.com/tasks/tasks
Remove task action icon
parent
c00344c56b
commit
3fbf0be594
@ -1,29 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* <p>See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.api;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
|
||||
/**
|
||||
* Represents an intent that can be called on a task
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*/
|
||||
public class TaskAction {
|
||||
|
||||
/** Intent to call when invoking this operation */
|
||||
public PendingIntent intent;
|
||||
|
||||
/** Quick action icon */
|
||||
public int icon;
|
||||
|
||||
/** Create an EditOperation object */
|
||||
public TaskAction(PendingIntent intent, int icon) {
|
||||
super();
|
||||
this.intent = intent;
|
||||
this.icon = icon;
|
||||
}
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* <p>See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.core;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.net.Uri;
|
||||
import android.text.Spannable;
|
||||
import android.text.style.URLSpan;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.AndroidRuntimeException;
|
||||
import com.todoroo.astrid.api.TaskAction;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import com.todoroo.astrid.files.FilesAction;
|
||||
import com.todoroo.astrid.notes.NotesAction;
|
||||
import java.util.List;
|
||||
import org.tasks.R;
|
||||
import timber.log.Timber;
|
||||
|
||||
/**
|
||||
* Exposes {@link TaskAction} for phone numbers, emails, urls, etc
|
||||
*
|
||||
* @author Tim Su <tim@todoroo.com>
|
||||
*/
|
||||
public class LinkActionExposer {
|
||||
|
||||
public static TaskAction getActionsForTask(Context context, Task task, boolean hasAttachments) {
|
||||
if (task == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean hasNotes = task.hasNotes();
|
||||
|
||||
Spannable titleSpan = Spannable.Factory.getInstance().newSpannable(task.getTitle());
|
||||
try {
|
||||
Linkify.addLinks(titleSpan, Linkify.ALL);
|
||||
} catch (AndroidRuntimeException e) {
|
||||
// This can happen if WebView is missing
|
||||
Timber.w(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
URLSpan[] urlSpans = titleSpan.getSpans(0, titleSpan.length(), URLSpan.class);
|
||||
if (urlSpans.length == 0 && !hasNotes && !hasAttachments) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PackageManager pm = context.getPackageManager();
|
||||
|
||||
for (URLSpan urlSpan : urlSpans) {
|
||||
String url = urlSpan.getURL();
|
||||
int start = titleSpan.getSpanStart(urlSpan);
|
||||
int end = titleSpan.getSpanEnd(urlSpan);
|
||||
String text = titleSpan.subSequence(start, end).toString();
|
||||
TaskAction taskAction = createLinkAction(context, task.getId(), url, text, pm);
|
||||
if (taskAction != null) {
|
||||
return taskAction;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasAttachments) {
|
||||
return new FilesAction(R.drawable.ic_attachment_24dp);
|
||||
}
|
||||
|
||||
if (hasNotes) {
|
||||
return new NotesAction(R.drawable.ic_event_note_24dp);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static TaskAction createLinkAction(
|
||||
Context context, long id, String url, String text, PackageManager pm) {
|
||||
Intent itemIntent = new Intent(Intent.ACTION_VIEW);
|
||||
itemIntent.setData(Uri.parse(url));
|
||||
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(itemIntent, 0);
|
||||
|
||||
Intent actionIntent;
|
||||
|
||||
// if options > 1, display open with...
|
||||
if (resolveInfoList.size() > 1) {
|
||||
actionIntent = Intent.createChooser(itemIntent, text);
|
||||
}
|
||||
|
||||
// else show app that gets opened
|
||||
else if (resolveInfoList.size() == 1) {
|
||||
actionIntent = itemIntent;
|
||||
}
|
||||
|
||||
// no intents -> no item
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
|
||||
int icon;
|
||||
if (url.startsWith("mailto")) {
|
||||
icon = R.drawable.ic_email_black_24dp;
|
||||
} else if (url.startsWith("tel")) {
|
||||
icon = R.drawable.ic_phone_white_24dp;
|
||||
} else {
|
||||
icon = R.drawable.ic_public_black_24dp;
|
||||
}
|
||||
|
||||
return new TaskAction(PendingIntent.getActivity(context, (int) id, actionIntent, 0), icon);
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* <p>See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.files;
|
||||
|
||||
import com.todoroo.astrid.api.TaskAction;
|
||||
|
||||
public class FilesAction extends TaskAction {
|
||||
|
||||
public FilesAction(int icon) {
|
||||
super(null, icon);
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2012 Todoroo Inc
|
||||
*
|
||||
* <p>See the file "LICENSE" for the full license governing this code.
|
||||
*/
|
||||
package com.todoroo.astrid.notes;
|
||||
|
||||
import com.todoroo.astrid.api.TaskAction;
|
||||
|
||||
public class NotesAction extends TaskAction {
|
||||
|
||||
public NotesAction(int icon) {
|
||||
super(null, icon);
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 340 B |
Binary file not shown.
Before Width: | Height: | Size: 246 B |
Binary file not shown.
Before Width: | Height: | Size: 420 B |
Binary file not shown.
Before Width: | Height: | Size: 597 B |
@ -1,12 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:autoMirrored="true"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0"
|
||||
android:width="24dp"
|
||||
tools:ignore="UnusedAttribute,VectorRaster">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/>
|
||||
</vector>
|
@ -1,12 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:autoMirrored="true"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0"
|
||||
android:width="24dp"
|
||||
tools:ignore="UnusedAttribute,VectorRaster">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM11,19.93c-3.95,-0.49 -7,-3.85 -7,-7.93 0,-0.62 0.08,-1.21 0.21,-1.79L9,15v1c0,1.1 0.9,2 2,2v1.93zM17.9,17.39c-0.26,-0.81 -1,-1.39 -1.9,-1.39h-1v-3c0,-0.55 -0.45,-1 -1,-1L8,12v-2h2c0.55,0 1,-0.45 1,-1L11,7h2c1.1,0 2,-0.9 2,-2v-0.41c2.93,1.19 5,4.06 5,7.41 0,2.08 -0.8,3.97 -2.1,5.39z"/>
|
||||
</vector>
|
Loading…
Reference in New Issue