more or less working

This commit is contained in:
Adam Szalkowski 2013-07-17 00:58:05 +02:00
parent ec96412b37
commit 5682e54260
12 changed files with 213 additions and 40 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
/gen
/bin
/libs

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeight" >
<ImageView
android:id="@android:id/icon"
android:layout_width="92dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:duplicateParentState="true"
android:src="@drawable/ic_launcher"
android:paddingLeft="60dp"/>
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:duplicateParentState="true"
android:paddingLeft="10dp"
android:text="Some activity"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="?android:attr/activatedBackgroundIndicator"
android:minHeight="?android:attr/listPreferredItemHeight" >
<ImageView
android:id="@android:id/icon"
android:layout_width="80dp"
android:layout_height="50dp"
android:layout_gravity="center_vertical"
android:duplicateParentState="true"
android:src="@drawable/ic_launcher"
android:paddingLeft="30dp" />
<TextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|left"
android:duplicateParentState="true"
android:paddingLeft="10dp"
android:text="Some package"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>

View file

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
android:layout_height="fill_parent"
android:orientation="vertical">
<ExpandableListView
android:id="@+id/expandableListView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_height="match_parent">
</ExpandableListView>
</ScrollView>
</LinearLayout>

View file

@ -5,4 +5,9 @@
<string name="title_section_all">All activities</string>
<string name="context_action_launch">Launch activity</string>
<string name="context_action_shortcut">Create shortcut</string>
<string name="starting_activity">Starting activity: %s</string>
<string name="starting_application">Starting application: %s</string>
<string name="creating_activity_shortcut">Creating activity shortcut for %s</string>
<string name="creating_application_shortcut">Creating application shortcut for %s</string>
<string name="error">Error</string>
</resources>

View file

