<commit_before>package com.ahmetkizilay.image.photostrips.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;

import com.ahmetkizilay.image.photostrips.PhotoCreator;
import com.ahmetkizilay.image.photostrips.R;
import com.ahmetkizilay.image.photostrips.ViewImageActivity;

import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * Created by ahmetkizilay on 12.07.2014.
 */
public class GalleryItemAdapter extends BaseAdapter {
    private String mGalleryDirectory;
    private String[] mPhotos;
    private Activity context;

    private int mDefaultThumbSize;
    private boolean mPortraitMode;

    public GalleryItemAdapter(Activity context, String galleryDirectory) {
        this.context = context;
        this.mGalleryDirectory = galleryDirectory;
        this.mPhotos = getFiles();

        DisplayMetrics dispMetrics = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(dispMetrics);

        int disp_height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, dispMetrics.heightPixels, dispMetrics);
        int disp_width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, dispMetrics.widthPixels, dispMetrics);

        mPortraitMode = disp_width < disp_height;
        if(mPortraitMode) {
            mDefaultThumbSize = disp_width + 50;
        }
        else {
            mDefaultThumbSize = (disp_width / 2) + 50;
        }
    }

    public void removeItem(String photo) {
        String[] newPhotos = new String[this.mPhotos.length - 1];

        for(int i = 0, j = 0; i < this.mPhotos.length; i += 1) {
            if(!this.mPhotos[i].equals(photo)) {
                newPhotos[j++] = this.mPhotos[i];
            }
        }

        this.mPhotos = newPhotos;
    }

    public int getCount() {
        return this.mPhotos.length;
    }

    public Object getItem(int i) {
        return this.mPhotos[i];
    }

    public long getItemId(int i) {
        return i;
    }

    public View getView(int position, View view, ViewGroup viewGroup) {

        ViewHolder holder;

        if(view == null) {
            LayoutInflater inflater = this.context.getLayoutInflater();
            view = inflater.inflate(R.layout.port_gallery_item, viewGroup, false);

            holder = new ViewHolder();

            holder.img = (ImageView) view.findViewById(R.id.imgPhoto);

            view.setTag(holder);
        }
        else {
            holder = (ViewHolder) view.getTag();
        }

        final String photo = this.mPhotos[position];

        Bitmap thumbBM = PhotoCreator.getThumbnailBM(new File(photo), mDefaultThumbSize, mPortraitMode);
        holder.img.setImageBitmap(thumbBM);
        holder.img.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                String selectedFile = photo;

                Intent showPicIntent = new Intent(GalleryItemAdapter.this.context, ViewImageActivity.class);
                showPicIntent.setDataAndType(Uri.parse(selectedFile), "image*//*");
                showPicIntent.setAction("com.ahmetkizilay.image.photostrips.ViewImageActivity");
                GalleryItemAdapter.this.context.startActivityForResult(showPicIntent, 0);
            }
        });

        final HorizontalScrollView hScrollView = (HorizontalScrollView) view;
        hScrollView.postDelayed(new Runnable() {
            public void run() {
                hScrollView.smoothScrollBy(20 + (int) Math.floor(Math.random() * 200.0f), 0);
            }
        }, 10);

        return view;
    }

    private static class ViewHolder {<commit_msg>set full scroll orientation based on position<commit_after>package com.ahmetkizilay.image.photostrips.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;

import com.ahmetkizilay.image.photostrips.PhotoCreator;
import com.ahmetkizilay.image.photostrips.R;
import com.ahmetkizilay.image.photostrips.ViewImageActivity;

import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * Created by ahmetkizilay on 12.07.2014.
 */
public class GalleryItemAdapter extends BaseAdapter {
    private String mGalleryDirectory;
    private String[] mPhotos;
    private Activity context;

    private int mDefaultThumbSize;
    private boolean mPortraitMode;

    public GalleryItemAdapter(Activity context, String galleryDirectory) {
        this.context = context;
        this.mGalleryDirectory = galleryDirectory;
        this.mPhotos = getFiles();

        DisplayMetrics dispMetrics = new DisplayMetrics();
        context.getWindowManager().getDefaultDisplay().getMetrics(dispMetrics);

        int disp_height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, dispMetrics.heightPixels, dispMetrics);
        int disp_width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PX, dispMetrics.widthPixels, dispMetrics);

        mPortraitMode = disp_width < disp_height;
        if(mPortraitMode) {
            mDefaultThumbSize = disp_width + 50;
        }
        else {
            mDefaultThumbSize = (disp_width / 2) + 50;
        }
    }

    public void removeItem(String photo) {
        String[] newPhotos = new String[this.mPhotos.length - 1];

        for(int i = 0, j = 0; i < this.mPhotos.length; i += 1) {
            if(!this.mPhotos[i].equals(photo)) {
                newPhotos[j++] = this.mPhotos[i];
            }
        }

        this.mPhotos = newPhotos;
    }

    public int getCount() {
        return this.mPhotos.length;
    }

    public Object getItem(int i) {
        return this.mPhotos[i];
    }

    public long getItemId(int i) {
        return i;
    }

    public View getView(final int position, View view, ViewGroup viewGroup) {

        ViewHolder holder;

        if(view == null) {
            LayoutInflater inflater = this.context.getLayoutInflater();
            view = inflater.inflate(R.layout.port_gallery_item, viewGroup, false);

            holder = new ViewHolder();

            holder.img = (ImageView) view.findViewById(R.id.imgPhoto);

            view.setTag(holder);
        }
        else {
            holder = (ViewHolder) view.getTag();
        }

        final String photo = this.mPhotos[position];

        Bitmap thumbBM = PhotoCreator.getThumbnailBM(new File(photo), mDefaultThumbSize, mPortraitMode);
        holder.img.setImageBitmap(thumbBM);
        holder.img.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                String selectedFile = photo;

                Intent showPicIntent = new Intent(GalleryItemAdapter.this.context, ViewImageActivity.class);
                showPicIntent.setDataAndType(Uri.parse(selectedFile), "image*//*");
                showPicIntent.setAction("com.ahmetkizilay.image.photostrips.ViewImageActivity");
                GalleryItemAdapter.this.context.startActivityForResult(showPicIntent, 0);
            }
        });

        final HorizontalScrollView hScrollView = (HorizontalScrollView) view;
        hScrollView.postDelayed(new Runnable() {
            public void run() {
                hScrollView.fullScroll(position % 2 == 0 ? CustomHorizontalScrollView.FOCUS_RIGHT : CustomHorizontalScrollView.FOCUS_LEFT);
            }
        }, 10);

        return view;
    }

    private static class ViewHolder {
{'fraction_non_alphanumeric': 0.09651247275369339, 'fraction_numerical': 0.005933640106563332, 'mean_word_length': 2.8431828757561655, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6275806', 'n_tokens_mistral': 2484, 'n_tokens_neox': 2323, 'n_words': 473}