mirror of
https://github.com/ethauvin/Clever.git
synced 2025-04-24 08:27:11 -07:00
Re-did UI to use native text box rather than web form.
This commit is contained in:
parent
f3b5d79cfa
commit
eadd6e7963
4 changed files with 168 additions and 83 deletions
|
@ -9,27 +9,7 @@
|
|||
|
||||
body{
|
||||
background-color: #000;
|
||||
color: #fff;
|
||||
text-align: center;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
.wrapper{
|
||||
margin: 150px auto;
|
||||
display: inline-block;
|
||||
max-width: 100%;
|
||||
}
|
||||
input{
|
||||
width: 600px;
|
||||
max-width: 100%;
|
||||
}
|
||||
input, button{
|
||||
font-size: 30px;
|
||||
border: 3px solid #333;
|
||||
border-radius: 10px;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.logo{
|
||||
position: absolute;
|
||||
bottom: 20px;
|
||||
|
@ -39,62 +19,11 @@
|
|||
}
|
||||
|
||||
</style>
|
||||
|
||||
<script>
|
||||
|
||||
window.onload = function(){
|
||||
|
||||
var loc = document.getElementById('loc');
|
||||
var url = document.getElementById('url');
|
||||
|
||||
|
||||
var prevUrl = localStorage.getItem('url');
|
||||
|
||||
if(prevUrl){
|
||||
url.value = prevUrl;
|
||||
}
|
||||
|
||||
url.onclick = function(){
|
||||
|
||||
this.select();
|
||||
|
||||
}
|
||||
|
||||
|
||||
loc.onsubmit = function(e){
|
||||
e.preventDefault();
|
||||
|
||||
var urlval = url.value;
|
||||
|
||||
if(urlval){
|
||||
|
||||
if(urlval.substring(0,7) !== 'http://' && urlval.substring(0,8) !== 'https://'){
|
||||
urlval = 'http://' + urlval;
|
||||
}
|
||||
|
||||
localStorage.setItem('url', urlval);
|
||||
|
||||
document.location = urlval;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="wrapper">
|
||||
|
||||
<form id="loc">
|
||||
<input placeholder="Enter URL" id="url" type="url" name="url" value=""/> <button>Go</button>
|
||||
</form>
|
||||
<img class="logo" src="file:///android_asset/www/clever.png"/>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
|
@ -1,14 +1,44 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/linearLayout1"
|
||||
android:id="@+id/linearLayout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/navbar"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:animateLayoutChanges="true"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/url"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1.0"
|
||||
android:hint="http://"
|
||||
android:imeOptions="actionGo"
|
||||
android:inputType="textAutoComplete|textUri"
|
||||
android:lines="1"
|
||||
/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/go_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:focusable="false"
|
||||
android:text="@string/go_button" />
|
||||
|
||||
</LinearLayout>
|
||||
<WebView
|
||||
android:id="@+id/webView1"
|
||||
android:id="@+id/webView"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1.0"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
|
@ -3,4 +3,7 @@
|
|||
<string name="app_name">Clever</string>
|
||||
<string name="title_activity_main">Clever</string>
|
||||
|
||||
<string name="go_button">Go</string>
|
||||
|
||||
|
||||
</resources>
|
|
@ -2,18 +2,31 @@ package io.clever;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.animation.*;
|
||||
import android.view.animation.Animation.AnimationListener;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.webkit.*;
|
||||
import android.webkit.WebSettings.*;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.*;
|
||||
import android.widget.TextView.OnEditorActionListener;
|
||||
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
|
||||
WebView webView;
|
||||
EditText urlField;
|
||||
Button goButton;
|
||||
LinearLayout linearLayout, navbar;
|
||||
Animation slideUp, slideDown;
|
||||
|
||||
public static final String HOME_PAGE = "file:///android_asset/www/index.html";
|
||||
public static final String PREFS_NAME = "CleverPrefs";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
|
@ -21,25 +34,104 @@ public class MainActivity extends Activity {
|
|||
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearLayout1);
|
||||
|
||||
linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
|
||||
linearLayout.setBackgroundColor(Color.BLACK);
|
||||
|
||||
// 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;
|
||||
}
|
||||
});
|
||||
|
||||
webView = (WebView) findViewById(R.id.webView1);
|
||||
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
|
||||
String lastUrl = settings.getString("lastUrl", "");
|
||||
|
||||
urlField.setText(lastUrl);
|
||||
|
||||
|
||||
|
||||
// Navbar animation settings
|
||||
|
||||
AnimationListener slideListener = new AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animation animation) {
|
||||
if(animation.equals(slideUp)){
|
||||
navbar.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation animation) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationStart(Animation animation) {
|
||||
if(animation.equals(slideDown)){
|
||||
navbar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
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, -1.0f
|
||||
);
|
||||
slideUp.setDuration(500);
|
||||
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);
|
||||
|
||||
|
||||
// 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);
|
||||
|
@ -52,6 +144,7 @@ public class MainActivity extends Activity {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
@ -73,13 +166,24 @@ public class MainActivity extends Activity {
|
|||
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("file:///android_asset/www/index.html");
|
||||
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
|
||||
|
@ -97,5 +201,24 @@ public class MainActivity extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
public void doNav(){
|
||||
|
||||
String url = urlField.getText().toString();
|
||||
|
||||
if(URLUtil.isValidUrl(url) == false){
|
||||
url = "http://" + url;
|
||||
}
|
||||
|
||||
|
||||
urlField.setText(url);
|
||||
|
||||
webView.requestFocus();
|
||||
|
||||
webView.loadUrl(url);
|
||||
|
||||
navbar.startAnimation(slideUp);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue