Allow desktop bookmarks to use page coordinates, and make that the default for newly created bookmarks.

This commit is contained in:
Pierrot 2019-03-04 09:44:38 +01:00
parent 49f08d35e8
commit 8acdf1d746
11 changed files with 121 additions and 44 deletions

View file

@ -863,7 +863,7 @@ public class Dashboard extends ResourceWrapperActivity implements OnLongClickLis
mScreen.runAction(mEngine, "SHORTCUT", eventAction);
handled = true;
} else {
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_PAGE)) {
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_DESKTOP)) {
mScreen.executeGoToDesktopPositionIntent(intent);
handled = true;
}
@ -945,7 +945,7 @@ public class Dashboard extends ResourceWrapperActivity implements OnLongClickLis
case REQUEST_SELECT_SHORTCUT_FOR_ADD1:
ComponentName cn = data.getComponent();
if(cn != null && cn.getClassName().endsWith(".activities.ShortcutsS")) {
Intent shortcut = PhoneUtils.createDesktopBookmarkShortcut(this, il, null, null, null);
Intent shortcut = PhoneUtils.createDesktopBookmarkShortcut(this, il, null, null, null, true);
newItem=Utils.addAndroidShortcutFromIntent(this, shortcut, page, mScreen.getLastTouchedAddX(), mScreen.getLastTouchedAddY(), scale);
mUndoStack.storePageAddItem(newItem);
} else {
@ -3282,7 +3282,7 @@ public class Dashboard extends ResourceWrapperActivity implements OnLongClickLis
private void addBookmark() {
ItemLayout il = mScreen.getTargetOrTopmostItemLayout();
Page page = il.getPage();
Intent intent = PhoneUtils.createDesktopBookmarkShortcut(this, il, null, null, null);
Intent intent = PhoneUtils.createDesktopBookmarkShortcut(this, il, null, null, null, true);
Item item = Utils.addAndroidShortcutFromIntent(this, intent, page, mScreen.getLastTouchedAddX(), mScreen.getLastTouchedAddY(), il.getCurrentScale());
mUndoStack.storePageAddItem(item);
boolean wasInEditMode = il.getEditMode();

View file

@ -419,7 +419,7 @@ public class ScreenManager extends ResourceWrapperActivity implements OnClickLis
int p = (Integer)v.getTag();
Screen screen = mScreens.get(getScreenIndex(p));
Page page = mLightningEngine.getOrLoadPage(p);
Intent shortcut = PhoneUtils.createDesktopBookmarkShortcut(this, null, page, screen.label, screen.icon);
Intent shortcut = PhoneUtils.createDesktopBookmarkShortcut(this, null, page, screen.label, screen.icon, true);
setResult(RESULT_OK, shortcut);
finish();
} else if(mMode==SCREEN_MODE_SELECT_MULTIPLE) {
@ -637,7 +637,7 @@ public class ScreenManager extends ResourceWrapperActivity implements OnClickLis
Intent intent = s.getIntent();
ComponentName cn=intent.getComponent();
if(cn!=null && cn.compareTo(ll_component_name)==0) {
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_PAGE) && intent.getIntExtra(LightningIntent.INTENT_EXTRA_PAGE, 0)==screen.page) {
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_DESKTOP) && intent.getIntExtra(LightningIntent.INTENT_EXTRA_DESKTOP, 0)==screen.page) {
// it looks like a screen&position shortcut
if(update_icon) {
icon_dir.mkdirs();

View file

@ -299,17 +299,17 @@ public class LightningLWPService extends WallpaperService {
}
@Override
public void goToDesktopPosition(int page, float x, float y, float s, boolean animate) {
public void goToDesktopPosition(int page, float x, float y, float s, boolean animate, boolean absolute) {
if(Page.isDashboard(page) && page != getCurrentRootPage().id) {
LightningEngine engine = mMainPage.getEngine();
engine.getGlobalConfig().lwpScreen = page;
engine.notifyGlobalConfigChanged();
ItemLayout il = loadRootItemLayout(page, false, true, animate);
goToItemLayoutPosition(il, x, y, s, animate);
goToItemLayoutPosition(il, x, y, s, animate, absolute);
} else {
ItemLayout[] itemLayouts = getItemLayoutsForPage(page);
for (ItemLayout il : itemLayouts) {
goToItemLayoutPosition(il, x, y, s, animate);
goToItemLayoutPosition(il, x, y, s, animate, absolute);
}
}
}

View file

@ -27,7 +27,7 @@ import net.pierrox.lightning_launcher.views.ItemLayout;
import net.pierrox.lightning_launcher_extreme.R;
public class PhoneUtils {
public static Intent createDesktopBookmarkShortcut(Context context, ItemLayout il, Page page, String label, Bitmap icon) {
public static Intent createDesktopBookmarkShortcut(Context context, ItemLayout il, Page page, String label, Bitmap icon, boolean animate) {
Matrix transform = null;
// arguments: either page is null (use il.getPage) or il is null (try to retrieve il from dashboard using page)
@ -44,27 +44,30 @@ public class PhoneUtils {
transform = il.getLocalTransform();
}
Intent intent = new Intent(context, Dashboard.class);
float[] matrix_values = new float[9];
if(transform == null) {
transform = new Matrix();
}
transform.getValues(matrix_values);
intent.putExtra(LightningIntent.INTENT_EXTRA_PAGE, page.id);
float x = matrix_values[Matrix.MTRANS_X];
float y = matrix_values[Matrix.MTRANS_Y];
float s = matrix_values[Matrix.MSCALE_X];
boolean absolute;
if(il != null) {
RectF r = il.getVirtualEditBordersBounds();
if(r != null) {
x -= r.left;
y -= r.top;
}
x /= il.getWidth();
y /= il.getHeight();
absolute = false;
} else {
absolute = true;
}
intent.putExtra(LightningIntent.INTENT_EXTRA_TX, x);
intent.putExtra(LightningIntent.INTENT_EXTRA_TY, y);
intent.putExtra(LightningIntent.INTENT_EXTRA_TS, s);
Intent intent = getDesktopBookmarkIntent(context, page.id, x, y, s, animate, absolute);
Intent shortcut = new Intent();
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, label==null? context.getString(net.pierrox.lightning_launcher.R.string.shortcut_screen) : label);
@ -78,6 +81,19 @@ public class PhoneUtils {
return shortcut;
}
public static Intent getDesktopBookmarkIntent(Context context, int page, float x, float y, float scale, boolean animate, boolean absolute) {
Intent intent = new Intent(context, Dashboard.class);
intent.putExtra(LightningIntent.INTENT_EXTRA_DESKTOP, page);
intent.putExtra(LightningIntent.INTENT_EXTRA_X, x);
intent.putExtra(LightningIntent.INTENT_EXTRA_Y, y);
intent.putExtra(LightningIntent.INTENT_EXTRA_SCALE, scale);
intent.putExtra(LightningIntent.INTENT_EXTRA_ANIMATE, animate);
intent.putExtra(LightningIntent.INTENT_EXTRA_ABSOLUTE, absolute);
return intent;
}
public static void showPreferenceHelp(Context context, LLPreference preference) {
int id;
if(preference == null) {

View file

@ -11,6 +11,7 @@ import net.pierrox.lightning_launcher.engine.variable.Variable;
import net.pierrox.lightning_launcher.script.Script;
import java.net.URISyntaxException;
import java.text.DecimalFormat;
public class EventAction {
public int action;
@ -84,9 +85,19 @@ public class EventAction {
case GlobalConfig.GO_DESKTOP_POSITION:
try {
Intent intent = Intent.parseUri(data, 0);
int p = intent.getIntExtra(LightningIntent.INTENT_EXTRA_PAGE, Page.FIRST_DASHBOARD_PAGE);
int p = intent.getIntExtra(LightningIntent.INTENT_EXTRA_DESKTOP, Page.FIRST_DASHBOARD_PAGE);
Page page = engine.getOrLoadPage(p);
return Utils.formatPageName(page, page.findFirstOpener());
String description = Utils.formatPageName(page, page.findFirstOpener());
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_X)) {
float x = intent.getFloatExtra(LightningIntent.INTENT_EXTRA_X, 0);
float y = intent.getFloatExtra(LightningIntent.INTENT_EXTRA_Y, 0);
float s = intent.getFloatExtra(LightningIntent.INTENT_EXTRA_SCALE, 1);
boolean absolute = intent.getBooleanExtra(LightningIntent.INTENT_EXTRA_ABSOLUTE, true);
DecimalFormat df = new DecimalFormat("0.##");
description += absolute ? " @" : " +";
description += df.format(x)+"x"+df.format(y)+"/"+df.format(s);
}
return description;
} catch (URISyntaxException e) {
// pass
}

View file

@ -5,9 +5,11 @@ public class LightningIntent {
public static final String INTENT_EXTRA_DATA = "d";
public static final String INTENT_EXTRA_EVENT_ACTION = "ea";
public static final String INTENT_EXTRA_TARGET = "t";
public static final String INTENT_EXTRA_PAGE = "p";
public static final String INTENT_EXTRA_TX = "x";
public static final String INTENT_EXTRA_TY = "y";
public static final String INTENT_EXTRA_TS = "s";
public static final String INTENT_EXTRA_DESKTOP = "p";
public static final String INTENT_EXTRA_X = "x";
public static final String INTENT_EXTRA_Y = "y";
public static final String INTENT_EXTRA_SCALE = "s";
public static final String INTENT_EXTRA_LOAD_SCRIPT_FROM_PACKAGE = "b";
public static final String INTENT_EXTRA_ANIMATE = "n";
public static final String INTENT_EXTRA_ABSOLUTE = "l";
}

View file

@ -400,9 +400,9 @@ public class PageProcessor {
cn = intent.getComponent();
if(cn.getPackageName().equals(pkg_name_to)) {
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_PAGE) && translated_page_ids != null) {
int old_bookmark_page = intent.getIntExtra(LightningIntent.INTENT_EXTRA_PAGE, Page.NONE);
intent.putExtra(LightningIntent.INTENT_EXTRA_PAGE, translated_page_ids.get(old_bookmark_page));
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_DESKTOP) && translated_page_ids != null) {
int old_bookmark_page = intent.getIntExtra(LightningIntent.INTENT_EXTRA_DESKTOP, Page.NONE);
intent.putExtra(LightningIntent.INTENT_EXTRA_DESKTOP, translated_page_ids.get(old_bookmark_page));
modified = true;
} else {
EventAction ea = Utils.decodeEventActionFromLightningIntent(intent);
@ -417,10 +417,13 @@ public class PageProcessor {
}
if(do_scale) {
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_TX)) {
intent.putExtra(LightningIntent.INTENT_EXTRA_TX, intent.getFloatExtra(LightningIntent.INTENT_EXTRA_TX, 0) * sx);
intent.putExtra(LightningIntent.INTENT_EXTRA_TY, intent.getFloatExtra(LightningIntent.INTENT_EXTRA_TY, 0) * sy);
modified = true;
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_X)) {
boolean absolute = intent.getBooleanExtra(LightningIntent.INTENT_EXTRA_ABSOLUTE, true);
if(absolute) {
intent.putExtra(LightningIntent.INTENT_EXTRA_X, intent.getFloatExtra(LightningIntent.INTENT_EXTRA_X, 0) * sx);
intent.putExtra(LightningIntent.INTENT_EXTRA_Y, intent.getFloatExtra(LightningIntent.INTENT_EXTRA_Y, 0) * sy);
modified = true;
}
}
}
}

View file

@ -1118,39 +1118,46 @@ public abstract class Screen implements ItemLayout.ItemLayoutListener, ItemView.
public void executeGoToDesktopPositionIntent(Intent intent) {
int page = intent.getIntExtra(LightningIntent.INTENT_EXTRA_PAGE, Page.FIRST_DASHBOARD_PAGE);
int page = intent.getIntExtra(LightningIntent.INTENT_EXTRA_DESKTOP, Page.FIRST_DASHBOARD_PAGE);
if(Page.isDashboard(page) && page != getCurrentRootPage().id) {
loadRootItemLayout(page, false, true, true);
}
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_TX)) {
float x = intent.getFloatExtra(LightningIntent.INTENT_EXTRA_TX, 0);
float y = intent.getFloatExtra(LightningIntent.INTENT_EXTRA_TY, 0);
float s = intent.getFloatExtra(LightningIntent.INTENT_EXTRA_TS, 1);
goToDesktopPosition(page, x, y, s, true);
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_X)) {
float x = intent.getFloatExtra(LightningIntent.INTENT_EXTRA_X, 0);
float y = intent.getFloatExtra(LightningIntent.INTENT_EXTRA_Y, 0);
float s = intent.getFloatExtra(LightningIntent.INTENT_EXTRA_SCALE, 1);
boolean absolute = intent.getBooleanExtra(LightningIntent.INTENT_EXTRA_ABSOLUTE, true);
boolean animate = intent.getBooleanExtra(LightningIntent.INTENT_EXTRA_ANIMATE, true);
goToDesktopPosition(page, x, y, s, animate, absolute);
}
}
public void goToDesktopPosition(int page, float x, float y, float s, boolean animate) {
public void goToDesktopPosition(int page, float x, float y, float s, boolean animate, boolean absolute) {
if(Page.isDashboard(page) && page != getCurrentRootPage().id) {
ItemLayout il = loadRootItemLayout(page, false, true, animate);
goToItemLayoutPosition(il, x, y, s, animate);
goToItemLayoutPosition(il, x, y, s, animate, absolute);
} else {
ItemLayout[] itemLayouts = getItemLayoutsForPage(page);
for (ItemLayout il : itemLayouts) {
goToItemLayoutPosition(il, x, y, s, animate);
goToItemLayoutPosition(il, x, y, s, animate, absolute);
}
}
}
public void goToItemLayoutPosition(ItemLayout il, float x, float y, float s, boolean animate) {
public void goToItemLayoutPosition(ItemLayout il, float x, float y, float s, boolean animate, boolean absolute) {
Page page = il.getPage();
if(page.isDashboard() && page != getCurrentRootPage()) {
loadRootItemLayout(page.id, false, true, true);
}
if(animate) {
il.animateZoomTo(x, y, s);
if(absolute) {
if (animate) {
il.animateZoomTo(x, y, s);
} else {
il.moveTo(x, y, s);
}
} else {
il.moveTo(x, y, s);
il.goToPage(x, y, s, animate);
}
}
@ -1629,7 +1636,7 @@ public abstract class Screen implements ItemLayout.ItemLayoutListener, ItemView.
if(eventAction != null) {
runAction(engine, "SHORTCUT", eventAction, itemView.getParentItemLayout(), itemView);
} else {
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_PAGE)) {
if(intent.hasExtra(LightningIntent.INTENT_EXTRA_DESKTOP)) {
executeGoToDesktopPositionIntent(intent);
}
}
@ -1767,7 +1774,7 @@ public abstract class Screen implements ItemLayout.ItemLayoutListener, ItemView.
if (eventAction != null) {
runAction(engine, source, eventAction, il, itemView);
} else {
if (intent.hasExtra(LightningIntent.INTENT_EXTRA_PAGE)) {
if (intent.hasExtra(LightningIntent.INTENT_EXTRA_DESKTOP)) {
executeGoToDesktopPositionIntent(intent);
}
}

View file

@ -174,7 +174,7 @@ public class LL {
*/
public void goToDesktopPosition(int id, float x, float y, float scale, boolean animate) {
net.pierrox.lightning_launcher.script.api.screen.Screen screen = mLightning.getScriptScreen();
screen.getScreen().goToDesktopPosition(id, -x * scale, -y * scale, scale, animate);
screen.getScreen().goToDesktopPosition(id, -x * scale, -y * scale, scale, animate, true);
}
/**

View file

@ -61,9 +61,37 @@ public class HomeScreen extends ActivityScreen {
* @param y absolute Y position, in pixel
* @param scale zoom factor (1=100%, 0.5=50%, negative values are acceptable, 0 is not very useful)
* @param animate whether to animate the move
* @see #goToDesktopPage(int, float, float, float, boolean) to use coordinates in page units
*/
public void goToDesktopPosition(int id, float x, float y, float scale, boolean animate) {
mScreen.goToDesktopPosition(id, -x * scale, -y * scale, scale, animate);
mScreen.goToDesktopPosition(id, -x * scale, -y * scale, scale, animate, true);
}
/**
* Go to a specified desktop and navigate to the specified page, with animation and a 1x scale. This method does nothing when the script is run in background.
* The benefit of using page coordinates is that it doesn't depend on the container geometry (screen orientation or resolution).
* @param id desktop identifier
* @param x horizontal page position
* @param y vertical page position
* @see #goToDesktopPosition(int, float, float) to use absolute coordinates
* @see #goToDesktopPage(int, float, float, float, boolean) to control scale and animation
*/
public void goToDesktopPage(int id, float x, float y) {
mScreen.goToDesktopPosition(id, -x, -y, 1, true, false);
}
/**
* Go to a specified desktop and navigate to the specified page. This method does nothing when the script is run in background.
* The benefit of using page coordinates is that it doesn't depend on the container geometry (screen orientation or resolution).
* @param id desktop identifier
* @param x horizontal page position
* @param y vertical page position
* @param scale zoom factor (1=100%, 0.5=50%, negative values are acceptable, 0 is not very useful)
* @param animate whether to animate the move
* @see #goToDesktopPosition(int, float, float) to use absolute coordinates
*/
public void goToDesktopPage(int id, float x, float y, float scale, boolean animate) {
mScreen.goToDesktopPosition(id, -x, -y, scale, animate, false);
}
}

View file

@ -1229,6 +1229,16 @@ public class ItemLayout extends ViewGroup {
computeCurrentLocalTransformValues();
}
public void goToPage(float x, float y, float to_scale, boolean animate) {
float to_x = (x * getWidth()) * to_scale;
float to_y = (y * getHeight()) * to_scale;
if(animate) {
animateZoomTo(to_x, to_y, to_scale);
} else {
moveTo(to_x, to_y, to_scale);
}
}
// recenter the view on the primary page after it has been scrolled multiple times in seamless mode
public void recenter() {
if(!mItemsBoundingBox.isEmpty()) { // this check does not apply if the ItemLayout has not been measured yet