Search in sources :

Example 1 with AppInfo

use of com.balaganovrocks.yourmasterclean.model.AppInfo in project superCleanMaster by joyoyao.

the class SoftwareAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    if (convertView == null) {
        convertView = infater.inflate(R.layout.listview_software, null);
        holder = new ViewHolder();
        holder.appIcon = (ImageView) convertView.findViewById(R.id.app_icon);
        holder.appName = (TextView) convertView.findViewById(R.id.app_name);
        holder.size = (TextView) convertView.findViewById(R.id.app_size);
        holder.ripleUninstall = (RippleView) convertView.findViewById(R.id.riple_uninstall);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    final AppInfo item = (AppInfo) getItem(position);
    if (item != null) {
        holder.appIcon.setImageDrawable(item.getAppIcon());
        holder.appName.setText(item.getAppName());
        if (item.isInRom()) {
            holder.size.setText(StorageUtil.convertStorage(item.getPkgSize()));
        } else {
            holder.size.setText(StorageUtil.convertStorage(item.getPkgSize()));
        }
    // holder.size.setText(StorageUtil.convertStorage(item.getUid()));
    }
    holder.ripleUninstall.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction("android.intent.action.VIEW");
            intent.setAction("android.intent.action.DELETE");
            intent.addCategory("android.intent.category.DEFAULT");
            intent.setData(Uri.parse("package:" + item.getPackname()));
            mContext.startActivity(intent);
        }
    });
    return convertView;
}
Also used : Intent(android.content.Intent) ImageView(android.widget.ImageView) RippleView(com.balaganovrocks.yourmasterclean.views.RippleView) TextView(android.widget.TextView) View(android.view.View) AppInfo(com.balaganovrocks.yourmasterclean.model.AppInfo)

Example 2 with AppInfo

use of com.balaganovrocks.yourmasterclean.model.AppInfo in project superCleanMaster by joyoyao.

the class SoftwareManageFragment method fillData.

private void fillData() {
    if (position == 0) {
        topText.setText("");
    } else {
        topText.setText(R.string.Attention);
    }
    task = new AsyncTask<Void, Integer, List<AppInfo>>() {

        private int mAppCount = 0;

        @Override
        protected List<AppInfo> doInBackground(Void... params) {
            PackageManager pm = mContext.getPackageManager();
            List<PackageInfo> packInfos = pm.getInstalledPackages(0);
            publishProgress(0, packInfos.size());
            List<AppInfo> appinfos = new ArrayList<AppInfo>();
            for (PackageInfo packInfo : packInfos) {
                publishProgress(++mAppCount, packInfos.size());
                final AppInfo appInfo = new AppInfo();
                Drawable appIcon = packInfo.applicationInfo.loadIcon(pm);
                appInfo.setAppIcon(appIcon);
                int flags = packInfo.applicationInfo.flags;
                int uid = packInfo.applicationInfo.uid;
                appInfo.setUid(uid);
                if ((flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
                    // 系统应用
                    appInfo.setUserApp(false);
                } else {
                    // 用户应用
                    appInfo.setUserApp(true);
                }
                if ((flags & ApplicationInfo.FLAG_EXTERNAL_STORAGE) != 0) {
                    appInfo.setInRom(false);
                } else {
                    appInfo.setInRom(true);
                }
                String appName = packInfo.applicationInfo.loadLabel(pm).toString();
                appInfo.setAppName(appName);
                String packname = packInfo.packageName;
                appInfo.setPackname(packname);
                String version = packInfo.versionName;
                appInfo.setVersion(version);
                try {
                    mGetPackageSizeInfoMethod.invoke(mContext.getPackageManager(), new Object[] { packname, new IPackageStatsObserver.Stub() {

                        @Override
                        public void onGetStatsCompleted(PackageStats pStats, boolean succeeded) throws RemoteException {
                            synchronized (appInfo) {
                                appInfo.setPkgSize(pStats.cacheSize + pStats.codeSize + pStats.dataSize);
                            }
                        }
                    } });
                } catch (Exception e) {
                }
                appinfos.add(appInfo);
            }
            return appinfos;
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            try {
                mProgressBarText.setText(getString(R.string.scanning_m_of_n, values[0], values[1]));
            } catch (Exception e) {
            }
        }

        @Override
        protected void onPreExecute() {
            try {
                showProgressBar(true);
                mProgressBarText.setText(R.string.scanning);
            } catch (Exception e) {
            }
            // loading.setVisibility(View.VISIBLE);
            super.onPreExecute();
        }

        @Override
        protected void onPostExecute(List<AppInfo> result) {
            super.onPostExecute(result);
            try {
                showProgressBar(false);
                userAppInfos = new ArrayList<>();
                systemAppInfos = new ArrayList<>();
                long allSize = 0;
                for (AppInfo a : result) {
                    if (a.isUserApp()) {
                        allSize += a.getPkgSize();
                        userAppInfos.add(a);
                    } else {
                        systemAppInfos.add(a);
                    }
                }
                if (position == 0) {
                    topText.setText(getString(R.string.software_top_text, userAppInfos.size(), StorageUtil.convertStorage(allSize)));
                    mAutoStartAdapter = new SoftwareAdapter(mContext, userAppInfos);
                    listview.setAdapter(mAutoStartAdapter);
                } else {
                    mAutoStartAdapter = new SoftwareAdapter(mContext, systemAppInfos);
                    listview.setAdapter(mAutoStartAdapter);
                }
            } catch (Exception e) {
            }
        }
    };
    task.execute();
}
Also used : PackageInfo(android.content.pm.PackageInfo) Drawable(android.graphics.drawable.Drawable) ArrayList(java.util.ArrayList) RemoteException(android.os.RemoteException) AppInfo(com.balaganovrocks.yourmasterclean.model.AppInfo) SoftwareAdapter(com.balaganovrocks.yourmasterclean.adapter.SoftwareAdapter) PackageManager(android.content.pm.PackageManager) PackageStats(android.content.pm.PackageStats) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

AppInfo (com.balaganovrocks.yourmasterclean.model.AppInfo)2 Intent (android.content.Intent)1 PackageInfo (android.content.pm.PackageInfo)1 PackageManager (android.content.pm.PackageManager)1 PackageStats (android.content.pm.PackageStats)1 Drawable (android.graphics.drawable.Drawable)1 RemoteException (android.os.RemoteException)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 SoftwareAdapter (com.balaganovrocks.yourmasterclean.adapter.SoftwareAdapter)1 RippleView (com.balaganovrocks.yourmasterclean.views.RippleView)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1