@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.apps_fragment, container, false); mListView = (ListView) view.findViewById(android.R.id.list); mProgressBar = view.findViewById(android.R.id.progress); mEmptyView = view.findViewById(android.R.id.empty); mErrorReporter = new ErrorReporter(getActivity(), view, AppContract.Apps.CONTENT_URI); mListView.setOnItemClickListener(this); Bitmap placeHolder = BitmapFactory.decodeResource(getResources(), R.drawable.placeholder); mRemoteImageLoader = RemoteImageLoader.createUsingDp(getActivity(), placeHolder, IMAGE_SIZE_DP, IMAGE_SIZE_DP); mAdapter = new AppsAdapter(getActivity(), mRemoteImageLoader, this); mListView.setAdapter(mAdapter); mDownloadHelper = new DownloadHelper( getActivity(), DownloadService.ACTION_SYNC, this, AppContract.Apps.CONTENT_URI); LoaderManager lm = getLoaderManager(); lm.initLoader(LOADER_APPS, null, this); setHasOptionsMenu(true); return view; }
@Override public void onDestroy() { loaderManager.destroyLoader(ID_RECEIVING_ADDRESS_LOADER); loaderManager.destroyLoader(ID_RATE_LOADER); super.onDestroy(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle args = getArguments(); if (args != null) { if (args.containsKey(Constants.ARG_ACCOUNT_ID)) { String accountId = args.getString(Constants.ARG_ACCOUNT_ID); pocket = checkNotNull(application.getAccount(accountId)); } if (args.containsKey(Constants.ARG_URI)) { try { processUri(args.getString(Constants.ARG_URI)); } catch (CoinURIParseException e) { // TODO handle more elegantly Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); ACRA.getErrorReporter().handleException(e); } } if (pocket == null) { List<WalletAccount> accounts = application.getAllAccounts(); if (accounts.size() > 0) pocket = accounts.get(0); if (pocket == null) { ACRA.getErrorReporter() .putCustomData("wallet-exists", application.getWallet() == null ? "no" : "yes"); Toast.makeText(getActivity(), R.string.no_such_pocket_error, Toast.LENGTH_LONG).show(); getActivity().finish(); return; } } checkNotNull(pocket, "No account selected"); } else { throw new RuntimeException("Must provide account ID or a payment URI"); } sendAmountType = pocket.getCoinType(); messageFactory = pocket.getCoinType().getMessagesFactory(); if (savedInstanceState != null) { address = (Address) savedInstanceState.getSerializable(STATE_ADDRESS); addressTypeCanChange = savedInstanceState.getBoolean(STATE_ADDRESS_CAN_CHANGE_TYPE); sendAmount = (Value) savedInstanceState.getSerializable(STATE_AMOUNT); sendAmountType = (CoinType) savedInstanceState.getSerializable(STATE_AMOUNT_TYPE); } updateBalance(); setHasOptionsMenu(true); mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer); String localSymbol = config.getExchangeCurrencyCode(); for (ExchangeRatesProvider.ExchangeRate rate : getRates(getActivity(), localSymbol)) { localRates.put(rate.currencyCodeId, rate.rate); } loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks); loaderManager.initLoader(ID_RECEIVING_ADDRESS_LOADER, null, receivingAddressLoaderCallbacks); }
/** Loads initial blog posts. */ public void loadPosts(boolean reload) { LoaderManager loaderManager = getLoaderManager(); if (reload) { loaderManager.restartLoader(BLOG_LOADER_ID, null, this); } else { loaderManager.initLoader(BLOG_LOADER_ID, null, this); } }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // 管理cursor LoaderManager loaderManager = getLoaderManager(); // 注册Loader loaderManager.initLoader(LOADER_ID, null, this); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); LoaderManager mgr = getActivity().getSupportLoaderManager(); mgr.initLoader(ARRIVALS_LIST_LOADER, getArguments(), this).forceLoad(); }
@Override public void onClick(final View view) { final Intent intent = getIntent(); final Uri uri = intent.getData(); final Uri orig = intent.getParcelableExtra(INTENT_KEY_URI_ORIG); switch (view.getId()) { case R.id.close: { onBackPressed(); break; } case R.id.refresh_stop_save: { final LoaderManager lm = getSupportLoaderManager(); if (!mImageLoaded && !lm.hasRunningLoaders()) { loadImage(); } else if (!mImageLoaded && lm.hasRunningLoaders()) { stopLoading(); } else if (mImageLoaded) { new SaveImageTask(this, mImageFile).execute(); } break; } case R.id.share: { if (uri == null) { break; } final Intent share_intent = new Intent(Intent.ACTION_SEND); if (mImageFile != null && mImageFile.exists()) { share_intent.setType("image/*"); share_intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(mImageFile)); } else { share_intent.setType("text/plain"); share_intent.putExtra(Intent.EXTRA_TEXT, uri.toString()); } startActivity(Intent.createChooser(share_intent, getString(R.string.share))); break; } case R.id.open_in_browser: { final Uri uri_preferred = orig != null ? orig : uri; if (uri_preferred == null) return; final String scheme = uri_preferred.getScheme(); if ("http".equals(scheme) || "https".equals(scheme)) { final Intent open_intent = new Intent(Intent.ACTION_VIEW, uri_preferred); open_intent.addCategory(Intent.CATEGORY_BROWSABLE); try { startActivity(open_intent); } catch (final ActivityNotFoundException e) { // Ignore. } } break; } } }
@Override public void onStart() { super.onStart(); LoaderManager lm = getLoaderManager(); if (lm.getLoader(1) != null) { lm.initLoader(1, null, this); } getLoaderManager().initLoader(1, null, this); }
@Override public void onPause() { prefs.unregisterOnSharedPreferenceChangeListener(this); loaderManager.destroyLoader(ID_RATE_LOADER); loaderManager.destroyLoader(ID_BALANCE_LOADER); activity.unregisterReceiver(broadcastReceiver); super.onPause(); }
private void restartGroupingLoader() { mGroupingCursor = null; if (mManager == null) { // can happen after an orientation change in ExportDialogFragment, when resetting multiple // accounts mManager = getLoaderManager(); } if (mManager.getLoader(GROUPING_CURSOR) != null && !mManager.getLoader(GROUPING_CURSOR).isReset()) mManager.restartLoader(GROUPING_CURSOR, null, this); else mManager.initLoader(GROUPING_CURSOR, null, this); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final MyExpenses ctx = (MyExpenses) getActivity(); if (mAccount == null) { TextView tv = new TextView(ctx); tv.setText( "Error loading transaction list for account " + getArguments().getLong(KEY_ACCOUNTID)); return tv; } mManager = getLoaderManager(); setGrouping(); setColors(); View v = inflater.inflate(R.layout.expenses_list, null, false); // TODO check if still needed with Appcompat // work around the problem that the view pager does not display its background correctly with // Sherlock if (Build.VERSION.SDK_INT < 11) { v.setBackgroundColor( ctx.getResources() .getColor( MyApplication.PrefKey.UI_THEME_KEY.value("dark").equals("light") ? android.R.color.white : android.R.color.black)); } mListView = (StickyListHeadersListView) v.findViewById(R.id.list); setAdapter(); mListView.setOnHeaderClickListener(this); mListView.setDrawingListUnderStickyHeader(false); mManager.initLoader(GROUPING_CURSOR, null, this); mManager.initLoader(TRANSACTION_CURSOR, null, this); mManager.initLoader(SUM_CURSOR, null, this); // Now create a simple cursor adapter and set it to display mListView.setEmptyView(v.findViewById(R.id.empty)); mListView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> a, View v, int position, long id) { FragmentManager fm = ctx.getSupportFragmentManager(); DialogFragment f = (DialogFragment) fm.findFragmentByTag("TRANSACTION_DETAIL"); if (f == null) { FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.add(TransactionDetailFragment.newInstance(id), "TRANSACTION_DETAIL"); ft.commitAllowingStateLoss(); } } }); registerForContextualActionBar(mListView.getWrappedList()); return v; }
@Override public void resetDataset(int viewIndex) { Log.d(LOGTAG, "Resetting dataset: " + viewIndex); final LoaderManager lm = getLoaderManager(); // Release any resources associated with the dataset if // it's currently loaded in memory. final Loader<?> datasetLoader = lm.getLoader(viewIndex); if (datasetLoader != null) { datasetLoader.reset(); } }
@Override public void onResume() { super.onResume(); activity.registerReceiver( broadcastReceiver, new IntentFilter(BlockchainService.ACTION_BLOCKCHAIN_STATE)); loaderManager.initLoader(ID_BALANCE_LOADER, null, balanceLoaderCallbacks); loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks); defaultCurrency = prefs.getString(Constants.PREFS_KEY_EXCHANGE_CURRENCY, null); prefs.registerOnSharedPreferenceChangeListener(this); updateView(); }
public synchronized void doFilter(String filterString) { mSearchString = filterString; if (mContactAdapter == null) { mContactAdapter = new ContactAdapter(mContext, R.layout.contact_view); ((ListView) mFilterList).setAdapter(mContactAdapter); mLoaderCallbacks = new MyLoaderCallbacks(); mLoaderManager.initLoader(mLoaderId, null, mLoaderCallbacks); } else { if (!mAwaitingUpdate) { mAwaitingUpdate = true; mHandler.postDelayed( new Runnable() { public void run() { mLoaderManager.restartLoader(mLoaderId, null, mLoaderCallbacks); mAwaitingUpdate = false; } }, 1000); } } }
/** * Loads and initializes the pager. * * @param fm FragmentManager for the adapter */ public void show( LoaderManager lm, FragmentManager fm, String panelId, PropertyAnimator animator) { mLoaded = true; mInitialPanelId = panelId; // Only animate on post-HC devices, when a non-null animator is given final boolean shouldAnimate = (animator != null && Build.VERSION.SDK_INT >= 11); final HomeAdapter adapter = new HomeAdapter(mContext, fm); adapter.setOnAddPanelListener(mAddPanelListener); adapter.setCanLoadHint(!shouldAnimate); setAdapter(adapter); setVisibility(VISIBLE); // Don't show the tabs strip until we have the // list of panels in place. mTabStrip.setVisibility(View.INVISIBLE); // Load list of panels from configuration. Restart the loader if necessary. if (mRestartLoader) { lm.restartLoader(LOADER_ID_CONFIG, null, mConfigLoaderCallbacks); mRestartLoader = false; } else { lm.initLoader(LOADER_ID_CONFIG, null, mConfigLoaderCallbacks); } if (shouldAnimate) { animator.addPropertyAnimationListener( new PropertyAnimator.PropertyAnimationListener() { @Override public void onPropertyAnimationStart() { setLayerType(View.LAYER_TYPE_HARDWARE, null); } @Override public void onPropertyAnimationEnd() { setLayerType(View.LAYER_TYPE_NONE, null); adapter.setCanLoadHint(true); } }); ViewHelper.setAlpha(this, 0.0f); animator.attach(this, PropertyAnimator.Property.ALPHA, 1.0f); } }
@Override public void onPause() { loaderManager.destroyLoader(ID_TRANSACTION_LOADER); activity.unregisterReceiver(tickReceiver); super.onPause(); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // create and auto start loader LoaderManager loaderManager = this.getLoaderManager(); loaderManager.destroyLoader(0); loaderManager.initLoader(0, null, this); this.mAdapter = new LocationsAdapter(getActivity(), R.layout.fragment_locations_item_view); this.setListAdapter(mAdapter); this.isListShown = true; this.setListShown(false); this.getActivity().invalidateOptionsMenu(); }
@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()); } } }
@Override public void onPause() { loaderManager.destroyLoader(ID_BALANCE_LOADER); activity.unregisterReceiver(broadcastReceiver); super.onPause(); }
@Override public void onDestroy() { config.unregisterOnSharedPreferenceChangeListener(this); loaderManager.destroyLoader(ID_RATE_LOADER); super.onDestroy(); }
@Override public void onResume() { super.onResume(); activity.registerReceiver(tickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK)); loaderManager.initLoader(ID_TRANSACTION_LOADER, null, transactionLoaderCallbacks); adapter.notifyDataSetChanged(); }
@Override public void onLoadFinished( final Loader<List<StoredBlock>> loader, final List<StoredBlock> blocks) { adapter.replace(blocks); final Loader<Set<Transaction>> transactionLoader = loaderManager.getLoader(ID_TRANSACTION_LOADER); if (transactionLoader != null && transactionLoader.isStarted()) transactionLoader.forceLoad(); }
@Override public void onPause() { loaderManager.destroyLoader(ID_RATE_LOADER); Nfc.unpublish(nfcManager, activity); amountCalculatorLink.setListener(null); super.onPause(); }
@Override public void onResume() { super.onResume(); activity.registerReceiver( broadcastReceiver, new IntentFilter(BlockchainService.ACTION_BLOCKCHAIN_STATE)); loaderManager.initLoader(ID_BALANCE_LOADER, null, balanceLoaderCallbacks); updateView(); }
private void onResume() { Log.d(TAG, "##### onResume #### " + person); // context.getContentResolver().registerContentObserver(GeoTrackerProvider.Constants.CONTENT_URI, // true, new MyContentObserver(uiHandler)); // Prefs this.sharedPreferences.registerOnSharedPreferenceChangeListener(this); // Listener context.registerReceiver(mStatusReceiver, mStatusReceiverIntentFilter); // Load Data loaderManager.initLoader(GEOTRACK_LIST_LOADER, null, geoTrackLoaderCallback); }
private void cargarListaDesdeBD() { // Se inicializa el cargador. gestor.initLoader(IMAGENES_LOADER, null, this); // Se crea un adaptador inicial con el cursor nulo. String[] from = new String[] {BD.Imagen.USERNAME, BD.Imagen.THUMBNAIL}; int[] to = new int[] {R.id.lblUsuario, R.id.imgFoto}; adaptador = new ImagenesCursorAdapter(this.getActivity(), null, from, to); // Se visualiza o oculta el relative layout de lista vacía. rlListaFotosVacia.setVisibility((adaptador.getCount() > 0) ? View.INVISIBLE : View.VISIBLE); lstFotos.setAdapter(adaptador); }
@Override public View getView(int i, View view, ViewGroup viewGroup) { final ViewHolder holder; if (view == null) { view = View.inflate(context, R.layout.main_pulltorefresh_item, null); holder = new ViewHolder(); holder.iv = (ImageView) view.findViewById(R.id.main_pull_imageView); holder.tv_title = (TextView) view.findViewById(R.id.main_pull_item_title); holder.tv_sendTime = (TextView) view.findViewById(R.id.main_pull_item_sendtime); holder.tv_feedback = (TextView) view.findViewById(R.id.main_pull_item_feedback); view.setTag(holder); } else { holder = (ViewHolder) view.getTag(); } HashMap<String, String> map = data.get(i); holder.tv_title.setText(map.get("shorttitle")); long senddate = Long.parseLong(map.get("senddate")); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String sendtime = sdf.format(senddate); holder.tv_sendTime.setText(sendtime); holder.tv_feedback.setText(map.get("click")); holder.iv.setImageResource(R.drawable.img_default); String imgPath = map.get("imgPath"); Bundle bundle = new Bundle(); bundle.putString("imgPath", imgPath); loaderManager.initLoader( loader_index++, bundle, new LoaderManager.LoaderCallbacks<Bitmap>() { @Override public Loader<Bitmap> onCreateLoader(int id, Bundle args) { return new ImagAsyncLoader(context, args); } @Override public void onLoadFinished(Loader<Bitmap> loader, Bitmap data) { if (data != null) { holder.iv.setImageBitmap(data); } else { Toast.makeText(context, "图片加载加载异常", Toast.LENGTH_SHORT).show(); } } @Override public void onLoaderReset(Loader<Bitmap> loader) { holder.iv.setImageBitmap(null); } }); return view; }
public static void restartFromCursor( LoaderManager manager, int loaderId, LoaderCallbacks<Cursor> callbacks, Cursor c) { // If there urls without in-memory favicons, trigger a new loader // to load the images from disk to memory. ArrayList<String> urls = getUrlsWithoutFavicon(c); if (urls.size() > 0) { Bundle args = new Bundle(); args.putStringArrayList(FAVICONS_LOADER_URLS_ARG, urls); manager.restartLoader(loaderId, args, callbacks); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.templates_list, null, false); ListView lv = (ListView) v.findViewById(R.id.list); mManager = getLoaderManager(); mManager.initLoader(0, null, this); // Create an array to specify the fields we want to display in the list String[] from = new String[] {DatabaseConstants.KEY_TITLE, DatabaseConstants.KEY_PLANID}; // and an array of the fields we want to bind those fields to int[] to = new int[] {R.id.title, R.id.plan}; mAdapter = new SimpleCursorAdapter(getActivity(), R.layout.template_row, null, from, to, 0) { @Override public View getView(int position, View convertView, ViewGroup parent) { convertView = super.getView(position, convertView, parent); convertView.findViewById(R.id.apply).setTag(getItemId(position)); Cursor c = getCursor(); c.moveToPosition(position); int color = c.getInt(c.getColumnIndex("color")); convertView.findViewById(R.id.colorAccount).setBackgroundColor(color); return convertView; } }; mAdapter.setViewBinder( new SimpleCursorAdapter.ViewBinder() { public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view.getId() == R.id.plan) { view.setVisibility( (DbUtils.getLongOrNull(cursor, DatabaseConstants.KEY_PLANID) == null) ? View.INVISIBLE : View.VISIBLE); return true; } return false; } }); lv.setAdapter(mAdapter); lv.setEmptyView(v.findViewById(R.id.empty)); // requires using activity (ManageTemplates) to implement OnChildClickListener // lv.setOnChildClickListener((OnChildClickListener) getActivity()); lv.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> a, View v, int position, long id) { TemplateDetailFragment.newInstance(id) .show(getActivity().getSupportFragmentManager(), "TEMPLATE_DETAIL"); } }); registerForContextMenu(lv); return v; }
@Override public void onCursorChanged(Cursor cursor) { if (mAdapter == null) { // The adapter is set in onAttach(), and is guaranteed to be non-null. We have magically // received an onCursorChanged without attaching to an activity. Ignore this cursor // change. return; } // FLAG: There is a problem here: // If the cursor changes, and new items are added at an earlier position than // the current item, we will switch photos here. Really we should probably // try to find a photo with the same url and move the cursor to that position. if (cursor.moveToPosition(mPosition) && !isPhotoBound()) { mCallback.onCursorChanged(this, cursor); final LoaderManager manager = getLoaderManager(); final Loader<BitmapResult> fakePhotoLoader = manager.getLoader(PhotoViewCallbacks.BITMAP_LOADER_PHOTO); if (fakePhotoLoader != null) { final PhotoBitmapLoaderInterface loader = (PhotoBitmapLoaderInterface) fakePhotoLoader; mResolvedPhotoUri = mAdapter.getPhotoUri(cursor); loader.setPhotoUri(mResolvedPhotoUri); loader.forceLoad(); } if (!mThumbnailShown) { final Loader<BitmapResult> fakeThumbnailLoader = manager.getLoader(PhotoViewCallbacks.BITMAP_LOADER_THUMBNAIL); if (fakeThumbnailLoader != null) { final PhotoBitmapLoaderInterface loader = (PhotoBitmapLoaderInterface) fakeThumbnailLoader; mThumbnailUri = mAdapter.getThumbnailUri(cursor); loader.setPhotoUri(mThumbnailUri); loader.forceLoad(); } } } }