<commit_before>package com.github.oryanmat.trellowidget;

import android.app.AlarmManager;
import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.StrictMode;
import android.preference.PreferenceManager;

import com.github.oryanmat.trellowidget.model.BoardList;
import com.github.oryanmat.trellowidget.util.Json;
import com.github.oryanmat.trellowidget.util.TrelloAPIUtil;
import com.github.oryanmat.trellowidget.widget.AlarmReceiver;

public class TrelloWidget extends Application {
    public static final String T_WIDGET = "TWidget";
    public static final String INTERNAL_PREFS = "com.oryanmat.trellowidget.prefs";
    private static final boolean DEBUG = true;

    @Override
    public void onCreate() {
        if (DEBUG) StrictMode.enableDefaults();
        super.onCreate();
        TrelloAPIUtil.init(getApplicationContext());
        startScheduleAlarmThread();
    }

    private void startScheduleAlarmThread() {
        new Thread(new Runnable() {
            public void run() {
                scheduleAlarm(TrelloWidget.this);
            }
        }).start();
    }

    public static void scheduleAlarm(Context context) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
                new Intent(context, AlarmReceiver.class),
                PendingIntent.FLAG_UPDATE_CURRENT);

        int interval = getInterval(context);
        AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        manager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, interval, interval, pendingIntent);
    }

    private static int getInterval(Context context) {
        return Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context)
                .getString(context.getString(R.string.pref_update_interval_key),
                        context.getString(R.string.pref_update_interval_default)));
    }

    public static BoardList getList(Context context, int appWidgetId) {
        return Json.get().fromJson(context.getSharedPreferences(INTERNAL_PREFS, Context.MODE_PRIVATE)
                .getString(String.valueOf(appWidgetId), BoardList.NULL_JSON), BoardList.class);
    }

    public static void putList(Context context, int appWidgetId, BoardList list) {
        context.getSharedPreferences(INTERNAL_PREFS, MODE_PRIVATE)<commit_msg>use ELAPSED_REALTIME for alarm for less wakeups<commit_after>package com.github.oryanmat.trellowidget;

import android.app.AlarmManager;
import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.StrictMode;
import android.preference.PreferenceManager;

import com.github.oryanmat.trellowidget.model.BoardList;
import com.github.oryanmat.trellowidget.util.Json;
import com.github.oryanmat.trellowidget.util.TrelloAPIUtil;
import com.github.oryanmat.trellowidget.widget.AlarmReceiver;

public class TrelloWidget extends Application {
    public static final String T_WIDGET = "TWidget";
    public static final String INTERNAL_PREFS = "com.oryanmat.trellowidget.prefs";
    private static final boolean DEBUG = true;

    @Override
    public void onCreate() {
        if (DEBUG) StrictMode.enableDefaults();
        super.onCreate();
        TrelloAPIUtil.init(getApplicationContext());
        startScheduleAlarmThread();
    }

    private void startScheduleAlarmThread() {
        new Thread(new Runnable() {
            public void run() {
                scheduleAlarm(TrelloWidget.this);
            }
        }).start();
    }

    public static void scheduleAlarm(Context context) {
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0,
                new Intent(context, AlarmReceiver.class),
                PendingIntent.FLAG_UPDATE_CURRENT);

        int interval = getInterval(context);
        AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        manager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, interval, interval, pendingIntent);
    }

    private static int getInterval(Context context) {
        return Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context)
                .getString(context.getString(R.string.pref_update_interval_key),
                        context.getString(R.string.pref_update_interval_default)));
    }

    public static BoardList getList(Context context, int appWidgetId) {
        return Json.get().fromJson(context.getSharedPreferences(INTERNAL_PREFS, Context.MODE_PRIVATE)
                .getString(String.valueOf(appWidgetId), BoardList.NULL_JSON), BoardList.class);
    }

    public static void putList(Context context, int appWidgetId, BoardList list) {
        context.getSharedPreferences(INTERNAL_PREFS, MODE_PRIVATE)
{'fraction_non_alphanumeric': 0.08597748208802457, 'fraction_numerical': 0.00040941658137154553, 'mean_word_length': 3.6935638808837656, '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': '3873034', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1336, 'n_words': 255}