Skip to content

Instantly share code, notes, and snippets.

View antocara's full-sized avatar

antocara antocara

View GitHub Profile
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) {
@antocara
antocara / gist:5fb2904df2c7de34ebe9
Last active September 16, 2023 06:22
Convert View to Bitmap Android
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());
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: () {
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: () {
Future _showMyDialog(BuildContext context) async {
return showDialog(
context: context,
builder: (_) => _buildAlertDialog(),
);
}
Future _showMyDialog(BuildContext context) async {
return showCupertinoDialog(
context: context,
builder: (_) => _buildAlertDialog(),
);
}
lazy var session: URLSession = {
let configuration = URLSessionConfiguration.default
configuration.requestCachePolicy = .returnCacheDataElseLoad
return URLSession(configuration: configuration)
}()
private func dateFromResponse(cachedResponse: CachedURLResponse?) -> Date?{
return (cachedResponse?.response as? HTTPURLResponse)?.value(forHTTPHeaderField: "Date")?.formatResponseHeaderDate()
}
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)
}
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