All posts in Mobile Development

When you create and restore a TWRP backup (as example because you tried out a custom ROM and saw that it’s not good) you’ll be greeted with:

a) A “enter PIN before boot” screen
b) A wrong lockscreen code (either PIN or Pattern) when booted to Android

————————
HOW TO FIX
————————

  1. Simply boot into TWRP and enter your PIN (if you’ve set one) to decrypt the stroage. If you don’t have TWRP (for whatever reason) you can do so via ADB too but ONLY if you’ve connected your phone to your PC beforehand and also accepted it’s fingerprint on the phone itself.
  2. Delete (or rename) the following files inside /data/system (note that probably not all of them exist for you, simply delete those you can find):
    • password.key
    • pattern.key
    • locksettings.db-wal
    • locksettings.db-shm
    • locksettings.db
  3. Reboot the phone and (if you’ve set a PIN) enter it to decrypt the storage one more time. After that you can simply unlock your phone with a swipe.
  4. Go into Settings > Security and set your preferred unlock method again, Android will ask you if you want to set a boot-time code too. Select whatever you want here, it’s a nice security addition but can be annoying sometimes.
  5. Enjoy your phone again!

I hope this helps some people here since I was searching on how to fix this for almost an hour after restoring a backup. This is probably due to another ROM overwriting existing lockdata when you set a code there, then again you’d wipe the /data partition anyways so I have no clue why it’s still acting up like this…

Post originally appeared at:

https://visualstudiomagazine.com/articles/2017/09/06/free-xamarin-book.aspx?m=1

 

Microsoft has been publishing a series of free eBooks and accompanying blog posts providing guidance about .NET application architecture best practices, with the latest focusing on Xamarin.Forms patterns.

Previous guidance addressed microservices architecture, containerized Docker apps and modern Web apps with ASP.NET and Microsoft Azure. The guidance consists of detailed eBooks, end-to-end reference architecture applications used as examples and blog posts that can help developers get a gist of the guidance and decide if they want to dig deeper with an eBook and reference application.

The new guide, “Enterprise Application Patterns Using Xamarin.Forms,” includes source code for a container-based eShop that extends the previous microservice/containers scenario. It includes the following functionality:

  • Authenticating and authorizing with a back-end service.
  • Browsing a catalog of shirts, coffee mugs and other marketing items.
  • Filtering the catalog.
  • Ordering items from the catalog.
  • Viewing the user’s order history.
  • Configuring settings.

“Guidance is provided on how to implement MVVM, dependency injection, navigation, validation and configuration management while maintaining loose coupling,” Microsoft said in a blog post. “In addition, there’s also guidance on performing authentication and authorization with IdentityServer, accessing remote data from containerized microservices, and unit testing.”

Developers don’t have to create the full-blown implementation that consumes back-end services from containerized microservices, however. They can just consume mock data services if they aren’t interested in how to deploy fully functional back-end services.

Written by David Britch, the 91-page book reportedly provides a comprehensive solution for Business-to-Employee (B2E), Business-to-Business (B2B) and Business-to-Consumer (B2C) apps that can share code across all target platforms — iOS, Android and the Universal Windows Platform (UWP) — and help lower the total cost of ownership (TCO).

 

The entire series of eBook guides are available on Microsoft’s .NET Application Architecture site. The new Xamarin.Forms offering can be downloaded here (note that this link triggers an automatic download).

While primarily targeting an audience of developers interested in learning how to design and create cross-platform enterprise apps, the book says it can also serve to help technical decision-makers choose an appropriate approach for creating such apps.

The post originally appeared at:

Developers can use Effects in Xamarin Forms to customize native controls and add some styling of their own. But why not simply use a custom renderer to achieve the same thing? While that is certainly possible there are some benefits to Effects.

Why would you use Effects?

Contrary to a custom renderer that always targets controls of a specific type an effect can be re-used throughout your app. Another advantage is that you can parameterize your effects with additional data. Most people use effects to simply change properties of a native control that aren’t yet made available through the existing Xamarin Forms controls. Effects work by attaching/detaching them to/from a Xamarin Forms control.

To get a quick idea of how that looks in XAML:

<Entry Text=This entry is awesome! TextColor=White HeightRequest=100 VerticalOptions=Center HorizontalOptions=Fill>
<Entry.Effects>
<local:CatEffect />
</Entry.Effects>
</Entry>
view rawCatEffect.xaml hosted with ❤ by GitHub

You can add multiple effects to a control. As you might have noticed this gives you a lot of freedom because unlike a custom renderer you specifically decide which control gets the effect without any need to subclass it. When creating an effect it is not mandatory to implement it in each platform. You can create an effect and choose to only implement it in iOS. It’s completely optional.

Creating our first Effect

We’re going to create an effect which puts an awesome cat as the background image of an Entry. To get started we create a class in our PCL that inherits from RoutingEffect which has no code but we’re going to use it to make sure we can consume our effect in our XAML code:

