1、增加BaseAdapter类添加/移除数据方法

2、新建ToolLog类
3、将基类修改为抽象类
This commit is contained in:
zengfantian 2014-12-31 17:07:53 +08:00
parent 65938b954a
commit fd6d4fcfe2
10 changed files with 144 additions and 78 deletions

View File

@ -8,6 +8,7 @@ import android.os.Bundle;
import android.util.Log;
import com.zftlive.android.MApplication;
import com.zftlive.android.config.SysEnv;
import com.zftlive.android.data.DTO;
import com.zftlive.android.tools.ToolAlert;
import com.zftlive.android.tools.ToolAlert.ILoadingOnKeyListener;
@ -24,8 +25,6 @@ public abstract class BaseActivity extends Activity {
protected Intent mIntent = new Intent();
/***整个应用Applicaiton**/
protected MApplication mApplication = null;
/***数据传输对象Key**/
private final static String DTO_KEY = "dtoKey";
/**当前Activity的弱引用防止内存泄露**/
private WeakReference<Activity> context = null;
/**日志输出标志**/
@ -85,18 +84,26 @@ public abstract class BaseActivity extends Activity {
* 跳转Activity
* @param activity需要跳转至的Activity
*/
protected void forward(Class activity) {
protected void forward(Class<? extends Activity> activity) {
mIntent.setClass(this, activity);
startActivity(mIntent);
}
/**
* 设置传递参数
* @param value 数据传输对象
*/
protected void assinAttriblte(DTO value) {
mIntent.putExtra(SysEnv.ACTIVITY_DTO_KEY, value);
}
/**
* 设置传递参数
* @param key 参数key
* @param value 数据传输对象
*/
protected void assinAttriblte(DTO value) {
mIntent.putExtra(DTO_KEY, value);
protected void assinAttriblte(String key,DTO value) {
mIntent.putExtra(key, value);
}
/**
@ -117,7 +124,7 @@ public abstract class BaseActivity extends Activity {
* @return
*/
protected DTO gainAttribltes() {
DTO parms = (DTO)getIntent().getExtras().getSerializable(DTO_KEY);
DTO parms = (DTO)getIntent().getExtras().getSerializable(SysEnv.ACTIVITY_DTO_KEY);
return parms;
}

View File

@ -1,38 +1,137 @@
package com.zftlive.android.base;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.zftlive.android.MApplication;
import com.zftlive.android.config.SysEnv;
import com.zftlive.android.data.DTO;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
/**
* Adapter基类
*
* @author 曾繁添
* @version 1.0
*
*
*/
public class BaseAdapter extends android.widget.BaseAdapter {
public abstract class BaseAdapter extends android.widget.BaseAdapter {
/** 数据存储集合 **/
protected List<Object> mDataList = new ArrayList<Object>();
/** Context上下文 **/
protected Context mContext;
public BaseAdapter() {
}
public BaseAdapter(Context mContext) {
this.mContext = mContext;
}
@Override
public int getCount() {
return 0;
return mDataList.size();
}
@Override
public Object getItem(int position) {
return null;
if (position < mDataList.size())
return mDataList.get(position);
else
return null;
}
@Override
public long getItemId(int position) {
return 0;
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
/**
* 添加数据
* @param item 数据项
*/
protected boolean addItem(Object object){
return mDataList.add(object);
}
/**
* 在指定索引位置添加数据
* @param location 索引
* @param object 数据
*/
protected void addItem(int location,Object object){
mDataList.add(location, object);
}
/**
* 集合方式添加数据
* @param collection 集合
*/
protected boolean addItem(Collection<? extends Object> collection){
return mDataList.addAll(collection);
}
/**
* 在指定索引位置添加数据集合
* @param location 索引
* @param collection 数据集合
*/
protected boolean addItem(int location,Collection<? extends Object> collection){
return mDataList.addAll(location,collection);
}
/**
* 移除指定对象数据
* @param object 移除对象
* @return 是否移除成功
*/
protected boolean removeItem(Object object){
return mDataList.remove(object);
}
/**
* 移除指定索引位置对象
* @param location 删除对象索引位置
* @return 被删除的对象
*/
protected Object removeItem(int location){
return mDataList.remove(location);
}
/**
* 移除指定集合对象
* @param collection 待移除的集合
* @return 是否移除成功
*/
protected boolean removeAll(Collection<? extends Object> collection){
return mDataList.removeAll(collection);
}
/**
* 清空数据
*/
protected void clear() {
mDataList.clear();
}
/**
* 获取BaseActivity方法
* @return BaseActivity
*/
protected BaseActivity getActivity(){
if(null == mContext ) return null;
if(mContext instanceof BaseActivity)
return (BaseActivity)mContext;
return null;
}
}

View File

@ -1,8 +1,6 @@
package com.zftlive.android.base;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
/**
* android 系统中的四大组件之一BroadcastReceiver基类
@ -10,11 +8,6 @@ import android.content.Intent;
* @version 1.0
*
*/
public class BaseBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
}
public abstract class BaseBroadcastReceiver extends BroadcastReceiver {
}

View File

@ -1,9 +1,6 @@
package com.zftlive.android.base;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
/**
* android 系统中的四大组件之一ContentProvider基类
@ -11,44 +8,6 @@ import android.net.Uri;
* @version 1.0
*
*/
public class BaseContentProvider extends ContentProvider {
@Override
public boolean onCreate() {
return false;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
return null;
}
@Override
public String getType(Uri uri) {
return null;
}
@Override
public Uri insert(Uri uri, ContentValues values) {
return null;
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
return 0;
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
return 0;
}
public abstract class BaseContentProvider extends ContentProvider {
}

View File

@ -8,7 +8,7 @@ import java.io.Serializable;
* @version 1.0
*
*/
public class BaseEntity implements Serializable {
public abstract class BaseEntity implements Serializable {
/**
*/

View File

@ -10,6 +10,6 @@ import android.app.Fragment;
*
*/
@SuppressLint("NewApi")
public class BaseFragment extends Fragment {
public abstract class BaseFragment extends Fragment {
}

View File

@ -8,6 +8,6 @@ import android.support.v4.app.Fragment;
* @version 1.0
*
*/
public class BaseFragmentV4 extends Fragment {
public abstract class BaseFragmentV4 extends Fragment {
}

View File

@ -10,12 +10,6 @@ import android.os.IBinder;
* @version 1.0
*
*/
public class BaseService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
public abstract class BaseService extends Service {
}

View File

@ -67,6 +67,9 @@ public final class SysEnv {
/***设备IMSI号码**/
public static final String IMSI = ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getSubscriberId();
/***Activity之间数据传输数据对象Key**/
public static final String ACTIVITY_DTO_KEY = "ACTIVITY_DTO_KEY";
/**获取系统显示材质***/
public static DisplayMetrics getDisplayMetrics(){
WindowManager windowMgr = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);

View File

@ -0,0 +1,11 @@
package com.zftlive.android.tools;
/**
* 日志工具类
* @author 曾繁添
* @version 1.0
*
*/
public class ToolLog {
}