Improved handling of copy handlers
This commit is contained in:
parent
b053b6ede2
commit
bbad38a97d
@ -1,9 +1,8 @@
|
|||||||
package com.cradle.iitc_mobile.share;
|
package com.cradle.iitc_mobile.share;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.cradle.iitc_mobile.R;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -13,6 +12,7 @@ import android.content.pm.PackageManager;
|
|||||||
import android.content.pm.ResolveInfo;
|
import android.content.pm.ResolveInfo;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Pair;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -20,7 +20,19 @@ import android.widget.ArrayAdapter;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.cradle.iitc_mobile.R;
|
||||||
|
|
||||||
public class IntentListView extends ListView {
|
public class IntentListView extends ListView {
|
||||||
|
private static class CopyHandler extends Pair<String, String> {
|
||||||
|
public CopyHandler(ResolveInfo resolveInfo) {
|
||||||
|
super(resolveInfo.activityInfo.packageName, resolveInfo.activityInfo.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CopyHandler(String packageName, String name) {
|
||||||
|
super(packageName, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private class IntentAdapter extends ArrayAdapter<ResolveInfo>
|
private class IntentAdapter extends ArrayAdapter<ResolveInfo>
|
||||||
{
|
{
|
||||||
private IntentAdapter()
|
private IntentAdapter()
|
||||||
@ -45,9 +57,24 @@ public class IntentListView extends ListView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final HashSet<CopyHandler> KNOWN_COPY_HANDLERS = new HashSet<CopyHandler>();
|
||||||
|
|
||||||
|
private static void setupKnownCopyHandlers() {
|
||||||
|
if (!KNOWN_COPY_HANDLERS.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
KNOWN_COPY_HANDLERS.add(new CopyHandler(
|
||||||
|
"com.google.android.apps.docs",
|
||||||
|
"com.google.android.apps.docs.app.SendTextToClipboardActivity"));
|
||||||
|
|
||||||
|
KNOWN_COPY_HANDLERS.add(new CopyHandler(
|
||||||
|
"com.aokp.romcontrol",
|
||||||
|
"com.aokp.romcontrol.ShareToClipboard"));
|
||||||
|
}
|
||||||
|
|
||||||
private IntentAdapter mAdapter;
|
private IntentAdapter mAdapter;
|
||||||
private PackageManager mPackageManager;
|
|
||||||
private Intent mIntent = null;
|
private Intent mIntent = null;
|
||||||
|
private PackageManager mPackageManager;
|
||||||
|
|
||||||
public IntentListView(Context context) {
|
public IntentListView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@ -65,6 +92,8 @@ public class IntentListView extends ListView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
|
setupKnownCopyHandlers();
|
||||||
|
|
||||||
mPackageManager = getContext().getPackageManager();
|
mPackageManager = getContext().getPackageManager();
|
||||||
mAdapter = new IntentAdapter();
|
mAdapter = new IntentAdapter();
|
||||||
setAdapter(mAdapter);
|
setAdapter(mAdapter);
|
||||||
@ -74,6 +103,16 @@ public class IntentListView extends ListView {
|
|||||||
return mAdapter.getItem(position);
|
return mAdapter.getItem(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Intent getTargetIntent(int position) {
|
||||||
|
ActivityInfo activity = mAdapter.getItem(position).activityInfo;
|
||||||
|
|
||||||
|
Intent intent = new Intent(mIntent)
|
||||||
|
.setComponent(new ComponentName(activity.packageName, activity.name))
|
||||||
|
.setPackage(activity.packageName);
|
||||||
|
|
||||||
|
return intent;
|
||||||
|
}
|
||||||
|
|
||||||
public void setIntent(Intent intent)
|
public void setIntent(Intent intent)
|
||||||
{
|
{
|
||||||
mIntent = intent;
|
mIntent = intent;
|
||||||
@ -86,13 +125,11 @@ public class IntentListView extends ListView {
|
|||||||
List<ResolveInfo> activities = mPackageManager.queryIntentActivities(intent, 0);
|
List<ResolveInfo> activities = mPackageManager.queryIntentActivities(intent, 0);
|
||||||
ResolveInfo defaultTarget = mPackageManager.resolveActivity(intent, 0);
|
ResolveInfo defaultTarget = mPackageManager.resolveActivity(intent, 0);
|
||||||
|
|
||||||
// search for "Copy to clipboard" target...provided by drive or AOKP
|
|
||||||
boolean hasCopyIntent = false;
|
boolean hasCopyIntent = false;
|
||||||
for (ResolveInfo resolveInfo : activities) {
|
for (ResolveInfo resolveInfo : activities) { // search for "Copy to clipboard" handler
|
||||||
if ((resolveInfo.activityInfo.name.equals("com.google.android.apps.docs.app.SendTextToClipboardActivity")
|
CopyHandler handler = new CopyHandler(resolveInfo);
|
||||||
&& resolveInfo.activityInfo.packageName.equals("com.google.android.apps.docs")) ||
|
|
||||||
(resolveInfo.activityInfo.name.equals("com.aokp.romcontrol.ShareToClipboard")
|
if (KNOWN_COPY_HANDLERS.contains(handler))
|
||||||
&& resolveInfo.activityInfo.packageName.equals("com.aokp.romcontrol")))
|
|
||||||
hasCopyIntent = true;
|
hasCopyIntent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,14 +161,4 @@ public class IntentListView extends ListView {
|
|||||||
mAdapter.setNotifyOnChange(true);
|
mAdapter.setNotifyOnChange(true);
|
||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Intent getTargetIntent(int position) {
|
|
||||||
ActivityInfo activity = mAdapter.getItem(position).activityInfo;
|
|
||||||
|
|
||||||
Intent intent = new Intent(mIntent)
|
|
||||||
.setComponent(new ComponentName(activity.packageName, activity.name))
|
|
||||||
.setPackage(activity.packageName);
|
|
||||||
|
|
||||||
return intent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user