-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
72 changed files
with
1,937 additions
and
812 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
app/src/main/java/cn/tongdun/android/activity/ItemListActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
package cn.tongdun.android.activity; | ||
|
||
import android.content.Context; | ||
import android.content.pm.ApplicationInfo; | ||
import android.content.pm.PackageInfo; | ||
import android.content.pm.PackageManager; | ||
import android.graphics.drawable.Drawable; | ||
import android.hardware.Sensor; | ||
import android.hardware.SensorManager; | ||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import androidx.core.content.ContextCompat; | ||
import androidx.recyclerview.widget.DividerItemDecoration; | ||
import androidx.recyclerview.widget.LinearLayoutManager; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.trustdevice.android.R; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import butterknife.BindView; | ||
import butterknife.OnClick; | ||
import cn.tongdun.android.adapter.AppListRecyclerViewAdapter; | ||
import cn.tongdun.android.base.BaseActivity; | ||
import cn.tongdun.android.beans.AppItemData; | ||
|
||
public class ItemListActivity extends BaseActivity { | ||
|
||
@BindView(R.id.tv_title) | ||
TextView tvTitle; | ||
@BindView(R.id.tv_title_right) | ||
TextView tvTitleRight; | ||
@BindView(R.id.rv_item_list) | ||
RecyclerView rvItemList; | ||
|
||
private int mType; | ||
private boolean mShowSystemApp = false; | ||
private List<AppItemData> mItemData = new ArrayList<>(); | ||
private AppListRecyclerViewAdapter mAdapter; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
} | ||
|
||
@Override | ||
protected int getContentViewResId() { | ||
return R.layout.activity_app_list; | ||
} | ||
|
||
@Override | ||
protected void initData() { | ||
mType = getIntent().getIntExtra("type", -1); | ||
if (mType == 0) { | ||
loadInstalledAppList(mShowSystemApp); | ||
} else if (mType == 1) { | ||
loadSensorList(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void initView() { | ||
if (mType == 0) { | ||
tvTitle.setText(getResources().getString(R.string.app_list)); | ||
tvTitleRight.setText(getResources().getString(R.string.show_system_apps)); | ||
} else if (mType == 1) { | ||
tvTitle.setText(getResources().getString(R.string.sensor_list)); | ||
tvTitleRight.setVisibility(View.GONE); | ||
} | ||
LinearLayoutManager manager = new LinearLayoutManager(this); | ||
rvItemList.setLayoutManager(manager); | ||
mAdapter = new AppListRecyclerViewAdapter(mItemData); | ||
rvItemList.setAdapter(mAdapter); | ||
rvItemList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL)); | ||
} | ||
|
||
@OnClick({R.id.tv_title, R.id.tv_title_right}) | ||
public void onViewClicked(View view) { | ||
switch (view.getId()) { | ||
case R.id.tv_title: | ||
this.finish(); | ||
break; | ||
case R.id.tv_title_right: | ||
mShowSystemApp = !mShowSystemApp; | ||
if (mShowSystemApp) { | ||
tvTitleRight.setText(getResources().getString(R.string.hide_system_apps)); | ||
} else { | ||
tvTitleRight.setText(getResources().getString(R.string.show_system_apps)); | ||
} | ||
loadInstalledAppList(mShowSystemApp); | ||
mAdapter.updateData(mItemData); | ||
break; | ||
} | ||
} | ||
|
||
private void loadInstalledAppList(boolean showSystemApp) { | ||
PackageManager packageManager = getPackageManager(); | ||
if (packageManager == null) { | ||
return; | ||
} | ||
List<PackageInfo> packageInfoList = packageManager.getInstalledPackages(0); | ||
for (PackageInfo info : packageInfoList) { | ||
if (info == null) { | ||
continue; | ||
} | ||
if (!showSystemApp && isSystemApp(info.applicationInfo)) { | ||
continue; | ||
} | ||
String packageName = info.packageName; | ||
String versionName = info.versionName; | ||
Drawable icon = info.applicationInfo.loadIcon(packageManager); | ||
String appName = packageManager.getApplicationLabel(info.applicationInfo).toString(); | ||
// if (mAppItemDataSet.contains(appName)){ | ||
// continue; | ||
// } | ||
mItemData.add(new AppItemData(icon, appName, packageName, versionName)); | ||
} | ||
} | ||
|
||
private boolean isSystemApp(ApplicationInfo info) { | ||
boolean isSysApp = (info.flags & ApplicationInfo.FLAG_SYSTEM) == ApplicationInfo.FLAG_SYSTEM; | ||
boolean isSysUpd = (info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == ApplicationInfo.FLAG_UPDATED_SYSTEM_APP; | ||
return isSysApp || isSysUpd; | ||
} | ||
|
||
private void loadSensorList() { | ||
|
||
SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); | ||
List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL); | ||
for (Sensor sensor : sensorList) { | ||
Drawable icon = ContextCompat.getDrawable(this, getIconByType(sensor.getType())); | ||
String name = sensor.getName(); | ||
String vendor = sensor.getVendor(); | ||
String version = String.valueOf(sensor.getVersion()); | ||
mItemData.add(new AppItemData(icon, name, vendor, version)); | ||
} | ||
} | ||
|
||
private int getIconByType(int sensorType) { | ||
switch (sensorType) { | ||
case 1: | ||
case 10: | ||
case 35: | ||
return R.drawable.ic_sensor_accelerometer; | ||
case 2: | ||
case 14: | ||
return R.drawable.ic_sensor_magnetic_field; | ||
case 3: | ||
case 11: | ||
case 15: | ||
case 20: | ||
case 27: | ||
return R.drawable.ic_sensor_orientation; | ||
case 4: | ||
case 16: | ||
return R.drawable.ic_sensor_gyroscope; | ||
case 5: | ||
return R.drawable.ic_sensor_light; | ||
case 6: | ||
return R.drawable.ic_sensor_pressure; | ||
case 7: | ||
case 13: | ||
return R.drawable.ic_sensor_temperature; | ||
case 8: | ||
return R.drawable.ic_sensor_proximity; | ||
case 9: | ||
return R.drawable.ic_sensor_gravity; | ||
case 12: | ||
return R.drawable.ic_sensor_humidity; | ||
case 17: | ||
case 30: | ||
return R.drawable.ic_sensor_motion; | ||
case 18: | ||
case 19: | ||
return R.drawable.ic_sensor_step; | ||
case 21: | ||
case 31: | ||
return R.drawable.ic_sensor_heartrate; | ||
case 22: | ||
case 26: | ||
return R.drawable.ic_sensor_tilt; | ||
case 23: | ||
case 24: | ||
case 25: | ||
case 28: | ||
case 29: | ||
case 32: | ||
case 33: | ||
case 34: | ||
return R.drawable.ic_sensor_all; | ||
case 36: | ||
return R.drawable.ic_sensor_hinge; | ||
default: | ||
return R.drawable.ic_sensor_private; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/cn/tongdun/android/adapter/AppListRecyclerViewAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package cn.tongdun.android.adapter; | ||
|
||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import com.trustdevice.android.R; | ||
|
||
import java.util.List; | ||
|
||
import cn.tongdun.android.beans.AppItemData; | ||
|
||
/** | ||
* @description: app list RecyclerView Adapter | ||
* @author: wuzuchang | ||
* @date: 2023/3/8 | ||
*/ | ||
public class AppListRecyclerViewAdapter extends BaseRecyclerViewAdapter<AppItemData> { | ||
|
||
public AppListRecyclerViewAdapter(List<AppItemData> data) { | ||
super(data); | ||
} | ||
|
||
@Override | ||
public int getLayoutId(int viewType) { | ||
|
||
return R.layout.item_app_list; | ||
} | ||
|
||
@Override | ||
public void convert(BaseViewHolder holder, final AppItemData data, final int position) { | ||
|
||
ImageView iv_icon = holder.getView(R.id.iv_app_icon); | ||
iv_icon.setImageDrawable(data.getIcon()); | ||
TextView tv_app_name = holder.getView(R.id.tv_app_name); | ||
tv_app_name.setText(data.getAppName() + ": " + data.getVersionName()); | ||
TextView tv_application = holder.getView(R.id.tv_application); | ||
tv_application.setText(data.getPackageName()); | ||
} | ||
|
||
|
||
public void updateData(List<AppItemData> data) { | ||
this.mData = data; | ||
notifyDataSetChanged(); | ||
} | ||
} |
Oops, something went wrong.