public class CatEffect : RoutingEffect
{
public CatEffect () : base (“SuperAwesome.CatEffect”)
{
}
}
view rawCatEffect.cs hosted with ❤ by GitHub

This class calls the RoutingEffect base class constructor and passes in a string parameter. Take note of this parameter as you will be seeing it later on in this sample. It is used to initialize an instance of this effect at runtime and is a concatenation of 2 variables we’ll be seeing in the platform-specific implementations of our effect.

Creating the platform-specific code

To actually create the custom Effect you need to subclass the PlatformEffect class in your platform-specific projects and each platform-specific PlatformEffect class subsequently exposes the following properties for you to use:

  • Container – the platform-specific control being used to implement the layout.
  • Control – the platform-specific control.
  • Element – the Xamarin.Forms control that’s being rendered.

When inheriting from PlatformEffect you also gain access to two methods for you to override: OnAttached and OnDetached. You can use OnAttached to apply your effect and OnDetached to clean up your effect. Now let’s create our effect shall we?

On iOS we implement it as follows:

using System;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using SampleApp.iOS.Effects;
[assembly: ResolutionGroupName(SuperAwesome)]
[assembly: ExportEffect(typeof(CatEffect), CatEffect)]
namespace SampleApp.iOS.Effects
{
public class CatEffect : PlatformEffect
{
protected override void OnAttached()
{
try
{
if (Control is UITextField)
{
// Set the border style to none to show background image.
(Control as UITextField).BorderStyle = UITextBorderStyle.None;
// Create an image and set it as background pattern.
var image = UIImage.FromBundle(cat.jpg).CreateResizableImage(new UIEdgeInsets(0, 10, 0, 10), UIImageResizingMode.Stretch);
Control.BackgroundColor = UIColor.FromPatternImage(image);
}
}
catch (Exception ex)
{
Console.WriteLine(Cannot set property on attached control. Error: , ex.Message);
}
}
protected override void OnDetached()
{
// Back to white.
Control.BackgroundColor = UIColor.White;
}
}
}
view rawCatEffectiOS.cs hosted with ❤ by GitHub

On Android our effect code looks like this:

using System;
using SampleApp.Droid.Effects;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ResolutionGroupName(SuperAwesome)]
[assembly: ExportEffect(typeof(CatEffect), CatEffect)]
namespace SampleApp.Droid.Effects
{
public class CatEffect : PlatformEffect
{
protected override void OnAttached()
{
try
{
if (Control is EntryEditText)
{
Control.SetBackgroundResource(Resource.Drawable.cat);
}
}
catch (Exception ex)
{
Console.WriteLine(Cannot set property on attached control. Error: , ex.Message);
}
}
protected override void OnDetached()
{
// Back to white.
Control.SetBackgroundColor(Android.Graphics.Color.White);
}
}
}
view rawCatEffectDroid.cs hosted with ❤ by GitHub

As you can see there are 2 assembly attributes decorating our effect.

[assembly:ResolutionGroupName (SuperAwesome)]
[assembly:ExportEffect (typeof(CatEffect), CatEffect)]
view rawCatEffect.cs hosted with ❤ by GitHub

You might remember I talked about passing a string value into the constructor of your RoutingEffect class in your PCL a bit higher up in this post. These two values uniquely identify this specific effect and are the linking pin between your PCL code and your platform-specific code. These two values need to match the string in your PCL code (concatenated with a period character in between). It’s what makes the whole thing come together!

The result of our Effects

Obviously this leaves a lot to be desired and it serves solely as a sample of how effects work and I can’t call this one production-worthy 🙂 There are however ways you can implement your effects that can be a lot more useful. Some samples include:

  • Creating drop shadows on visual elements
  • Setting keyboard types on an entry
  • Setting auto-correct settings on an entry
  • Etc.

 

Sharing is caring

Why did I create such a useless effect to show off how effects work instead of creating one from the list above? Because the ones I mentioned have already been created by other people! The beauty of Effects is that you can easily share them which is exactly what some people have done. The FormsCommunityToolkit is a project that tries to aggregate Effects (among other things) and you can contribute to it if you’ve created one. Since it already contains some nice ones you don’t have to recreate them yourself.

A word of warning…

You can attach effects to any type of view however you need to take care of the fact that someone might attach your effect to a Button even though it was meant to work with an Entry control. Xamarin Forms does nothing to stop this behaviour. You will need to take care of graceful exception handling yourself just in case this type of thing occurs either by also implementing it for Button or by silently (yet gracefully) failing.

Just found out from somewhere than syncfusion is offering free license for lifetime which includes all the products. No Strings attached.


Here’s the link. Please tell everyone there’s nothing better than getting everything for free with future support and everything legit too!

A question that regularly pops up in the Framer community is how to use Framer if you’re using a PC. Currently, Framer Studio is only available on a Mac but the Framer.js framework, that powers Framer Studio, is free and open source. That means if you’re using Windows, Linux or on a Mac but still on the fence about purchasing Framer Studio, you can still create Framer prototypes.

framerjs-github

