summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtem Shvadskiy <ashvadskiy@cyngn.com>2015-12-09 18:46:16 (GMT)
committerArtem Shvadskiy <ashvadskiy@cyngn.com>2015-12-10 00:10:41 (GMT)
commit57f0a5ecd4afd88659a36fdb698942b0c0cfda9e (patch)
treea76a6e10849fe730e5a38b3d9cf119916a394787
parentd69f636f145d8ff2b49348d179cfa0bbb8d4f83b (diff)
downloadandroid_packages_apps_Trebuchet-57f0a5ecd4afd88659a36fdb698942b0c0cfda9e.zip
android_packages_apps_Trebuchet-57f0a5ecd4afd88659a36fdb698942b0c0cfda9e.tar.gz
android_packages_apps_Trebuchet-57f0a5ecd4afd88659a36fdb698942b0c0cfda9e.tar.bz2
Add remote folder if it is not already present after OOBE, and enable toggle
in settings to hide remote folder if unwanted. Refactor RemoteFolderUpdater to hold static instance of itself. Refactor FolderInfo to use method for determining remote folder status, instead of manually comparing subType flag. Switch back from temp-coordinates after workspace drag/drop is completed. Remove disable button from remote folder UI. Patch 2: Pull remote folder code out of Launcher and into RemoteFolderManager. Patch 3: Remote @author from RemoteFolderManager Patch 4: 1. Remove delete button from folder. 2. Fix NPE when screens are full. Create a new screen and ad at (0,0). 3. Set default preference to false. 4. Clean up leftover imports and unnecessary conditionals. 5. Refactor Launcher.addFolder() method signature. Patch 5: Add missing parenthesis. Change-Id: I36b7a53175a568c5ebdc908d0256d9128e1bee65 issue-id: CYNGNOS-1378 issue-id: CYNGNOS-1331
-rw-r--r--AndroidManifest.xml1
-rw-r--r--RemoteFolder/src/com.cyngn.RemoteFolder/RemoteFolderUpdater.java15
-rw-r--r--res/layout/remote_folder.xml11
-rw-r--r--res/values/preferences_defaults.xml1
-rw-r--r--src/com/android/launcher3/DeleteDropTarget.java12
-rw-r--r--src/com/android/launcher3/Folder.java12
-rw-r--r--src/com/android/launcher3/FolderIcon.java2
-rw-r--r--src/com/android/launcher3/FolderInfo.java20
-rw-r--r--src/com/android/launcher3/Launcher.java41
-rw-r--r--src/com/android/launcher3/LauncherModel.java23
-rw-r--r--src/com/android/launcher3/LauncherSettings.java2
-rw-r--r--src/com/android/launcher3/OverviewSettingsPanel.java7
-rw-r--r--src/com/android/launcher3/RemoteFolder.java37
-rw-r--r--src/com/android/launcher3/RemoteFolderManager.java159
-rw-r--r--src/com/android/launcher3/Workspace.java8
-rw-r--r--src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java19
-rw-r--r--src/com/android/launcher3/settings/SettingsProvider.java1
17 files changed, 265 insertions, 106 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d433424..2b35a5b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -68,6 +68,7 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.BROADCAST_STICKY"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
+ <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
<uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS" />
<uses-permission android:name="com.android.launcher3.permission.READ_SETTINGS" />
diff --git a/RemoteFolder/src/com.cyngn.RemoteFolder/RemoteFolderUpdater.java b/RemoteFolder/src/com.cyngn.RemoteFolder/RemoteFolderUpdater.java
index eb0da80..1322c05 100644
--- a/RemoteFolder/src/com.cyngn.RemoteFolder/RemoteFolderUpdater.java
+++ b/RemoteFolder/src/com.cyngn.RemoteFolder/RemoteFolderUpdater.java
@@ -11,11 +11,26 @@ public class RemoteFolderUpdater {
private static final String TAG = "RemoteFolderUpdater";
+ private static final Object sLock = new Object();
+ private static RemoteFolderUpdater sInstance;
+
public interface RemoteFolderUpdateListener {
void onSuccess(List<RemoteFolderInfo> remoteFolderInfoList);
void onFailure(String error);
}
+ public static RemoteFolderUpdater getInstance() {
+ synchronized (sLock) {
+ if (sInstance == null) {
+ sInstance = new RemoteFolderUpdater();
+ }
+
+ return sInstance;
+ }
+ }
+
+ private RemoteFolderUpdater() { }
+
/**
* Requests data needed by remote folders.
* @param context
diff --git a/res/layout/remote_folder.xml b/res/layout/remote_folder.xml
index b185a21..ffbcb64 100644
--- a/res/layout/remote_folder.xml
+++ b/res/layout/remote_folder.xml
@@ -92,17 +92,6 @@ android:background="@drawable/folder_bg">
android:layout_alignParentRight="true"
/>
- <Button
- android:id="@+id/disable_remote_folder_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:minHeight="@dimen/folder_lock_icon"
- android:text="@string/disable"
- android:layout_below="@id/help_text_view"
- android:layout_toLeftOf="@id/close_info_button"
- android:layout_alignParentBottom="true"
- />
-
</RelativeLayout>
<ScrollView
diff --git a/res/values/preferences_defaults.xml b/res/values/preferences_defaults.xml
index 5693dbb..fd82dbf 100644
--- a/res/values/preferences_defaults.xml
+++ b/res/values/preferences_defaults.xml
@@ -6,6 +6,7 @@
<bool name="preferences_interface_homescreen_scrolling_page_outlines_default">@bool/config_workspaceDefaultShowOutlines</bool>
<bool name="preferences_interface_homescreen_scrolling_fade_adjacent_default">@@bool/config_workspaceFadeAdjacentScreens</bool>
<bool name="preferences_interface_homescreen_hide_icon_labels_default">false</bool>
+ <bool name="preferences_interface_homescreen_remote_folder_default">false</bool>
<string name="preferences_interface_drawer_scrolling_transition_effect">none</string>
<bool name="preferences_interface_drawer_scrolling_fade_adjacent_default">false</bool>
<bool name="preferences_interface_drawer_remove_hidden_apps_shortcuts_default">true</bool>
diff --git a/src/com/android/launcher3/DeleteDropTarget.java b/src/com/android/launcher3/DeleteDropTarget.java
index ea058ea..74b21df 100644
--- a/src/com/android/launcher3/DeleteDropTarget.java
+++ b/src/com/android/launcher3/DeleteDropTarget.java
@@ -330,10 +330,16 @@ public class DeleteDropTarget extends ButtonDropTarget {
} else if (isWorkspaceOrFolderApplication(d)) {
LauncherModel.deleteItemFromDatabase(mLauncher, item);
} else if (isWorkspaceFolder(d)) {
- // Remove the folder from the workspace and delete the contents from launcher model
FolderInfo folderInfo = (FolderInfo) item;
- mLauncher.removeFolder(folderInfo);
- LauncherModel.deleteFolderContentsFromDatabase(mLauncher, folderInfo);
+
+ // Remote folder should not really be deleted. Let the manager handle it.
+ if (folderInfo.isRemote()) {
+ mLauncher.getRemoteFolderManager().onFolderDeleted();
+ } else {
+ // Remove the folder from the workspace and delete the contents from launcher model
+ mLauncher.removeFolder(folderInfo);
+ LauncherModel.deleteFolderContentsFromDatabase(mLauncher, folderInfo);
+ }
} else if (isWorkspaceOrFolderWidget(d)) {
// Remove the widget from the workspace
mLauncher.removeAppWidget((LauncherAppWidgetInfo) item);
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 4cc328c..a0bb2dc 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -486,9 +486,9 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mInfo = info;
final ArrayList<ShortcutInfo> children = info.contents;
- if (info.subType == FolderInfo.REMOTE_SUBTYPE && children.isEmpty()) {
+ if (info.isRemote() && children.isEmpty()) {
final int count = 6;
- RemoteFolderUpdater updater = mLauncher.getRemoteFolderUpdaterInstance();
+ RemoteFolderUpdater updater = RemoteFolderUpdater.getInstance();
updater.requestSync(getContext(), count, new RemoteFolderUpdater.RemoteFolderUpdateListener() {
@Override
public void onSuccess(List<RemoteFolderUpdater.RemoteFolderInfo> remoteFolderInfoList) {
@@ -699,7 +699,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
circX, circY, 0, mScreenWidth);
final View[] alphaViewSet;
- if (mInfo.subType == FolderInfo.REMOTE_SUBTYPE) {
+ if (mInfo.isRemote()) {
alphaViewSet = new View[] { mContent, mFolderName };
} else {
alphaViewSet = new View[] { mFolderNameLockContainer,
@@ -1517,7 +1517,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
}
private void replaceFolderWithFinalItem() {
- if (mInfo.subType == FolderInfo.REMOTE_SUBTYPE) {
+ if (mInfo.isRemote()) {
return;
}
@@ -1681,8 +1681,8 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
mLauncher, item, mInfo.id, 0, item.cellX, item.cellY);
// If this is a Remote Folder, we need to register each view with our updater for click handling.
- if (mInfo.subType == FolderInfo.REMOTE_SUBTYPE) {
- RemoteFolderUpdater updater = mLauncher.getModel().getRemoteFolderUpdaterInstance();
+ if (mInfo.isRemote()) {
+ RemoteFolderUpdater updater = RemoteFolderUpdater.getInstance();
updater.registerViewForInteraction(getViewForInfo(item), item.getIntent());
}
diff --git a/src/com/android/launcher3/FolderIcon.java b/src/com/android/launcher3/FolderIcon.java
index b66d5b7..c414856 100644
--- a/src/com/android/launcher3/FolderIcon.java
+++ b/src/com/android/launcher3/FolderIcon.java
@@ -170,7 +170,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
icon.mLauncher = launcher;
icon.setContentDescription(String.format(launcher.getString(R.string.folder_name_format),
folderInfo.title));
- if (folderInfo.subType == FolderInfo.REMOTE_SUBTYPE) {
+ if (folderInfo.isRemote()) {
RemoteFolder folder = RemoteFolder.fromXml(launcher);
folder.setDragController(launcher.getDragController());
folder.setFolderIcon(icon);
diff --git a/src/com/android/launcher3/FolderInfo.java b/src/com/android/launcher3/FolderInfo.java
index af9cf07..abc6c27 100644
--- a/src/com/android/launcher3/FolderInfo.java
+++ b/src/com/android/launcher3/FolderInfo.java
@@ -75,6 +75,25 @@ public class FolderInfo extends ItemInfo {
itemsChanged();
}
+ /**
+ * @return true if this info represents a remote folder, false otherwise
+ */
+ public boolean isRemote() {
+ return (subType & REMOTE_SUBTYPE) != 0;
+ }
+
+ /**
+ * Set flag indicating whether this folder is remote
+ * @param remote true if folder is remote, false otherwise
+ */
+ public void setRemote(final boolean remote) {
+ if (remote) {
+ subType |= REMOTE_SUBTYPE;
+ } else {
+ subType &= ~REMOTE_SUBTYPE;
+ }
+ }
+
public void setTitle(CharSequence title) {
this.title = title;
for (int i = 0; i < listeners.size(); i++) {
@@ -87,6 +106,7 @@ public class FolderInfo extends ItemInfo {
super.onAddToDatabase(context, values);
values.put(LauncherSettings.Favorites.TITLE, title.toString());
values.put(LauncherSettings.Favorites.HIDDEN, hidden ? 1 : 0);
+ values.put(LauncherSettings.BaseLauncherColumns.SUBTYPE, subType);
}
void addListener(FolderListener listener) {
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index b734ad0..5567a58 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -32,9 +32,7 @@ import android.app.AlertDialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
-import android.app.Dialog;
import android.app.SearchManager;
-import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
@@ -62,7 +60,6 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Rect;
-import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
@@ -73,8 +70,6 @@ import android.os.Handler;
import android.os.Message;
import android.os.StrictMode;
import android.os.SystemClock;
-import android.os.UserHandle;
-import android.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Selection;
@@ -82,7 +77,6 @@ import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.method.TextKeyListener;
import android.util.Log;
-import android.util.Pair;
import android.view.Display;
import android.view.Gravity;
import android.view.HapticFeedbackConstants;
@@ -124,8 +118,6 @@ import com.android.launcher3.compat.UserManagerCompat;
import com.android.launcher3.PagedView.TransitionEffect;
import com.android.launcher3.settings.SettingsProvider;
import com.android.launcher3.stats.LauncherStats;
-import com.android.launcher3.stats.internal.service.AggregationIntentService;
-import com.cyngn.RemoteFolder.RemoteFolderUpdater;
import java.io.DataInputStream;
import java.io.DataOutputStream;
@@ -295,6 +287,7 @@ public class Launcher extends Activity
private DynamicGridSizeFragment mDynamicGridSizeFragment;
private LauncherClings mLauncherClings;
protected HiddenFolderFragment mHiddenFolderFragment;
+ private RemoteFolderManager mRemoteFolderManager;
private AppWidgetManagerCompat mAppWidgetManager;
private LauncherAppWidgetHost mAppWidgetHost;
@@ -404,9 +397,6 @@ public class Launcher extends Activity
private BubbleTextView mWaitingForResume;
- // Remote Folder Updater, used in Workspace and Folder
- private RemoteFolderUpdater remoteFolderUpdater;
-
// Search widget
int mSearchWidgetId;
AppWidgetProviderInfo mSearchWidgetInfo;
@@ -516,6 +506,8 @@ public class Launcher extends Activity
mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
mAppWidgetHost.startListening();
+ mRemoteFolderManager = new RemoteFolderManager(this);
+
// If we are getting an onCreate, we can actually preempt onResume and unset mPaused here,
// this also ensures that any synchronous binding below doesn't re-trigger another
// LauncherModel load.
@@ -2256,6 +2248,10 @@ public class Launcher extends Activity
return mWorkspace;
}
+ public RemoteFolderManager getRemoteFolderManager() {
+ return mRemoteFolderManager;
+ }
+
public Hotseat getHotseat() {
return mHotseat;
}
@@ -2806,10 +2802,14 @@ public class Launcher extends Activity
}
FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
- int cellY) {
- final FolderInfo folderInfo = new FolderInfo();
+ int cellY) {
+ FolderInfo folderInfo = new FolderInfo();
folderInfo.title = getText(R.string.folder_name);
+ return addFolder(layout, container, screenId, cellX, cellY, folderInfo);
+ }
+ FolderIcon addFolder(CellLayout layout, long container, final long screenId, int cellX,
+ int cellY, FolderInfo folderInfo) {
// Update the model
LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screenId, cellX, cellY,
false);
@@ -3230,7 +3230,7 @@ public class Launcher extends Activity
// Open the requested folder
openFolder(folderIcon, folderTouchXYOffset);
- if (info.subType == FolderInfo.REMOTE_SUBTYPE) {
+ if (info.isRemote()) {
mModel.syncRemoteFolder(info, this);
}
} else {
@@ -4948,6 +4948,10 @@ public class Launcher extends Activity
newFolder.setTextVisible(!mHideIconLabels);
workspace.addInScreenFromBind(newFolder, item.container, item.screenId, item.cellX,
item.cellY, 1, 1);
+
+ if (((FolderInfo) item).isRemote()) {
+ mRemoteFolderManager.setRemoteFolder(newFolder);
+ }
break;
default:
throw new RuntimeException("Invalid Item Type");
@@ -5199,6 +5203,8 @@ public class Launcher extends Activity
mWorkspace.resetOverviewMode();
}
mModel.updateCount();
+
+ mRemoteFolderManager.bindFinished();
}
private void sendLoadingCompleteBroadcastIfNecessary() {
@@ -5946,13 +5952,6 @@ public class Launcher extends Activity
SettingsProvider.SETTINGS_UI_HOMESCREEN_SEARCH,
R.bool.preferences_interface_homescreen_search_default);
}
-
- public RemoteFolderUpdater getRemoteFolderUpdaterInstance() {
- if (remoteFolderUpdater == null) {
- remoteFolderUpdater = new RemoteFolderUpdater();
- }
- return remoteFolderUpdater;
- }
}
interface LauncherTransitionable {
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 3a04285..365396b 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -2393,7 +2393,7 @@ public class LauncherModel extends BroadcastReceiver
sBgItemsIdMap.put(folderInfo.id, folderInfo);
sBgFolders.put(folderInfo.id, folderInfo);
- if (folderInfo.subType == FolderInfo.REMOTE_SUBTYPE) {
+ if (folderInfo.isRemote()) {
syncRemoteFolder(folderInfo, mContext);
}
@@ -2872,7 +2872,7 @@ public class LauncherModel extends BroadcastReceiver
}
workspaceItems.remove(i);
folders.remove(Long.valueOf(item.id));
- } else if (folder.contents.size() == 0 && folder.subType == 0) {
+ } else if (folder.contents.size() == 0 && !folder.isRemote()) {
LauncherModel.deleteFolderContentsFromDatabase(mContext, folder);
workspaceItems.remove(i);
folders.remove(Long.valueOf(item.id));
@@ -4259,25 +4259,8 @@ public class LauncherModel extends BroadcastReceiver
return mCallbacks != null ? mCallbacks.get() : null;
}
- public static RemoteFolderUpdater getRemoteFolderUpdaterInstance() {
- if (remoteFolderUpdater == null) {
- remoteFolderUpdater = new RemoteFolderUpdater();
- }
- return remoteFolderUpdater;
- }
-
protected synchronized void syncRemoteFolder(final FolderInfo folderInfo, final Context context) {
-
- String spKey = LauncherAppState.getSharedPreferencesKey();
- SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
- boolean isEnabled = sp.getBoolean(RemoteFolder.REMOTE_FOLDER_ENABLED, true);
-
- if (!isEnabled) {
- Log.e(TAG, "Prevented remote folder sync, since it has been explicitly disabled.");
- return;
- }
-
- RemoteFolderUpdater updater = getRemoteFolderUpdaterInstance();
+ RemoteFolderUpdater updater = RemoteFolderUpdater.getInstance();
final int count = 6;
updater.requestSync(context, count, new RemoteFolderUpdater.RemoteFolderUpdateListener() {
diff --git a/src/com/android/launcher3/LauncherSettings.java b/src/com/android/launcher3/LauncherSettings.java
index 50aa5c4..d7df5a7 100644
--- a/src/com/android/launcher3/LauncherSettings.java
+++ b/src/com/android/launcher3/LauncherSettings.java
@@ -262,8 +262,6 @@ class LauncherSettings {
*/
static final int ITEM_TYPE_WIDGET_PHOTO_FRAME = 1002;
- static final int ITEM_TYPE_REMOTE_FOLDER = 2000;
-
/**
* The appWidgetId of the widget
*
diff --git a/src/com/android/launcher3/OverviewSettingsPanel.java b/src/com/android/launcher3/OverviewSettingsPanel.java
index fef1643..58567ab 100644
--- a/src/com/android/launcher3/OverviewSettingsPanel.java
+++ b/src/com/android/launcher3/OverviewSettingsPanel.java
@@ -46,7 +46,8 @@ public class OverviewSettingsPanel {
res.getString(R.string.scroll_effect_text),
res.getString(R.string.icon_labels),
res.getString(R.string.scrolling_wallpaper),
- res.getString(R.string.grid_size_text)};
+ res.getString(R.string.grid_size_text),
+ res.getString(R.string.recommendations_title)};
String[] valuesDrawer = new String[] {
res.getString(R.string.drawer_type),
@@ -174,7 +175,8 @@ public class OverviewSettingsPanel {
res.getString(R.string.scroll_effect_text),
res.getString(R.string.icon_labels),
res.getString(R.string.scrolling_wallpaper),
- res.getString(R.string.grid_size_text)};
+ res.getString(R.string.grid_size_text),
+ res.getString(R.string.recommendations_title)};
mSettingsAdapter.changeCursor(0, createCursor(res
.getString(R.string.home_screen_settings), values));
}
@@ -192,7 +194,6 @@ public class OverviewSettingsPanel {
mSettingsAdapter.notifyDataSetInvalidated();
}
-
class SettingsSimplePanelSlideListener extends SlidingUpPanelLayout.SimplePanelSlideListener {
ImageView mAnimatedArrow;
diff --git a/src/com/android/launcher3/RemoteFolder.java b/src/com/android/launcher3/RemoteFolder.java
index 0d33a55..9478ea6 100644
--- a/src/com/android/launcher3/RemoteFolder.java
+++ b/src/com/android/launcher3/RemoteFolder.java
@@ -24,7 +24,6 @@ public class RemoteFolder extends Folder {
private ImageView mFolderInfo;
private TextView mFolderHelpText;
private Button mCloseInfoButton;
- private Button mDisableFolderButton;
private View mFolderInfoContainer;
private int mFolderInfoContainerHeight;
@@ -82,11 +81,6 @@ public class RemoteFolder extends Folder {
mCloseInfoButton.measure(measureSpec, measureSpec);
mButtonHeight = mCloseInfoButton.getMeasuredHeight();
mCloseInfoButton.setOnClickListener(this);
-
- mDisableFolderButton = (Button) findViewById(R.id.disable_remote_folder_button);
- mDisableFolderButton.setText(getResources().getString(R.string.disable));
- mDisableFolderButton.measure(measureSpec, measureSpec);
- mDisableFolderButton.setOnClickListener(this);
}
protected int getFolderHeight() {
@@ -146,8 +140,6 @@ public class RemoteFolder extends Folder {
mFolderInfoIconHeight + mHelpTextHeight + mButtonHeight, MeasureSpec.EXACTLY));
mCloseInfoButton.measure(contentAreaWidthSpec,
MeasureSpec.makeMeasureSpec(mButtonHeight, MeasureSpec.EXACTLY));
- mDisableFolderButton.measure(contentAreaWidthSpec,
- MeasureSpec.makeMeasureSpec(mButtonHeight, MeasureSpec.EXACTLY));
} else {
mHelpTextHeight = 0;
mFolderHelpText.measure(contentAreaWidthSpec, MeasureSpec.makeMeasureSpec(
@@ -156,8 +148,6 @@ public class RemoteFolder extends Folder {
MeasureSpec.makeMeasureSpec(mFolderInfoIconHeight, MeasureSpec.EXACTLY));
mCloseInfoButton.measure(contentAreaWidthSpec,
MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
- mDisableFolderButton.measure(contentAreaWidthSpec,
- MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY));
}
Log.e(TAG, "onMeasure(), width: " + width + ", height:" + height);
@@ -178,9 +168,6 @@ public class RemoteFolder extends Folder {
case R.id.close_info_button:
mLauncher.closeFolder();
break;
- case R.id.disable_remote_folder_button:
- disableRemoteFolder();
- break;
default:
break;
}
@@ -195,7 +182,6 @@ public class RemoteFolder extends Folder {
mFolderHelpText.setVisibility(GONE);
mCloseInfoButton.setVisibility(GONE);
- mDisableFolderButton.setVisibility(GONE);
mFolderInfo.setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher_info_normal_holo));
@@ -207,31 +193,10 @@ public class RemoteFolder extends Folder {
mFolderHelpText.setVisibility(VISIBLE);
mCloseInfoButton.setVisibility(VISIBLE);
- mDisableFolderButton.setVisibility(VISIBLE);
mFolderInfo.setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher_clear_normal_holo));
}
this.invalidate();
-
- }
-
- private void disableRemoteFolder() {
- // close the folder UX & disable remote folders.
- mLauncher.closeFolder();
-
- if (mContext != null) {
- String spKey = LauncherAppState.getSharedPreferencesKey();
- SharedPreferences sp = mContext.getSharedPreferences(spKey, Context.MODE_PRIVATE);
- sp.edit().putBoolean(REMOTE_FOLDER_ENABLED, false).commit();
- Log.e(TAG, "Set preference to disable remote folder. Requesting sync to remove existing folder");
-
- LauncherModel.deleteFolderContentsFromDatabase(mContext, mInfo);
- LauncherModel.deleteItemFromDatabase(mContext, mInfo);
- mLauncher.getWorkspace().removeView(this);
- mLauncher.removeFolder(mInfo);
-
- mLauncher.getWorkspace().refreshDrawableState();
- }
}
@Override
@@ -239,7 +204,6 @@ public class RemoteFolder extends Folder {
super.animateClosed(animate);
mFolderHelpText.setVisibility(GONE);
mCloseInfoButton.setVisibility(GONE);
- mDisableFolderButton.setVisibility(GONE);
mContentScrollView.setVisibility(VISIBLE);
mFolderInfo.setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher_info_normal_holo));
}
@@ -251,7 +215,6 @@ public class RemoteFolder extends Folder {
mFolderHelpText.setText(getResources().getString(R.string.recommendations_help_text));
mFolderHelpText.setVisibility(GONE);
mCloseInfoButton.setVisibility(GONE);
- mDisableFolderButton.setVisibility(GONE);
mContentScrollView.setVisibility(VISIBLE);
mContent.setVisibility(VISIBLE);
mFolderInfo.setImageDrawable(getResources().getDrawable(R.drawable.ic_launcher_info_normal_holo));
diff --git a/src/com/android/launcher3/RemoteFolderManager.java b/src/com/android/launcher3/RemoteFolderManager.java
new file mode 100644
index 0000000..efbc915
--- /dev/null
+++ b/src/com/android/launcher3/RemoteFolderManager.java
@@ -0,0 +1,159 @@
+package com.android.launcher3;
+
+import android.util.Log;
+import android.util.Pair;
+import android.view.View;
+import com.android.launcher3.settings.SettingsProvider;
+
+import java.util.ArrayList;
+
+/**
+ * Manages adding and removing the remote folder from the workspace.
+ */
+public class RemoteFolderManager {
+ private static final String TAG = "RemoteFolderManager";
+
+ private final Launcher mLauncher;
+
+ /** View which is displayed in the workspace **/
+ private FolderIcon mRemoteFolder;
+ /** Coordinates of the folder's position before being hidden **/
+ private int[] mRemoteFolderCell;
+
+ public RemoteFolderManager(final Launcher launcher) {
+ mLauncher = launcher;
+ mRemoteFolderCell = new int[2];
+ }
+
+ public void setRemoteFolder(final FolderIcon remoteFolder) {
+ mRemoteFolder = remoteFolder;
+ }
+
+ /**
+ * Called when Launcher finishes binding items from the model.
+ */
+ public void bindFinished() {
+ boolean remoteFolderEnabled = SettingsProvider.getBoolean(mLauncher,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_REMOTE_FOLDER,
+ R.bool.preferences_interface_homescreen_remote_folder_default);
+ if (remoteFolderEnabled && mRemoteFolder == null) {
+ showRemoteFolder();
+ } else if (!remoteFolderEnabled) {
+ // We might load the remote folder on startup, but we shouldn't show it
+ hideRemoteFolder();
+ }
+ }
+
+ /**
+ * Called when the setting for remote folder is updated.
+ * @param newValue the new setting for remote folder
+ */
+ public void onSettingChanged(final boolean newValue) {
+ if (newValue) {
+ showRemoteFolder();
+ } else {
+ hideRemoteFolder();
+ }
+ }
+
+ /**
+ * Called when the remote folder is dropped into the delete area on the workspace.
+ */
+ public void onFolderDeleted() {
+ hideRemoteFolder();
+ SettingsProvider.putBoolean(mLauncher,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_REMOTE_FOLDER, false);
+ mLauncher.mOverviewSettingsPanel.notifyDataSetInvalidated();
+ }
+
+ private void showRemoteFolder() {
+ int[] cell;
+ long screen;
+ long container;
+ boolean findNewSpace = true;
+ FolderInfo folderInfo = null;
+ Workspace workspace = mLauncher.getWorkspace();
+
+ // Check if we can re-add at our old location
+ if (mRemoteFolder != null) {
+ folderInfo = mRemoteFolder.getFolderInfo();
+ CellLayout cellLayout = mLauncher.getCellLayout(
+ folderInfo.container, folderInfo.screenId);
+ if (cellLayout != null
+ && !cellLayout.isOccupied(mRemoteFolderCell[0], mRemoteFolderCell[1])) {
+ findNewSpace = false;
+ }
+ }
+ if (findNewSpace) {
+ // Try to find a new space to add.
+ Pair<Long, int[]> space = LauncherModel.findNextAvailableIconSpace(mLauncher, null,
+ null, 0, new ArrayList<Long>(workspace.getWorkspaceScreenIds()));
+
+ // All screens are full. Create a new screen.
+ if (space == null) {
+ workspace.addExtraEmptyScreen();
+ screen = workspace.commitExtraEmptyScreen();
+ cell = new int[2];
+ } else {
+ screen = space.first;
+ cell = space.second;
+ }
+
+ container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
+ } else {
+ screen = folderInfo.screenId;
+ cell = mRemoteFolderCell;
+ container = folderInfo.container;
+ }
+
+ // Create the folder if this is our first time showing it
+ if (mRemoteFolder == null) {
+ folderInfo = new FolderInfo();
+ folderInfo.setTitle(mLauncher.getString(R.string.recommendations_title));
+ folderInfo.setRemote(true);
+
+ CellLayout cellLayout = mLauncher.getCellLayout(container, screen);
+ mRemoteFolder = mLauncher.addFolder(cellLayout, container, screen,
+ cell[0], cell[1], folderInfo);
+
+ mLauncher.getModel().syncRemoteFolder(folderInfo, mLauncher);
+ } else {
+ // Folder may be hidden by drop delete animation, so force visibility.
+ mRemoteFolder.setVisibility(View.VISIBLE);
+ workspace.addInScreen(mRemoteFolder, container, screen,
+ cell[0], cell[1], 1, 1, mLauncher.isWorkspaceLocked());
+ mLauncher.getCellLayout(container, screen)
+ .getShortcutsAndWidgets().measureChild(mRemoteFolder);
+
+ // Update the model
+ folderInfo.cellX = cell[0];
+ folderInfo.cellY = cell[1];
+ folderInfo.container = container;
+ folderInfo.screenId = screen;
+ LauncherModel.updateItemInDatabase(mLauncher, folderInfo);
+ }
+ }
+
+ private void hideRemoteFolder() {
+ // Remote folder does not exist
+ if (mRemoteFolder == null) {
+ Log.e(TAG, "Remote folder is null");
+ return;
+ }
+
+ FolderInfo info = mRemoteFolder.getFolderInfo();
+
+ // Store our current location so we can try to re-add in the same spot later.
+ mRemoteFolderCell[0] = info.cellX;
+ mRemoteFolderCell[1] = info.cellY;
+
+ // Clear the spot
+ mLauncher.getCellLayout(info.container, info.screenId).removeView(mRemoteFolder);
+ info.cellX = -1;
+ info.cellY = -1;
+ LauncherModel.updateItemInDatabase(mLauncher, info);
+
+ // We may be removing from a screen we're on alone, so remove it if necessary.
+ mLauncher.getWorkspace().removeExtraEmptyScreen(false, true);
+ }
+}
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 197c09a..e6087a6 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -400,6 +400,13 @@ public class Workspace extends SmoothPagedView
}
}
+ /**
+ * @return A {@link Set} of {@link Long}s representing ids of the workspace screens
+ */
+ public Set<Long> getWorkspaceScreenIds() {
+ return mWorkspaceScreens.keySet();
+ }
+
// estimate the size of a widget with spans hSpan, vSpan. return MAX_VALUE for each
// dimension if unsuccessful
public int[] estimateItemSize(int hSpan, int vSpan,
@@ -4462,6 +4469,7 @@ public class Workspace extends SmoothPagedView
}
if (cellLayout != null) {
cellLayout.onDropChild(mDragInfo.cell);
+ cellLayout.setUseTempCoords(false);
}
}
if ((d.cancelled || (beingCalledAfterUninstall && !mUninstallSuccessful))
diff --git a/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java b/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java
index df9a1f0..a9364d4 100644
--- a/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java
+++ b/src/com/android/launcher3/list/SettingsPinnedHeaderAdapter.java
@@ -132,6 +132,14 @@ public class SettingsPinnedHeaderAdapter extends PinnedHeaderListAdapter {
case 4:
updateDynamicGridSizeSettingsItem(v);
break;
+ case 5:
+ current = SettingsProvider.getBoolean(mContext,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_REMOTE_FOLDER,
+ R.bool.preferences_interface_homescreen_remote_folder_default);
+ state = current ? res.getString(R.string.setting_state_on)
+ : res.getString(R.string.setting_state_off);
+ ((TextView) v.findViewById(R.id.item_state)).setText(state);
+ break;
default:
((TextView) v.findViewById(R.id.item_state)).setText("");
}
@@ -308,7 +316,12 @@ public class SettingsPinnedHeaderAdapter extends PinnedHeaderListAdapter {
case 4:
mLauncher.onClickDynamicGridSizeButton();
break;
-
+ case 5:
+ boolean newValue = onSettingsBooleanChanged(v,
+ SettingsProvider.SETTINGS_UI_HOMESCREEN_REMOTE_FOLDER,
+ R.bool.preferences_interface_homescreen_remote_folder_default);
+ mLauncher.getRemoteFolderManager().onSettingChanged(newValue);
+ break;
}
break;
case OverviewSettingsPanel.DRAWER_SETTINGS_POSITION:
@@ -372,7 +385,7 @@ public class SettingsPinnedHeaderAdapter extends PinnedHeaderListAdapter {
R.bool.preferences_interface_homescreen_search_default);
}
- private void onSettingsBooleanChanged(View v, String key, int res) {
+ private boolean onSettingsBooleanChanged(View v, String key, int res) {
boolean current = SettingsProvider.getBoolean(
mContext, key, res);
@@ -384,6 +397,8 @@ public class SettingsPinnedHeaderAdapter extends PinnedHeaderListAdapter {
R.string.setting_state_off) : mLauncher.getResources().getString(
R.string.setting_state_on);
((TextView) v.findViewById(R.id.item_state)).setText(state);
+
+ return !current;
}
private void onIconLabelsBooleanChanged(View v, String key, int res) {
diff --git a/src/com/android/launcher3/settings/SettingsProvider.java b/src/com/android/launcher3/settings/SettingsProvider.java
index 042053c..841fa3e 100644
--- a/src/com/android/launcher3/settings/SettingsProvider.java
+++ b/src/com/android/launcher3/settings/SettingsProvider.java
@@ -31,6 +31,7 @@ public final class SettingsProvider {
public static final String SETTINGS_UI_HOMESCREEN_SCROLLING_WALLPAPER_SCROLL = "ui_homescreen_scrolling_wallpaper_scroll";
public static final String SETTINGS_UI_HOMESCREEN_SCROLLING_PAGE_OUTLINES = "ui_homescreen_scrolling_page_outlines";
public static final String SETTINGS_UI_HOMESCREEN_SCROLLING_FADE_ADJACENT = "ui_homescreen_scrolling_fade_adjacent";
+ public static final String SETTINGS_UI_HOMESCREEN_REMOTE_FOLDER = "ui_homescreen_remote_folder";
public static final String SETTINGS_UI_DYNAMIC_GRID_SIZE = "ui_dynamic_grid_size";
public static final String SETTINGS_UI_HOMESCREEN_ROWS = "ui_homescreen_rows";
public static final String SETTINGS_UI_HOMESCREEN_COLUMNS = "ui_homescreen_columns";