Commit bb9ced53 authored by fallenstardust's avatar fallenstardust

直接显示卡图,不new一个activity

parent 1e8dadec
package cn.garymb.ygomobile.ui.activities;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import androidx.appcompat.widget.Toolbar;
import java.io.IOException;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.loader.ImageLoader;
import uk.co.senab.photoview.PhotoView;
public class PhotoViewActivity extends BaseActivity {
PhotoView mPhotoView;
private long cardCode;
private String mName;
private ImageLoader mImageLoader;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo);
final Toolbar toolbar = $(R.id.toolbar);
setSupportActionBar(toolbar);
enableBackHome();
mImageLoader = ImageLoader.get(this);
mPhotoView = $(R.id.photoview);
if (loadItem(getIntent())) {
loadImage();
}
}
@Override
protected void onDestroy() {
ImageLoader.onDestory(this);
try {
mImageLoader.close();
} catch (IOException e) {
}
super.onDestroy();
}
private void loadImage() {
if (!TextUtils.isEmpty(mName)) {
setTitle(mName);
}
mImageLoader.bindImage(mPhotoView, cardCode, null, true);
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (loadItem(intent)) {
loadImage();
}
}
public static void showImage(Context context, long code, String name) {
Intent intent = new Intent(context, PhotoViewActivity.class);
intent.putExtra(Intent.EXTRA_TITLE, name);
intent.putExtra(Intent.EXTRA_TEXT, code);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
private boolean loadItem(Intent intent) {
try {
if (intent.hasExtra(Intent.EXTRA_TITLE)) {
mName = intent.getStringExtra(Intent.EXTRA_TITLE);
}
if (intent.hasExtra(Intent.EXTRA_TEXT)) {
cardCode = intent.getLongExtra(Intent.EXTRA_TEXT, 0);
}
} catch (Exception e) {
}
return cardCode > 0;
}
}
package cn.garymb.ygomobile.ui.cards; package cn.garymb.ygomobile.ui.cards;
import android.app.Dialog;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
...@@ -10,12 +11,10 @@ import android.widget.Toast; ...@@ -10,12 +11,10 @@ import android.widget.Toast;
import cn.garymb.ygomobile.lite.R; import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.loader.ImageLoader; import cn.garymb.ygomobile.loader.ImageLoader;
import cn.garymb.ygomobile.ui.activities.BaseActivity; import cn.garymb.ygomobile.ui.activities.BaseActivity;
import cn.garymb.ygomobile.ui.activities.PhotoViewActivity;
import cn.garymb.ygomobile.ui.adapters.BaseAdapterPlus; import cn.garymb.ygomobile.ui.adapters.BaseAdapterPlus;
import cn.garymb.ygomobile.utils.CardUtils; import cn.garymb.ygomobile.utils.CardUtils;
import ocgcore.StringManager; import ocgcore.StringManager;
import ocgcore.data.Card; import ocgcore.data.Card;
import ocgcore.data.CardData;
import ocgcore.enums.CardType; import ocgcore.enums.CardType;
/*** /***
...@@ -160,7 +159,12 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder { ...@@ -160,7 +159,12 @@ public class CardDetail extends BaseAdapterPlus.BaseViewHolder {
mCardInfo = cardInfo; mCardInfo = cardInfo;
imageLoader.bindImage(cardImage, cardInfo.Code, null, true); imageLoader.bindImage(cardImage, cardInfo.Code, null, true);
cardImage.setOnClickListener((v) -> { cardImage.setOnClickListener((v) -> {
PhotoViewActivity.showImage(context, cardInfo.Code, cardInfo.Name); Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog_photo);
dialog.show();
ImageView photoView = dialog.findViewById(R.id.photoView);
imageLoader.bindImage(photoView, cardInfo.Code, null, true);
}); });
name.setText(cardInfo.Name); name.setText(cardInfo.Name);
desc.setText(cardInfo.Desc); desc.setText(cardInfo.Desc);
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/content_toolbar" />
<uk.co.senab.photoview.PhotoView
android:id="@+id/photoview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/photoView"
android:layout_width="421dp"
android:layout_height="614dp"
android:layout_gravity="center_vertical"
android:background="@color/tr_transparent_background" />
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment