Search in sources :

Example 21 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project Carbon by ZieIony.

the class SampleListActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    SharedPreferences preferences = getSharedPreferences("samples", Context.MODE_PRIVATE);
    allPreferences = (Map<String, String>) preferences.getAll();
    RecyclerView recyclerView = findViewById(R.id.recycler);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    adapter = new RowListAdapter<>();
    adapter.putFactory(SampleActivityGroup.class, parent -> new DataBindingComponent<>(parent, R.layout.row_main));
    adapter.putFactory(SampleActivityItem.class, parent -> {
        return new DataBindingComponent<SampleActivityItem>(parent, R.layout.row_sample) {

            @Override
            public void bind(SampleActivityItem data) {
                super.bind(data);
                getView().findViewById(R.id.star).setOnClickListener(v -> {
                    data.setStarred(!data.isStarred());
                    if (data.isStarred()) {
                        preferences.edit().putString(data.getActivityClass().getName(), getString(data.getName())).commit();
                    } else {
                        preferences.edit().remove(data.getActivityClass().getName()).commit();
                    }
                    for (int i = 0; i < adapter.getItemCount(); i++) {
                        if (adapter.getItems().get(i) == data) {
                            adapter.notifyItemChanged(i);
                            break;
                        }
                    }
                });
            }
        };
    });
    adapter.putFactory(String.class, parent -> new DataBindingComponent<>(parent, R.layout.row_description));
    adapter.setOnItemClickedListener((view, item, position) -> {
        if (item instanceof SampleActivityGroup) {
            Class activityClass = ((SampleActivityGroup) item).getActivityClass();
            Intent intent = new Intent(view.getContext(), activityClass);
            startActivity(intent);
        }
    });
    recyclerView.setAdapter(adapter);
    ViewItemDecoration itemDecoration = new ViewItemDecoration(this, R.layout.carbon_row_padding);
    itemDecoration.setDrawBefore(position -> position == 0);
    itemDecoration.setDrawAfter(position -> position == adapter.getItemCount() - 1);
    recyclerView.addItemDecoration(itemDecoration);
}
Also used : ViewItemDecoration(carbon.recycler.ViewItemDecoration) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RecyclerView(carbon.widget.RecyclerView)

Example 22 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project Carbon by ZieIony.

the class ExpandableRecyclerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    initToolbar();
    final ExpandableRecyclerView recyclerView = findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    final ExpandableFruitAdapter fruitAdapter = new ExpandableFruitAdapter(fruits);
    recyclerView.setAdapter(fruitAdapter);
    DividerItemDecoration decoration = new DividerItemDecoration(this);
    decoration.setDrawBefore(position -> position > 0 && fruits.contains(fruitAdapter.getItem(position)));
    recyclerView.addItemDecoration(decoration);
}
Also used : ExpandableRecyclerView(carbon.widget.ExpandableRecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerItemDecoration(carbon.recycler.DividerItemDecoration)

Example 23 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project MaterialDateTimePicker by wdullaer.

the class GravitySnapHelper method findEndView.

private View findEndView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) {
    if (layoutManager instanceof LinearLayoutManager) {
        int lastChild = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
        if (lastChild == RecyclerView.NO_POSITION) {
            return null;
        }
        View child = layoutManager.findViewByPosition(lastChild);
        float visibleWidth;
        if (isRtlHorizontal) {
            visibleWidth = (float) helper.getDecoratedEnd(child) / helper.getDecoratedMeasurement(child);
        } else {
            visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child)) / helper.getDecoratedMeasurement(child);
        }
        // If we're at the start of the list, we shouldn't snap
        // to avoid having the first item not completely visible.
        boolean startOfList = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition() == 0;
        if (visibleWidth > 0.5f && !startOfList) {
            return child;
        } else if (startOfList) {
            return null;
        } else {
            // If the child wasn't returned, we need to return the previous view
            return layoutManager.findViewByPosition(lastChild - 1);
        }
    }
    return null;
}
Also used : LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 24 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project MaterialDateTimePicker by wdullaer.

the class GravitySnapHelper method findStartView.

/**
 * Returns the first view that we should snap to.
 *
 * @param layoutManager the recyclerview's layout manager
 * @param helper        orientation helper to calculate view sizes
 * @return the first view in the LayoutManager to snap to
 */
private View findStartView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) {
    if (layoutManager instanceof LinearLayoutManager) {
        int firstChild = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
        if (firstChild == RecyclerView.NO_POSITION) {
            return null;
        }
        View child = layoutManager.findViewByPosition(firstChild);
        float visibleWidth;
        // In a RTL configuration, we need to check the start point and in LTR the end point
        if (isRtlHorizontal) {
            visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child)) / helper.getDecoratedMeasurement(child);
        } else {
            visibleWidth = (float) helper.getDecoratedEnd(child) / helper.getDecoratedMeasurement(child);
        }
        // If we're at the end of the list, we shouldn't snap
        // to avoid having the last item not completely visible.
        boolean endOfList = ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1;
        if (visibleWidth > 0.5f && !endOfList) {
            return child;
        } else if (endOfList) {
            return null;
        } else {
            // the next view close to the start.
            return layoutManager.findViewByPosition(firstChild + 1);
        }
    }
    return null;
}
Also used : LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 25 with LinearLayoutManager

use of androidx.recyclerview.widget.LinearLayoutManager in project OneSignal-Android-SDK by OneSignal.

the class MainActivityViewModel method setupTriggerRecyclerView.

private void setupTriggerRecyclerView() {
    recyclerViewBuilder.setupRecyclerView(triggersRecyclerView, 20, false, true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    triggersRecyclerView.setLayoutManager(linearLayoutManager);
    triggerPairRecyclerViewAdapter = new PairRecyclerViewAdapter(context, triggerArrayList, key -> {
        OneSignal.removeTriggerForKey(key);
        triggerSet.remove(key);
        refreshTriggerRecyclerView();
        toaster.makeCustomViewToast("Deleted trigger " + key, ToastType.SUCCESS);
    });
    triggersRecyclerView.setAdapter(triggerPairRecyclerViewAdapter);
}
Also used : LinearLayout(android.widget.LinearLayout) Switch(android.widget.Switch) PairItemActionCallback(com.onesignal.sdktest.callback.PairItemActionCallback) PairRecyclerViewAdapter(com.onesignal.sdktest.adapter.PairRecyclerViewAdapter) NestedScrollView(androidx.core.widget.NestedScrollView) UpdateAlertDialogCallback(com.onesignal.sdktest.callback.UpdateAlertDialogCallback) OSDeviceState(com.onesignal.OSDeviceState) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) Toaster(com.onesignal.sdktest.util.Toaster) AppBarLayout(com.google.android.material.appbar.AppBarLayout) OneSignal(com.onesignal.OneSignal) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) InAppMessageRecyclerViewAdapter(com.onesignal.sdktest.adapter.InAppMessageRecyclerViewAdapter) Map(java.util.Map) View(android.view.View) Button(android.widget.Button) RecyclerView(androidx.recyclerview.widget.RecyclerView) ProfileUtil(com.onesignal.sdktest.util.ProfileUtil) SharedPreferenceUtil(com.onesignal.sdktest.util.SharedPreferenceUtil) Notification(com.onesignal.sdktest.type.Notification) TextView(android.widget.TextView) RecyclerViewBuilder(com.onesignal.sdktest.ui.RecyclerViewBuilder) AddPairAlertDialogCallback(com.onesignal.sdktest.callback.AddPairAlertDialogCallback) Toolbar(androidx.appcompat.widget.Toolbar) RelativeLayout(android.widget.RelativeLayout) NotificationRecyclerViewAdapter(com.onesignal.sdktest.adapter.NotificationRecyclerViewAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ToastType(com.onesignal.sdktest.type.ToastType) Context(android.content.Context) SecondaryActivity(com.onesignal.sdktest.activity.SecondaryActivity) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) R(com.onesignal.sdktest.R) Pair(android.util.Pair) Dialog(com.onesignal.sdktest.util.Dialog) Intent(android.content.Intent) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IntentTo(com.onesignal.sdktest.util.IntentTo) Animate(com.onesignal.sdktest.util.Animate) CurrentUser(com.onesignal.sdktest.user.CurrentUser) Font(com.onesignal.sdktest.util.Font) Iterator(java.util.Iterator) CompoundButton(android.widget.CompoundButton) InAppMessage(com.onesignal.sdktest.type.InAppMessage) OSPermissionStateChanges(com.onesignal.OSPermissionStateChanges) ViewTreeObserver(android.view.ViewTreeObserver) Text(com.onesignal.sdktest.constant.Text) Activity(android.app.Activity) OSEmailSubscriptionStateChanges(com.onesignal.OSEmailSubscriptionStateChanges) OSSubscriptionStateChanges(com.onesignal.OSSubscriptionStateChanges) PairRecyclerViewAdapter(com.onesignal.sdktest.adapter.PairRecyclerViewAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)470 RecyclerView (androidx.recyclerview.widget.RecyclerView)281 View (android.view.View)183 TextView (android.widget.TextView)65 ArrayList (java.util.ArrayList)37 Nullable (androidx.annotation.Nullable)33 Bundle (android.os.Bundle)32 Toolbar (androidx.appcompat.widget.Toolbar)32 Intent (android.content.Intent)30 ImageView (android.widget.ImageView)27 List (java.util.List)24 Test (org.junit.Test)24 Context (android.content.Context)23 NonNull (androidx.annotation.NonNull)23 ViewGroup (android.view.ViewGroup)22 AlertDialog (androidx.appcompat.app.AlertDialog)21 ContextualCard (com.android.settings.homepage.contextualcards.ContextualCard)20 LayoutInflater (android.view.LayoutInflater)18 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)16 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)16