Tutorial by Examples

public class ReplaceFont { public static void changeDefaultFont(Context context, String oldFont, String assetsFont) { Typeface typeface = Typeface.createFromAsset(context.getAssets(), assetsFont); replaceFont(oldFont, typeface); } private static void replaceFont(String oldFont, Type...
Add the required libraries into the dependencies section of your Android module's build.gradle: android { ... defaultConfig { ... testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } } dependencies { ... androidTestCompile 'com.android.su...
In order to enable writing more complex UI tests the UIAutomatorViewer is needed. The tool located at /tools/ makes a fullscreen screenshot including the layouts of the currently displayed views. See the subsequent picture to get an idea of what is shown: For the UI tests we are looking for resou...
Putting UIAutomator tests together to a test suite is a quick thing: package de.androidtest.myapplication; import org.junit.runner.RunWith; import org.junit.runners.Suite; @RunWith(Suite.class) @Suite.SuiteClasses({InterAppTest1.class, InterAppTest2.class}) public class AppTestSuite {} ...
This example creates a MediaSession object when a Service is started. The MediaSession object is released when the Service gets destroyed: public final class MyService extends Service { private static MediaSession s_mediaSession; @Override public void onCreate() { // Insta...
Form controls have some default styling without using any special classes. However labels and controls can be wrapped in .form-group tags for optimum spacing. <form> <div class="form-group"> <label for="input-email">Email address</label> &lt...
Trigger speech to text translation private void startListening() { //Intent to listen to user vocal input and return result in same activity Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); //Use a language model based on free-form speech recognition. ...
The following code can be used to trigger speech-to-text translation without showing a dialog: public void startListeningWithoutDialog() { // Intent to listen to user vocal input and return the result to the same activity. Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEEC...
This example assumes that you have already set up a Firebase Realtime Database. If you are a starter, then please inform yourself here on how to add Firebase to your Android project. First, add the dependency of the Firebase Database to the app level build.gradle file: compile 'com.google.firebase...
First create a BroadcastReceiver class to handle the incoming Location updates: public class LocationReceiver extends BroadcastReceiver implements Constants { @Override public void onReceive(Context context, Intent intent) { if (LocationResult.hasResult(intent)) { ...
A repository pattern can be used to encapsulate data storage specific code in designated components. The part of your application, that needs the data will only work with the repositories. You will want to create a repository for each combination of item you store and your database technology. Read...
We will take vehicle hierarchy example as depicted below. Vehicle.java package com.thejavageek.jpa.entities; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Inheritance...
angular.component("SampleComponent", { bindings: { title: '@', movies: '<', reservation: "=", processReservation: "&" } }); Here we have all binding elements. @ indicates that we need a very basic binding, from the parent scope ...
CREATE TABLE [dbo].[ProcessLog]( [LogId] [int] IDENTITY(1,1) NOT NULL, [LogType] [varchar](20) NULL, [StartTime] [datetime] NULL, [EndTime] [datetime] NULL, [RunMinutes] AS (datediff(minute,coalesce([StartTime],getdate()),coalesce([EndTime],getdate()))) This gives run difference in minutes ...
The next example can be used to determine whether a enumeration has the FlagsAttribute specified. The methodology used is based on Reflection. This example will give a True result: Dim enu As [Enum] = New FileAttributes() Dim hasFlags As Boolean = enu.GetType().GetCustomAttributes(GetType(FlagsAt...
In some very specific scenarios we would feel the need to perform a specific action for each flag of the source enumeration. We can write a simple Generic extension method to realize this task. <DebuggerStepThrough> <Extension> <EditorBrowsable(EditorBrowsableState.Always)> Pu...
The next example is intended to count the amount of flags in the specified flag combination. The example is provided as a extension method: <DebuggerStepThrough> <Extension> <EditorBrowsable(EditorBrowsableState.Always)> Public Function CountFlags(ByVal sender As [Enum]) As In...
The next code illustrates how to find the nearest value of a Enum. First we define this Enum that will serve to specify search criteria (search direction) Public Enum EnumFindDirection As Integer Nearest = 0 Less = 1 LessOrEqual = 2 Greater = 3 GreaterOrEqual = 4 End Enum...
There are a number of guidelines to follow when creating and using header files in a C project: Idemopotence If a header file is included multiple times in a translation unit (TU), it should not break builds. Self-containment If you need the facilities declared in a header file, you sh...
If a particular header file is included more than once in a translation unit (TU), there should not be any compilation problems. This is termed 'idempotence'; your headers should be idempotent. Think how difficult life would be if you had to ensure that #include <stdio.h> was only included ...

Page 859 of 1336