<commit_before>package net.ebt.muzei.miyazaki.activity;


import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import net.ebt.muzei.miyazaki.BuildConfig;
import net.ebt.muzei.miyazaki.R;
import net.ebt.muzei.miyazaki.app.MuzeiMiyazakiApplication;
import net.ebt.muzei.miyazaki.model.Artwork;
import net.ebt.muzei.miyazaki.service.MuzeiMiyazakiService;
import net.ebt.muzei.miyazaki.util.UiUtils;
import net.ebt.muzei.miyazaki.util.Utils;

import java.util.List;
import java.util.logging.Level;

import static net.ebt.muzei.miyazaki.Constants.ACTION_RELOAD;
import static net.ebt.muzei.miyazaki.Constants.CURRENT_PREF_NAME;
import static net.ebt.muzei.miyazaki.Constants.DEFAULT_INTERVAL;
import static net.ebt.muzei.miyazaki.Constants.INTERVALS;
import static net.ebt.muzei.miyazaki.Constants.MUZEI_COLOR;
import static net.ebt.muzei.miyazaki.Constants.MUZEI_FRAME;
import static net.ebt.muzei.miyazaki.Constants.MUZEI_INTERVAL;
import static net.ebt.muzei.miyazaki.Constants.MUZEI_WIFI;

public class MuzeiMiyazakiSettings extends FragmentActivity {

  private static final String TAG = "MuzeiMiyazakiSettings";
  private static final float ALPHA_DEACTIVATED = 0.3f;

  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    final String muzeiPackageId = Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN ? "net.nurik.roman.muzei" : "net.nurik.roman.muzei.muik";
    final SharedPreferences settings = getApplicationContext().getSharedPreferences(CURRENT_PREF_NAME, Context.MODE_PRIVATE);

