How to use okhttp get the json
http://stackoverflow.com/questions/28221555/how-does-okhttp-get-json-string
Create the right object
gson = new Gson();
Build the request
HttpUrl.Builder urlBuilder = HttpUrl.parse("https://api.github.help").newBuilder();
urlBuilder.addQueryParameter("v", "1.0");
urlBuilder.addQueryParameter("user", "vogella");
String url = urlBuilder.build().toString();
Request request = new Request.Builder()
.url(url)
.build();
OKHTTP3 update UI
client.newCall(request).enqueue(new Callback() {
@Override
public void onResponse(Call call, final Response response) throws IOException {
// ... check for failure using `isSuccessful` before proceeding
// Read data on the worker thread
final String responseData = response.body().string();
// Run view-related code back on the main thread
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
try {
TextView myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setText(responseData);
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
});
2016年10月1日 星期六
Specifica view raitio
https://plus.google.com/+AndroidDevelopers/posts/ZQS29a5yroK
use Percent Support Library
use Percent Support Library
Embeed the youtube into the APP
Youtube API way:
https://www.sitepoint.com/using-the-youtube-api-to-embed-video-in-an-android-app/
Not use Youtube API way:
https://www.sitepoint.com/using-the-youtube-api-to-embed-video-in-an-android-app/
Not use Youtube API way:
Video
Youtube
No need use youtube api way:
Tutorial:
Webview
Picasso:how to add a Reflect effect to the image
at the into function,add a callback
private void setImageUrl(ImageView imageView, String url) {
Picasso.with(getContext())
.load(url)
.centerCrop().fit()
.transform(new EffectTransformation())
.into(imageView, new Callback() {
@Override
public void onSuccess() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (imageVBackground.getDrawable() != null) {
Bitmap bmp = ((BitmapDrawable) (imageVBackground.getDrawable())).getBitmap();
int bmpWidth = bmp.getWidth();
int bmpHeight = bmp.getHeight();
Bitmap b = Bitmap.createBitmap(bmp, 0, bmpHeight * 5 / 6, bmpWidth, bmpHeight / 6, null, false);
Bitmap newBitmap = addGradient(b);
ivMirror.setImageBitmap(newBitmap);
// ivMirror.setAlpha(0.1f);
}
}
}, 300);
}
@Override
public void onError() {
}
});
}
訂閱:
文章 (Atom)