forked from jeasonlzy/okhttp-OkGo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
152 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
app/src/main/java/com/lzy/okhttpdemo/okhttputils/TestActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.lzy.okhttpdemo.okhttputils; | ||
|
||
import android.os.Bundle; | ||
import android.view.View; | ||
import android.widget.EditText; | ||
import android.widget.ImageView; | ||
|
||
import com.lzy.okhttpdemo.R; | ||
import com.lzy.okhttpdemo.base.BaseActivity; | ||
import com.lzy.okhttpdemo.callback.DialogCallback; | ||
import com.lzy.okhttpdemo.model.ServerModel; | ||
import com.lzy.okhttpdemo.utils.Urls; | ||
import com.lzy.okhttputils.OkHttpUtils; | ||
|
||
import butterknife.Bind; | ||
import butterknife.ButterKnife; | ||
import butterknife.OnClick; | ||
import okhttp3.Call; | ||
import okhttp3.Response; | ||
|
||
public class TestActivity extends BaseActivity { | ||
|
||
@Bind(R.id.image) ImageView imageView; | ||
@Bind(R.id.edit) EditText editText; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_test); | ||
setTitle("测试页面"); | ||
ButterKnife.bind(this); | ||
} | ||
|
||
@Override | ||
protected void onDestroy() { | ||
super.onDestroy(); | ||
//Activity销毁时,取消网络请求 | ||
OkHttpUtils.getInstance().cancelTag(this); | ||
} | ||
|
||
@OnClick(R.id.btn1) | ||
public void btn1(View view) { | ||
|
||
OkHttpUtils.get(Urls.URL_METHOD)// | ||
.tag(this)// | ||
.headers("header1", "headerValue1")// | ||
.params("param1", "paramValue1")// | ||
.execute(new DialogCallback<ServerModel>(this, ServerModel.class) { | ||
@Override | ||
public void onSuccess(ServerModel serverModel, Call call, Response response) { | ||
System.out.println("onSuccess -- " + serverModel); | ||
} | ||
|
||
@Override | ||
public void onError(Call call, Response response, Exception e) { | ||
super.onError(call, response, e); | ||
System.out.println("onError"); | ||
} | ||
}); | ||
|
||
} | ||
|
||
@OnClick(R.id.btn2) | ||
public void btn2(View view) { | ||
} | ||
|
||
@OnClick(R.id.btn3) | ||
public void btn3(View view) { | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.