android.support.v4.app.LoaderManager Java Examples

The following examples show how to use android.support.v4.app.LoaderManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FragmentDelegate.java    From CompositeAndroid with Apache License 2.0 6 votes vote down vote up
public LoaderManager getLoaderManager() {
    if (mPlugins.isEmpty()) {
        return getOriginal().super_getLoaderManager();
    }

    final ListIterator<FragmentPlugin> iterator = mPlugins.listIterator(mPlugins.size());

    final CallFun0<LoaderManager> superCall = new CallFun0<LoaderManager>("getLoaderManager()") {

        @Override
        public LoaderManager call() {
            if (iterator.hasPrevious()) {
                return iterator.previous().getLoaderManager(this);
            } else {
                return getOriginal().super_getLoaderManager();
            }
        }
    };
    return superCall.call();
}
 
Example #2
Source File: SMSConversationsListFragment.java    From BlackList with Apache License 2.0 6 votes vote down vote up
private void loadListViewItems(int listPosition, boolean markSeen, boolean showProgress) {
    if (!isAdded()) {
        return;
    }
    int loaderId = 0;
    ConversationsLoaderCallbacks callbacks =
            new ConversationsLoaderCallbacks(getContext(), listView,
                    listPosition, cursorAdapter, markSeen, showProgress);

    LoaderManager manager = getLoaderManager();
    Loader<?> loader = manager.getLoader(loaderId);
    if (loader == null) {
        // init and run the items loader
        manager.initLoader(loaderId, null, callbacks);
    } else {
        // restart loader
        manager.restartLoader(loaderId, null, callbacks);
    }
}
 
Example #3
Source File: PatientListFragment.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    Log.d(TAG, "onActivityCreated()");
    super.onActivityCreated(savedInstanceState);

    // signal the dispatcher to sync
    mUri = getActivity().getIntent().getData();
    if (mUri == null) {
        mUri = Patients.CONTENT_URI;
    }
    Log.d(TAG, "onActivityCreated(): sync?");
    mAdapter = new PatientCursorAdapter(getActivity(), null, 0);
    setListAdapter(mAdapter);
    mAdapter.setOnScrollCompleteListener(this);
    // Do we sync with server
    delta = getActivity().getResources().getInteger(R.integer.sync_delta_subjects);
    //sync(getActivity(), Subjects.CONTENT_URI);
    LoaderManager.enableDebugLogging(true);
    getActivity().getSupportLoaderManager().initLoader(PATIENTS_LOADER, null, this);
}
 
Example #4
Source File: ItemTradeFragment.java    From MonsterHunter4UDatabase with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setRetainInstance(true);

    // Check for a Item ID as an argument, and find the item
    Bundle args = getArguments();
    if (args != null) {
        long itemInId = args.getLong(ARG_ITEM_IN_ID, -1);
        if (itemInId != -1) {
            LoaderManager lm = getLoaderManager();
            lm.initLoader(R.id.wyporium_trade_detail_fragment, args,
                    new WyporiumTradeLoaderCallbacks());
        }
    }
}
 
Example #5
Source File: CategoryController.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
CategoryController(final Activity activity, LoaderManager loaderManager, View itemView) {
    super(itemView);

    this.activity = activity;
    this.loaderManager = loaderManager;

    appCardsAdapter = new AppPreviewAdapter(activity);

    viewAll = (Button) itemView.findViewById(R.id.view_all_button);
    viewAll.setOnClickListener(onViewAll);

    heading = (TextView) itemView.findViewById(R.id.name);
    image = (FeatureImage) itemView.findViewById(R.id.category_image);
    background = (FrameLayout) itemView.findViewById(R.id.category_background);

    RecyclerView appCards = (RecyclerView) itemView.findViewById(R.id.app_cards);
    appCards.setAdapter(appCardsAdapter);
    appCards.addItemDecoration(new ItemDecorator(activity));

    displayImageOptions = Utils.getDefaultDisplayImageOptionsBuilder()
            .displayer(new FadeInBitmapDisplayer(100, true, true, false))
            .build();
}
 
Example #6
Source File: WeaponBladeDetailFragment.java    From MonsterHunter4UDatabase with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Override and recreate calls from WeaponDetailFragment
    // so we can call HornMelodyLoader after WeaponLoader is finished ----------------------
    setRetainInstance(true);

    // Check for a Weapon ID as an argument, and find the weapon
    Bundle args = getArguments();
    if (args != null) {
        long weaponId = args.getLong(ARG_WEAPON_ID, -1);
        if (weaponId != -1) {
            LoaderManager lm = getLoaderManager();
            lm.initLoader(R.id.weapon_detail_fragment, args, new WeaponLoaderCallbacks2());
        }
    }
    //-------------------------------------------------------------------------------------

}
 
Example #7
Source File: JournalFragment.java    From BlackList with Apache License 2.0 6 votes vote down vote up
private void loadListViewItems(String itemsFilter, boolean deleteItems, int listPosition) {
    if (!isAdded()) {
        return;
    }
    int loaderId = 0;
    JournalItemsLoaderCallbacks callbacks =
            new JournalItemsLoaderCallbacks(getContext(), cursorAdapter,
                    itemsFilter, deleteItems, listView, listPosition);
    LoaderManager manager = getLoaderManager();
    if (manager.getLoader(loaderId) == null) {
        // init and run the items loader
        manager.initLoader(loaderId, null, callbacks);
    } else {
        // restart loader
        manager.restartLoader(loaderId, null, callbacks);
    }
}
 
Example #8
Source File: SMSConversationFragment.java    From BlackList with Apache License 2.0 6 votes vote down vote up
private void loadListViewItems(int threadId, int unreadCount, int listPosition) {
    if (!isAdded()) {
        return;
    }
    int loaderId = 0;
    ConversationLoaderCallbacks callbacks =
            new ConversationLoaderCallbacks(getContext(),
                    threadId, unreadCount, listView, listPosition, cursorAdapter);

    LoaderManager manager = getLoaderManager();
    if (manager.getLoader(loaderId) == null) {
        // init and run the items loader
        manager.initLoader(loaderId, null, callbacks);
    } else {
        // restart loader
        manager.restartLoader(loaderId, null, callbacks);
    }
}
 
Example #9
Source File: ContactsFragment.java    From BlackList with Apache License 2.0 6 votes vote down vote up
private void loadListViewItems(String itemsFilter, boolean deleteItems, int listPosition) {
    if (!isAdded()) {
        return;
    }
    int loaderId = 0;
    ContactsLoaderCallbacks callbacks =
            new ContactsLoaderCallbacks(getContext(), contactType, cursorAdapter,
                    itemsFilter, deleteItems, listView, listPosition);
    LoaderManager manager = getLoaderManager();
    if (manager.getLoader(loaderId) == null) {
        // init and run the items loader
        manager.initLoader(loaderId, null, callbacks);
    } else {
        // restart loader
        manager.restartLoader(loaderId, null, callbacks);
    }
}
 
Example #10
Source File: MainActivity.java    From android-samples with Apache License 2.0 6 votes vote down vote up
private void search(EditText editText) {
    mEditText = editText;
    // Initialize the Loader with id '1239' and callbacks.
    // If the loader doesn't already exist, one is created. Otherwise,
    // the already created Loader is reused. In either case, the
    // LoaderManager will manage the Loader across the Activity/Fragment
    // lifecycle, will receive any new loads once they have completed,
    // and will report this new data back via callbacks.
    LoaderManager lm = getSupportLoaderManager();

    //close any loader that is already running
    lm.destroyLoader(LOADER_ID);

    //init new loader
    lm.initLoader(LOADER_ID, null, this);
}
 
Example #11
Source File: ItemDetailFragment.java    From MonsterHunter4UDatabase with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	setRetainInstance(true);
	
	// Check for a Item ID as an argument, and find the item
	Bundle args = getArguments();
	if (args != null) {
		long itemId = args.getLong(ARG_ITEM_ID, -1);
		if (itemId != -1) {
			LoaderManager lm = getLoaderManager();
			lm.initLoader(R.id.item_detail_fragment, args, new ItemLoaderCallbacks());
		}
	}
}
 
Example #12
Source File: LocationDetailFragment.java    From MonsterHunter4UDatabase with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	setRetainInstance(true);
	
	// Check for a Item ID as an argument, and find the item
	Bundle args = getArguments();
	if (args != null) {
		long locationId = args.getLong(ARG_LOCATION_ID, -1);
		if (locationId != -1) {
			LoaderManager lm = getLoaderManager();
			lm.initLoader(R.id.location_detail_fragment, args, new LocationLoaderCallbacks());
		}
	}
}
 
Example #13
Source File: WeaponDetailFragment.java    From MonsterHunter4UDatabase with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	setRetainInstance(true);

	// Check for a Weapon ID as an argument, and find the weapon
	Bundle args = getArguments();
	if (args != null) {
		long weaponId = args.getLong(ARG_WEAPON_ID, -1);
		if (weaponId != -1) {
			LoaderManager lm = getLoaderManager();
			lm.initLoader(R.id.weapon_detail_fragment, args, new WeaponLoaderCallbacks());
		}
	}
}
 
Example #14
Source File: ArmorDetailFragment.java    From MonsterHunter4UDatabase with MIT License 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	setRetainInstance(true);
	setHasOptionsMenu(true);

	// Check for a Item ID as an argument, and find the item
	Bundle args = getArguments();
	if (args != null) {
		long armorId = args.getLong(ARG_ARMOR_ID, -1);
		if (armorId != -1) {
			LoaderManager lm = getLoaderManager();
			lm.initLoader(R.id.armor_detail_fragment, args,
					new ArmorLoaderCallbacks());
		}
	}
}
 
Example #15
Source File: CacheOnlyCommentRepository.java    From PhilHackerNews with MIT License 5 votes vote down vote up
public CacheOnlyCommentRepository(LoaderManager loaderManager,
                                  Context context,
                                  DataConverter<List<Item>, Cursor> dataConverter) {
    mLoaderManager = loaderManager;
    mContext = context;
    mDataConverter = dataConverter;
}
 
Example #16
Source File: CursorDataSource.java    From NIM_Android_UIKit with MIT License 5 votes vote down vote up
/**
 * @param activity 用于初始化LoaderManager,需要兼容到2.3
 * @param path     指定扫描的文件夹目录,可以为 null,表示扫描所有图片
 */
CursorDataSource(FragmentActivity activity, String path) {
    this.activity = activity;

    LoaderManager loaderManager = activity.getSupportLoaderManager();
    if (path == null) {
        // 加载所有的图片
        loader = loaderManager.initLoader(getId(LOADER_ALL), null, this);
    } else {
        // 加载指定目录的图片
        Bundle bundle = new Bundle();
        bundle.putString("path", path);
        loader = loaderManager.initLoader(getId(LOADER_CATEGORY), bundle, this);
    }
}
 
Example #17
Source File: PluginClientFragmentActivity.java    From AndroidPlugin with MIT License 5 votes vote down vote up
@Override
public LoaderManager getSupportLoaderManager() {
	if (mProxyActivity == null) {
		return super.getSupportLoaderManager();
	}
	return mProxyActivity.getSupportLoaderManager();
}
 
Example #18
Source File: LoaderManagerCreator.java    From android-atleap with Apache License 2.0 5 votes vote down vote up
/**
 * Init Loader Manager for fragment
 * @param fragment fragment
 * @param callbacks callbacks
 * @param args arguments for loader construction
 * @param <T>
 */
public <T> LoaderManagerCreator(Fragment fragment, LoaderManager.LoaderCallbacks<T> callbacks, Bundle args) {
    this(
            fragment.getActivity().getApplicationContext(),
            fragment.getLoaderManager(),
            (int) HashUtil.longHash(((Object) fragment).getClass(), fragment.getArguments(), callbacks),
            callbacks,
            args
    );
}
 
Example #19
Source File: HomeFragment.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Make a dummy query to create/update database if needed
    LoaderManager lm = getLoaderManager();
    lm.initLoader(R.id.home_fragment, null, new DummyLoaderCallbacks());
}
 
Example #20
Source File: AttendeeListFragment.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
    if (key.equals(GutenbergApplication.PREF_EVENT_ID)) {
        Bundle args = new Bundle(getArguments());
        args.putString(ARG_EVENT_ID, prefs.getString(key, null));
        LoaderManager manager = getLoaderManager();
        manager.destroyLoader(LOADER_ATTENDEES);
        manager.initLoader(LOADER_ATTENDEES, args, this);
    }
}
 
Example #21
Source File: AttendeeListFragment.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Bundle args = new Bundle(getArguments());
    args.putString(ARG_EVENT_ID, GutenbergApplication.from(getActivity()).getEventId());
    LoaderManager manager = getLoaderManager();
    manager.initLoader(LOADER_ATTENDEES, args, this);
    if (args.getBoolean(ARG_ONLY_COMING)) {
        manager.initLoader(LOADER_COUNT_ALL_ATTENDEES, args, this);
    }
}
 
Example #22
Source File: RepositoriesLoadable.java    From android-oauth-client with Apache License 2.0 5 votes vote down vote up
RepositoriesLoadable(LoaderManager loaderManager, int loaderId,
        LoaderCallbacks<Result<Repositories>> callbacks) {
    super();
    this.mLoaderManager = Preconditions.checkNotNull(loaderManager);
    this.mLoaderId = loaderId;
    this.mCallbacks = callbacks;
}
 
Example #23
Source File: TimelineFragment.java    From attendee-checkin with Apache License 2.0 5 votes vote down vote up
@Override
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
    if (key.equals(GutenbergApplication.PREF_EVENT_ID)) {
        LoaderManager manager = getLoaderManager();
        Bundle args = new Bundle();
        args.putString(ARG_EVENT_ID, prefs.getString(key, null));
        manager.destroyLoader(LOADER_ATTENDEES);
        manager.initLoader(LOADER_ATTENDEES, args, this);
        manager.destroyLoader(LOADER_EVENT);
        manager.initLoader(LOADER_EVENT, args, this);
    }
}
 
Example #24
Source File: PhotosLoadable.java    From android-oauth-client with Apache License 2.0 5 votes vote down vote up
PhotosLoadable(LoaderManager loaderManager, int loaderId,
        LoaderCallbacks<Result<ContactsPhotos>> callbacks) {
    super();
    this.mLoaderManager = Preconditions.checkNotNull(loaderManager);
    this.mLoaderId = loaderId;
    this.mCallbacks = callbacks;
}
 
Example #25
Source File: AlbumPresenter.java    From AlbumSelector with Apache License 2.0 5 votes vote down vote up
public AlbumPresenter(
        @NonNull AlbumRepository albumRepository,
        @NonNull LoaderManager loaderManager,
        @NonNull AlbumContract.View albumView) {
    mLoadManager = checkNotNull(loaderManager, "loader manager cannot be null");
    mAlbumView = checkNotNull(albumView, "albumView cannot be null");
    mAlbumRepository = checkNotNull(albumRepository, "albumRepository cannot be null");
    //为mAlbumView 设置Presenter
    mAlbumView.setPresenter(this);
}
 
Example #26
Source File: MonsterSummaryFragment.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
@Override
public void onLoadFinished(Loader<Monster> loader, Monster run) {
	mMonster = run;
          LoaderManager lm = getLoaderManager();
	Bundle args = new Bundle();
          args.putLong(ARG_MONSTER_ID, run.getId());

          // Load ailments data after monster is found
          lm.initLoader(R.id.monster_ailments, args, new MonsterAilmentsLoaderCallbacks());
}
 
Example #27
Source File: QuestDetailFragment.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	
	// Check for a Quest ID as an argument, and find the monster
	Bundle args = getArguments();
	if (args != null) {
		long questId = args.getLong(ARG_QUEST_ID, -1);
		if (questId != -1) {
			LoaderManager lm = getLoaderManager();
			lm.initLoader(R.id.quest_detail_fragment, args, new QuestLoaderCallbacks());
		}
	}
}
 
Example #28
Source File: MonsterDamageFragment.java    From MonsterHunter4UDatabase with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setRetainInstance(true);
	
	// Check for a Monster ID as an argument, and find the monster
	Bundle args = getArguments();
	if (args != null) {
		long monsterId = args.getLong(ARG_MONSTER_ID, -1);
		if (monsterId != -1) {
			LoaderManager lm = getLoaderManager();
			lm.initLoader(R.id.monster_detail_fragment, args, new MonsterLoaderCallbacks());
		}
	}
}
 
Example #29
Source File: ImageDataSource.java    From imsdk-android with MIT License 5 votes vote down vote up
/**
 * @param activity       用于初始化LoaderManager,需要兼容到2.3
 * @param path           指定扫描的文件夹目录,可以为 null,表示扫描所有图片
 * @param loadedListener 图片加载完成的监听
 */
public ImageDataSource(FragmentActivity activity, String path, OnImagesLoadedListener loadedListener) {
    this.activity = activity;
    this.loadedListener = loadedListener;

    LoaderManager loaderManager = activity.getSupportLoaderManager();
    if (path == null) {
        loaderManager.initLoader(LOADER_ALL, null, this);//加载所有的图片
    } else {
        //加载指定目录的图片
        Bundle bundle = new Bundle();
        bundle.putString("path", path);
        loaderManager.initLoader(LOADER_CATEGORY, bundle, this);
    }
}
 
Example #30
Source File: RepositoryModule.java    From PhilHackerNews with MIT License 5 votes vote down vote up
@Provides
Observable<List<Item>> provideApiStoriesObservable(LoaderManager loaderManager,
                                                               CursorLoader storyLoader,
                                                                 DataConverter<List<Item>, Cursor> cursorDataConverter) {
    return Observable.create(new LoaderInitializingOnSubscribe<>(API_STORY_LOADER, loaderManager, storyLoader, cursorDataConverter))
            .observeOn(AndroidSchedulers.mainThread());
}