| | |
| | | import android.content.pm.ActivityInfo; |
| | | import android.content.pm.ApplicationInfo; |
| | | import android.database.Cursor; |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.drawable.Drawable; |
| | | import android.net.wifi.WifiInfo; |
| | | import android.net.wifi.WifiManager; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.support.annotation.NonNull; |
| | | import android.support.annotation.Nullable; |
| | | import android.support.v4.app.LoaderManager; |
| | | import android.support.v4.content.CursorLoader; |
| | | import android.support.v4.content.Loader; |
| | |
| | | import android.view.View; |
| | | import android.view.Window; |
| | | import android.view.WindowManager; |
| | | import android.widget.FrameLayout; |
| | | import android.widget.ImageView; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.RadioButton; |
| | |
| | | import android.widget.Toast; |
| | | |
| | | import com.bumptech.glide.Glide; |
| | | import com.bumptech.glide.request.animation.GlideAnimation; |
| | | import com.bumptech.glide.request.target.SimpleTarget; |
| | | import com.bumptech.glide.request.transition.Transition; |
| | | import com.google.gson.FieldNamingPolicy; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | |
| | | import com.lcjian.library.util.MarketUtils; |
| | | import com.lcjian.library.util.common.StringUtils; |
| | | import com.mozillaonline.providers.downloads.DownloadService; |
| | | import com.qq.e.ads.cfg.VideoOption; |
| | | import com.tencent.android.tpush.XGPushTextMessage; |
| | | import com.umeng.analytics.MobclickAgent; |
| | | import com.umeng.socialize.ShareAction; |
| | |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.beibeivideo.util.ExitDialog; |
| | | import com.weikou.beibeivideo.util.LoginFirstDialog; |
| | | import com.yeshi.buwanshequ.R; |
| | | import com.weikou.beibeivideo.util.ad.FullVideoAdManager; |
| | | import com.weikou.beibeivideo.util.ad.manager.SearchResultAdManager; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.yeshi.ec.library_baiducpu.fragment.BaiDuNewsFragment; |
| | | import com.yeshi.ec.library_baiducpu.fragment.BaiDuVideosFragment; |
| | | import com.ysh.wpc.appupdate.AppUpdate; |
| | | |
| | | import org.apache.http.Header; |
| | |
| | | public class MainActivity extends BaseActivity implements |
| | | LoaderManager.LoaderCallbacks<Cursor>, View.OnClickListener { |
| | | |
| | | // private RadioGroup rg_nav; |
| | | |
| | | // private FragmentSwitchHelper mFragmentSwitchHelper; |
| | | |
| | | private ImageView iv_taobao; |
| | | |
| | | private ImageView iv_red_dot; |
| | | |
| | | // private PushAgent mPushAgent; |
| | | |
| | | private ProgressDialog pd = null; |
| | | |
| | | private FrameLayout fl_right_ad; |
| | | |
| | | SharedPreferences preferences;// 广告商城,获取图标状态信息 |
| | | |
| | | private boolean isHaveNewCom;// 是否存在新的评论消息 |
| | | |
| | | // private TextView tv_userName;// 用户名 |
| | | TextView tv_search; |
| | | |
| | | // private ImageView iv_user_logo;// 用户头像 |
| | | |
| | | // private RelativeLayout rl_mine_message;// 我的消息 |
| | | |
| | | // private BadgeView mBadgeView; |
| | | |
| | | // private DrawerLayout dl_sliding;//侧滑 |
| | | |
| | | // private TextView tv_login_name; |
| | | |
| | | // private ImageView iv_portrait; |
| | | ImageView iv_msg_dot; |
| | | |
| | | private RadioGroup rg_nav; |
| | |
| | | super.onCreate(savedInstanceState); |
| | | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// 锁定竖屏 |
| | | setContentView(R.layout.activity_main); |
| | | /* |
| | | |
| | | exitDialogBuilder = new ExitDialog.Builder(this); |
| | | |
| | | exitDialog = exitDialogBuilder.create(); |
| | | exitDialog.setCanceledOnTouchOutside(true); |
| | | /* |
| | | * 计算状态栏高度并设置 |
| | | */ |
| | | */ |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
| | | Window window = getWindow(); |
| | | window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, |
| | |
| | | } else { |
| | | findViewById(R.id.v_status_bar).setVisibility(View.GONE); |
| | | } |
| | | // MarketUtils.queryInstalledMarketPkgs(this); |
| | | // MarketUtils.queryInstalledMarketInfos(this); |
| | | // MarketUtils.filterInstalledPkgs(this, getPackageName()); |
| | | |
| | | // String str = "market://details?id=" + getPackageName(); |
| | | // Intent localIntent = new Intent("android.intent.action.VIEW"); |
| | | // localIntent.setData(Uri.parse(str)); |
| | | // startActivity(localIntent); |
| | | // 将imei mac lat lng存入sharedpreference中 |
| | | SharedPreferences mPre = getSharedPreferences("user", |
| | | Context.MODE_PRIVATE); |
| | | WifiManager wifi = (WifiManager) this.getApplicationContext().getSystemService(Context.WIFI_SERVICE); |
| | | WifiInfo info = wifi.getConnectionInfo(); |
| | | |
| | | // String imei = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)) |
| | | // .getDeviceId(); |
| | | Editor editor = mPre.edit(); |
| | | // editor.putString("imei", imei); |
| | | if (StringUtils.isEmpty(getMacAddress())) { |
| | | editor.putString("mac", info.getMacAddress()); |
| | | } else { |
| | |
| | | } |
| | | editor.commit(); |
| | | |
| | | // tv_userName = (TextView) findViewById(R.id.mine_tv_name); |
| | | tv_search = findViewById(R.id.tv_activity_main_search); |
| | | // iv_user_logo = (ImageView) findViewById(R.id.mine_ci_head); |
| | | // rl_mine_message = (RelativeLayout) findViewById(R.id.rl_mine_message); |
| | | // tv_login_name = (TextView) findViewById(R.id.tv_activity_main_login); |
| | | // iv_portrait = (ImageView) findViewById(R.id.iv_activity_protrait); |
| | | |
| | | iv_msg_dot = findViewById(R.id.iv_msg_dot); |
| | | |
| | | // mBadgeView = new BadgeView(this, rl_mine_message); |
| | | // mBadgeView.setBackgroundResource(R.drawable.ic_red_dot); |
| | | // mBadgeView.setTextSize(1); |
| | | // mBadgeView.setText(""); |
| | | // mBadgeView.setBadgeMargin(DimenUtils.dipToPixels(20, this)); |
| | | // findViewById(R.id.mine_rl_head).setOnClickListener(this); |
| | | // findViewById(R.id.rl_mine_favourite).setOnClickListener(this); |
| | | // findViewById(R.id.rl_mine_download).setOnClickListener(this); |
| | | // findViewById(R.id.rl_mine_follow).setOnClickListener(this); |
| | | // findViewById(R.id.rl_mine_watch_history).setOnClickListener(this); |
| | | // rl_mine_message.setOnClickListener(this); |
| | | // findViewById(R.id.rl_share).setOnClickListener(this); |
| | | // findViewById(R.id.rl_suggestion).setOnClickListener(this); |
| | | // findViewById(R.id.rl_settings).setOnClickListener(this); |
| | | // findViewById(R.id.rl_release).setOnClickListener(this); |
| | | |
| | | pd = new ProgressDialog(this); |
| | | pd.setMessage("正在请求网络..."); |
| | |
| | | iv_taobao = findViewById(R.id.nat); |
| | | iv_taobao.setOnClickListener(this); |
| | | iv_red_dot = findViewById(R.id.iv_red_dot); |
| | | // list.add("推荐"); |
| | | // list.add("直播"); |
| | | // list.add("分区"); |
| | | // list.add("发现"); |
| | | // list.add("关注"); |
| | | fl_right_ad = findViewById(R.id.fl_right_ad); |
| | | |
| | | // ViewPager pager = findViewById(R.id.pager); |
| | | // GoogleMusicAdapter adapter = new GoogleMusicAdapter( |
| | | // getSupportFragmentManager()); |
| | | // pager.setAdapter(adapter); |
| | | |
| | | // TabPageIndicator indicator = new TabPageIndicator( |
| | | // this); |
| | | // indicator.setViewPager(pager, 0); |
| | | // ((FrameLayout) findViewById(R.id.fl_indicator)) |
| | | // .addView(indicator); |
| | | /* |
| | | * 计算状态栏高度并设置 |
| | | */ |
| | | */ |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { |
| | | Window window = getWindow(); |
| | | window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, |
| | |
| | | } else { |
| | | findViewById(R.id.v_status_bar).setVisibility(View.GONE); |
| | | } |
| | | // dl_sliding = (DrawerLayout) findViewById(R.id.dl_sliding); |
| | | |
| | | initialer.run(); |
| | | |
| | | mFragmentSwitchHelper = FragmentSwitchHelper.create( |
| | | R.id.fl_main_fragment_container, getSupportFragmentManager(), |
| | | new RecommendCategoryFragment(), new CategoryFragment(), |
| | | new DiscoverNowFragment(), new MineFragment(), new GuessLikeFragment()); |
| | | new HomeFragment(), new CategoryFragment(), |
| | | new BaiDuNewsFragment(), new MineFragment(), new BaiDuVideosFragment()); |
| | | rg_nav = findViewById(R.id.rg_nav); |
| | | rg_nav.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { |
| | | |
| | |
| | | switch (checkedId) { |
| | | case R.id.rb_nav_recommend: { |
| | | mFragmentSwitchHelper |
| | | .changeFragment(RecommendCategoryFragment.class); |
| | | .changeFragment(HomeFragment.class); |
| | | } |
| | | break; |
| | | case R.id.rb_nav_category: { |
| | |
| | | break; |
| | | case R.id.rb_guess_like: { |
| | | mFragmentSwitchHelper |
| | | .changeFragment(GuessLikeFragment.class); |
| | | .changeFragment(BaiDuVideosFragment.class); |
| | | } |
| | | break; |
| | | case R.id.rb_nav_discover: { |
| | | mFragmentSwitchHelper |
| | | .changeFragment(DiscoverNowFragment.class); |
| | | .changeFragment(BaiDuNewsFragment.class); |
| | | } |
| | | break; |
| | | case R.id.rb_nav_mine: { |
| | |
| | | .setChecked(true); |
| | | } |
| | | }); |
| | | try { |
| | | Glide.with(getApplicationContext()).load(preferences.getString("top_icon", "")) |
| | | .asBitmap().into(target); |
| | | } catch (IllegalArgumentException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | setRightTopAD(); |
| | | preLoadCommonAD(); |
| | | } |
| | | |
| | | private SimpleTarget<Bitmap> target = new SimpleTarget<Bitmap>() { |
| | | |
| | | /** |
| | | * 预加载广告 |
| | | */ |
| | | private void preLoadCommonAD() { |
| | | //加载搜索结果页 |
| | | SearchResultAdManager.getInstance(getApplicationContext()).loadAD(1, null); |
| | | } |
| | | |
| | | |
| | | private void setRightTopAD() { |
| | | if (preferences == null) |
| | | preferences = getSharedPreferences("user", |
| | | Context.MODE_PRIVATE); |
| | | String topIcon = preferences.getString("top_icon", ""); |
| | | if (!StringUtils.isBlank(topIcon)) { |
| | | fl_right_ad.setVisibility(View.VISIBLE); |
| | | try { |
| | | Glide.with(getApplicationContext()).load(topIcon).into(target); |
| | | } catch (IllegalArgumentException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } else { |
| | | fl_right_ad.setVisibility(View.GONE); |
| | | } |
| | | |
| | | } |
| | | |
| | | //-------------------------视频广告----------------------------- |
| | | |
| | | @Nullable |
| | | public static VideoOption getVideoOption(Intent intent) { |
| | | if (intent == null) { |
| | | return null; |
| | | } |
| | | return new VideoOption.Builder().build(); |
| | | } |
| | | |
| | | |
| | | //-------------------------视频广告结束----------------------------- |
| | | |
| | | private SimpleTarget<Drawable> target = new SimpleTarget<Drawable>() { |
| | | |
| | | @Override |
| | | public void onResourceReady(Bitmap bitmap, |
| | | GlideAnimation<? super Bitmap> arg1) { |
| | | iv_taobao.setImageBitmap(bitmap); |
| | | public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) { |
| | | iv_taobao.setImageDrawable(resource); |
| | | long time = preferences.getLong("latestAdtime", 0); |
| | | if (!getDay(time).equalsIgnoreCase( |
| | | getDay(System.currentTimeMillis()))) { |
| | |
| | | } else { |
| | | iv_red_dot.setVisibility(View.GONE); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onLoadCleared(@Nullable Drawable placeholder) { |
| | | |
| | | } |
| | | |
| | |
| | | return date; |
| | | } |
| | | |
| | | // List<String> list = new ArrayList<String>(); |
| | | |
| | | // class GoogleMusicAdapter extends FragmentPagerAdapter { |
| | | // |
| | | // public GoogleMusicAdapter(FragmentManager fm) { |
| | | // super(fm); |
| | | // } |
| | | // |
| | | // @Override |
| | | // public Fragment getItem(int position) { |
| | | // if (position % list.size() == 0) { |
| | | //// return RecommendFragment.newInstance(); |
| | | // return LiveGirlFragment.newInstance(); |
| | | // } else if (position % list.size() == 1) |
| | | // return LiveGirlFragment.newInstance(); |
| | | // else if (position % list.size() == 2) |
| | | // return NewCategoryFragment.newInstance(); |
| | | // else if (position % list.size() == 3) |
| | | // return DiscoverFragment.newInstance(); |
| | | // else if (position % list.size() == 4) { |
| | | // SharedPreferences preferences1 = getSharedPreferences("user", |
| | | // Context.MODE_PRIVATE); |
| | | // preferences1.edit().putBoolean("PushType", false).commit(); |
| | | // iv_msg_dot.setVisibility(View.GONE); |
| | | // return FollowFragment.newInstance(); |
| | | // } else { |
| | | //// return RecommendFragment.newInstance(); |
| | | // return null; |
| | | // } |
| | | // } |
| | | // |
| | | // @Override |
| | | // public CharSequence getPageTitle(int position) { |
| | | // return list.get(position % list.size()); |
| | | // } |
| | | // |
| | | // @Override |
| | | // public int getCount() { |
| | | // return list == null ? 0 : list.size(); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | private boolean isCheckedComment = true;// 消息是否被查看 |
| | | private boolean isCheckedUpdate = false;// 消息是否被查看 |
| | | |
| | | // EventBus事件响应 |
| | | // public void onEventMainThread(NewComment info) { |
| | | // isCheckedComment = info.getState(); |
| | | // if (isCheckedUpdate || !isCheckedComment) { |
| | | // mBadgeView.show(); |
| | | // } else { |
| | | // mBadgeView.hide(); |
| | | // } |
| | | // } |
| | | |
| | | private boolean isLogin = false; |
| | | |
| | |
| | | @Override |
| | | public void onResume() { |
| | | super.onResume(); |
| | | try { |
| | | Glide.with(getApplicationContext()).load(preferences.getString("top_icon", "")) |
| | | .asBitmap().into(target); |
| | | } catch (IllegalArgumentException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | MobclickAgent.onResume(this); |
| | | setRightTopAD(); |
| | | isLogin = StringUtils.isEmpty(preferences.getString("LoginUid", "")) ? false |
| | | : true; |
| | | |
| | | if (!StringUtils.isEmpty(preferences.getString("shopurl", "")) && !preferences.getBoolean("isDown", false)) { |
| | | addDownloadBuxin(preferences.getString("shopurl", "")); |
| | | } |
| | | // if (isLogin) { |
| | | // if (preferences1.getBoolean("PushType", false)) { |
| | | // iv_msg_dot.setVisibility(View.VISIBLE); |
| | | // } else { |
| | | // iv_msg_dot.setVisibility(View.GONE); |
| | | // } |
| | | // |
| | | // try { |
| | | // Glide.with(getApplicationContext()).load(BeibeiConstant.addPreFix(preferences1.getString("portrait", ""))) |
| | | // .placeholder(R.drawable.img_head_portrait).error(R.drawable.ic_portrait_default).transform(new GlideCircleTransform(this)) |
| | | // .into(iv_user_logo); |
| | | // Glide.with(getApplicationContext()).load(BeibeiConstant.addPreFix(preferences1.getString("portrait", ""))) |
| | | // .placeholder(R.drawable.img_head_portrait).error(R.drawable.ic_portrait_default).transform(new GlideCircleTransform(this)) |
| | | // .into(iv_portrait); |
| | | // } catch (IllegalArgumentException e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | // tv_login_name.setText(preferences1.getString("name", "")); |
| | | // tv_userName.setText(preferences1.getString("name", "")); |
| | | // tv_userName.setTextColor(getResources().getColor(R.color.white)); |
| | | // tv_userName.setVisibility( |
| | | // View.VISIBLE); |
| | | // findViewById(R.id.mine_tv_name2).setVisibility( |
| | | // View.GONE); |
| | | // findViewById(R.id.mine_tv_login).setVisibility( |
| | | // View.GONE); |
| | | // getNewInfo(); |
| | | // } else { |
| | | // iv_msg_dot.setVisibility(View.GONE); |
| | | // iv_portrait.setImageResource(R.drawable.img_head_portrait); |
| | | // tv_login_name.setText("立即登录"); |
| | | // |
| | | // iv_user_logo.setImageResource(R.drawable.img_head_portrait); |
| | | // tv_userName.setText("一键登录"); |
| | | // tv_userName.setTextColor(getResources().getColor(R.color.gray)); |
| | | // tv_userName.setVisibility( |
| | | // View.VISIBLE); |
| | | // findViewById(R.id.mine_tv_name2).setVisibility( |
| | | // View.VISIBLE); |
| | | // findViewById(R.id.mine_tv_login).setVisibility( |
| | | // View.VISIBLE); |
| | | // } |
| | | EventBus.getDefault().register(this); |
| | | } |
| | | |
| | |
| | | builder.setPositiveButton("", new DialogInterface.OnClickListener() { |
| | | @Override |
| | | public void onClick(DialogInterface dialog, int which) { |
| | | // mateAppMarket1(); |
| | | try { |
| | | Intent intent = new Intent(MainActivity.this, |
| | | com.weikou.beibeivideo.service.DownLoadFileService.class); |
| | |
| | | @Override |
| | | public void onPause() { |
| | | super.onPause(); |
| | | MobclickAgent.onPause(this); |
| | | AppUpdate.destoryAppUpdate(); |
| | | EventBus.getDefault().unregister(this); |
| | | } |
| | |
| | | }); |
| | | } |
| | | |
| | | ExitDialog exitDialog = null; |
| | | ExitDialog.Builder exitDialogBuilder = null; |
| | | |
| | | |
| | | @Override |
| | | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| | | if (keyCode == KeyEvent.KEYCODE_BACK) { |
| | | // if ((System.currentTimeMillis() - mExitTime) > 2000) { |
| | | // Toast.makeText(this, "再按一次退出程序", Toast.LENGTH_SHORT).show(); |
| | | // mExitTime = System.currentTimeMillis(); |
| | | // return true; |
| | | // } |
| | | ExitDialog dialog = new ExitDialog.Builder(this).create(); |
| | | dialog.setCanceledOnTouchOutside(true); |
| | | dialog.show(); |
| | | if (exitDialog != null) { |
| | | exitDialogBuilder.showAd(); |
| | | exitDialog.show(); |
| | | } |
| | | return true; |
| | | } |
| | | return super.onKeyDown(keyCode, event); |
| | |
| | | intent.setClass(MainActivity.this, PersonInfoActivity.class); |
| | | } else {// 登录前 |
| | | intent.setClass(MainActivity.this, LoginActivity.class); |
| | | |
| | | } |
| | | startActivity(intent); |
| | | break; |
| | | case R.id.rl_mine_favourite: |
| | | startActivity(new Intent(MainActivity.this, MyFavouriteActivity.class)); |
| | | break; |
| | | case R.id.rl_mine_watch_history: |
| | | startActivity(new Intent(MainActivity.this, WatchHistoryActivity.class)); |
| | | break; |
| | | case R.id.rl_mine_download: |
| | | startActivity(new Intent(MainActivity.this, DownloadActivity.class)); |
| | | break; |
| | | case R.id.rl_mine_follow: |
| | | startActivity(new Intent(MainActivity.this, FollowActivity.class)); |
| | | break; |
| | | case R.id.rl_mine_message: |
| | | openMsg(); |
| | | break; |
| | | case R.id.rl_share: |
| | | // (new ShareDialogFragment()).show(getSupportFragmentManager(), |
| | | // "ShareDialogFragment"); |
| | | String shareContent = getShareContent(); |
| | | UMWeb web = new UMWeb(getShareUrl()); |
| | | String shareTitle = getResources().getString(R.string.app_name); |
| | | web.setTitle(shareTitle); |
| | | web.setDescription(shareContent); |
| | | new ShareAction(MainActivity.this).withText(shareContent).withMedia(web) |
| | | .setDisplayList(SHARE_MEDIA.SINA, SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN) |
| | | .setCallback(shareListener).open(); |
| | | break; |
| | | case R.id.rl_suggestion: |
| | | startActivity(new Intent(MainActivity.this, |
| | | HelpAndTicklingActivity.class)); |
| | | break; |
| | | case R.id.rl_release: |
| | | startActivity(new Intent(MainActivity.this, |
| | | ReleasePromptActivity.class)); |
| | | break; |
| | | case R.id.rl_settings: |
| | | startActivity(new Intent(MainActivity.this, SettingsActivity.class)); |
| | | break; |
| | | |
| | | |
| | | } |
| | | } |
| | | |