repositories {
flatDir {
dir 'libs' //注意:需要提前在app module中创建出libs文件夹
}
}
compile 'com.squareup.okhttp3:okhttp:3.3.1' compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0' compile (name: 'simplecommand', ext: 'aar')
package com.danny_mcoy.commandlibdemo;
import android.content.Context;
import android.net.Uri;
import android.os.Parcel;
import com.danny_mcoy.simplecommad.cmd.network.NetworkCommand;
import com.danny_mcoy.simplecommad.log.Logger;
import com.squareup.okhttp.Request;
/**
* Created by Danny_姜新星 on 3/8/2017.
*/
public class HumourCommand extends NetworkCommand {
@Override
protected String buildUrl(Context context) {
Uri.Builder builder = Uri.parse("http://api.laifudao.com")
.buildUpon();
builder.appendEncodedPath("open/xiaohua.json");
Logger.e("JIANG", "url is " + builder.toString());
return builder.toString();
}
@Override
protected Request getRequest(String url) {
return new Request.Builder()
.url(url)
.build();
}
public static final Creator<HumourCommand> CREATOR = new Creator<HumourCommand>() {
@Override
public HumourCommand createFromParcel(Parcel source) {
return new HumourCommand();
}
@Override
public HumourCommand[] newArray(int size) {
return new HumourCommand[size];
}
};
}
package com.danny_mcoy.commandlibdemo;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.danny_mcoy.simplecommad.extra.Params;
import com.danny_mcoy.simplecommad.log.Logger;
import com.danny_mcoy.simplecommad.receiver.AppResultReceiver;
public class MainActivity extends AppCompatActivity implements AppResultReceiver.ResultListener {
private TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = ((TextView) findViewById(R.id.text_Main));
}
public void btnClick(View view) {
HumourCommand apiCommand = new HumourCommand();
AppResultReceiver receiver = new AppResultReceiver(new Handler(), this);
apiCommand.start(this, receiver);
}
@Override
public void onResultSuccess(Bundle resultData) {
if (null != resultData) {
String body = resultData.getString(Params.CommandMessage.EXTRA_BODY);
Logger.e("JIANG", " body is " + body);
textView.setText(body);
}
}
@Override
public void onResultFailed(Bundle resultData) {
Logger.e("JIANG", " failed");
}
@Override
public void onResultProgress(Bundle resultData) {
Logger.e("JIANG", " progress");
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有