@ -8,20 +8,17 @@ import java.util.Map;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.util.Log;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class AllTasksListAdapter extends BaseExpandableListAdapter {
final static private String LOG = "de.szalkowski.activitylauncher.alltaskslistadapter";
protected List<MyPackageInfo> packages = null;
protected List<MyActivityInfo> activities = null;
protected Map<Pair<Integer,Integer>,Integer> index = null;
@ -41,14 +38,15 @@ public class AllTasksListAdapter extends BaseExpandableListAdapter {
int pack_pos = this.packages.size();
for(ActivityInfo activity : pack.activities) {
if(activity.isEnabled()) {
if(activity.isEnabled() && activity.exported) {
ComponentName acomp = new ComponentName(activity.packageName, activity.name);
MyActivityInfo myactivity = new MyActivityInfo(acomp, pm);
myactivity.package_id = pack_pos;
int act_pos = this.activities.size();
this.activities.add(myactivity);
this.index.put(new Pair<Integer, Integer>(pack_pos, n_activities), act_pos);
this.index.put(new Pair<Integer, Integer>(pack_pos, n_activities), act_pos);
n_activities++;
}
}
if(n_activities > 0) {
@ -73,12 +71,13 @@ public class AllTasksListAdapter extends BaseExpandableListAdapter {
public View getChildView (int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
MyActivityInfo activity = activities.get(index.get(new Pair<Integer,Integer>(groupPosition,childPosition)));
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(android.R.layout.simple_expandable_list_item_2, null);
View view = inflater.inflate(R.layout.all_activities_child_item, null);
TextView text = (TextView) view.findViewById(android.R.id.text1);
text.setText(activity.name);
Log.d(LOG, "createChild " + activity.name);
text.setText(activity.name + " (" + activity.component_name.getClassName() + ")");
ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
icon.setImageDrawable(activity.icon);
return view;
}
@ -107,11 +106,13 @@ public class AllTasksListAdapter extends BaseExpandableListAdapter {
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
MyPackageInfo pack = this.packages.get(groupPosition);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(android.R.layout.simple_expandable_list_item_1, null);
View view = inflater.inflate(R.layout.all_activities_group_item, null);
TextView text = (TextView) view.findViewById(android.R.id.text1);
text.setText(pack.name);
Log.d(LOG, "createGroup " + pack.name);
ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
icon.setImageDrawable(pack.icon);
return view;
}

View file

@ -1,22 +1,94 @@
package de.szalkowski.activitylauncher;
import org.thirdparty.LauncherIconCreator;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.Toast;
public class AllTasksListFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.frament_all_list, container);
View view = inflater.inflate(R.layout.frament_all_list, null);
ExpandableListView list = (ExpandableListView) view.findViewById(R.id.expandableListView1);
list.setAdapter(new AllTasksListAdapter(this.getActivity()));
list.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
ExpandableListAdapter adapter = parent.getExpandableListAdapter();
MyActivityInfo info = (MyActivityInfo)adapter.getChild(groupPosition, childPosition);
LauncherIconCreator.launchActivity(getActivity(), info.component_name);
return false;
}
});
return view;
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ExpandableListView list = (ExpandableListView) getView().findViewById(R.id.expandableListView1);
this.registerForContextMenu(list);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.add(Menu.NONE, 0, Menu.NONE, R.string.context_action_shortcut);
menu.add(Menu.NONE, 1, Menu.NONE, R.string.context_action_launch);
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo)item.getMenuInfo();
ExpandableListView list = (ExpandableListView) getView().findViewById(R.id.expandableListView1);
switch(ExpandableListView.getPackedPositionType(info.packedPosition)) {
case ExpandableListView.PACKED_POSITION_TYPE_CHILD:
MyActivityInfo activity = (MyActivityInfo) list.getExpandableListAdapter().getChild(ExpandableListView.getPackedPositionGroup(info.packedPosition), ExpandableListView.getPackedPositionChild(info.packedPosition));
switch(item.getItemId()) {
case 0:
LauncherIconCreator.createLauncherIcon(getActivity(), activity);
break;
case 1:
LauncherIconCreator.launchActivity(getActivity(), activity.component_name);
break;
}
break;
case ExpandableListView.PACKED_POSITION_TYPE_GROUP:
MyPackageInfo pack = (MyPackageInfo) list.getExpandableListAdapter().getGroup(ExpandableListView.getPackedPositionGroup(info.packedPosition));
switch(item.getItemId()) {
case 0:
LauncherIconCreator.createLauncherIcon(getActivity(), pack);
break;
case 1:
PackageManager pm = getActivity().getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(pack.package_name);
Toast.makeText(getActivity(), String.format(getText(R.string.starting_application).toString(), pack.name), Toast.LENGTH_LONG).show();
getActivity().startActivity(intent);
break;
}
}
return super.onContextItemSelected(item);
}
}

View file

@ -7,7 +7,6 @@ import android.content.Context;
import android.os.Build;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.widget.ArrayAdapter;
public class MainActivity extends FragmentActivity implements

View file

@ -8,7 +8,7 @@ import android.graphics.drawable.BitmapDrawable;
public class MyActivityInfo {
public MyActivityInfo(ComponentName activity, PackageManager pm) {
this.componentName = activity;
this.component_name = activity;
ActivityInfo act;
try {
@ -27,12 +27,14 @@ public class MyActivityInfo {
this.icon_resource = 0;
}
try {
this.icon_resource_name = pm.getResourcesForActivity(activity).getResourceName(this.icon_resource);
} catch (Exception e) {}
if(this.icon_resource != 0) {
try {
this.icon_resource_name = pm.getResourcesForActivity(activity).getResourceName(this.icon_resource);
} catch (Exception e) {}
}
}
public ComponentName componentName;
public ComponentName component_name;
public BitmapDrawable icon;
public int icon_resource;
public String icon_resource_name;

View file

@ -25,9 +25,11 @@ public class MyPackageInfo {
this.icon_resource = 0;
}
try {
this.icon_resource_name = pm.getResourcesForApplication(app).getResourceName(this.icon_resource);
} catch (Exception e) {}
if(this.icon_resource != 0) {
try {
this.icon_resource_name = pm.getResourcesForApplication(app).getResourceName(this.icon_resource);
} catch (Exception e) {}
}
}
public String package_name;

View file

@ -8,7 +8,6 @@ import org.thirdparty.LauncherIconCreator;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
@ -26,7 +25,6 @@ import android.widget.ListView;
import android.widget.TextView;
public class RecentTaskListFragment extends ListFragment {
final private String LOG = "de.szalkowski.activitylauncher";
protected List<MyActivityInfo> activities;
@Override
@ -66,9 +64,8 @@ public class RecentTaskListFragment extends ListFragment {
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
ComponentName activity = RecentTaskListFragment.this.activities.get(position).componentName;
Intent intent = LauncherIconCreator.getActivityIntent(activity);
RecentTaskListFragment.this.getActivity().startActivity(intent);
ComponentName activity = RecentTaskListFragment.this.activities.get(position).component_name;
LauncherIconCreator.launchActivity(getActivity(), activity);
}
@Override
@ -89,8 +86,7 @@ public class RecentTaskListFragment extends ListFragment {
LauncherIconCreator.createLauncherIcon(getActivity(), activity);
break;
case 1:
Intent intent = LauncherIconCreator.getActivityIntent(activity.componentName);
getActivity().startActivity(intent);
LauncherIconCreator.launchActivity(getActivity(), activity.component_name);
break;
}
return super.onContextItemSelected(item);

View file

@ -12,16 +12,16 @@
package org.thirdparty;
import de.szalkowski.activitylauncher.MyActivityInfo;
import de.szalkowski.activitylauncher.MyPackageInfo;
import de.szalkowski.activitylauncher.R;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;
import android.widget.Toast;
public class LauncherIconCreator {
final static private String LOG = "de.szalkowski.thirdparty.launchericoncreator";
public static Intent getActivityIntent(ComponentName activity) {
Intent intent = new Intent();
intent.setComponent(activity);
@ -32,10 +32,17 @@ public class LauncherIconCreator {
}
public static void createLauncherIcon(Context context, MyActivityInfo activity) {
createLauncherIcon(context, activity.componentName, activity.name, activity.icon_resource_name);
createLauncherIcon(context, activity.component_name, activity.name, activity.icon_resource_name);
}
public static void createLauncherIcon(Context context, MyPackageInfo pack) {
Intent intent = context.getPackageManager().getLaunchIntentForPackage(pack.package_name);
createLauncherIcon(context, intent, pack.name, pack.icon_resource_name);
}
public static void createLauncherIcon(Context context, ComponentName activity, String name, BitmapDrawable icon) {
Toast.makeText(context, String.format(context.getText(R.string.creating_activity_shortcut).toString(), activity.flattenToShortString()), Toast.LENGTH_LONG).show();
Intent shortcutIntent = new Intent();
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getActivityIntent(activity));
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
@ -45,7 +52,10 @@ public class LauncherIconCreator {
context.sendBroadcast(shortcutIntent);
//finish();
}
public static void createLauncherIcon(Context context, ComponentName activity, String name, String icon_resource_name) {
Toast.makeText(context, String.format(context.getText(R.string.creating_activity_shortcut).toString(), activity.flattenToShortString()), Toast.LENGTH_LONG).show();
Intent shortcutIntent = new Intent();
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getActivityIntent(activity));
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
@ -57,4 +67,31 @@ public class LauncherIconCreator {
context.sendBroadcast(shortcutIntent);
//finish();
}
public static void createLauncherIcon(Context context, Intent intent, String name, String icon_resource_name) {
Toast.makeText(context, String.format(context.getText(R.string.creating_application_shortcut).toString(), name), Toast.LENGTH_LONG).show();
Intent shortcutIntent = new Intent();
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
Intent.ShortcutIconResource ir = new Intent.ShortcutIconResource();
ir.packageName = intent.getPackage();
ir.resourceName = icon_resource_name;
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ir);
shortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(shortcutIntent);
//finish();
}
public static void launchActivity(Context context, ComponentName activity) {
Intent intent = LauncherIconCreator.getActivityIntent(activity);
Toast.makeText(context, String.format(context.getText(R.string.starting_activity).toString(), activity.flattenToShortString()), Toast.LENGTH_LONG).show();
try {
context.startActivity(intent);
}
catch(Exception e) {
Toast.makeText(context, context.getText(R.string.error).toString() + ": " + e.toString(), Toast.LENGTH_LONG).show();
}
}
}