Explorar el Código

实现邀请赚钱分享效果

zengjiebin hace 7 años
padre
commit
e7bb668a13

+ 6 - 5
app/src/main/AndroidManifest.xml

@@ -595,16 +595,17 @@
         <activity android:name="com.sheep.gamegroup.view.activity.MessageInteractionDetailActivity"
             android:exported="true"/>
         <activity android:name="com.sheep.gamegroup.view.activity.ActModifyThird"
-            android:exported="true"/>
+            android:screenOrientation="portrait"/>
         <activity android:name="com.sheep.gamegroup.view.activity.ActEverydayPlayGame"
-            android:exported="true"/>
+            android:screenOrientation="portrait"/>
         <activity android:name="com.sheep.gamegroup.view.activity.ActPlayGameDetail"
-            android:screenOrientation="portrait"
-            android:exported="true"/>
+            android:screenOrientation="portrait"/>
         <activity android:name="com.sheep.gamegroup.view.activity.MessageCenterDetailActivity"
             android:exported="true"/>
         <activity android:name="com.sheep.gamegroup.view.activity.InvitationActivity"
-            android:exported="true"/>
+            android:screenOrientation="portrait"/>
+        <activity android:name="com.sheep.gamegroup.view.activity.ActInvitation"
+            android:screenOrientation="portrait"/>
 
         <!--start幂动科技-->
 

+ 37 - 0
app/src/main/java/com/sheep/gamegroup/transformer/ScaleTransformer.java

@@ -0,0 +1,37 @@
+package com.sheep.gamegroup.transformer;
+
+import android.support.annotation.NonNull;
+import android.support.v4.view.ViewPager;
+import android.view.View;
+
+
+/**
+ * Created by realicing on 2018/9/7.
+ * realicing@sina.com
+ */
+public class ScaleTransformer implements ViewPager.PageTransformer {
+    private static final float MIN_SCALE = 0.85f;
+    private static final float MIN_ALPHA = 0.5f;
+
+    @Override
+    public void transformPage(@NonNull View page, float position) {
+        if (position < -1 || position > 1) {
+            page.setAlpha(MIN_ALPHA);
+            page.setScaleX(MIN_SCALE);
+            page.setScaleY(MIN_SCALE);
+        } else if (position <= 1) { // [-1,1]
+            float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position));
+            if (position < 0) {
+                float scaleX = 1 + 0.15f * position;
+                page.setScaleX(scaleX);
+                page.setScaleY(scaleX);
+            } else {
+                float scaleX = 1 - 0.15f * position;
+                page.setScaleX(scaleX);
+                page.setScaleY(scaleX);
+            }
+            page.setAlpha(MIN_ALPHA + (scaleFactor - MIN_SCALE) / (1 - MIN_SCALE) * (1 - MIN_ALPHA));
+        }
+    }
+}
+

+ 112 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/ActInvitation.java

