Clover Coverage Report - Subsonic-Android Coverage Report
Coverage timestamp: ven dic 19 2014 17:57:13 EST
../../../../../img/srcFileCovDistChart0.png 86% of files have more coverage
41   147   16   3,73
6   102   0,39   5,5
11     1,45  
2    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  PlayVideoActivity       Line # 44 33 12 0% 0.0
  PlayVideoActivity.Client       Line # 121 8 4 0% 0.0
 
No Tests
 
1    /*
2    This file is part of Subsonic.
3   
4    Subsonic is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8   
9    Subsonic is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12    GNU General Public License for more details.
13   
14    You should have received a copy of the GNU General Public License
15    along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
16   
17    Copyright 2009 (C) Sindre Mehus
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    * Plays videos in a web page.
41    *
42    * @author Sindre Mehus
43    */
 
44    public final class PlayVideoActivity extends Activity {
45   
46    private static final String TAG = PlayVideoActivity.class.getSimpleName();
47    private WebView webView;
48   
 
49  0 toggle @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    // Show warning if Flash plugin is not installed.
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   
 
79  0 toggle @Override
80    protected void onPause() {
81  0 super.onPause();
82  0 callHiddenWebViewMethod("onPause");
83    }
84   
 
85  0 toggle @Override
86    protected void onResume() {
87  0 super.onResume();
88  0 callHiddenWebViewMethod("onResume");
89    }
90   
 
91  0 toggle 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   
 
96  0 toggle @Override
97    protected void onSaveInstanceState(Bundle state) {
98  0 webView.saveState(state);
99    }
100   
 
101  0 toggle 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   
 
112  0 toggle 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   
 
121    private final class Client extends WebViewClient {
122   
 
123  0 toggle @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   
 
129  0 toggle @Override
130    public void onLoadResource(WebView view, String url) {
131  0 super.onLoadResource(view, url);
132  0 Log.d(TAG, "onLoadResource: " + url);
133    }
134   
 
135  0 toggle @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   
 
141  0 toggle @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    }