其他分享
首页 > 其他分享> > Android上拉吸顶(上滑标题固定在顶部)

Android上拉吸顶(上滑标题固定在顶部)

作者:互联网

效果图

1.home_layout.xml
此布局即可实现上拉标题固定在顶部

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:rvp="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:tl="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/ll_base"
    android:background="@drawable/bg_f8f8f8"
    >

   <!-- <android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">-->


    <!--中间内容-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >

            <FrameLayout
                android:focusableInTouchMode="true"
                android:focusable="true"
                android:layout_width="match_parent"
                android:visibility="gone"
                android:layout_height="205dp">

                <com.broker.liming.banner.view.BannerBgContainer
                    android:id="@+id/banner_bg_container"
                    android:layout_width="match_parent"
                    android:layout_height="205dp" />

                <com.broker.liming.banner.LoopLayout
                    android:id="@+id/loop_layout"
                    android:layout_width="match_parent"
                    android:layout_height="120dp"
                    android:layout_gravity="bottom"
                    android:layout_marginTop="@dimen/lay_85" />
            </FrameLayout>
            <android.support.design.widget.CoordinatorLayout
                android:id="@+id/main_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.design.widget.AppBarLayout
                    android:id="@+id/appbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    app:elevation="0dp"
                    app:layout_behavior="com.broker.liming.widget.AppBarLayoutBehavior"

                    >

                    <android.support.design.widget.CollapsingToolbarLayout
                        android:id="@+id/main.collapsing"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        app:layout_scrollFlags="scroll|exitUntilCollapsed">
                       <!-- android:fitsSystemWindows="true"
                        app:contentScrim="?attr/colorPrimary"
                        app:expandedTitleMarginEnd="64dp"
                        app:expandedTitleMarginStart="48dp"-->
                      <!--  <android.support.constraint.ConstraintLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:fitsSystemWindows="true"
                            android:scaleType="centerCrop"
                            app:layout_collapseMode="parallax">-->
                            <RelativeLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:orientation="vertical"
                                android:background="@drawable/bg_f8f8f8"
                                >
                                <!--app:layout_constraintTop_toTopOf="parent"
                                app:layout_constraintLeft_toLeftOf="parent"
                                app:layout_constraintRight_toRightOf="parent"
                                app:layout_constraintBottom_toBottomOf="parent"-->
                                <com.jcodecraeer.xrecyclerview.XRecyclerView
                                    android:id="@+id/xrv_product"
                                    style="@style/match_view"
                                    android:nestedScrollingEnabled="false"
                                    android:scrollbars="none"
                                    android:visibility="visible"

                                    />
                                <android.support.v7.widget.RecyclerView
                                    android:id="@+id/recycler"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:visibility="gone"
                                    android:overScrollMode="never" />
                                <!--<com.yi.haigou.shop.view.ShopInfoView
                                    android:id="@+id/shop_inof_view"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    app:layout_constraintTop_toTopOf="parent" />

                                <com.yi.haigou.shop.view.ShopAddressView
                                    android:id="@+id/shop_address_view"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    app:layout_constraintBottom_toBottomOf="parent"
                                    app:layout_constraintTop_toTopOf="parent" />-->
                            </RelativeLayout>

                      <!--  </android.support.constraint.ConstraintLayout>-->
                        <android.support.v7.widget.Toolbar
                            android:id="@+id/toolbar"
                            android:layout_width="match_parent"
                            android:layout_height="@dimen/lay_60"
                            >

                            <!--<android.support.constraint.ConstraintLayout-->
                            <!--android:layout_width="match_parent"-->
                            <!--android:layout_height="match_parent">-->
                            <!--<com.yi.shop.shop.view.ShopSearchBar-->
                            <!--android:id="@+id/search_bar_view"-->
                            <!--android:layout_width="match_parent"-->
                            <!--android:layout_height="wrap_content"-->
                            <!--android:background="@drawable/ic_shop_title"-->
                            <!--app:layout_constraintTop_toTopOf="parent"/>-->
                            <!--</android.support.constraint.ConstraintLayout>-->
                        </android.support.v7.widget.Toolbar>


                    </android.support.design.widget.CollapsingToolbarLayout>

                </android.support.design.widget.AppBarLayout>


            <!--吸顶tab-->
                <LinearLayout
                    android:id="@+id/ll_tab"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:visibility="gone"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior">

                    <com.broker.liming.widget.SlidingTabLayout
                        android:id="@+id/tl_9"
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/lay_45"
                        android:paddingLeft="12dp"
                        android:paddingRight="12dp"
                        android:layout_marginTop="@dimen/lay_20"
                        tl:tl_indicator_anim_duration="100"
                        tl:tl_indicator_anim_enable="true"
                        tl:tl_indicator_bounce_enable="false"
                        tl:tl_indicator_color="@color/name_1A75FF"
                        tl:tl_indicator_margin_left="2dp"
                        tl:tl_indicator_margin_right="2dp"
                        tl:tl_indicator_style="BLOCK"
                        tl:tl_textSelectColor="@color/white"
                        tl:tl_textUnselectColor="@color/text_000000"
                        tl:tl_textsize="@dimen/font_13"
                        />
                    <android.support.v4.view.ViewPager
                        android:id="@+id/viewpager"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_marginTop="@dimen/lay_12"
                        />
                    <!--公司信息-->
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="vertical"
                        android:layout_alignParentBottom="true"
                        android:visibility="gone"
                        >


                        <TextView
                            android:id="@+id/tv_phone"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="@dimen/lay_12"
                            android:layout_marginRight="@dimen/lay_12"
                            android:layout_marginTop="@dimen/lay_34"
                            android:gravity="center"
                            android:text="1569796696"
                            android:textColor="@color/color_c7c7c7"
                            android:textSize="@dimen/font_13" />

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginBottom="@dimen/font_16"
                            android:layout_marginLeft="@dimen/lay_12"
                            android:layout_marginRight="@dimen/lay_12"
                            android:layout_marginTop="@dimen/lay_12"
                            android:gravity="center">

                            <TextView
                                android:id="@+id/tv_email"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:textColor="@color/color_c7c7c7"
                                android:textSize="@dimen/font_13" />

                            <ImageView
                                android:id="@+id/iv_copy"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginLeft="@dimen/lay_6"
                                android:background="@mipmap/home_copy" />
                        </LinearLayout>
                    </LinearLayout>
                </LinearLayout>

            </android.support.design.widget.CoordinatorLayout>


        </LinearLayout>
  <!--  </android.support.v4.widget.SwipeRefreshLayout>-->


    <!--搜索-->
    <RelativeLayout
        android:id="@+id/rl_top"
        android:layout_width="match_parent"
        android:layout_height="@dimen/lay_70"
        android:background="@color/transparent"
        android:gravity="bottom">

        <RelativeLayout
            android:id="@+id/rl_title"
            android:layout_width="match_parent"
            android:layout_height="@dimen/lay_45"
            android:gravity="center_vertical"
            android:paddingLeft="@dimen/lay_12">

            <TextView
                android:id="@+id/tv_title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginRight="@dimen/lay_12"
                android:text="日月保盒"
                android:textColor="@color/white"
                android:textSize="@dimen/font_18"
                android:textStyle="bold" />

            <LinearLayout
                android:id="@+id/ll_search"
                android:layout_width="match_parent"
                android:layout_height="@dimen/lay_31"
                android:layout_centerVertical="true"
                android:layout_marginRight="@dimen/lay_57"
                android:layout_toRightOf="@+id/tv_title"
                android:background="@drawable/shape_search_product"
                android:gravity="center_vertical">

                <ImageView
                    android:id="@+id/iv_search"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_marginLeft="@dimen/lay_12"
                    android:layout_marginRight="@dimen/lay_5"
                    android:background="@mipmap/home_search" />

                <TextView
                    android:id="@+id/tv_search"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:ellipsize="end"
                    android:paddingRight="@dimen/lay_12"
                    android:singleLine="true"
                    android:text=""
                    android:textColor="@color/color_c7c7c7"
                    android:textSize="@dimen/lay_14" />
            </LinearLayout>

            <RelativeLayout
                android:id="@+id/rl_msg"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_alignParentRight="true"
                android:layout_marginEnd="@dimen/lay_12"
                android:gravity="center_vertical">

                <ImageView
                    android:id="@+id/iv_msg"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/lay_5"
                    android:background="@mipmap/home_message_white" />

                <TextView
                    android:id="@+id/tv_msgnum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="11dp"
                    android:layout_marginTop="@dimen/lay_2"
                    android:background="@drawable/yuandianred"
                    android:gravity="center"
                    android:minWidth="14dp"
                    android:paddingLeft="3dp"
                    android:paddingRight="3dp"
                    android:singleLine="true"
                    android:textColor="@android:color/white"
                    android:textSize="@dimen/font_10"
                    android:visibility="visible" />
            </RelativeLayout>

        </RelativeLayout>

    </RelativeLayout>
 
    
