pull/11/head
parent
6876a5ade3
commit
ad7048de1f
Before Width: | Height: | Size: 81 KiB After Width: | Height: | Size: 82 KiB |
Binary file not shown.
Binary file not shown.
@ -1,76 +0,0 @@
|
||||
package com.tanshui.timeuse;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.usage.UsageStats;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
private Button app_use;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
app_use = findViewById(R.id.app_use);
|
||||
|
||||
//如没有开启应用权限,则开启
|
||||
if (!isStatAccessPermissionSet()) {
|
||||
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
|
||||
this.startActivity(intent);
|
||||
}
|
||||
app_use.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent=new Intent(MainActivity.this,appTimeUse.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
// 开启应用访问权限
|
||||
public boolean isStatAccessPermissionSet() {
|
||||
try {
|
||||
PackageManager packageManager = this.getPackageManager();
|
||||
ApplicationInfo info = packageManager.getApplicationInfo(this.getPackageName(), 0);
|
||||
AppOpsManager appOpsManager = (AppOpsManager) this.getSystemService(APP_OPS_SERVICE);
|
||||
return appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, info.uid, info.packageName) == AppOpsManager.MODE_ALLOWED;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.tanshui.timeuse.adapter;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MainViewPagerAdapter extends FragmentPagerAdapter {
|
||||
|
||||
private final List<Fragment> mFragmentList = new ArrayList<>();
|
||||
|
||||
public MainViewPagerAdapter(FragmentManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
public void addFragment(Fragment fragment) {
|
||||
mFragmentList.add(fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return mFragmentList.size();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment getItem(int position) {
|
||||
return mFragmentList.get(position);
|
||||
}
|
||||
}
|
@ -1,277 +0,0 @@
|
||||
package com.tanshui.timeuse;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.AppOpsManager;
|
||||
import android.app.ProgressDialog;
|
||||
import android.app.usage.UsageStats;
|
||||
import android.app.usage.UsageStatsManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleAdapter;
|
||||
import android.widget.Toast;
|
||||
import com.tanshui.timeuse.database.timeUseDBHelper;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class appTimeUse extends AppCompatActivity {
|
||||
|
||||
private ArrayList<AppInfo> mApplicationInfos;
|
||||
private timeUseDBHelper dbHelper;
|
||||
private List<AppInfo> appInfoList;
|
||||
private SimpleAdapter simpleAdapter;
|
||||
private ProgressDialog progressDialog;
|
||||
private ArrayList<HashMap<String, Object>> listItem;
|
||||
private String date;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_app_time_use);
|
||||
|
||||
dbHelper = timeUseDBHelper.getInstance(this);
|
||||
dbHelper.openWriteLink();
|
||||
dbHelper.openReadLink();
|
||||
showProgressDialog("1","11");
|
||||
ListView lv_app = findViewById(R.id.lv_app);
|
||||
Button list = findViewById(R.id.jump_app_list);
|
||||
Button report = findViewById(R.id.jump_app_report);
|
||||
Button appClassify =findViewById(R.id.jump_app_appClassify);
|
||||
// 接受task_show传的date
|
||||
Intent intent1=getIntent();
|
||||
date = intent1.getStringExtra("date");
|
||||
|
||||
|
||||
list.setOnClickListener(v -> {
|
||||
Intent intent=new Intent(appTimeUse.this,task_show.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
report.setOnClickListener(v -> {
|
||||
Intent intent=new Intent(appTimeUse.this,report.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
appClassify.setOnClickListener(v -> {
|
||||
Intent intent=new Intent(appTimeUse.this,software_classification.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
mApplicationInfos=getAllAppInfo(this);
|
||||
listItem = new ArrayList<>();
|
||||
|
||||
listItem =getApp(dbHelper);
|
||||
// ---------------------------------------
|
||||
simpleAdapter = new SimpleAdapter(this,
|
||||
//绑定的数据
|
||||
listItem,
|
||||
//每一行的布局
|
||||
R.layout.appitem,
|
||||
//动态数组中的数据源的键映射到布局文件对应的控件中
|
||||
new String[] {"ItemImage", "ItemLabel","ItemTime"},
|
||||
new int[] {R.id.iv_appIcon, R.id.label,R.id.times});
|
||||
lv_app.setAdapter(simpleAdapter);
|
||||
|
||||
|
||||
// 显示app图标
|
||||
simpleAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
|
||||
@Override
|
||||
public boolean setViewValue(View view, Object o, String s) {
|
||||
if(view instanceof ImageView && o instanceof Drawable){
|
||||
|
||||
ImageView iv=(ImageView)view;
|
||||
iv.setImageDrawable((Drawable)o);
|
||||
return true;
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
});
|
||||
hideProgressDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
// 从数据库获取applist
|
||||
// appInfoList=dbHelper.queryAllAppInfo();
|
||||
}
|
||||
|
||||
public static String getTimeFromInt(long time) {
|
||||
|
||||
if (time <= 0) { return "已结束"; }
|
||||
// long day = time / (1 * 60 * 60 * 24);
|
||||
String hour = time / (1000*60*60) % 60 +"";
|
||||
String minute = time / (1000*60) % 60<10?"0"+time / (1000*60) % 60:""+time / (1000*60) % 60;
|
||||
String second = time /1000 % 60<10?"0"+time / 1000 % 60:""+time / 1000 % 60;
|
||||
|
||||
return hour+"小时"+minute+"分钟"+second+"秒";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取手机已安装应用列表
|
||||
* @param ctx
|
||||
* isFilterSystem 是否过滤系统应用
|
||||
*/
|
||||
public ArrayList<AppInfo> getAllAppInfo(Context ctx) {
|
||||
ArrayList<AppInfo> appBeanList = new ArrayList<>();
|
||||
AppInfo bean = null;
|
||||
PackageManager packageManager = ctx.getPackageManager();
|
||||
List<PackageInfo> list = packageManager.getInstalledPackages(0);
|
||||
for (PackageInfo p : list) {
|
||||
bean = new AppInfo();
|
||||
|
||||
bean.setIcon(p.applicationInfo.loadIcon(packageManager));
|
||||
bean.setLabel(packageManager.getApplicationLabel(p.applicationInfo).toString());
|
||||
bean.setPackage_name(p.applicationInfo.packageName);
|
||||
|
||||
int flags = p.applicationInfo.flags;
|
||||
// 判断是否是属于系统的apk
|
||||
if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
|
||||
// bean.setSystem(true);
|
||||
} else {
|
||||
appBeanList.add(bean);
|
||||
}
|
||||
|
||||
}
|
||||
return appBeanList;
|
||||
}
|
||||
// 弹出正在加载弹窗
|
||||
public void showProgressDialog(String title, String message) {
|
||||
if (progressDialog == null) {
|
||||
|
||||
progressDialog = ProgressDialog.show(appTimeUse.this,
|
||||
title, message, true, false);
|
||||
} else if (progressDialog.isShowing()) {
|
||||
progressDialog.setTitle(title);
|
||||
progressDialog.setMessage(message);
|
||||
}
|
||||
|
||||
progressDialog.show();
|
||||
|
||||
}
|
||||
// 隐藏提示加载弹窗
|
||||
public void hideProgressDialog() {
|
||||
|
||||
if (progressDialog != null && progressDialog.isShowing()) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
progressDialog=null;
|
||||
}
|
||||
// 获取应用信息
|
||||
public ArrayList<HashMap<String, Object>> getApp(timeUseDBHelper dbHelper){
|
||||
|
||||
// 从早上8点开始监听
|
||||
Calendar setBeginCal=Calendar.getInstance();
|
||||
|
||||
|
||||
Calendar setEndCal=Calendar.getInstance();
|
||||
|
||||
|
||||
Calendar beginCal = Calendar.getInstance();
|
||||
int hour = beginCal.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = beginCal.get(Calendar.MINUTE);
|
||||
int second = beginCal.get(Calendar.SECOND);
|
||||
|
||||
setBeginCal.add(Calendar.SECOND, -1 * second);
|
||||
setBeginCal.add(Calendar.MINUTE, -1 * minute);
|
||||
setBeginCal.add(Calendar.HOUR, -1 * hour+8);
|
||||
|
||||
setEndCal.add(Calendar.SECOND, -1 * second);
|
||||
setEndCal.add(Calendar.MINUTE, -1 * minute);
|
||||
setEndCal.add(Calendar.HOUR, -1 * hour+10);
|
||||
|
||||
beginCal.add(Calendar.SECOND, -1 * second);
|
||||
beginCal.add(Calendar.MINUTE, -1 * minute);
|
||||
beginCal.add(Calendar.HOUR, -1 * hour+8);
|
||||
|
||||
Calendar endCal = Calendar.getInstance();
|
||||
|
||||
UsageStatsManager manager=(UsageStatsManager)getApplicationContext().getSystemService(USAGE_STATS_SERVICE);
|
||||
List<UsageStats> stats=manager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY,beginCal.getTimeInMillis(),endCal.getTimeInMillis());
|
||||
Map<String, UsageStats> statsMap = manager.queryAndAggregateUsageStats(setBeginCal.getTimeInMillis(), setEndCal.getTimeInMillis());
|
||||
|
||||
ArrayList<HashMap<String, Object>> listItem = new ArrayList<>();
|
||||
|
||||
List<String> name = new ArrayList<>();
|
||||
List<Drawable> icons = new ArrayList<>();
|
||||
|
||||
for(UsageStats us:stats){
|
||||
try {
|
||||
PackageManager pm=getApplicationContext().getPackageManager();
|
||||
ApplicationInfo applicationInfo=pm.getApplicationInfo(us.getPackageName(),PackageManager.GET_META_DATA);
|
||||
// Toast.makeText(this, appInfo.package_name, Toast.LENGTH_SHORT).show();
|
||||
PackageInfo packageInfo = pm.getPackageInfo(applicationInfo.packageName, PackageManager.GET_CONFIGURATIONS);
|
||||
int flags = packageInfo.applicationInfo.flags;
|
||||
// SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
|
||||
//
|
||||
// String t=format.format(new Date(us.getLastTimeUsed()));
|
||||
// long t1=us.getLastTimeStamp();
|
||||
// String t2=format.format(new Date(us.getLastTimeUsed()));
|
||||
String appName = "";
|
||||
Drawable icon=null;
|
||||
|
||||
for(AppInfo app:mApplicationInfos){
|
||||
if(applicationInfo.packageName.equals(app.package_name)){
|
||||
appName=app.label;
|
||||
name.add(appName);
|
||||
icon=app.icon;
|
||||
icons.add(icon);
|
||||
}
|
||||
}
|
||||
|
||||
if(getTimeFromInt(us.getTotalTimeInForeground())!="已结束"){
|
||||
UsageStats usageStats=statsMap.get(applicationInfo.packageName);
|
||||
// 判断是否为系统应用系统
|
||||
if((flags & ApplicationInfo.FLAG_SYSTEM) == 0){
|
||||
AppInfo appInfo=new AppInfo();
|
||||
HashMap<String,Object> map = new HashMap<>();
|
||||
//加入图片
|
||||
map.put("ItemImage", icon);
|
||||
// 添加app名称
|
||||
|
||||
map.put("ItemLabel", appName);
|
||||
appInfo.label=appName;
|
||||
// 添加app使用时间
|
||||
map.put("ItemTime","今天使用时间:"+getTimeFromInt(usageStats.getTotalTimeInForeground()));
|
||||
appInfo.timeString=getTimeFromInt(usageStats.getTotalTimeInForeground());
|
||||
appInfo.timeLong=usageStats.getTotalTimeInForeground();
|
||||
appInfo.package_name=applicationInfo.packageName;
|
||||
|
||||
// dbHelper=timeUseDBHelper.getInstance(this);
|
||||
|
||||
if(dbHelper.searchPacketName(appInfo.package_name,"appList")){
|
||||
// 修改时间
|
||||
dbHelper.updateAppUseTime(appInfo,date);
|
||||
|
||||
}else{
|
||||
|
||||
dbHelper.insertAppInfos(appInfo,date);
|
||||
}
|
||||
listItem.add(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return listItem;
|
||||
}
|
||||
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package com.tanshui.timeuse.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.tanshui.timeuse.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link TaskListFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class TaskListFragment extends Fragment {
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
public TaskListFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment TaskListFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static TaskListFragment newInstance(String param1, String param2) {
|
||||
TaskListFragment fragment = new TaskListFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_task_list, container, false);
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package com.tanshui.timeuse.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.tanshui.timeuse.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link appUseFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class appUseFragment extends Fragment {
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
public appUseFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment appUseFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static appUseFragment newInstance(String param1, String param2) {
|
||||
appUseFragment fragment = new appUseFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_app_use, container, false);
|
||||
}
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
package com.tanshui.timeuse.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.tanshui.timeuse.R;
|
||||
import com.tanshui.timeuse.appTimeUse;
|
||||
import com.tanshui.timeuse.task_show;
|
||||
|
||||
public class main_tabFragment extends Fragment implements View.OnClickListener{
|
||||
private Button jump_appUse;
|
||||
private Button jump_report;
|
||||
private Fragment TaskListFragment,reportFragment,appUseFragment;
|
||||
private FragmentManager fragmentManager;
|
||||
@Nullable
|
||||
@Override
|
||||
public Context getContext() {
|
||||
return super.getContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
View view=inflater.inflate(R.layout.fragment_main_tab, container, false);
|
||||
initViews(view);
|
||||
setTabSelection(R.id.jump_list);
|
||||
return view;
|
||||
}
|
||||
//初始化视图对象
|
||||
private void initViews(View view){
|
||||
//主页面
|
||||
Button jump_list = (Button) view.findViewById(R.id.jump_list);
|
||||
jump_list.setOnClickListener(this);
|
||||
//分类页面
|
||||
jump_appUse=(Button)view.findViewById(R.id.jump_appUse);
|
||||
jump_appUse.setOnClickListener(this);
|
||||
//购物车页面
|
||||
jump_report=(Button) view.findViewById(R.id.jump_report);
|
||||
jump_report.setOnClickListener(this);
|
||||
fragmentManager=getFragmentManager();//获得Fragment管理类
|
||||
}
|
||||
//点击事件
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setTabSelection(v.getId());
|
||||
}
|
||||
//设置Tab选中
|
||||
public void setTabSelection(int id) {
|
||||
//开启一个事务
|
||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||
//隐藏所有Fragment
|
||||
if (TaskListFragment != null) {
|
||||
fragmentTransaction.hide(TaskListFragment);
|
||||
}
|
||||
if (reportFragment != null) {
|
||||
fragmentTransaction.hide(reportFragment);
|
||||
}
|
||||
if (appUseFragment != null) {
|
||||
fragmentTransaction.hide(appUseFragment);
|
||||
}
|
||||
|
||||
//根据tabItem的id来执行不同的操作
|
||||
switch (id) {
|
||||
case R.id.jump_list:
|
||||
if (TaskListFragment == null) {
|
||||
TaskListFragment = new TaskListFragment();
|
||||
fragmentTransaction.add(R.id.fg_content, TaskListFragment);
|
||||
} else {
|
||||
fragmentTransaction.show(TaskListFragment);
|
||||
}
|
||||
break;
|
||||
case R.id.jump_appUse:
|
||||
if (appUseFragment == null) {
|
||||
appUseFragment = new appUseFragment();
|
||||
fragmentTransaction.add(R.id.fg_content, appUseFragment);
|
||||
} else {
|
||||
fragmentTransaction.show(appUseFragment);
|
||||
}
|
||||
break;
|
||||
case R.id.jump_report:
|
||||
if (reportFragment == null) {
|
||||
reportFragment = new reportFragment();
|
||||
fragmentTransaction.add(R.id.fg_content, reportFragment);
|
||||
} else {
|
||||
fragmentTransaction.show(reportFragment);
|
||||
}
|
||||
break;
|
||||
}
|
||||
fragmentTransaction.commit();
|
||||
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
package com.tanshui.timeuse.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.tanshui.timeuse.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link reportFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class reportFragment extends Fragment {
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
private static final String ARG_PARAM1 = "param1";
|
||||
private static final String ARG_PARAM2 = "param2";
|
||||
|
||||
// TODO: Rename and change types of parameters
|
||||
private String mParam1;
|
||||
private String mParam2;
|
||||
|
||||
public reportFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
* this fragment using the provided parameters.
|
||||
*
|
||||
* @param param1 Parameter 1.
|
||||
* @param param2 Parameter 2.
|
||||
* @return A new instance of fragment reportFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static reportFragment newInstance(String param1, String param2) {
|
||||
reportFragment fragment = new reportFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putString(ARG_PARAM1, param1);
|
||||
args.putString(ARG_PARAM2, param2);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mParam1 = getArguments().getString(ARG_PARAM1);
|
||||
mParam2 = getArguments().getString(ARG_PARAM2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_today, container, false);
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.tanshui.timeuse.login;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.tanshui.timeuse.R;
|
||||
|
||||
public class login extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.tanshui.timeuse.login;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.tanshui.timeuse.R;
|
||||
|
||||
public class registered extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_registered);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue