thieumao

MainFragment Xem Youtube

May 4th, 2015
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 34.11 KB | None | 0 0
  1. package com.watchsportbd.fblive.fragment;
  2.  
  3. import havvn.libs.view.AdIDListener;
  4. import havvn.libs.view.AdIDManager;
  5. import io.vov.vitamio.LibsChecker;
  6.  
  7. import java.util.ArrayList;
  8. import java.util.LinkedHashMap;
  9. import java.util.Locale;
  10. import java.util.Map;
  11.  
  12. import org.json.JSONException;
  13. import org.json.JSONObject;
  14.  
  15. import com.google.android.gms.ads.AdRequest;
  16. import com.google.android.gms.ads.AdSize;
  17. import com.google.android.gms.ads.InterstitialAd;
  18. //import com.google.ads.AdSize;
  19. import com.google.gson.Gson;
  20. //import com.inmobi.androidsdk.BannerView;
  21. import com.loopj.android.http.AsyncHttpClient;
  22. import com.loopj.android.http.AsyncHttpResponseHandler;
  23. import com.watchsportbd.fblive.CustomPlayVideo;
  24. import com.watchsportbd.fblive.DetailLiveScore;
  25. import com.watchsportbd.fblive.R;
  26. import com.watchsportbd.fblive.adapter.ExpandableListLiveScoreAdapter;
  27. import com.watchsportbd.fblive.adapter.ExpandableListTheThaoAdapter;
  28. import com.watchsportbd.fblive.adapter.adapter1ListTheThao;
  29. import com.watchsportbd.fblive.adapter.adapter1ListTrangChu;
  30. import com.watchsportbd.fblive.adapter.adapter1LiveScore;
  31. import com.watchsportbd.fblive.adapter.adapterTrangChu;
  32. import com.watchsportbd.fblive.database.MyDatabase;
  33. import com.watchsportbd.fblive.database.objTivi;
  34. import com.watchsportbd.fblive.obj.obj1CateNo;
  35. import com.watchsportbd.fblive.obj.obj1ListChannel;
  36. import com.watchsportbd.fblive.obj.obj1ListLiveScore;
  37. import com.watchsportbd.fblive.obj.obj1ListTheThao;
  38. import com.watchsportbd.fblive.obj.obj1Thethao;
  39. import com.watchsportbd.fblive.obj.obj1TiviK;
  40. import com.watchsportbd.fblive.obj.obj1TranDau;
  41. import com.watchsportbd.fblive.obj.objInfo;
  42. import com.watchsportbd.fblive.util.AdsDialog;
  43. import com.watchsportbd.fblive.util.MyConstans;
  44. import com.watchsportbd.fblive.util.MyDataPref;
  45. import com.watchsportbd.fblive.util.MyLog;
  46. import com.watchsportbd.fblive.util.MyUtil;
  47.  
  48. //import com.searchboxsdk.android.StartAppSearch;
  49. //import com.startapp.android.publish.StartAppAd;
  50. //import com.tivifootballkplus.filmhd.util.AdflexHelper;
  51. import android.app.Activity;
  52. import android.app.AlertDialog;
  53. import android.content.DialogInterface;
  54. import android.content.Intent;
  55. import android.content.SharedPreferences;
  56. import android.content.pm.PackageManager.NameNotFoundException;
  57. import android.graphics.Bitmap;
  58. import android.net.Uri;
  59. import android.os.Bundle;
  60. import android.os.Handler;
  61. import android.support.v4.app.Fragment;
  62. import android.util.Log;
  63. import android.view.LayoutInflater;
  64. import android.view.View;
  65. import android.view.ViewGroup;
  66. import android.view.animation.AccelerateInterpolator;
  67. import android.view.animation.Animation;
  68. import android.view.animation.TranslateAnimation;
  69. import android.webkit.WebChromeClient;
  70. import android.webkit.WebView;
  71. import android.webkit.WebViewClient;
  72. import android.widget.AdapterView;
  73. import android.widget.ExpandableListAdapter;
  74. import android.widget.ExpandableListView;
  75. import android.widget.ExpandableListView.OnChildClickListener;
  76. import android.widget.GridView;
  77. import android.widget.ImageView;
  78. import android.widget.LinearLayout;
  79. import android.widget.ListView;
  80. import android.widget.ProgressBar;
  81. import android.widget.TextView;
  82. import android.widget.Toast;
  83. import android.widget.ViewFlipper;
  84. import android.widget.AdapterView.OnItemClickListener;
  85. import android.widget.TableRow.LayoutParams;
  86. import com.startapp.android.publish.StartAppAd;
  87.  
  88.  
  89. public class MainFragment extends Fragment {
  90.  
  91.     public TextView tvTitle;
  92.     private ViewFlipper viewFliper;
  93.     // private Context aContext;
  94.     // private int maxValueWidth;
  95.     public SharedPreferences prefs;
  96.     public SharedPreferences.Editor editor;
  97.     // private boolean mBack = false;
  98.     private MyUtil myUtil;
  99.     private MyDataPref myData1;
  100.     // private String admodkey = "a1525ab0b0afef0";// "a15237fed2d5ac8";//
  101.     // "a14fcf1cbf28ea8";
  102. //  private String inmobiKey = "fdc0e73341344009977eeb4f65ea8b32";
  103.     private LinearLayout adview;
  104.  
  105.     private View view;
  106.     private MyDatabase myData;
  107.  
  108.     private ListView lvTrangChu;
  109.     private ArrayList<obj1ListChannel> arrTrangChu;
  110.  
  111.     private ProgressBar mLoadWebview;
  112.     private boolean isLoaded = false;
  113.  
  114.     // list phim
  115.     private GridView gridTivi;
  116.     private TextView tvTitleTivi;
  117.    
  118.     // the thao
  119.     private ExpandableListView expListViewTheThao;
  120.     private boolean isLoadedTheThao = false;
  121.     private ArrayList<obj1ListTheThao> groupList;
  122. //  private ArrayList<obj1Thethao> childList;/
  123.     private Map<obj1ListTheThao, ArrayList<obj1Thethao>> thethaoCollection;
  124. //  private  ExpandableListView expListView;
  125.    
  126.     //livescore
  127.     private boolean isLoadedScore = false;
  128.     private ArrayList<obj1ListLiveScore> arrLiveScore;
  129.     private ExpandableListView lvLiveScore;
  130.     private Map<obj1ListLiveScore, ArrayList<obj1TranDau>> liveScoreCollection;
  131.    
  132.     // all of tivi for search or the thao
  133.     private ArrayList<obj1TiviK> listAllTiviK;
  134.  
  135.        
  136.     @Override
  137.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  138.             Bundle savedInstanceState) {
  139.         // TODO Auto-generated method stub
  140.  
  141.         view = inflater.inflate(R.layout.mainslide, container, false);
  142.         ImageView imgback = (ImageView) view.findViewById(R.id.imgMainback);
  143.         imgback.setOnClickListener(homeClickListenner);
  144.         tvTitle = (TextView) view.findViewById(R.id.tvMainTitle);
  145.  
  146.         viewFliper = (ViewFlipper) view.findViewById(R.id.vfMainFliper1);
  147.         mLoadWebview = (ProgressBar) view.findViewById(R.id.llLoadingWebview);
  148.         // db = new MyDatabase(getActivity());
  149.         myUtil = new MyUtil(getActivity());
  150.         myData = new MyDatabase(getActivity());
  151.         myData1 = new MyDataPref(getActivity());
  152.  
  153.         initViewFragment(view);
  154.         iniStartApp();
  155.    
  156.          initAdmob();
  157.          initInterstitialAds();
  158.    
  159.         showTab(MyConstans.FRAG_TRANGCHU, null);
  160.  
  161.         new Handler().postDelayed(new Runnable() {
  162.  
  163.             @Override
  164.             public void run() {
  165.                 updateVersion();
  166.             }
  167.         }, 1000);
  168.  
  169.         return view;
  170.     }
  171.  
  172.     private void initAdmob(){
  173.         AdIDManager.getInstance();
  174.         AdIDManager.initAdManager(getActivity(), AdSize.SMART_BANNER, MyConstans.ADDMOD_BANNER_ID);
  175.         adview = (LinearLayout) view.findViewById(R.id.ad);
  176.         LinearLayout.LayoutParams adWhirlLayoutParams = new LinearLayout.LayoutParams(
  177.                 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  178.         adview.addView(AdIDManager.adviewLayout, adWhirlLayoutParams);
  179.         AdIDManager.setAdview(adview);
  180.     }      
  181.     private void initViewFragment(View view) {
  182.         lvTrangChu = (ListView) view.findViewById(R.id.listTrangChu);
  183.         arrTrangChu = new ArrayList<obj1ListChannel>();
  184.         gridTivi = (GridView) view.findViewById(R.id.gridTivi);
  185.         expListViewTheThao = (ExpandableListView) view.findViewById(R.id.listTheThao);
  186.         lvLiveScore = (ExpandableListView ) view.findViewById(R.id.listLiveScore);
  187. //      arrLiveScore = new ArrayList<obj1TranDau>();
  188.         listAllTiviK = new ArrayList<obj1TiviK>();
  189.     }
  190.  
  191.     @Override
  192.     public void onActivityCreated(Bundle savedInstanceState) {
  193.         // TODO Auto-generated method stub
  194.         super.onActivityCreated(savedInstanceState);
  195.         // selectTab(MyConstans.SLIDE_NEW);
  196.     }
  197.  
  198.     private View.OnClickListener homeClickListenner = new View.OnClickListener() {
  199.  
  200.         @Override
  201.         public void onClick(View v) {
  202.             // TODO Auto-generated method stub
  203.  
  204.             listenner.onMainClick();
  205.         }
  206.     };
  207.  
  208.     @Override
  209.     public void onAttach(Activity activity) {
  210.         super.onAttach(activity);
  211.  
  212.         // This makes sure that the container activity has implemented
  213.         // the callback interface. If not, it throws an exception.
  214.         try {
  215.             listenner = (OnMainClickListenner) activity;
  216.         } catch (ClassCastException e) {
  217.             throw new ClassCastException(activity.toString()
  218.                     + " must implement OnMainClickListenner");
  219.         }
  220.     }
  221.  
  222.     OnMainClickListenner listenner;
  223.  
  224.     public interface OnMainClickListenner {
  225.         public void onMainClick();
  226.     }
  227.  
  228.     // ////////////////////////////
  229.  
  230.     public void showTab(int tag, obj1CateNo obj) {
  231.         switch (tag) {
  232.         case MyConstans.FRAG_TRANGCHU:
  233.             tvTitle.setText(getResources().getString(R.string.home));
  234.             showTrangChu(obj);
  235.             break;
  236.         case MyConstans.FRAG_NEWS:
  237.             tvTitle.setText(obj.name.toUpperCase());
  238.             showNEWS(obj);
  239.             break;
  240.         case MyConstans.FRAG_WEBVIEW:
  241.             tvTitle.setText(obj.name.toUpperCase());
  242.             showWEBVIEW(obj);
  243.             break;
  244.         case MyConstans.FRAG_LISTTIVI:
  245.             tvTitle.setText(obj.name.toUpperCase());
  246.             showListTivi(obj);
  247.             break;
  248.         case MyConstans.FRAG_SCORE:
  249.             tvTitle.setText(obj.name.toUpperCase());
  250.             showLiveScore(obj);
  251.             break;
  252.         default:
  253.             break;
  254.         }
  255.     }
  256.  
  257.     public void setTitle(String text){
  258.         tvTitle.setText(text.toUpperCase());
  259.     }
  260.     private void showTrangChu(obj1CateNo obj1) {
  261.         slide(MyConstans.FRAG_TRANGCHU, true);
  262.         try {
  263.             showAdmob(false);
  264.             if (obj1 != null && arrTrangChu != null) {
  265.                 MyLog.E("Co du lieu trang chu");
  266.                 ArrayList<obj1ListChannel> listACate = new ArrayList<obj1ListChannel>();
  267.                 for (obj1ListChannel _obj : arrTrangChu) {
  268.                     if (_obj.categoryId.contentEquals(obj1.id)) {
  269.                         listACate.add(_obj);
  270.                     }
  271.                 }
  272.  
  273.                 try {
  274.  
  275.                     adapterTrangChu adapter = new adapterTrangChu(
  276.                             MainFragment.this, R.layout.item_trangchu,
  277.                             listACate);
  278.                     lvTrangChu.setAdapter(adapter);
  279.                     // MyLog.E(">>>>size trang chu"+ arrTrangChu.size());
  280.                 } catch (Exception e) {
  281.                     // TODO: handle exception
  282.                     e.printStackTrace();
  283.                     // MyLog.E(">>>>EEEEERRRRR");
  284.                 }
  285.             } else {
  286.                 MyLog.E("Khong Co du lieu trang chu");
  287.                  if (isLoaded)
  288.                     loadAllTrangChu();// cache
  289.                 else
  290.                     getAllTrangChu();
  291.             }
  292.  
  293.         } catch (Exception e) {
  294.             // TODO Auto-generated catch block
  295.             e.printStackTrace();
  296.         }
  297.  
  298.     }
  299.  
  300.     private void showListTivi(obj1CateNo obj1) {
  301.         slide(MyConstans.FRAG_LISTTIVI, true);
  302.         try {
  303.             showAdmob(false);
  304.             if (obj1 != null && arrTrangChu != null) {
  305.                 ArrayList<obj1ListChannel> listACate = new ArrayList<obj1ListChannel>();
  306.                 for (obj1ListChannel _obj : arrTrangChu) {
  307.                     if (_obj.categoryId.contentEquals(obj1.id)) {
  308.                         listACate.add(_obj);
  309.                     }
  310.                 }
  311.                 try {
  312.  
  313.                     adapter1ListTrangChu adapter = new adapter1ListTrangChu(
  314.                             MainFragment.this, R.layout.item_listtivi,
  315.                             listACate.get(0).channelList,0);
  316.                     gridTivi.setAdapter(adapter);
  317.                     gridTivi.setOnItemClickListener(onItemGridPhimClick);
  318.                 } catch (Exception e) {
  319.                     // TODO: handle exception
  320.                     e.printStackTrace();
  321.                     // MyLog.E(">>>>EEEEERRRRR");
  322.                 }
  323.             } else {
  324.                 if (isLoaded)
  325.                     loadAllTrangChu();// cache
  326.                 else
  327.                     getAllTrangChu();
  328.             }
  329.  
  330.         } catch (Exception e) {
  331.             // TODO Auto-generated catch block
  332.             e.printStackTrace();
  333.         }
  334.  
  335.     }
  336.  
  337.     public void showListTivi(ArrayList<obj1TiviK> listtivi) {
  338.         slide(MyConstans.FRAG_LISTTIVI, true);
  339.        
  340.         showAdmob(false);
  341.         try {
  342.             adapter1ListTrangChu adapter = new adapter1ListTrangChu(
  343.                     MainFragment.this, R.layout.item_listtivi, listtivi,0);
  344.             gridTivi.setAdapter(adapter);
  345.             gridTivi.setOnItemClickListener(onItemGridPhimClick);
  346.  
  347.         } catch (Exception e) {
  348.             // TODO: handle exception
  349.             e.printStackTrace();
  350.             // MyLog.E(">>>>EEEEERRRRR");
  351.         }
  352.  
  353.     }
  354.  
  355.     private OnItemClickListener onItemGridPhimClick = new OnItemClickListener() {
  356.         @Override
  357.         public void onItemClick(AdapterView<?> parent, View view, int position,
  358.                 long arg3) {
  359.         //  Log.e("Menu","Click vao Menu");
  360.             //showInterstitialAd();
  361.         //startAppAd.showAd(); // show the ad
  362.         //startAppAd.loadAd(); // load the next ad
  363.             // TODO Auto-generated method stub
  364.             obj1TiviK obj = (obj1TiviK) parent.getAdapter().getItem(position);
  365.             playTivi(obj);
  366.         }
  367.     };
  368.  
  369.     private void showNEWS(obj1CateNo objcate) {
  370.         slide(MyConstans.FRAG_NEWS, true);
  371.         try {
  372.             showAdmob(false);
  373.             if(!isLoadedTheThao)
  374.             getAllTheThao(objcate);
  375.             // getAllTrangChu();
  376.         } catch (Exception e) {
  377.             // TODO Auto-generated catch block
  378.             e.printStackTrace();
  379.         }
  380.  
  381.     }
  382.    
  383.     private void showLiveScore(obj1CateNo objcate) {
  384.         slide(MyConstans.FRAG_SCORE, true);
  385.         try {
  386.             showAdmob(false);
  387.             if(!isLoadedScore)
  388.             getAllScore(objcate);
  389.            
  390.         } catch (Exception e) {
  391.             // TODO Auto-generated catch block
  392.             e.printStackTrace();
  393.         }
  394.  
  395.     }
  396.  
  397.     private void showWEBVIEW(obj1CateNo obj) {
  398.         slide(MyConstans.FRAG_WEBVIEW, true);
  399.         try {
  400.             showAdmob(false);
  401.  
  402.             loadWebView(obj.description.replace("<p>", "").replace("</p>", ""));
  403.         } catch (Exception e) {
  404.             // TODO Auto-generated catch block
  405.             e.printStackTrace();
  406.         }
  407.  
  408.     }
  409.  
  410.     private void loadWebView(String url) {
  411.  
  412.         final WebView mWebview = (WebView) view
  413.                 .findViewById(R.id.customize_webview);
  414.         mWebview.getSettings().setJavaScriptEnabled(true); // enable javascript
  415.         mWebview.getSettings().setLoadWithOverviewMode(true);
  416.         mWebview.getSettings().setUseWideViewPort(true);
  417.         mWebview.getSettings().setBuiltInZoomControls(true);
  418.  
  419.         mWebview.setWebViewClient(new WebViewClient() {
  420.             public void onReceivedError(WebView view, int errorCode,
  421.                     String description, String failingUrl) {
  422.                 Toast.makeText(getActivity(), description, Toast.LENGTH_SHORT)
  423.                         .show();
  424.                 // llError.setVisibility(View.VISIBLE);
  425.                 // llLoading.setVisibility(View.GONE);
  426.             }
  427.  
  428.             @Override
  429.             public void onPageStarted(WebView view, String url, Bitmap favicon) {
  430.                 // pd.show();
  431.                 // llError.setVisibility(View.GONE);
  432.                 // llLoading.setVisibility(View.VISIBLE);
  433.                 mLoadWebview.setVisibility(View.VISIBLE);
  434.             }
  435.  
  436.             @Override
  437.             public void onPageFinished(WebView view, String url) {
  438.                 // pd.dismiss();
  439.                 // llError.setVisibility(View.GONE);
  440.                 // llLoading.setVisibility(View.GONE);
  441.                 // String webUrl = mWebview.getUrl();
  442.             }
  443.         });
  444.  
  445.         mWebview.setWebChromeClient(new WebChromeClient() {
  446.  
  447.             @Override
  448.             public void onProgressChanged(WebView view, int newProgress) {
  449.                 // TODO Auto-generated method stub
  450.                 super.onProgressChanged(view, newProgress);
  451.                 if (newProgress >= 100) {
  452.                     // llError.setVisibility(View.GONE);
  453.                     // llLoading.setVisibility(View.GONE);
  454.                     mLoadWebview.setVisibility(View.GONE);
  455.                 } else {
  456.                     // llError.setVisibility(View.VISIBLE);
  457.                     // llLoading.setVisibility(View.VISIBLE);
  458.                     mLoadWebview.setVisibility(View.VISIBLE);
  459.                 }
  460.  
  461.                 MyLog.E("newprogress>>>" + newProgress);
  462.             }
  463.  
  464.         });
  465.  
  466.         mWebview.loadUrl(url);
  467.     }
  468.  
  469.     public void playTivi(obj1TiviK obj) {
  470.  
  471.         // getActivity().startActivity(i);
  472.         if (obj != null) {
  473.             getVideo(obj);
  474.  
  475.         } else {
  476.             Toast.makeText(getActivity(), "Error", Toast.LENGTH_SHORT).show();
  477.         }
  478.  
  479.     }
  480.     AsyncHttpClient client = new AsyncHttpClient();
  481.     private void getVideo(final obj1TiviK obj){
  482.  
  483.         client.cancelRequests(getActivity(), true);
  484.         client = new AsyncHttpClient();
  485. ///     String video_id = "1FJHYqE0RDg";
  486.         String video_id = "";
  487.         String gdata = "http://gdata.youtube.com/feeds/api/videos/";
  488.        
  489.         String urlrequest = "";
  490.         final String url = obj.urls;
  491.         MyLog.E("url before>>>" + obj.urls);
  492.        
  493.         if(url.contains("youtube.com")){
  494.             urlrequest = url;
  495.             client.setUserAgent("Mozilla/5.0 (iPad; CPU OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25");
  496.             MyLog.E("urlrequest youtube>>>" + urlrequest);
  497.            
  498.  
  499.             if(myUtil.isInternet(getActivity()))   
  500.             client.get(urlrequest, new AsyncHttpResponseHandler() {
  501.  
  502.                 @Override
  503.                 public void onStart() {
  504.                     // TODO Auto-generated method stub
  505.                     super.onStart();
  506.                     //progressLoading.setVisibility(View.VISIBLE);
  507.                 }
  508.  
  509.                 @Override
  510.                 public void onSuccess(int arg0, String arg1) {
  511.                     // TODO Auto-generated method stub
  512.                     super.onSuccess(arg0, arg1);
  513.                     //progressLoading.setVisibility(View.GONE);
  514.                     //btnPlayPhim.setVisibility(View.VISIBLE);             
  515.                     MyLog.E("You tube detail>>>" + arg1);
  516.                     try {      
  517.                         Intent i = new Intent(getActivity(),CustomPlayVideo.class );
  518. //                          String rtsp_link = "rtsp:"+ MyUtil.split(MyUtil.split(arg1, "rtsp:")[1], ".3gp")[0] + ".3gp";
  519.                             String rtsp_link =MyUtil.getYoutubeRespond(arg1);
  520.                             MyLog.E("rtsp_link>>>" + rtsp_link);
  521.                             i.putExtra("URLPLAY", rtsp_link);
  522.                             i.putExtra("FILM_NAME", obj.channelName);
  523.                         getActivity().startActivity(i);
  524.                                                    
  525.                     } catch (Exception e) {
  526.                         // TODO: handle exception
  527.                         e.printStackTrace();
  528.                     }
  529.  
  530.                 }
  531.  
  532.                 @Override
  533.                 protected void sendFailureMessage(Throwable arg0, String arg1) {
  534.                     // TODO Auto-generated method stub
  535.                     super.sendFailureMessage(arg0, arg1);
  536.                 }
  537.  
  538.             });
  539.             else
  540.                 Toast.makeText(getActivity(), "Error Network", Toast.LENGTH_SHORT).show();
  541.            
  542.         }else{
  543.             //urlrequest = String.format(String.valueOf(MyConstans.API_PHIMDETAIL),obj.VideoId,url);
  544.             //MyLog.E("url phimdetail>>>" + urlrequest);
  545.             Intent i1 = new Intent(getActivity(), CustomPlayVideo.class);
  546.             i1.putExtra("URLPLAY", obj.urls);
  547.             i1.putExtra("FILM_NAME", obj.channelName);
  548.             getActivity().startActivity(i1);
  549.         }
  550.        
  551.        
  552.     }
  553.     private void slide(int newSlide, boolean n2c) {
  554.         if (n2c && newSlide == currentScreen)
  555.             return;
  556.         viewFliper.setInAnimation(inFromRightAnimation());
  557.         viewFliper.setOutAnimation(outToLeftAnimation());
  558.         viewFliper.setDisplayedChild(newSlide);
  559.         lastScreen = currentScreen;
  560.         currentScreen = newSlide;
  561.     }
  562.  
  563.     private Animation inFromRightAnimation() {
  564.         Animation inFromRight = new TranslateAnimation(
  565.                 Animation.RELATIVE_TO_PARENT, +1.0f,
  566.                 Animation.RELATIVE_TO_PARENT, 0.0f,
  567.                 Animation.RELATIVE_TO_PARENT, 0.0f,
  568.                 Animation.RELATIVE_TO_PARENT, 0.0f);
  569.         inFromRight.setDuration(000);// 500
  570.         inFromRight.setInterpolator(new AccelerateInterpolator());
  571.         return inFromRight;
  572.     }
  573.  
  574.     private Animation outToLeftAnimation() {
  575.         Animation outtoLeft = new TranslateAnimation(
  576.                 Animation.RELATIVE_TO_PARENT, 0.0f,
  577.                 Animation.RELATIVE_TO_PARENT, -1.0f,
  578.                 Animation.RELATIVE_TO_PARENT, 0.0f,
  579.                 Animation.RELATIVE_TO_PARENT, 0.0f);
  580.         outtoLeft.setDuration(000);// 500
  581.         outtoLeft.setInterpolator(new AccelerateInterpolator());
  582.         return outtoLeft;
  583.     }
  584.  
  585.     public void handerBackBottom() {
  586.         if (currentScreen == MyConstans.FRAG_NEWS
  587.                 || currentScreen == MyConstans.FRAG_WEBVIEW || currentScreen == MyConstans.FRAG_LISTTIVI) {
  588.             tvTitle.setText("HOME".toUpperCase());
  589.             showTrangChu(null);
  590.         } else
  591.             quitGame();
  592.     }
  593.  
  594.     public void quitGame() {
  595.         AlertDialog.Builder editDialog = new AlertDialog.Builder(getActivity());      
  596.         editDialog.setTitle(getResources().getString(R.string.exit));
  597.         editDialog.setMessage(getResources().getString(R.string.exit_question));
  598.         editDialog.setIcon(R.drawable.logo_50);
  599.  
  600.         editDialog.setPositiveButton(getResources().getString(R.string.exit),
  601.                 new DialogInterface.OnClickListener() {
  602.                     public void onClick(DialogInterface dialog, int which) {
  603.                         //showInterstitialAd();
  604. //                      showInterstitialAd();
  605.                         // adBuddiz.showAd();
  606.                          //  startAppAd.onBackPressed();
  607.                         startAppAd.showAd();
  608.                          getActivity().finish();
  609.                         //startAppAd.showAd(); // show the ad
  610.                         //startAppAd.s
  611.                     }
  612.                 });
  613.  
  614.         editDialog.setNegativeButton(getResources().getString(R.string.rate),
  615.                 new DialogInterface.OnClickListener() {
  616.                     public void onClick(DialogInterface dialog, int which) {
  617.                         Intent i = new Intent(
  618.                                 Intent.ACTION_VIEW,
  619.                                 Uri.parse("market://details?id="+ MyConstans.packagename));
  620.                         startActivity(i);
  621.                     }
  622.                 });
  623.  
  624.         editDialog.setNeutralButton(getResources().getString(R.string.skip),
  625.                 new DialogInterface.OnClickListener() {
  626.                     public void onClick(DialogInterface dialog, int which) {
  627.  
  628.                     }
  629.                 });
  630.         editDialog.show();
  631.     }
  632.     private void updateVersion() {
  633.         AsyncHttpClient client = new AsyncHttpClient();
  634.         String url = MyConstans.API_INFO;
  635.  
  636.         client.get(url, new AsyncHttpResponseHandler() {
  637.  
  638.             @Override
  639.             public void onSuccess(int arg0, String request) {
  640.                 super.onSuccess(arg0, request);
  641.                 // MyLog.E("update" + request);
  642.                 JSONObject jsonObj;
  643.                 try {
  644.                     jsonObj = new JSONObject(request);
  645.                     String LinkDownload = "", versionName = "";
  646.                     int versionCode = -1;
  647.                     if (jsonObj != null) {
  648.                         LinkDownload = jsonObj.getString("LinkDownload");
  649.                         versionCode = jsonObj.getInt("versionCode");
  650.                         versionName = jsonObj.getString("versionName");
  651.                         MyConstans.packagename = jsonObj.getString("package");
  652.                         MyConstans.moreapp = jsonObj.getString("store");
  653.  
  654.                         if (versionCode > getVersionApp()) // show dialog
  655.                             showDialogUpdate(versionName, LinkDownload);
  656.                     }
  657.                 } catch (JSONException e) {
  658.                     e.printStackTrace();
  659.                 }
  660.             }
  661.  
  662.             @Override
  663.             protected void sendFailureMessage(Throwable arg0, String arg1) {
  664.                 super.sendFailureMessage(arg0, arg1);
  665.             }
  666.  
  667.         });
  668.     }
  669.  
  670.     // get version code
  671.     public int getVersionApp() {
  672.         int v = 0;
  673.         try {
  674.             v = this.getActivity().getPackageManager()
  675.                     .getPackageInfo(this.getActivity().getPackageName(), 0).versionCode;
  676.         } catch (NameNotFoundException e) {
  677.             // Huh? Really?
  678.         }
  679.         return v;
  680.     }
  681.  
  682.     // show dialog update
  683.     public void showDialogUpdate(String versionName, final String urldownload) {
  684.         AlertDialog.Builder editDialog = new AlertDialog.Builder(
  685.                 this.getActivity());
  686.         editDialog.setTitle(getResources().getString(
  687.                 R.string.dialog_update_title));
  688.         editDialog.setMessage(String.format(
  689.                 getResources().getString(R.string.dialog_update_content),
  690.                 versionName));
  691.         editDialog.setPositiveButton("Yes",
  692.                 new DialogInterface.OnClickListener() {
  693.                     public void onClick(DialogInterface dialog, int which) {
  694.                         Intent i = new Intent(Intent.ACTION_VIEW, Uri
  695.                                 .parse(urldownload));
  696.                         startActivity(i);
  697.                     }
  698.                 });
  699.  
  700.         editDialog.setNegativeButton("No",
  701.                 new DialogInterface.OnClickListener() {
  702.                     public void onClick(DialogInterface dialog, int which) {
  703.                     }
  704.                 });
  705.         editDialog.show();
  706.     }
  707.  
  708.     // //////
  709.     private int currentScreen = -1;
  710.     private int lastScreen = -1;
  711.  
  712.  
  713.     private void getAllTrangChu() throws Exception {
  714.         MyLog.E("loading" );
  715.         View viewLoading = (View) view.findViewById(R.id.llTrangchuLoading);
  716.         final View llError = (View) viewLoading
  717.                 .findViewById(R.id.loading_error);
  718.         final View llLoading = (View) viewLoading
  719.                 .findViewById(R.id.loading_layout);
  720.  
  721.         llError.setVisibility(View.GONE);
  722.         llLoading.setVisibility(View.GONE);
  723.        
  724.         AsyncHttpClient client = new AsyncHttpClient();
  725.         String url = String.valueOf(MyConstans.API_TIVI_EN);
  726.        
  727.        
  728.         if (Locale.getDefault().getLanguage().equals("vi"))
  729.         {
  730.            url = String.valueOf(MyConstans.API_TIVI_VN);
  731.            
  732.         }
  733.         MyLog.E("Url tivi>>>" + url);
  734.  
  735.         // if (arrTrangChu.size() < 1)
  736.         client.get(url, new AsyncHttpResponseHandler() {
  737.            
  738.             @Override
  739.             public void onStart() {
  740.                
  741.                 // TODO Auto-generated method stub
  742.                 super.onStart();
  743.                 mLoadWebview.setVisibility(View.VISIBLE);
  744.                 if (!myUtil.isInternet(getActivity()))
  745.                     llError.setVisibility(View.VISIBLE);
  746.                 else
  747.                     llLoading.setVisibility(View.VISIBLE);
  748.                
  749.                
  750.             }
  751.  
  752.             @Override
  753.             public void onSuccess(int arg0, String arg1) {
  754.                 // TODO Auto-generated method stub
  755.                 //MyLog.E("onSuccess()>>>");
  756.                 super.onSuccess(arg0, arg1);
  757.                 llLoading.setVisibility(View.GONE);
  758.                 MyLog.E("setVisibility()>>>");
  759.                
  760.                 mLoadWebview.setVisibility(View.GONE);
  761.                 MyLog.E("phim trang chu>>>" + arg1);
  762.                 isLoaded = true;
  763.                 myData1.saveDataTrangChu(arg1);
  764.                 loadAllTrangChu();
  765.             }
  766.  
  767.             @Override
  768.             protected void sendFailureMessage(Throwable arg0, String arg1) {
  769.                 // TODO Auto-generated method stub
  770.                 super.sendFailureMessage(arg0, arg1);
  771.                 llLoading.setVisibility(View.GONE);
  772.                 llError.setVisibility(View.VISIBLE);
  773.             }
  774.  
  775.         });
  776.     }
  777.  
  778.     private void loadAllTrangChu() {
  779.         try {
  780.  
  781.             arrTrangChu = new ArrayList<obj1ListChannel>();
  782.             MyLog.E("data trang chu>>>" + myData1.getDataTrangChu());
  783.             arrTrangChu = myUtil.getListChannel(myData1.getDataTrangChu());
  784.        
  785.             adapterTrangChu adapter = new adapterTrangChu(MainFragment.this,
  786.                     R.layout.item_trangchu, arrTrangChu);
  787.             lvTrangChu.setAdapter(adapter);
  788.            
  789.             // create all listviti
  790.             listAllTiviK = new ArrayList<obj1TiviK>();
  791.             for (obj1ListChannel objitem : arrTrangChu) {
  792.                 for (obj1TiviK objTivi : objitem.channelList) {
  793.                     listAllTiviK.add(objTivi);
  794.                 }
  795.             }
  796.             // MyLog.E(">>>>size trang chu"+ arrTrangChu.size());
  797.         } catch (Exception e) {
  798.             // TODO: handle exception
  799.             e.printStackTrace();
  800.             // MyLog.E(">>>>EEEEERRRRR");
  801.         }
  802.     }
  803.  
  804.  
  805.     private void getAllTheThao(obj1CateNo objcate) throws Exception {
  806.         View viewLoading = (View) view.findViewById(R.id.llThethaoLoading);
  807.         final View llError = (View) viewLoading
  808.                 .findViewById(R.id.loading_error);
  809.         final View llLoading = (View) viewLoading
  810.                 .findViewById(R.id.loading_layout);
  811.  
  812.         llError.setVisibility(View.GONE);
  813.         llLoading.setVisibility(View.GONE);
  814.  
  815.         AsyncHttpClient client = new AsyncHttpClient();
  816.         String url = String.valueOf(objcate.description) ;
  817.  
  818.        
  819.         client.get(url, new AsyncHttpResponseHandler() {
  820.  
  821.             @Override
  822.             public void onStart() {
  823.                 // TODO Auto-generated method stub
  824.                 super.onStart();
  825.                 mLoadWebview.setVisibility(View.VISIBLE);
  826.                 if (!myUtil.isInternet(getActivity()))
  827.                     llError.setVisibility(View.VISIBLE);
  828.                 else
  829.                     llLoading.setVisibility(View.VISIBLE);
  830.             }
  831.  
  832.             @Override
  833.             public void onSuccess(int arg0, String arg1) {
  834.                 // TODO Auto-generated method stub
  835.                 super.onSuccess(arg0, arg1);
  836.                 llLoading.setVisibility(View.GONE);
  837.                 mLoadWebview.setVisibility(View.GONE);
  838.                 MyLog.E(" the thao>>>" + arg1);
  839.                 isLoadedTheThao = true;
  840.                 myData1.saveDataTheThao(arg1);
  841.                 loadingThethao();
  842.             }
  843.  
  844.             @Override
  845.             protected void sendFailureMessage(Throwable arg0, String arg1) {
  846.                 // TODO Auto-generated method stub
  847.                 super.sendFailureMessage(arg0, arg1);
  848.                 llLoading.setVisibility(View.GONE);
  849.                 llError.setVisibility(View.VISIBLE);
  850.             }
  851.  
  852.         });
  853.     }
  854.    
  855.     private void loadingThethao() {
  856.         try {
  857.  
  858.             //init group and child
  859.             groupList = new ArrayList<obj1ListTheThao>();
  860.             thethaoCollection = new LinkedHashMap<obj1ListTheThao, ArrayList<obj1Thethao>>();
  861.             groupList = myUtil.getListTheThao(myData1.getDataTheThao());
  862.            
  863.             for(obj1ListTheThao obj: groupList){
  864.                 thethaoCollection.put(obj, obj.listChiTiet);
  865.             }
  866.            
  867.            
  868.             final ExpandableListTheThaoAdapter expListAdapter = new ExpandableListTheThaoAdapter(
  869.                     MainFragment.this, groupList, thethaoCollection);
  870.             expListViewTheThao.setAdapter(expListAdapter);
  871.             expListViewTheThao.setOnChildClickListener(new OnChildClickListener() {
  872.                  
  873.                 public boolean onChildClick(ExpandableListView parent, View v,
  874.                         int groupPosition, int childPosition, long id) {
  875.                     final obj1Thethao FCitem = (obj1Thethao) expListAdapter.getChild(
  876.                             groupPosition, childPosition);
  877.                     // check to show tivi
  878.                     long current = MyUtil.createCurrentTimeStamp();
  879.                     MyLog.E("time>>>" + MyUtil.createTimeStamp());
  880.                     try {
  881.                         if (listAllTiviK != null) {
  882.                             obj1TiviK objNew = new obj1TiviK();
  883.                             for (obj1TiviK obj : listAllTiviK) {
  884.                                 if (obj.channelId
  885.                                         .contentEquals(FCitem.List_tvchannel_id))
  886.                                     objNew = obj;
  887.                             }
  888.                             if (objNew != null)
  889.                                 playTivi(objNew);
  890.                         }
  891.                     } catch (Exception e) {
  892.                         // TODO: handle exception
  893.  
  894.                     }
  895.  
  896.                     return true;
  897.                 }
  898.             });
  899.             // MyLog.E(">>>>size trang chu"+ arrTrangChu.size());
  900.         } catch (Exception e) {
  901.             // TODO: handle exception
  902.             e.printStackTrace();
  903.             // MyLog.E(">>>>EEEEERRRRR");
  904.         }
  905.     }
  906.  
  907.     //live score
  908.  
  909.     private void getAllScore(obj1CateNo objcate) throws Exception {
  910.         View viewLoading = (View) view.findViewById(R.id.llLiveScore);
  911.         final View llError = (View) viewLoading
  912.                 .findViewById(R.id.loading_error);
  913.         final View llLoading = (View) viewLoading
  914.                 .findViewById(R.id.loading_layout);
  915.  
  916.         llError.setVisibility(View.GONE);
  917.         llLoading.setVisibility(View.GONE);
  918.  
  919.         AsyncHttpClient client = new AsyncHttpClient();
  920.         String url = String.valueOf(objcate.description) ;
  921.         client.get(url, new AsyncHttpResponseHandler() {
  922.  
  923.             @Override
  924.             public void onStart() {
  925.                 // TODO Auto-generated method stub
  926.                 super.onStart();
  927.                 mLoadWebview.setVisibility(View.VISIBLE);
  928.                 if (!myUtil.isInternet(getActivity()))
  929.                     llError.setVisibility(View.VISIBLE);
  930.                 else
  931.                     llLoading.setVisibility(View.VISIBLE);
  932.             }
  933.  
  934.             @Override
  935.             public void onSuccess(int arg0, String arg1) {
  936.                 // TODO Auto-generated method stub
  937.                 super.onSuccess(arg0, arg1);
  938.                 llLoading.setVisibility(View.GONE);
  939.                 mLoadWebview.setVisibility(View.GONE);
  940.                 MyLog.E("live score>>>" + arg1);
  941.                 isLoadedScore = true;
  942.                 myData1.saveDataLiveScore(arg1);
  943.                 loadingLiveScore();
  944.             }
  945.  
  946.             @Override
  947.             protected void sendFailureMessage(Throwable arg0, String arg1) {
  948.                 // TODO Auto-generated method stub
  949.                 super.sendFailureMessage(arg0, arg1);
  950.                 llLoading.setVisibility(View.GONE);
  951.                 llError.setVisibility(View.VISIBLE);
  952.             }
  953.  
  954.         });
  955.     }
  956.    
  957.     private void loadingLiveScore() {
  958.         try {
  959.            
  960.            
  961.             arrLiveScore = new ArrayList<obj1ListLiveScore>();
  962.             liveScoreCollection = new LinkedHashMap<obj1ListLiveScore, ArrayList<obj1TranDau>>();
  963.             arrLiveScore = myUtil.getLiveScore(myData1.getDataLiveScore());
  964.            
  965.             for(obj1ListLiveScore obj: arrLiveScore){
  966.                 liveScoreCollection.put(obj, obj.listTranDau);
  967.             }
  968.            
  969.             final ExpandableListLiveScoreAdapter expListAdapter = new ExpandableListLiveScoreAdapter(
  970.                     MainFragment.this, arrLiveScore, liveScoreCollection);
  971.             lvLiveScore.setAdapter(expListAdapter);
  972.             lvLiveScore.setOnChildClickListener(new OnChildClickListener() {
  973.                
  974.                 @Override
  975.                 public boolean onChildClick(ExpandableListView parent, View v,
  976.                         int groupPosition, int childPosition, long id) {
  977.                     // TODO Auto-generated method stub
  978.                       final obj1TranDau obj = (obj1TranDau) expListAdapter.getChild(
  979.                                 groupPosition, childPosition);
  980.                    
  981.                         Intent i = new Intent(getActivity(), DetailLiveScore.class);
  982.                         i.putExtra("TranDauID", obj.TranDauID);
  983.                         i.putExtra("BanThangDoiBong1", obj.BanThangDoiBong1);
  984.                         i.putExtra("BanThangDoiBong2", obj.BanThangDoiBong2);
  985.                         i.putExtra("DoiBong1Full_Icon", obj.DoiBong1Full_Icon);
  986.                         i.putExtra("DoiBong2Full_Icon", obj.DoiBong2Full_Icon);
  987.                         i.putExtra("DoiBong1Full_TenDoiBong", obj.DoiBong1Full_TenDoiBong);
  988.                         i.putExtra("DoiBong2Full_TenDoiBong", obj.DoiBong2Full_TenDoiBong);                
  989.                         getActivity().startActivity(i);
  990.                     return false;
  991.                 }
  992.             });
  993.            
  994. //          arrLiveScore = new ArrayList<obj1TranDau>();
  995. //          arrLiveScore = myUtil.getLiveScore(myData1.getDataLiveScore());
  996. //          adapter1LiveScore adapter = new adapter1LiveScore(MainFragment.this, R.layout.item_1livescore, arrLiveScore);
  997. //          lvLiveScore.setAdapter(adapter);
  998.                        
  999. //          lvLiveScore.setOnItemClickListener(new OnItemClickListener() {
  1000. //
  1001. //              @Override
  1002. //              public void onItemClick(AdapterView<?> parent, View arg1,
  1003. //                      int position, long arg3) {
  1004. //                  // TODO Auto-generated method stub
  1005. //                  obj1TranDau obj = (obj1TranDau) parent.getAdapter().getItem(position);
  1006. //                  Intent i = new Intent(getActivity(), DetailLiveScore.class);
  1007. //                  i.putExtra("TranDauID", obj.TranDauID);
  1008. //                  i.putExtra("BanThangDoiBong1", obj.BanThangDoiBong1);
  1009. //                  i.putExtra("BanThangDoiBong2", obj.BanThangDoiBong2);
  1010. //                  i.putExtra("DoiBong1Full_Icon", obj.DoiBong1Full_Icon);
  1011. //                  i.putExtra("DoiBong2Full_Icon", obj.DoiBong2Full_Icon);
  1012. //                  i.putExtra("DoiBong1Full_TenDoiBong", obj.DoiBong1Full_TenDoiBong);
  1013. //                  i.putExtra("DoiBong2Full_TenDoiBong", obj.DoiBong2Full_TenDoiBong);                
  1014. //                  getActivity().startActivity(i);
  1015. //                 
  1016. //              }
  1017. //          });
  1018.        
  1019.             // MyLog.E(">>>>size trang chu"+ arrTrangChu.size());
  1020.         } catch (Exception e) {
  1021.             // TODO: handle exception
  1022.             e.printStackTrace();
  1023.             // MyLog.E(">>>>EEEEERRRRR");
  1024.         }
  1025.     }
  1026.  
  1027.    
  1028.     @Override
  1029.     public void onDestroy() {
  1030.         // TODO Auto-generated method stub
  1031.         super.onDestroy();
  1032.         myData.close();
  1033.     }
  1034.  
  1035.     // start app
  1036.     private StartAppAd startAppAd;
  1037.  
  1038.      private void iniStartApp() {
  1039.      //if (MyUtil.isShowAds) {
  1040.     // StartAppSearch.init(getActivity());
  1041.      startAppAd = new StartAppAd(getActivity());
  1042.      //}
  1043.      }
  1044.  
  1045.     @Override
  1046.     public void onResume() {
  1047.         super.onResume();
  1048.         // if (MyUtil.isShowAds)
  1049.         // startAppAd.onResume();
  1050.         AdIDManager.addtoParent(adview);
  1051.         // adBuddiz.onStart(getActivity());
  1052.     }
  1053.  
  1054.    
  1055.      private InterstitialAd interstitialAd;
  1056.         //  private final static String interstitialKey = "ca-app-pub-9820030150756925/5059024695";//"b99ec229ebcc49ea";
  1057.          
  1058.        
  1059.           private void requestAds() {
  1060.            interstitialAd.loadAd(new AdRequest.Builder().build());
  1061.           }
  1062.          
  1063.           private void initInterstitialAds(){
  1064.            interstitialAd = new InterstitialAd(getActivity());
  1065.            interstitialAd.setAdUnitId(MyConstans.ADDMOD_POPUP_ID);
  1066.            interstitialAd.setAdListener(new AdIDListener(getActivity()){
  1067.  
  1068.             public void onAdLoaded() {
  1069.              // TODO Auto-generated method stub
  1070.              super.onAdLoaded();
  1071.              Log.e("interstitialAd",
  1072.                "onAdLoaded");
  1073.             }
  1074.  
  1075.             @Override
  1076.             public void onAdFailedToLoad(int errorCode) {
  1077.              // TODO Auto-generated method stub
  1078.              super.onAdFailedToLoad(errorCode);
  1079.              requestAds();
  1080.              Log.e("interstitialAd",
  1081.                "onAdFailedToLoad");
  1082.             }
  1083.  
  1084.             @Override
  1085.             public void onAdOpened() {
  1086.              // TODO Auto-generated method stub
  1087.              super.onAdOpened();
  1088.              Log.e("interstitialAd",
  1089.                "onAdOpened");
  1090.             }
  1091.  
  1092.             @Override
  1093.             public void onAdClosed() {
  1094.              // TODO Auto-generated method stub
  1095.              super.onAdClosed();
  1096.              requestAds();
  1097.              //showHighscore();
  1098.              Log.e("interstitialAd",
  1099.                "onAdClosed");
  1100.             }
  1101.  
  1102.             @Override
  1103.             public void onAdLeftApplication() {
  1104.              // TODO Auto-generated method stub
  1105.              super.onAdLeftApplication();
  1106.              Log.e("interstitialAd",
  1107.                "onAdLeftApplication");
  1108.             }
  1109.            
  1110.            
  1111.            });
  1112.               requestAds();
  1113.           }
  1114.          
  1115.           private void showInterstitialAd() {
  1116.              if (interstitialAd.isLoaded()) {
  1117.                   Log.e("Menu","Menu");
  1118.               interstitialAd.show();
  1119.                   }else{
  1120.                    Log.e("interstitialAd",
  1121.                "Interstitial ad was not ready to be shown.");
  1122.              //showHighscore();
  1123.                   }
  1124.           }
  1125.  
  1126.  
  1127.     private void showAdmob(boolean ishow) {
  1128.         adview.setVisibility(View.VISIBLE);
  1129.     }
  1130. }
Advertisement
Add Comment
Please, Sign In to add comment