Search in sources :

Example 41 with AdapterView

use of android.widget.AdapterView in project realm-java by realm.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Setup initial views
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    //noinspection ConstantConditions
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    adapter = null;
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            presenter.listItemSelected(position);
        }
    });
    listView.setEmptyView(getLayoutInflater().inflate(R.layout.common_emptylist, listView, false));
    refreshView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            presenter.refreshList();
        }
    });
    progressBar.setVisibility(View.INVISIBLE);
    // After setup, notify presenter
    presenter.onCreate();
}
Also used : AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) Toolbar(android.support.v7.widget.Toolbar)

Example 42 with AdapterView

use of android.widget.AdapterView in project howabout-android by recomio.

the class MusicPlaylistActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    imageLoader = ImageLoader.getInstance();
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    setAdsContainer(R.id.adView);
    HowaboutApplication application = (HowaboutApplication) getApplication();
    playlistAdapter = application.getPlaylistAdapter();
    if (MusicPlayerService.isLoading()) {
        loadingProgressBar.setVisibility(View.VISIBLE);
        playPauseToggleButton.setVisibility(View.GONE);
    } else {
        if (MusicPlayerService.isPlaying()) {
            playPauseToggleButton.setImageDrawable(pauseIcon);
        } else {
            playPauseToggleButton.setImageDrawable(playIcon);
        }
        loadingProgressBar.setVisibility(View.GONE);
        playPauseToggleButton.setVisibility(View.VISIBLE);
    }
    listView.setAdapter(playlistAdapter);
    playlistAdapter.registerDataSetObserver(new DataSetObserver() {

        @Override
        public void onChanged() {
            try {
                Track track = playlistAdapter.getCurrentItem();
                actionBar.setTitle(track.getTrackTitle());
                actionBar.setSubtitle(track.getArtistName());
                if (MusicPlayerService.isLoading()) {
                    loadingProgressBar.setVisibility(View.VISIBLE);
                    playPauseToggleButton.setVisibility(View.GONE);
                } else {
                    if (MusicPlayerService.isPlaying()) {
                        playPauseToggleButton.setImageDrawable(pauseIcon);
                    } else {
                        playPauseToggleButton.setImageDrawable(playIcon);
                    }
                    loadingProgressBar.setVisibility(View.GONE);
                    playPauseToggleButton.setVisibility(View.VISIBLE);
                }
                imageLoader.displayImage(track.getThumbnailUrl(), songImageView, new ImageLoadingListener() {

                    @Override
                    public void onLoadingStarted(String imageUri, View view) {
                    }

                    @Override
                    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                    }

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    }

                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {
                    }
                });
                String lyrics = playlistAdapter.getCurrentLyrics();
                if (lyrics == null) {
                    lyricsScrollView.setVisibility(View.GONE);
                    lyricsTextView.setText("");
                } else {
                    lyricsScrollView.setVisibility(View.VISIBLE);
                    lyricsTextView.setText(lyrics);
                }
                listView.invalidate();
            } catch (Exception e) {
            }
        }

        @Override
        public void onInvalidated() {
        }
    });
    playlistAdapter.notifyDataSetChanged();
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            playlistAdapter.play(position);
            playlistAdapter.notifyDataSetChanged();
        }
    });
    listView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            playlistAdapter.remove(position);
            return true;
        }
    });
    playPauseToggleButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            playlistAdapter.playPauseToggle();
            if (MusicPlayerService.isPlaying()) {
                playPauseToggleButton.setImageDrawable(pauseIcon);
            } else {
                playPauseToggleButton.setImageDrawable(playIcon);
            }
        }
    });
    prevButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            playlistAdapter.playPrev();
        }
    });
    nextButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            playlistAdapter.playNext();
        }
    });
    UpdateCurrentPositionTask updateCurrentPositionTask = new UpdateCurrentPositionTask();
    updateCurrentPositionTimer.scheduleAtFixedRate(updateCurrentPositionTask, 0, 1000);
}
Also used : ImageLoadingListener(com.nostra13.universalimageloader.core.assist.ImageLoadingListener) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) FailReason(com.nostra13.universalimageloader.core.assist.FailReason) HowaboutApplication(io.recom.howabout.HowaboutApplication) DataSetObserver(android.database.DataSetObserver) ContentView(roboguice.inject.ContentView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) InjectView(roboguice.inject.InjectView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ListView(android.widget.ListView) OnItemLongClickListener(android.widget.AdapterView.OnItemLongClickListener) Bitmap(android.graphics.Bitmap) OnClickListener(android.view.View.OnClickListener) ActionBar(com.actionbarsherlock.app.ActionBar) Track(io.recom.howabout.category.music.model.Track)

Example 43 with AdapterView

use of android.widget.AdapterView in project material by rey5137.

the class ListPopupWindow method buildDropDown.

/**
     * <p>Builds the popup window's content and returns the height the popup
     * should have. Returns -1 when the content already exists.</p>
     *
     * @return the content's height or -1 if content already exists
     */
private int buildDropDown() {
    int otherHeights = 0;
    if (mDropDownList == null) {
        ViewGroup dropDownView;
        Context context = mContext;
        /**
             * This Runnable exists for the sole purpose of checking if the view layout has got
             * completed and if so call showDropDown to display the drop down. This is used to show
             * the drop down as soon as possible after user opens up the search dialog, without
             * waiting for the normal UI pipeline to do it's job which is slower than this method.
             */
        mShowDropDownRunnable = new Runnable() {

            public void run() {
                // View layout should be all done before displaying the drop down.
                View view = getAnchorView();
                if (view != null && view.getWindowToken() != null) {
                    show();
                }
            }
        };
        mDropDownList = new DropDownListView(context, !mModal);
        if (mDropDownListHighlight != null) {
            mDropDownList.setSelector(mDropDownListHighlight);
        }
        mDropDownList.setAdapter(mAdapter);
        mDropDownList.setOnItemClickListener(mItemClickListener);
        mDropDownList.setFocusable(true);
        mDropDownList.setFocusableInTouchMode(true);
        mDropDownList.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (position != -1) {
                    DropDownListView dropDownList = mDropDownList;
                    if (dropDownList != null) {
                        dropDownList.mListSelectionHidden = false;
                    }
                }
            }

            public void onNothingSelected(AdapterView<?> parent) {
            }
        });
        mDropDownList.setOnScrollListener(mScrollListener);
        if (mItemSelectedListener != null) {
            mDropDownList.setOnItemSelectedListener(mItemSelectedListener);
        }
        dropDownView = mDropDownList;
        View hintView = mPromptView;
        if (hintView != null) {
            // if a hint has been specified, we accomodate more space for it and
            // add a text view in the drop down menu, at the bottom of the list
            LinearLayout hintContainer = new LinearLayout(context);
            hintContainer.setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f);
            switch(mPromptPosition) {
                case POSITION_PROMPT_BELOW:
                    hintContainer.addView(dropDownView, hintParams);
                    hintContainer.addView(hintView);
                    break;
                case POSITION_PROMPT_ABOVE:
                    hintContainer.addView(hintView);
                    hintContainer.addView(dropDownView, hintParams);
                    break;
                default:
                    Log.e(TAG, "Invalid hint position " + mPromptPosition);
                    break;
            }
            // measure the hint's height to find how much more vertical space
            // we need to add to the drop down's height
            int widthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.AT_MOST);
            int heightSpec = MeasureSpec.UNSPECIFIED;
            hintView.measure(widthSpec, heightSpec);
            hintParams = (LinearLayout.LayoutParams) hintView.getLayoutParams();
            otherHeights = hintView.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
            dropDownView = hintContainer;
        }
        mPopup.setContentView(dropDownView);
    } else {
        final View view = mPromptView;
        if (view != null) {
            LinearLayout.LayoutParams hintParams = (LinearLayout.LayoutParams) view.getLayoutParams();
            otherHeights = view.getMeasuredHeight() + hintParams.topMargin + hintParams.bottomMargin;
        }
    }
    // getMaxAvailableHeight() subtracts the padding, so we put it back
    // to get the available height for the whole window
    int padding = 0;
    Drawable background = mPopup.getBackground();
    if (background != null) {
        background.getPadding(mTempRect);
        padding = mTempRect.top + mTempRect.bottom;
        // background so that content will line up.
        if (!mDropDownVerticalOffsetSet) {
            mDropDownVerticalOffset = -mTempRect.top;
        }
    } else {
        mTempRect.setEmpty();
    }
    int systemBarsReservedSpace = 0;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        //  getMaxAvailableHeight() on Lollipop seems to ignore the system bars.
        systemBarsReservedSpace = Math.max(getSystemBarHeight("status_bar_height"), getSystemBarHeight("navigation_bar_height"));
    }
    // Max height available on the screen for a popup.
    boolean ignoreBottomDecorations = mPopup.getInputMethodMode() == PopupWindow.INPUT_METHOD_NOT_NEEDED;
    final int maxHeight = mPopup.getMaxAvailableHeight(getAnchorView(), mDropDownVerticalOffset) - systemBarsReservedSpace;
    if (mDropDownAlwaysVisible || mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
        return maxHeight + padding;
    }
    final int childWidthSpec;
    switch(mDropDownWidth) {
        case ViewGroup.LayoutParams.WRAP_CONTENT:
            childWidthSpec = MeasureSpec.makeMeasureSpec(mContext.getResources().getDisplayMetrics().widthPixels - (mTempRect.left + mTempRect.right), MeasureSpec.AT_MOST);
            break;
        case ViewGroup.LayoutParams.MATCH_PARENT:
            childWidthSpec = MeasureSpec.makeMeasureSpec(mContext.getResources().getDisplayMetrics().widthPixels - (mTempRect.left + mTempRect.right), MeasureSpec.EXACTLY);
            break;
        default:
            childWidthSpec = MeasureSpec.makeMeasureSpec(mDropDownWidth, MeasureSpec.EXACTLY);
            break;
    }
    final int listContent = mDropDownList.measureHeightOfChildrenCompat(childWidthSpec, 0, DropDownListView.NO_POSITION, maxHeight - otherHeights, -1);
    // the popup if it is not needed
    if (listContent > 0)
        otherHeights += padding;
    return listContent + otherHeights;
}
Also used : Context(android.content.Context) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) View(android.view.View) AdapterView(android.widget.AdapterView) AbsListView(android.widget.AbsListView) AdapterView(android.widget.AdapterView) LinearLayout(android.widget.LinearLayout)

