Skip to content
kymjs edited this page Aug 21, 2014 · 15 revisions

What KJFrameForAndroid?

explain: thinks for you follow this framework.I'll a little bit of English.So,hope you can understand my translation.You can tell me letter for kymjs123@gmail.com,thinks


KJFrameForAndroid is also called KJLibrary. It's an Android ORM and IOC framework and includes UILibrary, UtilsLibrary, HttpLibrary, BitmapLibrary, DBLibrary. KJFrameForAndroid is designed to wrap complexity of the Android native SDK and keep things simple. However,KJFrameForAndroid is free open source object.

Integrating KJFrameForAndroid to your project

You can include in two ways

Create /binrary/kjlibrary.jar and include as jar dependency to your project.
Include the KJFrameForAndroid project as Library Dependency in your project.
warn make use of KJFrameForAndroid need permission in your AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

*And if your project make use of utilsLibrary function,you may need to more than permission.

UILibrary

UILibrary -> Widget function import in common use widget,for example, can pull's ListView/ScrollView; can double click zoom's ImageView.
UILibrary -> Topology function import a Activity inheritance link.Get topology all function, you can extends org.kymjs.aframe.ui.activity.BaseActivity for your Activity, or extends org.kymjs.aframe.ui.fragment.BaseFragment for your Fragment. example:

public class TabExample extends BaseActivity {
    @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("widget clicked listener");
    }

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

in topology method called queue:
*setRootView();
*@BindView
*initDataWithThread();(asynchronous,called in thread)
*initData();
*initWidget();
*registerBroadcast();

BitmapLibrary

Can whichever View set image(for ImageView set src;for View set background).
Loading bitmap,never out of memory exception.
defualt make use of memory least recently used + disk least recently used cache image.
before in android 2.3, we used to SoftReference or WeakReference to cache image. However,on the basis of Google represent, System.gc() more likely recovery to SoftReference or WeakReference.And into android 3.0,image data for cache in memory,will difficult recovery, have possible crash. BitmapLibrary make use of lru algorithm manager cache called

KJBitmap kjb = KJBitmap.create();
/**
 * url can be local sdcard path or internet url;
 * view can whichever View set image(for ImageView set src;for View set background).
 */
// local sdcard image
kjb.display(imageView, "/storage/sdcard0/1.jpg",80,80); //width,height(unimportant,optional)
// internet url
kjb.display(textView, "http://www.eoeandroid.com/data/attachment/forum/201107/18/142935bbi8d3zpf3d0dd7z.jpg");

HttpLibrary

Android has provided two HTTP Clients AndroidHttpClient (Extended from apache HTTPClient) and HttpUrlConnection to make a HTTP Request. You can select which Http client.

get method request JSON example

// 使用HttpClient
KJHttp kjh = new KJHttp();
kjh.get(String url,I_HttpParams params, HttpCallback callback);

// 使用HttpUrlConnection
KJHttp kjh = new KJHttp();
kjh.urlGet("http://my.oschina.net/kymjs/blog", new StringRespond(){

	@Override
	public void success(String t) {
			ViewInject.toast("display JSON information " + t);
	}

	@Override
	public void failure(Throwable t, int errorNo, String strMsg) {
		ViewInject.toast("net error");
	}
});

post request JSON example

// 使用HttpClient
KJHttp kjh = new KJHttp();
kjh.post(String url,I_HttpParams params, HttpCallback callback);

// 使用HttpUrlConnection
KJHttp kjh = new KJHttp();
KJStringParams params = new KJStringParams();
params.put("user_id", "33");
params.put("birthday", "2008-8-1");
kjh.urlPost("http://my.oschina.net/kymjs/blog", params, new StringRespond(){
	@Override
	public void success(String t) {
			ViewInject.toast("display JSON information :" + t);
	}

	@Override
	public void failure(Throwable t, int errorNo, String strMsg) {
		ViewInject.toast("net error");
	}
});

post upload file parameter

// 使用HttpClient
kjh.post(String url,I_HttpParams params, HttpCallback callback);

// 使用HttpUrlConnection
KJHttp kjh = new KJHttp();
KJFileParams params = new KJFileParams();
params.put("user_id", "33");
params.put(new File("/storage/sdcard0/1.jpg"));//File object parameter
params.put(inputstream);//or FileInputstream parameter
params.put(byteArray);//or file's byte[] parameter
//three of one or two or all
kjh.urlPost("http://my.oschina.net/kymjs/blog", params, new StringRespond(){

	@Override
	public void success(String t) {
			ViewInject.toast("显示JSON信息:" + t);
	}

	@Override
	public void failure(Throwable t, int errorNo, String strMsg) {
		ViewInject.toast("网络加载失败,请检查您的网络");
	}
});

Multipart thread download example

KJHttp kjh = new KJHttp();
FileCallBack file = new FileCallBack() {
    @Override
    public void onSuccess(File f) {
        ViewInject.toast("download success");
    }
    @Override
    public void onLoading(long count, long current) {
        super.onLoading(count, current);
        if (!maxed) {
            mProgress.setMax((int) count);
            maxed = true;
        }
        mProgress.setProgress((int) current);
    }
    @Override
    public void onFailure(Throwable t, int errorNo, String strMsg) {
        super.onFailure(t, errorNo, strMsg);
        ViewInject.toast("error information" + strMsg);
    }
};
file.setProgress(true); // if your called onLoading(long,long),must set be true
kjh.urlDownload(mEt.getText().toString(), "/storage/sdcard0/3.png",file);

DBLibrary

in android orm framework. Make use of sqlite handle. one line just to add/delete/update/query. holder one-more,more-one entity
About DataBase function,comes frome to afinal object. Thinks.[https://github.com/kymjs/afinal]

// data file
KJDB db = KJDB.create(this);
User ugc = new User(); //warn: The ugc must have id field or @ID annotate
ugc.setEmail("kymjs123@gmail.com");
ugc.setName("kymjs");
db.save(ugc);
//one - many
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)
                Toast.makeText(this,item.getText() + item.getChildren().getList().get(0).getText(),Toast.LENGTH_LONG).show();
        }

UtilsLibrary

you can see package org.kymjs.aframe.utils 包含了应用开发中的常用工具类,例如系统级别的Log管理、网络状态监测、Bitmap压缩工具类、获取屏幕宽高以及单位转换的工具类、错误信息处理与文件处理工具类、preference工具类、字符串操作与常用正则判断等。详细内容请自行查看项目文件中org.kymjs.aframe.utils包下的内容更多介绍...

##License

 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.
Clone this wiki locally