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:com.ultramegatech.ey.ElementListFragment.java

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

    final Context context = getContext();
    if (context == null) {
        return;/*from  w  ww  .j ava2s .  c o m*/
    }

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
    prefs.registerOnSharedPreferenceChangeListener(this);

    if (savedInstanceState != null) {
        mSort = savedInstanceState.getInt(KEY_SORT, mSort);
        mSortReverse = savedInstanceState.getBoolean(KEY_SORT_REVERSE, mSortReverse);
        mFilter = savedInstanceState.getString(KEY_FILTER);
        mActivatedItem = savedInstanceState.getLong(KEY_ACTIVATED_ITEM, mActivatedItem);
    }

    mAdapter = new ElementListAdapter(context);
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            setActivatedPosition(mAdapter.getItemPosition(mActivatedItem));
        }
    });
    mAdapter.getFilter().filter(mFilter);
    mAdapter.setSort(mSort, mSortReverse);
    setListAdapter(mAdapter);

    setupFilter();
    setupSort();
}

From source file:com.jecelyin.editor.v2.ui.TabManager.java

private void initEditor() {
    editorAdapter = new EditorAdapter(mainActivity);
    mainActivity.mTabPager.setAdapter(editorAdapter); //??TabAdapter??CurrentItem

    if (Pref.getInstance(mainActivity).isOpenLastFiles()) {
        ArrayList<DBHelper.RecentFileItem> recentFiles = DBHelper.getInstance(mainActivity)
                .getRecentFiles(true);/*from  www.j a  va 2s . co m*/

        File f;
        for (DBHelper.RecentFileItem item : recentFiles) {
            f = new File(item.path);
            if (!f.isFile())
                continue;
            editorAdapter.newEditor(false, f, item.offset, item.encoding);
        }
        editorAdapter.notifyDataSetChanged();
        updateTabList();
    }

    editorAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            updateTabList();

            if (!exitApp && editorAdapter.getCount() == 0) {
                mainActivity.mTabPager.post(new Runnable() {
                    @Override
                    public void run() {
                        newTab();
                    }
                });
            }
        }
    });

    if (editorAdapter.getCount() == 0)
        editorAdapter.newEditor(
                mainActivity.getString(R.string.new_filename, editorAdapter.countNoFileEditor() + 1), null);
}

From source file:com.serenegiant.aceparrot.PhotoFragment.java

private void initView(final View rootView) {
    mViewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
    mViewPager.setKeepScreenOn(true);//from   ww  w .  jav a  2 s  .  com
    mAdapter = new MediaStoreImageAdapter(getActivity(), R.layout.grid_item_media, false);
    // MediaStoreImageAdapter?Cursor???????
    // ???0????ViewPager#setAdapter?
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            mViewPager.setAdapter(mAdapter);
            mViewPager.setCurrentItem(mAdapter.getItemPositionFromID(mId));
            mAdapter.unregisterDataSetObserver(this); // ????OK????
        }

        @Override
        public void onInvalidated() {
            super.onInvalidated();
        }
    });
    mAdapter.startQuery(); // ??
}

From source file:com.acbelter.scheduleview.ScheduleView.java

public ScheduleView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    mClipRect = new Rect();
    mClickedViewBounds = new Rect();
    mSelectedIds = new HashSet<Long>();
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mTopEdgeEffect = new EdgeEffectCompat(context);
    mBottomEdgeEffect = new EdgeEffectCompat(context);

    mDataSetObserver = new DataSetObserver() {
        @Override/*from   www.  ja va  2s .c  om*/
        public void onChanged() {
            super.onChanged();
            removeAllViewsInLayout();
            requestLayout();
        }

        @Override
        public void onInvalidated() {
            super.onInvalidated();
            removeAllViewsInLayout();
            requestLayout();
        }
    };

    init(context);

    setVerticalScrollBarEnabled(true);
    setHorizontalScrollBarEnabled(false);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScheduleView, defStyle, 0);
    try {
        if (a != null) {
            DisplayMetrics dm = context.getResources().getDisplayMetrics();
            mInternalPaddingTop = (int) a.getDimension(R.styleable.ScheduleView_internalPaddingTop,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            mInternalPaddingBottom = (int) a.getDimension(R.styleable.ScheduleView_internalPaddingBottom,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            mTimeMarksDistance = (int) a.getDimension(R.styleable.ScheduleView_timeMarksDistance,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, dm));
            mItemPaddingLeft = (int) a.getDimension(R.styleable.ScheduleView_itemPaddingLeft,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            mItemPaddingRight = (int) a.getDimension(R.styleable.ScheduleView_itemPaddingRight,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            initializeScrollbars(a);
        }
    } finally {
        if (a != null) {
            a.recycle();
        }
    }

    // Draw the background even if no items to display
    setWillNotDraw(false);

    mActionModeCallback = new ActionMode.Callback() {
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.getMenuInflater().inflate(R.menu.menu_context, menu);
            mIsActionMode = true;
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            if (item.getItemId() == R.id.delete_items) {
                deleteSelectedItems();
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            clearSelection();
            mIsActionMode = false;
            mActionMode = null;
            invalidate();
        }
    };
}

From source file:org.dmfs.webcal.adapters.SectionTitlesAdapter.java

public SectionTitlesAdapter(Context context, ListAdapter adapter, SectionIndexer indexer,
        int sectionHeaderViewid) {
    mAdaptedAdapter = adapter;/*from ww w . j ava 2s .com*/
    mIndexer = indexer;
    mSectionHeaderViewId = sectionHeaderViewid;
    adapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            buildIndex();
        }
    });
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    buildIndex();
}

From source file:org.gdg.frisbee.android.fragment.GdgListFragment.java

/**
 * Provide the cursor for the list view.
 *//*from ww  w . j a va 2  s  .  c  om*/
public void setListAdapter(ListAdapter adapter) {
    boolean hadAdapter = mAdapter != null;
    mAdapter = adapter;
    if (mList != null) {
        mList.setAdapter(adapter);
        if (!mListShown && !hadAdapter) {
            // The list was hidden, and previously didn't have an
            // adapter.  It is now time to show it.
            setListShown(true, getView().getWindowToken() != null);
        }
    }
    updateEmpty();
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();

            updateEmpty();
        }

        @Override
        public void onInvalidated() {
            super.onInvalidated();

            updateEmpty();
        }

    });
}

From source file:tw.idv.palatis.danboorugallery.PostListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // enable progress icon
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setProgressBarIndeterminate(true);// w  ww. j av  a  2s . com

    setContentView(R.layout.activity_post_list);

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // setup drawer
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLeft = (RelativeLayout) findViewById(R.id.left_drawer);
    mDrawerRight = (RelativeLayout) findViewById(R.id.right_drawer);
    ListView hostsList = (ListView) findViewById(R.id.host_list);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {
        @Override
        public void onDrawerStateChanged(int newState) {
            super.onDrawerStateChanged(newState);

            if (newState == DrawerLayout.STATE_DRAGGING)
                mUiHider.show();
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);
        }

        public void onDrawerClosed(View view) {
            if (!mIsDoingSearch && !mDrawerLayout.isDrawerVisible(mDrawerLeft)
                    && !mDrawerLayout.isDrawerVisible(mDrawerRight)) {
                mUiHider.setAutoHideDelay(AUTO_HIDE_DELAY_MILLIS);
                mUiHider.hide();
            }
        }

        public void onDrawerOpened(View drawerView) {
            mUiHider.setAutoHideDelay(UiHider.AUTO_HIDE_DELAY_DISABLED);
            mUiHider.show();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    HostsTable.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            getLoaderManager().restartLoader(R.id.loader_host_ids, null, PostListActivity.this);
        }

        @Override
        public void onInvalidated() {
            super.onInvalidated();
            mHostsAdapter.swapCursor(null);
        }
    });
    mHostsAdapter = new CursorAdapter(this, null, false) {
        private CompoundButton.OnCheckedChangeListener mOnCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton button, boolean checked) {
                ViewHolder holder = (ViewHolder) button.getTag(R.id.view_tag_view_holder);
                Host host = SiteSession.getHostById(holder.host_id);
                host.enabled = checked;
                HostsTable.addOrUpdateHost(host);
            }
        };

        class ViewHolder {
            int host_id;
            TextView title;
            TextView summary;
            CheckBox toggle;

            public ViewHolder(View view, int host_id) {
                this.host_id = host_id;
                this.title = (TextView) view.findViewById(android.R.id.title);
                this.summary = (TextView) view.findViewById(android.R.id.summary);
                this.toggle = (CheckBox) view.findViewById(android.R.id.toggle);
                this.toggle.setTag(R.id.view_tag_view_holder, this);
            }
        }

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.listitem_drawer_host_item, parent, false);
            view.setTag(R.id.view_tag_view_holder,
                    new ViewHolder(view, cursor.getInt(HostsTable.INDEX_HOST_DATABASE_ID)));
            return view;
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            Host host = SiteSession.getHostById(cursor.getInt(HostsTable.INDEX_HOST_DATABASE_ID));
            if (host == null)
                return;

            ViewHolder holder = (ViewHolder) view.getTag(R.id.view_tag_view_holder);

            holder.host_id = host.id;
            holder.toggle.setChecked(host.enabled);
            holder.title.setText(host.name);
            holder.summary.setText(host.url);
            holder.toggle.setOnCheckedChangeListener(mOnCheckedChangeListener);
        }
    };
    DrawerListAdapter adapter = new DrawerListAdapter(this, mHostsAdapter);
    hostsList.setAdapter(adapter);
    hostsList.setChoiceMode(AbsListView.CHOICE_MODE_NONE);
    hostsList.setOnItemClickListener(this);
    hostsList.setOnItemLongClickListener(this);

    getLoaderManager().initLoader(R.id.loader_host_ids, null, this);

    // Set up an instance of SystemUiHider to control the system UI for
    // this activity.
    mUiHider = new UiHider(AUTO_HIDE_DELAY_MILLIS, new UiHider.OnVisibilityChangeListener() {
        @Override
        public void onVisibilityChange(boolean visible) {
            if (visible)
                getActionBar().show();
            else
                getActionBar().hide();
        }
    });

    if (savedInstanceState == null) {
        mPostListFragment = new PostListFragment();
        getFragmentManager().beginTransaction().replace(R.id.post_list_container, mPostListFragment).commit();
    }
}

