List of usage examples for android.database DataSetObserver DataSetObserver
DataSetObserver
From source file:saphion.fragments.alarm.AlarmFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { mCursorLoader = getActivity().getSupportLoaderManager().initLoader(0, null, this); try {//from w w w. j a v a2 s. c om if (!created) mCursorLoader.forceLoad(); } catch (Exception ex) { } // Inflate the layout for this fragment final View v = inflater.inflate(R.layout.alarm_listview, container, false); long[] expandedIds = null; long[] repeatCheckedIds = null; long[] selectedAlarms = null; Bundle previousDayMap = null; if (savedState != null) { expandedIds = savedState.getLongArray(KEY_EXPANDED_IDS); repeatCheckedIds = savedState.getLongArray(KEY_REPEAT_CHECKED_IDS); mRingtoneTitleCache = savedState.getBundle(KEY_RINGTONE_TITLE_CACHE); mDeletedAlarm = savedState.getParcelable(KEY_DELETED_ALARM); mUndoShowing = savedState.getBoolean(KEY_UNDO_SHOWING); selectedAlarms = savedState.getLongArray(KEY_SELECTED_ALARMS); previousDayMap = savedState.getBundle(KEY_PREVIOUS_DAY_MAP); mSelectedAlarm = savedState.getParcelable(KEY_SELECTED_ALARM); } mMessageBar = new MessageBar(getActivity()); mExpandInterpolator = new DecelerateInterpolator(EXPAND_DECELERATION); mCollapseInterpolator = new DecelerateInterpolator(COLLAPSE_DECELERATION); mAddAlarmButton = (ImageButton) v.findViewById(R.id.alarm_add_alarm); mAddAlarmButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { hideUndoBar(true, null); startCreatingAlarm(); } }); // For landscape, put the add button on the right and the menu in the // actionbar. FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mAddAlarmButton.getLayoutParams(); boolean isLandscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; if (isLandscape) { layoutParams.gravity = Gravity.RIGHT; } else { layoutParams.gravity = Gravity.CENTER; } mAddAlarmButton.setLayoutParams(layoutParams); View menuButton = v.findViewById(R.id.menu_button); if (menuButton != null) { if (isLandscape) { menuButton.setVisibility(View.GONE); } else { menuButton.setVisibility(View.VISIBLE); setupFakeOverflowMenuButton(menuButton); } } mEmptyView = v.findViewById(R.id.alarms_empty_view); mEmptyView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { startCreatingAlarm(); } }); mAlarmsList = (ListView) v.findViewById(R.id.alarms_list); mFadeIn = AnimatorInflater.loadAnimator(getActivity(), R.anim.fade_in); mFadeIn.setDuration(ANIMATION_DURATION); mFadeIn.addListener(new AnimatorListener() { @Override public void onAnimationStart(Animator animation) { mEmptyView.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator animation) { // Do nothing. } @Override public void onAnimationEnd(Animator animation) { // Do nothing. } @Override public void onAnimationRepeat(Animator animation) { // Do nothing. } }); mFadeIn.setTarget(mEmptyView); mFadeOut = AnimatorInflater.loadAnimator(getActivity(), R.anim.fade_out); mFadeOut.setDuration(ANIMATION_DURATION); mFadeOut.addListener(new AnimatorListener() { @Override public void onAnimationStart(Animator arg0) { mEmptyView.setVisibility(View.VISIBLE); } @Override public void onAnimationCancel(Animator arg0) { // Do nothing. } @Override public void onAnimationEnd(Animator arg0) { mEmptyView.setVisibility(View.GONE); } @Override public void onAnimationRepeat(Animator arg0) { // Do nothing. } }); mFadeOut.setTarget(mEmptyView); mFooterView = v.findViewById(R.id.alarms_footer_view); mFooterView.setOnTouchListener(this); mAdapter = new AlarmItemAdapter(getActivity(), expandedIds, repeatCheckedIds, selectedAlarms, previousDayMap, mAlarmsList); hideandshow(mAdapter.getCount()); mAdapter.registerDataSetObserver(new DataSetObserver() { private int prevAdapterCount = -1; @Override public void onChanged() { final int count = mAdapter.getCount(); if (mDeletedAlarm != null && prevAdapterCount > count) { showUndoBar(); } hideandshow(count); // Cache this adapter's count for when the adapter changes. prevAdapterCount = count; super.onChanged(); } }); if (mRingtoneTitleCache == null) { mRingtoneTitleCache = new Bundle(); } mAlarmsList.setAdapter(mAdapter); mAlarmsList.setVerticalScrollBarEnabled(true); mAlarmsList.setOnCreateContextMenuListener(this); if (mUndoShowing) { showUndoBar(); } return v; }
From source file:net.naonedbus.fragment.CustomListFragment.java
@Override public void onLoadFinished(final Loader<AsyncResult<ListAdapter>> loader, final AsyncResult<ListAdapter> result) { if (DBG)//from w w w . ja v a2 s . c o m Log.d(LOG_TAG + "$" + getClass().getSimpleName(), "onLoadFinished " + result); if (result == null) { showMessage(mMessageEmptyTitleId, mMessageEmptySummaryId, mMessageEmptyDrawableId); return; } final Exception exception = result.getException(); if (exception == null) { final ListAdapter adapter = result.getResult(); setListAdapter(adapter); if (adapter == null) { showMessage(mMessageEmptyTitleId, mMessageEmptySummaryId, mMessageEmptyDrawableId); } else { adapter.registerDataSetObserver(new DataSetObserver() { @Override public void onChanged() { super.onChanged(); onListAdapterChange(adapter); } }); if (adapter.getCount() > 0) { if (mListViewStatePosition != -1 && isAdded()) { getListView().setSelectionFromTop(mListViewStatePosition, mListViewStateTop); mListViewStatePosition = -1; } showContent(); resetNextUpdate(); } else { showMessage(mMessageEmptyTitleId, mMessageEmptySummaryId, mMessageEmptyDrawableId); } } } else { int titleRes = R.string.error_title; int messageRes = R.string.error_summary; int drawableRes = R.drawable.warning; // Erreur rseau ou interne ? if (exception instanceof IOException) { titleRes = R.string.error_title_network; messageRes = R.string.error_summary_network; drawableRes = R.drawable.ic_thunderstorm; } else if (exception instanceof JSONException) { titleRes = R.string.error_title_webservice; messageRes = R.string.error_summary_webservice; } if (getListAdapter() == null || getListAdapter().isEmpty()) { showMessage(titleRes, messageRes, drawableRes); } else { Crouton.makeText(getActivity(), titleRes, Style.ALERT, (ViewGroup) getView()).show(); } Log.e(getClass().getSimpleName(), "Erreur de chargement.", exception); } onPostExecute(); }
From source file:com.simas.vc.MainActivity.java
@Override public void onFileChosen(File file) { final NavItem item = new NavItem(file); item.registerUpdateListener(new NavItem.OnUpdatedListener() { @Override//w w w . j av a2 s .c om public void onUpdated(NavItem.ItemAttribute attribute, Object old, Object newValue) { if (newValue == NavItem.State.INVALID) { Utils.runOnUiThread(new Runnable() { @Override public void run() { // If an exception was throw we can fetch the message via the NavItem if (item.getError() != null) { try { new AlertDialog.Builder(MainActivity.this) .setTitle(Utils.getString(R.string.error)).setMessage(item.getError()) .setPositiveButton("OK", null).show(); } catch (Exception ignored) { // If an error occurs while showing a dialog, the context may // be dead, instead show a toast (The truth will be revealed!) Toast.makeText(VC.getAppContext(), item.getError(), Toast.LENGTH_LONG).show(); } } else { // If an error was not registered, we just display a toast warning Toast.makeText(VC.getAppContext(), Utils.getString(R.string.format_parse_failed, item.getFile().getName()), Toast.LENGTH_LONG).show(); } // If an invalid state was reached, remove this item from the drawer MainActivity.sItems.remove(item); } }); } else if (newValue == NavItem.State.VALID) { // Upon reaching the VALID state, remove this listener item.unregisterUpdateListener(this); } } }); MainActivity.sItems.add(item); // Wait until item is added to the pager final boolean addedViaToolbar = mAddedItemViaToolbar; mPagerAdapter.registerDataSetObserver(new DataSetObserver() { @Override public void onChanged() { super.onChanged(); // Only 1 change is needed, remove observer mPagerAdapter.unregisterDataSetObserver(this); // Let the viewPager receive the information about the changes mViewPager.post(new Runnable() { @Override public void run() { // If item added via the ToolBar, and the drawer is closed, // switch pager to the item if (addedViaToolbar && (mNavDrawerFragment .getDrawerState() == NavDrawerFragment.DrawerState.CLOSING || mNavDrawerFragment.getDrawerState() == NavDrawerFragment.DrawerState.CLOSED)) { mViewPager.setCurrentItem(mPagerAdapter.getCount()); } } }); } }); }
From source file:com.gm.common.ui.widget.pageindicator.PageIndicatorView.java
private void registerSetObserver() { if (setObserver == null && viewPager != null && viewPager.getAdapter() != null) { setObserver = new DataSetObserver() { @Override/*from ww w .j a v a2 s . c om*/ public void onChanged() { if (viewPager != null && viewPager.getAdapter() != null) { int newCount = viewPager.getAdapter().getCount(); int currItem = viewPager.getCurrentItem(); selectedPosition = currItem; selectingPosition = currItem; lastSelectedPosition = currItem; endAnimation(); setCount(newCount); setProgress(selectingPosition, 1.0f); } } }; try { viewPager.getAdapter().registerDataSetObserver(setObserver); } catch (IllegalStateException e) { e.printStackTrace(); } } }
From source file:im.getsocial.testapp.MainActivity.java
private void initUi() { userInfoView = (UserInfoView) findViewById(R.id.toolbar_userInfo); userInfoView.setUser(getSocial.getCurrentUser()); userInfoView.setOnClickListener(new View.OnClickListener() { @Override/*from w w w . ja va2 s. c o m*/ public void onClick(View v) { if (getSocial.isInitialized()) { FragmentManager fm = getSupportFragmentManager(); UserInfoDialog userInfoDialog = new UserInfoDialog(); userInfoDialog.show(fm, "user_info_dialog"); } } }); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); final ListView menuListView = (ListView) findViewById(R.id.menu_listView); menuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ListViewMenu menuItem = ((ListViewMenuItemView) view).getMenuItem(); if (menuItem instanceof ActionableListViewMenu) { ((ActionableListViewMenu) menuItem).invokeAction(); } else if (menuItem instanceof CheckboxListViewMenu) { // do nothing } else { listViewMenuAdapter.setMenu(menuItem); } } }); ListViewMenu rootMenu = populateMenu(); listViewMenuAdapter = new ListViewMenuAdapter(getApplicationContext(), rootMenu); listViewMenuAdapter.registerDataSetObserver(new DataSetObserver() { @Override public void onChanged() { updateToolbarBackButton(listViewMenuAdapter.getMenu()); } }); menuListView.setAdapter(listViewMenuAdapter); updateToolbarBackButton(rootMenu); TextView versionTextView = (TextView) findViewById(R.id.version_textView); versionTextView.setText(getTestAppInfo()); }