Skip to content

Commit

Permalink
Optimized selection and find & replace. Ready for 1.8.6 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
oO0oO0oO0o0o00 committed Mar 12, 2019
1 parent 26adbc0 commit a722aba
Show file tree
Hide file tree
Showing 19 changed files with 2,281 additions and 2,178 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mBinding = DataBindingUtil.setContentView(this, R.layout.activity_create_world);
mToolTipsManager = new ToolTipsManager();
Log.logFirebaseEvent(this, Log.CustomFirebaseEvent.CREATE_WORLD_OPEN);
mBinding.scroll.post(() -> mBinding.scroll.scrollTo(0, 0));
}

public void onClickPositiveButton(View view) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
Expand Down Expand Up @@ -212,7 +213,7 @@ private void moveCameraToPlayer(View view) {

Snackbar.make(mBinding.tileView,
getString(R.string.something_at_xyz_dim_float, getString(R.string.player),
playerPos.x, playerPos.y, playerPos.z, playerPos.dimension.name),
playerPos.x, playerPos.y, playerPos.z),
Snackbar.LENGTH_SHORT)
.setAction("Action", null).show();

Expand Down Expand Up @@ -251,7 +252,7 @@ private void moveCameraToSpawn(View view) {

Snackbar.make(mBinding.tileView,
getString(R.string.something_at_xyz_dim_int, getString(R.string.spawn),
spawnPos.x, spawnPos.y, spawnPos.z, spawnPos.dimension.name),
spawnPos.x, spawnPos.y, spawnPos.z),
Snackbar.LENGTH_SHORT)
.setAction("Action", null).show();

Expand Down Expand Up @@ -287,14 +288,31 @@ private void closeFloatPane() {
.newInstance(mBinding.selectionBoard.getSelection(),
this::doSelectionBasedEdit);
trans.add(R.id.float_window_container, fragment);
setUpSelectionMenu();
mFloatingFragment = fragment;
setUpSelectionMenu();
} else mFloatingFragment = null;

trans.commit();
}
}

@Override
public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (mFloatingFragment != null) {
FloatPaneFragment fragment;
if (mFloatingFragment instanceof AdvancedLocatorFragment) {
fragment = AdvancedLocatorFragment.create(world, this::frameTo);
} else if (mFloatingFragment instanceof SelectionMenuFragment) {
fragment = SelectionMenuFragment
.newInstance(mBinding.selectionBoard.getSelection(), this::doSelectionBasedEdit);
} else return;
closeFloatPane();
openFloatPane(fragment);
setUpSelectionMenu();
}
}

