Fragments
This commit is contained in:
parent
009f536772
commit
726ef0795c
@ -5,16 +5,12 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator;
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.*;
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.FragmentManager;
|
|
||||||
import android.app.FragmentTransaction;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.Fragment;
|
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -77,22 +73,9 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
|
|
||||||
CalculatorKeyboardFragment.fixThemeParameters(true, theme, this.getWindow().getDecorView());
|
CalculatorKeyboardFragment.fixThemeParameters(true, theme, this.getWindow().getDecorView());
|
||||||
|
|
||||||
final FragmentManager fragmentManager = getFragmentManager();
|
createFragment(CalculatorEditorFragment.class, R.id.editorContainer, "tag");
|
||||||
|
createFragment(CalculatorDisplayFragment.class, R.id.displayContainer, "display");
|
||||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
createFragment(CalculatorKeyboardFragment.class, R.id.keyboardContainer, "keyboard");
|
||||||
final CalculatorEditorFragment editorFragment = new CalculatorEditorFragment();
|
|
||||||
fragmentTransaction.add(R.id.editorContainer, editorFragment, "editor");
|
|
||||||
fragmentTransaction.commit();
|
|
||||||
|
|
||||||
fragmentTransaction = fragmentManager.beginTransaction();
|
|
||||||
final CalculatorDisplayFragment displayFragment = new CalculatorDisplayFragment();
|
|
||||||
fragmentTransaction.add(R.id.displayContainer, displayFragment, "display");
|
|
||||||
fragmentTransaction.commit();
|
|
||||||
|
|
||||||
fragmentTransaction = fragmentManager.beginTransaction();
|
|
||||||
final CalculatorKeyboardFragment keyboardFragment = new CalculatorKeyboardFragment();
|
|
||||||
fragmentTransaction.add(R.id.keyboardContainer, keyboardFragment, "keyboard");
|
|
||||||
fragmentTransaction.commit();
|
|
||||||
|
|
||||||
if (customTitleSupported) {
|
if (customTitleSupported) {
|
||||||
try {
|
try {
|
||||||
@ -122,6 +105,26 @@ public class CalculatorActivity extends Activity implements FontSizeAdjuster, Sh
|
|||||||
preferences.registerOnSharedPreferenceChangeListener(this);
|
preferences.registerOnSharedPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createFragment(@NotNull Class<? extends Fragment> fragmentClass, int parentViewId, @NotNull String tag) {
|
||||||
|
final FragmentManager fm = getFragmentManager();
|
||||||
|
|
||||||
|
Fragment messagesFragment = fm.findFragmentByTag(tag);
|
||||||
|
|
||||||
|
final FragmentTransaction ft = fm.beginTransaction();
|
||||||
|
try {
|
||||||
|
if (messagesFragment == null) {
|
||||||
|
messagesFragment = Fragment.instantiate(this, fragmentClass.getName(), null);
|
||||||
|
ft.add(parentViewId, messagesFragment, tag);
|
||||||
|
} else {
|
||||||
|
if (messagesFragment.isDetached()) {
|
||||||
|
ft.attach(messagesFragment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
ft.commit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private AndroidCalculatorEngine getEngine() {
|
private AndroidCalculatorEngine getEngine() {
|
||||||
return ((AndroidCalculatorEngine) CalculatorLocatorImpl.getInstance().getEngine());
|
return ((AndroidCalculatorEngine) CalculatorLocatorImpl.getInstance().getEngine());
|
||||||
|
Loading…
Reference in New Issue
Block a user