├── settings.gradle
├── screenshots
├── 1-main.png
└── icon-web.png
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── Application
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable-hdpi
│ │ │ ├── tile.9.png
│ │ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values-v21
│ │ │ ├── base-colors.xml
│ │ │ └── base-template-styles.xml
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── dimens.xml
│ │ │ ├── fragmentview_strings.xml
│ │ │ ├── base-strings.xml
│ │ │ ├── template-dimens.xml
│ │ │ └── template-styles.xml
│ │ ├── values-v11
│ │ │ └── template-styles.xml
│ │ ├── values-sw600dp
│ │ │ ├── template-dimens.xml
│ │ │ └── template-styles.xml
│ │ ├── menu
│ │ │ └── main.xml
│ │ ├── layout
│ │ │ ├── ztranslation.xml
│ │ │ └── activity_main.xml
│ │ └── layout-w720dp
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── android
│ │ ├── common
│ │ ├── activities
│ │ │ └── SampleActivityBase.java
│ │ └── logger
│ │ │ ├── LogNode.java
│ │ │ ├── MessageOnlyLogFilter.java
│ │ │ ├── LogWrapper.java
│ │ │ ├── LogFragment.java
│ │ │ ├── LogView.java
│ │ │ └── Log.java
│ │ └── elevationdrag
│ │ ├── MainActivity.java
│ │ ├── ElevationDragFragment.java
│ │ └── DragFrameLayout.java
├── build.gradle
└── tests
│ ├── AndroidManifest.xml
│ └── src
│ └── com
│ └── example
│ └── android
│ └── elevationdrag
│ └── tests
│ └── SampleTests.java
├── README.md
├── packaging.yaml
├── .google
└── packaging.yaml
├── CONTRIBUTING.md
├── CONTRIB.md
├── gradlew.bat
├── gradlew
└── LICENSE
/settings.gradle:
--------------------------------------------------------------------------------
1 | include 'Application'
2 |
--------------------------------------------------------------------------------
/screenshots/1-main.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-ElevationDrag/master/screenshots/1-main.png
--------------------------------------------------------------------------------
/screenshots/icon-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-ElevationDrag/master/screenshots/icon-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-ElevationDrag/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/Application/src/main/res/drawable-hdpi/tile.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-ElevationDrag/master/Application/src/main/res/drawable-hdpi/tile.9.png
--------------------------------------------------------------------------------
/Application/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-ElevationDrag/master/Application/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Application/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-ElevationDrag/master/Application/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Application/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-ElevationDrag/master/Application/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Application/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/googlearchive/android-ElevationDrag/master/Application/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | Android ElevationDrag Sample
3 | ============================
4 |
5 | This repo has been migrated to [github.com/android/user-interface][1]. Please check that repo for future updates. Thank you!
6 |
7 | [1]: https://github.com/android/user-interface
8 |
9 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
--------------------------------------------------------------------------------
/packaging.yaml:
--------------------------------------------------------------------------------
1 | # GOOGLE SAMPLE PACKAGING DATA
2 | #
3 | # This file is used by Google as part of our samples packaging process.
4 | # End users may safely ignore this file. It has no relevance to other systems.
5 | ---
6 |
7 | status: PUBLISHED
8 | technologies: [Android]
9 | categories: [UI]
10 | languages: [Java]
11 | solutions: [Mobile]
12 | github: googlesamples/android-ElevationDrag
13 | level: BEGINNER
14 | icon: ElevationDragSample/src/main/res/drawable-xxhdpi/ic_launcher.png
15 | license: apache2
16 |
--------------------------------------------------------------------------------
/.google/packaging.yaml:
--------------------------------------------------------------------------------
1 |
2 | # GOOGLE SAMPLE PACKAGING DATA
3 | #
4 | # This file is used by Google as part of our samples packaging process.
5 | # End users may safely ignore this file. It has no relevance to other systems.
6 | ---
7 | status: PUBLISHED
8 | technologies: [Android]
9 | categories: [UI, Views]
10 | languages: [Java]
11 | solutions: [Mobile]
12 | github: android-ElevationDrag
13 | level: BEGINNER
14 | icon: screenshots/icon-web.png
15 | apiRefs:
16 | - android:android.view.View
17 | license: apache2
18 |
--------------------------------------------------------------------------------
/Application/src/main/res/values-v21/base-colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
36 | * For devices with displays with a width of 720dp or greater, the sample log is always visible,
37 | * on other devices it's visibility is controlled by an item on the Action Bar.
38 | */
39 | public class MainActivity extends SampleActivityBase {
40 |
41 | public static final String TAG = "MainActivity";
42 |
43 | // Whether the Log Fragment is currently shown
44 | private boolean mLogShown;
45 |
46 | @Override
47 | protected void onCreate(Bundle savedInstanceState) {
48 | super.onCreate(savedInstanceState);
49 | setContentView(R.layout.activity_main);
50 |
51 | if (savedInstanceState == null) {
52 | FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
53 | ElevationDragFragment fragment = new ElevationDragFragment();
54 | transaction.replace(R.id.sample_content_fragment, fragment);
55 | transaction.commit();
56 | }
57 | }
58 |
59 | @Override
60 | public boolean onCreateOptionsMenu(Menu menu) {
61 | getMenuInflater().inflate(R.menu.main, menu);
62 | return true;
63 | }
64 |
65 | @Override
66 | public boolean onPrepareOptionsMenu(Menu menu) {
67 | MenuItem logToggle = menu.findItem(R.id.menu_toggle_log);
68 | logToggle.setVisible(findViewById(R.id.sample_output) instanceof ViewAnimator);
69 | logToggle.setTitle(mLogShown ? R.string.sample_hide_log : R.string.sample_show_log);
70 |
71 | return super.onPrepareOptionsMenu(menu);
72 | }
73 |
74 | @Override
75 | public boolean onOptionsItemSelected(MenuItem item) {
76 | switch(item.getItemId()) {
77 | case R.id.menu_toggle_log:
78 | mLogShown = !mLogShown;
79 | ViewAnimator output = (ViewAnimator) findViewById(R.id.sample_output);
80 | if (mLogShown) {
81 | output.setDisplayedChild(1);
82 | } else {
83 | output.setDisplayedChild(0);
84 | }
85 | supportInvalidateOptionsMenu();
86 | return true;
87 | }
88 | return super.onOptionsItemSelected(item);
89 | }
90 |
91 | /** Create a chain of targets that will receive log data */
92 | @Override
93 | public void initializeLogging() {
94 | // Wraps Android's native log framework.
95 | LogWrapper logWrapper = new LogWrapper();
96 | // Using Log, front-end to the logging chain, emulates android.util.log method signatures.
97 | Log.setLogNode(logWrapper);
98 |
99 | // Filter strips out everything except the message text.
100 | MessageOnlyLogFilter msgFilter = new MessageOnlyLogFilter();
101 | logWrapper.setNext(msgFilter);
102 |
103 | // On screen logging via a fragment with a TextView.
104 | LogFragment logFragment = (LogFragment) getSupportFragmentManager()
105 | .findFragmentById(R.id.log_fragment);
106 | msgFilter.setNext(logFragment.getLogView());
107 |
108 | Log.i(TAG, "Ready");
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/Application/src/main/java/com/example/android/elevationdrag/ElevationDragFragment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.elevationdrag;
18 |
19 | import com.example.android.common.logger.Log;
20 |
21 | import android.graphics.Outline;
22 | import android.os.Bundle;
23 | import android.support.v4.app.Fragment;
24 | import android.view.LayoutInflater;
25 | import android.view.View;
26 | import android.view.ViewGroup;
27 | import android.view.ViewOutlineProvider;
28 |
29 | import java.util.Locale;
30 |
31 | public class ElevationDragFragment extends Fragment {
32 |
33 | public static final String TAG = "ElevationDragFragment";
34 |
35 | /* The circular outline provider */
36 | private ViewOutlineProvider mOutlineProviderCircle;
37 |
38 | /* The current elevation of the floating view. */
39 | private float mElevation = 0;
40 |
41 | /* The step in elevation when changing the Z value */
42 | private int mElevationStep;
43 |
44 | @Override
45 | public void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 |
48 | mOutlineProviderCircle = new CircleOutlineProvider();
49 |
50 | mElevationStep = getResources().getDimensionPixelSize(R.dimen.elevation_step);
51 | }
52 |
53 | @Override
54 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
55 | Bundle savedInstanceState) {
56 | View rootView = inflater.inflate(R.layout.ztranslation, container, false);
57 |
58 | /* Find the {@link View} to apply z-translation to. */
59 | final View floatingShape = rootView.findViewById(R.id.circle);
60 |
61 | /* Define the shape of the {@link View}'s shadow by setting one of the {@link Outline}s. */
62 | floatingShape.setOutlineProvider(mOutlineProviderCircle);
63 |
64 | /* Clip the {@link View} with its outline. */
65 | floatingShape.setClipToOutline(true);
66 |
67 | DragFrameLayout dragLayout = ((DragFrameLayout) rootView.findViewById(R.id.main_layout));
68 |
69 | dragLayout.setDragFrameController(new DragFrameLayout.DragFrameLayoutController() {
70 |
71 | @Override
72 | public void onDragDrop(boolean captured) {
73 | /* Animate the translation of the {@link View}. Note that the translation
74 | is being modified, not the elevation. */
75 | floatingShape.animate()
76 | .translationZ(captured ? 50 : 0)
77 | .setDuration(100);
78 | Log.d(TAG, captured ? "Drag" : "Drop");
79 | }
80 | });
81 |
82 | dragLayout.addDragView(floatingShape);
83 |
84 | /* Raise the circle in z when the "z+" button is clicked. */
85 | rootView.findViewById(R.id.raise_bt).setOnClickListener(new View.OnClickListener() {
86 | @Override
87 | public void onClick(View v) {
88 | mElevation += mElevationStep;
89 | Log.d(TAG, String.format(Locale.US, "Elevation: %.1f", mElevation));
90 | floatingShape.setElevation(mElevation);
91 | }
92 | });
93 |
94 | /* Lower the circle in z when the "z-" button is clicked. */
95 | rootView.findViewById(R.id.lower_bt).setOnClickListener(new View.OnClickListener() {
96 | @Override
97 | public void onClick(View v) {
98 | mElevation -= mElevationStep;
99 | // Don't allow for negative values of Z.
100 | if (mElevation < 0) {
101 | mElevation = 0;
102 | }
103 | Log.d(TAG, String.format(Locale.US, "Elevation: %.1f", mElevation));
104 | floatingShape.setElevation(mElevation);
105 | }
106 | });
107 |
108 | return rootView;
109 | }
110 |
111 | /**
112 | * ViewOutlineProvider which sets the outline to be an oval which fits the view bounds.
113 | */
114 | private class CircleOutlineProvider extends ViewOutlineProvider {
115 | @Override
116 | public void getOutline(View view, Outline outline) {
117 | outline.setOval(0, 0, view.getWidth(), view.getHeight());
118 | }
119 | }
120 |
121 | }
--------------------------------------------------------------------------------
/Application/src/main/java/com/example/android/elevationdrag/DragFrameLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2014 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.example.android.elevationdrag;
18 |
19 | import android.content.Context;
20 | import android.support.v4.widget.ViewDragHelper;
21 | import android.util.AttributeSet;
22 | import android.view.MotionEvent;
23 | import android.view.View;
24 | import android.widget.FrameLayout;
25 |
26 | import java.util.ArrayList;
27 | import java.util.List;
28 |
29 | /**
30 | * A {@link FrameLayout} that allows the user to drag and reposition child views.
31 | */
32 | public class DragFrameLayout extends FrameLayout {
33 |
34 | /**
35 | * The list of {@link View}s that will be draggable.
36 | */
37 | private List When this is set as the head of the list,
22 | * an instance of it can function as a drop-in replacement for {@link android.util.Log}.
23 | * Most of the methods in this class server only to map a method call in Log to its equivalent
24 | * in LogNode.