/**
* Set up selection menu and connect it with selection board.
*
Expand Down Expand Up @@ -517,20 +535,14 @@ Create tile(=bitmap) provider
tileView.getMarkerLayout().setMarkerTapListener(new MarkerLayout.MarkerTapListener() {
@Override
public void onMarkerTap(View view, int tapX, int tapY) {
if (!(view instanceof MarkerImageView)) {
Log.d(this, "Markertaplistener found a marker that is not a MarkerImageView! " + view.toString());
return;
}
if (!(view instanceof MarkerImageView)) return;

final AbstractMarker marker = ((MarkerImageView) view).getMarkerHook();
if (marker == null) {
Log.d(this, "abstract marker is null! " + view.toString());
return;
}
if (marker == null) return;

AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder
.setTitle(String.format(getString(R.string.marker_info), marker.getNamedBitmapProvider().getBitmapDisplayName(), marker.getNamedBitmapProvider().getBitmapDataName(), marker.x, marker.y, marker.z, marker.dimension))
.setTitle(String.format(getString(R.string.marker_info), marker.getNamedBitmapProvider().getBitmapDisplayName(), marker.x, marker.y, marker.z))
.setItems(getMarkerTapOptions(), new DialogInterface.OnClickListener() {
@SuppressWarnings("RedundantCast")
public void onClick(DialogInterface dialog, int which) {
Expand Down Expand Up @@ -848,7 +860,7 @@ private void onLongPressed(@NotNull MotionEvent event) {
}

AlertDialog alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(activity, R.style.AppTheme_Floating))
.setTitle(getString(R.string.postion_2D_floats_with_chunkpos, worldX, worldZ, chunkXint, chunkZint, dim.name))
.setTitle(getString(R.string.postion_2D_floats_with_chunkpos, worldX, worldZ, chunkXint, chunkZint))
.setItems(getLongClickOptions(), (dialog, which) -> {


Expand All @@ -874,6 +886,8 @@ private void onLongPressed(@NotNull MotionEvent event) {
.setCancelable(true)
.setNegativeButton(android.R.string.cancel, null)
.show();
alertDialog.getListView().post(() ->
alertDialog.getListView().smoothScrollToPositionFromTop(4, 40));
Window window = alertDialog.getWindow();
if (window != null) {
window.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_dialog_transparent));
Expand Down Expand Up @@ -1069,7 +1083,7 @@ private void onChooseTeleportPlayer(float worldX, float worldZ, Dimension dim, V
(int) newX, (int) newY, (int) newZ, dim);

Snackbar.make(container,
String.format(getString(R.string.teleported_player_to_xyz_dim), newX, newY, newZ, dim.name),
getString(R.string.teleported_player_to_xyz_dim, newX, newY, newZ),
Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
} else {
Expand Down Expand Up @@ -1430,8 +1444,7 @@ public void onClick(DialogInterface dialog, int whichButton) {
playerKey,
playerPos.x,
playerPos.y,
playerPos.z,
playerPos.dimension.name),
playerPos.z),
Snackbar.LENGTH_LONG)
.setAction("Action", null).show();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public boolean onTouchEvent(MotionEvent event) {
return false;
}

@Override
public boolean onSingleTapConfirmed(MotionEvent event) {
if (super.onSingleTapConfirmed(event)) return true;
if (mOnLongPressListener != null) {
mOnLongPressListener.onLongPressed(event);
return true;
}
return false;
}

/**
* Sets the long press callback.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mithrilmania.blocktopograph.map.edit;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
Expand All @@ -25,6 +26,7 @@
import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.DialogFragment;

Expand Down Expand Up @@ -101,7 +103,13 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
mBinding.ok.setOnClickListener(this::onClickOk);
mBinding.help.setOnClickListener(this::onClickHelpMain);
mToolTipsManager = new ToolTipsManager();
return mBinding.getRoot();
View root = mBinding.getRoot();
Dialog dialog = getDialog();
if (dialog instanceof AlertDialog) {
((AlertDialog) dialog).setView(root);
}
mBinding.scroll.post(() -> mBinding.scroll.scrollTo(0, 0));
return root;
}

private void onClickHelpMain(@NotNull View view) {
Expand Down Expand Up @@ -257,8 +265,11 @@ private void onClickOk(View view) {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.setTitle(R.string.map_edit_func_snr);
Context context = requireContext();
AlertDialog dialog = new AlertDialog.Builder(context)
//.setView(onCreateView(LayoutInflater.from(context), null, savedInstanceState))
.setTitle(R.string.map_edit_func_snr)
.create();
return dialog;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.graphics.Rect;

import com.mithrilmania.blocktopograph.Log;

import com.mithrilmania.blocktopograph.WorldData;
import com.mithrilmania.blocktopograph.chunk.Chunk;
import com.mithrilmania.blocktopograph.chunk.Version;
Expand All @@ -30,6 +29,7 @@ public void renderToBitmap(Chunk chunk, Canvas canvas, Dimension dimension, int
for (x = 0, tX = pX; x < 16; x++, tX += pW) {

y = chunk.getHeightMapValue(x, z);
if (y == 0) continue;

color = getColumnColour(chunk, x, y, z,
(x == 0) ? (west ? dataW.getHeightMapValue(dimension.chunkW - 1, z) : y)//chunk edge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import android.widget.EditText;
import android.widget.Toast;

import com.github.florent37.expansionpanel.ExpansionLayout;
import com.mithrilmania.blocktopograph.Log;
import com.mithrilmania.blocktopograph.R;
import com.mithrilmania.blocktopograph.databinding.FragSelMenuBinding;
Expand Down Expand Up @@ -62,9 +63,17 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
mBinding.content.applyButton.setOnClickListener(this::onApply);
mBinding.content.funcLampshade.setOnClickListener(this::onChooseLampshade);
mBinding.content.funcSnr.setOnClickListener(this::onChooseSnr);
mBinding.expansionLayout.post(() -> mBinding.expansionLayout.scrollTo(0, 0));
if (mBinding.scroll != null)
mBinding.expansionLayout.addListener(this::onExpansionChanged);
return mBinding.getRoot();
}

private void onExpansionChanged(ExpansionLayout layout, boolean expanded) {
mBinding.scroll.setScrollY(mBinding.scroll.getChildAt(0).getMeasuredHeight());
mBinding.scroll.post(() -> mBinding.scroll.smoothScrollTo(0, 0));
}

@Override
public void onDestroyView() {
super.onDestroyView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

public class SelectionView extends FrameLayout {

public static final int MIN_DIST_DRAGGERS = 50;
public static final int HALF_MIN_DIST_DRAGGERS = MIN_DIST_DRAGGERS / 2;
/**
* The view being dragged now.
*/
Expand Down Expand Up @@ -115,6 +113,19 @@ public class SelectionView extends FrameLayout {
*/
private float BUTTON_TO_BOUND_MIN_DIST;

/**
* The minimal non-auto-scroll distance from touched point to screen boundary.
*
* <p>
* Once it's exceed the tileView would be scrolled automatically.
* </p>
*/
private int MIN_DIST_TO_SCREEN_BOUND;

private int MIN_DIST_DRAGGERS;

private int HALF_MIN_DIST_DRAGGERS;

/**
* Runnable used to frequently alter selection while user dragging a adjust button.
*/
Expand Down Expand Up @@ -160,6 +171,9 @@ private void init(Context context) {
mPaint.setColor(Color.argb(0x80, 0, 0, 0));
setWillNotDraw(false);// Otherwise `onDraw` won't be called.
BUTTON_TO_BOUND_MIN_DIST = UiUtil.dpToPx(context, 72);
MIN_DIST_TO_SCREEN_BOUND = UiUtil.dpToPxInt(context, 100);
MIN_DIST_DRAGGERS = UiUtil.dpToPxInt(context, 50);
HALF_MIN_DIST_DRAGGERS = MIN_DIST_DRAGGERS / 2;

mDragger = null;
}
Expand Down Expand Up @@ -385,15 +399,35 @@ private void onMove() {
if (mSelectionChangedListener != null)
mSelectionChangedListener.onSelectionChanged(mSelectionRect);

// Move the tileView as well.
// Should we move the underlying tileView as well?
// If touched point is near the moving direction (not the dragger position)
// then we scroll.

int sw = getMeasuredWidth();
int sh = getMeasuredHeight();
int minw = Math.max(MIN_DIST_TO_SCREEN_BOUND, sw / 8);
int minh = Math.max(MIN_DIST_TO_SCREEN_BOUND, sh / 8);

switch (draggerId) {
case R.id.left:
case R.id.right:
tileView.setScrollX((int) (tileView.getScrollX() + movement));
// (Moving right and near right bound) or
// (Moving left and near left bound)
if (mDragDirection > 0 && sw - mDragCurrentPos < minw
|| (mDragDirection < 0 && mDragCurrentPos < minw)
)
tileView.setScrollX((int) (tileView.getScrollX() + movement));
else
requestLayout();
break;
case R.id.top:
case R.id.bottom:
tileView.setScrollY((int) (tileView.getScrollY() + movement));
if (mDragDirection > 0 && sh - mDragCurrentPos < minh
|| (mDragDirection < 0 && mDragCurrentPos < minh)
)
tileView.setScrollY((int) (tileView.getScrollY() + movement));
else
requestLayout();
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_create_world.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
android:padding="6dp">

<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fadeScrollbars="false">
android:layout_weight="1">

<RelativeLayout
android:id="@+id/help_frame_layers"
Expand Down
Loading

0 comments on commit a722aba

Please sign in to comment.