Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-24174]: Android: Update ListView check/disclosure/child graphics #8832

Merged
merged 32 commits into from Jul 19, 2017

Conversation

m1ga
Copy link
Contributor

@m1ga m1ga commented Feb 11, 2017

JIRA: https://jira.appcelerator.org/browse/TIMOB-24174

  • update the old PR with ListView graphics
  • bigger margin on left side of the labels
  • bigger default height in a default ListView

@@ -439,6 +441,36 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
setNativeView(wrapper);
}

private int getImageRessource(String img){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved into TiRHelper so we can use this elsewhere 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to TiRHelper

@garymathews garymathews changed the title [TIMOB-24174]: Update ListView check/disclosure/child graphics [TIMOB-24174]: Android: Update ListView check/disclosure/child graphics Feb 13, 2017
@hansemannn
Copy link
Collaborator

bildschirmfoto 2017-02-13 um 14 14 02

They should retain the old color, otherwise developers might complain about the change.

@@ -439,6 +441,36 @@ public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCoun
setNativeView(wrapper);
}

private int getImageRessource(String img){
//
String resName = "drawable."+img+"_48"; // default medium
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces: + img +

@@ -43,7 +43,7 @@
// every time we add a row. No sense checking it each time.
private static boolean ICS_OR_GREATER = (Build.VERSION.SDK_INT >= TiC.API_LEVEL_ICE_CREAM_SANDWICH);

private static final int LEFT_MARGIN = 5;
private static final int LEFT_MARGIN = 22;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Android natively has 22dp left and 27dp right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit hard to find out as I find various examples (from 0 margin to 48). But I found this theme.xml:
https://github.com/android/platform_frameworks_base/blob/82834baa358f55acb542e17da828b2d497cf8332/core/res/res/values/themes.xml#L146
and it looks like 6dp is a default value for listitems in a basic theme. I will update ListView and TableView to look the same

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finally solved it :) Stupid dp vs pixels. Now both images (listview/tableview) have a 6dp padding

@hansemannn
Copy link
Collaborator

@garymathews or @fmerzadyan Can one of you review this? Thxxxx!

Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: PASS
FT: PASS

TEST CASE
var win = Ti.UI.createWindow({
        backgroundColor: 'gray',
        layout: 'vertical'
    }),
    tv = Ti.UI.createTableView({
        headerTitle: 'TableView',
        data: [
            {
                title: 'Apples',
                hasChild: true
            }, {
                title: 'Bananas'
            }
        ],
        height: Ti.UI.SIZE
    }),
    ls = Ti.UI.createListSection({
        headerTitle: 'ListView'
    }),
    lv = Ti.UI.createListView({
        height: Ti.UI.SIZE
    });

ls.setItems([
    {
        properties: {
            title: 'Apples',
            accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_CHECKMARK
        }
    }, {
        properties: {
           title: 'Bananas',
           accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_DETAIL
       }
    }
]);
lv.sections = [ls];

win.add(tv);
win.add(lv);
win.open();
BEFORE AFTER

👍

@garymathews garymathews added this to the 6.2.0 milestone Apr 12, 2017
@lokeshchdhry lokeshchdhry self-assigned this Apr 18, 2017
@lokeshchdhry
Copy link
Contributor

@hansemannn , Can you please rebase/update this branch, so that merge is enabled. Thanks.

@hansemannn
Copy link
Collaborator

@lokeshchdhry done!

@hansemannn
Copy link
Collaborator

@m1ga We need a backport for this asap to include it in 6.1.0. Should I do or can you?

@lokeshchdhry
Copy link
Contributor

@hansemannn ,Cool thanks. I still see the merge not enabled due to statuses/checks did not pass.

@lokeshchdhry
Copy link
Contributor

lokeshchdhry commented Apr 18, 2017

@m1ga, @hansemannn, @garymathews - I am seeing some differences in phone & emulator between tableview & listview icon sizes.

One Plus one - 6.0.1 Emulator android 7.1.1
android_6 0 1-one_plus_one emu_android_7 1 1

If you see the apple icon in table view is slightly larger than the 2 list view icons where as in the emulator the tableview icon is smaller compared to the listview icons.

Is this expected ?

@m1ga
Copy link
Contributor Author

m1ga commented Apr 19, 2017

@lokeshchdhry No, that shouldn't be. I'll check that again, thanks for the feedback!

@m1ga
Copy link
Contributor Author

m1ga commented Apr 19, 2017

No luck in finding the culprit at the moment. Guess it's somewhere in TiTableViewRowProxyItem.java around line 552. So I need more time to test it

And I have a strange crash on 5.0.2, that /android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/TiListItem.java #62 s null:

04-19 21:13:00.387: E/AndroidRuntime(12800): java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageResource(int)' on a null object reference 04-19 21:13:00.387: E/AndroidRuntime(12800): at ti.modules.titanium.ui.widget.listview.TiListItem.handleAccessory(TiListItem.java:62)

