The PSLab works as a Wave generator and the Oscilloscope when connected with the Android device. The mockup of the Wave Generator has been created in the blog Creating the Mockup for Wave Generator using Moqups.
In this blog, we will create the monitor screen in the PSLab Android app using Android studio.
Deciding the layout to use for monitors
As monitors with rounded border look appealing on android device screen so we will select CardView to be the base layout of our monitors. The CardView element allows us to add certain properties like rounded corners, elevation etc.
To use the CardView in your app, add the following dependency to build.gradle file and sync the project.
dependencies { // CardView
implementation 'com.android.support:cardview-v7:27.1.1'
}
Add the <android.support.v7.widget.CardView> widget to your layout and all the other views to be shown on monitor screen will be placed inside this card layout as its child layout.
Creating the monitor cards
We need to decide how much spacing is to be provided to the cards to properly view them on different screens. Here we make use of the special attribute in the View class.
android:layout_weight=1
This attribute assigns an “importance” value to a View in terms of how much space it should occupy on the screen. That is if we give equal weight to two views which inside the same parent then they will both occupy equal space.
To implement this create two CardViews inside <LinearLayout> with the same layout_weight.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="250dp"
android:layout_weight="1"
card_view:cardCornerRadius="10dp" />
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="250dp"
android:layout_weight="1"
card_view:cardCornerRadius="10dp" />
</LinearLayout>
So this will give us a screen like this with equally weighted monitor card views as shown in Figure 1.
Both the cards have the width equal to half the screen width which is set automatically by the Android.
Creating partitions in the monitors
We have to make partitions in the monitor screen so that every characteristic of Wave Generator like wave frequency, phase, selected pin etc. can be viewed simultaneously on the screen with proper spacing.
For making partitions we need to make a separator line which we can create by using <View> and setting the attributes as below:
<View
android:layout_width="@dimen/length_0dp"
android:layout_height="@dimen/divider_width"
android:background="@color/dark_grey" />
This will create a thin line having the grey color. We have to make four partitions of the card view for both monitors as shown in Figure 2.
Populating the screen with text and image icons
We have to include the <TextView> and <ImageView> to show the property data on the monitors.
Different partitions as shown in Figure 3 can be used for showing different data such as:
- Top Partition:- To view the selected wave.
- Left Partition:- To view the selected waveform eg:- sine, triangular
- Right Partition:- To view the selected wave characteristics like frequency, phase etc.
- Bottom Partition:- To view the property selected which has been selected by user
After inserting all the desired Views and providing the Views with dummy data and icons and customizing the Views by giving proper color and spacing finally we will have a layout as shown in Figure 4.
In Figure 4, the left CardView shows all the properties for the Analog Wave Generator and the right CardView shows all the properties for Digital Wave Generator.
All the characteristics on the monitors can be controlled by the controlling panel which is work in progress.
Resources:
- https://developer.android.com/guide/topics/ui/layout/cardview– Article on How to Create a card based layout by Android Developer Documentation
- https://stackoverflow.com/questions/5049852/android-drawing-separator-divider-line-in-layout – Stack Overflow post to create separator line