1 package com.freerdp.freerdpcore.utils;
3 import android.annotation.TargetApi;
4 import android.content.ClipData;
5 import android.content.ClipboardManager;
6 import android.content.Context;
7 import android.os.Build.VERSION;
8 import android.os.Build.VERSION_CODES;
15 if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB)
16 return new PreHCClipboardManager(ctx);
18 return new HCClipboardManager(ctx);
21 public abstract void setClipboardData(String data);
27 public abstract void getPrimaryClipManually();
30 void onClipboardChanged(String data);
36 public PreHCClipboardManager(Context ctx)
40 @Override
public void setClipboardData(String data)
44 @Override
public void addClipboardChangedListener(OnClipboardChangedListener listener)
49 public void removeClipboardboardChangedListener(OnClipboardChangedListener listener)
53 @Override
public void getPrimaryClipManually()
59 private static class HCClipboardManager
60 extends ClipboardManagerProxy implements ClipboardManager.OnPrimaryClipChangedListener
62 private ClipboardManager mClipboardManager;
63 private OnClipboardChangedListener mListener;
65 public HCClipboardManager(Context ctx)
67 mClipboardManager = (ClipboardManager)ctx.getSystemService(Context.CLIPBOARD_SERVICE);
70 @Override
public void setClipboardData(String data)
72 mClipboardManager.setPrimaryClip(
73 ClipData.newPlainText(
"rdp-clipboard", data ==
null ?
"" : data));
76 @Override
public void onPrimaryClipChanged()
78 ClipData clip = mClipboardManager.getPrimaryClip();
81 if (clip !=
null && clip.getItemCount() > 0)
83 CharSequence cs = clip.getItemAt(0).getText();
87 if (mListener !=
null)
89 mListener.onClipboardChanged(data);
93 @Override
public void addClipboardChangedListener(OnClipboardChangedListener listener)
96 mClipboardManager.addPrimaryClipChangedListener(
this);
100 public void removeClipboardboardChangedListener(OnClipboardChangedListener listener)
103 mClipboardManager.removePrimaryClipChangedListener(
this);
106 @Override
public void getPrimaryClipManually()
108 onPrimaryClipChanged();