Skip to content

Commit

Permalink
自定义具有弹簧效果的控件
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchong211 committed Mar 13, 2019
1 parent 756f0aa commit 4475bff
Show file tree
Hide file tree
Showing 28 changed files with 592 additions and 163 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,38 +1,35 @@
package com.ns.yc.lifehelper.ui.data.contract;


import com.ns.yc.lifehelper.model.bean.ImageIconBean;
import com.ycbjie.library.base.mvp.BasePresenter;
import com.ycbjie.library.base.mvp.BaseView;
import com.ns.yc.lifehelper.model.bean.ImageIconBean;
import com.ns.yc.lifehelper.ui.main.view.MainActivity;

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


/**
* ================================================
* 者:杨充
* 本:1.0
* 创建日期:2017/3/18
* 述:工具页面
* 修订历史:
* v1.5 17年10月3日修改
* ================================================
* <pre>
* @author yangchong
* blog : https://github.com/yangchong211
* time : 2016/03/22
* desc :
* revise: v1.4 17年6月8日
* v1.5 17年10月3日修改
* </pre>
*/
public interface DataFragmentContract {

//View(activity/fragment)继承,需要实现的方法
interface View extends BaseView {
void setGridView(String[] toolName, ArrayList<Integer> logoList);
void setRecycleView(ArrayList<Integer> list);
}

//Presenter控制器
interface Presenter extends BasePresenter {
List<ImageIconBean> getVpData();
void initGridViewData();
void initRecycleViewData();
void bindActivity(MainActivity activity);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import android.content.res.TypedArray;

import com.blankj.utilcode.util.Utils;
import com.ns.yc.lifehelper.R;
import com.ns.yc.lifehelper.model.bean.ImageIconBean;
import com.ns.yc.lifehelper.ui.data.contract.DataFragmentContract;
import com.ns.yc.lifehelper.ui.main.view.MainActivity;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -27,7 +27,6 @@ public class DataFragmentPresenter implements DataFragmentContract.Presenter {

private DataFragmentContract.View mView;
private CompositeSubscription mSubscriptions;
private MainActivity activity;


public DataFragmentPresenter(DataFragmentContract.View androidView) {
Expand All @@ -46,22 +45,15 @@ public void unSubscribe() {
if(mSubscriptions.isUnsubscribed()){
mSubscriptions.unsubscribe();
}
if(activity!=null){
activity = null;
}
}

@Override
public void bindActivity(MainActivity activity) {
this.activity = activity;
}


@Override
public List<ImageIconBean> getVpData() {
List<ImageIconBean> listData = new ArrayList<>();
TypedArray proPic = activity.getResources().obtainTypedArray(R.array.data_pro_pic);
String[] proName = activity.getResources().getStringArray(R.array.data_pro_title);
TypedArray proPic = Utils.getApp().getResources().obtainTypedArray(R.array.data_pro_pic);
String[] proName = Utils.getApp().getResources().getStringArray(R.array.data_pro_title);
for (int i = 0; i < proName.length; i++) {
int proPicId = proPic.getResourceId(i, R.drawable.ic_investment);
listData.add(new ImageIconBean(proName[i], proPicId,i));
Expand All @@ -73,8 +65,8 @@ public List<ImageIconBean> getVpData() {

@Override
public void initGridViewData() {
TypedArray toolLogo = activity.getResources().obtainTypedArray(R.array.data_tool_pro_pic);
String[] toolName = activity.getResources().getStringArray(R.array.data_tool_pro_title);
TypedArray toolLogo = Utils.getApp().getResources().obtainTypedArray(R.array.data_tool_pro_pic);
String[] toolName = Utils.getApp().getResources().getStringArray(R.array.data_tool_pro_title);
ArrayList<Integer> logoList = new ArrayList<>();
for(int a=0 ; a<toolName.length ; a++){
logoList.add(toolLogo.getResourceId(a,R.drawable.ic_investment));
Expand All @@ -87,7 +79,7 @@ public void initGridViewData() {
@SuppressWarnings("AlibabaUndefineMagicConstant")
@Override
public void initRecycleViewData() {
TypedArray typedArray = activity.getResources().obtainTypedArray(R.array.data_narrow_Image);
TypedArray typedArray = Utils.getApp().getResources().obtainTypedArray(R.array.data_narrow_Image);
final ArrayList<Integer> list = new ArrayList<>();
int b = 8;
for(int a=0 ; a<b ; a++){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public class DataFragment extends BaseFragment<DataFragmentPresenter> implements
public void onAttach(Context context) {
super.onAttach(context);
activity = (MainActivity) context;
presenter.bindActivity(activity);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@


/**
* ================================================
* 作 者:杨充
* 版 本:1.0
* 创建日期:2017/11/21
* 描 述:数据页面
* 修订历史:
* ================================================
* <pre>
* @author yangchong
* blog : https://github.com/yangchong211
* time : 2017/11/21
* desc : 数据页面,使用阿里巴巴Vlayout框架
* revise: v1.4 17年6月8日
* v1.5 17年10月3日修改
* </pre>
*/
public interface FindFragmentContract {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.ycbjie.library.base.mvp.BaseActivity;
import com.ycbjie.library.constant.Constant;
import com.ycbjie.library.utils.image.ImageUtils;
import com.ycbjie.library.weight.CustomScrollView;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class DouBookDetailActivity extends BaseActivity {
private Constant.CollapsingToolbarLayoutState state;
private String id;
private String alt;

private CustomScrollView scrollView;

@Override
protected void onDestroy() {
Expand Down Expand Up @@ -91,6 +92,7 @@ private void initFindViewById() {
toolbar = findViewById(R.id.toolbar);
tvName = findViewById(R.id.tv_name);
tvCasts = findViewById(R.id.tv_casts);
scrollView = findViewById(R.id.scrollView);
}

@SuppressLint("SetTextI18n")
Expand Down Expand Up @@ -139,6 +141,21 @@ public void initListener() {
toolbar.setBackgroundColor(getResources().getColor(R.color.colorTransparent));
}
});
scrollView.setListener(new CustomScrollView.ScrollListener() {
@Override
public int onScrollListener() {
switch (state){
case INTERNEDIATE:
return CustomScrollView.STATES.INTERMEDIATE;
case COLLAPSED:
return CustomScrollView.STATES.COLLAPSED;
case EXPANDED:
return CustomScrollView.STATES.EXPANDED;
default:
return CustomScrollView.STATES.INTERMEDIATE;
}
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.ycbjie.library.base.mvp.BaseActivity;
import com.ycbjie.douban.view.adapter.MovieTopAdapter;
import com.ycbjie.douban.bean.DouHotMovieBean;
import com.ycbjie.library.weight.manager.FullyGridLayoutManager;
import com.ycbjie.library.weight.FullyGridLayoutManager;

import org.yczbj.ycrefreshviewlib.YCRefreshView;
import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.ycbjie.douban.view.activity.DouBookDetailActivity;
import com.ycbjie.douban.view.adapter.DouBookAdapter;
import com.ycbjie.library.base.mvp.BaseLazyFragment;
import com.ycbjie.library.weight.manager.FullyGridLayoutManager;
import com.ycbjie.library.weight.FullyGridLayoutManager;

import org.yczbj.ycrefreshviewlib.YCRefreshView;
import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
Expand Down
13 changes: 11 additions & 2 deletions douban/src/main/res/layout/activity_book_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<include layout="@layout/activity_book_detail_content"/>

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="270dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
Expand All @@ -23,6 +22,14 @@
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<!--app:contentScrim设置折叠时工具栏布局的颜色-->
<!--app:statusBarScrim设置折叠时状态栏的颜色-->

<!--app:layout_collapseMode折叠模式-->
<!--off:这个是默认属性,布局将正常显示,没有折叠的行为。-->
<!--pin:CollapsingToolbarLayout折叠后,此布局将固定在顶部。-->
<!--parallax:CollapsingToolbarLayout折叠时,此布局也会有视差折叠效果。-->
<!--app:layout_collapseParallaxMultiplier设置视差滚动因子,值为:0~1-->

<!--封面图片-->
<ImageView
Expand Down Expand Up @@ -83,4 +90,6 @@
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<include layout="@layout/activity_book_detail_content"/>

</android.support.design.widget.CoordinatorLayout>
5 changes: 3 additions & 2 deletions douban/src/main/res/layout/activity_book_detail_content.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
<com.ycbjie.library.weight.CustomScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
Expand Down Expand Up @@ -98,5 +99,5 @@
android:textColor="@color/blackText2" />

</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</com.ycbjie.library.weight.CustomScrollView>

5 changes: 3 additions & 2 deletions douban/src/main/res/layout/activity_movie_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<include layout="@layout/activity_movie_detail_content"/>

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="270dp"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
Expand Down Expand Up @@ -91,4 +90,6 @@
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

<include layout="@layout/activity_movie_detail_content"/>

</android.support.design.widget.CoordinatorLayout>
4 changes: 2 additions & 2 deletions douban/src/main/res/layout/activity_movie_detail_content.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
<com.ycbjie.library.weight.CustomScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
Expand Down Expand Up @@ -106,4 +106,4 @@

</LinearLayout>

</android.support.v4.widget.NestedScrollView>
</com.ycbjie.library.weight.CustomScrollView>
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ dependencies {
exclude module: "support-annotations"
}
api rootProject.ext.dependencies["design"]
api rootProject.ext.dependencies["dynamic"]
api rootProject.ext.dependencies["palette"]
api rootProject.ext.dependencies["cardview-v7"]
api rootProject.ext.dependencies["support-v4"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.net.Uri;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.lzy.imagepicker.loader.ImageLoader;
import com.ycbjie.library.R;
Expand All @@ -20,17 +19,11 @@ public class GlideImageLoader implements ImageLoader {

@Override
public void displayImage(Activity activity, String path, ImageView imageView, int width, int height) {
/*Picasso.with(activity) //配置上下文
.load(Uri.fromFile(new File(path))) //设置图片路径(fix #8,文件名包含%符号 无法识别和显示)
.error(R.drawable.bg_stack_blur_default) //设置错误图片
.placeholder(R.drawable.bg_stack_blur_default) //设置占位图片
.into(imageView);*/

GlideApp.with(activity) //配置上下文
.load(Uri.fromFile(new File(path))) //设置图片路径(fix #8,文件名包含%符号 无法识别和显示)
.error(R.mipmap.default_image) //设置错误图片
.placeholder(R.mipmap.default_image) //设置占位图片
.diskCacheStrategy(DiskCacheStrategy.ALL)//缓存全尺寸
GlideApp.with(activity)
.load(Uri.fromFile(new File(path)))
.error(R.mipmap.default_image)
.placeholder(R.mipmap.default_image)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(imageView);
}

Expand Down
Loading

0 comments on commit 4475bff

Please sign in to comment.