-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PiperOrigin-RevId: 237829773
- Loading branch information
Showing
24 changed files
with
763 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,7 @@ def srcDirs = [ | |
'chip', | ||
'dialog', | ||
'draggable', | ||
'elevation', | ||
'fab', | ||
'feature', | ||
'font', | ||
|
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
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
119 changes: 119 additions & 0 deletions
119
catalog/java/io/material/catalog/elevation/ElevationOverlaysDemoActivity.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,119 @@ | ||
/* | ||
* Copyright 2019 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.elevation; | ||
|
||
import io.material.catalog.R; | ||
|
||
import android.os.Bundle; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import com.google.android.material.elevation.ElevationOverlayProvider; | ||
import com.google.android.material.internal.ViewUtils; | ||
import androidx.core.view.ViewCompat; | ||
import androidx.recyclerview.widget.LinearLayoutManager; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
import io.material.catalog.feature.DemoActivity; | ||
import java.util.Locale; | ||
|
||
/** A fragment that displays the Elevation Overlays demo for the Catalog app. */ | ||
public class ElevationOverlaysDemoActivity extends DemoActivity { | ||
|
||
@Override | ||
public View onCreateDemoView( | ||
LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) { | ||
View view = | ||
layoutInflater.inflate( | ||
R.layout.cat_elevation_overlays_activity, viewGroup, /* attachToRoot= */ false); | ||
|
||
RecyclerView recyclerView = view.findViewById(R.id.recycler_view); | ||
recyclerView.setAdapter(new Adapter(getElevationDpValues())); | ||
recyclerView.setLayoutManager( | ||
new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, /* reverseLayout= */ false)); | ||
|
||
return view; | ||
} | ||
|
||
@Override | ||
public int getDemoTitleResId() { | ||
return R.string.cat_elevation_overlays_title; | ||
} | ||
|
||
protected int[] getElevationDpValues() { | ||
return new int[] {1, 2, 3, 4, 6, 8, 12, 16, 24}; | ||
} | ||
|
||
private class Adapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { | ||
|
||
private final int[] elevationDpValues; | ||
|
||
public Adapter(int[] elevationDpValues) { | ||
this.elevationDpValues = elevationDpValues; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
LayoutInflater inflater = LayoutInflater.from(parent.getContext()); | ||
View view = | ||
inflater.inflate(R.layout.cat_elevation_overlays_item, parent, /* attachToRoot= */ false); | ||
return new ItemViewHolder(view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int position) { | ||
((ItemViewHolder) viewHolder).bind(elevationDpValues[position]); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return elevationDpValues.length; | ||
} | ||
|
||
private class ItemViewHolder extends RecyclerView.ViewHolder { | ||
|
||
private final ElevationOverlayProvider overlayProvider; | ||
|
||
private final TextView dpLabelView; | ||
private final TextView alphaLabelView; | ||
|
||
private ItemViewHolder(View itemView) { | ||
super(itemView); | ||
overlayProvider = new ElevationOverlayProvider(itemView.getContext()); | ||
dpLabelView = itemView.findViewById(R.id.elevation_overlay_dp_label); | ||
alphaLabelView = itemView.findViewById(R.id.elevation_overlay_alpha_label); | ||
} | ||
|
||
@SuppressWarnings("RestrictTo") | ||
private void bind(int elevationDp) { | ||
float elevation = ViewUtils.dpToPx(ElevationOverlaysDemoActivity.this, elevationDp); | ||
int color = | ||
overlayProvider.layerOverlayIfNeeded(overlayProvider.getColorSurface(), elevation); | ||
int alphaPercent = | ||
Math.round(overlayProvider.calculateOverlayAlphaFraction(elevation) * 100); | ||
|
||
ViewCompat.setElevation(itemView, elevation); | ||
itemView.setBackgroundColor(color); | ||
dpLabelView.setText(String.format(Locale.getDefault(), "%02d dp", elevationDp)); | ||
alphaLabelView.setText(String.format(Locale.getDefault(), "%d%% On Surface", alphaPercent)); | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
catalog/java/io/material/catalog/elevation/res/layout/cat_elevation_overlays_activity.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,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2019 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.recyclerview.widget.RecyclerView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/recycler_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingTop="8dp" | ||
android:paddingBottom="16dp" | ||
android:clipToPadding="false"/> |
39 changes: 39 additions & 0 deletions
39
catalog/java/io/material/catalog/elevation/res/layout/cat_elevation_overlays_item.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,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright 2019 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. | ||
--> | ||
|
||
<FrameLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/elevation_overlay_frame" | ||
android:layout_width="match_parent" | ||
android:layout_height="150dp" | ||
android:layout_marginTop="8dp" | ||
android:layout_marginBottom="8dp" | ||
android:layout_marginLeft="16dp" | ||
android:layout_marginRight="16dp" | ||
android:padding="16dp"> | ||
|
||
<TextView | ||
android:id="@+id/elevation_overlay_dp_label" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content"/> | ||
|
||
<TextView | ||
android:id="@+id/elevation_overlay_alpha_label" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom"/> | ||
</FrameLayout> |
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
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
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
Oops, something went wrong.