<commit_before>/*
 * Copyright 2012 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.pickncrop;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.UUID;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewManager;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.widget.ZoomButtonsController;
import android.widget.ZoomButtonsController.OnZoomListener;

public class MainActivity extends Activity {
	private ImageView imageView;
	private ViewManager viewManager;
	private Matrix matrix;
	private int size;
	private final int outputSize = 100;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Display display = getWindowManager().getDefaultDisplay();
		int width = display.getWidth();
		int height = display.getHeight();
		size = width < height ? width : height;
		size -= 50;

		imageView = (ImageView) findViewById(R.id.imageViewCrop);
		imageView.getLayoutParams().width = size;
		imageView.getLayoutParams().height = size;
		viewManager = (ViewManager) imageView.getParent();

		if (!getPackageManager().hasSystemFeature(
				PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) {
			createZoomControls();
		}

		imageView.setOnTouchListener(new OnTouchListener() {
			float initX;
			float initY;
			float scale;
			float initDistance;
			float currentDistance;
			boolean isMultitouch = false;

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction() & MotionEvent.ACTION_MASK) {
				case MotionEvent.ACTION_DOWN:
					initX = event.getX();
					initY = event.getY();
					break;
				case MotionEvent.ACTION_POINTER_DOWN:
					isMultitouch = true;
					initDistance = (float) Math.sqrt(Math.pow(
							initX - event.getX(1), 2)
							+ Math.pow(initY - event.getY(1), 2));
					break;
				case MotionEvent.ACTION_MOVE:
					if (isMultitouch) {
						matrix = imageView.getImageMatrix();
						currentDistance = (float) Math.sqrt(Math.pow(initX
								- event.getX(1), 2)
								+ Math.pow(initY - event.getY(1), 2));
						scale = 1 + 0.001f * (currentDistance - initDistance);
						matrix.postScale(scale, scale, 0.5f * size, 0.5f * size);
						imageView.setImageMatrix(matrix);
						imageView.invalidate();
					} else {
						imageView.scrollBy((int) (initX - event.getX()),
								(int) (initY - event.getY()));
						initX = event.getX();
						initY = event.getY();
					}
					break;
				case MotionEvent.ACTION_UP:
					isMultitouch = false;
					break;
				case MotionEvent.ACTION_POINTER_UP:
					isMultitouch = false;
					break;
				}
				return true;
			}
		});
	}

	public void createZoomControls() {
		ZoomButtonsController zoomButtonsController = new ZoomButtonsController(
				imageView);
		zoomButtonsController.setVisible(true);
		zoomButtonsController.setAutoDismissed(false);<commit_msg>Fix bitmap centering during multitouch zoom<commit_after>/*
 * Copyright 2012 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.github.pickncrop;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.UUID;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.Matrix;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewManager;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.widget.ZoomButtonsController;
import android.widget.ZoomButtonsController.OnZoomListener;

public class MainActivity extends Activity {
	private ImageView imageView;
	private ViewManager viewManager;
	private Matrix matrix;
	private int size;
	private final int outputSize = 100;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Display display = getWindowManager().getDefaultDisplay();
		int width = display.getWidth();
		int height = display.getHeight();
		size = width < height ? width : height;
		size -= 50;

		imageView = (ImageView) findViewById(R.id.imageViewCrop);
		imageView.getLayoutParams().width = size;
		imageView.getLayoutParams().height = size;
		viewManager = (ViewManager) imageView.getParent();

		if (getPackageManager().hasSystemFeature(
				PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH)) {
			createZoomControls();
		}

		imageView.setOnTouchListener(new OnTouchListener() {
			float initX;
			float initY;
			float midX;
			float midY;
			float scale;
			float initDistance;
			float currentDistance;
			boolean isMultitouch = false;

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				switch (event.getAction() & MotionEvent.ACTION_MASK) {
				case MotionEvent.ACTION_DOWN:
					initX = event.getX();
					initY = event.getY();
					break;
				case MotionEvent.ACTION_POINTER_DOWN:
					isMultitouch = true;
					initDistance = (float) Math.sqrt(Math.pow(
							initX - event.getX(1), 2)
							+ Math.pow(initY - event.getY(1), 2));
					break;
				case MotionEvent.ACTION_MOVE:
					if (isMultitouch) {
						matrix = imageView.getImageMatrix();
						currentDistance = (float) Math.sqrt(Math.pow(initX
								- event.getX(1), 2)
								+ Math.pow(initY - event.getY(1), 2));
						scale = 1 + 0.001f * (currentDistance - initDistance);
						midX = 0.5f * (initX + event.getX(1));
						midY = 0.5f * (initY + event.getY(1));
						matrix.postScale(scale, scale, midX, midY);
						imageView.setImageMatrix(matrix);
						imageView.invalidate();
					} else {
						imageView.scrollBy((int) (initX - event.getX()),
								(int) (initY - event.getY()));
						initX = event.getX();
						initY = event.getY();
					}
					break;
				case MotionEvent.ACTION_UP:
					isMultitouch = false;
					break;
				case MotionEvent.ACTION_POINTER_UP:
					isMultitouch = false;
					break;
				}
				return true;
			}
		});
	}

	public void createZoomControls() {
		ZoomButtonsController zoomButtonsController = new ZoomButtonsController(
				imageView);
		zoomButtonsController.setVisible(true);
		zoomButtonsController.setAutoDismissed(false);
{'fraction_non_alphanumeric': 0.10338962458996477, 'fraction_numerical': 0.007532499088810594, 'mean_word_length': 3.959036144578313, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6635443', 'n_tokens_mistral': 2905, 'n_tokens_neox': 2424, 'n_words': 622}