<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Valeria Chub on Medium]]></title>
        <description><![CDATA[Stories by Valeria Chub on Medium]]></description>
        <link>https://medium.com/@valeriachub?source=rss-4934e3f94e9d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*PO3EwOOiR81Lzcrnwf6OTA.jpeg</url>
            <title>Stories by Valeria Chub on Medium</title>
            <link>https://medium.com/@valeriachub?source=rss-4934e3f94e9d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 19 May 2026 12:48:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@valeriachub/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[iOS Notes — CALayers.]]></title>
            <link>https://medium.com/@valeriachub/ios-notes-calayers-64108a3c7114?source=rss-4934e3f94e9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/64108a3c7114</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[calayer]]></category>
            <category><![CDATA[uiview]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Valeria Chub]]></dc:creator>
            <pubDate>Wed, 20 Feb 2019 12:38:52 GMT</pubDate>
            <atom:updated>2019-02-20T12:38:52.785Z</atom:updated>
            <content:encoded><![CDATA[<h3>iOS Notes — CALayer.</h3><p>Under the hood of UIView.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2MDQZ5BdQgo5ViEUbTiviw.png" /></figure><blockquote>CALayers are simply classes representing a rectangle on the screen with visual content. Root layer of UIView.</blockquote><p><strong>CALayer properties = visual appearance</strong>, such as:</p><ul><li>The size and position of the layer;</li><li>The layer’s background color;</li><li>The contents of the layer;</li><li>The corners of the layer;</li><li>Shadow of the layer;</li><li>Stroke around the edges of the layer;</li><li>etc.</li></ul><p><strong>With CALayer you can:</strong></p><ol><li>Create some neat effects.</li></ol><p><em>Example:</em> Maybe you want to take an image, and put it in a white frame, and apply a shadow to it to make it look neat.</p><p>2. Create some neat animating effects.</p><p><em>Example: </em>You could start your image out with rounded corners, tap a button, and have it animate the corners back out to straight.</p><blockquote>The default layer class for a UIView is the plain-old CALayer class .But you can use one of the handy subclasses that are available, such as CAGradientLayer, CATextLayer, CAShapeLayer, and others.</blockquote><h4>CALayer</h4><pre>self.view.layer.backgroundColor = [UIColor orangeColor].CGColor;<br>self.view.layer.cornerRadius = 20.0;<br>self.view.layer.frame = CGRectInset(self.view.layer.frame, 20, 20);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hd5EXN7fkxd5WJ-b-zRTRg.png" /></figure><h4>Sublayer of CALayer</h4><pre>CALayer *sublayer = [CALayer layer];<br>sublayer.backgroundColor = [UIColor blueColor].CGColor;<br>sublayer.shadowOffset = CGSizeMake(0, 3);<br>sublayer.shadowRadius = 5.0;<br>sublayer.shadowColor = [UIColor blackColor].CGColor;<br>sublayer.shadowOpacity = 0.8;<br>sublayer.frame = CGRectMake(30, 30, 128, 192);<br>[self.view.layer addSublayer:sublayer];</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AXWnYs-RXMke1Y-R9PGzkg.png" /></figure><h4>Image Sublayer of CALayer</h4><pre>sublayer.contents = (id) [UIImage imageNamed:@&quot;BattleMapSplashScreen.jpg&quot;].CGImage;<br>sublayer.borderColor = [UIColor blackColor].CGColor;<br>sublayer.borderWidth = 2.0;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VRRJ724v4xs9M6Za5sHXBA.png" /></figure><h4>Rounded corner Image Sublayer of CALayer</h4><pre><strong>CALayer *sublayer = [CALayer layer]</strong>;<br>sublayer.backgroundColor = [UIColor blueColor].CGColor;<br>sublayer.shadowOffset = CGSizeMake(0, 3);<br>sublayer.shadowRadius = 5.0;<br>sublayer.shadowColor = [UIColor blackColor].CGColor;<br>sublayer.shadowOpacity = 0.8;<br>sublayer.frame = CGRectMake(30, 30, 128, 192);<br>sublayer.borderColor = [UIColor blackColor].CGColor;<br>sublayer.borderWidth = 2.0;<br>sublayer.cornerRadius = 10.0;<br>[self.view.layer addSublayer:sublayer];<br><br><strong>CALayer *imageLayer = [CALayer layer];</strong><br>imageLayer.frame = sublayer.bounds;<br>imageLayer.cornerRadius = 10.0;<br>imageLayer.contents = (id) [UIImage imageNamed:@&quot;BattleMapSplashScreen.jpg&quot;].CGImage;<br><strong>imageLayer.masksToBounds = YES;</strong><br>[sublayer addSublayer:imageLayer];</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aM4FzuFbyl-Zhvzlu03QMA.png" /></figure><p>Thanks for reading this article. I hope that you have got something new for you. Be sure to click ❤ below to recommend this article if you found it helpful. It means a lot to me. It inspires me.</p><p>Feel free to ask me any questions. Lets become friends on<strong> </strong><a href="https://www.linkedin.com/in/valeria-chub-a0b218121"><strong>Linkedin</strong></a> :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64108a3c7114" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Life by Valeria.]]></title>
            <link>https://medium.com/series/life-by-valeria-9930411f1ca2?source=rss-4934e3f94e9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9930411f1ca2</guid>
            <dc:creator><![CDATA[Valeria Chub]]></dc:creator>
            <pubDate>Wed, 20 Feb 2019 12:02:37 GMT</pubDate>
            <atom:updated>2019-02-20T12:02:37.923Z</atom:updated>
            <content:encoded><![CDATA[<h3>Hello, world!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9930411f1ca2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Assert() vs Require()]]></title>
            <link>https://medium.com/@valeriachub/assert-vs-require-53ef2b1fc0a?source=rss-4934e3f94e9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/53ef2b1fc0a</guid>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[solidity]]></category>
            <dc:creator><![CDATA[Valeria Chub]]></dc:creator>
            <pubDate>Fri, 09 Feb 2018 13:44:06 GMT</pubDate>
            <atom:updated>2019-02-20T12:55:26.014Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gbFcFp4iObZykRu6EpKUcA.png" /></figure><p>The functions <strong><em>assert()</em></strong> and <strong><em>require()</em></strong> are used for check a condition.</p><p>Lets see what will be if the condition is <strong><em>false:</em></strong></p><ul><li><strong><em>assert(false) </em></strong>— compiles to <strong><em>0xfe</em></strong>, which is an invalid opcode, using up all remaining gas, and reverting all changes.</li><li><strong><em>require(false) </em></strong>— compiles to <strong><em>0xfed </em></strong>which is the <strong><em>REVERT </em></strong>opcode, meaning it will refund the remaining gas.</li></ul><p>Due to this, there are some tips which can help you to make a decision.</p><h3>1. Use assert() to:</h3><ul><li>check for overflow/underflow</li><li>check invariants</li><li>validate contract state <em>after</em> making changes</li><li>avoid conditions which should never, ever be possible.</li><li>Generally, you should use assert <strong><em>less often</em></strong></li><li>Generally, it will be use towards the end of your function.</li></ul><h3>2. Use require() to:</h3><ul><li>Validate user inputs</li><li>Validate the response from an external contract (for example, <strong><em>require(external.send(amount)) </em></strong>)</li><li>Validate state conditions prior to executing state changing operations, for example, in an owned contract situation</li><li>Generally, you should use require <strong><em>more often</em></strong></li><li>Generally, it will be used towards the beginning of a function.</li></ul><p>Thanks for reading this article. I hope that you have got something new for you. Be sure to click ❤ below to recommend this article if you found it helpful. It means a lot to me. It inspires me.</p><p>Feel free to ask me any questions. Lets become friends on<strong> </strong><a href="https://www.linkedin.com/in/valeria-chub-a0b218121"><strong>Linkedin</strong></a> :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=53ef2b1fc0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Classic chain AlarmManager — Service — BroadcastReceiver with new features from Android M and N]]></title>
            <link>https://medium.com/@valeriachub/classic-chain-alarmmanager-service-broadcastreceiver-with-new-features-from-android-m-and-n-14fc0b4cf0db?source=rss-4934e3f94e9d------2</link>
            <guid isPermaLink="false">https://medium.com/p/14fc0b4cf0db</guid>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-nougat]]></category>
            <category><![CDATA[androiddev]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-marshmallow]]></category>
            <dc:creator><![CDATA[Valeria Chub]]></dc:creator>
            <pubDate>Thu, 31 Aug 2017 13:25:38 GMT</pubDate>
            <atom:updated>2017-08-31T13:25:38.450Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UlUkY4r6HR_56sbDk2KrXQ.jpeg" /></figure><p>On 28 May 2015 and on 22 August 2016 Android M(arshmallow) and Android N(ougat) showed themselves to this wonderful world and the developers got their hearts beating with a new speed because of new cool features that Google has given to them.</p><p>This article is for people who have just started to learn Android development, but who is already in that time when Android M and N have been announced. In the article I will tell you what are the AlarmManager, Service and BroadcastReceiver and how to make them work in a team, that can help you to manage repeating actions in your application. And also I will introduce you with a new features in Android M — Doze Mode and Android N — Direct Boot Mode and show how to use them to have all benefits from Google updates and how that was before.</p><h3>Our task:</h3><p>The simplest example. We have two places of data sources: server A which generates some data, server B where we want to send that data to mix it with another one. We have all APIs for using the data from the both sides. We need to create a synchronizer, which will send the data from place A to place B every day with a determined frequency.</p><p>To make that we need:</p><ol><li><strong>AlarmManager</strong> which will work every day on a determined time;</li><li><strong>Service</strong> which will synchronize the data from A to B (lets call it SyncService);</li><li><strong>BroadcastReceiver</strong> which will help us to manage some actions when the system was rebooted (lets call it BootCompletedBroadcast) and a <strong>Service</strong> which will be called from <strong>BroadcastReceiver</strong> to manage our alarm (lets call it BootCompletedService).</li></ol><h3>1. AlarmManager</h3><blockquote><a href="https://developer.android.com/reference/android/app/AlarmManager.html"><strong>AlarmManager</strong></a> provides access to the system alarm services. These allow to schedule the application to be run at some point in the future.</blockquote><p>First of all we should create an <strong>AlarmManager.</strong></p><pre>AlarmManager alarmManager = (AlarmManager)    context.getSystemService(Context.<strong><em>ALARM_SERVICE</em></strong>);</pre><p>Then we declare a new <strong>Intent</strong> which will execute our service for synchronizing the data and wrap it in a new <strong>PendingIntent.</strong></p><blockquote>An <a href="https://developer.android.com/reference/android/content/Intent.html"><strong>Intent</strong></a> is an abstract description of an operation to be performed. It is an abstract representation of an action . By using the Intent class we, for example, start activities within a application, or communicate with components defined by the Android system (Activity, Service, ContentProvider, BroadcastReceiver).</blockquote><blockquote>A <a href="https://developer.android.com/reference/android/app/PendingIntent.html"><strong>PendingIntent</strong></a> is a wrapper, which allows the another application to execute some code of our own application with the permissions of our application. Some code here means our intent.</blockquote><pre><strong>private static final int <em>RQ_SYNC_SERVICE </em></strong>= 1101;</pre><pre>Intent intent = <strong>new </strong>Intent(context, SyncService.<strong>class</strong>);<br>PendingIntent pendingIntent = PendingIntent.<em>getService</em>(context, <strong><em>RQ_SYNC_SERVICE</em></strong>, intent, 0);</pre><p>Finally we have come to the most interesting part of the <a href="https://developer.android.com/reference/android/app/AlarmManager.html">AlarmManager</a>. There are different variants to set an alarm. For our purpose was chosen only 3 and I will explain you why.</p><ol><li><strong><em>void set (int type, long triggerAtMillis, PendingIntent operation) </em></strong>ordinary method to set the alarm added in API level 1. BUT! The world isn’t interesting if all work so easy. The method <strong>set(int, long, PendingIntent) </strong>works like a charm and does its main job only before the API 19. Be sure if the application’s <strong><em>targetSdkVersion</em></strong> is below API 19, all of its scheduled alarms will be treated as exact. Beginning in API 19, the trigger time passed to this method is treated as inexact: the alarm will not be delivered before this time, but may be deferred and delivered some time later.</li><li><strong><em>void setExact (int type, long triggerAtMillis, PendingIntent operation) </em></strong>new method to set the alarm added in API level 19. It doesn’t permit the OS to adjust the delivery time. The alarm will be delivered as nearly as possible to the requested trigger time.</li><li><strong><em>void setExactAndAllowWhileIdle (int type, long triggerAtMillis, PendingIntent operation) </em></strong>another<strong><em> </em></strong>method to set the alarm added in API level 23. It is like <strong><em>setExact (int, long, PendingIntent)</em></strong>, but this alarm will be allowed to execute even when the system is in low-power idle modes. But what is the low-power idle mode? One of the new features of Android M is Doze Mode. This mode means that then the device lays without moving and without charging, after an hour it goes into Doze Mode — shutdown mode, when almost all applications stop using battery, they sleep. But don’t worry, when the user takes the device in his hands all applications wake up. So, to allow our alarm to execute exactly in time on Android M, we use the method <strong><em>setExactAndAllowWhileIdle (int, long, PendingIntent).</em></strong></li></ol><p>And now here is my “lovely” if-else-if-else <em>(joke)</em>:</p><pre><strong>if </strong>(Build.VERSION.<strong><em>SDK_INT </em></strong>&gt;= Build.VERSION_CODES.<strong><em>M</em></strong>) {<br>     alarmManager.setAndAllowWhileIdle(AlarmManager.<strong><em>RTC_WAKEUP</em></strong>,  targetTime, pendingIntent);<br>} <br><strong>else if </strong>(Build.VERSION.<strong><em>SDK_INT </em></strong>&gt;= Build.VERSION_CODES.<strong><em>KITKAT</em></strong>) {<br>     alarmManager.setExact(AlarmManager.<strong><em>RTC_WAKEUP</em></strong>, frequency, pendingIntent);<br>} <br><strong>else </strong>{<br>     alarmManager.set(AlarmManager.<strong><em>RTC_WAKEUP</em></strong>, frequency, pendingIntent);<br>}</pre><p>But you can simplify the code by removing <strong><em>set(int, long, PendingIntent)</em></strong>, all will work as expected.</p><h3>2. Service</h3><p>There are two types of services in Android which can help us to achieve the goal: IntentService and Service. Some words about their differences.</p><p><strong><em>When to use</em></strong></p><ul><li>The <strong>Service</strong> can be used in tasks with no UI, but shouldn’t be too long.</li><li>The <strong>IntentService</strong> can be used in long tasks usually with no communication to Main Thread. Another case of use is when callbacks are needed (Intent triggered tasks).</li></ul><p><strong><em>Runs On</em></strong></p><ul><li>The <strong>Service</strong> runs in background but it runs on the Main Thread of an application.</li><li>The <strong>IntentService</strong> runs on a separate worker thread.</li></ul><p><strong><em>Limitations / Drawbacks</em></strong></p><ul><li>The <strong>Service</strong> may block the Main Thread of an application.</li><li>The <strong>IntentService</strong> cannot run tasks in parallel. Hence all the consecutive intents will go into the message queue for the worker thread and will execute sequentially.</li></ul><p>So for our task, we have chosen an <strong>IntentService</strong>, because it is used for long tasks and works in a separate thread. The simplest <strong>IntentService </strong>looks like this:</p><pre><strong>public class </strong>SyncService <strong>extends </strong>IntentService {<br>    <strong>public </strong>SyncService() {<br>        <strong>super</strong>(<strong>&quot;SyncService&quot;</strong>);<br>    }<br><br>    @Override<br>    <strong>protected void </strong>onHandleIntent(@Nullable Intent intent) {<br>       // the code which will be executed when the service starts<br>    }<br>}</pre><p>Don’t forget to <a href="https://developer.android.com/guide/topics/manifest/service-element.html">register the service</a> in the AndroidManifest.xml:</p><pre>&lt;<strong>service<br>    android:name=&quot;.service.SyncService&quot;<br>    android:enabled=&quot;true&quot;<br>    android:exported=&quot;false&quot;<br>    android:process=&quot;:remote&quot;</strong>/&gt;</pre><h3>3. <strong>BroadcastReceiver</strong></h3><blockquote>A <a href="https://developer.android.com/reference/android/content/BroadcastReceiver.html"><strong>BroadcastReceiver</strong></a> is an Android component which allows to register for system or application events. All registered receivers for an event are notified by the Android runtime once this event happens. For example, applications can register for the <strong>ACTION_BOOT_COMPLETED</strong> system event which is fired once the Android system has completed the boot process.</blockquote><p>So the simplest <strong>BroadcastReceiver </strong>looks like this:</p><pre><strong>public class </strong>BootCompletedBroadcast <strong>extends </strong>BroadcastReceiver {<br>    @Override<br>    <strong>public void </strong>onReceive(Context context, Intent intent) {<br>        Intent i = <strong>new </strong>Intent(context, BootCompletedService.<strong>class</strong>);<br>        context.startService(i);<br>    }<br>}</pre><p>Also we need to register the <strong>BroadcastReceiver </strong>in the AndroidManifest.xml and add the permission <strong>RECEIVE_BOOT_COMPLETED:</strong></p><pre>&lt;<strong>manifest&gt;<br>...<br></strong>&lt;<strong>uses-permission android:name=&quot;android.permission.RECEIVE_BOOT_COMPLETED&quot;</strong>/&gt;<br>...<br><strong>&lt;application&gt;<br>...<br></strong>&lt;<strong>receiver<br>    android:name=&quot;.service.BootCompletedBroadcast&quot;<br>    android:directBootAware=&quot;true&quot;<br>    android:enabled=&quot;true&quot;<br>    android:exported=&quot;true&quot;</strong>&gt;<br>    &lt;<strong>intent-filter</strong>&gt;<br>        &lt;<strong>action android:name=&quot;android.intent.action.BOOT_COMPLETED&quot;</strong>/&gt;<br>        &lt;<strong>action android:name=&quot;android.intent.action.LOCKED_BOOT_COMPLETED&quot;</strong>/&gt;<br>    &lt;/<strong>intent-filter</strong>&gt;<br>&lt;/<strong>receiver</strong>&gt;<br><strong>&lt;/application&gt;<br>&lt;/manifest&gt;</strong></pre><p>Keep attention, please! Now i am going to speak about Android N new feature that should know everybody to make the code works properly.</p><p>There is a problem (or a feature) on the Android devices when it reboots, which causes the device’s storage to be encrypted until the user enters his credentials. Applications can’t function normally until the device is decrypted, so at this point the device can’t perform essential tasks such as receiving incoming calls, emails or messages. It also means applications can’t deliver notifications, or act on scheduled alarms . This means that applications that schedule alarms, or provide important and timely notifications, can’t run. This problem Android N solves with the introduction of Direct Boot mode.</p><blockquote>Direct Boot is, essentially, the new name for that strange no-man’s land where the device has finished rebooting but isn’t fully initialized yet. Direct Boot mode allows applications to perform limited tasks and access specific sections of data, even when the device is encrypted.</blockquote><p>To make the application work properly and use a new feature from Android N for getting notifications or alarms in Direct Boot mode, we set an attribute <strong>directBootAware </strong>to be<strong> true </strong>in the <strong>BroadcastReceiver</strong>.</p><pre><strong>android:directBootAware=&quot;true&quot;</strong></pre><p>And add a new flag <strong>LOCKED_BOOT_COMPLETED, </strong>which works in a Direct Boot mode. On pre Android N devices we still use <strong>BOOT_COMPLETED </strong>to get rebooting action.</p><pre>&lt;<strong>action android:name=&quot;android.intent.action.BOOT_COMPLETED&quot;</strong>/&gt;<br>&lt;<strong>action android:name=&quot;android.intent.action.LOCKED_BOOT_COMPLETED&quot;</strong>/&gt;</pre><p>And the service which will be called from <strong>BroadcastReceiver</strong> to manage our alarm looks like this:</p><pre><strong>public class </strong>BootCompletedService <strong>extends </strong>IntentService {<br>    <strong>public </strong>BootCompletedService(String name) {<br>        <strong>super</strong>(<strong>&quot;BootCompleted&quot;</strong>);<br>    }<br><br>    @Override<br>    <strong>protected void </strong>onHandleIntent(@Nullable Intent intent) {<br>        // register our alarm again because rebooting has canceled it<br>    }<br>}</pre><h3>Conclusion</h3><p>In this article we have learnt what is a chain AlarmManager — Service — BroadcastReceiver and where we can use it. Also we have told about new features from Android M — Doze Mode and from Android N — Direct Boot Mode and how to make them bring us all benefits from Google updates.</p><p>Thanks for reading this article. I hope that you have got something new for you. Be sure to click ❤ below to recommend this article if you found it helpful. It means a lot to me. It inspires me.</p><p>Feel free to ask me any questions. Lets become friends on<strong> </strong><a href="https://www.linkedin.com/in/valeria-chub-a0b218121"><strong>Linkedin</strong></a> :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14fc0b4cf0db" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>