[Android Software Development] lukakas:
Reverse engineer SystemUI.apk code of RecentsActivity.java from Xperia Z 4.2.2

package com.android.systemui.recent;

import android.app.*;
import android.content.*;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.UserHandle;
import android.view.*;
import android.widget.FrameLayout;
import com.android.systemui.statusbar.tablet.StatusBarPanel;
import com.sony.smallapp.internal.util.WindowUtils;
import java.util.List;

// Referenced classes of package com.android.systemui.recent:
// RemotePluginView, RecentsPanelView, RecentTasksLoader

public class RecentsActivity extends Activity
{
public class TouchOutsideListener
implements android.view.View.OnTouchListener
{

private StatusBarPanel mPanel;
final RecentsActivity this$0;

public boolean onTouch(View view, MotionEvent motionevent)
{
int i = motionevent.getAction();
if (i != 4 && (i != 0 || mPanel.isInContentArea((int)motionevent.getX(), (int)motionevent.getY())))
{
return false;
} else
{
dismissAndGoHome();
return true;
}
}

public TouchOutsideListener(StatusBarPanel statusbarpanel)
{
this$0 = RecentsActivity.this;
super();
mPanel = statusbarpanel;
}
}

private static int sLastOrientation = -1;
private static RemotePluginView sPluginView;
private ViewGroup mContainer;
private boolean mForeground;
private final String mHideSmallAppCallerString = (new Object()).toString();
private IntentFilter mIntentFilter;
private BroadcastReceiver mIntentReceiver;
private boolean mOrientationChanged;
private RecentsPanelView mRecentsPanel;
private boolean mShowing;

public RecentsActivity()
{
mIntentReceiver = new BroadcastReceiver() {

final RecentsActivity this$0;

public void onReceive(Context context, Intent intent)
{
if ("com.android.systemui.recent.action.CLOSE".equals(intent.getAction()))
{
if (mRecentsPanel != null && mRecentsPanel.isShowing())
{
if (mShowing && !mForeground && !mOrientationChanged)
{
mRecentsPanel.show(false);
WindowUtils.showSmallAppWindows(RecentsActivity.this, mHideSmallAppCallerString);
}
mOrientationChanged = false;
}
} else
if ("com.android.systemui.recent.action.WINDOW_ANIMATION_START".equals(intent.getAction()))
{
if (mRecentsPanel != null)
{
mRecentsPanel.onWindowAnimationStart();
return;
}
} else
if ("com.android.systemui.recent.action.CLOSE_RECENTS_INTENT_FROM_SMALL_APP_LAUNCHER".equals(intent.getAction()) && mRecentsPanel != null && mRecentsPanel.isShowing())
{
dismissAndGoBack();
return;
}
}

{
this$0 = RecentsActivity.this;
super();
}
}
;
}

private void attachPluginView()
{
if (sPluginView != null)
{
detachPluginView();
((ViewGroup)findViewById(0x7f080091)).addView(sPluginView);
int i = sPluginView.getInitialHeight();
((FrameLayout)findViewById(0x7f08008c)).setPadding(0, 0, 0, i);
}
}

public static void createPluginView(Context context)
{
if (sPluginView != null)
{
detachPluginView();
sPluginView = null;
}
sPluginView = (RemotePluginView)View.inflate(context, 0x7f04000c, null);
}

private static void detachPluginView()
{
if (sPluginView != null)
{
android.view.ViewParent viewparent = sPluginView.getParent();
if (viewparent != null && (viewparent instanceof ViewGroup))
((ViewGroup)viewparent).removeView(sPluginView);
}
}

public static boolean forceOpaqueBackground(Context context)
{
return WallpaperManager.getInstance(context).getWallpaperInfo() != null;
}

public static int getPluginViewInitialHeight()
{
RemotePluginView remotepluginview = sPluginView;
int i = 0;
if (remotepluginview != null)
i = sPluginView.getInitialHeight();
return i;
}

private void handleIntent(Intent intent, boolean flag)
{
super.onNewIntent(intent);
if ("com.android.systemui.recent.action.TOGGLE_RECENTS".equals(intent.getAction()))
{
if (mRecentsPanel != null)
if (mShowing && mRecentsPanel.isShowing())
{
dismissAndGoBack();
} else
{
RecentTasksLoader recenttasksloader1 = RecentTasksLoader.getInstance(this);
boolean flag3 = false;
if (flag)
{
boolean flag4 = intent.getBooleanExtra("com.android.systemui.recent.WAITING_FOR_WINDOW_ANIMATION", false);
flag3 = false;
if (flag4)
flag3 = true;
}
mRecentsPanel.show(true, recenttasksloader1.getLoadedTasks(), recenttasksloader1.isFirstScreenful(), flag3);
return;
}
} else
if ("com.android.systemui.recent.action.OPEN_RECENTS_INTENT_FROM_SMALL_APP_LAUNCHER".equals(intent.getAction()) && mRecentsPanel != null)
{
RecentTasksLoader recenttasksloader = RecentTasksLoader.getInstance(this);
boolean flag1 = false;
if (flag)
{
boolean flag2 = intent.getBooleanExtra("com.android.systemui.recent.WAITING_FOR_WINDOW_ANIMATION", false);
flag1 = false;
if (flag2)
flag1 = true;
}
mRecentsPanel.show(true, recenttasksloader.getLoadedTasks(), recenttasksloader.isFirstScreenful(), flag1);
return;
}
}

private void updateWallpaperVisibility(boolean flag)
{
int i;
if (flag)
i = 0x100000;
else
i = 0;
if (i != (0x100000 & getWindow().getAttributes().flags))
getWindow().setFlags(i, 0x100000);
}

public void dismissAndGoBack()
{
if (mRecentsPanel != null)
{
List list = ((ActivityManager)getSystemService("activity")).getRecentTasks(2, 3);
if (list.size() > 1 && mRecentsPanel.simulateClick(((android.app.ActivityManager.RecentTaskInfo)list.get(1)).persistentId))
return;
mRecentsPanel.show(false);
}
finish();
}

public void dismissAndGoHome()
{
if (mRecentsPanel != null)
{
Intent intent = new Intent("android.intent.action.MAIN", null);
intent.addCategory("android.intent.category.HOME");
intent.addFlags(0x10200000);
startActivityAsUser(intent, new UserHandle(-2));
mRecentsPanel.show(false);
}
}

public boolean dispatchKeyEvent(KeyEvent keyevent)
{
boolean flag;
label0:
{
flag = true;
if (sPluginView != null)
{
if (keyevent.getKeyCode() == 4 && keyevent.getAction() == flag)
{
if (sPluginView.dispatchKeyEvent(keyevent))
break label0;
dismissAndGoBack();
}
} else
if (keyevent.getKeyCode() == 4 && keyevent.getAction() == flag)
dismissAndGoBack();
flag = super.dispatchKeyEvent(keyevent);
}
return flag;
}

boolean isActivityShowing()
{
return mShowing;
}

protected void onCreate(Bundle bundle)
{
boolean flag = true;
setContentView(0x7f04002b);
mRecentsPanel = (RecentsPanelView)findViewById(0x7f08008b);
mRecentsPanel.setOnTouchListener(new TouchOutsideListener(mRecentsPanel));
RecentTasksLoader.getInstance(this).setRecentsPanel(mRecentsPanel, mRecentsPanel);
mRecentsPanel.setMinSwipeAlpha((float)getResources().getInteger(0x7f0c0008) / 100F);
boolean flag1;
if (sLastOrientation != -1 && sLastOrientation != getResources().getConfiguration().orientation)
flag1 = flag;
else
flag1 = false;
mOrientationChanged = flag1;
if (bundle == null || bundle.getBoolean("was_showing"))
{
Intent intent = getIntent();
if (bundle != null)
flag = false;
handleIntent(intent, flag);
}
mIntentFilter = new IntentFilter();
mIntentFilter.addAction("com.android.systemui.recent.action.CLOSE");
mIntentFilter.addAction("com.android.systemui.recent.action.WINDOW_ANIMATION_START");
mIntentFilter.addAction("com.android.systemui.recent.action.CLOSE_RECENTS_INTENT_FROM_SMALL_APP_LAUNCHER");
registerReceiver(mIntentReceiver, mIntentFilter);
mContainer = (ViewGroup)findViewById(0x7f080091);
if (sPluginView == null)
createPluginView(this);
attachPluginView();
super.onCreate(bundle);
}

protected void onDestroy()
{
RecentTasksLoader.getInstance(this).setRecentsPanel(null, mRecentsPanel);
unregisterReceiver(mIntentReceiver);
mContainer.removeView(sPluginView);
super.onDestroy();
}

protected void onNewIntent(Intent intent)
{
handleIntent(intent, true);
}

public void onPause()
{
overridePendingTransition(0x7f05000e, 0x7f05000f);
mForeground = false;
super.onPause();
}

public void onResume()
{
sLastOrientation = getResources().getConfiguration().orientation;
mForeground = true;
super.onResume();
}

protected void onSaveInstanceState(Bundle bundle)
{
bundle.putBoolean("was_showing", mRecentsPanel.isShowing());
}

public void onStart()
{
if (forceOpaqueBackground(this))
updateWallpaperVisibility(false);
else
updateWallpaperVisibility(true);
mShowing = true;
if (mRecentsPanel != null)
{
if (!mRecentsPanel.isShowing())
mRecentsPanel.show(true);
mRecentsPanel.refreshViews();
}
WindowUtils.hideSmallAppWindows(this, mHideSmallAppCallerString);
super.onStart();
}

public void onStop()
{
mShowing = false;
if (mRecentsPanel != null)
mRecentsPanel.onUiHidden();
WindowUtils.showSmallAppWindows(this, mHideSmallAppCallerString);
super.onStop();
}

/*
static boolean access$302(RecentsActivity recentsactivity, boolean flag)
{
recentsactivity.mOrientationChanged = flag;
return flag;
}

*/

}