<commit_before>package com.mikekorcha.mediabuttonoverlay;

import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;

import com.mikekorcha.mediabuttonoverlay.services.OverlayService;
import com.mikekorcha.mediabuttonoverlay.views.MediaOverlayView;

public class MainActivity extends ActionBarActivity {

    protected SharedPreferences sharedPrefs;

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

        sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

        // Fix settings from previous version to work with this version, if needed
        String player = sharedPrefs.getString("player", "Default");

        if(player.equals("Google Play")) {
            sharedPrefs.edit().putString("player", "PlayMusic").apply();
        }
        else if(player.equals("Default Music Player")) {
            sharedPrefs.edit().putString("player", "Default").apply();
        }

        try {
            // Will fail if it's actually a string, indicating old version, which drops to the catch
            // which will fix it
            sharedPrefs.getInt("location", 0);
        }
        catch(ClassCastException e) {
            if(sharedPrefs.getString("location", "Left").equals("Left")) {
                sharedPrefs.edit().putInt("location", MediaOverlayView.LEFT).apply();
            }
            else {
                sharedPrefs.edit().putInt("location", MediaOverlayView.RIGHT).apply();
            }
        }

        try {
            sharedPrefs.getFloat("opacity", 0.5f);
        }
        catch(ClassCastException e) {
            sharedPrefs.edit().putFloat("opacity", sharedPrefs.getInt("opacity", 0) / 100).apply();
        }

        setContentView(R.layout.activity_main);

        if(sharedPrefs.getBoolean("notification", false)) {
            startNotification(getApplicationContext());
        }

        getFragmentManager().beginTransaction().replace(R.id.content, new PrefFragment()).commit();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {<commit_msg>Minor fix that reopens the overlay if the app is reinstalled with it running<commit_after>package com.mikekorcha.mediabuttonoverlay;

import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;

import com.mikekorcha.mediabuttonoverlay.services.OverlayService;
import com.mikekorcha.mediabuttonoverlay.views.MediaOverlayView;

public class MainActivity extends ActionBarActivity {

    protected SharedPreferences sharedPrefs;

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

        sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

        // Fix settings from previous version to work with this version, if needed
        String player = sharedPrefs.getString("player", "Default");

        if(player.equals("Google Play")) {
            sharedPrefs.edit().putString("player", "PlayMusic").apply();
        }
        else if(player.equals("Default Music Player")) {
            sharedPrefs.edit().putString("player", "Default").apply();
        }

        try {
            // Will fail if it's actually a string, indicating old version, which drops to the catch
            // which will fix it
            sharedPrefs.getInt("location", 0);
        }
        catch(ClassCastException e) {
            if(sharedPrefs.getString("location", "Left").equals("Left")) {
                sharedPrefs.edit().putInt("location", MediaOverlayView.LEFT).apply();
            }
            else {
                sharedPrefs.edit().putInt("location", MediaOverlayView.RIGHT).apply();
            }
        }

        try {
            sharedPrefs.getFloat("opacity", 0.5f);
        }
        catch(ClassCastException e) {
            sharedPrefs.edit().putFloat("opacity", sharedPrefs.getInt("opacity", 0) / 100).apply();
        }

        setContentView(R.layout.activity_main);

        if(sharedPrefs.getBoolean("notification", false)) {
            startNotification(getApplicationContext());
        }

        if(!sharedPrefs.getBoolean("started", false)) {
            startService(new Intent(this, OverlayService.class));

            sharedPrefs.edit().putBoolean("started", true).apply();
        }

        getFragmentManager().beginTransaction().replace(R.id.content, new PrefFragment()).commit();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
{'fraction_non_alphanumeric': 0.10847988855998607, 'fraction_numerical': 0.003134250391781299, 'mean_word_length': 3.2929745889387143, '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': '533875', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1464, 'n_words': 296}