Search in sources :

Example 31 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project flexbox-layout by google.

the class FlexboxItemDecoration method drawHorizontalDecorations.

private void drawHorizontalDecorations(Canvas canvas, RecyclerView parent) {
    if (!needsHorizontalDecoration()) {
        return;
    }
    FlexboxLayoutManager layoutManager = (FlexboxLayoutManager) parent.getLayoutManager();
    int flexDirection = layoutManager.getFlexDirection();
    int parentLeft = parent.getLeft() - parent.getPaddingLeft();
    int parentRight = parent.getRight() + parent.getPaddingRight();
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View child = parent.getChildAt(i);
        RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
        int top, bottom;
        if (flexDirection == FlexDirection.COLUMN_REVERSE) {
            top = child.getBottom() + lp.bottomMargin;
            bottom = top + mDrawable.getIntrinsicHeight();
        } else {
            bottom = child.getTop() - lp.topMargin;
            top = bottom - mDrawable.getIntrinsicHeight();
        }
        int left, right;
        if (layoutManager.isMainAxisDirectionHorizontal()) {
            if (layoutManager.isLayoutRtl()) {
                right = child.getRight() + lp.rightMargin + mDrawable.getIntrinsicWidth();
                right = Math.min(right, parentRight);
                left = child.getLeft() - lp.leftMargin;
            } else {
                left = child.getLeft() - lp.leftMargin - mDrawable.getIntrinsicWidth();
                left = Math.max(left, parentLeft);
                right = child.getRight() + lp.rightMargin;
            }
        } else {
            left = child.getLeft() - lp.leftMargin;
            right = child.getRight() + lp.rightMargin;
        }
        mDrawable.setBounds(left, top, right, bottom);
        mDrawable.draw(canvas);
    }
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 32 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project Gadgetbridge by Freeyourgadget.

the class ConfigureAlarms method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_configure_alarms);
    IntentFilter filterLocal = new IntentFilter();
    filterLocal.addAction(DeviceService.ACTION_SAVE_ALARMS);
    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
    gbDevice = getIntent().getParcelableExtra(GBDevice.EXTRA_DEVICE);
    mGBAlarmListAdapter = new GBAlarmListAdapter(this);
    RecyclerView alarmsRecyclerView = findViewById(R.id.alarm_list);
    alarmsRecyclerView.setHasFixedSize(true);
    alarmsRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    alarmsRecyclerView.setAdapter(mGBAlarmListAdapter);
    updateAlarmsFromDB();
}
Also used : IntentFilter(android.content.IntentFilter) RecyclerView(androidx.recyclerview.widget.RecyclerView) GBAlarmListAdapter(nodomain.freeyourgadget.gadgetbridge.adapter.GBAlarmListAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 33 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project Gadgetbridge by Freeyourgadget.

the class ControlCenterv2 method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    AbstractGBActivity.init(this, AbstractGBActivity.NO_ACTIONBAR);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_controlcenterv2);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.controlcenter_navigation_drawer_open, R.string.controlcenter_navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    // end of material design boilerplate
    deviceManager = ((GBApplication) getApplication()).getDeviceManager();
    deviceListView = findViewById(R.id.deviceListView);
    deviceListView.setHasFixedSize(true);
    deviceListView.setLayoutManager(new LinearLayoutManager(this));
    deviceList = deviceManager.getDevices();
    mGBDeviceAdapter = new GBDeviceAdapterv2(this, deviceList, deviceActivityHashMap);
    // get activity data asynchronously, this fills the deviceActivityHashMap
    // and calls refreshPairedDevices() → notifyDataSetChanged
    createRefreshTask("get activity data", getApplication()).execute();
    deviceListView.setAdapter(this.mGBDeviceAdapter);
    fab = findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            launchDiscoveryActivity();
        }
    });
    showFabIfNeccessary();
    /* uncomment to enable fixed-swipe to reveal more actions

        ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(
                ItemTouchHelper.LEFT , ItemTouchHelper.RIGHT) {
            @Override
            public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
                if(dX>50)
                    dX = 50;
                super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);

            }

            @Override
            public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
                GB.toast(getBaseContext(), "onMove", Toast.LENGTH_LONG, GB.ERROR);

                return false;
            }

            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
                GB.toast(getBaseContext(), "onSwiped", Toast.LENGTH_LONG, GB.ERROR);

            }

            @Override
            public void onChildDrawOver(Canvas c, RecyclerView recyclerView,
                                        RecyclerView.ViewHolder viewHolder, float dX, float dY,
                                        int actionState, boolean isCurrentlyActive) {
            }
        });

        swipeToDismissTouchHelper.attachToRecyclerView(deviceListView);
        */
    registerForContextMenu(deviceListView);
    IntentFilter filterLocal = new IntentFilter();
    filterLocal.addAction(GBApplication.ACTION_LANGUAGE_CHANGE);
    filterLocal.addAction(GBApplication.ACTION_QUIT);
    filterLocal.addAction(GBApplication.ACTION_NEW_DATA);
    filterLocal.addAction(DeviceManager.ACTION_DEVICES_CHANGED);
    filterLocal.addAction(DeviceService.ACTION_REALTIME_SAMPLES);
    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
    refreshPairedDevices();
    /*
         * Ask for permission to intercept notifications on first run.
         */
    Prefs prefs = GBApplication.getPrefs();
    pesterWithPermissions = prefs.getBoolean("permission_pestering", true);
    Set<String> set = NotificationManagerCompat.getEnabledListenerPackages(this);
    if (pesterWithPermissions) {
        if (!set.contains(this.getPackageName())) {
            // If notification listener access hasn't been granted
            Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
            startActivity(enableIntent);
        }
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        checkAndRequestPermissions();
    }
    ChangeLog cl = createChangeLog();
    if (cl.isFirstRun()) {
        try {
            cl.getLogDialog().show();
        } catch (Exception ignored) {
            GB.toast(getBaseContext(), "Error showing Changelog", Toast.LENGTH_LONG, GB.ERROR);
        }
    }
    GBApplication.deviceService().start();
    if (GB.isBluetoothEnabled() && deviceList.isEmpty() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        startActivity(new Intent(this, DiscoveryActivity.class));
    } else {
        GBApplication.deviceService().requestDeviceInfo();
    }
}
Also used : IntentFilter(android.content.IntentFilter) NavigationView(com.google.android.material.navigation.NavigationView) ActionBarDrawerToggle(androidx.appcompat.app.ActionBarDrawerToggle) GBDeviceAdapterv2(nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2) Intent(android.content.Intent) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NavigationView(com.google.android.material.navigation.NavigationView) ChangeLog(de.cketti.library.changelog.ChangeLog) DrawerLayout(androidx.drawerlayout.widget.DrawerLayout) Toolbar(androidx.appcompat.widget.Toolbar)

Example 34 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project Gadgetbridge by Freeyourgadget.

the class AbstractAppManagerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mGBDevice = ((AppManagerActivity) getActivity()).getGBDevice();
    mCoordinator = DeviceHelper.getInstance().getCoordinator(mGBDevice);
    final FloatingActionButton appListFab = ((FloatingActionButton) getActivity().findViewById(R.id.fab));
    final FloatingActionButton appListFabNew = ((FloatingActionButton) getActivity().findViewById(R.id.fab_new));
    watchfaceDesignerActivity = mCoordinator.getWatchfaceDesignerActivity();
    View rootView = inflater.inflate(R.layout.activity_appmanager, container, false);
    RecyclerView appListView = (RecyclerView) (rootView.findViewById(R.id.appListView));
    appListView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (dy > 0) {
                appListFab.hide();
                appListFabNew.hide();
            } else if (dy < 0) {
                appListFab.show();
                if (watchfaceDesignerActivity != null) {
                    appListFabNew.show();
                }
            }
        }
    });
    appListView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mGBDeviceAppAdapter = new GBDeviceAppAdapter(appList, R.layout.item_pebble_watchapp, this);
    appListView.setAdapter(mGBDeviceAppAdapter);
    ItemTouchHelper.Callback appItemTouchHelperCallback = new AppItemTouchHelperCallback(mGBDeviceAppAdapter);
    appManagementTouchHelper = new ItemTouchHelper(appItemTouchHelperCallback);
    appManagementTouchHelper.attachToRecyclerView(appListView);
    if ((watchfaceDesignerActivity != null) && (appListFabNew != null)) {
        appListFabNew.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent startIntent = new Intent(getContext(), watchfaceDesignerActivity);
                startIntent.putExtra(GBDevice.EXTRA_DEVICE, mGBDevice);
                getContext().startActivity(startIntent);
            }
        });
        appListFabNew.show();
    }
    return rootView;
}
Also used : GBDeviceAppAdapter(nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAppAdapter) Intent(android.content.Intent) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 35 with RecyclerView

use of androidx.recyclerview.widget.RecyclerView in project Gadgetbridge by Freeyourgadget.

the class CommuteActionsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_commute_actions);
    sharedPreferences = GBApplication.getPrefs().getPreferences();
    findViewById(R.id.actionAddFab).setOnClickListener(this);
    // set up the RecyclerView
    RecyclerView recyclerView = findViewById(R.id.actionsListView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    actionsListAdapter = new CommuteActionsListAdapter(this, actionsList);
    actionsListAdapter.setClickListener(this);
    recyclerView.setAdapter(actionsListAdapter);
    refreshActions();
    // set up touch helper for reordering items
    ItemTouchHelper.Callback actionTouchHelperCallback = new ActionTouchHelperCallback(actionsListAdapter);
    actionTouchHelper = new ItemTouchHelper(actionTouchHelperCallback);
    actionTouchHelper.attachToRecyclerView(recyclerView);
}
Also used : ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

RecyclerView (androidx.recyclerview.widget.RecyclerView)352 View (android.view.View)232 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)156 TextView (android.widget.TextView)51 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)39 ImageView (android.widget.ImageView)29 Nullable (androidx.annotation.Nullable)29 Toolbar (androidx.appcompat.widget.Toolbar)25 Test (org.junit.Test)24 ArrayList (java.util.ArrayList)20 Intent (android.content.Intent)19 NonNull (androidx.annotation.NonNull)19 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)19 Bundle (android.os.Bundle)18 ViewGroup (android.view.ViewGroup)16 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)16 Context (android.content.Context)15 Rect (android.graphics.Rect)15 SuppressLint (android.annotation.SuppressLint)12 LayoutInflater (android.view.LayoutInflater)11