From source file:fr.free.nrw.commons.media.MediaDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    detailProvider = (fr.free.nrw.commons.media.MediaDetailPagerFragment.MediaDetailProvider) getActivity();

    if (savedInstanceState != null) {
        editable = savedInstanceState.getBoolean("editable");
        index = savedInstanceState.getInt("index");
        initialListTop = savedInstanceState.getInt("listTop");
    } else {/*from   w  w w.j a  v a 2  s .  co  m*/
        editable = getArguments().getBoolean("editable");
        index = getArguments().getInt("index");
        initialListTop = 0;
    }
    categoryNames = new ArrayList<String>();
    categoryNames.add(getString(R.string.detail_panel_cats_loading));

    final View view = inflater.inflate(R.layout.fragment_media_detail, container, false);

    image = (ImageView) view.findViewById(R.id.mediaDetailImage);
    loadingProgress = (ProgressBar) view.findViewById(R.id.mediaDetailImageLoading);
    loadingFailed = (ImageView) view.findViewById(R.id.mediaDetailImageFailed);
    scrollView = (ScrollView) view.findViewById(R.id.mediaDetailScrollView);

    // Detail consists of a list view with main pane in header view, plus category list.
    spacer = (fr.free.nrw.commons.media.MediaDetailSpacer) view.findViewById(R.id.mediaDetailSpacer);
    title = (TextView) view.findViewById(R.id.mediaDetailTitle);
    desc = (TextView) view.findViewById(R.id.mediaDetailDesc);
    license = (TextView) view.findViewById(R.id.mediaDetailLicense);
    categoryContainer = (LinearLayout) view.findViewById(R.id.mediaDetailCategoryContainer);

    licenseList = new LicenseList(getActivity());

    Media media = detailProvider.getMediaAtPosition(index);
    if (media == null) {
        // Ask the detail provider to ping us when we're ready
        Log.d("Commons", "MediaDetailFragment not yet ready to display details; registering observer");
        dataObserver = new DataSetObserver() {
            public void onChanged() {
                Log.d("Commons", "MediaDetailFragment ready to display delayed details!");
                detailProvider.unregisterDataSetObserver(dataObserver);
                dataObserver = null;
                displayMediaDetails(detailProvider.getMediaAtPosition(index));
            }
        };
        detailProvider.registerDataSetObserver(dataObserver);
    } else {
        Log.d("Commons", "MediaDetailFragment ready to display details");
        displayMediaDetails(media);
    }

    // Progressively darken the image in the background when we scroll detail pane up
    scrollListener = new ViewTreeObserver.OnScrollChangedListener() {
        public void onScrollChanged() {
            updateTheDarkness();
        }
    };
    view.getViewTreeObserver().addOnScrollChangedListener(scrollListener);

    // Layout layoutListener to size the spacer item relative to the available space.
    // There may be a .... better way to do this.
    layoutListener = new ViewTreeObserver.OnGlobalLayoutListener() {
        private int currentHeight = -1;

        public void onGlobalLayout() {
            int viewHeight = view.getHeight();
            //int textHeight = title.getLineHeight();
            int paddingDp = 112;
            float paddingPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, paddingDp,
                    getResources().getDisplayMetrics());
            int newHeight = viewHeight - Math.round(paddingPx);

            if (newHeight != currentHeight) {
                currentHeight = newHeight;
                ViewGroup.LayoutParams params = spacer.getLayoutParams();
                params.height = newHeight;
                spacer.setLayoutParams(params);

                scrollView.scrollTo(0, initialListTop);
            }

        }
    };
    view.getViewTreeObserver().addOnGlobalLayoutListener(layoutListener);
    return view;
}

