Search in sources :

Example 6 with DataSetObserver

use of android.database.DataSetObserver in project howabout-android by recomio.

the class MusicBottomBarFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_music_bottom_bar, container, false);
    rootView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(getActivity(), MusicPlaylistActivity.class);
            Bundle bundle = new Bundle();
            intent.putExtras(bundle);
            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
            startActivity(intent);
        }
    });
    imageView = (ImageView) rootView.findViewById(R.id.image);
    trackTitle = (TextView) rootView.findViewById(R.id.trackTitle);
    artistName = (TextView) rootView.findViewById(R.id.artistName);
    isLoading = (ProgressBar) rootView.findViewById(R.id.isLoading);
    isPlaying = (ImageView) rootView.findViewById(R.id.isPlaying);
    isPlaying.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            HowaboutApplication application = (HowaboutApplication) getActivity().getApplication();
            MusicPlaylistAdapter playlistAdapter = application.getPlaylistAdapter();
            playlistAdapter.playPauseToggle();
        }
    });
    playlistObserver = new DataSetObserver() {

        @Override
        public void onChanged() {
            updateTrack();
        }

        @Override
        public void onInvalidated() {
            updateTrack();
        }
    };
    HowaboutApplication application = (HowaboutApplication) getActivity().getApplication();
    MusicPlaylistAdapter playlistAdapter = application.getPlaylistAdapter();
    playlistAdapter.registerDataSetObserver(playlistObserver);
    return rootView;
}
Also used : Bundle(android.os.Bundle) MusicPlaylistAdapter(io.recom.howabout.category.music.adapter.MusicPlaylistAdapter) OnClickListener(android.view.View.OnClickListener) Intent(android.content.Intent) MusicPlaylistActivity(io.recom.howabout.category.music.activity.MusicPlaylistActivity) HowaboutApplication(io.recom.howabout.HowaboutApplication) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) DataSetObserver(android.database.DataSetObserver)

Example 7 with DataSetObserver

use of android.database.DataSetObserver in project XobotOS by xamarin.

the class CalendarView method setUpAdapter.

/**
     * Creates a new adapter if necessary and sets up its parameters.
     */
private void setUpAdapter() {
    if (mAdapter == null) {
        mAdapter = new WeeksAdapter(getContext());
        mAdapter.registerDataSetObserver(new DataSetObserver() {

            @Override
            public void onChanged() {
                if (mOnDateChangeListener != null) {
                    Calendar selectedDay = mAdapter.getSelectedDay();
                    mOnDateChangeListener.onSelectedDayChange(CalendarView.this, selectedDay.get(Calendar.YEAR), selectedDay.get(Calendar.MONTH), selectedDay.get(Calendar.DAY_OF_MONTH));
                }
            }
        });
        mListView.setAdapter(mAdapter);
    }
    // refresh the view with the new parameters
    mAdapter.notifyDataSetChanged();
}
Also used : Calendar(java.util.Calendar) DataSetObserver(android.database.DataSetObserver)

Example 8 with DataSetObserver

use of android.database.DataSetObserver in project UltimateAndroid by cymcsg.

the class BaseSuperAbsListview method setAdapter.

/**
     * Set the adapter to the listview
     * Automativally hide the progressbar
     * Set the refresh to false
     * If adapter is empty, then the emptyview is shown
     *
     * @param adapter
     */
public void setAdapter(ListAdapter adapter) {
    mProgress.setVisibility(View.GONE);
    if (mEmpty != null && mEmptyId != 0)
        mList.setEmptyView(mEmpty);
    mList.setVisibility(View.VISIBLE);
    mPtrLayout.setRefreshing(false);
    adapter.registerDataSetObserver(new DataSetObserver() {

        @Override
        public void onChanged() {
            super.onChanged();
            mProgress.setVisibility(View.GONE);
            isLoadingMore = false;
            mPtrLayout.setRefreshing(false);
            if (mList.getAdapter().getCount() == 0 && mEmptyId != 0) {
                mEmpty.setVisibility(View.VISIBLE);
            } else if (mEmptyId != 0) {
                mEmpty.setVisibility(View.GONE);
            }
        }
    });
    if ((adapter == null || adapter.getCount() == 0) && mEmptyId != 0) {
        mEmpty.setVisibility(View.VISIBLE);
    }
}
Also used : DataSetObserver(android.database.DataSetObserver)

