1 Star 0 Fork 41

朱强1002 / Wei.Lib2A

forked from 中成才 / Wei.Lib2A 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

#Wei.Lib2A

Android快速开发框架,Android常用工具集。数据加载和下载框架并未集成,见另一项目,待续。。。(大部分东西在2013年前都写好了,一直懒得整理) ###欢迎加入我的 QQ群:215621863 相互学习探讨!

###这个库都有什么?能帮我们做什么? ####我写代码遵循两个基本原则:

  • 减少代码量。希望达到的效果是,让使用者尽可能减少代码,能一句话搞定的,绝不两句,能静态方法搞定的,绝不new对象;
  • 增强适应性和稳定性。由于Android平台厂商定制的碎片化和众多版本兼容性问题,本库的开发会着重考虑这些因素,而且基本都是经上线的项目考验过的。

本库的所有代码都经过本人严格测试,字斟句酌,了如指掌,注释也很清晰。覆盖Android基础开发的方方面面,推荐作为项目的基础框架来使用,以便于各功能的正常便利集成。若有任何疑问请联系作者 Wei.Chou(weichou2010@gmail.com)加群@群主

###基础常用组件介绍如下:

###1、存储卡工具类 Storage 仅通过几个常量即可便捷的取得内置或外置存储卡 Storage.SdCard 对象。例如:


//输出外置存储卡的路径到logcat
if (Storage.CARD_EXT != null) L.i(this, Storage.CARD_EXT.path);

//是否可以在默认的卡上创建任意目录
if (Storage.CARD_DEF.isCustomDirCreatable(context)) {
    //...
    try {
        File dir = FileUtils.makeDir(dirPath, true);
        L.i(this, dir.getPath());
        //...
    } catch (FileCreateFailureException e) {
        L.e(this, e);
    }
}

###2、存储卡自动选择与存储 FStoreLoc 仅有存储卡工具就够了吗?它需要去判断存储卡是否存在、能否创建目录和文件,再决定是否写文件。而FStoreLoc可以一步完成:


    public static File getImagesCacheDir() throws SdCardNotMountedException,
                                SdCardNotValidException, FileCreateFailureException {
		return FStoreLoc.BIGFILE.getImagesCacheDir(get(), DirLevel.CUSTOM);
	}
  • 上面代码中的 DirLevel.CUSTOM 表示选择自定义根目录,只有在存储卡支持创建自定义目录时才有效,否则抛异常。当然也可选择私有目录 DirLevel.PRIVATE 或自适应目录 DirLevel.DEFAULT,详见代码中的文档。

FStoreLoc有三种预置存储模式:

大文件模式生存模式根据业务需要可能需要设置存储卡根目录,那就放在App初始化里:


public class App extends AbsApp {
    @Override
    public void onCreate() {
		Debug.DEBUG = isDebugMode();
		if (Debug.DEBUG) {
            //...
        }
		super.onCreate();
        //...
        /* 设置大文件模式的文件根目录。若存储卡根目录允许写文件,则创建该目录,否则会使用存储卡上的
         * 系统为App分配的私有目录:Android/appname/files/
         * 大文件模式,即只存放在内置或外置存储卡上,外置优先。
         */
		FStoreLoc.BIGFILE.setBaseDirName(this, Const.APP_DIR_NAME);
        //切换到外置卡(默认会自动选择剩余空间最大的那张卡)。但是读写文件过程中如果不存在会自动切换到内置卡。
		FStoreLoc.BIGFILE.switchTo(this, Storage.CARD_EXT);
	}
    //...
}

###3、文件工具 FileUtils 和基于版本控制的文件并发读写工具 FileVersioned

###4、增强的SharedPreferences SPref 基于FileVersioned,解决SharedPreferences在多进程同时频繁读写时易丢失的问题。

###5、网络连接状况判断 Network

###6、网络连接状况监听 NetConnectionReceiver

