|
| 1 | +package com.code4a.jlibrarydemo.home.frag.home.one; |
| 2 | + |
| 3 | +import android.content.Intent; |
| 4 | +import android.net.Uri; |
| 5 | +import android.os.Bundle; |
| 6 | +import android.view.LayoutInflater; |
| 7 | +import android.view.View; |
| 8 | +import android.widget.ImageView; |
| 9 | +import android.widget.Toast; |
| 10 | + |
| 11 | +import com.bumptech.glide.Glide; |
| 12 | +import com.code4a.jlibrary.base.BaseFragment; |
| 13 | +import com.code4a.jlibrary.utils.ToastUtil; |
| 14 | +import com.code4a.jlibrarydemo.R; |
| 15 | +import com.daimajia.androidanimations.library.Techniques; |
| 16 | +import com.daimajia.androidanimations.library.YoYo; |
| 17 | +import com.daimajia.androidviewhover.BlurLayout; |
| 18 | +import com.youth.banner.Banner; |
| 19 | +import com.youth.banner.BannerConfig; |
| 20 | +import com.youth.banner.Transformer; |
| 21 | +import com.youth.banner.listener.OnBannerClickListener; |
| 22 | +import com.youth.banner.listener.OnLoadImageListener; |
| 23 | + |
| 24 | +import butterknife.BindView; |
| 25 | + |
| 26 | + |
| 27 | +public class OneFragment extends BaseFragment { |
| 28 | + |
| 29 | + @BindView(R.id.banner) |
| 30 | + Banner banner; |
| 31 | + |
| 32 | + @BindView(R.id.blur_layout) |
| 33 | + BlurLayout mSampleLayout; |
| 34 | + @BindView(R.id.blur_layout2) |
| 35 | + BlurLayout mSampleLayout2; |
| 36 | + @BindView(R.id.blur_layout3) |
| 37 | + BlurLayout mSampleLayout3; |
| 38 | + @BindView(R.id.blur_layout4) |
| 39 | + BlurLayout mSampleLayout4; |
| 40 | + |
| 41 | + String[] images,titles; |
| 42 | + |
| 43 | + public static OneFragment getInstance() { |
| 44 | + OneFragment oneFragment = new OneFragment(); |
| 45 | + return oneFragment; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + protected void initView(View view, Bundle savedInstanceState) { |
| 50 | + initBanner(); |
| 51 | + initHoverView(); |
| 52 | + } |
| 53 | + |
| 54 | + private void initHoverView() { |
| 55 | + BlurLayout.setGlobalDefaultDuration(450); |
| 56 | + View hover = LayoutInflater.from(getHoldingActivity()).inflate(R.layout.hover_sample, null); |
| 57 | + hover.findViewById(R.id.heart).setOnClickListener(new View.OnClickListener() { |
| 58 | + @Override |
| 59 | + public void onClick(View v) { |
| 60 | + YoYo.with(Techniques.Tada) |
| 61 | + .duration(550) |
| 62 | + .playOn(v); |
| 63 | + } |
| 64 | + }); |
| 65 | + hover.findViewById(R.id.share).setOnClickListener(new View.OnClickListener() { |
| 66 | + @Override |
| 67 | + public void onClick(View v) { |
| 68 | + YoYo.with(Techniques.Swing) |
| 69 | + .duration(550) |
| 70 | + .playOn(v); |
| 71 | + } |
| 72 | + }); |
| 73 | + mSampleLayout.setHoverView(hover); |
| 74 | + mSampleLayout.setBlurDuration(550); |
| 75 | + mSampleLayout.addChildAppearAnimator(hover, R.id.heart, Techniques.FlipInX, 550, 0); |
| 76 | + mSampleLayout.addChildAppearAnimator(hover, R.id.share, Techniques.FlipInX, 550, 250); |
| 77 | + mSampleLayout.addChildAppearAnimator(hover, R.id.more, Techniques.FlipInX, 550, 500); |
| 78 | + |
| 79 | + mSampleLayout.addChildDisappearAnimator(hover, R.id.heart, Techniques.FlipOutX, 550, 500); |
| 80 | + mSampleLayout.addChildDisappearAnimator(hover, R.id.share, Techniques.FlipOutX, 550, 250); |
| 81 | + mSampleLayout.addChildDisappearAnimator(hover, R.id.more, Techniques.FlipOutX, 550, 0); |
| 82 | + |
| 83 | + mSampleLayout.addChildAppearAnimator(hover, R.id.description, Techniques.FadeInUp); |
| 84 | + mSampleLayout.addChildDisappearAnimator(hover, R.id.description, Techniques.FadeOutDown); |
| 85 | + |
| 86 | + View hover2 = LayoutInflater.from(getHoldingActivity()).inflate(R.layout.hover_sample2, null); |
| 87 | + hover2.findViewById(R.id.avatar).setOnClickListener(new View.OnClickListener() { |
| 88 | + @Override |
| 89 | + public void onClick(View v) { |
| 90 | + Toast.makeText(getHoldingActivity(), "Pretty Cool, Right?", Toast.LENGTH_SHORT).show(); |
| 91 | + } |
| 92 | + }); |
| 93 | + mSampleLayout2.setHoverView(hover2); |
| 94 | + |
| 95 | + mSampleLayout2.addChildAppearAnimator(hover2, R.id.description, Techniques.FadeInUp); |
| 96 | + mSampleLayout2.addChildDisappearAnimator(hover2, R.id.description, Techniques.FadeOutDown); |
| 97 | + mSampleLayout2.addChildAppearAnimator(hover2, R.id.avatar, Techniques.DropOut, 1200); |
| 98 | + mSampleLayout2.addChildDisappearAnimator(hover2, R.id.avatar, Techniques.FadeOutUp); |
| 99 | + mSampleLayout2.setBlurDuration(1000); |
| 100 | + |
| 101 | + View hover3 = LayoutInflater.from(getHoldingActivity()).inflate(R.layout.hover_sample3, null); |
| 102 | + mSampleLayout3.setHoverView(hover3); |
| 103 | + mSampleLayout3.addChildAppearAnimator(hover3, R.id.eye, Techniques.Landing); |
| 104 | + mSampleLayout3.addChildDisappearAnimator(hover3, R.id.eye, Techniques.TakingOff); |
| 105 | + mSampleLayout3.enableZoomBackground(true); |
| 106 | + mSampleLayout3.setBlurDuration(1200); |
| 107 | + |
| 108 | + View hover4 = LayoutInflater.from(getHoldingActivity()).inflate(R.layout.hover_sample4,null); |
| 109 | + mSampleLayout4.setHoverView(hover4); |
| 110 | + mSampleLayout4.addChildAppearAnimator(hover4, R.id.cat, Techniques.SlideInLeft); |
| 111 | + mSampleLayout4.addChildAppearAnimator(hover4, R.id.mail, Techniques.SlideInRight); |
| 112 | + |
| 113 | + mSampleLayout4.addChildDisappearAnimator(hover4, R.id.cat, Techniques.SlideOutLeft); |
| 114 | + mSampleLayout4.addChildDisappearAnimator(hover4, R.id.mail, Techniques.SlideOutRight); |
| 115 | + |
| 116 | + mSampleLayout4.addChildAppearAnimator(hover4, R.id.content, Techniques.BounceIn); |
| 117 | + mSampleLayout4.addChildDisappearAnimator(hover4, R.id.content, Techniques.FadeOutUp); |
| 118 | + |
| 119 | + |
| 120 | + hover4.findViewById(R.id.cat).setOnClickListener(new View.OnClickListener() { |
| 121 | + @Override |
| 122 | + public void onClick(View v) { |
| 123 | + Intent getWebPage = new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/code4a")); |
| 124 | + startActivity(getWebPage); |
| 125 | + } |
| 126 | + }); |
| 127 | + |
| 128 | + hover4.findViewById(R.id.mail).setOnClickListener(new View.OnClickListener() { |
| 129 | + @Override |
| 130 | + public void onClick(View v) { |
| 131 | + final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); |
| 132 | + |
| 133 | + emailIntent.setType("plain/text"); |
| 134 | + emailIntent. putExtra( android. content. Intent. EXTRA_EMAIL, new String[]{ "[email protected]"}); |
| 135 | + emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "About AndroidViewHover"); |
| 136 | + emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "I have a good idea about this project.."); |
| 137 | + |
| 138 | + startActivity(Intent.createChooser(emailIntent, "Send mail...")); |
| 139 | + } |
| 140 | + }); |
| 141 | + } |
| 142 | + |
| 143 | + private void initBanner() { |
| 144 | + images= getResources().getStringArray(R.array.url); |
| 145 | + titles= getResources().getStringArray(R.array.title); |
| 146 | + |
| 147 | + //显示圆形指示器和标题 |
| 148 | + banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR_TITLE_INSIDE); |
| 149 | + //设置标题列表 |
| 150 | + banner.setBannerTitle(titles); |
| 151 | + //设置动画 |
| 152 | + banner.setBannerAnimation(Transformer.CubeOut); |
| 153 | + /** |
| 154 | + * 可以选择设置图片网址或者资源文件,默认用Glide加载 |
| 155 | + * 如果你想设置默认图片就在xml里设置default_image |
| 156 | + * banner.setImages(images); |
| 157 | + */ |
| 158 | + //如果你想用自己项目的图片加载,那么----->自定义图片加载框架 |
| 159 | + banner.setImages(images, new OnLoadImageListener() { |
| 160 | + @Override |
| 161 | + public void OnLoadImage(ImageView view, Object url) { |
| 162 | + /** |
| 163 | + * 这里你可以根据框架灵活设置 |
| 164 | + */ |
| 165 | + Glide.with(getHoldingActivity()) |
| 166 | + .load(url) |
| 167 | + .into(view); |
| 168 | + } |
| 169 | + }); |
| 170 | + //设置点击事件 |
| 171 | + banner.setOnBannerClickListener(new OnBannerClickListener() { |
| 172 | + @Override |
| 173 | + public void OnBannerClick(int position) { |
| 174 | + ToastUtil.showShort(getHoldingActivity(), "你点击了:"+position); |
| 175 | + } |
| 176 | + }); |
| 177 | + } |
| 178 | + |
| 179 | + @Override |
| 180 | + protected int getLayoutId() { |
| 181 | + return R.layout.fragment_home_one; |
| 182 | + } |
| 183 | +} |
0 commit comments