fixable message dialog

This commit is contained in:
Sergey Solovyev 2012-12-04 11:01:08 +04:00
parent 6991b3c7ae
commit dc25f1897c
8 changed files with 83 additions and 65 deletions

View File

@ -7,13 +7,13 @@
a:orientation="vertical"> a:orientation="vertical">
<LinearLayout <LinearLayout
a:id="@+id/calculation_messages_container" a:id="@+id/cpp_fixable_messages_container"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:orientation="vertical"/> a:orientation="vertical"/>
<CheckBox <CheckBox
a:id="@+id/do_not_show_calculation_messages_checkbox" a:id="@+id/cpp_do_not_show_fixable_messages_checkbox"
a:text="@string/do_not_show_messages_in_session" a:text="@string/do_not_show_messages_in_session"
a:layout_width="match_parent" a:layout_width="match_parent"
a:layout_height="wrap_content"/> a:layout_height="wrap_content"/>

View File

@ -6,15 +6,15 @@
a:orientation="horizontal" a:orientation="horizontal"
a:padding="6dp"> a:padding="6dp">
<TextView a:id="@+id/calculation_messages_text_view" <TextView a:id="@+id/cpp_fixable_messages_text_view"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_weight="5" a:layout_weight="5"
a:layout_gravity="fill" a:layout_gravity="fill"
a:text="@+id/calculation_messages_text_view"/> a:text="@+id/cpp_fixable_messages_text_view"/>
<Button <Button
a:id="@+id/fix_button" a:id="@+id/cpp_fix_button"
a:layout_width="0dp" a:layout_width="0dp"
a:layout_height="wrap_content" a:layout_height="wrap_content"
a:layout_weight="2" a:layout_weight="2"

View File

@ -12,27 +12,27 @@ import org.solovyev.common.msg.MessageType;
* Date: 11/17/12 * Date: 11/17/12
* Time: 6:54 PM * Time: 6:54 PM
*/ */
public class CalculatorFixableMessage implements Parcelable { public class FixableMessage implements Parcelable {
public static final Creator<CalculatorFixableMessage> CREATOR = new Creator<CalculatorFixableMessage>() { public static final Creator<FixableMessage> CREATOR = new Creator<FixableMessage>() {
@Override @Override
public CalculatorFixableMessage createFromParcel(@NotNull Parcel in) { public FixableMessage createFromParcel(@NotNull Parcel in) {
return CalculatorFixableMessage.fromParcel(in); return FixableMessage.fromParcel(in);
} }
@Override @Override
public CalculatorFixableMessage[] newArray(int size) { public FixableMessage[] newArray(int size) {
return new CalculatorFixableMessage[size]; return new FixableMessage[size];
} }
}; };
@NotNull @NotNull
private static CalculatorFixableMessage fromParcel(@NotNull Parcel in) { private static FixableMessage fromParcel(@NotNull Parcel in) {
final String message = in.readString(); final String message = in.readString();
final MessageType messageType = (MessageType) in.readSerializable(); final MessageType messageType = (MessageType) in.readSerializable();
final FixableError fixableError = (FixableError) in.readSerializable(); final FixableError fixableError = (FixableError) in.readSerializable();
return new CalculatorFixableMessage(message, messageType, fixableError); return new FixableMessage(message, messageType, fixableError);
} }
@NotNull @NotNull
@ -44,13 +44,13 @@ public class CalculatorFixableMessage implements Parcelable {
@Nullable @Nullable
private final FixableError fixableError; private final FixableError fixableError;
public CalculatorFixableMessage(@NotNull Message message) { public FixableMessage(@NotNull Message message) {
this.message = message.getLocalizedMessage(); this.message = message.getLocalizedMessage();
this.messageType = message.getMessageType(); this.messageType = message.getMessageType();
this.fixableError = CalculatorFixableError.getErrorByMessageCode(message.getMessageCode()); this.fixableError = CalculatorFixableError.getErrorByMessageCode(message.getMessageCode());
} }
public CalculatorFixableMessage(@NotNull String message, public FixableMessage(@NotNull String message,
@NotNull MessageType messageType, @NotNull MessageType messageType,
@Nullable FixableError fixableError) { @Nullable FixableError fixableError) {
this.message = message; this.message = message;

View File

@ -28,39 +28,44 @@ import java.util.List;
* Date: 11/17/12 * Date: 11/17/12
* Time: 3:37 PM * Time: 3:37 PM
*/ */
public class CalculatorMessagesDialog extends SherlockActivity { public class FixableMessagesDialog extends SherlockActivity {
private static final String INPUT = "input"; private static final String INPUT = "input";
@NotNull @NotNull
private Input input = new Input(Collections.<CalculatorFixableMessage>emptyList()); private Input input = new Input(Collections.<FixableMessage>emptyList(), false);
public CalculatorMessagesDialog() { public FixableMessagesDialog() {
} }
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.calculator_messages_dialog); setContentView(R.layout.cpp_fixable_messages_dialog);
final Intent intent = getIntent(); final Intent intent = getIntent();
if (intent != null) { if (intent != null) {
parseIntent(intent); parseIntent(intent);
} }
final CheckBox doNotShowCalculationMessagesCheckbox = (CheckBox) findViewById(R.id.do_not_show_calculation_messages_checkbox); final CheckBox doNotShowCalculationMessagesCheckbox = (CheckBox) findViewById(R.id.cpp_do_not_show_fixable_messages_checkbox);
if ( input.isShowCheckbox() ) {
doNotShowCalculationMessagesCheckbox.setVisibility(View.VISIBLE);
} else {
doNotShowCalculationMessagesCheckbox.setVisibility(View.GONE);
}
final Button closeButton = (Button) findViewById(R.id.close_button); final Button closeButton = (Button) findViewById(R.id.close_button);
closeButton.setOnClickListener(new View.OnClickListener() { closeButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (doNotShowCalculationMessagesCheckbox.isChecked()) { if (doNotShowCalculationMessagesCheckbox.isChecked()) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(CalculatorMessagesDialog.this); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(FixableMessagesDialog.this);
CalculatorPreferences.Calculations.showCalculationMessagesDialog.putPreference(prefs, false); CalculatorPreferences.Calculations.showCalculationMessagesDialog.putPreference(prefs, false);
} }
CalculatorMessagesDialog.this.finish(); FixableMessagesDialog.this.finish();
} }
}); });
} }
@ -74,19 +79,19 @@ public class CalculatorMessagesDialog extends SherlockActivity {
} }
private void onInputChanged() { private void onInputChanged() {
final ViewGroup viewGroup = (ViewGroup) findViewById(R.id.calculation_messages_container); final ViewGroup viewGroup = (ViewGroup) findViewById(R.id.cpp_fixable_messages_container);
viewGroup.removeAllViews(); viewGroup.removeAllViews();
final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final List<CalculatorFixableMessage> messages = input.getMessages(); final List<FixableMessage> messages = input.getMessages();
for (final CalculatorFixableMessage message : messages) { for (final FixableMessage message : messages) {
final View view = layoutInflater.inflate(R.layout.calculator_messages_dialog_message, null); final View view = layoutInflater.inflate(R.layout.cpp_fixable_messages_dialog_message, null);
final TextView calculationMessagesTextView = (TextView) view.findViewById(R.id.calculation_messages_text_view); final TextView calculationMessagesTextView = (TextView) view.findViewById(R.id.cpp_fixable_messages_text_view);
calculationMessagesTextView.setText(message.getMessage()); calculationMessagesTextView.setText(message.getMessage());
final Button fixButton = (Button) view.findViewById(R.id.fix_button); final Button fixButton = (Button) view.findViewById(R.id.cpp_fix_button);
final FixableError fixableError = message.getFixableError(); final FixableError fixableError = message.getFixableError();
if (fixableError == null) { if (fixableError == null) {
fixButton.setVisibility(View.GONE); fixButton.setVisibility(View.GONE);
@ -122,22 +127,26 @@ public class CalculatorMessagesDialog extends SherlockActivity {
********************************************************************** **********************************************************************
*/ */
public static void showDialogForMessages(@NotNull List<Message> messages, @NotNull Context context) { public static void showDialogForMessages(@NotNull List<Message> messages,
@NotNull Context context,
boolean showCheckbox) {
if (!messages.isEmpty()) { if (!messages.isEmpty()) {
final Intent intent = new Intent(context, CalculatorMessagesDialog.class); final Intent intent = new Intent(context, FixableMessagesDialog.class);
intent.putExtra(INPUT, Input.fromMessages(messages)); intent.putExtra(INPUT, Input.fromMessages(messages, showCheckbox));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); context.startActivity(intent);
} }
} }
public static void showDialog(@NotNull List<CalculatorFixableMessage> messages, @NotNull Context context) { public static void showDialog(@NotNull List<FixableMessage> messages,
@NotNull Context context,
boolean showCheckbox) {
if (!messages.isEmpty()) { if (!messages.isEmpty()) {
final Intent intent = new Intent(context, CalculatorMessagesDialog.class); final Intent intent = new Intent(context, FixableMessagesDialog.class);
intent.putExtra(INPUT, new Input(messages)); intent.putExtra(INPUT, new Input(messages, showCheckbox));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); context.startActivity(intent);
@ -160,21 +169,25 @@ public class CalculatorMessagesDialog extends SherlockActivity {
@NotNull @NotNull
private static Input fromParcel(@NotNull Parcel in) { private static Input fromParcel(@NotNull Parcel in) {
final List<CalculatorFixableMessage> messages = new ArrayList<CalculatorFixableMessage>(); final List<FixableMessage> messages = new ArrayList<FixableMessage>();
in.readTypedList(messages, CalculatorFixableMessage.CREATOR); boolean showCheckbox = in.readInt() == 1;
return new Input(messages); in.readTypedList(messages, FixableMessage.CREATOR);
return new Input(messages, showCheckbox);
} }
@NotNull @NotNull
private List<CalculatorFixableMessage> messages = new ArrayList<CalculatorFixableMessage>(); private List<FixableMessage> messages = new ArrayList<FixableMessage>();
private Input(@NotNull List<CalculatorFixableMessage> messages) { private boolean showCheckbox;
private Input(@NotNull List<FixableMessage> messages, boolean showCheckbox) {
this.messages = messages; this.messages = messages;
this.showCheckbox = showCheckbox;
} }
@NotNull @NotNull
public List<CalculatorFixableMessage> getMessages() { public List<FixableMessage> getMessages() {
return messages; return messages;
} }
@ -185,38 +198,43 @@ public class CalculatorMessagesDialog extends SherlockActivity {
@Override @Override
public void writeToParcel(@NotNull Parcel out, int flags) { public void writeToParcel(@NotNull Parcel out, int flags) {
out.writeInt(showCheckbox ? 1 : 0);
out.writeTypedList(messages); out.writeTypedList(messages);
} }
@NotNull @NotNull
public static Input fromMessages(@NotNull List<Message> messages) { public static Input fromMessages(@NotNull List<Message> messages, boolean showCheckbox) {
final List<CalculatorFixableMessage> stringMessages = new ArrayList<CalculatorFixableMessage>(messages.size()); final List<FixableMessage> stringMessages = new ArrayList<FixableMessage>(messages.size());
for (Message message : messages) { for (Message message : messages) {
stringMessages.add(new CalculatorFixableMessage(message)); stringMessages.add(new FixableMessage(message));
} }
return new Input(stringMessages); return new Input(stringMessages, showCheckbox);
}
public boolean isShowCheckbox() {
return showCheckbox;
} }
} }
private class FixErrorOnClickListener implements View.OnClickListener { private class FixErrorOnClickListener implements View.OnClickListener {
@NotNull @NotNull
private final List<CalculatorFixableMessage> messages; private final List<FixableMessage> messages;
@NotNull @NotNull
private final CalculatorFixableMessage currentMessage; private final FixableMessage currentMessage;
public FixErrorOnClickListener(@NotNull List<CalculatorFixableMessage> messages, public FixErrorOnClickListener(@NotNull List<FixableMessage> messages,
@NotNull CalculatorFixableMessage message) { @NotNull FixableMessage message) {
this.messages = messages; this.messages = messages;
this.currentMessage = message; this.currentMessage = message;
} }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
final List<CalculatorFixableMessage> filteredMessages = new ArrayList<CalculatorFixableMessage>(messages.size() - 1); final List<FixableMessage> filteredMessages = new ArrayList<FixableMessage>(messages.size() - 1);
for (CalculatorFixableMessage message : messages) { for (FixableMessage message : messages) {
if ( message.getFixableError() == null ) { if ( message.getFixableError() == null ) {
filteredMessages.add(message); filteredMessages.add(message);
} else if ( message.getFixableError() != currentMessage.getFixableError() ) { } else if ( message.getFixableError() != currentMessage.getFixableError() ) {
@ -227,10 +245,10 @@ public class CalculatorMessagesDialog extends SherlockActivity {
currentMessage.getFixableError().fix(); currentMessage.getFixableError().fix();
if (!filteredMessages.isEmpty()) { if (!filteredMessages.isEmpty()) {
CalculatorMessagesDialog.this.input = new Input(filteredMessages); FixableMessagesDialog.this.input = new Input(filteredMessages, FixableMessagesDialog.this.input.showCheckbox);
onInputChanged(); onInputChanged();
} else { } else {
CalculatorMessagesDialog.this.finish(); FixableMessagesDialog.this.finish();
} }
} }
} }

View File

@ -9,8 +9,8 @@ import org.jetbrains.annotations.NotNull;
import org.solovyev.android.AndroidUtils2; import org.solovyev.android.AndroidUtils2;
import org.solovyev.android.calculator.AbstractFixableError; import org.solovyev.android.calculator.AbstractFixableError;
import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.App;
import org.solovyev.android.calculator.CalculatorFixableMessage; import org.solovyev.android.calculator.FixableMessage;
import org.solovyev.android.calculator.CalculatorMessagesDialog; import org.solovyev.android.calculator.FixableMessagesDialog;
import org.solovyev.android.calculator.CalculatorPreferences; import org.solovyev.android.calculator.CalculatorPreferences;
import org.solovyev.common.msg.MessageType; import org.solovyev.common.msg.MessageType;
@ -26,7 +26,7 @@ public class CalculatorOnscreenStartActivity extends Activity {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!CalculatorPreferences.OnscreenCalculator.removeIconDialogShown.getPreference(prefs)) { if (!CalculatorPreferences.OnscreenCalculator.removeIconDialogShown.getPreference(prefs)) {
CalculatorMessagesDialog.showDialog(Arrays.asList(new CalculatorFixableMessage(getString(R.string.cpp_onscreen_remove_icon_message), MessageType.warning, new RemoveIconFixableError(this))), this); FixableMessagesDialog.showDialog(Arrays.asList(new FixableMessage(getString(R.string.cpp_onscreen_remove_icon_message), MessageType.warning, new RemoveIconFixableError(this))), this, false);
CalculatorPreferences.OnscreenCalculator.removeIconDialogShown.putPreference(prefs, true); CalculatorPreferences.OnscreenCalculator.removeIconDialogShown.putPreference(prefs, true);
} }
} }

View File

@ -39,7 +39,7 @@
<activity android:label="@string/c_history" android:name=".history.CalculatorHistoryActivity"/> <activity android:label="@string/c_history" android:name=".history.CalculatorHistoryActivity"/>
<activity android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:label="@string/calculation_messages_dialog_title" android:launchMode="singleTask" android:name=".CalculatorMessagesDialog" android:theme="@style/Theme.Sherlock.Dialog"/> <activity android:excludeFromRecents="true" android:finishOnTaskLaunch="true" android:label="@string/calculation_messages_dialog_title" android:launchMode="singleTask" android:name=".FixableMessagesDialog" android:theme="@style/Theme.Sherlock.Dialog"/>
<activity android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/> <activity android:label="@string/c_about" android:name=".about.CalculatorAboutActivity"/>

View File

@ -43,16 +43,16 @@ public class AndroidCalculatorPreferenceService implements CalculatorPreferenceS
final AngleUnit preferredAngleUnits = CalculatorPreferences.Calculations.preferredAngleUnits.getPreference(prefs); final AngleUnit preferredAngleUnits = CalculatorPreferences.Calculations.preferredAngleUnits.getPreference(prefs);
final AngleUnit angleUnits = AndroidCalculatorEngine.Preferences.angleUnit.getPreference(prefs); final AngleUnit angleUnits = AndroidCalculatorEngine.Preferences.angleUnit.getPreference(prefs);
final List<CalculatorFixableMessage> messages = new ArrayList<CalculatorFixableMessage>(2); final List<FixableMessage> messages = new ArrayList<FixableMessage>(2);
if ( numeralBase != preferredNumeralBase ) { if ( numeralBase != preferredNumeralBase ) {
messages.add(new CalculatorFixableMessage(application.getString(R.string.preferred_numeral_base_message, preferredNumeralBase.name(), numeralBase.name()), MessageType.warning, CalculatorFixableError.preferred_numeral_base)); messages.add(new FixableMessage(application.getString(R.string.preferred_numeral_base_message, preferredNumeralBase.name(), numeralBase.name()), MessageType.warning, CalculatorFixableError.preferred_numeral_base));
} }
if ( angleUnits != preferredAngleUnits ) { if ( angleUnits != preferredAngleUnits ) {
messages.add(new CalculatorFixableMessage(application.getString(R.string.preferred_angle_units_message, preferredAngleUnits.name(), angleUnits.name()), MessageType.warning, CalculatorFixableError.preferred_angle_units)); messages.add(new FixableMessage(application.getString(R.string.preferred_angle_units_message, preferredAngleUnits.name(), angleUnits.name()), MessageType.warning, CalculatorFixableError.preferred_angle_units));
} }
CalculatorMessagesDialog.showDialog(messages, application); FixableMessagesDialog.showDialog(messages, application, true);
CalculatorPreferences.Calculations.lastPreferredPreferencesCheck.putPreference(prefs, currentTime); CalculatorPreferences.Calculations.lastPreferredPreferencesCheck.putPreference(prefs, currentTime);
} }

View File

@ -166,7 +166,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if ( CalculatorPreferences.Calculations.showCalculationMessagesDialog.getPreference(prefs) ) { if ( CalculatorPreferences.Calculations.showCalculationMessagesDialog.getPreference(prefs) ) {
CalculatorMessagesDialog.showDialogForMessages(messages, context); FixableMessagesDialog.showDialogForMessages(messages, context, true);
} }
} }