Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Catalog] Add Navigation Drawer demo
PiperOrigin-RevId: 429379636
- Loading branch information
1 parent
bdbf052
commit 2ce5f3b
Showing
9 changed files
with
393 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
catalog/java/io/material/catalog/navigationdrawer/NavigationDrawerDemoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2021 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 | ||
* | ||
* https://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. | ||
*/ | ||
|
||
package io.material.catalog.navigationdrawer; | ||
|
||
import io.material.catalog.R; | ||
|
||
import android.os.Bundle; | ||
import androidx.appcompat.app.ActionBarDrawerToggle; | ||
import androidx.appcompat.widget.Toolbar; | ||
import android.view.Gravity; | ||
import android.view.LayoutInflater; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.drawerlayout.widget.DrawerLayout; | ||
import com.google.android.material.navigation.NavigationView; | ||
import io.material.catalog.feature.DemoActivity; | ||
|
||
/** A fragment that displays the main Navigation Drawer demo for the Catalog app. */ | ||
public class NavigationDrawerDemoActivity extends DemoActivity { | ||
|
||
private DrawerLayout drawerLayout; | ||
|
||
@NonNull | ||
@Override | ||
public View onCreateDemoView( | ||
@NonNull LayoutInflater layoutInflater, | ||
@Nullable ViewGroup viewGroup, | ||
@Nullable Bundle bundle) { | ||
View view = | ||
layoutInflater.inflate(R.layout.cat_navigationdrawer, viewGroup, false /* attachToRoot */); | ||
|
||
Toolbar toolbar = view.findViewById(R.id.toolbar); | ||
setSupportActionBar(toolbar); | ||
|
||
drawerLayout = view.findViewById(R.id.drawer); | ||
drawerLayout.addDrawerListener( | ||
new ActionBarDrawerToggle( | ||
this, | ||
drawerLayout, | ||
toolbar, | ||
R.string.cat_navigationdrawer_button_show_content_description, | ||
R.string.cat_navigationdrawer_button_hide_content_description)); | ||
|
||
NavigationView navigationView = view.findViewById(R.id.navigation_view); | ||
navigationView.setNavigationItemSelectedListener( | ||
menuItem -> { | ||
navigationView.setCheckedItem(menuItem); | ||
drawerLayout.closeDrawer(Gravity.START); | ||
return true; | ||
}); | ||
|
||
return view; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(@NonNull MenuItem menuItem) { | ||
if (menuItem.getItemId() == android.R.id.home) { | ||
drawerLayout.openDrawer(Gravity.START); | ||
return true; | ||
} | ||
|
||
return super.onOptionsItemSelected(menuItem); | ||
} | ||
|
||
@Override | ||
protected boolean shouldShowDefaultDemoActionBar() { | ||
return false; | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
catalog/java/io/material/catalog/navigationdrawer/NavigationDrawerFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright 2022 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. | ||
*/ | ||
|
||
package io.material.catalog.navigationdrawer; | ||
|
||
import io.material.catalog.R; | ||
|
||
import android.content.Intent; | ||
import androidx.fragment.app.Fragment; | ||
import androidx.annotation.NonNull; | ||
import dagger.Provides; | ||
import dagger.android.ContributesAndroidInjector; | ||
import dagger.multibindings.IntoSet; | ||
import io.material.catalog.application.scope.ActivityScope; | ||
import io.material.catalog.application.scope.FragmentScope; | ||
import io.material.catalog.feature.Demo; | ||
import io.material.catalog.feature.DemoLandingFragment; | ||
import io.material.catalog.feature.FeatureDemo; | ||
|
||
/** A landing fragment that links to navigation drawer demos for the Catalog app. */ | ||
public class NavigationDrawerFragment extends DemoLandingFragment { | ||
|
||
@Override | ||
public int getTitleResId() { | ||
return R.string.cat_navigationdrawer_title; | ||
} | ||
|
||
@Override | ||
public int getDescriptionResId() { | ||
return R.string.cat_navigationdrawer_description; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Demo getMainDemo() { | ||
return new Demo() { | ||
@Override | ||
public Intent createActivityIntent() { | ||
return new Intent(requireContext(), NavigationDrawerDemoActivity.class); | ||
} | ||
}; | ||
} | ||
|
||
/** The Dagger module for {@link NavigationDrawerFragment} dependencies. */ | ||
@dagger.Module | ||
public abstract static class Module { | ||
@FragmentScope | ||
@ContributesAndroidInjector | ||
abstract NavigationDrawerFragment contributeInjector(); | ||
|
||
@IntoSet | ||
@Provides | ||
@ActivityScope | ||
static FeatureDemo provideFeatureDemo() { | ||
return new FeatureDemo(R.string.cat_navigationdrawer_title, R.drawable.ic_side_drawer) { | ||
@Override | ||
public Fragment createFragment() { | ||
return new NavigationDrawerFragment(); | ||
} | ||
}; | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
catalog/java/io/material/catalog/navigationdrawer/res/layout/cat_navigationdrawer.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright 2022 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 | ||
~ | ||
~ https://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. | ||
--> | ||
|
||
<androidx.drawerlayout.widget.DrawerLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:id="@+id/drawer" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fitsSystemWindows="true"> | ||
|
||
<androidx.coordinatorlayout.widget.CoordinatorLayout | ||
android:id="@+id/linear_layout" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical" | ||
android:fitsSystemWindows="true"> | ||
|
||
<com.google.android.material.appbar.AppBarLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:fitsSystemWindows="true"> | ||
|
||
<androidx.appcompat.widget.Toolbar | ||
android:id="@+id/toolbar" | ||
style="?attr/catalogToolbarStyle" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
app:navigationIcon="@drawable/ic_drawer_menu_24px" | ||
app:title="@string/cat_navigationdrawer_title"/> | ||
</com.google.android.material.appbar.AppBarLayout> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="center" | ||
android:gravity="center" | ||
android:text="@string/cat_navigationdrawer_instructions" | ||
android:textAppearance="?attr/textAppearanceBodyLarge" | ||
android:padding="64dp" /> | ||
|
||
</androidx.coordinatorlayout.widget.CoordinatorLayout> | ||
|
||
<com.google.android.material.navigation.NavigationView | ||
android:id="@+id/navigation_view" | ||
android:layout_width="wrap_content" | ||
android:layout_height="match_parent" | ||
android:layout_gravity="start" | ||
app:headerLayout="@layout/cat_navigationdrawer_header" | ||
app:menu="@menu/cat_navigationdrawer_menu"/> | ||
|
||
</androidx.drawerlayout.widget.DrawerLayout> |
50 changes: 50 additions & 0 deletions
50
catalog/java/io/material/catalog/navigationdrawer/res/layout/cat_navigationdrawer_header.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright 2022 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 | ||
~ | ||
~ https://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. | ||
--> | ||
|
||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingLeft="16dp" | ||
android:paddingTop="16dp" | ||
android:paddingRight="16dp" | ||
android:paddingBottom="8dp" | ||
android:gravity="bottom" | ||
android:minHeight="174dp" | ||
android:orientation="vertical"> | ||
|
||
<ImageView | ||
android:id="@+id/imageView" | ||
android:layout_width="48dp" | ||
android:layout_height="48dp" | ||
android:layout_marginBottom="12dp" | ||
android:scaleType="centerCrop" | ||
android:contentDescription="@string/cat_navigationdrawer_header_image_content_description" | ||
app:srcCompat="@drawable/logo_avatar_anonymous_40dp"/> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/cat_navigationdrawer_header_title" | ||
android:textAppearance="?attr/textAppearanceTitleLarge" /> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/cat_navigationdrawer_header_subtitle" | ||
android:textAppearance="?attr/textAppearanceBodyMedium" /> | ||
</LinearLayout> |
68 changes: 68 additions & 0 deletions
68
catalog/java/io/material/catalog/navigationdrawer/res/menu/cat_navigationdrawer_menu.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?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. | ||
--> | ||
|
||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<item | ||
android:id="@+id/main_item" | ||
android:title="@string/cat_navigationdrawer_header_mail"> | ||
<menu> | ||
<item | ||
android:id="@+id/search_item" | ||
android:icon="@drawable/ic_search_24px" | ||
android:title="@string/cat_navigationdrawer_search" | ||
android:checkable="true" | ||
app:showAsAction="ifRoom"/> | ||
<item | ||
android:id="@+id/rotation_item" | ||
android:icon="@drawable/ic_3d_rotation_24px" | ||
android:title="@string/cat_navigationdrawer_3d" | ||
android:checkable="true" | ||
app:showAsAction="ifRoom"/> | ||
<item | ||
android:id="@+id/accelerator_item" | ||
android:icon="@drawable/ic_accelerator_24px" | ||
android:title="@string/cat_navigationdrawer_accelerator" | ||
android:checkable="true" | ||
app:showAsAction="ifRoom"/> | ||
<item | ||
android:id="@+id/dashboard_item" | ||
android:icon="@drawable/ic_dashboard_24px" | ||
android:title="@string/cat_navigationdrawer_dashboard" | ||
android:checkable="true" | ||
app:showAsAction="ifRoom"/> | ||
</menu> | ||
</item> | ||
<item | ||
android:id="@+id/labels_item" | ||
android:title="@string/cat_navigationdrawer_header_labels"> | ||
<menu> | ||
<item | ||
android:id="@+id/label_one" | ||
android:icon="@drawable/ic_info_outline_24px" | ||
android:title="@string/cat_navigationdrawer_label" | ||
android:checkable="true" | ||
app:showAsAction="ifRoom"/> | ||
<item | ||
android:id="@+id/label_two" | ||
android:icon="@drawable/ic_info_outline_24px" | ||
android:title="@string/cat_navigationdrawer_label" | ||
android:checkable="true" | ||
app:showAsAction="ifRoom"/> | ||
</menu> | ||
</item> | ||
</menu> |
Oops, something went wrong.