Friday, October 7, 2011

Far too long

I always end up getting sidetracked with doing other things and don't update this. I guess I'll post a couple tidbits about Android/Java stuff.
Ok, so you're writing an app and part of the requirements is removing pictures from the device. That's easy right, Get the uri of the picture from the media store, get the real path from the uri, delete the file. Viola, the picture's gone. But wait, the actual file is gone but there is still an entry for it in the media store. Simple. Give the uri to the content resolver and delete it. The entry is now gone. However, there will still be a thumbnail/entry showing in the gallery/picture app if it is running at the time of removal.

This is the code that does it:
getContentResolver().delete(uri, null, null);



Now suppose you want to show an image to the user and want to float a label or a button or a whatever over the top of the image. Here's how you do it. You put a frame layout in your layout, put the image in the frame layout, put a table layout in the frame layout, put your label/button/whatever in the table layout. (you can nest all kinds of layouts in the table to get things where you want them. An example in xml: {puts an image view on the screen and floats option buttons and labels over the top of the image on the left hand side):


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">
    <FrameLayout android:id="@+id/frameLayout1" android:layout_height="wrap_content" android:layout_width="wrap_content">
        <ImageView android:src="@drawable/icon" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/imageView1"></ImageView>
        <TableLayout android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="fill_parent">
            <LinearLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content">
                <Button android:text="Delete" android:layout_width="wrap_content" android:id="@+id/Discardbutton" android:layout_height="wrap_content"></Button>
            </LinearLayout>
            <LinearLayout android:id="@+id/linearLayout2" android:layout_width="wrap_content" android:layout_height="wrap_content">
                <Button android:text="Save" android:layout_width="wrap_content" android:id="@+id/Savebutton" android:layout_height="wrap_content"></Button>
            </LinearLayout>
            <LinearLayout android:id="@+id/linearLayout3" android:layout_width="wrap_content" android:layout_height="wrap_content">
                <Button android:text="Upload" android:layout_width="wrap_content" android:id="@+id/Uploadbutton" android:layout_height="wrap_content"></Button>
            </LinearLayout>
            <LinearLayout android:id="@+id/linearLayout4" android:layout_width="wrap_content" android:layout_height="wrap_content">
                <TextView android:id="@+id/textView1" android:textColor="#ffffffff" android:layout_width="wrap_content" android:background="#AA000000" android:layout_height="wrap_content" android:text="Filename:  "></TextView>
            </LinearLayout>
            <LinearLayout android:id="@+id/linearLayout5" android:layout_width="wrap_content" android:layout_height="wrap_content">
                <Button android:text="Rename" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/Renamebutton"></Button>
            </LinearLayout>
            <LinearLayout android:id="@+id/linearLayout6" android:layout_width="wrap_content" android:layout_height="wrap_content">
                <CheckBox android:layout_width="wrap_content" android:id="@+id/checkBox1"  android:background="#AA000000" android:layout_height="wrap_content" android:text="          "></CheckBox>
                <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Delete after upload" android:textColor="#ffffffff" android:background="#AA000000" ></TextView>
            </LinearLayout>
        </TableLayout>
    </FrameLayout>
</LinearLayout>







No comments:

Post a Comment