Search in sources :

Example 56 with AbsListView

use of android.widget.AbsListView in project fuckView by w568w.

the class MainFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
    context = getActivity();
    pm = context.getPackageManager();
    FrameLayout layout = (FrameLayout) inflater.inflate(R.layout.main_fragment, null);
    listView = (ListView) layout.findViewById(R.id.listView);
    models = MainActivity.read();
    try {
        Collections.sort(models, new Comparator<BlockModel>() {

            @Override
            public int compare(BlockModel blockModel, BlockModel t1) {
                String s1 = getAppTitle(pm, blockModel.packageName);
                String s2 = getAppTitle(pm, t1.packageName);
                // Synopsis: Updated sort behavior for Arrays and Collections may throw an IllegalArgumentException
                if (s1.equals(s2)) {
                    return 0;
                }
                return Collator.getInstance(Locale.CHINA).compare(s1, s2);
            }
        });
    } catch (IllegalArgumentException e) {
        // So we will not sort them,OK?
        e.printStackTrace();
    }
    adapter = new AppAdapter();
    listView.setAdapter(adapter);
    registerForContextMenu(listView);
    final FloatingActionButton button = (FloatingActionButton) layout.findViewById(R.id.fab);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            SelectAppWizard tw = new SelectAppWizard();
            Bundle bundle = new Bundle();
            if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean("system_app", false)) {
                bundle.putBoolean("sys", true);
            }
            tw.setArguments(bundle);
            if (context instanceof MainActivity) {
                ((MainActivity) context).setFragment(tw);
            }
        }
    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            BlockModel model = models.get(i);
            Bundle bundle = new Bundle();
            bundle.putString("pkg", model.packageName);
            bundle.putString("record", model.record);
            bundle.putString("className", model.className);
            InfoFragment infoFragment = new InfoFragment();
            infoFragment.setArguments(bundle);
            if (context instanceof MainActivity) {
                ((MainActivity) context).setFragment(infoFragment);
            }
        }
    });
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {

        /* 标记是否滑动 */
        boolean scrollFlag = false;

        /* 标记第一次进入,因为第一次进来lastVisibleItemPosition默认为0, */
        boolean isFirst = true;

        /*
            此时如果listview的第一个显示的条目不是第一个(下表为0),则往下滑也会出现firstVisibleItem>lastVisibleItemPosition的情况
            所以第一次进入时不做操作,第二次进来已经给lastVisibleItemPosition赋值,就可以判断了
            */
        /* 标记上次的显示位置 */
        int lastVisibleItemPosition;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            scrollFlag = scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL || scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING;
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (!isFirst) {
                if (firstVisibleItem < lastVisibleItemPosition) {
                    button.show();
                // 执行向上滑动时要做的逻辑
                } else if (firstVisibleItem > lastVisibleItemPosition) {
                    button.hide();
                }
                // 记录当前条目
                lastVisibleItemPosition = firstVisibleItem;
            }
            isFirst = false;
        }
    });
    return layout;
}
Also used : Bundle(android.os.Bundle) AbsListView(android.widget.AbsListView) MainActivity(ml.qingsu.fuckview.ui.activities.MainActivity) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ListView(android.widget.ListView) FrameLayout(android.widget.FrameLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) AdapterView(android.widget.AdapterView) BlockModel(ml.qingsu.fuckview.models.BlockModel) SelectAppWizard(ml.qingsu.fuckview.ui.fragments.select_app.SelectAppWizard) Nullable(android.support.annotation.Nullable)

Example 57 with AbsListView

use of android.widget.AbsListView in project RoMote by wseemann.