###7、存储卡挂载状况监听 StorageReceiver 示例:


    @Override
	protected void onResume() {
		super.onResume();
		NetConnectionReceiver.registerObserver(mNetObserver);
    	StorageReceiver.registerObserver(mToastStorageObserver);
    	//StorageReceiver.registerObserver(mStorageObserver);
	}

	@Override
	protected void onPause() {
    	StorageReceiver.unregisterObserver(mToastStorageObserver);
    	//StorageReceiver.unregisterObserver(mStorageObserver);
		NetConnectionReceiver.unregisterObserver(mNetObserver);
		super.onPause();
	}

    private final NetObserver mNetObserver = new NetObserver() {
		@Override
		public void onChanged(Type type, State state) {
			ensureViewState(true, false);
		}
	};

    private final ToastStorageObserver mToastStorageObserver = new ToastStorageObserver(this);
    private final StorageObserver mStorageObserver = new StorageObserver() {
	    /**按下"MediaButton"按键时发出的广播,假如有"MediaButton"按键的话(硬件按键),
	     * Intent.EXTRA_KEY_EVENT携带了这个KeyEvent对象**/
    	protected void onMediaButton(KeyEvent ev) {}
    	/**已经插入,但是不能挂载**/
    	protected void onMediaUnMountable(SdCard sdcard) {}
    	/**对象为空白或正在使用不受支持的文件系统,未格式化**/
    	protected void onMediaNoFS(SdCard sdcard) {}
    	/**扩展介质被插入,而且已经被挂载。intent包含一个名为"read-only"的boolean extra表明挂载点是否只读**/
    	protected void onMediaMounted(SdCard sdcard, boolean readOnly) {}
    	/**正在磁盘检查**/
    	protected void onMediaChecking(SdCard sdcard) {}
    	/**请求媒体扫描器扫描存储介质,以将媒体文件信息放入数据库**/
    	protected void onMediaScannerScanFile(String filePath) {}
    	/**媒体扫描器开始扫描文件目录**/
    	protected void onMediaScannerStarted(String dirPath) {}
    	/**媒体扫描器完成扫描文件目录**/
    	protected void onMediaScannerFinished(String dirPath) {}
    	/**由于通过USB存储共享导致无法挂载,挂载点路径可参见参数Intent.mData**/
    	protected void onMediaShared(SdCard sdcard) {}
    	/**用户希望弹出外部存储介质,收到此广播之后应该立即关闭正在读写的文件;
    	 * 要弹出的卡的路径在intent.getData()里面包含了,可以先判断是不是正在读写的文件的那个卡**/
    	protected void onMediaEject(SdCard sdcard) {}
    	/**已经卸载但未拔出**/
    	protected void onMediaUnmounted(SdCard sdcard) {}
    	/**已经卸载并拔出**/
    	protected void onMediaRemoved(SdCard sdcard) {}
    	/**未卸载直接拔出**/
    	protected void onMediaBadRemoval(SdCard sdcard) {}
    }

###8、托管广播事件监听器 EventDelegater 基于但简化了BroadcastLocalBroadcast的发送/接收操作,在页面初始化的时候可以调用AbsActivity/AbsFragment.hostingLocalEventReceiver(...)将事件监听器进行托管,不再需要在onPause()onResume()以及onDestroy()等事件的时候进行unregisterXxx()registerXxx()编码,托管组件将自动完成。受惠于Broadcast的松散耦合机制和简化了的发送/接收操作,可将传统的Callack模式用本事件模式重构,轻松解决由于某些原因导致的资源无法释放内存泄露等问题。示例:

//在Activity或Fragment中发送事件
@ViewLayoutId(R.layout.f_m_m_tabs_left_btn_page)
public class MTabsLeftFrgmt extends AbsFragment {
    public void scroll2TopAndRefresh() {
        //发送事件
		sendLocalEvent(mRbtnRecommend.isChecked() ? Const.EventName.SCROLL_2_TOP_AND_REFRESH_frgmt_recommend
				: Const.EventName.SCROLL_2_TOP_AND_REFRESH_frgmt_favorite, null);
	}
    //...
}

//在子Fragment中接收事件
@ViewLayoutId(R.layout.f_f_m_m_tabs_left_btn_page_recommend)
public class RecommendFrgmt extends AbsFragment {
    @Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        //只需要提前托管就好了,不用考虑onPause()、onResume()以及onDestroy()的时候还要取消注册或重新注册事件监听
		hostingLocalEventReceiver(Const.EventName.SCROLL_2_TOP_AND_REFRESH_frgmt_recommend, PeriodMode.PAUSE_RESUME, new EventReceiver() {
			@Override
			public void onEvent(Bundle data) {
				scroll2TopAndRefresh();
			}
		});
	}

	public void scroll2TopAndRefresh() {
		L.i(this, "scroll2TopAndRefresh");
		//TODO 这里需要处理多次连续调用的情况
	}
}