For most of us, we want to do as little configuration as possible — that’s where Atom comes in.Atom is a free, text editor from GitHub that’s modern and customizable to do almost anything without ever touching a config file.

atom-logo

Keep in mind is that Framer.js is written in JavaScript. Because Framer Studio uses theCoffeeScript programming language, which has a slightly different syntax that eventually gets compiled down to JavaScript, the majority of the Framer prototypes and examples you’ll see will be written in CoffeeScript. If you wanted to learn from any of these examples, you would need to first convert the code to JavaScript to run with Framer.js.

With a few simple steps, Atom takes care of that for us so we’ll be able to create Framer prototypes using CoffeeScript and preview them on our PC, Linux, or Mac machine. Let’s get started:

1. Download and install Atom

Go to the Atom website and look for the button to download. The button should be specific for your platform.

atom-download

  • If you’re on a Mac, you’ll download a zip file. Simply unzip it, move it to your Applications folder and run Atom
  • If you’re on a PC, run the installer and then open Atom
  • If you’re on Linux, download and install the Debian package or RPM package

2. Install Packages

When you launch Atom for the first time, you should see a welcome guide.

atom-welcome

Click on the “Install a Package” button on the right pane and then Open Installer.
atom-welcome-open-installer

The Install Packages screen should appear. If the future, you can also access this Settings screen through Preferences and then the install tab.

atom-settings-install

Search for the “coffee-compile” package and install it. This allows you to save your CoffeeScript file in the editor and it will convert it to Javascript. You may notice there are a few different packages that come up in the search results that do the same thing – these should work as well but I haven’t tested all of them.

atom-coffee-compile

Search for the “atom-html-preview” package and install it. This allows you to get a live preview when you make changes to the code.

atom-html-preview

If you click the Packages tab, you should now see your 2 new installed packages under the Community Packages section.

community-packages

3. Update Package Settings

If you installed the coffee-compile package, click the Settings button and check the “Compile on Save without Preview” option. This will automatically compile the file when you save and not show you the JavaScript.

compile-on-save-no-preview

4. Download the Framer.js Starter Template

You can download the template here or by going to the Get Started section of the Framer.js GitHub page and clicking the download link.

framerjs-template

Once downloaded, unzip the file and open up the Framer folder.

framer-js-template

Framer Generator is an application for Mac that comes bundled with Framer.js. It allows you to import layers directly out of Photoshop and Sketch files into your Framer projects . This feature is built into Framer Studio.

Let’s look at the files in the project folder in more detail:

  • /framer/framer.js — This is the JavaScript file that powers the interactions and animations you are able to create for your prototypes. You shouldn’t be touching this file unless you want to replace it with a newer version.
  • /framer/framer.js.map — This is a SourceMap file. It maps the code within a compressed file back to it’s original position in a source file to allow you to debug code for compressed file. You don’t need to worry about it and like the framer.js file, you don’t want to touch this file either.
  • /images/background.png & /images/icon.png — The icon image is used in the default prototype and the background image is just a black background that is specified in the CSS.
  • app.js — Here’s where you would write your JavaScript code for your prototypes. We’ll be writing CoffeeScript code that will generate this app.js file for us.
  • index.html — Open this file in a WebKit browser — such as Google Chrome or Safari to view your prototype. If you look at it, it includes the framer.js and app.js file that we looked at earlier.

5. Open up the Project folder in Atom

Go to File – Add Project Folder and open up the Framer Project folder template.

atom-project-js

6. Rename app.js to app.coffee

Right-click on the app.js file and then select rename.

atom-rename

Change the file extension from .js (JavaScript) to .coffee (CoffeeScript).

atom-rename-coffee

7. Write your CoffeeScript code

Delete the code that is in app.coffee since it’s in JavaScript. You can now write your CoffeeScript code in the file. If you’re not sure where to start, copy and paste the following example code.

Save your file when you’re done writing your code and you should see an app.js file appear in your project folder.

atom-compile-js

8. Preview your Prototype

Click the index.html file in the sidebar and then go to Packages – Preview HTML – Enable Preview

atom-enable-preview

You should now see your Framer prototype that you can interact with on your Windows machine.

framer-atom

Note that although there is a live preview, updating the app.coffee file doesn’t trigger a refresh. You’ll need to make your updates to app.coffee, save it to generate a new app.js, and then in your index.html file, make a change – such as adding a return to one line or deleting a blank line. The prototype will then refresh with your newest code.


Now that you’re able to use Framer on Windows, I can’t wait to see what prototypes you come up with. If Atom isn’t your style, you can also check out a Framer video I did as part of my Rapid Prototyping with Framer course for O’Reilly where I also show you how you can use Framer with another text editor, Brackets, as well as with online code editors like CodePen.

In my personal opinion, if you’re on a Mac and plan on using Framer past the trial period,Framer Studio is well worth the price for the amount of time you’ll save with features like easily creating new projects, instant visual feedback, inline error checking, code completion and much more.

Do you have any tips or additional questions for using Framer on Windows? Let me know with a comment below or share your thoughts with me on Twitter (@kennycheny).