Example 9 with DataSetObserver

use of android.database.DataSetObserver in project MaterialList by dexafree.

the class ListCardProvider method render.

@Override
public void render(@NonNull final View view, @NonNull final Card card) {
    super.render(view, card);
    if (getAdapter() != null) {
        final ListView listView = (ListView) view.findViewById(R.id.listView);
        listView.setScrollbarFadingEnabled(true);
        listView.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // That the gesture detection is correct
                return false;
            }
        });
        listView.setAdapter(getAdapter());
        listView.getAdapter().registerDataSetObserver(new DataSetObserver() {

            @Override
            public void onChanged() {
                super.onChanged();
                calculateListHeight(listView);
            }
        });
        listView.setOnItemClickListener(getOnItemClickListener());
        calculateListHeight(listView);
    }
}
Also used : ListView(android.widget.ListView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) DataSetObserver(android.database.DataSetObserver) MotionEvent(android.view.MotionEvent)

Example 10 with DataSetObserver

use of android.database.DataSetObserver in project Launcher3 by chislon.

the class WallpaperPickerActivity method init.

// called by onCreate; this is subclassed to overwrite WallpaperCropActivity
protected void init() {
    setContentView(R.layout.wallpaper_picker);
    mCropView = (CropView) findViewById(R.id.cropView);
    mWallpaperStrip = findViewById(R.id.wallpaper_strip);
    mCropView.setTouchCallback(new CropView.TouchCallback() {

        LauncherViewPropertyAnimator mAnim;

        @Override
        public void onTouchDown() {
            if (mAnim != null) {
                mAnim.cancel();
            }
            if (mWallpaperStrip.getAlpha() == 1f) {
                mIgnoreNextTap = true;
            }
            mAnim = new LauncherViewPropertyAnimator(mWallpaperStrip);
            mAnim.alpha(0f).setDuration(150).addListener(new Animator.AnimatorListener() {

                public void onAnimationStart(Animator animator) {
                }

                public void onAnimationEnd(Animator animator) {
                    mWallpaperStrip.setVisibility(View.INVISIBLE);
                }

                public void onAnimationCancel(Animator animator) {
                }

                public void onAnimationRepeat(Animator animator) {
                }
            });
            mAnim.setInterpolator(new AccelerateInterpolator(0.75f));
            mAnim.start();
        }

        @Override
        public void onTouchUp() {
            mIgnoreNextTap = false;
        }

        @Override
        public void onTap() {
            boolean ignoreTap = mIgnoreNextTap;
            mIgnoreNextTap = false;
            if (!ignoreTap) {
                if (mAnim != null) {
                    mAnim.cancel();
                }
                mWallpaperStrip.setVisibility(View.VISIBLE);
                mAnim = new LauncherViewPropertyAnimator(mWallpaperStrip);
                mAnim.alpha(1f).setDuration(150).setInterpolator(new DecelerateInterpolator(0.75f));
                mAnim.start();
            }
        }
    });
    mThumbnailOnClickListener = new OnClickListener() {

        public void onClick(View v) {
            if (mActionMode != null) {
                // When CAB is up, clicking toggles the item instead
                if (v.isLongClickable()) {
                    mLongClickListener.onLongClick(v);
                }
                return;
            }
            WallpaperTileInfo info = (WallpaperTileInfo) v.getTag();
            if (info.isSelectable()) {
                if (mSelectedThumb != null) {
                    mSelectedThumb.setSelected(false);
                    mSelectedThumb = null;
                }
                mSelectedThumb = v;
                v.setSelected(true);
                // TODO: Remove this once the accessibility framework and
                // services have better support for selection state.
                v.announceForAccessibility(getString(R.string.announce_selection, v.getContentDescription()));
            }
            info.onClick(WallpaperPickerActivity.this);
        }
    };
    mLongClickListener = new View.OnLongClickListener() {

        // Called when the user long-clicks on someView
        public boolean onLongClick(View view) {
            CheckableFrameLayout c = (CheckableFrameLayout) view;
            c.toggle();
            if (mActionMode != null) {
                mActionMode.invalidate();
            } else {
                // Start the CAB using the ActionMode.Callback defined below
                mActionMode = startActionMode(mActionModeCallback);
                int childCount = mWallpapersView.getChildCount();
                for (int i = 0; i < childCount; i++) {
                    mWallpapersView.getChildAt(i).setSelected(false);
                }
            }
            return true;
        }
    };
    // Populate the built-in wallpapers
    ArrayList<ResourceWallpaperInfo> wallpapers = findBundledWallpapers();
    mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list);
    BuiltInWallpapersAdapter ia = new BuiltInWallpapersAdapter(this, wallpapers);
    populateWallpapersFromAdapter(mWallpapersView, ia, false, true);
    // Populate the saved wallpapers
    mSavedImages = new SavedWallpaperImages(this);
    mSavedImages.loadThumbnailsAndImageIdList();
    populateWallpapersFromAdapter(mWallpapersView, mSavedImages, true, true);
    // Populate the live wallpapers
    final LinearLayout liveWallpapersView = (LinearLayout) findViewById(R.id.live_wallpaper_list);
    final LiveWallpaperListAdapter a = new LiveWallpaperListAdapter(this);
    a.registerDataSetObserver(new DataSetObserver() {

        public void onChanged() {
            liveWallpapersView.removeAllViews();
            populateWallpapersFromAdapter(liveWallpapersView, a, false, false);
            initializeScrollForRtl();
            updateTileIndices();
        }
    });
    // Populate the third-party wallpaper pickers
    final LinearLayout thirdPartyWallpapersView = (LinearLayout) findViewById(R.id.third_party_wallpaper_list);
    final ThirdPartyWallpaperPickerListAdapter ta = new ThirdPartyWallpaperPickerListAdapter(this);
    populateWallpapersFromAdapter(thirdPartyWallpapersView, ta, false, false);
    // Add a tile for the Gallery
    LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list);
    FrameLayout pickImageTile = (FrameLayout) getLayoutInflater().inflate(R.layout.wallpaper_picker_image_picker_item, masterWallpaperList, false);
    setWallpaperItemPaddingToZero(pickImageTile);
    masterWallpaperList.addView(pickImageTile, 0);
    // Make its background the last photo taken on external storage
    Bitmap lastPhoto = getThumbnailOfLastPhoto();
    if (lastPhoto != null) {
        ImageView galleryThumbnailBg = (ImageView) pickImageTile.findViewById(R.id.wallpaper_image);
        galleryThumbnailBg.setImageBitmap(getThumbnailOfLastPhoto());
        int colorOverlay = getResources().getColor(R.color.wallpaper_picker_translucent_gray);
        galleryThumbnailBg.setColorFilter(colorOverlay, PorterDuff.Mode.SRC_ATOP);
    }
    PickImageInfo pickImageInfo = new PickImageInfo();
    pickImageTile.setTag(pickImageInfo);
    pickImageInfo.setView(pickImageTile);
    pickImageTile.setOnClickListener(mThumbnailOnClickListener);
    pickImageInfo.setView(pickImageTile);
    updateTileIndices();
    // Update the scroll for RTL
    initializeScrollForRtl();
    // Create smooth layout transitions for when items are deleted
    final LayoutTransition transitioner = new LayoutTransition();
    transitioner.setDuration(200);
    transitioner.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0);
    transitioner.setAnimator(LayoutTransition.DISAPPEARING, null);
    mWallpapersView.setLayoutTransition(transitioner);
    // Action bar
    // Show the custom action bar view
    final ActionBar actionBar = getActionBar();
    actionBar.setCustomView(R.layout.actionbar_set_wallpaper);
    actionBar.getCustomView().setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mSelectedThumb != null) {
                WallpaperTileInfo info = (WallpaperTileInfo) mSelectedThumb.getTag();
                info.onSave(WallpaperPickerActivity.this);
            }
        }
    });
    // CAB for deleting items
    mActionModeCallback = new ActionMode.Callback() {

        // Called when the action mode is created; startActionMode() was called
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // Inflate a menu resource providing context menu items
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.cab_delete_wallpapers, menu);
            return true;
        }

        private int numCheckedItems() {
            int childCount = mWallpapersView.getChildCount();
            int numCheckedItems = 0;
            for (int i = 0; i < childCount; i++) {
                CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i);
                if (c.isChecked()) {
                    numCheckedItems++;
                }
            }
            return numCheckedItems;
        }

        // Called each time the action mode is shown. Always called after onCreateActionMode,
        // but may be called multiple times if the mode is invalidated.
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            int numCheckedItems = numCheckedItems();
            if (numCheckedItems == 0) {
                mode.finish();
                return true;
            } else {
                mode.setTitle(getResources().getQuantityString(R.plurals.number_of_items_selected, numCheckedItems, numCheckedItems));
                return true;
            }
        }

        // Called when the user selects a contextual menu item
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            int itemId = item.getItemId();
            if (itemId == R.id.menu_delete) {
                int childCount = mWallpapersView.getChildCount();
                ArrayList<View> viewsToRemove = new ArrayList<View>();
                for (int i = 0; i < childCount; i++) {
                    CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i);
                    if (c.isChecked()) {
                        WallpaperTileInfo info = (WallpaperTileInfo) c.getTag();
                        info.onDelete(WallpaperPickerActivity.this);
                        viewsToRemove.add(c);
                    }
                }
                for (View v : viewsToRemove) {
                    mWallpapersView.removeView(v);
                }
                updateTileIndices();
                // Action picked, so close the CAB
                mode.finish();
                return true;
            } else {
                return false;
            }
        }

        // Called when the user exits the action mode
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            int childCount = mWallpapersView.getChildCount();
            for (int i = 0; i < childCount; i++) {
                CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i);
                c.setChecked(false);
            }
            mSelectedThumb.setSelected(true);
            mActionMode = null;
        }
    };
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ArrayList(java.util.ArrayList) LayoutTransition(android.animation.LayoutTransition) Bitmap(android.graphics.Bitmap) ImageView(android.widget.ImageView) Menu(android.view.Menu) ActionBar(android.app.ActionBar) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) MenuInflater(android.view.MenuInflater) OnClickListener(android.view.View.OnClickListener) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) DataSetObserver(android.database.DataSetObserver) Point(android.graphics.Point) Animator(android.animation.Animator) ActionMode(android.view.ActionMode) FrameLayout(android.widget.FrameLayout) OnClickListener(android.view.View.OnClickListener) LinearLayout(android.widget.LinearLayout)

Aggregations

DataSetObserver (android.database.DataSetObserver)36 View (android.view.View)14 AdapterView (android.widget.AdapterView)9 ImageView (android.widget.ImageView)9 TextView (android.widget.TextView)9 OnClickListener (android.view.View.OnClickListener)8 ListView (android.widget.ListView)8 Calendar (android.icu.util.Calendar)5 PrintManager (android.print.PrintManager)5 PrinterInfo (android.print.PrinterInfo)5 PrintServiceInfo (android.printservice.PrintServiceInfo)5 SearchView (android.widget.SearchView)5 Intent (android.content.Intent)3 Calendar (java.util.Calendar)3 Bitmap (android.graphics.Bitmap)2 DisplayMetrics (android.util.DisplayMetrics)2 ViewGroup (android.view.ViewGroup)2 ScrollView (android.widget.ScrollView)2 HowaboutApplication (io.recom.howabout.HowaboutApplication)2 ArrayList (java.util.ArrayList)2