Communicating between two lists

Next problem:

I have two lists on one activity: one to select from and one with results. When  selection is clicked, how to I make list one to update?

Looking for sources.

1. This is example of using thread communication with Handler class

http://capdroid.wordpress.com/2011/07/28/android-message-passing-sample-using-handler/

 

More later. Have to go. (didn;t work most of yesterday either..)

Advertisements

Progress indicator – not solved

I’d like to add “Wait” indicator to some longer running operations, like loading bitmaps and reading from server.

Let’s gather info

1.  http://www.techrepublic.com/blog/android-app-builder/show-a-progress-bar-in-your-android-app-for-a-better-ux/

has example of activity with a progress bar that can be shown and updated during execution of background thread

I don’t want to replace activity, I just want a “wait” indicator

2.

ProgressDialog dialog = new ProgressDialog(this);
dialog.setMessage("Thinking...");
dialog.setIndeterminate(true);
dialog.setCancelable(false);
dialog.show();

..

if (dialog.isShowing()) {
dialog.dismiss();
}

 

 with setProgressStyle(STYLE_SPINNER)

This seems to be easy to implement. However this dialog doesn't come up. Why? 

3.

You need to request this as a feature near the top of the onCreate() method of your Activityusing the following code:

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

Then turn it on like this:

setProgressBarIndeterminateVisibility(true);

and turn it off like this:

setProgressBarIndeterminateVisibility(false);

3. I liked this:
define invisible area in the layout: and the toggle visible/Gone when you need to

((ShowListActivity)mAct).mAHeaderProgress.setVisibility(View.GONE);
((ShowListActivity)mAct).lView.setVisibility(View.VISIBLE);

<LinearLayout
android:id=”@+id/aHeaderProgress”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:gravity=”center”
android:orientation=”vertical”
android:layout_weight=”1″
android:visibility=”gone” >

<ProgressBar
android:id=”@+id/bHeaderProgress”
style=”@android:style/Widget.Spinner”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” >
</ProgressBar>
</LinearLayout>

None of these works for me. I get nothing, no bar or spinner. 
Only time i get spinning circle is if I put it in ocCreate and put the start pinning right there.  
This must be something wrong on my side, because instructions are clear.

android java.io.ioexception mark has been invalidated

Created by Jason Hise with Maya and Macromedia...

Created by Jason Hise with Maya and Macromedia Fireworks. A 3D projection of a 5-cell performing a simple rotation. (Photo credit: Wikipedia)

Bitmaps still giving me problems.

Earlier on I created code that scales bitmaps down “well enough” with rough measurements. It was ok for larger bitmaps but didn’t work well for smaller images found in gallery. Most obvious this became when I implemented nice zoom window.  This window initially shows bitmap in it’s size whatever is stored. Sometimes it’s nice (for camera images) and sometimes it’s tiny.

Let’s fix it.

Android dev guide recommends two steps: measure with options.inJustDecodeBounds = true and scale with options.inJustDecodeBounds = false.

That’s awesome but the stream is used up on a first pass.

Calling stream.reset()  gives error.

Wrapping stream into BufferedStream (makes sense at first) leads to a similar issue. Buffered stream can have marks

inputStream.mark(inputStream.available());

However for larger images (camera) i get error Mark has been invalidated.

So let’s try this: use mark. But if exception hits I will re-open the Uri.

try{
// this gives error for larger images taken by camera
is.reset();
} catch(IOException e){
is.close();
options.inPreferredConfig = Config.RGB_565;
options.inSampleSize = 8;
imageStream = activity.getContentResolver().openInputStream(
selectedImageUri);
is = new BufferedInputStream(imageStream);
}

This is working for both small and large images.

Leaving this for now.  Do you have a better idea? Write to me.

 

Android back button

Android has built in back button. When I am in any activity user can press a back button just like in browser. If there is partial data entered it will be lost (good), if there is partial data saved it will be left dangled (not good).

I want to capture back button event and do preps.

This captures back button event:

@Override
public void onBackPressed(){
Log.d(TAG, “back button is pressed”);
// do something
}

What is something to do? I decided to set RESULT_OK and call finish().

My receiving activity recognizes that all has been taken care of (OK) and refreshes the screen.

