Clipboard as a Bean

This commit is contained in:
serso 2016-01-31 10:35:10 +01:00
parent 654f4b8809
commit 030a93cce5
9 changed files with 23 additions and 127 deletions

View File

@ -121,7 +121,6 @@ public class CalculatorApplication extends android.app.Application implements Sh
Locator.getInstance().init(calculator,
engine,
new AndroidCalculatorClipboard(this),
new AndroidCalculatorNotifier(this),
errorReporter,
new AndroidCalculatorPreferenceService(this),

View File

@ -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);
}

View File

@ -30,7 +30,6 @@ public interface CalculatorLocator {
void init(@Nonnull Calculator calculator,
@Nonnull Engine engine,
@Nonnull CalculatorClipboard clipboard,
@Nonnull CalculatorNotifier notifier,
@Nonnull ErrorReporter errorReporter,
@Nonnull CalculatorPreferenceService preferenceService,
@ -46,9 +45,6 @@ public interface CalculatorLocator {
@Nonnull
Keyboard getKeyboard();
@Nonnull
CalculatorClipboard getClipboard();
@Nonnull
CalculatorNotifier getNotifier();

View File

@ -27,40 +27,36 @@ import android.content.Context;
import android.text.ClipboardManager;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
/**
* User: serso
* Date: 9/22/12
* Time: 1:35 PM
*/
public class AndroidCalculatorClipboard implements CalculatorClipboard {
@Singleton
public class Clipboard {
@SuppressWarnings("deprecation")
@Nonnull
private final Context context;
private final ClipboardManager clipboard;
public AndroidCalculatorClipboard(@Nonnull Application application) {
this.context = application;
@SuppressWarnings("deprecation")
@Inject
public Clipboard(@Nonnull Application application) {
clipboard = (ClipboardManager) application.getSystemService(Context.CLIPBOARD_SERVICE);
}
@Override
@SuppressWarnings("deprecation")
@Nonnull
public String getText() {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if (clipboard.hasText()) {
return String.valueOf(clipboard.getText());
} else {
return null;
}
return "";
}
@Override
public void setText(@Nonnull CharSequence text) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(text);
}
@Override
public void setText(@Nonnull String text) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(text);
}
}

View File

@ -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) {
}
}

View File

@ -22,6 +22,7 @@
package org.solovyev.android.calculator;
import android.text.TextUtils;
import org.solovyev.android.calculator.math.MathType;
import org.solovyev.common.text.Strings;
@ -38,9 +39,10 @@ public class Keyboard {
@Inject
Editor editor;
@Inject
Display display;
@Inject
Clipboard clipboard;
@Inject
public Keyboard() {
@ -119,8 +121,8 @@ public class Keyboard {
}
public void pasteButtonPressed() {
final String text = Locator.getInstance().getClipboard().getText();
if (text != null) {
final String text = clipboard.getText();
if (!TextUtils.isEmpty(text)) {
editor.insert(text);
}
}
@ -134,7 +136,7 @@ public class Keyboard {
if (!displayState.valid) {
return;
}
Locator.getInstance().getClipboard().setText(displayState.text);
clipboard.setText(displayState.text);
Locator.getInstance().getNotifier().showMessage(CalculatorMessage.newInfoMessage(CalculatorMessages.result_copied));
}

View File

@ -41,8 +41,6 @@ public class Locator implements CalculatorLocator {
@Nonnull
private ErrorReporter errorReporter = new SystemErrorReporter();
@Nonnull
private CalculatorClipboard calculatorClipboard = new DummyCalculatorClipboard();
@Nonnull
private CalculatorPreferenceService calculatorPreferenceService;
@Nonnull
@ -59,7 +57,6 @@ public class Locator implements CalculatorLocator {
@Override
public void init(@Nonnull Calculator calculator,
@Nonnull Engine engine,
@Nonnull CalculatorClipboard clipboard,
@Nonnull CalculatorNotifier notifier,
@Nonnull ErrorReporter errorReporter,
@Nonnull CalculatorPreferenceService preferenceService,
@ -68,7 +65,6 @@ public class Locator implements CalculatorLocator {
this.calculator = calculator;
this.engine = engine;
this.calculatorClipboard = clipboard;
this.calculatorNotifier = notifier;
this.errorReporter = errorReporter;
this.calculatorPreferenceService = preferenceService;
@ -99,12 +95,6 @@ public class Locator implements CalculatorLocator {
instance.keyboard = keyboard;
}
@Override
@Nonnull
public CalculatorClipboard getClipboard() {
return calculatorClipboard;
}
@Override
@Nonnull
public CalculatorNotifier getNotifier() {

View File

@ -36,7 +36,7 @@ import java.util.concurrent.Executor;
public class AbstractCalculatorTest {
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() {
@Override
public void execute(Runnable command) {

View File

@ -66,7 +66,7 @@ public class CalculatorTestUtils {
public static void staticSetUp() throws Exception {
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() {
@Override
public void execute(Runnable command) {
@ -81,7 +81,7 @@ public class CalculatorTestUtils {
}
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() {
@Override
public void execute(Runnable command) {