XPOSED源码研究之XposedInstaller(2)从manifest开始WelcomeActivity

来源:互联网 发布:追信魔盒在线制作软件 编辑:程序博客网 时间:2024/06/05 00:22
上一节分析了XposedApp,这一节继续分析WelcomeActivity。

WelcomeActivity继承自XposedBaseActivity,并实现了两个接口类:ModuleListener, RepoListener,主要用以接受一些通知。
XposedBaseActivity作为该项目的基础类,实现了一些样式风格的功能,代码不是很多,主要功能还是在ThemeUtil和NavUtil中,后面再分析。

WelcomeActivity界面:
布局设计确实一个TextView加一个ListView,其中框架、模块、下载、设置、日志、关于均为ListView的一个Item。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"android:layout_height="match_parent" android:orientation="vertical"android:padding="6dp" tools:context=".WelcomeActivity" > <TextViewandroid:layout_width="match_parent" android:layout_height="wrap_content"android:layout_marginBottom="8dp" android:gravity="center"android:text="@string/welcome" android:textSize="18sp" /> <ListViewandroid:id="@+id/welcome_list" android:layout_width="match_parent"android:layout_height="0dp" android:layout_weight="1" android:clipToPadding="false"android:divider="@null" android:dividerHeight="0dp" > </ListView> </LinearLayout>
Item的设计比较直观:
class WelcomeItem { public final String title; public final String description;protected WelcomeItem(int titleResId, int descriptionResId) { this.title =getString(titleResId); this.description = getString(descriptionResId); } @Overridepublic String toString() { return title; } }
添加Item也比较直观:
mAdapter = new WelcomeAdapter(this); // TODO add proper description texts and load them from resources, add icons, make it more fancy, ... mAdapter.add(newWelcomeItem(R.string.tabInstall, R.string.tabInstallDescription)); mAdapter.add(newWelcomeItem(R.string.tabModules, R.string.tabModulesDescription)); mAdapter.add(newWelcomeItem(R.string.tabDownload, R.string.tabDownloadDescription)); mAdapter.add(newWelcomeItem(R.string.tabSettings, R.string.tabSettingsDescription)); mAdapter.add(newWelcomeItem(R.string.tabLogs, R.string.tabLogsDescription)); mAdapter.add(newWelcomeItem(R.string.tabAbout, R.string.tabAboutDescription));
点击Item的响应代码:
ListView lv = (ListView) findViewById(R.id.welcome_list); lv.setAdapter(mAdapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public voidonItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intentnew Intent(WelcomeActivity.this, XposedInstallerActivity.class); intent.putExtra(XposedInstallerActivity.EXTRA_SECTION, position); intent.putExtra(NavUtil.FINISH_ON_UP_NAVIGATION, true); startActivity(intent); NavUtil.setTransitionSlideEnter(WelcomeActivity.this); } });
把选择的Item的position作为参数传递给XposedInstallerActivity并启动,因此后面一节应当分析XposedInstallerActivity
setTransitionSlideEnter作为一种进出效果,后面分析util功能的时候一并细述。

最后添加当前对象到监听列表里去,方便接受通知:
ModuleUtil.getInstance().addListener(this); mRepoLoader.addListener(thisfalse);
因此还要实现一些监听通知的接口:
@Override public void onInstalledModulesReloaded(ModuleUtil moduleUtil) { notifyDataSetChanged(); } @Override public voidonSingleInstalledModuleReloaded(ModuleUtil moduleUtil, String packageName, InstalledModule module) { notifyDataSetChanged(); } @Override public voidonRepoReloaded(RepoLoader loader) { notifyDataSetChanged(); }
主要用于更新ListView。

ListView的Item布局文件并不是一个标题对应一个描述那么简单,其实还隐藏了一些TextView,主要用于显示异常信息的,默认是GONE状态,一旦有异常出现就显示,例如本文开头的图片中的红色字体。
if (position == XposedInstallerActivity.TAB_INSTALL) { xposedActive = XposedApp.getActiveXposedVersion() >= InstallerFragment.getJarLatestVersion(); }
view.findViewById(R.id.txtXposedNotActive).setVisibility(!xposedActive ? View.VISIBLE : View.GONE);

0 0
原创粉丝点击