Simple.

 

Creating background image for the app

What size is required for all devices

What is image quality requirement

Should I create separate images for each of screen sizes?

Do I have to worry about all these?

Let’s collect data:

1. The following are the best dimensions for the app to run in all devices.

xhdpi: 640x960 px
hdpi: 480x800 px
mdpi: 320x480 px
ldpi: 240x320 px

2. What is small, med, large..  for screens?
  • xlarge screens are at least 960dp x 720dp
  • large screens are at least 640dp x 480dp
  • normal screens are at least 470dp x 320dp
  • small screens are at least 426dp x 320dp

3. This article explains screen sizes

http://developer.android.com/guide/practices/screens_support.html

So let’s see. I have one image (of golden gate bridge). Let’s try to adopt it for my app as experiment.

Opened my image in Gimp. My image is 480×640 px which is good enough only for ldpi and mdpi.  WFT is my emulator?

Resized canvas to 320x480 (preserve aspect ratio) and placed to mdpi. What's going to happen? Image size of png became 267K (up from 71K jpg). Why is that? 

Startup time is higher. My imaged came up but.. I can see only around sides which is correct. Such a waste! I have to put close to 1M of image to see nicer picture around the borders of the app. No way that it’s a best we could do! Is it?  Anyone?

Next experiment. Maybe I create a gradient background and leave it as is. Maybe will place an image to lower third.

<?xml version=”1.0″ encoding=”utf-8″?>
<selector xmlns:android=”http://schemas.android.com/apk/res/android”&gt;
<item>
<shape>
<gradient
android:angle=”90″
android:startColor=”@color/united_blue”
android:endColor=”@color/lightest_teal”
android:type=”linear” />
</shape>
</item>
</selector>

Result: using this selector file as drawable for background creates a gradient vertically. I don’t understand that that 90 degrees is about.

What’s this linear? Let’s try radial.  That crashed the app. Ok, that’s for crashing the app. : )

– People recommend to do this , I don’t know yet why..

window.getDecorView().getBackground().setDither(true);

Ok winner!!! I can do gradient background overlayed with an image on a bottom right:

<?xml version=”1.0″ encoding=”utf-8″?>
<layer-list xmlns:android=”http://schemas.android.com/apk/res/android”&gt;
<item><shape>
<gradient
android:angle=”90″
android:endColor=”@color/lightest_teal”
android:startColor=”@color/united_blue”
android:type=”linear” />
</shape></item>
<item android:top=”400dp” android:left=”200dp”
android:drawable=”@drawable/poison”
android:bottom=”10dp”
android:right=”10dp” >
</item>
</layer-list>

 or this one:

<?xml version=”1.0″ encoding=”utf-8″?>
<layer-list xmlns:android=”http://schemas.android.com/apk/res/android”&gt;
<item><shape>
<gradient
android:angle=”90″
android:endColor=”@color/lightest_teal”
android:startColor=”@color/united_blue”
android:type=”linear” />
</shape></item>
<item >
<bitmap
android:src=”@drawable/airport_ppl”
android:tileMode=”disabled” android:gravity=”bottom|right” >
</bitmap>
</item>
</layer-list>

Nice!

 

I want to see a prompt for my EditText boxes with all strings that user already entered in previous sessions. All these data is captured in my database, that’s not a problem. How to do the UI?

1. I came across this excellent post

http://android-er.blogspot.com/2010/07/example-of-autocompletetextview.html

That’s it.  Implemented as described without flaws. BTW my style for EditText still applies for

AutoCompleteTextView. 

...
However not as fast. This works on emulator and does absolutely nothing on device. Grrr!!
2. Found this tutorial https://developers.google.com/places/training/autocomplete-android
Will have to read and follow. Oh men..

Startup performance

My app is taking a bit longer to start than I want to. Yes, there is lots of code and lot of Log.d statements.

Let’s see what I can do.

1. Turned off Log statements. I had it tooled to be able to turn all Log on and off.

Faster? Gmm questionable.

2. Have to tame more code out to another thread.   That’s the key.

3. looked into proper use of graphics, i’m ok.  Got all my icons done with Android Studio.  (Iconology, then follow links)

 

Take care. Do things right from the first time.