1 Star 0 Fork 183

tianxia007 / KJFrameForAndroid

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

logo KJFrameForAndroid简介

================= Android Arsenal BlackDuck OpenHUB OSChina
KJFrameForAndroid 又叫KJLibrary,是一个Android的快速开发工具包。同时封装了android中的Bitmap、Http、插件模块加载操作的框架,使开发者更容易轻松实现这些功能;
KJFrameForAndroid的设计思想是通过封装Android原生SDK中复杂的复杂操作而达到简化Android应用级开发,最终实现快速而又安全高效的开发APP。我们的目标是用最少的代码,完成最多的操作,用最高的效率,完成最复杂的功能。

KJFrameForAndroid 相关链接


框架使用

Demo工程运行下载框架最新源码。 ②选择KJLibraryExample工程导入Eclipse。 ③将/binrary目录KJFrameForAndroid_Vxxx.jar包复制至demo的libs目录。 ④删除project.properties文件的最后一行
在项目中使用 :将/binrary目录最新jar包KJFrameForAndroid_xxx.jar添加到你工程/libs目录中并引用。

  • 由于使用了SDK最新的API函数,以及3.0版Fragment。KJFrameForAndroid框架最低支持API 11。
    注:使用 KJFrameForAndroid 应用开发框架需要在你项目的AndroidManifest.xml文件中加入以下基本权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

=======各模块使用介绍=======

Plugin模块

使用Plugin模块可以让你的插件apk不用安装便直接被运行,极大的方便了APP动态更新,且可以轻松实现插件与APP项目之间的解耦。
你可以在这里获取项目示例中插件的Demo apk与源码。更多介绍请看Plugin模块详细介绍
现支持以下功能

  • apk无需安装即可被应用调用
  • Activity的动态加载:包括生命周期和交互事件、R文件资源引用、插件与APP之间的数据通信
  • Fragment的完美加载使用
  • 动态注册的BroadcastReceiver
  • 绑定式、启动式Service均可完美使用
  • 已成功模拟出launchMode的效果。(launchModer实际上是一个虚拟的,生命周期的调用还是一样的,仅仅模拟出了系统的BackStack)
  • 完美集成了KJFrameForAndroid中UiLibrary->Topology的全部功能,支持注解式绑定控件设置监听

UILibrary模块

UILibrary包含两个部分Widget(控件)、Topology(Android框架结构继承链) 详细介绍...

UILibrary -> Widget控件部分 主要封装了常用的UI控件,为了不让项目jar包过大,我们只引入了开发中一定会用到的控件,例如:可上下拉的KJScrollView、圆形显示的ImageView,可以双指缩放双击缩放双指旋转的ScaleImageView、等等......更多内容请自行查看项目文件中org.kymjs.kjframe.widget包下的内容

UILibrary -> Topology拓扑部分 规范了Activity中数据及控件的初始化,并包含一个使用IOC设计思想的控件初始化方式:可通过注解的方式进行UI绑定,与设置监听,在Activity和Fragment中均可以通过一行代码绑定控件并实现点击监听;同时UILibrary为开发者定义了完善的KJActivity和KJFragment等基类,开发者只需手动继承就可以获得Topology部分的全部功能。

public class TabExample extends KJActivity {
    @BindView(id = R.id.bottombar_content1, click = true)
    public RadioButton mRbtn1;
    @BindView(id = R.id.bottombar_content2, click = true)
    private RadioButton mRbtn2;

    @Override
    public void setRootView() {
        setContentView(R.layout.aty_tab_example);
    }
    
    @Override
    protected void initWidget() {
        super.initWidget();
        mRbtn1.setText("控件已经初始化绑定并设置了监听");
    }

    @Override
    public void widgetClick(View v) {
        super.widgetClick(v);
        switch (v.getId()) {
        case R.id.bottombar_content1:
        ViewInject.toast("点击了mRbtn1");
            break;
        case R.id.bottombar_content2:
        ViewInject.toast("点击了mRbtn2");
            break;
        }
    }
}

###Topology中各函数调用顺序: setRootView();
@BindView
initDataFromThread();(异步调用,可做耗时操作)
threadDataInited();(initDataFromThread执行完成后才会回调)
initData();
initWidget();
registerBroadcast();

BitmapLibrary模块

任何View(ImageView设置src,普通View设置bg)加载图片的时候都无需考虑图片加载过程中出现的oom和android容器快速滑动时候出现的图片错位等现象,同时无需考虑图片加载过程中出现的OOM。默认使用内存lru算法+磁盘lru算法缓存图片 详细介绍
**注:**在Android2.3之前,我们常常使用软引用或弱引用的形式去做缓存图片,然而根据Google的描述:垃圾回收器会更倾向于回收持有软引用或弱引用的对象,这让软引用和弱引用变得不再可靠。另外,Android 3.0 (API Level 11)中,图片的数据会存储在本地的内存当中,因而无法用一种可预见的方式将其释放,这就有潜在的风险造成应用程序的内存溢出并崩溃。BitmapLibrary使用lru算法去管理缓存,同时内存缓存配合磁盘缓存能更有效的管理缓存调用。

KJBitmap kjb = KJBitmap.create();
/**
 * url不仅支持网络图片显示,同时支持本地SD卡上的图片显示;
 * view不仅可以是imageview,同时普通view也可以传入,框架会自动识别对imageview设置src对普通view设置bg
 */