@@ -0,0 +1,112 @@
+package com.sheep.gamegroup.view.activity;
+
+import android.annotation.SuppressLint;
+import android.graphics.drawable.Drawable;
+import android.support.annotation.Nullable;
+import android.support.v4.view.ViewPager;
+import android.view.LayoutInflater;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.ImageView;
+
+import com.bumptech.glide.Glide;
+import com.bumptech.glide.load.DataSource;
+import com.bumptech.glide.load.engine.GlideException;
+import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
+import com.bumptech.glide.request.RequestListener;
+import com.bumptech.glide.request.RequestOptions;
+import com.bumptech.glide.request.target.Target;
+import com.sheep.gamegroup.absBase.BaseActivity;
+import com.sheep.gamegroup.model.entity.BaseMessage;
+import com.sheep.gamegroup.model.entity.PictureInvitationEntity;
+import com.sheep.gamegroup.model.util.SheepSubscriber;
+import com.sheep.gamegroup.transformer.ScaleTransformer;
+import com.sheep.gamegroup.view.adapter.ArrayPagerAdapter;
+import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import butterknife.BindView;
+import rx.android.schedulers.AndroidSchedulers;
+import rx.schedulers.Schedulers;
+
+/**
+ * Created by realicing on 2018/9/7.
+ * realicing@sina.com
+ */
+public class ActInvitation extends BaseActivity {
+    @BindView(R.id.act_invitation_rl)
+    View act_invitation_rl;
+    @BindView(R.id.act_invitation_cvp)
+    ViewPager viewPager;
+    @Override
+    protected int getLayoutId() {
+        return R.layout.act_invitation;
+    }
+    private List<PictureInvitationEntity> mPictureList = new ArrayList<>();
+    private List<View> viewArrayList = new ArrayList<>();
+
+    @SuppressLint("ClickableViewAccessibility")
+    @Override
+    public void initView() {
+        act_invitation_rl.setOnTouchListener(new View.OnTouchListener() {
+            @Override
+            public boolean onTouch(View v, MotionEvent event) {
+                return viewPager.dispatchTouchEvent(event);
+            }
+        });
+    }
+
+    @Override
+    public void initData() {
+        SheepApp.getInstance()
+                .getNetComponent()
+                .getApiService()
+                .getSharePicture()
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                    @Override
+                    public void onNext(BaseMessage baseMessage) {
+                        mPictureList.addAll(baseMessage.getDataList(PictureInvitationEntity.class));
+                        loadData();
+                    }
+
+                    @Override
+                    public void onError(BaseMessage baseMessage) {
+                    }
+                });
+    }
+
+    private void loadData() {
+        for (final PictureInvitationEntity item : mPictureList) {
+            View itemView = LayoutInflater.from(SheepApp.getInstance()).inflate(R.layout.item_image2, null);
+
+            ImageView image_full = itemView.findViewById(R.id.image_full);
+            Glide.with(SheepApp.getInstance())
+                    .load(item.getPicture())
+                    .listener(new RequestListener<Drawable>() {
+                        @Override
+                        public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+                            item.setLoaded(false);
+                            return false;
+                        }
+
+                        @Override
+                        public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+                            item.setLoaded(true);
+                            return false;
+                        }
+                    })
+                    .apply(new RequestOptions().centerCrop().transform(new RoundedCorners((int) getResources().getDimension(R.dimen.content_padding_8))))
+                    .into(image_full);
+            viewArrayList.add(itemView);
+        }
+        ArrayPagerAdapter adapter = new ArrayPagerAdapter(viewArrayList);
+        viewPager.setAdapter(adapter);
+        viewPager.setOffscreenPageLimit(mPictureList.size());
+        viewPager.setPageTransformer(true, new ScaleTransformer());
+    }
+}

+ 11 - 2
app/src/main/java/com/sheep/gamegroup/view/activity/InvitationActivity.java

@@ -7,6 +7,7 @@ import android.support.annotation.Nullable;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.GridLayoutManager;
 import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.PagerSnapHelper;
 import android.support.v7.widget.RecyclerView;
 import android.text.TextUtils;
 import android.util.Log;
@@ -24,6 +25,8 @@ import com.bumptech.glide.request.RequestListener;
 import com.bumptech.glide.request.RequestOptions;
 import com.bumptech.glide.request.target.Target;
 import com.kfzs.appstore.utils.adapter.recyclerview.RecyclerViewAdapter;
+import com.kfzs.duanduan.cardview.CardLinearSnapHelper;
+import com.kfzs.duanduan.cardview.CardScaleHelper;
 import com.sheep.gamegroup.helper.ScalableCardHelper;
 import com.sheep.gamegroup.model.api.ICallBack;
 import com.sheep.gamegroup.model.entity.BaseMessage;
@@ -143,8 +146,14 @@ public class InvitationActivity extends AppCompatActivity implements ScalableCar
 
         };
         mRecyclerView.setAdapter(mRecyclerViewAdapter);
-        ScalableCardHelper cardHelper = new ScalableCardHelper(this);
-        cardHelper.attachToRecyclerView(mRecyclerView);
+//        CardLinearSnapHelper cardLinearSnapHelper = new CardLinearSnapHelper();
+//        cardLinearSnapHelper.attachToRecyclerView(mRecyclerView);
+        CardScaleHelper cardLinearSnapHelper = new CardScaleHelper();
+        cardLinearSnapHelper.attachToRecyclerView(mRecyclerView);
+//        PagerSnapHelper cardLinearSnapHelper = new PagerSnapHelper();
+//        cardLinearSnapHelper.attachToRecyclerView(mRecyclerView);
+//        ScalableCardHelper cardHelper = new ScalableCardHelper(this);
+//        cardHelper.attachToRecyclerView(mRecyclerView);
     }
     private SparseArray<View> viewList = new SparseArray<>();
 

