1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package net.sourceforge.subsonic.androidapp.activity; |
21 |
|
|
22 |
|
import java.lang.reflect.Method; |
23 |
|
|
24 |
|
import android.app.Activity; |
25 |
|
import android.graphics.Bitmap; |
26 |
|
import android.media.AudioManager; |
27 |
|
import android.os.Bundle; |
28 |
|
import android.util.Log; |
29 |
|
import android.view.Window; |
30 |
|
import android.webkit.WebView; |
31 |
|
import android.webkit.WebViewClient; |
32 |
|
import android.content.pm.PackageInfo; |
33 |
|
import android.content.pm.PackageManager; |
34 |
|
import net.sourceforge.subsonic.androidapp.R; |
35 |
|
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory; |
36 |
|
import net.sourceforge.subsonic.androidapp.util.Constants; |
37 |
|
import net.sourceforge.subsonic.androidapp.util.Util; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@author |
43 |
|
|
|
|
| 0% |
Uncovered Elements: 46 (46) |
Complexity: 12 |
Complexity Density: 0,36 |
|
44 |
|
public final class PlayVideoActivity extends Activity { |
45 |
|
|
46 |
|
private static final String TAG = PlayVideoActivity.class.getSimpleName(); |
47 |
|
private WebView webView; |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 3 |
Complexity Density: 0,18 |
|
49 |
0
|
@Override... |
50 |
|
protected void onCreate(Bundle bundle) { |
51 |
0
|
super.onCreate(bundle); |
52 |
0
|
getWindow().requestFeature(Window.FEATURE_NO_TITLE); |
53 |
0
|
setVolumeControlStream(AudioManager.STREAM_MUSIC); |
54 |
|
|
55 |
0
|
setContentView(R.layout.play_video); |
56 |
|
|
57 |
0
|
webView = (WebView) findViewById(R.id.play_video_contents); |
58 |
0
|
webView.getSettings().setJavaScriptEnabled(true); |
59 |
0
|
webView.getSettings().setPluginsEnabled(true); |
60 |
0
|
webView.getSettings().setAllowFileAccess(true); |
61 |
0
|
webView.getSettings().setSupportZoom(true); |
62 |
0
|
webView.getSettings().setBuiltInZoomControls(true); |
63 |
|
|
64 |
0
|
webView.setWebViewClient(new Client()); |
65 |
0
|
if (bundle != null) { |
66 |
0
|
webView.restoreState(bundle); |
67 |
|
} else { |
68 |
0
|
webView.loadUrl(getVideoUrl()); |
69 |
|
} |
70 |
|
|
71 |
|
|
72 |
0
|
if (isFlashPluginInstalled()) { |
73 |
0
|
Util.toast(this, R.string.play_video_loading, false); |
74 |
|
} else { |
75 |
0
|
Util.toast(this, R.string.play_video_noplugin, false); |
76 |
|
} |
77 |
|
} |
78 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
79 |
0
|
@Override... |
80 |
|
protected void onPause() { |
81 |
0
|
super.onPause(); |
82 |
0
|
callHiddenWebViewMethod("onPause"); |
83 |
|
} |
84 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
85 |
0
|
@Override... |
86 |
|
protected void onResume() { |
87 |
0
|
super.onResume(); |
88 |
0
|
callHiddenWebViewMethod("onResume"); |
89 |
|
} |
90 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
91 |
0
|
private String getVideoUrl() {... |
92 |
0
|
String id = getIntent().getStringExtra(Constants.INTENT_EXTRA_NAME_ID); |
93 |
0
|
return MusicServiceFactory.getMusicService(this).getVideoUrl(this, id); |
94 |
|
} |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
96 |
0
|
@Override... |
97 |
|
protected void onSaveInstanceState(Bundle state) { |
98 |
0
|
webView.saveState(state); |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0,6 |
|
101 |
0
|
private void callHiddenWebViewMethod(String name){... |
102 |
0
|
if( webView != null ){ |
103 |
0
|
try { |
104 |
0
|
Method method = WebView.class.getMethod(name); |
105 |
0
|
method.invoke(webView); |
106 |
|
} catch (Throwable x) { |
107 |
0
|
Log.e(TAG, "Failed to invoke " + name, x); |
108 |
|
} |
109 |
|
} |
110 |
|
} |
111 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0,5 |
|
112 |
0
|
private boolean isFlashPluginInstalled() {... |
113 |
0
|
try { |
114 |
0
|
PackageInfo packageInfo = getPackageManager().getPackageInfo("com.adobe.flashplayer", 0); |
115 |
0
|
return packageInfo != null; |
116 |
|
} catch (PackageManager.NameNotFoundException x) { |
117 |
0
|
return false; |
118 |
|
} |
119 |
|
} |
120 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0,5 |
|
121 |
|
private final class Client extends WebViewClient { |
122 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
123 |
0
|
@Override... |
124 |
|
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { |
125 |
0
|
Util.toast(PlayVideoActivity.this, description); |
126 |
0
|
Log.e(TAG, "Error: " + description); |
127 |
|
} |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
129 |
0
|
@Override... |
130 |
|
public void onLoadResource(WebView view, String url) { |
131 |
0
|
super.onLoadResource(view, url); |
132 |
0
|
Log.d(TAG, "onLoadResource: " + url); |
133 |
|
} |
134 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
135 |
0
|
@Override... |
136 |
|
public void onPageStarted(WebView view, String url, Bitmap favicon) { |
137 |
0
|
super.onPageStarted(view, url, favicon); |
138 |
0
|
Log.d(TAG, "onPageStarted: " + url); |
139 |
|
} |
140 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
141 |
0
|
@Override... |
142 |
|
public void onPageFinished(WebView view, String url) { |
143 |
0
|
super.onPageFinished(view, url); |
144 |
0
|
Log.d(TAG, "onPageFinished: " + url); |
145 |
|
} |
146 |
|
} |
147 |
|
} |