Giter VIP home page Giter VIP logo

lxlpp123 / kjframeforandroid Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kymjs/kjframeforandroid

0.0 1.0 0.0 26.94 MB

KJFrameForAndroid 又叫KJLibrary,是一个帮助快速开发的框架。使用KJFrameForAndroid,你可以只用一行代码就完成http请求、网络图片加载、数据库数据保存或读取。

License: Apache License 2.0

Java 86.87% JavaScript 0.20% CSS 12.93%

kjframeforandroid's Introduction

logo

================= #KJFrameForAndroid Summary Android Arsenal BlackDuck OpenHUB OSChina

What is KJFrameForAndroid

KJFrameForAndroid is also called KJLibrary. It's an Android ORM and IOC framework and includes UILibrary, PluginLibrary, 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. Thanks for you follow this KJFrameForAndroid.

KJFrameForAndroid links

Integrating KJFrameForAndroid to your project

Create /binrary/kjlibrary.jar and include as jar dependency to your project.
Include the KJFrameForAndroid project as Library Dependency in your project.
make use of KJFrameForAndroid works on Android 3.0 or higher and need permission in your AndroidManifest.xml

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

PluginLibrary

Did you really try? execute not installed apk file, PluginLibrary can I help you.
you can download pluginDemo project integrating example project learn KJFrameForAndroid.Detail

UILibrary

UILibrary -> Widget function import in common use widget,for example, can pull 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.kjframe.KJActivity(KJFragment) for your Activity(Fragment).

		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("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
initDataFromThread();(asynchronous,can do time consuming)
threadDataInited();(initDataFromThread() executed just call back)
initData();
initWidget();
registerBroadcast();

BitmapLibrary

Can whichever View set image(for ImageView set src;other 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, "file:///storage/sdcard0/1.jpg"); 
	// internet url
	kjb.display(textView, http://www.xxx.com/xxx.jpg); 
	//自定义图片显示大小
	kjb.display(view, http://www.xxx.com/xxx.jpg, 80, 80); //width=80,height=80

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

		// get
		kjh.get("http://www.oschina.net/", new HttpCallBack();//like post, so just one example
		
		// 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("before start");
            }
            @Override
            public void onSuccess(String t) {
                super.onSuccess(t);
                ViewInject.longToast("request success");
                KJLoger.debug("log:" + t.toString());
            }
            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                super.onFailure(t, errorNo, strMsg);
                KJLoger.debug("exception:" + strMsg);
            }
            @Override
            public void onFinish() {
                super.onFinish();
                KJLoger.debug("request finish. Regardless of success or failure.");
            }
        });

post upload file parameter

	// on server example
	<?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();
        //support more file
        params.put("file", FileUtils.getSaveFile("KJLibrary", "logo.jpg"));
		params.put("file1", new File("/path/xxx/xxx")); // support
		params.put("file2", new FileInputStream(file)); // support
        kjh.post("http://192.168.1.149/kymjs/hello.php", params,
                new HttpCallBack() {
                    @Override
                    public void onSuccess(String t) {
                        super.onSuccess(t);
                        ViewInject.toast("success");
                    }

                    @Override
                    public void onFailure(Throwable t, int errorNo,
                            String strMsg) {
                        super.onFailure(t, errorNo, strMsg);
                        ViewInject.toast("error" + strMsg);
                    }
					/** more method... **/
                });
    }
		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("toast");
                mProgress.setProgress(mProgress.getMax());
            }

            @Override
            public void onFailure(Throwable t, int errorNo,String strMsg) {
                super.onFailure(t, errorNo, strMsg);
                KJLoger.debug("onFailure");
            }

            /* onLoading just in download method effective,1 second 1 call */
            @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

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 finaldb object. Thinks.finaldb

	// data file
	KJDB db = KJDB.create(this);
	User ugc = new User(); //warn: The ugc must have id field or @ID annotate
	ugc.setEmail("[email protected]");
	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();
			}

##License

 Copyright (c) 2014,The KJFrameForAndroid Open Source Project.
 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.

About Me

I am kymjs, From ShenZhen China.
blog:http://my.oschina.net/kymjs/blog
email:[email protected]
QQ: 766136833
If my project help you, Can you buy a bottle of beer for me?
my account is: [email protected] click there one's voluntary contribution
如果我的项目帮助了你,希望你有能力的基础上能捐助我买书学习,以让我更有信心和能力回馈网友。 我的支付宝账号:[email protected]点这里参与我的众筹

kjframeforandroid's People

Contributors

kymjs avatar erhu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.