// 载入本地图片
kjb.display(imageView, "file:///storage/sdcard0/1.jpg"); 
// 载入网络图片
kjb.display(textView, http://www.xxx.com/xxx.jpg); 
//自定义图片显示大小
kjb.display(view, http://www.xxx.com/xxx.jpg, 80, 80); //如不指定图片大小,默认采用控件大小显示图片

HttpLibrary模块

KJLibrary默认对所有Http通信的数据做了缓存处理,缓存时间为5分钟。这么做的目的不仅是为了节省用户手机流量,同时是为了减少服务器压力
HttpLibrary模块使用HttpUrlConnection实现方式实现网络通信、数据上传,使用HttpClient实现文件的断点下载。根据Google建议:在2.3系统之前由于HttpUrlConnection不稳定且有一定的BUG,应该尽量使用HttpClient;在2.3以后的系统,若只是简单的数据交互,应该使用更加轻量级、易扩展的HttpUrlConnection。

###普通get、post方法示例:

    	kjh.get("http://www.oschina.net/", new HttpCallBack();//与post相似,就只写一种了
		
		KJHttp kjh = new KJHttp();
		HttpParams params = new HttpParams();
        params.put("id", "1");
        params.put("name", "kymjs");
		kjh.post("http://192.168.1.149/post.php", params, new HttpCallBack() {
            @Override
            public void onPreStart() {
                super.onPreStart();
                KJLoger.debug("即将开始http请求");
            }
            @Override
            public void onSuccess(String t) {
                super.onSuccess(t);
                ViewInject.longToast("请求成功");
                KJLoger.debug("请求成功:" + t.toString());
            }
            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                super.onFailure(t, errorNo, strMsg);
                KJLoger.debug("出现异常:" + strMsg);
            }
            @Override
            public void onFinish() {
                super.onFinish();
                KJLoger.debug("请求完成,不管成功还是失败");
            }
        });

###post上传文件方法示例:

// 文件上传的PHP后台实现示例
<?php
    if ($_FILES["file"]["error"] > 0)
    {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
    else
    {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    
		if (file_exists("upload/" . $_FILES["file"]["name"]))
        {
            echo $_FILES["file"]["name"] . " already exists. ";
        }
        else
        {
            move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
            echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
        }
    }
?>
	private void upload() {
       HttpParams params = new HttpParams();
		//支持一次传递多个文件,这里使用UtilsLibrary中的工具类获取一个文件
        params.put("file", FileUtils.getSaveFile("KJLibrary", "logo.jpg"));
        kjh.post("http://192.168.1.149/kymjs/hello.php", params,
                new HttpCallBack() {
                    @Override
                    public void onSuccess(String t) {
                        super.onSuccess(t);
                        ViewInject.toast("文件上传完成");
                    }

                    @Override
                    public void onFailure(Throwable t, int errorNo,
                            String strMsg) {
                        super.onFailure(t, errorNo, strMsg);
                        ViewInject.toast("文件上传失败" + strMsg);
                    }
                });
    }

###断点下载方法示例:

	kjh.download(mEtDownloadPath.getText().toString(), FileUtils.getSaveFile("KJLibrary", "l.pdf"),
            new HttpCallBack() {
                @Override
                public void onSuccess(File f) {
                    super.onSuccess(f);
                    KJLoger.debug("success");
                    ViewInject.toast("下载成功");
                    mProgress.setProgress(mProgress.getMax());
                }
				
                @Override
                public void onFailure(Throwable t, int errorNo,
                        String strMsg) {
                    super.onFailure(t, errorNo, strMsg);
                    KJLoger.debug("onFailure");
                }
					
				/* onLoading方法只在下载方法中有效,且每秒回调一次 */
                @Override
                public void onLoading(long count, long current) {
                    super.onLoading(count, current);
                    mProgress.setMax((int) count);
                    mProgress.setProgress((int) current);
                    KJLoger.debug(count + "------" + current);
                }
            });

DBLibrary模块

包含了android中的orm框架,一行代码就可以进行增删改查。支持一对多,多对一等查询。
DB模块,很大程度上参考了finalDB的设计,并在此基础上完善了几乎全部的API注释,与更多可定制的DB操作

	//普通数据存储
	KJDB db = KJDB.create(this);
	User ugc = new User(); //这里需要注意的是User对象必须有id属性,或者有通过@ID注解的属性
	ugc.setEmail("kymjs123@gmail.com");
	ugc.setName("kymjs");
	db.save(ugc);
	//一对多数据存储
	public class Parent{  //JavaBean
		private int id;
		@OneToMany(manyColumn = "parentId")
		private OneToManyLazyLoader<Parent ,Child> children;
		/*....*/
	}
	public class Child{ //JavaBean
		private int id;
		private String text;
		@ManyToOne(column = "parentId")
		private  Parent  parent;
		/*....*/
	}
	List<Parent> all = db.findAll(Parent.class);
		for( Parent  item : all){
			if(item.getChildren ().getList().size()>0)
				ViewInject.toast(item.getText() + item.getChildren().getList().get(0).getText());
		}

帮助我

我是张涛,中国深圳,Android高级工程师
如果我的项目帮到了你,可否在你有能力的基础捐助我买书学习,以让我更有信心和能力回馈网友。
点这里参与我的众筹 我的支付宝账号kymjs@foxmail.com
书本计划清单:
项目经理应该知道的97件事》 ¥39
简约至上:交互式设计四策略》 ¥21
参与感:小米口碑营销内部手册》 ¥42
格拉德威尔经典系列》 ¥132

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: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) 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 (d) 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 {yyyy} {name of copyright owner} 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.

简介

KJFrameForAndroid的设计思想是通过封装Android原生SDK中复杂的复杂操作而达到简化Android应用级开发,最终实现快速而又安全高效的开发APP。我们的目标是用最少的代码,完成最多的操作,用最高的效率,完成最复杂的功能。 展开 收起
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/dwxdfhx/KJFrameForAndroid.git
git@gitee.com:dwxdfhx/KJFrameForAndroid.git
dwxdfhx
KJFrameForAndroid
KJFrameForAndroid
master

搜索帮助