@Override public void call(final Subscriber<? super String> subscriber) { final OnPrimaryClipChangedListener listener = new OnPrimaryClipChangedListener() { @Override public void onPrimaryClipChanged() { if (!subscriber.isUnsubscribed()) { propagate(subscriber); } } }; clipboard.addPrimaryClipChangedListener(listener); subscriber.add(new BaseUnsubscription() { @Override protected void onUnsubscribe() { clipboard.removePrimaryClipChangedListener(listener); } }); propagate(subscriber); }
@Override public void call(final Subscriber<? super Intent> subscriber) { final OnPrimaryClipChangedListener listener = new OnPrimaryClipChangedListener() { @Override public void onPrimaryClipChanged() { if (!subscriber.isUnsubscribed()) { propagate(subscriber); } } }; clipboard.addPrimaryClipChangedListener(listener); subscriber.add(new BaseUnsubscription() { @Override protected void onUnsubscribe() { clipboard.removePrimaryClipChangedListener(listener); } }); propagate(subscriber); }
@Override public void call(final Subscriber<? super ClipData> subscriber) { final OnPrimaryClipChangedListener listener = new OnPrimaryClipChangedListener() { @Override public void onPrimaryClipChanged() { if (!subscriber.isUnsubscribed()) { propagate(subscriber); } } }; clipboard.addPrimaryClipChangedListener(listener); subscriber.add(new BaseUnsubscription() { @Override protected void onUnsubscribe() { clipboard.removePrimaryClipChangedListener(listener); } }); propagate(subscriber); }
@Override public void call(final Subscriber<? super Uri> subscriber) { final OnPrimaryClipChangedListener listener = new OnPrimaryClipChangedListener() { @Override public void onPrimaryClipChanged() { if (!subscriber.isUnsubscribed()) { propagate(subscriber); } } }; clipboard.addPrimaryClipChangedListener(listener); subscriber.add(new BaseUnsubscription() { @Override protected void onUnsubscribe() { clipboard.removePrimaryClipChangedListener(listener); } }); propagate(subscriber); }
@Override protected OnPrimaryClipChangedListener createListener() { return new OnPrimaryClipChangedListener() { public void onPrimaryClipChanged() { performClipboardCheck(); } }; }
public void setListener(final Context context, final Runnable listener) { ClipboardManager clipboard = (ClipboardManager) context.getSystemService(context.CLIPBOARD_SERVICE); clipboard.addPrimaryClipChangedListener(new OnPrimaryClipChangedListener() { public void onPrimaryClipChanged() { listener.run(); } }); }
@Implementation public void setPrimaryClip(ClipData clip) { if (clip != null) { clip.prepareToLeaveProcess(); } this.clip = clip; for (OnPrimaryClipChangedListener listener : listeners) { listener.onPrimaryClipChanged(); } }
@Implementation public void addPrimaryClipChangedListener(OnPrimaryClipChangedListener listener) { listeners.add(listener); }
@Implementation public void removePrimaryClipChangedListener(OnPrimaryClipChangedListener listener) { listeners.remove(listener); }