Java Code Examples for androidx.recyclerview.widget.LinearLayoutManager#HORIZONTAL

The following examples show how to use androidx.recyclerview.widget.LinearLayoutManager#HORIZONTAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridSpacingItemDecoration.java    From a with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void getItemOffsets(@NonNull Rect outRect, @NonNull View view,
                           @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
    if (parent.getLayoutManager() != null) {
        if (parent.getLayoutManager() instanceof LinearLayoutManager && !(parent.getLayoutManager() instanceof GridLayoutManager)) {
            if (((LinearLayoutManager) parent.getLayoutManager()).getOrientation() == LinearLayoutManager.HORIZONTAL) {
                outRect.set(space, 0, space, 0);
            } else {
                outRect.set(0, space, 0, space);
            }
        } else {
            outRect.set(space, space, space, space);
        }
    }

}
 
Example 2
Source File: GridSpacingItemDecoration.java    From a with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
    super.onDraw(c, parent, state);
    if (parent.getLayoutManager() != null) {
        if (parent.getLayoutManager() instanceof LinearLayoutManager && !(parent.getLayoutManager() instanceof GridLayoutManager)) {
            if (((LinearLayoutManager) parent.getLayoutManager()).getOrientation() == LinearLayoutManager.HORIZONTAL) {
                drawHorizontal(c, parent);
            } else {
                drawVertical(c, parent);
            }
        } else {
            if (type == 0) {
                drawGrideview(c, parent);
            } else {
                drawGrideview1(c, parent);
            }
        }
    }
}
 
Example 3
Source File: HourlyActivity.java    From weather with Apache License 2.0 5 votes vote down vote up
private void initRecyclerView() {
  LinearLayoutManager layoutManager
      = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
  recyclerView.setLayoutManager(layoutManager);
  mItemAdapter = new ItemAdapter<>();
  mFastAdapter = FastAdapter.with(mItemAdapter);
  recyclerView.setItemAnimator(new DefaultItemAnimator());
  recyclerView.setAdapter(mFastAdapter);
}
 
Example 4
Source File: RecyclerViewAttacher.java    From ScrollingPagerIndicator with Apache License 2.0 5 votes vote down vote up
private void updateCurrentOffset() {
    final View firstView = findFirstVisibleView();
    if (firstView == null) {
        return;
    }

    int position = recyclerView.getChildAdapterPosition(firstView);
    if (position == RecyclerView.NO_POSITION) {
        return;
    }
    final int itemCount = attachedAdapter.getItemCount();

    // In case there is an infinite pager
    if (position >= itemCount && itemCount != 0) {
        position = position % itemCount;
    }

    float offset;
    if (layoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
        offset = (getCurrentFrameLeft() - firstView.getX()) / firstView.getMeasuredWidth();
    } else {
        offset = (getCurrentFrameBottom() - firstView.getY()) / firstView.getMeasuredHeight();
    }

    if (offset >= 0 && offset <= 1 && position < itemCount) {
        indicator.onPageScrolled(position, offset);
    }
}
 
Example 5
Source File: EditImageActivity.java    From indigenous-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    makeFullScreen();
    setContentView(R.layout.photoeditor_activity_edit_image);

    initViews();
    handleIntentImage();

    mPropertiesBSFragment = new PropertiesBSFragment();
    mEmojiBSFragment = new EmojiBSFragment();
    mEmojiBSFragment.setEmojiListener(this);
    mPropertiesBSFragment.setPropertiesChangeListener(this);

    LinearLayoutManager llmTools = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    mRvTools.setLayoutManager(llmTools);
    mRvTools.setAdapter(mEditingToolsAdapter);

    LinearLayoutManager llmFilters = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    mRvFilters.setLayoutManager(llmFilters);
    mRvFilters.setAdapter(mFilterViewAdapter);

    mPhotoEditor = new PhotoEditor.Builder(this, mPhotoEditorView)
            .setPinchTextScalable(true)
            .build();

    mPhotoEditor.setOnPhotoEditorListener(this);
}
 
Example 6
Source File: SaveActivity.java    From Chimee with MIT License 5 votes vote down vote up
private void setupRecyclerView(List<String> files) {
    RecyclerView recyclerView = findViewById(R.id.rv_document_list);
    LinearLayoutManager horizontalLayoutManager
            = new LinearLayoutManager(this,
            LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(horizontalLayoutManager);
    DividerItemDecoration dividerItemDecoration =
            new DividerItemDecoration(recyclerView.getContext(),
                    horizontalLayoutManager.getOrientation());
    recyclerView.addItemDecoration(dividerItemDecoration);
    adapter = new SimpleListRvAdapter(this, files);
    adapter.setClickListener(this);
    recyclerView.setAdapter(adapter);
}
 
Example 7
Source File: ListViewDecoration.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if (divider != null) {
        outRect.set(0, 0, 0, divider.getIntrinsicHeight());
    } else {
        int position = parent.getChildAdapterPosition(view); // item position
        boolean hasHeader = false;
        if (parent instanceof SuperRecyclerView) {
            SuperRecyclerView superRecyclerView = (SuperRecyclerView) parent;
            if (superRecyclerView.getHeaderContainer().getChildCount() > position) {
                return;
            }
            int headerCount = superRecyclerView.getHeaderContainer().getChildCount();
            position -= headerCount;
            hasHeader = headerCount > 0;
        }
        RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
        if (layoutManager instanceof GridLayoutManager) {

        } else if (layoutManager instanceof LinearLayoutManager) {
            LinearLayoutManager linearLayoutManager = ((LinearLayoutManager) layoutManager);
            if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
                outRect.right = divideSize;
                if (hasHeader && position == 0) {
                    outRect.left = divideSize;
                }
            } else {
                outRect.bottom = divideSize;
                if (position == 0) {
                    outRect.top = divideSize;
                }
            }

        }
    }
}
 
Example 8
Source File: LayoutInfoUtils.java    From litho with Apache License 2.0 5 votes vote down vote up
/**
 * Return the accumulated height of ComponentTreeHolders, or return the {@param maxHeight} if the
 * accumulated height is higher than the {@param maxHeight}.
 */
public static int computeLinearLayoutWrappedHeight(
    LinearLayoutManager linearLayoutManager,
    int maxHeight,
    List<ComponentTreeHolder> componentTreeHolders) {
  final int itemCount = componentTreeHolders.size();
  int measuredHeight = 0;

  switch (linearLayoutManager.getOrientation()) {
    case LinearLayoutManager.VERTICAL:
      for (int i = 0; i < itemCount; i++) {
        final ComponentTreeHolder holder = componentTreeHolders.get(i);

        measuredHeight += holder.getMeasuredHeight();
        measuredHeight += LayoutInfoUtils.getTopDecorationHeight(linearLayoutManager, i);
        measuredHeight += LayoutInfoUtils.getBottomDecorationHeight(linearLayoutManager, i);

        if (measuredHeight > maxHeight) {
          measuredHeight = maxHeight;
          break;
        }
      }
      return measuredHeight;

    case LinearLayoutManager.HORIZONTAL:
    default:
      throw new IllegalStateException(
          "This method should only be called when orientation is vertical");
  }
}
 
Example 9
Source File: NovelHeader.java    From Pixiv-Shaft with MIT License 5 votes vote down vote up
public void initView(Context context) {
    baseBind.topRela.setVisibility(View.GONE);
    baseBind.seeMore.setOnClickListener(v -> {
        Intent intent = new Intent(context, RankActivity.class);
        intent.putExtra("dataType", "小说");
        context.startActivity(intent);
    });
    baseBind.ranking.addItemDecoration(new LinearItemHorizontalDecoration(DensityUtil.dp2px(8.0f)));
    LinearLayoutManager manager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
    baseBind.ranking.setLayoutManager(manager);
    baseBind.ranking.setHasFixedSize(true);
}
 
Example 10
Source File: FragmentPivisionHorizontal.java    From Pixiv-Shaft with MIT License 5 votes vote down vote up
@Override
public void initRecyclerView() {
    baseBind.recyclerView.addItemDecoration(new LinearItemHorizontalDecoration(DensityUtil.dp2px(8.0f)));
    LinearLayoutManager manager = new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false);
    baseBind.recyclerView.setLayoutManager(manager);
    baseBind.recyclerView.setHasFixedSize(true);
    ViewGroup.LayoutParams layoutParams = baseBind.recyclerView.getLayoutParams();
    layoutParams.width = MATCH_PARENT;
    layoutParams.height = mContext.getResources()
            .getDimensionPixelSize(R.dimen.article_horizontal_height) +
            mContext.getResources()
                    .getDimensionPixelSize(R.dimen.sixteen_dp);
    baseBind.recyclerView.setLayoutParams(layoutParams);
}
 
Example 11
Source File: DayPickerView.java    From cathode with Apache License 2.0 5 votes vote down vote up
public void init(Context context) {
  setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

  inflate(context, R.layout.day_picker_view, this);

  recyclerView = (RecyclerView) findViewById(android.R.id.list);
  layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
  recyclerView.setLayoutManager(layoutManager);
  recyclerView.setAdapter(mAdapter);
  SnapHelper snapHelper = new LinearSnapHelper();
  snapHelper.attachToRecyclerView(recyclerView);
}
 
Example 12
Source File: PuzzleSelectorActivity.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
private void initPreview() {
    rvPreview = (RecyclerView) findViewById(R.id.rv_preview_selected_photos);
    LinearLayoutManager lm = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    previewAdapter = new PuzzleSelectorPreviewAdapter(this, selectedPhotos, this);
    rvPreview.setLayoutManager(lm);
    rvPreview.setAdapter(previewAdapter);
}
 
Example 13
Source File: MongolMenu.java    From mongol-library with MIT License 5 votes vote down vote up
private void createContentViewIfNeeded() {
    if (mContentView != null) return;
    RecyclerView recyclerView = new RecyclerView(mContext);
    LinearLayoutManager layoutManager = new LinearLayoutManager(mContext,
            LinearLayoutManager.HORIZONTAL, false);
    recyclerView.setLayoutManager(layoutManager);
    MenuItemAdapter adapter = new MenuItemAdapter(mContext);
    recyclerView.setAdapter(adapter);
    recyclerView.setBackgroundColor(Color.WHITE);
    mContentView = recyclerView;
}
 
Example 14
Source File: FamiliarDefaultItemDecoration.java    From FamiliarRecyclerView with MIT License 5 votes vote down vote up
private void initLayoutManagerType() {
    mLayoutManagerType = mFamiliarRecyclerView.getCurLayoutManagerType();
    RecyclerView.LayoutManager layoutManager = mFamiliarRecyclerView.getLayoutManager();
    switch (mLayoutManagerType) {
        case FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_LINEAR:
            LinearLayoutManager curLinearLayoutManager = (LinearLayoutManager) layoutManager;
            if (curLinearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
                mOrientation = OrientationHelper.HORIZONTAL;
            } else {
                mOrientation = OrientationHelper.VERTICAL;
            }
            break;
        case FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_GRID:
            GridLayoutManager curGridLayoutManager = (GridLayoutManager) layoutManager;
            mGridSpanCount = curGridLayoutManager.getSpanCount();
            if (curGridLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
                mOrientation = OrientationHelper.HORIZONTAL;
            } else {
                mOrientation = OrientationHelper.VERTICAL;
            }
            break;
        case FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_STAGGERED_GRID:
            StaggeredGridLayoutManager curStaggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            mGridSpanCount = curStaggeredGridLayoutManager.getSpanCount();
            if (curStaggeredGridLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
                mOrientation = OrientationHelper.HORIZONTAL;
            } else {
                mOrientation = OrientationHelper.VERTICAL;
            }
            break;
        default:
            mLayoutManagerType = FamiliarRecyclerView.LAYOUT_MANAGER_TYPE_LINEAR;
    }

    initDivisible();
}
 
