Commit c8165ffa authored by Steve Johnson's avatar Steve Johnson

minor cleanup

parent 8890520c
......@@ -13,10 +13,11 @@
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
......@@ -37,34 +38,51 @@
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
</content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="appcompat-v7-19.0.0" level="project" />
<orderEntry type="library" exported="" name="mediarouter-v7-19.0.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-19.1.0" level="project" />
<orderEntry type="library" exported="" name="play-services-5.0.89" level="project" />
<orderEntry type="library" exported="" name="support-v4-19.0.0" level="project" />
<orderEntry type="library" exported="" name="commons-lang3-3.1" level="project" />
</component>
</module>
......@@ -2,12 +2,15 @@ apply plugin: 'android'
android {
compileSdkVersion 19
//compileSdkVersion 17
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.cablelabs.android.dial"
minSdkVersion 19
targetSdkVersion 19
//minSdkVersion 17
//targetSdkVersion 17
}
buildTypes {
......@@ -19,13 +22,7 @@ android {
}
dependencies {
//compile files('libs/android-support-v4.jar')
//compile files('libs/libGoogleAnalyticsV2.jar')
//compile 'com.google.android.gms:play-services:+'
//compile 'com.android.support:mediarouter-v7:+'
compile 'com.android.support:support-v4:19.0.0'
compile 'com.android.support:appcompat-v7:19.0.0'
compile 'com.android.support:mediarouter-v7:19.0.0'
compile 'com.google.android.gms:play-services:5.0.89'
compile 'org.apache.commons:commons-lang3:3.1'
}
......@@ -18,22 +18,16 @@
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
<!--meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /-->
<activity
android:name="com.cablelabs.android.dial.MainActivity"
android:hardwareAccelerated="true"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.cablelabs.android.dial.SettingsActivity"
android:label="@string/app_name" >cp
<!--intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter-->
</activity>
</application>
</manifest>
\ No newline at end of file
......@@ -116,11 +116,12 @@ public class HttpServer extends NanoHTTPD {
else if (method == Method.GET) {
// We currently support 3 requests - device description, config, and app status.
if (uri.equals(MSEConfig.CONFIG)) {
String msg = "<html><head><style>body { font-family:'Arial', 'Helvetica', sans-serif; }</style></head><body><center><h1>MSE Dial Server Configuration</h1></center>\n";
String msg = "<html><head><style>body { margin: 50px; font-family:'Arial', 'Helvetica', sans-serif; }</style></head><body><h1>MSE Dial Server Configuration</h1>\n";
Map<String, String> parms = session.getParms();
if (parms.get("friendlyName") != null) {
setFriendlyName(parms.get("friendlyName"));
setDeviceType(parms.get("deviceType"));
Message notify = Message.obtain();
notify.what = REFRESH_HOMEPAGE;
......@@ -131,9 +132,11 @@ public class HttpServer extends NanoHTTPD {
String value = getFriendlyName();
msg += "<center><form action='?' method='get'>\n" +
"<p>TV Name: <input type='text' name='friendlyName' value=\""+value+"\"></p>\n" +
"</form></center>\n";
msg += "<form action='?' method='get'>\n" +
"<p>Device Type: <input type='text' name='deviceType' value=\""+getDeviceType()+"\"></p>\n" +
"<p>TV Name: <input type='text' name='friendlyName' value=\""+getFriendlyName()+"\"></p>\n" +
"<input type='submit' value='Update'>" +
"</form>\n";
msg += "</body></html>\n";
......@@ -201,6 +204,21 @@ public class HttpServer extends NanoHTTPD {
editor.commit();
}
public String getDeviceType() {
String defaultType = "Toshiba TZ5000";
Context context = mainActivity.getApplicationContext();
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
return settings.getString("deviceType", defaultType);
}
private void setDeviceType(String type) {
Context context = mainActivity.getApplicationContext();
SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("deviceType", type);
editor.commit();
}
//public static void main(String[] args) {
//ServerRunner.run(HttpServer.class);
......
......@@ -23,46 +23,31 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import java.io.IOException;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.google.android.gms.cast.CastDevice;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import java.util.Timer;
import java.util.TimerTask;
/**
* DIAL protocol client:
* http://www.dial-multiscreen.org/dial-protocol-specification
*
* @author leon_nicholls
*
* 8/2014 - Steve Johnson - adapted code to be used as mseclient, added Chromecast support
*
*/
import android.webkit.WebChromeClient;
import at.maui.cheapcast.ssdp.SSDP;
public class MainActivity extends Activity {
private static final String LOG_TAG = "MainActivity";
public static final String PREFS_NAME = "preferences";
private static final int RESULT_SETTINGS = 1;
private boolean firstRun = true;
private SSDP ssdp;
private Thread ssdpThread;
private HttpServer httpServer;
/**
* Request code used by this activity.
*/
private ChromecastDiscovery chromecastDiscovery;
private DialDiscovery dialDiscovery;
private DialServer[] dialServers;
private boolean guestMode = false;
private boolean disableCache = false;
private String deviceID = null;
// TODO: Bridge discovery
private String wsBridge = null;
private WifiManager wifiManager;
SharedPreferences.OnSharedPreferenceChangeListener myPrefListner = new SharedPreferences.OnSharedPreferenceChangeListener() {
......@@ -87,11 +72,9 @@ public class MainActivity extends Activity {
setContentView(R.layout.activity_main);
WebView myWebView = (WebView) findViewById(R.id.webview);
//myWebView.clearCache(true);
//dialServers = new DialServer[0];
// TODO: Splash screen..
myWebView.setWebChromeClient(new WebChromeClient());
myWebView.getSettings().setMediaPlaybackRequiresUserGesture(false);
myWebView.clearCache(true);
// Prevent android from opening redirect urls in external browser
myWebView.setWebViewClient(new WebViewClient() {
......@@ -99,13 +82,6 @@ public class MainActivity extends Activity {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
//public void onPageFinished(WebView view, String url) {
//String jsExp = "javascript:document.body.innerHTML+=\"<div style=\\\"position: absolute; top: 83%; left: 5%; color: white; opacity: .3; font-family:'Arial', 'Helvetica', sans-serif; font-weight: '100'; font-size: 135%;\\\"><p>Toshiba TZ5000 - Living Room</p></div>\"";
//Log.d(LOG_TAG,jsExp);
//view.loadUrl(jsExp);
//}
});
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
......@@ -113,36 +89,25 @@ public class MainActivity extends Activity {
}
myWebView.getSettings().setJavaScriptEnabled(true);
//myWebView.addJavascriptInterface(new JavaScriptBridge(this), "proxyObject");
//loadPreferences();
navigateHome();
/*
int resultCode = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
if (resultCode == ConnectionResult.SUCCESS) {
dialDiscovery = new DialDiscovery(this);
dialDiscovery.startDiscovery();
chromecastDiscovery = new ChromecastDiscovery(this);
chromecastDiscovery.startDiscovery();
wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(myPrefListner);
navigateHome();
// Start SSDP
try {
ssdp = new SSDP(getApplicationContext());
ssdpThread = new Thread(ssdp);
ssdpThread.start();
} catch (IOException e) {
Log.e(LOG_TAG, "SSDP exception: ", e);
}
} else if (resultCode == ConnectionResult.SERVICE_MISSING ||
resultCode == ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED ||
resultCode == ConnectionResult.SERVICE_DISABLED) {
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(resultCode, this, 1);
dialog.show();
httpServer = new HttpServer(this);
try {
httpServer.start();
} catch(IOException ioe) {
Log.w("Httpd", "The server could not start.");
}
*/
Log.w("Httpd", "Web server initialized.");
navigateHome();
}
/*
......@@ -156,38 +121,30 @@ public class MainActivity extends Activity {
return true;
}
/*
* Menu selection
*
* @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
*/
public Handler _handler = new Handler() {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
public void handleMessage(Message msg) {
case R.id.menu_settings:
startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
break;
}
if (msg.what == HttpServer.LAUNCH_APPLICATION) {
return true; }
Log.d(LOG_TAG, "Received Launch Application. Url: " + msg.obj);
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl((String)msg.obj);
MSEState.appStatus = MSE.AppStatus.RUNNING;
public Handler _handler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == DialDiscovery.SERVER_LIST_UPDATE) {
Log.d(LOG_TAG, "Received DIAL Server List Update:");
DialServer [] servers = (DialServer[])msg.obj;
for (DialServer server : servers) {
Log.d(LOG_TAG, String.format(" - %s", server.getFriendlyName()));
}
dialServers = servers;
//navigateHome();
//setRemoteDeviceList();
else if (msg.what == HttpServer.KILL_APPLICATION) {
Log.d(LOG_TAG, "Received Kill Application");
navigateHome();
}
else if (msg.what == HttpServer.REFRESH_HOMEPAGE) {
Log.d(LOG_TAG, "Received Refresh Homepage");
if (MSEState.appStatus == MSE.AppStatus.STOPPED) {
navigateHome();
}
else if (msg.what == ChromecastDiscovery.DEVICE_LIST_UPDATE) {
Log.d(LOG_TAG, "Received Chromecast Device List Update:");
//setRemoteDeviceList();
}
super.handleMessage(msg);
......@@ -195,13 +152,18 @@ public class MainActivity extends Activity {
};
public void navigateHome() {
WebView myWebView = (WebView) findViewById(R.id.webview);
// TODO: Read device name from settings and pass in url.
//myWebView.loadUrl("http://10.4.10.32/test/tz5000.html");
myWebView.loadUrl("https://html5.cablelabs.com/mse/tz5000.html");
String url = "https://html5.cablelabs.com/mse/tz5000.html?friendlyName="+httpServer.getFriendlyName()+"&deviceType="+httpServer.getDeviceType();
if (firstRun) {
firstRun = false;
url += "&host="+MSEState.ipaddr+":"+MSEConfig.PORT;
}
MSEState.appStatus = MSE.AppStatus.STOPPED;
//10.4.0.133
myWebView.loadUrl(url);
}
private boolean isSimulator() {
......
package com.cablelabs.android.dial;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
/**
* Created by svenyonson on 8/19/14.
*/
public class SettingsActivity extends PreferenceActivity {
//private SharedPreferences.OnSharedPreferenceChangeListener listener;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
//@Override
//public void onBuildHeaders(List<Header> target) {
// loadHeadersFromResource(R.xml.preference_headers, target);
//}
}
package com.cablelabs.android.dial;
/**
* Created by svenyonson on 8/19/14.
*/
import android.os.Bundle;
import android.preference.PreferenceFragment;
import com.cablelabs.android.dial.R;
public class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
//int res=getActivity().getResources().getIdentifier(getArguments().getString("resource"), "xml", getActivity().getPackageName());
//addPreferencesFromResource(res);
}
//...
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment