diff --git a/.gitignore b/.gitignore index c6cbe56..4c9e2c6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ -*.iml -.gradle -/local.properties -/.idea/workspace.xml -/.idea/libraries -.DS_Store -/build -/captures +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures diff --git a/TvPlayer/.gitignore b/TvPlayer/.gitignore index da112a3..7f43336 100644 --- a/TvPlayer/.gitignore +++ b/TvPlayer/.gitignore @@ -1,4 +1,4 @@ -/build -*.iml -.idea -/.gradle +/build +*.iml +.idea +/.gradle diff --git a/TvPlayer/build.gradle b/TvPlayer/build.gradle index 5200638..930f66f 100644 --- a/TvPlayer/build.gradle +++ b/TvPlayer/build.gradle @@ -1,56 +1,56 @@ -apply plugin: 'com.android.application' - -android { - compileSdkVersion 24 - buildToolsVersion '26.0.2' - - defaultConfig { - applicationId "com.gxf.liveplay" - minSdkVersion 17 - targetSdkVersion 22 - versionCode 9 - versionName "1.9" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - lintOptions { - checkReleaseBuilds false - // Or, if you prefer, you can continue to checkforerrorsinrelease builds, - // but continue the build even whenerrorsarefound: - abortOnError false - } - sourceSets { - main { - jniLibs.srcDir 'libs' - } - - // Move the tests to tests/java, tests/res, etc... - instrumentTest.setRoot('tests') - - // Move the build types to build-types/ - // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... - // This moves them out of them default location under src//... which would - // conflict with src/ being used by the main source set. - // Adding new build types or product flavors should be accompanied - // by a similar customization. - debug.setRoot('build-types/debug') - release.setRoot('build-types/release') - } -} - -dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':Ijkplayer') - - compile 'com.android.support:appcompat-v7:23.4.0' - compile 'com.android.support:design:23.1.1' - compile 'com.android.support:cardview-v7:23.1.1' - compile 'com.alibaba:fastjson:1.1.62.android' - compile 'com.squareup.okhttp3:okhttp:3.8.1' - compile 'com.android.support.constraint:constraint-layout:1.0.2' - testCompile 'junit:junit:4.12' -} +apply plugin: 'com.android.application' + +android { + compileSdkVersion 24 + buildToolsVersion '26.0.2' + + defaultConfig { + applicationId "com.gxf.liveplay" + minSdkVersion 17 + targetSdkVersion 22 + versionCode 9 + versionName "1.9" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + lintOptions { + checkReleaseBuilds false + // Or, if you prefer, you can continue to checkforerrorsinrelease builds, + // but continue the build even whenerrorsarefound: + abortOnError false + } + sourceSets { + main { + jniLibs.srcDir 'libs' + } + + // Move the tests to tests/java, tests/res, etc... + instrumentTest.setRoot('tests') + + // Move the build types to build-types/ + // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ... + // This moves them out of them default location under src//... which would + // conflict with src/ being used by the main source set. + // Adding new build types or product flavors should be accompanied + // by a similar customization. + debug.setRoot('build-types/debug') + release.setRoot('build-types/release') + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile project(':Ijkplayer') + + compile 'com.android.support:appcompat-v7:23.4.0' + compile 'com.android.support:design:23.1.1' + compile 'com.android.support:cardview-v7:23.1.1' + compile 'com.alibaba:fastjson:1.1.62.android' + compile 'com.squareup.okhttp3:okhttp:3.8.1' + compile 'com.android.support.constraint:constraint-layout:1.0.2' + testCompile 'junit:junit:4.12' +} diff --git a/TvPlayer/proguard-rules.pro b/TvPlayer/proguard-rules.pro index e5362ac..e717afb 100644 --- a/TvPlayer/proguard-rules.pro +++ b/TvPlayer/proguard-rules.pro @@ -1,17 +1,17 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in D:\Studio SDK/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in D:\Studio SDK/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/TvPlayer/src/main/AndroidManifest.xml b/TvPlayer/src/main/AndroidManifest.xml index 11b341b..013f881 100644 --- a/TvPlayer/src/main/AndroidManifest.xml +++ b/TvPlayer/src/main/AndroidManifest.xml @@ -1,55 +1,55 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/BootBroadcastReceiver.java b/TvPlayer/src/main/java/com/gxf/liveplay/BootBroadcastReceiver.java index 076e67e..4485397 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/BootBroadcastReceiver.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/BootBroadcastReceiver.java @@ -1,24 +1,24 @@ -package com.gxf.liveplay; - - -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.util.Log; - -/** - * @Description 功能描述: 该类用来实现该app开机自动运行 - */ -public class BootBroadcastReceiver extends BroadcastReceiver { - - @Override - public void onReceive(Context context, Intent intent) { - - Log.d("XRGPS", "BootReceiver.onReceive: " + intent.getAction()); - //MainActivity就是开机显示的界面 - Intent mBootIntent = new Intent(context, MainActivity.class); - //下面这句话必须加上才能开机自动运行app的界面 - mBootIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(mBootIntent); - } +package com.gxf.liveplay; + + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +/** + * @Description 功能描述: 该类用来实现该app开机自动运行 + */ +public class BootBroadcastReceiver extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + + Log.d("XRGPS", "BootReceiver.onReceive: " + intent.getAction()); + //MainActivity就是开机显示的界面 + Intent mBootIntent = new Intent(context, MainActivity.class); + //下面这句话必须加上才能开机自动运行app的界面 + mBootIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(mBootIntent); + } } \ No newline at end of file diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/DeviceUtils.java b/TvPlayer/src/main/java/com/gxf/liveplay/DeviceUtils.java index 42533af..a171632 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/DeviceUtils.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/DeviceUtils.java @@ -1,172 +1,172 @@ -package com.gxf.liveplay; - -import android.content.Context; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; -import android.util.Log; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.io.StringWriter; -import java.io.Writer; -import java.net.Inet4Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.SocketException; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; - -/** - * Created by gongxufan on 2017/9/7. - */ - -public class DeviceUtils { - private static final String marshmallowMacAddress = "02:00:00:00:00:00"; - private static final String fileAddressMac = "/sys/class/net/wlan0/address"; - - - private static String parseByte(byte b) { - String s = "00" + Integer.toHexString(b) + ":"; - return s.substring(s.length() - 3); - } - - /** - * 获取当前系统连接网络的网卡的mac地址 - * - * @return - */ - public static final String getMac() { - byte[] mac = null; - StringBuffer sb = new StringBuffer(); - try { - Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces(); - while (netInterfaces.hasMoreElements()) { - NetworkInterface ni = netInterfaces.nextElement(); - Enumeration address = ni.getInetAddresses(); - - while (address.hasMoreElements()) { - InetAddress ip = address.nextElement(); - if (ip.isAnyLocalAddress() || !(ip instanceof Inet4Address) || ip.isLoopbackAddress()) - continue; - if (ip.isSiteLocalAddress()) - mac = ni.getHardwareAddress(); - else if (!ip.isLinkLocalAddress()) { - mac = ni.getHardwareAddress(); - break; - } - } - } - } catch (SocketException e) { - e.printStackTrace(); - } - - if (mac != null) { - for (int i = 0; i < mac.length; i++) { - sb.append(parseByte(mac[i])); - } - }else{ - return ""; - } - return sb.substring(0, sb.length() - 1); - } - - public static String getAdresseMAC(Context context) { - WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); - WifiInfo wifiInf = wifiMan.getConnectionInfo(); - - if (wifiInf != null && marshmallowMacAddress.equals(wifiInf.getMacAddress())) { - String result = null; - try { - result = getAdressMacByInterface(); - if (result != null) { - return result; - } else { - result = getAddressMacByFile(wifiMan); - return result; - } - } catch (IOException e) { - Log.e("MobileAccess", "Erreur lecture propriete Adresse MAC"); - } catch (Exception e) { - Log.e("MobileAcces", "Erreur lecture propriete Adresse MAC "); - } - } else { - if (wifiInf != null && wifiInf.getMacAddress() != null) { - return wifiInf.getMacAddress(); - } else { - return ""; - } - } - return marshmallowMacAddress; - } - - private static String getAdressMacByInterface() { - try { - List all = Collections.list(NetworkInterface.getNetworkInterfaces()); - for (NetworkInterface nif : all) { - if (nif.getName().equalsIgnoreCase("wlan0")) { - byte[] macBytes = nif.getHardwareAddress(); - if (macBytes == null) { - return ""; - } - - StringBuilder res1 = new StringBuilder(); - for (byte b : macBytes) { - res1.append(String.format("%02X:", b)); - } - - if (res1.length() > 0) { - res1.deleteCharAt(res1.length() - 1); - } - return res1.toString(); - } - } - - } catch (Exception e) { - Log.e("MobileAcces", "Erreur lecture propriete Adresse MAC "); - } - return null; - } - - private static String getAddressMacByFile(WifiManager wifiMan) throws Exception { - String ret; - int wifiState = wifiMan.getWifiState(); - - wifiMan.setWifiEnabled(true); - File fl = new File(fileAddressMac); - FileInputStream fin = new FileInputStream(fl); - ret = crunchifyGetStringFromStream(fin); - fin.close(); - - boolean enabled = WifiManager.WIFI_STATE_ENABLED == wifiState; - wifiMan.setWifiEnabled(enabled); - return ret; - } - - private static String crunchifyGetStringFromStream(InputStream crunchifyStream) throws IOException { - if (crunchifyStream != null) { - Writer crunchifyWriter = new StringWriter(); - - char[] crunchifyBuffer = new char[2048]; - try { - Reader crunchifyReader = new BufferedReader(new InputStreamReader(crunchifyStream, "UTF-8")); - int counter; - while ((counter = crunchifyReader.read(crunchifyBuffer)) != -1) { - crunchifyWriter.write(crunchifyBuffer, 0, counter); - } - } finally { - crunchifyStream.close(); - } - return crunchifyWriter.toString(); - } else { - return "No Contents"; - } - } - - -} +package com.gxf.liveplay; + +import android.content.Context; +import android.net.wifi.WifiInfo; +import android.net.wifi.WifiManager; +import android.util.Log; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.Reader; +import java.io.StringWriter; +import java.io.Writer; +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; + +/** + * Created by gongxufan on 2017/9/7. + */ + +public class DeviceUtils { + private static final String marshmallowMacAddress = "02:00:00:00:00:00"; + private static final String fileAddressMac = "/sys/class/net/wlan0/address"; + + + private static String parseByte(byte b) { + String s = "00" + Integer.toHexString(b) + ":"; + return s.substring(s.length() - 3); + } + + /** + * 获取当前系统连接网络的网卡的mac地址 + * + * @return + */ + public static final String getMac() { + byte[] mac = null; + StringBuffer sb = new StringBuffer(); + try { + Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces(); + while (netInterfaces.hasMoreElements()) { + NetworkInterface ni = netInterfaces.nextElement(); + Enumeration address = ni.getInetAddresses(); + + while (address.hasMoreElements()) { + InetAddress ip = address.nextElement(); + if (ip.isAnyLocalAddress() || !(ip instanceof Inet4Address) || ip.isLoopbackAddress()) + continue; + if (ip.isSiteLocalAddress()) + mac = ni.getHardwareAddress(); + else if (!ip.isLinkLocalAddress()) { + mac = ni.getHardwareAddress(); + break; + } + } + } + } catch (SocketException e) { + e.printStackTrace(); + } + + if (mac != null) { + for (int i = 0; i < mac.length; i++) { + sb.append(parseByte(mac[i])); + } + }else{ + return ""; + } + return sb.substring(0, sb.length() - 1); + } + + public static String getAdresseMAC(Context context) { + WifiManager wifiMan = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); + WifiInfo wifiInf = wifiMan.getConnectionInfo(); + + if (wifiInf != null && marshmallowMacAddress.equals(wifiInf.getMacAddress())) { + String result = null; + try { + result = getAdressMacByInterface(); + if (result != null) { + return result; + } else { + result = getAddressMacByFile(wifiMan); + return result; + } + } catch (IOException e) { + Log.e("MobileAccess", "Erreur lecture propriete Adresse MAC"); + } catch (Exception e) { + Log.e("MobileAcces", "Erreur lecture propriete Adresse MAC "); + } + } else { + if (wifiInf != null && wifiInf.getMacAddress() != null) { + return wifiInf.getMacAddress(); + } else { + return ""; + } + } + return marshmallowMacAddress; + } + + private static String getAdressMacByInterface() { + try { + List all = Collections.list(NetworkInterface.getNetworkInterfaces()); + for (NetworkInterface nif : all) { + if (nif.getName().equalsIgnoreCase("wlan0")) { + byte[] macBytes = nif.getHardwareAddress(); + if (macBytes == null) { + return ""; + } + + StringBuilder res1 = new StringBuilder(); + for (byte b : macBytes) { + res1.append(String.format("%02X:", b)); + } + + if (res1.length() > 0) { + res1.deleteCharAt(res1.length() - 1); + } + return res1.toString(); + } + } + + } catch (Exception e) { + Log.e("MobileAcces", "Erreur lecture propriete Adresse MAC "); + } + return null; + } + + private static String getAddressMacByFile(WifiManager wifiMan) throws Exception { + String ret; + int wifiState = wifiMan.getWifiState(); + + wifiMan.setWifiEnabled(true); + File fl = new File(fileAddressMac); + FileInputStream fin = new FileInputStream(fl); + ret = crunchifyGetStringFromStream(fin); + fin.close(); + + boolean enabled = WifiManager.WIFI_STATE_ENABLED == wifiState; + wifiMan.setWifiEnabled(enabled); + return ret; + } + + private static String crunchifyGetStringFromStream(InputStream crunchifyStream) throws IOException { + if (crunchifyStream != null) { + Writer crunchifyWriter = new StringWriter(); + + char[] crunchifyBuffer = new char[2048]; + try { + Reader crunchifyReader = new BufferedReader(new InputStreamReader(crunchifyStream, "UTF-8")); + int counter; + while ((counter = crunchifyReader.read(crunchifyBuffer)) != -1) { + crunchifyWriter.write(crunchifyBuffer, 0, counter); + } + } finally { + crunchifyStream.close(); + } + return crunchifyWriter.toString(); + } else { + return "No Contents"; + } + } + + +} diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/HttpUtils.java b/TvPlayer/src/main/java/com/gxf/liveplay/HttpUtils.java index dcf8b94..0288490 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/HttpUtils.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/HttpUtils.java @@ -1,92 +1,92 @@ -package com.gxf.liveplay; - -import android.content.Context; -import android.content.SharedPreferences; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -/** - * Created by gongxufan on 2017/9/5. - */ - -public class HttpUtils { - public static String apiPath = "http://220.248.174.237:3390/api/"; - public static String apiPathLocal = "http://172.17.30.14:8080/api/"; - public static String apiPathOuter = "http://220.248.174.237:3390/api/"; - public static String apkPath = apiPath + "downloadApk"; - - public static String getPlayList(String userName, String password) throws Exception { - OkHttpClient client = new OkHttpClient(); - Request request = new Request.Builder() - .url(apiPath + "getPlayList?userName=" + userName + "&password=" + password) - .build(); - Response response = client.newCall(request).execute(); - String playList = response.body().string(); - return playList; - } - - public static String getOfflinePlayList() { - return "[{\"group\":\"省内频道\",\"list\":[{\"湖南都市\":\"http://220.248.175.231:6610/001/2/ch00000090990000001049/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南经视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001052/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南都市\":\"http://220.248.175.230:6610/001/2/ch00000090990000001049/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南公共\":\"http://220.248.175.230:6610/001/2/ch00000090990000001051/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南电影\":\"http://220.248.175.230:6610/001/2/ch00000090990000001070/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南剧场\":\"http://220.248.175.230:6610/001/2/ch00000090990000001050/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南时尚\":\"http://220.248.175.230:6610/001/2/ch00000090990000001085/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南娱乐\":\"http://220.248.175.230:6610/001/2/ch00000090990000001013/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"金鹰纪实\":\"http://220.248.175.230:6610/001/2/ch00000090990000001057/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"金鹰卡通\":\"http://220.248.175.230:6610/001/2/ch00000090990000001058/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南国际\":\"http://220.248.175.230:6610/001/2/ch00000090990000001044/index.m3u8?virtualDomain=001.live_hls.zte.com\"}]},{\"group\":\"其他频道\",\"list\":[{\"安徽卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001024/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"北京卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001025/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"东方卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001036/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"东南卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001037/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"甘肃卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001109/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"广东卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001042/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"广西卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001045/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"贵州卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001046/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"河北卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001110/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"河南卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001111/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"黑龙江卫\":\"http://220.248.175.230:6610/001/2/ch00000090990000001048/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖北卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001047/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"吉林卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001112/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"江苏卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001055/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"江西卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001056/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"辽宁卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001061/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"旅游卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001062/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"南方卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001118/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"内蒙古卫\":\"http://220.248.175.230:6610/001/2/ch00000090990000001119/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"宁夏卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001120/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"青海卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001121/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"山东卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001065/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"山西卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001123/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"陕西卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001067/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"深圳卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001068/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"四川卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001064/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"天津卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001069/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"西藏卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001129/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"新疆卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001128/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"云南卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001072/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"浙江卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001073/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"重庆卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001033/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"长沙经贸\":\"http://220.248.175.230:6610/001/2/ch00000090990000001034/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"长沙女性\":\"http://220.248.175.230:6610/001/2/ch00000090990000001106/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"长沙新闻\":\"http://220.248.175.230:6610/001/2/ch00000090990000001104/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"长沙政法\":\"http://220.248.175.230:6610/001/2/ch00000090990000001107/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果直播\":\"http://220.248.175.230:6610/001/2/ch00000090990000001140/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果独播\":\"http://220.248.175.230:6610/001/2/ch00000090990000001089/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果儿歌\":\"http://220.248.175.230:6610/001/2/ch00000090990000001096/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果港台\":\"http://220.248.175.230:6610/001/2/ch00000090990000001101/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果古装\":\"http://220.248.175.230:6610/001/2/ch00000090990000001092/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果韩国\":\"http://220.248.175.230:6610/001/2/ch00000090990000001094/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果好莱坞\":\"http://220.248.175.230:6610/001/2/ch00000090990000001091/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果快乐购\":\"http://220.248.175.230:6610/001/2/ch00000090990000001090/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果欧美A\":\"http://220.248.175.230:6610/001/2/ch00000090990000001100/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果欧美B\":\"http://220.248.175.230:6610/001/2/ch00000090990000001108/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果汽车\":\"http://220.248.175.230:6610/001/2/ch00000090990000001095/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果亲子\":\"http://220.248.175.230:6610/001/2/ch00000090990000001086/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果综艺\":\"http://220.248.175.230:6610/001/2/ch00000090990000001088/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果军事\":\"http://220.248.175.230:6610/001/2/ch00000090990000001087/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"卡酷少儿\":\"http://220.248.175.230:6610/001/2/ch00000090990000001059/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CGTN\":\"http://220.248.175.230:6610/001/2/ch00000090990000001032/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CGTN DOCUMENTARY\":\"http://220.248.175.230:6610/001/2/ch00000090990000001026/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CNTV经典电影\":\"http://220.248.175.230:6610/001/2/ch00000090990000001054/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CNTV魅力时尚\":\"http://220.248.175.230:6610/001/2/ch00000090990000001117/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CNTV热播剧场\":\"http://220.248.175.230:6610/001/2/ch00000090990000001063/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"电子体育\":\"http://220.248.175.230:6610/001/2/ch00000090990000001038/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"高尔夫\":\"http://220.248.175.230:6610/001/2/ch00000090990000001043/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"国家卫计\\r\\n\":\"http://220.248.175.230:6610/001/2/ch00000090990000001102/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"快乐垂钓\":\"http://220.248.175.230:6610/001/2/ch00000090990000001060/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"先锋乒羽\":\"http://220.248.175.230:6610/001/2/ch00000090990000001127/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"家庭理财\":\"http://220.248.175.230:6610/001/2/ch00000090990000001114/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"财富天下\":\"http://220.248.175.230:6610/001/2/ch00000090990000001103/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"江苏靓妆\":\"http://220.248.175.230:6610/001/2/ch00000090990000001113/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"快乐宠物\":\"http://220.248.175.230:6610/001/2/ch00000090990000001115/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"快乐购\":\"http://220.248.175.230:6610/001/2/ch00000090990000001116/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"美食天府\":\"http://220.248.175.230:6610/001/2/ch00000090990000001132/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"人物频道\":\"http://220.248.175.230:6610/001/2/ch00000090990000001122/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"四海钓鱼\":\"http://220.248.175.230:6610/001/2/ch00000090990000001066/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"天元围棋\":\"http://220.248.175.230:6610/001/2/ch00000090990000001125/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"休闲棋牌\":\"http://220.248.175.230:6610/001/2/ch00000090990000001134/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"优漫卡通\":\"http://220.248.175.230:6610/001/2/ch00000090990000001071/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"优优宝贝\":\"http://220.248.175.230:6610/001/2/ch00000090990000001131/index.m3u8?virtualDomain=001.live_hls.zte.com\"}]},{\"group\":\"高清频道\",\"list\":[{\"CCTV1综合HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001075/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"北京卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001077/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"东方卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001081/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"黑龙江卫HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001084/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"江苏卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001082/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"山东卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001083/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"深圳卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001078/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"浙江卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001076/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"天津卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001135/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001079/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南经视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001080/index.m3u8?virtualDomain=001.live_hls.zte.com\"}]},{\"group\":\"央视频道\",\"list\":[{\"CCTV1综合\":\"http://220.248.175.230:6610/001/2/ch00000090990000001075/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV2财经\":\"http://220.248.175.230:6610/001/2/ch00000090990000001014/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV3综艺\":\"http://220.248.175.230:6610/001/2/ch00000090990000001023/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV4国际\":\"http://220.248.175.230:6610/001/2/ch00000090990000001015/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV5体育\":\"http://220.248.175.230:6610/001/2/ch00000090990000001016/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV5赛事\":\"http://220.248.175.230:6610/001/2/ch00000090990000001074/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV7农业\":\"http://220.248.175.230:6610/001/2/ch00000090990000001018/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV9记录\":\"http://220.248.175.230:6610/001/2/ch00000090990000001020/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV10科教\":\"http://220.248.175.230:6610/001/2/ch00000090990000001021/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV11戏曲\":\"http://220.248.175.230:6610/001/2/ch00000090990000001027/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV12法制\":\"http://220.248.175.230:6610/001/2/ch00000090990000001028/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV13新闻\":\"http://220.248.175.230:6610/001/2/ch00000090990000001029/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV14少儿\":\"http://220.248.175.230:6610/001/2/ch00000090990000001030/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV15音乐\":\"http://220.248.175.230:6610/001/2/ch00000090990000001031/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV足球\":\"http://220.248.175.230:6610/001/2/ch00000090990000001041/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV证券\":\"http://220.248.175.230:6610/001/2/ch00000090990000001133/index.m3u8?virtualDomain=001.live_hls.zte.com\"}]}]"; - } - - public static Boolean login(String mEmail, String mPassword, Context context) throws Exception { - try { - //获取uuid - SharedPreferences userSettings = context.getSharedPreferences("auth", Context.MODE_PRIVATE); - String uuid = userSettings.getString("uuid", "none"); - if ("none".equals(uuid)) { - SharedPreferences.Editor editor = userSettings.edit(); - uuid = UUID.randomUUID().toString(); - editor.putString("uuid", uuid); - editor.commit(); - } - String mac = DeviceUtils.getAdresseMAC(context); - String eth0 = DeviceUtils.getMac(); - OkHttpClient client = new OkHttpClient(); - Request request = new Request.Builder() - .url(apiPath + "auth?userName=" + mEmail + "&password=" + mPassword + "&mac=" + mac + "ð0=" + eth0 + "&uuid=" + uuid) - .build(); - Response response = client.newCall(request).execute(); - //网络连接错误 - if (response.code() != 200) { - LoginActivity.state = 0; - return false; - } - String result = response.body().string(); - JSONObject jsonObject = (JSONObject) JSON.parse(result); - LoginActivity.state = (Integer) jsonObject.get("result"); - return true; - } catch (Exception e) { - e.printStackTrace(); - LoginActivity.state = 0; - return false; - } - } - - public static Map getVersionInfo() { - Map versionInfo = new HashMap<>(); - try { - OkHttpClient client = new OkHttpClient(); - Request request = new Request.Builder() - .url(apiPath + "getAppVersion").build(); - Response response = client.newCall(request).execute(); - String result = response.body().string(); - JSONObject jsonObject = (JSONObject) JSON.parse(result); - versionInfo.put("version", jsonObject.getString("version")); - versionInfo.put("updateInfo", jsonObject.getString("updateInfo")); - } catch (IOException e) { - e.printStackTrace(); - } - return versionInfo; - } -} +package com.gxf.liveplay; + +import android.content.Context; +import android.content.SharedPreferences; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +/** + * Created by gongxufan on 2017/9/5. + */ + +public class HttpUtils { + public static String apiPath = "http://220.248.174.237:3390/api/"; + public static String apiPathLocal = "http://172.17.30.14:8080/api/"; + public static String apiPathOuter = "http://220.248.174.237:3390/api/"; + public static String apkPath = apiPath + "downloadApk"; + + public static String getPlayList(String userName, String password) throws Exception { + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url(apiPath + "getPlayList?userName=" + userName + "&password=" + password) + .build(); + Response response = client.newCall(request).execute(); + String playList = response.body().string(); + return playList; + } + + public static String getOfflinePlayList() { + return "[{\"group\":\"省内频道\",\"list\":[{\"湖南都市\":\"http://220.248.175.231:6610/001/2/ch00000090990000001049/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南经视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001052/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南都市\":\"http://220.248.175.230:6610/001/2/ch00000090990000001049/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南公共\":\"http://220.248.175.230:6610/001/2/ch00000090990000001051/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南电影\":\"http://220.248.175.230:6610/001/2/ch00000090990000001070/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南剧场\":\"http://220.248.175.230:6610/001/2/ch00000090990000001050/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南时尚\":\"http://220.248.175.230:6610/001/2/ch00000090990000001085/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南娱乐\":\"http://220.248.175.230:6610/001/2/ch00000090990000001013/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"金鹰纪实\":\"http://220.248.175.230:6610/001/2/ch00000090990000001057/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"金鹰卡通\":\"http://220.248.175.230:6610/001/2/ch00000090990000001058/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南国际\":\"http://220.248.175.230:6610/001/2/ch00000090990000001044/index.m3u8?virtualDomain=001.live_hls.zte.com\"}]},{\"group\":\"其他频道\",\"list\":[{\"安徽卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001024/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"北京卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001025/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"东方卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001036/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"东南卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001037/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"甘肃卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001109/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"广东卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001042/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"广西卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001045/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"贵州卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001046/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"河北卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001110/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"河南卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001111/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"黑龙江卫\":\"http://220.248.175.230:6610/001/2/ch00000090990000001048/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖北卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001047/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"吉林卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001112/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"江苏卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001055/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"江西卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001056/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"辽宁卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001061/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"旅游卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001062/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"南方卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001118/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"内蒙古卫\":\"http://220.248.175.230:6610/001/2/ch00000090990000001119/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"宁夏卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001120/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"青海卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001121/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"山东卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001065/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"山西卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001123/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"陕西卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001067/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"深圳卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001068/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"四川卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001064/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"天津卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001069/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"西藏卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001129/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"新疆卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001128/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"云南卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001072/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"浙江卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001073/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"重庆卫视\":\"http://220.248.175.230:6610/001/2/ch00000090990000001033/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"长沙经贸\":\"http://220.248.175.230:6610/001/2/ch00000090990000001034/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"长沙女性\":\"http://220.248.175.230:6610/001/2/ch00000090990000001106/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"长沙新闻\":\"http://220.248.175.230:6610/001/2/ch00000090990000001104/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"长沙政法\":\"http://220.248.175.230:6610/001/2/ch00000090990000001107/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果直播\":\"http://220.248.175.230:6610/001/2/ch00000090990000001140/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果独播\":\"http://220.248.175.230:6610/001/2/ch00000090990000001089/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果儿歌\":\"http://220.248.175.230:6610/001/2/ch00000090990000001096/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果港台\":\"http://220.248.175.230:6610/001/2/ch00000090990000001101/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果古装\":\"http://220.248.175.230:6610/001/2/ch00000090990000001092/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果韩国\":\"http://220.248.175.230:6610/001/2/ch00000090990000001094/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果好莱坞\":\"http://220.248.175.230:6610/001/2/ch00000090990000001091/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果快乐购\":\"http://220.248.175.230:6610/001/2/ch00000090990000001090/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果欧美A\":\"http://220.248.175.230:6610/001/2/ch00000090990000001100/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果欧美B\":\"http://220.248.175.230:6610/001/2/ch00000090990000001108/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果汽车\":\"http://220.248.175.230:6610/001/2/ch00000090990000001095/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果亲子\":\"http://220.248.175.230:6610/001/2/ch00000090990000001086/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果综艺\":\"http://220.248.175.230:6610/001/2/ch00000090990000001088/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"芒果军事\":\"http://220.248.175.230:6610/001/2/ch00000090990000001087/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"卡酷少儿\":\"http://220.248.175.230:6610/001/2/ch00000090990000001059/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CGTN\":\"http://220.248.175.230:6610/001/2/ch00000090990000001032/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CGTN DOCUMENTARY\":\"http://220.248.175.230:6610/001/2/ch00000090990000001026/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CNTV经典电影\":\"http://220.248.175.230:6610/001/2/ch00000090990000001054/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CNTV魅力时尚\":\"http://220.248.175.230:6610/001/2/ch00000090990000001117/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CNTV热播剧场\":\"http://220.248.175.230:6610/001/2/ch00000090990000001063/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"电子体育\":\"http://220.248.175.230:6610/001/2/ch00000090990000001038/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"高尔夫\":\"http://220.248.175.230:6610/001/2/ch00000090990000001043/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"国家卫计\\r\\n\":\"http://220.248.175.230:6610/001/2/ch00000090990000001102/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"快乐垂钓\":\"http://220.248.175.230:6610/001/2/ch00000090990000001060/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"先锋乒羽\":\"http://220.248.175.230:6610/001/2/ch00000090990000001127/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"家庭理财\":\"http://220.248.175.230:6610/001/2/ch00000090990000001114/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"财富天下\":\"http://220.248.175.230:6610/001/2/ch00000090990000001103/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"江苏靓妆\":\"http://220.248.175.230:6610/001/2/ch00000090990000001113/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"快乐宠物\":\"http://220.248.175.230:6610/001/2/ch00000090990000001115/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"快乐购\":\"http://220.248.175.230:6610/001/2/ch00000090990000001116/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"美食天府\":\"http://220.248.175.230:6610/001/2/ch00000090990000001132/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"人物频道\":\"http://220.248.175.230:6610/001/2/ch00000090990000001122/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"四海钓鱼\":\"http://220.248.175.230:6610/001/2/ch00000090990000001066/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"天元围棋\":\"http://220.248.175.230:6610/001/2/ch00000090990000001125/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"休闲棋牌\":\"http://220.248.175.230:6610/001/2/ch00000090990000001134/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"优漫卡通\":\"http://220.248.175.230:6610/001/2/ch00000090990000001071/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"优优宝贝\":\"http://220.248.175.230:6610/001/2/ch00000090990000001131/index.m3u8?virtualDomain=001.live_hls.zte.com\"}]},{\"group\":\"高清频道\",\"list\":[{\"CCTV1综合HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001075/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"北京卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001077/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"东方卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001081/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"黑龙江卫HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001084/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"江苏卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001082/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"山东卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001083/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"深圳卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001078/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"浙江卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001076/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"天津卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001135/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南卫视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001079/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"湖南经视HD\":\"http://220.248.175.230:6610/001/2/ch00000090990000001080/index.m3u8?virtualDomain=001.live_hls.zte.com\"}]},{\"group\":\"央视频道\",\"list\":[{\"CCTV1综合\":\"http://220.248.175.230:6610/001/2/ch00000090990000001075/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV2财经\":\"http://220.248.175.230:6610/001/2/ch00000090990000001014/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV3综艺\":\"http://220.248.175.230:6610/001/2/ch00000090990000001023/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV4国际\":\"http://220.248.175.230:6610/001/2/ch00000090990000001015/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV5体育\":\"http://220.248.175.230:6610/001/2/ch00000090990000001016/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV5赛事\":\"http://220.248.175.230:6610/001/2/ch00000090990000001074/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV7农业\":\"http://220.248.175.230:6610/001/2/ch00000090990000001018/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV9记录\":\"http://220.248.175.230:6610/001/2/ch00000090990000001020/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV10科教\":\"http://220.248.175.230:6610/001/2/ch00000090990000001021/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV11戏曲\":\"http://220.248.175.230:6610/001/2/ch00000090990000001027/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV12法制\":\"http://220.248.175.230:6610/001/2/ch00000090990000001028/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV13新闻\":\"http://220.248.175.230:6610/001/2/ch00000090990000001029/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV14少儿\":\"http://220.248.175.230:6610/001/2/ch00000090990000001030/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV15音乐\":\"http://220.248.175.230:6610/001/2/ch00000090990000001031/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV足球\":\"http://220.248.175.230:6610/001/2/ch00000090990000001041/index.m3u8?virtualDomain=001.live_hls.zte.com\"},{\"CCTV证券\":\"http://220.248.175.230:6610/001/2/ch00000090990000001133/index.m3u8?virtualDomain=001.live_hls.zte.com\"}]}]"; + } + + public static Boolean login(String mEmail, String mPassword, Context context) throws Exception { + try { + //获取uuid + SharedPreferences userSettings = context.getSharedPreferences("auth", Context.MODE_PRIVATE); + String uuid = userSettings.getString("uuid", "none"); + if ("none".equals(uuid)) { + SharedPreferences.Editor editor = userSettings.edit(); + uuid = UUID.randomUUID().toString(); + editor.putString("uuid", uuid); + editor.commit(); + } + String mac = DeviceUtils.getAdresseMAC(context); + String eth0 = DeviceUtils.getMac(); + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url(apiPath + "auth?userName=" + mEmail + "&password=" + mPassword + "&mac=" + mac + "ð0=" + eth0 + "&uuid=" + uuid) + .build(); + Response response = client.newCall(request).execute(); + //网络连接错误 + if (response.code() != 200) { + LoginActivity.state = 0; + return false; + } + String result = response.body().string(); + JSONObject jsonObject = (JSONObject) JSON.parse(result); + LoginActivity.state = (Integer) jsonObject.get("result"); + return true; + } catch (Exception e) { + e.printStackTrace(); + LoginActivity.state = 0; + return false; + } + } + + public static Map getVersionInfo() { + Map versionInfo = new HashMap<>(); + try { + OkHttpClient client = new OkHttpClient(); + Request request = new Request.Builder() + .url(apiPath + "getAppVersion").build(); + Response response = client.newCall(request).execute(); + String result = response.body().string(); + JSONObject jsonObject = (JSONObject) JSON.parse(result); + versionInfo.put("version", jsonObject.getString("version")); + versionInfo.put("updateInfo", jsonObject.getString("updateInfo")); + } catch (IOException e) { + e.printStackTrace(); + } + return versionInfo; + } +} diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/LiveActivityRel.java b/TvPlayer/src/main/java/com/gxf/liveplay/LiveActivityRel.java index 8b754fb..0c1e267 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/LiveActivityRel.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/LiveActivityRel.java @@ -1,446 +1,446 @@ -package com.gxf.liveplay; - -/** - * Created by gongxufan on 2017/9/4. - */ - -import android.app.Activity; -import android.app.DownloadManager; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.IntentFilter; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.net.Uri; -import android.os.Bundle; -import android.os.Handler; -import android.os.Message; -import android.support.v7.app.AlertDialog; -import android.view.KeyEvent; -import android.view.MotionEvent; -import android.view.View; -import android.widget.AdapterView; -import android.widget.LinearLayout; -import android.widget.ListView; -import android.widget.RelativeLayout; -import android.widget.SimpleAdapter; -import android.widget.TextView; - -import com.gxf.liveplay.ijkplayer.media.IjkVideoView; -import com.gxf.liveplay.update.UpdateAppReceiver; -import com.gxf.liveplay.update.UpdateAppUtils; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import tv.danmaku.ijk.media.player.IMediaPlayer; -import tv.danmaku.ijk.media.player.IjkMediaPlayer; - -/** - * 直播 - */ -public class LiveActivityRel extends Activity { - - private IjkVideoView mVideoView; - private RelativeLayout mVideoViewLayout; - private RelativeLayout mLoadingLayout; - private LinearLayout leftMenuCtrl; - private TextView mLoadingText; - private TextView mTextClock; - private String mVideoUrl = ""; - private int mRetryTimes = 0; - private static final int CONNECTION_TIMES = 5; - private ListView listView; - private TextView tvGroupTitle; - private AlertDialog.Builder builder; - private int choice = 1; - private UpdateAppReceiver updateAppReceiver = new UpdateAppReceiver(); - Handler handler = new Handler(new Handler.Callback() { - @Override - public boolean handleMessage(Message message) { - if (message.what == 1) { - Map versionInfo = (Map) message.obj; - //版本检测 - UpdateAppUtils.from(LiveActivityRel.this) - .checkBy(UpdateAppUtils.CHECK_BY_VERSION_NAME) //更新检测方式,默认为VersionCode - .serverVersionName(versionInfo.get("version")) - .apkPath(HttpUtils.apkPath) - .showNotification(true) //是否显示下载进度到通知栏,默认为true - .updateInfo(versionInfo.get("updateInfo")) //更新日志信息 String - .downloadBy(UpdateAppUtils.DOWNLOAD_BY_APP) //下载方式:app下载、手机浏览器下载。默认app下载 - .isForce(false) //是否强制更新,默认false 强制更新情况下用户不同意更新则不能使用app - .update(); - } - return false; - } - }); - /* //显示时钟 - private Handler mHandler = new Handler() { - @Override - public void handleMessage(Message msg) { - super.handleMessage(msg); - switch (msg.what) { - case 1: - long sysTime = System.currentTimeMillis();//获取系统时间 - CharSequence sysTimeStr = DateFormat.format("hh:mm:ss", sysTime);//时间显示格式 - //更新时间 - mTextClock.setText(getDateFormate()); - break; - default: - break; - - } - } - }; - - class TimeThread extends Thread { - @Override - public void run() { - do { - try { - Thread.sleep(1000); - Message msg = new Message(); - msg.what = 1; //消息(一个整型值) - mHandler.sendMessage(msg);// 每隔1秒发送一个msg给mHandler - } catch (InterruptedException e) { - e.printStackTrace(); - } - } while (true); - } - }*/ - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_play_rel); - new Thread(new Runnable() { - @Override - public void run() { - Map versionInfo = HttpUtils.getVersionInfo(); - Message message = Message.obtain(); - message.obj = versionInfo; - message.what = 1; - handler.sendMessage(message); - } - }).start(); - initUI(); - initDialog(); - initVideo(); - //new TimeThread().start(); //启动新的线程刷新时间 - } - - private void initUI() { - mVideoUrl = getIntent().getStringExtra("url"); - //定位当前频道位置,用于上下切换频道 - PlayListCache.locateCurrChannel(mVideoUrl); - SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); - SharedPreferences.Editor editor = userSettings.edit(); - editor.putString("lastVedioUrl", mVideoUrl); - editor.commit(); - leftMenuCtrl = (LinearLayout) findViewById(R.id.leftMenuCtrl); - tvGroupTitle = (TextView) findViewById(R.id.tvGroupTitle); - //侧滑节目列表 - listView = (ListView) findViewById(R.id.listView); - listView.setAdapter(new SimpleAdapter(this, getItem(), R.layout.item_menu, new String[]{"title", "no"}, new int[]{R.id.tvInfo, R.id.no})); - listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { - @Override - public void onItemClick(AdapterView adapterView, View view, int i, long l) { - TextView textView = (TextView) view.findViewById(R.id.tvInfo); - String tvInfo = (String) textView.getText(); - //mMenu.toggle(); - LiveActivityRel.activityStart(LiveActivityRel.this, PlayListCache.playListMap.get(tvInfo)); - //结束当前播放 - LiveActivityRel.this.finish(); - } - }); - mVideoView = (IjkVideoView) findViewById(R.id.videoview); - mVideoViewLayout = (RelativeLayout) findViewById(R.id.fl_videoview); - mLoadingLayout = (RelativeLayout) findViewById(R.id.rl_loading); - mLoadingText = (TextView) findViewById(R.id.tv_load_msg); - mLoadingText.setText("节目加载中..."); - //mTextClock = (TextView) findViewById(R.id.tv_time); - } - - private ArrayList> reNo(ArrayList> group) { - int index = 0; - if (group != null && group.size() > 0) { - for (int i = 0; i < group.size(); i++) { - HashMap stirngHashMap = group.get(i); - Iterator it = stirngHashMap.keySet().iterator(); - while (it.hasNext()) { - String key = it.next(); - if ("no".equals(key)) - stirngHashMap.put("no", String.valueOf(++index)); - } - } - } - return group; - } - - public ArrayList> getItem() { - - if (PlayListCache.index == 0) { - tvGroupTitle.setText("我的频道"); - int no = 0; - ArrayList> item = new ArrayList>(); - Iterator stringKyeSet = PlayListCache.groupInfo.keySet().iterator(); - while (stringKyeSet.hasNext()) { - ArrayList> hashMapArrayList = PlayListCache.groupInfo.get(stringKyeSet.next()); - if (hashMapArrayList != null && hashMapArrayList.size() > 0) { - for (int i = 0; i < hashMapArrayList.size(); i++) { - HashMap h = hashMapArrayList.get(i); - for (String k : h.keySet()) { - if ("no".equals(k)) - h.put(k, String.valueOf(++no)); - } - - } - } - item.addAll(hashMapArrayList); - } - return item; - } else { - tvGroupTitle.setText(PlayListCache.groupInfoArray[PlayListCache.index]); - return reNo(PlayListCache.groupInfo.get(PlayListCache.groupInfoArray[PlayListCache.index])); - } - - } - - private String getDateFormate() { - Calendar c = Calendar.getInstance(); - SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - String formattedDate = df.format(c.getTime()); - return formattedDate; - } - - public void initVideo() { - // init player` - IjkMediaPlayer.loadLibrariesOnce(null); - IjkMediaPlayer.native_profileBegin("libijkplayer.so"); - mVideoView.setVideoURI(Uri.parse(mVideoUrl)); - mVideoView.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() { - @Override - public void onPrepared(IMediaPlayer mp) { - mp.setVolume(100, 100); - mVideoView.start(); - } - }); - - mVideoView.setOnInfoListener(new IMediaPlayer.OnInfoListener() { - @Override - public boolean onInfo(IMediaPlayer mp, int what, int extra) { - switch (what) { - case IjkMediaPlayer.MEDIA_INFO_BUFFERING_START: - mLoadingLayout.setVisibility(View.VISIBLE); - break; - case IjkMediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START: - case IjkMediaPlayer.MEDIA_INFO_BUFFERING_END: - mLoadingLayout.setVisibility(View.GONE); - break; - } - return false; - } - }); - - mVideoView.setOnCompletionListener(new IMediaPlayer.OnCompletionListener() { - @Override - public void onCompletion(IMediaPlayer mp) { - mLoadingLayout.setVisibility(View.VISIBLE); - mVideoView.stopPlayback(); - mVideoView.release(true); - mVideoView.setVideoURI(Uri.parse(mVideoUrl)); - } - }); - - mVideoView.setOnErrorListener(new IMediaPlayer.OnErrorListener() { - @Override - public boolean onError(IMediaPlayer mp, int what, int extra) { - if (++mRetryTimes > CONNECTION_TIMES) { - new AlertDialog.Builder(LiveActivityRel.this) - .setMessage("该频道媒体资源出现错误,节目暂时不能播放...") - .setPositiveButton(R.string.VideoView_error_button, - new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - dialog.dismiss(); - //LiveActivityRel.this.finish(); - } - }) - .setCancelable(false) - .show(); - } else { - mVideoView.stopPlayback(); - mVideoView.release(true); - mVideoView.setVideoURI(Uri.parse(mVideoUrl)); - } - return false; - } - }); - - } - - @Override - protected void onResume() { - this.registerReceiver(updateAppReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); - super.onResume(); - } - - @Override - protected void onPause() { - this.unregisterReceiver(updateAppReceiver); - super.onPause(); - } - - @Override - protected void onStop() { - super.onStop(); - if (!mVideoView.isBackgroundPlayEnabled()) { - mVideoView.stopPlayback(); - mVideoView.release(true); - mVideoView.stopBackgroundPlay(); - } - IjkMediaPlayer.native_profileEnd(); - } - - public static void activityStart(Context context, String url) { - Intent intent = new Intent(context, LiveActivityRel.class); - intent.putExtra("url", url); - context.startActivity(intent); - } - - @Override - public void onConfigurationChanged(Configuration newConfig) { - super.onConfigurationChanged(newConfig); - } - - public void turnLeft(View view) { - PlayListCache.index--; - if (PlayListCache.index < 0) { - PlayListCache.index = 0; - } - listView.setAdapter(new SimpleAdapter(this, getItem(), R.layout.item_menu, new String[]{"title", "no"}, new int[]{R.id.tvInfo, R.id.no})); - } - - public void turnRight(View view) { - PlayListCache.index++; - if (PlayListCache.index > PlayListCache.groupInfoArray.length - 1) { - PlayListCache.index = PlayListCache.groupInfoArray.length - 1; - } - listView.setAdapter(new SimpleAdapter(this, getItem(), R.layout.item_menu, new String[]{"title", "no"}, new int[]{R.id.tvInfo, R.id.no})); - } - - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - boolean isCtrl = leftMenuCtrl.getVisibility() == View.GONE; - //确认键弹出频道列表界面 - if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { - if (isCtrl) { - leftMenuCtrl.setVisibility(View.VISIBLE); - leftMenuCtrl.requestFocus(); - } else - leftMenuCtrl.setVisibility(View.GONE); - } - //左右切换频道列表 - if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { - turnRight(null); - } - if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { - turnLeft(null); - } - int size = PlayListCache.channelInfoList.size() - 1; - //上下换台 - if (keyCode == KeyEvent.KEYCODE_DPAD_UP && isCtrl) { - PlayListCache.currChannel--; - if (PlayListCache.currChannel < 0) - PlayListCache.currChannel = size; - LiveActivityRel.activityStart(LiveActivityRel.this, PlayListCache.channelInfoList.get(PlayListCache.currChannel)); - //结束当前播放 - LiveActivityRel.this.finish(); - } - if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && isCtrl) { - PlayListCache.currChannel++; - if (PlayListCache.currChannel > size) - PlayListCache.currChannel = 0; - LiveActivityRel.activityStart(LiveActivityRel.this, PlayListCache.channelInfoList.get(PlayListCache.currChannel)); - //结束当前播放 - LiveActivityRel.this.finish(); - } - return super.onKeyDown(keyCode, event); - } - - /** - * 初始化好确认退出的对话框 - */ - private void initDialog() { - - builder = new AlertDialog.Builder(LiveActivityRel.this); - builder.setIcon(R.drawable.ic_launcher); - builder.setTitle("请选择操作"); - final String[] serviceType = {"退出当前登录", "关闭程序"}; - // 设置一个单项选择下拉框 - /** - * 第一个参数指定我们要显示的一组下拉单选框的数据集合 - * 第二个参数代表索引,指定默认哪一个单选框被勾选上,1表示默认'女' 会被勾选上 - * 第三个参数给每一个单选项绑定一个监听器 - */ - builder.setSingleChoiceItems(serviceType, 1, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - choice = which; - } - }); - builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - //注销登录 - if (choice == 0) { - /* SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); - SharedPreferences.Editor editor = userSettings.edit(); - editor.remove("userName"); - editor.remove("password"); - editor.commit();*/ - startActivity(new Intent(LiveActivityRel.this, LoginActivity.class)); - finish(); - } - if (choice == 1) - finish(); - } - }); - builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); - } - - - /** - * 重写点击返回建的事件处理,展示 我们写好的dialog - */ - @Override - public void onBackPressed() { - if (leftMenuCtrl.getVisibility() == View.GONE) - builder.show(); - else - leftMenuCtrl.setVisibility(View.GONE); - } - - @Override - public boolean onTouchEvent(MotionEvent event) { - //触摸控制频道界面 - boolean isCtrl = leftMenuCtrl.getVisibility() == View.GONE; - if (isCtrl) { - leftMenuCtrl.setVisibility(View.VISIBLE); - leftMenuCtrl.requestFocus(); - } - return false; - } - - +package com.gxf.liveplay; + +/** + * Created by gongxufan on 2017/9/4. + */ + +import android.app.Activity; +import android.app.DownloadManager; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; +import android.os.Message; +import android.support.v7.app.AlertDialog; +import android.view.KeyEvent; +import android.view.MotionEvent; +import android.view.View; +import android.widget.AdapterView; +import android.widget.LinearLayout; +import android.widget.ListView; +import android.widget.RelativeLayout; +import android.widget.SimpleAdapter; +import android.widget.TextView; + +import com.gxf.liveplay.ijkplayer.media.IjkVideoView; +import com.gxf.liveplay.update.UpdateAppReceiver; +import com.gxf.liveplay.update.UpdateAppUtils; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import tv.danmaku.ijk.media.player.IMediaPlayer; +import tv.danmaku.ijk.media.player.IjkMediaPlayer; + +/** + * 直播 + */ +public class LiveActivityRel extends Activity { + + private IjkVideoView mVideoView; + private RelativeLayout mVideoViewLayout; + private RelativeLayout mLoadingLayout; + private LinearLayout leftMenuCtrl; + private TextView mLoadingText; + private TextView mTextClock; + private String mVideoUrl = ""; + private int mRetryTimes = 0; + private static final int CONNECTION_TIMES = 5; + private ListView listView; + private TextView tvGroupTitle; + private AlertDialog.Builder builder; + private int choice = 1; + private UpdateAppReceiver updateAppReceiver = new UpdateAppReceiver(); + Handler handler = new Handler(new Handler.Callback() { + @Override + public boolean handleMessage(Message message) { + if (message.what == 1) { + Map versionInfo = (Map) message.obj; + //版本检测 + UpdateAppUtils.from(LiveActivityRel.this) + .checkBy(UpdateAppUtils.CHECK_BY_VERSION_NAME) //更新检测方式,默认为VersionCode + .serverVersionName(versionInfo.get("version")) + .apkPath(HttpUtils.apkPath) + .showNotification(true) //是否显示下载进度到通知栏,默认为true + .updateInfo(versionInfo.get("updateInfo")) //更新日志信息 String + .downloadBy(UpdateAppUtils.DOWNLOAD_BY_APP) //下载方式:app下载、手机浏览器下载。默认app下载 + .isForce(false) //是否强制更新,默认false 强制更新情况下用户不同意更新则不能使用app + .update(); + } + return false; + } + }); + /* //显示时钟 + private Handler mHandler = new Handler() { + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + switch (msg.what) { + case 1: + long sysTime = System.currentTimeMillis();//获取系统时间 + CharSequence sysTimeStr = DateFormat.format("hh:mm:ss", sysTime);//时间显示格式 + //更新时间 + mTextClock.setText(getDateFormate()); + break; + default: + break; + + } + } + }; + + class TimeThread extends Thread { + @Override + public void run() { + do { + try { + Thread.sleep(1000); + Message msg = new Message(); + msg.what = 1; //消息(一个整型值) + mHandler.sendMessage(msg);// 每隔1秒发送一个msg给mHandler + } catch (InterruptedException e) { + e.printStackTrace(); + } + } while (true); + } + }*/ + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_play_rel); + new Thread(new Runnable() { + @Override + public void run() { + Map versionInfo = HttpUtils.getVersionInfo(); + Message message = Message.obtain(); + message.obj = versionInfo; + message.what = 1; + handler.sendMessage(message); + } + }).start(); + initUI(); + initDialog(); + initVideo(); + //new TimeThread().start(); //启动新的线程刷新时间 + } + + private void initUI() { + mVideoUrl = getIntent().getStringExtra("url"); + //定位当前频道位置,用于上下切换频道 + PlayListCache.locateCurrChannel(mVideoUrl); + SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); + SharedPreferences.Editor editor = userSettings.edit(); + editor.putString("lastVedioUrl", mVideoUrl); + editor.commit(); + leftMenuCtrl = (LinearLayout) findViewById(R.id.leftMenuCtrl); + tvGroupTitle = (TextView) findViewById(R.id.tvGroupTitle); + //侧滑节目列表 + listView = (ListView) findViewById(R.id.listView); + listView.setAdapter(new SimpleAdapter(this, getItem(), R.layout.item_menu, new String[]{"title", "no"}, new int[]{R.id.tvInfo, R.id.no})); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + TextView textView = (TextView) view.findViewById(R.id.tvInfo); + String tvInfo = (String) textView.getText(); + //mMenu.toggle(); + LiveActivityRel.activityStart(LiveActivityRel.this, PlayListCache.playListMap.get(tvInfo)); + //结束当前播放 + LiveActivityRel.this.finish(); + } + }); + mVideoView = (IjkVideoView) findViewById(R.id.videoview); + mVideoViewLayout = (RelativeLayout) findViewById(R.id.fl_videoview); + mLoadingLayout = (RelativeLayout) findViewById(R.id.rl_loading); + mLoadingText = (TextView) findViewById(R.id.tv_load_msg); + mLoadingText.setText("节目加载中..."); + //mTextClock = (TextView) findViewById(R.id.tv_time); + } + + private ArrayList> reNo(ArrayList> group) { + int index = 0; + if (group != null && group.size() > 0) { + for (int i = 0; i < group.size(); i++) { + HashMap stirngHashMap = group.get(i); + Iterator it = stirngHashMap.keySet().iterator(); + while (it.hasNext()) { + String key = it.next(); + if ("no".equals(key)) + stirngHashMap.put("no", String.valueOf(++index)); + } + } + } + return group; + } + + public ArrayList> getItem() { + + if (PlayListCache.index == 0) { + tvGroupTitle.setText("我的频道"); + int no = 0; + ArrayList> item = new ArrayList>(); + Iterator stringKyeSet = PlayListCache.groupInfo.keySet().iterator(); + while (stringKyeSet.hasNext()) { + ArrayList> hashMapArrayList = PlayListCache.groupInfo.get(stringKyeSet.next()); + if (hashMapArrayList != null && hashMapArrayList.size() > 0) { + for (int i = 0; i < hashMapArrayList.size(); i++) { + HashMap h = hashMapArrayList.get(i); + for (String k : h.keySet()) { + if ("no".equals(k)) + h.put(k, String.valueOf(++no)); + } + + } + } + item.addAll(hashMapArrayList); + } + return item; + } else { + tvGroupTitle.setText(PlayListCache.groupInfoArray[PlayListCache.index]); + return reNo(PlayListCache.groupInfo.get(PlayListCache.groupInfoArray[PlayListCache.index])); + } + + } + + private String getDateFormate() { + Calendar c = Calendar.getInstance(); + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + String formattedDate = df.format(c.getTime()); + return formattedDate; + } + + public void initVideo() { + // init player` + IjkMediaPlayer.loadLibrariesOnce(null); + IjkMediaPlayer.native_profileBegin("libijkplayer.so"); + mVideoView.setVideoURI(Uri.parse(mVideoUrl)); + mVideoView.setOnPreparedListener(new IMediaPlayer.OnPreparedListener() { + @Override + public void onPrepared(IMediaPlayer mp) { + mp.setVolume(100, 100); + mVideoView.start(); + } + }); + + mVideoView.setOnInfoListener(new IMediaPlayer.OnInfoListener() { + @Override + public boolean onInfo(IMediaPlayer mp, int what, int extra) { + switch (what) { + case IjkMediaPlayer.MEDIA_INFO_BUFFERING_START: + mLoadingLayout.setVisibility(View.VISIBLE); + break; + case IjkMediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START: + case IjkMediaPlayer.MEDIA_INFO_BUFFERING_END: + mLoadingLayout.setVisibility(View.GONE); + break; + } + return false; + } + }); + + mVideoView.setOnCompletionListener(new IMediaPlayer.OnCompletionListener() { + @Override + public void onCompletion(IMediaPlayer mp) { + mLoadingLayout.setVisibility(View.VISIBLE); + mVideoView.stopPlayback(); + mVideoView.release(true); + mVideoView.setVideoURI(Uri.parse(mVideoUrl)); + } + }); + + mVideoView.setOnErrorListener(new IMediaPlayer.OnErrorListener() { + @Override + public boolean onError(IMediaPlayer mp, int what, int extra) { + if (++mRetryTimes > CONNECTION_TIMES) { + new AlertDialog.Builder(LiveActivityRel.this) + .setMessage("该频道媒体资源出现错误,节目暂时不能播放...") + .setPositiveButton(R.string.VideoView_error_button, + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int whichButton) { + dialog.dismiss(); + //LiveActivityRel.this.finish(); + } + }) + .setCancelable(false) + .show(); + } else { + mVideoView.stopPlayback(); + mVideoView.release(true); + mVideoView.setVideoURI(Uri.parse(mVideoUrl)); + } + return false; + } + }); + + } + + @Override + protected void onResume() { + this.registerReceiver(updateAppReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)); + super.onResume(); + } + + @Override + protected void onPause() { + this.unregisterReceiver(updateAppReceiver); + super.onPause(); + } + + @Override + protected void onStop() { + super.onStop(); + if (!mVideoView.isBackgroundPlayEnabled()) { + mVideoView.stopPlayback(); + mVideoView.release(true); + mVideoView.stopBackgroundPlay(); + } + IjkMediaPlayer.native_profileEnd(); + } + + public static void activityStart(Context context, String url) { + Intent intent = new Intent(context, LiveActivityRel.class); + intent.putExtra("url", url); + context.startActivity(intent); + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + } + + public void turnLeft(View view) { + PlayListCache.index--; + if (PlayListCache.index < 0) { + PlayListCache.index = 0; + } + listView.setAdapter(new SimpleAdapter(this, getItem(), R.layout.item_menu, new String[]{"title", "no"}, new int[]{R.id.tvInfo, R.id.no})); + } + + public void turnRight(View view) { + PlayListCache.index++; + if (PlayListCache.index > PlayListCache.groupInfoArray.length - 1) { + PlayListCache.index = PlayListCache.groupInfoArray.length - 1; + } + listView.setAdapter(new SimpleAdapter(this, getItem(), R.layout.item_menu, new String[]{"title", "no"}, new int[]{R.id.tvInfo, R.id.no})); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + boolean isCtrl = leftMenuCtrl.getVisibility() == View.GONE; + //确认键弹出频道列表界面 + if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) { + if (isCtrl) { + leftMenuCtrl.setVisibility(View.VISIBLE); + leftMenuCtrl.requestFocus(); + } else + leftMenuCtrl.setVisibility(View.GONE); + } + //左右切换频道列表 + if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) { + turnRight(null); + } + if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) { + turnLeft(null); + } + int size = PlayListCache.channelInfoList.size() - 1; + //上下换台 + if (keyCode == KeyEvent.KEYCODE_DPAD_UP && isCtrl) { + PlayListCache.currChannel--; + if (PlayListCache.currChannel < 0) + PlayListCache.currChannel = size; + LiveActivityRel.activityStart(LiveActivityRel.this, PlayListCache.channelInfoList.get(PlayListCache.currChannel)); + //结束当前播放 + LiveActivityRel.this.finish(); + } + if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && isCtrl) { + PlayListCache.currChannel++; + if (PlayListCache.currChannel > size) + PlayListCache.currChannel = 0; + LiveActivityRel.activityStart(LiveActivityRel.this, PlayListCache.channelInfoList.get(PlayListCache.currChannel)); + //结束当前播放 + LiveActivityRel.this.finish(); + } + return super.onKeyDown(keyCode, event); + } + + /** + * 初始化好确认退出的对话框 + */ + private void initDialog() { + + builder = new AlertDialog.Builder(LiveActivityRel.this); + builder.setIcon(R.drawable.ic_launcher); + builder.setTitle("请选择操作"); + final String[] serviceType = {"退出当前登录", "关闭程序"}; + // 设置一个单项选择下拉框 + /** + * 第一个参数指定我们要显示的一组下拉单选框的数据集合 + * 第二个参数代表索引,指定默认哪一个单选框被勾选上,1表示默认'女' 会被勾选上 + * 第三个参数给每一个单选项绑定一个监听器 + */ + builder.setSingleChoiceItems(serviceType, 1, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + choice = which; + } + }); + builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + //注销登录 + if (choice == 0) { + /* SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); + SharedPreferences.Editor editor = userSettings.edit(); + editor.remove("userName"); + editor.remove("password"); + editor.commit();*/ + startActivity(new Intent(LiveActivityRel.this, LoginActivity.class)); + finish(); + } + if (choice == 1) + finish(); + } + }); + builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + } + + + /** + * 重写点击返回建的事件处理,展示 我们写好的dialog + */ + @Override + public void onBackPressed() { + if (leftMenuCtrl.getVisibility() == View.GONE) + builder.show(); + else + leftMenuCtrl.setVisibility(View.GONE); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + //触摸控制频道界面 + boolean isCtrl = leftMenuCtrl.getVisibility() == View.GONE; + if (isCtrl) { + leftMenuCtrl.setVisibility(View.VISIBLE); + leftMenuCtrl.requestFocus(); + } + return false; + } + + } \ No newline at end of file diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/LoginActivity.java b/TvPlayer/src/main/java/com/gxf/liveplay/LoginActivity.java index 7923cb4..560c052 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/LoginActivity.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/LoginActivity.java @@ -1,197 +1,197 @@ -package com.gxf.liveplay; - -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.AsyncTask; -import android.os.Bundle; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; -import android.view.View; -import android.view.View.OnClickListener; -import android.view.Window; -import android.widget.Button; -import android.widget.EditText; -import android.widget.ImageButton; -import android.widget.TextView; -import android.widget.Toast; - -/** - * A login screen that offers login via email/password. - */ -public class LoginActivity extends AppCompatActivity { - - private static UserLoginTask mAuthTask = null; - public static int state; - private EditText userName; - private EditText password; - private Button loginBtn; - private TextView promptText; - private ImageButton settings; - private int choice; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - getSupportActionBar().hide(); - - setContentView(R.layout.activity_login); - settings = (ImageButton) findViewById(R.id.settings); - settings.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - Intent intent = new Intent(LoginActivity.this, ServiceSettings.class); - LoginActivity.this.startActivity(intent); - /* SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); - final SharedPreferences.Editor editor = userSettings.edit(); - //默认为公网服务器 - choice = userSettings.getInt("serviceType",0); - - AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this); - builder.setIcon(R.drawable.ic_launcher); - builder.setTitle("请选择服务器类型"); - final String[] serviceType = {"公网服务器", "内网服务器"}; - // 设置一个单项选择下拉框 - *//** - * 第一个参数指定我们要显示的一组下拉单选框的数据集合 - * 第二个参数代表索引,指定默认哪一个单选框被勾选上,1表示默认'女' 会被勾选上 - * 第三个参数给每一个单选项绑定一个监听器 - *//* - builder.setSingleChoiceItems(serviceType, choice, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - choice = which; - } - }); - builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - editor.putInt("serviceType", choice); - editor.commit(); - if(choice == 0) - HttpUtils.apiPath = HttpUtils.apiPathOuter; - if(choice == 1) - HttpUtils.apiPath = HttpUtils.apiPathLocal; - } - }); - builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.dismiss(); - } - }); - builder.show();*/ - } - }); - userName = (EditText) findViewById(R.id.userName); - password = (EditText) findViewById(R.id.password); - loginBtn = (Button) findViewById(R.id.loginBtn); - promptText = (TextView) findViewById(R.id.promptText); - loginBtn.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View view) { - attemptLogin(); - } - }); - } - - private void attemptLogin() { - String name = userName.getText().toString(); - if (name == null || name.trim().length() == 0) { - promptText.setText("用户名不能为空..."); - return; - } - String pwd = password.getText().toString(); - - if (pwd == null || pwd.trim().length() == 0) { - promptText.setText("密码不能为空..."); - return; - } - mAuthTask = new UserLoginTask(name, pwd); - mAuthTask.execute((Void) null); - } - - - public class UserLoginTask extends AsyncTask { - - private final String mEmail; - private final String mPassword; - - UserLoginTask(String email, String password) { - mEmail = email; - mPassword = password; - } - - @Override - protected Boolean doInBackground(Void... params) { - try { - return HttpUtils.login(mEmail, mPassword, LoginActivity.this); - } catch (Exception e) { - Toast.makeText(LoginActivity.this, "登录失败...", Toast.LENGTH_SHORT).show(); - return false; - } - } - - @Override - protected void onPostExecute(final Boolean success) { - mAuthTask = null; - if (success) { - //登录成功 - if (state == -1) { - //保存登录状态 - SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); - SharedPreferences.Editor editor = userSettings.edit(); - editor.putString("userName", mEmail); - editor.putString("password", mPassword); - editor.commit(); - final String lastVedioUrl = userSettings.getString("lastVedioUrl", "none"); - //初始化节目列表 - new Thread(new Runnable() { - @Override - public void run() { - try { - PlayListCache.initPlayInfo(mEmail,mPassword); - //启动播放器,传递播放地址 - String url = lastVedioUrl; - if (url.equals("none")) - url = PlayListCache.playListMap.get(PlayListCache.playListMap.keySet().iterator().next()); - LiveActivityRel.activityStart(LoginActivity.this, url); - finish(); - } catch (Exception e) { - promptText.setText("5:获取节目列表失败..."); - e.printStackTrace(); - } - } - }).start(); - - } else if (state == 0) { - promptText.setText("0:网络不通,请检查网络连接情况..."); - } else if (state == 1) { - promptText.setText("1:帐号不存在..."); - } else if (state == 2) { - promptText.setText("2:密码错误..."); - } else if (state == 3) { - promptText.setText("3:帐号失效..."); - } else if (state == 5) { - promptText.setText("5:获取设备uuid失败..."); - } else if (state == 6) { - promptText.setText("6:该帐号已被其他设备绑定无法登录,如需解除请联系管理员..."); - } else if (state == 7) { - promptText.setText("7:获取设备信息失败..."); - } else if (state == 8) { - promptText.setText("8:该帐号已被其他设备绑定无法登录..."); - } else { - promptText.setText("4:登录服务出现异常,请稍后重试..."); - } - } else { - promptText.setText("4:登录服务出现异常,请稍后重试..."); - } - } - - @Override - protected void onCancelled() { - mAuthTask = null; - } - } -} - +package com.gxf.liveplay; + +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.v7.app.AlertDialog; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.view.View.OnClickListener; +import android.view.Window; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageButton; +import android.widget.TextView; +import android.widget.Toast; + +/** + * A login screen that offers login via email/password. + */ +public class LoginActivity extends AppCompatActivity { + + private static UserLoginTask mAuthTask = null; + public static int state; + private EditText userName; + private EditText password; + private Button loginBtn; + private TextView promptText; + private ImageButton settings; + private int choice; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + getSupportActionBar().hide(); + + setContentView(R.layout.activity_login); + settings = (ImageButton) findViewById(R.id.settings); + settings.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(LoginActivity.this, ServiceSettings.class); + LoginActivity.this.startActivity(intent); + /* SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); + final SharedPreferences.Editor editor = userSettings.edit(); + //默认为公网服务器 + choice = userSettings.getInt("serviceType",0); + + AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this); + builder.setIcon(R.drawable.ic_launcher); + builder.setTitle("请选择服务器类型"); + final String[] serviceType = {"公网服务器", "内网服务器"}; + // 设置一个单项选择下拉框 + *//** + * 第一个参数指定我们要显示的一组下拉单选框的数据集合 + * 第二个参数代表索引,指定默认哪一个单选框被勾选上,1表示默认'女' 会被勾选上 + * 第三个参数给每一个单选项绑定一个监听器 + *//* + builder.setSingleChoiceItems(serviceType, choice, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + choice = which; + } + }); + builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + editor.putInt("serviceType", choice); + editor.commit(); + if(choice == 0) + HttpUtils.apiPath = HttpUtils.apiPathOuter; + if(choice == 1) + HttpUtils.apiPath = HttpUtils.apiPathLocal; + } + }); + builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + } + }); + builder.show();*/ + } + }); + userName = (EditText) findViewById(R.id.userName); + password = (EditText) findViewById(R.id.password); + loginBtn = (Button) findViewById(R.id.loginBtn); + promptText = (TextView) findViewById(R.id.promptText); + loginBtn.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View view) { + attemptLogin(); + } + }); + } + + private void attemptLogin() { + String name = userName.getText().toString(); + if (name == null || name.trim().length() == 0) { + promptText.setText("用户名不能为空..."); + return; + } + String pwd = password.getText().toString(); + + if (pwd == null || pwd.trim().length() == 0) { + promptText.setText("密码不能为空..."); + return; + } + mAuthTask = new UserLoginTask(name, pwd); + mAuthTask.execute((Void) null); + } + + + public class UserLoginTask extends AsyncTask { + + private final String mEmail; + private final String mPassword; + + UserLoginTask(String email, String password) { + mEmail = email; + mPassword = password; + } + + @Override + protected Boolean doInBackground(Void... params) { + try { + return HttpUtils.login(mEmail, mPassword, LoginActivity.this); + } catch (Exception e) { + Toast.makeText(LoginActivity.this, "登录失败...", Toast.LENGTH_SHORT).show(); + return false; + } + } + + @Override + protected void onPostExecute(final Boolean success) { + mAuthTask = null; + if (success) { + //登录成功 + if (state == -1) { + //保存登录状态 + SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); + SharedPreferences.Editor editor = userSettings.edit(); + editor.putString("userName", mEmail); + editor.putString("password", mPassword); + editor.commit(); + final String lastVedioUrl = userSettings.getString("lastVedioUrl", "none"); + //初始化节目列表 + new Thread(new Runnable() { + @Override + public void run() { + try { + PlayListCache.initPlayInfo(mEmail,mPassword); + //启动播放器,传递播放地址 + String url = lastVedioUrl; + if (url.equals("none")) + url = PlayListCache.playListMap.get(PlayListCache.playListMap.keySet().iterator().next()); + LiveActivityRel.activityStart(LoginActivity.this, url); + finish(); + } catch (Exception e) { + promptText.setText("5:获取节目列表失败..."); + e.printStackTrace(); + } + } + }).start(); + + } else if (state == 0) { + promptText.setText("0:网络不通,请检查网络连接情况..."); + } else if (state == 1) { + promptText.setText("1:帐号不存在..."); + } else if (state == 2) { + promptText.setText("2:密码错误..."); + } else if (state == 3) { + promptText.setText("3:帐号失效..."); + } else if (state == 5) { + promptText.setText("5:获取设备uuid失败..."); + } else if (state == 6) { + promptText.setText("6:该帐号已被其他设备绑定无法登录,如需解除请联系管理员..."); + } else if (state == 7) { + promptText.setText("7:获取设备信息失败..."); + } else if (state == 8) { + promptText.setText("8:该帐号已被其他设备绑定无法登录..."); + } else { + promptText.setText("4:登录服务出现异常,请稍后重试..."); + } + } else { + promptText.setText("4:登录服务出现异常,请稍后重试..."); + } + } + + @Override + protected void onCancelled() { + mAuthTask = null; + } + } +} + diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/MainActivity.java b/TvPlayer/src/main/java/com/gxf/liveplay/MainActivity.java index 2433676..64bd615 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/MainActivity.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/MainActivity.java @@ -1,73 +1,73 @@ -/* - * Copyright (C) 2016 hejunlin - * - * Github:https://github.com/hejunlin2013/LivePlayback - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gxf.liveplay; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.widget.Toast; - -/** - * splash - * 启动登录检测 - */ -public class MainActivity extends Activity { - private final int SPLASH_DISPLAY_LENGHT = 1000; // 两秒后进入系统 - private boolean isUpdateChecked = false; - public void checkLogin(){ - SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); - final String userName = userSettings.getString("userName", "none"); - final String password = userSettings.getString("password", "none"); - final String lastVedioUrl = userSettings.getString("lastVedioUrl", "none"); - final String serviceUrl = userSettings.getString("serviceUrl", "none"); - if(!"none".equals(serviceUrl)) - HttpUtils.apiPath = serviceUrl; - final Toast toast = Toast.makeText(MainActivity.this, "获取节目列表错误,系统初始化失败...", Toast.LENGTH_SHORT); - // 开启一个子线程,进行网络操作,等待有返回结果,使用handler通知UI - new Thread(new Runnable() { - @Override - public void run() { - try { - //Thread.currentThread().sleep(SPLASH_DISPLAY_LENGHT); - //跳转登录 - if ("none".equals(userName) || !HttpUtils.login(userName, password,MainActivity.this) || LoginActivity.state != -1) { - MainActivity.this.startActivity(new Intent(MainActivity.this, LoginActivity.class)); - } else { - PlayListCache.initPlayInfo(userName,password); - String url = lastVedioUrl; - if (url.equals("none")) - url = PlayListCache.playListMap.get(PlayListCache.playListMap.keySet().iterator().next()); - LiveActivityRel.activityStart(MainActivity.this, url); - } - MainActivity.this.finish(); - } catch (Exception e) { - toast.show(); - e.printStackTrace(); - } - } - }).start(); - } - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - checkLogin(); - } -} +/* + * Copyright (C) 2016 hejunlin + * + * Github:https://github.com/hejunlin2013/LivePlayback + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gxf.liveplay; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.widget.Toast; + +/** + * splash + * 启动登录检测 + */ +public class MainActivity extends Activity { + private final int SPLASH_DISPLAY_LENGHT = 1000; // 两秒后进入系统 + private boolean isUpdateChecked = false; + public void checkLogin(){ + SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); + final String userName = userSettings.getString("userName", "none"); + final String password = userSettings.getString("password", "none"); + final String lastVedioUrl = userSettings.getString("lastVedioUrl", "none"); + final String serviceUrl = userSettings.getString("serviceUrl", "none"); + if(!"none".equals(serviceUrl)) + HttpUtils.apiPath = serviceUrl; + final Toast toast = Toast.makeText(MainActivity.this, "获取节目列表错误,系统初始化失败...", Toast.LENGTH_SHORT); + // 开启一个子线程,进行网络操作,等待有返回结果,使用handler通知UI + new Thread(new Runnable() { + @Override + public void run() { + try { + //Thread.currentThread().sleep(SPLASH_DISPLAY_LENGHT); + //跳转登录 + if ("none".equals(userName) || !HttpUtils.login(userName, password,MainActivity.this) || LoginActivity.state != -1) { + MainActivity.this.startActivity(new Intent(MainActivity.this, LoginActivity.class)); + } else { + PlayListCache.initPlayInfo(userName,password); + String url = lastVedioUrl; + if (url.equals("none")) + url = PlayListCache.playListMap.get(PlayListCache.playListMap.keySet().iterator().next()); + LiveActivityRel.activityStart(MainActivity.this, url); + } + MainActivity.this.finish(); + } catch (Exception e) { + toast.show(); + e.printStackTrace(); + } + } + }).start(); + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + checkLogin(); + } +} diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/MainActivityOffline.java b/TvPlayer/src/main/java/com/gxf/liveplay/MainActivityOffline.java index 9d20b58..da6c725 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/MainActivityOffline.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/MainActivityOffline.java @@ -1,62 +1,62 @@ -/* - * Copyright (C) 2016 hejunlin - * - * Github:https://github.com/hejunlin2013/LivePlayback - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.gxf.liveplay; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.widget.Toast; - -/** - * splash - * 启动登录检测 - */ -public class MainActivityOffline extends Activity { - private final int SPLASH_DISPLAY_LENGHT = 1000; // 两秒后进入系统 - private boolean isUpdateChecked = false; - public void checkLogin(){ - SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); - final String lastVedioUrl = userSettings.getString("lastVedioUrl", "none"); - final Toast toast = Toast.makeText(MainActivityOffline.this, "系统初始化失败...", Toast.LENGTH_SHORT); - // 开启一个子线程,进行网络操作,等待有返回结果,使用handler通知UI - new Thread(new Runnable() { - @Override - public void run() { - try { - PlayListCache.initPlayInfo(null,null); - String url = lastVedioUrl; - if (url.equals("none")) - url = PlayListCache.playListMap.get(PlayListCache.playListMap.keySet().iterator().next()); - LiveActivityRel.activityStart(MainActivityOffline.this, url); - MainActivityOffline.this.finish(); - } catch (Exception e) { - toast.show(); - e.printStackTrace(); - } - } - }).start(); - } - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_main); - checkLogin(); - } -} +/* + * Copyright (C) 2016 hejunlin + * + * Github:https://github.com/hejunlin2013/LivePlayback + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gxf.liveplay; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.widget.Toast; + +/** + * splash + * 启动登录检测 + */ +public class MainActivityOffline extends Activity { + private final int SPLASH_DISPLAY_LENGHT = 1000; // 两秒后进入系统 + private boolean isUpdateChecked = false; + public void checkLogin(){ + SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); + final String lastVedioUrl = userSettings.getString("lastVedioUrl", "none"); + final Toast toast = Toast.makeText(MainActivityOffline.this, "系统初始化失败...", Toast.LENGTH_SHORT); + // 开启一个子线程,进行网络操作,等待有返回结果,使用handler通知UI + new Thread(new Runnable() { + @Override + public void run() { + try { + PlayListCache.initPlayInfo(null,null); + String url = lastVedioUrl; + if (url.equals("none")) + url = PlayListCache.playListMap.get(PlayListCache.playListMap.keySet().iterator().next()); + LiveActivityRel.activityStart(MainActivityOffline.this, url); + MainActivityOffline.this.finish(); + } catch (Exception e) { + toast.show(); + e.printStackTrace(); + } + } + }).start(); + } + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + checkLogin(); + } +} diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/PlayListCache.java b/TvPlayer/src/main/java/com/gxf/liveplay/PlayListCache.java index 9d9cc6c..edaf4a6 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/PlayListCache.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/PlayListCache.java @@ -1,68 +1,68 @@ -package com.gxf.liveplay; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Created by gongxufan on 2017/8/25. - */ - -public class PlayListCache { - public static Map playListMap = new HashMap(); - public static Map>> groupInfo = new HashMap>>(); - //1=全部频道 2=央视频道 3=卫视频道 4=省内频道 5=其他频道 - public static String[] groupInfoArray; - public static List channelInfoList = new ArrayList<>(); - //当前频道分组编号 - public static int index = 0; - //当前播放的节目编号 - public static int currChannel = 0; - - public static void locateCurrChannel(String url){ - for (int i = 0; i < channelInfoList.size(); i++) { - String s = channelInfoList.get(i); - if(url.equals(s)){ - PlayListCache.currChannel = i; - return; - } - } - } - public static void initPlayInfo(String userName,String password) throws Exception{ - String playList = HttpUtils.getPlayList(userName,password); - JSONArray jsonArray = JSON.parseArray(playList); - PlayListCache.groupInfoArray = new String[jsonArray.size() + 1]; - PlayListCache.groupInfoArray[0] = "我的频道"; - if (jsonArray != null && jsonArray.size() > 0) { - for (int i = 0; i < jsonArray.size(); i++) { - JSONObject jo = jsonArray.getJSONObject(i); - //分组 - String group = (String) jo.get("group"); - PlayListCache.groupInfoArray[i + 1] = group; - JSONArray list = jo.getJSONArray("list"); - if (list != null && list.size() > 0) { - ArrayList> hashMaps = new ArrayList>(); - int no = 0; - for (int j = 0; j < list.size(); j++) { - JSONObject o = list.getJSONObject(j); - HashMap m = new HashMap(); - for (String k : o.keySet()) { - String v = (String) o.get(k); - m.put("title", k); - m.put("no", String.valueOf(++no)); - channelInfoList.add(v); - PlayListCache.playListMap.put(k, v); - hashMaps.add(m); - } - } - PlayListCache.groupInfo.put(group, hashMaps); - } - } - } - } -} +package com.gxf.liveplay; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by gongxufan on 2017/8/25. + */ + +public class PlayListCache { + public static Map playListMap = new HashMap(); + public static Map>> groupInfo = new HashMap>>(); + //1=全部频道 2=央视频道 3=卫视频道 4=省内频道 5=其他频道 + public static String[] groupInfoArray; + public static List channelInfoList = new ArrayList<>(); + //当前频道分组编号 + public static int index = 0; + //当前播放的节目编号 + public static int currChannel = 0; + + public static void locateCurrChannel(String url){ + for (int i = 0; i < channelInfoList.size(); i++) { + String s = channelInfoList.get(i); + if(url.equals(s)){ + PlayListCache.currChannel = i; + return; + } + } + } + public static void initPlayInfo(String userName,String password) throws Exception{ + String playList = HttpUtils.getPlayList(userName,password); + JSONArray jsonArray = JSON.parseArray(playList); + PlayListCache.groupInfoArray = new String[jsonArray.size() + 1]; + PlayListCache.groupInfoArray[0] = "我的频道"; + if (jsonArray != null && jsonArray.size() > 0) { + for (int i = 0; i < jsonArray.size(); i++) { + JSONObject jo = jsonArray.getJSONObject(i); + //分组 + String group = (String) jo.get("group"); + PlayListCache.groupInfoArray[i + 1] = group; + JSONArray list = jo.getJSONArray("list"); + if (list != null && list.size() > 0) { + ArrayList> hashMaps = new ArrayList>(); + int no = 0; + for (int j = 0; j < list.size(); j++) { + JSONObject o = list.getJSONObject(j); + HashMap m = new HashMap(); + for (String k : o.keySet()) { + String v = (String) o.get(k); + m.put("title", k); + m.put("no", String.valueOf(++no)); + channelInfoList.add(v); + PlayListCache.playListMap.put(k, v); + hashMaps.add(m); + } + } + PlayListCache.groupInfo.put(group, hashMaps); + } + } + } + } +} diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/ServiceSettings.java b/TvPlayer/src/main/java/com/gxf/liveplay/ServiceSettings.java index a7c4821..e396b1b 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/ServiceSettings.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/ServiceSettings.java @@ -1,63 +1,63 @@ -package com.gxf.liveplay; - -import android.content.Context; -import android.content.SharedPreferences; -import android.os.Bundle; -import android.support.design.widget.FloatingActionButton; -import android.support.design.widget.Snackbar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; -import android.widget.Toast; - -public class ServiceSettings extends AppCompatActivity { - - private EditText editText; - private Button saveUrl; - private Button reloadUrl; - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_service_settings); - final SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); - String serviceUrl = userSettings.getString("serviceUrl","none"); - editText = (EditText) findViewById(R.id.serviceUrl); - saveUrl = (Button) findViewById(R.id.saveServiceUrl); - reloadUrl = (Button) findViewById(R.id.reloadServiceUrl); - final Toast toast = Toast.makeText(this, "服务地址提交成功...", Toast.LENGTH_SHORT); - final Toast toast2 = Toast.makeText(this, "服务地址恢复默认值成功...", Toast.LENGTH_SHORT); - //设置默认地址 - if("none".equals(serviceUrl)){ - editText.setText(HttpUtils.apiPathOuter); - }else{ - editText.setText(serviceUrl); - } - saveUrl.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SharedPreferences.Editor editor = userSettings.edit(); - String newUrl = editText.getText().toString(); - editor.putString("serviceUrl",newUrl); - HttpUtils.apiPath = newUrl; - editor.commit(); - toast.show(); - ServiceSettings.this.finish(); - } - }); - reloadUrl.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - SharedPreferences.Editor editor = userSettings.edit(); - editText.setText(HttpUtils.apiPathOuter); - editor.putString("serviceUrl",HttpUtils.apiPathOuter); - HttpUtils.apiPath = HttpUtils.apiPathOuter; - editor.commit(); - toast2.show(); - ServiceSettings.this.finish(); - } - }); - } - -} +package com.gxf.liveplay; + +import android.content.Context; +import android.content.SharedPreferences; +import android.os.Bundle; +import android.support.design.widget.FloatingActionButton; +import android.support.design.widget.Snackbar; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.Toolbar; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +public class ServiceSettings extends AppCompatActivity { + + private EditText editText; + private Button saveUrl; + private Button reloadUrl; + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_service_settings); + final SharedPreferences userSettings = getSharedPreferences("auth", Context.MODE_PRIVATE); + String serviceUrl = userSettings.getString("serviceUrl","none"); + editText = (EditText) findViewById(R.id.serviceUrl); + saveUrl = (Button) findViewById(R.id.saveServiceUrl); + reloadUrl = (Button) findViewById(R.id.reloadServiceUrl); + final Toast toast = Toast.makeText(this, "服务地址提交成功...", Toast.LENGTH_SHORT); + final Toast toast2 = Toast.makeText(this, "服务地址恢复默认值成功...", Toast.LENGTH_SHORT); + //设置默认地址 + if("none".equals(serviceUrl)){ + editText.setText(HttpUtils.apiPathOuter); + }else{ + editText.setText(serviceUrl); + } + saveUrl.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = userSettings.edit(); + String newUrl = editText.getText().toString(); + editor.putString("serviceUrl",newUrl); + HttpUtils.apiPath = newUrl; + editor.commit(); + toast.show(); + ServiceSettings.this.finish(); + } + }); + reloadUrl.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = userSettings.edit(); + editText.setText(HttpUtils.apiPathOuter); + editor.putString("serviceUrl",HttpUtils.apiPathOuter); + HttpUtils.apiPath = HttpUtils.apiPathOuter; + editor.commit(); + toast2.show(); + ServiceSettings.this.finish(); + } + }); + } + +} diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/update/CallBack.java b/TvPlayer/src/main/java/com/gxf/liveplay/update/CallBack.java index e582724..ff8c06e 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/update/CallBack.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/update/CallBack.java @@ -1,9 +1,9 @@ -package com.gxf.liveplay.update; - -/** - * Created by gongxufan on 2017/9/6. - */ - -public interface CallBack { - public void callback(int position); -} +package com.gxf.liveplay.update; + +/** + * Created by gongxufan on 2017/9/6. + */ + +public interface CallBack { + public void callback(int position); +} diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/update/ConfirmDialog.java b/TvPlayer/src/main/java/com/gxf/liveplay/update/ConfirmDialog.java index 596f3fb..3110962 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/update/ConfirmDialog.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/update/ConfirmDialog.java @@ -1,57 +1,57 @@ -package com.gxf.liveplay.update; - -import android.app.Dialog; -import android.content.Context; -import android.view.LayoutInflater; -import android.view.View; -import android.widget.Button; -import android.widget.TextView; - -import com.gxf.liveplay.R; - - -public class ConfirmDialog extends Dialog { - - CallBack callback; - private TextView content; - private Button sureBtn; - private Button cancleBtn; - - public ConfirmDialog(Context context, CallBack callback) { - super(context, R.style.CustomDialog); - this.callback = callback; - setCustomDialog(); - } - - private void setCustomDialog() { - View mView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_confirm, null); - sureBtn = (Button)mView.findViewById(R.id.dialog_confirm_sure); - cancleBtn = (Button)mView.findViewById(R.id.dialog_confirm_cancle); - content = (TextView) mView.findViewById(R.id.dialog_confirm_title); - - - sureBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - callback.callback(1); - ConfirmDialog.this.cancel(); - } - }); - cancleBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - callback.callback(0); - ConfirmDialog.this.cancel(); - } - }); - super.setContentView(mView); - } - - - public ConfirmDialog setContent(String s){ - content.setText(s); - return this; - } - - -} +package com.gxf.liveplay.update; + +import android.app.Dialog; +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.widget.Button; +import android.widget.TextView; + +import com.gxf.liveplay.R; + + +public class ConfirmDialog extends Dialog { + + CallBack callback; + private TextView content; + private Button sureBtn; + private Button cancleBtn; + + public ConfirmDialog(Context context, CallBack callback) { + super(context, R.style.CustomDialog); + this.callback = callback; + setCustomDialog(); + } + + private void setCustomDialog() { + View mView = LayoutInflater.from(getContext()).inflate(R.layout.dialog_confirm, null); + sureBtn = (Button)mView.findViewById(R.id.dialog_confirm_sure); + cancleBtn = (Button)mView.findViewById(R.id.dialog_confirm_cancle); + content = (TextView) mView.findViewById(R.id.dialog_confirm_title); + + + sureBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + callback.callback(1); + ConfirmDialog.this.cancel(); + } + }); + cancleBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + callback.callback(0); + ConfirmDialog.this.cancel(); + } + }); + super.setContentView(mView); + } + + + public ConfirmDialog setContent(String s){ + content.setText(s); + return this; + } + + +} diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/update/DownloadAppUtils.java b/TvPlayer/src/main/java/com/gxf/liveplay/update/DownloadAppUtils.java index ac7a825..3ef0bfb 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/update/DownloadAppUtils.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/update/DownloadAppUtils.java @@ -1,90 +1,90 @@ -package com.gxf.liveplay.update; - -import android.app.DownloadManager; -import android.content.Context; -import android.content.Intent; -import android.content.IntentFilter; -import android.net.Uri; -import android.os.Environment; -import android.text.TextUtils; -import android.util.Log; - -import com.gxf.liveplay.LiveActivityRel; - -import java.io.File; - - - -public class DownloadAppUtils { - private static final String TAG = DownloadAppUtils.class.getSimpleName(); - public static long downloadUpdateApkId = -1;//下载更新Apk 下载任务对应的Id - public static String downloadUpdateApkFilePath;//下载更新Apk 文件路径 - - /** - * 通过浏览器下载APK包 - * @param context - * @param url - */ - public static void downloadForWebView(Context context, String url) { - Uri uri = Uri.parse(url); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(intent); - } - - - /** - * 下载更新apk包 - * 权限:1, - * @param context - * @param url - */ - public static void downloadForAutoInstall(Context context, String url, String fileName, String title) { - if (TextUtils.isEmpty(url)) { - return; - } - try { - Uri uri = Uri.parse(url); - DownloadManager downloadManager = (DownloadManager) context - .getSystemService(Context.DOWNLOAD_SERVICE); - DownloadManager.Request request = new DownloadManager.Request(uri); - //在通知栏中显示 - request.setVisibleInDownloadsUi(true); - request.setTitle(title); - - // VISIBILITY_VISIBLE: 下载过程中可见, 下载完后自动消失 (默认) - // VISIBILITY_VISIBLE_NOTIFY_COMPLETED: 下载过程中和下载完成后均可见 - // VISIBILITY_HIDDEN: 始终不显示通知 - if (!UpdateAppUtils.showNotification) - request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN); - - - - String filePath = null; - if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {//外部存储卡 - filePath = Environment.getExternalStorageDirectory().getAbsolutePath(); - } else { - Log.i(TAG,"没有SD卡"); - return; - } - - downloadUpdateApkFilePath = filePath + File.separator + fileName; - deleteFile(downloadUpdateApkFilePath);// 若存在,则删除 - Uri fileUri = Uri.fromFile(new File(downloadUpdateApkFilePath)); - request.setDestinationUri(fileUri); - downloadUpdateApkId = downloadManager.enqueue(request); - - } catch (Exception e) { - e.printStackTrace(); - downloadForWebView(context, url); - }finally { - - } - } - - - private static boolean deleteFile(String fileStr) { - File file = new File(fileStr); - return file.delete(); - } -} +package com.gxf.liveplay.update; + +import android.app.DownloadManager; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.net.Uri; +import android.os.Environment; +import android.text.TextUtils; +import android.util.Log; + +import com.gxf.liveplay.LiveActivityRel; + +import java.io.File; + + + +public class DownloadAppUtils { + private static final String TAG = DownloadAppUtils.class.getSimpleName(); + public static long downloadUpdateApkId = -1;//下载更新Apk 下载任务对应的Id + public static String downloadUpdateApkFilePath;//下载更新Apk 文件路径 + + /** + * 通过浏览器下载APK包 + * @param context + * @param url + */ + public static void downloadForWebView(Context context, String url) { + Uri uri = Uri.parse(url); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + + + /** + * 下载更新apk包 + * 权限:1, + * @param context + * @param url + */ + public static void downloadForAutoInstall(Context context, String url, String fileName, String title) { + if (TextUtils.isEmpty(url)) { + return; + } + try { + Uri uri = Uri.parse(url); + DownloadManager downloadManager = (DownloadManager) context + .getSystemService(Context.DOWNLOAD_SERVICE); + DownloadManager.Request request = new DownloadManager.Request(uri); + //在通知栏中显示 + request.setVisibleInDownloadsUi(true); + request.setTitle(title); + + // VISIBILITY_VISIBLE: 下载过程中可见, 下载完后自动消失 (默认) + // VISIBILITY_VISIBLE_NOTIFY_COMPLETED: 下载过程中和下载完成后均可见 + // VISIBILITY_HIDDEN: 始终不显示通知 + if (!UpdateAppUtils.showNotification) + request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN); + + + + String filePath = null; + if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {//外部存储卡 + filePath = Environment.getExternalStorageDirectory().getAbsolutePath(); + } else { + Log.i(TAG,"没有SD卡"); + return; + } + + downloadUpdateApkFilePath = filePath + File.separator + fileName; + deleteFile(downloadUpdateApkFilePath);// 若存在,则删除 + Uri fileUri = Uri.fromFile(new File(downloadUpdateApkFilePath)); + request.setDestinationUri(fileUri); + downloadUpdateApkId = downloadManager.enqueue(request); + + } catch (Exception e) { + e.printStackTrace(); + downloadForWebView(context, url); + }finally { + + } + } + + + private static boolean deleteFile(String fileStr) { + File file = new File(fileStr); + return file.delete(); + } +} diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/update/UpdateAppReceiver.java b/TvPlayer/src/main/java/com/gxf/liveplay/update/UpdateAppReceiver.java index 8495257..509912b 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/update/UpdateAppReceiver.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/update/UpdateAppReceiver.java @@ -1,67 +1,67 @@ -package com.gxf.liveplay.update; - -import android.app.DownloadManager; -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.database.Cursor; -import android.net.Uri; -import android.os.Build; -import android.support.v4.content.FileProvider; - -import java.io.File; - - -/** - * 注册 - * - * - */ -public class UpdateAppReceiver extends BroadcastReceiver { - public UpdateAppReceiver() { - } - - @Override - public void onReceive(Context context, Intent intent) { - // 处理下载完成 - Cursor c = null; - - if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) { - if (DownloadAppUtils.downloadUpdateApkId >= 0) { - long downloadId = DownloadAppUtils.downloadUpdateApkId; - DownloadManager.Query query = new DownloadManager.Query(); - query.setFilterById(downloadId); - DownloadManager downloadManager = (DownloadManager) context - .getSystemService(Context.DOWNLOAD_SERVICE); - c = downloadManager.query(query); - if (c.moveToFirst()) { - int status = c.getInt(c - .getColumnIndex(DownloadManager.COLUMN_STATUS)); - if (status == DownloadManager.STATUS_FAILED) { - downloadManager.remove(downloadId); - - } else if (status == DownloadManager.STATUS_SUCCESSFUL) { - if (DownloadAppUtils.downloadUpdateApkFilePath != null) { - Intent i = new Intent(Intent.ACTION_VIEW); - File apkFile = new File(DownloadAppUtils.downloadUpdateApkFilePath); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - Uri contentUri = FileProvider.getUriForFile( - context, context.getPackageName() + ".fileprovider", apkFile); - i.setDataAndType(contentUri, "application/vnd.android.package-archive"); - } else { - i.setDataAndType(Uri.fromFile(apkFile), - "application/vnd.android.package-archive"); - } - i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - context.startActivity(i); - } - } - } - c.close(); - } - } - - - } -} +package com.gxf.liveplay.update; + +import android.app.DownloadManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.net.Uri; +import android.os.Build; +import android.support.v4.content.FileProvider; + +import java.io.File; + + +/** + * 注册 + * + * + */ +public class UpdateAppReceiver extends BroadcastReceiver { + public UpdateAppReceiver() { + } + + @Override + public void onReceive(Context context, Intent intent) { + // 处理下载完成 + Cursor c = null; + + if (DownloadManager.ACTION_DOWNLOAD_COMPLETE.equals(intent.getAction())) { + if (DownloadAppUtils.downloadUpdateApkId >= 0) { + long downloadId = DownloadAppUtils.downloadUpdateApkId; + DownloadManager.Query query = new DownloadManager.Query(); + query.setFilterById(downloadId); + DownloadManager downloadManager = (DownloadManager) context + .getSystemService(Context.DOWNLOAD_SERVICE); + c = downloadManager.query(query); + if (c.moveToFirst()) { + int status = c.getInt(c + .getColumnIndex(DownloadManager.COLUMN_STATUS)); + if (status == DownloadManager.STATUS_FAILED) { + downloadManager.remove(downloadId); + + } else if (status == DownloadManager.STATUS_SUCCESSFUL) { + if (DownloadAppUtils.downloadUpdateApkFilePath != null) { + Intent i = new Intent(Intent.ACTION_VIEW); + File apkFile = new File(DownloadAppUtils.downloadUpdateApkFilePath); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + Uri contentUri = FileProvider.getUriForFile( + context, context.getPackageName() + ".fileprovider", apkFile); + i.setDataAndType(contentUri, "application/vnd.android.package-archive"); + } else { + i.setDataAndType(Uri.fromFile(apkFile), + "application/vnd.android.package-archive"); + } + i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(i); + } + } + } + c.close(); + } + } + + + } +} diff --git a/TvPlayer/src/main/java/com/gxf/liveplay/update/UpdateAppUtils.java b/TvPlayer/src/main/java/com/gxf/liveplay/update/UpdateAppUtils.java index 1320511..ac870a9 100644 --- a/TvPlayer/src/main/java/com/gxf/liveplay/update/UpdateAppUtils.java +++ b/TvPlayer/src/main/java/com/gxf/liveplay/update/UpdateAppUtils.java @@ -1,207 +1,207 @@ -package com.gxf.liveplay.update; - -import android.app.Activity; -import android.content.Context; -import android.content.pm.PackageInfo; -import android.content.pm.PackageManager; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.text.TextUtils; -import android.util.Log; - -public class UpdateAppUtils { - - private final String TAG = "UpdateAppUtils"; - public static final int CHECK_BY_VERSION_NAME = 1001; - public static final int CHECK_BY_VERSION_CODE = 1002; - public static final int DOWNLOAD_BY_APP = 1003; - public static final int DOWNLOAD_BY_BROWSER = 1004; - - private Activity activity; - private int checkBy = CHECK_BY_VERSION_CODE; - private int downloadBy = DOWNLOAD_BY_APP; - private int serverVersionCode = 0; - private String apkPath = ""; - private String serverVersionName = ""; - private boolean isForce = false; //是否强制更新 - private int localVersionCode = 0; - private String localVersionName = ""; - public static boolean showNotification = true; - private String updateInfo = ""; - - - private UpdateAppUtils(Activity activity) { - this.activity = activity; - getAPPLocalVersion(activity); - } - - public static UpdateAppUtils from(Activity activity) { - return new UpdateAppUtils(activity); - } - - public UpdateAppUtils checkBy(int checkBy) { - this.checkBy = checkBy; - return this; - } - - public UpdateAppUtils apkPath(String apkPath) { - this.apkPath = apkPath; - return this; - } - - public UpdateAppUtils downloadBy(int downloadBy) { - this.downloadBy = downloadBy; - return this; - } - - public UpdateAppUtils showNotification(boolean showNotification) { - this.showNotification = showNotification; - return this; - } - - public UpdateAppUtils updateInfo(String updateInfo) { - this.updateInfo = updateInfo; - return this; - } - - - public UpdateAppUtils serverVersionCode(int serverVersionCode) { - this.serverVersionCode = serverVersionCode; - return this; - } - - public UpdateAppUtils serverVersionName(String serverVersionName) { - this.serverVersionName = serverVersionName; - return this; - } - - public UpdateAppUtils isForce(boolean isForce) { - this.isForce = isForce; - return this; - } - - //获取apk的版本号 currentVersionCode - private void getAPPLocalVersion(Context ctx) { - PackageManager manager = ctx.getPackageManager(); - try { - PackageInfo info = manager.getPackageInfo(ctx.getPackageName(), 0); - localVersionName = info.versionName; // 版本名 - localVersionCode = info.versionCode; // 版本号 - } catch (PackageManager.NameNotFoundException e) { - e.printStackTrace(); - } - } - - public void update() { - - switch (checkBy) { - case CHECK_BY_VERSION_CODE: - if (serverVersionCode > localVersionCode) { - toUpdate(); - } else { - Log.i(TAG, "当前版本是最新版本" + serverVersionCode + "/" + serverVersionName); - } - break; - - case CHECK_BY_VERSION_NAME: - if (serverVersionName.compareTo(localVersionName) > 0) { - toUpdate(); - } else { - Log.i(TAG, "当前版本是最新版本" + serverVersionCode + "/" + serverVersionName); - } - break; - } - - } - - private void toUpdate() { - - realUpdate(); - - //尝试在内部适配6.0 -// if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) -// == PackageManager.PERMISSION_GRANTED){ -// realUpdate(); -// }else {//申请权限 -// ActivityCompat.requestPermissions(activity, -// new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},1); -// } - - } - - private void realUpdate() { - ConfirmDialog dialog = new ConfirmDialog(activity, new CallBack() { - @Override - public void callback(int position) { - switch (position) { - case 0: //cancle - if (isForce) activity.finish(); - break; - - case 1: //sure - if (downloadBy == DOWNLOAD_BY_APP) { - if (isWifiConnected(activity)) { - DownloadAppUtils.downloadForAutoInstall(activity, apkPath, "demo.apk", serverVersionName); - } else { - new ConfirmDialog(activity, new CallBack() { - @Override - public void callback(int position) { - if (position == 1) { - DownloadAppUtils.downloadForAutoInstall(activity, apkPath, "demo.apk", serverVersionName); - } else { - if (isForce) activity.finish(); - } - } - }).setContent("目前您的设备不是WiFi状态\n确认是否继续下载更新?").show(); - } - - } else if (downloadBy == DOWNLOAD_BY_BROWSER) { - DownloadAppUtils.downloadForWebView(activity, apkPath); - } - break; - } - } - }); - - String content = "发现新版本:" + serverVersionName + "\n是否下载更新?"; - if (!TextUtils.isEmpty(updateInfo)) { - content = "发现新版本:" + serverVersionName + "是否下载更新?\n\n" + updateInfo; - } - dialog.setContent(content); - dialog.setCancelable(false); - dialog.show(); - } - - - //尝试在内部适配6.0 可能会引起内存泄露 -// public static void onRequestPermissionsResult(int requestCode, -// @NonNull String[] permissions, -// @NonNull int[] grantResults){ -// switch (requestCode){ -// case 1: -// if (grantResults[0] == PackageManager.PERMISSION_GRANTED){ -//// realUpdate(); -// mHandler.sendEmptyMessage(1); -// }else { -// //提示用户没有授予权限 -// } -// break; -// } -// } - - - /** - * 检测wifi是否连接 - */ - public static boolean isWifiConnected(Context context) { - ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); - if (cm != null) { - NetworkInfo networkInfo = cm.getActiveNetworkInfo(); - if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { - return true; - } - } - return false; - } - -} +package com.gxf.liveplay.update; + +import android.app.Activity; +import android.content.Context; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.text.TextUtils; +import android.util.Log; + +public class UpdateAppUtils { + + private final String TAG = "UpdateAppUtils"; + public static final int CHECK_BY_VERSION_NAME = 1001; + public static final int CHECK_BY_VERSION_CODE = 1002; + public static final int DOWNLOAD_BY_APP = 1003; + public static final int DOWNLOAD_BY_BROWSER = 1004; + + private Activity activity; + private int checkBy = CHECK_BY_VERSION_CODE; + private int downloadBy = DOWNLOAD_BY_APP; + private int serverVersionCode = 0; + private String apkPath = ""; + private String serverVersionName = ""; + private boolean isForce = false; //是否强制更新 + private int localVersionCode = 0; + private String localVersionName = ""; + public static boolean showNotification = true; + private String updateInfo = ""; + + + private UpdateAppUtils(Activity activity) { + this.activity = activity; + getAPPLocalVersion(activity); + } + + public static UpdateAppUtils from(Activity activity) { + return new UpdateAppUtils(activity); + } + + public UpdateAppUtils checkBy(int checkBy) { + this.checkBy = checkBy; + return this; + } + + public UpdateAppUtils apkPath(String apkPath) { + this.apkPath = apkPath; + return this; + } + + public UpdateAppUtils downloadBy(int downloadBy) { + this.downloadBy = downloadBy; + return this; + } + + public UpdateAppUtils showNotification(boolean showNotification) { + this.showNotification = showNotification; + return this; + } + + public UpdateAppUtils updateInfo(String updateInfo) { + this.updateInfo = updateInfo; + return this; + } + + + public UpdateAppUtils serverVersionCode(int serverVersionCode) { + this.serverVersionCode = serverVersionCode; + return this; + } + + public UpdateAppUtils serverVersionName(String serverVersionName) { + this.serverVersionName = serverVersionName; + return this; + } + + public UpdateAppUtils isForce(boolean isForce) { + this.isForce = isForce; + return this; + } + + //获取apk的版本号 currentVersionCode + private void getAPPLocalVersion(Context ctx) { + PackageManager manager = ctx.getPackageManager(); + try { + PackageInfo info = manager.getPackageInfo(ctx.getPackageName(), 0); + localVersionName = info.versionName; // 版本名 + localVersionCode = info.versionCode; // 版本号 + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + } + } + + public void update() { + + switch (checkBy) { + case CHECK_BY_VERSION_CODE: + if (serverVersionCode > localVersionCode) { + toUpdate(); + } else { + Log.i(TAG, "当前版本是最新版本" + serverVersionCode + "/" + serverVersionName); + } + break; + + case CHECK_BY_VERSION_NAME: + if (serverVersionName.compareTo(localVersionName) > 0) { + toUpdate(); + } else { + Log.i(TAG, "当前版本是最新版本" + serverVersionCode + "/" + serverVersionName); + } + break; + } + + } + + private void toUpdate() { + + realUpdate(); + + //尝试在内部适配6.0 +// if (ContextCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) +// == PackageManager.PERMISSION_GRANTED){ +// realUpdate(); +// }else {//申请权限 +// ActivityCompat.requestPermissions(activity, +// new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},1); +// } + + } + + private void realUpdate() { + ConfirmDialog dialog = new ConfirmDialog(activity, new CallBack() { + @Override + public void callback(int position) { + switch (position) { + case 0: //cancle + if (isForce) activity.finish(); + break; + + case 1: //sure + if (downloadBy == DOWNLOAD_BY_APP) { + if (isWifiConnected(activity)) { + DownloadAppUtils.downloadForAutoInstall(activity, apkPath, "demo.apk", serverVersionName); + } else { + new ConfirmDialog(activity, new CallBack() { + @Override + public void callback(int position) { + if (position == 1) { + DownloadAppUtils.downloadForAutoInstall(activity, apkPath, "demo.apk", serverVersionName); + } else { + if (isForce) activity.finish(); + } + } + }).setContent("目前您的设备不是WiFi状态\n确认是否继续下载更新?").show(); + } + + } else if (downloadBy == DOWNLOAD_BY_BROWSER) { + DownloadAppUtils.downloadForWebView(activity, apkPath); + } + break; + } + } + }); + + String content = "发现新版本:" + serverVersionName + "\n是否下载更新?"; + if (!TextUtils.isEmpty(updateInfo)) { + content = "发现新版本:" + serverVersionName + "是否下载更新?\n\n" + updateInfo; + } + dialog.setContent(content); + dialog.setCancelable(false); + dialog.show(); + } + + + //尝试在内部适配6.0 可能会引起内存泄露 +// public static void onRequestPermissionsResult(int requestCode, +// @NonNull String[] permissions, +// @NonNull int[] grantResults){ +// switch (requestCode){ +// case 1: +// if (grantResults[0] == PackageManager.PERMISSION_GRANTED){ +//// realUpdate(); +// mHandler.sendEmptyMessage(1); +// }else { +// //提示用户没有授予权限 +// } +// break; +// } +// } + + + /** + * 检测wifi是否连接 + */ + public static boolean isWifiConnected(Context context) { + ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + if (cm != null) { + NetworkInfo networkInfo = cm.getActiveNetworkInfo(); + if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) { + return true; + } + } + return false; + } + +} diff --git a/TvPlayer/src/main/res/drawable/bg_dialog_confirm.xml b/TvPlayer/src/main/res/drawable/bg_dialog_confirm.xml index 6b79e7f..01756a7 100644 --- a/TvPlayer/src/main/res/drawable/bg_dialog_confirm.xml +++ b/TvPlayer/src/main/res/drawable/bg_dialog_confirm.xml @@ -1,9 +1,9 @@ - - - - - - - + + + + + + + \ No newline at end of file diff --git a/TvPlayer/src/main/res/drawable/tv_switch_bg_left.xml b/TvPlayer/src/main/res/drawable/tv_switch_bg_left.xml index b049ee2..a6c2a3b 100644 --- a/TvPlayer/src/main/res/drawable/tv_switch_bg_left.xml +++ b/TvPlayer/src/main/res/drawable/tv_switch_bg_left.xml @@ -1,9 +1,9 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/TvPlayer/src/main/res/drawable/tv_switch_bg_right.xml b/TvPlayer/src/main/res/drawable/tv_switch_bg_right.xml index 12a55d8..685effe 100644 --- a/TvPlayer/src/main/res/drawable/tv_switch_bg_right.xml +++ b/TvPlayer/src/main/res/drawable/tv_switch_bg_right.xml @@ -1,8 +1,8 @@ - - - - - + + + + + \ No newline at end of file diff --git a/TvPlayer/src/main/res/layout/activity_login.xml b/TvPlayer/src/main/res/layout/activity_login.xml index 321037d..1f10f6c 100644 --- a/TvPlayer/src/main/res/layout/activity_login.xml +++ b/TvPlayer/src/main/res/layout/activity_login.xml @@ -1,101 +1,101 @@ - - - - - - - - - - - - - - - -