it.tidalwave.bluebill.mobile.android.BlueBillLookup Maven / Gradle / Ivy
/***********************************************************************************************************************
*
* blueBill Mobile - open source birdwatching
* ==========================================
*
* Copyright (C) 2009, 2010 by Tidalwave s.a.s. (http://www.tidalwave.it)
* http://bluebill.tidalwave.it/mobile/
*
***********************************************************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
***********************************************************************************************************************
*
* $Id: BlueBillLookup.java,v 7922dab344d7 2010/06/24 01:04:55 fabrizio $
*
**********************************************************************************************************************/
package it.tidalwave.bluebill.mobile.android;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.openide.util.Lookup;
import org.openide.util.LookupListener;
import org.openide.util.lookup.Lookups;
import it.tidalwave.mobile.io.FileSystem;
import it.tidalwave.mobile.util.LazyLookup;
import it.tidalwave.mobile.location.LocationFinder;
import it.tidalwave.mobile.location.LocationPreferences;
import it.tidalwave.mobile.preferences.PreferencesAdapter;
import it.tidalwave.bluebill.observation.ObservationManager;
import it.tidalwave.bluebill.mobile.DefaultGeneralPreferences;
import it.tidalwave.bluebill.mobile.GeneralPreferences;
import it.tidalwave.bluebill.mobile.observation.ObservationClipboard;
import it.tidalwave.bluebill.mobile.observation.BlueBillObservationManager;
import it.tidalwave.bluebill.mobile.observation.DefaultObservationPreferences;
import it.tidalwave.bluebill.mobile.observation.ObservationPreferences;
import it.tidalwave.bluebill.mobile.taxonomy.TaxonomyPreferences;
import it.tidalwave.bluebill.mobile.network.NetworkingPreferences;
import it.tidalwave.bluebill.mobile.network.DefaultNetworkingPreferences;
import it.tidalwave.bluebill.mobile.share.SharingPreferences;
import it.tidalwave.bluebill.mobile.share.DefaultSharingPreferences;
import it.tidalwave.bluebill.mobile.android.taxonomy.AndroidTaxonomyPreferences;
import android.content.Context;
import android.location.LocationManager;
import android.preference.PreferenceManager;
import it.tidalwave.bluebill.factsheet.FactSheetFactory;
import it.tidalwave.bluebill.factsheet.impl.DefaultFactSheetFactory;
//import it.tidalwave.bluebill.factsheet.xenocanto.XenoCantoFactSheetProvider;
import it.tidalwave.bluebill.othermarshallers.TripleMarshallerFactoryImpl;
import it.tidalwave.bluebill.othermarshallers.TripleUnmarshallerFactoryImpl;
import it.tidalwave.mobile.android.io.AndroidFileSystem;
import it.tidalwave.mobile.android.location.AndroidLocationFinder;
import it.tidalwave.mobile.android.preferences.AndroidPreferencesAdapter;
import it.tidalwave.mobile.android.location.AndroidLocationPreferences;
import it.tidalwave.mobile.android.media.AndroidMediaPlayer;
import it.tidalwave.mobile.media.MediaPlayer;
import it.tidalwave.semantic.io.json.spi.TripleMarshallerFactory;
import it.tidalwave.semantic.io.json.spi.TripleUnmarshallerFactory;
/***********************************************************************************************************************
*
* @author Fabrizio Giudici
* @version $Id: $
*
**********************************************************************************************************************/
public class BlueBillLookup extends Lookup
{
private final LazyLookup lazyLookup = new LazyLookup();
@CheckForNull
private Lookup extraLookup = Lookup.EMPTY;
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public BlueBillLookup()
{
lazyLookup.register(FactSheetFactory.class, DefaultFactSheetFactory.class);
// lazyLookup.register(FactSheetProvider.class, XenoCantoFactSheetProvider.class);
lazyLookup.register(FileSystem.class, AndroidFileSystem.class);
lazyLookup.register(GeneralPreferences.class, DefaultGeneralPreferences.class);
lazyLookup.register(LocationFinder.class, AndroidLocationFinder.class);
lazyLookup.register(LocationPreferences.class, AndroidLocationPreferences.class);
lazyLookup.register(MediaPlayer.class, AndroidMediaPlayer.class);
lazyLookup.register(NetworkingPreferences.class, DefaultNetworkingPreferences.class);
lazyLookup.register(ObservationClipboard.class, ObservationClipboard.class);
lazyLookup.register(ObservationManager.class, BlueBillObservationManager.class);
lazyLookup.register(ObservationPreferences.class, DefaultObservationPreferences.class);
lazyLookup.register(PreferencesAdapter.class, AndroidPreferencesAdapter.class);
lazyLookup.register(SharingPreferences.class, DefaultSharingPreferences.class);
lazyLookup.register(TaxonomyPreferences.class, AndroidTaxonomyPreferences.class);
lazyLookup.register(TripleMarshallerFactory.class, TripleMarshallerFactoryImpl.class);
lazyLookup.register(TripleUnmarshallerFactory.class,TripleUnmarshallerFactoryImpl.class);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@CheckForNull
public T lookup (final @Nonnull Class clazz)
{
final T r = extraLookup.lookup(clazz);
return (r != null) ? r : lazyLookup.lookup(clazz);
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
@Override @Nonnull
public Result lookup (final @Nonnull Template template)
{
return new Result()
{
@Override
public void addLookupListener(LookupListener ll)
{
}
@Override
public void removeLookupListener(LookupListener ll)
{
}
@Override
public Collection extends T> allInstances()
{
final List results = new ArrayList();
results.addAll(extraLookup.lookup(template).allInstances());
results.addAll(lazyLookup.lookup(template).allInstances());
return results;
}
};
}
/*******************************************************************************************************************
*
*
******************************************************************************************************************/
public void setContext (final @Nonnull Context context)
{
extraLookup = Lookups.fixed(BlueBillLookup.class.getClassLoader(),
context,
context.getAssets(),
PreferenceManager.getDefaultSharedPreferences(context),
(LocationManager)context.getSystemService(Context.LOCATION_SERVICE));
}
}