tv增加geckoview内核
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
package com.moontvplus.tv;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import org.mozilla.geckoview.GeckoRuntime;
|
||||
import org.mozilla.geckoview.GeckoSession;
|
||||
import org.mozilla.geckoview.GeckoView;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
private static GeckoRuntime runtime;
|
||||
|
||||
private GeckoSession session;
|
||||
private GeckoView geckoView;
|
||||
private boolean canGoBack = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
getWindow().getDecorView().setSystemUiVisibility(
|
||||
View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
);
|
||||
|
||||
geckoView = new GeckoView(this);
|
||||
geckoView.setFocusable(true);
|
||||
geckoView.setFocusableInTouchMode(true);
|
||||
geckoView.requestFocus();
|
||||
setContentView(geckoView, new FrameLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
));
|
||||
|
||||
if (runtime == null) {
|
||||
runtime = GeckoRuntime.create(this);
|
||||
}
|
||||
|
||||
session = new GeckoSession();
|
||||
session.setNavigationDelegate(new GeckoSession.NavigationDelegate() {
|
||||
@Override
|
||||
public void onCanGoBack(GeckoSession session, boolean canGoBackValue) {
|
||||
canGoBack = canGoBackValue;
|
||||
}
|
||||
});
|
||||
session.open(runtime);
|
||||
geckoView.setSession(session);
|
||||
session.loadUri(buildTvUrl(BuildConfig.BASE_URL));
|
||||
}
|
||||
|
||||
private static String buildTvUrl(String baseUrl) {
|
||||
String url = baseUrl == null ? "" : baseUrl.trim();
|
||||
if (url.isEmpty()) {
|
||||
url = "http://192.168.1.10:3000";
|
||||
}
|
||||
if (!url.startsWith("http://") && !url.startsWith("https://")) {
|
||||
url = "http://" + url;
|
||||
}
|
||||
while (url.endsWith("/")) {
|
||||
url = url.substring(0, url.length() - 1);
|
||||
}
|
||||
if (url.endsWith("/tv")) {
|
||||
return url;
|
||||
}
|
||||
return url + "/tv";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (session != null && canGoBack) {
|
||||
session.goBack();
|
||||
return;
|
||||
}
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
session = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user