history improvements

This commit is contained in:
Sergey Solovyev 2013-06-26 01:45:33 +04:00
parent d6b4863fa2
commit d8d79e85f1
12 changed files with 96 additions and 29 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 679 B

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="cpp_list_divider">#ffffffffff2e2e2e</color>
<color name="cpp_default_text_color">#ffffffff</color> <color name="cpp_default_text_color">#ffffffff</color>
<color name="cpp_display_error_text_color">#ff393939</color> <color name="cpp_display_error_text_color">#ff393939</color>
<color name="cpp_button_text_color">#ffffffff</color> <color name="cpp_button_text_color">#ffffffff</color>

View File

@ -113,6 +113,7 @@
<string name="c_calc_color_display_summary">Toggles colouring and styling in calculator editor</string> <string name="c_calc_color_display_summary">Toggles colouring and styling in calculator editor</string>
<string name="c_calc_theme_summary">Sets the theme for calculator</string> <string name="c_calc_theme_summary">Sets the theme for calculator</string>
<string name="c_clear_history">Clear history</string> <string name="c_clear_history">Clear history</string>
<string name="c_toggle_datetime">Show/hide date</string>
<string name="c_simplify_instead_of_numeric">Next constants are undefined: {0}!</string> <string name="c_simplify_instead_of_numeric">Next constants are undefined: {0}!</string>
<string name="p_grouping_separator_no">No grouping separator</string> <string name="p_grouping_separator_no">No grouping separator</string>

View File

@ -31,12 +31,17 @@
<item name="android:padding">6dp</item> <item name="android:padding">6dp</item>
</style> </style>
<style name="cpp_default_fragment_list_view_item_style"></style> <style name="cpp_default_fragment_list_view_item_style">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">match_parent</item>
<item name="android:minHeight">50dp</item>
<item name="android:gravity">center_vertical|left</item>
</style>
<style name="cpp_default_fragment_list_view_style"> <style name="cpp_default_fragment_list_view_style">
<item name="android:id">@android:id/list</item> <item name="android:id">@android:id/list</item>
<item name="android:divider">@null</item> <item name="android:dividerHeight">1dp</item>
<item name="android:dividerHeight">0dp</item> <item name="android:divider">@color/cpp_list_divider</item>
<item name="android:cacheColorHint">@android:color/transparent</item> <item name="android:cacheColorHint">@android:color/transparent</item>
<item name="android:layout_height">match_parent</item> <item name="android:layout_height">match_parent</item>
<item name="android:layout_width">match_parent</item> <item name="android:layout_width">match_parent</item>

View File

@ -149,6 +149,7 @@ public final class CalculatorPreferences {
public static class History { public static class History {
public static final Preference<Boolean> showIntermediateCalculations = BooleanPreference.of("history_show_intermediate_calculations", false); public static final Preference<Boolean> showIntermediateCalculations = BooleanPreference.of("history_show_intermediate_calculations", false);
public static final Preference<Boolean> showDatetime = BooleanPreference.of("history_show_datetime", true);
} }
@ -201,6 +202,7 @@ public final class CalculatorPreferences {
applyDefaultPreference(preferences, Graph.plotImag); applyDefaultPreference(preferences, Graph.plotImag);
applyDefaultPreference(preferences, History.showIntermediateCalculations); applyDefaultPreference(preferences, History.showIntermediateCalculations);
applyDefaultPreference(preferences, History.showDatetime);
applyDefaultPreference(preferences, Calculations.calculateOnFly); applyDefaultPreference(preferences, Calculations.calculateOnFly);
applyDefaultPreference(preferences, Calculations.preferredAngleUnits); applyDefaultPreference(preferences, Calculations.preferredAngleUnits);
applyDefaultPreference(preferences, Calculations.preferredNumeralBase); applyDefaultPreference(preferences, Calculations.preferredNumeralBase);

View File

@ -8,9 +8,7 @@
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="horizontal" a:orientation="horizontal"
style="?cpp_fragment_list_view_item_style" style="?cpp_fragment_list_view_item_style">
a:layout_width="match_parent"
a:layout_height="wrap_content">
<LinearLayout <LinearLayout

View File

@ -8,9 +8,7 @@
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
a:orientation="vertical" a:orientation="vertical"
style="?cpp_fragment_list_view_item_style" style="?cpp_fragment_list_view_item_style">
a:layout_width="fill_parent"
a:layout_height="fill_parent">
<TextView <TextView
a:id="@+id/history_time" a:id="@+id/history_time"

View File

@ -8,8 +8,15 @@
<menu xmlns:a="http://schemas.android.com/apk/res/android"> <menu xmlns:a="http://schemas.android.com/apk/res/android">
<item
a:id="@+id/history_menu_toggle_datetime"
a:icon="@drawable/kb_clock"
a:title="@string/c_toggle_datetime"
a:showAsAction="always" />
<item <item
a:id="@+id/history_menu_clear_history" a:id="@+id/history_menu_clear_history"
a:icon="@drawable/kb_remove"
a:title="@string/c_clear_history" a:title="@string/c_clear_history"
a:showAsAction="always" /> a:showAsAction="always" />

View File

@ -7,7 +7,9 @@
package org.solovyev.android.calculator.history; package org.solovyev.android.calculator.history;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -20,9 +22,8 @@ import com.actionbarsherlock.app.SherlockListFragment;
import com.actionbarsherlock.view.Menu; import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater; import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem; import com.actionbarsherlock.view.MenuItem;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.jscl.JsclOperation; import org.solovyev.android.calculator.jscl.JsclOperation;
import org.solovyev.android.menu.*; import org.solovyev.android.menu.*;
import org.solovyev.android.sherlock.menu.SherlockMenuHelper; import org.solovyev.android.sherlock.menu.SherlockMenuHelper;
@ -33,10 +34,14 @@ import org.solovyev.common.filter.Filter;
import org.solovyev.common.filter.FilterRulesChain; import org.solovyev.common.filter.FilterRulesChain;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import static org.solovyev.android.calculator.CalculatorEventType.clear_history_requested;
/** /**
* User: serso * User: serso
* Date: 10/15/11 * Date: 10/15/11
@ -80,12 +85,15 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
@Nonnull @Nonnull
private ArrayAdapter<CalculatorHistoryState> adapter; private HistoryArrayAdapter adapter;
@Nonnull @Nonnull
private CalculatorFragmentHelper fragmentHelper; private CalculatorFragmentHelper fragmentHelper;
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromResource(org.solovyev.android.calculator.R.menu.history_menu, HistoryMenu.class, SherlockMenuHelper.getInstance()); private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromResource(R.menu.history_menu, HistoryMenu.class, SherlockMenuHelper.getInstance());
@Nonnull
private final SharedPreferences.OnSharedPreferenceChangeListener preferencesListener = new HistoryOnPreferenceChangeListener();
protected AbstractCalculatorHistoryFragment(@Nonnull CalculatorFragmentType fragmentType) { protected AbstractCalculatorHistoryFragment(@Nonnull CalculatorFragmentType fragmentType) {
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId(), false); fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId(), false);
@ -115,11 +123,12 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
public void onViewCreated(View root, Bundle savedInstanceState) { public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState); super.onViewCreated(root, savedInstanceState);
logDebug("onViewCreated"); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
final Boolean showDatetime = CalculatorPreferences.History.showDatetime.getPreference(preferences);
fragmentHelper.onViewCreated(this, root); fragmentHelper.onViewCreated(this, root);
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), org.solovyev.android.calculator.R.id.history_item, new ArrayList<CalculatorHistoryState>()); adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), org.solovyev.android.calculator.R.id.history_item, new ArrayList<CalculatorHistoryState>(), showDatetime);
setListAdapter(adapter); setListAdapter(adapter);
final ListView lv = getListView(); final ListView lv = getListView();
@ -175,10 +184,13 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
this.fragmentHelper.onResume(this); this.fragmentHelper.onResume(this);
updateAdapter(); updateAdapter();
PreferenceManager.getDefaultSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(preferencesListener);
} }
@Override @Override
public void onPause() { public void onPause() {
PreferenceManager.getDefaultSharedPreferences(getActivity()).unregisterOnSharedPreferenceChangeListener(preferencesListener);
this.fragmentHelper.onPause(this); this.fragmentHelper.onPause(this);
super.onPause(); super.onPause();
@ -281,7 +293,7 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
protected abstract void clearHistory(); protected abstract void clearHistory();
@Nonnull @Nonnull
protected ArrayAdapter<CalculatorHistoryState> getAdapter() { protected HistoryArrayAdapter getAdapter() {
return adapter; return adapter;
} }
@ -297,7 +309,6 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
} }
}); });
break; break;
case clear_history_requested: case clear_history_requested:
getActivity().runOnUiThread(new Runnable() { getActivity().runOnUiThread(new Runnable() {
@Override @Override
@ -335,10 +346,19 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
private static enum HistoryMenu implements IdentifiableMenuItem<MenuItem> { private static enum HistoryMenu implements IdentifiableMenuItem<MenuItem> {
clear_history(org.solovyev.android.calculator.R.id.history_menu_clear_history) { clear_history(R.id.history_menu_clear_history) {
@Override @Override
public void onClick(@Nonnull MenuItem data, @Nonnull Context context) { public void onClick(@Nonnull MenuItem data, @Nonnull Context context) {
Locator.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.clear_history_requested, null); Locator.getInstance().getCalculator().fireCalculatorEvent(clear_history_requested, null);
}
},
toggle_datetime(R.id.history_menu_toggle_datetime) {
@Override
public void onClick(@Nonnull MenuItem data, @Nonnull Context context) {
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(CalculatorApplication.getInstance());
final Boolean showDatetime = CalculatorPreferences.History.showDatetime.getPreference(preferences);
CalculatorPreferences.History.showDatetime.putPreference(preferences, !showDatetime);
} }
}; };
@ -354,4 +374,22 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
return this.itemId; return this.itemId;
} }
} }
/*
**********************************************************************
*
* STATIC/INNER
*
**********************************************************************
*/
private final class HistoryOnPreferenceChangeListener implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
if (CalculatorPreferences.History.showDatetime.isSameKey(key)) {
getAdapter().setShowDatetime(CalculatorPreferences.History.showDatetime.getPreference(preferences));
}
}
}
} }

View File

@ -6,13 +6,14 @@
package org.solovyev.android.calculator.history; package org.solovyev.android.calculator.history;
import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import javax.annotation.Nonnull;
import org.solovyev.android.calculator.CalculatorFragmentType; import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.CalculatorPreferences; import org.solovyev.android.calculator.CalculatorPreferences;
import org.solovyev.android.calculator.Locator; import org.solovyev.android.calculator.Locator;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import javax.annotation.Nonnull;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -35,8 +36,10 @@ public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment
@Nonnull @Nonnull
@Override @Override
protected List<CalculatorHistoryState> getHistoryItems() { protected List<CalculatorHistoryState> getHistoryItems() {
final boolean showIntermediateCalculations = CalculatorPreferences.History.showIntermediateCalculations.getPreference(PreferenceManager.getDefaultSharedPreferences(getActivity())); final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
return new ArrayList<CalculatorHistoryState>(Locator.getInstance().getHistory().getStates(showIntermediateCalculations)); final boolean showIntermediateCalculations = CalculatorPreferences.History.showIntermediateCalculations.getPreference(preferences);
final List<CalculatorHistoryState> historyStates = Locator.getInstance().getHistory().getStates(showIntermediateCalculations);
return new ArrayList<CalculatorHistoryState>(historyStates);
} }
@Override @Override

View File

@ -12,17 +12,15 @@ import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import javax.annotation.Nonnull;
import org.solovyev.android.calculator.CalculatorActivityLauncher;
import org.solovyev.android.calculator.CalculatorFragmentType;
import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.R;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import static android.view.View.GONE;
import static android.view.View.INVISIBLE; import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static org.solovyev.android.calculator.CalculatorFragmentType.saved_history; import static org.solovyev.android.calculator.CalculatorFragmentType.saved_history;
@ -35,8 +33,11 @@ import static org.solovyev.android.calculator.history.AbstractCalculatorHistoryF
*/ */
public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> { public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> {
HistoryArrayAdapter(Context context, int resource, int textViewResourceId, @Nonnull List<CalculatorHistoryState> historyList) { private boolean showDatetime;
HistoryArrayAdapter(Context context, int resource, int textViewResourceId, @Nonnull List<CalculatorHistoryState> historyList, boolean showDatetime) {
super(context, resource, textViewResourceId, historyList); super(context, resource, textViewResourceId, historyList);
this.showDatetime = showDatetime;
} }
@Override @Override
@ -46,7 +47,13 @@ public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> {
final CalculatorHistoryState state = getItem(position); final CalculatorHistoryState state = getItem(position);
final TextView time = (TextView) result.findViewById(R.id.history_time); final TextView time = (TextView) result.findViewById(R.id.history_time);
if (showDatetime) {
time.setVisibility(VISIBLE);
time.setText(new SimpleDateFormat().format(new Date(state.getTime()))); time.setText(new SimpleDateFormat().format(new Date(state.getTime())));
} else {
time.setVisibility(GONE);
time.setText(null);
}
final TextView editor = (TextView) result.findViewById(R.id.history_item); final TextView editor = (TextView) result.findViewById(R.id.history_item);
editor.setText(AbstractCalculatorHistoryFragment.getHistoryText(state)); editor.setText(AbstractCalculatorHistoryFragment.getHistoryText(state));
@ -60,7 +67,7 @@ public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> {
commentLayout.setVisibility(VISIBLE); commentLayout.setVisibility(VISIBLE);
} else { } else {
commentView.setText(null); commentView.setText(null);
commentLayout.setVisibility(INVISIBLE); commentLayout.setVisibility(GONE);
} }
} }
@ -94,4 +101,11 @@ public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> {
this.setNotifyOnChange(true); this.setNotifyOnChange(true);
super.notifyDataSetChanged(); super.notifyDataSetChanged();
} }
public void setShowDatetime(boolean showDatetime) {
if (this.showDatetime != showDatetime) {
this.showDatetime = showDatetime;
notifyDataSetChanged();
}
}
} }