Search in sources :

Example 16 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project AdvancedMaterialDrawer by madcyph3r.

the class ThemeFragment method createAdapter.

private void createAdapter(RecyclerView recyclerView) {
    final List<ExampleData> content = new ArrayList<>();
    content.add(new ExampleData("Dark Theme", DarkThemeActivity.class));
    content.add(new ExampleData("Light Theme", LightThemeActivity.class));
    content.add(new ExampleData("My Theme", MyThemeActivity.class));
    content.add(new ExampleData("Unique Toolbar Color", UniqueToolbarColorActivity.class));
    content.add(new ExampleData("Actionbar Overlay", ActionBarOverlayActivity.class));
    content.add(new ExampleData("KitKat Translucent Statusbar", KitKatTranslucentStatusBarActivity.class));
    content.add(new ExampleData("Actionbar Own Font", ActionBarOwnFontActivity.class));
    content.add(new ExampleData("Own Drawer Width", OwnDrawerWidthActivity.class));
    content.add(new ExampleData("Only Icons Menu", OnlyIconsActivity.class));
    final ParallaxRecyclerAdapter<ExampleData> adapter = new ParallaxRecyclerAdapter<>(content);
    View header = getActivity().getLayoutInflater().inflate(R.layout.recycleview_header, recyclerView, false);
    ImageView headerImage = (ImageView) header.findViewById(R.id.imageViewHeader);
    headerImage.setImageResource(R.drawable.l_8);
    adapter.setParallaxHeader(header, recyclerView);
    adapter.setData(content);
    adapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() {

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
            ((ViewHolder) viewHolder).textView.setText(adapter.getData().get(i).getTitle());
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, final int i) {
            final ViewHolder holder = new ViewHolder(getActivity().getLayoutInflater().inflate(R.layout.recycleview_row, viewGroup, false));
            return holder;
        }

        @Override
        public int getItemCount() {
            return content.size();
        }
    });
    adapter.setOnParallaxScroll(new ParallaxRecyclerAdapter.OnParallaxScroll() {

        @Override
        public void onParallaxScroll(float percentage, float offset, View view) {
            ((MainActivity) getActivity()).setActionBarAlpha(percentage);
        }
    });
    adapter.setOnClickEvent(new ParallaxRecyclerAdapter.OnClickEvent() {

        @Override
        public void onClick(View view, int i) {
            if (i >= 0) {
                Intent intent = new Intent(getActivity(), adapter.getData().get(i).getClazz());
                startActivity(intent);
            }
        }
    });
    recyclerView.setAdapter(adapter);
}
Also used : ExampleData(de.madcyph3r.example.data.ExampleData) KitKatTranslucentStatusBarActivity(de.madcyph3r.example.example.theme.KitKatTranslucentStatusBarActivity) ArrayList(java.util.ArrayList) ActionBarOwnFontActivity(de.madcyph3r.example.example.theme.ActionBarOwnFontActivity) ParallaxRecyclerAdapter(com.poliveira.parallaxrecycleradapter.ParallaxRecyclerAdapter) DarkThemeActivity(de.madcyph3r.example.example.theme.DarkThemeActivity) ImageView(android.widget.ImageView) ActionBarOverlayActivity(de.madcyph3r.example.example.theme.ActionBarOverlayActivity) ViewGroup(android.view.ViewGroup) OwnDrawerWidthActivity(de.madcyph3r.example.example.theme.OwnDrawerWidthActivity) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) MyThemeActivity(de.madcyph3r.example.example.theme.MyThemeActivity) OnlyIconsActivity(de.madcyph3r.example.example.theme.OnlyIconsActivity) UniqueToolbarColorActivity(de.madcyph3r.example.example.theme.UniqueToolbarColorActivity) RecyclerView(android.support.v7.widget.RecyclerView) LightThemeActivity(de.madcyph3r.example.example.theme.LightThemeActivity)

Example 17 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project AdvancedMaterialDrawer by madcyph3r.

the class BackPatternFragment method createAdapter.

private void createAdapter(RecyclerView recyclerView) {
    final List<ExampleData> content = new ArrayList<>();
    content.add(new ExampleData("Custom Back Pattern", BackPatternCustomActivity.class));
    content.add(new ExampleData("Default Back Pattern", BackPatternDefaultActivity.class));
    content.add(new ExampleData("StartIndex Back Pattern", BackPatternStartIndexActivity.class));
    content.add(new ExampleData("Last Section Fragment Back Pattern", BackPatternLastSectionActivity.class));
    final ParallaxRecyclerAdapter<ExampleData> adapter = new ParallaxRecyclerAdapter<>(content);
    View header = getActivity().getLayoutInflater().inflate(R.layout.recycleview_header, recyclerView, false);
    ImageView headerImage = (ImageView) header.findViewById(R.id.imageViewHeader);
    headerImage.setImageResource(R.drawable.l_1);
    adapter.setParallaxHeader(header, recyclerView);
    adapter.setData(content);
    adapter.implementRecyclerAdapterMethods(new ParallaxRecyclerAdapter.RecyclerAdapterMethods() {

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
            ((ViewHolder) viewHolder).textView.setText(adapter.getData().get(i).getTitle());
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, final int i) {
            final ViewHolder holder = new ViewHolder(getActivity().getLayoutInflater().inflate(R.layout.recycleview_row, viewGroup, false));
            return holder;
        }

        @Override
        public int getItemCount() {
            return content.size();
        }
    });
    adapter.setOnParallaxScroll(new ParallaxRecyclerAdapter.OnParallaxScroll() {

        @Override
        public void onParallaxScroll(float percentage, float offset, View view) {
            ((MainActivity) getActivity()).setActionBarAlpha(percentage);
        }
    });
    adapter.setOnClickEvent(new ParallaxRecyclerAdapter.OnClickEvent() {

        @Override
        public void onClick(View view, int i) {
            if (i >= 0) {
                Intent intent = new Intent(getActivity(), adapter.getData().get(i).getClazz());
                startActivity(intent);
            }
        }
    });
    recyclerView.setAdapter(adapter);
}
Also used : ExampleData(de.madcyph3r.example.data.ExampleData) BackPatternLastSectionActivity(de.madcyph3r.example.example.backPattern.BackPatternLastSectionActivity) BackPatternCustomActivity(de.madcyph3r.example.example.backPattern.BackPatternCustomActivity) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) Intent(android.content.Intent) BackPatternDefaultActivity(de.madcyph3r.example.example.backPattern.BackPatternDefaultActivity) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) ParallaxRecyclerAdapter(com.poliveira.parallaxrecycleradapter.ParallaxRecyclerAdapter) RecyclerView(android.support.v7.widget.RecyclerView) ImageView(android.widget.ImageView) BackPatternStartIndexActivity(de.madcyph3r.example.example.backPattern.BackPatternStartIndexActivity)

Example 18 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project xabber-android by redsolution.

the class GroupedContactAdapter method getAccountView.

private View getAccountView(int position, View convertView, ViewGroup parent) {
    final View view;
    final ContactListAccountItemViewHolder viewHolder;
    if (convertView == null) {
        view = layoutInflater.inflate(R.layout.contact_list_account_group_item, parent, false);
        viewHolder = new ContactListAccountItemViewHolder(view);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            view.setElevation(accountElevation);
        }
        view.setTag(viewHolder);
    } else {
        view = convertView;
        viewHolder = (ContactListAccountItemViewHolder) view.getTag();
    }
    final AccountConfiguration configuration = (AccountConfiguration) getItem(position);
    final String account = configuration.getAccount();
    viewHolder.statusIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onClickListener.onAccountMenuClick(v, account);
        }
    });
    final int level = AccountManager.getInstance().getColorLevel(account);
    view.setBackgroundDrawable(new ColorDrawable(accountGroupColors[level]));
    viewHolder.name.setText(GroupManager.getInstance().getGroupName(account, configuration.getUser()));
    viewHolder.smallRightText.setText(configuration.getOnline() + "/" + configuration.getTotal());
    AccountItem accountItem = AccountManager.getInstance().getAccount(account);
    String statusText = accountItem.getStatusText().trim();
    if (statusText.isEmpty()) {
        statusText = activity.getString(accountItem.getDisplayStatusMode().getStringID());
    }
    viewHolder.secondLineMessage.setText(statusText);
    if (SettingsManager.contactsShowAvatars()) {
        viewHolder.avatar.setVisibility(View.VISIBLE);
        viewHolder.avatar.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
    } else {
        viewHolder.avatar.setVisibility(View.GONE);
    }
    viewHolder.avatar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            activity.startActivity(AccountViewer.createAccountInfoIntent(activity, account));
        }
    });
    viewHolder.statusIcon.setImageLevel(accountItem.getDisplayStatusMode().getStatusLevel());
    ShowOfflineMode showOfflineMode = configuration.getShowOfflineMode();
    if (showOfflineMode == ShowOfflineMode.normal) {
        if (SettingsManager.contactsShowOffline()) {
            showOfflineMode = ShowOfflineMode.always;
        } else {
            showOfflineMode = ShowOfflineMode.never;
        }
    }
    viewHolder.smallRightIcon.setImageLevel(showOfflineMode.ordinal());
    StatusMode statusMode = AccountManager.getInstance().getAccount(configuration.getAccount()).getDisplayStatusMode();
    if (statusMode == StatusMode.unavailable || statusMode == StatusMode.connection) {
        viewHolder.offlineShadow.setVisibility(View.VISIBLE);
    } else {
        viewHolder.offlineShadow.setVisibility(View.GONE);
    }
    return view;
}
Also used : StatusMode(com.xabber.android.data.account.StatusMode) ColorDrawable(android.graphics.drawable.ColorDrawable) AccountItem(com.xabber.android.data.account.AccountItem) ShowOfflineMode(com.xabber.android.data.roster.ShowOfflineMode) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 19 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project android-advancedrecyclerview by h6ah4i.

the class LauncherButtonsAdapter method onCreateViewHolder.

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view_item_launcher_button, parent, false);
    ViewHolder holder = new ViewHolder(v);
    holder.mButton.setOnClickListener(this);
    return holder;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 20 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project AwesomeRecyclerView by forceLain.

the class ArticleAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
    ArticleViewHolder articleViewHolder = (ArticleViewHolder) viewHolder;
    Article article = articles.get(position);
    articleViewHolder.textContent.setText(article.text);
    articleViewHolder.textTitle.setText(article.title);
    if (article.image.startsWith(SCHEME_ASSETS)) {
        String fileName = article.image.replace(SCHEME_ASSETS, "");
        AssetManager assetManager = viewHolder.itemView.getContext().getAssets();
        InputStream is = null;
        try {
            is = assetManager.open(fileName);
            Bitmap bitmap = BitmapFactory.decodeStream(is);
            articleViewHolder.imageView.setImageBitmap(bitmap);
        } catch (IOException e) {
            Log.e(TAG, Log.getStackTraceString(e));
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
    viewHolder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (itemClickListener != null) {
                itemClickListener.onItemClicked(position);
            }
        }
    });
}
Also used : Bitmap(android.graphics.Bitmap) AssetManager(android.content.res.AssetManager) InputStream(java.io.InputStream) Article(com.forcelain.android.awesomerecyclerview.model.Article) IOException(java.io.IOException) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)265 View (android.view.View)248 TextView (android.widget.TextView)129 ImageView (android.widget.ImageView)95 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)47 LayoutInflater (android.view.LayoutInflater)34 ViewGroup (android.view.ViewGroup)32 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)28 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)27 Intent (android.content.Intent)26 ArrayList (java.util.ArrayList)25 Context (android.content.Context)21 ViewPropertyAnimatorCompat (android.support.v4.view.ViewPropertyAnimatorCompat)17 BindView (butterknife.BindView)17 CardView (android.support.v7.widget.CardView)15 Paint (android.graphics.Paint)11 ParallaxRecyclerAdapter (com.poliveira.parallaxrecycleradapter.ParallaxRecyclerAdapter)8 ExampleData (de.madcyph3r.example.data.ExampleData)8 Drawable (android.graphics.drawable.Drawable)7 Test (org.junit.Test)7