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

Commit c348d48

Browse files
search bar
1 parent b37af95 commit c348d48

File tree

5 files changed

+126
-4
lines changed

5 files changed

+126
-4
lines changed

android/canonical/app/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ dependencies {
3939
implementation 'com.google.android.material:material:1.1.0'
4040
implementation 'com.google.android.gms:play-services-maps:17.0.0'
4141
implementation 'com.google.android.gms:play-services-location:17.0.0'
42+
implementation 'com.google.android.libraries.places:places:2.3.0'
4243
implementation "android.arch.lifecycle:extensions:1.1.1"
4344
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0'
45+
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
4446
kapt 'com.android.databinding:compiler:3.1.4'
4547
testImplementation 'junit:junit:4.12'
4648
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
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 [AutocompleteFragment.newInstance] factory method to
17+
* create an instance of this fragment.
18+
*/
19+
class AutocompleteFragment : 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_autocomplete, 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 AutocompleteFragment.
48+
*/
49+
// TODO: Rename and change types and number of parameters
50+
@JvmStatic
51+
fun newInstance(param1: String, param2: String) =
52+
AutocompleteFragment().apply {
53+
arguments = Bundle().apply {
54+
putString(ARG_PARAM1, param1)
55+
putString(ARG_PARAM2, param2)
56+
}
57+
}
58+
}
59+
}

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ 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.FrameLayout
57
import androidx.fragment.app.FragmentTransaction
68
import com.google.android.material.bottomnavigation.BottomNavigationView
79

@@ -14,7 +16,7 @@ class MainActivity : AppCompatActivity() {
1416
val runFragment = RunFragment()
1517
supportFragmentManager
1618
.beginTransaction()
17-
.replace(R.id.fragment_container, runFragment)
19+
.replace(R.id.content_view, runFragment)
1820
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
1921
.commit()
2022

@@ -23,30 +25,41 @@ class MainActivity : AppCompatActivity() {
2325
when (item.itemId) {
2426

2527
R.id.bottom_navigation_item_run -> {
28+
val autocompleteFrameLayout : FrameLayout = findViewById(R.id.autocomplete_view)
29+
autocompleteFrameLayout.visibility = View.INVISIBLE
30+
2631
val runFragment = RunFragment()
2732
supportFragmentManager
2833
.beginTransaction()
29-
.replace(R.id.fragment_container, runFragment)
34+
.replace(R.id.content_view, runFragment)
3035
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
3136
.commit()
3237
true
3338
}
3439

3540
R.id.bottom_navigation_item_map -> {
41+
val autocompleteFrameLayout : FrameLayout = findViewById(R.id.autocomplete_view)
42+
autocompleteFrameLayout.visibility = View.VISIBLE
43+
3644
val mapsFragment = MapsFragment()
45+
val autocompleteFragment = AutocompleteFragment()
3746
supportFragmentManager
3847
.beginTransaction()
39-
.replace(R.id.fragment_container, mapsFragment)
48+
.replace(R.id.content_view, mapsFragment)
49+
.replace(R.id.autocomplete_view, autocompleteFragment)
4050
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
4151
.commit()
4252
true
4353
}
4454

4555
R.id.bottom_navigation_item_profile -> {
56+
val autocompleteFrameLayout : FrameLayout = findViewById(R.id.autocomplete_view)
57+
autocompleteFrameLayout.visibility = View.INVISIBLE
58+
4659
val meFragment = MeFragment()
4760
supportFragmentManager
4861
.beginTransaction()
49-
.replace(R.id.fragment_container, meFragment)
62+
.replace(R.id.content_view, meFragment)
5063
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
5164
.commit()
5265
true

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,31 @@
1919
android:id="@+id/fragment_container"
2020
android:layout_width="match_parent"
2121
android:layout_height="0dp"
22+
android:measureAllChildren="true"
2223
app:layout_constraintBottom_toTopOf="@+id/bottom_navigation_view"
2324
app:layout_constraintTop_toTopOf="parent">
2425

26+
<androidx.constraintlayout.widget.ConstraintLayout
27+
android:layout_width="match_parent"
28+
android:layout_height="match_parent"
29+
android:orientation="vertical"
30+
tools:context=".MainActivity">
31+
32+
<FrameLayout
33+
android:id="@+id/autocomplete_view"
34+
android:layout_width="match_parent"
35+
android:layout_height="wrap_content"
36+
app:layout_constraintTop_toTopOf="parent"/>
37+
38+
<FrameLayout
39+
android:id="@+id/content_view"
40+
android:layout_width="match_parent"
41+
android:layout_height="0dp"
42+
app:layout_constraintBottom_toBottomOf="parent"
43+
app:layout_constraintTop_toTopOf="parent" />
44+
45+
</androidx.constraintlayout.widget.ConstraintLayout>
46+
2547
</FrameLayout>
2648

2749

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
3+
<!-- xmlns:tools="http://schemas.android.com/tools"-->
4+
<!-- android:layout_width="match_parent"-->
5+
<!-- android:layout_height="match_parent"-->
6+
<!-- tools:context=".AutocompleteFragment">-->
7+
8+
<!-- &lt;!&ndash; TODO: Update blank fragment layout &ndash;&gt;-->
9+
<!-- <TextView-->
10+
<!-- android:layout_width="match_parent"-->
11+
<!-- android:layout_height="match_parent"-->
12+
<!-- android:text="@string/hello_blank_fragment" />-->
13+
14+
<!-- <SearchView-->
15+
<!-- android:layout_width="match_parent"-->
16+
<!-- android:layout_height="50dp" />-->
17+
18+
<!--</FrameLayout>-->
19+
20+
<fragment
21+
xmlns:android="http://schemas.android.com/apk/res/android"
22+
xmlns:tools="http://schemas.android.com/tools"
23+
android:id="@+id/autocomplete_fragment"
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment" />

0 commit comments

Comments
 (0)