Java Code Examples for android.content.ClipboardManager.OnPrimaryClipChangedListener

The following are top voted examples for showing how to use android.content.ClipboardManager.OnPrimaryClipChangedListener. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: RxClipboard   File: ClipboardHtmlOnSubscribe.java   View source code 6 votes vote down vote up
@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);
}
 
Example 2
Project: RxClipboard   File: ClipboardIntentOnSubscribe.java   View source code 6 votes vote down vote up
@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);
}
 
Example 3
Project: RxClipboard   File: ClipboardClipOnSubscribe.java   View source code 6 votes vote down vote up
@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);
}
 
Example 4
Project: RxClipboard   File: ClipboardUriOnSubscribe.java   View source code 6 votes vote down vote up
@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);
}
 
Example 5
Project: RxClipboard   File: ClipboardStringOnSubscribe.java   View source code 6 votes vote down vote up
@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);
}
 
Example 6
Project: aDictOnCopy   File: DictionaryOnCopyService.java   View source code 5 votes vote down vote up
@Override
protected OnPrimaryClipChangedListener createListener() {
    return new OnPrimaryClipChangedListener() {
        public void onPrimaryClipChanged() {
            performClipboardCheck();
        }
    };
}
 
Example 7
Project: NeoTerm   File: Clipboard.java   View source code 5 votes vote down vote up
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();
		}
	});
}
 
Example 8
Project: FullRobolectricTestSample   File: ShadowClipboardManager.java   View source code 5 votes vote down vote up
@Implementation
public void setPrimaryClip(ClipData clip) {
  if (clip != null) {
     clip.prepareToLeaveProcess();
  }
  this.clip = clip;

  for (OnPrimaryClipChangedListener listener : listeners) {
    listener.onPrimaryClipChanged();
  }
}
 
Example 9
Project: FullRobolectricTestSample   File: ShadowClipboardManager.java   View source code 4 votes vote down vote up
@Implementation
public void addPrimaryClipChangedListener(OnPrimaryClipChangedListener listener) {
  listeners.add(listener);
}
 
Example 10
Project: FullRobolectricTestSample   File: ShadowClipboardManager.java   View source code 4 votes vote down vote up
@Implementation
public void removePrimaryClipChangedListener(OnPrimaryClipChangedListener listener) {
  listeners.remove(listener);
}