// Path: app/src/main/java/com/leelit/stuer/constant/NetConstant.java
// public class NetConstant {
// 
//     public static final int NET_ERROR_RECORD_EXISTED = 601;
// 
//     //    public static final String HOST = "http://192.168.191.1:8080/STUer/";
//     public static final String HOST = "http://stuer.applinzi.com/";
// 
//     public static final String IMAGE_HOST = "http://stuer-picture.stor.sinaapp.com/";
// 
// }
// 
// Path: app/src/main/java/com/leelit/stuer/utils/ImageUtils.java
// public class ImageUtils {
// 
// 
//     /**
//      * @param imageView
//      * @return byte[]
//      */
//     public static byte[] image2byte(ImageView imageView) {
//         if (imageView == null) {
//             return null;
//         }
//         BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
//         Bitmap bitmap = drawable.getBitmap();
//         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
//         bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
//         return outputStream.toByteArray();
//     }
// }


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.leelit.stuer.R;
import com.leelit.stuer.constant.NetConstant;
import com.leelit.stuer.utils.ImageUtils;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import butterknife.ButterKnife;
import butterknife.InjectView;
import uk.co.senab.photoview.PhotoViewAttacher;
package com.leelit.stuer.base_view;





public class PhotoActivity extends AppCompatActivity {

    @InjectView(R.id.imageView)
    ImageView mImageView;

    PhotoViewAttacher mAttacher;

    public static final String IMAGE_HOST = NetConstant.IMAGE_HOST;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);
        ButterKnife.inject(this);
        final String picName = getIntent().getStringExtra("picName");
        RequestCreator requestCreator = Picasso.with(this)
                .load(IMAGE_HOST + picName + ".jpg");
        requestCreator.into(mImageView);
        requestCreator.fetch(new Callback() {
            @Override
            public void onSuccess() {
                // 一开始为wrap_content使其居中，成功加载后match_parent使其放缩效果更佳
                mImageView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
            }

            @Override
            public void onError() {
                Toast.makeText(PhotoActivity.this, "加载图片失败", Toast.LENGTH_SHORT).show();
            }
// Path: app/src/main/java/com/leelit/stuer/constant/NetConstant.java
// public class NetConstant {
// 
//     public static final int NET_ERROR_RECORD_EXISTED = 601;
// 
//     //    public static final String HOST = "http://192.168.191.1:8080/STUer/";
//     public static final String HOST = "http://stuer.applinzi.com/";
// 
//     public static final String IMAGE_HOST = "http://stuer-picture.stor.sinaapp.com/";
// 
// }
// 
// Path: app/src/main/java/com/leelit/stuer/utils/ImageUtils.java
// public class ImageUtils {
// 
// 
//     /**
//      * @param imageView
//      * @return byte[]
//      */
//     public static byte[] image2byte(ImageView imageView) {
//         if (imageView == null) {
//             return null;
//         }
//         BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable();
//         Bitmap bitmap = drawable.getBitmap();
//         ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
//         bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
//         return outputStream.toByteArray();
//     }
// }


// Path: app/src/main/java/com/leelit/stuer/base_view/PhotoActivity.java
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.leelit.stuer.R;
import com.leelit.stuer.constant.NetConstant;
import com.leelit.stuer.utils.ImageUtils;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import butterknife.ButterKnife;
import butterknife.InjectView;
import uk.co.senab.photoview.PhotoViewAttacher;

package com.leelit.stuer.base_view;





public class PhotoActivity extends AppCompatActivity {

    @InjectView(R.id.imageView)
    ImageView mImageView;

    PhotoViewAttacher mAttacher;

    public static final String IMAGE_HOST = NetConstant.IMAGE_HOST;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo);
        ButterKnife.inject(this);
        final String picName = getIntent().getStringExtra("picName");
        RequestCreator requestCreator = Picasso.with(this)
                .load(IMAGE_HOST + picName + ".jpg");
        requestCreator.into(mImageView);
        requestCreator.fetch(new Callback() {
            @Override
            public void onSuccess() {
                // 一开始为wrap_content使其居中，成功加载后match_parent使其放缩效果更佳
                mImageView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
            }

            @Override
            public void onError() {
                Toast.makeText(PhotoActivity.this, "加载图片失败", Toast.LENGTH_SHORT).show();
            }
        });