thieumao

Get Youtube

Apr 16th, 2015
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 23.41 KB | None | 0 0
  1. package com.fastestvideotube.funnyclip.utils;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileInputStream;
  6. import java.io.FileOutputStream;
  7. import java.io.IOException;
  8. import java.io.InputStream;
  9. import java.io.InputStreamReader;
  10. import java.io.OutputStreamWriter;
  11. import java.security.MessageDigest;
  12. import java.security.NoSuchAlgorithmException;
  13. import java.util.ArrayList;
  14. import org.apache.http.HttpResponse;
  15. import org.apache.http.client.methods.HttpGet;
  16. import org.apache.http.impl.client.DefaultHttpClient;
  17. import org.json.JSONArray;
  18. import org.json.JSONException;
  19. import org.json.JSONObject;
  20.  
  21.  
  22. import android.app.Activity;
  23. import android.content.Context;
  24. import android.net.ConnectivityManager;
  25. import android.os.Build;
  26. import android.os.Environment;
  27. import android.os.Handler;
  28. import android.provider.Settings;
  29. import android.provider.Settings.Secure;
  30. import android.telephony.TelephonyManager;
  31. import android.view.View;
  32. import android.view.ViewGroup;
  33. import android.view.View.MeasureSpec;
  34. import android.view.inputmethod.InputMethodManager;
  35. import android.widget.ListAdapter;
  36. import android.widget.ListView;
  37. import android.widget.Toast;
  38.  
  39. public class MyUtil {
  40.  
  41.     Activity mcontext;
  42.  
  43.     public static final boolean isShowAds = true;
  44.  
  45.     public MyUtil(Activity activity) {
  46.  
  47.         this.mcontext = activity;
  48.     }
  49.  
  50.     public void isCloseKeyboard() {
  51.         InputMethodManager inputManager = (InputMethodManager) mcontext
  52.                 .getSystemService(mcontext.INPUT_METHOD_SERVICE);
  53.         inputManager.hideSoftInputFromWindow(mcontext.getCurrentFocus()
  54.                 .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
  55.     }
  56.  
  57.     public boolean isInternet(Context context) {
  58.         ConnectivityManager con_manager = (ConnectivityManager) context
  59.                 .getSystemService(Context.CONNECTIVITY_SERVICE);
  60.         if (con_manager.getActiveNetworkInfo() != null
  61.                 && con_manager.getActiveNetworkInfo().isAvailable()
  62.                 && con_manager.getActiveNetworkInfo().isConnected()) {
  63.             return true;
  64.         } else {
  65.             return false;
  66.         }
  67.     }
  68.  
  69.     public static String[] split(String url, String regular) {
  70.         String str[] = url.split(regular);
  71.         return str;
  72.        
  73.     }
  74.  
  75.      public static String getYoutubeDirectUrl(String paramString)
  76.       {
  77.         try
  78.         {
  79.           String str1 = readStream(retrieveStreamCustom(paramString, "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"));
  80.           String str2 = str1.substring(str1.indexOf("\\\"fmt_stream_map\\\":"));
  81.           String str3 = str2.substring(0, str2.indexOf("\"}]"));
  82.           String str4 = str3.substring(str3.indexOf("http"));
  83.           String str5 = str4.substring(0, str4.indexOf("\"")).replace("%252", "%2").replace("\\u0026", "&").replace("\\", "");
  84.           return str5;
  85.         }
  86.         catch (Exception localException)
  87.         {
  88.          MyLog.E( "Youtube Eror:" + localException.getMessage());
  89.         }
  90.         return "";
  91.       }
  92.      
  93.      public static String getYoutubeRespond(String paramString)
  94.       {
  95.         try
  96.         {
  97.           String str1 = paramString;//readStream(retrieveStreamCustom(paramString, "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"));
  98.           String str2 = str1.substring(str1.indexOf("\\\"fmt_stream_map\\\":"));
  99.           String str3 = str2.substring(0, str2.indexOf("\"}]"));
  100.           String str4 = str3.substring(str3.indexOf("http"));
  101.           String str5 = str4.substring(0, str4.indexOf("\"")).replace("%252", "%2").replace("\\u0026", "&").replace("\\", "");
  102.           return str5;
  103.         }
  104.         catch (Exception localException)
  105.         {
  106.          MyLog.E( "Youtube Eror:" + localException.getMessage());
  107.         }
  108.         return "";
  109.       }
  110.      
  111.      public static InputStream retrieveStreamCustom(String paramString1, String paramString2)
  112.       {
  113.         DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient();
  114.         HttpGet localHttpGet = new HttpGet(paramString1);
  115.         localHttpGet.setHeader("User-Agent", paramString2);
  116.         try
  117.         {
  118.           HttpResponse localHttpResponse = localDefaultHttpClient.execute(localHttpGet);
  119.           int i = localHttpResponse.getStatusLine().getStatusCode();
  120.           if (i != 200)
  121.           {
  122.               MyLog.E("Error " + i + " for URL " + paramString1);
  123.             return null;
  124.           }
  125.           InputStream localInputStream = localHttpResponse.getEntity().getContent();
  126.           return localInputStream;
  127.         }
  128.         catch (IOException localIOException)
  129.         {
  130.           localHttpGet.abort();
  131.           MyLog.E("Error for URL " + paramString1+ localIOException);
  132.         }
  133.         return null;
  134.       }
  135.  
  136.      static String readStream(InputStream paramInputStream)
  137.                 throws IOException
  138.               {
  139.                 InputStreamReader localInputStreamReader = new InputStreamReader(paramInputStream);
  140.                 BufferedReader localBufferedReader = new BufferedReader(localInputStreamReader);
  141.                 StringBuilder localStringBuilder = new StringBuilder();
  142.                 while (true)
  143.                 {
  144.                   String str = localBufferedReader.readLine();
  145.                   if (str == null)
  146.                   {
  147.                     localBufferedReader.close();
  148.                     localInputStreamReader.close();
  149.                     paramInputStream.close();
  150.                     return localStringBuilder.toString();
  151.                   }
  152.                   localStringBuilder.append(str);
  153.                 }
  154.               }
  155.      
  156.     public void setListViewHeightBasedOnChildren(ListView listView) {
  157.         ListAdapter listAdapter = listView.getAdapter();
  158.         if (listAdapter == null) {
  159.             // pre-condition
  160.             return;
  161.         }
  162.  
  163.         int totalHeight = 0;
  164.         int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(),
  165.                 MeasureSpec.AT_MOST);
  166.         for (int i = 0; i < listAdapter.getCount(); i++) {
  167.             View listItem = listAdapter.getView(i, null, listView);
  168.             listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED);
  169.             totalHeight += listItem.getMeasuredHeight();
  170.         }
  171.  
  172.         ViewGroup.LayoutParams params = listView.getLayoutParams();
  173.         params.height = totalHeight
  174.                 + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
  175.         listView.setLayoutParams(params);
  176.         listView.requestLayout();
  177.     }
  178.  
  179.     // public static String initPhotoPager(ArrayList<objHaiVL> photo)
  180.     // throws JSONException, UnsupportedEncodingException {
  181.     // JSONArray jArrayFacebookData = new JSONArray();
  182.     // for (objHaiVL obj : photo) {
  183.     // JSONObject jObjectType = new JSONObject();
  184.     // jObjectType.put("Id", obj.Id);
  185.     // jObjectType.put("Caption", obj.Caption);
  186.     // jObjectType.put("CreatedAt", obj.CreatedAt);
  187.     // jObjectType.put("ImageUrl", obj.ImageUrl);
  188.     // jObjectType.put("ThumbnailUrl", obj.ThumbnailUrl);
  189.     // jObjectType.put("CreatedBy",obj.CreatedBy);
  190.     // jObjectType.put("YoutubeId", obj.YoutubeId);
  191.     // jObjectType.put("Views", obj.Views);
  192.     // jObjectType.put("Likes",obj.Likes);
  193.     // jObjectType.put("Comments",obj.Comments);
  194.     // jObjectType.put("IsVideo", obj.IsVideo);
  195.     //
  196.     // jArrayFacebookData.put(jObjectType);
  197.     // }
  198.     // MyLog.E("tao json Filter>>>>>"
  199.     // + jArrayFacebookData.toString());
  200.     // return jArrayFacebookData.toString();
  201.     // }
  202.  
  203.     // public ArrayList<objCategory> getCategory(String resStr)
  204.     // throws JSONException {
  205.     // ArrayList<objCategory> list = new ArrayList<objCategory>();
  206.     //
  207.     // JSONArray jsonArray = new JSONArray(resStr);
  208.     // if (jsonArray != null) {
  209.     // int size = jsonArray.length();
  210.     // JSONObject obj;
  211.     // for (int i = 0; i < size; i++) {
  212.     // objCategory newfeed = new objCategory();
  213.     // obj = (JSONObject) jsonArray.get(i);
  214.     // if (obj != null) {
  215.     // newfeed.id = obj.getString("id");
  216.     // newfeed.img = obj.getString("img");
  217.     // newfeed.name = obj.getString("name");
  218.     // }
  219.     // list.add(newfeed);
  220.     // }
  221.     // return list;
  222.     // } else
  223.     // return null;
  224.     // }
  225.     //
  226.     // public ArrayList<objVideo> getVideo(String resStr)
  227.     // throws JSONException {
  228.     // ArrayList<objVideo> list = new ArrayList<objVideo>();
  229.     //
  230.     // JSONArray jsonArray = new JSONArray(resStr);
  231.     // if (jsonArray != null) {
  232.     // int size = jsonArray.length();
  233.     // JSONObject obj;
  234.     // for (int i = 0; i < size; i++) {
  235.     // objVideo newfeed = new objVideo();
  236.     // obj = (JSONObject) jsonArray.get(i);
  237.     // if (obj != null) {
  238.     // newfeed.id = obj.getString("id");
  239.     // newfeed.duration = obj.getString("duration");
  240.     // newfeed.imgPath = obj.getString("imgPath");
  241.     // newfeed.title = obj.getString("title");
  242.     // newfeed.v = obj.getString("v");
  243.     // newfeed.videoType = obj.getString("videoType");
  244.     // }
  245.     // list.add(newfeed);
  246.     // }
  247.     // return list;
  248.     // } else
  249.     // return null;
  250.     // }
  251.     //
  252.     // public ArrayList<objVideoDetail> getVideoDetail(String resStr)
  253.     // throws JSONException {
  254.     // ArrayList<objVideoDetail> list = new ArrayList<objVideoDetail>();
  255.     //
  256.     // JSONArray jsonArray = new JSONArray(resStr);
  257.     // if (jsonArray != null) {
  258.     // int size = jsonArray.length();
  259.     // JSONObject obj;
  260.     // for (int i = 0; i < size; i++) {
  261.     // objVideoDetail newfeed = new objVideoDetail();
  262.     // obj = (JSONObject) jsonArray.get(i);
  263.     // if (obj != null) {
  264.     // newfeed.id = obj.getString("id");
  265.     // newfeed.duration = obj.getString("duration");
  266.     // newfeed.imgPath = obj.getString("imgPath");
  267.     // newfeed.title = obj.getString("title");
  268.     // newfeed.v = obj.getString("v");
  269.     // newfeed.videoType = obj.getString("videoType");
  270.     // newfeed.channelId = obj.getString("channelId");
  271.     // newfeed.channelImgPath = obj.getString("channelImgPath");
  272.     // newfeed.channelName = obj.getString("channelName");
  273.     // newfeed.createDate = obj.getString("createDate");
  274.     // newfeed.description = obj.getString("description");
  275.     // newfeed.videCount = obj.getString("videCount");
  276.     //
  277.     // }
  278.     // list.add(newfeed);
  279.     // }
  280.     // return list;
  281.     // } else
  282.     // return null;
  283.     // }
  284.     //
  285.     // public ArrayList<objVideoRelate> getVideoRelate(String resStr)
  286.     // throws JSONException {
  287.     // ArrayList<objVideoRelate> list = new ArrayList<objVideoRelate>();
  288.     //
  289.     // JSONArray jsonArray = new JSONArray(resStr);
  290.     // if (jsonArray != null) {
  291.     // int size = jsonArray.length();
  292.     // JSONObject obj;
  293.     // for (int i = 0; i < size; i++) {
  294.     // objVideoRelate newfeed = new objVideoRelate();
  295.     // obj = (JSONObject) jsonArray.get(i);
  296.     // if (obj != null) {
  297.     // newfeed.id = obj.getString("id");
  298.     // newfeed.duration = obj.getString("duration");
  299.     // newfeed.imgPath = obj.getString("imgPath");
  300.     // newfeed.title = obj.getString("title");
  301.     // newfeed.v = obj.getString("v");
  302.     // newfeed.videoType = obj.getString("videoType");
  303.     // newfeed.createdDate = obj.getString("createdDate");
  304.     // newfeed.viewCount = obj.getString("viewCount");
  305.     // }
  306.     // list.add(newfeed);
  307.     // }
  308.     // return list;
  309.     // } else
  310.     // return null;
  311.     // }
  312.  
  313.     // public ArrayList<objCategoryPhim> getCategory(String resStr)
  314.     // throws JSONException {
  315.     // ArrayList<objCategoryPhim> list = new ArrayList<objCategoryPhim>();
  316.     //
  317.     // JSONObject jsonObject = new JSONObject(resStr);
  318.     // JSONArray jsonArray = jsonObject.getJSONArray("result");
  319.     // if (jsonArray != null) {
  320.     // int size = jsonArray.length();
  321.     // JSONObject obj;
  322.     // for (int i = 0; i < size; i++) {
  323.     // objCategoryPhim newfeed = new objCategoryPhim();
  324.     // obj = (JSONObject) jsonArray.get(i);
  325.     // if (obj != null) {
  326.     // newfeed.id = obj.getString("id");
  327.     // newfeed.title = obj.getString("img");
  328.     // newfeed.type = obj.getString("name");
  329.     // newfeed.url = obj.getString("url");
  330.     // }
  331.     // list.add(newfeed);
  332.     // }
  333.     // return list;
  334.     // } else
  335.     // return null;
  336.     // }
  337.  
  338.     // public ArrayList<objCategoryPhim> getCategory1(String resStr)
  339.     // throws JSONException {
  340.     // ArrayList<objCategoryPhim> list = new ArrayList<objCategoryPhim>();
  341.     // JSONObject object = new JSONObject(resStr.toString());
  342.     // JSONArray jsonArray = object.getJSONArray("result");
  343.     // if (jsonArray != null) {
  344.     // int size = jsonArray.length();
  345.     // JSONObject obj;
  346.     // for (int i = 0; i < size; i++) {
  347.     // objCategoryPhim newfeed = new objCategoryPhim();
  348.     // obj = (JSONObject) jsonArray.get(i);
  349.     // if (obj != null) {
  350.     // newfeed.id = obj.getString("id");
  351.     // newfeed.title = obj.getString("title");
  352.     // newfeed.type = obj.getString("type");
  353.     // newfeed.url = obj.getString("url");
  354.     // }
  355.     // list.add(newfeed);
  356.     // }
  357.     // return list;
  358.     // } else
  359.     // return null;
  360.     // }
  361.  
  362.     // public ArrayList<objCategoryPhim> getCategory2(String resStr)
  363.     // throws JSONException {
  364.     // ArrayList<objCategoryPhim> list = new ArrayList<objCategoryPhim>();
  365.     //
  366.     // JSONArray jsonArray = new JSONArray(resStr);
  367.     // if (jsonArray != null) {
  368.     // int size = jsonArray.length();
  369.     // JSONObject obj;
  370.     // for (int i = 0; i < size; i++) {
  371.     // objCategoryPhim newfeed = new objCategoryPhim();
  372.     // obj = (JSONObject) jsonArray.get(i);
  373.     // if (obj != null) {
  374.     // newfeed.id = obj.getString("id");
  375.     // newfeed.title = obj.getString("title");
  376.     // newfeed.type = obj.getString("type");
  377.     // newfeed.url = obj.getString("url");
  378.     // }
  379.     // list.add(newfeed);
  380.     // }
  381.     // return list;
  382.     // } else
  383.     // return null;
  384.     // }
  385.  
  386. //  public ArrayList<objTrangChu> getListTrangChu(String resStr)
  387. //          throws JSONException {
  388. //      ArrayList<objTrangChu> list = new ArrayList<objTrangChu>();
  389. //
  390. //      JSONObject objobject = new JSONObject(resStr);
  391. //      JSONArray jsonArray = objobject.getJSONArray("payload");
  392. //      if (jsonArray != null) {
  393. //          int size = jsonArray.length();
  394. //          JSONObject objTrChu;
  395. //          for (int i = 0; i < size; i++) {
  396. //              objTrangChu newTrangChu = new objTrangChu();
  397. //              ArrayList<objListPhim> listPhim = new ArrayList<objListPhim>();
  398. //              objTrChu = (JSONObject) jsonArray.get(i);
  399. //              if (objTrChu != null) {
  400. //                  newTrangChu.label = objTrChu.getString("label").replace(
  401. //                          "SS", "");
  402. //                  newTrangChu.ref = objTrChu.getString("ref");
  403. //                  // MyLog.E("JSON>>>" + newTrangChu.label );
  404. //                  JSONArray jsonArrayPhim = objTrChu.getJSONArray("film");
  405. //                  if (jsonArrayPhim != null) {
  406. //                      int size1 = jsonArrayPhim.length();
  407. //                      JSONObject obj;
  408. //                      for (int j = 0; j < size1; j++) {
  409. //                          objListPhim newfeed = new objListPhim();
  410. //                          obj = (JSONObject) jsonArrayPhim.get(j);
  411. //                          if (obj != null) {
  412. //
  413. //                              newfeed.id = obj.getString("id");
  414. //                              // MyLog.E("JSON>>>id" + newfeed.id );
  415. //                              newfeed.category = obj.getString("category");
  416. //                              newfeed.daodien = obj.getString("daodien");
  417. //                              newfeed.diemimdb = obj.getString("diemimdb");
  418. //                              newfeed.dienvienchinh = obj
  419. //                                      .getString("dienvienchinh");
  420. //                              newfeed.filmURL = obj.getString("filmURL");
  421. //                              newfeed.hinhanh = obj.getString("hinhanh");
  422. //                              newfeed.imgFullURL = obj
  423. //                                      .getString("imgFullURL");
  424. //                              newfeed.imgThumbURL = obj
  425. //                                      .getString("imgThumbURL");
  426. //                              newfeed.kichban = obj.getString("kichban");
  427. //                              newfeed.name = obj.getString("name");
  428. //                              newfeed.ngayphathanh = obj
  429. //                                      .getString("ngayphathanh");
  430. //                              newfeed.phude = obj.getString("phude");
  431. //                              newfeed.quocgia = obj.getString("quocgia");
  432. //                              newfeed.theloai = obj.getString("theloai");
  433. //                              newfeed.thoiluong = obj.getString("thoiluong");
  434. //                              newfeed.views = obj.getString("views");
  435. //                              listPhim.add(newfeed);
  436. //                          }
  437. //                      }
  438. //                      newTrangChu.listPhim = listPhim;
  439. //                  }
  440. //                  list.add(newTrangChu);
  441. //              }
  442. //
  443. //          }
  444. //          return list;
  445. //      } else
  446. //          return null;
  447. //  }
  448.  
  449. //  public ArrayList<objListPhim> getListPhim(String resStr)
  450. //          throws JSONException {
  451. //      ArrayList<objListPhim> list = new ArrayList<objListPhim>();
  452. //
  453. ////        JSONObject objobject = new JSONObject(resStr);
  454. ////        JSONArray jsonArray = objobject.getJSONArray("payload");
  455. //      JSONArray jsonArray = new JSONArray(resStr);
  456. //      if (jsonArray != null) {
  457. //          int size = jsonArray.length();
  458. //          JSONObject obj;
  459. //          for (int i = 0; i < size; i++) {
  460. //              objListPhim newfeed = new objListPhim();
  461. //              obj = (JSONObject) jsonArray.get(i);
  462. //              if (obj != null) {
  463. //                  newfeed.VideoId = obj.getString("VideoId");
  464. //                  newfeed.Title = obj.getString("Title");
  465. //                  newfeed.Description = obj.getString("Description");
  466. //                  newfeed.PhotoUrl = obj.getString("PhotoUrl");
  467. //                  newfeed.Director = obj.getString("Director");
  468. //                  newfeed.Year = obj.getString("Year");
  469. //                  newfeed.Length = obj.getString("Length");
  470. //                  newfeed.Actor = obj.getString("Actor");
  471. //                  newfeed.Chapters = obj.getString("Chapters");
  472. //                  newfeed.DetailUrl = obj.getString("DetailUrl");
  473. //                  newfeed.TypeID = obj.getString("TypeID");
  474. //                  newfeed.ViewNumbers = obj.getString("ViewNumbers");
  475. ////                    newfeed.phude = obj.getString("Sort");
  476. //                  newfeed.VideoUrl = obj.getString("VideoUrl");
  477. //                  newfeed.IsCancelDownload = obj.getString("IsCancelDownload");
  478. //                  newfeed.SubTitle = obj.getString("SubTitle");
  479. //                  //Active
  480. //                  //Note
  481. //              }
  482. //              list.add(newfeed);
  483. //          }
  484. //          return list;
  485. //      } else
  486. //          return null;
  487. //  }
  488.    
  489. //  public ArrayList<objListPhim> getListPhim(String resStr)
  490. //          throws JSONException {
  491. //      ArrayList<objListPhim> list = new ArrayList<objListPhim>();
  492. //
  493. //      JSONObject objobject = new JSONObject(resStr);
  494. //      JSONArray jsonArray = objobject.getJSONArray("payload");
  495. //      if (jsonArray != null) {
  496. //          int size = jsonArray.length();
  497. //          JSONObject obj;
  498. //          for (int i = 0; i < size; i++) {
  499. //              objListPhim newfeed = new objListPhim();
  500. //              obj = (JSONObject) jsonArray.get(i);
  501. //              if (obj != null) {
  502. //                  newfeed.id = obj.getString("id");
  503. //                  newfeed.category = obj.getString("category");
  504. //                  newfeed.daodien = obj.getString("daodien");
  505. //                  newfeed.diemimdb = obj.getString("diemimdb");
  506. //                  newfeed.dienvienchinh = obj.getString("dienvienchinh");
  507. //                  newfeed.filmURL = obj.getString("filmURL");
  508. //                  newfeed.hinhanh = obj.getString("hinhanh");
  509. //                  newfeed.imgFullURL = obj.getString("imgFullURL");
  510. //                  newfeed.imgThumbURL = obj.getString("imgThumbURL");
  511. //                  newfeed.kichban = obj.getString("kichban");
  512. //                  newfeed.name = obj.getString("name");
  513. //                  newfeed.ngayphathanh = obj.getString("ngayphathanh");
  514. //                  newfeed.phude = obj.getString("phude");
  515. //                  newfeed.quocgia = obj.getString("quocgia");
  516. //                  newfeed.theloai = obj.getString("theloai");
  517. //                  newfeed.thoiluong = obj.getString("thoiluong");
  518. //                  newfeed.views = obj.getString("views");
  519. //              }
  520. //              list.add(newfeed);
  521. //          }
  522. //          return list;
  523. //      } else
  524. //          return null;
  525. //  }
  526.  
  527. //  public objDetailPhim getDetailPhim(String resStr) throws JSONException {
  528. //      objDetailPhim newfeed = new objDetailPhim();
  529. //      JSONObject objPayload = new JSONObject(resStr);
  530. //      if (objPayload != null) {
  531. //          JSONObject objTotal = objPayload.getJSONObject("payload");
  532. //          if (objTotal != null) {
  533. //              JSONObject obj = objTotal.getJSONObject("info");
  534. //              // JSONArray objRelative = objTotal.getJSONArray("relative");
  535. //              if (obj != null) {
  536. //                  newfeed.category = obj.getString("category");
  537. //                  newfeed.daodien = obj.getString("daodien");
  538. //                  newfeed.diemimdb = obj.getString("diemimdb");
  539. //                  newfeed.dienvienchinh = obj.getString("dienvienchinh");
  540. //                  newfeed.filmDesc = obj.getString("filmDesc");
  541. //                  newfeed.hinhanh = obj.getString("hinhanh");
  542. //                  newfeed.id = obj.getString("id");
  543. //                  newfeed.imgFullURL = obj.getString("imgFullURL");
  544. //                  newfeed.kichban = obj.getString("kichban");
  545. //                  newfeed.name = obj.getString("name");
  546. //                  newfeed.ngayphathanh = obj.getString("ngayphathanh");
  547. //                  newfeed.phude = obj.getString("phude");
  548. //                  newfeed.quocgia = obj.getString("quocgia");
  549. //                  newfeed.suburi = obj.getString("suburi");
  550. //                  newfeed.theloai = obj.getString("theloai");
  551. //                  newfeed.thoiluong = obj.getString("thoiluong");
  552. //                  newfeed.uri = obj.getString("uri");
  553. //                  newfeed.views = obj.getString("views");
  554. //
  555. //                  return newfeed;
  556. //              } else
  557. //                  return null;
  558. //          } else
  559. //              return null;
  560. //      }
  561. //
  562. //      else
  563. //          return null;
  564. //  }
  565.  
  566.     public String saveSubToSdCard(final Context mContext, final String content,
  567.             final String nameSub) {
  568.         String pathSub = "-1";
  569.         // new Handler().postDelayed(new Runnable() {
  570.         //
  571.         // @Override
  572.         // public void run() {
  573.         // // TODO Auto-generated method stub
  574.  
  575.         try {
  576.             // MyLog.E("MediaType>>>>>" + content + ">>>>");
  577.             File wallpaperDirectory;// = new
  578.                                     // File(Environment.getExternalStorageDirectory().getAbsolutePath()+
  579.                                     // "/JQK_PHOTO/");
  580.  
  581.             Boolean isSDPresent = android.os.Environment
  582.                     .getExternalStorageState().equals(
  583.                             android.os.Environment.MEDIA_MOUNTED);
  584.             if (isSDPresent) {
  585.                 wallpaperDirectory = new File(Environment
  586.                         .getExternalStorageDirectory().getAbsolutePath()
  587.                         + "/SPHIM/");
  588.             } else {
  589.                 File mydir = mContext.getDir("SPHIM", Context.MODE_PRIVATE);
  590.                 wallpaperDirectory = new File(mydir, "");
  591.             }
  592.  
  593.             wallpaperDirectory.mkdirs();
  594.             String file = wallpaperDirectory.getPath() + "/" + "subviet"
  595.                     + nameSub.hashCode() + ".srt";
  596.             MyLog.E(file.toString() + ">>>file save");
  597.  
  598.             File testImageOnSdCard = new File(file);
  599.             FileOutputStream fos = new FileOutputStream(testImageOnSdCard);
  600.             // OutputStreamWriter osw = new OutputStreamWriter(fos,"UTF-16");
  601.             OutputStreamWriter osw = new OutputStreamWriter(fos);
  602.             // ---write the string to the file---
  603.             osw.write(content);
  604.             osw.flush();
  605.             osw.close();
  606.  
  607.             pathSub = file.toString();
  608.             // ---display file saved message---
  609.             // Toast.makeText(mContext, "Load sub successfully!",
  610.             // Toast.LENGTH_SHORT).show();
  611.  
  612.         } catch (IOException e) {
  613.             MyLog.E("Can't copy test image onto SD card");
  614.             pathSub = "-1";
  615.         }
  616.         //
  617.         // }
  618.         // }, 100);
  619.  
  620.         return pathSub;
  621.     }
  622.  
  623.     // MD5 string
  624.     public  char[] hextable = { '0', '1', '2', '3', '4', '5', '6', '7',
  625.             '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
  626.  
  627.     // public static Boolean done;
  628.     public  String md5(String s) {
  629.         MessageDigest digest;
  630.         try {
  631.             digest = MessageDigest.getInstance("MD5");
  632.             digest.update(s.getBytes(), 0, s.length());
  633.             byte[] bytes = digest.digest();
  634.  
  635.             String hash = "";
  636.             for (int i = 0; i < bytes.length; ++i) {
  637.                 int di = (bytes[i] + 256) & 0xFF;
  638.                 hash = hash + hextable[(di >> 4) & 0xF] + hextable[di & 0xF];
  639.             }
  640.  
  641.             return hash;
  642.         } catch (NoSuchAlgorithmException e) {
  643.         }
  644.  
  645.         return "";
  646.     }
  647.  
  648.     public  String getDeviceId(Context paramContext) {
  649.         String str;
  650.         str = Secure.getString(paramContext.getContentResolver(),
  651.                 Secure.ANDROID_ID);
  652.         // TelephonyManager TelephonyMgr = (TelephonyManager)
  653.         // paramContext.getSystemService(paramContext.TELEPHONY_SERVICE);
  654.         // DEVICE_ID = TelephonyMgr.getDeviceId();
  655.         if ("9774d56d682e549c".equals(str))
  656.             str = ((TelephonyManager) paramContext.getSystemService("phone"))
  657.                     .getDeviceId();
  658.         if (str == null)
  659.             str = (Build.VERSION.RELEASE + "_" + Build.MANUFACTURER)
  660.                     .replaceAll("[ \\?&=]", "");
  661.         return str;
  662.     }
  663.  
  664. //  public static String getAuthParam(Context paramContext) {
  665. //      Object[] arrayOfObject = new Object[3];
  666. //      arrayOfObject[0] = paramContext.getString(2131492878);
  667. //      arrayOfObject[1] = getDeviceId(paramContext);
  668. //      arrayOfObject[2] = getToken(paramContext);
  669. //      return String.format("os=%s&clid=%s&t=%s", arrayOfObject);
  670. //  }
  671.  
  672.     public  String getToken(Context paramContext) {
  673.         String str;
  674.         String os = "a";
  675.         char key[] = { 'r', 'c', 's', 's' };
  676.         String device = getDeviceId(paramContext);
  677.         str = md5(String.format("%s_%s_%s", os, String.valueOf(key), device));
  678.         return str;
  679.     }
  680.  
  681.     public  String getToken(Context paramContext, String deviceid) {
  682.         String str;
  683.         String os = "a";
  684.         char key[] = { 'r', 'c', 's', 's' };
  685. //      String device = getDeviceId(paramContext);
  686.         str = md5(String.format("%s_%s_%s", os, String.valueOf(key), deviceid));
  687.         return str;
  688.     }
  689.    
  690.    
  691.    
  692. }
Advertisement
Add Comment
Please, Sign In to add comment