add a AC (reset) button to the widget
- it does the same as long pressing the C in the app, however widgets cannot be long pressed
This commit is contained in:
parent
5d75720619
commit
66dc345c1b
|
@ -156,7 +156,7 @@ public class CalculatorImpl {
|
|||
baseValue = Double.parseDouble(newValue);
|
||||
}
|
||||
|
||||
public void handleLongClear() {
|
||||
public void handleReset() {
|
||||
resetValues();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ public class Constants {
|
|||
public static final String ROOT = "root";
|
||||
public static final String DECIMAL = "decimal";
|
||||
public static final String CLEAR = "clear";
|
||||
public static final String RESET = "reset";
|
||||
|
||||
public static final String ZERO = "zero";
|
||||
public static final String ONE = "one";
|
||||
|
|
|
@ -65,7 +65,7 @@ public class MainActivity extends AppCompatActivity implements Calculator {
|
|||
|
||||
@OnLongClick(R.id.btn_clear)
|
||||
public boolean clearLongClicked() {
|
||||
calc.handleLongClear();
|
||||
calc.handleReset();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.appwidget.AppWidgetManager;
|
|||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
public class MyWidgetProvider extends AppWidgetProvider implements Calculator {
|
||||
|
@ -19,6 +20,7 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calculator {
|
|||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
widgetManager = appWidgetManager;
|
||||
remoteViews = new RemoteViews(context.getPackageName(), R.layout.activity_main);
|
||||
remoteViews.setViewVisibility(R.id.btn_reset, View.VISIBLE);
|
||||
calc = new CalculatorImpl(this);
|
||||
widgetIds = appWidgetIds;
|
||||
cxt = context;
|
||||
|
@ -45,6 +47,7 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calculator {
|
|||
setupIntent(Constants.POWER, R.id.btn_power);
|
||||
setupIntent(Constants.ROOT, R.id.btn_root);
|
||||
setupIntent(Constants.CLEAR, R.id.btn_clear);
|
||||
setupIntent(Constants.RESET, R.id.btn_reset);
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
|
||||
}
|
||||
|
@ -98,6 +101,9 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calculator {
|
|||
case Constants.CLEAR:
|
||||
calc.handleClear();
|
||||
break;
|
||||
case Constants.RESET:
|
||||
calc.handleReset();
|
||||
break;
|
||||
case Constants.PLUS:
|
||||
case Constants.MINUS:
|
||||
case Constants.MULTIPLY:
|
||||
|
|
|
@ -64,6 +64,15 @@
|
|||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="C"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_reset"
|
||||
style="@style/MyButtonStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:text="AC"
|
||||
android:visibility="gone"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -102,7 +102,7 @@ public class MainActivityTest {
|
|||
@Test
|
||||
public void clearBtnLongClick_resetsEverything() {
|
||||
calcResult(-1.2, Constants.PLUS, 3.4);
|
||||
activity.getCalc().handleLongClear();
|
||||
activity.getCalc().handleReset();
|
||||
handleOperation(Constants.PLUS);
|
||||
setDouble(3);
|
||||
activity.getCalc().handleResult();
|
||||
|
|
Loading…
Reference in New Issue