Skip to content
This repository was archived by the owner on Jul 2, 2025. It is now read-only.

Commit 7ac54d7

Browse files
basic view and Running fragment
1 parent 72244e3 commit 7ac54d7

File tree

15 files changed

+449
-8
lines changed

15 files changed

+449
-8
lines changed

android/canonical/app/build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,12 @@ android {
2727
dependencies {
2828
implementation fileTree(dir: "libs", include: ["*.jar"])
2929
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
30-
implementation 'androidx.core:core-ktx:1.1.0'
30+
implementation 'androidx.core:core-ktx:1.3.0'
3131
implementation 'androidx.appcompat:appcompat:1.1.0'
3232
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
33+
implementation 'com.google.android.gms:play-services-auth:18.0.0'
34+
implementation 'com.google.android.material:material:1.1.0'
35+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
3336
testImplementation 'junit:junit:4.12'
3437
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
3538
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

android/canonical/app/src/main/java/com/google/samples/quickstart/canonical/MainActivity.kt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,69 @@ package com.google.samples.quickstart.canonical
22

33
import androidx.appcompat.app.AppCompatActivity
44
import android.os.Bundle
5+
import android.view.View
6+
import android.widget.Button
7+
import android.widget.Chronometer
8+
import android.widget.Toast
9+
import androidx.fragment.app.FragmentTransaction
10+
import com.google.android.material.bottomnavigation.BottomNavigationView
11+
import org.jetbrains.annotations.Nullable
512

613
class MainActivity : AppCompatActivity() {
14+
15+
lateinit var runFragment: RunFragment
16+
lateinit var mapFragment: MapFragment
17+
lateinit var meFragment: MeFragment
18+
719
override fun onCreate(savedInstanceState: Bundle?) {
820
super.onCreate(savedInstanceState)
921
setContentView(R.layout.activity_main)
22+
23+
runFragment = RunFragment()
24+
supportFragmentManager
25+
.beginTransaction()
26+
.replace(R.id.fragment_layout, runFragment)
27+
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
28+
.commit()
29+
30+
val bottomNavigation : BottomNavigationView = findViewById(R.id.bottom_navigation_view)
31+
bottomNavigation.setOnNavigationItemSelectedListener { item ->
32+
when (item.itemId) {
33+
34+
R.id.bottom_navigation_item_run -> {
35+
runFragment = RunFragment()
36+
supportFragmentManager
37+
.beginTransaction()
38+
.replace(R.id.fragment_layout, runFragment)
39+
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
40+
.commit()
41+
}
42+
43+
R.id.bottom_navigation_item_map -> {
44+
mapFragment = MapFragment()
45+
supportFragmentManager
46+
.beginTransaction()
47+
.replace(R.id.fragment_layout, mapFragment)
48+
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
49+
.commit()
50+
}
51+
52+
R.id.bottom_navigation_item_profile -> {
53+
meFragment = MeFragment()
54+
supportFragmentManager
55+
.beginTransaction()
56+
.replace(R.id.fragment_layout, meFragment)
57+
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
58+
.commit()
59+
}
60+
61+
62+
}
63+
true
64+
65+
}
1066
}
67+
68+
69+
1170
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.google.samples.quickstart.canonical
2+
3+
import android.os.Bundle
4+
import androidx.fragment.app.Fragment
5+
import android.view.LayoutInflater
6+
import android.view.View
7+
import android.view.ViewGroup
8+
9+
// TODO: Rename parameter arguments, choose names that match
10+
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
11+
private const val ARG_PARAM1 = "param1"
12+
private const val ARG_PARAM2 = "param2"
13+
14+
/**
15+
* A simple [Fragment] subclass.
16+
* Use the [MapFragment.newInstance] factory method to
17+
* create an instance of this fragment.
18+
*/
19+
class MapFragment : Fragment() {
20+
// TODO: Rename and change types of parameters
21+
private var param1: String? = null
22+
private var param2: String? = null
23+
24+
override fun onCreate(savedInstanceState: Bundle?) {
25+
super.onCreate(savedInstanceState)
26+
arguments?.let {
27+
param1 = it.getString(ARG_PARAM1)
28+
param2 = it.getString(ARG_PARAM2)
29+
}
30+
}
31+
32+
override fun onCreateView(
33+
inflater: LayoutInflater, container: ViewGroup?,
34+
savedInstanceState: Bundle?
35+
): View? {
36+
// Inflate the layout for this fragment
37+
return inflater.inflate(R.layout.fragment_map, container, false)
38+
}
39+
40+
companion object {
41+
/**
42+
* Use this factory method to create a new instance of
43+
* this fragment using the provided parameters.
44+
*
45+
* @param param1 Parameter 1.
46+
* @param param2 Parameter 2.
47+
* @return A new instance of fragment MapFragment.
48+
*/
49+
// TODO: Rename and change types and number of parameters
50+
@JvmStatic
51+
fun newInstance(param1: String, param2: String) =
52+
MapFragment().apply {
53+
arguments = Bundle().apply {
54+
putString(ARG_PARAM1, param1)
55+
putString(ARG_PARAM2, param2)
56+
}
57+
}
58+
}
59+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.google.samples.quickstart.canonical
2+
3+
import android.os.Bundle
4+
import androidx.fragment.app.Fragment
5+
import android.view.LayoutInflater
6+
import android.view.View
7+
import android.view.ViewGroup
8+
9+
// TODO: Rename parameter arguments, choose names that match
10+
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
11+
private const val ARG_PARAM1 = "param1"
12+
private const val ARG_PARAM2 = "param2"
13+
14+
/**
15+
* A simple [Fragment] subclass.
16+
* Use the [MeFragment.newInstance] factory method to
17+
* create an instance of this fragment.
18+
*/
19+
class MeFragment : Fragment() {
20+
// TODO: Rename and change types of parameters
21+
private var param1: String? = null
22+
private var param2: String? = null
23+
24+
override fun onCreate(savedInstanceState: Bundle?) {
25+
super.onCreate(savedInstanceState)
26+
arguments?.let {
27+
param1 = it.getString(ARG_PARAM1)
28+
param2 = it.getString(ARG_PARAM2)
29+
}
30+
}
31+
32+
override fun onCreateView(
33+
inflater: LayoutInflater, container: ViewGroup?,
34+
savedInstanceState: Bundle?
35+
): View? {
36+
// Inflate the layout for this fragment
37+
return inflater.inflate(R.layout.fragment_me, container, false)
38+
}
39+
40+
companion object {
41+
/**
42+
* Use this factory method to create a new instance of
43+
* this fragment using the provided parameters.
44+
*
45+
* @param param1 Parameter 1.
46+
* @param param2 Parameter 2.
47+
* @return A new instance of fragment MeFragment.
48+
*/
49+
// TODO: Rename and change types and number of parameters
50+
@JvmStatic
51+
fun newInstance(param1: String, param2: String) =
52+
MeFragment().apply {
53+
arguments = Bundle().apply {
54+
putString(ARG_PARAM1, param1)
55+
putString(ARG_PARAM2, param2)
56+
}
57+
}
58+
}
59+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.google.samples.quickstart.canonical
2+
3+
import android.os.Bundle
4+
import android.os.SystemClock
5+
import androidx.fragment.app.Fragment
6+
import android.view.LayoutInflater
7+
import android.view.View
8+
import android.view.ViewGroup
9+
import android.widget.Button
10+
import android.widget.Chronometer
11+
import kotlinx.android.synthetic.main.fragment_run.*
12+
import org.jetbrains.annotations.Nullable
13+
14+
// TODO: Rename parameter arguments, choose names that match
15+
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
16+
private const val ARG_PARAM1 = "param1"
17+
private const val ARG_PARAM2 = "param2"
18+
19+
/**
20+
* A simple [Fragment] subclass.
21+
* Use the [RunFragment.newInstance] factory method to
22+
* create an instance of this fragment.
23+
*/
24+
class RunFragment : Fragment() {
25+
// TODO: Rename and change types of parameters
26+
private var param1: String? = null
27+
private var param2: String? = null
28+
29+
override fun onCreate(savedInstanceState: Bundle?) {
30+
super.onCreate(savedInstanceState)
31+
arguments?.let {
32+
param1 = it.getString(ARG_PARAM1)
33+
param2 = it.getString(ARG_PARAM2)
34+
}
35+
}
36+
37+
override fun onCreateView(
38+
inflater: LayoutInflater, container: ViewGroup?,
39+
savedInstanceState: Bundle?
40+
): View? {
41+
// Inflate the layout for this fragment
42+
return inflater.inflate(R.layout.fragment_run, container, false)
43+
}
44+
45+
companion object {
46+
/**
47+
* Use this factory method to create a new instance of
48+
* this fragment using the provided parameters.
49+
*
50+
* @param param1 Parameter 1.
51+
* @param param2 Parameter 2.
52+
* @return A new instance of fragment RunFragment.
53+
*/
54+
// TODO: Rename and change types and number of parameters
55+
@JvmStatic
56+
fun newInstance(param1: String, param2: String) =
57+
RunFragment().apply {
58+
arguments = Bundle().apply {
59+
putString(ARG_PARAM1, param1)
60+
putString(ARG_PARAM2, param2)
61+
}
62+
}
63+
}
64+
65+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
66+
super.onViewCreated(view, savedInstanceState)
67+
val chronometer = view.findViewById<Chronometer>(R.id.chronometer)
68+
val runBtn = view.findViewById<Button>(R.id.run_btn)
69+
var pauseOffset = 0L
70+
71+
// chronometer.format = "00:00:00"
72+
runBtn.setOnClickListener (object : View.OnClickListener{
73+
var isWorking = false
74+
override fun onClick(v: View) {
75+
isWorking = if (!isWorking) {
76+
chronometer.base = SystemClock.elapsedRealtime() - pauseOffset
77+
chronometer.start()
78+
true
79+
} else {
80+
pauseOffset = SystemClock.elapsedRealtime() - chronometer.base
81+
chronometer.stop()
82+
false
83+
}
84+
run_btn.setText(if (!isWorking) R.string.start else R.string.stop)
85+
}
86+
})
87+
88+
}
89+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M22,5.72l-4.6,-3.86 -1.29,1.53 4.6,3.86L22,5.72zM7.88,3.39L6.6,1.86 2,5.71l1.29,1.53 4.59,-3.85zM12.5,8L11,8v6l4.75,2.85 0.75,-1.23 -4,-2.37L12.5,8zM12,4c-4.97,0 -9,4.03 -9,9s4.02,9 9,9c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,20c-3.87,0 -7,-3.13 -7,-7s3.13,-7 7,-7 7,3.13 7,7 -3.13,7 -7,7z"/>
10+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M13.49,5.48c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM9.89,19.38l1,-4.4 2.1,2v6h2v-7.5l-2.1,-2 0.6,-3c1.3,1.5 3.3,2.5 5.5,2.5v-2c-1.9,0 -3.5,-1 -4.3,-2.4l-1,-1.6c-0.4,-0.6 -1,-1 -1.7,-1 -0.3,0 -0.5,0.1 -0.8,0.1l-5.2,2.2v4.7h2v-3.4l1.8,-0.7 -1.6,8.1 -4.9,-1 -0.4,2 7,1.4z"/>
10+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M20.5,3l-0.16,0.03L15,5.1 9,3 3.36,4.9c-0.21,0.07 -0.36,0.25 -0.36,0.48V20.5c0,0.28 0.22,0.5 0.5,0.5l0.16,-0.03L9,18.9l6,2.1 5.64,-1.9c0.21,-0.07 0.36,-0.25 0.36,-0.48V3.5c0,-0.28 -0.22,-0.5 -0.5,-0.5zM15,19l-6,-2.11V5l6,2.11V19z"/>
10+
</vector>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="24"
5+
android:viewportHeight="24"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M16,11c1.66,0 2.99,-1.34 2.99,-3S17.66,5 16,5c-1.66,0 -3,1.34 -3,3s1.34,3 3,3zM8,11c1.66,0 2.99,-1.34 2.99,-3S9.66,5 8,5C6.34,5 5,6.34 5,8s1.34,3 3,3zM8,13c-2.33,0 -7,1.17 -7,3.5L1,19h14v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5zM16,13c-0.29,0 -0.62,0.02 -0.97,0.05 1.16,0.84 1.97,1.97 1.97,3.45L17,19h6v-2.5c0,-2.33 -4.67,-3.5 -7,-3.5z"/>
10+
</vector>

android/canonical/app/src/main/res/layout/activity_main.xml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@
44
xmlns:tools="http://schemas.android.com/tools"
55
android:layout_width="match_parent"
66
android:layout_height="match_parent"
7+
android:orientation="vertical"
78
tools:context=".MainActivity">
8-
<TextView
9-
android:layout_width="wrap_content"
9+
10+
<com.google.android.material.bottomnavigation.BottomNavigationView
11+
android:id="@+id/bottom_navigation_view"
12+
android:layout_width="match_parent"
1013
android:layout_height="wrap_content"
11-
android:text="Hello World!"
14+
android:background="@android:color/white"
1215
app:layout_constraintBottom_toBottomOf="parent"
13-
app:layout_constraintLeft_toLeftOf="parent"
14-
app:layout_constraintRight_toRightOf="parent"
15-
app:layout_constraintTop_toTopOf="parent" />
16+
app:menu="@menu/bottom_navigation_menu" />
17+
18+
<FrameLayout
19+
android:id="@+id/fragment_layout"
20+
android:layout_width="match_parent"
21+
android:layout_height="0dp"
22+
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation_view"
23+
app:layout_constraintTop_toTopOf="parent">
24+
25+
</FrameLayout>
26+
1627

1728
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)