Example 15
Source File: FakeFootballActivity.java    From AndroidAnimationExercise with Apache License 2.0 4 votes vote down vote up
private void initData() {
    String json = Tools.readStrFromAssets("player.json", mContext);
    Gson mGson = new Gson();
    mPlayerBeanList = mGson.fromJson(json, new TypeToken<List<PlayerBean>>() {
    }.getType());

    adapter = new PlayAdapter(mPlayerBeanList);
    GridLayoutManager manager = new GridLayoutManager(mContext,
            2, LinearLayoutManager.HORIZONTAL, false);
    playerLists.setLayoutManager(manager);
    playerLists.setAdapter(adapter);
    adapter.setOnRVItemClickListener(new PlayAdapter.OnRVItemClickListener() {
        @Override
        public void onRVItemClick(ViewGroup parent, View itemView, int position) {
            int mBubblePosition = mGameView.getCurrentPos();

            if (mBubblePosition == -1) {
                Toast.makeText(mContext, "先点击气泡,再添加球员", Toast.LENGTH_SHORT).show();
                return;
            }


            if (mPlayerBeanList.get(position).isSelected()) {
                Toast.makeText(mContext, "球员已被选择!", Toast.LENGTH_SHORT).show();
            } else {


                View avatar = itemView.findViewById(R.id.img);


                int width = avatar.getWidth();
                int height = avatar.getHeight();
                Bitmap bitmap = Tools.View2Bitmap(avatar, width, height);
                int[] location = new int[2];
                itemView.getLocationOnScreen(location);
                if (bitmap != null) {
                    mGameView.updatePlayer(bitmap, mPlayerBeanList.get(position).getName(), location, content);
                    for (int i = 0; i < mPlayerBeanList.size(); i++) {
                        if (mPlayerBeanList.get(i).getPosition() == mBubblePosition) {
                            //同一个位置,先把上次选中的球员,设置为未选中
                            mPlayerBeanList.get(i).setSelected(false);
                        }
                    }
                    //将此次更新的球员设置为气泡上选中的球员
                    mPlayerBeanList.get(position).setSelected(true);
                    mPlayerBeanList.get(position).setPosition(mBubblePosition);
                    adapter.notifyDataSetChanged();
                }

            }
        }
    });
}
 
Example 16
Source File: ReorderListHorizontalFragment.java    From RecyclerExt with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    orientation = LinearLayoutManager.HORIZONTAL;
    return super.onCreateView(inflater, container, savedInstanceState);
}
 
Example 17
Source File: ChatAttachAlertPhotoLayout.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean onCustomMeasure(View view, int width, int height) {
    boolean isPortrait = width < height;
    if (view == cameraIcon) {
        cameraIcon.measure(View.MeasureSpec.makeMeasureSpec(itemSize, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(itemSize - cameraViewOffsetBottomY - cameraViewOffsetY, View.MeasureSpec.EXACTLY));
        return true;
    } else if (view == cameraView) {
        if (cameraOpened && !cameraAnimationInProgress) {
            cameraView.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
            return true;
        }
    } else if (view == cameraPanel) {
        if (isPortrait) {
            cameraPanel.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(126), View.MeasureSpec.EXACTLY));
        } else {
            cameraPanel.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(126), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
        }
        return true;
    } else if (view == zoomControlView) {
        if (isPortrait) {
            zoomControlView.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(50), View.MeasureSpec.EXACTLY));
        } else {
            zoomControlView.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(50), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
        }
        return true;
    } else if (view == cameraPhotoRecyclerView) {
        cameraPhotoRecyclerViewIgnoreLayout = true;
        if (isPortrait) {
            cameraPhotoRecyclerView.measure(View.MeasureSpec.makeMeasureSpec(width, View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(80), View.MeasureSpec.EXACTLY));
            if (cameraPhotoLayoutManager.getOrientation() != LinearLayoutManager.HORIZONTAL) {
                cameraPhotoRecyclerView.setPadding(AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8), 0);
                cameraPhotoLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
                cameraAttachAdapter.notifyDataSetChanged();
            }
        } else {
            cameraPhotoRecyclerView.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(80), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(height, View.MeasureSpec.EXACTLY));
            if (cameraPhotoLayoutManager.getOrientation() != LinearLayoutManager.VERTICAL) {
                cameraPhotoRecyclerView.setPadding(0, AndroidUtilities.dp(8), 0, AndroidUtilities.dp(8));
                cameraPhotoLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                cameraAttachAdapter.notifyDataSetChanged();
            }
        }
        cameraPhotoRecyclerViewIgnoreLayout = false;
        return true;
    }
    return false;
}
 
Example 18
Source File: WeatherFragment.java    From Weather with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    rootView = inflater.inflate(R.layout.fragment_weather, container, false);
    ButterKnife.bind(this, rootView);
    MaterialDialog.Builder builder = new MaterialDialog.Builder(this.activity())
            .title(getString(R.string.please_wait))
            .content(getString(R.string.loading))
            .cancelable(false)
            .progress(true, 0);
    pd = builder.build();
    setHasOptionsMenu(true);
    preferences = new Prefs(context());
    weatherFont = Typeface.createFromAsset(activity().getAssets(), "fonts/weather-icons-v2.0.10.ttf");
    fab = ((WeatherActivity) activity()).findViewById(R.id.fab);
    Bundle bundle = getArguments();
    fabProgressCircle = ((WeatherActivity) activity()).findViewById(R.id.fabProgressCircle);
    int mode;
    if (bundle != null)
        mode = bundle.getInt(Constants.MODE, 0);
    else
        mode = 0;
    if (mode == 0)
        updateWeatherData(preferences.getCity(), null, null);
    else
        updateWeatherData(null, Float.toString(preferences.getLatitude()), Float.toString(preferences.getLongitude()));
    gps = new GPSTracker(context());
    cityField.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    updatedField.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    humidityView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunriseIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunriseIcon.setTypeface(weatherFont);
    sunriseIcon.setText(activity().getString(R.string.sunrise_icon));
    sunsetIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunsetIcon.setTypeface(weatherFont);
    sunsetIcon.setText(activity().getString(R.string.sunset_icon));
    humidityIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    humidityIcon.setTypeface(weatherFont);
    humidityIcon.setText(activity().getString(R.string.humidity_icon));
    windView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    swipeView.setColorSchemeResources(R.color.red, R.color.green, R.color.blue, R.color.yellow, R.color.orange);
    swipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    changeCity(preferences.getCity());
                    swipeView.setRefreshing(false);
                }
            });
        }
    });
    horizontalLayoutManager
            = new LinearLayoutManager(context(), LinearLayoutManager.HORIZONTAL, false);
    horizontalRecyclerView.setLayoutManager(horizontalLayoutManager);
    horizontalRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (horizontalLayoutManager.findLastVisibleItemPosition() == 9 || citys != null)
                fab.hide();
            else
                fab.show();
        }
    });
    directionView.setTypeface(weatherFont);
    directionView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    dailyView.setText(getString(R.string.daily));
    dailyView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunriseView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    sunsetView.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    button.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    pd.show();
    horizontalRecyclerView.setBackgroundColor(getResources().getColor(R.color.colorPrimary));
    weatherIcon.setTypeface(weatherFont);
    weatherIcon.setTextColor(ContextCompat.getColor(context(), R.color.textColor));
    if (citys == null)
        ((WeatherActivity) activity()).showFab();
    else
        ((WeatherActivity) activity()).hideFab();
    return rootView;
}
 
