Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Issue 2738503007: POC: Use a tint list to change colors (Closed)

Created:
3 years, 9 months ago by ortuno
Modified:
3 years, 8 months ago
Reviewers:
Ted C
CC:
agrieve+watch_chromium.org, chromium-reviews
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

POC: Use a tint list to change colors DO NOT SUMMIT

Patch Set 1 #

Patch Set 2 : Show which test fails #

Total comments: 13

Patch Set 3 : Stop calling notifyDataSetChanged() when tapping on item #

Messages

Total messages: 10 (1 generated)
ortuno
https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java File chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java (right): https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java#newcode389 chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java:389: mConnectedIcon.getConstantState().newDrawable().mutate(), Creating a new Drawable for each item seemed ...
3 years, 9 months ago (2017-03-08 05:55:41 UTC) #1
Ted C
https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java File chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java (right): https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java#newcode389 chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java:389: mConnectedIcon.getConstantState().newDrawable().mutate(), On 2017/03/08 05:55:41, ortuno wrote: > Creating a ...
3 years, 9 months ago (2017-03-08 20:54:03 UTC) #3
ortuno
https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java File chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java (right): https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java#newcode389 chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java:389: mConnectedIcon.getConstantState().newDrawable().mutate(), On 2017/03/08 at 20:54:03, Ted C wrote: > ...
3 years, 9 months ago (2017-03-08 23:23:59 UTC) #4
Ted C
https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java File chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java (right): https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java#newcode389 chrome/android/java/src/org/chromium/chrome/browser/BluetoothChooserDialog.java:389: mConnectedIcon.getConstantState().newDrawable().mutate(), On 2017/03/08 23:23:58, ortuno wrote: > On 2017/03/08 ...
3 years, 9 months ago (2017-03-09 17:03:26 UTC) #5
ortuno
So to sum up I had three concerns with this approach: 1. Some hacky calls ...
3 years, 9 months ago (2017-03-10 00:38:49 UTC) #6
Ted C
On 2017/03/10 00:38:49, ortuno wrote: > So to sum up I had three concerns with ...
3 years, 9 months ago (2017-03-10 05:10:55 UTC) #7
Ted C
https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java File chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java (right): https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java#newcode366 chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java:366: row.mImageView.setImageDrawable(icon.mIcon); On 2017/03/10 00:38:49, ortuno wrote: > On 2017/03/09 ...
3 years, 9 months ago (2017-03-10 05:11:03 UTC) #8
ortuno
Seems like we resolved all my concerns! Thanks! I'll update the other patch. https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java File ...
3 years, 9 months ago (2017-03-13 06:13:23 UTC) #9
Ted C
3 years, 9 months ago (2017-03-13 22:56:23 UTC) #10
On 2017/03/13 06:13:23, ortuno wrote:
> Seems like we resolved all my concerns! Thanks! I'll update the other patch.
> 
>
https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src...
> File
chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java
> (right):
> 
>
https://codereview.chromium.org/2738503007/diff/20001/chrome/android/java/src...
>
chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java:366:
> row.mImageView.setImageDrawable(icon.mIcon);
> On 2017/03/10 at 05:11:03, Ted C wrote:
> > On 2017/03/10 00:38:49, ortuno wrote:
> > > On 2017/03/09 at 17:03:26, Ted C wrote:
> > > > On 2017/03/08 23:23:58, ortuno wrote:
> > > > > On 2017/03/08 at 20:54:03, Ted C wrote:
> > > > > > If you were to do row.mImageView.jumpToDrawableState(); would that
> address
> > > it?
> > > > > > 
> > > > > > You definitely shouldn't have to set it to null for this to get
> reflected,
> > > so
> > > > > there is something wonky going on.  When you say the drawable state
> isn't
> > > > > reflected, are you seeing the tint not being updated to the state you
> > > expect?
> > > > > 
> > > > > The behavior is rather weird as if the state is not propagated to the
> > > > > ImageView's drawable:
> > > > > 
> > > > > 1. See item with icon
> > > > > 2. Tap on item to select it -> Nothing happens
> > > > > 3. Wait a couple of minutes or scroll all the way down the list ->
> Icon's
> > > color
> > > > > changes O.O
> > > > > 
> > > > > I tried with jumpDrawablesToCurrentState() and invalidateDrawable()
> neither
> > > > > worked.
> > > > 
> > > > Tapping on an item results in notifyDataSetChanged?
> > > 
> > > This was it! We were calling notifyDataSetChanged() in onItemClick()[1]
> because
> > > older code used to manually set the color. I guess the state wasn't being
> set
> > > into the new drawable. Removing that line fixed the issue. I think it's
> > > interesting that the TextView which also uses a tint list didn't suffer
from
> > > this.
> > > 
> > > [1]
> > >
>
https://cs.chromium.org/chromium/src/chrome/android/java/src/org/chromium/chr...
> > > 
> > > >  I wouldn't necessarily have expected this function to be called at all
on
> tap
> > > (scrolling would because eventually the list items would need to be
> rebuilt).
> > > > 
> > > > I'd probably just create an quick extension to ImageView that logs what
> > > drawable states are being set to verify.  Something seems weird here in
> terms of
> > > state being applied and I'd be inclined to think our tint list isn't
correct
> or
> > > the list view isn't applying the state we expect.
> > 
> > Are you saying that removing notifyDataSetChanged solved this issue?   That
is
> actually the opposite of what I expected to be honest.
> > 
> > If removing notifyDataSetChanged solves the problem, it might come back if
you
> were to select something and scroll the list to where the item was off screen
> and then back on (where the views would be regenerated), so the items might be
> wrong at that point.
> > 
> 
> Right, the icon turned grey for a bit when I scrolled back really fast.
> 
> > Maybe we need to be calling:
> >
>
https://developer.android.com/reference/android/view/View.html#setSelected(bo...
> > 
> > On the image view in this case if it is part of the selected row.
> > 
> > You "should" be able to call notifyDataSetChanged many times (it would be
very
> inefficient if you did), but it would be regenerate all the views in their
> current state.
> 
> tldr; Calling setSelected fixed the problem.
> 
> So I added a couple log statements for ImageView#isSelected and
> Drawable#getState().
> 
> Calling notifyDataSetChanged in onItemClicked():
>  - The Drawable state doesn't change. Stays as state_enabled. Future calls to
> notifyDataSetChange from us don't change the state but after a couple of
seconds
> there is another call to notifyDataSetChanged (unsure where it comes from) and
> then the drawable state changes to state_active
>  - ImageView#isSelected stays as false
> 
> Not calling notifyDataSetChanged in onItemClicked():
>   - The Drawable state changes immediately to state_active
>   - ImageView#isSelected stays as false
> 
> Calling notifyDataSetChanged in onItemClicked and calling
ImageView#setSelected.
>   - The drawable state immediately changes to state_selected
>   - ImageView#isSelected becomes true

You'll likely want to call setSelected in notifyDataSetChanged as well
to ensure the views are recycled correctly.

> 
> Seems live we've been incorrectly using state_activated instead of
> state_selected.
> 
> I'll do the following:
> 
> 1. Send out patch to use state_selected for the text color and call
> TextView#setSelected. Should I add a test to make sure the view is marked as
> selected?
> 2. Fix this patch to use state_selected for the icon color and call
> ImageView#setSelected.
> 
> Does that sound good to you?

Sounds good to me!  We "might" want to keep state_activated and add
state_selected if the tint is shared among other things (or at least
confirm it doesn't break them).

Thanks for all the investigation work you did as well!

Powered by Google App Engine
This is Rietveld 408576698