BuWanVideo/res/drawable-xhdpi/icon_search_hot.png
BuWanVideo/res/drawable/shape_search_rank_item_bg.xml
New file @@ -0,0 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/white" /> <stroke android:width="1dp" android:color="#FFECC5" /> <corners android:radius="6dp" /> </shape> BuWanVideo/res/drawable/shape_search_rank_item_bottom_bg.xml
New file @@ -0,0 +1,11 @@ <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#FFFFFF" /> <corners android:bottomLeftRadius="6dp" android:bottomRightRadius="6dp" /> </shape> BuWanVideo/res/drawable/shape_search_rank_item_top_bg.xml
New file @@ -0,0 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#ffffecec" /> <gradient android:angle="90" android:centerColor="#ffffffff" android:endColor="#fffff8e5" android:startColor="#ffffffff" android:type="linear" android:useLevel="true" /> <corners android:topLeftRadius="6dp" android:topRightRadius="6dp" /> </shape> BuWanVideo/res/layout/item_cate_recommend_top.xml
@@ -2,36 +2,26 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <com.lcjian.library.widget.RatioLayout xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/rl_banner" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginBottom="2dp" app:ratio="0.4375"> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="8dp" android:paddingRight="8dp"> <androidx.viewpager.widget.ViewPager android:layout_width="match_parent" android:layout_height="match_parent"> <com.lzj.gallery.library.views.BannerViewPager android:id="@+id/vp_recommend" android:layout_width="match_parent" android:layout_height="match_parent" /> android:layout_height="wrap_content"></com.lzj.gallery.library.views.BannerViewPager> <com.viewpagerindicator.CirclePageIndicator android:id="@+id/indicator_recommend" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:padding="10dip" app:fillColor="@color/banner_indicator_highlight_color" app:pageColor="#aaffffff" app:radius="5dp" app:strokeColor="#00000000" /> </FrameLayout> BuWanVideo/res/layout/item_search_rank.xml
New file @@ -0,0 +1,36 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/shape_search_rank_item_bg" android:orientation="vertical" android:padding="1dp"> <TextView android:id="@+id/tv_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/shape_search_rank_item_top_bg" android:padding="15dp" android:text="热搜榜" android:textColor="@color/item_title_text_color" android:textSize="14sp" android:textStyle="bold"></TextView> <com.lcjian.library.widget.MyGridView android:id="@+id/gv_content" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="-1dp" android:background="@drawable/shape_search_rank_item_bottom_bg" android:horizontalSpacing="20dp" android:listSelector="@null" android:numColumns="2" android:paddingLeft="15dp" android:paddingRight="15dp" android:paddingBottom="15dp" android:verticalSpacing="11dp"></com.lcjian.library.widget.MyGridView> </LinearLayout> BuWanVideo/res/layout/item_search_rank_content.xml
New file @@ -0,0 +1,30 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:orientation="horizontal"> <TextView android:id="@+id/tv_rank" android:layout_width="17dp" android:layout_height="17dp" android:gravity="center" android:textColor="@color/white" android:textSize="11sp" /> <TextView android:id="@+id/tv_content" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginLeft="12.5dp" android:layout_weight="1" android:ellipsize="end" android:lines="1" android:textColor="@color/search_item_text_color" android:textSize="12sp" /> </LinearLayout> BuWanVideo/res/layout/search_actvity.xml
@@ -74,67 +74,35 @@ android:layout_weight="1"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> android:layout_height="match_parent" android:paddingLeft="11dp" android:paddingRight="11dp" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginTop="5dp" android:layout_marginRight="10dp" android:orientation="vertical"> <LinearLayout <com.lcjian.library.widget.MyGridView android:id="@+id/gv_hot_search" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> android:numColumns="1" android:paddingTop="8dp" android:layout_marginBottom="10dp" android:paddingBottom="8dp" android:stretchMode="columnWidth" android:verticalSpacing="19dp"></com.lcjian.library.widget.MyGridView> <TextView style="@style/TextBuleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="8dp" android:text="@string/hot_search" android:textColor="@color/item_title_text_color" android:textSize="16sp" /> <com.lcjian.library.widget.MyGridView android:id="@+id/gv_hot_search" android:layout_width="match_parent" android:layout_height="wrap_content" android:horizontalSpacing="8dp" android:numColumns="2" android:paddingLeft="8dp" android:paddingTop="8dp" android:paddingRight="8dp" android:paddingBottom="8dp" android:stretchMode="columnWidth" android:verticalSpacing="8dp"></com.lcjian.library.widget.MyGridView> </LinearLayout> <FrameLayout android:id="@+id/fl_advertisement" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:paddingLeft="8dp" android:paddingRight="8dp"> <ImageView android:id="@+id/iv_search_ad" android:layout_width="match_parent" android:layout_height="wrap_content" /> </FrameLayout> <LinearLayout android:id="@+id/ll_search_history" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:orientation="vertical"> <RelativeLayout @@ -145,8 +113,8 @@ style="@style/TextBuleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="8dp" android:text="@string/history_search" android:textStyle="bold" android:textColor="@color/item_title_text_color" android:textSize="16sp" /> @@ -157,34 +125,61 @@ android:layout_alignParentRight="true" android:layout_centerVertical="true" android:drawableLeft="@drawable/ic_history_delete" android:padding="8dp" android:textColor="@color/gray" /> </RelativeLayout> <com.lcjian.library.widget.MyGridView android:id="@+id/gv_history_search" <com.lcjian.library.widget.FlowLayout android:id="@+id/fl_history_search" android:layout_width="match_parent" android:layout_height="wrap_content" android:horizontalSpacing="8dp" android:numColumns="2" android:paddingLeft="8dp" android:paddingTop="8dp" android:paddingRight="8dp" android:paddingBottom="8dp" android:stretchMode="columnWidth" android:verticalSpacing="8dp"></com.lcjian.library.widget.MyGridView> android:layout_height="wrap_content"> </com.lcjian.library.widget.FlowLayout> </LinearLayout> <HorizontalScrollView android:layout_width="match_parent" android:layout_height="wrap_content" android:scrollbars="none"> <LinearLayout android:id="@+id/ll_search_rank" android:layout_width="match_parent" android:layout_height="wrap_content" android:paddingTop="10dp"> </LinearLayout> </HorizontalScrollView> <FrameLayout android:id="@+id/fl_advertisement" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:layout_marginBottom="10dp"> <ImageView android:id="@+id/iv_search_ad" android:layout_width="match_parent" android:layout_height="wrap_content" /> </FrameLayout> </LinearLayout> </ScrollView> <FrameLayout android:visibility="gone" android:id="@+id/fl_suggest" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/page_content_bg_color"></FrameLayout> android:background="@color/page_content_bg_color" android:visibility="gone"></FrameLayout> </FrameLayout> BuWanVideo/res/layout/suggestion_grid_item.xml
@@ -9,17 +9,13 @@ android:id="@+id/tv_suggestion" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/shape_search_keyword_bg" android:drawableLeft="@drawable/icon_search_hot" android:drawablePadding="10dp" android:ellipsize="end" android:gravity="left" android:paddingLeft="10dp" android:paddingTop="5dp" android:paddingRight="10dp" android:paddingBottom="5dp" android:singleLine="true" android:text="123123" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@color/search_item_text_color" android:textSize="12sp" /> android:textSize="13sp" /> </LinearLayout> BuWanVideo/src/com/weikou/beibeivideo/BeibeiVideoAPI.java
@@ -622,8 +622,14 @@ public static void getHotSearch(Context context, String uid, ResponseHandlerInterface handler) { LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); params.put("Method", "getHotSearch"); params.put("Method", "getHotSearchNew"); params.put("Uid", uid); commonPost(context, BASE_URL + "user", params, handler); } public static void getSearchRank(Context context, ResponseHandlerInterface handler) { LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); params.put("Method", "getSearchRank"); commonPost(context, BASE_URL + "user", params, handler); } @@ -1173,7 +1179,7 @@ * @param handler */ public static void getVideoEpisodeList(Context context, String uid, String ResourceId, String videoId, int page,int pageSize, String ResourceId, String videoId, int page, int pageSize, ResponseHandlerInterface handler) { LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); params.put("Method", "getVideoEpisodeList"); BuWanVideo/src/com/weikou/beibeivideo/ui/baidu/BaiDuNewsFragment.java
@@ -5,8 +5,11 @@ import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.viewpager.widget.ViewPager; import android.os.Parcelable; import android.util.Log; import android.view.View; import android.widget.FrameLayout; @@ -161,7 +164,7 @@ initCacheData(); } class ContentAdapter extends FragmentStatePagerAdapter { class ContentAdapter extends FragmentPagerAdapter { private FragmentManager fm; private List<BaiDuCPUType> mlist; @@ -198,6 +201,10 @@ return mlist.get(position).getName(); } @Override public Parcelable saveState() { return null; } } @Override BuWanVideo/src/com/weikou/beibeivideo/ui/baidu/BaiDuVideosFragment.java
@@ -1,11 +1,15 @@ package com.weikou.beibeivideo.ui.baidu; import android.os.Bundle; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.viewpager.widget.ViewPager; import android.os.Parcelable; import android.view.View; import android.widget.FrameLayout; import android.widget.LinearLayout; @@ -149,7 +153,7 @@ indicator.setViewPager(viewPager, 0); } class ContentAdapter extends FragmentStatePagerAdapter { class ContentAdapter extends FragmentPagerAdapter { private FragmentManager fm; private List<BaiDuCPUType> mlist; @@ -185,6 +189,11 @@ public CharSequence getPageTitle(int position) { return mlist.get(position).getName(); } @Override public Parcelable saveState() { return null; } } } BuWanVideo/src/com/weikou/beibeivideo/ui/category/CategoryRecommendAdapter.java
@@ -3,21 +3,25 @@ import android.app.Activity; import android.graphics.Canvas; import android.graphics.Rect; import androidx.annotation.NonNull; import androidx.viewpager.widget.ViewPager; import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.RelativeLayout; import com.lcjian.library.util.common.DimenUtils; import com.lzj.gallery.library.views.BannerViewPager; import com.viewpagerindicator.CirclePageIndicator; import com.weikou.beibeivideo.entity.CategoryRecommendVideo; import com.weikou.beibeivideo.entity.VideoInfo; import com.weikou.beibeivideo.entity.VideoType; import com.weikou.beibeivideo.ui.video.VideoColumn2Adapter; import com.weikou.beibeivideo.R; import com.weikou.beibeivideo.util.ad.HomeAdUtil; import java.util.ArrayList; import java.util.List; @@ -168,17 +172,34 @@ return; if (viewHolder.vp_recommend == null) return; if (viewHolder.indicator_recommend == null) return; if (bannerList == null || bannerList.size() == 0) { viewHolder.rl_banner.setVisibility(View.GONE); } else { viewHolder.rl_banner.setVisibility(View.VISIBLE); CategoryRecommedTopAdapter topAdapter = new CategoryRecommedTopAdapter(bannerList, mContext); viewHolder.vp_recommend.setAdapter(topAdapter); viewHolder.indicator_recommend.setViewPager(viewHolder.vp_recommend); autoPlayBanner(viewHolder.vp_recommend); List<String> urlList = new ArrayList<>(); for (CategoryRecommendVideo banner : bannerList) { urlList.add(banner.getPicture()); } float ratio = 0.4375f; viewHolder.vp_recommend.initBanner(urlList, false, ratio)//开启3D画廊效果 .addPageMargin((int) (com.weikou.beibeivideo.util.DimenUtils.dip2px(mContext, 1) * 1.5), com.weikou.beibeivideo.util.DimenUtils.dip2px(mContext, 3))//参数1page之间的间距,参数2中间item距离边界的间距 // .addPointMargin(5)//指示器点间距 .addStartTimer(3)//自动轮播3秒间隔 // .addPointBottom(0)//底部间距 .addDefaultImg(R.drawable.shape_video_list_cover_placeholder) .addRoundCorners(com.weikou.beibeivideo.util.DimenUtils.dip2px(mContext, 8))//圆角 .finishConfig()//这句必须加 .addBannerListener(new BannerViewPager.OnClickBannerListener() { @Override public void onBannerClick(int position) { if (position >= bannerList.size()) return; // HomeAdUtil.jump(bannerList.get(position), getActivity()); } }); } } else { @@ -214,14 +235,12 @@ } class BannerHolder extends RecyclerView.ViewHolder { ViewPager vp_recommend; CirclePageIndicator indicator_recommend; BannerViewPager vp_recommend; RelativeLayout rl_banner; public BannerHolder(View itemView) { super(itemView); vp_recommend = itemView.findViewById(R.id.vp_recommend); indicator_recommend = itemView.findViewById(R.id.indicator_recommend); rl_banner = itemView.findViewById(R.id.rl_banner); } } BuWanVideo/src/com/weikou/beibeivideo/ui/main/HomeFragment.java
@@ -7,12 +7,15 @@ import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentStatePagerAdapter; import androidx.viewpager.widget.ViewPager; import android.os.Parcelable; import android.view.View; import android.widget.FrameLayout; import android.widget.LinearLayout; @@ -360,5 +363,10 @@ else return mlist.get(position).getName(); } @Override public Parcelable saveState() { return null; } } } BuWanVideo/src/com/weikou/beibeivideo/ui/main/MainActivity.java
@@ -14,11 +14,13 @@ import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.loader.app.LoaderManager; import androidx.loader.content.CursorLoader; import androidx.loader.content.Loader; import android.view.KeyEvent; import android.view.View; import android.widget.FrameLayout; @@ -70,12 +72,15 @@ import com.yeshi.appupdate.AppUpdate; import org.apache.http.Header; import org.json.JSONArray; import org.json.JSONObject; import java.io.BufferedReader; import java.io.InputStreamReader; import java.lang.reflect.Type; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.Random; @@ -705,23 +710,32 @@ SharedPreferences preferences = getSharedPreferences("user", Context.MODE_PRIVATE); String uid = preferences.getString("uid", ""); BeibeiVideoAPI.getHotSearch(this, uid, BeibeiVideoAPI.getSearchRank(this, new BasicTextHttpResponseHandler() { @Override public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { if (jsonObject.getBoolean("IsPost")) { Gson gson = new GsonBuilder().setFieldNamingPolicy( FieldNamingPolicy.UPPER_CAMEL_CASE) .create(); List<String> hotSearchs = gson.fromJson(jsonObject .getJSONObject("Data").getJSONArray("data") .toString(), new TypeToken<List<String>>() { }.getType()); Random random = new Random(); int p = random.nextInt(hotSearchs.size()); tv_search.setText(hotSearchs.get(p)); JSONObject data = jsonObject.getJSONObject("Data").getJSONObject("data"); if (data != null) for (Iterator<String> its = data.keys(); its.hasNext(); ) { String key = its.next(); if (key.contains("热搜")) { Type type = new TypeToken<List<String>>() { }.getType(); Gson gson = new Gson(); JSONArray array = data.optJSONArray(key); if (array != null) { List<String> list = gson.fromJson(array.toString(), type); if (list != null && list.size() > 0) { Random random = new Random(); int p = random.nextInt(list.size()); tv_search.setText(list.get(p)); } } } } } } }); BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/HotSearchAdapter.java
File was renamed from BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/GridSuggestionAdapter.java @@ -11,12 +11,12 @@ import com.weikou.beibeivideo.R; public class GridSuggestionAdapter extends BaseAdapter { public class HotSearchAdapter extends BaseAdapter { private List<String> mSuggestions; private boolean isHot; public GridSuggestionAdapter(List<String> suggestions, boolean isHot) { public HotSearchAdapter(List<String> suggestions, boolean isHot) { super(); this.mSuggestions = suggestions; this.isHot = isHot; BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/RecommendFragment.java
@@ -63,6 +63,7 @@ import com.weikou.beibeivideo.util.JumpActivityUtil; import com.weikou.beibeivideo.util.ad.AdUtil; import com.weikou.beibeivideo.util.ad.ExpressAdManager; import com.weikou.beibeivideo.util.ad.HomeAdUtil; import com.weikou.beibeivideo.util.ui.DividerItemDecoration; import com.yeshi.appupdate.GoReview; import com.yeshi.appupdate.service.DownLoadFileService; @@ -345,6 +346,7 @@ if (position == 0) { getAdRecommendRight(); } loadCacheData(); } private List<ExpressAdContainer> adList; @@ -394,9 +396,6 @@ if (!vp_recommend.hasAdapter()) { int width = ScreenUtils.getScreenWidth(getContext()); vp_recommend.initBanner(urlList, false, ratio)//开启3D画廊效果 .addPageMargin((int) (DimenUtils.dip2px(getContext(), 1) * 1.5), DimenUtils.dip2px(getContext(), 3))//参数1page之间的间距,参数2中间item距离边界的间距 // .addPointMargin(5)//指示器点间距 @@ -410,74 +409,8 @@ public void onBannerClick(int position) { if (position >= mHomeAds.size()) return; Intent intent = null; if (mHomeAds.get(position).getLinkType() == 1) { intent = new Intent(getContext(), VideoDetailActivity.class); intent.putExtra("video_info", mHomeAds.get(position) .getVideo()); } else if (mHomeAds.get(position).getLinkType() == 5) { try { JSONObject object = new JSONObject(mHomeAds .get(position).getParams() .replace("\\", "")); String thumb = object.optString("thumb"); String title = object.optString("title"); String desc = object.optString("desc"); String path = object.optString("path"); String username = object.optString("username"); String url = object.optString("url"); CustomShareDialog.Builder builder = new CustomShareDialog.Builder(getActivity()); builder.setMessage(desc); builder.setUrl(url); builder.setContentImage(thumb); builder.setTitle(title); builder.setPath(path); builder.setUserName(username); builder.setNegativeButton("取消分享", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); } catch (Exception e) { } } else { try { intent = new Intent(getContext(), Class .forName(mHomeAds.get(position).getClazz())); JSONObject object = new JSONObject(mHomeAds .get(position).getParams() .replace("\\", "")); if (mHomeAds.get(position).getClazz().contains("FXBrowserActivity") && object.optString("url").endsWith(".apk")) { // startDownLoadFile(object.optString("url")); return; } if (mHomeAds.get(position).getParams() != null) { @SuppressWarnings("unchecked") Iterator<String> its = object.keys(); while (its.hasNext()) { String key = its.next(); String value = object.optString(key); intent.putExtra(key, value); intent.putExtra("isPush", true); } } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } if (intent != null) getContext().startActivity(intent); HomeAdUtil.jump(mHomeAds.get(position), getActivity()); } }); } else { vp_recommend.notifyDataSetChanged(); @@ -490,12 +423,14 @@ { DiskLruCache.Snapshot snapshot = null; try { snapshot = cache.get(getKey("getHomeAd") + type.getId()); snapshot = cache.get(getKey("getHomeAdNew") + type.getId()); if (snapshot != null) { List<HomeAd> adList = new ArrayList<HomeAd>(); List<HomeAd> adList = new ArrayList<>(); String str = snapshot.getString(0); try { JSONArray array = new JSONArray(str); JSONObject jsonObject = new JSONObject(str); String bannerRate = jsonObject.optString("bannerSizeRate"); JSONArray array = jsonObject.optJSONArray("data"); HomeAd ad; for (int i = 0; i < array.length(); i++) { ad = new HomeAd(); @@ -529,7 +464,7 @@ if (adList != null && adList.size() > 0) { mHomeAds.clear(); mHomeAds.addAll(adList); setHomeAdsData(0.4375f); setHomeAdsData(StringUtils.isBlank(bannerRate) ? 0.4375f : new BigDecimal(bannerRate).floatValue()); } } catch (JSONException e) { e.printStackTrace(); @@ -544,31 +479,31 @@ } } } { DiskLruCache.Snapshot snapshot = null; try { snapshot = cache.get(getKey("getHomeType") + type.getId()); if (snapshot != null) { Gson gson = new GsonBuilder().setFieldNamingPolicy( FieldNamingPolicy.UPPER_CAMEL_CASE).create(); List<HomeType> homeTypes = gson.fromJson( snapshot.getString(0), new TypeToken<List<HomeType>>() { }.getType()); mHomeTypes.clear(); if (homeTypes != null) { mHomeTypes.addAll(homeTypes); DiskLruCache.Snapshot snapshot = null; try { snapshot = cache.get(getKey("getHomeType") + type.getId()); if (snapshot != null) { Gson gson = new GsonBuilder().setFieldNamingPolicy( FieldNamingPolicy.UPPER_CAMEL_CASE).create(); List<HomeType> homeTypes = gson.fromJson( snapshot.getString(0), new TypeToken<List<HomeType>>() { }.getType()); mHomeTypes.clear(); if (homeTypes != null) { mHomeTypes.addAll(homeTypes); // mRecommendNewAdapter.notifyDataSetChanged(); } } } catch (Exception e) { e.printStackTrace(); } finally { if (snapshot != null) { snapshot.close(); } } } catch (Exception e) { e.printStackTrace(); } finally { if (snapshot != null) { snapshot.close(); } } } } @@ -743,9 +678,8 @@ if (position == 0) { DiskLruCache.Editor editor = cache .edit(getKey("getHomeAd") + type.getId()); editor.set(0, jsonObject.getJSONObject("Data") .getJSONArray("data").toString()); .edit(getKey("getHomeAdNew") + type.getId()); editor.set(0, jsonObject.getJSONObject("Data").toString()); editor.commit(); } } BuWanVideo/src/com/weikou/beibeivideo/ui/recommend/SearchActivity.java
@@ -4,28 +4,34 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.graphics.Color; import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.os.Bundle; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnTouchListener; import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.BaseAdapter; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.GridView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; import android.widget.ScrollView; import android.widget.TextView; import android.widget.Toast; @@ -34,6 +40,8 @@ import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.lcjian.library.util.common.StringUtils; import com.lcjian.library.widget.FlowLayout; import com.lcjian.library.widget.MyGridView; import com.qq.e.ads.cfg.VideoOption; import com.qq.e.ads.nativ.ADSize; import com.qq.e.ads.nativ.NativeExpressAD; @@ -45,6 +53,7 @@ import com.weikou.beibeivideo.entity.ad.AdPositionEnum; import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; import com.weikou.beibeivideo.ui.BaseActivity; import com.weikou.beibeivideo.ui.common.GridVideoAdapter1; import com.weikou.beibeivideo.ui.video.SuggestKeysAdapter; import com.weikou.beibeivideo.util.BeibeiConstant; import com.weikou.beibeivideo.R; @@ -54,9 +63,13 @@ import com.weikou.beibeivideo.util.ui.TopStatusSettings; import org.apache.http.Header; import org.json.JSONArray; import org.json.JSONObject; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Arrays; import java.util.Iterator; import java.util.List; public class SearchActivity extends BaseActivity implements OnClickListener { @@ -69,9 +82,9 @@ private GridView gv_hot_search; private GridView gv_history_search; private FlowLayout fl_history_search; private LinearLayout ll_search_history; private LinearLayout ll_search_history, ll_search_rank; private SearchSuggestFragment suggestFragment; @@ -87,14 +100,16 @@ fl_advertisement.setOnClickListener(this); tv_search_cancel = findViewById(R.id.tv_search_cancel); gv_hot_search = findViewById(R.id.gv_hot_search); gv_history_search = findViewById(R.id.gv_history_search); fl_history_search = findViewById(R.id.fl_history_search); tv_clear = findViewById(R.id.tv_search_clear_his); ll_search_history = findViewById(R.id.ll_search_history); fl_suggest = findViewById(R.id.fl_suggest); ll_search_rank = findViewById(R.id.ll_search_rank); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.search_actvity); TopStatusSettings.setStatusViewAndDeepColor(this); @@ -105,7 +120,7 @@ @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class); if (StringUtils.isEmpty(et_search_key.getEditableText() .toString()) && StringUtils.isEmpty(et_search_key.getHint() .toString())) { @@ -114,13 +129,13 @@ } else { if (!StringUtils.isEmpty(et_search_key.getEditableText() .toString())) { intent.putExtra("key", et_search_key.getEditableText() jumpToSearch(et_search_key.getEditableText() .toString()); } else { intent.putExtra("key", et_search_key.getHint()); jumpToSearch(et_search_key.getHint() + ""); } } startActivity(intent); return true; } @@ -203,23 +218,7 @@ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class); intent.putExtra("key", (String) parent.getItemAtPosition(position)); startActivity(intent); } }); gv_history_search.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class); intent.putExtra("key", (String) parent.getItemAtPosition(position)); startActivity(intent); jumpToSearch((String) parent.getItemAtPosition(position)); } }); @@ -228,6 +227,7 @@ getHotSearch(); getHistorySearch(); initAdvertisement();// 广点通广告 getSearchRank(); } @Override @@ -278,10 +278,7 @@ suggestFragment.setItemClickListener(new SearchSuggestFragment.OnItemClickListener() { @Override public void onClick(String st) { Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class); intent.putExtra("key", st); startActivity(intent); jumpToSearch(st); hiddenSuggestFragment(); } }); @@ -340,13 +337,35 @@ if (!StringUtils.isBlank(historyStr)) { String[] historyArray = historyStr.split(","); ll_search_history.setVisibility(View.VISIBLE); List<String> history = new ArrayList<String>(); List<String> history = new ArrayList<>(); for (int i = 0; i < 10 && i < historyArray.length; i++) { if (!TextUtils.isEmpty(historyArray[historyArray.length - 1 - i])) { history.add(historyArray[historyArray.length - 1 - i]); String st = historyArray[historyArray.length - 1 - i]; if (st != null && !history.contains(st.trim())) history.add(st.trim()); } } gv_history_search.setAdapter(new GridSuggestionAdapter(history, false)); fl_history_search.removeAllViews(); for (String st : history) { TextView textView = new TextView(getApplicationContext()); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setTextSize(13); textView.setPadding(DimenUtils.dip2px(getApplicationContext(), 20), DimenUtils.dip2px(getApplicationContext(), 5), DimenUtils.dip2px(getApplicationContext(), 20), DimenUtils.dip2px(getApplicationContext(), 5)); textView.setText(st); textView.setTextColor(getResources().getColor(R.color.search_item_text_color)); textView.setBackgroundResource(R.drawable.shape_search_history_item_bg); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); params.setMargins(0, DimenUtils.dip2px(getApplicationContext(), 15), DimenUtils.dip2px(getApplicationContext(), 13), 0); textView.setLayoutParams(params); textView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { jumpToSearch(st); } }); fl_history_search.addView(textView); } } else { ll_search_history.setVisibility(View.GONE); } @@ -379,8 +398,31 @@ .getJSONObject("Data").getJSONArray("data") .toString(), new TypeToken<List<String>>() { }.getType()); gv_hot_search.setAdapter(new GridSuggestionAdapter( if (hotSearchs == null || hotSearchs.size() == 0) { gv_hot_search.setVisibility(View.GONE); } else { gv_hot_search.setVisibility(View.VISIBLE); } gv_hot_search.setAdapter(new HotSearchAdapter( hotSearchs, true)); } else { gv_hot_search.setVisibility(View.GONE); } } }); } private void getSearchRank() { BeibeiVideoAPI.getSearchRank(this, new BasicTextHttpResponseHandler() { @Override public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception { if (jsonObject.getBoolean("IsPost")) { JSONObject data = jsonObject .getJSONObject("Data").getJSONObject("data"); initSearchRank(data); } } }); @@ -393,7 +435,12 @@ // 1.加载广告,先设置加载上下文环境和条件 private void initAdvertisement() { AdUtil.AD_TYPE adType = AdUtil.getAdType(getApplicationContext(), AdPositionEnum.videoSearch); AdUtil.AD_TYPE adType1 = AdUtil.getAdType(getApplicationContext(), AdPositionEnum.videoSearch); if (adType1 == AdUtil.AD_TYPE.gdt) { adType1 = AdUtil.AD_TYPE.gdt2; } final AdUtil.AD_TYPE adType = adType1; fl_advertisement.post(new Runnable() { @Override public void run() { @@ -410,10 +457,10 @@ }); } else if (adType != null) { AdUtil.AD_TYPE newAdType = null; if (adType == AdUtil.AD_TYPE.gdt) { if (adType == AdUtil.AD_TYPE.gdt2) { newAdType = AdUtil.AD_TYPE.csj; } else newAdType = AdUtil.AD_TYPE.gdt; newAdType = AdUtil.AD_TYPE.gdt2; new ExpressAdManager(newAdType, getApplicationContext()).loadSearchAd(DimenUtils.px2dip(getApplicationContext(), width), new ExpressAdManager.IAdLoadListener() { @Override @@ -435,4 +482,128 @@ }); } private void initSearchRank(JSONObject data) { ll_search_rank.removeAllViews(); Type type = new TypeToken<List<String>>() { }.getType(); Gson gson = new Gson(); int count = 0; for (Iterator<String> its = data.keys(); its.hasNext(); ) { String key = its.next(); JSONArray array = data.optJSONArray(key); List<String> list = gson.fromJson(array.toString(), type); String[] sts = new String[list.size()]; int row = list.size() / 2; for (int i = 0; i < list.size(); i++) { if (i < row) { sts[i * 2] = list.get(i); } else { sts[(i % row) * 2 + 1] = list.get(i); } } count++; addSearchRankView(key, Arrays.asList(sts), ll_search_rank, count == data.length()); } } private void addSearchRankView(String title, List<String> contentList, LinearLayout container, boolean last) { View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.item_search_rank, null); MyGridView gv = view.findViewById(R.id.gv_content); TextView tv_title = view.findViewById(R.id.tv_title); tv_title.setText(title); gv.setAdapter(new SearchRankAdapter(contentList, getApplicationContext())); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(DimenUtils.dip2px(getApplicationContext(), 284), LinearLayout.LayoutParams.WRAP_CONTENT); params.rightMargin = DimenUtils.dip2px(getApplicationContext(), !last ? 11 : 0); container.addView(view, params); } private void jumpToSearch(String key) { Intent intent = new Intent(SearchActivity.this, SearchResultActivity.class); intent.putExtra("key", key); startActivity(intent); } class SearchRankAdapter extends BaseAdapter { private List<String> mList; private LayoutInflater layoutInflater; public SearchRankAdapter(List<String> list, Context context) { this.mList = list; layoutInflater = LayoutInflater.from(context); } @Override public int getCount() { return mList == null ? 0 : mList.size(); } @Override public Object getItem(int position) { return mList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder viewHolder; if (convertView == null) { viewHolder = new ViewHolder(); convertView = LayoutInflater.from(parent.getContext()).inflate( R.layout.item_search_rank_content, parent, false); viewHolder.tv_rank = convertView .findViewById(R.id.tv_rank); viewHolder.tv_content = convertView .findViewById(R.id.tv_content); convertView.setTag(viewHolder); } else { viewHolder = (ViewHolder) convertView.getTag(); } if (position % 2 == 0) { viewHolder.tv_rank.setText((position / 2 + 1) + ""); } else { viewHolder.tv_rank.setText((mList.size() / 2 + (position + 1) / 2) + ""); } viewHolder.tv_content.setText(mList.get(position)); String color = "#C2C2C2"; switch (viewHolder.tv_rank.getText() + "") { case "1": color = "#FE3E3C"; break; case "2": color = "#FE853C"; break; case "3": color = "#FEC03C"; break; default: color = "#C2C2C2"; } GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, new int[]{Color.parseColor(color), Color.parseColor(color)}); gd.setCornerRadius(DimenUtils.dip2px(convertView.getContext(), 4)); viewHolder.tv_rank.setBackground(gd); convertView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { jumpToSearch(mList.get(position)); } }); return convertView; } class ViewHolder { TextView tv_rank; TextView tv_content; } } } BuWanVideo/src/com/weikou/beibeivideo/util/BeibeiConstant.java
@@ -101,7 +101,7 @@ // // 广点通 原生播放详情页3 // public static final String GDT_PLAYER_NATIVE3 = "5030710478681919"; // 广点通 原生搜索底部 public static String GDT_SEARCH_NATIVE = "5070457746467145"; public static String GDT_SEARCH_NATIVE = "3091676401133809"; // 广点通 发现页 public static String GDT_DISCOVER_NATIVE = "4020358673719753"; // 广点通 猜你喜欢 BuWanVideo/src/com/weikou/beibeivideo/util/ad/ExpressAdManager.java
@@ -329,7 +329,7 @@ String pid = null; if (sourceType == AdUtil.AD_TYPE.csj) { pid = CSJConstant.VIDEO_SEARCH; } else if (sourceType == AdUtil.AD_TYPE.gdt) { } else if (sourceType == AdUtil.AD_TYPE.gdt2) { pid = BeibeiConstant.GDT_SEARCH_NATIVE; } int height = (int) (widthDP / 1.78f); BuWanVideo/src/com/weikou/beibeivideo/util/ad/HomeAdUtil.java
New file @@ -0,0 +1,97 @@ package com.weikou.beibeivideo.util.ad; import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import com.weikou.beibeivideo.entity.HomeAd; import com.weikou.beibeivideo.ui.media.VideoDetailActivity2; import com.weikou.beibeivideo.util.CustomShareDialog; import com.weikou.beibeivideo.util.downutil.DownFiles; import org.json.JSONObject; import java.util.Iterator; public class HomeAdUtil { public static void jump(HomeAd homeAd, Activity context) { Intent intent = null; if (homeAd.getLinkType() == 1) { intent = new Intent(context, VideoDetailActivity2.class); intent.putExtra("video_info", homeAd .getVideo()); intent.putExtra("from", "homeAd"); } else if (homeAd.getLinkType() == 5) { try { JSONObject object = new JSONObject(homeAd.getParams() .replace("\\", "")); String thumb = object.optString("thumb"); String title = object.optString("title"); String desc = object.optString("desc"); String path = object.optString("path"); String username = object.optString("username"); String url = object.optString("url"); CustomShareDialog.Builder builder = new CustomShareDialog.Builder(context); builder.setMessage(desc); builder.setUrl(url); builder.setContentImage(thumb); builder.setTitle(title); builder.setPath(path); builder.setUserName(username); builder.setNegativeButton("取消分享", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show(); } catch (Exception e) { } } else { try { intent = new Intent(context, Class .forName(homeAd.getClazz())); JSONObject object = new JSONObject(homeAd.getParams() .replace("\\", "")); if (homeAd.getClazz().contains("FXBrowserActivity") && object.optString("url").endsWith(".apk")) { startDownLoadFile(context, object.optString("url")); return; } if (homeAd.getParams() != null) { @SuppressWarnings("unchecked") Iterator<String> its = object.keys(); while (its.hasNext()) { String key = its.next(); String value = object.optString(key); intent.putExtra(key, value); intent.putExtra("isPush", true); } } } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } if (context != null && intent != null) context.startActivity(intent); } private static void startDownLoadFile(Context context, String url) { new DownFiles(context, new DownFiles.IProgress() { @Override public void getProgress(int p) { //TODO 处理进度 } }).execute(url); } } gradle.properties
New file @@ -0,0 +1,2 @@ android.enableJetifier=true android.useAndroidX=true library-BaiduCPU/src/main/java/com/yeshi/ec/library_baiducpu/fragment/BaiDuCPUContentFragment.java
@@ -313,4 +313,5 @@ } } library-common/src/com/lcjian/library/widget/FlowLayout.java
New file @@ -0,0 +1,203 @@ package com.lcjian.library.widget; import java.util.ArrayList; import java.util.List; import android.content.Context; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.view.ViewGroup; /** * 流式布局 */ public class FlowLayout extends ViewGroup { private static final String TAG = "FlowLayout"; public FlowLayout(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected LayoutParams generateLayoutParams( LayoutParams p) { return new MarginLayoutParams(p); } @Override public LayoutParams generateLayoutParams(AttributeSet attrs) { return new MarginLayoutParams(getContext(), attrs); } @Override protected LayoutParams generateDefaultLayoutParams() { return new MarginLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); } /** * 负责设置子控件的测量模式和大小 根据所有子控件设置自己的宽和高 */ @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); // 获得它的父容器为它设置的测量模式和大小 int sizeWidth = MeasureSpec.getSize(widthMeasureSpec); int sizeHeight = MeasureSpec.getSize(heightMeasureSpec); int modeWidth = MeasureSpec.getMode(widthMeasureSpec); int modeHeight = MeasureSpec.getMode(heightMeasureSpec); Log.e(TAG, sizeWidth + "," + sizeHeight); // 如果是warp_content情况下,记录宽和高 int width = 0; int height = 0; /** * 记录每一行的宽度,width不断取最大宽度 */ int lineWidth = 0; /** * 每一行的高度,累加至height */ int lineHeight = 0; int cCount = getChildCount(); // 遍历每个子元素 for (int i = 0; i < cCount; i++) { View child = getChildAt(i); // 测量每一个child的宽和高 measureChild(child, widthMeasureSpec, heightMeasureSpec); // 得到child的lp MarginLayoutParams lp = (MarginLayoutParams) child .getLayoutParams(); // 当前子空间实际占据的宽度 int childWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; // 当前子空间实际占据的高度 int childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin; /** * 如果加入当前child,则超出最大宽度,则的到目前最大宽度给width,类加height 然后开启新行 */ if (lineWidth + childWidth > sizeWidth) { width = Math.max(lineWidth, childWidth);// 取最大的 lineWidth = childWidth; // 重新开启新行,开始记录 // 叠加当前高度, height += lineHeight; // 开启记录下一行的高度 lineHeight = childHeight; } else // 否则累加值lineWidth,lineHeight取最大高度 { lineWidth += childWidth; lineHeight = Math.max(lineHeight, childHeight); } // 如果是最后一个,则将当前记录的最大宽度和当前lineWidth做比较 if (i == cCount - 1) { width = Math.max(width, lineWidth); height += lineHeight; } } setMeasuredDimension((modeWidth == MeasureSpec.EXACTLY) ? sizeWidth : width, (modeHeight == MeasureSpec.EXACTLY) ? sizeHeight : height); } /** * 存储所有的View,按行记录 */ private List<List<View>> mAllViews = new ArrayList<List<View>>(); /** * 记录每一行的最大高度 */ private List<Integer> mLineHeight = new ArrayList<Integer>(); @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { mAllViews.clear(); mLineHeight.clear(); int width = getWidth(); int lineWidth = 0; int lineHeight = 0; // 存储每一行所有的childView List<View> lineViews = new ArrayList<View>(); int cCount = getChildCount(); // 遍历所有的孩子 for (int i = 0; i < cCount; i++) { View child = getChildAt(i); MarginLayoutParams lp = (MarginLayoutParams) child .getLayoutParams(); int childWidth = child.getMeasuredWidth(); int childHeight = child.getMeasuredHeight(); // 如果已经需要换行 if (childWidth + lp.leftMargin + lp.rightMargin + lineWidth > width) { // 记录这一行所有的View以及最大高度 mLineHeight.add(lineHeight); // 将当前行的childView保存,然后开启新的ArrayList保存下一行的childView mAllViews.add(lineViews); lineWidth = 0;// 重置行宽 lineViews = new ArrayList<View>(); } /** * 如果不需要换行,则累加 */ lineWidth += childWidth + lp.leftMargin + lp.rightMargin; lineHeight = Math.max(lineHeight, childHeight + lp.topMargin + lp.bottomMargin); lineViews.add(child); } // 记录最后一行 mLineHeight.add(lineHeight); mAllViews.add(lineViews); int left = 0; int top = 0; // 得到总行数 int lineNums = mAllViews.size(); for (int i = 0; i < lineNums; i++) { // 每一行的所有的views lineViews = mAllViews.get(i); // 当前行的最大高度 lineHeight = mLineHeight.get(i); Log.e(TAG, "第" + i + "行 :" + lineViews.size() + " , " + lineViews); Log.e(TAG, "第" + i + "行, :" + lineHeight); // 遍历当前行所有的View for (int j = 0; j < lineViews.size(); j++) { View child = lineViews.get(j); if (child.getVisibility() == View.GONE) { continue; } MarginLayoutParams lp = (MarginLayoutParams) child .getLayoutParams(); //计算childView的left,top,right,bottom int lc = left + lp.leftMargin; int tc = top + lp.topMargin; int rc = lc + child.getMeasuredWidth(); int bc = tc + child.getMeasuredHeight(); Log.e(TAG, child + " , l = " + lc + " , t = " + t + " , r =" + rc + " , b = " + bc); child.layout(lc, tc, rc, bc); left += child.getMeasuredWidth() + lp.rightMargin + lp.leftMargin; } left = 0; top += lineHeight; } } } library-gallery/.gitignore
New file @@ -0,0 +1 @@ /build library-gallery/build.gradle
New file @@ -0,0 +1,40 @@ apply plugin: 'com.android.library' android { compileSdkVersion 28 defaultConfig { minSdkVersion 17 targetSdkVersion 28 versionCode 13 versionName "1.3" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { abortOnError false } compileOptions { sourceCompatibility = 1.8 targetCompatibility = 1.8 } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(path: ':library-common') testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' } library-gallery/proguard-rules.pro
New file @@ -0,0 +1,21 @@ # Add project specific ProGuard rules here. # You can control the set of applied configuration files using the # proguardFiles setting in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile library-gallery/src/androidTest/java/com/lzj/gallery/library/ExampleInstrumentedTest.java
New file @@ -0,0 +1,26 @@ package com.lzj.gallery.library; import android.content.Context; import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.ext.junit.runners.AndroidJUnit4; import org.junit.Test; import org.junit.runner.RunWith; import static org.junit.Assert.*; /** * Instrumented test, which will execute on an Android device. * * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> */ @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest { @Test public void useAppContext() throws Exception { // Context of the app under test. Context appContext = InstrumentationRegistry.getTargetContext(); assertEquals("com.lzj.gallery.library.test", appContext.getPackageName()); } } library-gallery/src/main/AndroidManifest.xml
New file @@ -0,0 +1,4 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.guangdiantongsdk" android:versionCode="1" android:versionName="1.0"></manifest> library-gallery/src/main/java/com/lzj/gallery/library/adapter/BannerPagerAdapter.java
New file @@ -0,0 +1,144 @@ package com.lzj.gallery.library.adapter; import android.content.Context; import androidx.viewpager.widget.PagerAdapter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import com.bumptech.glide.Glide; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.RoundedCorners; import com.example.guangdiantongsdk.R; import com.lcjian.library.widget.RatioLayout; import java.util.List; /** * Created by Administrator on 2018/11/28. * banner的适配器 */ public class BannerPagerAdapter extends PagerAdapter { private List<String> mList; private Context mContext; private int defaultImg = R.mipmap.ic_banner_error;//默认图片 private int mRoundCorners = -1; private int mMaxNumber;//最大banner数 private Float imgRatio; /** * 默认 * * @param defaultImg */ public void setDefaultImg(int defaultImg) { this.defaultImg = defaultImg; } /** * 设置圆角 * * @param mRoundCorners */ public void setmRoundCorners(int mRoundCorners) { this.mRoundCorners = mRoundCorners; } /** * 点击回调 */ public interface OnClickImagesListener { void onImagesClick(int position); } private OnClickImagesListener mImagesListener; public void setOnClickImagesListener(OnClickImagesListener listener) { mImagesListener = listener; } public BannerPagerAdapter(List<String> list, Context context, Float imgRatio) { // this.mList = list; this.imgRatio = imgRatio; this.mContext = context; if (mList == null) { mList = list; } if (list.size() > 20) { this.mMaxNumber = 20; } else { this.mMaxNumber = list.size(); } } @Override public int getCount() { return mList.size() == 1 ? 1 : Integer.MAX_VALUE; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); } @Override public Object instantiateItem(ViewGroup container, int position) { View view = LayoutInflater.from(mContext).inflate(R.layout.banner_img_layout, container, false); ViewGroup.LayoutParams params = view.getLayoutParams(); ImageView imageView = view.findViewById(R.id.img); RatioLayout rl = view.findViewById(R.id.rl_img); if (imgRatio != null) rl.setRatio(imgRatio); final int index = position % mMaxNumber; LoadImage(mList.get(index), imageView); //OnClick imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mImagesListener.onImagesClick(index); } }); container.addView(view); return view; } /** * 加载图片 */ public void LoadImage(String url, ImageView imageview) { if (mRoundCorners == -1) { Glide.with(mContext) .load(url) // .centerCrop() .dontAnimate() .placeholder(defaultImg)// 加载中图片 .error(defaultImg) // 加载失败图片 .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)//设置磁盘缓存 .into(imageview); } else { Glide.with(mContext) .load(url) .centerCrop() .dontAnimate() .placeholder(defaultImg)// 加载中图片 .error(defaultImg) // 加载失败图片 .transform(new RoundedCorners(mRoundCorners)) // .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)//设置磁盘缓存 .into(imageview); } } } library-gallery/src/main/java/com/lzj/gallery/library/transformer/CornerTransform.java
New file @@ -0,0 +1,65 @@ package com.lzj.gallery.library.transformer; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapShader; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.RectF; import androidx.annotation.NonNull; import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; import java.security.MessageDigest; /** * Created by Administrator on 2018/11/28. * 自定义圆角 */ public class CornerTransform extends BitmapTransformation { private static float radius = 0f; public CornerTransform(Context context) { this(context, 4); } public CornerTransform(Context context, int dp) { // super(context); radius = Resources.getSystem().getDisplayMetrics().density * dp; } @Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { return roundCrop(pool, toTransform); } private static Bitmap roundCrop(BitmapPool pool, Bitmap source) { if (source == null) return null; Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); if (result == null) { result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); } Canvas canvas = new Canvas(result); Paint paint = new Paint(); paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); paint.setAntiAlias(true); RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); canvas.drawRoundRect(rectF, radius, radius, paint); return result; } public String getId() { return getClass().getName() + Math.round(radius); } @Override public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) { } } library-gallery/src/main/java/com/lzj/gallery/library/transformer/ZoomPageTransformer.java
New file @@ -0,0 +1,70 @@ package com.lzj.gallery.library.transformer; import androidx.viewpager.widget.ViewPager; import android.view.View; /** * Created by Administrator on 2018/11/28. * 3D画廊效果其实就是ViewPager的item切换时,进行缩放的动画效果 * */ public class ZoomPageTransformer implements ViewPager.PageTransformer { private static final float MAX_SCALE = 1.0f;//0缩放 private static final float MIN_SCALE = 0.90f;//0.85缩放 private float MIN_ALPHA = 1.0f;//最小透明度 public ZoomPageTransformer() { } public ZoomPageTransformer(float MIN_ALPHA) { this.MIN_ALPHA = MIN_ALPHA; } @Override public void transformPage(View view, float position) { //setScaleY只支持api11以上 /** * (-oo,-1) 相对于左边第一页,其左边的所有页面 ** * x、y拉伸为MIN_SCALE、透明度MIN_ALPHA */ if (position < -1) { view.setScaleX(MIN_SCALE); view.setScaleY(MIN_SCALE); view.setAlpha(MIN_ALPHA); } /** * [-1, 1 )当前页的左右第一页 */ else if (position < 1) { float scaleFactor = MIN_SCALE + (1 - Math.abs(position)) * (MAX_SCALE - MIN_SCALE); //[0, 1 ) 相对于当前选中页,其右边第一页 ** if (position > 0) { view.setTranslationX(-scaleFactor); } // [-1, 0 ) 相对于当前选中页,其左边的第一页** else if (position < 0) { view.setTranslationX(scaleFactor); } view.setScaleY(scaleFactor); view.setScaleX(scaleFactor); // float alpha = 1f - Math.abs(position) * (1 - ); float alpha = MIN_ALPHA + (1 - MIN_ALPHA) * (1 - Math.abs(position)); view.setAlpha(alpha); } /** * [1,+oo) 相对于右边第一页,其右边的所有页面 * x、y拉伸为MIN_SCALE、透明度MIN_ALPHA */ else { // (1,+Infinity] view.setScaleX(MIN_SCALE); view.setScaleY(MIN_SCALE); view.setAlpha(MIN_ALPHA); } } } library-gallery/src/main/java/com/lzj/gallery/library/views/BannerViewPager.java
New file @@ -0,0 +1,486 @@ package com.lzj.gallery.library.views; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; import android.os.Handler; import androidx.viewpager.widget.ViewPager; import android.util.AttributeSet; import android.util.Log; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import com.example.guangdiantongsdk.R; import com.lzj.gallery.library.adapter.BannerPagerAdapter; import com.lzj.gallery.library.transformer.ZoomPageTransformer; import java.util.List; /** * Created by Administrator on 2018/11/28. * banner的控件处理 */ public class BannerViewPager extends RelativeLayout implements ViewPager.OnPageChangeListener { private View mLayout;//布局 private Activity mContext;//上下文 private ViewPager mViewPager;//viewpager private BannerPagerAdapter mPagerAdapter;//adapter private LinearLayout mLineIndicator;//指示器集合容器 private ImageView[] mImageView;//小圆点imageview对象 private List<String> mList;//url数组 private int mMaxNumber;//最大banner数 private int currentIndex = 0;//当前实际page private int startCurrentIndex = 0;//当前page private long secondTime = 0, firstTime = 0; private boolean isSlide = false; //private Timer mTimer=null;//定时器 //private MyTimerTask mTimerTask=null; private Handler mHandler = null; private AutoRollRunnable mAutoRollRunnable = null; private int mRollTime = 5000; private int resId_piont_press = R.mipmap.ic_banner_point_press; private int resId_piont = R.mipmap.ic_banner_point; private boolean isPoint = false;//开启指示器 private float imgRatio;//显示图片的宽高比 public interface OnClickBannerListener { void onBannerClick(int position); } private OnClickBannerListener mBannerListener; public BannerViewPager addBannerListener(OnClickBannerListener listener) { mBannerListener = listener; return this; } //ui更新 // Handler mHandler=mHandler= new Handler(){ // public void handleMessage(Message msg) { // int index = mViewPager.getCurrentItem()+1;//下一个页 // mViewPager.setCurrentItem(index);//设置此次要显示的pager // currentIndex=index%mList.size(); // setImageBackground(currentIndex); // } // }; public BannerViewPager(Context context) { super(context); } public BannerViewPager(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public BannerViewPager(Context context, AttributeSet attrs) { super(context, attrs); this.mContext = (Activity) context; } /** * 初始化viewpager * * @param list url集合 * @param isGallery 是否使用3D画廊效果 */ public BannerViewPager initBanner(List<String> list, boolean isGallery, float imgRatio) { this.imgRatio = imgRatio; checkException(list); if (mList == null) { mList = list; if (list.size() > 20) { mMaxNumber = 20; } else { mMaxNumber = list.size(); } } Log.i("test", "----------------------size=" + mList.size()); //引入布局 mLayout = LayoutInflater.from(mContext).inflate(R.layout.banner_view_layout, null); mViewPager = mLayout.findViewById(R.id.viewPager);//关闭 mLineIndicator = mLayout.findViewById(R.id.lineIndicator); //初始化位置 // if (list.size() == 1) { // startCurrentIndex = 0; // } currentIndex = startCurrentIndex % mMaxNumber; mPagerAdapter = new BannerPagerAdapter(mList, mContext, imgRatio); mPagerAdapter.setOnClickImagesListener(new BannerPagerAdapter.OnClickImagesListener() { @Override public void onImagesClick(int position) { if (mBannerListener != null) { mBannerListener.onBannerClick(position); } } }); mViewPager.setAdapter(mPagerAdapter); if (isGallery) { mViewPager.setPageTransformer(true, new ZoomPageTransformer()); } mViewPager.setCurrentItem(startCurrentIndex); mViewPager.setOffscreenPageLimit(2);//设置预加载的数量,这里设置了2,会预加载中心item左边两个Item和右边两个Item mViewPager.addOnPageChangeListener(this); return this; } /** * 是否有adapter * * @return */ public boolean hasAdapter() { return mViewPager != null && mViewPager.getAdapter() != null; } public void notifyDataSetChanged() { if (mPagerAdapter != null) mPagerAdapter.notifyDataSetChanged(); } /** * 初始化viewpager * * @param list url集合 * @param isGallery 是否使用3D画廊效果 * @param alpha 滑动透明度变化 */ public BannerViewPager initBanner(List<String> list, boolean isGallery, float imgRatio, float alpha) { checkException(list); this.imgRatio = imgRatio; if (mList == null) { mList = list; if (list.size() > 20) { this.mMaxNumber = 20; } else { this.mMaxNumber = list.size(); } } Log.i("test", "----------------------size=" + mList.size()); //引入布局 mLayout = LayoutInflater.from(mContext).inflate(R.layout.banner_view_layout, null); mViewPager = mLayout.findViewById(R.id.viewPager);//关闭 mLineIndicator = mLayout.findViewById(R.id.lineIndicator); //初始化位置 currentIndex = startCurrentIndex % mMaxNumber; mPagerAdapter = new BannerPagerAdapter(mList, mContext, imgRatio); mPagerAdapter.setOnClickImagesListener(new BannerPagerAdapter.OnClickImagesListener() { @Override public void onImagesClick(int position) { if (mBannerListener != null) { mBannerListener.onBannerClick(position); } } }); mViewPager.setAdapter(mPagerAdapter); if (isGallery) { mViewPager.setPageTransformer(true, new ZoomPageTransformer(alpha)); } mViewPager.setCurrentItem(startCurrentIndex); mViewPager.setOffscreenPageLimit(2);//设置预加载的数量,这里设置了2,会预加载中心item左边两个Item和右边两个Item mViewPager.addOnPageChangeListener(this); return this; } /** * 添加默认图片,当加载失败后显示 * * @param resId_img * @return */ public BannerViewPager addDefaultImg(int resId_img) { mPagerAdapter.setDefaultImg(resId_img); return this; } /** * 添加圆角 * * @param corners * @return */ public BannerViewPager addRoundCorners(int corners) { mPagerAdapter.setmRoundCorners(corners); return this; } /** * @param columnMargin 两个Page之间的距离 * @param rowMargin page的外边距 * 注意当添加了3D画廊效果时,columnMargin尽量设小。应该本是已经进行了x、y的缩放 */ public BannerViewPager addPageMargin(int columnMargin, int rowMargin) { mViewPager.setPageMargin(dip2px(columnMargin)); RelativeLayout.LayoutParams layout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); layout.setMargins(dip2px(rowMargin), 0, dip2px(rowMargin), 0); mViewPager.setLayoutParams(layout); return this; } /** * 添加小圆点 * * @param distance 间距 */ public BannerViewPager addPointMargin(int distance) { isPoint = true; mImageView = new ImageView[mMaxNumber]; for (int i = 0; i < mMaxNumber; i++) { ImageView imageView = new ImageView(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(dip2px(distance) / 2, 0, dip2px(distance) / 2, 0); imageView.setLayoutParams(params); if (i == currentIndex) { imageView.setImageResource(resId_piont_press); } else { imageView.setImageResource(resId_piont); } mImageView[i] = imageView; mLineIndicator.addView(imageView); } return this; } /** * 添加小圆点 * * @param distance 间距 * @param piont_press 替换选中图标 * @param piont 替换未选中图片 */ public BannerViewPager addPoint(int distance, int piont_press, int piont) { isPoint = true; resId_piont_press = piont_press; resId_piont = piont; mImageView = new ImageView[mMaxNumber]; for (int i = 0; i < mMaxNumber; i++) { ImageView imageView = new ImageView(mContext); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); params.setMargins(dip2px(distance) / 2, 0, dip2px(distance) / 2, 0); imageView.setLayoutParams(params); if (i == currentIndex) { imageView.setImageResource(resId_piont_press); } else { imageView.setImageResource(resId_piont); } mImageView[i] = imageView; mLineIndicator.addView(imageView); } return this; } /** * 添加小圆点底部间距 * * @param paddBottom */ public BannerViewPager addPointBottom(int paddBottom) { mLineIndicator.setPadding(0, 0, 0, dip2px(paddBottom)); return this; } /** * 配置完成,将布局添加到父容器 */ public BannerViewPager finishConfig() { this.removeAllViews(); this.addView(mLayout); return this; } //开始轮播 public BannerViewPager addStartTimer(int time) { mRollTime = time; if (mHandler == null) { mHandler = new Handler(); } if (mAutoRollRunnable == null) { mAutoRollRunnable = new AutoRollRunnable(); } mAutoRollRunnable.start(); return this; } // 停止轮播 public void stopTimer() { if (mAutoRollRunnable != null) { mAutoRollRunnable.stop(); } } private class AutoRollRunnable implements Runnable { //是否在轮播的标志 boolean isRunning = false; @SuppressLint("ClickableViewAccessibility") @Override public void run() { if (isRunning && !isSlide) { int index = mViewPager.getCurrentItem() + 1;//下一个页 mViewPager.setCurrentItem(index);//设置此次要显示的pager currentIndex = index % mMaxNumber; setImageBackground(currentIndex); mHandler.postDelayed(this, 1000 * mRollTime); } if (isSlide) { mHandler.postDelayed(this, 1000 * mRollTime); isSlide = false; } //轮播图触摸监听,解决滑动计时无法停止的问题 /* * viewPager监听触摸事件,因为我们要保证用户在手动滑动viewPager后,系统重新计时,viewPage按一定时间间隔循环展示, * 当手指按上屏幕或者是手指出现滑动动作,子线程都必须撤销(计时也就是消失) * 当手机松开之后系统重新计时,子线程与UI线程绑定,进行计时操作 */ mViewPager.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_MOVE: mHandler.removeCallbacks(mAutoRollRunnable); break; case MotionEvent.ACTION_UP: isSlide = true; mHandler.post(mAutoRollRunnable); break; } return false; } }); } public void start() { if (!isRunning) { isRunning = true; mHandler.removeCallbacks(this); mHandler.postDelayed(this, 1000 * mRollTime); } } public void stop() { if (isRunning) { mHandler.removeCallbacks(this); isRunning = false; } } } // /** // * 开启定时器 // * @param time // */ // public BannerViewPager addStartTimer(int time) { // if (mTimer == null) { // mTimer = new Timer(); // } // if(mTimerTask==null){ // mTimerTask=new MyTimerTask(); // } // mTimer.schedule(mTimerTask, 3000, 1000*time); // return this; // } // /** // * 停止定时器 // */ // public void stopTimer(){ // if(mTimer!=null){ // mTimer.cancel(); // mTimer = null; // } // if(mTimerTask!=null){ // mTimerTask.cancel(); // mTimerTask = null; // } // } // class MyTimerTask extends TimerTask { // @Override // public void run() { // mHandler.sendEmptyMessage(1001);//在此线程中,不能操作ui主线程 // } // } /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dip2px(float dpValue) { final float scale = mContext.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } //---------------viewpager滑动事件----------------- @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageScrollStateChanged(int state) { } /** * 滑动时同步改变底部小圆点 * * @param position */ @Override public void onPageSelected(int position) { currentIndex = position % mMaxNumber; setImageBackground(currentIndex); } /** * 改变指示器 * * @param selectItemsIndex */ private void setImageBackground(int selectItemsIndex) { if (isPoint) { for (int i = 0; i < mImageView.length; i++) { if (i == selectItemsIndex) { mImageView[i].setImageResource(resId_piont_press); } else { mImageView[i].setImageResource(resId_piont); } } } } /** * 检查异常 * * @param list */ private void checkException(List<String> list) { if (list == null) { throw new NullPointerException("The array is null at initBanner function"); } if (list.size() == 0) { throw new ArithmeticException("Your array size is 0"); } } } library-gallery/src/main/res/layout/banner_img_layout.xml
New file @@ -0,0 +1,20 @@ <?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" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_horizontal"> <com.lcjian.library.widget.RatioLayout android:id="@+id/rl_img" android:layout_width="match_parent" android:layout_height="wrap_content" app:ratio="0.7"> <ImageView android:id="@+id/img" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="fitXY" /> </com.lcjian.library.widget.RatioLayout> </RelativeLayout> library-gallery/src/main/res/layout/banner_view_layout.xml
New file @@ -0,0 +1,41 @@ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rootView" android:layout_width="match_parent" android:layout_height="wrap_content" android:clipChildren="false"> <!--viewpager--> <androidx.viewpager.widget.ViewPager android:id="@+id/viewPager" android:layout_width="match_parent" android:layout_height="wrap_content" android:clipChildren="false" android:layout_marginLeft="60dp" android:layout_marginRight="60dp"/> <!--指示器--> <LinearLayout android:id="@+id/lineIndicator" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:orientation="horizontal" android:paddingBottom="7dp" android:visibility="gone" android:gravity="center"> <!--<ImageView--> <!--android:layout_width="wrap_content"--> <!--android:layout_height="wrap_content"--> <!--android:src="@mipmap/ic_banner_point_press"--> <!--android:layout_marginLeft="8dp"--> <!--android:layout_marginRight="8dp"/>--> </LinearLayout> </RelativeLayout> library-gallery/src/main/res/mipmap-xhdpi/ic_banner_error.png
library-gallery/src/main/res/mipmap-xhdpi/ic_banner_point.png
library-gallery/src/main/res/mipmap-xhdpi/ic_banner_point_press.png
library-gallery/src/main/res/values/strings.xml
New file @@ -0,0 +1,3 @@ <resources> <string name="app_name">gallery</string> </resources> library-gallery/src/test/java/com/lzj/gallery/library/ExampleUnitTest.java
New file @@ -0,0 +1,17 @@ package com.lzj.gallery.library; import org.junit.Test; import static org.junit.Assert.*; /** * Example local unit test, which will execute on the development machine (host). * * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> */ public class ExampleUnitTest { @Test public void addition_isCorrect() throws Exception { assertEquals(4, 2 + 2); } }