Example usage for android.database DataSetObserver DataSetObserver

List of usage examples for android.database DataSetObserver DataSetObserver

Introduction

In this page you can find the example usage for android.database DataSetObserver DataSetObserver.

Prototype

DataSetObserver

Source Link

Usage

From source file:net.naonedbus.fragment.impl.SearchFragment.java

@Override
protected CursorAdapter getCursorAdapter(final Context context) {
    mEquipementManager = EquipementManager.getInstance();
    final String[] types = getResources().getStringArray(R.array.types_equipements);

    mAdapter = new EquipementCursorAdapter(getActivity(), null);
    mAdapter.setIndexer(new EquipementCursorIndexer(null, types, EquipementTable.ID_TYPE));
    mAdapter.setFilterQueryProvider(this);
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override//from   w  w w . j a  v a 2s. c om
        public void onChanged() {
            if (mAdapter.getCount() == 0) {
                showMessage();
            } else {
                showContent();
            }
        }
    });

    return mAdapter;
}

From source file:com.thelastcrusade.soundstream.components.MusicLibraryFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);
    View v = inflater.inflate(R.layout.list, container, false);

    //for 2.3 compatibility
    setListAdapter(null);//from   ww w  . j av  a  2s .c  o m

    if (getArguments() != null) {
        String query = getArguments().getString(SearchActivity.QUERY_KEY);
        if (query != null) {
            mQuery = query;
            //Most of the time the music library service will not be bound
            // so this will not update the list
            mMusicAdapter.updateMusicFromQuery(mQuery);

            mHeaderView = inflater.inflate(R.layout.search_counter, null);
            mHeaderView.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT,
                    ListView.LayoutParams.WRAP_CONTENT));

            mMusicAdapter.registerDataSetObserver(new DataSetObserver() {
                @Override
                public void onChanged() {
                    super.onChanged();
                    TextView resultsCounter = (TextView) mHeaderView.findViewById(R.id.results_count);
                    resultsCounter.setText("" + mMusicAdapter.getCount());
                }
            });
        } else {
            Log.w(TAG, "Fragment recieved arguments but no query");
        }
    } else {
        mQuery = null;
    }

    //Since most of the time the service will not be bound here set
    // the onBindListenter with an update that has the proper query
    musicLibraryServiceLocator.setOnBindListener(new IOnBindListener() {
        @Override
        public void onServiceBound() {
            mMusicAdapter.updateMusicFromQuery(mQuery);
        }
    });

    return v;
}

From source file:com.github.rubensousa.stackview.StackView.java

/**
 * Set a StackAdapter so that this StackView can inflate it's views.
 *
 * @param adapter adapter to be set//  w w w.j a v  a 2 s  .c o m
 */
public void setAdapter(StackAdapter<?> adapter) {

    if (mAdapter != null && mObserver != null) {
        mAdapter.unregisterDataSetObserver(mObserver);
    }

    mAdapter = adapter;
    mObserver = new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();

            int newSize = mAdapter.getCount() > mSize ? mSize : mAdapter.getCount();

            if (mCurrentSize < newSize) {
                int itemsToAdd = newSize - mCurrentSize;
                for (int i = 0; i < itemsToAdd; i++) {
                    int stackPosition = mCurrentSize;
                    View view = mAdapter.getView(stackPosition, mViews.get(stackPosition), StackView.this);
                    view.setVisibility(View.VISIBLE);
                    ViewCompat.setTranslationY(view, 0f);
                    ViewCompat.setTranslationZ(view, (mSize - 1 - mCurrentSize) * mElevationSpacing);
                    mAnimator.animateAdd(view);
                    mCurrentSize++;
                }
            }
        }

        @Override
        public void onInvalidated() {
            super.onInvalidated();
            removeAllViews();
            addViews();
        }
    };

    mAdapter.registerDataSetObserver(mObserver);
    removeAllViews();
    addViews();
}

From source file:com.amitupadhyay.aboutexample.ui.widget.InkPageIndicator.java

public void setViewPager(ViewPager viewPager) {
    this.viewPager = viewPager;
    viewPager.addOnPageChangeListener(this);
    setPageCount(viewPager.getAdapter().getCount());
    viewPager.getAdapter().registerDataSetObserver(new DataSetObserver() {
        @Override/*from   ww w. ja  v a 2 s  . com*/
        public void onChanged() {
            setPageCount(InkPageIndicator.this.viewPager.getAdapter().getCount());
        }
    });
    setCurrentPageImmediate();
}

From source file:com.amaze.carbonfilemanager.ui.views.Indicator.java

public void setViewPager(ViewPager viewPager) {
    this.viewPager = viewPager;
    viewPager.addOnPageChangeListener(this);
    setPageCount(viewPager.getAdapter().getCount());
    viewPager.getAdapter().registerDataSetObserver(new DataSetObserver() {
        @Override//  ww  w.java 2s.  co  m
        public void onChanged() {
            setPageCount(Indicator.this.viewPager.getAdapter().getCount());
        }
    });
    setCurrentPageImmediate();
}

From source file:itkach.aard2.ArticleCollectionActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.activity_article_collection_loading);
    final Application app = (Application) getApplication();
    app.push(this);
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setSubtitle("...");
    final Intent intent = getIntent();
    final int position = intent.getIntExtra("position", 0);

    AsyncTask<Void, Void, ArticleCollectionPagerAdapter> createAdapterTask = new AsyncTask<Void, Void, ArticleCollectionPagerAdapter>() {

        @Override// w ww  . j a v  a  2  s  .co m
        protected ArticleCollectionPagerAdapter doInBackground(Void... params) {
            ArticleCollectionPagerAdapter result;
            Uri articleUrl = intent.getData();
            if (articleUrl != null) {
                result = createFromUri(app, articleUrl);
            } else {
                String action = intent.getAction();
                if (action == null) {
                    result = createFromLastResult(app);
                } else if (action.equals("showRandom")) {
                    result = createFromRandom(app);
                } else if (action.equals("showBookmarks")) {
                    result = createFromBookmarks(app);
                } else if (action.equals("showHistory")) {
                    result = createFromHistory(app);
                } else {
                    result = createFromIntent(app, intent);
                }
            }
            return result;
        }

        @Override
        protected void onPostExecute(ArticleCollectionPagerAdapter adapter) {
            if (isFinishing() || onDestroyCalled) {
                return;
            }
            articleCollectionPagerAdapter = adapter;
            if (articleCollectionPagerAdapter == null || articleCollectionPagerAdapter.getCount() == 0) {
                Toast.makeText(ArticleCollectionActivity.this, R.string.article_collection_nothing_found,
                        Toast.LENGTH_SHORT).show();
                finish();
                return;
            }

            if (position > articleCollectionPagerAdapter.getCount() - 1) {
                Toast.makeText(ArticleCollectionActivity.this,
                        R.string.article_collection_selected_not_available, Toast.LENGTH_SHORT).show();
                finish();
                return;
            }

            setContentView(R.layout.activity_article_collection);

            findViewById(R.id.pager_title_strip).setVisibility(
                    articleCollectionPagerAdapter.getCount() == 1 ? ViewGroup.GONE : ViewGroup.VISIBLE);

            viewPager = (ViewPager) findViewById(R.id.pager);
            viewPager.setAdapter(articleCollectionPagerAdapter);
            viewPager.setOnPageChangeListener(new OnPageChangeListener() {

                @Override
                public void onPageScrollStateChanged(int arg0) {
                }

                @Override
                public void onPageScrolled(int arg0, float arg1, int arg2) {
                }

                @Override
                public void onPageSelected(final int position) {
                    updateTitle(position);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ArticleFragment fragment = (ArticleFragment) articleCollectionPagerAdapter
                                    .getItem(position);
                            fragment.applyTextZoomPref();
                        }
                    });

                }
            });
            viewPager.setCurrentItem(position);

            PagerTitleStrip titleStrip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);
            titleStrip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            updateTitle(position);
            articleCollectionPagerAdapter.registerDataSetObserver(new DataSetObserver() {
                @Override
                public void onChanged() {
                    if (articleCollectionPagerAdapter.getCount() == 0) {
                        finish();
                    }
                }
            });
        }
    };

    createAdapterTask.execute();

}

From source file:com.heinrichreimersoftware.materialintro.view.InkPageIndicator.java

public void setViewPager(ViewPager viewPager) {
    this.viewPager = viewPager;
    viewPager.addOnPageChangeListener(this);
    setPageCount(viewPager.getAdapter().getCount());
    viewPager.getAdapter().registerDataSetObserver(new DataSetObserver() {
        @Override/*from  www  .j  a va  2  s .com*/
        public void onChanged() {
            setPageCount(InkPageIndicator.this.viewPager.getAdapter().getCount());
            invalidate();
        }
    });
}

From source file:org.tigase.mobile.muc.MucRoomFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    if (getArguments() != null) {
        long id = getArguments().getLong("roomId");
        MultiJaxmpp multi = ((MessengerApplication) getActivity().getApplication()).getMultiJaxmpp();
        ChatWrapper ch = multi.getRoomById(id);

        if (ch == null) {
            String msg = ChatHistoryFragment.prepareAdditionalDebug(multi);
            Log.v(TAG, "ChatWrapper is null with id = " + id + '\n' + msg);
            ((TigaseMobileMessengerActivity) getActivity()).viewPager.getAdapter().notifyDataSetChanged();
        } else {/*from   w ww  .j a va 2 s  .com*/
            if (ch.getRoom() == null) {
                throw new NullPointerException("ChatWrapper.getRoom() is null with id = " + id);
            }
            if (ch.getRoom().getSessionObject() == null) {
                throw new NullPointerException(
                        "ChatWrapper.getRoom().getSessionObject() is null with id = " + id);
            }

            this.room = ch.getRoom();
            this.jaxmpp = multi.get(ch.getRoom().getSessionObject());

        }
    }

    this.mucAdapter = new MucAdapter(getActivity(), R.layout.muc_chat_item, room, nickameClickListener);
    getLoaderManager().initLoader(fragmentUID, null, this);
    mucAdapter.registerDataSetObserver(new DataSetObserver() {

        @Override
        public void onChanged() {
            super.onChanged();
            if (DEBUG)
                Log.i(TAG, "Changed!");
            if (lv != null)
                lv.post(new Runnable() {

                    @Override
                    public void run() {
                        lv.setSelection(Integer.MAX_VALUE);
                    }
                });
        }
    });

    TextView title = (TextView) view.findViewById(R.id.textView1);
    if (title != null) {
        title.setText("--" + room.getRoomJid().toString());
    }
    ed.setEnabled(room.getState() == State.joined);
    sendButton.setEnabled(room.getState() == State.joined);
    lv.setAdapter(mucAdapter);
}

From source file:com.android.settings.widget.DotsPageIndicator.java

public void setViewPager(ViewPager viewPager) {
    this.viewPager = viewPager;
    viewPager.setOnPageChangeListener(this);
    setPageCount(viewPager.getAdapter().getCount());
    viewPager.getAdapter().registerDataSetObserver(new DataSetObserver() {
        @Override/* w w w.j av  a2 s .co m*/
        public void onChanged() {
            setPageCount(DotsPageIndicator.this.viewPager.getAdapter().getCount());
        }
    });
    setCurrentPageImmediate();
}

From source file:com.dictionary.activity.ArticleCollectionActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Application app = (Application) getApplication();
    app.installTheme(this);
    requestWindowFeature(Window.FEATURE_PROGRESS);
    setContentView(R.layout.activity_article_collection_loading);
    app.push(this);
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setSubtitle("...");
    final Intent intent = getIntent();
    final int position = intent.getIntExtra("position", 0);

    AsyncTask<Void, Void, ArticleCollectionPagerAdapter> createAdapterTask = new AsyncTask<Void, Void, ArticleCollectionPagerAdapter>() {

        @Override//from   w w w  .  j  av  a 2  s .  c  o m
        protected ArticleCollectionPagerAdapter doInBackground(Void... params) {
            ArticleCollectionPagerAdapter result;
            Uri articleUrl = intent.getData();
            if (articleUrl != null) {
                result = createFromUri(app, articleUrl);
            } else {
                String action = intent.getAction();
                if (action == null) {
                    result = createFromLastResult(app);
                } else if (action.equals("showRandom")) {
                    result = createFromRandom(app);
                } else if (action.equals("showBookmarks")) {
                    result = createFromBookmarks(app);
                } else if (action.equals("showHistory")) {
                    result = createFromHistory(app);
                } else {
                    result = createFromIntent(app, intent);
                }
            }
            return result;
        }

        @Override
        protected void onPostExecute(ArticleCollectionPagerAdapter adapter) {
            if (isFinishing() || onDestroyCalled) {
                return;
            }
            articleCollectionPagerAdapter = adapter;
            if (articleCollectionPagerAdapter == null || articleCollectionPagerAdapter.getCount() == 0) {
                int messageId;
                if (articleCollectionPagerAdapter == null) {
                    messageId = R.string.article_collection_invalid_link;
                } else {
                    messageId = R.string.article_collection_nothing_found;
                }
                Toast.makeText(ArticleCollectionActivity.this, messageId, Toast.LENGTH_SHORT).show();
                finish();
                return;
            }

            if (position > articleCollectionPagerAdapter.getCount() - 1) {
                Toast.makeText(ArticleCollectionActivity.this,
                        R.string.article_collection_selected_not_available, Toast.LENGTH_SHORT).show();
                finish();
                return;
            }

            setContentView(R.layout.activity_article_collection);

            findViewById(R.id.pager_title_strip).setVisibility(
                    articleCollectionPagerAdapter.getCount() == 1 ? ViewGroup.GONE : ViewGroup.VISIBLE);

            viewPager = (ViewPager) findViewById(R.id.pager);
            viewPager.setAdapter(articleCollectionPagerAdapter);
            viewPager.setOnPageChangeListener(new OnPageChangeListener() {

                @Override
                public void onPageScrollStateChanged(int arg0) {
                }

                @Override
                public void onPageScrolled(int arg0, float arg1, int arg2) {
                }

                @Override
                public void onPageSelected(final int position) {
                    updateTitle(position);
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ArticleFragment fragment = (ArticleFragment) articleCollectionPagerAdapter
                                    .getItem(position);
                            fragment.applyTextZoomPref();
                        }
                    });

                }
            });
            viewPager.setCurrentItem(position);

            PagerTitleStrip titleStrip = (PagerTitleStrip) findViewById(R.id.pager_title_strip);
            titleStrip.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
            updateTitle(position);
            articleCollectionPagerAdapter.registerDataSetObserver(new DataSetObserver() {
                @Override
                public void onChanged() {
                    if (articleCollectionPagerAdapter.getCount() == 0) {
                        finish();
                    }
                }
            });
        }
    };

    createAdapterTask.execute();

}