Skip to content

Instantly share code, notes, and snippets.

Avatar

sonnguyen0310

View GitHub Profile
@sonnguyen0310
sonnguyen0310 / View.kt
Created Jan 12, 2021
Android Kotlin's extension rounded corner any view
View View.kt
fun View.clipToRounded(curveRadius: Float) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
outlineProvider = object : ViewOutlineProvider() {
override fun getOutline(view: View?, outline: Outline?) {
view?.let {
outline?.setRoundRect(0, 0, it.width, (view.height), curveRadius)
}
}
}
clipToOutline = true
View gist:7b0f8f4bae2a0731b601a5f23d01a2d9
var syncContext = SynchronizationContext.Current; // UI Thread
Task.Run(() =>
{
LatLon result = HeavyFunction(); // Run synchronously on background
syncContext.Post(state =>
{
// Run on UI Thread
map.Pins.Add(new Pin(…)); // Add pin or few pins
}, null);
@sonnguyen0310
sonnguyen0310 / gist:6720cbf39ce877c20fea1a987543fb99
Created Jul 2, 2018
iOS 11: Change size of UIBarButtonItem (image) in Swift 3
View gist:6720cbf39ce877c20fea1a987543fb99
func setUpMenuButton(){
let menuBtn = UIButton(type: .custom)
menuBtn.frame = CGRect(x: 0.0, y: 0.0, width: 20, height: 20)
menuBtn.setImage(UIImage(named:"menuIcon"), for: .normal)
menuBtn.addTarget(self, action: #selector(vc.onMenuButtonPressed(_:)), for: UIControlEvents.touchUpInside)
let menuBarItem = UIBarButtonItem(customView: menuBtn)
let currWidth = menuBarItem.customView?.widthAnchor.constraint(equalToConstant: 24)
currWidth?.isActive = true
let currHeight = menuBarItem.customView?.heightAnchor.constraint(equalToConstant: 24)
@sonnguyen0310
sonnguyen0310 / gist:9f8040ec7b376c035fd7864e3cf11e24
Created Jun 15, 2018
Accessing ResourceDictionary from xaml to c# programmatically
View gist:9f8040ec7b376c035fd7864e3cf11e24
(Color) App.Current.Resources["textColor"];
@sonnguyen0310
sonnguyen0310 / gist:d09cb346a1a322c4889d54142545f9a9
Created Jun 11, 2018
Xamarin form PropertyChangedEventHandler
View gist:d09cb346a1a322c4889d54142545f9a9
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
{
var changed = PropertyChanged;
if (changed == null)
return;
changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
@sonnguyen0310
sonnguyen0310 / gist:db7d669c4d75e444904f36298d0fdfe3
Last active Oct 19, 2017
Get current child fragment in viewpager
View gist:db7d669c4d75e444904f36298d0fdfe3
if (pageAdapter != null && viewpager != null && pageAdapter.instantiateItem(viewpager, viewpager.getCurrentItem()) instanceof Reloadable) {
((Reloadable) pageAdapter.get().instantiateItem(viewpager, viewpager.getCurrentItem())).reload();
}
@sonnguyen0310
sonnguyen0310 / 0_reuse_code.js
Created Mar 23, 2016
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console