[Galaxy S I9000 Android Development] XYunknown:
Hey Guys!

After a few requests I decided to share my X-Recents mod with you, so that other developers get the ability to add it to their Rom. This is just for Developers building Roms from Source! Also, medium skills on java coding are recommended!

What is X-Recents mod?

It's a mod improving the stock android recents, to make them more user-friendly and feature-rich. It was already implemented in my X-Bean Rom for i9000

Please note:

- you can use this for all ICS/JB Roms and for all devices

- just add me to the credits, if you want to use it, and notify me: kgreshake@gmail.com

- The swype FC Bug (occurs when swyping over the Button) still exists, to fix it just add try/catch blocks at all points that cause the FC it (use adb/logcat for analysis)

Okay, so let's get started: You can find all files in: system/frameworks/base/packages/SystemUI/src/com/android/systemui/recent (in your working directory)

At first, we modify the RecentTasksLoader.java:

l.260: final int first = 1;

to : final int first = 0;

This loads the current activity into the recents list.. Only problem: The launcher shall not be shown in the recents list, so we have to make a exeption for it:

l.270: if (item != null) {

to : if (item != null && item.packageName!="com.cyanogenmod.trebuchet") { // You can add as many exeptions for apps as you want

Next point: Adding the Taskmanager button:

At first, open RecentsVerticalScrollView.java:

Insert this at line 95:

private void opentaskmanager() {
PackageManager pm = getContext().getPackageManager();
Intent appStartIntent = pm.getLaunchIntentForPackage("com.sec.android.app.controlpanel");
if (null != appStartIntent)
{
getContext().startActivity(appStartIntent);
}
}

Now, wrap a try/catch block around the loop content in line 107:

for (int i = 0; i < mLinearLayout.getChildCount(); i++) {
try {
View v = mLinearLayout.getChildAt(i);
addToRecycledViews(v);
mAdapter.recycleView(v);
} catch (Exception ex) {
}

}

Also add a try here (I can't give you a line, because you inserted something before) :

for (int i = 0; i < mAdapter.getCount(); i++) {
try {
View old = null;

And a catch here:

calloutLine.setOnTouchListener(noOpListener);
mLinearLayout.addView(view);
} catch (Exception ex) {
}
}

To add the button, insert this:

Button bt_taskmanager = new Button(getContext());
bt_taskmanager.setText("Task Manager");
bt_taskmanager.setWidth(mLinearLayout.getWidth());
bt_taskmanager.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
opentaskmanager();
}
});
mLinearLayout.addView(bt_taskmanager);

Between these two lines:

setLayoutTransition(transitioner);

// Scroll to end after layout.

Okay, now we've got the button!

At last I want to give you something you can experiment with:

private void clearalltasks() {
final ActivityManager am = (ActivityManager)
mContext.getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RecentTaskInfo> recentTasks =
am.getRecentTasks(50, ActivityManager.RECENT_IGNORE_UNAVAILABLE);

for (int i = 0; i >= recentTasks.size(); i++) {
RecentTaskInfo item = recentTasks.get(i);

if (am != null && item!=null) {
try {
am.removeTask(item.persistentId, ActivityManager.REMOVE_TASK_KILL_PROCESS);
} catch (Exception ex) {

}
try {
am.killBackgroundProcesses(item.origActivity.getPackageName());
} catch (Exception ex) {

}
}
}
mLinearLayout.removeAllViews();
try {
update();
} catch (Exception ex) {
ex.printStackTrace();
}
}

This is my first attempt to add a clear all button.. Do with it what you want, I tried it and it works half-ways.. But not perfectly. I will add some more things later!

P.S: Screenshot is attached!