User Tools

Site Tools


android

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
android [2020/12/27 20:35] – external edit 127.0.0.1android [2022/09/03 22:42] (current) skipidar
Line 1: Line 1:
 +==== Linux environment ====
 +How to set up a headless build environment.
 +
 +|OS|Ubuntu 20.04|
 +|Android SDK|Android 11 (API level 30) as of 26.11.2021|
 +
 +
 +==== Install android-sdk on Ubuntu ====
 +
 +<sxh bash>
 +# install openjdk8 - tested android sdk and its compatible
 +sudo apt-get install openjdk-8-jdk
 +# activate the 8th version if you have multiple using:
 +# sudo update-alternatives --config java
 +
 +
 +# install android-sdk under /usr/lib/android-sdk/
 +sudo apt update && sudo apt install android-sdk
 +
 +
 +
 +# download the commandlinetools and add them to sdk
 +# <sdk>/cmdline-tools/latest/
 +wget -P /tmp/ https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip
 +
 +# check https://stackoverflow.com/questions/60440509/android-command-line-tools-sdkmanager-always-shows-warning-could-not-create-se
 +sudo mkdir -p /usr/lib/android-sdk/cmdline-tools/
 +
 +sudo unzip /tmp/commandlinetools-*.zip -d /usr/lib/android-sdk/cmdline-tools/
 +sudo mv /usr/lib/android-sdk/cmdline-tools/cmdline-tools/ /usr/lib/android-sdk/cmdline-tools/tools/
 +
 +# open bashrc and modify the environment variables
 +vim ~/.bashrc
 +export ANDROID_HOME="/usr/lib/android-sdk/"
 +export PATH=$PATH:$ANDROID_HOME/cmdline-tools/tools/bin:$ANDROID_HOME/platform-tools
 +
 +# apply changes in bashrc
 +source ~/.bashrc
 +
 +
 +# setting the rights 
 +sudo chown $USER:$USER $ANDROID_HOME -R
 +
 +
 +
 +# can successfully access the sdkmanager
 +sdkmanager --version
 +
 +# install the platform tools https://developer.android.com/studio/releases/platform-tools
 +sdkmanager "platform-tools" "platforms;android-29"
 +
 +# install the build tools https://developer.android.com/studio/releases/build-tools
 +sdkmanager "build-tools;29.0.3"
 +
 +
 +# confirm all the licenses for the android tools otherwise they wont work
 +yes | sdkmanager --licenses
 +
 +
 +# check for android sdk updates
 +sdkmanager --update
 +
 +
 +
 +
 +# you can build android project now 
 +cd <YOUR_ANDROID_PROJECT>
 +./gradlew build
 +
 +
 +
 +
 +</sxh>
 +
 +
 +
 +
 ==== HOWTO ==== ==== HOWTO ====
  
Line 256: Line 333:
   * Before every test  - the method **setUp()** is executed   * Before every test  - the method **setUp()** is executed
   * test methods names have to start with **"test"**, or they won't be found   * test methods names have to start with **"test"**, or they won't be found
 +
 +
 +=== Espresso - UI tests ===
 +
 +<sxh java>
 +package digital.alf.geosound;
 +
 +import static androidx.test.espresso.Espresso.onView;
 +import static androidx.test.espresso.assertion.ViewAssertions.matches;
 +import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
 +import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
 +import static androidx.test.espresso.matcher.ViewMatchers.withText;
 +import static org.hamcrest.CoreMatchers.allOf;
 +
 +import android.Manifest;
 +import android.app.Activity;
 +import android.os.Bundle;
 +
 +import androidx.navigation.NavController;
 +import androidx.navigation.Navigation;
 +import androidx.test.espresso.action.ViewActions;
 +import androidx.test.espresso.matcher.ViewMatchers;
 +import androidx.test.ext.junit.rules.ActivityScenarioRule;
 +import androidx.test.ext.junit.runners.AndroidJUnit4;
 +import androidx.test.filters.LargeTest;
 +import androidx.test.rule.GrantPermissionRule;
 +
 +import org.junit.Rule;
 +import org.junit.Test;
 +import org.junit.runner.RunWith;
 +
 +@RunWith(AndroidJUnit4.class)
 +@LargeTest
 +public class JustOpenAllWindows {
 +
 +    @Rule
 +    public ActivityScenarioRule<MainActivity> activityRule = new ActivityScenarioRule<>(MainActivity.class);
 +
 +    @Rule
 +    public GrantPermissionRule mRuntimePermissionRuleFine = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION);
 +
 +    @Rule
 +    public GrantPermissionRule mRuntimePermissionRuleCoarse = GrantPermissionRule.grant(Manifest.permission.ACCESS_COARSE_LOCATION);
 +
 +    @Rule
 +    public GrantPermissionRule mRuntimePermissionRuleBackground = GrantPermissionRule.grant(Manifest.permission.ACCESS_BACKGROUND_LOCATION);
 +
 +
 +    @Test
 +    public void openPreferences() {
 +
 +        activityRule.getScenario().onActivity(activity -> {
 +            Bundle args = new Bundle();
 +            NavController navController = Navigation.findNavController(activity, R.id.map);
 +            navController.navigate(R.id.action_fragment_maps_to_fragment_preferences, args);
 +        });
 +
 +        onView(allOf(ViewMatchers.withText(R.string.dialog_preference_label), withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE)))
 +                .check(matches(isDisplayed()));
 +
 +        onView(ViewMatchers.withText(R.string.dialog_default_onout_volume_title))
 +                .perform(ViewActions.click());
 +
 +        //Click on cancel button
 +        onView(ViewMatchers.withId(android.R.id.button2))
 +                .perform(ViewActions.click());
 +
 +
 +        onView(ViewMatchers.withText(R.string.dialog_default_onout_volume_title))
 +                .perform(ViewActions.click());
 +
 +        //Click on cancel button
 +        onView(ViewMatchers.withId(android.R.id.button2))
 +                .perform(ViewActions.click());
 +
 +        System.out.println("done");
 +    }
 +
 +}
 +
 +</sxh>
 +
 +=== Execution in CodeBuild ===
 +https://devops.stackexchange.com/questions/3965/configuration-of-aws-codepipeline-for-android-ci-cd
 +
 +
 ==== Snippets ==== ==== Snippets ====
  
Line 1172: Line 1335:
  
 </code> </code>
 +
 +
 +
 +==== Style ====
 +
 +=== Styles, attributes ===
 +
 +{{https://s3.eu-central-1.amazonaws.com/alf-digital-wiki-pics/sharex/0A2xTQpLXn.png}}
 +
 +
 +=== TextAppearance ===
 +The text size in android is controlled by "TextAppearance"
 +
 +
 +Material Design provides 13 type “styles” that are applied to all the text in your app. Each of these have a design term (eg. “Body 1”) along with a corresponding type attribute that can be overridden in your app theme (eg. textAppearanceBody1). There are default “baseline” values (text size, letter spacing, capitalization, etc.) for each style.
 +
 +https://material.io/blog/android-material-theme-type
 +
 +{{https://s3.eu-central-1.amazonaws.com/alf-digital-wiki-pics/sharex/9SsVsrtpPT.png}}
 +
 +
 +== Usage in your view ==
 +
 +At the end, 
 +to express which size the text in your custom view should have 
 +instead of influencing "textSize" directly
 +which will lead to difficulties with consistancy across app and consistancy with android native textSizes
 +
 +you should set "android:textAppearance=" on your view.
 +
 +and the value should be one of androids own textAppearance **attributes**: 
 +  * textAppearanceHeadline1
 +  * textAppearanceHeadline2
 +  * textAppearanceHeadline3
 +  * textAppearanceHeadline4
 +  * textAppearanceBody1
 +  * textAppearanceBody2
 +
 +The same attributes are used by android too, so your view will be consistant with android natives
 +
 +In your someAppPartLayout.xml
 +<code>
 +                <!-- My title in my app view -->
 +                <TextView
 +                    android:layout_width="wrap_content"
 +                    android:layout_height="wrap_content"
 +                    android:text="Title"
 +                    android:textAppearance="?attr/textAppearanceHeadline4" />
 +</code>
 +
 +
 +== Changing the value of attributes in AppTheme ==
 +
 +In your theme, maybe defined in your styles.xml
 +you can change single android attributes.
 +
 +In my theme, which is defined in this style - overriding the single attributes "textAppearance*"
 +referencing MY styles, which can interfere and override the default values for textAppearance.
 +
 +**Remark:** 
 +Those textAppearance* attributes are also used in android native views,
 +like buttons
 +see https://material.io/blog/android-material-theme-type.
 +So overriding those in a theme - changes the behavior also for Android native elements
 +
 +THose attributes are not just strings, but are introduced as typed attributes in attrs.xml
 +with format="reference".
 +format="reference" means, that one can take a "<style></style>" element as a value.
 +In the value-style element - the items a la  android:textSize are expected (convention).
 +
 +USAGE of attributes
 +The attribute can be USED in views, by refering to the attribute in the view
 +e.g.
 +<code>android:textAppearance="?attr/textAppearanceHeadline4" /> </code>
 +
 +In your styles.xml pointing textAppearanceHeadline1 attribute of type "reference"
 +to my own style.
 +
 +The style inherits from androids own style but I still can override some values in my inherited style.
 +
 +<code>
 +    <!-- Base application theme. -->
 +    <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
 +        <!-- Customize your theme here. -->
 +        <item name="colorPrimary">@color/colorPrimary</item>
 +        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
 +        <item name="colorAccent">@color/colorAccent</item>
 +
 +       
 +        <item name="textAppearanceHeadline1">
 +            @style/TextAppearance.Headline1
 +        </item>
 +</code>
 +
 +
 +== Introducing own styles, to refer from overridden attributes textAppearance* ==
 +
 +THe value of an overridden attribute **textAppearance*** is a style
 +
 +
 +in your styles.xml 
 +parallel to the AppTheme - introduce styles, to refer from attributes.
 +<code>
 +
 +    <!-- here I can change attributes of the STYLES.
 +    by Inheriting from "TextAppearance.MaterialComponents.*" I inherit all the native properties
 +    but get the possibility to override them here
 +    -->
 +    <style name="TextAppearance.Headline1" parent="TextAppearance.MaterialComponents.Headline1">
 +        <item name="android:textSize">96sp</item>
 +    </style>
 +
 +    <style name="TextAppearance.Headline2" parent="TextAppearance.MaterialComponents.Headline2">
 +        <item name="android:textSize">60sp</item>
 +    </style>
 +
 +    <style name="TextAppearance.Headline3" parent="TextAppearance.MaterialComponents.Headline3">
 +        <item name="android:textSize">48sp</item>
 +    </style>
 +
 +    <style name="TextAppearance.Headline4" parent="TextAppearance.MaterialComponents.Headline4">
 +        <item name="android:textSize">34sp</item>
 +    </style>
 +
 +    <style name="TextAppearance.Headline5" parent="TextAppearance.MaterialComponents.Headline5">
 +        <item name="android:textSize">24sp</item>
 +    </style>
 +
 +    <style name="TextAppearance.Headline6" parent="TextAppearance.MaterialComponents.Headline6">
 +        <item name="android:textSize">20sp</item>
 +    </style>
 +
 +    <style name="TextAppearance.Body1" parent="TextAppearance.MaterialComponents.Body1">
 +        <item name="android:textSize">16sp</item>
 +    </style>
 +
 +    <style name="TextAppearance.Body2" parent="TextAppearance.MaterialComponents.Body2">
 +        <item name="android:textSize">14sp</item>
 +    </style>
 +</code> 
  
android.1609101328.txt.gz · Last modified: by 127.0.0.1