Search in sources :

Example 81 with ViewHolder

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

the class RecentPanelView method setupItemTouchHelper.

private void setupItemTouchHelper() {
    ItemTouchHelper touchHelper = new ItemTouchHelper(new ItemTouchHelper.Callback() {

        RecentCard card;

        int taskid;

        int initPos;

        int finalPos;

        boolean isSwipe;

        boolean unwantedDrag = true;

        @Override
        public boolean onMove(RecyclerView recyclerView, ViewHolder viewHolder, ViewHolder target) {
            /* We'll start multiwindow action in the clearView void, when the drag action
                and all animations are completed. Otherwise we'd do a loop action
                till the drag is completed for each onMove (wasting resources and making
                the drag not smooth).*/
            ExpandableCardAdapter.ViewHolder vh = (ExpandableCardAdapter.ViewHolder) viewHolder;
            vh.hideOptions(-1, -1);
            initPos = viewHolder.getAdapterPosition();
            card = (RecentCard) mCardAdapter.getCard(initPos);
            taskid = card.task.persistentTaskId;
            unwantedDrag = false;
            return true;
        }

        @Override
        public void onMoved(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, int fromPos, RecyclerView.ViewHolder target, int toPos, int x, int y) {
            finalPos = toPos;
            isSwipe = false;
        }

        @Override
        public float getMoveThreshold(RecyclerView.ViewHolder viewHolder) {
            // if less then this we consider it as unwanted drag
            return 0.2f;
        }

        @Override
        public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            super.clearView(recyclerView, viewHolder);
            if (isSwipe) {
                //don't start multiwindow on swipe
                return;
            }
            if (unwantedDrag) {
                /*this means MoveThreshold is less than needed, so onMove
                    has not been considered, so we don't consider the action as wanted drag*/
                return;
            }
            //restore the drag check
            unwantedDrag = true;
            boolean wasDocked = false;
            int dockSide = WindowManagerProxy.getInstance().getDockSide();
            if (dockSide != WindowManager.DOCKED_INVALID) {
                try {
                    //resize the docked stack to fullscreen to disable current multiwindow mode
                    ActivityManagerNative.getDefault().resizeStack(ActivityManager.StackId.DOCKED_STACK_ID, null, true, true, false, -1);
                } catch (RemoteException e) {
                }
                wasDocked = true;
            }
            ActivityOptions options = ActivityOptions.makeBasic();
            //0 means dock app to top, 1 to bottom
            options.setDockCreateMode(0);
            options.setLaunchStackId(ActivityManager.StackId.DOCKED_STACK_ID);
            Handler mHandler = new Handler();
            mHandler.postDelayed(new Runnable() {

                public void run() {
                    try {
                        card = (RecentCard) mCardAdapter.getCard(finalPos);
                        int newTaskid = card.task.persistentTaskId;
                        ActivityManagerNative.getDefault().startActivityFromRecents((finalPos > initPos) ? taskid : newTaskid, options.toBundle());
                        /*after we docked our main app, on the other side of the screen we
                            open the app we dragged the main app over*/
                        mController.openOnDraggedApptoOtherSide((finalPos > initPos) ? newTaskid : taskid);
                    } catch (RemoteException e) {
                    }
                }
            }, wasDocked ? 100 : 0);
        }

        @Override
        public boolean isLongPressDragEnabled() {
            return true;
        }

        @Override
        public void onSwiped(ViewHolder viewHolder, int direction) {
            int pos = viewHolder.getAdapterPosition();
            RecentCard card = (RecentCard) mCardAdapter.getCard(pos);
            mCardAdapter.removeCard(pos);
            removeApplication(card.task);
            isSwipe = true;
        }

        @Override
        public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            // Set movement flags based on the layout manager
            final int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
            final int swipeFlags = ItemTouchHelper.START | ItemTouchHelper.END;
            return makeMovementFlags(dragFlags, swipeFlags);
        }
    });
    touchHelper.attachToRecyclerView(mCardRecyclerView);
}
Also used : Handler(android.os.Handler) Paint(android.graphics.Paint) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) RecyclerView(android.support.v7.widget.RecyclerView) RemoteException(android.os.RemoteException) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) ActivityOptions(android.app.ActivityOptions)

Example 82 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ConditionAdapterUtils method addDismiss.

public static void addDismiss(final RecyclerView recyclerView) {
    ItemTouchHelper.SimpleCallback callback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.START | ItemTouchHelper.END) {

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            return true;
        }

        @Override
        public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            return viewHolder.getItemViewType() == R.layout.condition_card ? super.getSwipeDirs(recyclerView, viewHolder) : 0;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            DashboardAdapter adapter = (DashboardAdapter) recyclerView.getAdapter();
            Object item = adapter.getItem(viewHolder.getItemId());
            if (item instanceof Condition) {
                ((Condition) item).silence();
            }
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
}
Also used : ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) RecyclerView(android.support.v7.widget.RecyclerView) DashboardAdapter(com.android.settings.dashboard.DashboardAdapter)

Example 83 with ViewHolder

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

the class RvBoxAdapter method onCreateViewHolder.

@Override
public RvBoxAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final ViewHolder h = new ViewHolder(new TextView(parent.getContext()));
    h.mTextView.setMinimumHeight(128);
    h.mTextView.setPadding(20, 0, 20, 0);
    h.mTextView.setFocusable(true);
    h.mTextView.setBackgroundResource(mBackground);
    RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lp.leftMargin = 10;
    lp.rightMargin = 5;
    lp.topMargin = 20;
    lp.bottomMargin = 15;
    h.mTextView.setLayoutParams(lp);
    return h;
}
Also used : TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView)

Example 84 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project LshUtils by SenhLinsh.

the class LshSimplifiedRcvAdapter method onCreateViewHolder.

@Override
public LshSimplifiedViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
    LshSimplifiedViewHolder viewHolder = new LshSimplifiedViewHolder(itemView);
    if (mOnItemClickListener != null) {
        viewHolder.setOnItemClickListener(new OnItemClickListener<Void>() {

            @Override
            public void onItemClick(LshSimplifiedViewHolder viewHolder, Void data, int position) {
                mOnItemClickListener.onItemClick(viewHolder, list.get(position), position);
            }
        });
    }
    return viewHolder;
}
Also used : ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) Paint(android.graphics.Paint)

Example 85 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project RSAndroidApp by RailwayStations.

the class AuthActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_auth);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    subscribtionStatus();
    mUsername = ANONYMOUS;
    // Initialize Firebase Auth
    mFirebaseAuth = FirebaseAuth.getInstance();
    mFirebaseUser = mFirebaseAuth.getCurrentUser();
    ChatMessage friendly_chat = new ChatMessage();
    mTimeStamp = friendly_chat.setChatTimeStamp();
    if (mFirebaseUser == null) {
        // Not signed in, launch the Sign In activity
        startActivity(new Intent(this, SignInActivity.class));
        finish();
        return;
    } else {
        mUsername = mFirebaseUser.getDisplayName();
        mPhotoUrl = mFirebaseUser.getPhotoUrl().toString();
    }
    mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, /* FragmentActivity */
    this).addApi(Auth.GOOGLE_SIGN_IN_API).build();
    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mMessageRecyclerView = (RecyclerView) findViewById(R.id.messageRecyclerView);
    mLinearLayoutManager = new LinearLayoutManager(this);
    mLinearLayoutManager.setStackFromEnd(true);
    mFirebaseDatabaseReference = FirebaseDatabase.getInstance().getReference();
    mFirebaseAdapter = new FirebaseRecyclerAdapter<ChatMessage, MessageViewHolder>(ChatMessage.class, R.layout.item_message, MessageViewHolder.class, mFirebaseDatabaseReference.child(MESSAGES_CHILD)) {

        @Override
        protected void populateViewHolder(MessageViewHolder viewHolder, ChatMessage friendlyMessage, int position) {
            mProgressBar.setVisibility(ProgressBar.INVISIBLE);
            viewHolder.messageTextView.setText(friendlyMessage.getText());
            viewHolder.messengerTextView.setText(friendlyMessage.getName());
            viewHolder.messengerTimeStamp.setText(friendlyMessage.getChatTimeStamp());
            if (friendlyMessage.getPhotoUrl() == null) {
                viewHolder.messengerImageView.setImageDrawable(ContextCompat.getDrawable(AuthActivity.this, R.drawable.ic_account_circle_black_36dp));
            } else {
                Glide.with(AuthActivity.this).load(friendlyMessage.getPhotoUrl()).into(viewHolder.messengerImageView);
            }
        }
    };
    mFirebaseAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {

        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            super.onItemRangeInserted(positionStart, itemCount);
            int friendlyMessageCount = mFirebaseAdapter.getItemCount();
            int lastVisiblePosition = mLinearLayoutManager.findLastCompletelyVisibleItemPosition();
            // to the bottom of the list to show the newly added message.
            if (lastVisiblePosition == -1 || (positionStart >= (friendlyMessageCount - 1) && lastVisiblePosition == (positionStart - 1))) {
                mMessageRecyclerView.scrollToPosition(positionStart);
            }
        }
    });
    mMessageRecyclerView.setLayoutManager(mLinearLayoutManager);
    mMessageRecyclerView.setAdapter(mFirebaseAdapter);
    // Initialize Firebase Remote Config.
    mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
    // Define Firebase Remote Config Settings.
    FirebaseRemoteConfigSettings firebaseRemoteConfigSettings = new FirebaseRemoteConfigSettings.Builder().setDeveloperModeEnabled(true).build();
    // Define default config values. Defaults are used when fetched config values are not
    // available. Eg: if an error occurred fetching values from the server.
    Map<String, Object> defaultConfigMap = new HashMap<>();
    defaultConfigMap.put("friendly_msg_length", 10L);
    // Apply config settings and default values.
    mFirebaseRemoteConfig.setConfigSettings(firebaseRemoteConfigSettings);
    mFirebaseRemoteConfig.setDefaults(defaultConfigMap);
    // Fetch remote config.
    fetchConfig();
    mMessageEditText = (EditText) findViewById(R.id.messageEditText);
    mMessageEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mSharedPreferences.getInt(FRIENDLY_MSG_LENGTH, DEFAULT_MSG_LENGTH_LIMIT)) });
    mMessageEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (charSequence.toString().trim().length() > 0) {
                mSendButton.setEnabled(true);
            } else {
                mSendButton.setEnabled(false);
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
    mSendButton = (Button) findViewById(R.id.sendButton);
    mSendButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            ChatMessage chatMessage = new ChatMessage(mMessageEditText.getText().toString(), mUsername, mPhotoUrl, mTimeStamp);
            mFirebaseDatabaseReference.child(MESSAGES_CHILD).push().setValue(chatMessage);
            mMessageEditText.setText("");
        }
    });
}
Also used : InputFilter(android.text.InputFilter) ChatMessage(de.bahnhoefe.deutschlands.bahnhofsfotos.model.ChatMessage) HashMap(java.util.HashMap) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) FirebaseRemoteConfigSettings(com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) RecyclerView(android.support.v7.widget.RecyclerView)

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