</RelativeLayout>

2.fragment

package com.broker.liming.fragment;

import android.Manifest;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Display;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.broker.liming.R;
import com.broker.liming.activity.AgreementActivity;
import com.broker.liming.activity.SplashActivity;
import com.broker.liming.activity.WebViewActivity;
import com.broker.liming.adapter.ArticleAdapter;
import com.broker.liming.adapter.HomeAdapter;
import com.broker.liming.api.HttpParams;
import com.broker.liming.api.WebHttpParams;
import com.broker.liming.application.LoadBugClass;
import com.broker.liming.banner.IndicatorLocation;
import com.broker.liming.banner.LoopLayout;
import com.broker.liming.banner.LoopStyle;
import com.broker.liming.banner.OnDefaultImageViewLoader;
import com.broker.liming.banner.bean.BannerInfo;
import com.broker.liming.banner.listener.OnBannerItemClickListener;
import com.broker.liming.banner.view.BannerBgContainer;
import com.broker.liming.base.BaseFragment;
import com.broker.liming.bean.ColorInfo;
import com.broker.liming.bean.CompanyBaseBean;
import com.broker.liming.bean.HeadHomeBean;
import com.broker.liming.bean.HomeBannerBean;
import com.broker.liming.bean.HomeBean;
import com.broker.liming.bean.HomeProductBean;
import com.broker.liming.bean.MineBean;
import com.broker.liming.bean.RecommendListBean;
import com.broker.liming.bean.SettingBean;
import com.broker.liming.bean.UserBean;
import com.broker.liming.bean.UserInfoBean;
import com.broker.liming.college.bean.ArticleClassifyListBean;
import com.broker.liming.college.bean.FaXianListsBean;
import com.broker.liming.college.bean.FindClassifysBean;
import com.broker.liming.college.bean.KaoShiStatussBean;
import com.broker.liming.constant.Constants;
import com.broker.liming.dao.UserBeanDao;
import com.broker.liming.editview.FunctionItem;
import com.broker.liming.editview.SFUtils;
import com.broker.liming.event.ChangXianLogin;
import com.broker.liming.event.ELoginSuccess;
import com.broker.liming.event.EventManager;
import com.broker.liming.event.LongRiskEvent;
import com.broker.liming.event.RefreshHomeArticleEvent;
import com.broker.liming.interf.OnBottomTabReselectListener;
import com.broker.liming.interfaclisetener.ArticleHomeClickLisener;
import com.broker.liming.utils.AccountUtils;
import com.broker.liming.utils.CommonUtils;
import com.broker.liming.utils.DensityUtil;
import com.broker.liming.utils.GsonUtils;
import com.broker.liming.utils.LogUtil;
import com.broker.liming.utils.LogUtil2;
import com.broker.liming.utils.SPUtils;
import com.broker.liming.utils.SobotUtils;
import com.broker.liming.utils.StatusBarUtil;
import com.broker.liming.utils.StringUtil;
import com.broker.liming.utils.ToastUtil;
import com.broker.liming.utils.UIHelper;
import com.broker.liming.utils.Utils;
import com.broker.liming.utils.ViewFindUtils;
import com.broker.liming.viewholder.NetworkImageHolderView;
import com.broker.liming.viewholder.TabViewHolder;
import com.broker.liming.widget.AppBarStateChangeListener;
import com.broker.liming.widget.CustomDialog;
import com.broker.liming.widget.MyScrollView;
import com.broker.liming.widget.OnTabSelectListener;
import com.broker.liming.widget.RecyclerviewScrollLisetener;
import com.broker.liming.widget.SetOnclickInterface;
import com.broker.liming.widget.SlidingTabLayout;
import com.broker.liming.widget.TitleBar;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;

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

import lecho.lib.hellocharts.model.Line;

import static com.broker.liming.constant.Constants.flag;
import static com.broker.liming.utils.SystemInfoUtils.getScreenWidth;
import static com.umeng.socialize.utils.ContextUtil.getPackageName;

/**
 * Description:
 * Creator: Chenqiang
 * DatePopAdapter: 2018/2/24
 */
public class HomeFragment extends BaseFragment implements OnBottomTabReselectListener, OnItemClickListener, XRecyclerView.LoadingListener, OnBannerItemClickListener, RecyclerviewScrollLisetener,ArticleHomeClickLisener {
    public static ConvenientBanner mConvenientBanner;
    private List<HomeBannerBean> mHomePagePlatAdList;
    private HomeAdapter mHomeAdapter;
    private XRecyclerView mXrvProduct;
    private SmartRefreshLayout refreshLayout;
    private XRecyclerView xRecyclerView;
    private ImageView iv_center;
    private RelativeLayout rl_wallet;
    private RelativeLayout rl_msg;
    private TextView tv_msgnum;
    private HomeBean.PopUpEntity popUp;
    private TitleBar mTitleBar;
    private TextView tv_statusBar_slide;

    private BannerBgContainer container;
    private LoopLayout loopLayout;
    private int imageHeight;
    private RelativeLayout rl_title;
    private String longRiskUrl;
    private String longCenterUrl;
    private String longCenterUrl2;
    private String longCenterNew;//新版

    private String longCenterUrl3;
    public static boolean canClick;
    public static boolean canClick2;
    private RelativeLayout rl_top;
    private ImageView iv_search;
    private String customerLevel;
    public static String flag3;
    public static String certifiedState;
    public static String flag2;
    private ImageView iv_contact;
    private int duration;
    public static boolean canClick3;
    //    private MoveImage iv_contact2;
    private TextView tv_245;
    private TextView tv_247;
    private TextView tv_chang_commit;
    private EditText edit_logoin;
    private EditText edit_screen;
    private EditText edit_riyuebaohe;
    private TextView tv_tinker;
    private TextView tv_title;
    private LinearLayout ll_search;
    private ImageView iv_msg;
    private int position;
    private TextView tv_search;

    private ImageView ivBannerHeadBg;
    private int count;
    private boolean isInit = true;
    private List<String> bannerList = new ArrayList<>();
    private List<ColorInfo> colorList = new ArrayList<>();
    private int mDistanceY;
    private LinearLayoutManager layoutManager;
    private int y;
    private int height;
    private String localVersion;
    private String key;
    private PopupWindow popWindow;
    private boolean hidden2 = false;
    private SFUtils sfUtils;
    private List<FunctionItem> allData;
    private List<FunctionItem> selData;
    private ImageView iv_back_top;
    private String localVersionLoad;
    private RecyclerView recycler;
    private /*ViewPagerForScrollView*/ ViewPager viewpager;
    private SlidingTabLayout tl_9;
    private Toolbar toolbar;
    private List<String> mTitles=new ArrayList<>();
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    //    private MyPagerAdapter mAdapter;
    private FragmentManager fragmentManager;
    private View pagerview;
    private SlidingTabLayout tab_head;
    private MyScrollView scrollowview;
    private int[] location2;
    private int[] location3;
    private int yrecycler;
    private TextView tv_phone;
    private TextView tv_email;
    private ImageView iv_copy;
    private AppBarLayout appbar;
    private CoordinatorLayout main_content;
    private CustomDialog dialog;
    private boolean isFirstLay = true;
    private List<ArticleClassifyListBean> articleClassifyList;
    private LinearLayout ll_tab;
    private RelativeLayout ll_base;
    public static SettingBean settingBean;
    private CompanyBaseBean companyBaseBean;
    private MyPagerAdapter mAdapter;
    private boolean isRemind=false;//点文章不会到顶部其余都回到顶部
    private boolean isSame=true;//是否有不同tab 判断后台增加或者减少tab刷新 否者不刷新tab方便记录点击位置
    private boolean isFirstTab=true;//是否第一进入加载 第一次进入app时刷新tab 不是第一次需判断后台增加或者减少tab刷新 否者不刷新tab方便记录点击位置
    private boolean isHoutai=false;
    private int appbarState;
    private boolean isOther=false;
    private boolean isRemindTrue=false;


    @Override
    protected int getContentView() {
        // 加载系统默认设置,字体不随用户设置变化
        Resources res = mContext.getResources();
        Configuration config = new Configuration();
        config.setToDefaults();
        res.updateConfiguration(config, res.getDisplayMetrics());

        return R.layout./*fragment_home*/home_fragment_two;
    }

    @Override
    protected void initTitleBar(View view) {
//        mTitleBar = (TitleBar) view.findViewById(R.id.title_bar);
//        mTitleBar.setTitle("");
//        setStateBar();
//        mTitleBar.setTitleBarBg(android.R.color.transparent);
         /* mTitleBar.setLeftBackground(R.mipmap.home_left);
        mTitleBar.setLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isLogin()) {
                    UIHelper.showLogin(mContext);
                    return;
                }
                UserBean query = UserBeanDao.query();
                UIHelper.showInvite(mContext, WebHttpParams.showInviting(query.customerImageUrl));
//                ToastUtil.showToast(mContext, "分享");
//                ((BaseActivity) getActivity())
//                        .getShareAction("", "", "", "").open();
            }
        });
        mTitleBar.setRightBackground(R.mipmap.home_right);
        mTitleBar.setRightClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!isLogin()) {
                    UIHelper.showLogin(mContext);
                    return;
                }
                UIHelper.showWebView(mContext, WebHttpParams.showMyNews());
            }
        });
        mTitleBar.setTitleBarBg(android.R.color.transparent);*/


        iv_search = (ImageView) view.findViewById(R.id.iv_search);

//        rl_wallet = (RelativeLayout) view.findViewById(R.id.rl_wallet);
//        rl_wallet.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (!isLogin()) {
//                    UIHelper.showLogin(mContext);
//                    return;
//                }
//
//                UserBean query = UserBeanDao.query();
//                if (AccountUtils.isAuthentication(query.certifiedState)) {
//                    UIHelper.showMyWallet(mContext);
//                } else {
//                    UIHelper.showWebView(mContext, WebHttpParams.showCredentials());
//                }
//            }
//        });
        rl_msg = (RelativeLayout) view.findViewById(R.id.rl_msg);
        rl_msg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!isLogin()) {
                    UIHelper.showLogin(mContext);
                    return;
                }
                UIHelper.showWebView2(mContext, WebHttpParams.showMyNews());
            }
        });
        tv_msgnum = (TextView) view.findViewById(R.id.tv_msgnum);

//        iv_center = (ImageView) view.findViewById(R.id.iv_center);
        /*Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.rotate);
        LinearInterpolator lir = new LinearInterpolator();// 设置插入器(线性匀速)
        anim.setInterpolator(lir);
        iv_center.startAnimation(anim);*/

//        iv_center.setVisibility(View.VISIBLE);
//        Animation anim =new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//        anim.setFillAfter(true); // 设置保持动画最后的状态
//        anim.setDuration(10000); // 设置动画时间
//        anim.setInterpolator(new LinearInterpolator()); // 设置插入器(线性匀速)
//        mTitleBar.startAnimation(anim);
    }



    @Override
    public void initView(View view) {
//        setFullScreen();
//        changeStatusBarTextColor(true);
//        BarUtils.setColorNoTranslucent(getActivity(), getResources().getColor(R.color.transparent));
//        BarUtils.setRootViewFitsSystemWindows(getActivity(), false);
//        //此方法上下状态栏都透明,状态栏字体颜色为黑色
//        BarUtils.setTranslucentForCoordinatorLayout(getActivity(),0);
        pagerview = view;
        StatusBarUtil.setTranslucentStatus(getActivity());
        StatusBarUtil.setStatusBarDarkTheme(getActivity(), false);

        if (!EventManager.isRegistered(this)) {
            EventManager.register(this);
        }
        tv_tinker = (TextView) view.findViewById(R.id.tv_tinker);
        tv_245 = (TextView) view.findViewById(R.id.tv_245);
        tv_247 = (TextView) view.findViewById(R.id.tv_247);
        tv_chang_commit = (TextView) view.findViewById(R.id.tv_chang_commit);
        edit_logoin = (EditText) view.findViewById(R.id.edit_logoin);
        edit_screen = (EditText) view.findViewById(R.id.edit_screen);
        edit_riyuebaohe = (EditText) view.findViewById(R.id.edit_riyuebaohe);
        tv_title = (TextView) view.findViewById(R.id.tv_title);
        ll_search = (LinearLayout) view.findViewById(R.id.ll_search);
        iv_msg = (ImageView) view.findViewById(R.id.iv_msg);
        rl_top = (RelativeLayout) view.findViewById(R.id.rl_top);
        iv_contact = (ImageView) view.findViewById(R.id.iv_contact);
        tv_search = (TextView) view.findViewById(R.id.tv_search);
        iv_back_top = (ImageView) view.findViewById(R.id.iv_back_top);
        recycler = (RecyclerView) view.findViewById(R.id.recycler);
//        refreshLayout = (SmartRefreshLayout) view.findViewById(R.id.refreshLayout);
        viewpager = (ViewPager) view.findViewById(R.id.viewpager);
        tl_9 = (SlidingTabLayout) view.findViewById(R.id.tl_9);
        toolbar = (Toolbar) view.findViewById(R.id.toolbar);
        appbar = (AppBarLayout) view.findViewById(R.id.appbar);
//        tab_head=(SlidingTabLayout)view.findViewById(R.id.tab_head);
//        scrollowview=(MyScrollView) view.findViewById(R.id.scrollowview);

        tv_phone = (TextView) view.findViewById(R.id.tv_phone);
        tv_email = (TextView) view.findViewById(R.id.tv_email);
        iv_copy = (ImageView) view.findViewById(R.id.iv_copy);
        main_content = (CoordinatorLayout) view.findViewById(R.id.main_content);
        ll_tab = (LinearLayout) view.findViewById(R.id.ll_tab);
        ll_base = (RelativeLayout) view.findViewById(R.id.ll_base);
        edit_riyuebaohe.setText(flag + "");
        tv_title.setTextColor(mContext.getResources().getColor(R.color.white));
        ll_search.setBackground(mContext.getResources().getDrawable(R.drawable.yuanjiao24whire));
        iv_msg.setBackground(mContext.getResources().getDrawable(R.mipmap.home_message_white));
        rl_top.setBackgroundColor(Color.argb((int) 0, 255, 255, 255));//AGB由相关工具获得,或者美工提供
        ArticleHomeFragment.setScrollListener(this);
        ArticleHomeFragment.setArticleListener(this);
        Constants.isHoutai=false;

        mAdapter = new MyPagerAdapter(getActivity().getSupportFragmentManager());

        mXrvProduct = (XRecyclerView) view.findViewById(R.id.xrv_product);
        mXrvProduct.setLoadingMoreEnabled(false);

        mXrvProduct.setPullRefreshEnabled(true);
        mXrvProduct.setLoadingListener(this);
        mXrvProduct.setArrowImageView(R.mipmap.iconfont_downgrey);
        mXrvProduct.setRefreshProgressStyle(ProgressStyle.SysProgress);
        mXrvProduct.setNestedScrollingEnabled(true);

        final View headerView = mInflater.inflate(R.layout.fragment_home_banner/*fragmen_home_header*/, (ViewGroup) view.findViewById(android.R.id.content), false);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
        headerView.setLayoutParams(layoutParams);

        container = (BannerBgContainer) headerView.findViewById(R.id.banner_bg_container);
        loopLayout = (LoopLayout) headerView.findViewById(R.id.loop_layout);
        //状态栏高度
        int statusBarHeight = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen",
                "android");
        if (resourceId > 0) {
            statusBarHeight = getResources().getDimensionPixelSize(resourceId);
        }
        //屏幕高度
        DisplayMetrics dm = mContext.getApplicationContext().getResources().getDisplayMetrics();

        final float scale = dm.density;
        int i = (int) (54 * scale + 0.5f) + DensityUtil.dp2px(100);

