fixable message dialog
This commit is contained in:
parent
6991b3c7ae
commit
dc25f1897c
@ -7,13 +7,13 @@
|
||||
a:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
a:id="@+id/calculation_messages_container"
|
||||
a:id="@+id/cpp_fixable_messages_container"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:orientation="vertical"/>
|
||||
|
||||
<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:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"/>
|
@ -6,15 +6,15 @@
|
||||
a:orientation="horizontal"
|
||||
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_height="wrap_content"
|
||||
a:layout_weight="5"
|
||||
a:layout_gravity="fill"
|
||||
a:text="@+id/calculation_messages_text_view"/>
|
||||
a:text="@+id/cpp_fixable_messages_text_view"/>
|
||||
|
||||
<Button
|
||||
a:id="@+id/fix_button"
|
||||
a:id="@+id/cpp_fix_button"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="wrap_content"
|
||||
a:layout_weight="2"
|
@ -12,27 +12,27 @@ import org.solovyev.common.msg.MessageType;
|
||||
* Date: 11/17/12
|
||||
* 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
|
||||
public CalculatorFixableMessage createFromParcel(@NotNull Parcel in) {
|
||||
return CalculatorFixableMessage.fromParcel(in);
|
||||
public FixableMessage createFromParcel(@NotNull Parcel in) {
|
||||
return FixableMessage.fromParcel(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatorFixableMessage[] newArray(int size) {
|
||||
return new CalculatorFixableMessage[size];
|
||||
public FixableMessage[] newArray(int size) {
|
||||
return new FixableMessage[size];
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
private static CalculatorFixableMessage fromParcel(@NotNull Parcel in) {
|
||||
private static FixableMessage fromParcel(@NotNull Parcel in) {
|
||||
final String message = in.readString();
|
||||
final MessageType messageType = (MessageType) in.readSerializable();
|
||||
final FixableError fixableError = (FixableError) in.readSerializable();
|
||||
|
||||
return new CalculatorFixableMessage(message, messageType, fixableError);
|
||||
return new FixableMessage(message, messageType, fixableError);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -44,13 +44,13 @@ public class CalculatorFixableMessage implements Parcelable {
|
||||
@Nullable
|
||||
private final FixableError fixableError;
|
||||
|
||||
public CalculatorFixableMessage(@NotNull Message message) {
|
||||
public FixableMessage(@NotNull Message message) {
|
||||
this.message = message.getLocalizedMessage();
|
||||
this.messageType = message.getMessageType();
|
||||
this.fixableError = CalculatorFixableError.getErrorByMessageCode(message.getMessageCode());
|
||||
}
|
||||
|
||||
public CalculatorFixableMessage(@NotNull String message,
|
||||
public FixableMessage(@NotNull String message,
|
||||
@NotNull MessageType messageType,
|
||||
@Nullable FixableError fixableError) {
|
||||
this.message = message;
|
@ -28,39 +28,44 @@ import java.util.List;
|
||||
* Date: 11/17/12
|
||||
* Time: 3:37 PM
|
||||
*/
|
||||
public class CalculatorMessagesDialog extends SherlockActivity {
|
||||
public class FixableMessagesDialog extends SherlockActivity {
|
||||
|
||||
private static final String INPUT = "input";
|
||||
|
||||
@NotNull
|
||||
private Input input = new Input(Collections.<CalculatorFixableMessage>emptyList());
|
||||
private Input input = new Input(Collections.<FixableMessage>emptyList(), false);
|
||||
|
||||
public CalculatorMessagesDialog() {
|
||||
public FixableMessagesDialog() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.calculator_messages_dialog);
|
||||
setContentView(R.layout.cpp_fixable_messages_dialog);
|
||||
|
||||
final Intent intent = getIntent();
|
||||
if (intent != null) {
|
||||
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);
|
||||
closeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (doNotShowCalculationMessagesCheckbox.isChecked()) {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(CalculatorMessagesDialog.this);
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(FixableMessagesDialog.this);
|
||||
CalculatorPreferences.Calculations.showCalculationMessagesDialog.putPreference(prefs, false);
|
||||
}
|
||||
|
||||
CalculatorMessagesDialog.this.finish();
|
||||
FixableMessagesDialog.this.finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -74,19 +79,19 @@ public class CalculatorMessagesDialog extends SherlockActivity {
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
final LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
|
||||
final List<CalculatorFixableMessage> messages = input.getMessages();
|
||||
for (final CalculatorFixableMessage message : messages) {
|
||||
final View view = layoutInflater.inflate(R.layout.calculator_messages_dialog_message, null);
|
||||
final List<FixableMessage> messages = input.getMessages();
|
||||
for (final FixableMessage message : messages) {
|
||||
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());
|
||||
|
||||
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();
|
||||
if (fixableError == null) {
|
||||
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()) {
|
||||
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);
|
||||
|
||||
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()) {
|
||||
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);
|
||||
|
||||
context.startActivity(intent);
|
||||
@ -160,21 +169,25 @@ public class CalculatorMessagesDialog extends SherlockActivity {
|
||||
|
||||
@NotNull
|
||||
private static Input fromParcel(@NotNull Parcel in) {
|
||||
final List<CalculatorFixableMessage> messages = new ArrayList<CalculatorFixableMessage>();
|
||||
in.readTypedList(messages, CalculatorFixableMessage.CREATOR);
|
||||
return new Input(messages);
|
||||
final List<FixableMessage> messages = new ArrayList<FixableMessage>();
|
||||
boolean showCheckbox = in.readInt() == 1;
|
||||
in.readTypedList(messages, FixableMessage.CREATOR);
|
||||
return new Input(messages, showCheckbox);
|
||||
}
|
||||
|
||||
|
||||
@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.showCheckbox = showCheckbox;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<CalculatorFixableMessage> getMessages() {
|
||||
public List<FixableMessage> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
@ -185,38 +198,43 @@ public class CalculatorMessagesDialog extends SherlockActivity {
|
||||
|
||||
@Override
|
||||
public void writeToParcel(@NotNull Parcel out, int flags) {
|
||||
out.writeInt(showCheckbox ? 1 : 0);
|
||||
out.writeTypedList(messages);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Input fromMessages(@NotNull List<Message> messages) {
|
||||
final List<CalculatorFixableMessage> stringMessages = new ArrayList<CalculatorFixableMessage>(messages.size());
|
||||
public static Input fromMessages(@NotNull List<Message> messages, boolean showCheckbox) {
|
||||
final List<FixableMessage> stringMessages = new ArrayList<FixableMessage>(messages.size());
|
||||
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 {
|
||||
|
||||
@NotNull
|
||||
private final List<CalculatorFixableMessage> messages;
|
||||
private final List<FixableMessage> messages;
|
||||
|
||||
@NotNull
|
||||
private final CalculatorFixableMessage currentMessage;
|
||||
private final FixableMessage currentMessage;
|
||||
|
||||
public FixErrorOnClickListener(@NotNull List<CalculatorFixableMessage> messages,
|
||||
@NotNull CalculatorFixableMessage message) {
|
||||
public FixErrorOnClickListener(@NotNull List<FixableMessage> messages,
|
||||
@NotNull FixableMessage message) {
|
||||
this.messages = messages;
|
||||
this.currentMessage = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final List<CalculatorFixableMessage> filteredMessages = new ArrayList<CalculatorFixableMessage>(messages.size() - 1);
|
||||
for (CalculatorFixableMessage message : messages) {
|
||||
final List<FixableMessage> filteredMessages = new ArrayList<FixableMessage>(messages.size() - 1);
|
||||
for (FixableMessage message : messages) {
|
||||
if ( message.getFixableError() == null ) {
|
||||
filteredMessages.add(message);
|
||||
} else if ( message.getFixableError() != currentMessage.getFixableError() ) {
|
||||
@ -227,10 +245,10 @@ public class CalculatorMessagesDialog extends SherlockActivity {
|
||||
currentMessage.getFixableError().fix();
|
||||
|
||||
if (!filteredMessages.isEmpty()) {
|
||||
CalculatorMessagesDialog.this.input = new Input(filteredMessages);
|
||||
FixableMessagesDialog.this.input = new Input(filteredMessages, FixableMessagesDialog.this.input.showCheckbox);
|
||||
onInputChanged();
|
||||
} else {
|
||||
CalculatorMessagesDialog.this.finish();
|
||||
FixableMessagesDialog.this.finish();
|
||||
}
|
||||
}
|
||||
}
|
@ -9,8 +9,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.AndroidUtils2;
|
||||
import org.solovyev.android.calculator.AbstractFixableError;
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.CalculatorFixableMessage;
|
||||
import org.solovyev.android.calculator.CalculatorMessagesDialog;
|
||||
import org.solovyev.android.calculator.FixableMessage;
|
||||
import org.solovyev.android.calculator.FixableMessagesDialog;
|
||||
import org.solovyev.android.calculator.CalculatorPreferences;
|
||||
import org.solovyev.common.msg.MessageType;
|
||||
|
||||
@ -26,7 +26,7 @@ public class CalculatorOnscreenStartActivity extends Activity {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
<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"/>
|
||||
|
||||
|
@ -43,16 +43,16 @@ public class AndroidCalculatorPreferenceService implements CalculatorPreferenceS
|
||||
final AngleUnit preferredAngleUnits = CalculatorPreferences.Calculations.preferredAngleUnits.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 ) {
|
||||
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 ) {
|
||||
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);
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ public final class CalculatorActivityLauncher implements CalculatorEventListener
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
if ( CalculatorPreferences.Calculations.showCalculationMessagesDialog.getPreference(prefs) ) {
|
||||
CalculatorMessagesDialog.showDialogForMessages(messages, context);
|
||||
FixableMessagesDialog.showDialogForMessages(messages, context, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user