-
-
Notifications
You must be signed in to change notification settings - Fork 671
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
Implemented Selection.set_font() for Android #2130
Open
t-arn
wants to merge
21
commits into
beeware:main
Choose a base branch
from
t-arn:selection_setfontV2_5b94842
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
37d6551
implemented TogaSpinnerAdapter
t-arn f8d428c
fixed some bugs; applied black
t-arn e95e04d
added remaining Adapter methods
t-arn e94c038
Renamed TogaSpinnerAdapter to TogaArrayAdapter
t-arn 057afb7
Fixed logic to get the default values
t-arn 27e93cc
removed examples/tutorial0/static
t-arn c5f1378
Added news fragment
t-arn e3e95a6
Mergedbranch 'main' into selection_setfontV2_5b94842
t-arn 7a26027
cleanup;
t-arn d019817
Merge branch 'main' into selection_setfontV2_5b94842
t-arn 67a16fd
added testbed probes
t-arn 99644e4
fixed testbed probe
t-arn c172e07
fixed set_font() so it also works after widget creation
t-arn 19951dd
Fixed set_font(), so get_textsize() and get_typeface() return the cor…
t-arn c8a34db
Removed impl.get_textsize() and impl.get_typeface();
t-arn 9a50e01
Removed cache font values;
t-arn aa1b2d3
Merge branch 'main' into selection_setfontV2_5b94842
t-arn 5afcc4c
Replaced Font.appy() with Label.set_textview_font()
t-arn 5417c42
Changed testbed to reset changed attributes one by one to avoid trigg…
t-arn de8694a
fixups
t-arn a8207cd
Reverted changes in testbed properties.py
t-arn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,9 @@ | |
|
||
from android import R | ||
from android.view import View | ||
from android.widget import AdapterView, ArrayAdapter, Spinner | ||
from android.widget import AdapterView, ArrayAdapter, Spinner, SpinnerAdapter | ||
|
||
from . import label | ||
from .base import Widget | ||
|
||
|
||
|
@@ -20,14 +21,90 @@ def onNothingSelected(self, parent): | |
self.impl.on_change(None) | ||
|
||
|
||
class TogaArrayAdapter(dynamic_proxy(SpinnerAdapter)): | ||
def __init__(self, impl): | ||
super().__init__() | ||
self.impl = impl | ||
self._default_textsize = -1 | ||
self._default_typeface = None | ||
self.adapter = ArrayAdapter( | ||
self.impl._native_activity, R.layout.simple_spinner_item | ||
) | ||
self.adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item) | ||
|
||
def apply_font(self, tv): | ||
if self.impl._font_impl and tv: | ||
label.set_textview_font( | ||
tv, | ||
self.impl._font_impl, | ||
self._default_typeface, | ||
self._default_textsize, | ||
) | ||
|
||
def cache_textview_defaults(self, tv): | ||
self._default_textsize = tv.getTextSize() | ||
self._default_typeface = tv.getTypeface() | ||
|
||
def getDropDownView(self, position, convertView, parent): | ||
tv = self.adapter.getDropDownView(position, convertView, parent) | ||
self.apply_font(tv) | ||
return tv | ||
|
||
def getView(self, position, convertView, parent): | ||
tv = self.adapter.getView(position, convertView, parent) | ||
if self._default_textsize == -1: | ||
self.cache_textview_defaults(tv) | ||
self.apply_font(tv) | ||
return tv | ||
|
||
def clear(self): | ||
return self.adapter.clear() | ||
|
||
def getAutofillOptions(self): | ||
return self.adapter.getAutofillOptions() | ||
|
||
def getCount(self): | ||
return self.adapter.getCount() | ||
|
||
def getItem(self, position): | ||
return self.adapter.getItem(position) | ||
|
||
def getItemId(self, position): | ||
return self.adapter.getItemId(position) | ||
|
||
def getItemViewType(self, position): | ||
return self.adapter.getItemViewType(position) | ||
|
||
def getViewTypeCount(self): | ||
return self.adapter.getViewTypeCount() | ||
|
||
def hasStableIds(self): | ||
return self.adapter.hasStableIds() | ||
|
||
def insert(self, object, index): | ||
return self.adapter.insert(object, index) | ||
|
||
def isEmpty(self): | ||
return self.adapter.isEmpty() | ||
|
||
def registerDataSetObserver(self, observer): | ||
self.adapter.registerDataSetObserver(observer) | ||
|
||
def remove(self, object): | ||
self.adapter.remove(object) | ||
|
||
def unregisterDataSetObserver(self, observer): | ||
self.adapter.unregisterDataSetObserver(observer) | ||
|
||
|
||
class Selection(Widget): | ||
focusable = False | ||
_font_impl = None | ||
|
||
def create(self): | ||
self.native = Spinner(self._native_activity, Spinner.MODE_DROPDOWN) | ||
self.native.setOnItemSelectedListener(TogaOnItemSelectedListener(impl=self)) | ||
self.adapter = ArrayAdapter(self._native_activity, R.layout.simple_spinner_item) | ||
self.adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item) | ||
self.adapter = TogaArrayAdapter(impl=self) | ||
self.native.setAdapter(self.adapter) | ||
self.last_selection = None | ||
|
||
|
@@ -87,3 +164,9 @@ def rehint(self): | |
self.native.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED) | ||
self.interface.intrinsic.width = at_least(self.native.getMeasuredWidth()) | ||
self.interface.intrinsic.height = self.native.getMeasuredHeight() | ||
|
||
def set_font(self, font): | ||
self._font_impl = font._impl | ||
tv = self.native.getSelectedView() | ||
if tv: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As above - how/when is this branch not triggered? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. During the creation of the widget, I saw that set_font() is called and tv was null |
||
self.adapter.apply_font(tv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The set_font() method has been implemented for Selection on Android |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How/when does this method get invoked when tv is None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During the creation of the widget, this can happen.