+ 62 - 0
app/src/main/java/com/sheep/gamegroup/view/customview/ClipViewPager.java

@@ -0,0 +1,62 @@
+package com.sheep.gamegroup.view.customview;
+
+import android.content.Context;
+import android.support.v4.view.ViewPager;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+
+/**
+ * Created by realicing on 2018/9/7.
+ * realicing@sina.com
+ */
+public class ClipViewPager extends ViewPager {
+
+    public ClipViewPager(Context context) {
+        super(context);
+    }
+
+    public ClipViewPager(Context context, AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    @Override
+    public boolean dispatchTouchEvent(MotionEvent ev) {
+
+        if (ev.getAction() == MotionEvent.ACTION_UP) {
+            View view = viewOfClickOnScreen(ev);
+            if (view != null) {
+                setCurrentItem(indexOfChild(view));
+            }
+        }
+
+        return super.dispatchTouchEvent(ev);
+    }
+
+    /**
+     * @param ev
+     * @return
+     */
+    private View viewOfClickOnScreen(MotionEvent ev) {
+        int childCount = getChildCount();
+        int[] location = new int[2];
+        for (int i = 0; i < childCount; i++) {
+            View v = getChildAt(i);
+            v.getLocationOnScreen(location);
+            int minX = location[0];
+            int minY = getTop();
+
+            int maxX = location[0] + v.getWidth();
+            int maxY = getBottom();
+
+            float x = ev.getX();
+            float y = ev.getY();
+
+            if ((x > minX && x < maxX) && (y > minY && y < maxY)) {
+                return v;
+            }
+        }
+        return null;
+    }
+}
+

+ 2 - 2
app/src/main/java/com/sheep/gamegroup/view/fragment/FgtAskgetmoney.java

@@ -27,8 +27,8 @@ import com.sheep.gamegroup.util.FastJsonUtils;
 import com.sheep.gamegroup.util.GlideImageLoader;
 import com.sheep.gamegroup.util.StringUtils;
 import com.sheep.gamegroup.util.ViewUtil;
+import com.sheep.gamegroup.view.activity.ActInvitation;
 import com.sheep.gamegroup.view.activity.ActMain;
-import com.sheep.gamegroup.view.activity.InvitationActivity;
 import com.sheep.gamegroup.view.adapter.TitleFragmentListAdapter;
 import com.sheep.jiuyan.samllsheep.BuildConfig;
 import com.sheep.jiuyan.samllsheep.R;
@@ -277,7 +277,7 @@ public class FgtAskgetmoney extends BaseFragment {
                 break;
             case R.id.ask_invite_tv:
                // showShareView();
-                startActivity(new Intent(getActivity(), InvitationActivity.class));
+                startActivity(new Intent(getActivity(), ActInvitation.class));
                 break;
         }
     }

+ 115 - 0
app/src/main/res/layout/act_invitation.xml