Example 44 with AdapterView

use of android.widget.AdapterView in project AndroidPractice by lguipeng.

the class SlideMenuFragment method init.

private void init() {
    final List<String> list = new ArrayList<>();
    list.add("Spring");
    list.add("Summer");
    list.add("Autumn");
    list.add("Winter");
    DrawerListAdapter adapter = new DrawerListAdapter(getActivity(), list);
    mDrawerMenuListView.setAdapter(adapter);
    mDrawerMenuListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mCurrentTitlePosition = position;
            mDrawerMenuListView.setItemChecked(position, true);
            mDrawerLayout.closeDrawer(parent);
        }
    });
    mDrawerMenuListView.setItemChecked(mCurrentTitlePosition, true);
    setTitle(list.get(mCurrentTitlePosition));
    mDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, 0, 0) {

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            activity.invalidateOptionsMenu();
            setTitle(R.string.slide_menu);
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            activity.invalidateOptionsMenu();
            setTitle(list.get(mCurrentTitlePosition));
        }
    };
    mDrawerToggle.setDrawerIndicatorEnabled(true);
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.setScrimColor(getColor(R.color.window_background));
}
Also used : ArrayList(java.util.ArrayList) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) AdapterView(android.widget.AdapterView) DrawerListAdapter(com.szu.androidpractice.adapter.DrawerListAdapter) InjectView(butterknife.InjectView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 45 with AdapterView

use of android.widget.AdapterView in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class WithGridView method createView.

@Override
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHeaderTitle(R.string.ptr_demo_block_grid_view);
    mImageLoader = ImageLoaderFactory.create(getContext());
    final View contentView = inflater.inflate(R.layout.fragment_classic_header_with_gridview, null);
    final GridView gridListView = (GridView) contentView.findViewById(R.id.rotate_header_grid_view);
    gridListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position >= 0) {
                final String url = mAdapter.getItem(position).optString("pic");
                if (!TextUtils.isEmpty(url)) {
                    getContext().pushFragmentToBackStack(MaterialStyleFragment.class, url);
                }
            }
        }
    });
    mAdapter = new ListViewDataAdapter<JsonData>(new ViewHolderCreator<JsonData>() {

        @Override
        public ViewHolderBase<JsonData> createViewHolder(int position) {
            return new ViewHolder();
        }
    });
    gridListView.setAdapter(mAdapter);
    mPtrFrame = (PtrClassicFrameLayout) contentView.findViewById(R.id.rotate_header_grid_view_frame);
    mPtrFrame.setLastUpdateTimeRelateObject(this);
    mPtrFrame.setPtrHandler(new PtrHandler() {

        @Override
        public void onRefreshBegin(PtrFrameLayout frame) {
            updateData();
        }

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
        }
    });
    // the following are default settings
    mPtrFrame.setResistance(1.7f);
    mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f);
    mPtrFrame.setDurationToClose(200);
    mPtrFrame.setDurationToCloseHeader(1000);
    // default is false
    mPtrFrame.setPullToRefresh(false);
    // default is true
    mPtrFrame.setKeepHeaderWhenRefresh(true);
    mPtrFrame.postDelayed(new Runnable() {

        @Override
        public void run() {
        // mPtrFrame.autoRefresh();
        }
    }, 100);
    // updateData();
    setupViews(mPtrFrame);
    return contentView;
}
Also used : PtrHandler(in.srain.cube.views.ptr.PtrHandler) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) GridView(android.widget.GridView) CubeImageView(in.srain.cube.image.CubeImageView) View(android.view.View) AdapterView(android.widget.AdapterView) JsonData(in.srain.cube.request.JsonData) MaterialStyleFragment(in.srain.cube.views.ptr.demo.ui.MaterialStyleFragment) AdapterView(android.widget.AdapterView) GridView(android.widget.GridView) ViewHolderCreator(in.srain.cube.views.list.ViewHolderCreator)

Aggregations

AdapterView (android.widget.AdapterView)677 View (android.view.View)653 ListView (android.widget.ListView)412 TextView (android.widget.TextView)342 Intent (android.content.Intent)177 ImageView (android.widget.ImageView)174 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)142 ArrayAdapter (android.widget.ArrayAdapter)75 ArrayList (java.util.ArrayList)71 ViewGroup (android.view.ViewGroup)63 AbsListView (android.widget.AbsListView)59 GridView (android.widget.GridView)58 Bundle (android.os.Bundle)53 Spinner (android.widget.Spinner)50 LinearLayout (android.widget.LinearLayout)49 OnClickListener (android.view.View.OnClickListener)46 RecyclerView (android.support.v7.widget.RecyclerView)42 DialogInterface (android.content.DialogInterface)41 SuppressLint (android.annotation.SuppressLint)38 LayoutInflater (android.view.LayoutInflater)34