<commit_before>package net.zerobandwidth.android.lib.content;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;

import net.zerobandwidth.android.lib.R;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Provides convenience methods and canonical implementations of methods for
 * working with content in general.
 * @since zerobandwidth-net/android 0.1.2 (#27)
 */
@SuppressWarnings( "unused" )                              // This is a library.
public class ContentUtils
{
	protected static final String LOG_TAG = ContentUtils.class.getSimpleName() ;

	/**
	 * A persistent reference to the system's clipboard manager.
	 */
	public static ClipboardManager s_mgrClipboard = null ;

	/**
	 * Retrieves the system's clipboard manager. If an instance is not already
	 * maintained in the class, then it will be fetched and bound there.
	 * @param ctx the context from which to retrieve the manager instance
	 * @return the manager instance
	 */
	public static ClipboardManager getClipboardManager( Context ctx )
	{
		if( s_mgrClipboard == null )
		{
			s_mgrClipboard = ((ClipboardManager)
					( ctx.getSystemService( Context.CLIPBOARD_SERVICE ) )) ;
		}
		return s_mgrClipboard ;
	}

	/**
	 * Copies the specified plain text into the clipboard.
	 * @param ctx the context in which to operate
	 * @param sClipLabel the "label" of the new clipboard item
	 * @param sText the plain text to be copied
	 * @see ClipboardManager#setPrimaryClip(ClipData)
	 */
	public static void copyTextToClipboard( Context ctx, String sClipLabel, String sText )
	{
		ClipData clip = ClipData.newPlainText( sClipLabel, sText ) ;
		getClipboardManager(ctx).setPrimaryClip(clip) ;
	}

	/**
	 * Copies the specified plain text into the clipboard.
	 * The "label" of the new clipboard item is defaulted to the value of the
	 * {@link R.string#app_name} resource, which is usually the name of the
	 * current app.
	 * @param ctx the context in which to operate
	 * @param sText the plain text to be copied
	 * @see ClipboardManager#setPrimaryClip(ClipData)
	 */
	public static void copyTextToClipboard( Context ctx, String sText )
	{ copyTextToClipboard( ctx, ctx.getString(R.string.app_name), sText ) ; }

	/**
	 * Copies the specified plain text into the clipboard.
	 * @param ctx the context in which to operate
	 * @param sClipLabel the "label" of the new clipboard item
	 * @param resText the resource ID of the text to be added to the clipboard
	 * @see ClipboardManager#setPrimaryClip(ClipData)
	 */
	public static void copyTextToClipboard( Context ctx, String sClipLabel, int resText )
	{ copyTextToClipboard( ctx, sClipLabel, ctx.getString(resText) ) ; }

	/**
	 * Copies the specified plain text into the clipboard.
	 * The "label" of the new clipboard item is defaulted to the value of the
	 * {@link R.string#app_name} resource, which is usually the name of the
	 * current app.
	 * @param ctx the context in which to operate
	 * @param resText the resource ID of the text to be added to the clipboard
	 * @see ClipboardManager#setPrimaryClip(ClipData)
	 */
	public static void copyTextToClipboard( Context ctx, int resText )
	{
		copyTextToClipboard( ctx, ctx.getString( R.string.app_name ),
				ctx.getString(resText) ) ;
	}

	/**
	 * Opens the OS-standard "share" dialog, using the specified text content to
	 * be shared.
	 * @param ctx the context in which to open the dialog
	 * @param sText the text to be shared
	 * @param sTitle the title of the dialog
	 */
	public static void shareText( Context ctx, String sText, String sTitle )
	{
		Intent sigShare = new Intent( Intent.ACTION_SEND ) ;
		sigShare.putExtra( Intent.EXTRA_TEXT, sText ) ;
		ctx.startActivity( Intent.createChooser( sigShare, sTitle ) ) ;
	}

	/**
	 * Opens the OS-standard "share" dialog, using the specified text content to
	 * be shared.
	 * @param ctx the context in which to open the dialog
	 * @param sText the text to be shared
	 * @param resTitle the resource ID of the string for the dialog title
	 */
	public static void shareText( Context ctx, String sText, int resTitle )
	{ shareText( ctx, sText, ctx.getString( resTitle ) ) ; }

	/**
	 * Opens the OS-standard "share" dialog, using the specified text content to
	 * be shared.
	 * The title of the dialog is defaulted to the value of
	 * {@link R.string#title_diaShare_default} provided by this library, which
	 * may be overridden in the app that consumes this library.
	 * @param ctx the context in which to operate
	 * @param sText the text to be shared
	 */<commit_msg>(#27) The generalized "share" action now works better.<commit_after>package net.zerobandwidth.android.lib.content;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;

import net.zerobandwidth.android.lib.R;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Provides convenience methods and canonical implementations of methods for
 * working with content in general.
 * @since zerobandwidth-net/android 0.1.2 (#27)
 */
@SuppressWarnings( "unused" )                              // This is a library.
public class ContentUtils
{
	protected static final String LOG_TAG = ContentUtils.class.getSimpleName() ;

	/** MIME type "text/plain" */
	public static final String MIMETYPE_TEXT_PLAIN = "text/plain" ;

	/**
	 * A persistent reference to the system's clipboard manager.
	 */
	public static ClipboardManager s_mgrClipboard = null ;

	/**
	 * Retrieves the system's clipboard manager. If an instance is not already
	 * maintained in the class, then it will be fetched and bound there.
	 * @param ctx the context from which to retrieve the manager instance
	 * @return the manager instance
	 */
	public static ClipboardManager getClipboardManager( Context ctx )
	{
		if( s_mgrClipboard == null )
		{
			s_mgrClipboard = ((ClipboardManager)
					( ctx.getSystemService( Context.CLIPBOARD_SERVICE ) )) ;
		}
		return s_mgrClipboard ;
	}

	/**
	 * Copies the specified plain text into the clipboard.
	 * @param ctx the context in which to operate
	 * @param sClipLabel the "label" of the new clipboard item
	 * @param sText the plain text to be copied
	 * @see ClipboardManager#setPrimaryClip(ClipData)
	 */
	public static void copyTextToClipboard( Context ctx, String sClipLabel, String sText )
	{
		ClipData clip = ClipData.newPlainText( sClipLabel, sText ) ;
		getClipboardManager(ctx).setPrimaryClip(clip) ;
	}

	/**
	 * Copies the specified plain text into the clipboard.
	 * The "label" of the new clipboard item is defaulted to the value of the
	 * {@link R.string#app_name} resource, which is usually the name of the
	 * current app.
	 * @param ctx the context in which to operate
	 * @param sText the plain text to be copied
	 * @see ClipboardManager#setPrimaryClip(ClipData)
	 */
	public static void copyTextToClipboard( Context ctx, String sText )
	{ copyTextToClipboard( ctx, ctx.getString(R.string.app_name), sText ) ; }

	/**
	 * Copies the specified plain text into the clipboard.
	 * @param ctx the context in which to operate
	 * @param sClipLabel the "label" of the new clipboard item
	 * @param resText the resource ID of the text to be added to the clipboard
	 * @see ClipboardManager#setPrimaryClip(ClipData)
	 */
	public static void copyTextToClipboard( Context ctx, String sClipLabel, int resText )
	{ copyTextToClipboard( ctx, sClipLabel, ctx.getString(resText) ) ; }

	/**
	 * Copies the specified plain text into the clipboard.
	 * The "label" of the new clipboard item is defaulted to the value of the
	 * {@link R.string#app_name} resource, which is usually the name of the
	 * current app.
	 * @param ctx the context in which to operate
	 * @param resText the resource ID of the text to be added to the clipboard
	 * @see ClipboardManager#setPrimaryClip(ClipData)
	 */
	public static void copyTextToClipboard( Context ctx, int resText )
	{
		copyTextToClipboard( ctx, ctx.getString( R.string.app_name ),
				ctx.getString(resText) ) ;
	}

	/**
	 * Opens the OS-standard "share" dialog, using the specified text content to
	 * be shared.
	 * @param ctx the context in which to open the dialog
	 * @param sText the text to be shared
	 * @param sTitle the title of the dialog
	 */
	public static void shareText( Context ctx, String sText, String sTitle )
	{
		Intent sigShare = new Intent( Intent.ACTION_SEND ) ;
		sigShare.putExtra( Intent.EXTRA_TEXT, sText ) ;
		sigShare.setType( MIMETYPE_TEXT_PLAIN ) ;
		ctx.startActivity( Intent.createChooser( sigShare, sTitle ) ) ;
	}

	/**
	 * Opens the OS-standard "share" dialog, using the specified text content to
	 * be shared.
	 * @param ctx the context in which to open the dialog
	 * @param sText the text to be shared
	 * @param resTitle the resource ID of the string for the dialog title
	 */
	public static void shareText( Context ctx, String sText, int resTitle )
	{ shareText( ctx, sText, ctx.getString( resTitle ) ) ; }

	/**
	 * Opens the OS-standard "share" dialog, using the specified text content to
	 * be shared.
	 * The title of the dialog is defaulted to the value of
	 * {@link R.string#title_diaShare_default} provided by this library, which
	 * may be overridden in the app that consumes this library.
	 * @param ctx the context in which to operate
	 * @param sText the text to be shared
	 */
{'fraction_non_alphanumeric': 0.08221897200167154, 'fraction_numerical': 0.0012536564981195152, 'mean_word_length': 3.834848484848485, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7253195', 'n_tokens_mistral': 2915, 'n_tokens_neox': 2746, 'n_words': 1086}