root/java/org/gnu/emacs/EmacsSdk8Clipboard.java

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. setClipboard
  2. ownsClipboard
  3. clipboardExists
  4. getClipboard
  5. getClipboardTargets
  6. getClipboardData

     1 /* Communication module for Android terminals.  -*- c-file-style: "GNU" -*-
     2 
     3 Copyright (C) 2023 Free Software Foundation, Inc.
     4 
     5 This file is part of GNU Emacs.
     6 
     7 GNU Emacs is free software: you can redistribute it and/or modify
     8 it under the terms of the GNU General Public License as published by
     9 the Free Software Foundation, either version 3 of the License, or (at
    10 your option) any later version.
    11 
    12 GNU Emacs is distributed in the hope that it will be useful,
    13 but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 GNU General Public License for more details.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    19 
    20 package org.gnu.emacs;
    21 
    22 /* Importing the entire package instead of just the legacy
    23    ClipboardManager class avoids the deprecation warning.  */
    24 
    25 import android.text.*;
    26 
    27 import android.content.Context;
    28 import android.util.Log;
    29 
    30 import java.io.UnsupportedEncodingException;
    31 
    32 /* This class implements EmacsClipboard for Android 2.2 and other
    33    similarly old systems.  */
    34 
    35 @SuppressWarnings ("deprecation")
    36 public final class EmacsSdk8Clipboard extends EmacsClipboard
    37 {
    38   private static final String TAG = "EmacsSdk8Clipboard";
    39   private ClipboardManager manager;
    40 
    41   public
    42   EmacsSdk8Clipboard ()
    43   {
    44     String what;
    45     Context context;
    46 
    47     what = Context.CLIPBOARD_SERVICE;
    48     context = EmacsService.SERVICE;
    49     manager
    50       = (ClipboardManager) context.getSystemService (what);
    51   }
    52 
    53   /* Set the clipboard text to CLIPBOARD, a string in UTF-8
    54      encoding.  */
    55 
    56   @Override
    57   public void
    58   setClipboard (byte[] bytes)
    59   {
    60     try
    61       {
    62         manager.setText (new String (bytes, "UTF-8"));
    63       }
    64     catch (UnsupportedEncodingException exception)
    65       {
    66         Log.w (TAG, "setClipboard: " + exception);
    67       }
    68   }
    69 
    70   /* Return whether or not Emacs owns the clipboard.  Value is 1 if
    71      Emacs does, 0 if Emacs does not, and -1 if that information is
    72      unavailable.  */
    73 
    74   @Override
    75   public int
    76   ownsClipboard ()
    77   {
    78     return -1;
    79   }
    80 
    81   /* Return whether or not clipboard content currently exists.  */
    82 
    83   @Override
    84   public boolean
    85   clipboardExists ()
    86   {
    87     return manager.hasText ();
    88   }
    89 
    90   /* Return the current content of the clipboard, as plain text, or
    91      NULL if no content is available.  */
    92 
    93   @Override
    94   public byte[]
    95   getClipboard ()
    96   {
    97     String string;
    98     CharSequence text;
    99 
   100     text = manager.getText ();
   101 
   102     if (text == null)
   103       return null;
   104 
   105     string = text.toString ();
   106 
   107     try
   108       {
   109         return string.getBytes ("UTF-8");
   110       }
   111     catch (UnsupportedEncodingException exception)
   112       {
   113         Log.w (TAG, "getClipboard: " + exception);
   114       }
   115 
   116     return null;
   117   }
   118 
   119   /* Return an array of targets currently provided by the
   120      clipboard, or NULL if there are none.  */
   121 
   122   @Override
   123   public byte[][]
   124   getClipboardTargets ()
   125   {
   126     return null;
   127   }
   128 
   129   /* Return the clipboard data for the given target, or NULL if it
   130      does not exist.
   131 
   132      Value is normally an array of three longs: the file descriptor,
   133      the start offset of the data, and its length; length may be
   134      AssetFileDescriptor.UNKOWN_LENGTH, meaning that the data extends
   135      from that offset to the end of the file.
   136 
   137      Do not use this function to open text targets; use `getClipboard'
   138      for that instead, as it will handle selection data consisting
   139      solely of a URI.  */
   140 
   141   @Override
   142   public long[]
   143   getClipboardData (byte[] target)
   144   {
   145     return null;
   146   }
   147 };

/* [<][>][^][v][top][bottom][index][help] */