Observable addObserver - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Observable addObserver method.

This code example shows how to use the following methods:addObserver
            mSettingsObserver = new Observer() {
                public void update(Observable o, Object arg) {
                    updateLocationToggles(); 
                } 
            }; 
            mContentQueryMap.addObserver(mSettingsObserver);
        } 
    } 
 
    @Override 
    public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
 
        if (preference == mNetwork) {
            Settings.Secure.setLocationProviderEnabled(getContentResolver(),
                    LocationManager.NETWORK_PROVIDER, mNetwork.isChecked());
        } else if (preference == mGps) {
            boolean enabled = mGps.isChecked();
            Settings.Secure.setLocationProviderEnabled(getContentResolver(),
                    LocationManager.GPS_PROVIDER, enabled);
            if (mAssistedGps != null) {
6
CodeRank
This code example shows how to use the following methods:getRows, getValues, addObserver
                        new String[] {
                            Settings.System.NAME,
                            Settings.System.VALUE,
                        }, null, null, null); 
 
                final ContentQueryMap cqm = new ContentQueryMap(
                        cursor, Settings.System.NAME, true, null);
                // Get the current state of the CQM. This forces a requery and means that the 
                // call to getValues() below won't do a requery(). 
                cqm.getRows();
                 
                // The cache won't notice changes until the loop runs. 
                Settings.System.putString(r, "test", "New Value");
                ContentValues v = cqm.getValues("test");
                String value = v.getAsString(Settings.System.VALUE);
                assertEquals("Value", value);
 
                // Use an Observer to find out when the cache does update. 
                cqm.addObserver(new Observer() {
                    public void update(Observable o, Object arg) {

6
CodeRank
This code example shows how to use the following methods:addObserver
    private float minTemp = 200;
    private float tempSum = 0.0f;
    private int numReadings;
 
    public StatisticsDisplay(Observable observable) {
        observable.addObserver(this);
    } 
 
    public void update(Observable observable, Object arg) {
        if (observable instanceof WeatherData) {
            WeatherData weatherData = (WeatherData) observable;
            float temp = weatherData.getTemperature();
            tempSum += temp;
            numReadings++;
 
            if (temp > maxTemp) {
                maxTemp = temp;
            } 
 
            if (temp < minTemp) {
4
CodeRank
This code example shows how to use the following methods:addObserver
	private float minTemp = 200;
	private float tempSum= 0.0f;
	private int numReadings;
 
	public StatisticsDisplay(Observable observable) {
		observable.addObserver(this);
	} 
 
	public void update(Observable observable, Object arg) {
		if (observable instanceof WeatherData) {
			WeatherData weatherData = (WeatherData)observable;
			float temp = weatherData.getTemperature();
			tempSum += temp;
			numReadings++;
 
			if (temp > maxTemp) {
				maxTemp = temp;
			} 
  
			if (temp < minTemp) {
4
CodeRank
This code example shows how to use the following methods:addObserver
    private Observable observable;
 
    public ForecastDisplay(Observable observable)
    { 
	this.observable = observable;
	observable.addObserver(this);
    } 
 
    public void update(Observable obs, Object arg)
    { 
	if (obs instanceof WeatherData) {
	    WeatherData weatherData = (WeatherData)obs;
	    lastPressure = currentPressure;
	    currentPressure = weatherData.getPressure();;
	    display(); 
	} 
    } 
 
    public void display() 
    { 
4
CodeRank
This code example shows how to use the following methods:addObserver
    private float minTemp = 200;
    private float tempSum = 0.0f;
    private int numReadings;
 
    public StatisticsDisplay(Observable observable) {
        observable.addObserver(this);
    } 
 
    public void update(Observable observable, Object arg) {
        if (observable instanceof WeatherData) {
            WeatherData weatherData = (WeatherData) observable;
            float temp = weatherData.getTemperature();
            tempSum += temp;
            numReadings++;
 
            if (temp > maxTemp) {
                maxTemp = temp;
            } 
 
            if (temp < minTemp) {
4
CodeRank
This code example shows how to use the following methods:addObserver
	private double temperature;
	private double humidity;
	 
	public CurrentConditionsDisplay(Observable observable) {
		this.observable = observable;
		observable.addObserver(this);
	} 
	 
	/** 
	 * This is called by notifyObservers 
	 * It is part of the Observer interface 
	 * The implementation determines what will  
	 * happen when the state of the Observable changes. 
	 */ 
	public void update(Observable obs, Object arg) {
		//instanceof ËüµÄ×÷ÓÃÊDzâÊÔËü×ó±ßµÄ¶ÔÏóÊÇ·ñÊÇËüÓұߵÄÀàµÄʵÀý£¬·µ»ØbooleanÀàÐ͵ÄÊý¾Ý 
		if (obs instanceof WeatherData) {
			WeatherData weatherData = (WeatherData)obs;
			this.temperature = weatherData.getTemperature();
			this.humidity = weatherData.getHumidity();
4
CodeRank
This code example shows how to use the following methods:addObserver
    private float humidity;
    Observable observable;
     
    public void registerObserver(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    } 
     
    @Override 
    public void update(Observable o, Object arg) {
        if(o instanceof WeatherData){
            WeatherData wd = (WeatherData)o;
            this.temperature = wd.getTemperature();
            this.humidity = wd.getHumidity();
            display(); 
        } 
    } 
 
    @Override 
    public void display() { 
4
CodeRank
This code example shows how to use the following methods:addObserver
    private float humidity;
    private float temperature;
 
    public CurrentConditionsDisplay(Observable observable){
        this.observable = observable;
        observable.addObserver(this);
    } 
 
    public void update(Observable observable,Object arg){
        if (observable instanceof WeatherData){
            WeatherData weatherData = (WeatherData)observable;
            this.temperature = weatherData.getTemperature();
            this.humidity = weatherData.getHumidity();
            display(); 
        } 
    } 
 
    public void display(){ 
        System.out.println("Current conditions: " + temperature);
    } 
4
CodeRank
This code example shows how to use the following methods:addObserver
	private float temperature ;
	private float humidity;
	 
	public CurrentConditionsDisplayUtil(Observable observable){
		this.observable = observable;
		observable.addObserver(this);
	} 
	@Override 
	public void display() { 
		// TODO Auto-generated method stub 
		System.out.println("Current Conditions:"+temperature +"F degrees and " + humidity +"%humidity");
	} 
 
	@Override 
	public void update(Observable obs, Object arg1) {
		// TODO Auto-generated method stub 
		if(obs instanceof WeatherDataUtil){
			WeatherDataUtil weatherDataUtil = (WeatherDataUtil)obs;
			this.temperature = weatherDataUtil.getTemperature();
			this.humidity = weatherDataUtil.getHumidity();
4
CodeRank
addObserver Method Overview
Adds an observer to the set of observers for this object, provided that it is not the same as some observer already in the set.
See Code Examples for other Java 8 Observable Methods: