android.support.v4.app.LoaderManager.LoaderCallbacks Java Examples
The following examples show how to use
android.support.v4.app.LoaderManager.LoaderCallbacks.
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: LoaderManagerImpl.java From letv with Apache License 2.0 | 6 votes |
public <D> Loader<D> initLoader(int id, Bundle args, LoaderCallbacks<D> callback) { if (this.mCreatingLoader) { throw new IllegalStateException("Called while creating a loader"); } LoaderInfo info = (LoaderInfo) this.mLoaders.get(id); if (DEBUG) { Log.v(TAG, "initLoader in " + this + ": args=" + args); } if (info == null) { info = createAndInstallLoader(id, args, callback); if (DEBUG) { Log.v(TAG, " Created new loader " + info); } } else { if (DEBUG) { Log.v(TAG, " Re-using existing loader " + info); } info.mCallbacks = callback; } if (info.mHaveData && this.mStarted) { info.callOnLoadFinished(info.mLoader, info.mData); } return info.mLoader; }
Example #2
Source File: PlurksLoadable.java From android-oauth-client with Apache License 2.0 | 5 votes |
PlurksLoadable(LoaderManager loaderManager, int loaderId, LoaderCallbacks<Result<Timeline>> callbacks) { super(); this.mLoaderManager = Preconditions.checkNotNull(loaderManager); this.mLoaderId = loaderId; this.mCallbacks = callbacks; }
Example #3
Source File: LoadableDecorator.java From android-oauth-client with Apache License 2.0 | 5 votes |
public LoadableDecorator(LoaderCallbacks<Result<T>> callbacks, int loaderId, ListFragment listFragment) { super(); this.mCallbacks = Preconditions.checkNotNull(callbacks); this.mLoaderId = loaderId; this.mListFragment = Preconditions.checkNotNull(listFragment); this.mAdapterView = Preconditions.checkNotNull(listFragment.getListView()); mListFragment.setListShown(false); }
Example #4
Source File: PhotosLoadable.java From android-oauth-client with Apache License 2.0 | 5 votes |
PhotosLoadable(LoaderManager loaderManager, int loaderId, LoaderCallbacks<Result<ContactsPhotos>> callbacks) { super(); this.mLoaderManager = Preconditions.checkNotNull(loaderManager); this.mLoaderId = loaderId; this.mCallbacks = callbacks; }
Example #5
Source File: TweetsLoadable.java From android-oauth-client with Apache License 2.0 | 5 votes |
TweetsLoadable(LoaderManager loaderManager, int loaderId, LoaderCallbacks<Result<Timeline>> callbacks) { super(); this.mLoaderManager = Preconditions.checkNotNull(loaderManager); this.mLoaderId = loaderId; this.mCallbacks = callbacks; }
Example #6
Source File: RepositoriesLoadable.java From android-oauth-client with Apache License 2.0 | 5 votes |
RepositoriesLoadable(LoaderManager loaderManager, int loaderId, LoaderCallbacks<Result<Repositories>> callbacks) { super(); this.mLoaderManager = Preconditions.checkNotNull(loaderManager); this.mLoaderId = loaderId; this.mCallbacks = callbacks; }
Example #7
Source File: LoaderManagerImpl.java From letv with Apache License 2.0 | 5 votes |
private LoaderInfo createAndInstallLoader(int id, Bundle args, LoaderCallbacks<Object> callback) { try { this.mCreatingLoader = true; LoaderInfo info = createLoader(id, args, callback); installLoader(info); return info; } finally { this.mCreatingLoader = false; } }
Example #8
Source File: SupportRequestDispatcher.java From arca-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void execute(final Update request, final UpdateListener listener) { final LoaderCallbacks<?> callbacks = new UpdateLoaderCallbacks(listener); execute(request, callbacks); }
Example #9
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* This TextView is used to display errors and will be hidden if there are no errors */ mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display); /* * A LinearLayoutManager is responsible for measuring and positioning item views within a * RecyclerView into a linear list. This means that it can produce either a horizontal or * vertical list depending on which parameter you pass in to the LinearLayoutManager * constructor. In our case, we want a vertical list, so we pass in the constant from the * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL. * * There are other LayoutManagers available to display your data in uniform grids, * staggered grids, and more! See the developer documentation for more details. */ int recyclerViewOrientation = LinearLayoutManager.VERTICAL; /* * This value should be true if you want to reverse your layout. Generally, this is only * true with horizontal lists that need to support a right-to-left layout. */ boolean shouldReverseLayout = false; LinearLayoutManager layoutManager = new LinearLayoutManager(this, recyclerViewOrientation, shouldReverseLayout); mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. */ mForecastAdapter = new ForecastAdapter(this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* * This ID will uniquely identify the Loader. We can use it, for example, to get a handle * on our Loader at a later point in time through the support LoaderManager. */ int loaderId = FORECAST_LOADER_ID; /* * From MainActivity, we have implemented the LoaderCallbacks interface with the type of * String array. (implements LoaderCallbacks<String[]>) The variable callback is passed * to the call to initLoader below. This means that whenever the loaderManager has * something to notify us of, it will do so through this callback. */ LoaderCallbacks<String[]> callback = MainActivity.this; /* * The second parameter of the initLoader method below is a Bundle. Optionally, you can * pass a Bundle to initLoader that you can then access from within the onCreateLoader * callback. In our case, we don't actually use the Bundle, but it's here in case we wanted * to. */ Bundle bundleForLoader = null; /* * Ensures a loader is initialized and active. If the loader doesn't already exist, one is * created and (if the activity/fragment is currently started) starts the loader. Otherwise * the last created loader is re-used. */ getSupportLoaderManager().initLoader(loaderId, bundleForLoader, callback); Log.d(TAG, "onCreate: registering preference changed listener"); /* * Register MainActivity as an OnPreferenceChangedListener to receive a callback when a * SharedPreference has changed. Please note that we must unregister MainActivity as an * OnSharedPreferenceChanged listener in onDestroy to avoid any memory leaks. */ PreferenceManager.getDefaultSharedPreferences(this) .registerOnSharedPreferenceChangeListener(this); }
Example #10
Source File: FeedLoadable.java From android-oauth-client with Apache License 2.0 | 4 votes |
FeedLoadable(LoaderManager loaderManager, int loaderId, LoaderCallbacks<Result<Feed>> callbacks) { super(); this.mLoaderManager = Preconditions.checkNotNull(loaderManager); this.mLoaderId = loaderId; this.mCallbacks = callbacks; }
Example #11
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* This TextView is used to display errors and will be hidden if there are no errors */ mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display); /* * A LinearLayoutManager is responsible for measuring and positioning item views within a * RecyclerView into a linear list. This means that it can produce either a horizontal or * vertical list depending on which parameter you pass in to the LinearLayoutManager * constructor. In our case, we want a vertical list, so we pass in the constant from the * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL. * * There are other LayoutManagers available to display your data in uniform grids, * staggered grids, and more! See the developer documentation for more details. */ int recyclerViewOrientation = LinearLayoutManager.VERTICAL; /* * This value should be true if you want to reverse your layout. Generally, this is only * true with horizontal lists that need to support a right-to-left layout. */ boolean shouldReverseLayout = false; LinearLayoutManager layoutManager = new LinearLayoutManager(this, recyclerViewOrientation, shouldReverseLayout); mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. */ mForecastAdapter = new ForecastAdapter(this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* * This ID will uniquely identify the Loader. We can use it, for example, to get a handle * on our Loader at a later point in time through the support LoaderManager. */ int loaderId = FORECAST_LOADER_ID; /* * From MainActivity, we have implemented the LoaderCallbacks interface with the type of * String array. (implements LoaderCallbacks<String[]>) The variable callback is passed * to the call to initLoader below. This means that whenever the loaderManager has * something to notify us of, it will do so through this callback. */ LoaderCallbacks<String[]> callback = MainActivity.this; /* * The second parameter of the initLoader method below is a Bundle. Optionally, you can * pass a Bundle to initLoader that you can then access from within the onCreateLoader * callback. In our case, we don't actually use the Bundle, but it's here in case we wanted * to. */ Bundle bundleForLoader = null; /* * Ensures a loader is initialized and active. If the loader doesn't already exist, one is * created and (if the activity/fragment is currently started) starts the loader. Otherwise * the last created loader is re-used. */ getSupportLoaderManager().initLoader(loaderId, bundleForLoader, callback); Log.d(TAG, "onCreate: registering preference changed listener"); }
Example #12
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* This TextView is used to display errors and will be hidden if there are no errors */ mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display); /* * A LinearLayoutManager is responsible for measuring and positioning item views within a * RecyclerView into a linear list. This means that it can produce either a horizontal or * vertical list depending on which parameter you pass in to the LinearLayoutManager * constructor. In our case, we want a vertical list, so we pass in the constant from the * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL. * * There are other LayoutManagers available to display your data in uniform grids, * staggered grids, and more! See the developer documentation for more details. */ int recyclerViewOrientation = LinearLayoutManager.VERTICAL; /* * This value should be true if you want to reverse your layout. Generally, this is only * true with horizontal lists that need to support a right-to-left layout. */ boolean shouldReverseLayout = false; LinearLayoutManager layoutManager = new LinearLayoutManager(this, recyclerViewOrientation, shouldReverseLayout); mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. */ mForecastAdapter = new ForecastAdapter(this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* * This ID will uniquely identify the Loader. We can use it, for example, to get a handle * on our Loader at a later point in time through the support LoaderManager. */ int loaderId = FORECAST_LOADER_ID; /* * From MainActivity, we have implemented the LoaderCallbacks interface with the type of * String array. (implements LoaderCallbacks<String[]>) The variable callback is passed * to the call to initLoader below. This means that whenever the loaderManager has * something to notify us of, it will do so through this callback. */ LoaderCallbacks<String[]> callback = MainActivity.this; /* * The second parameter of the initLoader method below is a Bundle. Optionally, you can * pass a Bundle to initLoader that you can then access from within the onCreateLoader * callback. In our case, we don't actually use the Bundle, but it's here in case we wanted * to. */ Bundle bundleForLoader = null; /* * Ensures a loader is initialized and active. If the loader doesn't already exist, one is * created and (if the activity/fragment is currently started) starts the loader. Otherwise * the last created loader is re-used. */ getSupportLoaderManager().initLoader(loaderId, bundleForLoader, callback); Log.d(TAG, "onCreate: registering preference changed listener"); /* * Register MainActivity as an OnPreferenceChangedListener to receive a callback when a * SharedPreference has changed. Please note that we must unregister MainActivity as an * OnSharedPreferenceChanged listener in onDestroy to avoid any memory leaks. */ PreferenceManager.getDefaultSharedPreferences(this) .registerOnSharedPreferenceChangeListener(this); }
Example #13
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* This TextView is used to display errors and will be hidden if there are no errors */ mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display); /* * A LinearLayoutManager is responsible for measuring and positioning item views within a * RecyclerView into a linear list. This means that it can produce either a horizontal or * vertical list depending on which parameter you pass in to the LinearLayoutManager * constructor. In our case, we want a vertical list, so we pass in the constant from the * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL. * * There are other LayoutManagers available to display your data in uniform grids, * staggered grids, and more! See the developer documentation for more details. */ int recyclerViewOrientation = LinearLayoutManager.VERTICAL; /* * This value should be true if you want to reverse your layout. Generally, this is only * true with horizontal lists that need to support a right-to-left layout. */ boolean shouldReverseLayout = false; LinearLayoutManager layoutManager = new LinearLayoutManager(this, recyclerViewOrientation, shouldReverseLayout); mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. */ mForecastAdapter = new ForecastAdapter(this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* * This ID will uniquely identify the Loader. We can use it, for example, to get a handle * on our Loader at a later point in time through the support LoaderManager. */ int loaderId = FORECAST_LOADER_ID; /* * From MainActivity, we have implemented the LoaderCallbacks interface with the type of * String array. (implements LoaderCallbacks<String[]>) The variable callback is passed * to the call to initLoader below. This means that whenever the loaderManager has * something to notify us of, it will do so through this callback. */ LoaderCallbacks<String[]> callback = MainActivity.this; /* * The second parameter of the initLoader method below is a Bundle. Optionally, you can * pass a Bundle to initLoader that you can then access from within the onCreateLoader * callback. In our case, we don't actually use the Bundle, but it's here in case we wanted * to. */ Bundle bundleForLoader = null; /* * Ensures a loader is initialized and active. If the loader doesn't already exist, one is * created and (if the activity/fragment is currently started) starts the loader. Otherwise * the last created loader is re-used. */ getSupportLoaderManager().initLoader(loaderId, bundleForLoader, callback); Log.d(TAG, "onCreate: registering preference changed listener"); /* * Register MainActivity as an OnPreferenceChangedListener to receive a callback when a * SharedPreference has changed. Please note that we must unregister MainActivity as an * OnSharedPreferenceChanged listener in onDestroy to avoid any memory leaks. */ PreferenceManager.getDefaultSharedPreferences(this) .registerOnSharedPreferenceChangeListener(this); }
Example #14
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* This TextView is used to display errors and will be hidden if there are no errors */ mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display); /* * A LinearLayoutManager is responsible for measuring and positioning item views within a * RecyclerView into a linear list. This means that it can produce either a horizontal or * vertical list depending on which parameter you pass in to the LinearLayoutManager * constructor. In our case, we want a vertical list, so we pass in the constant from the * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL. * * There are other LayoutManagers available to display your data in uniform grids, * staggered grids, and more! See the developer documentation for more details. */ int recyclerViewOrientation = LinearLayoutManager.VERTICAL; /* * This value should be true if you want to reverse your layout. Generally, this is only * true with horizontal lists that need to support a right-to-left layout. */ boolean shouldReverseLayout = false; LinearLayoutManager layoutManager = new LinearLayoutManager(this, recyclerViewOrientation, shouldReverseLayout); mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. */ mForecastAdapter = new ForecastAdapter(this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* * This ID will uniquely identify the Loader. We can use it, for example, to get a handle * on our Loader at a later point in time through the support LoaderManager. */ int loaderId = FORECAST_LOADER_ID; /* * From MainActivity, we have implemented the LoaderCallbacks interface with the type of * String array. (implements LoaderCallbacks<String[]>) The variable callback is passed * to the call to initLoader below. This means that whenever the loaderManager has * something to notify us of, it will do so through this callback. */ LoaderCallbacks<String[]> callback = MainActivity.this; /* * The second parameter of the initLoader method below is a Bundle. Optionally, you can * pass a Bundle to initLoader that you can then access from within the onCreateLoader * callback. In our case, we don't actually use the Bundle, but it's here in case we wanted * to. */ Bundle bundleForLoader = null; /* * Ensures a loader is initialized and active. If the loader doesn't already exist, one is * created and (if the activity/fragment is currently started) starts the loader. Otherwise * the last created loader is re-used. */ getSupportLoaderManager().initLoader(loaderId, bundleForLoader, callback); Log.d(TAG, "onCreate: registering preference changed listener"); /* * Register MainActivity as an OnPreferenceChangedListener to receive a callback when a * SharedPreference has changed. Please note that we must unregister MainActivity as an * OnSharedPreferenceChanged listener in onDestroy to avoid any memory leaks. */ PreferenceManager.getDefaultSharedPreferences(this) .registerOnSharedPreferenceChangeListener(this); }
Example #15
Source File: SupportRequestDispatcher.java From arca-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void execute(final Request<?> request, final LoaderCallbacks<?> callbacks) { final int identifier = request.getIdentifier(); final Bundle bundle = createRequestBundle(request); mLoaderManager.restartLoader(identifier, bundle, callbacks); }
Example #16
Source File: SupportRequestDispatcher.java From arca-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void execute(final Batch request, final BatchListener listener) { final LoaderCallbacks<?> callbacks = new BatchLoaderCallbacks(listener); execute(request, callbacks); }
Example #17
Source File: SupportRequestDispatcher.java From arca-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void execute(final Delete request, final DeleteListener listener) { final LoaderCallbacks<?> callbacks = new DeleteLoaderCallbacks(listener); execute(request, callbacks); }
Example #18
Source File: SupportRequestDispatcher.java From arca-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void execute(final Insert request, final InsertListener listener) { final LoaderCallbacks<?> callbacks = new InsertLoaderCallbacks(listener); execute(request, callbacks); }
Example #19
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* This TextView is used to display errors and will be hidden if there are no errors */ mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display); /* * A LinearLayoutManager is responsible for measuring and positioning item views within a * RecyclerView into a linear list. This means that it can produce either a horizontal or * vertical list depending on which parameter you pass in to the LinearLayoutManager * constructor. In our case, we want a vertical list, so we pass in the constant from the * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL. * * There are other LayoutManagers available to display your data in uniform grids, * staggered grids, and more! See the developer documentation for more details. */ int recyclerViewOrientation = LinearLayoutManager.VERTICAL; /* * This value should be true if you want to reverse your layout. Generally, this is only * true with horizontal lists that need to support a right-to-left layout. */ boolean shouldReverseLayout = false; LinearLayoutManager layoutManager = new LinearLayoutManager(this, recyclerViewOrientation, shouldReverseLayout); mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. */ mForecastAdapter = new ForecastAdapter(this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* * This ID will uniquely identify the Loader. We can use it, for example, to get a handle * on our Loader at a later point in time through the support LoaderManager. */ int loaderId = FORECAST_LOADER_ID; /* * From MainActivity, we have implemented the LoaderCallbacks interface with the type of * String array. (implements LoaderCallbacks<String[]>) The variable callback is passed * to the call to initLoader below. This means that whenever the loaderManager has * something to notify us of, it will do so through this callback. */ LoaderCallbacks<String[]> callback = MainActivity.this; /* * The second parameter of the initLoader method below is a Bundle. Optionally, you can * pass a Bundle to initLoader that you can then access from within the onCreateLoader * callback. In our case, we don't actually use the Bundle, but it's here in case we wanted * to. */ Bundle bundleForLoader = null; /* * Ensures a loader is initialized and active. If the loader doesn't already exist, one is * created and (if the activity/fragment is currently started) starts the loader. Otherwise * the last created loader is re-used. */ getSupportLoaderManager().initLoader(loaderId, bundleForLoader, callback); Log.d(TAG, "onCreate: registering preference changed listener"); // COMPLETED (6) Register MainActivity as a OnSharedPreferenceChangedListener in onCreate PreferenceManager.getDefaultSharedPreferences(this) .registerOnSharedPreferenceChangeListener(this); }
Example #20
Source File: SupportRequestDispatcher.java From arca-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void execute(final Query request, final QueryListener listener) { final LoaderCallbacks<?> callbacks = new QueryLoaderCallbacks(listener); execute(request, callbacks); }
Example #21
Source File: LoaderManagerImpl.java From letv with Apache License 2.0 | 4 votes |
public <D> Loader<D> restartLoader(int id, Bundle args, LoaderCallbacks<D> callback) { if (this.mCreatingLoader) { throw new IllegalStateException("Called while creating a loader"); } LoaderInfo info = (LoaderInfo) this.mLoaders.get(id); if (DEBUG) { Log.v(TAG, "restartLoader in " + this + ": args=" + args); } if (info != null) { LoaderInfo inactive = (LoaderInfo) this.mInactiveLoaders.get(id); if (inactive == null) { if (DEBUG) { Log.v(TAG, " Making last loader inactive: " + info); } info.mLoader.abandon(); this.mInactiveLoaders.put(id, info); } else if (info.mHaveData) { if (DEBUG) { Log.v(TAG, " Removing last inactive loader: " + info); } inactive.mDeliveredData = false; inactive.destroy(); info.mLoader.abandon(); this.mInactiveLoaders.put(id, info); } else if (info.mStarted) { if (DEBUG) { Log.v(TAG, " Current loader is running; attempting to cancel"); } info.cancel(); if (info.mPendingLoader != null) { if (DEBUG) { Log.v(TAG, " Removing pending loader: " + info.mPendingLoader); } info.mPendingLoader.destroy(); info.mPendingLoader = null; } if (DEBUG) { Log.v(TAG, " Enqueuing as new pending loader"); } info.mPendingLoader = createLoader(id, args, callback); return info.mPendingLoader.mLoader; } else { if (DEBUG) { Log.v(TAG, " Current loader is stopped; replacing"); } this.mLoaders.put(id, null); info.destroy(); } } return createAndInstallLoader(id, args, callback).mLoader; }
Example #22
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* This TextView is used to display errors and will be hidden if there are no errors */ mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display); /* * A LinearLayoutManager is responsible for measuring and positioning item views within a * RecyclerView into a linear list. This means that it can produce either a horizontal or * vertical list depending on which parameter you pass in to the LinearLayoutManager * constructor. In our case, we want a vertical list, so we pass in the constant from the * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL. * * There are other LayoutManagers available to display your data in uniform grids, * staggered grids, and more! See the developer documentation for more details. */ int recyclerViewOrientation = LinearLayoutManager.VERTICAL; /* * This value should be true if you want to reverse your layout. Generally, this is only * true with horizontal lists that need to support a right-to-left layout. */ boolean shouldReverseLayout = false; LinearLayoutManager layoutManager = new LinearLayoutManager(this, recyclerViewOrientation, shouldReverseLayout); mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. */ mForecastAdapter = new ForecastAdapter(this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* * This ID will uniquely identify the Loader. We can use it, for example, to get a handle * on our Loader at a later point in time through the support LoaderManager. */ int loaderId = FORECAST_LOADER_ID; /* * From MainActivity, we have implemented the LoaderCallbacks interface with the type of * String array. (implements LoaderCallbacks<String[]>) The variable callback is passed * to the call to initLoader below. This means that whenever the loaderManager has * something to notify us of, it will do so through this callback. */ LoaderCallbacks<String[]> callback = MainActivity.this; /* * The second parameter of the initLoader method below is a Bundle. Optionally, you can * pass a Bundle to initLoader that you can then access from within the onCreateLoader * callback. In our case, we don't actually use the Bundle, but it's here in case we wanted * to. */ Bundle bundleForLoader = null; /* * Ensures a loader is initialized and active. If the loader doesn't already exist, one is * created and (if the activity/fragment is currently started) starts the loader. Otherwise * the last created loader is re-used. */ getSupportLoaderManager().initLoader(loaderId, bundleForLoader, callback); Log.d(TAG, "onCreate: registering preference changed listener"); /* * Register MainActivity as an OnPreferenceChangedListener to receive a callback when a * SharedPreference has changed. Please note that we must unregister MainActivity as an * OnSharedPreferenceChanged listener in onDestroy to avoid any memory leaks. */ PreferenceManager.getDefaultSharedPreferences(this) .registerOnSharedPreferenceChangeListener(this); }
Example #23
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* This TextView is used to display errors and will be hidden if there are no errors */ mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display); /* * A LinearLayoutManager is responsible for measuring and positioning item views within a * RecyclerView into a linear list. This means that it can produce either a horizontal or * vertical list depending on which parameter you pass in to the LinearLayoutManager * constructor. In our case, we want a vertical list, so we pass in the constant from the * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL. * * There are other LayoutManagers available to display your data in uniform grids, * staggered grids, and more! See the developer documentation for more details. */ int recyclerViewOrientation = LinearLayoutManager.VERTICAL; /* * This value should be true if you want to reverse your layout. Generally, this is only * true with horizontal lists that need to support a right-to-left layout. */ boolean shouldReverseLayout = false; LinearLayoutManager layoutManager = new LinearLayoutManager(this, recyclerViewOrientation, shouldReverseLayout); mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. */ mForecastAdapter = new ForecastAdapter(this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* * This ID will uniquely identify the Loader. We can use it, for example, to get a handle * on our Loader at a later point in time through the support LoaderManager. */ int loaderId = FORECAST_LOADER_ID; /* * From MainActivity, we have implemented the LoaderCallbacks interface with the type of * String array. (implements LoaderCallbacks<String[]>) The variable callback is passed * to the call to initLoader below. This means that whenever the loaderManager has * something to notify us of, it will do so through this callback. */ LoaderCallbacks<String[]> callback = MainActivity.this; /* * The second parameter of the initLoader method below is a Bundle. Optionally, you can * pass a Bundle to initLoader that you can then access from within the onCreateLoader * callback. In our case, we don't actually use the Bundle, but it's here in case we wanted * to. */ Bundle bundleForLoader = null; /* * Ensures a loader is initialized and active. If the loader doesn't already exist, one is * created and (if the activity/fragment is currently started) starts the loader. Otherwise * the last created loader is re-used. */ getSupportLoaderManager().initLoader(loaderId, bundleForLoader, callback); Log.d(TAG, "onCreate: registering preference changed listener"); }
Example #24
Source File: LoaderManagerImpl.java From letv with Apache License 2.0 | 4 votes |
private LoaderInfo createLoader(int id, Bundle args, LoaderCallbacks<Object> callback) { LoaderInfo info = new LoaderInfo(id, args, callback); info.mLoader = callback.onCreateLoader(id, args); return info; }
Example #25
Source File: LoaderManagerImpl.java From letv with Apache License 2.0 | 4 votes |
public LoaderInfo(int id, Bundle args, LoaderCallbacks<Object> callbacks) { this.mId = id; this.mArgs = args; this.mCallbacks = callbacks; }
Example #26
Source File: LiveSubTypeActivity.java From letv with Apache License 2.0 | 4 votes |
public LiveSubTypeActivity() { if (HotFix.PREVENT_VERIFY) { System.out.println(VerifyLoad.class); } this.mData = new ArrayList(); this.mLunboData = new ArrayList(); this.mPrograms = new HashMap(); this.mCurrentActionType = 1; this.mBookLoaderCallback = new LoaderCallbacks<Cursor>(this) { final /* synthetic */ LiveSubTypeActivity this$0; { if (HotFix.PREVENT_VERIFY) { System.out.println(VerifyLoad.class); } this.this$0 = this$0; } public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader(this.this$0, LetvContentProvider.URI_LIVEBOOKTRACE, null, null, null, null); } public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (cursor != null) { Set<String> mBookedPrograms = new HashSet(); while (cursor.moveToNext()) { try { int idx = cursor.getColumnIndexOrThrow(Field.MD5_ID); if (idx != -1) { mBookedPrograms.add(cursor.getString(idx)); } } catch (Exception e) { e.printStackTrace(); return; } } if (this.this$0.mRoomAdapter != null) { this.this$0.mRoomAdapter.setBookedPrograms(mBookedPrograms); } } } public void onLoaderReset(Loader<Cursor> loader) { } }; this.mRefreshData = new RefreshData(this) { final /* synthetic */ LiveSubTypeActivity this$0; { if (HotFix.PREVENT_VERIFY) { System.out.println(VerifyLoad.class); } this.this$0 = this$0; } public void refreshData() { this.this$0.mRootView.loading(false); this.this$0.getData(); } }; }
Example #27
Source File: LiveFragment.java From letv with Apache License 2.0 | 4 votes |
public LiveFragment() { if (HotFix.PREVENT_VERIFY) { System.out.println(VerifyLoad.class); } this.SCROLL_LEFT = 1; this.SCROLL_RIGTH = -1; this.mLiveList = new ArrayList(); this.mGotoChildPageIndex = -1; this.mRefreshData = new RefreshData(this) { final /* synthetic */ LiveFragment this$0; { if (HotFix.PREVENT_VERIFY) { System.out.println(VerifyLoad.class); } this.this$0 = this$0; } public void refreshData() { this.this$0.mRootView.loading(false); this.this$0.getData(); } }; this.mBookLoaderCallback = new LoaderCallbacks<Cursor>(this) { final /* synthetic */ LiveFragment this$0; { if (HotFix.PREVENT_VERIFY) { System.out.println(VerifyLoad.class); } this.this$0 = this$0; } public Loader<Cursor> onCreateLoader(int id, Bundle args) { return new CursorLoader(this.this$0.getContext(), LetvContentProvider.URI_LIVEBOOKTRACE, null, null, null, null); } public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (cursor != null) { Set<String> mBookedPrograms = new HashSet(); while (cursor.moveToNext()) { try { int idx = cursor.getColumnIndexOrThrow(Field.MD5_ID); if (idx != -1) { mBookedPrograms.add(cursor.getString(idx)); } } catch (SQLiteException e) { e.printStackTrace(); return; } } if (this.this$0.mLiveAdapter != null) { this.this$0.mLiveAdapter.setBookedPrograms(mBookedPrograms); } } } public void onLoaderReset(Loader<Cursor> loader) { } }; }
Example #28
Source File: MainActivity.java From android-dev-challenge with Apache License 2.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forecast); /* * Using findViewById, we get a reference to our RecyclerView from xml. This allows us to * do things like set the adapter of the RecyclerView and toggle the visibility. */ mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview_forecast); /* This TextView is used to display errors and will be hidden if there are no errors */ mErrorMessageDisplay = (TextView) findViewById(R.id.tv_error_message_display); /* * A LinearLayoutManager is responsible for measuring and positioning item views within a * RecyclerView into a linear list. This means that it can produce either a horizontal or * vertical list depending on which parameter you pass in to the LinearLayoutManager * constructor. In our case, we want a vertical list, so we pass in the constant from the * LinearLayoutManager class for vertical lists, LinearLayoutManager.VERTICAL. * * There are other LayoutManagers available to display your data in uniform grids, * staggered grids, and more! See the developer documentation for more details. */ int recyclerViewOrientation = LinearLayoutManager.VERTICAL; /* * This value should be true if you want to reverse your layout. Generally, this is only * true with horizontal lists that need to support a right-to-left layout. */ boolean shouldReverseLayout = false; LinearLayoutManager layoutManager = new LinearLayoutManager(this, recyclerViewOrientation, shouldReverseLayout); mRecyclerView.setLayoutManager(layoutManager); /* * Use this setting to improve performance if you know that changes in content do not * change the child layout size in the RecyclerView */ mRecyclerView.setHasFixedSize(true); /* * The ForecastAdapter is responsible for linking our weather data with the Views that * will end up displaying our weather data. */ mForecastAdapter = new ForecastAdapter(this); /* Setting the adapter attaches it to the RecyclerView in our layout. */ mRecyclerView.setAdapter(mForecastAdapter); /* * The ProgressBar that will indicate to the user that we are loading data. It will be * hidden when no data is loading. * * Please note: This so called "ProgressBar" isn't a bar by default. It is more of a * circle. We didn't make the rules (or the names of Views), we just follow them. */ mLoadingIndicator = (ProgressBar) findViewById(R.id.pb_loading_indicator); /* * This ID will uniquely identify the Loader. We can use it, for example, to get a handle * on our Loader at a later point in time through the support LoaderManager. */ int loaderId = FORECAST_LOADER_ID; /* * From MainActivity, we have implemented the LoaderCallbacks interface with the type of * String array. (implements LoaderCallbacks<String[]>) The variable callback is passed * to the call to initLoader below. This means that whenever the loaderManager has * something to notify us of, it will do so through this callback. */ LoaderCallbacks<String[]> callback = MainActivity.this; /* * The second parameter of the initLoader method below is a Bundle. Optionally, you can * pass a Bundle to initLoader that you can then access from within the onCreateLoader * callback. In our case, we don't actually use the Bundle, but it's here in case we wanted * to. */ Bundle bundleForLoader = null; /* * Ensures a loader is initialized and active. If the loader doesn't already exist, one is * created and (if the activity/fragment is currently started) starts the loader. Otherwise * the last created loader is re-used. */ getSupportLoaderManager().initLoader(loaderId, bundleForLoader, callback); Log.d(TAG, "onCreate: registering preference changed listener"); /* * Register MainActivity as an OnPreferenceChangedListener to receive a callback when a * SharedPreference has changed. Please note that we must unregister MainActivity as an * OnSharedPreferenceChanged listener in onDestroy to avoid any memory leaks. */ PreferenceManager.getDefaultSharedPreferences(this) .registerOnSharedPreferenceChangeListener(this); }