|
|
|
@ -3,29 +3,32 @@
@@ -3,29 +3,32 @@
|
|
|
|
|
*/ |
|
|
|
|
package acr.browser.lightning.constant; |
|
|
|
|
|
|
|
|
|
import android.app.Activity; |
|
|
|
|
import android.app.Application; |
|
|
|
|
import android.os.AsyncTask; |
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
import java.io.FileWriter; |
|
|
|
|
import java.io.IOException; |
|
|
|
|
import java.lang.ref.WeakReference; |
|
|
|
|
|
|
|
|
|
import acr.browser.lightning.app.BrowserApp; |
|
|
|
|
import acr.browser.lightning.R; |
|
|
|
|
import acr.browser.lightning.app.BrowserApp; |
|
|
|
|
import acr.browser.lightning.preference.PreferenceManager; |
|
|
|
|
import acr.browser.lightning.utils.Utils; |
|
|
|
|
import acr.browser.lightning.view.LightningView; |
|
|
|
|
|
|
|
|
|
public class StartPage { |
|
|
|
|
public class StartPage extends AsyncTask<Void, Void, Void> { |
|
|
|
|
|
|
|
|
|
public static final String FILENAME = "homepage.html"; |
|
|
|
|
|
|
|
|
|
private static final String HEAD = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\">" |
|
|
|
|
private static final String HEAD_1 = "<!DOCTYPE html><html xmlns=\"http://www.w3.org/1999/xhtml\">" |
|
|
|
|
+ "<head>" |
|
|
|
|
+ "<meta content=\"en-us\" http-equiv=\"Content-Language\" />" |
|
|
|
|
+ "<meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\" />" |
|
|
|
|
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no\">" |
|
|
|
|
+ "<title>" |
|
|
|
|
+ BrowserApp.getContext().getString(R.string.home) |
|
|
|
|
+ "</title>" |
|
|
|
|
+ "<title>"; |
|
|
|
|
|
|
|
|
|
private static final String HEAD_2 = "</title>" |
|
|
|
|
+ "</head>" |
|
|
|
|
+ "<style>body{background:#f2f2f2;text-align:center;margin:0px;}#search_input{height:35px; " |
|
|
|
|
+ "width:100%;outline:none;border:none;font-size: 16px;background-color:transparent;}" |
|
|
|
@ -47,14 +50,41 @@ public class StartPage {
@@ -47,14 +50,41 @@ public class StartPage {
|
|
|
|
|
|
|
|
|
|
private static final String END = "\" + document.getElementById(\"search_input\").value;document.getElementById(\"search_input\").value = \"\";}return false;}</script></body></html>"; |
|
|
|
|
|
|
|
|
|
private final String mTitle; |
|
|
|
|
private final File mFilesDir; |
|
|
|
|
private final WeakReference<LightningView> mTabReference; |
|
|
|
|
|
|
|
|
|
private String mStartpageUrl; |
|
|
|
|
|
|
|
|
|
public StartPage(LightningView tab, Application app) { |
|
|
|
|
mTitle = app.getString(R.string.home); |
|
|
|
|
mFilesDir = app.getFilesDir(); |
|
|
|
|
mTabReference = new WeakReference<>(tab); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected Void doInBackground(Void... params) { |
|
|
|
|
mStartpageUrl = getHomepage(); |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void onPostExecute(Void aVoid) { |
|
|
|
|
super.onPostExecute(aVoid); |
|
|
|
|
LightningView tab = mTabReference.get(); |
|
|
|
|
if (tab != null) { |
|
|
|
|
tab.loadUrl(mStartpageUrl); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This method builds the homepage and returns the local URL to be loaded |
|
|
|
|
* when it finishes building. |
|
|
|
|
* |
|
|
|
|
* @return the URL to load |
|
|
|
|
*/ |
|
|
|
|
public static String getHomepage(Activity activity) { |
|
|
|
|
StringBuilder homepageBuilder = new StringBuilder(StartPage.HEAD); |
|
|
|
|
private String getHomepage() { |
|
|
|
|
StringBuilder homepageBuilder = new StringBuilder(HEAD_1 + mTitle + HEAD_2); |
|
|
|
|
String icon; |
|
|
|
|
String searchUrl; |
|
|
|
|
final PreferenceManager preferenceManager = BrowserApp.getPreferenceManager(); |
|
|
|
@ -89,14 +119,14 @@ public class StartPage {
@@ -89,14 +119,14 @@ public class StartPage {
|
|
|
|
|
break; |
|
|
|
|
case 5: |
|
|
|
|
// STARTPAGE_SEARCH;
|
|
|
|
|
icon = "file:///android_asset/startpage.png"; |
|
|
|
|
// "https://startpage.com/graphics/startp_logo.gif";
|
|
|
|
|
icon = "file:///android_asset/png"; |
|
|
|
|
// "https://com/graphics/startp_logo.gif";
|
|
|
|
|
searchUrl = Constants.STARTPAGE_SEARCH; |
|
|
|
|
break; |
|
|
|
|
case 6: |
|
|
|
|
// STARTPAGE_MOBILE
|
|
|
|
|
icon = "file:///android_asset/startpage.png"; |
|
|
|
|
// "https://startpage.com/graphics/startp_logo.gif";
|
|
|
|
|
icon = "file:///android_asset/png"; |
|
|
|
|
// "https://com/graphics/startp_logo.gif";
|
|
|
|
|
searchUrl = Constants.STARTPAGE_MOBILE_SEARCH; |
|
|
|
|
break; |
|
|
|
|
case 7: |
|
|
|
@ -132,11 +162,11 @@ public class StartPage {
@@ -132,11 +162,11 @@ public class StartPage {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
homepageBuilder.append(icon); |
|
|
|
|
homepageBuilder.append(StartPage.MIDDLE); |
|
|
|
|
homepageBuilder.append(MIDDLE); |
|
|
|
|
homepageBuilder.append(searchUrl); |
|
|
|
|
homepageBuilder.append(StartPage.END); |
|
|
|
|
homepageBuilder.append(END); |
|
|
|
|
|
|
|
|
|
File homepage = new File(activity.getFilesDir(), StartPage.FILENAME); |
|
|
|
|
File homepage = new File(mFilesDir, FILENAME); |
|
|
|
|
FileWriter hWriter = null; |
|
|
|
|
try { |
|
|
|
|
//noinspection IOResourceOpenedButNotSafelyClosed
|
|
|
|
@ -150,4 +180,5 @@ public class StartPage {
@@ -150,4 +180,5 @@ public class StartPage {
|
|
|
|
|
|
|
|
|
|
return Constants.FILE + homepage; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|