Commit 5896f532 by Baoxy

fix: 禁止桌面摆放多个相同图标/优化激活逻辑

parent 7808bffa
......@@ -80,7 +80,7 @@
<activity android:name=".settings.wifi.WifiWhiteListActivity"
android:excludeFromRecents="true"/>
<activity android:name=".function.setting.AdminSettingActivity"
<activity android:name=".function.setting.SettingAdminActivity"
android:theme="@style/SettingTheme"
android:excludeFromRecents="true"/>
......
......@@ -5,7 +5,7 @@
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context="com.android.launcher3.function.setting.AdminSettingActivity">
tools:context="com.android.launcher3.function.setting.SettingAdminActivity">
<TextView
android:id="@+id/tv_setting_title"
......
......@@ -153,6 +153,7 @@ import com.android.launcher3.widget.WidgetAddFlowHandler;
import com.android.launcher3.widget.WidgetHostViewLoader;
import com.android.launcher3.widget.WidgetsContainerView;
import com.google.gson.Gson;
import com.secspace.lib.common.dialog.other.DialogUIUtils;
import com.secspace.lib.common.event.ChangeWallPaperEvent;
import com.secspace.lib.common.event.InitEvent;
import com.secspace.lib.common.event.RefreshWorkSpaceEvent;
......@@ -1211,12 +1212,6 @@ public class Launcher extends BaseActivity
}
private void activationNext() {
String pwd = Prefs.getLoginPwd(this);
if (TextUtils.isEmpty(pwd)) {
Intent intent = new Intent(this, PwdPinSetPwdActivity.class);
startActivity(intent);
return;
}
LauncherAppState app = LauncherAppState.getInstanceNoCreate();
if (app != null) {
app.getModel().forceReload();
......@@ -3121,7 +3116,7 @@ public class Launcher extends BaseActivity
if (TextUtils.equals(((EditText)view).getText().toString(), Prefs.getLoginPwd(mAppContext))) {
IntentUtil.startExitService(mAppContext);
} else {
ToastUtil.showLong(mAppContext, "密码错误!");
DialogUIUtils.showToastCenter("密码错误");
ErrorTimeHelper.getInstance(mAppContext).addErrorCount();
}
}
......
......@@ -9,8 +9,9 @@ import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import com.android.launcher3.function.setting.AdminSettingActivity;
import com.android.launcher3.function.setting.SettingAdminActivity;
import com.android.launcher3.settings.ErrorTimeHelper;
import com.secspace.lib.common.dialog.other.DialogUIUtils;
import com.secspace.lib.common.function.DialogManager;
import com.secspace.lib.common.utils.InputUtil;
import com.secspace.lib.common.utils.Prefs;
......@@ -37,14 +38,13 @@ public class ManagerAuthActivity extends BaseActivity {
boolean canInputPwd = ErrorTimeHelper.getInstance(mAppContext).canInputPwd();
if (canInputPwd){
if (TextUtils.equals(editText.getText().toString(), Prefs.getLoginPwd(mAppContext))) {
ToastUtil.showLong(mAppContext, "密码正确!");
finish();
ErrorTimeHelper.getInstance(mAppContext).resetLockTimeAndCount();
Intent intent = new Intent();
intent.setClass(mAppContext, AdminSettingActivity.class);
intent.setClass(mAppContext, SettingAdminActivity.class);
startActivity(intent);
} else {
ToastUtil.showLong(mAppContext, "密码错误!");
DialogUIUtils.showToastCenter("密码错误");
ErrorTimeHelper.getInstance(mAppContext).addErrorCount();
finish();
}
......
......@@ -105,12 +105,16 @@ public class Workspace extends PagedView
Insettable, DropTargetSource {
private static final String TAG = "Launcher.Workspace";
/** The value that {@link #mTransitionProgress} must be greater than for
* {@link #transitionStateShouldAllowDrop()} to return true. */
/**
* The value that {@link #mTransitionProgress} must be greater than for
* {@link #transitionStateShouldAllowDrop()} to return true.
*/
private static final float ALLOW_DROP_TRANSITION_PROGRESS = 0.25f;
/** The value that {@link #mTransitionProgress} must be greater than for
* {@link #isFinishedSwitchingState()} ()} to return true. */
/**
* The value that {@link #mTransitionProgress} must be greater than for
* {@link #isFinishedSwitchingState()} ()} to return true.
*/
private static final float FINISHED_SWITCHING_STATE_TRANSITION_PROGRESS = 0.5f;
private static boolean ENFORCE_DRAG_EVENT_ORDER = false;
......@@ -135,15 +139,20 @@ public class Workspace extends PagedView
private long mCustomContentShowTime = -1;
private LayoutTransition mLayoutTransition;
@Thunk final WallpaperManager mWallpaperManager;
@Thunk
final WallpaperManager mWallpaperManager;
private ShortcutAndWidgetContainer mDragSourceInternal;
@Thunk LongArrayMap<CellLayout> mWorkspaceScreens = new LongArrayMap<>();
@Thunk ArrayList<Long> mScreenOrder = new ArrayList<Long>();
@Thunk
LongArrayMap<CellLayout> mWorkspaceScreens = new LongArrayMap<>();
@Thunk
ArrayList<Long> mScreenOrder = new ArrayList<Long>();
@Thunk Runnable mRemoveEmptyScreenRunnable;
@Thunk boolean mDeferRemoveExtraEmptyScreen = false;
@Thunk
Runnable mRemoveEmptyScreenRunnable;
@Thunk
boolean mDeferRemoveExtraEmptyScreen = false;
/**
* CellInfo for the cell that is currently being dragged
......@@ -153,7 +162,8 @@ public class Workspace extends PagedView
/**
* Target drop area calculated during last acceptDrop call.
*/
@Thunk int[] mTargetCell = new int[2];
@Thunk
int[] mTargetCell = new int[2];
private int mDragOverX = -1;
private int mDragOverY = -1;
......@@ -165,7 +175,8 @@ public class Workspace extends PagedView
/**
* The CellLayout that is currently being dragged over
*/
@Thunk CellLayout mDragTargetLayout = null;
@Thunk
CellLayout mDragTargetLayout = null;
/**
* The CellLayout that we will show as highlighted
*/
......@@ -176,15 +187,18 @@ public class Workspace extends PagedView
*/
private CellLayout mDropToLayout = null;
@Thunk Launcher mLauncher;
@Thunk DragController mDragController;
@Thunk
Launcher mLauncher;
@Thunk
DragController mDragController;
// These are temporary variables to prevent having to allocate a new object just to
// return an (x, y) value from helper functions. Do NOT use them to maintain other state.
private static final Rect sTempRect = new Rect();
private final int[] mTempXY = new int[2];
@Thunk float[] mDragViewVisualCenter = new float[2];
@Thunk
float[] mDragViewVisualCenter = new float[2];
private float[] mTempTouchCoordinates = new float[2];
private SpringLoadedDragController mSpringLoadedDragController;
......@@ -194,11 +208,11 @@ public class Workspace extends PagedView
// in all apps or customize mode)
public enum State {
NORMAL (false, false, ContainerType.WORKSPACE),
NORMAL_HIDDEN (false, false, ContainerType.ALLAPPS),
SPRING_LOADED (false, true, ContainerType.WORKSPACE),
OVERVIEW (true, true, ContainerType.OVERVIEW),
OVERVIEW_HIDDEN (true, false, ContainerType.WIDGETS);
NORMAL(false, false, ContainerType.WORKSPACE),
NORMAL_HIDDEN(false, false, ContainerType.ALLAPPS),
SPRING_LOADED(false, true, ContainerType.WORKSPACE),
OVERVIEW(true, true, ContainerType.OVERVIEW),
OVERVIEW_HIDDEN(true, false, ContainerType.WIDGETS);
public final boolean shouldUpdateWidget;
public final boolean hasMultipleVisiblePages;
......@@ -213,8 +227,8 @@ public class Workspace extends PagedView
// Direction used for moving the workspace and hotseat UI
public enum Direction {
X (TRANSLATION_X),
Y (TRANSLATION_Y);
X(TRANSLATION_X),
Y(TRANSLATION_Y);
private final Property<View, Float> viewProperty;
......@@ -228,13 +242,13 @@ public class Workspace extends PagedView
/**
* These values correspond to {@link Direction#X} & {@link Direction#Y}
*/
private float[] mPageAlpha = new float[] {1, 1};
private float[] mPageAlpha = new float[]{1, 1};
/**
* Hotseat alpha can be changed when moving horizontally, vertically, changing states.
* The values correspond to {@link Direction#X}, {@link Direction#Y} &
* {@link #HOTSEAT_STATE_ALPHA_INDEX} respectively.
*/
private float[] mHotseatAlpha = new float[] {1, 1, 1};
private float[] mHotseatAlpha = new float[]{1, 1, 1};
public static final int QSB_ALPHA_INDEX_STATE_CHANGE = 0;
public static final int QSB_ALPHA_INDEX_Y_TRANSLATION = 1;
......@@ -259,7 +273,8 @@ public class Workspace extends PagedView
final WallpaperOffsetInterpolator mWallpaperOffset;
private boolean mUnlockWallpaperFromDefaultPageOnLayout;
@Thunk Runnable mDelayedResizeRunnable;
@Thunk
Runnable mDelayedResizeRunnable;
private Runnable mDelayedSnapToPageRunnable;
// Variables relating to the creation of user folders by hovering shortcuts over shortcuts
......@@ -295,8 +310,10 @@ public class Workspace extends PagedView
private static final int DRAG_MODE_ADD_TO_FOLDER = 2;
private static final int DRAG_MODE_REORDER = 3;
private int mDragMode = DRAG_MODE_NONE;
@Thunk int mLastReorderX = -1;
@Thunk int mLastReorderY = -1;
@Thunk
int mLastReorderX = -1;
@Thunk
int mLastReorderY = -1;
private SparseArray<Parcelable> mSavedStates;
private final ArrayList<Integer> mRestoredPages = new ArrayList<Integer>();
......@@ -304,7 +321,8 @@ public class Workspace extends PagedView
private float mCurrentScale;
private float mTransitionProgress;
@Thunk Runnable mDeferredAction;
@Thunk
Runnable mDeferredAction;
private boolean mDeferDropAfterUninstall;
private boolean mUninstallSuccessful;
......@@ -331,7 +349,7 @@ public class Workspace extends PagedView
* Used to inflate the Workspace from XML.
*
* @param context The application's context.
* @param attrs The attributes set containing the Workspace's customization values.
* @param attrs The attributes set containing the Workspace's customization values.
*/
public Workspace(Context context, AttributeSet attrs) {
this(context, attrs, 0);
......@@ -340,8 +358,8 @@ public class Workspace extends PagedView
/**
* Used to inflate the Workspace from XML.
*
* @param context The application's context.
* @param attrs The attributes set containing the Workspace's customization values.
* @param context The application's context.
* @param attrs The attributes set containing the Workspace's customization values.
* @param defStyle Unused.
*/
public Workspace(Context context, AttributeSet attrs, int defStyle) {
......@@ -559,6 +577,7 @@ public class Workspace extends PagedView
void enableLayoutTransitions() {
setLayoutTransition(mLayoutTransition);
}
void disableLayoutTransitions() {
setLayoutTransition(null);
}
......@@ -586,6 +605,7 @@ public class Workspace extends PagedView
/**
* Initializes and binds the first page
*
* @param qsb an existing qsb to recycle or null.
*/
public void bindAndInitFirstWorkspaceScreen(View qsb) {
......@@ -712,7 +732,7 @@ public class Workspace extends PagedView
// Inflate the cell layout, but do not add it automatically so that we can get the newly
// created CellLayout.
CellLayout newScreen = (CellLayout) mLauncher.getLayoutInflater().inflate(
R.layout.workspace_screen, this, false /* attachToRoot */);
R.layout.workspace_screen, this, false /* attachToRoot */);
newScreen.setOnLongClickListener(mLongClickListener);
newScreen.setOnClickListener(mLauncher);
newScreen.setSoundEffectsEnabled(false);
......@@ -767,7 +787,7 @@ public class Workspace extends PagedView
}
public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks,
String description) {
String description) {
if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) {
throw new RuntimeException("Expected custom content screen to exist");
}
......@@ -777,10 +797,10 @@ public class Workspace extends PagedView
int spanX = customScreen.getCountX();
int spanY = customScreen.getCountY();
CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY);
lp.canReorder = false;
lp.canReorder = false;
lp.isFullscreen = true;
if (customContent instanceof Insettable) {
((Insettable)customContent).setInsets(mInsets);
((Insettable) customContent).setInsets(mInsets);
}
// Verify that the child is removed from any existing parent.
......@@ -865,7 +885,7 @@ public class Workspace extends PagedView
}
public void removeExtraEmptyScreenDelayed(final boolean animate, final Runnable onComplete,
final int delay, final boolean stripEmptyScreens) {
final int delay, final boolean stripEmptyScreens) {
if (mLauncher.isWorkspaceLoading()) {
// Don't strip empty screens if the workspace is still loading
return;
......@@ -906,7 +926,7 @@ public class Workspace extends PagedView
}
private void fadeAndRemoveEmptyScreen(int delay, int duration, final Runnable onComplete,
final boolean stripEmptyScreens) {
final boolean stripEmptyScreens) {
// XXX: Do we need to update LM workspace screens below?
PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f);
PropertyValuesHolder bgAlpha = PropertyValuesHolder.ofFloat("backgroundAlpha", 0f);
......@@ -1034,7 +1054,7 @@ public class Workspace extends PagedView
int minScreens = 1 + numCustomPages();
int pageShift = 0;
for (Long id: removeScreens) {
for (Long id : removeScreens) {
CellLayout cl = mWorkspaceScreens.get(id);
mWorkspaceScreens.remove(id);
mScreenOrder.remove(id);
......@@ -1095,15 +1115,15 @@ public class Workspace extends PagedView
* Adds the specified child in the specified screen. The position and dimension of
* the child are defined by x, y, spanX and spanY.
*
* @param child The child to add in one of the workspace's screens.
* @param child The child to add in one of the workspace's screens.
* @param screenId The screen in which to add the child.
* @param x The X position of the child in the screen's grid.
* @param y The Y position of the child in the screen's grid.
* @param spanX The number of cells spanned horizontally by the child.
* @param spanY The number of cells spanned vertically by the child.
* @param x The X position of the child in the screen's grid.
* @param y The Y position of the child in the screen's grid.
* @param spanX The number of cells spanned horizontally by the child.
* @param spanY The number of cells spanned vertically by the child.
*/
private void addInScreen(View child, long container, long screenId, int x, int y,
int spanX, int spanY) {
int spanX, int spanY) {
if (container == LauncherSettings.Favorites.CONTAINER_DESKTOP) {
if (getScreenWithId(screenId) == null) {
Log.e(TAG, "Skipping child, screenId " + screenId + " not found");
......@@ -1192,14 +1212,16 @@ public class Workspace extends PagedView
return mIsSwitchingState;
}
/** This differs from isSwitchingState in that we take into account how far the transition
* has completed. */
/**
* This differs from isSwitchingState in that we take into account how far the transition
* has completed.
*/
public boolean isFinishedSwitchingState() {
return !mIsSwitchingState
|| (mTransitionProgress > FINISHED_SWITCHING_STATE_TRANSITION_PROGRESS);
}
protected void onWindowVisibilityChanged (int visibility) {
protected void onWindowVisibilityChanged(int visibility) {
mLauncher.onWindowVisibilityChanged(visibility);
}
......@@ -1215,19 +1237,19 @@ public class Workspace extends PagedView
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mXDown = ev.getX();
mYDown = ev.getY();
mTouchDownTime = System.currentTimeMillis();
break;
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_REST) {
final CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage);
if (currentPage != null) {
onWallpaperTap(ev);
case MotionEvent.ACTION_DOWN:
mXDown = ev.getX();
mYDown = ev.getY();
mTouchDownTime = System.currentTimeMillis();
break;
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_REST) {
final CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage);
if (currentPage != null) {
onWallpaperTap(ev);
}
}
}
}
return super.onInterceptTouchEvent(ev);
}
......@@ -1500,8 +1522,9 @@ public class Workspace extends PagedView
/**
* Moves the workspace UI in the Y direction.
*
* @param translation the amount of shift.
* @param alpha the alpha for the workspace page
* @param alpha the alpha for the workspace page
*/
public void setWorkspaceYTranslationAndAlpha(float translation, float alpha) {
setWorkspaceTranslationAndAlpha(Direction.Y, translation, alpha);
......@@ -1512,9 +1535,10 @@ public class Workspace extends PagedView
/**
* Moves the workspace UI in the provided direction.
* @param direction the direction to move the workspace
*
* @param direction the direction to move the workspace
* @param translation the amount of shift.
* @param alpha the alpha for the workspace page
* @param alpha the alpha for the workspace page
*/
private void setWorkspaceTranslationAndAlpha(Direction direction, float translation, float alpha) {
Property<View, Float> property = direction.viewProperty;
......@@ -1539,9 +1563,10 @@ public class Workspace extends PagedView
/**
* Moves the Hotseat UI in the provided direction.
* @param direction the direction to move the workspace
*
* @param direction the direction to move the workspace
* @param translation the amount of shift.
* @param alpha the alpha for the hotseat page
* @param alpha the alpha for the hotseat page
*/
public void setHotseatTranslationAndAlpha(Direction direction, float translation, float alpha) {
Property<View, Float> property = direction.viewProperty;
......@@ -1843,12 +1868,15 @@ public class Workspace extends PagedView
return mState != State.NORMAL;
}
/** Returns whether a drag should be allowed to be started from the current workspace state. */
/**
* Returns whether a drag should be allowed to be started from the current workspace state.
*/
public boolean workspaceIconsCanBeDragged() {
return mState == State.NORMAL || mState == State.SPRING_LOADED;
}
@Thunk void updateChildrenLayersEnabled(boolean force) {
@Thunk
void updateChildrenLayersEnabled(boolean force) {
boolean small = mState == State.OVERVIEW || mIsSwitchingState;
boolean enableChildrenLayers = force || small || mAnimatingViewIntoPlace || isPageInTransition();
......@@ -1894,9 +1922,9 @@ public class Workspace extends PagedView
if (mForceDrawAdjacentPages) {
// In overview mode, make sure that the two side pages are visible.
leftScreen = Utilities.boundToRange(getCurrentPage() - 1,
numCustomPages(), rightScreen);
numCustomPages(), rightScreen);
rightScreen = Utilities.boundToRange(getCurrentPage() + 1,
leftScreen, getPageCount() - 1);
leftScreen, getPageCount() - 1);
}
if (leftScreen == rightScreen) {
......@@ -2047,14 +2075,14 @@ public class Workspace extends PagedView
* to that new state.
*/
public Animator setStateWithAnimation(State toState, boolean animated,
AnimationLayerSet layerViews) {
AnimationLayerSet layerViews) {
final State fromState = mState;
// Update the current state
mState = toState;
// Create the animation to the new state
AnimatorSet workspaceAnim = mStateTransitionAnimation.getAnimationToState(fromState,
AnimatorSet workspaceAnim = mStateTransitionAnimation.getAnimationToState(fromState,
toState, animated, layerViews);
......@@ -2122,7 +2150,7 @@ public class Workspace extends PagedView
} else {
int accessible = mState == State.NORMAL ?
IMPORTANT_FOR_ACCESSIBILITY_AUTO :
IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS;
page.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
page.getShortcutsAndWidgets().setImportantForAccessibility(accessible);
page.setContentDescription(null);
......@@ -2163,14 +2191,14 @@ public class Workspace extends PagedView
}
void showCustomContentIfNecessary() {
boolean show = mState == Workspace.State.NORMAL;
boolean show = mState == Workspace.State.NORMAL;
if (show && hasCustomContent()) {
mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID).setVisibility(VISIBLE);
}
}
void hideCustomContentIfNecessary() {
boolean hide = mState != Workspace.State.NORMAL;
boolean hide = mState != Workspace.State.NORMAL;
if (hide && hasCustomContent()) {
disableLayoutTransitions();
mWorkspaceScreens.get(CUSTOM_CONTENT_SCREEN_ID).setVisibility(INVISIBLE);
......@@ -2208,7 +2236,7 @@ public class Workspace extends PagedView
@Override
protected void enableAccessibleDrag(boolean enable) {
super.enableAccessibleDrag(enable);
setEnableForLayout(mLauncher.getHotseat().getLayout(),enable);
setEnableForLayout(mLauncher.getHotseat().getLayout(), enable);
// We need to allow our individual children to become click handlers in this
// case, so temporarily unset the click handlers.
......@@ -2234,7 +2262,7 @@ public class Workspace extends PagedView
public DragView beginDragShared(View child, DragSource source, ItemInfo dragObject,
DragPreviewProvider previewProvider, DragOptions dragOptions) {
DragPreviewProvider previewProvider, DragOptions dragOptions) {
child.clearFocus();
child.setPressed(false);
mOutlineProvider = previewProvider;
......@@ -2256,13 +2284,13 @@ public class Workspace extends PagedView
dragLayerY += dragRect.top;
// Note: The dragRect is used to calculate drag layer offsets, but the
// dragVisualizeOffset in addition to the dragRect (the size) to position the outline.
dragVisualizeOffset = new Point(- halfPadding, halfPadding);
dragVisualizeOffset = new Point(-halfPadding, halfPadding);
} else if (child instanceof FolderIcon) {
int previewSize = grid.folderIconSizePx;
dragVisualizeOffset = new Point(- halfPadding, halfPadding - child.getPaddingTop());
dragVisualizeOffset = new Point(-halfPadding, halfPadding - child.getPaddingTop());
dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize);
} else if (previewProvider instanceof ShortcutDragPreviewProvider) {
dragVisualizeOffset = new Point(- halfPadding, halfPadding);
dragVisualizeOffset = new Point(-halfPadding, halfPadding);
}
// Clear the pressed state if necessary
......@@ -2297,141 +2325,10 @@ public class Workspace extends PagedView
(mState == State.NORMAL || mState == State.SPRING_LOADED));
}
// /**
// * {@inheritDoc}
// */
// @Override
// public boolean acceptDrop(DragObject d) {
// // If it's an external drop (e.g. from All Apps), check if it should be accepted
// CellLayout dropTargetLayout = mDropToLayout;
// if (d.dragSource != this) {
// // Don't accept the drop if we're not over a screen at time of drop
// if (dropTargetLayout == null) {
// return false;
// }
//
// // Don't accept the drop if intent of drop is empty
// if (d.dragInfo == null || d.dragInfo.getIntent() == null) {
// return false;
// }
//
// // Don't accept the drop if intent exists
// Intent dragIntent = d.dragInfo.getIntent();
// Intent cloneIntent = dragIntent.cloneFilter();
// cloneIntent.putExtras(dragIntent);
//
// String intentUriWithPackage = cloneIntent.toUri(0);
// String intentUriOnlyComponent = null;
// if (dragIntent.getComponent() != null) {
// if (dragIntent.getPackage() == null) {
// intentUriWithPackage = cloneIntent.setPackage(dragIntent.getComponent().getPackageName()).toUri(0);
// }
// intentUriOnlyComponent = new Intent().setComponent(dragIntent.getComponent()).toUri(0);
// }
// String intentUriWithoutPackage = cloneIntent.setPackage(null).toUri(0);
// synchronized (LauncherModel.sBgDataModel) {
// List<ItemInfo> itemInfos = LauncherModel.sBgDataModel.workspaceItems;
// if (itemInfos.size() > 0) {
// for (ItemInfo info : itemInfos) {
// if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
// FolderInfo folderInfo = (FolderInfo) info;
// if (folderInfo.contents != null && folderInfo.contents.size() > 0) {
// for (ShortcutInfo shortcutInfo : folderInfo.contents) {
// if (shortcutInfo.intent != null) {
// Intent shortcutIntent = shortcutInfo.intent.cloneFilter().putExtras(shortcutInfo.intent);
//
// String intentUri = shortcutIntent.toUri(0);
// if (intentUriWithoutPackage.equals(intentUri) || intentUriWithPackage.equals(intentUri) || intentUri.equals(intentUriOnlyComponent)) {
// return false;
// }
// }
// }
// }
// } else {
// if (info.getIntent() != null) {
// Intent shortcutIntent = info.getIntent().cloneFilter().putExtras(info.getIntent());
// String intentUri = shortcutIntent.toUri(0);
// if (intentUriWithoutPackage.equals(intentUri) || intentUriWithPackage.equals(intentUri) || intentUri.equals(intentUriOnlyComponent)) {
// return false;
// }
// }
// }
// }
// }
// }
//
// if (!transitionStateShouldAllowDrop()) return false;
//
// mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
//
// // We want the point to be mapped to the dragTarget.
// if (mLauncher.isHotseatLayout(dropTargetLayout)) {
// mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter);
// } else {
// mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter);
// }
//
// int spanX;
// int spanY;
// if (mDragInfo != null) {
// final CellLayout.CellInfo dragCellInfo = mDragInfo;
// spanX = dragCellInfo.spanX;
// spanY = dragCellInfo.spanY;
// } else {
// spanX = d.dragInfo.spanX;
// spanY = d.dragInfo.spanY;
// }
//
// int minSpanX = spanX;
// int minSpanY = spanY;
// if (d.dragInfo instanceof PendingAddWidgetInfo) {
// minSpanX = ((PendingAddWidgetInfo) d.dragInfo).minSpanX;
// minSpanY = ((PendingAddWidgetInfo) d.dragInfo).minSpanY;
// }
//
// mTargetCell = findNearestArea((int) mDragViewVisualCenter[0],
// (int) mDragViewVisualCenter[1], minSpanX, minSpanY, dropTargetLayout,
// mTargetCell);
// float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0],
// mDragViewVisualCenter[1], mTargetCell);
// if (mCreateUserFolderOnDrop && willCreateUserFolder(d.dragInfo,
// dropTargetLayout, mTargetCell, distance, true)) {
// // Don't directly create folder on hotseat.
// return !mLauncher.isHotseatLayout(dropTargetLayout);
// }
//
// if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder(d.dragInfo,
// dropTargetLayout, mTargetCell, distance)) {
// return true;
// }
//
// int[] resultSpan = new int[2];
// mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0],
// (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY,
// null, mTargetCell, resultSpan, CellLayout.MODE_ACCEPT_DROP);
// boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0;
//
// // Don't accept the drop if there's no room for the item
// if (!foundCell) {
// // Don't show the message if we are dropping on the AllApps button and the hotseat
// // is full
// boolean isHotseat = mLauncher.isHotseatLayout(dropTargetLayout);
// return false;
// }
// }
//
// long screenId = getIdForScreen(dropTargetLayout);
// if (screenId == EXTRA_EMPTY_SCREEN_ID) {
// commitExtraEmptyScreen();
// }
//
// return true;
// }
/**
* {@inheritDoc}
*/
@Override
public boolean acceptDrop(DragObject d) {
// If it's an external drop (e.g. from All Apps), check if it should be accepted
CellLayout dropTargetLayout = mDropToLayout;
......@@ -2440,6 +2337,57 @@ public class Workspace extends PagedView
if (dropTargetLayout == null) {
return false;
}
// Don't accept the drop if intent of drop is empty
if (d.dragInfo == null || d.dragInfo.getIntent() == null) {
return false;
}
// Don't accept the drop if intent exists
Intent dragIntent = d.dragInfo.getIntent();
Intent cloneIntent = dragIntent.cloneFilter();
cloneIntent.putExtras(dragIntent);
String intentUriWithPackage = cloneIntent.toUri(0);
String intentUriOnlyComponent = null;
if (dragIntent.getComponent() != null) {
if (dragIntent.getPackage() == null) {
intentUriWithPackage = cloneIntent.setPackage(dragIntent.getComponent().getPackageName()).toUri(0);
}
intentUriOnlyComponent = new Intent().setComponent(dragIntent.getComponent()).toUri(0);
}
String intentUriWithoutPackage = cloneIntent.setPackage(null).toUri(0);
synchronized (LauncherModel.sBgDataModel) {
List<ItemInfo> itemInfos = LauncherModel.sBgDataModel.workspaceItems;
if (itemInfos.size() > 0) {
for (ItemInfo info : itemInfos) {
if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
FolderInfo folderInfo = (FolderInfo) info;
if (folderInfo.contents != null && folderInfo.contents.size() > 0) {
for (ShortcutInfo shortcutInfo : folderInfo.contents) {
if (shortcutInfo.intent != null) {
Intent shortcutIntent = shortcutInfo.intent.cloneFilter().putExtras(shortcutInfo.intent);
String intentUri = shortcutIntent.toUri(0);
if (intentUriWithoutPackage.equals(intentUri) || intentUriWithPackage.equals(intentUri) || intentUri.equals(intentUriOnlyComponent)) {
return false;
}
}
}
}
} else {
if (info.getIntent() != null) {
Intent shortcutIntent = info.getIntent().cloneFilter().putExtras(info.getIntent());
String intentUri = shortcutIntent.toUri(0);
if (intentUriWithoutPackage.equals(intentUri) || intentUriWithPackage.equals(intentUri) || intentUri.equals(intentUriOnlyComponent)) {
return false;
}
}
}
}
}
}
if (!transitionStateShouldAllowDrop()) return false;
mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
......@@ -2451,8 +2399,8 @@ public class Workspace extends PagedView
mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter);
}
int spanX = 1;
int spanY = 1;
int spanX;
int spanY;
if (mDragInfo != null) {
final CellLayout.CellInfo dragCellInfo = mDragInfo;
spanX = dragCellInfo.spanX;
......@@ -2476,7 +2424,8 @@ public class Workspace extends PagedView
mDragViewVisualCenter[1], mTargetCell);
if (mCreateUserFolderOnDrop && willCreateUserFolder(d.dragInfo,
dropTargetLayout, mTargetCell, distance, true)) {
return true;
// Don't directly create folder on hotseat.
return !mLauncher.isHotseatLayout(dropTargetLayout);
}
if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder(d.dragInfo,
......@@ -2492,7 +2441,9 @@ public class Workspace extends PagedView
// Don't accept the drop if there's no room for the item
if (!foundCell) {
onNoCellFound(dropTargetLayout);
// Don't show the message if we are dropping on the AllApps button and the hotseat
// is full
boolean isHotseat = mLauncher.isHotseatLayout(dropTargetLayout);
return false;
}
}
......@@ -2505,8 +2456,84 @@ public class Workspace extends PagedView
return true;
}
/**
* {@inheritDoc}
*/
// public boolean acceptDrop(DragObject d) {
// // If it's an external drop (e.g. from All Apps), check if it should be accepted
// CellLayout dropTargetLayout = mDropToLayout;
// if (d.dragSource != this) {
// // Don't accept the drop if we're not over a screen at time of drop
// if (dropTargetLayout == null) {
// return false;
// }
// if (!transitionStateShouldAllowDrop()) return false;
//
// mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
//
// // We want the point to be mapped to the dragTarget.
// if (mLauncher.isHotseatLayout(dropTargetLayout)) {
// mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter);
// } else {
// mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter);
// }
//
// int spanX = 1;
// int spanY = 1;
// if (mDragInfo != null) {
// final CellLayout.CellInfo dragCellInfo = mDragInfo;
// spanX = dragCellInfo.spanX;
// spanY = dragCellInfo.spanY;
// } else {
// spanX = d.dragInfo.spanX;
// spanY = d.dragInfo.spanY;
// }
//
// int minSpanX = spanX;
// int minSpanY = spanY;
// if (d.dragInfo instanceof PendingAddWidgetInfo) {
// minSpanX = ((PendingAddWidgetInfo) d.dragInfo).minSpanX;
// minSpanY = ((PendingAddWidgetInfo) d.dragInfo).minSpanY;
// }
//
// mTargetCell = findNearestArea((int) mDragViewVisualCenter[0],
// (int) mDragViewVisualCenter[1], minSpanX, minSpanY, dropTargetLayout,
// mTargetCell);
// float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0],
// mDragViewVisualCenter[1], mTargetCell);
// if (mCreateUserFolderOnDrop && willCreateUserFolder(d.dragInfo,
// dropTargetLayout, mTargetCell, distance, true)) {
// return true;
// }
//
// if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder(d.dragInfo,
// dropTargetLayout, mTargetCell, distance)) {
// return true;
// }
//
// int[] resultSpan = new int[2];
// mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0],
// (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY,
// null, mTargetCell, resultSpan, CellLayout.MODE_ACCEPT_DROP);
// boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0;
//
// // Don't accept the drop if there's no room for the item
// if (!foundCell) {
// onNoCellFound(dropTargetLayout);
// return false;
// }
// }
//
// long screenId = getIdForScreen(dropTargetLayout);
// if (screenId == EXTRA_EMPTY_SCREEN_ID) {
// commitExtraEmptyScreen();
// }
//
// return true;
// }
boolean willCreateUserFolder(ItemInfo info, CellLayout target, int[] targetCell,
float distance, boolean considerTimeout) {
float distance, boolean considerTimeout) {
if (distance > mMaxDistanceForFolderCreation) return false;
View dropOverView = target.getChildAt(targetCell[0], targetCell[1]);
return willCreateUserFolder(info, dropOverView, considerTimeout);
......@@ -2539,12 +2566,13 @@ public class Workspace extends PagedView
}
boolean willAddToExistingUserFolder(ItemInfo dragInfo, CellLayout target, int[] targetCell,
float distance) {
float distance) {
if (distance > mMaxDistanceForFolderCreation) return false;
View dropOverView = target.getChildAt(targetCell[0], targetCell[1]);
return willAddToExistingUserFolder(dragInfo, dropOverView);
}
boolean willAddToExistingUserFolder(ItemInfo dragInfo, View dropOverView) {
if (dropOverView != null) {
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) dropOverView.getLayoutParams();
......@@ -2563,9 +2591,9 @@ public class Workspace extends PagedView
}
boolean createUserFolderIfNecessary(View newView, long container, CellLayout target,
int[] targetCell, float distance, boolean external, DragView dragView,
Runnable postAnimationRunnable) {
if (true)return false;
int[] targetCell, float distance, boolean external, DragView dragView,
Runnable postAnimationRunnable) {
if (true) return false;
if (distance > mMaxDistanceForFolderCreation) return false;
View v = target.getChildAt(targetCell[0], targetCell[1]);
......@@ -2596,7 +2624,7 @@ public class Workspace extends PagedView
target.removeView(v);
FolderIcon fi =
mLauncher.addFolder(target, container, screenId, targetCell[0], targetCell[1]);
mLauncher.addFolder(target, container, screenId, targetCell[0], targetCell[1]);
destInfo.cellX = -1;
destInfo.cellY = -1;
sourceInfo.cellX = -1;
......@@ -2622,7 +2650,7 @@ public class Workspace extends PagedView
}
boolean addToExistingFolderIfNecessary(View newView, CellLayout target, int[] targetCell,
float distance, DragObject d, boolean external) {
float distance, DragObject d, boolean external) {
if (distance > mMaxDistanceForFolderCreation) return false;
View dropOverView = target.getChildAt(targetCell[0], targetCell[1]);
......@@ -2645,9 +2673,11 @@ public class Workspace extends PagedView
}
@Override
public void prepareAccessibilityDrop() { }
public void prepareAccessibilityDrop() {
}
public void onDrop(final DragObject d) {
Log.e("TAG1", "workspace onDrop: ");
mDragViewVisualCenter = d.getVisualCenter(mDragViewVisualCenter);
CellLayout dropTargetLayout = mDropToLayout;
......@@ -2665,8 +2695,8 @@ public class Workspace extends PagedView
int snapScreen = -1;
boolean resizeOnDrop = false;
if (d.dragSource != this) {
final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0],
(int) mDragViewVisualCenter[1] };
final int[] touchXY = new int[]{(int) mDragViewVisualCenter[0],
(int) mDragViewVisualCenter[1]};
onDropExternal(touchXY, dropTargetLayout, d);
} else if (mDragInfo != null) {
final View cell = mDragInfo.cell;
......@@ -3036,47 +3066,47 @@ public class Workspace extends PagedView
mLastReorderY = -1;
}
/*
*
* Convert the 2D coordinate xy from the parent View's coordinate space to this CellLayout's
* coordinate space. The argument xy is modified with the return result.
*/
void mapPointFromSelfToChild(View v, float[] xy) {
xy[0] = xy[0] - v.getLeft();
xy[1] = xy[1] - v.getTop();
}
boolean isPointInSelfOverHotseat(int x, int y) {
mTempXY[0] = x;
mTempXY[1] = y;
mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempXY, true);
View hotseat = mLauncher.getHotseat();
return mTempXY[0] >= hotseat.getLeft() &&
mTempXY[0] <= hotseat.getRight() &&
mTempXY[1] >= hotseat.getTop() &&
mTempXY[1] <= hotseat.getBottom();
}
void mapPointFromSelfToHotseatLayout(Hotseat hotseat, float[] xy) {
mTempXY[0] = (int) xy[0];
mTempXY[1] = (int) xy[1];
mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempXY, true);
mLauncher.getDragLayer().mapCoordInSelfToDescendant(hotseat.getLayout(), mTempXY);
xy[0] = mTempXY[0];
xy[1] = mTempXY[1];
}
/*
*
* Convert the 2D coordinate xy from this CellLayout's coordinate space to
* the parent View's coordinate space. The argument xy is modified with the return result.
*
*/
void mapPointFromChildToSelf(View v, float[] xy) {
xy[0] += v.getLeft();
xy[1] += v.getTop();
}
/*
*
* Convert the 2D coordinate xy from the parent View's coordinate space to this CellLayout's
* coordinate space. The argument xy is modified with the return result.
*/
void mapPointFromSelfToChild(View v, float[] xy) {
xy[0] = xy[0] - v.getLeft();
xy[1] = xy[1] - v.getTop();
}
boolean isPointInSelfOverHotseat(int x, int y) {
mTempXY[0] = x;
mTempXY[1] = y;
mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempXY, true);
View hotseat = mLauncher.getHotseat();
return mTempXY[0] >= hotseat.getLeft() &&
mTempXY[0] <= hotseat.getRight() &&
mTempXY[1] >= hotseat.getTop() &&
mTempXY[1] <= hotseat.getBottom();
}
void mapPointFromSelfToHotseatLayout(Hotseat hotseat, float[] xy) {
mTempXY[0] = (int) xy[0];
mTempXY[1] = (int) xy[1];
mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempXY, true);
mLauncher.getDragLayer().mapCoordInSelfToDescendant(hotseat.getLayout(), mTempXY);
xy[0] = mTempXY[0];
xy[1] = mTempXY[1];
}
/*
*
* Convert the 2D coordinate xy from this CellLayout's coordinate space to
* the parent View's coordinate space. The argument xy is modified with the return result.
*
*/
void mapPointFromChildToSelf(View v, float[] xy) {
xy[0] += v.getLeft();
xy[1] += v.getTop();
}
private boolean isDragWidget(DragObject d) {
return (d.dragInfo instanceof LauncherAppWidgetInfo ||
......@@ -3138,7 +3168,7 @@ public class Workspace extends PagedView
manageFolderFeedback(mDragTargetLayout, mTargetCell, targetCellDistance, d);
boolean nearestDropOccupied = mDragTargetLayout.isNearestDropLocationOccupied((int)
mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], item.spanX,
mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], item.spanX,
item.spanY, child, mTargetCell);
if (!nearestDropOccupied) {
......@@ -3173,7 +3203,7 @@ public class Workspace extends PagedView
/**
* Updates {@link #mDragTargetLayout} and {@link #mDragOverlappingLayout}
* based on the DragObject's position.
*
* <p>
* The layout will be:
* - The Hotseat if the drag object is over it
* - A side page if we are in spring-loaded mode and the drag object is over it
......@@ -3220,7 +3250,7 @@ public class Workspace extends PagedView
/**
* Returns the child CellLayout if the point is inside the page coordinates, null otherwise.
*/
private CellLayout verifyInsidePage(int pageNo, float[] touchXy) {
private CellLayout verifyInsidePage(int pageNo, float[] touchXy) {
if (pageNo >= numCustomPages() && pageNo < getPageCount()) {
CellLayout cl = (CellLayout) getChildAt(pageNo);
mapPointFromSelfToChild(cl, touchXy);
......@@ -3234,7 +3264,7 @@ public class Workspace extends PagedView
}
private void manageFolderFeedback(CellLayout targetLayout,
int[] targetCell, float distance, DragObject dragObject) {
int[] targetCell, float distance, DragObject dragObject) {
if (distance > mMaxDistanceForFolderCreation) return;
final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[0], mTargetCell[1]);
......@@ -3321,7 +3351,7 @@ public class Workspace extends PagedView
View child;
public ReorderAlarmListener(float[] dragViewCenter, int minSpanX, int minSpanY, int spanX,
int spanY, DragObject dragObject, View child) {
int spanY, DragObject dragObject, View child) {
this.dragViewCenter = dragViewCenter;
this.minSpanX = minSpanX;
this.minSpanY = minSpanY;
......@@ -3340,8 +3370,8 @@ public class Workspace extends PagedView
mLastReorderY = mTargetCell[1];
mTargetCell = mDragTargetLayout.performReorder((int) mDragViewVisualCenter[0],
(int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY,
child, mTargetCell, resultSpan, CellLayout.MODE_DRAG_OVER);
(int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY,
child, mTargetCell, resultSpan, CellLayout.MODE_DRAG_OVER);
if (mTargetCell[0] < 0 || mTargetCell[1] < 0) {
mDragTargetLayout.revertTempState();
......@@ -3351,7 +3381,7 @@ public class Workspace extends PagedView
boolean resize = resultSpan[0] != spanX || resultSpan[1] != spanY;
mDragTargetLayout.visualizeDropLocation(child, mOutlineProvider,
mTargetCell[0], mTargetCell[1], resultSpan[0], resultSpan[1], resize, dragObject);
mTargetCell[0], mTargetCell[1], resultSpan[0], resultSpan[1], resize, dragObject);
}
}
......@@ -3366,10 +3396,11 @@ public class Workspace extends PagedView
* Drop an item that didn't originate on one of the workspace screens.
* It may have come from Launcher (e.g. from all apps or customize), or it may have
* come from another app altogether.
*
* <p>
* NOTE: This can also be called when we are outside of a drag event, when we want
* to add an item to one of the workspace screens.
*/
private void onDropExternal(final int[] touchXY, final CellLayout cellLayout, DragObject d) {
final Runnable exitSpringLoadedRunnable = new Runnable() {
@Override
......@@ -3387,6 +3418,26 @@ public class Workspace extends PagedView
}
}
// String className = null;
// ItemInfo current = d.dragInfo;
// if(current != null){
// ComponentName cpm = current.getTargetComponent();
// if(cpm != null){
// className = cpm.getClassName();
// }
// }
//
// final LongArrayMap<ItemInfo> shortcutMapCopy =
// LauncherModel.sBgDataModel.itemsIdMap.clone();
// for (ItemInfo itemInfo : shortcutMapCopy) {
// ComponentName cpm = itemInfo.getTargetComponent();
// if(cpm != null){
// if(TextUtils.equals(className, cpm.getClassName())){
// return;
// }
// }
// }
ItemInfo info = d.dragInfo;
int spanX = info.spanX;
int spanY = info.spanY;
......@@ -3397,7 +3448,7 @@ public class Workspace extends PagedView
final long container = mLauncher.isHotseatLayout(cellLayout) ?
LauncherSettings.Favorites.CONTAINER_HOTSEAT :
LauncherSettings.Favorites.CONTAINER_DESKTOP;
LauncherSettings.Favorites.CONTAINER_DESKTOP;
final long screenId = getIdForScreen(cellLayout);
if (!mLauncher.isHotseatLayout(cellLayout)
&& screenId != getScreenIdForPageIndex(mCurrentPage)
......@@ -3416,7 +3467,7 @@ public class Workspace extends PagedView
mDragViewVisualCenter[1], mTargetCell);
if (willCreateUserFolder(d.dragInfo, cellLayout, mTargetCell, distance, true)
|| willAddToExistingUserFolder(
d.dragInfo, cellLayout, mTargetCell, distance)) {
d.dragInfo, cellLayout, mTargetCell, distance)) {
findNearestVacantCell = false;
}
}
......@@ -3479,22 +3530,22 @@ public class Workspace extends PagedView
View view = null;
switch (info.itemType) {
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
if (info.container == NO_ID && info instanceof AppInfo) {
// Came from all apps -- make a copy
info = ((AppInfo) info).makeShortcut();
d.dragInfo = info;
}
view = mLauncher.createShortcut(cellLayout, (ShortcutInfo) info);
break;
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher, cellLayout,
(FolderInfo) info);
break;
default:
throw new IllegalStateException("Unknown item type: " + info.itemType);
case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION:
case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT:
case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
if (info.container == NO_ID && info instanceof AppInfo) {
// Came from all apps -- make a copy
info = ((AppInfo) info).makeShortcut();
d.dragInfo = info;
}
view = mLauncher.createShortcut(cellLayout, (ShortcutInfo) info);
break;
case LauncherSettings.Favorites.ITEM_TYPE_FOLDER:
view = FolderIcon.fromXml(R.layout.folder_icon, mLauncher, cellLayout,
(FolderInfo) info);
break;
default:
throw new IllegalStateException("Unknown item type: " + info.itemType);
}
// First we find the cell nearest to point at which the item is
......@@ -3565,7 +3616,7 @@ public class Workspace extends PagedView
}
private void getFinalPositionForDropAnimation(int[] loc, float[] scaleXY,
DragView dragView, CellLayout layout, ItemInfo info, int[] targetCell, boolean scale) {
DragView dragView, CellLayout layout, ItemInfo info, int[] targetCell, boolean scale) {
// Now we animate the dragView, (ie. the widget or shortcut preview) into its final
// location and size on the home screen.
int spanX = info.spanX;
......@@ -3613,8 +3664,8 @@ public class Workspace extends PagedView
}
public void animateWidgetDrop(ItemInfo info, CellLayout cellLayout, final DragView dragView,
final Runnable onCompleteRunnable, int animationType, final View finalView,
boolean external) {
final Runnable onCompleteRunnable, int animationType, final View finalView,
boolean external) {
Rect from = new Rect();
mLauncher.getDragLayer().getViewRectRelativeToSelf(dragView, from);
......@@ -3634,7 +3685,7 @@ public class Workspace extends PagedView
dragView.setCrossFadeBitmap(crossFadeBitmap);
dragView.crossFade((int) (duration * 0.8f));
} else if (isWidget && external) {
scaleXY[0] = scaleXY[1] = Math.min(scaleXY[0], scaleXY[1]);
scaleXY[0] = scaleXY[1] = Math.min(scaleXY[0], scaleXY[1]);
}
DragLayer dragLayer = mLauncher.getDragLayer();
......@@ -3673,6 +3724,7 @@ public class Workspace extends PagedView
setScaleY(mStateTransitionAnimation.getFinalScale());
}
}
public void resetTransitionTransform(CellLayout layout) {
if (isSwitchingState()) {
setScaleX(mCurrentScale);
......@@ -3688,7 +3740,6 @@ public class Workspace extends PagedView
* Return the current CellInfo describing our current drag; this method exists
* so that Launcher can sync this object with the correct info when the activity is created/
* destroyed
*
*/
public CellLayout.CellInfo getDragInfo() {
return mDragInfo;
......@@ -3700,11 +3751,12 @@ public class Workspace extends PagedView
/**
* Calculate the nearest cell where the given object would be dropped.
*
* <p>
* pixelX and pixelY should be in the coordinate system of layout
*/
@Thunk int[] findNearestArea(int pixelX, int pixelY,
int spanX, int spanY, CellLayout layout, int[] recycle) {
@Thunk
int[] findNearestArea(int pixelX, int pixelY,
int spanX, int spanY, CellLayout layout, int[] recycle) {
return layout.findNearestArea(
pixelX, pixelY, spanX, spanY, recycle);
}
......@@ -3722,7 +3774,7 @@ public class Workspace extends PagedView
* Called at the end of a drag which originated on the workspace.
*/
public void onDropCompleted(final View target, final DragObject d,
final boolean isFlingToDelete, final boolean success) {
final boolean isFlingToDelete, final boolean success) {
if (mDeferDropAfterUninstall) {
final CellLayout.CellInfo dragInfo = mDragInfo;
mDeferredAction = new Runnable() {
......@@ -3749,7 +3801,8 @@ public class Workspace extends PagedView
} else if (ProviderConfig.IS_DOGFOOD_BUILD) {
throw new RuntimeException("Invalid state: cellLayout == null in "
+ "Workspace#onDropCompleted. Please file a bug. ");
};
}
;
}
if ((d.cancelled || (beingCalledAfterUninstall && !mUninstallSuccessful))
&& mDragInfo.cell != null) {
......@@ -3995,7 +4048,7 @@ public class Workspace extends PagedView
*/
public void removeItemsByMatcher(final ItemInfoMatcher matcher) {
ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
for (final CellLayout layoutParent: cellLayouts) {
for (final CellLayout layoutParent : cellLayouts) {
final ViewGroup layout = layoutParent.getShortcutsAndWidgets();
LongArrayMap<View> idToViewMap = new LongArrayMap<>();
......@@ -4050,7 +4103,7 @@ public class Workspace extends PagedView
* Map the operator over the shortcuts and widgets, return the first-non-null value.
*
* @param recurse true: iterate over folder children. false: op get the folders themselves.
* @param op the operator to map over the shortcuts
* @param op the operator to map over the shortcuts
*/
void mapOverItems(boolean recurse, ItemOperator op) {
ArrayList<ShortcutAndWidgetContainer> containers = getAllShortcutAndWidgetContainers();
......@@ -4084,7 +4137,7 @@ public class Workspace extends PagedView
}
void updateShortcuts(ArrayList<ShortcutInfo> shortcuts) {
int total = shortcuts.size();
int total = shortcuts.size();
final HashSet<ShortcutInfo> updates = new HashSet<ShortcutInfo>(total);
final HashSet<Long> folderIds = new HashSet<>();
......@@ -4254,7 +4307,7 @@ public class Workspace extends PagedView
if (child != null) {
child.requestFocus();
}
}
}
exitWidgetResizeMode();
}
......@@ -4326,7 +4379,7 @@ public class Workspace extends PagedView
private boolean mRefreshPending;
public DeferredWidgetRefresh(ArrayList<LauncherAppWidgetInfo> infos,
LauncherAppWidgetHost host) {
LauncherAppWidgetHost host) {
mInfos = infos;
mHost = host;
mHandler = new Handler();
......@@ -4367,7 +4420,8 @@ public class Workspace extends PagedView
/**
* Called when the workspace state is changing.
* @param toState final state
*
* @param toState final state
* @param targetAnim animation which will be played during the transition or null.
*/
void prepareStateChange(State toState, AnimatorSet targetAnim);
......
......@@ -27,7 +27,7 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus
class AdminSettingActivity : BaseActivity() {
class SettingAdminActivity : BaseActivity() {
private var mContext: Context? = null
private var icon: QMUICommonListItemView? = null
private var reinforce: QMUICommonListItemView? = null
......
package com.android.launcher3.function.setting
import android.app.Activity
import android.app.AlertDialog
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.GridLayout
import android.widget.LinearLayout
import android.widget.TextView
import com.android.launcher3.BaseActivity
import com.android.launcher3.R
import com.android.launcher3.mdm.DisableCompat
import com.android.launcher3.settings.Contants
import com.qmuiteam.qmui.widget.grouplist.QMUICommonListItemView
import com.qmuiteam.qmui.widget.grouplist.QMUIGroupListView
import com.secspace.lib.common.dialog.SwitcherDialog
import com.secspace.lib.common.event.ChangeWallPaperEvent
import com.secspace.lib.common.utils.PkgManager
import com.secspace.lib.common.utils.Prefs
import com.secspace.lib.common.utils.ToastUtil
import com.secspace.lib.common.utils.UninstallUtil.removeForbidden
import com.secspace.lib.common.utils.UninstallUtil.uninstallService
import com.secspace.lib.common.utils.dp2px
import kotlinx.android.synthetic.main.activity_setting.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus
class SettingPwdActivity : BaseActivity(){
private var mContext: Context? = null
......@@ -85,60 +70,4 @@ class SettingPwdActivity : BaseActivity(){
DisableCompat.disableApplication(mContext, packageName)
}
}
private fun uninstall() {
GlobalScope.launch(Dispatchers.Main) {
SwitcherDialog.getInstance(mContext).show(getString(R.string.edu_uninstall), "unInstall")
removeForbidden(mContext)
delay(1000)
uninstallService(mContext)
delay(800)
SwitcherDialog.getInstance(mContext).dismiss("unInstall")
}
}
override fun onActivityResult(
requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == REQUEST_PICK_WALLPAPER) {
if (resultCode == Activity.RESULT_OK) {
Log.e("WWWW", "AAAAA")
val selectedImage = data!!.data
EventBus.getDefault().postSticky(ChangeWallPaperEvent(selectedImage))
ToastUtil.showShort(this, "壁纸修改成功")
}
}
}
private inline fun showTipDialog(crossinline block: () -> Unit, text: String) {
val alertDialog: AlertDialog
val textView = TextView(this)
val view = LayoutInflater.from(this).inflate(R.layout.item_ll, null)
textView.text = text
val ll = view.findViewById<LinearLayout>(R.id.item_ll)
ll.addView(textView)
alertDialog = AlertDialog.Builder(this)
.setTitle(getString(R.string.tip))
.setCancelable(false)
.setView(view)
.setNegativeButton(R.string.work_cancel) { dialog, _ -> dialog.dismiss() }
.setPositiveButton(R.string.work_sure) { dialog, _ ->
run {
dialog.dismiss()
block()
}
}
.create()
if (!alertDialog.isShowing) {
alertDialog.show()
}
}
companion object {
private const val REQUEST_PICK_WALLPAPER = 10
private const val ACTION_CHANGE_WALLPAPER = "action_change_wallpaper"
//允许添加先安装应用
const val ALLOW_NEW_APP = 0
//允许本身自启
const val AUTO_START_SELF = 1
}
}
\ No newline at end of file
package com.android.launcher3.settings;
import android.content.Intent;
import android.text.TextUtils;
import com.android.launcher3.function.pwd.PwdPinSetPwdActivity;
import com.secspace.lib.common.base.BaseActivity;
import com.secspace.lib.common.function.DialogManager;
import com.secspace.lib.common.utils.IntentUtil;
......@@ -26,6 +28,12 @@ public class BlankActivity extends BaseActivity {
DialogManager.INSTANCE.showPrivacyPolicyDialog(this);
return;
}
String pwd = Prefs.getLoginPwd(this);
if (TextUtils.isEmpty(pwd)) {
Intent intent = new Intent(this, PwdPinSetPwdActivity.class);
startActivity(intent);
return;
}
IntentUtil.startEduLauncher(this);
}
......
......@@ -96,7 +96,7 @@ object ActivationHelper {
return File(FILE_PATH + context.packageName, PROBATION_FILE_NAME).exists()
}
private suspend fun isProbationFromLocal(context: Context): Boolean {
suspend fun isProbationFromLocal(context: Context): Boolean {
return withContext(Dispatchers.IO) {
val file = File(FILE_PATH + context.packageName, PROBATION_FILE_NAME)
if (!file.exists()) {
......
......@@ -11,10 +11,6 @@ import com.secspace.lib.common.R
import com.secspace.lib.common.function.ActivationHelper.ActivationListener
import com.secspace.lib.common.function.ActivationHelper.active
import com.secspace.lib.common.utils.IntentUtil
import com.secspace.lib.common.utils.Prefs
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
class BuyCodeDialog(activity: Activity) : DialogInterface.OnDismissListener, View.OnClickListener {
private var mActivity: Activity?
......@@ -64,10 +60,7 @@ class BuyCodeDialog(activity: Activity) : DialogInterface.OnDismissListener, Vie
}
}, true)
dismiss()
Prefs.setMdmInitializedWhenEnter(mContext, false)
GlobalScope.launch(Dispatchers.IO) {
SwitchOutMdm.onInit(mContext)
}
WorkManager.removeForbidden(mContext)
}
}
......
......@@ -94,6 +94,18 @@ object DialogManager{
}).show()
}
fun showActivateLoseDialog(activity: Activity?, title: String?, content: String?, listener: MessageListener) {
DialogUIUtils.showAlert(activity, title, content, "", "", "确定", "输入激活码", false, false, false, object : DialogUIListener() {
override fun onPositive() {
listener.onPositive()
}
override fun onNegative() {
listener.onNegative()
}
}).show()
}
fun showMessageDialogBySure(activity: Activity?, title: String?, content: String?, listener: MessageListener) {
DialogUIUtils.showAlert(activity, title, content, "", "", "确定", "", false, false, false, object : DialogUIListener() {
override fun onPositive() {
......
......@@ -176,7 +176,11 @@ public class PrivacyPolicyDialog implements DialogInterface.OnDismissListener, V
mActivity.finish();
} else if (v.getId() == R.id.btn_accept) {
Prefs.setPrivacyPolicyState(mActivity, true);
IntentUtil.startEduLauncher(mActivity);
try {
mActivity.startActivity(new Intent(mActivity, Class.forName("com.android.launcher3.settings.BlankActivity")));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
dismiss();
mActivity.finish();
}
......
......@@ -19,7 +19,7 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.io.File
object WorkManager{
object WorkManager {
private val TAG = "SecSpaceWorkManager"
private lateinit var mContext: Context
private val mHandler: Handler = Handler(Looper.getMainLooper(), Handler.Callback { true })
......@@ -50,7 +50,7 @@ object WorkManager{
//安装耗时,检查是否都是最新的
if (!DpmHelper.getInstance(mContext).isMiddlewareLatest) {
Log.i(TAG, "will install delay")
mHandler.postDelayed( { enter(launcher) }, 2000)
mHandler.postDelayed({ enter(launcher) }, 2000)
return
}
LoadingDialog.getInstance(launcher).show("切换中")
......@@ -63,7 +63,7 @@ object WorkManager{
Prefs.setMdmInitializedWhenEnter(mContext, true)
}
fun exit(context: Context?){
fun exit(context: Context?) {
GlobalScope.launch(Dispatchers.IO) {
context?.let { SwitchOutMdm.onExit(it) }
}
......@@ -140,18 +140,43 @@ object WorkManager{
install(path)
}
fun removeForbidden(context: Context){
Prefs.setMdmInitializedWhenEnter(context, false)
GlobalScope.launch(Dispatchers.IO) {
SwitchOutMdm.onInit(context)
UninstallUtil.removeForbidden(context)
}
}
internal class EduCheckActiveStatusListener(var activity: Activity) : CheckActiveStatusListener {
override fun needActivate() {
Log.i(TAG, "activedFailed: ")
DialogManager.showMessageDialogBySure(activity, activity.getString(R.string.common_remind), activity.getString(R.string.dialog_tip_activate_lose), object: DialogManager.MessageListener{
override fun onPositive() {
IntentUtil.startExitService(activity)
GlobalScope.launch(Dispatchers.Main) {
val isActivateLocal = ActivationHelper.isProbationFromLocal(activity)
if (isActivateLocal) {
return@launch
}
override fun onNegative() {
}
})
DialogManager.showActivateLoseDialog(activity, activity.getString(R.string.common_remind), activity.getString(R.string.dialog_tip_activate_lose), object : DialogManager.MessageListener {
override fun onPositive() {
IntentUtil.startExitService(activity)
removeForbidden(activity)
}
override fun onNegative() {
ActivationHelper.active(activity, object : ActivationHelper.ActivationListener {
override fun activated() {
IntentUtil.startEduLauncher(activity)
}
override fun activationFailed() {
IntentUtil.startExitService(activity)
removeForbidden(activity)
}
}, true)
removeForbidden(activity)
}
})
}
}
override fun trialCodeWillPastDue() {
......
......@@ -92,15 +92,16 @@
android:orientation="horizontal">
<Button
android:id="@+id/btn_1"
android:id="@+id/btn_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/dialogui_selector_left_bottom"
android:background="@drawable/dialogui_selector_all_no"
android:gravity="center"
android:minHeight="48dp"
android:padding="5dp"
android:text="1"
android:text="2"
android:textColor="@color/ios_btntext_blue"
android:textSize="@dimen/dialogui_btn_txt_size"/>
......@@ -111,19 +112,20 @@
android:background="@color/line_dd"/>
<Button
android:id="@+id/btn_2"
android:id="@+id/btn_1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:background="@drawable/dialogui_selector_all_no"
android:background="@drawable/dialogui_selector_left_bottom"
android:gravity="center"
android:minHeight="48dp"
android:padding="5dp"
android:text="2"
android:text="1"
android:textColor="@color/ios_btntext_blue"
android:textSize="@dimen/dialogui_btn_txt_size"/>
<View
android:id="@+id/line_btn3"
android:layout_width="1px"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment