Show Widget Settings if settings button was clicked

This commit is contained in:
serso 2016-01-06 15:07:08 +01:00
parent 640580a3d8
commit 926909a62d
8 changed files with 43 additions and 32 deletions

View File

@ -25,19 +25,16 @@ package org.solovyev.android.calculator;
import android.app.Application;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import jscl.NumeralBase;
import jscl.math.Generic;
import org.solovyev.android.calculator.history.CalculatorHistoryState;
import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.common.history.HistoryAction;
import org.solovyev.common.msg.Message;
import java.util.List;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import jscl.NumeralBase;
import jscl.math.Generic;
import java.util.List;
/**
* User: serso
@ -219,6 +216,9 @@ public class AndroidCalculator implements Calculator, CalculatorEventListener, S
case show_settings_detached:
CalculatorActivityLauncher.showSettings(CalculatorApplication.getInstance(), true);
break;
case show_settings_widget:
CalculatorActivityLauncher.showWidgetSettings(CalculatorApplication.getInstance(), true);
break;
case show_like_dialog:
CalculatorActivityLauncher.likeButtonPressed(CalculatorApplication.getInstance());
break;

View File

@ -75,6 +75,12 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
showSettings(context, false);
}
public static void showWidgetSettings(@Nonnull final Context context, boolean detached) {
final Intent intent = PreferencesActivity.makeIntent(context, R.xml.preferences_widget, R.string.prefs_widget_title);
Activities.addIntentFlags(intent, detached, context);
context.startActivity(intent);
}
public static void showSettings(@Nonnull final Context context, boolean detached) {
final Intent intent = new Intent(context, PreferencesActivity.class);
Activities.addIntentFlags(intent, detached, context);

View File

@ -59,6 +59,7 @@ 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),
/*last row*/

View File

@ -174,6 +174,7 @@ public enum CalculatorEventType {
show_settings,
show_settings_detached,
show_settings_widget,
show_like_dialog,

View File

@ -24,11 +24,10 @@ package org.solovyev.android.calculator;
import org.solovyev.common.text.Strings;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
/**
* User: serso
@ -75,6 +74,13 @@ public enum CalculatorSpecialButton {
}
},
settings_widget("settings_widget") {
@Override
public void onClick(@Nonnull CalculatorKeyboard keyboard) {
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.show_settings_widget, null);
}
},
like("like") {
@Override
public void onClick(@Nonnull CalculatorKeyboard keyboard) {

View File

@ -39,28 +39,17 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import org.solovyev.android.Android;
import org.solovyev.android.Threads;
import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.CalculatorApplication;
import org.solovyev.android.calculator.CalculatorEventData;
import org.solovyev.android.calculator.CalculatorEventHolder;
import org.solovyev.android.calculator.CalculatorEventListener;
import org.solovyev.android.calculator.CalculatorEventType;
import org.solovyev.android.calculator.CalculatorFragment;
import org.solovyev.android.calculator.CalculatorUtils;
import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.preferences.PreferencesActivity;
import org.solovyev.android.menu.AMenuItem;
import org.solovyev.android.menu.ActivityMenu;
import org.solovyev.android.menu.AndroidMenuHelper;
import org.solovyev.android.menu.IdentifiableMenuItem;
import org.solovyev.android.menu.ListActivityMenu;
import org.solovyev.android.menu.*;
import org.solovyev.common.JPredicate;
import org.solovyev.common.msg.MessageType;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -70,9 +59,6 @@ import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences;
/**
@ -433,7 +419,7 @@ public abstract class AbstractCalculatorPlotFragment extends CalculatorFragment
preferences(R.id.menu_plot_settings) {
@Override
public void onClick(@Nonnull MenuItem data, @Nonnull Context context) {
PreferencesActivity.start(context, R.xml.preferences_plot, R.string.prefs_graph_screen_title);
PreferencesActivity.showPlotPreferences(context);
}
};

View File

@ -51,13 +51,17 @@ public class PreferencesActivity extends BaseActivity implements SharedPreferenc
return preferences;
}
public static void start(@Nonnull Context context, @XmlRes int preference, @StringRes int title) {
public static void showPlotPreferences(@Nonnull Context context) {
start(context, R.xml.preferences_plot, R.string.prefs_graph_screen_title);
}
private static void start(@Nonnull Context context, @XmlRes int preference, @StringRes int title) {
final Intent intent = makeIntent(context, preference, title);
context.startActivity(intent);
}
@Nonnull
static Intent makeIntent(@Nonnull Context context, @XmlRes int preference, @StringRes int title) {
public static Intent makeIntent(@Nonnull Context context, @XmlRes int preference, @StringRes int title) {
final Intent intent = new Intent(context, PreferencesActivity.class);
intent.putExtra(EXTRA_PREFERENCE, preference);
if (title != 0) {

View File

@ -111,9 +111,16 @@ public class CalculatorWidget extends AppWidgetProvider {
final RemoteViews views = new RemoteViews(context.getPackageName(), getLayout(manager, widgetId, resources, theme));
for (CalculatorButton button : CalculatorButton.values()) {
final PendingIntent intent = PendingIntent.getBroadcast(context, button.getButtonId(), newButtonClickedIntent(context, button), PendingIntent.FLAG_UPDATE_CURRENT);
final int buttonId;
if (button == CalculatorButton.settings_widget) {
// overriding default settings button behavior
buttonId = CalculatorButton.settings.getButtonId();
} else {
buttonId = button.getButtonId();
}
final PendingIntent intent = PendingIntent.getBroadcast(context, buttonId, newButtonClickedIntent(context, button), PendingIntent.FLAG_UPDATE_CURRENT);
if (intent != null) {
views.setOnClickPendingIntent(button.getButtonId(), intent);
views.setOnClickPendingIntent(buttonId, intent);
}
}