history improvements
This commit is contained in:
parent
d6b4863fa2
commit
d8d79e85f1
BIN
android-app-core/res/drawable-xhdpi/kb_clock.png
Normal file
BIN
android-app-core/res/drawable-xhdpi/kb_clock.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
BIN
android-app-core/res/drawable-xhdpi/kb_remove.png
Normal file
BIN
android-app-core/res/drawable-xhdpi/kb_remove.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 679 B |
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="cpp_list_divider">#ffffffffff2e2e2e</color>
|
||||
<color name="cpp_default_text_color">#ffffffff</color>
|
||||
<color name="cpp_display_error_text_color">#ff393939</color>
|
||||
<color name="cpp_button_text_color">#ffffffff</color>
|
||||
|
@ -113,6 +113,7 @@
|
||||
<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_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="p_grouping_separator_no">No grouping separator</string>
|
||||
|
@ -31,12 +31,17 @@
|
||||
<item name="android:padding">6dp</item>
|
||||
</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">
|
||||
<item name="android:id">@android:id/list</item>
|
||||
<item name="android:divider">@null</item>
|
||||
<item name="android:dividerHeight">0dp</item>
|
||||
<item name="android:dividerHeight">1dp</item>
|
||||
<item name="android:divider">@color/cpp_list_divider</item>
|
||||
<item name="android:cacheColorHint">@android:color/transparent</item>
|
||||
<item name="android:layout_height">match_parent</item>
|
||||
<item name="android:layout_width">match_parent</item>
|
||||
|
@ -149,6 +149,7 @@ public final class CalculatorPreferences {
|
||||
|
||||
public static class History {
|
||||
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, History.showIntermediateCalculations);
|
||||
applyDefaultPreference(preferences, History.showDatetime);
|
||||
applyDefaultPreference(preferences, Calculations.calculateOnFly);
|
||||
applyDefaultPreference(preferences, Calculations.preferredAngleUnits);
|
||||
applyDefaultPreference(preferences, Calculations.preferredNumeralBase);
|
||||
|
@ -8,9 +8,7 @@
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:orientation="horizontal"
|
||||
style="?cpp_fragment_list_view_item_style"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content">
|
||||
style="?cpp_fragment_list_view_item_style">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
|
@ -8,9 +8,7 @@
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:orientation="vertical"
|
||||
style="?cpp_fragment_list_view_item_style"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent">
|
||||
style="?cpp_fragment_list_view_item_style">
|
||||
|
||||
<TextView
|
||||
a:id="@+id/history_time"
|
||||
|
@ -8,8 +8,15 @@
|
||||
|
||||
<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
|
||||
a:id="@+id/history_menu_clear_history"
|
||||
a:icon="@drawable/kb_remove"
|
||||
a:title="@string/c_clear_history"
|
||||
a:showAsAction="always" />
|
||||
|
||||
|
@ -7,7 +7,9 @@
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
@ -20,9 +22,8 @@ import com.actionbarsherlock.app.SherlockListFragment;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
import org.solovyev.android.menu.*;
|
||||
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.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorEventType.clear_history_requested;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 10/15/11
|
||||
@ -80,12 +85,15 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
|
||||
|
||||
@Nonnull
|
||||
private ArrayAdapter<CalculatorHistoryState> adapter;
|
||||
private HistoryArrayAdapter adapter;
|
||||
|
||||
@Nonnull
|
||||
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) {
|
||||
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) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
logDebug("onViewCreated");
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final Boolean showDatetime = CalculatorPreferences.History.showDatetime.getPreference(preferences);
|
||||
|
||||
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);
|
||||
|
||||
final ListView lv = getListView();
|
||||
@ -175,10 +184,13 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
this.fragmentHelper.onResume(this);
|
||||
|
||||
updateAdapter();
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(preferencesListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).unregisterOnSharedPreferenceChangeListener(preferencesListener);
|
||||
|
||||
this.fragmentHelper.onPause(this);
|
||||
|
||||
super.onPause();
|
||||
@ -281,7 +293,7 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
protected abstract void clearHistory();
|
||||
|
||||
@Nonnull
|
||||
protected ArrayAdapter<CalculatorHistoryState> getAdapter() {
|
||||
protected HistoryArrayAdapter getAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@ -297,7 +309,6 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
case clear_history_requested:
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
@ -335,10 +346,19 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
|
||||
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
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,13 +6,14 @@
|
||||
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import javax.annotation.Nonnull;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorPreferences;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -35,8 +36,10 @@ public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment
|
||||
@Nonnull
|
||||
@Override
|
||||
protected List<CalculatorHistoryState> getHistoryItems() {
|
||||
final boolean showIntermediateCalculations = CalculatorPreferences.History.showIntermediateCalculations.getPreference(PreferenceManager.getDefaultSharedPreferences(getActivity()));
|
||||
return new ArrayList<CalculatorHistoryState>(Locator.getInstance().getHistory().getStates(showIntermediateCalculations));
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final boolean showIntermediateCalculations = CalculatorPreferences.History.showIntermediateCalculations.getPreference(preferences);
|
||||
final List<CalculatorHistoryState> historyStates = Locator.getInstance().getHistory().getStates(showIntermediateCalculations);
|
||||
return new ArrayList<CalculatorHistoryState>(historyStates);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -12,17 +12,15 @@ import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
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.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
import static android.view.View.INVISIBLE;
|
||||
import static android.view.View.VISIBLE;
|
||||
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> {
|
||||
|
||||
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);
|
||||
this.showDatetime = showDatetime;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -46,7 +47,13 @@ public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> {
|
||||
final CalculatorHistoryState state = getItem(position);
|
||||
|
||||
final TextView time = (TextView) result.findViewById(R.id.history_time);
|
||||
if (showDatetime) {
|
||||
time.setVisibility(VISIBLE);
|
||||
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);
|
||||
editor.setText(AbstractCalculatorHistoryFragment.getHistoryText(state));
|
||||
@ -60,7 +67,7 @@ public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> {
|
||||
commentLayout.setVisibility(VISIBLE);
|
||||
} else {
|
||||
commentView.setText(null);
|
||||
commentLayout.setVisibility(INVISIBLE);
|
||||
commentLayout.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,4 +101,11 @@ public class HistoryArrayAdapter extends ArrayAdapter<CalculatorHistoryState> {
|
||||
this.setNotifyOnChange(true);
|
||||
super.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setShowDatetime(boolean showDatetime) {
|
||||
if (this.showDatetime != showDatetime) {
|
||||
this.showDatetime = showDatetime;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user