change package name to uiuios
This commit is contained in:
148
src/com/android/uiuios/states/InternalStateHandler.java
Normal file
148
src/com/android/uiuios/states/InternalStateHandler.java
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.uiuios.states;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Binder;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
|
||||
import com.android.uiuios.Launcher;
|
||||
import com.android.uiuios.LauncherAppState;
|
||||
import com.android.uiuios.LauncherModel.Callbacks;
|
||||
import com.android.uiuios.MainThreadExecutor;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
||||
/**
|
||||
* Utility class to sending state handling logic to Launcher from within the same process.
|
||||
*
|
||||
* Extending {@link Binder} ensures that the platform maintains a single instance of each object
|
||||
* which allows this object to safely navigate the system process.
|
||||
*/
|
||||
public abstract class InternalStateHandler extends Binder {
|
||||
|
||||
public static final String EXTRA_STATE_HANDLER = "launcher.state_handler";
|
||||
|
||||
private static final Scheduler sScheduler = new Scheduler();
|
||||
|
||||
/**
|
||||
* Initializes the handler when the launcher is ready.
|
||||
* @return true if the handler wants to stay alive.
|
||||
*/
|
||||
protected abstract boolean init(Launcher launcher, boolean alreadyOnHome);
|
||||
|
||||
public final Intent addToIntent(Intent intent) {
|
||||
Bundle extras = new Bundle();
|
||||
extras.putBinder(EXTRA_STATE_HANDLER, this);
|
||||
intent.putExtras(extras);
|
||||
return intent;
|
||||
}
|
||||
|
||||
public final void initWhenReady() {
|
||||
sScheduler.schedule(this);
|
||||
}
|
||||
|
||||
public boolean clearReference() {
|
||||
return sScheduler.clearReference(this);
|
||||
}
|
||||
|
||||
public static boolean hasPending() {
|
||||
return sScheduler.hasPending();
|
||||
}
|
||||
|
||||
public static boolean handleCreate(Launcher launcher, Intent intent) {
|
||||
return handleIntent(launcher, intent, false, false);
|
||||
}
|
||||
|
||||
public static boolean handleNewIntent(Launcher launcher, Intent intent, boolean alreadyOnHome) {
|
||||
return handleIntent(launcher, intent, alreadyOnHome, true);
|
||||
}
|
||||
|
||||
private static boolean handleIntent(
|
||||
Launcher launcher, Intent intent, boolean alreadyOnHome, boolean explicitIntent) {
|
||||
boolean result = false;
|
||||
if (intent != null && intent.getExtras() != null) {
|
||||
IBinder stateBinder = intent.getExtras().getBinder(EXTRA_STATE_HANDLER);
|
||||
if (stateBinder instanceof InternalStateHandler) {
|
||||
InternalStateHandler handler = (InternalStateHandler) stateBinder;
|
||||
if (!handler.init(launcher, alreadyOnHome)) {
|
||||
intent.getExtras().remove(EXTRA_STATE_HANDLER);
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
if (!result && !explicitIntent) {
|
||||
result = sScheduler.initIfPending(launcher, alreadyOnHome);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static class Scheduler implements Runnable {
|
||||
|
||||
private WeakReference<InternalStateHandler> mPendingHandler = new WeakReference<>(null);
|
||||
private MainThreadExecutor mMainThreadExecutor;
|
||||
|
||||
public void schedule(InternalStateHandler handler) {
|
||||
synchronized (this) {
|
||||
mPendingHandler = new WeakReference<>(handler);
|
||||
if (mMainThreadExecutor == null) {
|
||||
mMainThreadExecutor = new MainThreadExecutor();
|
||||
}
|
||||
}
|
||||
mMainThreadExecutor.execute(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
LauncherAppState app = LauncherAppState.getInstanceNoCreate();
|
||||
if (app == null) {
|
||||
return;
|
||||
}
|
||||
Callbacks cb = app.getModel().getCallback();
|
||||
if (!(cb instanceof Launcher)) {
|
||||
return;
|
||||
}
|
||||
Launcher launcher = (Launcher) cb;
|
||||
initIfPending(launcher, launcher.isStarted());
|
||||
}
|
||||
|
||||
public boolean initIfPending(Launcher launcher, boolean alreadyOnHome) {
|
||||
InternalStateHandler pendingHandler = mPendingHandler.get();
|
||||
if (pendingHandler != null) {
|
||||
if (!pendingHandler.init(launcher, alreadyOnHome)) {
|
||||
clearReference(pendingHandler);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean clearReference(InternalStateHandler handler) {
|
||||
synchronized (this) {
|
||||
if (mPendingHandler.get() == handler) {
|
||||
mPendingHandler.clear();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasPending() {
|
||||
return mPendingHandler.get() != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
213
src/com/android/uiuios/states/RotationHelper.java
Normal file
213
src/com/android/uiuios/states/RotationHelper.java
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.uiuios.states;
|
||||
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LOCKED;
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
|
||||
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
import static android.util.DisplayMetrics.DENSITY_DEVICE_STABLE;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.content.res.Resources;
|
||||
import android.view.WindowManager;
|
||||
import android.view.WindowManager.LayoutParams;
|
||||
|
||||
import com.android.uiuios.Launcher;
|
||||
import com.android.uiuios.R;
|
||||
import com.android.uiuios.Utilities;
|
||||
import com.android.uiuios.config.FeatureFlags;
|
||||
import com.android.uiuios.util.UiThreadHelper;
|
||||
|
||||
/**
|
||||
* Utility class to manage launcher rotation
|
||||
*/
|
||||
public class RotationHelper implements OnSharedPreferenceChangeListener {
|
||||
|
||||
public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
|
||||
|
||||
public static boolean getAllowRotationDefaultValue() {
|
||||
// If the device was scaled, used the original dimensions to determine if rotation
|
||||
// is allowed of not.
|
||||
Resources res = Resources.getSystem();
|
||||
int originalSmallestWidth = res.getConfiguration().smallestScreenWidthDp
|
||||
* res.getDisplayMetrics().densityDpi / DENSITY_DEVICE_STABLE;
|
||||
return originalSmallestWidth >= 600;
|
||||
}
|
||||
|
||||
public static final int REQUEST_NONE = 0;
|
||||
public static final int REQUEST_ROTATE = 1;
|
||||
public static final int REQUEST_LOCK = 2;
|
||||
|
||||
private final Launcher mLauncher;
|
||||
private final SharedPreferences mPrefs;
|
||||
|
||||
private boolean mIgnoreAutoRotateSettings;
|
||||
private boolean mAutoRotateEnabled;
|
||||
|
||||
/**
|
||||
* Rotation request made by {@link InternalStateHandler}. This supersedes any other request.
|
||||
*/
|
||||
private int mStateHandlerRequest = REQUEST_NONE;
|
||||
/**
|
||||
* Rotation request made by an app transition
|
||||
*/
|
||||
private int mCurrentTransitionRequest = REQUEST_NONE;
|
||||
/**
|
||||
* Rotation request made by a Launcher State
|
||||
*/
|
||||
private int mCurrentStateRequest = REQUEST_NONE;
|
||||
|
||||
// This is used to defer setting rotation flags until the activity is being created
|
||||
private boolean mInitialized;
|
||||
private boolean mDestroyed;
|
||||
private boolean mRotationHasDifferentUI;
|
||||
|
||||
private int mLastActivityFlags = -1;
|
||||
|
||||
public RotationHelper(Launcher launcher) {
|
||||
mLauncher = launcher;
|
||||
|
||||
// On large devices we do not handle auto-rotate differently.
|
||||
mIgnoreAutoRotateSettings = mLauncher.getResources().getBoolean(R.bool.allow_rotation);
|
||||
if (!mIgnoreAutoRotateSettings) {
|
||||
mPrefs = Utilities.getPrefs(mLauncher);
|
||||
mPrefs.registerOnSharedPreferenceChangeListener(this);
|
||||
mAutoRotateEnabled = mPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
|
||||
getAllowRotationDefaultValue());
|
||||
} else {
|
||||
mPrefs = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void setRotationHadDifferentUI(boolean rotationHasDifferentUI) {
|
||||
mRotationHasDifferentUI = rotationHasDifferentUI;
|
||||
}
|
||||
|
||||
public boolean homeScreenCanRotate() {
|
||||
return mRotationHasDifferentUI || mIgnoreAutoRotateSettings || mAutoRotateEnabled
|
||||
|| mStateHandlerRequest != REQUEST_NONE
|
||||
|| mLauncher.getDeviceProfile().isMultiWindowMode;
|
||||
}
|
||||
|
||||
public void updateRotationAnimation() {
|
||||
if (FeatureFlags.FAKE_LANDSCAPE_UI.get()) {
|
||||
WindowManager.LayoutParams lp = mLauncher.getWindow().getAttributes();
|
||||
int oldAnim = lp.rotationAnimation;
|
||||
lp.rotationAnimation = homeScreenCanRotate()
|
||||
? WindowManager.LayoutParams.ROTATION_ANIMATION_ROTATE
|
||||
: WindowManager.LayoutParams.ROTATION_ANIMATION_SEAMLESS;
|
||||
if (oldAnim != lp.rotationAnimation) {
|
||||
mLauncher.getWindow().setAttributes(lp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
|
||||
boolean wasRotationEnabled = mAutoRotateEnabled;
|
||||
mAutoRotateEnabled = mPrefs.getBoolean(ALLOW_ROTATION_PREFERENCE_KEY,
|
||||
getAllowRotationDefaultValue());
|
||||
if (mAutoRotateEnabled != wasRotationEnabled) {
|
||||
|
||||
notifyChange();
|
||||
updateRotationAnimation();
|
||||
mLauncher.reapplyUi();
|
||||
}
|
||||
}
|
||||
|
||||
public void setStateHandlerRequest(int request) {
|
||||
if (mStateHandlerRequest != request) {
|
||||
mStateHandlerRequest = request;
|
||||
updateRotationAnimation();
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentTransitionRequest(int request) {
|
||||
if (mCurrentTransitionRequest != request) {
|
||||
mCurrentTransitionRequest = request;
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentStateRequest(int request) {
|
||||
if (mCurrentStateRequest != request) {
|
||||
mCurrentStateRequest = request;
|
||||
notifyChange();
|
||||
}
|
||||
}
|
||||
|
||||
// Used by tests only.
|
||||
public void forceAllowRotationForTesting(boolean allowRotation) {
|
||||
mIgnoreAutoRotateSettings =
|
||||
allowRotation || mLauncher.getResources().getBoolean(R.bool.allow_rotation);
|
||||
notifyChange();
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
if (!mInitialized) {
|
||||
mInitialized = true;
|
||||
notifyChange();
|
||||
updateRotationAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
if (!mDestroyed) {
|
||||
mDestroyed = true;
|
||||
if (mPrefs != null) {
|
||||
mPrefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyChange() {
|
||||
if (!mInitialized || mDestroyed) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int activityFlags;
|
||||
if (mStateHandlerRequest != REQUEST_NONE) {
|
||||
activityFlags = mStateHandlerRequest == REQUEST_LOCK ?
|
||||
SCREEN_ORIENTATION_LOCKED : SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
} else if (mCurrentTransitionRequest != REQUEST_NONE) {
|
||||
activityFlags = mCurrentTransitionRequest == REQUEST_LOCK ?
|
||||
SCREEN_ORIENTATION_LOCKED : SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
} else if (mCurrentStateRequest == REQUEST_LOCK) {
|
||||
activityFlags = SCREEN_ORIENTATION_LOCKED;
|
||||
} else if (mIgnoreAutoRotateSettings || mCurrentStateRequest == REQUEST_ROTATE
|
||||
|| mAutoRotateEnabled) {
|
||||
activityFlags = SCREEN_ORIENTATION_UNSPECIFIED;
|
||||
} else {
|
||||
// If auto rotation is off, allow rotation on the activity, in case the user is using
|
||||
// forced rotation.
|
||||
activityFlags = SCREEN_ORIENTATION_NOSENSOR;
|
||||
}
|
||||
if (activityFlags != mLastActivityFlags) {
|
||||
mLastActivityFlags = activityFlags;
|
||||
UiThreadHelper.setOrientationAsync(mLauncher, activityFlags);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[mStateHandlerRequest=%d, mCurrentStateRequest=%d,"
|
||||
+ " mLastActivityFlags=%d, mIgnoreAutoRotateSettings=%b, mAutoRotateEnabled=%b]",
|
||||
mStateHandlerRequest, mCurrentStateRequest, mLastActivityFlags,
|
||||
mIgnoreAutoRotateSettings, mAutoRotateEnabled);
|
||||
}
|
||||
}
|
||||
105
src/com/android/uiuios/states/SpringLoadedState.java
Normal file
105
src/com/android/uiuios/states/SpringLoadedState.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.uiuios.states;
|
||||
|
||||
import static com.android.uiuios.LauncherAnimUtils.SPRING_LOADED_TRANSITION_MS;
|
||||
import static com.android.uiuios.states.RotationHelper.REQUEST_LOCK;
|
||||
|
||||
import android.graphics.Rect;
|
||||
|
||||
import com.android.uiuios.DeviceProfile;
|
||||
import com.android.uiuios.InstallShortcutReceiver;
|
||||
import com.android.uiuios.Launcher;
|
||||
import com.android.uiuios.LauncherState;
|
||||
import com.android.uiuios.Workspace;
|
||||
import com.android.uiuios.userevent.nano.LauncherLogProto.ContainerType;
|
||||
|
||||
/**
|
||||
* Definition for spring loaded state used during drag and drop.
|
||||
*/
|
||||
public class SpringLoadedState extends LauncherState {
|
||||
|
||||
private static final int STATE_FLAGS = FLAG_MULTI_PAGE |
|
||||
FLAG_DISABLE_ACCESSIBILITY | FLAG_DISABLE_RESTORE | FLAG_WORKSPACE_ICONS_CAN_BE_DRAGGED |
|
||||
FLAG_DISABLE_PAGE_CLIPPING | FLAG_PAGE_BACKGROUNDS | FLAG_HIDE_BACK_BUTTON;
|
||||
|
||||
public SpringLoadedState(int id) {
|
||||
super(id, ContainerType.OVERVIEW, SPRING_LOADED_TRANSITION_MS, STATE_FLAGS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScaleAndTranslation getWorkspaceScaleAndTranslation(Launcher launcher) {
|
||||
DeviceProfile grid = launcher.getDeviceProfile();
|
||||
Workspace ws = launcher.getWorkspace();
|
||||
if (ws.getChildCount() == 0) {
|
||||
return super.getWorkspaceScaleAndTranslation(launcher);
|
||||
}
|
||||
|
||||
if (grid.isVerticalBarLayout()) {
|
||||
float scale = grid.workspaceSpringLoadShrinkFactor;
|
||||
return new ScaleAndTranslation(scale, 0, 0);
|
||||
}
|
||||
|
||||
float scale = grid.workspaceSpringLoadShrinkFactor;
|
||||
Rect insets = launcher.getDragLayer().getInsets();
|
||||
|
||||
float scaledHeight = scale * ws.getNormalChildHeight();
|
||||
float shrunkTop = insets.top + grid.dropTargetBarSizePx;
|
||||
float shrunkBottom = ws.getMeasuredHeight() - insets.bottom
|
||||
- grid.workspacePadding.bottom
|
||||
- grid.workspaceSpringLoadedBottomSpace;
|
||||
float totalShrunkSpace = shrunkBottom - shrunkTop;
|
||||
|
||||
float desiredCellTop = shrunkTop + (totalShrunkSpace - scaledHeight) / 2;
|
||||
|
||||
float halfHeight = ws.getHeight() / 2;
|
||||
float myCenter = ws.getTop() + halfHeight;
|
||||
float cellTopFromCenter = halfHeight - ws.getChildAt(0).getTop();
|
||||
float actualCellTop = myCenter - cellTopFromCenter * scale;
|
||||
return new ScaleAndTranslation(scale, 0, (desiredCellTop - actualCellTop) / scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScaleAndTranslation getHotseatScaleAndTranslation(Launcher launcher) {
|
||||
return new ScaleAndTranslation(1, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateEnabled(Launcher launcher) {
|
||||
Workspace ws = launcher.getWorkspace();
|
||||
ws.showPageIndicatorAtCurrentScroll();
|
||||
ws.getPageIndicator().setShouldAutoHide(false);
|
||||
|
||||
// Prevent any Un/InstallShortcutReceivers from updating the db while we are
|
||||
// in spring loaded mode
|
||||
InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_DRAG_AND_DROP);
|
||||
launcher.getRotationHelper().setCurrentStateRequest(REQUEST_LOCK);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWorkspaceScrimAlpha(Launcher launcher) {
|
||||
return 0.3f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStateDisabled(final Launcher launcher) {
|
||||
launcher.getWorkspace().getPageIndicator().setShouldAutoHide(true);
|
||||
|
||||
// Re-enable any Un/InstallShortcutReceiver and now process any queued items
|
||||
InstallShortcutReceiver.disableAndFlushInstallQueue(
|
||||
InstallShortcutReceiver.FLAG_DRAG_AND_DROP, launcher);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user