Fragments
This commit is contained in:
parent
c6c2682362
commit
ff1dd19018
@ -2,7 +2,10 @@ package org.solovyev.android.calculator;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistoryState;
|
||||
import org.solovyev.android.calculator.history.EditorHistoryState;
|
||||
import org.solovyev.common.gui.CursorControl;
|
||||
import org.solovyev.common.text.StringUtils;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
@ -77,7 +80,11 @@ public class CalculatorEditorImpl implements CalculatorEditor {
|
||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData,
|
||||
@NotNull CalculatorEventType calculatorEventType,
|
||||
@Nullable Object data) {
|
||||
//To change body of implemented methods use File | Settings | File Templates.
|
||||
if (calculatorEventType == CalculatorEventType.use_history_state) {
|
||||
final CalculatorHistoryState calculatorHistoryState = (CalculatorHistoryState)data;
|
||||
final EditorHistoryState editorState = calculatorHistoryState.getEditorState();
|
||||
this.setText(StringUtils.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -75,7 +75,21 @@ public enum CalculatorEventType {
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
engine_preferences_changed;
|
||||
engine_preferences_changed,
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* HISTORY
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
// @NotNull CalculatorHistoryState
|
||||
history_state_added,
|
||||
|
||||
// @NotNull CalculatorHistoryState
|
||||
use_history_state;
|
||||
|
||||
public boolean isOfType(@NotNull CalculatorEventType... types) {
|
||||
for (CalculatorEventType type : types) {
|
||||
|
@ -102,6 +102,7 @@ public class CalculatorHistoryImpl implements CalculatorHistory {
|
||||
public void addState(@Nullable CalculatorHistoryState currentState) {
|
||||
synchronized (history) {
|
||||
history.addState(currentState);
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.history_state_added, currentState);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,11 +23,7 @@
|
||||
<!--NOTE: a:configChanges="orientation|keyboardHidden" is needed to correct work of dialog windows (not to close them on orientation change) -->
|
||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_app_settings" android:name=".CalculatorPreferencesActivity"/>
|
||||
|
||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_app_history" android:name=".history.CalculatorHistoryFragmentActivity"/>
|
||||
|
||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_history" android:name=".history.CalculatorHistoryFragment"/>
|
||||
|
||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_saved_history" android:name=".history.CalculatorSavedHistoryFragment"/>
|
||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_history" android:name=".history.CalculatorHistoryFragmentActivity"/>
|
||||
|
||||
<activity android:configChanges="orientation|keyboardHidden" android:label="@string/c_about" android:name=".about.CalculatorAboutTabActivity"/>
|
||||
|
||||
|
@ -75,7 +75,6 @@
|
||||
<dependency>
|
||||
<groupId>org.solovyev.android</groupId>
|
||||
<artifactId>android-common-sherlock</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
|
||||
@ -101,7 +100,7 @@
|
||||
<dependency>
|
||||
<groupId>com.actionbarsherlock</groupId>
|
||||
<artifactId>library</artifactId>
|
||||
<version>4.1.0</version>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -14,51 +14,6 @@
|
||||
a:layout_gravity="center"
|
||||
a:background="@color/default_background">
|
||||
|
||||
<LinearLayout a:id="@+id/editorContainer"
|
||||
a:layout_weight="2"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp"/>
|
||||
|
||||
<LinearLayout a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/calc_left_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<include layout="@layout/calc_erase_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<LinearLayout a:id="@+id/displayContainer"
|
||||
a:layout_margin="@dimen/display_margin"
|
||||
a:layout_weight="4"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"/>
|
||||
|
||||
<include layout="@layout/calc_clear_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<include layout="@layout/calc_right_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout a:id="@+id/keyboardContainer"
|
||||
a:layout_weight="3"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp"/>
|
||||
|
||||
<include layout="@layout/main_first_pane"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
62
calculatorpp/res/layout-land/main_first_pane.xml
Normal file
62
calculatorpp/res/layout-land/main_first_pane.xml
Normal file
@ -0,0 +1,62 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ Copyright (c) 2009-2011. Created by serso aka se.solovyev.
|
||||
~ For more information, please, contact se.solovyev@gmail.com
|
||||
~ or visit http://se.solovyev.org
|
||||
-->
|
||||
<LinearLayout
|
||||
xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical"
|
||||
a:layout_gravity="center">
|
||||
|
||||
<LinearLayout a:id="@+id/editorContainer"
|
||||
a:layout_weight="2"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp"/>
|
||||
|
||||
<LinearLayout a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/calc_left_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<include layout="@layout/calc_erase_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<LinearLayout a:id="@+id/displayContainer"
|
||||
a:layout_margin="@dimen/display_margin"
|
||||
a:layout_weight="4"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"/>
|
||||
|
||||
<include layout="@layout/calc_clear_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<include layout="@layout/calc_right_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout a:id="@+id/keyboardContainer"
|
||||
a:layout_weight="3"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
@ -15,60 +15,13 @@
|
||||
a:background="@color/default_background"
|
||||
a:baselineAligned="false">
|
||||
|
||||
<LinearLayout a:orientation="vertical"
|
||||
<include layout="@layout/main_first_pane"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_width="0dp"
|
||||
a:layout_weight="1">
|
||||
|
||||
<LinearLayout a:id="@+id/editorContainer"
|
||||
a:layout_weight="2"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp"/>
|
||||
|
||||
<LinearLayout a:layout_weight="1"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp">
|
||||
|
||||
<include layout="@layout/calc_left_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<include layout="@layout/calc_erase_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<LinearLayout a:id="@+id/displayContainer"
|
||||
a:layout_margin="@dimen/display_margin"
|
||||
a:layout_weight="4"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"/>
|
||||
|
||||
<include layout="@layout/calc_clear_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
<include layout="@layout/calc_right_button"
|
||||
a:layout_margin="@dimen/button_margin"
|
||||
a:layout_width="0dp"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout a:id="@+id/keyboardContainer"
|
||||
a:layout_weight="3"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="0dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout a:id="@+id/content_second_pane"
|
||||
<LinearLayout a:id="@+id/main_second_pane"
|
||||
a:orientation="vertical"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_width="0dp"
|
||||
|
6
calculatorpp/res/layout/ad.xml
Normal file
6
calculatorpp/res/layout/ad.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:id="@+id/ad_parent_view"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="75px"/>
|
15
calculatorpp/res/layout/history_fragment.xml
Normal file
15
calculatorpp/res/layout/history_fragment.xml
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:orientation="vertical">
|
||||
|
||||
<include layout="@layout/ad"/>
|
||||
|
||||
<ListView
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="match_parent"
|
||||
a:id="@android:id/list"/>
|
||||
|
||||
</LinearLayout>
|
@ -7,15 +7,9 @@
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||
a:id="@+id/ad_parent_view"
|
||||
a:id="@+id/main_layout"
|
||||
a:orientation="vertical"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent">
|
||||
|
||||
<ListView
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_height="fill_parent"
|
||||
a:layout_weight="1"
|
||||
a:id="@android:id/list"/>
|
||||
|
||||
</LinearLayout>
|
@ -1,4 +1,5 @@
|
||||
<resources>
|
||||
<dimen name="button_margin">0.5dp</dimen>
|
||||
<dimen name="display_margin">@dimen/button_margin</dimen>
|
||||
<dimen name="display_margin">2.0dp</dimen>
|
||||
<dimen name="display_margin_land">2.5dp</dimen>
|
||||
</resources>
|
@ -12,13 +12,13 @@ import android.content.SharedPreferences;
|
||||
import android.content.pm.ActivityInfo;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.text.Html;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
import android.view.*;
|
||||
import android.widget.TextView;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import net.robotmedia.billing.BillingController;
|
||||
import net.robotmedia.billing.IBillingObserver;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -26,18 +26,16 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.FontSizeAdjuster;
|
||||
import org.solovyev.android.calculator.about.CalculatorReleaseNotesActivity;
|
||||
import org.solovyev.android.calculator.view.CalculatorAdditionalTitle;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
||||
import org.solovyev.android.calculator.history.CalculatorSavedHistoryFragment;
|
||||
import org.solovyev.android.fragments.FragmentUtils;
|
||||
import org.solovyev.android.menu.ActivityMenu;
|
||||
import org.solovyev.android.menu.AndroidMenuHelper;
|
||||
import org.solovyev.android.menu.ListActivityMenu;
|
||||
import org.solovyev.android.prefs.Preference;
|
||||
import org.solovyev.android.view.ColorButton;
|
||||
import org.solovyev.common.equals.EqualsTool;
|
||||
import org.solovyev.common.history.HistoryAction;
|
||||
import org.solovyev.common.text.StringUtils;
|
||||
|
||||
public class CalculatorActivity extends FragmentActivity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public class CalculatorActivity extends SherlockFragmentActivity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@NotNull
|
||||
public static final String TAG = "Calculator++";
|
||||
@ -47,16 +45,10 @@ public class CalculatorActivity extends FragmentActivity implements FontSizeAdju
|
||||
@Nullable
|
||||
private IBillingObserver billingObserver;
|
||||
|
||||
@NotNull
|
||||
private CalculatorPreferences.Gui.Theme theme;
|
||||
|
||||
@NotNull
|
||||
private CalculatorPreferences.Gui.Layout layout;
|
||||
|
||||
private boolean useBackAsPrev;
|
||||
|
||||
@NotNull
|
||||
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromList(CalculatorMenu.class, AndroidMenuHelper.getInstance());
|
||||
private CalculatorActivityHelper activityHelper;
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
@ -66,23 +58,30 @@ public class CalculatorActivity extends FragmentActivity implements FontSizeAdju
|
||||
|
||||
CalculatorApplication.registerOnRemoteStackTrace();
|
||||
|
||||
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
|
||||
/*final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);*/
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
|
||||
setTheme(this.theme.getThemeId());
|
||||
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
||||
|
||||
activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(layout.getLayoutId());
|
||||
activityHelper.onCreate(this, savedInstanceState);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setLayout(preferences);
|
||||
|
||||
CalculatorKeyboardFragment.fixThemeParameters(true, theme, this.getWindow().getDecorView());
|
||||
if (findViewById(R.id.main_second_pane) != null) {
|
||||
activityHelper.addTab(this, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.id.main_second_pane);
|
||||
activityHelper.addTab(this, "saved_history", CalculatorSavedHistoryFragment.class, null, R.string.c_saved_history, R.id.main_second_pane);
|
||||
activityHelper.restoreSavedTab(this);
|
||||
}
|
||||
|
||||
CalculatorKeyboardFragment.fixThemeParameters(true, activityHelper.getTheme(), this.getWindow().getDecorView());
|
||||
|
||||
FragmentUtils.createFragment(this, CalculatorEditorFragment.class, R.id.editorContainer, "editor");
|
||||
FragmentUtils.createFragment(this, CalculatorDisplayFragment.class, R.id.displayContainer, "display");
|
||||
FragmentUtils.createFragment(this, CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
|
||||
|
||||
if (customTitleSupported) {
|
||||
/*if (customTitleSupported) {
|
||||
try {
|
||||
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.calc_title);
|
||||
final CalculatorAdditionalTitle additionalAdditionalTitleText = (CalculatorAdditionalTitle)findViewById(R.id.additional_title_text);
|
||||
@ -92,7 +91,7 @@ public class CalculatorActivity extends FragmentActivity implements FontSizeAdju
|
||||
// super fix for issue with class cast in android.view.Window.setFeatureInt() (see app error reports)
|
||||
Log.e(CalculatorActivity.class.getName(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
billingObserver = new CalculatorBillingObserver(this);
|
||||
BillingController.registerObserver(billingObserver);
|
||||
@ -105,7 +104,7 @@ public class CalculatorActivity extends FragmentActivity implements FontSizeAdju
|
||||
|
||||
toggleOrientationChange(preferences);
|
||||
|
||||
CalculatorKeyboardFragment.toggleEqualsButton(preferences, this, theme, findViewById(R.id.main_layout));
|
||||
CalculatorKeyboardFragment.toggleEqualsButton(preferences, this, activityHelper.getTheme(), findViewById(R.id.main_layout));
|
||||
|
||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
@ -115,12 +114,6 @@ public class CalculatorActivity extends FragmentActivity implements FontSizeAdju
|
||||
return ((AndroidCalculator) CalculatorLocatorImpl.getInstance().getCalculator());
|
||||
}
|
||||
|
||||
private synchronized void setLayout(@NotNull SharedPreferences preferences) {
|
||||
layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
||||
|
||||
setContentView(layout.getLayoutId());
|
||||
}
|
||||
|
||||
private static void firstTimeInit(@NotNull SharedPreferences preferences, @NotNull Context context) {
|
||||
final Integer appOpenedCounter = CalculatorPreferences.appOpenedCounter.getPreference(preferences);
|
||||
if (appOpenedCounter != null) {
|
||||
@ -217,7 +210,7 @@ public class CalculatorActivity extends FragmentActivity implements FontSizeAdju
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
/* @Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
return this.menu.onPrepareOptionsMenu(this, menu);
|
||||
}
|
||||
@ -230,7 +223,7 @@ public class CalculatorActivity extends FragmentActivity implements FontSizeAdju
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
return menu.onOptionsItemSelected(this, item);
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* The font sizes in the layout files are specified for a HVGA display.
|
||||
@ -251,12 +244,12 @@ public class CalculatorActivity extends FragmentActivity implements FontSizeAdju
|
||||
super.onResume();
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
final CalculatorPreferences.Gui.Layout newLayout = CalculatorPreferences.Gui.layout.getPreference(preferences);
|
||||
final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
|
||||
if (!theme.equals(newTheme) || !layout.equals(newLayout)) {
|
||||
if ( newLayout.getLayoutId() != activityHelper.getLayoutId() ) {
|
||||
AndroidUtils.restartActivity(this);
|
||||
}
|
||||
|
||||
this.activityHelper.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -279,6 +272,13 @@ public class CalculatorActivity extends FragmentActivity implements FontSizeAdju
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
||||
activityHelper.onSaveInstanceState(this, outState);
|
||||
}
|
||||
|
||||
private void toggleOrientationChange(@Nullable SharedPreferences preferences) {
|
||||
preferences = preferences == null ? PreferenceManager.getDefaultSharedPreferences(this) : preferences;
|
||||
if (CalculatorPreferences.Gui.autoOrientation.getPreference(preferences)) {
|
||||
|
@ -1,6 +1,9 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@ -13,7 +16,24 @@ import org.jetbrains.annotations.Nullable;
|
||||
public interface CalculatorActivityHelper {
|
||||
|
||||
void onCreate(@NotNull SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState);
|
||||
void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState);
|
||||
|
||||
void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState);
|
||||
void onSaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState);
|
||||
|
||||
int getLayoutId();
|
||||
|
||||
@NotNull
|
||||
CalculatorPreferences.Gui.Theme getTheme();
|
||||
|
||||
void onResume(@NotNull SherlockFragmentActivity activity);
|
||||
void onResume(@NotNull Activity activity);
|
||||
|
||||
void addTab(@NotNull SherlockFragmentActivity activity,
|
||||
@NotNull String tag,
|
||||
@NotNull Class<? extends Fragment> fragmentClass,
|
||||
@Nullable Bundle fragmentArgs,
|
||||
int captionResId, int parentViewId);
|
||||
|
||||
void restoreSavedTab(@NotNull SherlockFragmentActivity activity);
|
||||
}
|
||||
|
@ -1,16 +1,21 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.app.Activity;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.history.CalculatorHistoryFragment;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.fragments.FragmentUtils;
|
||||
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 9/25/12
|
||||
@ -37,23 +42,37 @@ public class CalculatorActivityHelperImpl implements CalculatorActivityHelper {
|
||||
|
||||
private int layoutId;
|
||||
|
||||
private boolean showActionBarTabs = true;
|
||||
|
||||
private boolean homeIcon = false;
|
||||
|
||||
@NotNull
|
||||
private final List<String> fragmentTags = new ArrayList<String>();
|
||||
|
||||
@NotNull
|
||||
private CalculatorPreferences.Gui.Theme theme;
|
||||
private int navPosition = 0;
|
||||
|
||||
public CalculatorActivityHelperImpl(int layoutId) {
|
||||
this.layoutId = layoutId;
|
||||
}
|
||||
|
||||
public CalculatorActivityHelperImpl(int layoutId, boolean showActionBarTabs, boolean homeIcon) {
|
||||
public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
|
||||
this.layoutId = layoutId;
|
||||
this.showActionBarTabs = showActionBarTabs;
|
||||
this.homeIcon = homeIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) {
|
||||
public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
|
||||
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
|
||||
activity.setTheme(this.theme.getThemeId());
|
||||
|
||||
activity.setContentView(layoutId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@NotNull final SherlockFragmentActivity activity, @Nullable Bundle savedInstanceState) {
|
||||
this.onCreate((Activity) activity, savedInstanceState);
|
||||
|
||||
final ActionBar actionBar = activity.getSupportActionBar();
|
||||
actionBar.setDisplayUseLogoEnabled(false);
|
||||
@ -61,61 +80,73 @@ public class CalculatorActivityHelperImpl implements CalculatorActivityHelper {
|
||||
actionBar.setDisplayShowHomeEnabled(true);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
|
||||
if (showActionBarTabs) {
|
||||
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
|
||||
addTab(activity, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.drawable.icon);
|
||||
//addTab(activity, "messages", MessengerChatsFragment.class, null, R.string.c_messages, R.drawable.msg_footer_messages_icon);
|
||||
|
||||
// settings tab
|
||||
final ActionBar.Tab tab = actionBar.newTab();
|
||||
tab.setTag("settings");
|
||||
tab.setText(R.string.c_settings);
|
||||
//tab.setIcon(R.drawable.msg_footer_settings_icon);
|
||||
tab.setTabListener(new ActionBar.TabListener() {
|
||||
@Override
|
||||
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
activity.startActivity(new Intent(activity.getApplicationContext(), CalculatorPreferencesActivity.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {
|
||||
}
|
||||
});
|
||||
actionBar.addTab(tab);
|
||||
|
||||
int navPosition = -1;
|
||||
if (savedInstanceState != null) {
|
||||
navPosition = savedInstanceState.getInt(SELECTED_NAV, -1);
|
||||
navPosition = savedInstanceState.getInt(SELECTED_NAV, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if (navPosition >= 0) {
|
||||
@Override
|
||||
public void restoreSavedTab(@NotNull SherlockFragmentActivity activity) {
|
||||
final ActionBar actionBar = activity.getSupportActionBar();
|
||||
if (navPosition >= 0 && navPosition < actionBar.getTabCount()) {
|
||||
activity.getSupportActionBar().setSelectedNavigationItem(navPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
|
||||
FragmentUtils.detachFragments(activity, fragmentTags);
|
||||
|
||||
onSaveInstanceState((Activity) activity, outState);
|
||||
outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex());
|
||||
}
|
||||
|
||||
private void addTab(@NotNull SherlockFragmentActivity activity,
|
||||
@Override
|
||||
public void onSaveInstanceState(@NotNull Activity activity, @NotNull Bundle outState) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(@NotNull Activity activity) {
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
|
||||
final CalculatorPreferences.Gui.Theme newTheme = CalculatorPreferences.Gui.theme.getPreference(preferences);
|
||||
if (!theme.equals(newTheme)) {
|
||||
AndroidUtils.restartActivity(activity);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTab(@NotNull SherlockFragmentActivity activity,
|
||||
@NotNull String tag,
|
||||
@NotNull Class<? extends Fragment> fragmentClass,
|
||||
@Nullable Bundle fragmentArgs,
|
||||
int captionResId,
|
||||
int iconResId) {
|
||||
int parentViewId) {
|
||||
activity.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
||||
|
||||
final ActionBar actionBar = activity.getSupportActionBar();
|
||||
final ActionBar.Tab tab = actionBar.newTab();
|
||||
tab.setTag(tag);
|
||||
tab.setText(captionResId);
|
||||
//tab.setIcon(iconResId);
|
||||
tab.setTabListener(new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, R.id.content_second_pane));
|
||||
tab.setTabListener(new ActionBarFragmentTabListener(activity, tag, fragmentClass, fragmentArgs, parentViewId));
|
||||
actionBar.addTab(tab);
|
||||
|
||||
fragmentTags.add(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
return layoutId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public CalculatorPreferences.Gui.Theme getTheme() {
|
||||
return theme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume(@NotNull SherlockFragmentActivity activity) {
|
||||
onResume((Activity) activity);
|
||||
}
|
||||
}
|
||||
|
@ -5,19 +5,18 @@ import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 25.09.12
|
||||
* Time: 12:03
|
||||
*/
|
||||
public class CalculatorDisplayFragment extends Fragment {
|
||||
public class CalculatorDisplayFragment extends SherlockFragment {
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View view = inflater.inflate(R.layout.calc_display, null);
|
||||
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
return view;
|
||||
return inflater.inflate(R.layout.calc_display, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,21 +1,38 @@
|
||||
package org.solovyev.android.calculator;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import com.actionbarsherlock.view.Menu;
|
||||
import com.actionbarsherlock.view.MenuInflater;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.menu.ActivityMenu;
|
||||
import org.solovyev.android.menu.ListActivityMenu;
|
||||
import org.solovyev.android.sherlock.menu.SherlockMenuHelper;
|
||||
|
||||
/**
|
||||
* User: Solovyev_S
|
||||
* Date: 25.09.12
|
||||
* Time: 10:49
|
||||
*/
|
||||
public class CalculatorEditorFragment extends Fragment {
|
||||
public class CalculatorEditorFragment extends SherlockFragment {
|
||||
|
||||
@NotNull
|
||||
private ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromList(CalculatorMenu.class, SherlockMenuHelper.getInstance());
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.calc_editor, null);
|
||||
return inflater.inflate(R.layout.calc_editor, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,4 +46,19 @@ public class CalculatorEditorFragment extends Fragment {
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
this.menu.onCreateOptionsMenu(this.getActivity(), menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
this.menu.onPrepareOptionsMenu(this.getActivity(), menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
return this.menu.onOptionsItemSelected(this.getActivity(), item);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import android.view.*;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
import com.actionbarsherlock.app.SherlockFragment;
|
||||
import jscl.AngleUnit;
|
||||
import jscl.NumeralBase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -39,7 +40,7 @@ import java.util.List;
|
||||
* Date: 25.09.12
|
||||
* Time: 12:25
|
||||
*/
|
||||
public class CalculatorKeyboardFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public class CalculatorKeyboardFragment extends SherlockFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@Nullable
|
||||
private Vibrator vibrator;
|
||||
@ -73,9 +74,7 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
final View view = inflater.inflate(R.layout.calc_keyboard, null);
|
||||
view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
return view;
|
||||
return inflater.inflate(R.layout.calc_keyboard, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -3,7 +3,7 @@ package org.solovyev.android.calculator;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import com.actionbarsherlock.view.MenuItem;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.android.calculator.view.NumeralBaseConverterDialog;
|
||||
import org.solovyev.android.menu.LabeledMenuItem;
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
package org.solovyev.android.calculator.history;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@ -20,8 +19,7 @@ import com.google.ads.AdView;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.ads.AdsController;
|
||||
import org.solovyev.android.calculator.CalculatorLocatorImpl;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.*;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
import org.solovyev.android.menu.AMenuBuilder;
|
||||
import org.solovyev.android.menu.MenuImpl;
|
||||
@ -42,7 +40,7 @@ import java.util.List;
|
||||
* Date: 10/15/11
|
||||
* Time: 1:13 PM
|
||||
*/
|
||||
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment {
|
||||
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment implements CalculatorEventListener {
|
||||
|
||||
|
||||
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
|
||||
@ -67,18 +65,21 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
@Nullable
|
||||
private AdView adView;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.history_activity, null);
|
||||
return inflater.inflate(R.layout.history_fragment, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
adView = AdsController.getInstance().inflateAd(this.getActivity());
|
||||
|
||||
adapter = new HistoryArrayAdapter(this.getActivity(), getLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
||||
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
||||
setListAdapter(adapter);
|
||||
|
||||
final ListView lv = getListView();
|
||||
@ -90,7 +91,7 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
final int position,
|
||||
final long id) {
|
||||
|
||||
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position), getActivity());
|
||||
useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position));
|
||||
}
|
||||
});
|
||||
|
||||
@ -125,11 +126,8 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
adView = AdsController.getInstance().inflateAd(this.getActivity(), (ViewGroup)view.findViewById(R.id.ad_parent_view), R.id.ad_parent_view);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -140,24 +138,40 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
protected abstract int getLayoutId();
|
||||
protected abstract int getItemLayoutId();
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
final List<CalculatorHistoryState> historyList = getHistoryList();
|
||||
try {
|
||||
this.adapter.setNotifyOnChange(false);
|
||||
this.adapter.clear();
|
||||
for (CalculatorHistoryState historyState : historyList) {
|
||||
this.adapter.add(historyState);
|
||||
}
|
||||
} finally {
|
||||
this.adapter.setNotifyOnChange(true);
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||
|
||||
updateAdapter();
|
||||
}
|
||||
|
||||
this.adapter.notifyDataSetChanged();
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
|
||||
|
||||
}
|
||||
|
||||
private void updateAdapter() {
|
||||
final List<CalculatorHistoryState> historyList = getHistoryList();
|
||||
|
||||
final ArrayAdapter<CalculatorHistoryState> adapter = getAdapter();
|
||||
try {
|
||||
adapter.setNotifyOnChange(false);
|
||||
adapter.clear();
|
||||
for (CalculatorHistoryState historyState : historyList) {
|
||||
adapter.add(historyState);
|
||||
}
|
||||
} finally {
|
||||
adapter.setNotifyOnChange(true);
|
||||
}
|
||||
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public static boolean isAlreadySaved(@NotNull CalculatorHistoryState historyState) {
|
||||
@ -183,11 +197,8 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState, @NotNull Activity activity) {
|
||||
final EditorHistoryState editorState = historyState.getEditorState();
|
||||
CalculatorLocatorImpl.getInstance().getEditor().setText(StringUtils.getNotEmpty(editorState.getText(), ""), editorState.getCursorPosition());
|
||||
|
||||
activity.finish();
|
||||
public static void useHistoryItem(@NotNull final CalculatorHistoryState historyState) {
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().fireCalculatorEvent(CalculatorEventType.use_history_state, historyState);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@ -259,4 +270,16 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
protected ArrayAdapter<CalculatorHistoryState> getAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||
if ( calculatorEventType == CalculatorEventType.history_state_added ) {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateAdapter();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import java.util.List;
|
||||
public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment {
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
protected int getItemLayoutId() {
|
||||
return R.layout.history;
|
||||
}
|
||||
|
||||
|
@ -10,25 +10,28 @@ import android.os.Bundle;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.CalculatorActivityHelper;
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.*;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
* Date: 12/18/11
|
||||
* Time: 7:37 PM
|
||||
*/
|
||||
public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity {
|
||||
public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
||||
|
||||
@NotNull
|
||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(R.layout.history_activity);
|
||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(R.layout.main_empty);
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
activityHelper.onCreate(this, savedInstanceState);
|
||||
|
||||
activityHelper.addTab(this, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.id.main_layout);
|
||||
activityHelper.addTab(this, "saved_history", CalculatorSavedHistoryFragment.class, null, R.string.c_saved_history, R.id.main_layout);
|
||||
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,4 +40,25 @@ public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity
|
||||
|
||||
activityHelper.onSaveInstanceState(this, outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
activityHelper.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCalculatorEvent(@NotNull CalculatorEventData calculatorEventData, @NotNull CalculatorEventType calculatorEventType, @Nullable Object data) {
|
||||
if ( calculatorEventType == CalculatorEventType.use_history_state ) {
|
||||
this.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import java.util.List;
|
||||
public class CalculatorSavedHistoryFragment extends AbstractCalculatorHistoryFragment {
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
protected int getItemLayoutId() {
|
||||
return R.layout.saved_history;
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,7 @@ public enum HistoryItemMenuItem implements LabeledMenuItem<HistoryItemMenuData>
|
||||
use(R.string.c_use) {
|
||||
@Override
|
||||
public void onClick(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||
if (context instanceof Activity) {
|
||||
AbstractCalculatorHistoryFragment.useHistoryItem(data.getHistoryState(), (Activity) context);
|
||||
} else {
|
||||
Log.e(HistoryItemMenuItem.class.getName(), AbstractCalculatorHistoryFragment.class + " must be passed as context!");
|
||||
}
|
||||
AbstractCalculatorHistoryFragment.useHistoryItem(data.getHistoryState());
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -4,7 +4,12 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.solovyev.common.collections.CollectionsUtils;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@ -35,4 +40,46 @@ public class FragmentUtils {
|
||||
ft.commit();
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeFragments(@NotNull SherlockFragmentActivity activity, @NotNull String... fragmentTags) {
|
||||
removeFragments(activity, CollectionsUtils.asList(fragmentTags));
|
||||
}
|
||||
|
||||
public static void removeFragments(@NotNull SherlockFragmentActivity activity, @NotNull List<String> fragmentTags) {
|
||||
for (String fragmentTag : fragmentTags) {
|
||||
removeFragment(activity, fragmentTag);
|
||||
}
|
||||
}
|
||||
|
||||
public static void detachFragments(@NotNull SherlockFragmentActivity activity, @NotNull String... fragmentTags) {
|
||||
detachFragments(activity, CollectionsUtils.asList(fragmentTags));
|
||||
}
|
||||
|
||||
public static void detachFragments(@NotNull SherlockFragmentActivity activity, @NotNull List<String> fragmentTags) {
|
||||
for (String fragmentTag : fragmentTags) {
|
||||
detachFragment(activity, fragmentTag);
|
||||
}
|
||||
}
|
||||
|
||||
public static void detachFragment(@NotNull SherlockFragmentActivity activity, @NotNull String fragmentTag) {
|
||||
final Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(fragmentTag);
|
||||
if ( fragment != null ) {
|
||||
if ( !fragment.isDetached() ) {
|
||||
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
|
||||
ft.detach(fragment);
|
||||
ft.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void removeFragment(@NotNull SherlockFragmentActivity activity, @NotNull String fragmentTag) {
|
||||
final Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(fragmentTag);
|
||||
if ( fragment != null ) {
|
||||
if ( fragment.isAdded()) {
|
||||
FragmentTransaction ft = activity.getSupportFragmentManager().beginTransaction();
|
||||
ft.remove(fragment);
|
||||
ft.commit();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
pom.xml
14
pom.xml
@ -71,6 +71,20 @@
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.solovyev.android</groupId>
|
||||
<artifactId>android-common-sherlock</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.actionbarsherlock</groupId>
|
||||
<artifactId>library</artifactId>
|
||||
<version>4.0.2</version>
|
||||
<type>apklib</type>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.solovyev</groupId>
|
||||
<artifactId>jscl</artifactId>
|
||||
|
Loading…
Reference in New Issue
Block a user