Bar 2: Chord is G and A# resolves to B. A# is chromatic (or would it not be because this moves from G minor to G major?).
- A# is a chromatic approach, you're right. (g-minor would need a Bb)
Bar 20: Chord is E. G#'s in this bar are part of E, so not chromatic.
from bar 20 we are in A major and E is the dominant of A (secondary dominant of D)
- The G# in Bar 20 is the 3rd of E and leading tone to A and all the further G# in this section your showing have the same function.
Bar 28: Chord is F minor: B#(C) is tritone of F so is chromatic. G# is 2nd note of F minor scale, so not chromatic?
we are still in A major and its related key f# -minor (and not F!)
B# isn't the tritone of F anyway and here B# is a chromatic appraoch to the 5th of f#m (or the 3rd of A major if you want). The G# is still lead tone to A.
The question could be: Is the lead tone of the secondary 5th a chromatic?
Regarding the tonic key D major someone will say "yes" - but as the entire phrase from bar 20 - 30 is in the dominant key of A I would say: No, in my opinion (as this passage is tonisiced to A major).
The term secondary dominant (also applied dominant, artificial dominant, or borrowed dominant) refers to a triad or seventh chord with dominant function set to resolve to a scale degree other than the tonic, with the dominant of the dominant (written as V/V or V of V) being the most frequently encountered. The chord that the secondary dominant is the dominant of is said to be a temporarily tonicized chord. Tonicizations that last longer than a phrase are generally regarded as modulations to a new key (or new tonic).
Are these notes with accidentals chromatic?
Not all of them. When the section B (bars 17-32) are considered as modulated to A major - then G# will be the diatonic lead tone of this key.