From source file:com.bccs.bsecure.Conversation.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    //If convo was opened from the main view, it will have a number value in the intent
    //currentNumber variable is used when loading messages from the DB.
    if (getIntent().hasExtra("contactid")) {
        currentNumber = new Contact(getIntent().getLongExtra("contactid", -1));
        //Cancel any notifications for this number
        if (currentNumber.getId() == SmsBroadcastReceiver.recentID)
            MessageReceivedNotification.cancel(this);
    } else {/*from w w  w . j  a va2s. co m*/
        //If it was not opened from the main view, use the most recent number an SMS
        //was received from.
        currentNumber = new Contact(SmsBroadcastReceiver.recentID);
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_conversation);
    setTitle(currentNumber.getName());

    conversation = new ArrayList<>();
    typeMessage = (EditText) findViewById(R.id.messageEditText);
    listView = (ListView) findViewById(R.id.contactListView);
    send = (Button) findViewById(R.id.sendButton);

    chatAdapter = new chatAdapter();
    listView.setAdapter(chatAdapter);
    // Create the on-click listener for the send button
    send.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            String message = typeMessage.getText().toString();
            typeMessage.setText("");

            if (currentNumber.getNumber().length() > 0 && message.length() > 0) {
                MyMessage msgObj = HandleMessage.send(currentNumber.getId(), message, getApplicationContext());
                ConversationManager.ConversationHelper helper = ConversationManager
                        .getConversation(Conversation.this, currentNumber.getId());
                helper.addMessage(msgObj);
                updateConvo();
            }
        }
    });

    // Scrolls to the bottom in the event of data change.
    listView.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
    chatAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            listView.setSelection(chatAdapter.getCount());
        }
    });

    findViewById(R.id.wipeConversation).setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            WipeConversationDialog dialog = new WipeConversationDialog();
            dialog.show(getFragmentManager(), "conversation_option");
        }
    });

    //Register our receiver in the LocalBroadcastManager.
    //NOTE this is different from calling registerReceiver from the contextWrapper.
    LocalBroadcastManager.getInstance(this).registerReceiver(onNewMsg, onNewMsgFilter);
    receiversRegistered = true;

    updateConvo();
}

From source file:org.peercast.pecaport.PecaPortFragmentBase.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mContentView = (ContainerFrame) view;

    final Spinner vWanConnectionSelector = (Spinner) mContentView.findViewById(R.id.vWanConnectionSelector);
    final TableView vMappingEntries = (TableView) mContentView.findViewById(R.id.vMappingEntries);
    vPeerCast = (PeerCastButton) mContentView.findViewById(R.id.vPeerCast);
    final ImageButton vAdd = (ImageButton) mContentView.findViewById(R.id.vAdd);

    if (!mPreferences.isDebug())
        vAdd.setVisibility(View.GONE);

    mWanConnectionAdapter = new WanConnectionsAdapter();
    vWanConnectionSelector.setAdapter(mWanConnectionAdapter);

    final AdapterView.OnItemSelectedListener wanItemListener = new AdapterView.OnItemSelectedListener() {
        @Override//ww w  .jav  a2s.co  m
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            WanConnection conn = (WanConnection) parent.getItemAtPosition(position);
            String externalIp = conn.getExternalIp();
            if (externalIp == null)
                externalIp = getContext().getString(R.string.t_empty);
            mViewBinder.updateTextView(R.id.vWanExternalIp, externalIp);

            onPreparePeerCastButton(vPeerCast, conn);
            mMappingAdapter.setPortMappings(conn.getMappingEntries());
            updateAddButton(vAdd);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    };
    vWanConnectionSelector.setOnItemSelectedListener(wanItemListener);

    mWanConnectionAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            int enabledPos = mWanConnectionAdapter.getConnectedPosition();
            if (enabledPos != -1) {
                wanItemListener.onItemSelected(vWanConnectionSelector, null, enabledPos, 0);
            }
            updateAddButton(vAdd);
        }
    });

    mMappingAdapter = new MappingEntryAdapter(getContext(), new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onDeleteMapping((WanConnection) vWanConnectionSelector.getSelectedItem(), (PortMapping) v.getTag());
        }
    });
    vMappingEntries.setAdapter(mMappingAdapter);

    vPeerCast.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Log.d(TAG, "" + v);
            WanConnection conn = (WanConnection) vWanConnectionSelector.getSelectedItem();
            if (conn != null)
                onClickPeerCastButton(vPeerCast, conn);
            else
                showToast("WanConnection not found.");
        }
    });

    vAdd.setEnabled(mActiveNicInfo != null);
    vAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onRequestAddPort(mWanConnectionAdapter.getConnected());
        }
    });
}