1.5 SDK problem with WebView.getZoomControls()

by Mariano Kamp » Wed, 29 Apr 2009 03:34:04 GMT


Sponsored Links
 Yeah, I have the same problem.
Anyone?

Is the suddenly breaking and now deprecated getZoomControls() considered
private API?






--~--~---------~--~----~------------~-------~--~----~



1.5 SDK problem with WebView.getZoomControls()

by Jason Parekh » Wed, 29 Apr 2009 04:30:58 GMT


 The preferred API is
WebView.getWebSettings().setBuiltInZoomControls(true).  The new API is
simpler in that just setting the flag will automatically add/hide the
zoom controls.  It will also have better performance on the G1 and
some other devices due to it being hardware composited on top of the
WebView instead of software compositing.

Unfortunately, I'm not sure why you're seeing layout issues with the
old zoom controls.  Could you try changing the LinearLayout's
layout_width to fill_parent?  If this does not work, could you please
post a screenshot?

jason






--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


1.5 SDK problem with WebView.getZoomControls()

by Mariano Kamp » Thu, 30 Apr 2009 00:33:24 GMT


 he following is butt ugly and should not be necessary in a perfect world,
but works for me:

private void createWebView(View parent) {

webView = (WebView) parent.findViewById(R.id.content_web_view);

webView.setWebViewClient(new EmbeddedWebViewClient());


Method setBuiltInZoomControlsMethod = null;

WebSettings webSettings = webView.getSettings();

try {

setBuiltInZoomControlsMethod = webSettings.getClass().getMethod(
"setBuiltInZoomControls",

new Class[] { boolean.class });

} catch (SecurityException e) {

} catch (NoSuchMethodException e) {

}


if (setBuiltInZoomControlsMethod != null) {

try {

setBuiltInZoomControlsMethod.invoke(webSettings, new Object[] { true });

} catch (IllegalArgumentException e) {

} catch (IllegalAccessException e) {

} catch (InvocationTargetException e) {

}

} else {

FrameLayout zoomControlContainer = (FrameLayout) findViewById(R.id.
browse_zoom);

zoomControlContainer.addView(webView.getZoomControls());

webView.getZoomControls().setVisibility(View.GONE);

}

}

I tested it with 1.1 and 1.5.

On Wed, Apr 29, 2009 at 8:47 AM, Mariano Kamp <mariano.k...@gmail.com>wrote:


--~--~---------~--~----~------------~-------~--~----~



1.5 SDK problem with WebView.getZoomControls()

by Jason Parekh » Thu, 30 Apr 2009 01:16:25 GMT


 


I saw your subsequent post about using reflection to try to enable the
new zoom (thanks for posting that so others can re-use), but just in
case you want to fully go back to the old way (which I don't recommend
because of worse performance), try:

<FrameLayout
  android:id="@+id/browse_zoom"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:layout_centerHorizontal="true"
  android:layout_alignParentBottom="true" />

jason

--~--~---------~--~----~------------~-------~--~----~



1.5 SDK problem with WebView.getZoomControls()

by Mariano Kamp » Thu, 30 Apr 2009 02:29:31 GMT


 Jason, thanks, I just tried that and, as you say, it works too.
Regarding performance you talk about the lack of HW acceleration for the old
way or is it layout performance you talk about?






--~--~---------~--~----~------------~-------~--~----~



1.5 SDK problem with WebView.getZoomControls()

by Jason Parekh » Thu, 30 Apr 2009 02:48:54 GMT


 


Not a problem.  I was referring to the lack of HW acceleration for the old way.

jason




--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. EditText stops displaying characters as I'm typing?

Basically what happens is I will start typing on the keyboard (stock
and third party), and all of a sudden it stops showing characters I
type in the EditText, (sometimes) resets the caret to the beginning,
yet I know I'm still typing because the suggestions box shows the
characters as I type.  I've experienced the behavior on at least 5
different devices (running 2.2, 2.3) as well as the emulator (running
2.1) but can't seem to nail down a solution.

It is seemingly random; I'm not reading any error logs through DDMS
from the system, (the only thing I see being written :sometimes: is
WARN/IInputConnectionWrapper(991): endBatchEdit on inactive
InputConnection) so I'm a little baffled.

Here is what it looks like: http://i.stack.imgur.com/gsB49.png

Here is the XML layout of the EditText:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <ListView android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:transcriptMode="alwaysScroll"/>

        <EditText android:id="@+id/etMain"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:inputType="text|textAutoCorrect"
            android:imeOptions="actionSend">
                <requestFocus />
            </EditText>
    </LinearLayout>


And here is my code from the Activity:

        et = (EditText) findViewById(R.id.etMain);

        et.setOnEditorActionListener(new OnEditorActionListener() {
                @Override
                        public boolean onEditorAction(TextView v, int actionId, 
KeyEvent
event) {
                        if ((event != null && (event.getKeyCode() ==
KeyEvent.KEYCODE_ENTER)) || actionId == EditorInfo.IME_ACTION_SEND) {
                                        String sendText = 
v.getText().toString();

                                        if (sendText.length() > 0) {
                                                v.setText("");

                                                ....

                                                }
                                        }
                                        return true;
                                }

                                return false;
                        }
        });


Appreciate any insights...let me know if you need anything else...

Ben

-- 

2. adding style in xml breaks onClick events.

when i add the style attribute for the my relativeLayout below it
breaks the onClick events in my activity.

---

<style name="list_item_bl" parent="text_large_bl">
        <item name="android:paddingRight">4sp</item>
        <item name="android:paddingLeft">4sp</item>
        <item name="android:background">@drawable/list_item_bl</item>
        <item name="android:focusable">false</item>
        <item name="android:focusableInTouchMode">false</item>
        <item name="android:clickable">true</item>
</style>

<?xml version="1.0" encoding="utf-8"?>
<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:id="@+id/TextView01"
                          android:layout_height="wrap_content"
                          android:text="blah blah blah... blah blah"
                          android:textStyle="normal|bold"
                          android:gravity="center_vertical|center_horizontal"
                          android:layout_width="fill_parent" />

        <ListView android:id="@android:id/list"
                          android:layout_height="wrap_content"
                          android:layout_width="fill_parent" />
        <TextView
                android:id="@+id/android:empty"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/nothing" />

 </LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
                android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/list_item"
        style="?listItem" >

        <TextView
                android:id="@+id/item_entry"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="left" android:focusable="false"
android:focusableInTouchMode="false"/>
    <TextView
                android:id="@+id/category_entry"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/item_entry"
                android:gravity="right"
                android:paddingLeft="8sp" android:focusable="false"
android:focusableInTouchMode="false"/>
    <TextView
                android:id="@+id/date_completed"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:gravity="right"
                android:paddingLeft="4sp" android:focusable="false"
android:focusableInTouchMode="false"/>

</RelativeLayout>

----

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

         ....

        fillData();
        getListView().setOnCreateContextMenuListener(this);

    }

        private void fillData() {
                ArrayList<String> names = new ArrayList<String>();
                for (int i = 0; i < _options.length; i++) {
                        String item = (String) _options[i];
                        if (_selections[i]) names.add(item);
                }
                _taskCursor = _dbHelper.fetchTasksByName(names);
                startManagingCursor(_taskCursor);

                String[] from = new String[] { TaskDbAdapter.KEY_ITEM,
TaskDbAdapter.KEY_CATEGORY, TaskDbAdapter.KEY_DATE };
                int[] to = new int[] { R.id.category_entry, R.id.item_entry,
R.id.date_completed };

                ListAdapter notesAdapter = new ListAdapter(this, 
R.layout.list_item,
_taskCursor, from, to);
                //SimpleCursorAdapter notesAdapter = new 
SimpleCursorAdapter(this,
R.layout.list_item, taskCursor, from, to)
                notesAdapter.setViewBinder(new ViewBinder() {
                                public boolean setViewValue(View aView, Cursor 
aCursor, int
aColumnIndex) {
                                        if (aColumnIndex == 3) {
                                                Date createDate = new 
Date(aCursor.getLong(aColumnIndex));
                                                TextView textView = (TextView) 
aView;
                                                
textView.setText(listFormat.format(createDate));
                                                return true;
                                        }
                                        return false;
                                }
                });

                setListAdapter(notesAdapter);
        }




---

i wrote a custom ListAdapter to see that would solve my problem.  i
can catch the listOnClick this way (with a lot of extra work) but
onCreateContextMenu never seems to get invoked.

this seems really weird that applying a style would break event
handling...

-- 

3. Tanya harga Archos 7" IT 8Gb

4. OOT: Paging pengguna paket data smartfren

5. About removing all android apps

6. simultaneous download of files - best way to handle it

7. Broadcast receiver not working in Activity