Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
youth5201314 committed Sep 4, 2017
1 parent fdd633d commit 0ba34f5
Show file tree
Hide file tree
Showing 32 changed files with 456 additions and 143 deletions.
16 changes: 14 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
Gradle
```groovy
dependencies{
compile 'com.youth.xframe:xframe:1.1.0'
compile 'com.youth.xframe:xframe:1.1.2'
}
```
或者引用本地lib
Expand All @@ -62,8 +62,20 @@ compile project(':xframe')

## 更新说明

#### v1.1.2
XFrame 优化更新
* XImage支持使用第三方框架来配置加载不同形状图片
* XRecyclerViewAdapter修改数据操作中移动,交换,删除,替换等列表更新bug
* XToast解决重复创建显示问题
* 修改优化了一些bug

#### v1.1.1
XFrame 优化更新
* 增加XImage第三方图片加载框架隔离框架
* 修改优化了一些bug

#### v1.1.0
banner 优化更新
XFrame 优化更新
* 增加Http网络隔离框架
* 修改优化了一些bug

Expand Down
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ android {
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':xframe')
compile 'com.android.support:design:25.3.1'
compile 'com.youth.banner:banner:+'
compile 'com.android.support:design:+'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'cat.ereza:customactivityoncrash:1.5.0'

Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/youth/xf/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.youth.xf.http.AsyncHttpEngine;
import com.youth.xf.http.OKHttpEngine;
import com.youth.xf.loder.GlideImageLoader;
import com.youth.xframe.base.XApplication;
import com.youth.xframe.XFrame;

Expand All @@ -13,7 +14,9 @@ public void onCreate() {
super.onCreate();
CustomActivityOnCrash.install(this);

//初始化日志
XFrame.initXLog();
//初始化多状态界面View
XFrame.initXLoadingView()
.setErrorViewResId(R.layout._loading_layout_error);

Expand All @@ -23,5 +26,11 @@ public void onCreate() {
AsyncHttpEngine、OKHttpEngine、VolleyHttpEngine
*/
XFrame.initXHttp(new AsyncHttpEngine());

/**
* 初始化全局图片加载框架
* GlideImageLoader为你的图片加载框架实现类
*/
XFrame.initXImageLoader(new GlideImageLoader(getApplicationContext()));
}
}
76 changes: 64 additions & 12 deletions app/src/main/java/com/youth/xf/http/OKHttpEngine.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,56 @@
package com.youth.xf.http;

import android.os.Environment;

import com.alibaba.fastjson.JSON;
import com.youth.xframe.XFrame;
import com.youth.xframe.utils.http.HttpCallBack;
import com.youth.xframe.utils.http.IHttpEngine;
import com.youth.xframe.utils.http.XHttp;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import okhttp3.Cache;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

import static okhttp3.internal.Util.EMPTY_REQUEST;

/**
* OKHttp简单实现,你可修改,这只是案例
*
*/
public class OKHttpEngine implements IHttpEngine {

private OkHttpClient client = null;
private int cacheSize = 10 * 1024 * 1024;

public OKHttpEngine() {
client = new OkHttpClient();
client = new OkHttpClient().newBuilder()
.retryOnConnectionFailure(true)
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.cache(new Cache(XFrame.getContext().getCacheDir(), cacheSize))
.build();
}

@Override
public void get(String url, Map<String, Object> params, final HttpCallBack callBack) {
final Request request = new Request.Builder().url(url).build();
Request request = new Request.Builder().url(url+getUrlParamsByMap(params)).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Expand All @@ -44,7 +65,7 @@ public void onResponse(Call call, final Response response) throws IOException {
@Override
public void run() {
//我这里使用的是fastjson,你也可以用gson,jackjson等
callBack.onSuccess(JSON.parseObject(result,XHttp.analysisClassInfo(callBack)));
callBack.onSuccess(JSON.parseObject(result, XHttp.analysisClassInfo(callBack)));
}
});
} else {
Expand All @@ -62,17 +83,35 @@ public void run() {

@Override
public void post(String url, Map<String, Object> params, final HttpCallBack callBack) {
FormBody.Builder body = new FormBody.Builder();
if(null!=params) {
for (String key:params.keySet()) {
body.add(key, (String) params.get(key));
RequestBody body = EMPTY_REQUEST;
if (null != params&&!params.isEmpty()) {
MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
for (String key : params.keySet()) {
Object value = params.get(key);
if (value instanceof File) {
File file = (File) value;
builder.addFormDataPart(key, file.getName(),
RequestBody.create(MediaType.parse("image/png"), file));//"application/octet-stream"
}
if (value instanceof ArrayList) {
ArrayList<Object> lists = (ArrayList) value;
for (Object obj : lists) {
if (obj instanceof File) {
File file = (File) obj;
builder.addFormDataPart(key, file.getName(),
RequestBody.create(MediaType.parse("image/png"), file));
}
}
} else {
builder.addFormDataPart(key, value.toString());
}
}
body = builder.build();
}

OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.post(body.build())
.post(body)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
Expand All @@ -88,7 +127,7 @@ public void onResponse(Call call, final Response response) throws IOException {
@Override
public void run() {
//我这里使用的是fastjson,你也可以用gson,jackjson等
callBack.onSuccess(JSON.parseObject(result,XHttp.analysisClassInfo(callBack)));
callBack.onSuccess(JSON.parseObject(result, XHttp.analysisClassInfo(callBack)));
}
});
} else {
Expand All @@ -99,9 +138,22 @@ public void run() {
}
});
}

}
});
}

private String getUrlParamsByMap(Map<String, Object> map) {
if (map == null||map.isEmpty()) {
return "";
}
StringBuffer params = new StringBuffer("?");
for (Map.Entry<String, Object> entry : map.entrySet()) {
params.append(entry.getKey());
params.append("=");
params.append(entry.getValue());
params.append("&");
}
String str=params.toString();
return str.substring(0,str.length()-1);
}
}
41 changes: 35 additions & 6 deletions app/src/main/java/com/youth/xf/loder/GlideImageLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,46 @@
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.youth.banner.loader.ImageLoader;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.youth.xf.view.GlideCircleTransform;
import com.youth.xframe.XFrame;
import com.youth.xframe.utils.imageload.ImageLoader;


public class GlideImageLoader extends ImageLoader {
public class GlideImageLoader implements ImageLoader {

private Context mContext;

public static GlideCircleTransform circleTransform;

public GlideImageLoader(Context context) {
this.mContext=context;
circleTransform=new GlideCircleTransform(mContext);
}

@Override
public void load(ImageView imageView, Object imageUrl) {
Glide.with(mContext)
.load(imageUrl)
.crossFade()
.into(imageView);
}

@Override
public void load(ImageView imageView, Object imageUrl, int defaultImage) {
Glide.with(mContext)
.load(imageUrl)
.crossFade()
.placeholder(defaultImage)
.into(imageView);
}

@Override
public void displayImage(Context context, Object path, ImageView imageView) {
//具体方法内容自己去选择,次方法是为了减少banner过多的依赖第三方包,所以将这个权限开放给使用者去选择
Glide.with(XFrame.getContext())
.load(path)
public void load(ImageView imageView, Object imageUrl, Object transformation) {
Glide.with(mContext)
.load(imageUrl)
.crossFade()
.transform((BitmapTransformation) transformation)
.into(imageView);
}
}
7 changes: 3 additions & 4 deletions app/src/main/java/com/youth/xf/ui/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

import com.youth.banner.Banner;
import com.youth.xf.BaseActivity;
import com.youth.xf.R;
import com.youth.xf.ui.adapter.MyFragmentPagerAdapter;
import com.youth.xframe.XFrame;
import com.youth.xframe.utils.log.XLog;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -35,6 +34,7 @@ public void initData(Bundle savedInstanceState) {
fragments=new ArrayList<>();
fragments.add(new DemoFragment());
fragments.add(new APIFragment());

}

@Override
Expand All @@ -45,7 +45,6 @@ public void initView() {
tabLayout.addTab(tabLayout.newTab().setText(titles[1]));
viewPager.setAdapter(new MyFragmentPagerAdapter(getSupportFragmentManager(),fragments,titles));
tabLayout.setupWithViewPager(viewPager);

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/com/youth/xf/ui/demo/XHttpActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
import com.youth.xf.data.Weather;
import com.youth.xframe.utils.http.HttpCallBack;
import com.youth.xframe.utils.http.XHttp;
import com.youth.xframe.utils.log.XLog;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class XHttpActivity extends BaseActivity {

Expand All @@ -38,10 +38,8 @@ public void onClick(View view) {
request();
}

/**
*
*/
public void request() {

//这里是公用接口,没有办法演示传参,谅解
String url = "http://wthrcdn.etouch.cn/weather_mini?citykey=101010100";
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.youth.xf.BaseActivity;
import com.youth.xf.R;
import com.youth.xframe.widget.XLoadingDialog;
import com.youth.xframe.widget.XToast;

public class XLoadingDialogActivity extends BaseActivity {
private Handler handler=new Handler(){
Expand Down Expand Up @@ -42,7 +43,7 @@ public void show(View view) {
XLoadingDialog.with(this).show();
break;
case R.id.loading2:
Toast.makeText(this,"3秒后自动取消",Toast.LENGTH_SHORT).show();
XToast.info("3秒后自动取消");
XLoadingDialog.with(this)
.setBackgroundColor(Color.parseColor("#aa000000"))
.setMessageColor(Color.WHITE)
Expand All @@ -52,18 +53,20 @@ public void show(View view) {
break;
case R.id.loading3:
XLoadingDialog.with(this)
.setOrientation(XLoadingDialog.HORIZONTAL)
.setMessage("我正在加载中...")
.setOrientation(XLoadingDialog.VERTICAL)
.setMessage("加载中...")
.show();
break;
case R.id.loading4:
XToast.info("3秒后自动取消");
XLoadingDialog.with(this)
.setCanceled(false)
.setOrientation(XLoadingDialog.HORIZONTAL)
.setOrientation(XLoadingDialog.VERTICAL)
.setBackgroundColor(Color.parseColor("#aa000000"))
.setMessageColor(Color.WHITE)
.setMessage("我正在加载中...")
.setMessage("加载中...")
.show();
handler.sendEmptyMessageDelayed(1,3000);
break;
}

Expand Down
Loading

0 comments on commit 0ba34f5

Please sign in to comment.