Skip to content

Commit

Permalink
The view ElevationShadowView is now used to visualize elevations.
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-rapp committed Nov 6, 2015
1 parent 3067e68 commit 676d572
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;

import java.util.ArrayList;
Expand All @@ -60,6 +59,7 @@
import de.mrapp.android.util.ElevationUtil;
import de.mrapp.android.util.ElevationUtil.Orientation;
import de.mrapp.android.util.VisibleForTesting;
import de.mrapp.android.util.view.ElevationShadowView;

import static de.mrapp.android.util.Condition.ensureAtLeast;
import static de.mrapp.android.util.Condition.ensureAtMaximum;
Expand Down Expand Up @@ -267,10 +267,10 @@ public abstract class PreferenceActivity extends AppCompatActivity
private Toolbar breadCrumbToolbar;

/**
* The image view, which is used to draw a shadow below the toolbar, which is used to show the
* bread crumb of the currently selected preference header on devices with a large screen.
* The view, which is used to draw a shadow below the toolbar, which is used to show the bread
* crumb of the currently selected preference header on devices with a large screen.
*/
private ImageView breadCrumbShadowView;
private ElevationShadowView breadCrumbShadowView;

/**
* The view group, which contains the buttons, which are shown when the activity is used as a
Expand All @@ -296,15 +296,15 @@ public abstract class PreferenceActivity extends AppCompatActivity
private Button finishButton;

/**
* The image view, which is used to draw a shadow below the activity's toolbar.
* The view, which is used to draw a shadow below the activity's toolbar.
*/
private ImageView toolbarShadowView;
private ElevationShadowView toolbarShadowView;

/**
* The image view, which is used to draw a shadow above the button bar when the activity is used
* as a wizard.
* The view, which is used to draw a shadow above the button bar when the activity is used as a
* wizard.
*/
private ImageView buttonBarShadowView;
private ElevationShadowView buttonBarShadowView;

/**
* The preference header, which is currently selected or null, if no preference header is
Expand Down Expand Up @@ -360,28 +360,12 @@ public abstract class PreferenceActivity extends AppCompatActivity
*/
private boolean navigationHidden;

/**
* The elevation of the toolbar in dp.
*/
private int toolbarElevation;

/**
* The elevation of the toolbar, which is used to show the bread crumb of the currently selected
* preference header on devices with a large screen.
*/
private int breadCrumbElevation;

/**
* The elevation of the view group, which contains the views, which are shown when a preference
* screen is selected on a device with a large screen, in dp.
*/
private int preferenceScreenElevation;

/**
* The elevation of the button bar in dp.
*/
private int buttonBarElevation;

/**
* True, if the progress should be shown as the bread crumb title, when the activity is used as
* a wizard, false otherwise.
Expand Down Expand Up @@ -1875,7 +1859,8 @@ public final void showButtonBar(final boolean showButtonBar) {
if (showButtonBar) {
buttonBar = (ViewGroup) findViewById(R.id.wizard_button_bar);
buttonBar.setVisibility(View.VISIBLE);
buttonBarShadowView = (ImageView) findViewById(R.id.wizard_button_bar_shadow_view);
buttonBarShadowView =
(ElevationShadowView) findViewById(R.id.wizard_button_bar_shadow_view);
buttonBarShadowView.setVisibility(View.VISIBLE);
nextButton = (Button) findViewById(R.id.next_button);
nextButton.setOnClickListener(createNextButtonListener());
Expand Down Expand Up @@ -1936,7 +1921,7 @@ public final int getSelectedPreferenceHeaderPosition() {
* @return The elevation of the activity's toolbar in dp as an {@link Integer} value
*/
public final int getToolbarElevation() {
return toolbarElevation;
return toolbarShadowView.getShadowElevation();
}

/**
Expand All @@ -1947,9 +1932,7 @@ public final int getToolbarElevation() {
* must be at least 0 and at maximum 16
*/
public final void setToolbarElevation(final int elevation) {
Bitmap shadow = createElevationShadow(this, elevation, Orientation.BOTTOM, true);
toolbarElevation = elevation;
toolbarShadowView.setImageBitmap(shadow);
toolbarShadowView.setShadowElevation(elevation);
}

/**
Expand All @@ -1962,7 +1945,7 @@ public final void setToolbarElevation(final int elevation) {
*/
public final int getBreadCrumbElevation() {
if (isSplitScreen()) {
return breadCrumbElevation;
return breadCrumbShadowView.getShadowElevation();
}

return -1;
Expand All @@ -1979,11 +1962,8 @@ public final int getBreadCrumbElevation() {
* @return True, if the elevation has been set, false otherwise
*/
public final boolean setBreadCrumbElevation(final int elevation) {
Bitmap shadow = createElevationShadow(this, elevation, Orientation.BOTTOM, true);

if (breadCrumbShadowView != null) {
breadCrumbElevation = elevation;
breadCrumbShadowView.setImageBitmap(shadow);
breadCrumbShadowView.setShadowElevation(elevation);
return true;
}

Expand Down Expand Up @@ -2040,7 +2020,7 @@ public final boolean setPreferenceScreenElevation(final int elevation) {
*/
public final int getButtonBarElevation() {
if (isButtonBarShown()) {
return buttonBarElevation;
return buttonBarShadowView.getShadowElevation();
}

return -1;
Expand All @@ -2060,8 +2040,7 @@ public final boolean setButtonBarElevation(final int elevation) {
Bitmap shadow = createElevationShadow(this, elevation, Orientation.TOP, true);

if (buttonBarShadowView != null) {
buttonBarElevation = elevation;
buttonBarShadowView.setImageBitmap(shadow);
buttonBarShadowView.setShadowElevation(elevation);
return true;
}

Expand Down Expand Up @@ -2475,11 +2454,11 @@ protected void onCreate(final Bundle savedInstanceState) {
preferenceHeaderParentView = (ViewGroup) findViewById(R.id.preference_header_parent);
preferenceScreenParentView = (ViewGroup) findViewById(R.id.preference_screen_parent);
preferenceScreenContainer = (CardView) findViewById(R.id.preference_screen_container);
toolbarShadowView = (ImageView) findViewById(R.id.toolbar_shadow_view);
toolbarShadowView = (ElevationShadowView) findViewById(R.id.toolbar_shadow_view);

if (isSplitScreen()) {
breadCrumbToolbar = (Toolbar) findViewById(R.id.bread_crumb_toolbar);
breadCrumbShadowView = (ImageView) findViewById(R.id.bread_crumb_shadow_view);
breadCrumbShadowView = (ElevationShadowView) findViewById(R.id.bread_crumb_shadow_view);
}

preferenceHeaderFragment = new PreferenceHeaderFragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
Expand All @@ -39,7 +38,6 @@
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;

Expand All @@ -49,11 +47,10 @@
import de.mrapp.android.preference.activity.animation.HideViewOnScrollAnimation;
import de.mrapp.android.preference.activity.animation.HideViewOnScrollAnimation.Direction;
import de.mrapp.android.preference.activity.decorator.PreferenceDecorator;
import de.mrapp.android.util.ElevationUtil.Orientation;
import de.mrapp.android.util.view.ElevationShadowView;

import static de.mrapp.android.util.Condition.ensureNotNull;
import static de.mrapp.android.util.DisplayUtil.pixelsToDp;
import static de.mrapp.android.util.ElevationUtil.createElevationShadow;

/**
* A fragment, which allows to show multiple preferences. Additionally, a button, which allows to
Expand Down Expand Up @@ -112,9 +109,9 @@ public abstract class PreferenceFragment extends android.preference.PreferenceFr
private ViewGroup buttonBar;

/**
* The image view, which is used to draw a shadow above the button bar.
* The view, which is used to draw a shadow above the button bar.
*/
private ImageView shadowView;
private ElevationShadowView shadowView;

/**
* The button, which allows to restore the preferences' default values.
Expand Down Expand Up @@ -160,7 +157,7 @@ private void inflateRestoreDefaultsButtonBar() {
restoreDefaultsButton =
(Button) buttonBarParent.findViewById(R.id.restore_defaults_button);
restoreDefaultsButton.setOnClickListener(createRestoreDefaultsListener());
shadowView = (ImageView) buttonBarParent
shadowView = (ElevationShadowView) buttonBarParent
.findViewById(R.id.restore_defaults_button_bar_shadow_view);
obtainStyledAttributes();
}
Expand Down Expand Up @@ -633,11 +630,9 @@ public final int getButtonBarElevation() {
*/
@SuppressWarnings("deprecation")
public final boolean setButtonBarElevation(final int elevation) {
Bitmap shadow = createElevationShadow(getActivity(), elevation, Orientation.TOP, true);

if (isRestoreDefaultsButtonShown()) {
this.buttonBarElevation = elevation;
shadowView.setImageBitmap(shadow);
buttonBarElevation = elevation;
shadowView.setShadowElevation(elevation);
return true;
}

Expand Down
21 changes: 11 additions & 10 deletions library/src/main/res/layout-large/preference_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ not, see <http://www.gnu.org/licenses/>.
android:id="@id/preference_activity_frame_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down Expand Up @@ -45,13 +46,13 @@ not, see <http://www.gnu.org/licenses/>.
android:layout_height="match_parent"
android:background="@color/navigation_background_light"/>

<ImageView
<de.mrapp.android.util.view.ElevationShadowView
android:id="@id/toolbar_shadow_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="@null"
android:scaleType="fitXY"/>
custom:emulateParallelLight="true"
custom:shadowOrientation="bottom"/>
</FrameLayout>
</LinearLayout>

Expand Down Expand Up @@ -93,22 +94,22 @@ not, see <http://www.gnu.org/licenses/>.
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<ImageView
<de.mrapp.android.util.view.ElevationShadowView
android:id="@id/bread_crumb_shadow_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="@null"
android:scaleType="fitXY"/>
custom:emulateParallelLight="true"
custom:shadowOrientation="bottom"/>

<ImageView
<de.mrapp.android.util.view.ElevationShadowView
android:id="@id/wizard_button_bar_shadow_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:contentDescription="@null"
android:scaleType="fitXY"
android:visibility="gone"/>
android:visibility="gone"
custom:emulateParallelLight="true"
custom:shadowOrientation="top"/>
</FrameLayout>

<include layout="@layout/wizard_button_bar"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ You should have received a copy of the GNU Lesser General Public License along w
not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
<de.mrapp.android.util.view.ElevationShadowView
android:id="@id/restore_defaults_button_bar_shadow_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:scaleType="fitXY"/>
custom:emulateParallelLight="true"
custom:shadowOrientation="top"/>

<RelativeLayout
android:id="@id/restore_defaults_button_bar"
Expand Down
7 changes: 4 additions & 3 deletions library/src/main/res/layout/preference_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ not, see <http://www.gnu.org/licenses/>.
android:id="@id/preference_activity_frame_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down Expand Up @@ -46,13 +47,13 @@ not, see <http://www.gnu.org/licenses/>.
android:layout_height="match_parent"
android:background="@color/navigation_background_light"/>

<ImageView
<de.mrapp.android.util.view.ElevationShadowView
android:id="@id/toolbar_shadow_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="@null"
android:scaleType="fitXY"/>
custom:emulateParallelLight="true"
custom:shadowOrientation="bottom"/>

<ImageView
android:id="@id/wizard_button_bar_shadow_view"
Expand Down
7 changes: 4 additions & 3 deletions library/src/main/res/layout/restore_defaults_button_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ You should have received a copy of the GNU Lesser General Public License along w
not, see <http://www.gnu.org/licenses/>.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<ImageView
<de.mrapp.android.util.view.ElevationShadowView
android:id="@id/restore_defaults_button_bar_shadow_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:scaleType="fitXY"/>
custom:emulateParallelLight="true"
custom:shadowOrientation="top"/>

<RelativeLayout
android:id="@id/restore_defaults_button_bar"
Expand Down

0 comments on commit 676d572

Please sign in to comment.