音乐类软件LoveMusic开发(二)----基本架构
来源:互联网 发布:spark sql java 实现 编辑:程序博客网 时间:2024/06/05 20:29
根据设计图打好基本框架,准备好用于统一输出的Log类,用于其他Activities与Fragments继承的基类ActivityBase与FragmentBase、统一的工具栏Utils、完成初始化MyApplication等
ActivityBase 类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
Log.I(L, "onCreate: " + this);
//获取设备的实际像素
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
sDisplayHeight = displaymetrics.heightPixels;
sDisplayWidth = displaymetrics.widthPixels;
setContentView(R.layout.activity_base);
mFrameContainer = (FrameLayout) findViewById(R.id.fragmentContainer);
View v = getView();
if(v!=null)
{
mFrameContainer.addView(v);
}
}
布局文件R.layout.activity_base中只有FrameLayout,子类统一通过getView()方法实现各自布局;获取设备实际像素以便实现适配。
private BroadcastReceiver mNetworkStatusReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
checkNetwork();
};
};
@Override
protected void onStart() {
super.onStart();
Log.I(L, "onStart: " + this);
//注册网络状态接收器
if (!mIsNetworkStatusReceiverRegisterred) {
IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(mNetworkStatusReceiver, filter);
mIsNetworkStatusReceiverRegisterred = true;
}
EventBus.getDefault().registerSticky(this);
}
在onStart()中注册网络状态接收器与EventBus
@Override
protected void onStop() {
super.onStop();
Log.I(L, "onStop: " + this);
//不活跃时注销网络状态接收器
if (mIsNetworkStatusReceiverRegisterred) {
unregisterReceiver(mNetworkStatusReceiver);
mIsNetworkStatusReceiverRegisterred = false;
}
EventBus.getDefault().unregister(this);
}
在onStop()中注销网络状态接收器与EventBus
@Override
protected void onResume() {
super.onResume();
if (!Utils.isNetworkConnected()) {
}
}
在onResume()中检查网络连接状况
private void checkNetwork() {
if (!Utils.isNetworkConnected()) {
Utils.showMessage(this, R.string.network_error, true);
}
}
receiver中检查网络状况的方法
protected View getView(){return null;}
public void onEventBackgroundThread(Message msg){}
public void onEventMainThread(Message msg){}
public void onEventAsync(Message msg){}
public void onEvent(Message msg){}
EventBus应用于不同状况的方法,子类根据需要复写
FragmentBase中也在其生命周期中注册相应的EventBus
Utils提供SD上文件存储、检查网络、检查权限、SharedPreferences存储等方法。
MyApplication中初始化Universal Image Loader、FlatUi、以及向服务器请求基本布局信息以便更新界面。
- 音乐类软件LoveMusic开发(二)----基本架构
- 音乐类软件LoveMusic开发(一)----产品简介
- 音乐类软件LoveMusic开发(三)----登录界面
- ERP软件开发架构之二 数据访问层设计
- vivi开发笔记(二):软件架构分析
- 移动端多人视频通话软件开发(二)-- 架构
- 软件架构设计(二)
- 软件开发的架构
- 软件开发,架构先行
- 软件开发架构
- 软件开发三层架构
- Tensorflow基本开发架构
- 软件开发基本流程
- 软件开发基本流程
- 软件架构笔记(二)
- Yarn架构基本概况(二)
- 软件开发(二)
- 软件开发生命周期(二)
- spin_lock & mutex_lock的区别
- Java注释@interface的用法
- cocos2d-x (音效音乐)SimpleAudioEngine
- UVALIVE 3971<最大化最小值>
- TCP Loop Connect
- 音乐类软件LoveMusic开发(二)----基本架构
- PHP5.5 配置 Apache2.4 + MySQL5.6
- mysql数据库中实现内连接、左连接、右连接
- A. Watching a movie
- 淘宝下单高并发解决方案
- 可以上google的东西
- 过滤器:保安过滤器的技术参数及特点解读
- 半联结&反联结!
- 剑指offer 面试题39 求二叉树深度|判断是否为平衡二叉树