Skip to content

Commit

Permalink
添加查看当前栈顶Activity的信息
Browse files Browse the repository at this point in the history
  • Loading branch information
azhon committed Apr 29, 2019
1 parent 4a89e26 commit a8d616d
Show file tree
Hide file tree
Showing 14 changed files with 439 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.didichuxing.doraemonkit.kit.sysinfo.SysInfo;
import com.didichuxing.doraemonkit.kit.temporaryclose.TemporaryClose;
import com.didichuxing.doraemonkit.kit.timecounter.TimeCounterKit;
import com.didichuxing.doraemonkit.kit.topactivity.TopActivity;
import com.didichuxing.doraemonkit.kit.viewcheck.ViewChecker;
import com.didichuxing.doraemonkit.kit.webdoor.WebDoor;
import com.didichuxing.doraemonkit.kit.webdoor.WebDoorManager;
Expand Down Expand Up @@ -161,6 +162,7 @@ public void onActivityDestroyed(Activity activity) {
tool.add(new Crash());
tool.add(new LogInfo());
tool.add(new DataClean());
tool.add(new TopActivity());

performance.add(new FrameInfo());
performance.add(new Cpu());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.didichuxing.doraemonkit.config;

import android.content.Context;

import com.didichuxing.doraemonkit.constant.SharedPrefsKey;
import com.didichuxing.doraemonkit.util.SharedPrefsUtil;

/**
* 项目名: Android
* 包名 com.didichuxing.doraemonkit.config
* 文件名: TopActivityConfig
* 创建时间: 2019-04-29 on 12:27
*
* @author 阿钟
*/

public class TopActivityConfig {
public static boolean isTopActivityOpen(Context context) {
return SharedPrefsUtil.getBoolean(context, SharedPrefsKey.TOP_ACTIVITY_OPEN, false);
}

public static void setTopActivityOpen(Context context, boolean open) {
SharedPrefsUtil.putBoolean(context, SharedPrefsKey.TOP_ACTIVITY_OPEN, open);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public interface FragmentIndex {
int FRAGMENT_TIME_COUNTER= 17;
int FRAGMENT_WEB_DOOR_DEFAULT = 18;
int FRAGMENT_CUSTOM = 19;
int FRAGMENT_TOP_ACTIVITY = 20;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public interface SharedPrefsKey {
String VIEW_CHECK_OPEN = "view_check_open";
String LAYOUT_BORDER_OPEN = "layout_border_open";
String LAYOUT_LEVEL_OPEN = "layout_level_open";
String TOP_ACTIVITY_OPEN = "top_activity_open";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.didichuxing.doraemonkit.kit.topactivity;

import android.content.Context;
import android.content.Intent;

import com.didichuxing.doraemonkit.R;
import com.didichuxing.doraemonkit.constant.BundleKey;
import com.didichuxing.doraemonkit.constant.FragmentIndex;
import com.didichuxing.doraemonkit.kit.Category;
import com.didichuxing.doraemonkit.kit.IKit;
import com.didichuxing.doraemonkit.ui.UniversalActivity;

/**
* 项目名: Android
* 包名 com.didichuxing.doraemonkit.kit.topactivity
* 文件名: TopActivity
* 创建时间: 2019-04-29 on 12:13
* 描述: 当前栈顶的Activity信息
*
* @author 阿钟
*/

public class TopActivity implements IKit {

@Override
public int getCategory() {
return Category.TOOLS;
}

@Override
public int getName() {
return R.string.dk_kit_top_activity;
}

@Override
public int getIcon() {
return R.drawable.dk_view_check;
}

@Override
public void onClick(Context context) {
Intent intent = new Intent(context, UniversalActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(BundleKey.FRAGMENT_INDEX, FragmentIndex.FRAGMENT_TOP_ACTIVITY);
context.startActivity(intent);
}

@Override
public void onAppInit(Context context) {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package com.didichuxing.doraemonkit.kit.topactivity;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import com.didichuxing.doraemonkit.R;
import com.didichuxing.doraemonkit.config.TopActivityConfig;
import com.didichuxing.doraemonkit.ui.base.BaseFloatPage;
import com.didichuxing.doraemonkit.ui.base.FloatPageManager;
import com.didichuxing.doraemonkit.ui.base.TouchProxy;

/**
* 项目名: Android
* 包名 com.didichuxing.doraemonkit.kit.topactivity
* 文件名: TopActivityFloatPage
* 创建时间: 2019-04-29 on 13:38
* 描述:
*
* @author 阿钟
*/

public class TopActivityFloatPage extends BaseFloatPage implements TouchProxy.OnTouchEventListener,
Application.ActivityLifecycleCallbacks {

private TouchProxy touchProxy = new TouchProxy(this);
private WindowManager windowManager;
private TextView className;
private TextView pkgName;
private TextView pathName;
private Application app;

@Override
protected void onCreate(Context context) {
super.onCreate(context);
app = (Application) context.getApplicationContext();
app.registerActivityLifecycleCallbacks(this);
windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
}

@Override
protected View onCreateView(Context context, ViewGroup view) {
return LayoutInflater.from(context).inflate(R.layout.dk_float_view_top_activity, null);
}

@Override
protected void onViewCreated(View view) {
super.onViewCreated(view);
getRootView().setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return touchProxy.onTouchEvent(v, event);
}
});
findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TopActivityConfig.setTopActivityOpen(getContext(), false);
FloatPageManager.getInstance().removeAll(TopActivityFloatPage.class);
}
});
pkgName = findViewById(R.id.pkg_name);
className = findViewById(R.id.class_name);
pathName = findViewById(R.id.path_name);
}

@Override
protected void onLayoutParamsCreated(WindowManager.LayoutParams params) {
params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
params.width = WindowManager.LayoutParams.MATCH_PARENT;
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
params.x = 0;
params.y = 0;
}

@Override
public void onEnterForeground() {
super.onEnterForeground();
getRootView().setVisibility(View.VISIBLE);
}

@Override
public void onEnterBackground() {
super.onEnterBackground();
getRootView().setVisibility(View.GONE);
}

@Override
public void onMove(int x, int y, int dx, int dy) {
getLayoutParams().x += dx;
getLayoutParams().y += dy;
windowManager.updateViewLayout(getRootView(), getLayoutParams());
}


@Override
public void onActivityResumed(Activity activity) {
pkgName.setText(activity.getPackageName());
className.setText(activity.getClass().getSimpleName());
pathName.setText(activity.getClass().getName());
}

@Override
public void onUp(int x, int y) {

}

@Override
public void onDown(int x, int y) {

}

@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {

}

@Override
public void onActivityStarted(Activity activity) {

}

@Override
public void onActivityPaused(Activity activity) {

}

@Override
public void onActivityStopped(Activity activity) {

}

@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

}

@Override
public void onActivityDestroyed(Activity activity) {

}

@Override
protected void onDestroy() {
super.onDestroy();
app.unregisterActivityLifecycleCallbacks(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.didichuxing.doraemonkit.kit.topactivity;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.didichuxing.doraemonkit.R;
import com.didichuxing.doraemonkit.config.TopActivityConfig;
import com.didichuxing.doraemonkit.ui.base.BaseFragment;
import com.didichuxing.doraemonkit.ui.base.FloatPageManager;
import com.didichuxing.doraemonkit.ui.base.PageIntent;
import com.didichuxing.doraemonkit.ui.setting.SettingItem;
import com.didichuxing.doraemonkit.ui.setting.SettingItemAdapter;
import com.didichuxing.doraemonkit.ui.widget.titlebar.HomeTitleBar;

/**
* 项目名: Android
* 包名 com.didichuxing.doraemonkit.kit.topactivity
* 文件名: TopActivityFragment
* 创建时间: 2019-04-29 on 12:16
* 描述:
*
* @author 阿钟
*/

public class TopActivityFragment extends BaseFragment {
@Override
protected int onRequestLayout() {
return R.layout.dk_fragment_top_activity;
}

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
initView();
}

private void initView() {
HomeTitleBar titleBar = findViewById(R.id.title_bar);
titleBar.setListener(new HomeTitleBar.OnTitleBarClickListener() {
@Override
public void onRightClick() {
getActivity().finish();
}
});
RecyclerView topActivityList = findViewById(R.id.top_activity_list);
topActivityList.setLayoutManager(new LinearLayoutManager(getContext()));
SettingItemAdapter topActivityAdapter = new SettingItemAdapter(getContext());
topActivityAdapter.append(new SettingItem(R.string.dk_kit_top_activity, TopActivityConfig.isTopActivityOpen(getContext())));
topActivityAdapter.setOnSettingItemSwitchListener(new SettingItemAdapter.OnSettingItemSwitchListener() {
@Override
public void onSettingItemSwitch(View view, SettingItem data, boolean on) {
if (data.desc == R.string.dk_kit_top_activity) {
if (on) {
PageIntent intent = new PageIntent(TopActivityFloatPage.class);
FloatPageManager.getInstance().add(intent);
getActivity().finish();
} else {
FloatPageManager.getInstance().removeAll(TopActivityFloatPage.class);
}
TopActivityConfig.setTopActivityOpen(getContext(), on);
}
}
});
topActivityList.setAdapter(topActivityAdapter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.didichuxing.doraemonkit.kit.colorpick.ColorPickerSettingFragment;
import com.didichuxing.doraemonkit.kit.crash.CrashCaptureMainFragment;
import com.didichuxing.doraemonkit.kit.custom.MonitorDataUploadFragment;
import com.didichuxing.doraemonkit.kit.custom.UploadMonitorInfoBean;
import com.didichuxing.doraemonkit.kit.dataclean.DataCleanFragment;
import com.didichuxing.doraemonkit.kit.fileexplorer.FileExplorerFragment;
import com.didichuxing.doraemonkit.kit.gpsmock.GpsMockFragment;
Expand All @@ -22,6 +21,7 @@
import com.didichuxing.doraemonkit.kit.parameter.ram.RamMainPageFragment;
import com.didichuxing.doraemonkit.kit.sysinfo.SysInfoFragment;
import com.didichuxing.doraemonkit.kit.timecounter.TimeCounterFragment;
import com.didichuxing.doraemonkit.kit.topactivity.TopActivityFragment;
import com.didichuxing.doraemonkit.kit.viewcheck.ViewCheckFragment;
import com.didichuxing.doraemonkit.kit.webdoor.WebDoorDefaultFragment;
import com.didichuxing.doraemonkit.kit.webdoor.WebDoorFragment;
Expand Down Expand Up @@ -103,6 +103,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
case FragmentIndex.FRAGMENT_CUSTOM:
fragmentClass = MonitorDataUploadFragment.class;
break;
case FragmentIndex.FRAGMENT_TOP_ACTIVITY:
fragmentClass = TopActivityFragment.class;
break;
default:
break;
}
Expand Down
Loading

0 comments on commit a8d616d

Please sign in to comment.