@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="utf-8"?>
+<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:background="#F0F0F0">
+
+    <ImageView
+        android:id="@+id/img_baseactivity_title"
+        android:layout_width="?attr/actionBarSize"
+        android:layout_height="?attr/actionBarSize"
+        android:gravity="center_vertical"
+        android:scaleType="centerInside"
+        android:src="@drawable/narrow_back_black"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <RelativeLayout
+        android:id="@+id/act_invitation_rl"
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        android:background="#F0F0F0"
+        android:clipChildren="false"
+        app:layout_constraintBottom_toTopOf="@+id/layout_f"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/img_baseactivity_title">
+
+        <TextView
+            android:id="@+id/tv_flags"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_alignParentBottom="true"
+            android:layout_centerHorizontal="true"
+            android:layout_marginBottom="@dimen/content_padding_16"
+            android:layout_marginTop="@dimen/content_padding_16"
+            android:text="左右滑动选择推广页" />
+
+        <com.sheep.gamegroup.view.customview.ClipViewPager
+            android:id="@+id/act_invitation_cvp"
+            android:layout_width="300dp"
+            android:layout_height="wrap_content"
+            android:layout_above="@+id/tv_flags"
+            android:layout_centerHorizontal="true"
+            android:clipChildren="false"
+            android:overScrollMode="never" />
+    </RelativeLayout>
+
+    <RelativeLayout
+        android:id="@+id/layout_f"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="#ffffffff"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/layout_f1">
+
+        <TextView
+            android:id="@+id/ask_share_title"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:padding="10dp"
+            android:text="邀请好友"
+            android:textColor="#ff333333"
+            android:textSize="14sp" />
+
+        <TextView
+            android:id="@+id/tv_copy"
+            android:layout_width="40dp"
+            android:layout_height="20dp"
+            android:layout_alignParentEnd="true"
+            android:layout_marginEnd="15dp"
+            android:layout_marginTop="20dp"
+            android:background="@drawable/shape_blue_stroke_withe_radius_5"
+            android:gravity="center"
+            android:text="复制"
+            android:textColor="@color/white"
+            android:visibility="invisible" />
+
+        <TextView
+            android:id="@+id/tv_invitation_code"
+            android:layout_width="wrap_content"
+            android:layout_height="30dp"
+            android:layout_marginRight="5dp"
+            android:layout_marginTop="15dp"
+            android:layout_toLeftOf="@id/tv_copy"
+            android:gravity="center"
+            android:text="12332"
+            android:textColor="#ff333333"
+            android:visibility="invisible" />
+
+        <TextView
+            android:id="@+id/tv_f_invatation"
+            android:layout_width="wrap_content"
+            android:layout_height="30dp"
+            android:layout_marginRight="5dp"
+            android:layout_marginTop="15dp"
+            android:layout_toLeftOf="@id/tv_invitation_code"
+            android:gravity="center"
+            android:text="你的邀请码:"
+            android:textColor="#ff333333"
+            android:visibility="invisible" />
+
+
+        <android.support.v7.widget.RecyclerView
+            android:id="@+id/ask_share_list"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@+id/ask_share_title"
+            android:layout_marginBottom="15dp"
+            android:layout_marginStart="@dimen/content_padding_15"
+            android:layout_marginTop="20dp" />
+    </RelativeLayout>
+
+
+</android.support.constraint.ConstraintLayout>

+ 3 - 2
app/src/main/res/layout/activity_invitation.xml

@@ -22,6 +22,7 @@
         android:background="#F0F0F0"
         android:gravity="center_horizontal"
         android:orientation="vertical"
+        android:clipChildren="false"
         app:layout_constraintBottom_toTopOf="@+id/layout_f"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
@@ -29,10 +30,10 @@
 
         <android.support.v7.widget.RecyclerView
             android:id="@+id/recyclerView"
-            android:layout_width="match_parent"
+            android:layout_width="300dp"
             android:layout_height="0dp"
             android:layout_weight="1"
-            android:clipChildren="true"/>
+            android:clipChildren="false"/>
 
         <TextView
             android:id="@+id/tv_flags"

+ 34 - 0
app/src/main/res/layout/item_image3.xml

@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/layout_view"
+    android:layout_width="300dp"
+    android:paddingStart="20dp"
+    android:paddingEnd="20dp"
+    android:layout_height="match_parent">
+
+    <ImageView
+        android:id="@+id/image_full"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_centerHorizontal="true"
+        android:adjustViewBounds="true"
+        android:scaleType="fitXY" />
+
+    <ImageView
+        android:id="@+id/image_bottom"
+        android:layout_width="100dp"
+        android:layout_height="100dp"
+        android:layout_alignParentBottom="true"
+        android:layout_centerHorizontal="true"
+        android:src="@drawable/loading_01" />
+
+    <ImageView
+        android:layout_width="100dp"
+        android:layout_height="100dp"
+        android:layout_alignParentBottom="true"
+        android:layout_centerHorizontal="true"
+        android:padding="40dp"
+        android:src="@mipmap/sheep_logo" />
+
+
+</RelativeLayout>