###9、ResourcesId注解 ViewId

  • 重点注意@ViewOnClick的用法非常灵活。示例:
@ViewLayoutId(R.layout.m_edit)
public class EditActy extends AbsActivity implements OnClickListener {
    @ViewOnClick    //当本类 implements OnClickListener, 那么直接加上本注解即可,不用参数
    @ViewId(R.id.m_edit_title_left_btn_back)
	private ImageButton mBtnBack;
	@ViewId(R.id.m_edit_magic_board)
	private MagicBoardView mMagicBoard;
    //...

    @Override
    @ViewOnClick(@Ids(R.id.m_edit_magic_board)) //若前面没有加@ViewOnClick, 也可以写在onClick()上面,参数也可以像下面这样
    @ViewOnClick(@Ids({R.id.m_edit_title_left_btn_back, R.id.m_edit_magic_board}))
	public void onClick(View v) {
    	switch (v.getId()) {
		case R.id.m_acty_btn_download:
            //...
        break;
    }

    @ViewOnClick(@Ids({R.id.m_edit_title_left_btn_back, R.id.m_edit_magic_board}))  //或者可以写在任意自定义方法上面
    private void myOnClick(View v) {  //这里也可以不用参数,像这样: private void myOnClick() {}
        //...
    }

    @ViewOnClick(@Ids({R.id.m_edit_title_left_btn_back, R.id.m_edit_magic_board}))  //甚至还可以这样,有没有觉得很cool
    private OnClickListener mOnClickListener = new OnClickListener() {
		@Override
		public void onClick(View v) {
			//...
		}
	};
}

###10、Json的抽象 IJson 示例:


/**由于typeKey可能全局都一样,做一个抽象**/
public abstract class AbsData<T extends AbsData<T>> extends AbsJsonTyped<T> {
    public static final String KEY_RESULT		= "result";

	@Expose
	public String result;

	protected String typeKey() {
		return KEY_RESULT;
	}
}

/**构建与Json字符串对应的类结构**/
public class EditBean extends AbsData<EditBean> {
    @Expose
	public long id;
	@Expose
	public long topicId;
	@Expose
	public boolean favorite;
    @Expose
    public Info info;

    public boolean selected = false;

    public static class Info {
		public Temp[] temps;
		public int total_number;
	}

	public static class Temp {
		public long mid;
		public MagicBoardBody body;
		public int forwarding_count;
		public int classify;
		public long start_time;
		public long end_time;
		public int collect;
	}

	public EditBean() {}

	@Override
	public int hashCode() {
		return (int)id;
	}

	@Override
	public boolean equals(Object o) {
		EditBean fb = ((EditBean)o);
		return fb.id == id && fb.topicId == topicId;
	}

	@Override
	public EditBean fromJson(String json) {
		return fromJsonWithExposeAnnoFields(json, getTypeToken());
	}

	@Override
	public String toJson() {
		return toJsonWithExposeAnnoFields(this);
	}

	@Override
	protected String[] typeValues() {
		return null;
	}

	@Override
	protected TypeToken<EditBean> getTypeToken() {
		return new TypeToken<EditBean>(){};
	}
}

/*以下为操作数据*/

EditBean edit = new EditBean();
//edit.xxx = xxx;
//...
//序列化
edit.toJson();

//判断是否属于本类型,一般情况用不到。
if (new EditBean().isBelongToMe(new JSONObject(jsonString))) {
    //...
}

//反序列化
new EditBean().fromJson(jsonString);

###11、用途广泛的 ViewHolder 既可用于ListViewAdapter


    @Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return EditGridViewHolder.getAndBindView(position, convertView, parent, getInflater(), EditGridViewHolder.class, getItem(position), mOnFavoriteClick);
	}
    //...

    @ViewLayoutId(R.layout.i_m_edit)
    public static class EditGridViewHolder extends ViewHolder<EditBean, OnClickListener> {
		@ViewId(R.id.i_m_edit_magic_board)
		private MagicBoardView mMagicBoard;
		@ViewId(R.id.i_m_edit_cb_favorite)
		private CheckBox mCBFav;

		private Animation mAnimYes, mAnimNo;
		private boolean mAnimYesStarted = false, mAnimNoStarted = false;

		public EditGridViewHolder(View view) {
			super(view);
		}

		@Override
		protected void init(OnClickListener... args) {
			mCBFav.setOnClickListener(args[0]);
		}

		@Override
		public void bind(int position, EditListBean data) {
			mCBFav.setTag(this);
			MagicBoardUtils.display(getView().getContext(), mMagicBoard, data.magicBoard);
			
			mPanelTranslucence.setVisibility(data.selected ? View.VISIBLE : View.GONE);
			updateFavorite(false);
		}
        //...
    }

