}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case 1: // 默认排序[当前]
break;
case 2: // 名称排序
Intent intent1 = new Intent(this, DeskByName.class);
startActivity(intent1);
break;
case 3: // 按安装时间排序
Intent intent2 = new Intent(this, DeskByTime.class);
startActivity(intent2);
break;
case 4:// 关于
Intent intent3 = new Intent(this, About.class);
startActivity(intent3);
break;
case 5:// 更新桌面
onCreate(null);
break;
default:
}
return super.onOptionsItemSelected(item);
}
public void initViews() {
packageManager = getPackageManager();
final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
List<HashMap<String, Object>> items = new ArrayList<HashMap<String, Object>>();
// get all apps
apps = packageManager.queryIntentActivities(mainIntent, 0);
for (ResolveInfo pi : apps) {
HashMap<String, Object> map = new HashMap<String, Object>();
PackageManager manager = this.getPackageManager();
map.put(“appIcon”, pi.loadIcon(packageManager));
map.put(“appName”, pi.loadLabel(packageManager).toString());
map.put(“appPack”, pi.activityInfo.packageName);
try {
map.put(“appTime”, Long.toString(manager.getPackageInfo(
pi.activityInfo.packageName, 0).firstInstallTime));
} catch (NameNotFoundException e) {
e.printStackTrace();
}
items.add(map);
}
// ToDB
db = new DbOperation(this);
long countlong = db.getCount(); // 获取数据库中记录数目
int countint = (int) countlong;
upCount = items.size();// +++++++++++++++++++++++++++++++++++++++upCount
if (countint == items.size()) {
isEqual = true;
// 若记录数目与当前items.size()相等,则不插入应用信息,只插入时间
for (int m = 0; m < items.size(); m++) {
// 插入时间:
String appPack2 = (String) items.get(m).get(“appPack”);
try {
PackageManager manager = this.getPackageManager();
String appTime2 = Long.toString(manager.getPackageInfo(
appPack2, 0).firstInstallTime);
db.insertTime(appTime2, appPack2);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} else {
// 若不等,则先清空表数据,然后再插入应用信息,然后插入时间
db.deleteTable();
for (int i = 0; i < items.size(); i++) {
String appName = (String) items.get(i).get(“appName”);
String appPack = (String) items.get(i).get(“appPack”);
String appTime = (String) items.get(i).get(“Time”);
App appInfo = new App(appName, appPack, appTime);
DbOperation db = new DbOperation(this);
db.insertApp(appInfo);
// 插入时间:
String appPack2 = (String) items.get(i).get(“appPack”);
try {
PackageManager manager = this.getPackageManager();
String appTime2 = Long.toString(manager.getPackageInfo(
appPack2, 0).firstInstallTime);
db.insertTime(appTime2, appPack2);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// 读取数据库信息
db = new DbOperation(this);
if (orderFlag == 0) {
appInfo = db.query(“appTable”);
} else if (orderFlag == 1) {
appInfo = db.queryByName(“appTable”);
} else if (orderFlag == 2) {
appInfo = db.queryByTime(“appTable”);
}
final int PageCount = (int) Math.ceil(apps.size() / APP_PAGE_SIZE);
Log.e(TAG, “size:” + apps.size() + " page:" + PageCount);
for (int i = 0; i < PageCount; i++) {
GridView appPage = new GridView(this);
this.registerForContextMenu(appPage);
appPage.setAdapter(new AppAdapter(this, appInfo, i, apps, items));
appPage.setNumColumns(6);
appPage.setOnItemClickListener(listener);
mScrollLayout.addView(appPage);
}
}
public OnItemClickListener listener = new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
GridView listView = (GridView) parent;
App appInfo = (App) (listView.getItemAtPosition(position));
String packName = appInfo.getPack();
Intent mainIntent = mContext.getPackageManager()
.getLaunchIntentForPackage(packName);
mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
mContext.startActivity(mainIntent);
} catch (ActivityNotFoundException noFound) {
Toast.makeText(mContext, “未发现该应用!”, Toast.LENGTH_SHORT).show();
}
}
};
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle(“操作”);
menu.add(0, 1, Menu.NONE, “更名”);
menu.add(0, 2, Menu.NONE, “卸载”);
}
public boolean onContextItemSelected(MenuItem item) {
// 得到当前被选中的item信息
AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item
.getMenuInfo();
final int a = menuInfo.position;
switch (item.getItemId()) {
case 1:
final EditText e = new EditText(this);
new AlertDialog.Builder(this).setTitle(“更名”)
// .setIcon(R.drawable.logo2)
.setView(e)
.setPositiveButton(“确定”,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int i) {
int b1 = mScrollLayout.getCurScreen();
int num1 = b1 * 36 + a;
String appName = appInfo.get(num1)
.getName();
System.out.println(appName);
String str = e.getText().toString();
System.out.println(str);
db.changeName(str, appName);
// 更新界面
onCreate(null);
}
}).setNegativeButton(“取消”, null).show();
break;
case 2:
int b1 = mScrollLayout.getCurScreen();
int num1 = b1 * 36 + a;
String appPack = appInfo.get(num1).getPack();
Uri uri = Uri.parse(“package:” + appPack);
System.out.println(appPack);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
intent.setData(uri);// 设置获取到的URI
db.deleteApp(appPack);
startActivity(intent);
// break;
default:
// 更新+延时
try {
Thread.currentThread().sleep(300);
onCreate(null);
} catch (InterruptedException e22) {
e22.printStackTrace();
}
onCreate(null);
return super.onContextItemSelected(item);
}
return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
class AppIntentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
onCreate(null);
}
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)
![](https://i-blog.csdnimg.cn/blog_migrate/0e2b6bbf1aa75b3e078ef186fc7a70a1.jpeg)
Android进阶资料
以下的资料是近年来,我和一些朋友面试收集整理了很多大厂的面试真题和资料,还有来自如阿里、小米、爱奇艺等一线大厂的大牛整理的架构进阶资料。希望可以帮助到大家。
Android进阶核心笔记
百万年薪必刷面试题
最全Android进阶学习视频
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!
!!(备注:Android)**
![](https://i-blog.csdnimg.cn/blog_migrate/0e2b6bbf1aa75b3e078ef186fc7a70a1.jpeg)
Android进阶资料
以下的资料是近年来,我和一些朋友面试收集整理了很多大厂的面试真题和资料,还有来自如阿里、小米、爱奇艺等一线大厂的大牛整理的架构进阶资料。希望可以帮助到大家。
Android进阶核心笔记
[外链图片转存中…(img-2noHjhZr-1712363655104)]
百万年薪必刷面试题
[外链图片转存中…(img-pihp7a5u-1712363655104)]
最全Android进阶学习视频
《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!