This file contains hidden or 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
| extension URLSession { | |
| func handleTaskOrCache(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) { | |
| let cachedDataForRequest = fetchCachedResponse(request: request) | |
| guard let dateCache = dateFromResponse(cachedResponse: cachedDataForRequest) else { | |
| handleDataTask(request: request, completionHandler: completionHandler) | |
| return |
This file contains hidden or 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
| func formatResponseHeaderDate() -> Date?{ | |
| let dateFormatter = DateFormatter() | |
| dateFormatter.locale = Locale(identifier: "en_US_POSIX") // set locale to reliable US_POSIX | |
| dateFormatter.dateFormat = "EEE,d MMM yyyy HH:mm:ss zzz" | |
| dateFormatter.timeZone = TimeZone(abbreviation: "GMT") | |
| return dateFormatter.date(from: self) | |
| } |
This file contains hidden or 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
| private func dateFromResponse(cachedResponse: CachedURLResponse?) -> Date?{ | |
| return (cachedResponse?.response as? HTTPURLResponse)?.value(forHTTPHeaderField: "Date")?.formatResponseHeaderDate() | |
| } |
This file contains hidden or 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
| lazy var session: URLSession = { | |
| let configuration = URLSessionConfiguration.default | |
| configuration.requestCachePolicy = .returnCacheDataElseLoad | |
| return URLSession(configuration: configuration) | |
| }() |
This file contains hidden or 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
| Future _showMyDialog(BuildContext context) async { | |
| return showCupertinoDialog( | |
| context: context, | |
| builder: (_) => _buildAlertDialog(), | |
| ); | |
| } |
This file contains hidden or 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
| Future _showMyDialog(BuildContext context) async { | |
| return showDialog( | |
| context: context, | |
| builder: (_) => _buildAlertDialog(), | |
| ); | |
| } |
This file contains hidden or 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
| Widget _buildCupertinoAlertDialog() { | |
| return CupertinoAlertDialog( | |
| title: Text('Notificaciones'), | |
| content: | |
| Text("¿Desea recibir notificaciones? Serán muy pocas de verdad :)"), | |
| actions: [ | |
| FlatButton( | |
| child: Text("Aceptar"), | |
| textColor: Colors.blue, | |
| onPressed: () { |
This file contains hidden or 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
| Widget _buildAlertDialog() { | |
| return AlertDialog( | |
| title: Text('Notificaciones'), | |
| content: | |
| Text("¿Desea recibir notificaciones? Serán muy pocas de verdad :)"), | |
| actions: [ | |
| FlatButton( | |
| child: Text("Aceptar"), | |
| textColor: Colors.blue, | |
| onPressed: () { |
This file contains hidden or 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
| private void savedBitmapFromViewToFile(){ | |
| //inflate layout | |
| View layout = LayoutInflater.from(this).inflate(R.layout.activity_main, null, false); | |
| RelativeLayout mContImage = (RelativeLayout) layout.findViewById(R.id.image_cont); | |
| //reference View with image | |
| mContImage.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED); | |
| Bitmap bitmap = Bitmap.createBitmap(mContImage.getMeasuredWidth(), mContImage.getMeasuredHeight(), Bitmap.Config.ARGB_8888); | |
| Canvas canvas = new Canvas(bitmap); | |
| mContImage.layout(0, 0, mContImage.getMeasuredWidth(), mContImage.getMeasuredHeight()); |
This file contains hidden or 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
| public class CustomView extends View implements ValueAnimator.AnimatorUpdateListener { | |
| private Paint paint; | |
| private Path path; | |
| private int angleFinal = 360; | |
| private RectF rect; | |
| public CustomView(Context context) { |