<commit_before>package com.afollestad.silk;

import android.content.Context;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;
import android.util.Base64;
import android.util.Log;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.Serializable;

/**
 * Various convenience methods.
 *
 * @author <NAME> (afollestad)
 */
public class Silk {

    /**
     * Checks if the device is currently online, works for both wifi and mobile networks.
     */
    public static boolean isOnline(Context context) {
        if (context == null)
            return false;
        boolean state = false;
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifiNetwork != null)
            state = wifiNetwork.isConnectedOrConnecting();
        NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (mobileNetwork != null)
            state = mobileNetwork.isConnectedOrConnecting();
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        if (activeNetwork != null)
            state = activeNetwork.isConnectedOrConnecting();
        return state;
    }

    /**
     * Detects whether or not the device is a tablet.
     */
    public static boolean isTablet(Context context) {
        return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
    }

    /**
     * Clears out preferences and files persisted for Silk.
     */
    public static void clearPersistence(Context context) {
        context.getSharedPreferences("feed_last_update", 0).edit().clear().commit();
        context.getSharedPreferences("[silk-cache-expirations]", 0).edit().clear().commit();
        context.getSharedPreferences("[silk-cache-limiters]", 0).edit().clear().commit();
        File cacheDir = new File(Environment.getExternalStorageDirectory(), ".silk_cache");
        File[] files = cacheDir.listFiles();
        if (files != null && files.length > 0) {
            for (File fi : files) fi.delete();
        }
        cacheDir.delete();<commit_msg>Updates<commit_after>package com.afollestad.silk;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Environment;
import android.util.Base64;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.Serializable;
import java.util.List;

/**
 * Various convenience methods.
 *
 * @author <NAME> (afollestad)
 */
public class Silk {

    /**
     * Checks if the device is currently online, works for both wifi and mobile networks.
     */
    public static boolean isOnline(Context context) {
        if (context == null)
            return false;
        boolean state = false;
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo wifiNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        if (wifiNetwork != null)
            state = wifiNetwork.isConnectedOrConnecting();
        NetworkInfo mobileNetwork = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        if (mobileNetwork != null)
            state = mobileNetwork.isConnectedOrConnecting();
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        if (activeNetwork != null)
            state = activeNetwork.isConnectedOrConnecting();
        return state;
    }

    /**
     * Checks if there's any apps available to open a certain intent on the current device.
     */
    public static boolean isIntentAvailable(Context context, String action) {
        final PackageManager packageManager = context.getPackageManager();
        final Intent intent = new Intent(action);
        List<ResolveInfo> list = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() > 0;
    }

    /**
     * Detects whether or not the device is a tablet.
     */
    public static boolean isTablet(Context context) {
        return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
    }

    /**
     * Clears out preferences and files persisted for Silk.
     */
    public static void clearPersistence(Context context) {
        context.getSharedPreferences("feed_last_update", 0).edit().clear().commit();
        context.getSharedPreferences("[silk-cache-expirations]", 0).edit().clear().commit();
        context.getSharedPreferences("[silk-cache-limiters]", 0).edit().clear().commit();
        File cacheDir = new File(Environment.getExternalStorageDirectory(), ".silk_cache");
        File[] files = cacheDir.listFiles();
        if (files != null && files.length > 0) {
            for (File fi : files) fi.delete();
        }
        cacheDir.delete();
{'fraction_non_alphanumeric': 0.10564890954594208, 'fraction_numerical': 0.0023239184840900965, 'mean_word_length': 3.364274570982839, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 11, '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': '239541', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1512, 'n_words': 349}