| | |
| | | android:value="570f28a578d6e12cba6f7f200b8d1c83"></meta-data> |
| | | <meta-data |
| | | android:name="UMENG_CHANNEL" |
| | | android:value="qq"></meta-data> |
| | | android:value="vivo"></meta-data> |
| | | |
| | | |
| | | <provider |
| | |
| | | android:exported="true" |
| | | android:label="@string/app_name" |
| | | android:launchMode="singleTop" |
| | | android:taskAffinity="net.sourceforge.simcpux" |
| | | android:taskAffinity="com.doudou.ysvideo" |
| | | android:theme="@android:style/Theme.Translucent.NoTitleBar" /> |
| | | |
| | | <!-- QQ分享 --> |
| | |
| | | } |
| | | defaultConfig { |
| | | applicationId "com.doudou.ysvideo" |
| | | versionCode 94 |
| | | versionName "3.7.6" |
| | | versionCode 95 |
| | | versionName "3.7.7" |
| | | multiDexEnabled = true |
| | | minSdkVersion 17 |
| | | targetSdkVersion 27 |
| | |
| | | <LinearLayout |
| | | android:layout_width="match_parent" |
| | | android:layout_height="match_parent" |
| | | android:orientation="vertical" |
| | | android:paddingLeft="50dp" |
| | | android:paddingRight="50dp"> |
| | | android:orientation="vertical"> |
| | | |
| | | <LinearLayout |
| | | android:id="@+id/ll_login_content" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="wrap_content" |
| | | android:layout_gravity="center_horizontal" |
| | | android:layout_marginLeft="50dp" |
| | | android:layout_marginTop="120dp" |
| | | android:layout_marginRight="50dp" |
| | | android:focusable="true" |
| | | android:focusableInTouchMode="true" |
| | | android:orientation="vertical"> |
| | |
| | | |
| | | <EditText |
| | | android:id="@+id/et_name" |
| | | style="@style/loginInputStyle" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="wrap_content" |
| | | android:layout_marginLeft="18dp" |
| | | android:background="@null" |
| | | android:digits="@string/rule_email" |
| | | android:hint="请输入账户邮箱" |
| | | android:inputType="textEmailAddress" |
| | | style="@style/loginInputStyle" /> |
| | | android:inputType="textEmailAddress" /> |
| | | </LinearLayout> |
| | | |
| | | <LinearLayout |
| | |
| | | <LinearLayout |
| | | android:layout_width="match_parent" |
| | | android:layout_height="wrap_content" |
| | | android:layout_marginLeft="50dp" |
| | | android:layout_marginRight="50dp" |
| | | android:orientation="vertical" |
| | | android:paddingBottom="20dp"> |
| | | |
| | |
| | | android:layout_marginTop="3dp" |
| | | android:ellipsize="end" |
| | | android:maxLines="1" |
| | | android:text="http://www,baidu.com" |
| | | android:textColor="#DDDDDD" |
| | | android:textSize="8sp"></TextView> |
| | | |
| | |
| | | android:layout_marginTop="3dp" |
| | | android:ellipsize="end" |
| | | android:maxLines="1" |
| | | android:text="http://www,baidu.com" |
| | | android:textColor="#DDDDDD" |
| | | android:textSize="8sp"></TextView> |
| | | |
New file |
| | |
| | | <?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="#656565" |
| | | android:orientation="vertical" |
| | | android:paddingLeft="17dp" |
| | | android:paddingRight="17dp"> |
| | | |
| | | |
| | | <TextView |
| | | android:id="@+id/tv_content" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:layout_marginTop="12dp" |
| | | android:layout_marginBottom="12dp" |
| | | android:text="那奶奶在哪里" |
| | | android:textColor="#ffdddddd" |
| | | android:textSize="12sp" /> |
| | | |
| | | <View |
| | | android:id="@+id/view_cutline" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="1dp" |
| | | android:background="#505050"></View> |
| | | |
| | | |
| | | </LinearLayout> |
New file |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:orientation="vertical"> |
| | | |
| | | <TextView |
| | | android:id="@+id/tv_name" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:background="@drawable/vpi__tab_selected_focused_holo" |
| | | android:text="电视剧" |
| | | android:paddingBottom="15dp" |
| | | android:gravity="center" |
| | | android:textColor="@color/white" |
| | | android:textSize="17sp"></TextView> |
| | | |
| | | |
| | | </LinearLayout> |
| | |
| | | android:textSize="15sp" /> |
| | | |
| | | |
| | | <TextView |
| | | android:id="@+id/tv_tag" |
| | | style="@style/TextGrayNormal" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:layout_marginTop="2dp" |
| | | android:text="琅琊榜" |
| | | android:textColor="#DCDCDC" |
| | | android:textSize="14sp" /> |
| | | |
| | | |
| | | </LinearLayout> |
| | | |
| | | </LinearLayout> |
| | |
| | | <?xml version="1.0" encoding="utf-8"?> |
| | | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| | | <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="40dp" |
| | | android:layout_height="wrap_content" |
| | | android:background="@color/theme" |
| | | android:orientation="horizontal" |
| | | android:padding="8dp"> |
| | | android:paddingLeft="8dp" |
| | | android:paddingRight="8dp" |
| | | android:paddingBottom="12dp"> |
| | | |
| | | <FrameLayout |
| | | android:layout_width="0dp" |
| | | android:layout_height="match_parent" |
| | | android:layout_weight="1"> |
| | | <HorizontalScrollView |
| | | android:layout_width="match_parent" |
| | | android:layout_height="wrap_content" |
| | | android:scrollbars="none"> |
| | | |
| | | <TextView |
| | | android:id="@+id/tv_moive_all" |
| | | <LinearLayout |
| | | android:id="@+id/ll_top_bar" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:layout_gravity="right|center_vertical" |
| | | android:background="@drawable/ic_select2" |
| | | android:gravity="center" |
| | | android:text="全部" |
| | | android:textAppearance="?android:attr/textAppearanceSmall" |
| | | android:textColor="@color/selector_bottom_bar_text" /> |
| | | </FrameLayout> |
| | | android:gravity="center_vertical" |
| | | android:orientation="horizontal"> |
| | | |
| | | |
| | | <FrameLayout |
| | | android:layout_width="0dp" |
| | | android:layout_height="match_parent" |
| | | android:layout_weight="1"> |
| | | |
| | | <TextView |
| | | android:id="@+id/tv_moive" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:layout_gravity="center" |
| | | android:background="@drawable/ic_select1" |
| | | android:gravity="center" |
| | | android:text="正片" |
| | | android:textColor="@color/selector_bottom_bar_text" /> |
| | | |
| | | </FrameLayout> |
| | | |
| | | <FrameLayout |
| | | android:layout_width="0dp" |
| | | android:layout_height="match_parent" |
| | | android:layout_weight="1"> |
| | | |
| | | |
| | | <TextView |
| | | android:id="@+id/tv_moive_special" |
| | | android:layout_width="wrap_content" |
| | | android:layout_height="wrap_content" |
| | | android:layout_gravity="left|center_vertical" |
| | | android:background="@drawable/ic_select1" |
| | | android:gravity="center" |
| | | android:text="专辑" |
| | | android:textAppearance="?android:attr/textAppearanceSmall" |
| | | android:textColor="@color/selector_bottom_bar_text" /> |
| | | |
| | | </FrameLayout> |
| | | |
| | | </LinearLayout> |
| | | </LinearLayout> |
| | | </HorizontalScrollView> |
| | | </FrameLayout> |
| | |
| | | <include layout="@layout/video_introduction" /> |
| | | |
| | | <LinearLayout |
| | | android:id="@+id/ll_relative_video" |
| | | android:layout_width="match_parent" |
| | | android:layout_height="wrap_content" |
| | | android:layout_marginTop="4dp" |
| | |
| | | import com.weikou.beibeivideo.BasicTextHttpResponseHandler; |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | import com.weikou.beibeivideo.BeibeiVideoApplication; |
| | | import com.weikou.beibeivideo.ui.BaseActivity; |
| | | import com.weikou.beibeivideo.util.UserUtil; |
| | | |
| | | import org.apache.http.Header; |
| | | import org.json.JSONObject; |
| | | |
| | | |
| | | public class WXEntryActivity extends Activity implements IWXAPIEventHandler { |
| | | public class WXEntryActivity extends BaseActivity implements IWXAPIEventHandler { |
| | | private static final int RETURN_MSG_TYPE_LOGIN = 1; |
| | | private static final int RETURN_MSG_TYPE_SHARE = 2; |
| | | private static final int RETURN_MSG_TYPE_XCX = 19; |
| | |
| | | public static void search(Context context, String uid, String key, |
| | | String contentType, String page, ResponseHandlerInterface handler) { |
| | | LinkedHashMap<String, String> params = new LinkedHashMap<String, String>(); |
| | | params.put("Method", "search"); |
| | | params.put("Method", "searchNew"); |
| | | params.put("Uid", uid); |
| | | params.put("Key", key); |
| | | params.put("Type", "1"); |
| | | params.put("ContentType", contentType); |
| | | params.put("Type", contentType); |
| | | params.put("Page", page); |
| | | commonPost(context, BASE_URL + "user", params, handler); |
| | | } |
| | |
| | | // if (res.getConfiguration().fontScale != 1) {//非默认值 |
| | | Configuration newConfig = new Configuration(); |
| | | newConfig.setToDefaults();//设置默认 |
| | | newConfig.fontScale=1.2f; |
| | | res.updateConfiguration(newConfig, res.getDisplayMetrics()); |
| | | // } |
| | | return res; |
| | |
| | | import com.weikou.beibeivideo.util.PermissionsActivity; |
| | | import com.weikou.beibeivideo.util.PermissionsChecker; |
| | | import com.weikou.beibeivideo.util.SDCardUtil; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.ad.CSJConstant; |
| | | import com.weikou.beibeivideo.util.ad.GDTConstant; |
| | | import com.weikou.beibeivideo.util.ad.SplashAdUtil; |
| | |
| | | ad_close_time = findViewById(R.id.ad_close_time); |
| | | iv_logo = findViewById(R.id.iv_logo); |
| | | |
| | | Glide.with(getApplicationContext()).load(R.drawable.ic_launcher).transform(new GlideRoundTransform(getApplicationContext(),5)).into(iv_logo); |
| | | Glide.with(getApplicationContext()).load(R.drawable.ic_launcher).transform(new GlideRoundTransform(getApplicationContext(), 5)).into(iv_logo); |
| | | |
| | | SharedPreferences preferences = getSharedPreferences("link_page", |
| | | Context.MODE_PRIVATE); |
| | |
| | | BeibeiConstant.GDT_DISCOVER_NATIVE = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | | BeibeiConstant.GDT_GUESS_LIKE_NATIVE = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | | BeibeiConstant.GDT_RECOMMEND_CATEGORY_NATIVE = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | | BeibeiConstant.GDT_EXIT_DIALOG = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | | BeibeiConstant.GDT_SEARCH_RESULT_MIN_NATIVE = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | | BeibeiConstant.GDT_PLAYER_DETAIL = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | | BeibeiConstant.GDT_CATEGORY_BANNER = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | |
| | | GDTConstant.PID_2_VIDEO_LIST_SMALL_AD_COLUMN3 = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | | GDTConstant.PID_2_VIDEO_LIST_SMALL_AD_COLUMN2 = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | | GDTConstant.PID_HOME_RECOMMEND_BIG_IMG = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | | GDTConstant.PID_VIDEO_DETAIL_PLAYER = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | | |
| | | CSJConstant.RECOMMEND_BIG_IMG_AD = CSJConstant.INVALID_AD; |
| | | } |
| | |
| | | * |
| | | * @param adType |
| | | */ |
| | | private void loadSplashAd(final String adType) { |
| | | private void loadSplashAd(final AdUtil.AD_TYPE adType) { |
| | | SplashAdUtil.loadAD(adType, SplashActivity.this, vg_input, vg_ad, ad_close_time, new SplashAdUtil.SplashAdListener() { |
| | | @Override |
| | | public void close() { |
| | |
| | | |
| | | @Override |
| | | public void noAd() {//初次加载未加载出广告 |
| | | if (AdTypeVO.TYPE_CSJ.equalsIgnoreCase(adType)) { |
| | | if (AdUtil.AD_TYPE.csj==adType) { |
| | | //再次加载广点通广告 |
| | | SplashAdUtil.loadAD(AdTypeVO.TYPE_GDT, SplashActivity.this, vg_input, vg_ad, ad_close_time, new SplashAdUtil.SplashAdListener() { |
| | | SplashAdUtil.loadAD(AdUtil.AD_TYPE.gdt, SplashActivity.this, vg_input, vg_ad, ad_close_time, new SplashAdUtil.SplashAdListener() { |
| | | @Override |
| | | public void close() { |
| | | runOnUiThread(new Runnable() { |
| | |
| | | } |
| | | }); |
| | | |
| | | } else if (AdTypeVO.TYPE_GDT.equalsIgnoreCase(adType)) { |
| | | } else if (AdUtil.AD_TYPE.gdt==adType) { |
| | | //再次加载穿山甲广告 |
| | | //再次加载广点通广告 |
| | | SplashAdUtil.loadAD(AdTypeVO.TYPE_CSJ, SplashActivity.this, vg_input, vg_ad, ad_close_time, new SplashAdUtil.SplashAdListener() { |
| | | SplashAdUtil.loadAD(AdUtil.AD_TYPE.csj, SplashActivity.this, vg_input, vg_ad, ad_close_time, new SplashAdUtil.SplashAdListener() { |
| | | @Override |
| | | public void close() { |
| | | runOnUiThread(new Runnable() { |
| | |
| | | if (jsonObject.getBoolean("IsPost")) { |
| | | JSONObject data = jsonObject.getJSONObject("Data"); |
| | | JSONObject ad = data.optJSONObject("ad"); |
| | | String splash = ad.optString("splash"); |
| | | AdUtil.saveAdConfig(getApplicationContext(), ad); |
| | | AdUtil.AD_TYPE splash = AdUtil.getAdType(getApplicationContext(), AdUtil.POSITION_SPLASH); |
| | | loadSplashAd(splash); |
| | | } |
| | | } else { |
| | | loadSplashAd(AdTypeVO.TYPE_GDT); |
| | | loadSplashAd(AdUtil.AD_TYPE.gdt); |
| | | } |
| | | } |
| | | |
| | |
| | | @Override |
| | | public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { |
| | | super.onFailure(statusCode, headers, responseString, throwable); |
| | | loadSplashAd(AdTypeVO.TYPE_GDT); |
| | | loadSplashAd(AdUtil.AD_TYPE.gdt); |
| | | } |
| | | }); |
| | | |
| | |
| | | import com.qq.e.comm.constants.AdPatternType; |
| | | import com.qq.e.comm.util.AdError; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.ad.GDTConstant; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | if (mAdData != null) |
| | | mAdData.destroy(); |
| | | pb_progress.setVisibility(View.VISIBLE); |
| | | NativeUnifiedAD mAdManager = new NativeUnifiedAD(getContext(), GDTConstant.PID_VIDEO_DETAIL_PLAYER, new NativeADUnifiedListener() { |
| | | String pid = GDTConstant.PID_VIDEO_DETAIL_PLAYER; |
| | | if (AdUtil.getAdType(getContext(), AdUtil.POSITION_VIDEO_PLAY_PRE) != AdUtil.AD_TYPE.gdt) |
| | | pid = BeibeiConstant.GDT_DOWNLOAD_HINT_ID; |
| | | |
| | | NativeUnifiedAD mAdManager = new NativeUnifiedAD(getContext(), pid, new NativeADUnifiedListener() { |
| | | |
| | | @Override |
| | | public void onNoAD(AdError adError) {//没有广告 |
| | |
| | | Log.d(TAG, "onVideoCacheFailed:" + msg); |
| | | } |
| | | }); |
| | | }else{ |
| | | } else { |
| | | pb_progress.setVisibility(View.GONE); |
| | | if (videoAdListener != null) { |
| | | videoAdListener.finishPlay(); |
| | |
| | | @Override |
| | | public void onComplete(SHARE_MEDIA platform, int action, final Map<String, String> data) { |
| | | dialog.dismiss(); |
| | | Toast.makeText(LoginActivity.this, new Gson().toJson(data), Toast.LENGTH_SHORT).show(); |
| | | Log.i("mResult", "返回的数据为----" + data); |
| | | BeibeiVideoAPI.userLogin(LoginActivity.this, uid, |
| | | data.get("name"), data.get("openid"), |
| | |
| | | @Override |
| | | protected void onActivityResult(int requestCode, int resultCode, Intent data) { |
| | | super.onActivityResult(requestCode, resultCode, data); |
| | | // UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data); |
| | | UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data); |
| | | } |
| | | |
| | | Handler mHandler = new Handler() { |
| | |
| | | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| | | if (keyCode == KeyEvent.KEYCODE_BACK) { |
| | | if (exitDialog != null) { |
| | | exitDialogBuilder.showAd(); |
| | | exitDialog.show(); |
| | | } |
| | | return true; |
| | |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.beibeivideo.util.GlideCircleTransform; |
| | | import com.weikou.beibeivideo.util.VideoUtil; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | | import com.weikou.beibeivideo.R; |
| | | |
| | |
| | | public void run() { |
| | | Log.i(TAG, "refresh"); |
| | | rv_episode.setAdapter(episodeAdapter); |
| | | if (mPlayingPosition > 4) |
| | | rv_episode.scrollToPosition(mPlayingPosition); |
| | | } |
| | | }, 500); |
| | | |
| | |
| | | |
| | | // 加载播放页第一条广告,先设置加载上下文环境和条件 |
| | | private void loadAD1() { |
| | | new ExpressAdManager(ExpressAdManager.SOURCE_GDT2, getContext()).loadVideoDetailPlayerBottomAd(new ExpressAdManager.IAdLoadListener() { |
| | | new ExpressAdManager(AdUtil.AD_TYPE.gdt2, getContext()).loadVideoDetailPlayerBottomAd(new ExpressAdManager.IAdLoadListener() { |
| | | @Override |
| | | public void onSuccess(List<ExpressAdContainer> adList) { |
| | | if (adList != null && adList.size() > 0) { |
| | |
| | | if (getIntent().getSerializableExtra("video_info") != null) { |
| | | videoInfo = (VideoInfo) getIntent().getSerializableExtra( |
| | | "video_info"); |
| | | if(videoInfo!=null) |
| | | videoInfo.setVideoDetailList(null); |
| | | if (getIntent().getBooleanExtra("isFromWatchHistory", false)) { |
| | | Cursor cursor = getContentResolver().query( |
| | | WatchHistoryTable.CONTENT_URI, null, |
| | |
| | | .findFragmentByTag("VideoDetailFragment"); |
| | | if (videoDetailFragment == null) { |
| | | videoDetailFragment = new VideoDetailFragment(); |
| | | Bundle bundle=new Bundle(); |
| | | bundle.putInt("playing_position",getIntent().getIntExtra("playing_position",0)); |
| | | videoDetailFragment.setArguments(bundle); |
| | | |
| | | fm.beginTransaction() |
| | | .add(R.id.fragment_video_detail_container, |
| | | videoDetailFragment, "VideoDetailFragment") |
| | |
| | | .getBooleanExtra("isFromWatchHistory", |
| | | false);// 是否从观看记录点击过来 |
| | | Log.i("mResult", "是否是从观看记录点击进来的:" + isFromWatchHistory); |
| | | if (isFromWatchHistory) { |
| | | if (isFromWatchHistory||position>0) { |
| | | mPosition = getIntent().getIntExtra("playing_position", 0); |
| | | EventBus.getDefault().post(videoInfo); |
| | | getUrl(videoInfo.getVideoDetailList().get(mPosition), isSetup); |
| | |
| | | View view = inflater.inflate(R.layout.video_detail_fragment, container, |
| | | false); |
| | | this.view = view; |
| | | if (getArguments() != null) |
| | | mPlayingPosition = getArguments().getInt("playing_position", 0); |
| | | return view; |
| | | } |
| | | |
| | |
| | | import com.weikou.beibeivideo.ui.video.IVideoClickListener; |
| | | import com.weikou.beibeivideo.ui.video.VideoColumn2Adapter; |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | | import com.weikou.beibeivideo.widget.FullyGridLayoutManager; |
| | | import com.weikou.beibeivideo.R; |
| | |
| | | private ImageView video_more_image; |
| | | private LinearLayout video_introduction_more; |
| | | private FrameLayout fl_native_ad_1; |
| | | private LinearLayout ll_relative_video; |
| | | |
| | | public static boolean isShowMore = false;// 是否显示更多 |
| | | public static int page_varietyshow = 0;// 综艺节目的分页 |
| | |
| | | fl_native_ad_1 = contentView |
| | | .findViewById(R.id.fl_native_ad_1); |
| | | |
| | | ll_relative_video = contentView |
| | | .findViewById(R.id.ll_relative_video); |
| | | |
| | | contentView.findViewById(R.id.ll_container).setFocusable(true); |
| | | contentView.findViewById(R.id.ll_container).setFocusableInTouchMode(true); |
| | | |
| | |
| | | new TypeToken<List<VideoInfo>>() { |
| | | }.getType()); |
| | | |
| | | |
| | | final VideoColumn2Adapter adapter = new VideoColumn2Adapter(getActivity(), getContext(), videoInfos, false, 2, new IVideoClickListener() { |
| | | @Override |
| | | public void onClick(VideoInfo video) { |
| | | ChangeVideoEvent changeVideoEvent = new ChangeVideoEvent(); |
| | | changeVideoEvent.setVideoInfo(video); |
| | | changeVideoEvent.setTag("VideoPlayerFragment"); |
| | | EventBus.getDefault().post(changeVideoEvent); |
| | | } |
| | | }); |
| | | adapter.initRecyclerViewDisplayWidthColumn2(rv_video_related_video); |
| | | |
| | | if (getActivity() == null) |
| | | return; |
| | | getActivity().runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (rv_video_related_video != null) { |
| | | rv_video_related_video.setAdapter(adapter); |
| | | if (videoInfos == null || videoInfos.size() == 0) { |
| | | ll_relative_video.setVisibility(View.GONE); |
| | | } else { |
| | | ll_relative_video.setVisibility(View.VISIBLE); |
| | | final VideoColumn2Adapter adapter = new VideoColumn2Adapter(getActivity(), getContext(), videoInfos, false, 2, new IVideoClickListener() { |
| | | @Override |
| | | public void onClick(VideoInfo video) { |
| | | ChangeVideoEvent changeVideoEvent = new ChangeVideoEvent(); |
| | | changeVideoEvent.setVideoInfo(video); |
| | | changeVideoEvent.setTag("VideoPlayerFragment"); |
| | | EventBus.getDefault().post(changeVideoEvent); |
| | | } |
| | | if (adRunnable != null) |
| | | rv_video_related_video.post(adRunnable); |
| | | } |
| | | }); |
| | | }); |
| | | adapter.initRecyclerViewDisplayWidthColumn2(rv_video_related_video); |
| | | |
| | | if (getActivity() == null) |
| | | return; |
| | | getActivity().runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (rv_video_related_video != null) { |
| | | rv_video_related_video.setAdapter(adapter); |
| | | } |
| | | if (adRunnable != null) |
| | | rv_video_related_video.post(adRunnable); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | |
| | | */ |
| | | // 加载播放页第二条广告 |
| | | private void loadAD2() { |
| | | new ExpressAdManager(ExpressAdManager.SOURCE_GDT2, getContext()).loadVideoDetailRelativeVideoBottomAd(new ExpressAdManager.IAdLoadListener() { |
| | | new ExpressAdManager(AdUtil.AD_TYPE.gdt2, getContext()).loadVideoDetailRelativeVideoBottomAd(new ExpressAdManager.IAdLoadListener() { |
| | | @Override |
| | | public void onSuccess(List<ExpressAdContainer> adList) { |
| | | if (adList != null && adList.size() > 0) |
| | |
| | | |
| | | private void loadAd() { |
| | | try { |
| | | ExpressAdManager recommendAdManager = new ExpressAdManager(ExpressAdManager.SOURCE_CSJ, context); |
| | | ExpressAdManager recommendAdManager = new ExpressAdManager(AdUtil.AD_TYPE.csj, context); |
| | | recommendAdManager.loadRecommendLargeAd(new ExpressAdManager.IAdLoadListener() { |
| | | @Override |
| | | public void onSuccess(final List<ExpressAdContainer> adList) { |
| | |
| | | import com.weikou.beibeivideo.BasicTextHttpResponseHandler; |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | import com.weikou.beibeivideo.ui.BaseActivity; |
| | | import com.weikou.beibeivideo.ui.video.SuggestKeysAdapter; |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.beibeivideo.R; |
| | | |
| | |
| | | .getJSONObject("Data").getJSONArray("data") |
| | | .toString(), new TypeToken<List<String>>() { |
| | | }.getType()); |
| | | ArrayAdapter<String> adapter = new ArrayAdapter<String>( |
| | | SearchActivity.this, |
| | | android.R.layout.simple_list_item_1, |
| | | results); |
| | | |
| | | SuggestKeysAdapter adapter = new SuggestKeysAdapter(getApplicationContext(), results); |
| | | et_search_key.setAdapter(adapter); |
| | | adapter.notifyDataSetChanged(); |
| | | } |
| | |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.SharedPreferences; |
| | | import android.graphics.Color; |
| | | import android.graphics.drawable.Drawable; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | |
| | | import android.widget.AdapterView.OnItemClickListener; |
| | | import android.widget.ArrayAdapter; |
| | | import android.widget.AutoCompleteTextView; |
| | | import android.widget.BaseAdapter; |
| | | import android.widget.Filter; |
| | | import android.widget.Filterable; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.LinearLayout.LayoutParams; |
| | | import android.widget.ProgressBar; |
| | | import android.widget.TextView; |
| | |
| | | import com.weikou.beibeivideo.BasicTextHttpResponseHandler; |
| | | import com.weikou.beibeivideo.BeibeiVideoAPI; |
| | | import com.weikou.beibeivideo.entity.VideoInfo; |
| | | import com.weikou.beibeivideo.entity.VideoType; |
| | | import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; |
| | | import com.weikou.beibeivideo.entity.video.VideoContent; |
| | | import com.weikou.beibeivideo.ui.BaseActivity; |
| | | import com.weikou.beibeivideo.ui.video.SearchResultAdapter; |
| | | import com.weikou.beibeivideo.ui.video.SuggestKeysAdapter; |
| | | import com.weikou.beibeivideo.ui.video.VideoCloumn1Adapter; |
| | | import com.weikou.beibeivideo.util.DimenUtils; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | |
| | | |
| | | private View loading; |
| | | |
| | | private LinearLayout ll_top_bar; |
| | | |
| | | List<VideoType> typeList; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | | super.onCreate(savedInstanceState); |
| | |
| | | et_search_key = findViewById(R.id.et_search_key); |
| | | tv_search_cancel = findViewById(R.id.tv_search_cancel); |
| | | rv_video_search = findViewById(R.id.rv_video_search); |
| | | findViewById(R.id.tv_moive_all).setOnClickListener(this); |
| | | findViewById(R.id.tv_moive).setOnClickListener(this); |
| | | findViewById(R.id.tv_moive_special).setOnClickListener(this); |
| | | ll_top_bar = findViewById(R.id.ll_top_bar); |
| | | |
| | | tv_search_cancel.setOnClickListener(this); |
| | | et_search_key.addTextChangedListener(new TextWatcher() { |
| | | |
| | |
| | | mCurrentKey = parent.getItemAtPosition(position).toString(); |
| | | SoftKeyboardUtils.hideSoftInput(SearchResultActivity.this); |
| | | mCurrentPage = 1; |
| | | //清除顶部分类 |
| | | typeList = null; |
| | | search(mCurrentKey, mCurrentType); |
| | | } |
| | | }); |
| | |
| | | SoftKeyboardUtils.hideSoftInput(SearchResultActivity.this); |
| | | mCurrentPage = 1; |
| | | rl_search_result.setRefreshing(true); |
| | | //清除顶部分类 |
| | | typeList = null; |
| | | search(mCurrentKey, mCurrentType); |
| | | return true; |
| | | } |
| | |
| | | }); |
| | | |
| | | |
| | | rv_video_search.setLayoutManager(new LinearLayoutManager(getApplicationContext())); |
| | | rv_video_search.setLayoutManager(new MyLinearLayoutManager(getApplicationContext())); |
| | | DividerItemDecoration decoration = new DividerItemDecoration(); |
| | | decoration.setSize(DimenUtils.dip2px(rv_video_search.getContext(), 6)); |
| | | rv_video_search.addItemDecoration(decoration); |
| | |
| | | int total = manager.getItemCount(); |
| | | if (newState == RecyclerView.SCROLL_STATE_IDLE) { |
| | | if ((!isLoad) && last == total - 1 && mVideoInfos.size() < 1000) { |
| | | mCurrentPage++; |
| | | isLoad = true; |
| | | loading.setVisibility(View.VISIBLE); |
| | | search(mCurrentKey, mCurrentType); |
| | | if (mVideoInfos != null && mVideoInfos.size() > 0 && !rl_search_result.isRefreshing()) {//列表中有数据才能加载更多 |
| | | mCurrentPage++; |
| | | isLoad = true; |
| | | loading.setVisibility(View.VISIBLE); |
| | | search(mCurrentKey, mCurrentType); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | rl_search_result.setRefreshing(true); |
| | | search(mCurrentKey, mCurrentType); |
| | | // loadAd(); |
| | | } |
| | | |
| | | private void initTopBar(List<VideoType> videoTypeList) { |
| | | int p = 0; |
| | | ll_top_bar.removeAllViews(); |
| | | LayoutInflater inflater = LayoutInflater.from(getApplicationContext()); |
| | | for (int i = 0; i < videoTypeList.size(); i++) { |
| | | final View view = inflater.inflate(R.layout.item_search_result_top_bar_content, null); |
| | | TextView tv_name = view.findViewById(R.id.tv_name); |
| | | tv_name.setText(videoTypeList.get(i).getName()); |
| | | setTopBarSelect(tv_name, i == p); |
| | | ll_top_bar.addView(view); |
| | | ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); |
| | | params.rightMargin = DimenUtils.dip2px(getApplicationContext(), 17); |
| | | params.leftMargin = DimenUtils.dip2px(getApplicationContext(), 10); |
| | | view.setTag(i); |
| | | view.setOnClickListener(new OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | int p = Integer.parseInt(view.getTag() + ""); |
| | | selectTopBar(p); |
| | | VideoType vt = videoTypeList.get(p); |
| | | |
| | | if (StringUtils.isBlank(mCurrentType) || !mCurrentType.equalsIgnoreCase(vt.getId())) { |
| | | mCurrentPage = 1; |
| | | mCurrentType = vt.getId(); |
| | | rl_search_result.setRefreshing(true); |
| | | search(mCurrentKey, mCurrentType); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | private void setTopBarSelect(TextView tv_name, boolean selected) { |
| | | if (selected) { |
| | | tv_name.setBackgroundResource(R.drawable.vpi__tab_selected_focused_holo); |
| | | tv_name.setTextSize(17); |
| | | tv_name.setTextColor(Color.parseColor("#FFFFFF")); |
| | | tv_name.setPadding(0, 0, 0, DimenUtils.dip2px(getApplicationContext(), 5)); |
| | | } else { |
| | | tv_name.setBackground(null); |
| | | tv_name.setTextSize(12); |
| | | tv_name.setTextColor(Color.parseColor("#999999")); |
| | | tv_name.setPadding(0, 0, 0, 0); |
| | | } |
| | | } |
| | | |
| | | private void selectTopBar(int p) { |
| | | for (int i = 0; i < ll_top_bar.getChildCount(); i++) { |
| | | TextView tv = ll_top_bar.getChildAt(i).findViewById(R.id.tv_name); |
| | | setTopBarSelect(tv, i == p); |
| | | } |
| | | } |
| | | |
| | | private void suggestSearch(String key) { |
| | |
| | | .getJSONObject("Data").getJSONArray("data") |
| | | .toString(), new TypeToken<List<String>>() { |
| | | }.getType()); |
| | | ArrayAdapter<String> adapter = new ArrayAdapter<String>( |
| | | SearchResultActivity.this, |
| | | android.R.layout.simple_list_item_1, |
| | | results); |
| | | SuggestKeysAdapter adapter = new SuggestKeysAdapter(getApplicationContext(), results); |
| | | et_search_key.setAdapter(adapter); |
| | | adapter.notifyDataSetChanged(); |
| | | } |
| | |
| | | Gson gson = new GsonBuilder().setFieldNamingPolicy( |
| | | FieldNamingPolicy.UPPER_CAMEL_CASE) |
| | | .create(); |
| | | JSONObject rootData = jsonObject.getJSONObject("Data"); |
| | | List<VideoInfo> videoInfos = gson.fromJson( |
| | | jsonObject.getJSONObject("Data") |
| | | .getJSONArray("data").toString(), |
| | | |
| | | rootData.getJSONArray("data").toString(), |
| | | new TypeToken<List<VideoInfo>>() { |
| | | }.getType()); |
| | | |
| | | //设置导航栏 |
| | | if (rootData.opt("typeList") != null) { |
| | | if (typeList == null) { |
| | | typeList = gson.fromJson( |
| | | rootData |
| | | .getJSONArray("typeList").toString(), |
| | | new TypeToken<List<VideoType>>() { |
| | | }.getType()); |
| | | initTopBar(typeList); |
| | | } |
| | | } |
| | | |
| | | List<VideoContent> videoContentList = new ArrayList<>(); |
| | | for (VideoInfo video : videoInfos) { |
| | |
| | | videoContentList.add(adPosition, VideoContent.createAdContent(adList.get(0))); |
| | | adList.remove(0); |
| | | } |
| | | if (mCurrentPage <= 1) |
| | | if (mCurrentPage <= 1) { |
| | | mVideoInfos.clear(); |
| | | } |
| | | mVideoInfos.addAll(videoContentList); |
| | | adapter.notifyDataSetChanged(); |
| | | |
| | |
| | | case R.id.tv_top_bar_left: |
| | | finish(); |
| | | break; |
| | | case R.id.tv_moive_all: |
| | | rl_search_result.setRefreshing(true); |
| | | mVideoInfos.clear(); |
| | | mCurrentPage = 1; |
| | | mCurrentType = "0"; |
| | | findViewById(R.id.tv_moive_all).setBackgroundResource(R.drawable.ic_select2); |
| | | findViewById(R.id.tv_moive).setBackgroundResource(R.drawable.ic_select1); |
| | | findViewById(R.id.tv_moive_special).setBackgroundResource(R.drawable.ic_select1); |
| | | search(mCurrentKey, mCurrentType); |
| | | break; |
| | | case R.id.tv_moive: |
| | | mVideoInfos.clear(); |
| | | rl_search_result.setRefreshing(true); |
| | | mCurrentPage = 1; |
| | | mCurrentType = "1"; |
| | | findViewById(R.id.tv_moive_all).setBackgroundResource(R.drawable.ic_select1); |
| | | findViewById(R.id.tv_moive).setBackgroundResource(R.drawable.ic_select2); |
| | | findViewById(R.id.tv_moive_special).setBackgroundResource(R.drawable.ic_select1); |
| | | search(mCurrentKey, mCurrentType); |
| | | break; |
| | | case R.id.tv_moive_special: |
| | | mVideoInfos.clear(); |
| | | rl_search_result.setRefreshing(true); |
| | | mCurrentPage = 1; |
| | | mCurrentType = "2"; |
| | | findViewById(R.id.tv_moive_all).setBackgroundResource(R.drawable.ic_select1); |
| | | findViewById(R.id.tv_moive).setBackgroundResource(R.drawable.ic_select1); |
| | | findViewById(R.id.tv_moive_special).setBackgroundResource(R.drawable.ic_select2); |
| | | search(mCurrentKey, mCurrentType); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | |
| | | .putString("history", |
| | | builder.substring(0, builder.length() - 1)).commit(); |
| | | } |
| | | |
| | | |
| | | class MyLinearLayoutManager extends LinearLayoutManager { |
| | | |
| | | public MyLinearLayoutManager(Context context) { |
| | | super(context); |
| | | } |
| | | |
| | | @Override |
| | | public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) { |
| | | try { |
| | | super.onLayoutChildren(recycler, state); |
| | | } catch (IndexOutOfBoundsException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | import android.app.Activity; |
| | | import android.content.Intent; |
| | | import android.net.http.DelegatingSSLSession; |
| | | import android.support.annotation.NonNull; |
| | | import android.support.v7.widget.RecyclerView; |
| | | import android.view.LayoutInflater; |
| | |
| | | import android.widget.TextView; |
| | | |
| | | import com.bumptech.glide.Glide; |
| | | import com.lcjian.library.util.common.StringUtils; |
| | | import com.weikou.beibeivideo.entity.VideoDetailInfo; |
| | | import com.weikou.beibeivideo.entity.VideoInfo; |
| | | import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; |
| | |
| | | final VideoInfo info = videoContent.getVideo(); |
| | | final AlbumVideoHolder albumVideoHolder = (AlbumVideoHolder) holder; |
| | | try { |
| | | Glide.with(mContext).load(info.getPicture()).transition(withCrossFade()).placeholder(R.color.black).into(albumVideoHolder.iv_picture); |
| | | String pic=info.getVpicture(); |
| | | if(StringUtils.isBlank(pic)) |
| | | pic=info.getPicture(); |
| | | |
| | | Glide.with(mContext).load(pic).transition(withCrossFade()).placeholder(R.color.black).into(albumVideoHolder.iv_picture); |
| | | } catch (IllegalArgumentException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | albumVideoHolder.tv_name.setText(info.getName() + ""); |
| | | albumVideoHolder.tv_type.setText(info.getYear() + "/" + info.getArea()); |
| | | albumVideoHolder.tv_type.setText(info.getTag()); |
| | | albumVideoHolder.tv_actors.setText(info.getMainActor()); |
| | | |
| | | |
| | |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (albumVideoHolder.tv_video_4.getVisibility() == View.VISIBLE) { |
| | | myClick(info, v, videoDetailInfos.size() - 2); |
| | | myClick(info, v, Integer.parseInt(videoDetailInfos.get(3).getTag())); |
| | | } |
| | | } |
| | | }); |
| | |
| | | @Override |
| | | public void onClick(View v) { |
| | | if (albumVideoHolder.tv_video_5.getVisibility() == View.VISIBLE) { |
| | | myClick(info, v, videoDetailInfos.size() - 1); |
| | | myClick(info, v, Integer.parseInt(videoDetailInfos.get(4).getTag())); |
| | | } |
| | | } |
| | | }); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | simpleVideoHolder.tv_movie_title.setText(info.getName() + ""); |
| | | |
| | | |
| | | if (!StringUtils.isBlank(info.getTag())) |
| | | simpleVideoHolder.tv_tag.setText(info.getTag()); |
| | | else |
| | | simpleVideoHolder.tv_tag.setText(""); |
| | | |
| | | simpleVideoHolder.view.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | |
| | | |
| | | class SimpleVideoHolder extends RecyclerView.ViewHolder { |
| | | ImageView iv_movie_cover; |
| | | TextView tv_movie_title; |
| | | TextView tv_movie_title, tv_tag; |
| | | View view; |
| | | |
| | | public SimpleVideoHolder(View view) { |
| | |
| | | this.view = view; |
| | | iv_movie_cover = view.findViewById(R.id.iv_movie_cover); |
| | | tv_movie_title = view.findViewById(R.id.tv_movie_title); |
| | | tv_tag = view.findViewById(R.id.tv_tag); |
| | | } |
| | | } |
| | | |
New file |
| | |
| | | package com.weikou.beibeivideo.ui.video; |
| | | |
| | | import android.content.Context; |
| | | import android.view.LayoutInflater; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.BaseAdapter; |
| | | import android.widget.Filter; |
| | | import android.widget.Filterable; |
| | | import android.widget.TextView; |
| | | |
| | | import com.weikou.beibeivideo.R; |
| | | |
| | | import java.util.List; |
| | | |
| | | public class SuggestKeysAdapter extends BaseAdapter implements Filterable { |
| | | private ArrayFilter mFilter; |
| | | private List<String> keys; |
| | | private LayoutInflater layoutInflater; |
| | | |
| | | |
| | | public SuggestKeysAdapter(Context context, List<String> keys) { |
| | | this.keys = keys; |
| | | layoutInflater = LayoutInflater.from(context); |
| | | } |
| | | |
| | | @Override |
| | | public int getCount() { |
| | | return keys.size(); |
| | | } |
| | | |
| | | @Override |
| | | public Object getItem(int position) { |
| | | return keys.get(position); |
| | | } |
| | | |
| | | @Override |
| | | public long getItemId(int position) { |
| | | return position; |
| | | } |
| | | |
| | | @Override |
| | | public View getView(int position, View convertView, ViewGroup parent) { |
| | | View view = layoutInflater.inflate(R.layout.item_search_result_sugguest, null); |
| | | TextView tv_content = view.findViewById(R.id.tv_content); |
| | | View view_cutLine = view.findViewById(R.id.view_cutline); |
| | | tv_content.setText(keys.get(position)); |
| | | |
| | | if (position == keys.size() - 1) { |
| | | view_cutLine.setVisibility(View.GONE); |
| | | } else { |
| | | view_cutLine.setVisibility(View.VISIBLE); |
| | | } |
| | | return view; |
| | | } |
| | | |
| | | @Override |
| | | public Filter getFilter() { |
| | | if (mFilter == null) { |
| | | mFilter = new ArrayFilter(); |
| | | } |
| | | return mFilter; |
| | | } |
| | | |
| | | |
| | | private class ArrayFilter extends Filter { |
| | | |
| | | @Override |
| | | protected FilterResults performFiltering(CharSequence prefix) { |
| | | FilterResults results = new FilterResults(); |
| | | results.values = keys; |
| | | results.count = keys.size(); |
| | | return results; |
| | | } |
| | | |
| | | @Override |
| | | protected void publishResults(CharSequence constraint, |
| | | FilterResults results) { |
| | | if (keys.size() > 0) { |
| | | notifyDataSetChanged(); |
| | | } else { |
| | | notifyDataSetInvalidated(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | public class BeibeiConstant { |
| | | |
| | | public final static boolean IS_TEST=false; |
| | | public final static boolean IS_TEST = false; |
| | | |
| | | //首页推荐第一个广告 |
| | | public final static boolean AD_SETTING_RECOMMEND_FIRST = true; |
| | |
| | | public static String GDT_SPLASH_POSITION_ID_HUAWEI = "5040607358287251"; |
| | | // 广点通 用于开屏广告_华为专用2 |
| | | public static String GDT_SPLASH_POSITION_ID_HUAWEI2 = "3050653675121935"; |
| | | //广点通VIVO开屏 |
| | | public static String GDT_SPLASH_VIVO_POSITION_ID = "3061221866743243"; |
| | | |
| | | // 广点通 原生首页推荐一屏 |
| | | public static String GDT_RECOMMAND_MIN_NATIVE = "2020450766955933"; |
| | |
| | | import com.qq.e.ads.nativ.NativeExpressADView; |
| | | import com.qq.e.comm.util.AdError; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.weikou.beibeivideo.entity.ad.AdTypeVO; |
| | | import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager.IAdEventListener; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | this.setCancelable(false); |
| | | } |
| | | |
| | | |
| | | public static class Builder { |
| | | private Activity context; |
| | | private String positiveButtonText; |
| | | private String negativeButtonText; |
| | | private OnClickListener positiveButtonClickListener; |
| | | private OnClickListener negativeButtonClickListener; |
| | | ExpressAdManager expressAdManager; |
| | | |
| | | public Builder(Activity context) { |
| | | this.context = context; |
| | | expressAdManager = new ExpressAdManager(AdUtil.getAdType(context, AdUtil.POSITION_EXIT_APP), context); |
| | | } |
| | | |
| | | |
| | |
| | | */ |
| | | private FrameLayout fl_advertisement; |
| | | |
| | | private ExpressAdContainer expressAdContainer; |
| | | |
| | | public ExitDialog create() { |
| | | LayoutInflater inflater = (LayoutInflater) context |
| | | .getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| | |
| | | final ExitDialog dialog = new ExitDialog(context, R.style.Dialog); |
| | | View layout = inflater.inflate(R.layout.item_exit, null); |
| | | fl_advertisement = layout.findViewById(R.id.fl_advertisement); |
| | | nativeAd(); |
| | | loadAd(); |
| | | dialog.addContentView(layout, new FrameLayout.LayoutParams( |
| | | FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)); |
| | | // set the confirm button |
| | |
| | | private NativeExpressAD nativeExpressAD; |
| | | |
| | | // 1.加载广告,先设置加载上下文环境和条件 |
| | | private void nativeAd() { |
| | | fl_advertisement.removeAllViews(); |
| | | nativeExpressAD = new NativeExpressAD(context, new ADSize(ADSize.FULL_WIDTH, ADSize.AUTO_HEIGHT), |
| | | BeibeiConstant.GDT_EXIT_DIALOG, new NativeExpressAD.NativeExpressADListener() { |
| | | private void loadAd() { |
| | | |
| | | expressAdManager.loadAppExitAd(new ExpressAdManager.IAdLoadListener() { |
| | | @Override |
| | | public void onADLoaded(final List<NativeExpressADView> list) { |
| | | fl_advertisement.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (null != list && list.size() > 0) { |
| | | NativeExpressADView adView = list.get(0); |
| | | adView.render(); |
| | | FrameLayout parent = (FrameLayout) adView.getParent(); |
| | | if (parent != null) { |
| | | parent.removeAllViews(); |
| | | } |
| | | fl_advertisement.addView(adView); |
| | | public void onSuccess(List<ExpressAdContainer> adList) { |
| | | if (adList != null && adList.size() > 0) { |
| | | |
| | | ExpressAdManager.renderAd(context, adList.get(0), new ExpressAdManager.IAdRenderListener() { |
| | | @Override |
| | | public void onRenderSuccess(List<ExpressAdContainer> adList) { |
| | | expressAdContainer = adList.get(0); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | @Override |
| | | public void onRenderFail(List<ExpressAdContainer> adList) { |
| | | |
| | | } |
| | | }, null); |
| | | |
| | | } |
| | | |
| | | } |
| | | }); |
| | | |
| | | @Override |
| | | public void onRenderFail(NativeExpressADView nativeExpressADView) { |
| | | } |
| | | |
| | | } |
| | | public void showAd() { |
| | | if (expressAdContainer != null) { |
| | | ExpressAdManager.bindCloseListener(context,expressAdContainer,new IAdEventListener(){ |
| | | |
| | | @Override |
| | | public void onRenderSuccess(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADExposure(NativeExpressADView nativeExpressADView) { |
| | | } |
| | | |
| | | @Override |
| | | public void onADClicked(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADClosed(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADLeftApplication(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADOpenOverlay(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onADCloseOverlay(NativeExpressADView nativeExpressADView) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onNoAD(AdError adError) { |
| | | } |
| | | }); // 传入Activity |
| | | // 注意:如果您在联盟平台上新建原生模板广告位时,选择了支持视频,那么可以进行个性化设置(可选) |
| | | nativeExpressAD.setVideoOption(new VideoOption.Builder() |
| | | .setAutoPlayPolicy(VideoOption.AutoPlayPolicy.WIFI) // WIFI 环境下可以自动播放视频 |
| | | .setAutoPlayMuted(true) // 自动播放时为静音 |
| | | .build()); // |
| | | nativeExpressAD.loadAD(2); |
| | | @Override |
| | | public void closeAd(ExpressAdContainer ad) { |
| | | fl_advertisement.removeAllViews(); |
| | | } |
| | | }); |
| | | ExpressAdManager.fillAd(expressAdContainer, fl_advertisement); |
| | | } |
| | | } |
| | | |
| | | public void refreshAd() { |
| | | nativeAd(); |
| | | loadAd(); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.weikou.beibeivideo.util.ad; |
| | | |
| | | import android.content.Context; |
| | | import android.content.SharedPreferences; |
| | | |
| | | import com.weikou.beibeivideo.entity.ad.AdTypeVO; |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.beibeivideo.util.downutil.StringUtils; |
| | | |
| | | //穿山甲广告 |
| | | import org.json.JSONException; |
| | | import org.json.JSONObject; |
| | | |
| | | //广告帮助 |
| | | public class AdUtil { |
| | | |
| | | public enum AD_TYPE { |
| | | gdt("广点通"), csj("穿山甲"), gdt2("广点通2.0"); |
| | | |
| | | public static int getSmallExpressAdType() { |
| | | private String name; |
| | | |
| | | private AD_TYPE(String name) { |
| | | this.name = name; |
| | | } |
| | | |
| | | } |
| | | |
| | | public final static String POSITION_SPLASH = "splash";//开屏 |
| | | public final static String POSITION_VIDEO_PLAY_PRE = "videoPlayPre";//视频播放前贴 |
| | | public final static String POSITION_EXIT_APP = "exitApp";//APP退出广告 |
| | | |
| | | public static AD_TYPE getSmallExpressAdType() { |
| | | if (BeibeiConstant.AD_TYPE != null && AdTypeVO.TYPE_CSJ.equalsIgnoreCase(BeibeiConstant.AD_TYPE.getExpressSmallType())) { |
| | | return ExpressAdManager.SOURCE_CSJ; |
| | | return AD_TYPE.csj; |
| | | } else { |
| | | return ExpressAdManager.SOURCE_GDT; |
| | | return AD_TYPE.gdt; |
| | | } |
| | | } |
| | | |
| | | public static int getBigExpressAdType() { |
| | | public static AD_TYPE getBigExpressAdType() { |
| | | if (BeibeiConstant.AD_TYPE != null && AdTypeVO.TYPE_CSJ.equalsIgnoreCase(BeibeiConstant.AD_TYPE.getExpressBigType())) { |
| | | return ExpressAdManager.SOURCE_CSJ; |
| | | return AD_TYPE.csj; |
| | | } else { |
| | | return ExpressAdManager.SOURCE_GDT2; |
| | | return AD_TYPE.gdt2; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 保存广告配置 |
| | | * |
| | | * @param context |
| | | * @param json |
| | | */ |
| | | public static void saveAdConfig(Context context, JSONObject json) { |
| | | SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = share.edit(); |
| | | editor.putString("config", json.toString()); |
| | | editor.commit(); |
| | | } |
| | | |
| | | /** |
| | | * 获取广告类型 |
| | | * |
| | | * @param context |
| | | * @param positionName |
| | | * @return |
| | | */ |
| | | public static AD_TYPE getAdType(Context context, String positionName) { |
| | | SharedPreferences share = context.getSharedPreferences("adConfig", Context.MODE_PRIVATE); |
| | | String config = share.getString("config", ""); |
| | | if (!StringUtils.isNullOrEmpty(config)) {//万一没设置起就用广点通 |
| | | try { |
| | | JSONObject object = new JSONObject(config); |
| | | return AD_TYPE.valueOf(object.optString(positionName)); |
| | | } catch (JSONException e) { |
| | | e.printStackTrace(); |
| | | } catch (Exception e1) { |
| | | return null; |
| | | } |
| | | } else { |
| | | return AD_TYPE.gdt; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | package com.weikou.beibeivideo.util.ad; |
| | | |
| | | public class CSJConstant { |
| | | |
| | | //首页大广告 |
| | | public static String RECOMMEND_BIG_IMG_AD = "945375047"; |
| | | |
| | | //VIVO开屏 |
| | | public static String SPLASH_AD_VIVO = "887378583"; |
| | | |
| | | //开屏广告 |
| | | public static String SPLASH_AD = "887360667"; |
| | | |
| | | //软件退出广告 |
| | | public static String APP_EXIT="945469133"; |
| | | |
| | | public static String INVALID_AD = "111111111"; |
| | | |
| | | } |
| | |
| | | * 信息流广告管理 |
| | | */ |
| | | public class ExpressAdManager { |
| | | public final static int SOURCE_GDT = 1;//广点通 |
| | | public final static int SOURCE_GDT2 = 11;//广点通2.0 |
| | | public final static int SOURCE_CSJ = 2;//穿山甲 |
| | | |
| | | |
| | | final static String TAG = "ExpressAdManager"; |
| | | |
| | | int sourceType = SOURCE_GDT; |
| | | AdUtil.AD_TYPE sourceType = AdUtil.AD_TYPE.gdt; |
| | | |
| | | private TTAdNative mTTAdNative; |
| | | private Context mContext; |
| | | |
| | | |
| | | public ExpressAdManager(int adSource, Context context) { |
| | | public ExpressAdManager(AdUtil.AD_TYPE adSource, Context context) { |
| | | sourceType = adSource; |
| | | this.mContext = context; |
| | | if (sourceType == SOURCE_CSJ) { |
| | | if (sourceType == AdUtil.AD_TYPE.csj) { |
| | | TTAdManager ttAdManager = TTAdManagerHolder.get(); |
| | | mTTAdNative = ttAdManager.createAdNative(context); |
| | | // TTAdManagerHolder.get().requestPermissionIfNecessary(context); |
| | |
| | | * @param adLoadListener |
| | | */ |
| | | public void loadAd(int widthDP, int heightDP, String pid, int count, final IAdLoadListener adLoadListener) { |
| | | if (sourceType == SOURCE_GDT) { |
| | | if (sourceType == AdUtil.AD_TYPE.gdt) { |
| | | loadGDT(pid, widthDP, heightDP, count, new IGDTAdLoadListener() { |
| | | @Override |
| | | public void onSuccess(List<NativeExpressADView> adList) { |
| | |
| | | |
| | | } |
| | | }, mContext); |
| | | } else if (sourceType == SOURCE_GDT2) { |
| | | } else if (sourceType == AdUtil.AD_TYPE.gdt2) { |
| | | loadGDT2(pid, widthDP, heightDP, count, new IGDTAdLoadListener() { |
| | | @Override |
| | | public void onSuccess(List<NativeExpressADView> adList) { |
| | |
| | | } |
| | | }, mContext); |
| | | |
| | | } else if (sourceType == SOURCE_CSJ) { |
| | | } else if (sourceType == AdUtil.AD_TYPE.csj) { |
| | | loadCSJ(pid, widthDP, heightDP, count, new ICSJAdLoadListener() { |
| | | @Override |
| | | public void onSuccess(List<TTNativeExpressAd> adList) { |
| | |
| | | int width = deviceWidth - 6; |
| | | int height = (int) (width * 0.8); |
| | | String pid = null; |
| | | if (sourceType == SOURCE_CSJ) { |
| | | if (sourceType == AdUtil.AD_TYPE.csj) { |
| | | pid = CSJConstant.RECOMMEND_BIG_IMG_AD; |
| | | height = (int) (width * 0.56); |
| | | } else if (sourceType == SOURCE_GDT) { |
| | | } else if (sourceType == AdUtil.AD_TYPE.gdt) { |
| | | pid = BeibeiConstant.GDT_RECOMMAND_NATIVE; |
| | | } else if (sourceType == SOURCE_GDT2) { |
| | | } else if (sourceType == AdUtil.AD_TYPE.gdt2) { |
| | | pid = GDTConstant.PID_HOME_RECOMMEND_BIG_IMG; |
| | | } |
| | | //获取屏幕的宽 |
| | |
| | | public void loadRecommendSmallAd(final IAdLoadListener adLoadListener) { |
| | | //加载大图 |
| | | String pid = null; |
| | | if (sourceType == SOURCE_CSJ) { |
| | | if (sourceType == AdUtil.AD_TYPE.csj) { |
| | | pid = "945375047"; |
| | | } else if (sourceType == SOURCE_GDT) { |
| | | } else if (sourceType == AdUtil.AD_TYPE.gdt) { |
| | | pid = BeibeiConstant.GDT_RECOMMAND_MIN_NATIVE; |
| | | } |
| | | //获取屏幕的宽 |
| | |
| | | public void loadVideoDetailPlayerBottomAd(final IAdLoadListener adLoadListener) { |
| | | //加载大图 |
| | | String pid = null; |
| | | if (sourceType == SOURCE_CSJ) { |
| | | if (sourceType == AdUtil.AD_TYPE.csj) { |
| | | pid = "945375047"; |
| | | } else if (sourceType == SOURCE_GDT2) { |
| | | } else if (sourceType == AdUtil.AD_TYPE.gdt2) { |
| | | pid = GDTConstant.PID_2_VIDEO_DETAIL_PLAY_EXPRESS1; |
| | | } |
| | | //获取屏幕的宽 |
| | |
| | | public void loadVideoDetailRelativeVideoBottomAd(final IAdLoadListener adLoadListener) { |
| | | //加载大图 |
| | | String pid = null; |
| | | if (sourceType == SOURCE_CSJ) { |
| | | if (sourceType == AdUtil.AD_TYPE.csj) { |
| | | pid = "945375047"; |
| | | } else if (sourceType == SOURCE_GDT2) { |
| | | } else if (sourceType == AdUtil.AD_TYPE.gdt2) { |
| | | pid = GDTConstant.PID_2_VIDEO_DETAIL_PLAY_EXPRESS2; |
| | | } |
| | | if (mContext == null) |
| | |
| | | public void loadRecommendCategorySmallAd(final IAdLoadListener adLoadListener) { |
| | | //加载大图 |
| | | String pid = null; |
| | | if (sourceType == SOURCE_CSJ) { |
| | | if (sourceType == AdUtil.AD_TYPE.csj) { |
| | | pid = "945375047"; |
| | | } else if (sourceType == SOURCE_GDT) { |
| | | } else if (sourceType == AdUtil.AD_TYPE.gdt) { |
| | | pid = BeibeiConstant.GDT_RECOMMEND_CATEGORY_MIN_NATIVE; |
| | | } |
| | | //获取屏幕的宽 |
| | |
| | | public void loadSearchResultSmallAd(int count, final IAdLoadListener adLoadListener) { |
| | | //加载大图 |
| | | String pid = null; |
| | | if (sourceType == SOURCE_CSJ) { |
| | | if (sourceType == AdUtil.AD_TYPE.csj) { |
| | | pid = "945379581"; |
| | | } else if (sourceType == SOURCE_GDT) { |
| | | } else if (sourceType == AdUtil.AD_TYPE.gdt) { |
| | | pid = BeibeiConstant.GDT_SEARCH_RESULT_MIN_NATIVE; |
| | | } |
| | | //获取屏幕的宽 |
| | |
| | | |
| | | //加载大图 |
| | | String pid = null; |
| | | if (sourceType == SOURCE_CSJ) { |
| | | if (sourceType == AdUtil.AD_TYPE.csj) { |
| | | pid = "945406595"; |
| | | } else if (sourceType == SOURCE_GDT2) { |
| | | } else if (sourceType == AdUtil.AD_TYPE.gdt2) { |
| | | if (columns == 3) |
| | | pid = GDTConstant.PID_2_VIDEO_LIST_SMALL_AD_COLUMN3; |
| | | else if (columns == 2) |
| | |
| | | |
| | | |
| | | /** |
| | | * 加载APP退出广告 |
| | | * |
| | | * @param adLoadListener |
| | | */ |
| | | public void loadAppExitAd(final IAdLoadListener adLoadListener) { |
| | | //加载大图 |
| | | String pid = null; |
| | | if (sourceType == AdUtil.AD_TYPE.csj) { |
| | | pid = CSJConstant.APP_EXIT; |
| | | } else if (sourceType == AdUtil.AD_TYPE.gdt) { |
| | | pid = BeibeiConstant.GDT_EXIT_DIALOG; |
| | | } |
| | | //获取屏幕的宽 |
| | | int deviceWidth = DimenUtils.getScreenWidth(mContext); |
| | | deviceWidth = DimenUtils.px2dip(mContext, deviceWidth); |
| | | int width = deviceWidth * 3 / 4; |
| | | int height = (int) (width / 1.78f); |
| | | |
| | | loadAd(width, height, pid, 1, adLoadListener); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 加载广点通广告 |
| | | * |
| | | * @param positionId |
| | |
| | | import com.bytedance.sdk.openadsdk.TTAdManager; |
| | | import com.bytedance.sdk.openadsdk.TTAdNative; |
| | | import com.bytedance.sdk.openadsdk.TTSplashAd; |
| | | import com.lcjian.library.util.ManifestDataUtil; |
| | | import com.qq.e.ads.splash.SplashAD; |
| | | import com.qq.e.ads.splash.SplashADListener; |
| | | import com.qq.e.comm.util.AdError; |
| | |
| | | * @param tv_time |
| | | * @param splashAdListener |
| | | */ |
| | | public static void loadAD(String adType, Activity context, final View skip, ViewGroup vg_ad, final TextView tv_time, final SplashAdListener splashAdListener) { |
| | | if (StringUtils.isNullOrEmpty(adType)) { |
| | | public static void loadAD(AdUtil.AD_TYPE adType, Activity context, final View skip, ViewGroup vg_ad, final TextView tv_time, final SplashAdListener splashAdListener) { |
| | | if (adType==null) { |
| | | splashAdListener.close(); |
| | | return; |
| | | } |
| | | if (AdTypeVO.TYPE_CSJ.equalsIgnoreCase(adType)) { |
| | | if (AdUtil.AD_TYPE.csj==adType) { |
| | | loadCSJ(context, skip, vg_ad, splashAdListener); |
| | | } else if (AdTypeVO.TYPE_GDT.equalsIgnoreCase(adType)) { |
| | | } else if (AdUtil.AD_TYPE.gdt==adType) { |
| | | loadGDT(context, skip, vg_ad, tv_time, splashAdListener); |
| | | } else { |
| | | splashAdListener.close(); |
| | |
| | | } |
| | | |
| | | private static void loadGDT(Activity context, final View skip, ViewGroup vg_ad, final TextView tv_time, final SplashAdListener splashAdListener) { |
| | | new SplashAD(context, skip, BeibeiConstant.GDT_SPLASH_POSITION_ID, new SplashADListener() { |
| | | |
| | | String channel = ManifestDataUtil.getAppMetaData(context, "UMENG_CHANNEL"); |
| | | String code = BeibeiConstant.GDT_SPLASH_POSITION_ID; |
| | | if ("vivo".equalsIgnoreCase(channel)) { |
| | | code = BeibeiConstant.GDT_SPLASH_VIVO_POSITION_ID; |
| | | } |
| | | new SplashAD(context, skip, code, new SplashADListener() { |
| | | @Override |
| | | public void onADDismissed() { |
| | | splashAdListener.close(); |
| | |
| | | width = 720; |
| | | if (height == 0) |
| | | height = 1080; |
| | | String channel = ManifestDataUtil.getAppMetaData(context, "UMENG_CHANNEL"); |
| | | String code = CSJConstant.SPLASH_AD; |
| | | if ("vivo".equalsIgnoreCase(channel)) { |
| | | code = CSJConstant.SPLASH_AD_VIVO; |
| | | } |
| | | |
| | | AdSlot adSlot = new AdSlot.Builder() |
| | | .setCodeId("887360667") |
| | | .setCodeId(code) |
| | | .setSupportDeepLink(true) |
| | | .setImageAcceptedSize(width, height) |
| | | .build(); |
| | |
| | | import android.content.Context; |
| | | |
| | | import com.weikou.beibeivideo.entity.ad.ExpressAdContainer; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.ad.ExpressAdManager; |
| | | |
| | | import java.util.List; |
| | |
| | | public SearchResultAdManager(Context context) { |
| | | mContext = context; |
| | | if (expressAdManager == null) |
| | | expressAdManager = new ExpressAdManager(ExpressAdManager.SOURCE_GDT, mContext); |
| | | expressAdManager = new ExpressAdManager(AdUtil.AD_TYPE.gdt, mContext); |
| | | } |
| | | |
| | | public static SearchResultAdManager getInstance(Context context) { |
| | |
| | | } |
| | | maven { url 'https://jitpack.io' } |
| | | maven { url 'https://dl.bintray.com/umsdk/release' } |
| | | maven { url "https://dl.bintray.com/thelasterstar/maven/" } |
| | | } |
| | | } |
New file |
| | |
| | | /* |
| | | * Copyright (C) 2011 The Android Open Source Project |
| | | * Copyright (C) 2011 Jake Wharton |
| | | * |
| | | * Licensed under the Apache License, Version 2.0 (the "License"); |
| | | * you may not use this file except in compliance with the License. |
| | | * You may obtain a copy of the License at |
| | | * |
| | | * http://www.apache.org/licenses/LICENSE-2.0 |
| | | * |
| | | * Unless required by applicable law or agreed to in writing, software |
| | | * distributed under the License is distributed on an "AS IS" BASIS, |
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| | | * See the License for the specific language governing permissions and |
| | | * limitations under the License. |
| | | */ |
| | | package com.viewpagerindicator; |
| | | |
| | | import android.annotation.SuppressLint; |
| | | import android.content.Context; |
| | | import android.graphics.Color; |
| | | import android.support.v4.view.PagerAdapter; |
| | | import android.support.v4.view.ViewPager; |
| | | import android.support.v4.view.ViewPager.OnPageChangeListener; |
| | | import android.util.AttributeSet; |
| | | import android.util.TypedValue; |
| | | import android.view.View; |
| | | import android.view.ViewGroup; |
| | | import android.widget.HorizontalScrollView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.TextView; |
| | | |
| | | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
| | | import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT; |
| | | |
| | | /** |
| | | * This widget implements the dynamic action bar tab behavior that can change |
| | | * across different configurations or circumstances. |
| | | */ |
| | | public class SearchTabPageIndicator extends HorizontalScrollView implements |
| | | PageIndicator { |
| | | /** |
| | | * Title text used when no title is provided by the adapter. |
| | | */ |
| | | private static final CharSequence EMPTY_TITLE = ""; |
| | | |
| | | /** |
| | | * Interface for a callback when the selected tab has been reselected. |
| | | */ |
| | | public interface OnTabReselectedListener { |
| | | /** |
| | | * Callback when the selected tab has been reselected. |
| | | * |
| | | * @param position Position of the current center item. |
| | | */ |
| | | void onTabReselected(int position); |
| | | } |
| | | |
| | | private Runnable mTabSelector; |
| | | /** |
| | | * ViewPager中tab的点击事件 |
| | | */ |
| | | private final OnClickListener mTabClickListener = new OnClickListener() { |
| | | public void onClick(View view) { |
| | | TabView tabView = (TabView) view; |
| | | final int oldSelected = mViewPager.getCurrentItem(); |
| | | final int newSelected = tabView.getIndex(); |
| | | mViewPager.setCurrentItem(newSelected); |
| | | if (oldSelected == newSelected && mTabReselectedListener != null) { |
| | | mTabReselectedListener.onTabReselected(newSelected); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | private final IcsLinearLayout mTabLayout; |
| | | |
| | | private ViewPager mViewPager; |
| | | private OnPageChangeListener mListener; |
| | | |
| | | private int mMaxTabWidth; |
| | | private int mSelectedTabIndex; |
| | | |
| | | private OnTabReselectedListener mTabReselectedListener; |
| | | |
| | | public SearchTabPageIndicator(Context context) { |
| | | this(context, null); |
| | | } |
| | | |
| | | public SearchTabPageIndicator(Context context, AttributeSet attrs) { |
| | | super(context, attrs); |
| | | setHorizontalScrollBarEnabled(false); |
| | | |
| | | mTabLayout = new IcsLinearLayout(context, |
| | | R.attr.vpiTabPageIndicatorStyle); |
| | | addView(mTabLayout, new ViewGroup.LayoutParams(WRAP_CONTENT, |
| | | MATCH_PARENT)); |
| | | } |
| | | |
| | | public void setOnTabReselectedListener(OnTabReselectedListener listener) { |
| | | mTabReselectedListener = listener; |
| | | } |
| | | |
| | | @Override |
| | | public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| | | final int widthMode = MeasureSpec.getMode(widthMeasureSpec); |
| | | final boolean lockedExpanded = widthMode == MeasureSpec.EXACTLY; |
| | | setFillViewport(lockedExpanded); |
| | | |
| | | final int childCount = mTabLayout.getChildCount(); |
| | | if (childCount > 1 |
| | | && (widthMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.AT_MOST)) { |
| | | if (childCount > 2) { |
| | | mMaxTabWidth = (int) (MeasureSpec.getSize(widthMeasureSpec) * 0.4f); |
| | | } else { |
| | | mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2; |
| | | } |
| | | } else { |
| | | mMaxTabWidth = -1; |
| | | } |
| | | |
| | | final int oldWidth = getMeasuredWidth(); |
| | | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| | | final int newWidth = getMeasuredWidth(); |
| | | |
| | | if (lockedExpanded && oldWidth != newWidth) { |
| | | // Recenter the tab display if we're at a new (scrollable) size. |
| | | setCurrentItem(mSelectedTabIndex); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 单个Tab |
| | | * |
| | | * @param position |
| | | */ |
| | | @SuppressLint("ResourceAsColor") |
| | | private void animateToTab(final int position) { |
| | | final View tabView = mTabLayout.getChildAt(position); |
| | | if (mTabSelector != null) { |
| | | removeCallbacks(mTabSelector); |
| | | } |
| | | for (int i = 0; i < mTabLayout.getChildCount(); i++) { |
| | | ((TextView) mTabLayout.getChildAt(i)).setTextSize( |
| | | TypedValue.COMPLEX_UNIT_SP, 15); |
| | | ((TextView) mTabLayout.getChildAt(i)).setTextColor(Color.parseColor("#999999")); |
| | | } |
| | | ((TextView) tabView).setTextColor(Color.WHITE); |
| | | ((TextView) tabView).setTextSize( |
| | | TypedValue.COMPLEX_UNIT_SP, 18); |
| | | // ((TextView) tabView).setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT,WRAP_CONTENT)); |
| | | mTabSelector = new Runnable() { |
| | | public void run() { |
| | | final int scrollPos = tabView.getLeft() |
| | | - (getWidth() - tabView.getWidth()) / 2; |
| | | smoothScrollTo(scrollPos, 0); |
| | | |
| | | mTabSelector = null; |
| | | } |
| | | }; |
| | | post(mTabSelector); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onAttachedToWindow() { |
| | | super.onAttachedToWindow(); |
| | | if (mTabSelector != null) { |
| | | // Re-post the selector we saved |
| | | post(mTabSelector); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onDetachedFromWindow() { |
| | | super.onDetachedFromWindow(); |
| | | if (mTabSelector != null) { |
| | | removeCallbacks(mTabSelector); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加tabView |
| | | * |
| | | * @param index |
| | | * @param text |
| | | * @param iconResId |
| | | */ |
| | | @SuppressLint("ResourceAsColor") |
| | | private void addTab(int index, CharSequence text, int iconResId) { |
| | | final TabView tabView = new TabView(getContext()); |
| | | tabView.mIndex = index; |
| | | tabView.setFocusable(true); |
| | | tabView.setOnClickListener(mTabClickListener); |
| | | tabView.setText(text); |
| | | tabView.setTextColor(R.color.black1); |
| | | |
| | | if (iconResId != 0) { |
| | | tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0); |
| | | } |
| | | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(WRAP_CONTENT, |
| | | MATCH_PARENT, 1); |
| | | |
| | | mTabLayout.addView(tabView, params); |
| | | } |
| | | |
| | | @Override |
| | | public void onPageScrollStateChanged(int arg0) { |
| | | if (mListener != null) { |
| | | mListener.onPageScrollStateChanged(arg0); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onPageScrolled(int arg0, float arg1, int arg2) { |
| | | if (mListener != null) { |
| | | mListener.onPageScrolled(arg0, arg1, arg2); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onPageSelected(int arg0) { |
| | | setCurrentItem(arg0); |
| | | if (mListener != null) { |
| | | mListener.onPageSelected(arg0); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void setViewPager(ViewPager view) { |
| | | if (mViewPager != null) { |
| | | mViewPager.setOnPageChangeListener(null); |
| | | } |
| | | final PagerAdapter adapter = view.getAdapter(); |
| | | if (adapter == null) { |
| | | throw new IllegalStateException( |
| | | "ViewPager does not have adapter instance."); |
| | | } |
| | | mViewPager = view; |
| | | view.setOnPageChangeListener(this); |
| | | notifyDataSetChanged(); |
| | | } |
| | | |
| | | public void notifyDataSetChanged() { |
| | | mTabLayout.removeAllViews(); |
| | | PagerAdapter adapter = mViewPager.getAdapter(); |
| | | IconPagerAdapter iconAdapter = null; |
| | | if (adapter instanceof IconPagerAdapter) { |
| | | iconAdapter = (IconPagerAdapter) adapter; |
| | | } |
| | | final int count = adapter.getCount(); |
| | | for (int i = 0; i < count; i++) { |
| | | CharSequence title = adapter.getPageTitle(i); |
| | | if (title == null) { |
| | | title = EMPTY_TITLE; |
| | | } |
| | | int iconResId = 0; |
| | | if (iconAdapter != null) { |
| | | iconResId = iconAdapter.getIconResId(i); |
| | | } |
| | | addTab(i, title, iconResId); |
| | | } |
| | | if (mSelectedTabIndex > count) { |
| | | mSelectedTabIndex = count - 1; |
| | | } |
| | | setCurrentItem(mSelectedTabIndex); |
| | | requestLayout(); |
| | | } |
| | | |
| | | @Override |
| | | public void setViewPager(ViewPager view, int initialPosition) { |
| | | setViewPager(view); |
| | | setCurrentItem(initialPosition); |
| | | } |
| | | |
| | | /** |
| | | * 设置当前Item |
| | | */ |
| | | @Override |
| | | public void setCurrentItem(int item) { |
| | | if (mViewPager == null) { |
| | | throw new IllegalStateException("ViewPager has not been bound."); |
| | | } |
| | | mSelectedTabIndex = item; |
| | | mViewPager.setCurrentItem(item); |
| | | |
| | | final int tabCount = mTabLayout.getChildCount(); |
| | | for (int i = 0; i < tabCount; i++) { |
| | | final View child = mTabLayout.getChildAt(i); |
| | | final boolean isSelected = (i == item); |
| | | child.setSelected(isSelected); |
| | | if (isSelected) { |
| | | animateToTab(item); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void setOnPageChangeListener(OnPageChangeListener listener) { |
| | | mListener = listener; |
| | | } |
| | | |
| | | /** |
| | | * 重写textview |
| | | * |
| | | * @author weikou2015 |
| | | */ |
| | | private class TabView extends TextView { |
| | | private int mIndex; |
| | | |
| | | public TabView(Context context) { |
| | | super(context, null, R.attr.vpiTabPageIndicatorStyle); |
| | | } |
| | | |
| | | @Override |
| | | public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| | | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| | | |
| | | // Re-measure if we went beyond our maximum size. |
| | | if (mMaxTabWidth > 0 && getMeasuredWidth() > mMaxTabWidth) { |
| | | super.onMeasure(MeasureSpec.makeMeasureSpec(mMaxTabWidth, |
| | | MeasureSpec.EXACTLY), heightMeasureSpec); |
| | | } |
| | | } |
| | | |
| | | public int getIndex() { |
| | | return mIndex; |
| | | } |
| | | } |
| | | } |
| | |
| | | dependencies { |
| | | api fileTree(include: '*', dir: 'libs') |
| | | |
| | | api 'com.sina.weibo.sdk:core:4.4.3:openDefaultRelease@aar' |
| | | |
| | | api files('libs/umeng-asms-armeabi-v1.1.3.aar') |
| | | api files('libs/umeng-common-9.2.4.jar') |
| | | api files('libs/umeng-crash-armeabi-v0.0.4.aar') |