Merge "Open root list when hovering on the edge in drawer layout."
This commit is contained in:
committed by
Android (Google) Code Review
commit
4e5b694ab2
@@ -52,7 +52,20 @@
|
||||
|
||||
</com.android.documentsui.DocumentsToolbar>
|
||||
|
||||
<include layout="@layout/directory_cluster"/>
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<include layout="@layout/directory_cluster"/>
|
||||
|
||||
<!-- Drawer edge is a dummy view used to capture hovering event
|
||||
on view edge to open the drawer. (b/28345294) -->
|
||||
<View
|
||||
android:id="@+id/drawer_edge"
|
||||
android:background="@android:color/transparent"
|
||||
android:layout_width="@dimen/drawer_edge_width"
|
||||
android:layout_height="match_parent"/>
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@
|
||||
<dimen name="grid_item_elevation">2dp</dimen>
|
||||
<dimen name="max_drawer_width">280dp</dimen>
|
||||
|
||||
<dimen name="drawer_edge_width">12dp</dimen>
|
||||
|
||||
<dimen name="drag_shadow_width">160dp</dimen>
|
||||
<dimen name="drag_shadow_height">48dp</dimen>
|
||||
|
||||
|
||||
@@ -256,6 +256,8 @@ public abstract class BaseActivity extends Activity
|
||||
} else {
|
||||
new PickRootTask(this, root).executeOnExecutor(getExecutorForCurrentDirectory());
|
||||
}
|
||||
|
||||
mNavigator.revealRootsDrawer(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -316,12 +316,6 @@ public class DocumentsActivity extends BaseActivity {
|
||||
.executeOnExecutor(getExecutorForCurrentDirectory());
|
||||
}
|
||||
|
||||
@Override
|
||||
void onRootPicked(RootInfo root) {
|
||||
super.onRootPicked(root);
|
||||
mNavigator.revealRootsDrawer(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDocumentPicked(DocumentInfo doc, Model model) {
|
||||
final FragmentManager fm = getFragmentManager();
|
||||
|
||||
@@ -20,7 +20,7 @@ import static com.android.documentsui.Shared.DEBUG;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.ColorRes;
|
||||
import android.support.v4.app.ActionBarDrawerToggle;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v4.widget.DrawerLayout.DrawerListener;
|
||||
@@ -120,7 +120,8 @@ abstract class DrawerController implements DrawerListener {
|
||||
/**
|
||||
* Runtime controller that manages a real drawer.
|
||||
*/
|
||||
private static final class RuntimeDrawerController extends DrawerController {
|
||||
private static final class RuntimeDrawerController extends DrawerController
|
||||
implements ItemDragListener.DragHost {
|
||||
private final ActionBarDrawerToggle mToggle;
|
||||
private DrawerLayout mLayout;
|
||||
private View mDrawer;
|
||||
@@ -138,6 +139,30 @@ abstract class DrawerController implements DrawerListener {
|
||||
mToggle = toggle;
|
||||
|
||||
mLayout.setDrawerListener(this);
|
||||
|
||||
View edge = layout.findViewById(R.id.drawer_edge);
|
||||
edge.setOnDragListener(new ItemDragListener<>(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runOnUiThread(Runnable runnable) {
|
||||
mDrawer.post(runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDropTargetHighlight(View v, boolean highlight) {
|
||||
assert (v.getId() == R.id.drawer_edge);
|
||||
|
||||
@ColorRes int id = highlight ? R.color.item_doc_background_selected :
|
||||
android.R.color.transparent;
|
||||
v.setBackgroundColor(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewHovered(View v) {
|
||||
assert (v.getId() == R.id.drawer_edge);
|
||||
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -263,12 +263,6 @@ public class FilesActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void onRootPicked(RootInfo root) {
|
||||
super.onRootPicked(root);
|
||||
mDrawer.setOpen(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDocumentsPicked(List<DocumentInfo> docs) {
|
||||
throw new UnsupportedOperationException();
|
||||
|
||||
@@ -186,25 +186,6 @@ public class RootsFragment extends Fragment implements ItemDragListener.DragHost
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void openItem(int position) {
|
||||
Item item = mAdapter.getItem(position);
|
||||
if (item instanceof RootItem) {
|
||||
BaseActivity activity = BaseActivity.get(this);
|
||||
RootInfo newRoot = ((RootItem) item).root;
|
||||
Metrics.logRootVisited(getActivity(), newRoot);
|
||||
activity.onRootPicked(newRoot);
|
||||
} else if (item instanceof AppItem) {
|
||||
DocumentsActivity activity = DocumentsActivity.get(this);
|
||||
ResolveInfo info = ((AppItem) item).info;
|
||||
Metrics.logAppVisited(getActivity(), info);
|
||||
activity.onAppPicked(info);
|
||||
} else if (item instanceof SpacerItem) {
|
||||
if (DEBUG) Log.d(TAG, "Ignoring click/hover on spacer item.");
|
||||
} else {
|
||||
throw new IllegalStateException("Unknown root: " + item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runOnUiThread(Runnable runnable) {
|
||||
getActivity().runOnUiThread(runnable);
|
||||
@@ -217,8 +198,9 @@ public class RootsFragment extends Fragment implements ItemDragListener.DragHost
|
||||
*/
|
||||
@Override
|
||||
public void onViewHovered(View view) {
|
||||
int position = (Integer) view.getTag(R.id.item_position_tag);
|
||||
openItem(position);
|
||||
final int position = (Integer) view.getTag(R.id.item_position_tag);
|
||||
final Item item = mAdapter.getItem(position);
|
||||
item.open(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -232,7 +214,8 @@ public class RootsFragment extends Fragment implements ItemDragListener.DragHost
|
||||
private OnItemClickListener mItemListener = new OnItemClickListener() {
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
openItem(position);
|
||||
final Item item = mAdapter.getItem(position);
|
||||
item.open(RootsFragment.this);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -269,6 +252,8 @@ public class RootsFragment extends Fragment implements ItemDragListener.DragHost
|
||||
abstract void bindView(View convertView);
|
||||
|
||||
abstract boolean isDropTarget();
|
||||
|
||||
abstract void open(RootsFragment fragment);
|
||||
}
|
||||
|
||||
private static class RootItem extends Item {
|
||||
@@ -304,6 +289,13 @@ public class RootsFragment extends Fragment implements ItemDragListener.DragHost
|
||||
boolean isDropTarget() {
|
||||
return root.supportsCreate() && !root.isLibrary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(RootsFragment fragment) {
|
||||
BaseActivity activity = BaseActivity.get(fragment);
|
||||
Metrics.logRootVisited(fragment.getActivity(), root);
|
||||
activity.onRootPicked(root);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SpacerItem extends Item {
|
||||
@@ -320,6 +312,11 @@ public class RootsFragment extends Fragment implements ItemDragListener.DragHost
|
||||
boolean isDropTarget() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(RootsFragment fragment) {
|
||||
if (DEBUG) Log.d(TAG, "Ignoring click/hover on spacer item.");
|
||||
}
|
||||
}
|
||||
|
||||
private static class AppItem extends Item {
|
||||
@@ -349,6 +346,13 @@ public class RootsFragment extends Fragment implements ItemDragListener.DragHost
|
||||
// We won't support drag n' drop in DocumentsActivity, and apps only show up there.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void open(RootsFragment fragment) {
|
||||
DocumentsActivity activity = DocumentsActivity.get(fragment);
|
||||
Metrics.logAppVisited(fragment.getActivity(), info);
|
||||
activity.onAppPicked(info);
|
||||
}
|
||||
}
|
||||
|
||||
private static class RootsAdapter extends ArrayAdapter<Item> {
|
||||
|
||||
@@ -1274,12 +1274,18 @@ public class DirectoryFragment extends Fragment
|
||||
*/
|
||||
@Override
|
||||
public void onViewHovered(View view) {
|
||||
BaseActivity activity = (BaseActivity) getActivity();
|
||||
if (getModelId(view) != null) {
|
||||
((BaseActivity) getActivity()).springOpenDirectory(getDestination(view));
|
||||
activity.springOpenDirectory(getDestination(view));
|
||||
}
|
||||
|
||||
activity.setRootsDrawerOpen(false);
|
||||
}
|
||||
|
||||
public boolean handleDropEvent(View v, DragEvent event) {
|
||||
BaseActivity activity = (BaseActivity) getActivity();
|
||||
activity.setRootsDrawerOpen(false);
|
||||
|
||||
ClipData clipData = event.getClipData();
|
||||
assert (clipData != null);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user