Commit 616ba36e by Baoxy

build: 本地完成应用使用情况界面(暂时屏蔽)

parent 30b6389c
......@@ -109,7 +109,8 @@
<activity
android:name=".function.setting.AppUseActivity"
android:excludeFromRecents="true"
android:theme="@style/SettingTheme"></activity>
android:theme="@style/SettingTheme"
android:configChanges="orientation|keyboardHidden"></activity>
<activity
android:name=".ManagerAuthActivity"
......
<vector android:height="24dp" android:tint="#E5E5E5"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M12,8l-6,6 1.41,1.41L12,10.83l4.59,4.58L18,14z"/>
</vector>
<vector android:height="24dp" android:tint="#E5E5E5"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M16.59,8.59L12,13.17 7.41,8.59 6,10l6,6 6,-6z"/>
</vector>
......@@ -11,7 +11,7 @@
android:id="@+id/tv_setting_title"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#FFF2F2F2"
android:background="#F6F6F6"
android:drawableStart="@mipmap/ic_back"
android:drawablePadding="10dp"
android:gravity="center_vertical"
......@@ -22,132 +22,122 @@
android:textColor="#363636"
android:textSize="16sp" />
<LinearLayout
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bg_white"
android:orientation="vertical">
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
android:layout_height="match_parent"
android:background="@color/bg_white"
android:orientation="vertical">
<TextView
android:id="@+id/tv_app_use_time"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:onClick="close"
android:textColor="#363636"
android:textSize="16sp" />
</LinearLayout>
<com.secspace.lib.common.function.view.AppUseProgress
android:id="@+id/time_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_margin="10dp"
android:background="@drawable/select_date_select"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="48dp"
android:drawablePadding="10dp"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="选择日期"
android:textColor="#ACACAC"
android:textSize="15sp" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:background="#ACACAC" />
<TextView
android:id="@+id/tv_date_start"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:gravity="center"
android:text="开始时间"
android:textColor="#ACACAC"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text=" — "
android:textColor="#ACACAC" />
<TextView
android:id="@+id/tv_date_end"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_weight="1"
android:gravity="center"
android:text="结束时间"
android:textColor="#ACACAC"
android:textSize="15sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:orientation="horizontal">
android:orientation="horizontal">
<TextView
android:id="@+id/tv_app_use_time"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:gravity="center_vertical"
android:textColor="#363636"
android:textSize="16sp" />
</LinearLayout>
<com.secspace.lib.common.function.view.AppUseProgress
android:id="@+id/time_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="6dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="6dp"
android:layout_marginRight="10dp"
android:background="@drawable/select_date_select"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:drawablePadding="10dp"
android:gravity="center_vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="选择日期"
android:textColor="#ACACAC"
android:textSize="15sp" />
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:background="#ACACAC" />
<TextView
android:id="@+id/tv_date_start"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="开始时间"
android:textColor="#ACACAC"
android:textSize="15sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:text=" — "
android:textColor="#ACACAC" />
<TextView
android:id="@+id/tv_date_end"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="结束时间"
android:textColor="#ACACAC"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:id="@+id/tv_app_use_total_time"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_vertical"
android:onClick="close"
android:textColor="#363636"
android:textSize="16sp" />
<com.qmuiteam.qmui.widget.QMUIEmptyView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="48dp"
android:onClick="more"
android:drawableEnd="@drawable/ic_chevron_right_gray_24dp"
android:gravity="center_vertical"
android:text="@string/edu_item_app_use_more"
android:textColor="#ABABAB"
android:textSize="15sp" />
<com.secspace.lib.common.function.view.UseTimeProgress
android:id="@+id/use_time_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_tree"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />
</LinearLayout>
<com.secspace.lib.common.function.view.UseTimeProgress
android:id="@+id/use_time_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="35dp"
android:background="@color/bg_white">
<LinearLayout
android:id="@+id/item_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/item_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
tools:src="@mipmap/ic_launcher_home" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="horizontal">
<TextView
android:id="@+id/item_tv_app_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#363636"
android:text="微信"
android:textSize="14sp" />
<TextView
android:id="@+id/item_tv_app_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#363636"
android:text="(21次)"
android:textSize="14sp" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/item_tv_app_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#363636"
android:text="20分钟"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_weight="1">
<com.secspace.lib.common.function.view.UseTimeProgress
android:id="@+id/item_use_time_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:layout_gravity="center"
android:layout_marginTop="5dp"/>
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/item_indicator"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
android:layout_margin="10dp"
tools:src="@mipmap/ic_launcher_home" />
</LinearLayout>
<LinearLayout
android:id="@+id/item_child"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<Space
android:layout_width="35dp"
android:layout_height="35dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<TextView
android:id="@+id/item_tv_app_details_start"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#ACACAC"
android:text="2020-04-07 17:33"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#ACACAC"
android:layout_margin="10dp"
android:text="-"
android:textSize="14sp" />
<TextView
android:id="@+id/item_tv_app_details_end"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="#ACACAC"
android:text="2020-04-07 17:33"
android:textSize="14sp" />
</LinearLayout>
<Space
android:layout_width="35dp"
android:layout_height="35dp"/>
</LinearLayout>
</FrameLayout>
......@@ -380,9 +380,10 @@
<string name="edu_item_input_encryted_title">请输入密保答案用于修改密码</string>
<string name="edu_item_app_use_title">应用使用情况</string>
<string name="edu_item_app_use_last_day">最近一天使用时长: %1$s分钟</string>
<string name="edu_item_app_use_last_day">最近一天使用时长: %1$s</string>
<string name="edu_item_app_use_more">生成报告</string>
<string name="edu_item_app_use_total">使用总时长: %1$s分钟</string>
<string name="edu_item_app_use_total">使用总时长: %1$s</string>
<string name="edu_item_app_use_count">(%1$d次)</string>
<string name="edu_item_app_use_time">%1$s</string>
</resources>
......@@ -205,6 +205,7 @@ public abstract class BaseContainerView extends FrameLayout
if (distance < viewConfig.getScaledTouchSlop()) {
// The background was clicked, so just go home
Launcher.getLauncher(getContext()).showWorkspace(true);
Launcher.forceReload();
return true;
}
}
......
package com.android.launcher3.function.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.launcher3.R;
import com.secspace.lib.common.function.entity.UseAppListEntity;
import com.secspace.lib.common.function.view.UseTimeProgress;
import java.util.LinkedList;
import java.util.List;
import static com.secspace.lib.common.utils.UtilsKt.formatDateTime;
public class TreeAdapter extends RecyclerView.Adapter<TreeAdapter.ViewHolder> implements TreeStateChangeListener {
private final static int ITEM_STATE_CLOSE = 0;
private final static int ITEM_STATE_OPEN = 1;
private Context mContext;
private List<UseAppListEntity> mList;
private float totalTime;
public TreeAdapter(Context context, List<UseAppListEntity> list, long totalTime) {
initList(list, 0);
this.totalTime = totalTime;
this.mList = new LinkedList<>();
this.mContext = context;
this.mList.addAll(list);
}
private void initList(List<UseAppListEntity> list, int itemLevel) {
if (list == null || list.size() <= 0) return;
for (UseAppListEntity item: list) {
item.setItemLevel(itemLevel);
if (item.getChild() != null && item.getChild().size() > 0) {
initList(item.getChild(), itemLevel + 1);
}
}
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
return new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_app_list, viewGroup, false));
}
@Override
public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int i) {
final UseAppListEntity treeItem = mList.get(i);
viewHolder.mAppName.setText(treeItem.getAppName());
viewHolder.mCount.setText(String.format(mContext.getString(R.string.edu_item_app_use_count), treeItem.getCount()));
viewHolder.mUseTime.setText(String.format(mContext.getString(R.string.edu_item_app_use_time), formatDateTime(treeItem.getUseTime())));
if(treeItem.getItemLevel() == 0){
viewHolder.mParent.setVisibility(View.VISIBLE);
viewHolder.mChild.setVisibility(View.GONE);
viewHolder.mIndicator.setVisibility(View.VISIBLE);
if (treeItem.getItemState() == ITEM_STATE_OPEN) {
viewHolder.mIndicator.setImageResource(R.drawable.ic_expand_more);
} else {
viewHolder.mIndicator.setImageResource(R.drawable.ic_expand_less_24dp);
}
if(treeItem.getIcon() != null){
viewHolder.mIcon.setImageDrawable(treeItem.getIcon());
}
viewHolder.mProgress.setProgress(treeItem.getUseTime()/totalTime * 100, treeItem.getAppName());
}else{
viewHolder.mParent.setVisibility(View.GONE);
viewHolder.mChild.setVisibility(View.VISIBLE);
viewHolder.mStartTime.setText(treeItem.getStartTime());
viewHolder.mEndTime.setText(treeItem.getEndTime());
viewHolder.mChild.setBackgroundColor(0xFFF2F2F2);
}
if (treeItem.getChild() != null && treeItem.getChild().size() > 0) {
if (treeItem.getItemState() == ITEM_STATE_OPEN) {
viewHolder.mIndicator.setImageResource(R.drawable.ic_expand_more);
} else {
viewHolder.mIndicator.setImageResource(R.drawable.ic_expand_less_24dp);
}
}
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (treeItem.getItemState() == ITEM_STATE_CLOSE) {
onOpen(treeItem, viewHolder.getAdapterPosition());
} else {
onClose(treeItem, viewHolder.getAdapterPosition());
}
}
});
}
@Override
public int getItemCount() {
return mList.size();
}
private void closeChild(UseAppListEntity entity) {
if (entity.getChild() != null) {
for (UseAppListEntity child: entity.getChild()) {
child.setItemState(ITEM_STATE_CLOSE);
closeChild(child);
}
}
}
@Override
public void onOpen(UseAppListEntity entity, int position) {
if (entity.getChild() != null && entity.getChild().size() > 0) {
mList.addAll(position + 1, entity.getChild());
entity.setItemState(ITEM_STATE_OPEN);
notifyItemRangeInserted(position + 1, entity.getChild().size());
notifyItemChanged(position);
}
}
@Override
public void onClose(UseAppListEntity entity, int position) {
if (entity.getChild() != null && entity.getChild().size() > 0) {
int nextSameOrHigherLevelNodePosition = mList.size() - 1;
if (mList.size() > position + 1) {
for (int i = position + 1; i < mList.size(); i++) {
if (mList.get(i).getItemLevel() <= mList.get(position).getItemLevel()) {
nextSameOrHigherLevelNodePosition = i - 1;
break;
}
}
closeChild(mList.get(position));
if (nextSameOrHigherLevelNodePosition > position) {
mList.subList(position + 1, nextSameOrHigherLevelNodePosition + 1).clear();
entity.setItemState(ITEM_STATE_CLOSE);
notifyItemRangeRemoved(position + 1, nextSameOrHigherLevelNodePosition - position);
notifyItemChanged(position);
}
}
}
}
class ViewHolder extends RecyclerView.ViewHolder {
LinearLayout mParent;
ImageView mIcon;
TextView mAppName;
TextView mCount;
TextView mUseTime;
UseTimeProgress mProgress;
ImageView mIndicator;
LinearLayout mChild;
TextView mStartTime;
TextView mEndTime;
ViewHolder(@NonNull View itemView) {
super(itemView);
mParent = itemView.findViewById(R.id.item_parent);
mChild = itemView.findViewById(R.id.item_child);
mIcon = itemView.findViewById(R.id.item_icon);
mAppName = itemView.findViewById(R.id.item_tv_app_name);
mCount = itemView.findViewById(R.id.item_tv_app_count);
mUseTime = itemView.findViewById(R.id.item_tv_app_time);
mProgress = itemView.findViewById(R.id.item_use_time_progress);
mIndicator = itemView.findViewById(R.id.item_indicator);
mStartTime = itemView.findViewById(R.id.item_tv_app_details_start);
mEndTime = itemView.findViewById(R.id.item_tv_app_details_end);
}
}
}
package com.android.launcher3.function.adapter;
import com.secspace.lib.common.function.entity.UseAppListEntity;
public interface TreeStateChangeListener {
void onOpen(UseAppListEntity entity, int position);
void onClose(UseAppListEntity entity, int position);
}
......@@ -2,16 +2,20 @@ package com.android.launcher3.function.setting
import android.content.Context
import android.os.Bundle
import android.support.v7.widget.DividerItemDecoration
import android.support.v7.widget.LinearLayoutManager
import android.util.Log
import android.view.View
import com.android.launcher3.BaseActivity
import com.android.launcher3.R
import com.android.launcher3.function.adapter.TreeAdapter
import com.bigkoo.pickerview.builder.TimePickerBuilder
import com.bigkoo.pickerview.listener.OnTimeSelectListener
import com.bigkoo.pickerview.view.TimePickerView
import com.secspace.lib.common.function.database.DatabaseManager
import com.secspace.lib.common.function.entity.UseAppEntity
import com.secspace.lib.common.function.entity.UseAppListEntity
import com.secspace.lib.common.function.model.UseTime
import com.secspace.lib.common.utils.*
import kotlinx.android.synthetic.main.activity_setting.tv_setting_title
import kotlinx.android.synthetic.main.activity_use_app.*
import kotlinx.coroutines.Dispatchers
......@@ -25,17 +29,19 @@ import kotlin.collections.ArrayList
class AppUseActivity : BaseActivity() {
private var TAG: String? = "TagAppUseActivity"
private var mContext: Context? = null
private var defaultUseAppEntitys: ArrayList<UseAppEntity>? = null
private lateinit var mContext: Context
private lateinit var defaultUseAppEntitys: ArrayList<UseAppEntity>
private var defaultStartTime: Long = 0
private var defaultEndTime: Long = 0
private var defaultTotalTime = 0L
private var selectStartTime: Long = 0
private var selectEndTime: Long = 0
private var selectUseAppEntitys: ArrayList<UseAppEntity>? = null
private lateinit var selectUseAppEntitys: ArrayList<UseAppEntity>
private var selectTotalTime: Long = 0
private lateinit var selectEntity: LinkedList<UseAppListEntity>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setAndroidNativeLightStatusBar(true)
......@@ -43,11 +49,7 @@ class AppUseActivity : BaseActivity() {
mContext = this
initView()
initSelector()
if (defaultUseAppEntitys == null) {
defaultLoadData()
} else {
initChart()
}
defaultLoadData()
}
private fun defaultLoadData() {
......@@ -56,59 +58,61 @@ class AppUseActivity : BaseActivity() {
defaultUseAppEntitys = ArrayList()
defaultTotalTime = 0L
GlobalScope.launch(Dispatchers.IO) {
mContext?.let { it ->
val useAppDao = DatabaseManager.getInstance(it).getUseAppDao()
val useTimeDao = DatabaseManager.getInstance(it).getUseTimeDao()
val useApps = useAppDao?.queryAll()
val useTimes = useTimeDao?.queryByTime(defaultStartTime, defaultEndTime)
if (useApps == null) {
return@let
val useAppDao = DatabaseManager.getInstance(mContext).getUseAppDao()
val useTimeDao = DatabaseManager.getInstance(mContext).getUseTimeDao()
val useApps = useAppDao?.queryAll()
val useTimes = useTimeDao?.queryByTime(defaultStartTime, defaultEndTime)
if (useApps == null) {
return@launch
}
Log.i(TAG, "useApps: ${useApps.size} useTimes: ${useTimes?.size}")
val tempEntitys = ArrayList<UseAppEntity>()
useTimes?.map<UseTime, UseTime> { useTime ->
if (useTime.useStartTime < defaultStartTime) {
useTime.useStartTime = defaultStartTime
}
if (useTime.useEndTime > defaultEndTime) {
useTime.useEndTime = defaultEndTime
}
Log.i(TAG, "useApps: ${useApps.size} useTimes: ${useTimes?.size}")
val tempEntitys = ArrayList<UseAppEntity>()
useTimes?.map<UseTime, UseTime> { useTime ->
if (useTime.useStartTime < defaultStartTime) {
useTime.useStartTime = defaultStartTime
}
if (useTime.useEndTime > defaultEndTime) {
useTime.useEndTime = defaultEndTime
}
useTime
}?.filter { useTime ->
useApps.any { useApp ->
useApp.appPackage == useTime.appPackage
}
}?.forEach { useTime ->
val useApp = UseAppEntity(useTime.appPackage, "", (useTime.useEndTime - useTime.useStartTime) / 1000 / 60)
tempEntitys.add(useApp)
useTime
}?.filter { useTime ->
useApps.any { useApp ->
useApp.appPackage == useTime.appPackage
}
tempEntitys.groupBy {
it.appPackage
}.values.flatten().forEach { useAppEntity ->
useApps.forEach {
if (it.appPackage == useAppEntity.appPackage) {
useAppEntity.appName = it.appName
}
}
defaultUseAppEntitys?.add(useAppEntity)
defaultTotalTime += useAppEntity.useTime
}?.forEach { useTime ->
val useApp = UseAppEntity(useTime.appPackage, "", (useTime.useEndTime - useTime.useStartTime) / 1000 / 60)
tempEntitys.add(useApp)
}
tempEntitys.groupBy {
it.appPackage
}.forEach {
var tempTotalTime = 0L
it.value.forEach { temp ->
defaultTotalTime += temp.useTime
tempTotalTime += temp.useTime
}
// 根据使用时间降序排列
defaultUseAppEntitys!!.sortByDescending { it.useTime }
if (defaultUseAppEntitys!!.size > 4) {
val tempAppEntity = UseAppEntity("", "", 0)
for (i in 4..defaultUseAppEntitys!!.size) {
tempAppEntity.appPackage = "Other"
tempAppEntity.appName = "其他"
tempAppEntity.useTime = tempAppEntity.useTime + defaultUseAppEntitys!![i - 1].useTime
}
defaultUseAppEntitys!![3] = tempAppEntity
defaultUseAppEntitys!!.removeAt(4)
val tempUseAppEntity = UseAppEntity(it.key, getApplicationName(mContext, it.key), tempTotalTime)
defaultUseAppEntitys.add(tempUseAppEntity)
}
// 根据使用时间降序排列
defaultUseAppEntitys.sortByDescending { it.useTime }
if (defaultUseAppEntitys.size > 4) {
val tempAppEntity = UseAppEntity("", "", 0)
for (i in 4..defaultUseAppEntitys.size) {
tempAppEntity.appPackage = "Other"
tempAppEntity.appName = "其他"
tempAppEntity.useTime = tempAppEntity.useTime + defaultUseAppEntitys[i - 1].useTime
}
withContext(Dispatchers.Main) {
initChart()
defaultUseAppEntitys[3] = tempAppEntity
for (i in defaultUseAppEntitys.size downTo 5) {
defaultUseAppEntitys.removeAt(i - 1)
}
}
withContext(Dispatchers.Main) {
initChart()
}
}
}
......@@ -117,11 +121,24 @@ class AppUseActivity : BaseActivity() {
}
private fun initChart() {
tv_app_use_time.text = String.format(getString(R.string.edu_item_app_use_last_day), defaultTotalTime)
tv_app_use_time.text = String.format(getString(R.string.edu_item_app_use_last_day), formatDateTime(defaultTotalTime))
time_progress.setData(defaultUseAppEntitys, defaultTotalTime)
time_progress.initAnimation()
}
private fun initRecyclerView() {
val treeAdapter = TreeAdapter(this, selectEntity, selectTotalTime)
val layoutManager = object:LinearLayoutManager(this){
override fun canScrollVertically(): Boolean {
return false
}
}
rv_tree.layoutManager = layoutManager
rv_tree.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
rv_tree.adapter = treeAdapter
}
private fun initSelector() {
val format = SimpleDateFormat("yyyy-MM-dd", Locale.US)
selectEndTime = System.currentTimeMillis()
......@@ -142,8 +159,8 @@ class AppUseActivity : BaseActivity() {
TimePickerBuilder(this, OnTimeSelectListener { date, _ ->
selectStartTime = date.time
tv_date_start.text = format.format(Date(selectStartTime))
Log.e(TAG, "开始选择:${selectStartTime}")
selectLoadData()
loadDetails()
}).setRangDate(startDate, endDate)
.setDate(startSelectDate)
.build().show()
......@@ -153,14 +170,15 @@ class AppUseActivity : BaseActivity() {
TimePickerBuilder(this, OnTimeSelectListener { date, _ ->
selectEndTime = date.time
tv_date_end.text = format.format(Date(selectEndTime))
Log.e(TAG, "结束选择:${selectEndTime}")
selectLoadData()
loadDetails()
}).setRangDate(startDate, endDate)
.setDate(nowDate)
.build().show()
}
selectLoadData()
loadDetails()
}
fun close(view: View?) {
......@@ -170,59 +188,109 @@ class AppUseActivity : BaseActivity() {
private fun selectLoadData() {
selectUseAppEntitys = ArrayList()
selectTotalTime = 0L
var tempTotalTime = 0L
GlobalScope.launch(Dispatchers.IO) {
mContext?.let { it ->
val useAppDao = DatabaseManager.getInstance(it).getUseAppDao()
val useTimeDao = DatabaseManager.getInstance(it).getUseTimeDao()
val useApps = useAppDao?.queryAll()
val useTimes = useTimeDao?.queryByTime(selectStartTime, selectEndTime)
if (useApps == null) {
return@let
val useAppDao = DatabaseManager.getInstance(mContext).getUseAppDao()
val useTimeDao = DatabaseManager.getInstance(mContext).getUseTimeDao()
val useApps = useAppDao?.queryAll()
val useTimes = useTimeDao?.queryByTime(selectStartTime, selectEndTime)
if (useApps == null) {
return@launch
}
Log.i(TAG, "useApps: ${useApps.size} useTimes: ${useTimes?.size}")
useTimes?.map<UseTime, UseTime> { useTime ->
if (useTime.useStartTime < selectStartTime) {
useTime.useStartTime = selectStartTime
}
Log.i(TAG, "useApps: ${useApps.size} useTimes: ${useTimes?.size}")
val tempEntitys = ArrayList<UseAppEntity>()
useTimes?.map<UseTime, UseTime> { useTime ->
if (useTime.useStartTime < selectStartTime) {
useTime.useStartTime = selectStartTime
}
if (useTime.useEndTime > selectEndTime) {
useTime.useEndTime = selectEndTime
}
useTime
}?.filter { useTime ->
useApps.any { useApp ->
useApp.appPackage == useTime.appPackage
}
}?.forEach { useTime ->
val useApp = UseAppEntity(useTime.appPackage, "", (useTime.useEndTime - useTime.useStartTime) / 1000 / 60)
tempEntitys.add(useApp)
if (useTime.useEndTime > selectEndTime) {
useTime.useEndTime = selectEndTime
}
tempEntitys.groupBy {
it.appPackage
}.values.flatten().forEach { useAppEntity ->
useApps.forEach {
if (it.appPackage == useAppEntity.appPackage) {
useAppEntity.appName = it.appName
}
}
selectUseAppEntitys?.add(useAppEntity)
selectTotalTime += useAppEntity.useTime
useTime
}?.filter { useTime ->
useApps.any { useApp ->
useApp.appPackage == useTime.appPackage
}
// 根据使用时间降序排列
selectUseAppEntitys!!.sortByDescending { it.useTime }
withContext(Dispatchers.Main) {
tv_app_use_total_time.text = String.format(getString(R.string.edu_item_app_use_total), selectTotalTime)
val allTime: Float = ((selectEndTime - selectStartTime) / 1000 / 60).toFloat()
val showTime = selectTotalTime / allTime * 100
Log.e(TAG, "showTime = $showTime , allTime = $allTime")
use_time_progress.setProgress(showTime)
}?.groupBy {
it.appPackage
}?.forEach {
it.value.forEach { temp ->
tempTotalTime += ((temp.useEndTime - temp.useStartTime) / 1000 / 60)
}
val tempUseAppEntity = UseAppEntity(it.key, getApplicationName(mContext, it.key), tempTotalTime)
selectUseAppEntitys.add(tempUseAppEntity)
}
selectTotalTime = tempTotalTime
Log.e(TAG, "selectLoadData selectTotalTime:$selectTotalTime")
// 根据使用时间降序排列
selectUseAppEntitys.sortByDescending { it.useTime }
withContext(Dispatchers.Main) {
tv_app_use_total_time.text = String.format(getString(R.string.edu_item_app_use_total), formatDateTime(selectTotalTime))
val allTime: Float = ((selectEndTime - selectStartTime) / 1000 / 60).toFloat()
val showTime = selectTotalTime / allTime * 100
Log.e(TAG, "showTime = $showTime , allTime = $allTime")
use_time_progress.setProgress(showTime)
}
}
}
fun more(view: View) {}
private fun loadDetails() {
selectEntity = LinkedList()
selectTotalTime = 0L
GlobalScope.launch(Dispatchers.IO) {
val useAppDao = DatabaseManager.getInstance(mContext).getUseAppDao()
val useTimeDao = DatabaseManager.getInstance(mContext).getUseTimeDao()
val useApps = useAppDao?.queryAll()
val useTimes = useTimeDao?.queryByTime(selectStartTime, selectEndTime)
if (useApps == null) {
return@launch
}
Log.i(TAG, "loadDetails useApps: ${useApps.size} useTimes: ${useTimes?.size}")
var tempTotalTimes = 0L
val tempUseApps = LinkedList<UseAppListEntity>()
useTimes?.map<UseTime, UseTime> { useTime ->
if (useTime.useStartTime < selectStartTime) {
useTime.useStartTime = selectStartTime
}
if (useTime.useEndTime > selectEndTime) {
useTime.useEndTime = selectEndTime
}
useTime
}?.filter { useTime ->
useApps.any { useApp ->
useApp.appPackage == useTime.appPackage
}
}?.groupBy {
it.appPackage
}?.forEach { map ->
val appList = UseAppListEntity(0)
appList.appPackage = map.key
appList.count = map.value.size.toLong()
val useAppsChild = LinkedList<UseAppListEntity>()
map.value.forEach {
val tempAppList = UseAppListEntity(1)
tempAppList.startTime = formatDate2MdHm(it.useStartTime)
tempAppList.endTime = formatDate2MdHm(it.useEndTime)
useAppsChild.add(tempAppList)
appList.useTime += ((it.useEndTime - it.useStartTime) / 1000 / 60)
}
tempTotalTimes += appList.useTime
appList.child = useAppsChild
tempUseApps.add(appList)
}
selectTotalTime = tempTotalTimes
Log.e(TAG, "loadDetails selectTotalTime:$selectTotalTime")
tempUseApps.forEach {
it.icon = getApplicationIcon(mContext, it.appPackage)
it.appName = getApplicationName(mContext, it.appPackage)
}
selectEntity.clear()
selectEntity.addAll(tempUseApps)
selectEntity.sortByDescending { it.useTime }
withContext(Dispatchers.Main) {
initRecyclerView()
}
}
}
}
......
......@@ -196,19 +196,20 @@ public class DialogUIUtils {
* @param listener 事件监听
*/
public static BuildBean showAlert(Activity activity, CharSequence title, CharSequence msg, CharSequence hint1, CharSequence hint2,
CharSequence firstTxt, CharSequence secondTxt, boolean isVertical, boolean cancleable, boolean outsideTouchable, DialogUIListener listener) {
CharSequence firstTxt, CharSequence secondTxt, boolean isVertical, boolean cancleable, boolean outsideTouchable, DialogUIListener listener) {
return DialogAssigner.getInstance().assignAlert(activity, title, msg, hint1, hint2, firstTxt, secondTxt, isVertical, cancleable, outsideTouchable, listener);
}
public static BuildBean showAlertPassword(Activity activity, CharSequence title, CharSequence msg, CharSequence hint1, CharSequence hint2,
CharSequence sure, CharSequence cancel, boolean isVertical, boolean cancleable, boolean outsideTouchable, DialogUIListener listener) {
CharSequence sure, CharSequence cancel, boolean isVertical, boolean cancleable, boolean outsideTouchable, DialogUIListener listener) {
return DialogAssigner.getInstance().assignAlertPassword(activity, title, msg, hint1, hint2, sure, cancel, isVertical, cancleable, outsideTouchable, listener);
}
public static BuildBean showAlertPasswordCanVer(Activity activity, CharSequence title, CharSequence msg, CharSequence thirdTx, CharSequence hint1, CharSequence hint2,
CharSequence sure, CharSequence cancel, boolean isVertical, boolean cancleable, boolean outsideTouchable, DialogUIListener listener) {
CharSequence sure, CharSequence cancel, boolean isVertical, boolean cancleable, boolean outsideTouchable, DialogUIListener listener) {
return DialogAssigner.getInstance().assignAlertPasswordCanVer(activity, title, msg, thirdTx, hint1, hint2, sure, cancel, isVertical, cancleable, outsideTouchable, listener);
}
/**
* 短时间中下位置显示。线程安全,可以在非UI线程调用。
*/
......
......@@ -68,7 +68,8 @@ object WorkManager {
}
// LoadingDialog.getInstance(launcher).show("切换中")
GlobalScope.launch(Dispatchers.IO) {
openAccessibility(launcher)
// TODO 暂时屏蔽
// openAccessibility(launcher)
SwitchInMdm.onInit(launcher)
activate(launcher)
withContext(Dispatchers.Main){
......
package com.secspace.lib.common.function.entity
import android.graphics.drawable.Drawable
data class UseAppListEntity(var itemLevel: Int) {
var appName: String = ""
var appPackage: String = ""
var icon: Drawable? = null
var useTime: Long = 0
var count: Long = 0
var startTime: String = ""
var endTime: String = ""
var itemState: Int = 0
var child: List<UseAppListEntity>? = null
}
\ No newline at end of file
......@@ -104,6 +104,15 @@ public class AppUseProgress extends View {
paintColors.add(0xFF9BFA13);
paintColors.add(0xFFFAB613);
paintColors.add(0xFFE5E5E5);
paintColors.add(0xFFE5E5E5);
paintColors.add(0xFFE5E5E5);
paintColors.add(0xFFE5E5E5);
paintColors.add(0xFFE5E5E5);
paintColors.add(0xFFE5E5E5);
paintColors.add(0xFFE5E5E5);
paintColors.add(0xFFE5E5E5);
paintColors.add(0xFFE5E5E5);
paintColors.add(0xFFE5E5E5);
}
public void setData(List<UseAppEntity> useAppEntities, long allTime) {
......
......@@ -8,6 +8,7 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.animation.LinearInterpolator;
......@@ -33,7 +34,7 @@ public class UseTimeProgress extends View {
*/
private float mProgress;
//描述文字的高度
private float textHeight;
// private float textHeight;
//描述文字的高度
private float textWidth;
......@@ -127,11 +128,8 @@ public class UseTimeProgress extends View {
progressHeight = dp2px(6);
roundRectRadius = dp2px(3);
textPaintSize = sp2px(10);
textHeight = dp2px(10);
progressMarginTop = dp2px(4);
//view真实的高度
mViewHeight = (int) (progressMarginTop + progressPaintWidth * 2 + progressHeight);
// textHeight = dp2px(10);
// progressMarginTop = dp2px(4);
}
......@@ -214,7 +212,7 @@ public class UseTimeProgress extends View {
switch (mode) {
case MeasureSpec.UNSPECIFIED:
case MeasureSpec.AT_MOST:
mHeight = mViewHeight;
mHeight = progressMarginTop + progressPaintWidth * 2 + progressHeight;
break;
case MeasureSpec.EXACTLY:
mHeight = height;
......@@ -226,7 +224,7 @@ public class UseTimeProgress extends View {
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mWidth = getMeasuredWidth();
//绘制文字
// drawText(canvas, textString);
//背景
......@@ -237,16 +235,17 @@ public class UseTimeProgress extends View {
private void drawBgProgress(Canvas canvas) {
bgRectF.left = 0;
bgRectF.top = textHeight + progressMarginTop;
bgRectF.top = progressMarginTop;
bgRectF.right = this.getMeasuredWidth();
bgRectF.bottom = bgRectF.top + progressHeight;
canvas.drawRoundRect(bgRectF, roundRectRadius, roundRectRadius, bgPaint);
Log.e("TAG1", " this.getMeasuredWidth():" + this.getMeasuredWidth());
}
private void drawProgress(Canvas canvas) {
progressRectF.left = 0;
progressRectF.top = textHeight + progressMarginTop;
progressRectF.right = currentProgress;
progressRectF.top = progressMarginTop;
progressRectF.right = mProgress * this.getMeasuredWidth() / 100;
progressRectF.bottom = progressRectF.top + progressHeight;
canvas.drawRoundRect(progressRectF, roundRectRadius, roundRectRadius, progressPaint);
}
......@@ -261,7 +260,7 @@ public class UseTimeProgress extends View {
textRect.left = (int) moveDis;
textRect.top = 0;
textRect.right = (int) (textPaint.measureText(textString) + moveDis);
textRect.bottom = (int) textHeight;
// textRect.bottom = (int) textHeight;
Paint.FontMetricsInt fontMetrics = textPaint.getFontMetricsInt();
int baseline = (textRect.bottom + textRect.top - fontMetrics.bottom - fontMetrics.top) / 2;
//文字绘制到整个布局的中心位置
......@@ -281,8 +280,6 @@ public class UseTimeProgress extends View {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float value = (float) valueAnimator.getAnimatedValue();
textString = "已售" + formatNum((int) value) + "%";
textWidth = textPaint.measureText(textString);
currentProgress = value * mWidth / 100;
if (progressListener != null) {
progressListener.currentProgressListener(value);
......@@ -318,8 +315,16 @@ public class UseTimeProgress extends View {
}
public UseTimeProgress setProgress(float progress) {
return setProgress(progress, "NoTag");
}
public UseTimeProgress setProgress(float progress, String tag) {
mWidth = this.getMeasuredWidth();
mProgress = progress;
initAnimation();
// initAnimation();
currentProgress = mProgress * mWidth / 100;
Log.e("TAG1", "tag: "+ tag + " mProgress:" + mProgress + " mWidth:" + mWidth);
invalidate();
return this;
}
......
......@@ -13,6 +13,8 @@ import com.skr.activation.utils.DesUtil
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileWriter
import java.text.SimpleDateFormat
import java.util.*
fun decrypt(strMi: String): String {
......@@ -98,3 +100,27 @@ fun write2File(source: String, filePath: String) {
fileWriter.write(source)
}
}
fun formatDate2MdHm(date: Long): String{
val format = SimpleDateFormat("MM-dd HH:mm", Locale.US)
return format.format(Date(date))
}
fun formatDateTime(minute: Long): String {
var stringTimes = ""
val days = minute / (60 * 24)
val hours = minute % (60 * 24) / 60
val minutes = minute % 60
when {
days > 0 -> {
stringTimes = days.toString() + "天" + hours + "时" + minutes + "分"
}
hours > 0 -> {
stringTimes = hours.toString() + "时" + minutes + "分"
}
minutes > 0 -> {
stringTimes = minutes.toString() + "分"
}
}
return stringTimes
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment