I am aware that this question has been asked before, but I have tried every "solution" to the other questions, but I still have not been able to achieve what I am trying to do. I have searched and searched, and tried and tried. Please forgive me. I simply want to display my row of buttons above my WebView, so that it is consistent with the rest of the activities in my app (they all have the row of buttons at the top). It seems like I have tried every possible combination of layouts, but to no avail. It displays correctly in the Graphical Layout (Eclipse), but on the phone and emulator it only displays the WebView, fullscreen, no buttons.... Any help will be very much appreciated!
Here's my xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/menu_panel">
<ImageButton
android:id="#+id/bHomeMenu"
android:layout_margin="-8dip"
android:layout_width="65dp"
android:layout_height="90dp"
android:background="#drawable/menu_btn_hcu_light_blue"
android:src="#drawable/icon_menu_home"
android:adjustViewBounds="true"
android:scaleType="centerInside"
style="#style/ButtonText"
android:textSize="13sp"
android:text="Home" />
<ImageButton
android:id="#+id/bItsMe247Menu"
android:layout_toRightOf="#+id/bHomeMenu"
android:layout_margin="-8dip"
android:layout_width="65dp"
android:layout_height="90dp"
android:background="#drawable/menu_btn_selected_hcu_light_blue"
android:src="#drawable/icon_menu_login"
android:adjustViewBounds="true"
android:scaleType="centerInside"
style="#style/ButtonText"
android:textSize="13sp"
android:text="It'sMe" />
<ImageButton
android:id="#+id/bFindUsMenu"
android:layout_toRightOf="#+id/bItsMe247Menu"
android:layout_margin="-8dip"
android:layout_width="65dp"
android:layout_height="90dp"
android:background="#drawable/menu_btn_hcu_light_blue"
android:src="#drawable/icon_menu_find_us"
android:adjustViewBounds="true"
android:scaleType="centerInside"
style="#style/ButtonText"
android:textSize="13sp"
android:text="FindUs" />
<ImageButton
android:id="#+id/bEmailMenu"
android:layout_toRightOf="#+id/bFindUsMenu"
android:layout_margin="-8dip"
android:layout_width="65dp"
android:layout_height="90dp"
android:background="#drawable/menu_btn_hcu_light_blue"
android:src="#drawable/icon_menu_email"
android:adjustViewBounds="true"
android:scaleType="centerInside"
style="#style/ButtonText"
android:textSize="13sp"
android:text="Email" />
<ImageButton
android:id="#+id/bRatesMenu"
android:layout_toRightOf="#+id/bEmailMenu"
android:layout_margin="-8dip"
android:layout_width="65dp"
android:layout_height="90dp"
android:background="#drawable/menu_btn_hcu_light_blue"
android:src="#drawable/icon_menu_rates"
android:adjustViewBounds="true"
android:scaleType="centerInside"
style="#style/ButtonText"
android:textSize="13sp"
android:text="Rates" />
</LinearLayout>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/wvItsMe"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
EDIT: Here's my java code, and a note below it:
package com.dummyapp.app;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import com.dummyapp.app.SimpleGestureFilter.SimpleGestureListener;
public class ItsMe247 extends Activity implements SimpleGestureListener{
private SimpleGestureFilter detector;
private WebView itsMeLogin;
// ImageButton menuHome, menuFindUs, menuEmail, menuRates;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//setContentView(R.layout.itsme247);
// menuHome = (ImageButton)findViewById(R.id.bHomeMenu);
// menuFindUs = (ImageButton)findViewById(R.id.bFindUsMenu);
// menuEmail = (ImageButton)findViewById(R.id.bEmailMenu);
// menuRates = (ImageButton)findViewById(R.id.bRatesMenu);
detector = new SimpleGestureFilter(this,this);
itsMeLogin = new WebView(this);
Toast.makeText(this, "Just Swipe To Exit", Toast.LENGTH_LONG).show();
itsMeLogin.getSettings().setJavaScriptEnabled(true); // JavaScript enabled
getWindow().requestFeature(Window.FEATURE_PROGRESS); // Show progress bar of page loading
final Activity itsMeActivity = this;
itsMeLogin.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress){
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
itsMeActivity.setProgress(progress * 100);
}
});
itsMeLogin.setWebViewClient(new WebViewClient(){
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
Toast.makeText(itsMeActivity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
itsMeLogin.loadUrl("http://www.google.com");
setContentView(itsMeLogin);
// itsMeLogin.setWebViewClient(new WebViewClient() {
// #Override
// public boolean shouldOverrideUrlLoading(final WebView view, final String url) {
// return super.shouldOverrideUrlLoading(view, url);
// }
// });
//******************* MENU BUTTONS START HERE ********************************************************//
// menuRates.setOnClickListener(new View.OnClickListener() {
//
// public void onClick(View v) {
// // TODO Auto-generated method stub
// Intent ratesIntent = new Intent(ItsMe247.this, Rates.class);
// ItsMe247.this.startActivity(ratesIntent);
//
// }
//
// });
//
//
// menuFindUs.setOnClickListener(new View.OnClickListener() {
//
// public void onClick(View v) {
// // TODO Auto-generated method stub
// Intent contactIntent = new Intent(ItsMe247.this, Contact.class);
// ItsMe247.this.startActivity(contactIntent);
//
// }
// });
//
// menuEmail.setOnClickListener(new View.OnClickListener() {
//
// public void onClick(View v) {
// // TODO Auto-generated method stub
// Intent emailIntent = new Intent(ItsMe247.this, Email.class);
// ItsMe247.this.startActivity(emailIntent);
//
//
// }
// });
//
// menuHome.setOnClickListener(new View.OnClickListener() {
//
// public void onClick(View v) {
// // TODO Auto-generated method stub
// Intent itsMeIntent = new Intent(ItsMe247.this, MainActivity.class);
// ItsMe247.this.startActivity(itsMeIntent);
// }
// });
//***************************** MENU BUTTONS END HERE ********************************************************//
}//end onCreate method
#Override
public boolean dispatchTouchEvent(MotionEvent me){
this.detector.onTouchEvent(me);
return super.dispatchTouchEvent(me);
}
public void onSwipe(int direction) {
switch (direction) {
case SimpleGestureFilter.SWIPE_RIGHT:
Intent funIntent = new Intent(ItsMe247.this, MainActivity.class);
ItsMe247.this.startActivity(funIntent);
//ItsMe247.this.finish();
break;
case SimpleGestureFilter.SWIPE_LEFT:
Intent funIntent2 = new Intent(ItsMe247.this, Contact.class);
ItsMe247.this.startActivity(funIntent2);
//ItsMe247.this.finish();
break;
case SimpleGestureFilter.SWIPE_DOWN:
break;
case SimpleGestureFilter.SWIPE_UP:
break;
}
}//end onSwipe method
public void onDoubleTap() {
}
}
I have all the menu buttons commented out (the buttons I'm trying to get to display above webview) until I finally get them to display through the xml. However, whenever I UNcomment the buttons and their listeners, the app crashes when trying to enter this activity.
Your code isn't using your XML layout, you're creating your own WebView in code and setting that as the view so it bypasses your XML completely.
I've provided a few changes here that should make it work. Pay particular attention to the setContentView line and the following line, these are what use the XML layout. You may need to change the name of the layout (R.layout.whatever) and the webview id (R.id.webview). There may be a few parse errors from me putting it here, might have missed a closing bracket. I deleted much of your commented out code just to keep it simple.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView( R.layout.xmlLayout );
itsMeLogin = (WebView)findViewById( R.id.webview );
detector = new SimpleGestureFilter(this,this);
Toast.makeText(this, "Just Swipe To Exit", Toast.LENGTH_LONG).show();
itsMeLogin.getSettings().setJavaScriptEnabled(true); // JavaScript enabled
getWindow().requestFeature(Window.FEATURE_PROGRESS); // Show progress bar of page loading
final Activity itsMeActivity = this;
itsMeLogin.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress){
// Activities and WebViews measure progress with different scales.
// The progress meter will automatically disappear when we reach 100%
itsMeActivity.setProgress(progress * 100);
}
});
itsMeLogin.setWebViewClient(new WebViewClient(){
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl){
Toast.makeText(itsMeActivity, "Oh no! " + description, Toast.LENGTH_SHORT).show();
}
});
itsMeLogin.loadUrl("http://www.google.com");
}
Here's my XML file from a similar layout as well, though yours will probably work with the edited code.
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:columnCount="3"
android:layout_height="match_parent"
android:layout_width="match_parent"
>
<EditText
android:ems="4"
android:imeOptions="actionNext"
android:inputType="number"
android:layout_gravity="center_horizontal"
android:maxLength="4"
android:selectAllOnFocus="true"
/>
<EditText
android:ems="4"
android:imeOptions="actionDone"
android:inputType="textCapCharacters|textNoSuggestions"
android:layout_gravity="center_horizontal"
android:maxLength="3"
android:selectAllOnFocus="true"
/>
<Button android:id="#+id/submit"
/>
<WebView android:id="#+id/webview"
android:layout_columnSpan="3"
android:layout_gravity="fill"
android:layout_height="0dp"
android:layout_width="0dp"
/>
</GridLayout>
Related
I have one Edit Text, 5 buttons and a Webview. Webview load url when user type url in edit text and tap Go button or hit Enter on soft keyboard.
I have three problems here.
1-WebView loads website for example "www.google.com" but soft keyboard does not hide itself. I want to hide it like other browser do.
2-When user open a specific url and then try to remove it from Edit Text to open a different url, webview start loading that incomplete url and get focus automatically on every letter removing. For example user loads "www.google.com" then he try to remove url from end and as he remove "m", webview try to load "www.google.co" then edit text is out of focus and webview stole focus from it then user have to tap in edit text again to remove url but it tries to load after every letter removing. I need Webview to load url only when user tap on Go button or hit Enter on soft keyboard.
Update (forgot to add third problem, here it is)
3-Where can i check when WebView CanGoBack and CanGoForward because i want to set visibility of Back and Forward buttons to false at startup and enabled these two buttons while they CanGoBack and CanGoForward. Where should i put my piece of code to check these conditions?
I hope you guys can understand what i am trying to say. Sorry for my poor english.
Here is my xml code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="13"
tools:context="com.hbss.chatapp.rashidfaheem.hybridsoftwaresolutions.rashidfaheem.youseebrowser.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="4"
>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="#+id/etUrl"
android:layout_weight="3"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="GO"
android:id="#+id/btnGo"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:weightSum="4"
>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Back"
android:id="#+id/btnBack"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Forward"
android:id="#+id/btnForward"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Clear"
android:id="#+id/btnClear"
/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Reload"
android:id="#+id/btnReload"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="11"
>
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/wb"
/>
</LinearLayout>
</LinearLayout>
Here is my java code.
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
EditText etUrl;
Button btnGo, btnBack, btnForward, btnClear, btnReload;
WebView wb;
String url;
View v;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wb = (WebView) findViewById(R.id.wb);
wb.getSettings().setJavaScriptEnabled(true);
wb.getSettings().setUseWideViewPort(true);
wb.getSettings().setLoadWithOverviewMode(true);
wb.setWebViewClient(new ourClient());
etUrl = (EditText) findViewById(R.id.etUrl);
btnGo = (Button) findViewById(R.id.btnGo);
btnBack = (Button) findViewById(R.id.btnBack);
btnForward = (Button) findViewById(R.id.btnForward);
btnClear = (Button) findViewById(R.id.btnClear);
btnReload = (Button) findViewById(R.id.btnReload);
btnGo.setOnClickListener(this);
btnReload.setOnClickListener(this);
btnBack.setOnClickListener(this);
btnForward.setOnClickListener(this);
btnClear.setOnClickListener(this);
etUrl.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if (keyEvent.getAction()==KeyEvent.ACTION_DOWN && i==KeyEvent.KEYCODE_ENTER) {
return true;
}
load();
return false;
}
});
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnGo:
load();
break;
case R.id.btnBack:
if (wb.canGoBack())
wb.goBack();
break;
case R.id.btnForward:
if (wb.canGoForward())
wb.goForward();
break;
case R.id.btnReload:
wb.reload();
break;
case R.id.btnClear:
wb.clearHistory();
break;
}
}
public void load(){
url = etUrl.getText().toString();
if (!url.startsWith("http://")) {
url = "http://" + url;
}
try {
wb.loadUrl(url);
wb.requestFocus();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), " " + e, Toast.LENGTH_LONG).show();
}
}
}
use this method to hide the keyboard:
public static void hideSoftKeyboard(Activity context) {
InputMethodManager inputManager = (InputMethodManager) context
.getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputManager != null)
inputManager.hideSoftInputFromWindow(context.getWindow()
.getDecorView().getApplicationWindowToken(), 0);
context.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}
call it in your load() method like:
hideSoftKeyboard(MainActivity.this);
For your second question you need to call your method inside the condition like:
etUrl.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View view, int i, KeyEvent keyEvent) {
if ((keyEvent.getAction()==KeyEvent.ACTION_DOWN) && (i==KeyEvent.KEYCODE_ENTER)){
load(); //add it here
return true;
}
return false;
}
});
EDIT
For the webview go back feature: override onKeyDown in your activity and check condition like:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the Back button and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && wb.canGoBack()) {
wb.goBack();
//show your back button here
return true;
}
// If it wasn't the Back key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
//show other buttons
return super.onKeyDown(keyCode, event);
}
You can add the check in your onResume() and load() also and show your button accordingly..
#Override
protected void onResume() {
super.onResume();
if(wb.canGoBack()){
//show back button}
else{
//other button
}
}
I have a simple app that is based on WebView.loadUrl("http://www.example.com").
When a user clicks on a URL, the default behavior is to immediately show a blank page, wait until the page is loaded, and then show this page.
I managed to show a splash screen in lieu of the blank page. However, is it possible to keep the current page rendered instead, and render the next page only when it is fully loaded?
This is, I feel, a hacky solution. I offer it as a temporary fix until someone posts the "real" way to do this.
MainActivity class:
public class MainActivity extends Activity
{
WebView webView1, webView2;
EditText editText;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText = (EditText) findViewById(R.id.edit_url);
webView1 = (WebView) findViewById(R.id.webView_1);
webView2 = (WebView) findViewById(R.id.webView_2);
webView1.setWebViewClient(client);
webView2.setWebViewClient(client);
webView1.loadUrl(editText.getText().toString());
}
private WebViewClient client = new WebViewClient()
{
public void onPageFinished(WebView webView, String url)
{
if (webView == webView1)
webView2.setVisibility(View.GONE);
else
webView1.setVisibility(View.GONE);
webView.setVisibility(View.VISIBLE);
Toast.makeText(MainActivity.this, "WebView " + (webView == webView1 ? "One" : "Two") + " is showing", 0).show();
}
};
private void loadUrl(String url)
{
if (webView1.getVisibility() == View.GONE)
webView1.loadUrl(url);
else
webView2.loadUrl(url);
}
public void onClick(View v)
{
loadUrl(editText.getText().toString());
}
}
main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.webkit.WebView android:id="#+id/webView_1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<android.webkit.WebView android:id="#+id/webView_2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText android:id="#+id/edit_url"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:layout_gravity="center_vertical"
android:text="http://www.example.com" />
<Button android:id="#+id/button_load"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClick"
android:text="Load" />
</LinearLayout>
</LinearLayout>
I have an activity that displays web pages. On some phones (e.g, Huawei Ascend) , this activity crashes in a way that causes the application to restart, but doesn't cause the usual android error popup for reporting. (Other phones (e.g. Nexus) never crash at all.) It does appear to always crash while a web page is loading, but not at any particular point e.g. sometimes at shoulOverrideUrlLoading, sometimes during onPageStarted or onPageFinished.
I think the WebView is causing this--
08-29 21:08:22.577: A/libc(957): Fatal signal 11 (SIGSEGV) at 0x00000008 (code=1), thread 957
--but I can't work out why.
Here's the activity:
public class WebDisplay extends Activity
{
private String sentUrl = "";
public WebView myWebView;
public ProgressBar spinner;
#SuppressLint("SetJavaScriptEnabled")
#Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.d("WEBVIEW", "onCreate");
getWindow().setBackgroundDrawableResource(R.color.white);
Bundle extras = getIntent().getExtras();
if (null != extras)
{
sentUrl = extras.getString("displayURL");
}
setContentView(R.layout.webdisplay);
myWebView = (WebView) findViewById(R.id.webDisplay);
spinner = (ProgressBar) findViewById(R.id.webLoading);
// WebView displays default to showing things in exact pixel size at 100%
// resolution, meaning it generally opens on a zoomed in portion of the
// top left of the web page and refuses to let you zoom out, so we have
// to force it to display pages a bit more reasonably.
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
// By default, there is no javascript support or zoom controls, so
// turn both of those on.
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportZoom(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
// We want links to continue opening inside the app.
myWebView.setWebViewClient(new WebViewClient() {
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.d("WEBVIEW", "loadUrl="+url);
view.loadUrl(url); // open link in the same web view.
return true;
}
#Override
public void onPageStarted(WebView view, String url, android.graphics.Bitmap favicon) {
Log.d("WEBVIEW", "onPageStarted="+url);
super.onPageStarted(view, url, favicon);
if (View.GONE == spinner.getVisibility()) { spinner.setVisibility(View.VISIBLE); }
}
#Override
public void onPageFinished(WebView view, String url) {
Log.d("WEBVIEW", "onPageFinished="+url);
super.onPageFinished(view, url);
if (View.VISIBLE == spinner.getVisibility()) { spinner.setVisibility(View.GONE); }
}
#Override
public void onReceivedError(WebView view, int errorCode, String description, String url) {
Log.d("WEBVIEW", "onPageError="+url+"::descr="+description);
}
});
// Try to get YouTube videos working.
myWebView.setWebChromeClient(new WebChromeClient() {
});
// So the user doesn't have to back through their entire history to get
// back to the app, we provide a "done browsing" button.
Button doneButton = (Button) findViewById(R.id.doneButton);
doneButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v)
{
finish();
}
});
ImageButton backButton = (ImageButton) findViewById(R.id.webBackButton);
backButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0)
{
myWebView.goBack();
}
});
ImageButton fwdButton = (ImageButton) findViewById(R.id.webForwardButton);
fwdButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0)
{
myWebView.goForward();
}
});
ImageButton refreshButton = (ImageButton) findViewById(R.id.refreshButton);
refreshButton.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View arg0)
{
myWebView.reload();
}
});
myWebView.loadUrl(sentUrl);
}
#Override
protected void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
// Save the state of the WebView
myWebView.saveState(outState);
}
#Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
super.onRestoreInstanceState(savedInstanceState);
// Restore the state of the WebView
myWebView.restoreState(savedInstanceState);
}
}
And here's the loaded layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white" >
<RelativeLayout
android:id="#+id/webNavBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/abs__background_holo_light"
android:layout_alignParentBottom="true"
android:padding="2dp" >
<Button
android:id="#+id/doneButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/refreshButton"
android:layout_alignTop="#+id/refreshButton"
android:background="#drawable/custom_button"
android:padding="5dp"
android:text="#string/web_done"
android:textColor="#color/white"
android:textStyle="bold" />
<ImageButton
android:id="#+id/refreshButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#drawable/custom_button"
android:src="#drawable/ic_action_refresh"
android:contentDescription="#string/web_refresh"
android:textColor="#color/white"
android:padding="5dp" />
<ImageButton
android:id="#+id/webBackButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="5dp"
android:layout_toLeftOf="#+id/webForwardButton"
android:background="#drawable/custom_button"
android:src="#drawable/navigation_back"
android:padding="5dp"
android:contentDescription="#string/web_back"
android:textColor="#color/white" />
<ImageButton
android:id="#+id/webForwardButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/custom_button"
android:src="#drawable/navigation_forward"
android:contentDescription="#string/web_forward"
android:textColor="#color/white"
android:padding="5dp" />
</RelativeLayout>
<WebView
android:id="#+id/webDisplay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_above="#id/webNavBar" />
<ProgressBar
android:id="#+id/webLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="80dp"
style="#android:style/Widget.ProgressBar.Large"
android:layout_centerHorizontal="true" />
</RelativeLayout>
ETA: Turning hardware acceleration off like this
myWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
seems to stop the SIGSEV thing, but also stops YouTube videos playing (I still have audio, but no image).
make sure the WebView is the first element of the RelativeLayout.
or don't use RelativeLayout, just try LinearLayout.
or remove the attributes
android:layout_alignParentTop="true"
android:layout_above="#id/webNavBar"
of WebView
webSettings.setJavaScriptEnabled(true);
Settings above causes "Fatal signal 11 (SIGSEGV)" error for some sites using java script. I reproduced this error on Samsung Galaxy Tab 3 And Galaxy tab 3 lite. Android version is 4.4.2 for both devices.
If I remove "setJavaScriptEnabled" function, it is working fine.
Ok, I've implemented a android datagrid that amongst other things, lets you drag and drop columns around. This functionality works beautifully (better than I expected).
I noticed recently that if the grids were placed in tabcontents... it seems like zindex isnt taken into account (even though my ACTION_DRAG_STARTED will return false for column headers further back in the z-index, I still see those column headers responding to some events (like ACTION_DRAG_EXITED).
Attempting to have a controlled environment, I went ahead and built a stand alone project that demonstrates this problem.
I am hoping its something simple I missed, or perhaps ideas on how to work around it. Pretty simple to reproduce... run project, drag buttons around with long press... change tabs, drag those around, change back to first tab, drag around. It should start drag process, but as soon as you drag out of the control you were just in, you see "Reporting drop result:false".
Any pointers would be greatly appreciated... I suspect the underlying views are cancelling the drag event.
BrokeDragNDropActivity.java
package cm.mc.busteddnd;
import android.app.Activity;
import android.content.ClipData;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.DragEvent;
import android.view.View;
import android.view.View.OnDragListener;
import android.view.View.OnLongClickListener;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.Toast;
public class BrokeDragNDropActivity extends Activity {
public static int selectedTab =0;
Extendedbutton button1;
Extendedbutton button2;
Extendedbutton button3;
Extendedbutton button4;
Extendedbutton button5;
Extendedbutton button6;
Extendedbutton button7;
Extendedbutton button8;
Extendedbutton button9;
#Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
final TabHost tabs = (TabHost) this.findViewById(R.id.my_tabhost);
tabs.setOnTabChangedListener(new OnTabChangeListener() {
#Override
public void onTabChanged(String arg0) {
selectedTab = tabs.getCurrentTab();
Log.i("***Selected Tab", "Im currently in tab with index::" + tabs.getCurrentTab());
}
});
tabs.setup();
TabSpec tspec1 = tabs.newTabSpec("First Tab");
tspec1.setIndicator("One");
tspec1.setContent(R.id.content);
tabs.addTab(tspec1);
TabSpec tspec2 = tabs.newTabSpec("Second Tab");
tspec2.setIndicator("Two");
tspec2.setContent(R.id.content2);
tabs.addTab(tspec2);
TabSpec tspec3 = tabs.newTabSpec("Third Tab");
tspec3.setIndicator("Three");
tspec3.setContent(R.id.content3);
tabs.addTab(tspec3);
//wire up buttons
button1 = (Extendedbutton)findViewById(R.id.button1);
button2 = (Extendedbutton)findViewById(R.id.button2);
button3 = (Extendedbutton)findViewById(R.id.button3);
button4 = (Extendedbutton)findViewById(R.id.button4);
button5 = (Extendedbutton)findViewById(R.id.button5);
button6 = (Extendedbutton)findViewById(R.id.button6);
button7 = (Extendedbutton)findViewById(R.id.button7);
button8 = (Extendedbutton)findViewById(R.id.button8);
button9 = (Extendedbutton)findViewById(R.id.button9);
//wire up listeners
button1.setGroup(1);
wireListeners(button1);
button2.setGroup(1);
wireListeners(button2);
button3.setGroup(1);
wireListeners(button3);
button4.setGroup(2);
wireListeners(button4);
button5.setGroup(2);
wireListeners(button5);
button6.setGroup(2);
wireListeners(button6);
button7.setGroup(3);
wireListeners(button7);
button8.setGroup(3);
wireListeners(button8);
button9.setGroup(3);
wireListeners(button9);
}
public void wireListeners(Extendedbutton button){
button.setOnLongClickListener(new OnLongClickListener() {
#Override
public boolean onLongClick(View paramView) {
Extendedbutton v = (Extendedbutton)paramView;
ClipData data = ClipData.newPlainText("group_"+v.getGroup(), v.getDesc());
paramView.startDrag(data, // the data to be dragged
new View.DragShadowBuilder(paramView), // the drag shadow builder
null, // no need to use local data
0 // flags (not currently used, set to 0)
);
return true;
}
});
button.setOnDragListener(new OnDragListener(){
#Override
public boolean onDrag(View v, DragEvent event) {
// Defines a variable to store the action type for the incoming event
final int action = event.getAction();
// Handles each of the expected events
CharSequence dragData;
switch(action) {
case DragEvent.ACTION_DRAG_STARTED:
// Determines if this View can accept the dragged data
if (event.getClipDescription().getLabel().equals("group_"+(selectedTab+1))) {
// As an example of what your application might do,
// applies a blue color tint to the View to indicate that it can accept
// data.
v.setBackgroundColor(Color.BLUE);
// Invalidate the view to force a redraw in the new tint
v.invalidate();
// returns true to indicate that the View can accept the dragged data.
return(true);
} else {
// Returns false. During the current drag and drop operation, this View will
// not receive events again until ACTION_DRAG_ENDED is sent.
return(false);
}
case DragEvent.ACTION_DRAG_ENTERED: {
// Applies a green tint to the View. Return true; the return value is ignored.
v.setBackgroundColor(Color.GREEN);
// Invalidate the view to force a redraw in the new tint
v.invalidate();
return(true);
}
case DragEvent.ACTION_DRAG_LOCATION:
// Ignore the event
return(true);
case DragEvent.ACTION_DRAG_EXITED:
// Re-sets the color tint to blue. Returns true; the return value is ignored.
v.setBackgroundColor(Color.BLUE);
// Invalidate the view to force a redraw in the new tint
v.invalidate();
return(true);
case DragEvent.ACTION_DROP:
// Gets the item containing the dragged data
ClipData.Item item = event.getClipData().getItemAt(0);
// Gets the text data from the item.
dragData = item.getText();
// Displays a message containing the dragged data.
Toast.makeText(BrokeDragNDropActivity.this, "Dragged data is " + dragData, Toast.LENGTH_LONG);
// Turns off any color tints
v.setBackgroundColor(Color.BLACK);
// Invalidates the view to force a redraw
v.invalidate();
// Returns true. DragEvent.getResult() will return true.
return(true);
case DragEvent.ACTION_DRAG_ENDED:
// Turns off any color tinting
v.setBackgroundColor(Color.BLACK);
// Invalidates the view to force a redraw
v.invalidate();
// Does a getResult(), and displays what happened.
if (event.getResult()) {
Toast.makeText(BrokeDragNDropActivity.this, "The drop was handled.", Toast.LENGTH_LONG);
} else {
Toast.makeText(BrokeDragNDropActivity.this, "The drop didn't work.", Toast.LENGTH_LONG);
};
// returns true; the value is ignored.
return(true);
// An unknown action type was received.
default:
Log.e("DragDrop Example","Unknown action type received by OnDragListener.");
return false;
}
}
});
}
}
ExtendedButton.java (needed this to handle the group filtering)
package cm.mc.busteddnd;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Button;
public class Extendedbutton extends Button {
private int group;
private String desc;
public int getGroup() {
return group;
}
public void setGroup(int group) {
this.group = group;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public Extendedbutton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public Extendedbutton(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public Extendedbutton(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
}
and finally...
main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/my_tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="65px"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="200px"
android:paddingTop="65px">
<LinearLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">
<cm.mc.busteddnd.Extendedbutton android:text="Button1" android:id="#+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></cm.mc.busteddnd.Extendedbutton>
<cm.mc.busteddnd.Extendedbutton android:text="Button2" android:id="#+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></cm.mc.busteddnd.Extendedbutton>
<cm.mc.busteddnd.Extendedbutton android:text="Button3" android:id="#+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content"></cm.mc.busteddnd.Extendedbutton>
</LinearLayout>
<LinearLayout
android:id="#+id/content2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">
<cm.mc.busteddnd.Extendedbutton android:text="Button4" android:id="#+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content"></cm.mc.busteddnd.Extendedbutton>
<cm.mc.busteddnd.Extendedbutton android:text="Button5" android:id="#+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content"></cm.mc.busteddnd.Extendedbutton>
<cm.mc.busteddnd.Extendedbutton android:text="Button6" android:id="#+id/button6" android:layout_width="wrap_content" android:layout_height="wrap_content"></cm.mc.busteddnd.Extendedbutton>
</LinearLayout>
<LinearLayout
android:id="#+id/content3"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal">
<cm.mc.busteddnd.Extendedbutton android:text="Button7" android:id="#+id/button7" android:layout_width="wrap_content" android:layout_height="wrap_content"></cm.mc.busteddnd.Extendedbutton>
<cm.mc.busteddnd.Extendedbutton android:text="Button8" android:id="#+id/button8" android:layout_width="wrap_content" android:layout_height="wrap_content"></cm.mc.busteddnd.Extendedbutton>
<cm.mc.busteddnd.Extendedbutton android:text="Button9" android:id="#+id/button9" android:layout_width="wrap_content" android:layout_height="wrap_content"></cm.mc.busteddnd.Extendedbutton>
</LinearLayout>
</FrameLayout>
</TabHost>
Im trying to change the icon on the handle when i try to open the slidingdrawer.
When I extract the handle from the view and sets the onclicklistener or ontouchlistener it seems to never get trigget.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
SlidingDrawer drawer = (SlidingDrawer)findViewById(R.id.drawer_landscape);
ImageView handle = (ImageView)findViewById(R.id.handle_l);
handle.setFocusable(true);
handle.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("test","onClick");
}
});
}
And my XML
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/base_frame_layout"
android:layout_gravity="bottom"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"
/>
</LinearLayout>
<SlidingDrawer
android:id="#+id/drawer_landscape"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:handle="#+id/handle_l"
android:content="#+id/content"
android:orientation="vertical"
android:visibility="visible"
>
<ImageView
android:id="#+id/handle_l"
android:layout_height="50px"
android:layout_width="64px"
android:padding="0px"
android:src="#drawable/icon"
/>
<TextView
android:id="#+id/content"
android:text="content"
android:layout_height="50px"
android:layout_width="64px"
/>
</SlidingDrawer>
</FrameLayout>
I was hoping this code should log "onClick" message, but it doesn't.
Any ideas?
I found it, it was pritty easy... I just need to setOnDrawerScrollListener on my drawer.
than implement the 2 methods onScrollEnded and onScrollStarted.
mSlidingDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener(){
#Override
public void onScrollEnded() {
// TODO Auto-generated method stub
Log.i("ddd","onScrollEnded slider");
slider_animation.reverseTransition(HANDLE_ANIMATION_SPEED);
}
#Override
public void onScrollStarted() {
// TODO Auto-generated method stub
Log.i("ddd","onScrollStarted slider");
slider_animation.startTransition(HANDLE_ANIMATION_SPEED);
}
});
I rather use an animation on the handle instead of changing the Image bacause of the flickering.
I found it for along time , but now it is completed about it .
It is the best way for Change Image Handle when you click to view SlidingDrawer.
It have 2 Method that we use in code below.
final SlidingDrawer drawer = (SlidingDrawer)findViewById(R.id.slidingDrawer);
drawer.setOnDrawerOpenListener(new SlidingDrawer.OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
arr.setImageResource(R.drawable.arrowdown);
}
});
drawer.setOnDrawerCloseListener(new SlidingDrawer.OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
arr.setImageResource(R.drawable.arrowup);
}
});