MAD Lab 4

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

Lab 4

Objective: Familiarize students with the Android Development Environment.


Description:
Programming is an increasingly important skill, whether you aspire to a career in
software development, or in other fields. This course is the first in the specialization
Android Application Development, but its lessons extend to any language you might
want to learn like Java or Kotlin. This is because programming is fundamentally about
figuring out how to solve a class of problems, development of application and writing the
algorithm, a clear set of steps to solve any problem in its class.

Assessment tools:
The assessment is according to the student participation in the lab if the student solves the
exercise, he will get the participation mark for this lab.

Time Table Application:


XML Code:
MainActivity:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:fab="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/drawer"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.ogaclejapan.smarttablayout.SmartTabLayout
android:id="@+id/viewpagertab"
android:layout_width="match_parent"
android:layout_height="48dp"
app:stl_indicatorAlwaysInCenter="false"
app:stl_indicatorWithoutPadding="false"
app:stl_indicatorInFront="false"
app:stl_indicatorInterpolation="smart"
app:stl_indicatorGravity="bottom"
app:stl_indicatorColor="#0D47A1"
app:stl_indicatorThickness="4dp"
app:stl_indicatorWidth="auto"
app:stl_indicatorCornerRadius="2dp"
app:stl_overlineColor="#BBfEFB"
app:stl_overlineThickness="0dp"
app:stl_underlineColor="#1E88E5"
app:stl_underlineThickness="1dp"
app:stl_dividerColor="#1E88E5"
app:stl_dividerThickness="1dp"
app:stl_defaultTabBackground="?attr/showAsAction"
app:stl_defaultTabTextAllCaps="true"
app:stl_defaultTabTextColor="#FC000080"
app:stl_defaultTabTextSize="12sp"
app:stl_defaultTabTextHorizontalPadding="16dp"
app:stl_defaultTabTextMinWidth="0dp"
app:stl_distributeEvenly="false"
app:stl_clickable="true"
app:stl_titleOffset="24dp"
app:stl_drawDecorationAfterTab="false"
/>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager

android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="@+id/pager">
</android.support.v4.view.ViewPager>
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp"
app:fab_colorRipple="#9FA8DA"
app:fab_colorNormal="#FFB300"
android:src="@drawable/fab_add"
fab:fab_colorNormal="@color/app_primary"
fab:fab_colorPressed="@color/app_primary_pressed"
fab:fab_colorRipple="@color/app_ripple"/>
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/navigation"
android:layout_width="match_parent"
android:layout_gravity = "left">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1.3"
android:background="@drawable/nav_bag">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:src="@mipmap/ic_launcher2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TimeTable"
android:paddingLeft="16dp"
android:textStyle="bold"
android:textSize="22dp"
android:textColor="#FFFF"/>
</LinearLayout>
<ListView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="3"
android:background="#FFFF"
android:id="@+id/leftlist">
</ListView>

</LinearLayout>

</android.support.v4.widget.DrawerLayout>

SplashScreenActivity:

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.kalyan.timetable.SplashActivity">

</RelativeLayout>

Kotlin Code:
import android.app.AlarmManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.icu.util.Calendar
import android.net.Uri
import android.os.Build
import android.preference.PreferenceManager
import android.support.annotation.RequiresApi
import android.support.v4.app.FragmentActivity
import android.support.v4.view.GravityCompat
import android.support.v4.view.ViewPager
import android.support.v4.widget.DrawerLayout
import android.os.Bundle
import android.support.v7.app.ActionBar
import android.util.Log
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.AdapterView
import android.widget.BaseAdapter
import android.widget.ImageView
import android.widget.ListView
import android.widget.TextView
import android.widget.Toast

import com.github.amlcurran.showcaseview.ShowcaseView
import com.github.amlcurran.showcaseview.targets.Target
import com.github.amlcurran.showcaseview.targets.ViewTarget
import com.github.clans.fab.FloatingActionButton
import com.majeur.cling.Cling
import com.majeur.cling.ClingManager
import com.ogaclejapan.smarttablayout.SmartTabLayout
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItemAdapter
import com.ogaclejapan.smarttablayout.utils.v4.FragmentPagerItems

import java.io.File
import java.util.Date

class MainActivity : FragmentActivity() {


var currentPage = 0

internal var fab: FloatingActionButton? = null


internal var leftlist: ListView
private var mDrawerLayout: DrawerLayout? = null

@RequiresApi(api = Build.VERSION_CODES.N)
@Override
protected fun onCreate(savedInstanceState: Bundle) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

fab = findViewById(R.id.fab) as FloatingActionButton


mDrawerLayout = findViewById(R.id.drawer) as DrawerLayout

leftlist = findViewById(R.id.leftlist) as ListView

mainActivity = this
context = this
val navigationSt = arrayOf("Projects ", "Tutorial
", "Attendence Manager ", "Poll ", "Settings ",
"Share ", "About ")
val navigationImg = intArrayOf(R.mipmap.ic_proj, R.mipmap.ic_tut,
R.mipmap.ic_att, R.mipmap.ic_poll, R.mipmap.ic_settings,
R.mipmap.ic_share, R.mipmap.ic_people)
val navigationAdapter = MyDrawerAdapter(getApplicationContext(),
navigationSt, navigationImg)
leftlist.setAdapter(navigationAdapter)

leftlist.setOnItemClickListener(object :
AdapterView.OnItemClickListener() {
@Override
fun onItemClick(parent: AdapterView<*>, view: View, position:
Int, id: Long) {
selectFromDrawer(position)
mDrawerLayout!!.closeDrawers()
}
})
val adapter = FragmentPagerItemAdapter(
getSupportFragmentManager(),
FragmentPagerItems.with(this)
.add("MONDAY", Monday::class.java)
.add("TUESDAY", Tuesday::class.java)
.add("WEDNESDAY", Wednesday::class.java)
.add("THURSDAY", Thursday::class.java)
.add("FRIDAY", Friday::class.java)
.create())

// Calendar c = Calendar.getInstance();

val viewPager = findViewById(R.id.pager) as ViewPager


viewPager.setAdapter(adapter)

val viewPagerTab = findViewById(R.id.viewpagertab) as


SmartTabLayout
viewPagerTab.setViewPager(viewPager)

if (getIntent() != null) {
viewPager.setCurrentItem(getIntent().getIntExtra("page", 0))
}

viewPagerTab.setOnPageChangeListener(object :
ViewPager.OnPageChangeListener() {
@Override
fun onPageScrolled(position: Int, positionOffset: Float,
positionOffsetPixels: Int) {

@Override
fun onPageSelected(position: Int) {
currentPage = position
//
Toast.makeText(getApplicationContext(),""+currentPage,Toast.LENGTH_SHORT)
.show();
}

@Override
fun onPageScrollStateChanged(state: Int) {

}
})
fab!!.setOnClickListener(object : View.OnClickListener() {
@Override
fun onClick(v: View) {
val intent = Intent(this@MainActivity,
EditorActivity::class.java)
startActivity(intent)
}
})
Guess It APP:
XML Code:

<?xml version="1.0" encoding="utf-8"?><!--


~ Copyright 2018, The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/main_navigation" />
</merge>
Game Fragment XML Code:
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright 2018, The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="gameViewModel"

type="com.example.android.guesstheword.screens.game.GameViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/game_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".screens.game.GameFragment">

<TextView
android:id="@+id/word_is_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:fontFamily="sans-serif"
android:text="@string/word_is"
android:textColor="@color/black_text_color"
android:textSize="14sp"
android:textStyle="normal"
app:layout_constraintBottom_toTopOf="@+id/word_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />

<TextView
android:id="@+id/word_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:fontFamily="sans-serif"
android:text="@{@string/quote_format(gameViewModel.word)}"

android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:textColor="@color/black_text_color"
android:textSize="34sp"
android:textStyle="normal"
app:layout_constraintBottom_toTopOf="@+id/score_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/word_is_text"
app:layout_constraintVertical_chainStyle="packed"
tools:text="&quot;Tuna&quot;" />

<TextView
android:id="@+id/timer_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:fontFamily="sans-serif"
android:text="@{gameViewModel.currentTimeString}"
android:textColor="@color/grey_text_color"
android:textSize="14sp"
android:textStyle="normal"
app:layout_constraintBottom_toTopOf="@+id/score_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="0:00" />

<TextView
android:id="@+id/score_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif"
android:text="@{@string/score_format(gameViewModel.score)}"
android:textColor="@color/grey_text_color"
android:textSize="14sp"
android:textStyle="normal"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="Score: 2" />

<Button
android:id="@+id/skip_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:onClick="@{() -> gameViewModel.onSkip()}"
android:text="@string/skip"
android:theme="@style/SkipButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/correct_button"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline" />

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_end="96dp" />

<Button
android:id="@+id/correct_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:onClick="@{() -> gameViewModel.onCorrect()}"
android:text="@string/got_it"
android:theme="@style/GoButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/skip_button"
app:layout_constraintTop_toTopOf="@+id/guideline" />

</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

Kotlin Code Main Activity:


package com.example.android.guesstheword

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

/**
* Creates an Activity that hosts all of the fragments in the app
*/
class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {


super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
}

You might also like