97 lines
3.2 KiB
Java
97 lines
3.2 KiB
Java
package com.uiuios.aios.activity;
|
|
|
|
import android.content.Intent;
|
|
import android.graphics.Bitmap;
|
|
import android.graphics.drawable.Drawable;
|
|
import android.util.Log;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.ViewTreeObserver;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.databinding.DataBindingUtil;
|
|
|
|
import com.bumptech.glide.Glide;
|
|
import com.bumptech.glide.request.target.CustomTarget;
|
|
import com.bumptech.glide.request.transition.Transition;
|
|
import com.shehuan.niv.NiceImageView;
|
|
import com.uiuios.aios.R;
|
|
import com.uiuios.aios.base.BaseDataBindingActivity;
|
|
import com.uiuios.aios.bean.ArticleInfo;
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.ButterKnife;
|
|
|
|
public class ArticleActivity extends BaseDataBindingActivity {
|
|
@BindView(R.id.iv_back)
|
|
ImageView iv_back;
|
|
@BindView(R.id.tv_title)
|
|
TextView tv_title;
|
|
@BindView(R.id.tv_content)
|
|
TextView tv_content;
|
|
@BindView(R.id.iv_img)
|
|
NiceImageView iv_img;
|
|
|
|
@Override
|
|
protected void initDataBinding() {
|
|
DataBindingUtil.setContentView(this, R.layout.activity_articl);
|
|
}
|
|
|
|
@Override
|
|
public void initView() {
|
|
ButterKnife.bind(this);
|
|
Intent intent = getIntent();
|
|
if (intent == null) {
|
|
finish();
|
|
}
|
|
ArticleInfo articleInfo = (ArticleInfo) intent.getSerializableExtra("ArticleInfo");
|
|
if (articleInfo == null) {
|
|
finish();
|
|
}
|
|
iv_back.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
finish();
|
|
}
|
|
});
|
|
tv_title.setText(articleInfo.getTitle());
|
|
tv_content.setText(articleInfo.getContent());
|
|
ViewTreeObserver observer = iv_img.getViewTreeObserver();
|
|
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
@Override
|
|
public void onGlobalLayout() {
|
|
ViewGroup.LayoutParams layoutParams = iv_img.getLayoutParams();
|
|
int width = iv_img.getWidth();
|
|
// layoutParams.height = width;
|
|
// iv_img.setLayoutParams(layoutParams);
|
|
}
|
|
});
|
|
Glide.with(iv_img).asBitmap().load(articleInfo.getImg()).into(new CustomTarget<Bitmap>() {
|
|
@Override
|
|
public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
|
|
int imgWidth = resource.getWidth();
|
|
int imgHeight = resource.getHeight();
|
|
iv_img.setImageBitmap(resource);
|
|
Log.e("into", "onResourceReady: width = " + imgWidth + "height = " + imgHeight);
|
|
ViewGroup.LayoutParams layoutParams = iv_img.getLayoutParams();
|
|
int width = iv_img.getWidth();
|
|
layoutParams.height = (int) (imgHeight * (1.0f * width / imgWidth));
|
|
iv_img.setLayoutParams(layoutParams);
|
|
}
|
|
|
|
@Override
|
|
public void onLoadCleared(@Nullable Drawable placeholder) {
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void initData() {
|
|
|
|
}
|
|
}
|