Clarification on loading local images with WebView

by Jeff Thorn » Fri, 14 May 2010 06:42:22 GMT


Sponsored Links
 Regarding option 1 - if I create a content provider it appears I need to
implement the openFile method and return a ParcelFileDescriptor. Sounds easy
enough.  But how do you create a File object from something in the assets
directory?






As I wrote in my previous reply:


Try creating a ContentProvider to serve the image, and see if you have
better luck with a content:/...

Not if your image is only in an asset. The image viewer won't have
rights to access it.


Not directly, but you can use the 2D graphics API (e.g., Canvas and
friends). Basically, you're looking to use the same techniques games do
to view a portion of a large map, for example.

--

Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
http://commonsware...
Android Online Training: 21-25 June 2010:  http://onlc.com 


--



Clarification on loading local images with WebView

by Mark Murphy » Fri, 14 May 2010 06:51:08 GMT


 


Perhaps use openAssetFile() instead?

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Android App Developer Books:  http://commonsware.com/books 

--


Sponsored Links


Clarification on loading local images with WebView

by Jeff Thorn » Fri, 14 May 2010 07:18:31 GMT


 You would think huh? But I got the impression for the docs that that method
just allows you return a file segment using an offset and length.

Can you do something like:

File f = new File("assets/myfile.png");

I wish you could create a ParcelFileDescriptor with something Oberlin than a
File.






Perhaps use openAssetFile() instead?

--

Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 

 http://commonsware.com/blog  |  http://twitter.com/commonsguy 
Android App Developer Books:  http://commonsware.com/books 


--



Clarification on loading local images with WebView

by Jeff Thorn » Fri, 14 May 2010 07:21:24 GMT


 PS - meant something OTHER than. Droid autospell. :)




You would think huh? But I got the impression for the docs that that method
just allows you return a file segment using an offset and length.

Can you do something like:

File f = new File("assets/myfile.png");

I wish you could create a ParcelFileDescriptor with something Oberlin than a
File.









Groups "Android Developers" group.
To post to this group, send email to android-develop...@googlegro...

--



Clarification on loading local images with WebView

by Mark Murphy » Fri, 14 May 2010 07:38:06 GMT


 



Hmmmm...yeah, I was probably a bit too off-the-cuff with that
recommendation. I had done a ContentProvider to serve large images to a
WebView, but it wasn't an asset. It doesn't look like doing one from an
asset will be terribly simple.

Sorry!

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.com/commonsguy 

Android Training in NYC: 4-6 June 2010:  http://guruloft.com 

--



Clarification on loading local images with WebView

by Jeff Thorn » Fri, 14 May 2010 08:14:59 GMT


 I appreciate your help. I think I will just open the large image in a new
custom Activity.









Hmmmm...yeah, I was probably a bit too off-the-cuff with that
recommendation. I had done a ContentProvider to serve large images to a
WebView, but it wasn't an asset. It doesn't look like doing one from an
asset will be terribly simple.

Sorry!

--

Mark Murphy (a Commons Guy)

 http://commonsware.com  |  http://github.com/commonsguy 
 http://commonsware.com/blog  |  http://twitter.c ...
Android Training in NYC: 4-6 June 2010:  http://guruloft.com 


--



Other Threads

1. tanya tweak picasa sync di gallery 2.1

guys,
kemarin ini saya upgrade droid ke 2.1 (official rom) dan jadi punya picasa
sync
saya suka sekali sama gallery 2.1nya, sayangnya jadi punya masalah baru
foto2 di picasanya sering kali macet, hanya thumbnails yg low res aja
padahal udah pake wifi yg mayan kenceng dirumah dan res foto picasanya ngak
gede
kadang perfoto harus nunggu sampai 10 detik, kadang ngak kelar2
gimana caranya biar picasanya bisa sync seluruhnya jadi bisa offline viewing
yg nyaman di HHnya?
ada yg punya solusi?

cheers,
tj

-- 
*~-*~-*~-*~-*~-*~-*~-*~-*~-
"There are three constants in life... change, choice and principles." -
Stephen Covey

-- 
"Indonesian Android Community [id-android]" 

2. UI android question/problem

Hi,

I'm trying to recreate the UI screen called 'My Places' that is used
in the Weather Channel app.  I'd attach a screenshot of it but I'm not
sure if I can when posting here.  It seems they're using two listviews
one on top of the other, but I'm not sure for certain.  Could anybody
confirm this for me?  If they are doing this, how is this done?  I've
tried to implement this, but without full success.  My top listview
'Add a place' 'comes up correctly, but the bottom listview will not
appear/populate for me?  I shall attach my code so far......

Any help would be greatly appreciated.

Thanks

Simon

header_row.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="wrap_content">
        <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginRight="6dip"
        android:src="@drawable/ic_menu_add" />
        <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dip"
        android:layout_weight="1"
        android:layout_height="fill_parent">
         <TextView
            android:id="@+id/caption"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:gravity="center_vertical"
            android:text="Add a place"/>
        </LinearLayout>
</LinearLayout>

main.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="?android:attr/listPreferredItemHeight"
    android:padding="6dip">
        <ListView
                android:id="@+id/header"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"/>
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <ListView
                        android:id="@+id/list"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"/>
        </LinearLayout>
</LinearLayout>

public class ListViewTest extends Activity
{
        private static String[] items={"lorem", "ipsum", "dolor",
                "sit", "amet", "consectetuer",
                "adipiscing", "elit", "morbi",
                "vel", "ligula", "vitae",
                "arcu", "aliquet", "mollis",
                "etiam", "vel", "erat",
                "placerat", "ante",
                "porttitor", "sodales",
                "pellentesque", "augue",
                "purus"};

        private ListView Header;
        private ListView List;
        private ArrayList<Caption> caption = null;
        private CaptionAdapter adapter;
        private ArrayAdapter listAdapter;

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

        caption = new ArrayList<Caption>();
        Caption cap = new Caption();
        cap.setCaption("Add a place");
        caption.add(cap);

        this.adapter = new CaptionAdapter(this, R.layout.header_row,
caption);

        Header = (ListView) findViewById(R.id.header);

        Header.setAdapter(adapter);

        //Log.d("ListViewTest", "caption size is:" + caption.size());

        adapter.notifyDataSetChanged();

        List = (ListView) findViewById(R.id.list);

        listAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, items);

        List.setAdapter(listAdapter);

        listAdapter.notifyDataSetChanged();

        //setListAdapter(new ArrayAdapter<String>(this,
                                //android.R.layout.simple_list_item_1,
                                //items));
    }

    private class CaptionAdapter extends ArrayAdapter<Caption>
    {
        private ArrayList<Caption> caption;

                public CaptionAdapter(Context context, int textViewResourceId,
ArrayList<Caption> caption)
                {
                        super(context, textViewResourceId, caption);
                        this.caption = caption;
                }

                @Override
            public View getView(int position, View convertView, ViewGroup
parent)
            {
                        View v = convertView;

                        if (v == null)
            {
                LayoutInflater vi =
(LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                v = vi.inflate(R.layout.header_row, null);
            }

                        Caption c = caption.get(position);

                        if (c != null)
            {
                                TextView caption = (TextView) 
v.findViewById(R.id.caption);

                                if (caption != null)
                {
 
caption.setText(c.getCaption());
                }
            }

                        return v;
            }

    }
}

-- 

3. Blocking intents from launching

4. How integrate my Settings Activity into Settings apk

5. Foreground periodic service and Battery life

6. Warning! puguh prasetya ingin ch

7. Info : gempa aceh