Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View sonnguyen0310's full-sized avatar

sonnguyen0310

View GitHub Profile
@sonnguyen0310
sonnguyen0310 / View.kt
Created January 12, 2021 01:13
Android Kotlin's extension rounded corner any view
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
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 July 2, 2018 08:31
iOS 11: Change size of UIBarButtonItem (image) in Swift 3
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 June 15, 2018 10:03
Accessing ResourceDictionary from xaml to c# programmatically
(Color) App.Current.Resources["textColor"];
@sonnguyen0310
sonnguyen0310 / gist:d09cb346a1a322c4889d54142545f9a9
Created June 11, 2018 10:05
Xamarin form PropertyChangedEventHandler
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 October 19, 2017 16:52
Get current child fragment in viewpager
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 March 23, 2016 07:28
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console