Merge "Terminate DocumentsUI opened for the specific root." into nyc-dev
am: e597323
* commit 'e597323939c85f1e7e32272250b790e4d9e234e6':
Terminate DocumentsUI opened for the specific root.
Change-Id: I7fca164e3191ee9ae4ea622cbf77dfcb700db358
This commit is contained in:
@@ -32,6 +32,7 @@ import android.content.pm.ApplicationInfo;
|
|||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ProviderInfo;
|
import android.content.pm.ProviderInfo;
|
||||||
|
import android.database.ContentObserver;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -46,7 +47,6 @@ import android.util.Log;
|
|||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
|
||||||
import com.android.documentsui.SearchViewManager.SearchManagerListener;
|
import com.android.documentsui.SearchViewManager.SearchManagerListener;
|
||||||
@@ -78,6 +78,12 @@ public abstract class BaseActivity extends Activity
|
|||||||
List<EventListener> mEventListeners = new ArrayList<>();
|
List<EventListener> mEventListeners = new ArrayList<>();
|
||||||
|
|
||||||
private final String mTag;
|
private final String mTag;
|
||||||
|
private final ContentObserver mRootsCacheObserver = new ContentObserver(new Handler()) {
|
||||||
|
@Override
|
||||||
|
public void onChange(boolean selfChange) {
|
||||||
|
new HandleRootsChangedTask(BaseActivity.this).execute(getCurrentRoot());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@LayoutRes
|
@LayoutRes
|
||||||
private int mLayoutId;
|
private int mLayoutId;
|
||||||
@@ -118,14 +124,8 @@ public abstract class BaseActivity extends Activity
|
|||||||
|
|
||||||
mRoots = DocumentsApplication.getRootsCache(this);
|
mRoots = DocumentsApplication.getRootsCache(this);
|
||||||
|
|
||||||
mRoots.setOnCacheUpdateListener(
|
getContentResolver().registerContentObserver(
|
||||||
new RootsCache.OnCacheUpdateListener() {
|
RootsCache.sNotificationUri, false, mRootsCacheObserver);
|
||||||
@Override
|
|
||||||
public void onCacheUpdate() {
|
|
||||||
new HandleRootsChangedTask(BaseActivity.this)
|
|
||||||
.execute(getCurrentRoot());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mSearchManager = new SearchViewManager(this, icicle);
|
mSearchManager = new SearchViewManager(this, icicle);
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ public abstract class BaseActivity extends Activity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
mRoots.setOnCacheUpdateListener(null);
|
getContentResolver().unregisterContentObserver(mRootsCacheObserver);
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -793,6 +793,7 @@ public abstract class BaseActivity extends Activity
|
|||||||
|
|
||||||
private static final class HandleRootsChangedTask
|
private static final class HandleRootsChangedTask
|
||||||
extends PairedTask<BaseActivity, RootInfo, RootInfo> {
|
extends PairedTask<BaseActivity, RootInfo, RootInfo> {
|
||||||
|
RootInfo mCurrentRoot;
|
||||||
DocumentInfo mDefaultRootDocument;
|
DocumentInfo mDefaultRootDocument;
|
||||||
|
|
||||||
public HandleRootsChangedTask(BaseActivity activity) {
|
public HandleRootsChangedTask(BaseActivity activity) {
|
||||||
@@ -802,11 +803,10 @@ public abstract class BaseActivity extends Activity
|
|||||||
@Override
|
@Override
|
||||||
protected RootInfo run(RootInfo... roots) {
|
protected RootInfo run(RootInfo... roots) {
|
||||||
assert(roots.length == 1);
|
assert(roots.length == 1);
|
||||||
|
mCurrentRoot = roots[0];
|
||||||
final RootInfo currentRoot = roots[0];
|
|
||||||
final Collection<RootInfo> cachedRoots = mOwner.mRoots.getRootsBlocking();
|
final Collection<RootInfo> cachedRoots = mOwner.mRoots.getRootsBlocking();
|
||||||
for (final RootInfo root : cachedRoots) {
|
for (final RootInfo root : cachedRoots) {
|
||||||
if (root.getUri().equals(currentRoot.getUri())) {
|
if (root.getUri().equals(mCurrentRoot.getUri())) {
|
||||||
// We don't need to change the current root as the current root was not removed.
|
// We don't need to change the current root as the current root was not removed.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -827,6 +827,14 @@ public abstract class BaseActivity extends Activity
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the activity has been launched for the specific root and it is removed, finish the
|
||||||
|
// activity.
|
||||||
|
final Uri uri = mOwner.getIntent().getData();
|
||||||
|
if (uri != null && uri.equals(mCurrentRoot.getUri())) {
|
||||||
|
mOwner.finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Clear entire backstack and start in new root.
|
// Clear entire backstack and start in new root.
|
||||||
mOwner.mState.onRootChanged(defaultRoot);
|
mOwner.mState.onRootChanged(defaultRoot);
|
||||||
mOwner.mSearchManager.update(defaultRoot);
|
mOwner.mSearchManager.update(defaultRoot);
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ public class RootsCache {
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final ContentObserver mObserver;
|
private final ContentObserver mObserver;
|
||||||
private OnCacheUpdateListener mCacheUpdateListener;
|
|
||||||
|
|
||||||
private final RootInfo mRecentsRoot;
|
private final RootInfo mRecentsRoot;
|
||||||
|
|
||||||
@@ -119,10 +118,6 @@ public class RootsCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static interface OnCacheUpdateListener {
|
|
||||||
void onCacheUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gather roots from all known storage providers.
|
* Gather roots from all known storage providers.
|
||||||
*/
|
*/
|
||||||
@@ -280,13 +275,6 @@ public class RootsCache {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Void result) {
|
|
||||||
if (mCacheUpdateListener != null) {
|
|
||||||
mCacheUpdateListener.onCacheUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleDocumentsProvider(ProviderInfo info) {
|
private void handleDocumentsProvider(ProviderInfo info) {
|
||||||
// Ignore stopped packages for now; we might query them
|
// Ignore stopped packages for now; we might query them
|
||||||
// later during UI interaction.
|
// later during UI interaction.
|
||||||
@@ -445,10 +433,6 @@ public class RootsCache {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnCacheUpdateListener(OnCacheUpdateListener cacheUpdateListener) {
|
|
||||||
mCacheUpdateListener = cacheUpdateListener;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the default root for the specified state.
|
* Returns the default root for the specified state.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user