the class ChannelFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_channels, container, false);
    final GridView mGridView = (GridView) v.findViewById(android.R.id.list);
    mSwiperefresh = (SwipeRefreshLayout) v.findViewById(R.id.swiperefresh);
    mSwiperefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            // This method performs the actual data-refresh operation.
            // The method calls setRefreshing(false) when it's finished.
            getLoaderManager().restartLoader(0, new Bundle(), ChannelFragment.this);
        }
    });
    // View emptyView = v.findViewById(android.R.id.empty);
    // mGridView.setEmptyView(emptyView);
    mGridView.setAdapter(mAdapter);
    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Channel channel = (Channel) parent.getItemAtPosition(position);
            performLaunch(channel.getId());
        }
    });
    mGridView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView absListView, int scrollState) {
            // Pause fetcher to ensure smoother scrolling when flinging
            if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) {
                // Before Honeycomb pause image loading on scroll to help with performance
                if (!Utils.hasHoneycomb()) {
                    mImageFetcher.setPauseWork(true);
                }
            } else {
                mImageFetcher.setPauseWork(false);
            }
        }

        @Override
        public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        }
    });
    // This listener is used to get the final width of the GridView and then calculate the
    // number of columns and the width of each column. The width of each column is variable
    // as the GridView has stretchMode=columnWidth. The column width is used to set the height
    // of each view so we get nice square thumbnails.
    mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @TargetApi(VERSION_CODES.JELLY_BEAN)
        @Override
        public void onGlobalLayout() {
            if (mAdapter.getNumColumns() == 0) {
                final int numColumns = (int) Math.floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing));
                if (numColumns > 0) {
                    final int columnWidth = (mGridView.getWidth() / numColumns) - mImageThumbSpacing;
                    mAdapter.setNumColumns(numColumns);
                    mAdapter.setItemHeight(columnWidth);
                    if (BuildConfig.DEBUG) {
                        Log.d(TAG, "onCreateView - numColumns set to " + numColumns);
                    }
                    if (Utils.hasJellyBean()) {
                        mGridView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
                    } else {
                        mGridView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                    }
                }
            }
        }
    });
    return v;
}
Also used : Bundle(android.os.Bundle) Channel(com.jaku.model.Channel) AbsListView(android.widget.AbsListView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SuppressLint(android.annotation.SuppressLint) AdapterView(android.widget.AdapterView) GridView(android.widget.GridView) ViewTreeObserver(android.view.ViewTreeObserver) TargetApi(android.annotation.TargetApi)

Example 58 with AbsListView

use of android.widget.AbsListView in project ultrasonic by ultrasonic.

the class SelectAlbumActivity method onCreate.

/**
 * Called when the activity is first created.
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.select_album);
    albumButtons = findViewById(R.id.menu_album);
    refreshAlbumListView = (PullToRefreshListView) findViewById(R.id.select_album_entries);
    albumListView = refreshAlbumListView.getRefreshableView();
    refreshAlbumListView.setOnRefreshListener(new OnRefreshListener<ListView>() {

        @Override
        public void onRefresh(PullToRefreshBase<ListView> refreshView) {
            new GetDataTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
        }
    });
    refreshAlbumListView.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            for (int i = 0; i < albumListView.getChildCount(); i++) {
                Object child = albumListView.getChildAt(i);
                if (child instanceof AlbumView) {
                    AlbumView albumView = (AlbumView) child;
                    if (albumView.isMaximized()) {
                        albumView.maximizeOrMinimize();
                    }
                }
                if (child instanceof SongView) {
                    SongView songView = (SongView) child;
                    if (songView.isMaximized()) {
                        songView.maximizeOrMinimize();
                    }
                }
            }
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
        }
    });
    header = LayoutInflater.from(this).inflate(R.layout.select_album_header, albumListView, false);
    albumListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    albumListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position >= 0) {
                MusicDirectory.Entry entry = (MusicDirectory.Entry) parent.getItemAtPosition(position);
                if (entry != null && entry.isDirectory()) {
                    Intent intent = new Intent(SelectAlbumActivity.this, SelectAlbumActivity.class);
                    intent.putExtra(Constants.INTENT_EXTRA_NAME_ID, entry.getId());
                    intent.putExtra(Constants.INTENT_EXTRA_NAME_IS_ALBUM, entry.isDirectory());
                    intent.putExtra(Constants.INTENT_EXTRA_NAME_NAME, entry.getTitle());
                    intent.putExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID, entry.getParent());
                    startActivityForResultWithoutTransition(SelectAlbumActivity.this, intent);
                } else if (entry != null && entry.isVideo()) {
                    playVideo(entry);
                } else {
                    enableButtons();
                }
            }
        }
    });
    albumListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            if (view instanceof AlbumView) {
                AlbumView albumView = (AlbumView) view;
                if (!albumView.isMaximized()) {
                    albumView.maximizeOrMinimize();
                    return true;
                } else {
                    return false;
                }
            }
            if (view instanceof SongView) {
                SongView songView = (SongView) view;
                songView.maximizeOrMinimize();
                return true;
            }
            return false;
        }
    });
    selectButton = (ImageView) findViewById(R.id.select_album_select);
    playNowButton = (ImageView) findViewById(R.id.select_album_play_now);
    playNextButton = (ImageView) findViewById(R.id.select_album_play_next);
    playLastButton = (ImageView) findViewById(R.id.select_album_play_last);
    pinButton = (ImageView) findViewById(R.id.select_album_pin);
    unpinButton = (ImageView) findViewById(R.id.select_album_unpin);
    downloadButton = (ImageView) findViewById(R.id.select_album_download);
    deleteButton = (ImageView) findViewById(R.id.select_album_delete);
    moreButton = (ImageView) findViewById(R.id.select_album_more);
    emptyView = findViewById(R.id.select_album_empty);
    selectButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            selectAllOrNone();
        }
    });
    playNowButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            playNow(false, false);
        }
    });
    playNextButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            download(true, false, false, true, false, getSelectedSongs(albumListView));
            selectAll(false, false);
        }
    });
    playLastButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            playNow(false, true);
        }
    });
    pinButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            downloadBackground(true);
            selectAll(false, false);
        }
    });
    unpinButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            unpin();
            selectAll(false, false);
        }
    });
    downloadButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            downloadBackground(false);
            selectAll(false, false);
        }
    });
    deleteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            delete();
            selectAll(false, false);
        }
    });
    registerForContextMenu(albumListView);
    enableButtons();
    String id = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID);
    boolean isAlbum = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_IS_ALBUM, false);
    String name = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_NAME);
    String parentId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PARENT_ID);
    String playlistId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID);
    String podcastChannelId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PODCAST_CHANNEL_ID);
    String playlistName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME);
    String shareId = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_SHARE_ID);
    String shareName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_SHARE_NAME);
    String albumListType = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TYPE);
    String genreName = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_GENRE_NAME);
    int albumListTitle = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_TITLE, 0);
    int getStarredTracks = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_STARRED, 0);
    int getVideos = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_VIDEOS, 0);
    int getRandomTracks = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_RANDOM, 0);
    int albumListSize = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_SIZE, 0);
    int albumListOffset = getIntent().getIntExtra(Constants.INTENT_EXTRA_NAME_ALBUM_LIST_OFFSET, 0);
    View browseMenuItem = findViewById(R.id.menu_browse);
    menuDrawer.setActiveView(browseMenuItem);
    if (playlistId != null) {
        getPlaylist(playlistId, playlistName);
    } else if (podcastChannelId != null) {
        getPodcastEpisodes(podcastChannelId);
    } else if (shareId != null) {
        getShare(shareId, shareName);
    } else if (albumListType != null) {
        getAlbumList(albumListType, albumListTitle, albumListSize, albumListOffset);
    } else if (genreName != null) {
        getSongsForGenre(genreName, albumListSize, albumListOffset);
    } else if (getStarredTracks != 0) {
        getStarred();
    } else if (getVideos != 0) {
        getVideos();
    } else if (getRandomTracks != 0) {
        getRandom(albumListSize);
    } else {
        if (!Util.isOffline(SelectAlbumActivity.this) && Util.getShouldUseId3Tags(SelectAlbumActivity.this)) {
            if (isAlbum) {
                getAlbum(id, name, parentId);
            } else {
                getArtist(id, name);
            }
        } else {
            getMusicDirectory(id, name, parentId);
        }
    }
}
Also used : MusicDirectory(org.moire.ultrasonic.domain.MusicDirectory) SongView(org.moire.ultrasonic.view.SongView) AlbumView(org.moire.ultrasonic.view.AlbumView) AbsListView(android.widget.AbsListView) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) AlbumView(org.moire.ultrasonic.view.AlbumView) PullToRefreshListView(com.handmark.pulltorefresh.library.PullToRefreshListView) TextView(android.widget.TextView) SongView(org.moire.ultrasonic.view.SongView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) PullToRefreshListView(com.handmark.pulltorefresh.library.PullToRefreshListView) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView)

Example 59 with AbsListView

use of android.widget.AbsListView in project platform_packages_apps_Settings by BlissRoms.

the class ListDialogPreference method onPrepareDialogBuilder.

@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder, DialogInterface.OnClickListener listener) {
    super.onPrepareDialogBuilder(builder, listener);
    final Context context = getContext();
    final int dialogLayout = getDialogLayoutResource();
    final View picker = LayoutInflater.from(context).inflate(dialogLayout, null);
    final ListPreferenceAdapter adapter = new ListPreferenceAdapter();
    final AbsListView list = (AbsListView) picker.findViewById(android.R.id.list);
    list.setAdapter(adapter);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
            if (callChangeListener((int) id)) {
                setValue((int) id);
            }
            final Dialog dialog = getDialog();
            if (dialog != null) {
                dialog.dismiss();
            }
        }
    });
    // Set initial selection.
    final int selectedPosition = getIndexForValue(mValue);
    if (selectedPosition != AbsListView.INVALID_POSITION) {
        list.setSelection(selectedPosition);
    }
    builder.setView(picker);
    builder.setPositiveButton(null, null);
}
Also used : Context(android.content.Context) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) AbsListView(android.widget.AbsListView) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 60 with AbsListView

use of android.widget.AbsListView in project iNaturalistAndroid by inaturalist.

the class TaxonSuggestionsActivity method resizeSuggestionsList.

private void resizeSuggestionsList() {
    final Handler handler = new Handler();
    if ((mSuggestionsList.getVisibility() == View.VISIBLE) && (mSuggestionsList.getWidth() == 0)) {
        // UI not initialized yet - try later
        handler.postDelayed(new Runnable() {

            @Override
            public void run() {
                resizeSuggestionsList();
            }
        }, 100);
        return;
    }
    mSuggestionsList.setOnScrollListener(new AbsListView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {
        }

        @Override
        public void onScroll(AbsListView absListView, int i, int i1, int i2) {
            int height = setListViewHeightBasedOnItems(mSuggestionsList);
        }
    });
}
Also used : Handler(android.os.Handler) AbsListView(android.widget.AbsListView)

Aggregations

AbsListView (android.widget.AbsListView)223 View (android.view.View)126 ListView (android.widget.ListView)80 AdapterView (android.widget.AdapterView)54 TextView (android.widget.TextView)46 ViewGroup (android.view.ViewGroup)33 ImageView (android.widget.ImageView)29 ScrollView (android.widget.ScrollView)23 RecyclerView (android.support.v7.widget.RecyclerView)21 GridView (android.widget.GridView)21 SuppressLint (android.annotation.SuppressLint)20 OnScrollListener (android.widget.AbsListView.OnScrollListener)19 Intent (android.content.Intent)17 ArrayList (java.util.ArrayList)16 Context (android.content.Context)12 Point (android.graphics.Point)12 Handler (android.os.Handler)12 WebView (android.webkit.WebView)12 ExpandableListView (android.widget.ExpandableListView)12 ArrayListLoader (com.klinker.android.twitter.adapters.ArrayListLoader)10