Example 19
Source File: TextSearchFragment.java    From trekarta with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    Bundle arguments = getArguments();
    double latitude = arguments.getDouble(ARG_LATITUDE);
    double longitude = arguments.getDouble(ARG_LONGITUDE);

    if (savedInstanceState != null) {
        latitude = savedInstanceState.getDouble(ARG_LATITUDE);
        longitude = savedInstanceState.getDouble(ARG_LONGITUDE);
    }

    Activity activity = getActivity();

    mCoordinates = new GeoPoint(latitude, longitude);

    mDatabase = MapTrek.getApplication().getDetailedMapDatabase();

    mAdapter = new DataListAdapter(activity, mEmptyCursor, 0);
    setListAdapter(mAdapter);

    QuickFilterAdapter adapter = new QuickFilterAdapter(activity);
    mViews.quickFilters.setAdapter(adapter);

    LinearLayoutManager horizontalLayoutManager
            = new LinearLayoutManager(activity, LinearLayoutManager.HORIZONTAL, false);
    mViews.quickFilters.setLayoutManager(horizontalLayoutManager);

    Resources resources = activity.getResources();
    String packageName = activity.getPackageName();
    mKinds = new CharSequence[Tags.kinds.length]; // we add two kinds but skip two last
    mKinds[0] = activity.getString(R.string.any);
    mKinds[1] = resources.getString(R.string.kind_place);
    for (int i = 0; i < Tags.kinds.length - 2; i++) { // skip urban and barrier kinds
        int id = resources.getIdentifier(Tags.kinds[i], "string", packageName);
        mKinds[i + 2] = id != 0 ? resources.getString(id) : Tags.kinds[i];
    }

    if (mUpdating || !MapTrekDatabaseHelper.hasFullTextIndex(mDatabase)) {
        mViews.searchFooter.setVisibility(View.GONE);
        mViews.ftsWait.spin();
        mViews.ftsWait.setVisibility(View.VISIBLE);
        mViews.message.setText(R.string.msgWaitForFtsTable);
        mViews.message.setVisibility(View.VISIBLE);

        if (!mUpdating) {
            mUpdating = true;
            final Message m = Message.obtain(mBackgroundHandler, () -> {
                MapTrekDatabaseHelper.createFtsTable(mDatabase);
                hideProgress();
                mUpdating = false;
            });
            m.what = MSG_CREATE_FTS;
            mBackgroundHandler.sendMessage(m);
        } else {
            mBackgroundHandler.post(this::hideProgress);
        }
    } else {
        HelperUtils.showTargetedAdvice(getActivity(), Configuration.ADVICE_TEXT_SEARCH, R.string.advice_text_search, mViews.searchFooter, false);
    }
}
 
Example 20
Source File: StickyFooterBehavior.java    From brickkit-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void translateStickyView() {
    BrickRecyclerAdapter adapter = brickDataManager.getBrickRecyclerAdapter();

    if (stickyViewHolder == null || adapter == null || adapter.getRecyclerView() == null) {
        return;
    }

    int footerOffsetX = 0, footerOffsetY = 0;

    //Search for the position where the next footer item is found and take the new offset
    for (int i = adapter.getRecyclerView().getChildCount() - 2; i < adapter.getItemCount(); i++) {
        final View nextChild = adapter.getRecyclerView().getChildAt(i);
        if (nextChild != null) {
            int adapterPos = adapter.getRecyclerView().getChildAdapterPosition(nextChild);
            int nextFooterPosition = getStickyViewPosition(adapterPos);
            if (stickyPosition != nextFooterPosition) {
                if (getOrientation(adapter.getRecyclerView()) == LinearLayoutManager.HORIZONTAL) {
                    if (nextChild.getRight() < adapter.getRecyclerView().getRight()) {
                        int footerWidth = stickyViewHolder.itemView.getMeasuredWidth();
                        footerOffsetX = Math.max(footerWidth - (adapter.getRecyclerView().getRight() - nextChild.getRight()), 0);
                        if (footerOffsetX > 0) {
                            break;
                        }
                    }
                } else {
                    if (nextChild.getBottom() < adapter.getRecyclerView().getBottom()) {
                        int footerHeight = stickyViewHolder.itemView.getMeasuredHeight();
                        footerOffsetY = Math.max(footerHeight - (adapter.getRecyclerView().getBottom() - nextChild.getBottom()), 0);
                        if (footerOffsetY > 0) {
                            break;
                        }
                    }
                }
            }
        }
    }

    //Apply translation
    stickyViewHolder.itemView.setTranslationX(footerOffsetX);
    stickyViewHolder.itemView.setTranslationY(footerOffsetY);
    if (stickyHolderShadowImage != null) {
        stickyHolderShadowImage.setTranslationX(footerOffsetX);
        stickyHolderShadowImage.setTranslationY(footerOffsetY);
    }
}