//        //获取当前控件的布局对象
        ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) container.getLayoutParams();
        params.width = getScreenWidth();//设置当前控件布局的宽度
        params.height = getScreenWidth() * 1 / 2;//设置当前控件布局的高度
        container.setLayoutParams(params);//将设置好的布局参数应用到控件中

        layoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);

        mXrvProduct.setLayoutManager(layoutManager);
        mXrvProduct.addHeaderView(headerView);
        mHomeAdapter = new HomeAdapter(mContext, getActivity().getSupportFragmentManager(), getActivity(), dm.heightPixels - statusBarHeight - i + DensityUtil.dip2px(mContext, 50));
        mXrvProduct.setAdapter(mHomeAdapter);


        // 设置轮播图属性
        loopLayout.setLoop_ms(4000);//轮播的速度(毫秒)
        loopLayout.setLoop_duration(400);//滑动的速率(毫秒)
        loopLayout.setScaleAnimation(false);// 设置是否需要动画
        loopLayout.setLoop_style(LoopStyle.Empty);//轮播的样式-默认empty
        loopLayout.setIndicatorLocation(IndicatorLocation.Center);//指示器位置-中Center
        loopLayout.initializeData(mContext);


        // 设置监听
        loopLayout.setOnLoadImageViewListener(new OnDefaultImageViewLoader() {
            @Override
            public void onl oadImageView(ImageView view, Object object, int point) {
              /*  Glide.with(view.getContext())
                        .load(object)
                        .into(view);*/
                Glide.with(mContext)
                        .load(object)
                        .apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(DensityUtil.dp2px(12))))
                        .into(view);

                LogUtil2.log("position--" + point + "");

            }

        });

        loopLayout.setOnBannerItemClickListener(this);

        setScroll();


        RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.RESOURCE);//只缓存最终的图片
        //!isDestroy(getActivity()
        if (getActivity() != null) {
            Glide.with(getActivity()).load(R.mipmap.jingzhi)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.apply(options).into(iv_contact);
        }

        iv_contact.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (!AccountUtils.isLogin()) {
                    UIHelper.showLogin(mContext);
                    return;
                }

                SobotUtils.startSobot(getActivity());
            }
        });
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
            RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) rl_top.getLayoutParams();
            layoutParams2.height = dip2px(getActivity(), 80);
            rl_top.setLayoutParams(layoutParams2);

        } else {
            RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) rl_top.getLayoutParams();
            layoutParams2.height = dip2px(getActivity(), 70);
            rl_top.setLayoutParams(layoutParams2);
        }


        imageHeight = dip2px(getActivity(), 200);
        rl_title = (RelativeLayout) view.findViewById(R.id.rl_title);
        initListeners();

    }

    public void setScroll() {

        main_content.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        Log.i("滚动高度--tt", "按下");
                        if (getActivity() != null) {
                            Glide.with(getActivity()).load(R.mipmap.huadong2)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.into(iv_contact);
                            new Handler().postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    Glide.with(getActivity()).load(R.mipmap.jingzhi)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.into(iv_contact);
                                }
                            }, 1500);
                        }
                        break;
                    case MotionEvent.ACTION_MOVE:
                        Log.i("滚动高度--tt", "移动");
                        if (getActivity() != null) {
                            Glide.with(getActivity()).load(R.mipmap.huadong)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.into(iv_contact);
                        }
                        break;
                    case MotionEvent.ACTION_UP:
                        Log.i("滚动高度--tt", "抬起");
                        break;
                }
                return false;
            }
        });
        appbar.addOnOffsetChangedListener(new AppBarStateChangeListener() {
            @Override
            public void onStateChanged(AppBarLayout appBarLayout, State state) {

                if (state == State.EXPANDED) {

                    Log.i("滚动高度--", "展开");


                } else if (state == State.COLLAPSED) {

                    Log.i("滚动高度--", "折叠");

                    setpopLoad();
                } else {


                    Log.i("滚动高度--", "中间");

                }
            }
        });
        appbar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
            @Override
            public void onOffsetChanged(AppBarLayout appBarLayout, int i) {
                height = dip2px(mContext, 170);
                y = Math.abs(i);
                int alpha = 255 * y / (height);
                if (alpha > 255) {
                    alpha = 255;
                }
                if (alpha < 5) {
                    alpha = 0;
                }

                LogUtil2.log("滑动高度--off" + y + "--" + height + "--");
                if (y <= height) {
                    tv_title.setTextColor(mContext.getResources().getColor(R.color.white));
                    ll_search.setBackground(mContext.getResources().getDrawable(R.drawable.yuanjiao24whire));
                    iv_msg.setBackground(mContext.getResources().getDrawable(R.mipmap.home_message_white));
                    rl_top.setBackgroundColor(Color.argb((int) 0, 255, 255, 255));//AGB由相关工具获得,或者美工提供

                    StatusBarUtil.setStatusBarDarkTheme(getActivity(), false);
                } else if (y > height && y < height * 1.5) {
                    rl_top.setBackgroundColor(mContext.getResources().getColor(R.color.white));
                    tv_title.setTextColor(mContext.getResources().getColor(R.color.text_000000));
                    ll_search.setBackground(mContext.getResources().getDrawable(R.drawable.shape_search_product));
                    iv_msg.setBackground(mContext.getResources().getDrawable(R.mipmap.home_message_black));
                    rl_top.setBackgroundColor(mContext.getResources().getColor(R.color.white));
                    rl_top.setBackgroundColor(Color.argb((int) 127, 255, 255, 255));

                    StatusBarUtil.setStatusBarDarkTheme(getActivity(), true);
                } else if (y > height * 1.5) {
                    rl_top.setBackgroundColor(mContext.getResources().getColor(R.color.white));
                    tv_title.setTextColor(mContext.getResources().getColor(R.color.text_000000));
                    ll_search.setBackground(mContext.getResources().getDrawable(R.drawable.shape_search_product));
                    iv_msg.setBackground(mContext.getResources().getDrawable(R.mipmap.home_message_black));
                    rl_top.setBackgroundColor(Color.argb((int) 255, 255, 255, 255));

                    StatusBarUtil.setStatusBarDarkTheme(getActivity(), true);
                }
            }
        });
        mXrvProduct.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                LinearLayoutManager manager = (LinearLayoutManager) recyclerView.getLayoutManager();
                //获取当前可见条目得索引
                int firstVisibleItemPosition = manager.findFirstVisibleItemPosition();
                int lastVisibleItemPosition = manager.findLastCompletelyVisibleItemPosition();

                //获取当前可见条目得itemView
                View firstView = manager.findViewByPosition(firstVisibleItemPosition);
                //获取当前可见条目得itemView得高度
                height = firstView.getHeight();
                //获取当前可见条目得偏移量
                y = (firstVisibleItemPosition) * height - firstView.getTop();

                int alpha = 255 * y / (height);
                if (alpha > 255) {
                    alpha = 255;
                }
                if (alpha < 5) {
                    alpha = 0;
                }

                float scale = (float) dy / height;
                float alphat = (255 * scale);
                LogUtil2.log("滑动高度--" + y + "--" + height + "--");
                if (y == height) {
                    tv_title.setTextColor(mContext.getResources().getColor(R.color.white));
                    ll_search.setBackground(mContext.getResources().getDrawable(R.drawable.yuanjiao24whire));
                    iv_msg.setBackground(mContext.getResources().getDrawable(R.mipmap.home_message_white));
                    rl_top.setBackgroundColor(Color.argb((int) 0, 255, 255, 255));//AGB由相关工具获得,或者美工提供
                    StatusBarUtil.setStatusBarDarkTheme(getActivity(), false);
                } else if (y > height && y < height * 1.5) {
                    rl_top.setBackgroundColor(mContext.getResources().getColor(R.color.white));
                    tv_title.setTextColor(mContext.getResources().getColor(R.color.text_000000));
                    ll_search.setBackground(mContext.getResources().getDrawable(R.drawable.shape_search_product));
                    iv_msg.setBackground(mContext.getResources().getDrawable(R.mipmap.home_message_black));
                    rl_top.setBackgroundColor(mContext.getResources().getColor(R.color.white));
                    rl_top.setBackgroundColor(Color.argb((int) 127, 255, 255, 255));
                    StatusBarUtil.setStatusBarDarkTheme(getActivity(), true);
                } else if (y > height * 1.5) {
                    rl_top.setBackgroundColor(mContext.getResources().getColor(R.color.white));
                    tv_title.setTextColor(mContext.getResources().getColor(R.color.text_000000));
                    ll_search.setBackground(mContext.getResources().getDrawable(R.drawable.shape_search_product));
                    iv_msg.setBackground(mContext.getResources().getDrawable(R.mipmap.home_message_black));
                    rl_top.setBackgroundColor(Color.argb((int) 255, 255, 255, 255));

                    StatusBarUtil.setStatusBarDarkTheme(getActivity(), true);
                }


            }
        });

    }



    public void setpopLoad() {
        try {
            localVersionLoad = Utils.getVersionName(mContext);
        } catch (Exception e) {
            e.printStackTrace();
        }

        key = "show_home_load" + localVersion;
        LogUtil2.log("=========================>>>key" + key);
        LogUtil2.log("=========================>>>AccountUtils.getVersioncode()" + AccountUtils.getVersioncode());
        //是否是安装的第一次
        if (!AccountUtils.getVersioncodeHomeLoad().equals(key)) {
            AccountUtils.putVersioncodeHomeLoad(key);


            dialog = new CustomDialog(mContext, R.layout.pop_home_load, R.style.CustomDialogTheme);
            dialog.setCancelable(false);
            dialog.setCanceledOnTouchOutside(false);

            ImageView iv_one_button = (ImageView) dialog.findViewById(R.id.iv_one_button);

            iv_one_button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    dialog.dismiss();

                }
            });
            dialog.show();
        }

    }


    private void changeStatusBarTextColor(boolean isBlack) {
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
            if (isBlack) {
                getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//设置状态栏黑色字体
            } else {
                getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);//恢复状态栏白色字体
            }
        }
    }

    /**
     * 判断是否是全面屏
     */
    private volatile static boolean mHasCheckAllScreen;
    private volatile static boolean mIsAllScreenDevice;

    public static boolean isAllScreenDevice(Context context) {
        if (mHasCheckAllScreen) {
            return mIsAllScreenDevice;
        }
        mHasCheckAllScreen = true;
        mIsAllScreenDevice = false;
        // 低于 API 21的,都不会是全面屏。。。
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            return false;
        }
        WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        if (windowManager != null) {
            Display display = windowManager.getDefaultDisplay();
            Point point = new Point();
            display.getRealSize(point);
            float width, height;
            if (point.x < point.y) {
                width = point.x;
                height = point.y;
            } else {
                width = point.y;
                height = point.x;
            }
            if (height / width >= 1.97f) {
                mIsAllScreenDevice = true;
            }
        }
        return mIsAllScreenDevice;
    }

    private int dip2px(Context context, float dipValue) {
        Resources r = context.getResources();
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, r.getDisplayMetrics());
    }

    //判断Activity是否Destroy
    public static boolean isDestroy(Activity activity) {
        if (activity == null || activity.isFinishing() || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && activity.isDestroyed())) {
            return true;
        } else {
            return false;
        }
    }

    private void initListeners() {
        mXrvProduct.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                switch (newState) {
                    case 0:
                        LogUtil2.log("recyclerview已经停止滚动");

                        if (getActivity() != null) {
                            Glide.with(getActivity()).load(R.mipmap.huadong2)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.into(iv_contact);
                            new Handler().postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    Glide.with(getActivity()).load(R.mipmap.jingzhi)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.into(iv_contact);
                                }
                            }, 1500);
                        }

