<commit_before>package com.gmail.alexellingsen.g2skintweaks;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.preference.*;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.gmail.alexellingsen.g2skintweaks.preference.PreviewColorPreference;
import com.gmail.alexellingsen.g2skintweaks.utils.SettingsHelper;
import it.gmariotti.android.colorpicker.calendarstock.ColorPickerDialog;
import it.gmariotti.android.colorpicker.calendarstock.ColorPickerSwatch;

import java.io.File;
import java.util.Arrays;

public class MainActivity extends PreferenceActivity {

    private static final int CROP_IMAGE = 112;
    private static final int PICK_IMAGE = 111;
    private static final String INSTALL_SHORTCUT_ACTION = "com.android.launcher.action.INSTALL_SHORTCUT";
    private static final String XPOSED_INSTALLER_PACKAGE = "de.robv.android.xposed.installer";

    private static SettingsHelper settings = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        settings = new SettingsHelper(this);

        MainFragment mainFragment = new MainFragment();

        getFragmentManager()
                .beginTransaction()
                .replace(android.R.id.content, mainFragment)
                .commit();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != RESULT_OK)
            return;

        if (requestCode == PICK_IMAGE) {
            cropImage(this, data.getData());
        } else if (requestCode == CROP_IMAGE) {
            Toast.makeText(this, getString(R.string.set_background_complete), Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        boolean debugging = settings.getBoolean(Prefs.ENABLE_DEBUGGING, false);

        menu.findItem(R.id.action_enable_debugging).setChecked(debugging);

        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_create_shortcut) {
            createHomeShortcut();
            return true;
        } else if (id == R.id.action_enable_debugging) {
            item.setChecked(!item.isChecked());
            settings.putBoolean(Prefs.ENABLE_DEBUGGING, item.isChecked());
            return true;
        } else if (id == R.id.action_settings) {
            Intent i = new Intent(getApplicationContext(), PrefsActivity.class);
            startActivity(i);
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private void createHomeShortcut() {
        Intent intent = new Intent(getApplicationContext(), MainActivity.class);

        intent.setAction(Intent.ACTION_MAIN);

        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                        R.drawable.ic_launcher)
        );

        addIntent.setAction(INSTALL_SHORTCUT_ACTION);
        getApplicationContext().sendBroadcast(addIntent);
    }

    private static void pickImage(Activity activity) {
        Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        intent.setType("image/*");
        activity.startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_IMAGE);
    }

    private static void cropImage(Activity activity, Uri data) {
        Intent intent = new Intent("com.android.camera.action.CROP");

        intent.setData(data);
        intent.putExtra("outputX", 1080);
        intent.putExtra("outputY", 1584);
        intent.putExtra("aspectX", 15);
        intent.putExtra("aspectY", 22);
        intent.putExtra("scale", true);

        Uri path = Uri.fromFile(new File(Environment.getExternalStorageDirectory().toString() +
                "/G2SkinTweaks/background.png"));

        intent.putExtra("output", path);
        activity.startActivityForResult(intent, CROP_IMAGE);
    }

    public static class MainFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener {

        public MainFragment() {<commit_msg>Create folder if it doesn't exists<commit_after>package com.gmail.alexellingsen.g2skintweaks;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.preference.*;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;
import com.gmail.alexellingsen.g2skintweaks.preference.PreviewColorPreference;
import com.gmail.alexellingsen.g2skintweaks.utils.SettingsHelper;
import it.gmariotti.android.colorpicker.calendarstock.ColorPickerDialog;
import it.gmariotti.android.colorpicker.calendarstock.ColorPickerSwatch;

import java.io.File;
import java.util.Arrays;

public class MainActivity extends PreferenceActivity {

    private static final int CROP_IMAGE = 112;
    private static final int PICK_IMAGE = 111;
    private static final String INSTALL_SHORTCUT_ACTION = "com.android.launcher.action.INSTALL_SHORTCUT";
    private static final String XPOSED_INSTALLER_PACKAGE = "de.robv.android.xposed.installer";

    private static SettingsHelper settings = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        settings = new SettingsHelper(this);

        MainFragment mainFragment = new MainFragment();

        getFragmentManager()
                .beginTransaction()
                .replace(android.R.id.content, mainFragment)
                .commit();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != RESULT_OK)
            return;

        if (requestCode == PICK_IMAGE) {
            cropImage(this, data.getData());
        } else if (requestCode == CROP_IMAGE) {
            Toast.makeText(this, getString(R.string.set_background_complete), Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        boolean debugging = settings.getBoolean(Prefs.ENABLE_DEBUGGING, false);

        menu.findItem(R.id.action_enable_debugging).setChecked(debugging);

        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_create_shortcut) {
            createHomeShortcut();
            return true;
        } else if (id == R.id.action_enable_debugging) {
            item.setChecked(!item.isChecked());
            settings.putBoolean(Prefs.ENABLE_DEBUGGING, item.isChecked());
            return true;
        } else if (id == R.id.action_settings) {
            Intent i = new Intent(getApplicationContext(), PrefsActivity.class);
            startActivity(i);
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    private void createHomeShortcut() {
        Intent intent = new Intent(getApplicationContext(), MainActivity.class);

        intent.setAction(Intent.ACTION_MAIN);

        Intent addIntent = new Intent();
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                        R.drawable.ic_launcher)
        );

        addIntent.setAction(INSTALL_SHORTCUT_ACTION);
        getApplicationContext().sendBroadcast(addIntent);
    }

    private static void pickImage(Activity activity) {
        File folder = new File(Environment.getExternalStorageDirectory(), "G2SkinTweaks");

        if (!folder.exists()) {
            try {
                folder.mkdir();
            } catch (Throwable e) {
                Toast.makeText(activity, "Couldn't create folder.", Toast.LENGTH_SHORT).show();
                return;
            }
        }

        Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
        intent.setType("image/*");
        activity.startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_IMAGE);
    }

    private static void cropImage(Activity activity, Uri data) {
        Intent intent = new Intent("com.android.camera.action.CROP");

        intent.setData(data);
        intent.putExtra("outputX", 1080);
        intent.putExtra("outputY", 1584);
        intent.putExtra("aspectX", 15);
        intent.putExtra("aspectY", 22);
        intent.putExtra("scale", true);

        Uri path = Uri.fromFile(new File(Environment.getExternalStorageDirectory().toString() +
                "/G2SkinTweaks/background.png"));

        intent.putExtra("output", path);
        activity.startActivityForResult(intent, CROP_IMAGE);
    }

    public static class MainFragment extends PreferenceFragment implements OnSharedPreferenceChangeListener {

        public MainFragment() {
{'fraction_non_alphanumeric': 0.0967429236138038, 'fraction_numerical': 0.004362155874369911, 'mean_word_length': 3.1136363636363638, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1887294', 'n_tokens_mistral': 2937, 'n_tokens_neox': 2792, 'n_words': 555}