mirror of
https://github.com/ethauvin/Clever.git
synced 2025-04-25 08:57:12 -07:00
Formatting with Eclipse
This commit is contained in:
parent
eadd6e7963
commit
d1f4326ca7
2 changed files with 176 additions and 181 deletions
|
@ -3,25 +3,26 @@
|
||||||
android:versionCode="1"
|
android:versionCode="1"
|
||||||
android:versionName="1.0" >
|
android:versionName="1.0" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="15"
|
android:minSdkVersion="15"
|
||||||
android:targetSdkVersion="15" />
|
android:targetSdkVersion="15" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:icon="@drawable/icon"
|
android:icon="@drawable/icon"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
|
||||||
>
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/title_activity_main"
|
|
||||||
android:screenOrientation="landscape"
|
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:windowSoftInputMode="adjustResize"
|
android:immersive="true"
|
||||||
android:immersive="true">
|
android:label="@string/title_activity_main"
|
||||||
|
android:screenOrientation="landscape"
|
||||||
|
android:windowSoftInputMode="adjustResize" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
|
@ -15,210 +15,204 @@ import android.webkit.WebSettings.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import android.widget.TextView.OnEditorActionListener;
|
import android.widget.TextView.OnEditorActionListener;
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
public class MainActivity extends Activity {
|
||||||
|
|
||||||
WebView webView;
|
WebView webView;
|
||||||
EditText urlField;
|
EditText urlField;
|
||||||
Button goButton;
|
Button goButton;
|
||||||
LinearLayout linearLayout, navbar;
|
LinearLayout linearLayout, navbar;
|
||||||
Animation slideUp, slideDown;
|
Animation slideUp, slideDown;
|
||||||
|
|
||||||
public static final String HOME_PAGE = "file:///android_asset/www/index.html";
|
public static final String HOME_PAGE = "file:///android_asset/www/index.html";
|
||||||
public static final String PREFS_NAME = "CleverPrefs";
|
public static final String PREFS_NAME = "CleverPrefs";
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
setContentView(R.layout.activity_main);
|
|
||||||
|
|
||||||
linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
|
|
||||||
linearLayout.setBackgroundColor(Color.BLACK);
|
|
||||||
|
|
||||||
// Navbar setup
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
navbar = (LinearLayout) findViewById(R.id.navbar);
|
super.onCreate(savedInstanceState);
|
||||||
goButton = (Button)findViewById(R.id.go_button);
|
|
||||||
urlField = (EditText)findViewById(R.id.url);
|
|
||||||
|
|
||||||
goButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
public void onClick(View v) {
|
|
||||||
doNav();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
urlField.setOnEditorActionListener(new OnEditorActionListener() {
|
setContentView(R.layout.activity_main);
|
||||||
@Override
|
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
||||||
boolean handled = false;
|
|
||||||
if (actionId == EditorInfo.IME_ACTION_GO) {
|
|
||||||
|
|
||||||
doNav();
|
|
||||||
|
|
||||||
handled = true;
|
|
||||||
}
|
|
||||||
return handled;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
|
|
||||||
String lastUrl = settings.getString("lastUrl", "");
|
|
||||||
|
|
||||||
urlField.setText(lastUrl);
|
|
||||||
|
|
||||||
|
linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
|
||||||
|
linearLayout.setBackgroundColor(Color.BLACK);
|
||||||
|
|
||||||
// Navbar animation settings
|
// Navbar setup
|
||||||
|
|
||||||
|
navbar = (LinearLayout) findViewById(R.id.navbar);
|
||||||
|
goButton = (Button) findViewById(R.id.go_button);
|
||||||
|
urlField = (EditText) findViewById(R.id.url);
|
||||||
|
|
||||||
|
goButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
public void onClick(View v) {
|
||||||
|
doNav();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
urlField.setOnEditorActionListener(new OnEditorActionListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onEditorAction(TextView v, int actionId,
|
||||||
|
KeyEvent event) {
|
||||||
|
boolean handled = false;
|
||||||
|
if (actionId == EditorInfo.IME_ACTION_GO) {
|
||||||
|
|
||||||
|
doNav();
|
||||||
|
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
return handled;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
|
||||||
|
String lastUrl = settings.getString("lastUrl", "");
|
||||||
|
|
||||||
|
urlField.setText(lastUrl);
|
||||||
|
|
||||||
|
// Navbar animation settings
|
||||||
|
|
||||||
AnimationListener slideListener = new AnimationListener() {
|
AnimationListener slideListener = new AnimationListener() {
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animation animation) {
|
|
||||||
if(animation.equals(slideUp)){
|
|
||||||
navbar.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationRepeat(Animation animation) {
|
public void onAnimationEnd(Animation animation) {
|
||||||
|
if (animation.equals(slideUp)) {
|
||||||
|
navbar.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAnimationRepeat(Animation animation) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationStart(Animation animation) {
|
public void onAnimationStart(Animation animation) {
|
||||||
if(animation.equals(slideDown)){
|
if (animation.equals(slideDown)) {
|
||||||
navbar.setVisibility(View.VISIBLE);
|
navbar.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
slideUp = new TranslateAnimation(
|
slideUp = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
|
||||||
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
|
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
|
||||||
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f
|
0.0f, Animation.RELATIVE_TO_SELF, -1.0f);
|
||||||
);
|
slideUp.setDuration(500);
|
||||||
slideUp.setDuration(500);
|
slideUp.setAnimationListener(slideListener);
|
||||||
slideUp.setAnimationListener(slideListener);
|
|
||||||
|
|
||||||
slideDown = new TranslateAnimation(
|
|
||||||
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
|
|
||||||
Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f
|
|
||||||
);
|
|
||||||
slideDown.setDuration(500);
|
|
||||||
slideDown.setAnimationListener(slideListener);
|
|
||||||
|
|
||||||
|
slideDown = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
|
||||||
|
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
|
||||||
|
-1.0f, Animation.RELATIVE_TO_SELF, 0.0f);
|
||||||
|
slideDown.setDuration(500);
|
||||||
|
slideDown.setAnimationListener(slideListener);
|
||||||
|
|
||||||
// WebView setup
|
// WebView setup
|
||||||
|
|
||||||
webView = (WebView) findViewById(R.id.webView);
|
|
||||||
|
|
||||||
WebSettings webSettings = webView.getSettings();
|
|
||||||
|
|
||||||
webView.setWebChromeClient(new WebChromeClient());
|
|
||||||
|
|
||||||
webView.setWebViewClient(new WebViewClient() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPageFinished(WebView view, String url) {
|
|
||||||
|
|
||||||
Log.d("scale", view.getScale() + "");
|
|
||||||
|
|
||||||
Log.d("pageFinished",url);
|
|
||||||
|
|
||||||
if(url.equalsIgnoreCase(HOME_PAGE)){
|
|
||||||
// navbar.setVisibility(View.VISIBLE);
|
|
||||||
navbar.startAnimation(slideDown);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onScaleChanged (WebView view, float oldScale, float newScale){
|
|
||||||
|
|
||||||
Log.d("scale changed", oldScale + " - " + newScale);
|
|
||||||
|
|
||||||
if(newScale > 0.7){
|
|
||||||
|
|
||||||
Log.d("scale","reset");
|
|
||||||
//view.setInitialScale(70);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
webView = (WebView) findViewById(R.id.webView);
|
||||||
});
|
|
||||||
|
|
||||||
webView.setInitialScale(70);
|
|
||||||
|
|
||||||
webView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
|
|
||||||
webView.setVerticalScrollBarEnabled(false);
|
|
||||||
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
|
|
||||||
webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
|
|
||||||
|
|
||||||
webSettings.setBuiltInZoomControls(false);
|
|
||||||
webSettings.setSupportZoom(false);
|
|
||||||
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
|
|
||||||
webSettings.setPluginState(WebSettings.PluginState.ON);
|
|
||||||
webSettings.setJavaScriptEnabled(true);
|
|
||||||
webSettings.setDomStorageEnabled(true);
|
|
||||||
webSettings.setDatabaseEnabled(true);
|
|
||||||
webSettings.setDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
|
|
||||||
webSettings.setSaveFormData(false);
|
|
||||||
webSettings.setLightTouchEnabled(false);
|
|
||||||
webSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
|
|
||||||
webSettings.setRenderPriority( RenderPriority.HIGH);
|
|
||||||
webSettings.setUserAgentString("Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Large Screen Safari/534.24 GoogleTV");
|
|
||||||
|
|
||||||
webView.loadUrl(HOME_PAGE);
|
WebSettings webSettings = webView.getSettings();
|
||||||
webView.requestFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop(){
|
|
||||||
|
|
||||||
super.onStop();
|
|
||||||
|
|
||||||
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
|
|
||||||
SharedPreferences.Editor editor = settings.edit();
|
|
||||||
editor.putString("lastUrl", urlField.getText().toString());
|
|
||||||
|
|
||||||
editor.commit();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
webView.setWebChromeClient(new WebChromeClient());
|
||||||
public void onBackPressed()
|
|
||||||
{
|
webView.setWebViewClient(new WebViewClient() {
|
||||||
if(webView.canGoBack()){
|
|
||||||
|
@Override
|
||||||
webView.goBack();
|
public void onPageFinished(WebView view, String url) {
|
||||||
webView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
|
|
||||||
|
Log.d("scale", view.getScale() + "");
|
||||||
} else {
|
|
||||||
|
Log.d("pageFinished", url);
|
||||||
super.onBackPressed();
|
|
||||||
|
if (url.equalsIgnoreCase(HOME_PAGE)) {
|
||||||
}
|
// navbar.setVisibility(View.VISIBLE);
|
||||||
}
|
navbar.startAnimation(slideDown);
|
||||||
|
}
|
||||||
public void doNav(){
|
|
||||||
|
}
|
||||||
String url = urlField.getText().toString();
|
|
||||||
|
@Override
|
||||||
|
public void onScaleChanged(WebView view, float oldScale,
|
||||||
|
float newScale) {
|
||||||
|
|
||||||
|
Log.d("scale changed", oldScale + " - " + newScale);
|
||||||
|
|
||||||
|
if (newScale > 0.7) {
|
||||||
|
|
||||||
|
Log.d("scale", "reset");
|
||||||
|
// view.setInitialScale(70);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
webView.setInitialScale(70);
|
||||||
|
|
||||||
|
webView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
|
||||||
|
webView.setVerticalScrollBarEnabled(false);
|
||||||
|
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
|
||||||
|
webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
|
||||||
|
|
||||||
|
webSettings.setBuiltInZoomControls(false);
|
||||||
|
webSettings.setSupportZoom(false);
|
||||||
|
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
|
||||||
|
webSettings.setPluginState(WebSettings.PluginState.ON);
|
||||||
|
webSettings.setJavaScriptEnabled(true);
|
||||||
|
webSettings.setDomStorageEnabled(true);
|
||||||
|
webSettings.setDatabaseEnabled(true);
|
||||||
|
webSettings.setDatabasePath("/data/data/"
|
||||||
|
+ webView.getContext().getPackageName() + "/databases/");
|
||||||
|
webSettings.setSaveFormData(false);
|
||||||
|
webSettings.setLightTouchEnabled(false);
|
||||||
|
webSettings.setLayoutAlgorithm(LayoutAlgorithm.NORMAL);
|
||||||
|
webSettings.setRenderPriority(RenderPriority.HIGH);
|
||||||
|
webSettings
|
||||||
|
.setUserAgentString("Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.77 Large Screen Safari/534.24 GoogleTV");
|
||||||
|
|
||||||
|
webView.loadUrl(HOME_PAGE);
|
||||||
|
webView.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onStop() {
|
||||||
|
|
||||||
|
super.onStop();
|
||||||
|
|
||||||
|
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
|
||||||
|
SharedPreferences.Editor editor = settings.edit();
|
||||||
|
editor.putString("lastUrl", urlField.getText().toString());
|
||||||
|
|
||||||
|
editor.commit();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
if (webView.canGoBack()) {
|
||||||
|
|
||||||
|
webView.goBack();
|
||||||
|
webView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
super.onBackPressed();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doNav() {
|
||||||
|
|
||||||
|
String url = urlField.getText().toString();
|
||||||
|
|
||||||
|
if (URLUtil.isValidUrl(url) == false) {
|
||||||
|
url = "http://" + url;
|
||||||
|
}
|
||||||
|
|
||||||
if(URLUtil.isValidUrl(url) == false){
|
|
||||||
url = "http://" + url;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
urlField.setText(url);
|
urlField.setText(url);
|
||||||
|
|
||||||
webView.requestFocus();
|
webView.requestFocus();
|
||||||
|
|
||||||
webView.loadUrl(url);
|
webView.loadUrl(url);
|
||||||
|
|
||||||
|
navbar.startAnimation(slideUp);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
navbar.startAnimation(slideUp);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue