171 lines
6.6 KiB
Java
171 lines
6.6 KiB
Java
package com.xwad.os.adapter;
|
|
|
|
import android.app.Activity;
|
|
import android.content.ComponentName;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.util.Log;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.hjq.toast.Toaster;
|
|
import com.xwad.os.BuildConfig;
|
|
import com.xwad.os.R;
|
|
import com.xwad.os.activity.ExitActivity;
|
|
import com.xwad.os.activity.ManualActivity;
|
|
import com.xwad.os.activity.PasswordActivity;
|
|
import com.xwad.os.activity.service.ServiceActivity;
|
|
import com.xwad.os.bean.DesktopIcon;
|
|
import com.xwad.os.manager.AppManager;
|
|
import com.xwad.os.manager.RemoteManager;
|
|
import com.xwad.os.utils.ApkUtils;
|
|
import com.xwad.os.utils.BitmapUtils;
|
|
import com.xwad.os.utils.IconUtils;
|
|
import com.xwad.os.utils.OpenApkUtils;
|
|
import com.xwad.os.utils.Utils;
|
|
|
|
import java.util.List;
|
|
|
|
public class AppAdapter extends RecyclerView.Adapter<AppAdapter.AppHolder> {
|
|
private static final String TAG = "AppAdapter";
|
|
|
|
private Context mContext;
|
|
|
|
private List<DesktopIcon> desktopIcons;
|
|
|
|
@NonNull
|
|
@Override
|
|
public AppHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
mContext = parent.getContext();
|
|
return new AppHolder(LayoutInflater.from(mContext).inflate(R.layout.item_app, parent, false));
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(@NonNull AppHolder holder, int position) {
|
|
DesktopIcon desktopIcon = desktopIcons.get(position);
|
|
String lable = desktopIcon.getLable();
|
|
holder.tv_appname.setText(lable);
|
|
holder.iv_icon.setImageDrawable(desktopIcon.getIcon());
|
|
String pkg = desktopIcon.getPackageName();
|
|
Log.e(TAG, "getView: " + pkg);
|
|
int i = IconUtils.appClassNameList.indexOf(pkg);
|
|
if (i != -1) {
|
|
String val = IconUtils.appIconList.get(i);
|
|
int resID = mContext.getResources().getIdentifier(val, "drawable", BuildConfig.APPLICATION_ID);
|
|
if (resID == 0) {
|
|
Log.e(TAG, "getView: not found src : " + pkg);
|
|
holder.iv_icon.setImageBitmap(BitmapUtils.getIconBitmap(mContext, desktopIcon.getIcon()));
|
|
} else {
|
|
holder.iv_icon.setImageDrawable(mContext.getResources().getDrawable(resID));
|
|
}
|
|
} else {
|
|
switch (pkg) {
|
|
case AppManager.ADD_NAME:
|
|
case AppManager.UPDATE_NAME:
|
|
case AppManager.MANUAL_NAME:
|
|
case AppManager.SERVICE_NAME:
|
|
holder.iv_icon.setImageDrawable(desktopIcon.getIcon());
|
|
break;
|
|
default:
|
|
holder.iv_icon.setImageBitmap(BitmapUtils.getIconBitmap(mContext, desktopIcon.getIcon()));
|
|
break;
|
|
}
|
|
}
|
|
holder.root.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
switch (pkg) {
|
|
case AppManager.ADD_NAME:
|
|
mContext.startActivity(new Intent(mContext, PasswordActivity.class));
|
|
break;
|
|
case AppManager.UPDATE_NAME:
|
|
Intent intent = new Intent();
|
|
ComponentName componentName = new ComponentName("com.uiui.zy", "com.uiui.zy.activity.update.UpdateActivity");
|
|
intent.setComponent(componentName);
|
|
try {
|
|
mContext.startActivity(intent);
|
|
} catch (Exception e) {
|
|
Toaster.show("打开失败,请检查是否安装");
|
|
Log.e(TAG, "onClick: " + e.getMessage());
|
|
}
|
|
break;
|
|
case AppManager.MANUAL_NAME:
|
|
mContext.startActivity(new Intent(mContext, ManualActivity.class));
|
|
break;
|
|
case AppManager.SERVICE_NAME:
|
|
mContext.startActivity(new Intent(mContext, ServiceActivity.class));
|
|
break;
|
|
case "com.jxw.zwpg":
|
|
OpenApkUtils.getInstance().openZuowenpigai6();
|
|
break;
|
|
case "com.jxw.gb.zwpg":
|
|
OpenApkUtils.getInstance().openZuowenpigai();
|
|
break;
|
|
case "com.jxw.huiben":
|
|
OpenApkUtils.getInstance().openARHuiben();
|
|
break;
|
|
case AppManager.DESKTOP_EXIT:
|
|
exitDesktop();
|
|
break;
|
|
default:
|
|
boolean settingOtherAppInstaller = RemoteManager.getInstance().showThirdApp();
|
|
if (!settingOtherAppInstaller && !ApkUtils.isSystemApp(mContext, desktopIcon.getPackageName())) {
|
|
Toaster.show("已禁止应用打开");
|
|
} else {
|
|
OpenApkUtils.getInstance().openApp(desktopIcon.getPackageName(), desktopIcon.getClassName());
|
|
}
|
|
break;
|
|
}
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
public void exitDesktop() {
|
|
Intent intent = new Intent("Receiver_Refresh_Password_Action");
|
|
intent.setPackage("com.uiui.zy");
|
|
mContext.sendBroadcast(intent);
|
|
|
|
boolean is_activation = RemoteManager.getInstance().getSnIsActivation();
|
|
if (is_activation) {
|
|
mContext.startActivity(new Intent(mContext, ExitActivity.class));
|
|
} else {
|
|
Utils.exitDesktop((Activity) mContext);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return desktopIcons == null ? 0 : desktopIcons.size();
|
|
}
|
|
|
|
public List<DesktopIcon> getDesktopIcons() {
|
|
return desktopIcons;
|
|
}
|
|
|
|
public void setDesktopIcons(List<DesktopIcon> desktopIcons) {
|
|
this.desktopIcons = desktopIcons;
|
|
notifyDataSetChanged();
|
|
}
|
|
|
|
class AppHolder extends RecyclerView.ViewHolder {
|
|
ConstraintLayout root;
|
|
TextView tv_appname;
|
|
ImageView iv_icon;
|
|
|
|
public AppHolder(@NonNull View itemView) {
|
|
super(itemView);
|
|
root = itemView.findViewById(R.id.root);
|
|
tv_appname = itemView.findViewById(R.id.tv_appname);
|
|
iv_icon = itemView.findViewById(R.id.iv_icon);
|
|
}
|
|
}
|
|
}
|