diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e1b8666..c71955e 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -17,6 +17,27 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/common/commonlibtest/DemoActivity.java b/app/src/main/java/com/common/commonlibtest/DemoActivity.java index cabe3f1..a15085f 100644 --- a/app/src/main/java/com/common/commonlibtest/DemoActivity.java +++ b/app/src/main/java/com/common/commonlibtest/DemoActivity.java @@ -1,9 +1,10 @@ package com.common.commonlibtest; -import androidx.appcompat.app.AppCompatActivity; - +import android.content.Intent; import android.os.Bundle; +import androidx.appcompat.app.AppCompatActivity; + import com.common.commonlib.image.config.GlideHolderConfig; import com.common.commonlib.image.config.GlideTransitionConfig; import com.common.commonlib.image.loader.ImageLoader; @@ -20,6 +21,7 @@ import com.common.commonlibtest.bean.LoginResponse; import com.common.commonlibtest.manager.CollectionLoader; import com.common.commonlibtest.manager.InternetLoader; import com.common.commonlibtest.manager.LoginLoader; +import com.common.commonlibtest.viewpagerlayoutmanager.VariousRvDemoActivity; import com.yinuo.commonlibtest.R; import com.yinuo.commonlibtest.databinding.ActivityMainBinding; @@ -67,6 +69,10 @@ public class DemoActivity extends AppCompatActivity { }); }); + binding.rv.setOnClickListener(v -> { + startActivity(new Intent(DemoActivity.this, VariousRvDemoActivity.class)); + }); + binding.clearBtn.setOnClickListener(l -> ImageLoader.INSTANCE.clearAllCache(DemoActivity.this)); binding.btn.setOnClickListener(l -> { diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/BaseActivity.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/BaseActivity.java new file mode 100644 index 0000000..3e7de66 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/BaseActivity.java @@ -0,0 +1,102 @@ +package com.common.commonlibtest.viewpagerlayoutmanager; + +import android.os.Bundle; +import android.view.Gravity; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Toast; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.RecyclerView; +import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; + +import com.common.commonlib.view.viewpagerlayoutmanager.ScrollHelper; +import com.common.commonlib.view.viewpagerlayoutmanager.ViewPagerLayoutManager; +import com.yinuo.commonlibtest.R; + + +/** + * Created by Dajavu on 26/10/2017. + */ + +public abstract class BaseActivity + extends AppCompatActivity { + private RecyclerView recyclerView; + private V viewPagerLayoutManager; + private S settingPopUpWindow; + + protected abstract V createLayoutManager(); + + protected abstract S createSettingPopUpWindow(); + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_base); + setTitle(getIntent().getCharSequenceExtra(VariousRvDemoActivity.INTENT_TITLE)); + recyclerView = findViewById(R.id.recycler); + viewPagerLayoutManager = createLayoutManager(); + DataAdapter dataAdapter = new DataAdapter(); + dataAdapter.setOnItemClickListener(new DataAdapter.OnItemClickListener() { + @Override + public void onItemClick(View v, int pos) { + Toast.makeText(v.getContext(), "clicked:" + pos, Toast.LENGTH_SHORT).show(); + ScrollHelper.smoothScrollToTargetView(recyclerView, v); + } + }); + recyclerView.setAdapter(dataAdapter); + recyclerView.setLayoutManager(viewPagerLayoutManager); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.settings, menu); + MenuItem settings = menu.findItem(R.id.setting); + VectorDrawableCompat settingIcon = + VectorDrawableCompat.create(getResources(), R.drawable.ic_settings_white_48px, null); + settings.setIcon(settingIcon); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.setting: + showDialog(); + return true; + case android.R.id.home: + onBackPressed(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } + + private void showDialog() { + if (settingPopUpWindow == null) { + settingPopUpWindow = createSettingPopUpWindow(); + } + settingPopUpWindow.showAtLocation(recyclerView, Gravity.CENTER, 0, 0); + } + + public V getViewPagerLayoutManager() { + return viewPagerLayoutManager; + } + + public S getSettingPopUpWindow() { + return settingPopUpWindow; + } + + public RecyclerView getRecyclerView() { + return recyclerView; + } + + @Override + protected void onDestroy() { + super.onDestroy(); + if (settingPopUpWindow != null && settingPopUpWindow.isShowing()) + settingPopUpWindow.dismiss(); + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/DataAdapter.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/DataAdapter.java new file mode 100644 index 0000000..428be93 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/DataAdapter.java @@ -0,0 +1,58 @@ +package com.common.commonlibtest.viewpagerlayoutmanager; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + +import androidx.recyclerview.widget.RecyclerView; + +import com.yinuo.commonlibtest.R; + +public class DataAdapter extends RecyclerView.Adapter { + public OnItemClickListener onItemClickListener; + private int[] images = {R.drawable.item1, R.drawable.item2, R.drawable.item3, + R.drawable.item4, R.drawable.item5, R.drawable.item6, R.drawable.item7, + R.drawable.item8, R.drawable.item9}; + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_image, parent, false)); + } + + @Override + public void onBindViewHolder(ViewHolder holder, int position) { + holder.imageView.setImageResource(images[position]); + holder.imageView.setTag(position); + } + + @Override + public int getItemCount() { + return images.length; + } + + public void setOnItemClickListener(OnItemClickListener onItemClickListener) { + this.onItemClickListener = onItemClickListener; + } + + public interface OnItemClickListener { + void onItemClick(View v, int pos); + } + + class ViewHolder extends RecyclerView.ViewHolder { + ImageView imageView; + + ViewHolder(View itemView) { + super(itemView); + imageView = itemView.findViewById(R.id.image); + itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (onItemClickListener != null) { + onItemClickListener.onItemClick(v, getAdapterPosition()); + } + } + }); + } + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/SettingPopUpWindow.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/SettingPopUpWindow.java new file mode 100644 index 0000000..763777e --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/SettingPopUpWindow.java @@ -0,0 +1,18 @@ +package com.common.commonlibtest.viewpagerlayoutmanager; + +import android.content.Context; +import android.view.WindowManager; +import android.widget.PopupWindow; + +/** + * Created by Dajavu on 26/10/2017. + */ + +public abstract class SettingPopUpWindow extends PopupWindow { + public SettingPopUpWindow(Context context) { + super(context); + setOutsideTouchable(true); + setWidth(Util.Dp2px(context, 320)); + setHeight(WindowManager.LayoutParams.WRAP_CONTENT); + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/Util.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/Util.java new file mode 100644 index 0000000..0953d56 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/Util.java @@ -0,0 +1,20 @@ +package com.common.commonlibtest.viewpagerlayoutmanager; + +import android.content.Context; + +import java.util.Locale; + +/** + * Created by Dajavu on 25/10/2017. + */ + +public class Util { + public static int Dp2px(Context context, float dp) { + final float scale = context.getResources().getDisplayMetrics().density; + return (int) (dp * scale + 0.5f); + } + + public static String formatFloat(float value) { + return String.format(Locale.getDefault(), "%.3f", value); + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/VariousRvDemoActivity.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/VariousRvDemoActivity.java new file mode 100644 index 0000000..82b2404 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/VariousRvDemoActivity.java @@ -0,0 +1,66 @@ +package com.common.commonlibtest.viewpagerlayoutmanager; + +import android.content.Intent; +import android.os.Bundle; +import android.view.View; + +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.AppCompatButton; + +import com.common.commonlibtest.viewpagerlayoutmanager.carousel.CarouselLayoutActivity; +import com.common.commonlibtest.viewpagerlayoutmanager.circle.CircleLayoutActivity; +import com.common.commonlibtest.viewpagerlayoutmanager.circlescale.CircleScaleLayoutActivity; +import com.common.commonlibtest.viewpagerlayoutmanager.gallery.GalleryLayoutActivity; +import com.common.commonlibtest.viewpagerlayoutmanager.rotate.RotateLayoutActivity; +import com.common.commonlibtest.viewpagerlayoutmanager.scale.ScaleLayoutActivity; +import com.yinuo.commonlibtest.R; + + +public class VariousRvDemoActivity extends AppCompatActivity implements View.OnClickListener { + public final static String INTENT_TITLE = "title"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.variois_rv_layout); + findViewById(R.id.bt_circle).setOnClickListener(this); + findViewById(R.id.bt_circle_scale).setOnClickListener(this); + findViewById(R.id.bt_elevate_scale).setOnClickListener(this); + findViewById(R.id.bt_gallery).setOnClickListener(this); + findViewById(R.id.bt_rotate).setOnClickListener(this); + findViewById(R.id.bt_scale).setOnClickListener(this); + + } + + @Override + public void onClick(View v) { + switch (v.getId()) { + case R.id.bt_circle: + startActivity(CircleLayoutActivity.class, v); + break; + case R.id.bt_circle_scale: + startActivity(CircleScaleLayoutActivity.class, v); + break; + case R.id.bt_elevate_scale: + startActivity(CarouselLayoutActivity.class, v); + break; + case R.id.bt_gallery: + startActivity(GalleryLayoutActivity.class, v); + break; + case R.id.bt_rotate: + startActivity(RotateLayoutActivity.class, v); + break; + case R.id.bt_scale: + startActivity(ScaleLayoutActivity.class, v); + break; + } + } + + private void startActivity(Class clz, View view) { + Intent intent = new Intent(this, clz); + if (view instanceof AppCompatButton) { + intent.putExtra(INTENT_TITLE, ((AppCompatButton) view).getText()); + } + startActivity(intent); + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/carousel/CarouselLayoutActivity.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/carousel/CarouselLayoutActivity.java new file mode 100644 index 0000000..05acd5e --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/carousel/CarouselLayoutActivity.java @@ -0,0 +1,18 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.carousel; + +import com.common.commonlib.view.viewpagerlayoutmanager.CarouselLayoutManager; +import com.common.commonlibtest.viewpagerlayoutmanager.BaseActivity; +import com.common.commonlibtest.viewpagerlayoutmanager.Util; + +public class CarouselLayoutActivity extends BaseActivity { + + @Override + protected CarouselLayoutManager createLayoutManager() { + return new CarouselLayoutManager(this, Util.Dp2px(this, 100)); + } + + @Override + protected CarouselPopUpWindow createSettingPopUpWindow() { + return new CarouselPopUpWindow(this, getViewPagerLayoutManager(), getRecyclerView()); + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/carousel/CarouselPopUpWindow.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/carousel/CarouselPopUpWindow.java new file mode 100644 index 0000000..028ca6b --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/carousel/CarouselPopUpWindow.java @@ -0,0 +1,136 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.carousel; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.SeekBar; +import android.widget.TextView; + +import androidx.appcompat.widget.SwitchCompat; +import androidx.recyclerview.widget.RecyclerView; + +import com.common.commonlib.view.viewpagerlayoutmanager.CarouselLayoutManager; +import com.common.commonlib.view.viewpagerlayoutmanager.CenterSnapHelper; +import com.common.commonlibtest.viewpagerlayoutmanager.SettingPopUpWindow; +import com.common.commonlibtest.viewpagerlayoutmanager.Util; +import com.yinuo.commonlibtest.R; + +@SuppressLint("InflateParams") +@SuppressWarnings("FieldCanBeLocal") +public class CarouselPopUpWindow extends SettingPopUpWindow + implements SeekBar.OnSeekBarChangeListener, CompoundButton.OnCheckedChangeListener { + + private CarouselLayoutManager carouselLayoutManager; + private RecyclerView recyclerView; + private TextView itemSpaceValue; + private TextView speedValue; + private TextView minScaleValue; + private SwitchCompat changeOrientation; + private SwitchCompat autoCenter; + private SwitchCompat infinite; + private SwitchCompat reverse; + private CenterSnapHelper centerSnapHelper; + + CarouselPopUpWindow(Context context, CarouselLayoutManager carouselLayoutManager, RecyclerView recyclerView) { + super(context); + this.carouselLayoutManager = carouselLayoutManager; + this.recyclerView = recyclerView; + View view = LayoutInflater.from(context).inflate(R.layout.dialog_carousel_setting, null); + setContentView(view); + + centerSnapHelper = new CenterSnapHelper(); + + SeekBar itemSpace = view.findViewById(R.id.sb_item_space); + SeekBar speed = view.findViewById(R.id.sb_speed); + SeekBar minScale = view.findViewById(R.id.sb_min_scale); + + itemSpaceValue = view.findViewById(R.id.item_space); + speedValue = view.findViewById(R.id.speed_value); + minScaleValue = view.findViewById(R.id.min_scale_value); + + changeOrientation = view.findViewById(R.id.s_change_orientation); + autoCenter = view.findViewById(R.id.s_auto_center); + infinite = view.findViewById(R.id.s_infinite); + reverse = view.findViewById(R.id.s_reverse); + + itemSpace.setOnSeekBarChangeListener(this); + speed.setOnSeekBarChangeListener(this); + minScale.setOnSeekBarChangeListener(this); + + itemSpace.setProgress(carouselLayoutManager.getItemSpace() / 5); + speed.setProgress(Math.round(carouselLayoutManager.getMoveSpeed() / 0.05f)); + minScale.setProgress(Math.round(carouselLayoutManager.getMinScale() * 100)); + + itemSpaceValue.setText(String.valueOf(carouselLayoutManager.getItemSpace())); + speedValue.setText(Util.formatFloat(carouselLayoutManager.getMoveSpeed())); + minScaleValue.setText(Util.formatFloat(carouselLayoutManager.getMinScale())); + + changeOrientation.setChecked(carouselLayoutManager.getOrientation() == RecyclerView.VERTICAL); + reverse.setChecked(carouselLayoutManager.getReverseLayout()); + infinite.setChecked(carouselLayoutManager.getInfinite()); + + changeOrientation.setOnCheckedChangeListener(this); + autoCenter.setOnCheckedChangeListener(this); + reverse.setOnCheckedChangeListener(this); + infinite.setOnCheckedChangeListener(this); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + switch (seekBar.getId()) { + case R.id.sb_item_space: + int itemSpace = progress * 5; + carouselLayoutManager.setItemSpace(itemSpace); + itemSpaceValue.setText(String.valueOf(itemSpace)); + break; + case R.id.sb_min_scale: + final float scale = progress / 100f; + carouselLayoutManager.setMinScale(scale); + minScaleValue.setText(Util.formatFloat(scale)); + break; + case R.id.sb_speed: + final float speed = progress * 0.05f; + carouselLayoutManager.setMoveSpeed(speed); + speedValue.setText(Util.formatFloat(speed)); + break; + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + switch (buttonView.getId()) { + case R.id.s_infinite: + recyclerView.scrollToPosition(0); + carouselLayoutManager.setInfinite(isChecked); + break; + case R.id.s_change_orientation: + carouselLayoutManager.scrollToPosition(0); + carouselLayoutManager.setOrientation(isChecked ? + RecyclerView.VERTICAL : RecyclerView.HORIZONTAL); + break; + case R.id.s_auto_center: + if (isChecked) { + centerSnapHelper.attachToRecyclerView(recyclerView); + } else { + centerSnapHelper.attachToRecyclerView(null); + } + break; + case R.id.s_reverse: + carouselLayoutManager.scrollToPosition(0); + carouselLayoutManager.setReverseLayout(isChecked); + break; + } + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circle/CircleLayoutActivity.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circle/CircleLayoutActivity.java new file mode 100644 index 0000000..825a029 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circle/CircleLayoutActivity.java @@ -0,0 +1,22 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.circle; + + +import com.common.commonlib.view.viewpagerlayoutmanager.CircleLayoutManager; +import com.common.commonlibtest.viewpagerlayoutmanager.BaseActivity; + +/** + * Created by Dajavu on 25/10/2017. + */ + +public class CircleLayoutActivity extends BaseActivity { + + @Override + protected CircleLayoutManager createLayoutManager() { + return new CircleLayoutManager(this); + } + + @Override + protected CirclePopUpWindow createSettingPopUpWindow() { + return new CirclePopUpWindow(this, getViewPagerLayoutManager(), getRecyclerView()); + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circle/CirclePopUpWindow.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circle/CirclePopUpWindow.java new file mode 100644 index 0000000..e54e21a --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circle/CirclePopUpWindow.java @@ -0,0 +1,216 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.circle; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.RadioGroup; +import android.widget.SeekBar; +import android.widget.TextView; + +import androidx.appcompat.widget.SwitchCompat; +import androidx.recyclerview.widget.RecyclerView; + +import com.common.commonlib.view.viewpagerlayoutmanager.CenterSnapHelper; +import com.common.commonlib.view.viewpagerlayoutmanager.CircleLayoutManager; +import com.common.commonlibtest.viewpagerlayoutmanager.SettingPopUpWindow; +import com.common.commonlibtest.viewpagerlayoutmanager.Util; +import com.yinuo.commonlibtest.R; + + +/** + * Created by Dajavu on 25/10/2017. + */ + +@SuppressLint("InflateParams") +@SuppressWarnings("FieldCanBeLocal") +class CirclePopUpWindow extends SettingPopUpWindow + implements SeekBar.OnSeekBarChangeListener, CompoundButton.OnCheckedChangeListener, + RadioGroup.OnCheckedChangeListener { + + private CircleLayoutManager circleLayoutManager; + private RecyclerView recyclerView; + private TextView radiusValue; + private TextView intervalValue; + private TextView speedValue; + private TextView distanceToBottomValue; + private SwitchCompat infinite; + private SwitchCompat autoCenter; + private SwitchCompat reverse; + private SwitchCompat flipRotate; + private CenterSnapHelper centerSnapHelper; + private RadioGroup gravity; + private RadioGroup zAlignment; + + CirclePopUpWindow(Context context, CircleLayoutManager circleLayoutManager, RecyclerView recyclerView) { + super(context); + this.circleLayoutManager = circleLayoutManager; + this.recyclerView = recyclerView; + View view = LayoutInflater.from(context).inflate(R.layout.dialog_circle_setting, null); + setContentView(view); + + centerSnapHelper = new CenterSnapHelper(); + + SeekBar radius = view.findViewById(R.id.sb_radius); + SeekBar interval = view.findViewById(R.id.sb_interval); + SeekBar speed = view.findViewById(R.id.sb_speed); + SeekBar distanceToBottom = view.findViewById(R.id.sb_distance_to_bottom); + + radiusValue = view.findViewById(R.id.radius_value); + intervalValue = view.findViewById(R.id.interval_value); + speedValue = view.findViewById(R.id.speed_value); + distanceToBottomValue = view.findViewById(R.id.distance_to_bottom_value); + + infinite = view.findViewById(R.id.s_infinite); + autoCenter = view.findViewById(R.id.s_auto_center); + reverse = view.findViewById(R.id.s_reverse); + flipRotate = view.findViewById(R.id.s_flip); + + gravity = view.findViewById(R.id.rg_gravity); + zAlignment = view.findViewById(R.id.rg_z_alignment); + + radius.setOnSeekBarChangeListener(this); + interval.setOnSeekBarChangeListener(this); + speed.setOnSeekBarChangeListener(this); + distanceToBottom.setOnSeekBarChangeListener(this); + + final int maxRadius = Util.Dp2px(radius.getContext(), 400); + radius.setProgress(Math.round(circleLayoutManager.getRadius() * 1f / maxRadius * 100)); + interval.setProgress(Math.round(circleLayoutManager.getAngleInterval() / 0.9f)); + speed.setProgress(Math.round(circleLayoutManager.getMoveSpeed() / 0.005f)); + distanceToBottom.setProgress(circleLayoutManager.getDistanceToBottom() / 10); + + radiusValue.setText(String.valueOf(circleLayoutManager.getRadius())); + intervalValue.setText(String.valueOf(circleLayoutManager.getAngleInterval())); + speedValue.setText(Util.formatFloat(circleLayoutManager.getMoveSpeed())); + distanceToBottomValue.setText(String.valueOf(circleLayoutManager.getDistanceToBottom())); + + infinite.setChecked(circleLayoutManager.getInfinite()); + reverse.setChecked(circleLayoutManager.getReverseLayout()); + flipRotate.setChecked(circleLayoutManager.getFlipRotate()); + + infinite.setOnCheckedChangeListener(this); + autoCenter.setOnCheckedChangeListener(this); + reverse.setOnCheckedChangeListener(this); + flipRotate.setOnCheckedChangeListener(this); + + switch (circleLayoutManager.getGravity()) { + case CircleLayoutManager.LEFT: + gravity.check(R.id.rb_left); + break; + case CircleLayoutManager.RIGHT: + gravity.check(R.id.rb_right); + break; + case CircleLayoutManager.TOP: + gravity.check(R.id.rb_top); + break; + case CircleLayoutManager.BOTTOM: + gravity.check(R.id.rb_bottom); + break; + } + + switch (circleLayoutManager.getZAlignment()) { + case CircleLayoutManager.LEFT_ON_TOP: + zAlignment.check(R.id.rb_left_on_top); + break; + case CircleLayoutManager.RIGHT_ON_TOP: + zAlignment.check(R.id.rb_right_on_top); + break; + case CircleLayoutManager.CENTER_ON_TOP: + zAlignment.check(R.id.rb_center_on_top); + break; + } + + gravity.setOnCheckedChangeListener(this); + zAlignment.setOnCheckedChangeListener(this); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + switch (seekBar.getId()) { + case R.id.sb_radius: + final int maxRadius = Util.Dp2px(seekBar.getContext(), 400); + final int radius = Math.round(progress / 100f * maxRadius); + circleLayoutManager.setRadius(radius); + radiusValue.setText(String.valueOf(radius)); + break; + case R.id.sb_interval: + final int interval = Math.round(progress * 0.9f); + circleLayoutManager.setAngleInterval(interval); + intervalValue.setText(String.valueOf(interval)); + break; + case R.id.sb_speed: + final float speed = progress * 0.005f; + circleLayoutManager.setMoveSpeed(speed); + speedValue.setText(Util.formatFloat(speed)); + break; + case R.id.sb_distance_to_bottom: + final int distance = progress * 10; + circleLayoutManager.setDistanceToBottom(distance); + distanceToBottomValue.setText(String.valueOf(distance)); + break; + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + switch (buttonView.getId()) { + case R.id.s_infinite: + recyclerView.scrollToPosition(0); + circleLayoutManager.setInfinite(isChecked); + break; + case R.id.s_auto_center: + if (isChecked) { + centerSnapHelper.attachToRecyclerView(recyclerView); + } else { + centerSnapHelper.attachToRecyclerView(null); + } + break; + case R.id.s_reverse: + circleLayoutManager.scrollToPosition(0); + circleLayoutManager.setReverseLayout(isChecked); + break; + case R.id.s_flip: + circleLayoutManager.setFlipRotate(isChecked); + break; + } + } + + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + switch (checkedId) { + case R.id.rb_left: + circleLayoutManager.setGravity(CircleLayoutManager.LEFT); + break; + case R.id.rb_right: + circleLayoutManager.setGravity(CircleLayoutManager.RIGHT); + break; + case R.id.rb_top: + circleLayoutManager.setGravity(CircleLayoutManager.TOP); + break; + case R.id.rb_bottom: + circleLayoutManager.setGravity(CircleLayoutManager.BOTTOM); + break; + case R.id.rb_left_on_top: + circleLayoutManager.setZAlignment(CircleLayoutManager.LEFT_ON_TOP); + break; + case R.id.rb_right_on_top: + circleLayoutManager.setZAlignment(CircleLayoutManager.RIGHT_ON_TOP); + break; + case R.id.rb_center_on_top: + circleLayoutManager.setZAlignment(CircleLayoutManager.CENTER_ON_TOP); + break; + } + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circlescale/CircleScaleLayoutActivity.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circlescale/CircleScaleLayoutActivity.java new file mode 100644 index 0000000..c781ea8 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circlescale/CircleScaleLayoutActivity.java @@ -0,0 +1,17 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.circlescale; + +import com.common.commonlib.view.viewpagerlayoutmanager.CircleScaleLayoutManager; +import com.common.commonlibtest.viewpagerlayoutmanager.BaseActivity; + +public class CircleScaleLayoutActivity extends BaseActivity { + + @Override + protected CircleScaleLayoutManager createLayoutManager() { + return new CircleScaleLayoutManager(this); + } + + @Override + protected CircleScalePopUpWindow createSettingPopUpWindow() { + return new CircleScalePopUpWindow(this, getViewPagerLayoutManager(), getRecyclerView()); + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circlescale/CircleScalePopUpWindow.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circlescale/CircleScalePopUpWindow.java new file mode 100644 index 0000000..6260a9f --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/circlescale/CircleScalePopUpWindow.java @@ -0,0 +1,211 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.circlescale; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.RadioGroup; +import android.widget.SeekBar; +import android.widget.TextView; + +import androidx.appcompat.widget.SwitchCompat; +import androidx.recyclerview.widget.RecyclerView; + +import com.common.commonlib.view.viewpagerlayoutmanager.CenterSnapHelper; +import com.common.commonlib.view.viewpagerlayoutmanager.CircleScaleLayoutManager; +import com.common.commonlibtest.viewpagerlayoutmanager.SettingPopUpWindow; +import com.common.commonlibtest.viewpagerlayoutmanager.Util; +import com.yinuo.commonlibtest.R; + +@SuppressLint("InflateParams") +@SuppressWarnings("FieldCanBeLocal") +public class CircleScalePopUpWindow extends SettingPopUpWindow + implements SeekBar.OnSeekBarChangeListener, CompoundButton.OnCheckedChangeListener, + RadioGroup.OnCheckedChangeListener { + + private CircleScaleLayoutManager circleScaleLayoutManager; + private RecyclerView recyclerView; + private TextView radiusValue; + private TextView intervalValue; + private TextView speedValue; + private TextView centerScaleValue; + private SwitchCompat infinite; + private SwitchCompat autoCenter; + private SwitchCompat reverse; + private SwitchCompat flipRotate; + private CenterSnapHelper centerSnapHelper; + private RadioGroup gravity; + private RadioGroup zAlignment; + + CircleScalePopUpWindow(Context context, CircleScaleLayoutManager circleScaleLayoutManager, RecyclerView recyclerView) { + super(context); + this.circleScaleLayoutManager = circleScaleLayoutManager; + this.recyclerView = recyclerView; + View view = LayoutInflater.from(context).inflate(R.layout.dialog_circle_scale_setting, null); + setContentView(view); + + centerSnapHelper = new CenterSnapHelper(); + + SeekBar radius = view.findViewById(R.id.sb_radius); + SeekBar interval = view.findViewById(R.id.sb_interval); + SeekBar speed = view.findViewById(R.id.sb_speed); + SeekBar centerScale = view.findViewById(R.id.sb_center_scale); + + radiusValue = view.findViewById(R.id.radius_value); + intervalValue = view.findViewById(R.id.interval_value); + speedValue = view.findViewById(R.id.speed_value); + centerScaleValue = view.findViewById(R.id.center_scale_value); + + infinite = view.findViewById(R.id.s_infinite); + autoCenter = view.findViewById(R.id.s_auto_center); + reverse = view.findViewById(R.id.s_reverse); + flipRotate = view.findViewById(R.id.s_flip); + + gravity = view.findViewById(R.id.rg_gravity); + zAlignment = view.findViewById(R.id.rg_z_alignment); + + radius.setOnSeekBarChangeListener(this); + interval.setOnSeekBarChangeListener(this); + speed.setOnSeekBarChangeListener(this); + centerScale.setOnSeekBarChangeListener(this); + + final int maxRadius = Util.Dp2px(radius.getContext(), 400); + radius.setProgress(Math.round(circleScaleLayoutManager.getRadius() * 1f / maxRadius * 100)); + interval.setProgress(Math.round(circleScaleLayoutManager.getAngleInterval() / 0.9f)); + speed.setProgress(Math.round(circleScaleLayoutManager.getMoveSpeed() / 0.005f)); + centerScale.setProgress(Math.round(circleScaleLayoutManager.getCenterScale() * 200f / 3 - 100f / 3)); + + radiusValue.setText(String.valueOf(circleScaleLayoutManager.getRadius())); + intervalValue.setText(String.valueOf(circleScaleLayoutManager.getAngleInterval())); + speedValue.setText(Util.formatFloat(circleScaleLayoutManager.getMoveSpeed())); + centerScaleValue.setText(Util.formatFloat(circleScaleLayoutManager.getCenterScale())); + + infinite.setChecked(circleScaleLayoutManager.getInfinite()); + reverse.setChecked(circleScaleLayoutManager.getReverseLayout()); + flipRotate.setChecked(circleScaleLayoutManager.getFlipRotate()); + + infinite.setOnCheckedChangeListener(this); + autoCenter.setOnCheckedChangeListener(this); + reverse.setOnCheckedChangeListener(this); + flipRotate.setOnCheckedChangeListener(this); + + switch (circleScaleLayoutManager.getGravity()) { + case CircleScaleLayoutManager.LEFT: + gravity.check(R.id.rb_left); + break; + case CircleScaleLayoutManager.RIGHT: + gravity.check(R.id.rb_right); + break; + case CircleScaleLayoutManager.TOP: + gravity.check(R.id.rb_top); + break; + case CircleScaleLayoutManager.BOTTOM: + gravity.check(R.id.rb_bottom); + break; + } + + switch (circleScaleLayoutManager.getZAlignment()) { + case CircleScaleLayoutManager.LEFT_ON_TOP: + zAlignment.check(R.id.rb_left_on_top); + break; + case CircleScaleLayoutManager.RIGHT_ON_TOP: + zAlignment.check(R.id.rb_right_on_top); + break; + case CircleScaleLayoutManager.CENTER_ON_TOP: + zAlignment.check(R.id.rb_center_on_top); + break; + } + + gravity.setOnCheckedChangeListener(this); + zAlignment.setOnCheckedChangeListener(this); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + switch (seekBar.getId()) { + case R.id.sb_radius: + final int maxRadius = Util.Dp2px(seekBar.getContext(), 400); + final int radius = Math.round(progress / 100f * maxRadius); + circleScaleLayoutManager.setRadius(radius); + radiusValue.setText(String.valueOf(radius)); + break; + case R.id.sb_interval: + final int interval = Math.round(progress * 0.9f); + circleScaleLayoutManager.setAngleInterval(interval); + intervalValue.setText(String.valueOf(interval)); + break; + case R.id.sb_center_scale: + final float scale = (progress + 100f / 3) * 3 / 200; + circleScaleLayoutManager.setCenterScale(scale); + centerScaleValue.setText(Util.formatFloat(scale)); + break; + case R.id.sb_speed: + final float speed = progress * 0.005f; + circleScaleLayoutManager.setMoveSpeed(speed); + speedValue.setText(Util.formatFloat(speed)); + break; + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + switch (buttonView.getId()) { + case R.id.s_infinite: + recyclerView.scrollToPosition(0); + circleScaleLayoutManager.setInfinite(isChecked); + break; + case R.id.s_auto_center: + if (isChecked) { + centerSnapHelper.attachToRecyclerView(recyclerView); + } else { + centerSnapHelper.attachToRecyclerView(null); + } + break; + case R.id.s_reverse: + circleScaleLayoutManager.scrollToPosition(0); + circleScaleLayoutManager.setReverseLayout(isChecked); + break; + case R.id.s_flip: + circleScaleLayoutManager.setFlipRotate(isChecked); + break; + } + } + + @Override + public void onCheckedChanged(RadioGroup group, int checkedId) { + switch (checkedId) { + case R.id.rb_left: + circleScaleLayoutManager.setGravity(CircleScaleLayoutManager.LEFT); + break; + case R.id.rb_right: + circleScaleLayoutManager.setGravity(CircleScaleLayoutManager.RIGHT); + break; + case R.id.rb_top: + circleScaleLayoutManager.setGravity(CircleScaleLayoutManager.TOP); + break; + case R.id.rb_bottom: + circleScaleLayoutManager.setGravity(CircleScaleLayoutManager.BOTTOM); + break; + case R.id.rb_left_on_top: + circleScaleLayoutManager.setZAlignment(CircleScaleLayoutManager.LEFT_ON_TOP); + break; + case R.id.rb_right_on_top: + circleScaleLayoutManager.setZAlignment(CircleScaleLayoutManager.RIGHT_ON_TOP); + break; + case R.id.rb_center_on_top: + circleScaleLayoutManager.setZAlignment(CircleScaleLayoutManager.CENTER_ON_TOP); + break; + } + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/gallery/GalleryLayoutActivity.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/gallery/GalleryLayoutActivity.java new file mode 100644 index 0000000..ef39c79 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/gallery/GalleryLayoutActivity.java @@ -0,0 +1,19 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.gallery; + + +import com.common.commonlib.view.viewpagerlayoutmanager.GalleryLayoutManager; +import com.common.commonlibtest.viewpagerlayoutmanager.BaseActivity; +import com.common.commonlibtest.viewpagerlayoutmanager.Util; + +public class GalleryLayoutActivity extends BaseActivity { + + @Override + protected GalleryLayoutManager createLayoutManager() { + return new GalleryLayoutManager(this, Util.Dp2px(this, 10)); + } + + @Override + protected GalleryPopUpWindow createSettingPopUpWindow() { + return new GalleryPopUpWindow(this, getViewPagerLayoutManager(), getRecyclerView()); + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/gallery/GalleryPopUpWindow.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/gallery/GalleryPopUpWindow.java new file mode 100644 index 0000000..dc491c0 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/gallery/GalleryPopUpWindow.java @@ -0,0 +1,178 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.gallery; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.SeekBar; +import android.widget.TextView; + +import androidx.appcompat.widget.SwitchCompat; +import androidx.recyclerview.widget.RecyclerView; + +import com.common.commonlib.view.viewpagerlayoutmanager.CenterSnapHelper; +import com.common.commonlib.view.viewpagerlayoutmanager.GalleryLayoutManager; +import com.common.commonlibtest.viewpagerlayoutmanager.SettingPopUpWindow; +import com.common.commonlibtest.viewpagerlayoutmanager.Util; +import com.yinuo.commonlibtest.R; + +@SuppressLint("InflateParams") +@SuppressWarnings("FieldCanBeLocal") +public class GalleryPopUpWindow extends SettingPopUpWindow + implements SeekBar.OnSeekBarChangeListener, CompoundButton.OnCheckedChangeListener { + + private GalleryLayoutManager galleryLayoutManager; + private RecyclerView recyclerView; + private TextView itemSpaceValue; + private TextView speedValue; + private TextView minAlphaValue; + private TextView maxAlphaValue; + private TextView angleValue; + private SwitchCompat centerInFront; + private SwitchCompat changeOrientation; + private SwitchCompat autoCenter; + private SwitchCompat infinite; + private SwitchCompat reverse; + private SwitchCompat flipRotate; + private SwitchCompat rotateFromEdge; + private CenterSnapHelper centerSnapHelper; + + GalleryPopUpWindow(Context context, GalleryLayoutManager galleryLayoutManager, RecyclerView recyclerView) { + super(context); + this.galleryLayoutManager = galleryLayoutManager; + this.recyclerView = recyclerView; + View view = LayoutInflater.from(context).inflate(R.layout.dialog_gallery_setting, null); + setContentView(view); + + centerSnapHelper = new CenterSnapHelper(); + + SeekBar itemSpace = view.findViewById(R.id.sb_item_space); + SeekBar speed = view.findViewById(R.id.sb_speed); + SeekBar minAlpha = view.findViewById(R.id.sb_min_alpha); + SeekBar maxAlpha = view.findViewById(R.id.sb_max_alpha); + SeekBar angle = view.findViewById(R.id.sb_interval); + + itemSpaceValue = view.findViewById(R.id.item_space); + speedValue = view.findViewById(R.id.speed_value); + minAlphaValue = view.findViewById(R.id.min_alpha_value); + maxAlphaValue = view.findViewById(R.id.max_alpha_value); + angleValue = view.findViewById(R.id.angle_value); + + centerInFront = view.findViewById(R.id.s_center_in_front); + changeOrientation = view.findViewById(R.id.s_change_orientation); + autoCenter = view.findViewById(R.id.s_auto_center); + infinite = view.findViewById(R.id.s_infinite); + reverse = view.findViewById(R.id.s_reverse); + flipRotate = view.findViewById(R.id.s_flip); + rotateFromEdge = view.findViewById(R.id.s_rotate_from_edge); + + itemSpace.setOnSeekBarChangeListener(this); + speed.setOnSeekBarChangeListener(this); + minAlpha.setOnSeekBarChangeListener(this); + maxAlpha.setOnSeekBarChangeListener(this); + angle.setOnSeekBarChangeListener(this); + + itemSpace.setProgress(galleryLayoutManager.getItemSpace() / 8 + 50); + speed.setProgress(Math.round(galleryLayoutManager.getMoveSpeed() / 0.05f)); + maxAlpha.setProgress(Math.round(galleryLayoutManager.getMaxAlpha() * 100)); + minAlpha.setProgress(Math.round(galleryLayoutManager.getMinAlpha() * 100)); + angle.setProgress(Math.round(galleryLayoutManager.getAngle() / 0.9f)); + + itemSpaceValue.setText(String.valueOf(galleryLayoutManager.getItemSpace())); + speedValue.setText(Util.formatFloat(galleryLayoutManager.getMoveSpeed())); + minAlphaValue.setText(Util.formatFloat(galleryLayoutManager.getMinAlpha())); + maxAlphaValue.setText(Util.formatFloat(galleryLayoutManager.getMaxAlpha())); + angleValue.setText(Util.formatFloat(galleryLayoutManager.getAngle())); + + centerInFront.setChecked(galleryLayoutManager.getEnableBringCenterToFront()); + changeOrientation.setChecked(galleryLayoutManager.getOrientation() == RecyclerView.VERTICAL); + reverse.setChecked(galleryLayoutManager.getReverseLayout()); + flipRotate.setChecked(galleryLayoutManager.getFlipRotate()); + rotateFromEdge.setChecked(galleryLayoutManager.getRotateFromEdge()); + infinite.setChecked(galleryLayoutManager.getInfinite()); + + centerInFront.setOnCheckedChangeListener(this); + changeOrientation.setOnCheckedChangeListener(this); + autoCenter.setOnCheckedChangeListener(this); + reverse.setOnCheckedChangeListener(this); + flipRotate.setOnCheckedChangeListener(this); + rotateFromEdge.setOnCheckedChangeListener(this); + infinite.setOnCheckedChangeListener(this); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + switch (seekBar.getId()) { + case R.id.sb_item_space: + int itemSpace = (progress - 50) * 8; + galleryLayoutManager.setItemSpace(itemSpace); + itemSpaceValue.setText(String.valueOf(itemSpace)); + break; + case R.id.sb_speed: + final float speed = progress * 0.05f; + galleryLayoutManager.setMoveSpeed(speed); + speedValue.setText(Util.formatFloat(speed)); + break; + case R.id.sb_interval: + final int angle = Math.round(progress * 0.9f); + galleryLayoutManager.setAngle(angle); + angleValue.setText(String.valueOf(angle)); + break; + case R.id.sb_max_alpha: + final float maxAlpha = progress / 100f; + galleryLayoutManager.setMaxAlpha(maxAlpha); + maxAlphaValue.setText(Util.formatFloat(maxAlpha)); + break; + case R.id.sb_min_alpha: + final float minAlpha = progress / 100f; + galleryLayoutManager.setMinAlpha(minAlpha); + minAlphaValue.setText(Util.formatFloat(minAlpha)); + break; + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + switch (buttonView.getId()) { + case R.id.s_infinite: + recyclerView.scrollToPosition(0); + galleryLayoutManager.setInfinite(isChecked); + break; + case R.id.s_change_orientation: + galleryLayoutManager.scrollToPosition(0); + galleryLayoutManager.setOrientation(isChecked ? + RecyclerView.VERTICAL : RecyclerView.HORIZONTAL); + break; + case R.id.s_auto_center: + if (isChecked) { + centerSnapHelper.attachToRecyclerView(recyclerView); + } else { + centerSnapHelper.attachToRecyclerView(null); + } + break; + case R.id.s_reverse: + galleryLayoutManager.scrollToPosition(0); + galleryLayoutManager.setReverseLayout(isChecked); + break; + case R.id.s_flip: + galleryLayoutManager.setFlipRotate(isChecked); + case R.id.s_center_in_front: + galleryLayoutManager.setEnableBringCenterToFront(isChecked); + break; + case R.id.s_rotate_from_edge: + galleryLayoutManager.setRotateFromEdge(isChecked); + break; + } + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/rotate/RotateLayoutActivity.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/rotate/RotateLayoutActivity.java new file mode 100644 index 0000000..8e7ee02 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/rotate/RotateLayoutActivity.java @@ -0,0 +1,19 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.rotate; + + +import com.common.commonlib.view.viewpagerlayoutmanager.RotateLayoutManager; +import com.common.commonlibtest.viewpagerlayoutmanager.BaseActivity; +import com.common.commonlibtest.viewpagerlayoutmanager.Util; + +public class RotateLayoutActivity extends BaseActivity { + + @Override + protected RotateLayoutManager createLayoutManager() { + return new RotateLayoutManager(this, Util.Dp2px(this, 10)); + } + + @Override + protected RotatePopUpWindow createSettingPopUpWindow() { + return new RotatePopUpWindow(this, getViewPagerLayoutManager(), getRecyclerView()); + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/rotate/RotatePopUpWindow.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/rotate/RotatePopUpWindow.java new file mode 100644 index 0000000..7857e87 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/rotate/RotatePopUpWindow.java @@ -0,0 +1,143 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.rotate; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.SeekBar; +import android.widget.TextView; + +import androidx.appcompat.widget.SwitchCompat; +import androidx.recyclerview.widget.RecyclerView; + +import com.common.commonlib.view.viewpagerlayoutmanager.CenterSnapHelper; +import com.common.commonlib.view.viewpagerlayoutmanager.RotateLayoutManager; +import com.common.commonlibtest.viewpagerlayoutmanager.SettingPopUpWindow; +import com.common.commonlibtest.viewpagerlayoutmanager.Util; +import com.yinuo.commonlibtest.R; + +@SuppressLint("InflateParams") +@SuppressWarnings("FieldCanBeLocal") +public class RotatePopUpWindow extends SettingPopUpWindow + implements SeekBar.OnSeekBarChangeListener, CompoundButton.OnCheckedChangeListener { + + private RotateLayoutManager rotateLayoutManager; + private RecyclerView recyclerView; + private TextView itemSpaceValue; + private TextView speedValue; + private TextView angleValue; + private SwitchCompat changeOrientation; + private SwitchCompat autoCenter; + private SwitchCompat infinite; + private SwitchCompat reverseRotate; + private SwitchCompat reverse; + private CenterSnapHelper centerSnapHelper; + + RotatePopUpWindow(Context context, RotateLayoutManager rotateLayoutManager, RecyclerView recyclerView) { + super(context); + this.rotateLayoutManager = rotateLayoutManager; + this.recyclerView = recyclerView; + View view = LayoutInflater.from(context).inflate(R.layout.dialog_rotate_setting, null); + setContentView(view); + + centerSnapHelper = new CenterSnapHelper(); + + SeekBar itemSpace = view.findViewById(R.id.sb_item_space); + SeekBar speed = view.findViewById(R.id.sb_speed); + SeekBar angle = view.findViewById(R.id.sb_angle); + + itemSpaceValue = view.findViewById(R.id.item_space); + speedValue = view.findViewById(R.id.speed_value); + angleValue = view.findViewById(R.id.angle_value); + + reverseRotate = view.findViewById(R.id.s_reverse_rotate); + changeOrientation = view.findViewById(R.id.s_change_orientation); + autoCenter = view.findViewById(R.id.s_auto_center); + infinite = view.findViewById(R.id.s_infinite); + reverse = view.findViewById(R.id.s_reverse); + + itemSpace.setOnSeekBarChangeListener(this); + speed.setOnSeekBarChangeListener(this); + angle.setOnSeekBarChangeListener(this); + + itemSpace.setProgress(rotateLayoutManager.getItemSpace() / 2); + speed.setProgress(Math.round(rotateLayoutManager.getMoveSpeed() / 0.05f)); + angle.setProgress(Math.round(rotateLayoutManager.getAngle() / 360 * 100)); + + itemSpaceValue.setText(String.valueOf(rotateLayoutManager.getItemSpace())); + speedValue.setText(Util.formatFloat(rotateLayoutManager.getMoveSpeed())); + angleValue.setText(Util.formatFloat(rotateLayoutManager.getAngle())); + + reverseRotate.setChecked(rotateLayoutManager.getEnableBringCenterToFront()); + changeOrientation.setChecked(rotateLayoutManager.getOrientation() == RecyclerView.VERTICAL); + reverse.setChecked(rotateLayoutManager.getReverseLayout()); + infinite.setChecked(rotateLayoutManager.getInfinite()); + + reverseRotate.setOnCheckedChangeListener(this); + changeOrientation.setOnCheckedChangeListener(this); + autoCenter.setOnCheckedChangeListener(this); + reverse.setOnCheckedChangeListener(this); + infinite.setOnCheckedChangeListener(this); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + switch (seekBar.getId()) { + case R.id.sb_item_space: + int itemSpace = progress * 2; + rotateLayoutManager.setItemSpace(itemSpace); + itemSpaceValue.setText(String.valueOf(itemSpace)); + break; + case R.id.sb_angle: + final float angle = progress / 100f * 360; + rotateLayoutManager.setAngle(angle); + angleValue.setText(Util.formatFloat(angle)); + break; + case R.id.sb_speed: + final float speed = progress * 0.05f; + rotateLayoutManager.setMoveSpeed(speed); + speedValue.setText(Util.formatFloat(speed)); + break; + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + switch (buttonView.getId()) { + case R.id.s_infinite: + recyclerView.scrollToPosition(0); + rotateLayoutManager.setInfinite(isChecked); + break; + case R.id.s_change_orientation: + rotateLayoutManager.scrollToPosition(0); + rotateLayoutManager.setOrientation(isChecked ? + RecyclerView.VERTICAL : RecyclerView.HORIZONTAL); + break; + case R.id.s_auto_center: + if (isChecked) { + centerSnapHelper.attachToRecyclerView(recyclerView); + } else { + centerSnapHelper.attachToRecyclerView(null); + } + break; + case R.id.s_reverse_rotate: + rotateLayoutManager.setReverseRotate(isChecked); + break; + case R.id.s_reverse: + rotateLayoutManager.scrollToPosition(0); + rotateLayoutManager.setReverseLayout(isChecked); + break; + } + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/scale/ScaleLayoutActivity.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/scale/ScaleLayoutActivity.java new file mode 100644 index 0000000..c21dae6 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/scale/ScaleLayoutActivity.java @@ -0,0 +1,19 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.scale; + + +import com.common.commonlib.view.viewpagerlayoutmanager.ScaleLayoutManager; +import com.common.commonlibtest.viewpagerlayoutmanager.BaseActivity; +import com.common.commonlibtest.viewpagerlayoutmanager.Util; + +public class ScaleLayoutActivity extends BaseActivity { + + @Override + protected ScaleLayoutManager createLayoutManager() { + return new ScaleLayoutManager(this, Util.Dp2px(this, 10)); + } + + @Override + protected ScalePopUpWindow createSettingPopUpWindow() { + return new ScalePopUpWindow(this, getViewPagerLayoutManager(), getRecyclerView()); + } +} diff --git a/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/scale/ScalePopUpWindow.java b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/scale/ScalePopUpWindow.java new file mode 100644 index 0000000..d531e76 --- /dev/null +++ b/app/src/main/java/com/common/commonlibtest/viewpagerlayoutmanager/scale/ScalePopUpWindow.java @@ -0,0 +1,158 @@ +package com.common.commonlibtest.viewpagerlayoutmanager.scale; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.CompoundButton; +import android.widget.SeekBar; +import android.widget.TextView; + +import androidx.appcompat.widget.SwitchCompat; +import androidx.recyclerview.widget.RecyclerView; + +import com.common.commonlib.view.viewpagerlayoutmanager.CenterSnapHelper; +import com.common.commonlib.view.viewpagerlayoutmanager.ScaleLayoutManager; +import com.common.commonlibtest.viewpagerlayoutmanager.SettingPopUpWindow; +import com.common.commonlibtest.viewpagerlayoutmanager.Util; +import com.yinuo.commonlibtest.R; + +@SuppressLint("InflateParams") +@SuppressWarnings("FieldCanBeLocal") +public class ScalePopUpWindow extends SettingPopUpWindow + implements SeekBar.OnSeekBarChangeListener, CompoundButton.OnCheckedChangeListener { + + private ScaleLayoutManager scaleLayoutManager; + private RecyclerView recyclerView; + private TextView itemSpaceValue; + private TextView speedValue; + private TextView minScaleValue; + private TextView minAlphaValue; + private TextView maxAlphaValue; + private SwitchCompat changeOrientation; + private SwitchCompat autoCenter; + private SwitchCompat infinite; + private SwitchCompat reverse; + private CenterSnapHelper centerSnapHelper; + + ScalePopUpWindow(Context context, ScaleLayoutManager scaleLayoutManager, RecyclerView recyclerView) { + super(context); + this.scaleLayoutManager = scaleLayoutManager; + this.recyclerView = recyclerView; + View view = LayoutInflater.from(context).inflate(R.layout.dialog_scale_setting, null); + setContentView(view); + + centerSnapHelper = new CenterSnapHelper(); + + SeekBar itemSpace = view.findViewById(R.id.sb_item_space); + SeekBar speed = view.findViewById(R.id.sb_speed); + SeekBar minScale = view.findViewById(R.id.sb_min_scale); + SeekBar minAlpha = view.findViewById(R.id.sb_min_alpha); + SeekBar maxAlpha = view.findViewById(R.id.sb_max_alpha); + + itemSpaceValue = view.findViewById(R.id.item_space); + speedValue = view.findViewById(R.id.speed_value); + minScaleValue = view.findViewById(R.id.min_scale_value); + minAlphaValue = view.findViewById(R.id.min_alpha_value); + maxAlphaValue = view.findViewById(R.id.max_alpha_value); + + changeOrientation = view.findViewById(R.id.s_change_orientation); + autoCenter = view.findViewById(R.id.s_auto_center); + infinite = view.findViewById(R.id.s_infinite); + reverse = view.findViewById(R.id.s_reverse); + + itemSpace.setOnSeekBarChangeListener(this); + speed.setOnSeekBarChangeListener(this); + minScale.setOnSeekBarChangeListener(this); + minAlpha.setOnSeekBarChangeListener(this); + maxAlpha.setOnSeekBarChangeListener(this); + + itemSpace.setProgress(scaleLayoutManager.getItemSpace() / 2); + speed.setProgress(Math.round(scaleLayoutManager.getMoveSpeed() / 0.05f)); + minScale.setProgress(Math.round((scaleLayoutManager.getMinScale() - 0.5f) * 200)); + maxAlpha.setProgress(Math.round(scaleLayoutManager.getMaxAlpha() * 100)); + minAlpha.setProgress(Math.round(scaleLayoutManager.getMinAlpha() * 100)); + + itemSpaceValue.setText(String.valueOf(scaleLayoutManager.getItemSpace())); + speedValue.setText(Util.formatFloat(scaleLayoutManager.getMoveSpeed())); + minScaleValue.setText(Util.formatFloat(scaleLayoutManager.getMinScale())); + minAlphaValue.setText(Util.formatFloat(scaleLayoutManager.getMinAlpha())); + maxAlphaValue.setText(Util.formatFloat(scaleLayoutManager.getMaxAlpha())); + + changeOrientation.setChecked(scaleLayoutManager.getOrientation() == RecyclerView.VERTICAL); + reverse.setChecked(scaleLayoutManager.getReverseLayout()); + infinite.setChecked(scaleLayoutManager.getInfinite()); + + changeOrientation.setOnCheckedChangeListener(this); + autoCenter.setOnCheckedChangeListener(this); + reverse.setOnCheckedChangeListener(this); + infinite.setOnCheckedChangeListener(this); + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + switch (seekBar.getId()) { + case R.id.sb_item_space: + int itemSpace = progress * 2; + scaleLayoutManager.setItemSpace(itemSpace); + itemSpaceValue.setText(String.valueOf(itemSpace)); + break; + case R.id.sb_min_scale: + final float scale = 0.5f + (progress / 200f); + scaleLayoutManager.setMinScale(scale); + minScaleValue.setText(Util.formatFloat(scale)); + break; + case R.id.sb_speed: + final float speed = progress * 0.05f; + scaleLayoutManager.setMoveSpeed(speed); + speedValue.setText(Util.formatFloat(speed)); + break; + case R.id.sb_max_alpha: + final float maxAlpha = progress / 100f; + scaleLayoutManager.setMaxAlpha(maxAlpha); + maxAlphaValue.setText(Util.formatFloat(maxAlpha)); + break; + case R.id.sb_min_alpha: + final float minAlpha = progress / 100f; + scaleLayoutManager.setMinAlpha(minAlpha); + minAlphaValue.setText(Util.formatFloat(minAlpha)); + break; + } + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + + } + + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + switch (buttonView.getId()) { + case R.id.s_infinite: + recyclerView.scrollToPosition(0); + scaleLayoutManager.setInfinite(isChecked); + break; + case R.id.s_change_orientation: + scaleLayoutManager.scrollToPosition(0); + scaleLayoutManager.setOrientation(isChecked ? + RecyclerView.VERTICAL : RecyclerView.HORIZONTAL); + break; + case R.id.s_auto_center: + if (isChecked) { + centerSnapHelper.attachToRecyclerView(recyclerView); + } else { + centerSnapHelper.attachToRecyclerView(null); + } + break; + case R.id.s_reverse: + scaleLayoutManager.scrollToPosition(0); + scaleLayoutManager.setReverseLayout(isChecked); + break; + } + } +} diff --git a/app/src/main/res/drawable-xhdpi/item1.jpg b/app/src/main/res/drawable-xhdpi/item1.jpg new file mode 100644 index 0000000..4d1d9c4 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/item1.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/item10.jpg b/app/src/main/res/drawable-xhdpi/item10.jpg new file mode 100644 index 0000000..68d59c7 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/item10.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/item2.jpg b/app/src/main/res/drawable-xhdpi/item2.jpg new file mode 100644 index 0000000..e86cc00 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/item2.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/item3.jpg b/app/src/main/res/drawable-xhdpi/item3.jpg new file mode 100644 index 0000000..e08b174 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/item3.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/item4.jpg b/app/src/main/res/drawable-xhdpi/item4.jpg new file mode 100644 index 0000000..d56a134 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/item4.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/item5.jpg b/app/src/main/res/drawable-xhdpi/item5.jpg new file mode 100644 index 0000000..dde30e4 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/item5.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/item6.jpg b/app/src/main/res/drawable-xhdpi/item6.jpg new file mode 100644 index 0000000..5ebf3a4 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/item6.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/item7.jpg b/app/src/main/res/drawable-xhdpi/item7.jpg new file mode 100644 index 0000000..c91de6b Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/item7.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/item8.jpg b/app/src/main/res/drawable-xhdpi/item8.jpg new file mode 100644 index 0000000..30ae7e5 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/item8.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/item9.jpg b/app/src/main/res/drawable-xhdpi/item9.jpg new file mode 100644 index 0000000..2e8e4e7 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/item9.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/logo.png b/app/src/main/res/drawable-xhdpi/logo.png new file mode 100644 index 0000000..3d84782 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/logo.png differ diff --git a/app/src/main/res/drawable/ic_settings_white_48px.xml b/app/src/main/res/drawable/ic_settings_white_48px.xml new file mode 100644 index 0000000..b1e3501 --- /dev/null +++ b/app/src/main/res/drawable/ic_settings_white_48px.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_base.xml b/app/src/main/res/layout/activity_base.xml new file mode 100644 index 0000000..0f519fe --- /dev/null +++ b/app/src/main/res/layout/activity_base.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 997822d..69229b1 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,21 +1,20 @@ + app:layout_constraintTop_toTopOf="parent" + app:show_style="left_middle_right" + app:title="111" /> +