也可用于ViewPagerPagerAdapter:

    mViewPager.setAdapter(new PagerAdapter() {
    		@Override
			public int getCount() {
				return 5;
			}

			@Override
			public boolean isViewFromObject(View view, Object obj) {
				return view == ((ViewHolder<?, ?>)obj).getView();
			}

			@Override
			public int getItemPosition(Object obj) {
				int position = super.getItemPosition(obj);
				if (obj instanceof ViewHolder4) {
					position = 4;
				} else if (obj instanceof ViewHolder3) {
					position = 3;
				} else if (obj instanceof ViewHolder2) {
					position = 2;
				} else if (obj instanceof ViewHolder1) {
					position = 1;
				} else if (obj instanceof ViewHolder0) {
					position = 0;
				}
				return position;
			}

			@Override
			public Object instantiateItem(ViewGroup container, int position) {
				ViewHolder<Void, OnClickListener> vHolder = null;
				switch (position) {
				case 0:
					vHolder = ViewHolder.bindView(0, ViewHolder.makeView(ViewHolder0.class, getLayoutInflater(), container), ViewHolder0.class, null, mOnNextClick);
					break;
				case 1:
					vHolder = ViewHolder.bindView(0, ViewHolder.makeView(ViewHolder1.class, getLayoutInflater(), container), ViewHolder1.class, null, mOnNextClick);
					break;
				case 2:
					vHolder = ViewHolder.bindView(0, ViewHolder.makeView(ViewHolder2.class, getLayoutInflater(), container), ViewHolder2.class, null, mOnNextClick);
					break;
				case 3:
					vHolder = ViewHolder.bindView(0, ViewHolder.makeView(ViewHolder3.class, getLayoutInflater(), container), ViewHolder3.class, null, mOnNextClick);
					break;
				case 4:
					vHolder = ViewHolder.bindView(0, ViewHolder.makeView(ViewHolder4.class, getLayoutInflater(), container), ViewHolder4.class, null, mOnCompleteClick);
					break;
				}
				container.addView(vHolder.getView());
				return vHolder;
			}

			@Override
			public void destroyItem(ViewGroup container, int position, Object obj) {
				container.removeView(((ViewHolder<?, ?>)obj).getView());
			}
		});
	}
    //...
    
    @ViewLayoutId(R.layout.i_m_guide_next)
    private static class ViewHolder0 extends ViewHolder<Void, OnClickListener> {
		@ViewId(R.id.i_m_guide_bg)
		protected View mBg;
		@ViewId(R.id.i_m_guide_btn_next)
		protected ImageButton mBtnNext;

		protected static final int WIDTH		= 720;
		protected static final int HEIGHT		= 1280;
		protected static final int WIDTH_BTN	= 224;
		protected static final int HEIGHT_BTN	= 88;
		protected static final int RIGHT_BTN	= 16;
		protected static final int BOTTOM_BTN	= 29;

		public ViewHolder0(View view) {
			super(view);
		}

		@Override
		protected void init(OnClickListener... args) {
			mBg.setBackgroundResource(R.drawable.img_i_m_guide_0);
			mBtnNext.setTag(0);
			mBtnNext.setOnClickListener(args[0]);
			initBtnNextPosition();
		}

		@Override
		public void bind(int position, Void data) {}

		protected void initBtnNextPosition() {
			int screenWidth = Device.getInstance(getView().getContext()).width;
			int screenHeight = Device.getInstance(getView().getContext()).height;
			RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) mBtnNext.getLayoutParams();
			float widthScale = screenWidth * 1.0f / WIDTH;
			float heightScale = screenHeight * 1.0f / HEIGHT;
			lp.width = (int) (widthScale * WIDTH_BTN);
			lp.height = (int) (heightScale * HEIGHT_BTN);
			lp.rightMargin = (int) (widthScale * RIGHT_BTN);
			lp.bottomMargin = (int) (heightScale * BOTTOM_BTN);
			mBtnNext.setLayoutParams(lp);
		}
	}

	private static class ViewHolder1 extends ViewHolder0 {
		public ViewHolder1(View view) {
			super(view);
		}

		@Override
		protected void init(OnClickListener... args) {
			mBg.setBackgroundResource(R.drawable.img_i_m_guide_1);
			mBtnNext.setTag(1);
			mBtnNext.setOnClickListener(args[0]);
			initBtnNextPosition();
		}
	}
    //...

