Button moved to a separate package
This commit is contained in:
parent
b09b3c11a8
commit
e0528ae340
@ -5,6 +5,7 @@ import android.view.HapticFeedbackConstants;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
|
||||
import org.solovyev.android.calculator.buttons.CppSpecialButton;
|
||||
import org.solovyev.android.calculator.view.ViewsCache;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -42,39 +43,39 @@ final class ButtonOnClickListener implements View.OnClickListener {
|
||||
onClick(v, ((Button) v).getText().toString());
|
||||
break;
|
||||
case R.id.cpp_button_clear:
|
||||
onClick(v, CalculatorSpecialButton.clear);
|
||||
onClick(v, CppSpecialButton.clear);
|
||||
break;
|
||||
case R.id.cpp_button_functions:
|
||||
onClick(v, CalculatorSpecialButton.functions);
|
||||
onClick(v, CppSpecialButton.functions);
|
||||
break;
|
||||
case R.id.cpp_button_history:
|
||||
onClick(v, CalculatorSpecialButton.history);
|
||||
onClick(v, CppSpecialButton.history);
|
||||
break;
|
||||
case R.id.cpp_button_erase:
|
||||
onClick(v, CalculatorSpecialButton.erase);
|
||||
onClick(v, CppSpecialButton.erase);
|
||||
break;
|
||||
case R.id.cpp_button_paste:
|
||||
onClick(v, CalculatorSpecialButton.paste);
|
||||
onClick(v, CppSpecialButton.paste);
|
||||
break;
|
||||
case R.id.cpp_button_copy:
|
||||
onClick(v, CalculatorSpecialButton.copy);
|
||||
onClick(v, CppSpecialButton.copy);
|
||||
break;
|
||||
case R.id.cpp_button_like:
|
||||
onClick(v, CalculatorSpecialButton.like);
|
||||
onClick(v, CppSpecialButton.like);
|
||||
break;
|
||||
case R.id.cpp_button_operators:
|
||||
onClick(v, CalculatorSpecialButton.operators);
|
||||
onClick(v, CppSpecialButton.operators);
|
||||
break;
|
||||
case R.id.cpp_button_vars:
|
||||
onClick(v, CalculatorSpecialButton.vars);
|
||||
onClick(v, CppSpecialButton.vars);
|
||||
break;
|
||||
case R.id.cpp_button_equals:
|
||||
onClick(v, CalculatorSpecialButton.equals);
|
||||
onClick(v, CppSpecialButton.equals);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void onClick(@Nonnull View v, @Nonnull CalculatorSpecialButton b) {
|
||||
private void onClick(@Nonnull View v, @Nonnull CppSpecialButton b) {
|
||||
onClick(v, b.getActionCode());
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.solovyev.android.calculator.buttons.CppButton;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.inject.Inject;
|
||||
|
||||
@ -19,7 +21,7 @@ public final class CalculatorReceiver extends BroadcastReceiver {
|
||||
Keyboard keyboard;
|
||||
|
||||
@Nonnull
|
||||
public static Intent newButtonClickedIntent(@Nonnull Context context, @Nonnull CalculatorButton button) {
|
||||
public static Intent newButtonClickedIntent(@Nonnull Context context, @Nonnull CppButton button) {
|
||||
final Intent intent = new Intent(context, CalculatorReceiver.class);
|
||||
intent.setAction(ACTION_BUTTON_PRESSED);
|
||||
intent.putExtra(ACTION_BUTTON_ID_EXTRA, button.id);
|
||||
@ -36,7 +38,7 @@ public final class CalculatorReceiver extends BroadcastReceiver {
|
||||
cast(context).getComponent().inject(this);
|
||||
|
||||
final int buttonId = intent.getIntExtra(ACTION_BUTTON_ID_EXTRA, 0);
|
||||
final CalculatorButton button = CalculatorButton.getById(buttonId);
|
||||
final CppButton button = CppButton.getById(buttonId);
|
||||
if (button == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import android.text.TextUtils;
|
||||
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import org.solovyev.android.calculator.buttons.CppSpecialButton;
|
||||
import org.solovyev.android.calculator.math.MathType;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@ -106,7 +107,7 @@ public class Keyboard {
|
||||
private boolean processSpecialButtons(@Nonnull String text) {
|
||||
boolean result = false;
|
||||
|
||||
final CalculatorSpecialButton button = CalculatorSpecialButton.getByActionCode(text);
|
||||
final CppSpecialButton button = CppSpecialButton.getByActionCode(text);
|
||||
if (button != null) {
|
||||
button.onClick(this);
|
||||
result = true;
|
||||
|
@ -20,25 +20,26 @@
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
package org.solovyev.android.calculator.buttons;
|
||||
|
||||
import android.util.SparseArray;
|
||||
|
||||
import org.solovyev.android.Check;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorSpecialButton.cursor_left;
|
||||
import static org.solovyev.android.calculator.CalculatorSpecialButton.cursor_right;
|
||||
import static org.solovyev.android.calculator.CalculatorSpecialButton.functions_detached;
|
||||
import static org.solovyev.android.calculator.CalculatorSpecialButton.history_detached;
|
||||
import static org.solovyev.android.calculator.CalculatorSpecialButton.open_app;
|
||||
import static org.solovyev.android.calculator.CalculatorSpecialButton.operators_detached;
|
||||
import static org.solovyev.android.calculator.CalculatorSpecialButton.settings_detached;
|
||||
import static org.solovyev.android.calculator.CalculatorSpecialButton.vars_detached;
|
||||
import static org.solovyev.android.calculator.buttons.CppSpecialButton.cursor_left;
|
||||
import static org.solovyev.android.calculator.buttons.CppSpecialButton.cursor_right;
|
||||
import static org.solovyev.android.calculator.buttons.CppSpecialButton.functions_detached;
|
||||
import static org.solovyev.android.calculator.buttons.CppSpecialButton.history_detached;
|
||||
import static org.solovyev.android.calculator.buttons.CppSpecialButton.open_app;
|
||||
import static org.solovyev.android.calculator.buttons.CppSpecialButton.operators_detached;
|
||||
import static org.solovyev.android.calculator.buttons.CppSpecialButton.settings_detached;
|
||||
import static org.solovyev.android.calculator.buttons.CppSpecialButton.vars_detached;
|
||||
|
||||
public enum CalculatorButton {
|
||||
public enum CppButton {
|
||||
|
||||
/*digits*/
|
||||
one(R.id.cpp_button_1, "1"),
|
||||
@ -56,8 +57,8 @@ public enum CalculatorButton {
|
||||
brackets(R.id.cpp_button_round_brackets, "()"),
|
||||
|
||||
settings(R.id.cpp_button_settings, settings_detached),
|
||||
settings_widget(R.id.cpp_button_settings_widget, CalculatorSpecialButton.settings_widget),
|
||||
like(R.id.cpp_button_like, CalculatorSpecialButton.like),
|
||||
settings_widget(R.id.cpp_button_settings_widget, CppSpecialButton.settings_widget),
|
||||
like(R.id.cpp_button_like, CppSpecialButton.like),
|
||||
|
||||
/*last row*/
|
||||
left(R.id.cpp_button_left, cursor_left),
|
||||
@ -77,43 +78,43 @@ public enum CalculatorButton {
|
||||
power(R.id.cpp_button_power, "^"),
|
||||
|
||||
/*last column*/
|
||||
clear(R.id.cpp_button_clear, CalculatorSpecialButton.clear),
|
||||
erase(R.id.cpp_button_erase, CalculatorSpecialButton.erase, CalculatorSpecialButton.clear),
|
||||
copy(R.id.cpp_button_copy, CalculatorSpecialButton.copy),
|
||||
paste(R.id.cpp_button_paste, CalculatorSpecialButton.paste),
|
||||
clear(R.id.cpp_button_clear, CppSpecialButton.clear),
|
||||
erase(R.id.cpp_button_erase, CppSpecialButton.erase, CppSpecialButton.clear),
|
||||
copy(R.id.cpp_button_copy, CppSpecialButton.copy),
|
||||
paste(R.id.cpp_button_paste, CppSpecialButton.paste),
|
||||
|
||||
/*equals*/
|
||||
equals(R.id.cpp_button_equals, CalculatorSpecialButton.equals);
|
||||
equals(R.id.cpp_button_equals, CppSpecialButton.equals);
|
||||
|
||||
@Nonnull
|
||||
private static SparseArray<CalculatorButton> buttonsByIds = new SparseArray<>();
|
||||
private static SparseArray<CppButton> buttonsByIds = new SparseArray<>();
|
||||
public final int id;
|
||||
@Nonnull
|
||||
public final String action;
|
||||
@Nullable
|
||||
public final String actionLong;
|
||||
|
||||
CalculatorButton(int id, @Nonnull CalculatorSpecialButton onClickButton, @Nullable CalculatorSpecialButton onLongClickButton) {
|
||||
CppButton(int id, @Nonnull CppSpecialButton onClickButton, @Nullable CppSpecialButton onLongClickButton) {
|
||||
this(id, onClickButton.getActionCode(), onLongClickButton == null ? null : onLongClickButton.getActionCode());
|
||||
}
|
||||
|
||||
CalculatorButton(int id, @Nonnull CalculatorSpecialButton onClickButton) {
|
||||
CppButton(int id, @Nonnull CppSpecialButton onClickButton) {
|
||||
this(id, onClickButton, null);
|
||||
}
|
||||
|
||||
CalculatorButton(int id, @Nonnull String action, @Nullable String actionLong) {
|
||||
CppButton(int id, @Nonnull String action, @Nullable String actionLong) {
|
||||
this.id = id;
|
||||
this.action = action;
|
||||
this.actionLong = actionLong;
|
||||
|
||||
}
|
||||
|
||||
CalculatorButton(int id, @Nonnull String action) {
|
||||
CppButton(int id, @Nonnull String action) {
|
||||
this(id, action, null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CalculatorButton getById(int buttonId) {
|
||||
public static CppButton getById(int buttonId) {
|
||||
initButtonsByIdsMap();
|
||||
return buttonsByIds.get(buttonId);
|
||||
}
|
||||
@ -121,7 +122,7 @@ public enum CalculatorButton {
|
||||
private static void initButtonsByIdsMap() {
|
||||
Check.isMainThread();
|
||||
if (buttonsByIds.size() == 0) {
|
||||
for (CalculatorButton button : values()) {
|
||||
for (CppButton button : values()) {
|
||||
buttonsByIds.append(button.id, button);
|
||||
}
|
||||
}
|
@ -20,7 +20,14 @@
|
||||
* Site: http://se.solovyev.org
|
||||
*/
|
||||
|
||||
package org.solovyev.android.calculator;
|
||||
package org.solovyev.android.calculator.buttons;
|
||||
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.Calculator;
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.android.calculator.DisplayState;
|
||||
import org.solovyev.android.calculator.Keyboard;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -28,7 +35,7 @@ import java.util.Map;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public enum CalculatorSpecialButton {
|
||||
public enum CppSpecialButton {
|
||||
|
||||
history("history") {
|
||||
@Override
|
||||
@ -72,7 +79,6 @@ public enum CalculatorSpecialButton {
|
||||
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_settings_widget, null);
|
||||
}
|
||||
},
|
||||
|
||||
like("like") {
|
||||
@Override
|
||||
public void onClick(@Nonnull Keyboard keyboard) {
|
||||
@ -164,17 +170,17 @@ public enum CalculatorSpecialButton {
|
||||
};
|
||||
|
||||
@Nonnull
|
||||
private static Map<String, CalculatorSpecialButton> buttonsByActionCodes = new HashMap<>();
|
||||
private static Map<String, CppSpecialButton> buttonsByActionCodes = new HashMap<>();
|
||||
|
||||
@Nonnull
|
||||
private final String actionCode;
|
||||
|
||||
CalculatorSpecialButton(@Nonnull String actionCode) {
|
||||
CppSpecialButton(@Nonnull String actionCode) {
|
||||
this.actionCode = actionCode;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static CalculatorSpecialButton getByActionCode(@Nonnull String actionCode) {
|
||||
public static CppSpecialButton getByActionCode(@Nonnull String actionCode) {
|
||||
initButtonsByActionCodesMap();
|
||||
return buttonsByActionCodes.get(actionCode);
|
||||
}
|
||||
@ -183,10 +189,10 @@ public enum CalculatorSpecialButton {
|
||||
if (buttonsByActionCodes.isEmpty()) {
|
||||
// if not initialized
|
||||
|
||||
final CalculatorSpecialButton[] specialButtons = values();
|
||||
final CppSpecialButton[] specialButtons = values();
|
||||
|
||||
final Map<String, CalculatorSpecialButton> localButtonsByActionCodes = new HashMap<String, CalculatorSpecialButton>(specialButtons.length);
|
||||
for (CalculatorSpecialButton specialButton : specialButtons) {
|
||||
final Map<String, CppSpecialButton> localButtonsByActionCodes = new HashMap<String, CppSpecialButton>(specialButtons.length);
|
||||
for (CppSpecialButton specialButton : specialButtons) {
|
||||
localButtonsByActionCodes.put(specialButton.getActionCode(), specialButton);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorButton;
|
||||
import org.solovyev.android.calculator.buttons.CppButton;
|
||||
import org.solovyev.android.calculator.DisplayState;
|
||||
import org.solovyev.android.calculator.DisplayView;
|
||||
import org.solovyev.android.calculator.EditorState;
|
||||
@ -152,7 +152,7 @@ public class CalculatorOnscreenView {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final CalculatorButton widgetButton : CalculatorButton.values()) {
|
||||
for (final CppButton widgetButton : CppButton.values()) {
|
||||
final View button = root.findViewById(widgetButton.id);
|
||||
if (button == null) {
|
||||
continue;
|
||||
@ -163,7 +163,7 @@ public class CalculatorOnscreenView {
|
||||
if (keyboard.buttonPressed(widgetButton.action)) {
|
||||
v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
||||
}
|
||||
if (widgetButton == CalculatorButton.app) {
|
||||
if (widgetButton == CppButton.app) {
|
||||
minimize();
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ import android.widget.RemoteViews;
|
||||
import org.solovyev.android.Check;
|
||||
import org.solovyev.android.Views;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.CalculatorButton;
|
||||
import org.solovyev.android.calculator.buttons.CppButton;
|
||||
import org.solovyev.android.calculator.DisplayState;
|
||||
import org.solovyev.android.calculator.EditorState;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
@ -129,13 +129,13 @@ public class CalculatorWidget extends AppWidgetProvider {
|
||||
final RemoteViews views = new RemoteViews(context.getPackageName(), getLayout(manager, widgetId, resources, theme));
|
||||
|
||||
if (!partially || Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
||||
for (CalculatorButton button : CalculatorButton.values()) {
|
||||
for (CppButton button : CppButton.values()) {
|
||||
final PendingIntent intent = intents.get(context, button);
|
||||
if (intent != null) {
|
||||
final int buttonId;
|
||||
if (button == CalculatorButton.settings_widget) {
|
||||
if (button == CppButton.settings_widget) {
|
||||
// overriding default settings button behavior
|
||||
buttonId = CalculatorButton.settings.id;
|
||||
buttonId = CppButton.settings.id;
|
||||
} else {
|
||||
buttonId = button.id;
|
||||
}
|
||||
@ -254,10 +254,10 @@ public class CalculatorWidget extends AppWidgetProvider {
|
||||
|
||||
private static class Intents {
|
||||
@Nonnull
|
||||
private final EnumMap<CalculatorButton, PendingIntent> map = new EnumMap<>(CalculatorButton.class);
|
||||
private final EnumMap<CppButton, PendingIntent> map = new EnumMap<>(CppButton.class);
|
||||
|
||||
@Nullable
|
||||
PendingIntent get(@Nonnull Context context, @Nonnull CalculatorButton button) {
|
||||
PendingIntent get(@Nonnull Context context, @Nonnull CppButton button) {
|
||||
Check.isMainThread();
|
||||
|
||||
PendingIntent intent = map.get(button);
|
||||
|
@ -11,7 +11,7 @@ import org.robolectric.annotation.Config;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.robolectric.RuntimeEnvironment.application;
|
||||
import static org.solovyev.android.calculator.CalculatorButton.four;
|
||||
import static org.solovyev.android.calculator.buttons.CppButton.four;
|
||||
import static org.solovyev.android.calculator.CalculatorReceiver.*;
|
||||
|
||||
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
|
||||
|
Loading…
Reference in New Issue
Block a user