Clipboard as a Bean
This commit is contained in:
parent
654f4b8809
commit
030a93cce5
@ -121,7 +121,6 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
|||||||
|
|
||||||
Locator.getInstance().init(calculator,
|
Locator.getInstance().init(calculator,
|
||||||
engine,
|
engine,
|
||||||
new AndroidCalculatorClipboard(this),
|
|
||||||
new AndroidCalculatorNotifier(this),
|
new AndroidCalculatorNotifier(this),
|
||||||
errorReporter,
|
errorReporter,
|
||||||
new AndroidCalculatorPreferenceService(this),
|
new AndroidCalculatorPreferenceService(this),
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013 serso aka se.solovyev
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
* Contact details
|
|
||||||
*
|
|
||||||
* Email: se.solovyev@gmail.com
|
|
||||||
* Site: http://se.solovyev.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 9/22/12
|
|
||||||
* Time: 1:34 PM
|
|
||||||
*/
|
|
||||||
public interface CalculatorClipboard {
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
String getText();
|
|
||||||
|
|
||||||
void setText(@Nonnull CharSequence text);
|
|
||||||
|
|
||||||
void setText(@Nonnull String text);
|
|
||||||
}
|
|
@ -30,7 +30,6 @@ public interface CalculatorLocator {
|
|||||||
|
|
||||||
void init(@Nonnull Calculator calculator,
|
void init(@Nonnull Calculator calculator,
|
||||||
@Nonnull Engine engine,
|
@Nonnull Engine engine,
|
||||||
@Nonnull CalculatorClipboard clipboard,
|
|
||||||
@Nonnull CalculatorNotifier notifier,
|
@Nonnull CalculatorNotifier notifier,
|
||||||
@Nonnull ErrorReporter errorReporter,
|
@Nonnull ErrorReporter errorReporter,
|
||||||
@Nonnull CalculatorPreferenceService preferenceService,
|
@Nonnull CalculatorPreferenceService preferenceService,
|
||||||
@ -46,9 +45,6 @@ public interface CalculatorLocator {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
Keyboard getKeyboard();
|
Keyboard getKeyboard();
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
CalculatorClipboard getClipboard();
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
CalculatorNotifier getNotifier();
|
CalculatorNotifier getNotifier();
|
||||||
|
|
||||||
|
@ -27,40 +27,36 @@ import android.content.Context;
|
|||||||
import android.text.ClipboardManager;
|
import android.text.ClipboardManager;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
/**
|
@Singleton
|
||||||
* User: serso
|
public class Clipboard {
|
||||||
* Date: 9/22/12
|
@SuppressWarnings("deprecation")
|
||||||
* Time: 1:35 PM
|
|
||||||
*/
|
|
||||||
public class AndroidCalculatorClipboard implements CalculatorClipboard {
|
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private final Context context;
|
private final ClipboardManager clipboard;
|
||||||
|
|
||||||
public AndroidCalculatorClipboard(@Nonnull Application application) {
|
@SuppressWarnings("deprecation")
|
||||||
this.context = application;
|
@Inject
|
||||||
|
public Clipboard(@Nonnull Application application) {
|
||||||
|
clipboard = (ClipboardManager) application.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@SuppressWarnings("deprecation")
|
||||||
|
@Nonnull
|
||||||
public String getText() {
|
public String getText() {
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
if (clipboard.hasText()) {
|
if (clipboard.hasText()) {
|
||||||
return String.valueOf(clipboard.getText());
|
return String.valueOf(clipboard.getText());
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
public void setText(@Nonnull CharSequence text) {
|
public void setText(@Nonnull CharSequence text) {
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
clipboard.setText(text);
|
clipboard.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setText(@Nonnull String text) {
|
public void setText(@Nonnull String text) {
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
|
||||||
clipboard.setText(text);
|
clipboard.setText(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,46 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013 serso aka se.solovyev
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*
|
|
||||||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
||||||
* Contact details
|
|
||||||
*
|
|
||||||
* Email: se.solovyev@gmail.com
|
|
||||||
* Site: http://se.solovyev.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.solovyev.android.calculator;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User: serso
|
|
||||||
* Date: 9/22/12
|
|
||||||
* Time: 2:00 PM
|
|
||||||
*/
|
|
||||||
public class DummyCalculatorClipboard implements CalculatorClipboard {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getText() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setText(@Nonnull CharSequence text) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setText(@Nonnull String text) {
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
import org.solovyev.android.calculator.math.MathType;
|
import org.solovyev.android.calculator.math.MathType;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
|
|
||||||
@ -38,9 +39,10 @@ public class Keyboard {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Editor editor;
|
Editor editor;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Display display;
|
Display display;
|
||||||
|
@Inject
|
||||||
|
Clipboard clipboard;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public Keyboard() {
|
public Keyboard() {
|
||||||
@ -119,8 +121,8 @@ public class Keyboard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void pasteButtonPressed() {
|
public void pasteButtonPressed() {
|
||||||
final String text = Locator.getInstance().getClipboard().getText();
|
final String text = clipboard.getText();
|
||||||
if (text != null) {
|
if (!TextUtils.isEmpty(text)) {
|
||||||
editor.insert(text);
|
editor.insert(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,7 +136,7 @@ public class Keyboard {
|
|||||||
if (!displayState.valid) {
|
if (!displayState.valid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Locator.getInstance().getClipboard().setText(displayState.text);
|
clipboard.setText(displayState.text);
|
||||||
Locator.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.result_copied));
|
Locator.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.result_copied));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,8 +41,6 @@ public class Locator implements CalculatorLocator {
|
|||||||
@Nonnull
|
@Nonnull
|
||||||
private ErrorReporter errorReporter = new SystemErrorReporter();
|
private ErrorReporter errorReporter = new SystemErrorReporter();
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard();
|
|
||||||
@Nonnull
|
|
||||||
private CalculatorPreferenceService calculatorPreferenceService;
|
private CalculatorPreferenceService calculatorPreferenceService;
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@ -59,7 +57,6 @@ public class Locator implements CalculatorLocator {
|
|||||||
@Override
|
@Override
|
||||||
public void init(@Nonnull Calculator calculator,
|
public void init(@Nonnull Calculator calculator,
|
||||||
@Nonnull Engine engine,
|
@Nonnull Engine engine,
|
||||||
@Nonnull CalculatorClipboard clipboard,
|
|
||||||
@Nonnull CalculatorNotifier notifier,
|
@Nonnull CalculatorNotifier notifier,
|
||||||
@Nonnull ErrorReporter errorReporter,
|
@Nonnull ErrorReporter errorReporter,
|
||||||
@Nonnull CalculatorPreferenceService preferenceService,
|
@Nonnull CalculatorPreferenceService preferenceService,
|
||||||
@ -68,7 +65,6 @@ public class Locator implements CalculatorLocator {
|
|||||||
|
|
||||||
this.calculator = calculator;
|
this.calculator = calculator;
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
this.calculatorClipboard = clipboard;
|
|
||||||
this.calculatorNotifier = notifier;
|
this.calculatorNotifier = notifier;
|
||||||
this.errorReporter = errorReporter;
|
this.errorReporter = errorReporter;
|
||||||
this.calculatorPreferenceService = preferenceService;
|
this.calculatorPreferenceService = preferenceService;
|
||||||
@ -99,12 +95,6 @@ public class Locator implements CalculatorLocator {
|
|||||||
instance.keyboard = keyboard;
|
instance.keyboard = keyboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nonnull
|
|
||||||
public CalculatorClipboard getClipboard() {
|
|
||||||
return calculatorClipboard;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public CalculatorNotifier getNotifier() {
|
public CalculatorNotifier getNotifier() {
|
||||||
|
@ -36,7 +36,7 @@ import java.util.concurrent.Executor;
|
|||||||
public class AbstractCalculatorTest {
|
public class AbstractCalculatorTest {
|
||||||
|
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
|
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), CalculatorTestUtils.newCalculatorEngine(), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
|
||||||
Locator.getInstance().getEngine().init(new Executor() {
|
Locator.getInstance().getEngine().init(new Executor() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(Runnable command) {
|
public void execute(Runnable command) {
|
||||||
|
@ -66,7 +66,7 @@ public class CalculatorTestUtils {
|
|||||||
|
|
||||||
public static void staticSetUp() throws Exception {
|
public static void staticSetUp() throws Exception {
|
||||||
App.init(new CalculatorApplication(), new Languages(new RoboSharedPreferences(new HashMap<String, Map<String, Object>>(), "test", 0)));
|
App.init(new CalculatorApplication(), new Languages(new RoboSharedPreferences(new HashMap<String, Map<String, Object>>(), "test", 0)));
|
||||||
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
|
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), newCalculatorEngine(), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
|
||||||
Locator.getInstance().getEngine().init(new Executor() {
|
Locator.getInstance().getEngine().init(new Executor() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(Runnable command) {
|
public void execute(Runnable command) {
|
||||||
@ -81,7 +81,7 @@ public class CalculatorTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void staticSetUp(@Nullable Context context) throws Exception {
|
public static void staticSetUp(@Nullable Context context) throws Exception {
|
||||||
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), newCalculatorEngine(), Mockito.mock(CalculatorClipboard.class), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
|
Locator.getInstance().init(new CalculatorImpl(Mockito.mock(Bus.class), Mockito.mock(Executor.class)), newCalculatorEngine(), Mockito.mock(CalculatorNotifier.class), new SystemErrorReporter(), Mockito.mock(CalculatorPreferenceService.class), Mockito.mock(Keyboard.class), Mockito.mock(CalculatorPlotter.class));
|
||||||
Locator.getInstance().getEngine().init(new Executor() {
|
Locator.getInstance().getEngine().init(new Executor() {
|
||||||
@Override
|
@Override
|
||||||
public void execute(Runnable command) {
|
public void execute(Runnable command) {
|
||||||
|
Loading…
Reference in New Issue
Block a user