还可用于其他任何场景:

public class Xxx {
	@Override
	public void onClick(View v) {
        //弹出删除对话框
    	FavoriteDeleteViewHolder.showDeleteDialog(FavoriteActy.this, (ViewGroup)getWindow().getDecorView(), mOnDeleteClick);
    }
    //...
}

@ViewLayoutId(R.layout.m_favorite_delete_panel)
public class FavoriteDeleteViewHolder extends ViewHolder<Void, OnClickListener> {
	@ViewId(R.id.m_favorite_delete_panel_content)
	private ViewGroup mContentView;
	@ViewId(R.id.m_favorite_delete_panel_btn_delete)
	private Button mBtnDelete;
	@ViewId(R.id.m_favorite_delete_panel_btn_cancel)
	private Button mBtnCancel;

	private Context mContext;
	private OnClickListener mOnDeleteClickCallback;
	private boolean mDelete;

	public FavoriteDeleteViewHolder(View view) {
		super(view);
		mContext = view.getContext();
	}

	public static FavoriteDeleteViewHolder showDeleteDialog(Activity context, ViewGroup parent, OnClickListener onDeleteClickCallback) {
		View view = FavoriteDeleteViewHolder.makeView(FavoriteDeleteViewHolder.class, context.getLayoutInflater(), parent);
		FavoriteDeleteViewHolder vHolder = FavoriteDeleteViewHolder.bindView(0, view, FavoriteDeleteViewHolder.class, null, onDeleteClickCallback);
		parent.addView(view);
		vHolder.startAnimIn();
		return vHolder;
	}

	public void destroy() {
		startAnimOut();
	}
    //...
}
  • 简直神乎其技呀,有木有?!!!

###12、相册选择图片、剪裁,保存图片到相册并广播刷新 PhotoUtils 示例:


    private static final String EXTRA_SESSION			= ContributeActy.class.getName() + ".SESSION";
	private static final String EXTRA_LIST_DATA			= ContributeActy.class.getName() + ".LIST_DATA";

    private static final int REQUEST_CODE_PICK_PHOTO	= 100;
    private static final int REQUEST_CODE_CROP			= 101;

    private PhotoUtils.Session session;
    //...

    @Override
    public void onClick(View v) {
        try {
        	session = PhotoUtils.openSysGallery2ChoosePhoto(ContributeActy.this, REQUEST_CODE_PICK_PHOTO,
        		new CropArgs(REQUEST_CODE_CROP,
            		new File(App.getImagesCacheDirPrivate(), "croptemp-" + System.currentTimeMillis() + ".png").getPath(),
            		Bitmap.CompressFormat.PNG, false, true, 0, 0, 0, 0, 640, 640));
        	L.i(ContributeActy.class, session.toString());
        } catch (Exception e) {
        	L.e(ContributeActy.class, e);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	super.onActivityResult(requestCode, resultCode, data);
    	Uri uri = PhotoUtils.onActivityResult(this, session, requestCode, resultCode, data);
    	if (uri != null) {
    		getAdapter().getData().add(uri);
    		getAdapter().notifyDataSetChanged();
    		session = null;
    	}
    }

    @Override
	protected void onSaveInstanceState(Bundle outState) {
		List<Uri> data = getAdapter().getData();
		if (data.size() > 0) {
			ArrayList<String> value = new ArrayList<String>();
			for (Uri uri : data) {
				value.add(uri.toString());
			}
			outState.putStringArrayList(EXTRA_LIST_DATA, value);
		}
		if (session != null) outState.putString(EXTRA_SESSION, session.toJson());
		super.onSaveInstanceState(outState);
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
		ArrayList<String> value = savedInstanceState.getStringArrayList(EXTRA_LIST_DATA);
		if (value != null && value.size() > 0) {
			List<Uri> data = new ArrayList<Uri>();
			for (String s : value) {
				data.add(Uri.parse(s));
			}
			getAdapter().setDataSource(data);
		}
		String json = savedInstanceState.getString(EXTRA_SESSION);
		if (json != null) session = Session.fromJsonWithAllFields(json, Session.class);
	}

###13、简化ListView及同类组件数据更新的套件 AbsListViewActivityAbsListViewFragmentAbsAdapter 示例:

@ViewLayoutId(R.layout.m_edit)
@ViewListId(R.id.m_edit_grid_view)
public class EditActy extends AbsListViewActivity<GridView, EditBean, EditGridAdapter> {
    private static final String EXTRA_CATEGORY_ID		= EditActy.class.getName() + ".EXTRA_CATEGORY_ID";

	public static void startMe(Context context, long categoryId) {
		Intent intent = new Intent(context, EditActy.class);
		intent.putExtra(EXTRA_CATEGORY_ID, categoryId);
		startMe(context, intent);
	}

	@ViewId(R.id.m_edit_title_left_btn_back)
	private ImageButton mBtnBack;
	@ViewId(R.id.m_edit_magic_board)
	private MagicBoardView mMagicBoard;

	@Override
	protected EditGridAdapter newAdapter() {
		return new EditGridAdapter(this, mOnFavoriteClick);
	}
    //...
}

###14、图像工具 BitmapUtils

###15、AndroidManifest.xml属性读取工具 Manifest

###16、对话框、弹窗和进度条 DialogHelper、Prompt 和 PromptProgress

  • UI和动画都可全局定制;
  • DialogHelper可弹出在桌面上。

###17、文本超链接点击效果 LinkMovementMethod、LinkSpan

###18、具有退出监听能力的 AbsApp


public class App extends AbsApp {
    @Override
	protected boolean onExit() {
		L.i(this, "程序正常退出------App.onExit()");
		//...
		super.onExit();
		if (mExitForRestart) {
			WelcomeActy.startMe(this);
			mExitForRestart = false;
		}
		return false;
	}
    //...
}

###19、非对称密钥对生成工具 RsaUtils

  • 可生成iOS项目能识别的公钥密钥文件(iOS要求比较苛刻,而java的库对密钥文件的识别能力较强)。

###20、时间工具 TimeUtils

  • 可解析C#生成的Java标准APISimpleDateFormat无法识别的格式化字符串如2013-05-22T09:16:44.871589GMT+08002013-05-22T09:16:44.871589+08:00
  • 可根据生日计算年龄;
  • 可生成无时区的时间长度表示,并定制单位,如:3天前,1周前,2年6个月前等;
  • 可根据系统时间返回凌晨、上午、中午、下午、晚上、晚休等信息。

###21、Log的简化版 L

  • 可用类名.class作为TAG;
  • 可根据Debug.DEBUG决定是否输出log日志信息,上线的版本可设置Debug.DEBUG = false来禁止所有的日志输出。

###22、全局异常拦截器 CrashHandler

  • 可dump运行时内存到存储卡(.hprof文件)用于内存分析;
  • 可拦截某线程的某异常或所有异常;
  • 可拦截所有线程的某异常或所有异常;
  • 拦截后的处理方式应该根据业务需要自定义处理,默认是作闪退处理。

###23、混淆 proguard-project.txt


#保持所有的R类,防止有很多需要通过资源名称取得id的情况
-keep class **.R$*{*;}

-keepattributes Signature
-keep class com.google.gson.stream.**{*;}

#上面已经有了-keepattributes Signature保持泛型,这里只保持构造方法
-keepclassmembers class * extends **.ViewHolder{
	<init>(android.view.View);
}
-keep class * extends com.wei.c.data.abs.**{*;}
#有些类虽然不是继承自**.data.abs.**,但是仍然需要被gson反序列化,
#如:一些被继承自**.data.abs.**的类作为变量的类,
#因此需要keep变量
-keepclassmembers class **.data.**{
	<fields>;
}
#在**.data.**包里面有匿名的TypeToken的子类,下面的方法都是无法keep的,因为匿名类并没有显式的使用extends关键字
#-keep class **.TypeToken{*;}
#-keep class * extends **.TypeToken{*;}
#TypeToken的匿名子类会以这种形式显示:如**.data.api.Login$1
-keep class **.data.**.*$*{*;}

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2014 Wei Chou Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

Android快速开发框架,Android常用工具集 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/farmer1002/Wei.Lib2A.git
git@gitee.com:farmer1002/Wei.Lib2A.git
farmer1002
Wei.Lib2A
Wei.Lib2A
master

搜索帮助