    if (getIntent() != null && getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN)) {
      try {
        Intent launchIntent = getPackageManager().getLaunchIntentForPackage(muzeiPackageId);
        if (launchIntent != null) {

          if (!settings.getBoolean("onboarding", false)) {
            Toast.makeText(this, getResources().getString(R.string.setup_muzei), Toast.LENGTH_LONG).show();
          }
          launchIntent.addCategory(Intent.CATEGORY_DEFAULT);
          launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
          startActivity(launchIntent);
          finish();
          return;

        } else {
          Toast.makeText(this, getResources().getString(R.string.install_muzei), Toast.LENGTH_LONG).show();
          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setData(Uri.parse("market://details?id=" + muzeiPackageId));
          startActivity(intent);
          finish();
          return;
        }
      } catch (Throwable e) {
        // No playstore
      }
    }

    setContentView(R.layout.settings);

    int interval = settings.getInt(MUZEI_INTERVAL, DEFAULT_INTERVAL);

    final View colors = findViewById(R.id.colors);
    final SeekBar seekBar = (SeekBar) findViewById(R.id.muzei_interval);
    final CheckBox wifi = (CheckBox) findViewById(R.id.muzei_wifi);
    final TextView configLabel = (TextView) findViewById(R.id.muzei_config_label);
    final TextView label = (TextView) findViewById(R.id.muzei_label);
    configLabel.setText("Refresh every " + Utils.formatDuration(INTERVALS.get(interval)));

    seekBar.setMax(INTERVALS.size() - 1);
    seekBar.setProgress(interval);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

      @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        label.setText(Utils.formatDuration(INTERVALS.get(progress)).toUpperCase());
      }

      @Override
      public void onStartTrackingTouch(SeekBar seekBar) {
        configLabel.setVisibility(View.INVISIBLE);
        colors.setVisibility(View.GONE);
        label.setVisibility(View.VISIBLE);
      }

      @Override
      public void onStopTrackingTouch(SeekBar seekBar) {
        label.setText(null);
        label.setVisibility(View.GONE);
        configLabel.setText("Refresh every " + Utils.formatDuration(INTERVALS.get(seekBar.getProgress())));
        configLabel.setVisibility(View.VISIBLE);
        colors.setVisibility(View.VISIBLE);

        SharedPreferences.Editor editor = settings.edit();
        editor.putInt(MUZEI_INTERVAL, seekBar.getProgress());
        editor.commit();

        Intent intent = new Intent(MuzeiMiyazakiService.ACTION_RESCHEDULE);
        intent.setClass(seekBar.getContext(), MuzeiMiyazakiService.class);
        startService(intent);
      }
    });

    wifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(MUZEI_WIFI, isChecked);
        editor.commit();
      }
    });

    wifi.setChecked(settings.getBoolean(MUZEI_WIFI, true));
    label.setVisibility(View.GONE);

    findViewById(R.id.seeall).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        try {
          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setData(Uri.parse("http://muzeighibli.net?jsessionid=" + String.valueOf(System.currentTimeMillis()).hashCode() + "&a=" + Settings.Secure.getString(MuzeiMiyazakiSettings.this.getContentResolver(), Settings.Secure.ANDROID_ID).hashCode()));
          startActivity(intent);<commit_msg>remove link to suspended website<commit_after>package net.ebt.muzei.miyazaki.activity;


import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;

import net.ebt.muzei.miyazaki.BuildConfig;
import net.ebt.muzei.miyazaki.R;
import net.ebt.muzei.miyazaki.app.MuzeiMiyazakiApplication;
import net.ebt.muzei.miyazaki.model.Artwork;
import net.ebt.muzei.miyazaki.service.MuzeiMiyazakiService;
import net.ebt.muzei.miyazaki.util.UiUtils;
import net.ebt.muzei.miyazaki.util.Utils;

import java.util.List;
import java.util.logging.Level;

import static net.ebt.muzei.miyazaki.Constants.ACTION_RELOAD;
import static net.ebt.muzei.miyazaki.Constants.CURRENT_PREF_NAME;
import static net.ebt.muzei.miyazaki.Constants.DEFAULT_INTERVAL;
import static net.ebt.muzei.miyazaki.Constants.INTERVALS;
import static net.ebt.muzei.miyazaki.Constants.MUZEI_COLOR;
import static net.ebt.muzei.miyazaki.Constants.MUZEI_FRAME;
import static net.ebt.muzei.miyazaki.Constants.MUZEI_INTERVAL;
import static net.ebt.muzei.miyazaki.Constants.MUZEI_WIFI;

public class MuzeiMiyazakiSettings extends FragmentActivity {

  private static final String TAG = "MuzeiMiyazakiSettings";
  private static final float ALPHA_DEACTIVATED = 0.3f;

  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    final String muzeiPackageId = Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN ? "net.nurik.roman.muzei" : "net.nurik.roman.muzei.muik";
    final SharedPreferences settings = getApplicationContext().getSharedPreferences(CURRENT_PREF_NAME, Context.MODE_PRIVATE);

    if (getIntent() != null && getIntent().getAction() != null && getIntent().getAction().equals(Intent.ACTION_MAIN)) {
      try {
        Intent launchIntent = getPackageManager().getLaunchIntentForPackage(muzeiPackageId);
        if (launchIntent != null) {

          if (!settings.getBoolean("onboarding", false)) {
            Toast.makeText(this, getResources().getString(R.string.setup_muzei), Toast.LENGTH_LONG).show();
          }
          launchIntent.addCategory(Intent.CATEGORY_DEFAULT);
          launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
          startActivity(launchIntent);
          finish();
          return;

        } else {
          Toast.makeText(this, getResources().getString(R.string.install_muzei), Toast.LENGTH_LONG).show();
          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setData(Uri.parse("market://details?id=" + muzeiPackageId));
          startActivity(intent);
          finish();
          return;
        }
      } catch (Throwable e) {
        // No playstore
      }
    }

    setContentView(R.layout.settings);

    int interval = settings.getInt(MUZEI_INTERVAL, DEFAULT_INTERVAL);

    final View colors = findViewById(R.id.colors);
    final SeekBar seekBar = (SeekBar) findViewById(R.id.muzei_interval);
    final CheckBox wifi = (CheckBox) findViewById(R.id.muzei_wifi);
    final TextView configLabel = (TextView) findViewById(R.id.muzei_config_label);
    final TextView label = (TextView) findViewById(R.id.muzei_label);
    configLabel.setText("Refresh every " + Utils.formatDuration(INTERVALS.get(interval)));

    seekBar.setMax(INTERVALS.size() - 1);
    seekBar.setProgress(interval);
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

      @Override
      public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        label.setText(Utils.formatDuration(INTERVALS.get(progress)).toUpperCase());
      }

      @Override
      public void onStartTrackingTouch(SeekBar seekBar) {
        configLabel.setVisibility(View.INVISIBLE);
        colors.setVisibility(View.GONE);
        label.setVisibility(View.VISIBLE);
      }

      @Override
      public void onStopTrackingTouch(SeekBar seekBar) {
        label.setText(null);
        label.setVisibility(View.GONE);
        configLabel.setText("Refresh every " + Utils.formatDuration(INTERVALS.get(seekBar.getProgress())));
        configLabel.setVisibility(View.VISIBLE);
        colors.setVisibility(View.VISIBLE);

        SharedPreferences.Editor editor = settings.edit();
        editor.putInt(MUZEI_INTERVAL, seekBar.getProgress());
        editor.commit();

        Intent intent = new Intent(MuzeiMiyazakiService.ACTION_RESCHEDULE);
        intent.setClass(seekBar.getContext(), MuzeiMiyazakiService.class);
        startService(intent);
      }
    });

    wifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
      @Override
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(MUZEI_WIFI, isChecked);
        editor.commit();
      }
    });

    wifi.setChecked(settings.getBoolean(MUZEI_WIFI, true));
    label.setVisibility(View.GONE);

    findViewById(R.id.seeall).setVisibility(View.GONE);
    findViewById(R.id.seeall).setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        try {
          Intent intent = new Intent(Intent.ACTION_VIEW);
          intent.setData(Uri.parse("http://muzeighibli.net?jsessionid=" + String.valueOf(System.currentTimeMillis()).hashCode() + "&a=" + Settings.Secure.getString(MuzeiMiyazakiSettings.this.getContentResolver(), Settings.Secure.ANDROID_ID).hashCode()));
          startActivity(intent);
{'fraction_non_alphanumeric': 0.11056594196768463, 'fraction_numerical': 0.0006767616952880467, 'mean_word_length': 4.052136752136752, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1795543', 'n_tokens_mistral': 3767, 'n_tokens_neox': 3663, 'n_words': 544}