Search in sources :

Example 6 with CardView

use of android.support.v7.widget.CardView in project ViewPagerCards by rubensousa.

the class ShadowTransformer method onPageScrolled.

@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
    int realCurrentPosition;
    int nextPosition;
    float baseElevation = mAdapter.getBaseElevation();
    float realOffset;
    boolean goingLeft = mLastOffset > positionOffset;
    // instead of the current one
    if (goingLeft) {
        realCurrentPosition = position + 1;
        nextPosition = position;
        realOffset = 1 - positionOffset;
    } else {
        nextPosition = position + 1;
        realCurrentPosition = position;
        realOffset = positionOffset;
    }
    // Avoid crash on overscroll
    if (nextPosition > mAdapter.getCount() - 1 || realCurrentPosition > mAdapter.getCount() - 1) {
        return;
    }
    CardView currentCard = mAdapter.getCardViewAt(realCurrentPosition);
    // and the views weren't created yet
    if (currentCard != null) {
        if (mScalingEnabled) {
            currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
            currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
        }
        currentCard.setCardElevation((baseElevation + baseElevation * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
    }
    CardView nextCard = mAdapter.getCardViewAt(nextPosition);
    // was already destroyed or a fragment might not have been created yet
    if (nextCard != null) {
        if (mScalingEnabled) {
            nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
            nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
        }
        nextCard.setCardElevation((baseElevation + baseElevation * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
    }
    mLastOffset = positionOffset;
}
Also used : CardView(android.support.v7.widget.CardView)

Example 7 with CardView

use of android.support.v7.widget.CardView in project platform_frameworks_base by android.

the class RecentsTvView method launchTaskFomRecents.

/**
     * Launch the given task from recents with animation. If the task is not focused, this will
     * attempt to scroll to focus the task before launching.
     * @param task
     */
private void launchTaskFomRecents(final Task task, boolean animate) {
    if (!animate) {
        SystemServicesProxy ssp = Recents.getSystemServices();
        ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
        return;
    }
    mTaskStackHorizontalView.requestFocus();
    Task focusedTask = mTaskStackHorizontalView.getFocusedTask();
    if (focusedTask != null && task != focusedTask) {
        if (mScrollListener != null) {
            mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
        }
        mScrollListener = new OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    TaskCardView cardView = mTaskStackHorizontalView.getChildViewForTask(task);
                    if (cardView != null) {
                        mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, cardView, null, INVALID_STACK_ID);
                    } else {
                        // This should not happen normally. If this happens then the data in
                        // the grid view was altered during the scroll. Log error and launch
                        // task with no animation.
                        Log.e(TAG, "Card view for task : " + task + ", returned null.");
                        SystemServicesProxy ssp = Recents.getSystemServices();
                        ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
                    }
                    mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
                }
            }
        };
        mTaskStackHorizontalView.addOnScrollListener(mScrollListener);
        mTaskStackHorizontalView.setSelectedPositionSmooth(((TaskStackHorizontalViewAdapter) mTaskStackHorizontalView.getAdapter()).getPositionOfTask(task));
    } else {
        mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, mTaskStackHorizontalView.getChildViewForTask(task), null, INVALID_STACK_ID);
    }
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) Task(com.android.systemui.recents.model.Task) OnScrollListener(android.support.v7.widget.RecyclerView.OnScrollListener) RecyclerView(android.support.v7.widget.RecyclerView)

Example 8 with CardView

use of android.support.v7.widget.CardView in project Hummingbird-for-Android by xiprox.

the class FeedTimelineAdapter method getInfiniteScrollListView.

@Override
public View getInfiniteScrollListView(final int position, View convertView, ViewGroup parent) {
    if (getCount() != 0) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rootView = new View(context);
        final Story item = mItems.get(position);
        storyType = item.getStoryType();
        if (storyType.equals(Story.STORY_TYPE_COMMENT))
            rootView = inflater.inflate(R.layout.item_story_comment, null);
        else if (storyType.equals(Story.STORY_TYPE_MEDIA))
            rootView = inflater.inflate(R.layout.item_story_media, null);
        if (storyType.equals(Story.STORY_TYPE_COMMENT)) {
            FrameLayout mAvatarHolder = (FrameLayout) rootView.findViewById(R.id.item_story_comment_avatar_holder);
            ImageView mAvatar = (ImageView) rootView.findViewById(R.id.item_story_comment_avatar);
            TextView mUsername = (TextView) rootView.findViewById(R.id.item_story_comment_username);
            RelativeTimeTextView mTime = (RelativeTimeTextView) rootView.findViewById(R.id.item_story_comment_time);
            TextView mText = (TextView) rootView.findViewById(R.id.item_story_comment_text);
            mAvatarHolder.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, ProfileActivity.class);
                    intent.putExtra(ProfileActivity.ARG_USERNAME, item.getPoster().getName());
                    context.startActivity(intent);
                }
            });
            /* The following 2 won't be used until we find out how to obtain the necessary data */
            View mDivider = rootView.findViewById(R.id.item_story_comment_divider);
            LinearLayout mComments = (LinearLayout) rootView.findViewById(R.id.item_story_comment_comments);
            Picasso.with(context).load(item.getPoster().getAvatar()).transform(new CircleTransformation()).into(mAvatar);
            mUsername.setText(item.getPoster().getName());
            for (Substory substory : item.getSubstories()) {
                if (substory.getSubstoryType().equals(Substory.SUBSTORY_TYPE_COMMENT)) {
                    mTime.setReferenceTime(substory.getCreatedAt());
                    mText.setText(substory.getComment());
                }
            }
        }
        if (storyType.equals(Story.STORY_TYPE_MEDIA)) {
            final CardView mCard = (CardView) rootView.findViewById(R.id.item_story_media_card);
            FrameLayout mCoverHolder = (FrameLayout) rootView.findViewById(R.id.item_story_media_cover_holder);
            final ImageView mCover = (ImageView) rootView.findViewById(R.id.item_story_media_cover);
            final TextView mTitle = (TextView) rootView.findViewById(R.id.item_story_media_title);
            final LinearLayout mSubstories = (LinearLayout) rootView.findViewById(R.id.item_story_media_substories);
            final TextView mMoreIndicator = (TextView) rootView.findViewById(R.id.item_story_media_more);
            AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, Utils.dpToPx(context, 160));
            rootView.setLayoutParams(params);
            expanded[position] = false;
            mCoverHolder.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    Intent intent = new Intent(context, AnimeDetailsActivity.class);
                    intent.putExtra(AnimeDetailsActivity.ARG_ID, item.getMedia().getId());
                    intent.putExtra(AnimeDetailsActivity.ARG_ANIME_OBJ, item.getMedia());
                    ActivityOptionsCompat transition = ActivityOptionsCompat.makeSceneTransitionAnimation((Activity) context, Pair.create((View) mCover, "anime_cover"));
                    Utils.startActivityWithTransition(context, intent, transition);
                }
            });
            /* Hide the VIEW MORE button if there are no more than a single substory */
            if (item.getSubstoriesCount() == 1)
                mMoreIndicator.setVisibility(View.GONE);
            if (item.getSubstoriesCount() > 1) {
                rootView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        if (!expanded[position]) {
                            for (int i = 0; i < mSubstories.getChildCount(); i++) {
                                View v = mSubstories.getChildAt(i);
                                v.setVisibility(View.VISIBLE);
                            }
                            AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT);
                            mCard.setLayoutParams(params);
                            expanded[position] = true;
                        } else {
                            for (int i = 0; i < mSubstories.getChildCount(); i++) {
                                if (i > 0) {
                                    View v = mSubstories.getChildAt(i);
                                    v.setVisibility(View.GONE);
                                }
                            }
                            AbsListView.LayoutParams params = new AbsListView.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, Utils.dpToPx(context, 160));
                            mCard.setLayoutParams(params);
                            expanded[position] = false;
                            notifyDataSetChanged();
                        }
                    }
                });
            }
            Picasso.with(context).load(item.getMedia().getCoverImage()).into(mCover);
            mTitle.setText(item.getMedia().getTitle());
            List<Substory> sortedSubstories = Utils.sortSubstoriesByDate(item.getSubstories());
            mSubstories.removeAllViews();
            for (Substory substory : sortedSubstories) {
                View view = inflater.inflate(R.layout.item_substory, null);
                FrameLayout avatarHolder = (FrameLayout) view.findViewById(R.id.item_substory_avatar_holder);
                ImageView avatar = (ImageView) view.findViewById(R.id.item_substory_avatar);
                TextView username = (TextView) view.findViewById(R.id.item_substory_username);
                RelativeTimeTextView time = (RelativeTimeTextView) view.findViewById(R.id.item_substory_time);
                Picasso.with(context).load(item.getUser().getAvatar()).transform(new CircleTransformation()).into(avatar);
                avatarHolder.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(context, ProfileActivity.class);
                        intent.putExtra(ProfileActivity.ARG_USERNAME, item.getUser().getName());
                        context.startActivity(intent);
                    }
                });
                username.setText(item.getUser().getName());
                time.setReferenceTime(substory.getCreatedAt());
                if (substory.getSubstoryType().equals(Substory.SUBSTORY_TYPE_WATCHED_EPISODE)) {
                    String textToSet = getString(R.string.content_watched_episode) + " " + substory.getEpisodeNumber();
                    ((TextView) view.findViewById(R.id.item_substory_text)).setText(textToSet);
                }
                if (substory.getSubstoryType().equals(Substory.SUBSTORY_TYPE_WATCHLIST_STATUS_UPDATE)) {
                    String textToSet = "";
                    String watchlistStatusUpdate = substory.getNewStatus();
                    if (watchlistStatusUpdate.equals(Substory.WATCHLIST_STATUS_CURRENTLY_WATCHING))
                        textToSet = getString(R.string.content_is_currently_watching);
                    if (watchlistStatusUpdate.equals(Substory.WATCHLIST_STATUS_COMPLETED))
                        textToSet = getString(R.string.content_has_completed);
                    if (watchlistStatusUpdate.equals(Substory.WATCHLIST_STATUS_DROPPED))
                        textToSet = getString(R.string.content_has_dropped);
                    if (watchlistStatusUpdate.equals(Substory.WATCHLIST_STATUS_ON_HOLD))
                        textToSet = getString(R.string.content_has_placed_on_hold);
                    if (watchlistStatusUpdate.equals(Substory.WATCHLIST_STATUS_PLAN_TO_WATCH))
                        textToSet = getString(R.string.content_is_planning_to_watch);
                    ((TextView) view.findViewById(R.id.item_substory_text)).setText(textToSet);
                }
                if (mSubstories.getChildCount() >= 1)
                    view.setVisibility(View.GONE);
                mSubstories.addView(view);
            }
        }
        return rootView;
    } else
        return getInfiniteScrollListView(position, convertView, parent);
}
Also used : ProfileActivity(tr.bcxip.hummingbird.ProfileActivity) CardView(android.support.v7.widget.CardView) AbsListView(android.widget.AbsListView) AnimeDetailsActivity(tr.bcxip.hummingbird.AnimeDetailsActivity) ProfileActivity(tr.bcxip.hummingbird.ProfileActivity) Activity(android.app.Activity) Intent(android.content.Intent) RelativeTimeTextView(tr.bcxip.hummingbird.widget.RelativeTimeTextView) ImageView(android.widget.ImageView) RelativeTimeTextView(tr.bcxip.hummingbird.widget.RelativeTimeTextView) View(android.view.View) CardView(android.support.v7.widget.CardView) AbsListView(android.widget.AbsListView) TextView(android.widget.TextView) ActivityOptionsCompat(android.support.v4.app.ActivityOptionsCompat) CircleTransformation(tr.bcxip.hummingbird.utils.CircleTransformation) Substory(tr.bcxip.hummingbird.api.objects.Substory) LayoutInflater(android.view.LayoutInflater) FrameLayout(android.widget.FrameLayout) RelativeTimeTextView(tr.bcxip.hummingbird.widget.RelativeTimeTextView) TextView(android.widget.TextView) AnimeDetailsActivity(tr.bcxip.hummingbird.AnimeDetailsActivity) ImageView(android.widget.ImageView) Story(tr.bcxip.hummingbird.api.objects.Story) LinearLayout(android.widget.LinearLayout)

Example 9 with CardView

use of android.support.v7.widget.CardView in project LeMondeRssReader by MBach.

the class ArticleAdapter method onCreateViewHolder.

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    switch(viewType) {
        default:
        case Model.TEXT_TYPE:
            return new ViewHolderText(new TextView(parent.getContext()));
        case Model.IMAGE_TYPE:
            ImageView imageView = new ImageView(parent.getContext());
            imageView.setImageResource(R.drawable.avatar);
            return new ViewHolderImage(imageView);
        case Model.TWEET_TYPE:
            return new ViewHolderCardView(new CardView(parent.getContext()));
        case Model.GRAPH_TYPE:
            BarChart barChart = new BarChart(parent.getContext());
            return new ViewHolderBarChart(barChart);
        case Model.COMMENT_TYPE:
            return new ViewHolderText(new TextView(parent.getContext()));
    }
}
Also used : CardView(android.support.v7.widget.CardView) BarChart(com.github.mikephil.charting.charts.BarChart) TextView(android.widget.TextView) ImageView(android.widget.ImageView) NonNull(android.support.annotation.NonNull)

Example 10 with CardView

use of android.support.v7.widget.CardView in project android_frameworks_base by ResurrectionRemix.

the class RecentsTvView method launchTaskFomRecents.

/**
     * Launch the given task from recents with animation. If the task is not focused, this will
     * attempt to scroll to focus the task before launching.
     * @param task
     */
private void launchTaskFomRecents(final Task task, boolean animate) {
    if (!animate) {
        SystemServicesProxy ssp = Recents.getSystemServices();
        ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
        return;
    }
    mTaskStackHorizontalView.requestFocus();
    Task focusedTask = mTaskStackHorizontalView.getFocusedTask();
    if (focusedTask != null && task != focusedTask) {
        if (mScrollListener != null) {
            mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
        }
        mScrollListener = new OnScrollListener() {

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    TaskCardView cardView = mTaskStackHorizontalView.getChildViewForTask(task);
                    if (cardView != null) {
                        mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, cardView, null, INVALID_STACK_ID);
                    } else {
                        // This should not happen normally. If this happens then the data in
                        // the grid view was altered during the scroll. Log error and launch
                        // task with no animation.
                        Log.e(TAG, "Card view for task : " + task + ", returned null.");
                        SystemServicesProxy ssp = Recents.getSystemServices();
                        ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
                    }
                    mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
                }
            }
        };
        mTaskStackHorizontalView.addOnScrollListener(mScrollListener);
        mTaskStackHorizontalView.setSelectedPositionSmooth(((TaskStackHorizontalViewAdapter) mTaskStackHorizontalView.getAdapter()).getPositionOfTask(task));
    } else {
        mTransitionHelper.launchTaskFromRecents(mStack, task, mTaskStackHorizontalView, mTaskStackHorizontalView.getChildViewForTask(task), null, INVALID_STACK_ID);
    }
}
Also used : SystemServicesProxy(com.android.systemui.recents.misc.SystemServicesProxy) Task(com.android.systemui.recents.model.Task) OnScrollListener(android.support.v7.widget.RecyclerView.OnScrollListener) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

CardView (android.support.v7.widget.CardView)30 View (android.view.View)26 TextView (android.widget.TextView)24 ImageView (android.widget.ImageView)10 IconicsImageView (com.mikepenz.iconics.view.IconicsImageView)10 DialogInterface (android.content.DialogInterface)9 AlertDialog (android.support.v7.app.AlertDialog)9 RecyclerView (android.support.v7.widget.RecyclerView)9 ScrollView (android.widget.ScrollView)8 OnScrollListener (android.support.v7.widget.RecyclerView.OnScrollListener)5 SystemServicesProxy (com.android.systemui.recents.misc.SystemServicesProxy)5 Task (com.android.systemui.recents.model.Task)5 Intent (android.content.Intent)3 Nullable (android.support.annotation.Nullable)3 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 EditText (android.widget.EditText)3 SeekBar (android.widget.SeekBar)3 NonNull (android.support.annotation.NonNull)2 SwitchCompat (android.support.v7.widget.SwitchCompat)2 CompoundButton (android.widget.CompoundButton)2