Search in sources :

Example 16 with BaseAdapter

use of android.widget.BaseAdapter in project RichText by zzhoujay.

the class ListViewActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list);
    ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(new BaseAdapter() {

        @Override
        public int getCount() {
            return testString__.length + 1;
        }

        @Override
        public Object getItem(int position) {
            return testString[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            Holder holder;
            if (convertView == null) {
                convertView = LayoutInflater.from(ListViewActivity.this).inflate(R.layout.item_list, parent, false);
                holder = new Holder(convertView);
                convertView.setTag(holder);
            } else {
                holder = (Holder) convertView.getTag();
            }
            Log.i("RichText", "position:" + position + ",textView:" + System.identityHashCode(holder.text));
            String text;
            if (position == 0) {
                text = test;
            } else {
                text = testString__[position - 1];
            }
            RichText.from(text).autoFix(false).fix(new ImageFixCallback() {

                @Override
                public void onFix(ImageHolder holder, boolean imageReady) {
                    if (holder.getImageType() != ImageHolder.ImageType.GIF) {
                        holder.setAutoFix(true);
                    } else {
                        holder.setHeight(200 + position * 10);
                        holder.setWidth(200 + position * 10);
                    }
                    if (position == 0) {
                        holder.setAutoPlay(true);
                    } else {
                        holder.setAutoPlay(false);
                    }
                //                        holder.setAutoPlay(false);
                }
            }).into(holder.text);
            return convertView;
        }

        class Holder {

            public final TextView text;

            public Holder(View view) {
                text = (TextView) view.findViewById(R.id.text_item);
            }
        }
    });
}
Also used : ImageHolder(com.zzhoujay.richtext.ImageHolder) ViewGroup(android.view.ViewGroup) ImageHolder(com.zzhoujay.richtext.ImageHolder) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) ImageFixCallback(com.zzhoujay.richtext.callback.ImageFixCallback) ListView(android.widget.ListView) TextView(android.widget.TextView) BaseAdapter(android.widget.BaseAdapter)

Example 17 with BaseAdapter

use of android.widget.BaseAdapter in project MagicaSakura by Bilibili.

the class ThemeUtils method refreshView.

private static void refreshView(View view, ExtraRefreshable extraRefreshable) {
    if (view == null)
        return;
    view.destroyDrawingCache();
    if (view instanceof Tintable) {
        ((Tintable) view).tint();
        if (view instanceof ViewGroup) {
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                refreshView(((ViewGroup) view).getChildAt(i), extraRefreshable);
            }
        }
    } else {
        if (extraRefreshable != null) {
            extraRefreshable.refreshSpecificView(view);
        }
        if (view instanceof AbsListView) {
            try {
                if (sRecyclerBin == null) {
                    sRecyclerBin = AbsListView.class.getDeclaredField("mRecycler");
                    sRecyclerBin.setAccessible(true);
                }
                if (sListViewClearMethod == null) {
                    sListViewClearMethod = Class.forName("android.widget.AbsListView$RecycleBin").getDeclaredMethod("clear");
                    sListViewClearMethod.setAccessible(true);
                }
                sListViewClearMethod.invoke(sRecyclerBin.get(view));
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
            ListAdapter adapter = ((AbsListView) view).getAdapter();
            while (adapter instanceof WrapperListAdapter) {
                adapter = ((WrapperListAdapter) adapter).getWrappedAdapter();
            }
            if (adapter instanceof BaseAdapter) {
                ((BaseAdapter) adapter).notifyDataSetChanged();
            }
        }
        if (view instanceof RecyclerView) {
            try {
                if (sRecycler == null) {
                    sRecycler = RecyclerView.class.getDeclaredField("mRecycler");
                    sRecycler.setAccessible(true);
                }
                if (sRecycleViewClearMethod == null) {
                    sRecycleViewClearMethod = Class.forName("android.support.v7.widget.RecyclerView$Recycler").getDeclaredMethod("clear");
                    sRecycleViewClearMethod.setAccessible(true);
                }
                sRecycleViewClearMethod.invoke(sRecycler.get(view));
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
            ((RecyclerView) view).getRecycledViewPool().clear();
            ((RecyclerView) view).invalidateItemDecorations();
        }
        if (view instanceof ViewGroup) {
            for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
                refreshView(((ViewGroup) view).getChildAt(i), extraRefreshable);
            }
        }
    }
}
Also used : Tintable(com.bilibili.magicasakura.widgets.Tintable) ViewGroup(android.view.ViewGroup) AbsListView(android.widget.AbsListView) InvocationTargetException(java.lang.reflect.InvocationTargetException) RecyclerView(android.support.v7.widget.RecyclerView) BaseAdapter(android.widget.BaseAdapter) ListAdapter(android.widget.ListAdapter) WrapperListAdapter(android.widget.WrapperListAdapter) WrapperListAdapter(android.widget.WrapperListAdapter)

Example 18 with BaseAdapter

use of android.widget.BaseAdapter in project BottomSheet by soarcn.

the class BottomSheet method init.

private void init(final Context context) {
    setCanceledOnTouchOutside(cancelOnTouchOutside);
    final ClosableSlidingLayout mDialogView = (ClosableSlidingLayout) View.inflate(context, R.layout.bottom_sheet_dialog, null);
    LinearLayout mainLayout = (LinearLayout) mDialogView.findViewById(R.id.bs_main);
    mainLayout.addView(View.inflate(context, mHeaderLayoutId, null), 0);
    setContentView(mDialogView);
    if (!cancelOnSwipeDown)
        mDialogView.swipeable = cancelOnSwipeDown;
    mDialogView.setSlideListener(new ClosableSlidingLayout.SlideListener() {

        @Override
        public void onClosed() {
            BottomSheet.this.dismiss();
        }

        @Override
        public void onOpened() {
            showFullItems();
        }
    });
    super.setOnShowListener(new OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {
            if (showListener != null)
                showListener.onShow(dialogInterface);
            list.setAdapter(adapter);
            list.startLayoutAnimation();
            if (builder.icon == null)
                icon.setVisibility(View.GONE);
            else {
                icon.setVisibility(View.VISIBLE);
                icon.setImageDrawable(builder.icon);
            }
        }
    });
    int[] location = new int[2];
    mDialogView.getLocationOnScreen(location);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        mDialogView.setPadding(0, location[0] == 0 ? helper.mStatusBarHeight : 0, 0, 0);
        mDialogView.getChildAt(0).setPadding(0, 0, 0, helper.mNavBarAvailable ? helper.getNavigationBarHeight(getContext()) + mDialogView.getPaddingBottom() : 0);
    }
    final TextView title = (TextView) mDialogView.findViewById(R.id.bottom_sheet_title);
    if (builder.title != null) {
        title.setVisibility(View.VISIBLE);
        title.setText(builder.title);
    }
    icon = (ImageView) mDialogView.findViewById(R.id.bottom_sheet_title_image);
    list = (GridView) mDialogView.findViewById(R.id.bottom_sheet_gridview);
    mDialogView.mTarget = list;
    if (!builder.grid) {
        list.setNumColumns(1);
    }
    if (builder.grid) {
        for (int i = 0; i < getMenu().size(); i++) {
            if (getMenu().getItem(i).getIcon() == null)
                throw new IllegalArgumentException("You must set icon for each items in grid style");
        }
    }
    if (builder.limit > 0)
        limit = builder.limit * getNumColumns();
    else
        limit = Integer.MAX_VALUE;
    mDialogView.setCollapsible(false);
    actions = builder.menu;
    menuItem = actions;
    // over the initial numbers
    if (getMenu().size() > limit) {
        fullMenuItem = builder.menu;
        menuItem = builder.menu.clone(limit - 1);
        ActionMenuItem item = new ActionMenuItem(context, 0, R.id.bs_more, 0, limit - 1, moreText);
        item.setIcon(more);
        menuItem.add(item);
        actions = menuItem;
        mDialogView.setCollapsible(true);
    }
    BaseAdapter baseAdapter = new BaseAdapter() {

        @Override
        public int getCount() {
            return actions.size() - hidden.size();
        }

        @Override
        public MenuItem getItem(int position) {
            return actions.getItem(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public int getViewTypeCount() {
            return 1;
        }

        @Override
        public boolean isEnabled(int position) {
            return getItem(position).isEnabled();
        }

        @Override
        public boolean areAllItemsEnabled() {
            return false;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                if (builder.grid)
                    convertView = inflater.inflate(mGridItemLayoutId, parent, false);
                else
                    convertView = inflater.inflate(mListItemLayoutId, parent, false);
                holder = new ViewHolder();
                holder.title = (TextView) convertView.findViewById(R.id.bs_list_title);
                holder.image = (ImageView) convertView.findViewById(R.id.bs_list_image);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            for (int i = 0; i < hidden.size(); i++) {
                if (hidden.valueAt(i) <= position)
                    position++;
            }
            MenuItem item = getItem(position);
            holder.title.setText(item.getTitle());
            if (item.getIcon() == null)
                holder.image.setVisibility(collapseListIcons ? View.GONE : View.INVISIBLE);
            else {
                holder.image.setVisibility(View.VISIBLE);
                holder.image.setImageDrawable(item.getIcon());
            }
            holder.image.setEnabled(item.isEnabled());
            holder.title.setEnabled(item.isEnabled());
            return convertView;
        }

        class ViewHolder {

            private TextView title;

            private ImageView image;
        }
    };
    adapter = new SimpleSectionedGridAdapter(context, baseAdapter, R.layout.bs_list_divider, R.id.headerlayout, R.id.header);
    list.setAdapter(adapter);
    adapter.setGridView(list);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (((MenuItem) adapter.getItem(position)).getItemId() == R.id.bs_more) {
                showFullItems();
                mDialogView.setCollapsible(false);
                return;
            }
            if (!((ActionMenuItem) adapter.getItem(position)).invoke()) {
                if (builder.menulistener != null)
                    builder.menulistener.onMenuItemClick((MenuItem) adapter.getItem(position));
                else if (builder.listener != null)
                    builder.listener.onClick(BottomSheet.this, ((MenuItem) adapter.getItem(position)).getItemId());
            }
            dismiss();
        }
    });
    if (builder.dismissListener != null) {
        setOnDismissListener(builder.dismissListener);
    }
    setListLayout();
}
Also used : DialogInterface(android.content.DialogInterface) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) GridView(android.widget.GridView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) ImageView(android.widget.ImageView) BaseAdapter(android.widget.BaseAdapter) LinearLayout(android.widget.LinearLayout)

Example 19 with BaseAdapter

use of android.widget.BaseAdapter in project chefly_android by chef-ly.

the class ShoppingListActivity method onListItemClick.

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    TextView name = (TextView) v.findViewById(R.id.name);
    ShoppingListItem item = shoppingList.get(position);
    if (item.isPurchased()) {
        item.setPurchased(false);
        name.setPaintFlags(name.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
    } else {
        item.setPurchased(true);
        name.setPaintFlags(name.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
    }
    ((BaseAdapter) getListAdapter()).notifyDataSetChanged();
}
Also used : TextView(android.widget.TextView) ShoppingListItem(com.se491.chef_ly.model.ShoppingListItem) BaseAdapter(android.widget.BaseAdapter)

Example 20 with BaseAdapter

use of android.widget.BaseAdapter in project chefly_android by chef-ly.

the class ListViewFragment method updateListAdapter.

public void updateListAdapter(RecipeList newList) {
    if (list == null) {
        list = new RecipeList();
    }
    for (RecipeInformation r : newList) {
        list.add(r);
    }
    if (listView != null) {
        ((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
        Log.d(TAG + "/" + title, "ListView updated " + title + " " + listView.getAdapter().getCount() + " list " + list.size());
    //listView.setVisibility(View.VISIBLE);
    }
}
Also used : RecipeList(com.se491.chef_ly.model.RecipeList) BaseAdapter(android.widget.BaseAdapter) RecipeInformation(com.se491.chef_ly.model.RecipeInformation)

Aggregations

BaseAdapter (android.widget.BaseAdapter)43 View (android.view.View)22 AdapterView (android.widget.AdapterView)21 ViewGroup (android.view.ViewGroup)16 Adapter (android.widget.Adapter)15 TextView (android.widget.TextView)15 ListAdapter (android.widget.ListAdapter)8 ListView (android.widget.ListView)7 RemoteAdapterConnectionCallback (android.widget.RemoteViewsAdapter.RemoteAdapterConnectionCallback)7 LayoutInflater (android.view.LayoutInflater)5 Context (android.content.Context)4 AbsListView (android.widget.AbsListView)4 RecipeInformation (com.se491.chef_ly.model.RecipeInformation)4 SuppressLint (android.annotation.SuppressLint)3 Intent (android.content.Intent)3 GridView (android.widget.GridView)3 HeaderViewListAdapter (android.widget.HeaderViewListAdapter)3 ImageView (android.widget.ImageView)3 FlipViewController (com.aphidmobile.flip.FlipViewController)3 NumberTextView (com.aphidmobile.flip.demo.views.NumberTextView)3