// Path: app/src/main/java/in/sahildave/gazetti/util/BitmapTransform.java
// public class BitmapTransform implements Transformation {
// 
//     int maxWidth;
//     int maxHeight;
// 
//     public BitmapTransform(int maxWidth, int maxHeight) {
//         this.maxWidth = maxWidth;
//         this.maxHeight = maxHeight;
//     }
// 
//     @Override
//     public Bitmap transform(Bitmap source) {
//         int targetWidth, targetHeight;
//         double aspectRatio;
// 
//         if (source.getWidth() > source.getHeight()) {
//             targetWidth = maxWidth;
//             aspectRatio = (double) source.getHeight() / (double) source.getWidth();
//             targetHeight = (int) (targetWidth * aspectRatio);
//         } else {
//             targetHeight = maxHeight;
//             aspectRatio = (double) source.getWidth() / (double) source.getHeight();
//             targetWidth = (int) (targetHeight * aspectRatio);
//         }
// 
//         Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
//         if (result != source) {
//             source.recycle();
//         }
//         return result;
//     }
// 
//     @Override
//     public String key() {
//         return maxWidth + "x" + maxHeight;
//     }
// 
// }


import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.TypedValue;
import android.view.Display;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.*;
import com.crashlytics.android.Crashlytics;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import fr.castorflex.android.smoothprogressbar.SmoothProgressBar;
import in.sahildave.gazetti.R;
import in.sahildave.gazetti.util.BitmapTransform;
    }

    public void onPostExecute(String[] result, String mArticlePubDate) {

        titleText = result[0];
        mImageURL = result[1];
        bodyText = result[2];

        mSubtitleLayout.setVisibility(View.VISIBLE);
        mArticleFooter.setVisibility(View.VISIBLE);
        mArticlePubDateView.setText(mArticlePubDate);
        mArticleTextView.setVisibility(View.VISIBLE);
        mArticleTextView.setText(bodyText);

        if (mImageURL == null) {
            mTitleTextView = (TextView) headerStub.findViewById(R.id.article_title);
            mTitleTextView.setText(titleText);
            detailViewProgress.progressiveStop();
        } else {
            mTitleTextView = (TextView) headerStub.findViewById(R.id.article_header_title);
            mTitleTextView.setText(titleText);

            mMainImageView = (ImageView) headerStub.findViewById(R.id.article_header_image);

            //height and width of screen
            final int MAX_HEIGHT = activity.getResources().getDisplayMetrics().heightPixels;
            final int MAX_WIDTH = activity.getResources().getDisplayMetrics().widthPixels;

            RequestCreator requestCreator = Picasso.with(activity)
                    .load(mImageURL)
// Path: app/src/main/java/in/sahildave/gazetti/util/BitmapTransform.java
// public class BitmapTransform implements Transformation {
// 
//     int maxWidth;
//     int maxHeight;
// 
//     public BitmapTransform(int maxWidth, int maxHeight) {
//         this.maxWidth = maxWidth;
//         this.maxHeight = maxHeight;
//     }
// 
//     @Override
//     public Bitmap transform(Bitmap source) {
//         int targetWidth, targetHeight;
//         double aspectRatio;
// 
//         if (source.getWidth() > source.getHeight()) {
//             targetWidth = maxWidth;
//             aspectRatio = (double) source.getHeight() / (double) source.getWidth();
//             targetHeight = (int) (targetWidth * aspectRatio);
//         } else {
//             targetHeight = maxHeight;
//             aspectRatio = (double) source.getWidth() / (double) source.getHeight();
//             targetWidth = (int) (targetHeight * aspectRatio);
//         }
// 
//         Bitmap result = Bitmap.createScaledBitmap(source, targetWidth, targetHeight, false);
//         if (result != source) {
//             source.recycle();
//         }
//         return result;
//     }
// 
//     @Override
//     public String key() {
//         return maxWidth + "x" + maxHeight;
//     }
// 
// }


// Path: app/src/main/java/in/sahildave/gazetti/news_activities/ArticleLoadingCallback.java
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Point;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.TypedValue;
import android.view.Display;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.*;
import com.crashlytics.android.Crashlytics;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import fr.castorflex.android.smoothprogressbar.SmoothProgressBar;
import in.sahildave.gazetti.R;
import in.sahildave.gazetti.util.BitmapTransform;

    }

    public void onPostExecute(String[] result, String mArticlePubDate) {

        titleText = result[0];
        mImageURL = result[1];
        bodyText = result[2];

        mSubtitleLayout.setVisibility(View.VISIBLE);
        mArticleFooter.setVisibility(View.VISIBLE);
        mArticlePubDateView.setText(mArticlePubDate);
        mArticleTextView.setVisibility(View.VISIBLE);
        mArticleTextView.setText(bodyText);

        if (mImageURL == null) {
            mTitleTextView = (TextView) headerStub.findViewById(R.id.article_title);
            mTitleTextView.setText(titleText);
            detailViewProgress.progressiveStop();
        } else {
            mTitleTextView = (TextView) headerStub.findViewById(R.id.article_header_title);
            mTitleTextView.setText(titleText);

            mMainImageView = (ImageView) headerStub.findViewById(R.id.article_header_image);

            //height and width of screen
            final int MAX_HEIGHT = activity.getResources().getDisplayMetrics().heightPixels;
            final int MAX_WIDTH = activity.getResources().getDisplayMetrics().widthPixels;

            RequestCreator requestCreator = Picasso.with(activity)
                    .load(mImageURL)
                    .transform(new BitmapTransform(MAX_WIDTH, MAX_HEIGHT));