Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ SlidrConfig config = new SlidrConfig.Builder()
.distanceThreshold(0.25f)
.edge(true|false)
.edgeSize(0.18f) // The % of the screen that counts as the edge, default 18%
.ignoreChildScroll(true|false) // default is false
.listener(new SlidrListener(){...})
.build();

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:3.5.3'
}
}

Expand Down
2 changes: 1 addition & 1 deletion example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {

defaultConfig {
applicationId "com.r0adkll.slidr.example"
minSdkVersion minSdk
minSdkVersion 21
targetSdkVersion targetSdk
versionCode 1
versionName VERSION_NAME
Expand Down
6 changes: 3 additions & 3 deletions example/example.iml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":example" />
<option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" value="3.5.0" />
<option name="LAST_KNOWN_AGP_VERSION" value="3.5.0" />
<option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" value="3.5.3" />
<option name="LAST_KNOWN_AGP_VERSION" value="3.5.3" />
</configuration>
</facet>
<facet type="android" name="Android">
Expand All @@ -19,7 +19,7 @@
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/build/generated/res/resValues/debug" />
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
Expand Down
55 changes: 55 additions & 0 deletions example/src/main/java/com/r0adkll/slidr/example/ColorAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.r0adkll.slidr.example;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;

import com.ftinc.kit.adapter.BetterRecyclerAdapter;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ColorAdapter extends BetterRecyclerAdapter<Integer, ColorAdapter.ColorViewHolder> {

public ColorAdapter() {
List<Integer> colorList = Arrays.asList(R.color.red_500, R.color.orange_500,
R.color.yellow_500, R.color.blue_500, R.color.green_500, R.color.purple_500,
R.color.amber_500, R.color.pink_500, R.color.brown_500, R.color.lime_500,
R.color.indigo_500, R.color.cyan_500);
addAll(colorList);
}

@NonNull
@Override
public ColorViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.color_item, parent, false);
return new ColorViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull ColorViewHolder viewHolder, int i) {
super.onBindViewHolder(viewHolder, i);
Integer color = getItem(i);
viewHolder.color.setBackgroundColor(ContextCompat.getColor(viewHolder.color.getContext(), color));
}

public static class ColorViewHolder extends RecyclerView.ViewHolder{
@BindView(R.id.color) public View color;

public ColorViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.r0adkll.slidr.example;

import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.ftinc.kit.adapter.BetterRecyclerAdapter;
import com.ftinc.kit.util.SizeUtils;
import com.ftinc.kit.util.Utils;
import com.ftinc.kit.widget.AspectRatioImageView;
Expand All @@ -34,6 +40,8 @@ public class ViewerActivity extends AppCompatActivity {
@BindView(R.id.version) TextView mVersion;
@BindView(R.id.sdk) TextView mSdk;
@BindView(R.id.position) TextView mPosition;
@BindView(R.id.recycler) RecyclerView recycler;
@BindView(R.id.recycler2) RecyclerView recycler2;

private AndroidOS mOS;
private SlidrConfig mConfig;
Expand All @@ -56,7 +64,7 @@ protected void onCreate(Bundle savedInstanceState) {
mConfig = new SlidrConfig.Builder()
.primaryColor(primary)
.secondaryColor(secondary)
.position(SlidrPosition.VERTICAL)
.position(SlidrPosition.HORIZONTAL)
.velocityThreshold(2400)
// .distanceThreshold(.25f)
// .edge(true)
Expand Down Expand Up @@ -84,11 +92,26 @@ protected void onCreate(Bundle savedInstanceState) {
.load(mOS.image_url)
.crossFade()
.into(mCover);

// Color recycler view
recycler.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
ColorAdapter colorAdapter = new ColorAdapter();
recycler.setAdapter(colorAdapter);
colorAdapter.setOnItemClickListener((view, colorNumber, i) -> {
onColorClicked(colorNumber);
});

// Color recycler view
recycler2.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
ColorAdapter colorAdapter2 = new ColorAdapter();
recycler2.setAdapter(colorAdapter2);
colorAdapter2.setOnItemClickListener((view, colorNumber, i) -> {
onColorClicked(colorNumber);
});
}

@OnClick({R.id.color1, R.id.color2, R.id.color3, R.id.color4, R.id.color5})
void onColorClicked(View v){
int color = ((ColorDrawable)v.getBackground()).getColor();
private void onColorClicked(Integer colorNumber) {
int color = ContextCompat.getColor(this, colorNumber);
getWindow().setStatusBarColor(color);
mConfig.setColorSecondary(color);
}
Expand Down
71 changes: 18 additions & 53 deletions example/src/main/res/layout/activity_viewer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,63 +155,28 @@
app:cardElevation="4dp"
>

<LinearLayout
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<View
android:id="@+id/color1"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_margin="8dp"

android:layout_weight="1"
android:background="@color/red_500"
/>

<View
android:id="@+id/color2"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_margin="8dp"

android:layout_weight="1"
android:background="@color/blue_500"
/>

<View
android:id="@+id/color3"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_margin="8dp"

android:layout_weight="1"
android:background="@color/pink_500"
/>

<View
android:id="@+id/color4"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_margin="8dp"

android:layout_weight="1"
android:background="@color/purple_500"
/>

<View
android:id="@+id/color5"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_margin="8dp"
android:layout_height="64dp"/>

android:layout_weight="1"
android:background="@color/orange_500"
/>
</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="8dp"
app:cardCornerRadius="2dp"
app:cardElevation="4dp"
>

</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler2"
android:layout_width="match_parent"
android:layout_height="64dp"/>

</androidx.cardview.widget.CardView>

Expand Down
17 changes: 17 additions & 0 deletions example/src/main/res/layout/color_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">

<View
android:id="@+id/color"
android:layout_width="64dp"
android:layout_height="0dp"
android:layout_margin="8dp"

android:layout_weight="1"
android:background="@color/blue_500"
/>

</LinearLayout>
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'maven'


android {
compileSdkVersion compileSdk

Expand Down
17 changes: 16 additions & 1 deletion library/src/main/java/com/r0adkll/slidr/model/SlidrConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ public class SlidrConfig {
private int colorPrimary = -1;
private int colorSecondary = -1;
private float touchSize = -1f;
private float sensitivity = 1f;
private float sensitivity = 0.5f;
private int scrimColor = Color.BLACK;
private float scrimStartAlpha = 0.8f;
private float scrimEndAlpha = 0f;
private float velocityThreshold = 5f;
private float distanceThreshold = 0.25f;
private boolean edgeOnly = false;
private float edgeSize = 0.18f;
private boolean ignoreChildScroll = false;

private SlidrPosition position = SlidrPosition.LEFT;
private SlidrListener listener;
Expand Down Expand Up @@ -179,6 +180,15 @@ public float getEdgeSize(float size) {
return edgeSize * size;
}

/**
* Has the user configured slidr to ignore all scrollable children inside
*
* @return true if is ignore all scrollable children under touch
*/
public boolean isIgnoreChildScroll() {
return ignoreChildScroll;
}


/***********************************************************************************************
*
Expand Down Expand Up @@ -304,6 +314,11 @@ public Builder edgeSize(@FloatRange(from = 0f, to = 1f) float edgeSize){
return this;
}

public Builder ignoreChildScroll(boolean ignoreChildScroll){
config.ignoreChildScroll = ignoreChildScroll;
return this;
}

public Builder listener(SlidrListener listener){
config.listener = listener;
return this;
Expand Down
Loading