@m1ga
Copy link
Contributor Author

m1ga commented Apr 22, 2017

Sorry about that. Should be fine again.

@lokeshchdhry the size of the tableview image was different (not 17dp like the listview) and one image was missing (disclosure_96.png). That is fixed now and tested on a Nexus 6 (emulator), Moto G and HTC A9.

@hansemannn
Copy link
Collaborator

Thanks Michael! I'm wondering why the header title background-color is different between tableview and listview?

@hansemannn
Copy link
Collaborator

What ever is used natively :-) All sizes, background-colors, text colors etc pp. Those values are from old times. Maybe we do those in 7.0.0, but better soon than later.

@m1ga
Copy link
Contributor Author

m1ga commented Apr 23, 2017

There is no real native version of this. In a ListView you would just create a View and add it (and style it yourself), so like the Ti-ListView is doing already. And you can already use custom views so the headerTitle is just a short cut.

The closest thing I could find in the Material style guide is:

But that should be a different (bigger) PR because you have to adjust the default Android theme (e.g. not use the dark one by default).

For this PR I'll use the bright version in both headerTitles so it looks fresher and a bit more like the iOS version.

@hansemannn
Copy link
Collaborator

Yeah, let's keep that part as it is. Thanks @m1ga!

@m1ga
Copy link
Contributor Author

m1ga commented Apr 23, 2017

Headers look the same now:

device-2017-04-23-124704

Copy link
Contributor

@garymathews garymathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR: PASS
FT: PASS

@lokeshchdhry
Copy link
Contributor

@garymathews , @m1ga , I am getting this crash when I run test code above with locally built 6.2.0 on android API 24 7.0.0 & above.

[ERROR] :  TiApplication: (main) [732,732] Sending event: exception on thread: main msg:java.lang.ClassCastException: ti.modules.titanium.ui.TableViewSectionProxy cannot be cast to ti.modules.titanium.ui.TableViewRowProxy; Titanium 6.2.0,2017/06/13 09:56,undefined
[ERROR] :  TiApplication: java.lang.ClassCastException: ti.modules.titanium.ui.TableViewSectionProxy cannot be cast to ti.modules.titanium.ui.TableViewRowProxy
[ERROR] :  TiApplication: 	at ti.modules.titanium.ui.widget.tableview.TiTableView$TTVListAdapter.getView(TiTableView.java:205)
[ERROR] :  TiApplication: 	at android.widget.AbsListView.obtainView(AbsListView.java:2360)
[ERROR] :  TiApplication: 	at android.widget.ListView.measureHeightOfChildren(ListView.java:1326)
[ERROR] :  TiApplication: 	at android.widget.ListView.onMeasure(ListView.java:1233)
[ERROR] :  TiApplication: 	at android.view.View.measure(View.java:19730)
[ERROR] :  TiApplication: 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
[ERROR] :  TiApplication: 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
[ERROR] :  TiApplication: 	at android.view.View.measure(View.java:19730)
[ERROR] :  TiApplication: 	at org.appcelerator.titanium.view.TiCompositeLayout.constrainChild(TiCompositeLayout.java:445)
[ERROR] :  TiApplication: 	at org.appcelerator.titanium.view.TiCompositeLayout.onMeasure(TiCompositeLayout.java:303)
[ERROR] :  TiApplication: 	at android.view.View.measure(View.java:19730)
[ERROR] :  TiApplication: 	at org.appcelerator.titanium.view.TiCompositeLayout.constrainChild(TiCompositeLayout.java:445)
[ERROR] :  TiApplication: 	at org.appcelerator.titanium.view.TiCompositeLayout.onMeasure(TiCompositeLayout.java:303)
[ERROR] :  TiApplication: 	at android.view.View.measure(View.java:19730)
[ERROR] :  TiApplication: 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
[ERROR] :  TiApplication: 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
[ERROR] :  TiApplication: 	at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:135)
[ERROR] :  TiApplication: 	at android.view.View.measure(View.java:19730)
[ERROR] :  TiApplication: 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
[ERROR] :  TiApplication: 	at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:391)
[ERROR] :  TiApplication: 	at android.view.View.measure(View.java:19730)
[ERROR] :  TiApplication: 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
[ERROR] :  TiApplication: 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
[ERROR] :  TiApplication: 	at android.view.View.measure(View.java:19730)
[ERROR] :  TiApplication: 	at android.widget.LinearLayout.measureVertical(LinearLayout.java:911)
[ERROR] :  TiApplication: 	at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
[ERROR] :  TiApplication: 	at android.view.View.measure(View.java:19730)
[ERROR] :  TiApplication: 	at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6120)
[ERROR] :  TiApplication: 	at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
[ERROR] :  TiApplication: 	at com.android.internal.policy.DecorView.onMeasure(DecorView.java:687)
[ERROR] :  TiApplication: 	at android.view.View.measure(View.java:19730)
[ERROR] :  TiApplication: 	at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2271)
[ERROR] :  TiApplication: 	at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1358)
[ERROR] :  TiApplication: 	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1607)
[ERROR] :  TiApplication: 	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1246)
[ERROR] :  TiApplication: 	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6301)
[ERROR] :  TiApplication: 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:871)
[ERROR] :  TiApplication: 	at android.view.Choreographer.doCallbacks(Choreographer.java:683)
[ERROR] :  TiApplication: 	at android.view.Choreographer.doFrame(Choreographer.java:619)
[ERROR] :  TiApplication: 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
[ERROR] :  TiApplication: 	at android.os.Handler.handleCallback(Handler.java:751)
[ERROR] :  TiApplication: 	at android.os.Handler.dispatchMessage(Handler.java:95)
[ERROR] :  TiApplication: 	at android.os.Looper.loop(Looper.java:154)
[ERROR] :  TiApplication: 	at android.app.ActivityThread.main(ActivityThread.java:6077)
[ERROR] :  TiApplication: 	at java.lang.reflect.Method.invoke(Native Method)
[ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
[ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

@hansemannn
Copy link
Collaborator

@lokeshchdhry Does it crash with master (non-PR) as well? Wondering because there is no proxy-change related to the crash.

@m1ga
Copy link
Contributor Author

m1ga commented Jun 14, 2017

I'll have a look at that again! It might be related to this PR: #8948 ?

@lokeshchdhry
Copy link
Contributor

@hansemannn , Yes I get the same error with a non-PR build as well when I run the test code above.

@hansemannn
Copy link
Collaborator

@garymathews might be the Android 7 PR then.

@hansemannn
Copy link
Collaborator

hansemannn commented Jun 24, 2017

@lokeshchdhry Can we revalidate that now that the list-view issue is fixed? I would need this PR in one of my projects as well. :)

@garymathews
Copy link
Contributor

@hansemannn @lokeshchdhry #9144 needs to be merged before this can be reviewed (to fix the crash bug).

@hansemannn hansemannn merged commit f20fc4d into tidev:master Jul 19, 2017
lokeshchdhry pushed a commit that referenced this pull request Jul 25, 2017
[TIMOB-24174] (6_1_X) Android: Update ListView check/disclosure/child graphics #8832
@jquick-axway
Copy link
Contributor

@m1ga, I know I'm late to the party here, but I'd like to add some feedback.

I don't think we should be custom loading these drawable images via the _48, _72, _96, etc. postfix notation. Instead, it would be better to take advantage of Android's built-in density aware drawable folders (ex: drawable-mdpi, drawable-hdpi, etc.) since the Android OS will automatically load the correct density scaled drawable for us... or the closest match in case we're running on under a DPI that we don't have an image. This will help make it more future proof for DPIs that we current do not support, such as tvdpi (sometimes used by tablets like the 1st generation Nexus 7), and Android will also auto-scale the drawable up to match the current DPI. An additional advantage of this approach is that you can then always assume a drawable will always be loaded as "48dp" (the mdpi base resolution), even if you don't have a matching drawable matching the device's DPI.

So, I recommend we do the following:

  • Move the UI module's drawable images to the following new directories:
    • drawable/*_36.png -> drawable-ldpi
    • drawable/*_48.png -> drawable-mdpi
    • drawable/*_72.png -> drawable-hdpi
    • drawable/*_96.png -> drawable-xhdpi
    • drawable/*_144.png -> drawable-xxhdpi
    • drawable/*_192.png -> drawable-xxxhdpi
  • Remove all the postfixed _### parts from the file names.
  • Delete the UI module's res/drawable directory.
  • Remove the TiRHelper.getImageRessource() method you've added.
    • The way it's loading drawables is non-standard. Might confuse developers.
  • Acquire these drawable images' resource IDs as follows:
    • int resId = TiRHelper.getResource("drawable." + imageName, false);

Sorry to picky about this. I know you didn't come up with this custom image loading scheme. But I think this is the best way to resolve this for good. And I appreciate you take a stab at this.

@jquick-axway
Copy link
Contributor

Also, if we do what I suggested above, we may want to prefix these drawable images with "titanium_*.png" to avoid name collision with the Titanium developer's own resource image files. Standard practice on Android is to use a C-style prefixing notation like this. (Ex: Facebook SDK uses a "fb_" prefix for its resources.)

@m1ga
Copy link
Contributor Author

m1ga commented Jul 26, 2017

@jquick-axway Sounds like a good idea! I'll have a look at this, thank you for the feedback

@m1ga m1ga deleted the listview branch December 10, 2022 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants