diff options
author | Jeff Sharkey <jsharkey@android.com> | 2014-07-28 16:38:52 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@google.com> | 2014-07-29 23:19:45 +0000 |
commit | f52773fd62fc2fec40c2e17230b644dfbee6cf2d (patch) | |
tree | f1cfd567aa9ae0639f962e7c3d23dd7e728775b2 /packages/DocumentsUI/src/com | |
parent | 1561fd3b066bef822dce69e26bdd7aaa41ca3a84 (diff) | |
download | frameworks_base-f52773fd62fc2fec40c2e17230b644dfbee6cf2d.zip frameworks_base-f52773fd62fc2fec40c2e17230b644dfbee6cf2d.tar.gz frameworks_base-f52773fd62fc2fec40c2e17230b644dfbee6cf2d.tar.bz2 |
More DocumentsUI material iteration.
Move to using Toolbar for all actions. Drawer contains its own
Toolbar with separate title, and hamburger is always visible. Change
drawer items to match spec. Switching to Toolbar allows us to remove
nasty dialog-on-tablet hacks, yay! This also means we can finally
get real IME resizing support.
Move to using elevation for all shadows; this removes more nasty
hacks around drawing directory shadows.
Bug: 15836082
Change-Id: Iba70b898f385a7debd8aabfc98ff39d20bca860d
Diffstat (limited to 'packages/DocumentsUI/src/com')
3 files changed, 90 insertions, 118 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/DirectoryContainerView.java b/packages/DocumentsUI/src/com/android/documentsui/DirectoryContainerView.java index 00b3c87..71ea8a9 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DirectoryContainerView.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DirectoryContainerView.java @@ -36,14 +36,6 @@ public class DirectoryContainerView extends FrameLayout { } @Override - protected void onFinishInflate() { - super.onFinishInflate(); - setClipChildren(false); - setClipToOutline(false); - setClipToPadding(false); - } - - @Override protected void dispatchDraw(Canvas canvas) { final ArrayList<View> disappearing = mDisappearingChildren; if (mDisappearingFirst && disappearing != null) { diff --git a/packages/DocumentsUI/src/com/android/documentsui/DirectoryView.java b/packages/DocumentsUI/src/com/android/documentsui/DirectoryView.java index c163c46..4f52a03 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DirectoryView.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DirectoryView.java @@ -37,19 +37,6 @@ public class DirectoryView extends FrameLayout { } @Override - public void setBackground(Drawable background) { - final Rect rect = new Rect(); - background.getPadding(rect); - - final boolean insetLeft = getResources().getBoolean(R.bool.list_divider_inset_left); - if (insetLeft) { - super.setBackground(new InsetDrawable(background, -rect.left, 0, -rect.right, 0)); - } else { - super.setBackground(new InsetDrawable(background, -rect.right, 0, -rect.left, 0)); - } - } - - @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); mWidth = w; @@ -63,5 +50,11 @@ public class DirectoryView extends FrameLayout { public void setPosition(float position) { mPosition = position; setX((mWidth > 0) ? (mPosition * mWidth) : 0); + + if (mPosition != 0) { + setTranslationZ(getResources().getDimensionPixelSize(R.dimen.dir_elevation)); + } else { + setTranslationZ(0); + } } } diff --git a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java index d0b6a1d..fc85a0a 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java @@ -28,8 +28,6 @@ import static com.android.documentsui.DocumentsActivity.State.ACTION_OPEN_TREE; import static com.android.documentsui.DocumentsActivity.State.MODE_GRID; import static com.android.documentsui.DocumentsActivity.State.MODE_LIST; -import android.app.ActionBar; -import android.app.ActionBar.OnNavigationListener; import android.app.Activity; import android.app.Fragment; import android.app.FragmentManager; @@ -39,14 +37,12 @@ import android.content.ComponentName; import android.content.ContentProviderClient; import android.content.ContentResolver; import android.content.ContentValues; +import android.content.Context; import android.content.Intent; import android.content.pm.ResolveInfo; import android.content.res.Resources; import android.database.Cursor; import android.graphics.Point; -import android.graphics.drawable.ColorDrawable; -import android.graphics.drawable.Drawable; -import android.graphics.drawable.InsetDrawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -55,7 +51,6 @@ import android.os.Parcelable; import android.provider.DocumentsContract; import android.provider.DocumentsContract.Root; import android.support.v4.app.ActionBarDrawerToggle; -import android.support.v4.view.GravityCompat; import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout.DrawerListener; import android.util.Log; @@ -64,17 +59,19 @@ import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.MenuItem.OnActionExpandListener; -import android.view.MotionEvent; import android.view.View; -import android.view.View.OnTouchListener; import android.view.ViewGroup; import android.view.WindowManager; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemSelectedListener; import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.SearchView; import android.widget.SearchView.OnQueryTextListener; +import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; +import android.widget.Toolbar; import com.android.documentsui.RecentsProvider.RecentColumns; import com.android.documentsui.RecentsProvider.ResumeColumns; @@ -105,9 +102,14 @@ public class DocumentsActivity extends Activity { private SearchView mSearchView; + private Toolbar mToolbar; + private Spinner mToolbarStack; + + private Toolbar mRootsToolbar; + private DrawerLayout mDrawerLayout; private ActionBarDrawerToggle mDrawerToggle; - private View mRootsContainer; + private View mRootsDrawer; private DirectoryContainerView mDirectoryContainer; @@ -115,6 +117,8 @@ public class DocumentsActivity extends Activity { private boolean mIgnoreNextClose; private boolean mIgnoreNextCollapse; + private boolean mSearchExpanded; + private RootsCache mRoots; private State mState; @@ -127,59 +131,31 @@ public class DocumentsActivity extends Activity { setResult(Activity.RESULT_CANCELED); setContentView(R.layout.activity); + final Context context = this; final Resources res = getResources(); mShowAsDialog = res.getBoolean(R.bool.show_as_dialog); if (mShowAsDialog) { - // backgroundDimAmount from theme isn't applied; do it manually + // Strongly define our horizontal dimension; we leave vertical as + // WRAP_CONTENT so that system resizes us when IME is showing. final WindowManager.LayoutParams a = getWindow().getAttributes(); - a.dimAmount = 0.6f; - getWindow().setAttributes(a); - - getWindow().setFlags(0, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN); - getWindow().setFlags(~0, WindowManager.LayoutParams.FLAG_DIM_BEHIND); - // Inset ourselves to look like a dialog final Point size = new Point(); getWindowManager().getDefaultDisplay().getSize(size); + a.width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x); - final int width = (int) res.getFraction(R.dimen.dialog_width, size.x, size.x); - final int height = (int) res.getFraction(R.dimen.dialog_height, size.y, size.y); - final int insetX = (size.x - width) / 2; - final int insetY = (size.y - height) / 2; - - final Drawable before = getWindow().getDecorView().getBackground(); - final Drawable after = new InsetDrawable(before, insetX, insetY, insetX, insetY); - getWindow().getDecorView().setBackground(after); - - // Dismiss when touch down in the dimmed inset area - getWindow().getDecorView().setOnTouchListener(new OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_DOWN) { - final float x = event.getX(); - final float y = event.getY(); - if (x < insetX || x > v.getWidth() - insetX || y < insetY - || y > v.getHeight() - insetY) { - finish(); - return true; - } - } - return false; - } - }); + getWindow().setAttributes(a); } else { // Non-dialog means we have a drawer mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, - R.drawable.ic_drawer_glyph, R.string.drawer_open, R.string.drawer_close); + R.drawable.ic_hamburger, R.string.drawer_open, R.string.drawer_close); mDrawerLayout.setDrawerListener(mDrawerListener); - mDrawerLayout.setDrawerShadow(R.drawable.ic_drawer_shadow, GravityCompat.START); - mRootsContainer = findViewById(R.id.container_roots); + mRootsDrawer = findViewById(R.id.drawer_roots); } mDirectoryContainer = (DirectoryContainerView) findViewById(R.id.container_directory); @@ -190,10 +166,23 @@ public class DocumentsActivity extends Activity { buildDefaultState(); } + mToolbar = (Toolbar) findViewById(R.id.toolbar); + mToolbar.setTitleTextAppearance(context, + android.R.style.TextAppearance_DeviceDefault_Widget_ActionBar_Title); + + mToolbarStack = (Spinner) findViewById(R.id.stack); + mToolbarStack.setOnItemSelectedListener(mStackListener); + + mRootsToolbar = (Toolbar) findViewById(R.id.roots_toolbar); + if (mRootsToolbar != null) { + mRootsToolbar.setTitleTextAppearance(context, + android.R.style.TextAppearance_DeviceDefault_Widget_ActionBar_Title); + } + // Hide roots when we're managing a specific root if (mState.action == ACTION_MANAGE) { if (mShowAsDialog) { - findViewById(R.id.dialog_roots).setVisibility(View.GONE); + findViewById(R.id.container_roots).setVisibility(View.GONE); } else { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } @@ -382,15 +371,11 @@ public class DocumentsActivity extends Activity { @Override public void onDrawerOpened(View drawerView) { mDrawerToggle.onDrawerOpened(drawerView); - updateActionBar(); - invalidateOptionsMenu(); } @Override public void onDrawerClosed(View drawerView) { mDrawerToggle.onDrawerClosed(drawerView); - updateActionBar(); - invalidateOptionsMenu(); } @Override @@ -410,9 +395,9 @@ public class DocumentsActivity extends Activity { public void setRootsDrawerOpen(boolean open) { if (!mShowAsDialog) { if (open) { - mDrawerLayout.openDrawer(mRootsContainer); + mDrawerLayout.openDrawer(mRootsDrawer); } else { - mDrawerLayout.closeDrawer(mRootsContainer); + mDrawerLayout.closeDrawer(mRootsDrawer); } } } @@ -421,44 +406,51 @@ public class DocumentsActivity extends Activity { if (mShowAsDialog) { return false; } else { - return mDrawerLayout.isDrawerOpen(mRootsContainer); + return mDrawerLayout.isDrawerOpen(mRootsDrawer); } } public void updateActionBar() { - final ActionBar actionBar = getActionBar(); - - actionBar.setDisplayShowHomeEnabled(true); - - final boolean showIndicator = !mShowAsDialog && (mState.action != ACTION_MANAGE); - actionBar.setDisplayHomeAsUpEnabled(showIndicator); - if (mDrawerToggle != null) { - mDrawerToggle.setDrawerIndicatorEnabled(showIndicator); - } - - if (isRootsDrawerOpen()) { - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); - actionBar.setIcon(new ColorDrawable()); - + if (mRootsToolbar != null) { if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT || mState.action == ACTION_OPEN_TREE) { - actionBar.setTitle(R.string.title_open); + mRootsToolbar.setTitle(R.string.title_open); } else if (mState.action == ACTION_CREATE) { - actionBar.setTitle(R.string.title_save); + mRootsToolbar.setTitle(R.string.title_save); } + } + + final RootInfo root = getCurrentRoot(); + final boolean showRootIcon = mShowAsDialog || (mState.action == ACTION_MANAGE); + if (showRootIcon) { + mToolbar.setNavigationIcon(root != null ? root.loadIcon(this) : null); + mToolbar.setNavigationOnClickListener(null); } else { - final RootInfo root = getCurrentRoot(); - actionBar.setIcon(root != null ? root.loadIcon(this) : null); + mToolbar.setNavigationIcon(R.drawable.ic_hamburger); + mToolbar.setNavigationOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + setRootsDrawerOpen(true); + } + }); + } + if (mSearchExpanded) { + mToolbar.setTitle(null); + mToolbarStack.setVisibility(View.GONE); + mToolbarStack.setAdapter(null); + } else { if (mState.stack.size() <= 1) { - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD); - actionBar.setTitle(root.title); + mToolbar.setTitle(root.title); + mToolbarStack.setVisibility(View.GONE); + mToolbarStack.setAdapter(null); } else { + mToolbar.setTitle(null); + mToolbarStack.setVisibility(View.VISIBLE); + mToolbarStack.setAdapter(mStackAdapter); + mIgnoreNextNavigation = true; - actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); - actionBar.setTitle(null); - actionBar.setListNavigationCallbacks(mStackAdapter, mStackListener); - actionBar.setSelectedNavigationItem(mStackAdapter.getCount() - 1); + mToolbarStack.setSelection(mStackAdapter.getCount() - 1); } } } @@ -480,6 +472,7 @@ public class DocumentsActivity extends Activity { mSearchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { + mSearchExpanded = true; mState.currentSearch = query; mSearchView.clearFocus(); onCurrentDirectoryChanged(ANIM_NONE); @@ -495,11 +488,14 @@ public class DocumentsActivity extends Activity { searchMenu.setOnActionExpandListener(new OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { + mSearchExpanded = true; + updateActionBar(); return true; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { + mSearchExpanded = false; if (mIgnoreNextCollapse) { mIgnoreNextCollapse = false; return true; @@ -514,6 +510,7 @@ public class DocumentsActivity extends Activity { mSearchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { + mSearchExpanded = false; if (mIgnoreNextClose) { mIgnoreNextClose = false; return false; @@ -545,18 +542,6 @@ public class DocumentsActivity extends Activity { final MenuItem list = menu.findItem(R.id.menu_list); final MenuItem settings = menu.findItem(R.id.menu_settings); - // Open drawer means we hide most actions - if (isRootsDrawerOpen()) { - createDir.setVisible(false); - search.setVisible(false); - sort.setVisible(false); - grid.setVisible(false); - list.setVisible(false); - mIgnoreNextCollapse = true; - search.collapseActionView(); - return true; - } - sort.setVisible(cwd != null); grid.setVisible(mState.derivedMode != MODE_GRID); list.setVisible(mState.derivedMode != MODE_LIST); @@ -730,7 +715,7 @@ public class DocumentsActivity extends Activity { public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_title, parent, false); + .inflate(R.layout.item_subdir_title, parent, false); } final TextView title = (TextView) convertView.findViewById(android.R.id.title); @@ -743,8 +728,6 @@ public class DocumentsActivity extends Activity { title.setText(doc.displayName); } - // No padding when shown in actionbar - convertView.setPadding(0, 0, 0, 0); return convertView; } @@ -752,7 +735,7 @@ public class DocumentsActivity extends Activity { public View getDropDownView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_title, parent, false); + .inflate(R.layout.item_subdir, parent, false); } final ImageView subdir = (ImageView) convertView.findViewById(R.id.subdir); @@ -772,20 +755,24 @@ public class DocumentsActivity extends Activity { } }; - private OnNavigationListener mStackListener = new OnNavigationListener() { + private OnItemSelectedListener mStackListener = new OnItemSelectedListener() { @Override - public boolean onNavigationItemSelected(int itemPosition, long itemId) { + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (mIgnoreNextNavigation) { mIgnoreNextNavigation = false; - return false; + return; } - while (mState.stack.size() > itemPosition + 1) { + while (mState.stack.size() > position + 1) { mState.stackTouched = true; mState.stack.pop(); } onCurrentDirectoryChanged(ANIM_UP); - return true; + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + // Ignored } }; |