//                        Glide.with(getActivity()).load(R.mipmap.jingzhi).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv_contact);
                        break;
                    case 1:
                        LogUtil2.log("recyclerview正在被拖拽");

                        if (getActivity() != null) {
                            Glide.with(getActivity()).load(R.mipmap.huadong)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.into(iv_contact);
                        }


                        break;
                    case 2:
                        LogUtil2.log("recyclerview正在依靠惯性滚动");

                        if (getActivity() != null) {
                            Glide.with(getActivity()).load(R.mipmap.huadong)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.into(iv_contact);
                        }
                        break;
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);

            }
        });

    }

    @Override
    public void initData() {
        super.initData();
    }


    @Override
    public void onResume() {
        super.onResume();

    }


    /**
     * IMEI 全称�?International Mobile Equipment Identity,中文翻译为国际移动装备辨识码, 即�?常所说的手机序列号,
     * 用于在手机网络中识别每一部独立的手机,是国际上公认的手机标志序号,相当于移动电话的身份证。序列号共有15位数字,�?位(TAC)是型号核准号码�?
     * 代表手机类型。接�?位(FAC)是�?��装配号,代表产地。后6位(SNR)是串号,代表生产顺序号。最�?位(SP)一般为0,是�?��码,备用�?
     * 国际移动装备辨识码一般贴于机身背面与外包装上,同时也存在于手机记忆体中,通过输入*#06#即可查询�?
     *
     * @param
     * @return
     */

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (!hidden) {
            hidden2 = hidden;
            LogUtil2.log("==========================>>>onHiddenChangedHome" + hidden);


            loopLayout.stopLoop();// 页面销毁时需要停止
            loopLayout.startLoop();
            StatusBarUtil.setTranslucentStatus(getActivity());
            if (y <= height) {
                tv_title.setTextColor(mContext.getResources().getColor(R.color.white));
                ll_search.setBackground(mContext.getResources().getDrawable(R.drawable.yuanjiao24whire));
                iv_msg.setBackground(mContext.getResources().getDrawable(R.mipmap.home_message_white));
                rl_top.setBackgroundColor(Color.argb((int) 0, 255, 255, 255));//AGB由相关工具获得,或者美工提供

                StatusBarUtil.setStatusBarDarkTheme(getActivity(), false);
            } else if (y > height && y < height * 1.5) {
                rl_top.setBackgroundColor(mContext.getResources().getColor(R.color.white));
                tv_title.setTextColor(mContext.getResources().getColor(R.color.text_000000));
                ll_search.setBackground(mContext.getResources().getDrawable(R.drawable.shape_search_product));
                iv_msg.setBackground(mContext.getResources().getDrawable(R.mipmap.home_message_black));
                rl_top.setBackgroundColor(mContext.getResources().getColor(R.color.white));
                rl_top.setBackgroundColor(Color.argb((int) 127, 255, 255, 255));
//                        changeStatusBarTextColor(false);
//                        BarUtils.setColorNoTranslucent(getActivity(), getResources().getColor(R.color.transparent));
//                        BarUtils.setRootViewFitsSystemWindows(getActivity(), false);
                StatusBarUtil.setStatusBarDarkTheme(getActivity(), true);
            } else if (y > height * 1.5) {
                rl_top.setBackgroundColor(mContext.getResources().getColor(R.color.white));
                tv_title.setTextColor(mContext.getResources().getColor(R.color.text_000000));
                ll_search.setBackground(mContext.getResources().getDrawable(R.drawable.shape_search_product));
                iv_msg.setBackground(mContext.getResources().getDrawable(R.mipmap.home_message_black));
                rl_top.setBackgroundColor(Color.argb((int) 255, 255, 255, 255));
//                        changeStatusBarTextColor(true);
//                        BarUtils.setColorNoTranslucent(getActivity(), getResources().getColor(R.color.transparent));
//                        BarUtils.setRootViewFitsSystemWindows(getActivity(), false);
                StatusBarUtil.setStatusBarDarkTheme(getActivity(), true);
            }

        } else {
            hidden2 = hidden;
            LogUtil2.log("==========================>>>onHiddenChanged" + hidden);
            loopLayout.stopLoop();// 页面销毁时需要停止
            mHomeAdapter.setIsStop(true);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        if (requestCode == 1000) {
            if ((grantResults.length > 0) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
                UserBean query = UserBeanDao.query();

            } else {
                Toast.makeText(mContext, "手机IMEI权限未开启!", Toast.LENGTH_LONG).show();
            }
        }
    }

    public boolean checkIme() {
        int permissionCheck = ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE);

        if (permissionCheck != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions((Activity) mContext, new String[]{Manifest.permission.READ_PHONE_STATE}, 1000);
            return false;
        } else {
            //TODO
            return true;
        }
    }

    @Override
    protected void initListener() {
        super.initListener();
        iv_back_top.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                appbar.setExpanded(true, false);
                iv_back_top.setVisibility(View.GONE);
                EventManager.post(new RefreshHomeArticleEvent());
            }
        });
        ll_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!isLogin()) {
                    UIHelper.showLogin(mContext);
                    return;
                }

                UIHelper.showProductSearch(mContext);
            }
        });



    }


    @Override
    protected void onSuccess(String response, int id) {
        super.onSuccess(response, id);
        switch (id) {
            case 100:
                LogUtil2.log("=========================>>>100" + response.toString());
                mXrvProduct.refreshComplete();
//                refreshLayout.finishRefresh(2000/*,false*/);//传入false表示刷新失败
                HomeBean homeBean = GsonUtils.toObject(response, HomeBean.class);
                mHomePagePlatAdList = homeBean.homePagePlatAdList;
                if (null != mHomePagePlatAdList && !mHomePagePlatAdList.isEmpty()) {

                    setBannerLoop(mHomePagePlatAdList);

                }

                break;

            case 600://精选产品
                setRecommendData(response);
                break;

            case 700:
                LogUtil2.log("=========================>>>700" + response.toString());
                setHomeBeanADV(response);
                break;
            case 800://提醒中心
                setHomeBeanRemind(response);
                break;
            case 601://云学院推荐橱窗列表
                setRecommendDatas(response);
                break;

            case 603:
                RecommendListBean recommendListBean = GsonUtils.toObject(response, RecommendListBean.class);
                if (recommendListBean.recommendList != null) {
                    if (recommendListBean.recommendList.size() > 0) {
                        tv_search.setText(recommendListBean.recommendList.get(0));
                    }

                }
                break;
            case 604://滚动头条
                LogUtil2.log("首页文章--滚动条" + response.toString());
                setHomeAdviance(response);
                break;
            case 605://文章标题
                LogUtil2.log("首页文章--文章标题" + response.toString());
                ll_tab.setVisibility(View.VISIBLE);
                setHomeArticle(response);

                break;

        }
    }

    private void setHomeArticle(String response) {
        if (TextUtils.isEmpty(response)) {
            return;
        }

        final FindClassifysBean bean = GsonUtils.toObject(response, FindClassifysBean.class);
        if (bean!=null){

            if (!isFirstTab) {
                if (articleClassifyList != null && bean.articleClassifyList.size() == articleClassifyList.size()) {
                    for (int i = 0; i < bean.articleClassifyList.size(); i++) {
                        for (int j = 0; j < articleClassifyList.size(); j++) {
                            if (bean.articleClassifyList.get(i).uuid.equals(articleClassifyList.get(j).uuid)) {
                                isSame = false;
                            }
                        }

                    }
                }

            }
            LogUtil2.log("第一次加载--"+isSame+"---"+isFirstTab+"--"+isRemind+"---"+isHoutai);
            if (isRemind) {
                isRemind=false;
                if (!isSame) {
                    isSame = true;
                    return;
                }
            }else {


                appbar.setExpanded(true, false);
                iv_back_top.setVisibility(View.GONE);
            }

        }


        isFirstTab=false;
        articleClassifyList = bean.articleClassifyList;

//        mHomeAdapter.setHomeArticle(bean);
        if (bean.articleClassifyList != null && bean.articleClassifyList.size() > 0) {
            mFragments.clear();
            mTitles.clear();
            for (int i = 0; i < bean.articleClassifyList.size(); i++) {
                ArticleClassifyListBean bean2 = bean.articleClassifyList.get(i);

                mTitles.add(bean2.name);
                Bundle b = new Bundle();
                b.putSerializable("bean", bean.articleClassifyList.get(i));
                b.putInt("positionClick", i);
                b.putSerializable("company",companyBaseBean);
                Fragment f = new ArticleHomeFragment()/*ArticleHomeFragment()*/;
                f.setArguments(b);
                mFragments.add(f);
            }
            if (getActivity() != null) {

                viewpager.setAdapter(mAdapter);
                tl_9.setViewPager(viewpager,mTitles);
                tl_9.setCurrentTab(0);
                viewpager.setCurrentItem(0);

                setTab();
                if (!isFirstLay){
                    LogUtil2.log("刷新--");
                    mAdapter.setNewFragments();
                }

                isFirstLay = false;

            }
        }


    }

    @Override
    public void onPause() {
        super.onPause();
        Log.i("滚动高度--onPause", "展开");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.i("滚动高度--onStop", "展开");
        if (isRemind){
            isOther=true;
        }
        if (appbarState == 1) {
            Log.i("滚动高度--", "展开");
            //展开状态

        } else if (appbarState == 2) {
            Log.i("滚动高度--", "折叠");
            //折叠状态

        }  else if (appbarState ==3){

            Log.i("滚动高度--", "中间");
            //中间状态

        }
    }

    public void setTab() {


        tl_9.setTextUnselectColor(getResources().getColor(R.color.text_000000));
        tl_9.setTextSelectColor(getResources().getColor(R.color.white));
        tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_1A75FF));
        tl_9.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                if (position % 9 == 0) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_1A75FF));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_1A75FF));
                } else if (position % 9 == 1) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_F05F12));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_F05F12));
                } else if (position % 9 == 2) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_DD8033));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_DD8033));
                } else if (position % 9 == 3) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_14BEDF));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_14BEDF));
                } else if (position % 9 == 4) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_2B2EF5));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_2B2EF5));
                } else if (position % 9 == 5) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_EEB01F));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_EEB01F));
                } else if (position % 9 == 6) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_E92A4B));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_E92A4B));
                } else if (position % 9 == 7) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_00C99E));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_00C99E));
                } else if (position % 9 == 8) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_299BF5));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_299BF5));
                }
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int position) {
//            tab_head.setCurrentTab(position);
//                if (!isFirstLay){
                if (mFragments != null && mFragments.size() > 0 && articleClassifyList != null && articleClassifyList.size() > 0) {
                    ArticleHomeFragment fragment = (ArticleHomeFragment) mFragments.get(position);
                    fragment.setRefresh(position, articleClassifyList.get(position));
                }
//                }
//
                if (position % 9 == 0) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_1A75FF));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_1A75FF));
                } else if (position % 9 == 1) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_F05F12));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_F05F12));
                } else if (position % 9 == 2) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_DD8033));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_DD8033));
                } else if (position % 9 == 3) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_14BEDF));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_14BEDF));
                } else if (position % 9 == 4) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_2B2EF5));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_2B2EF5));
                } else if (position % 9 == 5) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_EEB01F));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_EEB01F));
                } else if (position % 9 == 6) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_E92A4B));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_E92A4B));
                } else if (position % 9 == 7) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_00C99E));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_00C99E));
                } else if (position % 9 == 8) {
                    tl_9.setIndicatorColor(mContext.getResources().getColor(R.color.name_299BF5));
//                tab_head.setIndicatorColor(mContext.getResources().getColor(R.color.name_299BF5));
                }

            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });



    }

    @Override
    public void onClickArticle(boolean isremind) {
        LogUtil2.log("isRemind----"+isremind);
        isRemind=isremind;
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {

        private List<String> tags;//标示fragment的tag
        private FragmentManager fragmentManager;

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
            this.tags = new ArrayList<>();
            this.fragmentManager = fm;
        }
//        public MyPagerAdapter(FragmentManager fm) {
//            super(fm);
//        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles.get(position);
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }

        @Override
        public int getItemPosition(@NonNull Object object) {
            return POSITION_NONE;
        }
        //这个就不说了
        private String makeFragmentName(int viewId, long id) {
            return "android:switcher:" + viewId + ":" + id;
        }
        @NonNull
        @Override
        public Object instantiateItem(@NonNull ViewGroup container, int position) {
            tags.add(makeFragmentName(container.getId(), getItemId(position)));
            Fragment fragment = (Fragment) super.instantiateItem(container, position);
            this.fragmentManager.beginTransaction().show(fragment).commitAllowingStateLoss();
            return fragment;
        }
        //根据tag查找缓存的fragment,移除缓存的fragment,替换成新的
        public void setNewFragments() {
            if (this.tags != null) {
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                for (int i = 0; i < tags.size(); i++) {
                    fragmentTransaction.remove(fragmentManager.findFragmentByTag(tags.get(i)));
                }
                fragmentTransaction.commitAllowingStateLoss();
                fragmentManager.executePendingTransactions();
                tags.clear();
            }
            notifyDataSetChanged();
        }
    }

    private void setBannerLoop(List<HomeBannerBean> mHomePagePlatAdList) {
        // 准备数据
        ArrayList<BannerInfo> bannerInfos = new ArrayList<>();
        List<String> bgList = new ArrayList<>();
        for (int i = 0; i < mHomePagePlatAdList.size(); i++) {
            bannerInfos.add(new BannerInfo(mHomePagePlatAdList.get(i).imageUrl, mHomePagePlatAdList.get(i).url));
            bgList.add(mHomePagePlatAdList.get(i).imageColour);
        }

        if (bannerInfos.size() == 0) {
            return;
        }
        if (bgList.size() == 0) {
            return;
        }
        loopLayout.setLoopData(bannerInfos);// 设置轮播数据
        if (bgList != null && mContext != null) {
            container.setBannerBackBg(mContext, bgList);// 背景容器设置轮播图片
        }
        loopLayout.setBannerBgContainer(container);
        loopLayout.stopLoop();
        loopLayout.startLoop();
    }

    private void setRecommendDatas(String response) {
        if (TextUtils.isEmpty(response)) {
            return;
        }
        FaXianListsBean bean = GsonUtils.toObject(response, FaXianListsBean.class);
//        KeChengRecommendsBean recommendsBean=bean.courseRecommends.get(0);
        mHomeAdapter.setHomeKeCheng(bean);
    }

    public static <T> List<T> getObjectList(String jsonString, Class<T> cls) {
        List<T> list = new ArrayList<T>();
        try {
            Gson gson = new Gson();
            JsonArray arry = new JsonParser().parse(jsonString).getAsJsonArray();
            for (JsonElement jsonElement : arry) {
                list.add(gson.fromJson(jsonElement, cls));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    private void setRecommendData(String response) {
        if (TextUtils.isEmpty(response)) {
            return;
        }
        HomeProductBean homeProductBean = GsonUtils.toObject(response, HomeProductBean.class);
//        List<HomeBottomProductBean> homeBean =/*GsonUtils.toList*/getObjectList(response, HomeBottomProductBean.class);

        mHomeAdapter.setHomeBean(homeProductBean);
    }

    private void setHomeBeanADV(String response) {
        HomeBean homeBean2 = GsonUtils.toObject(response, HomeBean.class);
        mHomeAdapter.setHomeBeanADV(homeBean2);
    }

    private void setHomeBeanRemind(String response) {
        if (TextUtils.isEmpty(response)) {
            return;
        }
        final KaoShiStatussBean bean = GsonUtils.toObject(response, KaoShiStatussBean.class);
        mHomeAdapter.setHomeRemind(bean);
    }

    private void setHomeAdviance(String response) {
        if (TextUtils.isEmpty(response)) {
            return;
        }

        final HeadHomeBean bean = GsonUtils.toObject(response, HeadHomeBean.class);

        mHomeAdapter.setHomeAdviance(bean);
    }



    @Override
    public void onTabReselect() {
        LogUtil.e(LogUtil.CQ, "onTabReselect HomeFragment");
    }


    /**
     * 生成一个0 到 count 之间的随机数
     *
     * @param endNum
     * @return
     */
    public int getNum(int endNum) {
        if (endNum > 0) {
            Random random = new Random();
            return random.nextInt(endNum);
        }
        return 0;
    }

    /**
     * banner点击事件
     *
     * @param position position
     */
    @Override
    public void onItemClick(int position) {
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventManager.unregister(this);
        loopLayout.stopLoop();// 页面销毁时需要停止
        mHomeAdapter.setIsStop(true);

        if(iv_contact != null &&  !getActivity().isDestroyed()){
            Glide.with(getContext()).clear(iv_contact);
            iv_contact = null;
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();

    }

    public static SetOnclickInterface listenersTOP;


    @Override
    public void onRefresh() {
    }

    @Override
    public void onl oadMore() {

    }

    /**
     * banner滚动轮播
     *
     * @param position
     * @param banner
     */
    @Override
    public void onBannerClick(int position, ArrayList<BannerInfo> banner) {

    }

    @Override
    public void onChildScroll(RecyclerView recyclerView, int newState) {
        switch (newState) {
            case 0:
                LogUtil2.log("recyclerview已经停止滚动");

                if (getActivity() != null) {
                    Glide.with(getActivity()).load(R.mipmap.huadong2)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.into(iv_contact);
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            Glide.with(getActivity()).load(R.mipmap.jingzhi)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.into(iv_contact);
                        }
                    }, 1500);
                }

                break;
            case 1:
                LogUtil2.log("recyclerview正在被拖拽");

                if (getActivity() != null) {
                    Glide.with(getActivity()).load(R.mipmap.huadong)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.into(iv_contact);
                }

                break;
            case 2:
                LogUtil2.log("recyclerview正在依靠惯性滚动");

                if (getActivity() != null) {
                    Glide.with(getActivity()).load(R.mipmap.huadong)/*.asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE)*/.into(iv_contact);
                }
                break;
        }
    }

}

 

标签:liming,mContext,顶部,private,import,Android,com,上拉吸,getResources
来源: https://blog.csdn.net/qq_35821446/article/details/112237660