Fragments
This commit is contained in:
parent
ff1dd19018
commit
5371dbaac1
@ -15,10 +15,62 @@
|
||||
a:background="@color/default_background"
|
||||
a:baselineAligned="false">
|
||||
|
||||
<include layout="@layout/main_first_pane"
|
||||
a:layout_height="match_parent"
|
||||
a:layout_width="0dp"
|
||||
a:layout_weight="1"/>
|
||||
<LinearLayout
|
||||
a:layout_height="match_parent"
|
||||
a:layout_width="0dp"
|
||||
a:layout_weight="1"
|
||||
a:orientation="vertical"
|
||||
a:layout_gravity="center">
|
||||
|
||||
<LinearLayout a:id="@+id/editorContainer"
|
||||
a:layout_weight="4"
|
||||
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/main_second_pane"
|
||||
|
@ -38,7 +38,7 @@ import org.solovyev.common.text.StringUtils;
|
||||
public class CalculatorActivity extends SherlockFragmentActivity implements FontSizeAdjuster, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@NotNull
|
||||
public static final String TAG = "Calculator++";
|
||||
public static final String TAG = CalculatorActivity.class.getSimpleName();
|
||||
|
||||
private static final int HVGA_WIDTH_PIXELS = 320;
|
||||
|
||||
@ -64,10 +64,12 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Font
|
||||
|
||||
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
||||
|
||||
activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(layout.getLayoutId());
|
||||
activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(layout.getLayoutId(), TAG);
|
||||
activityHelper.logDebug("onCreate");
|
||||
activityHelper.onCreate(this, savedInstanceState);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
activityHelper.logDebug("super.onCreate");
|
||||
|
||||
if (findViewById(R.id.main_second_pane) != null) {
|
||||
activityHelper.addTab(this, "history", CalculatorHistoryFragment.class, null, R.string.c_history, R.id.main_second_pane);
|
||||
@ -201,29 +203,6 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Font
|
||||
getCalculator().evaluate();
|
||||
}
|
||||
|
||||
/*
|
||||
**********************************************************************
|
||||
*
|
||||
* MENU
|
||||
*
|
||||
**********************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* @Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
return this.menu.onPrepareOptionsMenu(this, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
return this.menu.onCreateOptionsMenu(this, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
return menu.onOptionsItemSelected(this, item);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* The font sizes in the layout files are specified for a HVGA display.
|
||||
@ -239,7 +218,14 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Font
|
||||
view.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontPixelSize * ratio);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
activityHelper.onPause(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
|
||||
@ -258,6 +244,8 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Font
|
||||
BillingController.unregisterObserver(billingObserver);
|
||||
}
|
||||
|
||||
activityHelper.onDestroy(this);
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ 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;
|
||||
@ -29,6 +28,8 @@ public interface CalculatorActivityHelper {
|
||||
void onResume(@NotNull SherlockFragmentActivity activity);
|
||||
void onResume(@NotNull Activity activity);
|
||||
|
||||
void onDestroy(@NotNull SherlockFragmentActivity activity);
|
||||
|
||||
void addTab(@NotNull SherlockFragmentActivity activity,
|
||||
@NotNull String tag,
|
||||
@NotNull Class<? extends Fragment> fragmentClass,
|
||||
@ -36,4 +37,8 @@ public interface CalculatorActivityHelper {
|
||||
int captionResId, int parentViewId);
|
||||
|
||||
void restoreSavedTab(@NotNull SherlockFragmentActivity activity);
|
||||
|
||||
void logDebug(@NotNull String message);
|
||||
|
||||
void onPause(@NotNull SherlockFragmentActivity activity);
|
||||
}
|
||||
|
@ -5,12 +5,12 @@ import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.util.Log;
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.AndroidUtils;
|
||||
import org.solovyev.android.fragments.FragmentUtils;
|
||||
import org.solovyev.android.sherlock.tabs.ActionBarFragmentTabListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -51,8 +51,12 @@ public class CalculatorActivityHelperImpl implements CalculatorActivityHelper {
|
||||
private CalculatorPreferences.Gui.Theme theme;
|
||||
private int navPosition = 0;
|
||||
|
||||
public CalculatorActivityHelperImpl(int layoutId) {
|
||||
@NotNull
|
||||
private String logTag = "CalculatorActivity";
|
||||
|
||||
public CalculatorActivityHelperImpl(int layoutId, @NotNull String logTag) {
|
||||
this.layoutId = layoutId;
|
||||
this.logTag = logTag;
|
||||
}
|
||||
|
||||
public CalculatorActivityHelperImpl(int layoutId, boolean homeIcon) {
|
||||
@ -62,6 +66,8 @@ public class CalculatorActivityHelperImpl implements CalculatorActivityHelper {
|
||||
|
||||
@Override
|
||||
public void onCreate(@NotNull Activity activity, @Nullable Bundle savedInstanceState) {
|
||||
Log.d(logTag + ": helper", "onCreate");
|
||||
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
|
||||
|
||||
this.theme = CalculatorPreferences.Gui.getTheme(preferences);
|
||||
@ -94,9 +100,12 @@ public class CalculatorActivityHelperImpl implements CalculatorActivityHelper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
|
||||
FragmentUtils.detachFragments(activity, fragmentTags);
|
||||
public void logDebug(@NotNull String message) {
|
||||
Log.d(logTag, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NotNull SherlockFragmentActivity activity, @NotNull Bundle outState) {
|
||||
onSaveInstanceState((Activity) activity, outState);
|
||||
outState.putInt(SELECTED_NAV, activity.getSupportActionBar().getSelectedNavigationIndex());
|
||||
}
|
||||
@ -115,6 +124,14 @@ public class CalculatorActivityHelperImpl implements CalculatorActivityHelper {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy(@NotNull SherlockFragmentActivity activity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause(@NotNull SherlockFragmentActivity activity) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTab(@NotNull SherlockFragmentActivity activity,
|
||||
@NotNull String tag,
|
||||
|
@ -111,7 +111,7 @@ public class CalculatorApplication extends android.app.Application {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public CalculatorActivityHelper createCalculatorHistoryHelper(int layoutResId) {
|
||||
return new CalculatorActivityHelperImpl(layoutResId);
|
||||
public CalculatorActivityHelper createCalculatorHistoryHelper(int layoutResId, @NotNull String logTag) {
|
||||
return new CalculatorActivityHelperImpl(layoutResId, logTag);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ package org.solovyev.android.calculator.history;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@ -42,6 +43,8 @@ import java.util.List;
|
||||
*/
|
||||
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment implements CalculatorEventListener {
|
||||
|
||||
@NotNull
|
||||
private static final String TAG = "CalculatorHistoryFragment";
|
||||
|
||||
public static final Comparator<CalculatorHistoryState> COMPARATOR = new Comparator<CalculatorHistoryState>() {
|
||||
@Override
|
||||
@ -68,17 +71,27 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
logDebug("onCreate");
|
||||
}
|
||||
|
||||
private int logDebug(@NotNull String msg) {
|
||||
return Log.d(TAG + ": " + getTag(), msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.history_fragment, container, false);
|
||||
final View result = inflater.inflate(R.layout.history_fragment, container, false);
|
||||
logDebug("onCreateView");
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
logDebug("onViewCreated");
|
||||
|
||||
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
||||
setListAdapter(adapter);
|
||||
|
||||
@ -132,7 +145,9 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
if ( this.adView != null ) {
|
||||
logDebug("onDestroy");
|
||||
|
||||
if ( this.adView != null ) {
|
||||
this.adView.destroy();
|
||||
}
|
||||
super.onDestroy();
|
||||
@ -142,7 +157,10 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
logDebug("onResume");
|
||||
|
||||
super.onResume();
|
||||
|
||||
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().addCalculatorEventListener(this);
|
||||
|
||||
@ -151,6 +169,8 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
logDebug("onPause");
|
||||
|
||||
super.onPause();
|
||||
|
||||
CalculatorLocatorImpl.getInstance().getCalculator().removeCalculatorEventListener(this);
|
||||
@ -274,9 +294,11 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
||||
@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() {
|
||||
logDebug("onCalculatorEvent");
|
||||
updateAdapter();
|
||||
}
|
||||
});
|
||||
|
@ -20,7 +20,7 @@ import org.solovyev.android.calculator.*;
|
||||
public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
||||
|
||||
@NotNull
|
||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(R.layout.main_empty);
|
||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
Loading…
Reference in New Issue
Block a user