Fragments
This commit is contained in:
parent
5371dbaac1
commit
fe4ba72c7a
@ -15,6 +15,6 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<gradient android:startColor="#1f1f1f" android:endColor="#1f1f1f"/>
|
<solid android:color="@color/metro_button_background"/>
|
||||||
<corners android:radius="1dp" />
|
<corners android:radius="1dp" />
|
||||||
</shape>
|
</shape>
|
@ -20,6 +20,7 @@
|
|||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_weight="1"
|
a:layout_weight="1"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
|
style="?fragmentLayoutStyle"
|
||||||
a:layout_gravity="center">
|
a:layout_gravity="center">
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/editorContainer"
|
<LinearLayout a:id="@+id/editorContainer"
|
||||||
@ -72,10 +73,10 @@
|
|||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout a:id="@+id/main_second_pane"
|
<LinearLayout a:id="@+id/main_second_pane"
|
||||||
a:orientation="vertical"
|
a:orientation="vertical"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
|
style="?secondPaneStyle"
|
||||||
a:layout_width="0dp"
|
a:layout_width="0dp"
|
||||||
a:layout_weight="1"/>
|
a:layout_weight="1"/>
|
||||||
|
|
||||||
|
@ -3,13 +3,22 @@
|
|||||||
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android"
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
|
style="?fragmentLayoutStyle"
|
||||||
a:orientation="vertical">
|
a:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView a:id="@+id/fragmentTitle"
|
||||||
|
a:layout_height="wrap_content"
|
||||||
|
a:layout_width="match_parent"
|
||||||
|
style="?fragmentTitleStyle"/>
|
||||||
|
|
||||||
<include layout="@layout/ad"/>
|
<include layout="@layout/ad"/>
|
||||||
|
|
||||||
<ListView
|
<ListView
|
||||||
a:layout_width="match_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="match_parent"
|
a:layout_height="match_parent"
|
||||||
a:id="@android:id/list"/>
|
a:id="@android:id/list"
|
||||||
|
a:divider="@null"
|
||||||
|
a:dividerHeight="0dp"
|
||||||
|
a:cacheColorHint="@android:color/transparent"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -5,5 +5,8 @@
|
|||||||
<attr name="controlButtonStyle" format="reference" />
|
<attr name="controlButtonStyle" format="reference" />
|
||||||
<attr name="controlImageButtonStyle" format="reference" />
|
<attr name="controlImageButtonStyle" format="reference" />
|
||||||
<attr name="operationButtonStyle" format="reference" />
|
<attr name="operationButtonStyle" format="reference" />
|
||||||
|
<attr name="fragmentLayoutStyle" format="reference" />
|
||||||
|
<attr name="secondPaneStyle" format="reference" />
|
||||||
|
<attr name="fragmentTitleStyle" format="reference" />
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -13,4 +13,6 @@
|
|||||||
<color name="display_error_text_color">#ff393939</color>
|
<color name="display_error_text_color">#ff393939</color>
|
||||||
<color name="selected_angle_unit_text_color">#ffffff99</color>
|
<color name="selected_angle_unit_text_color">#ffffff99</color>
|
||||||
<color name="default_background">#ff000000</color>
|
<color name="default_background">#ff000000</color>
|
||||||
|
<color name="second_pane_background">#ff1f1f1f</color>
|
||||||
|
<color name="metro_button_background">#ff1f1f1f</color>
|
||||||
</resources>
|
</resources>
|
@ -11,7 +11,7 @@
|
|||||||
<item name="android:paddingTop">6dp</item>
|
<item name="android:paddingTop">6dp</item>
|
||||||
<item name="android:paddingLeft">6dp</item>
|
<item name="android:paddingLeft">6dp</item>
|
||||||
<item name="android:paddingRight">6dp</item>
|
<item name="android:paddingRight">6dp</item>
|
||||||
<item name="android:paddingBottom">3dp</item>
|
<item name="android:paddingBottom">0dp</item>
|
||||||
<item name="android:textStyle">bold</item>
|
<item name="android:textStyle">bold</item>
|
||||||
<item name="android:textColor">@android:color/white</item>
|
<item name="android:textColor">@android:color/white</item>
|
||||||
</style>
|
</style>
|
||||||
@ -20,7 +20,7 @@
|
|||||||
<item name="android:paddingTop">0dp</item>
|
<item name="android:paddingTop">0dp</item>
|
||||||
<item name="android:paddingLeft">6dp</item>
|
<item name="android:paddingLeft">6dp</item>
|
||||||
<item name="android:paddingRight">6dp</item>
|
<item name="android:paddingRight">6dp</item>
|
||||||
<item name="android:paddingBottom">6dp</item>
|
<item name="android:paddingBottom">0dp</item>
|
||||||
<item name="android:textColor">#bebebe</item>
|
<item name="android:textColor">#bebebe</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
@ -20,10 +20,30 @@
|
|||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="default_theme">
|
<style name="default_second_pane_style">
|
||||||
|
<item name="android:background">@color/second_pane_background</item>
|
||||||
|
<item name="android:layout_margin">5dp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="default_fragment_title_style">
|
||||||
|
<item name="android:textColor">@android:color/white</item>
|
||||||
|
<item name="android:textSize">25sp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="default_fragment_layout_style">
|
||||||
|
<item name="android:layout_marginBottom">5dp</item>
|
||||||
|
<item name="android:layout_marginTop">5dp</item>
|
||||||
|
<item name="android:layout_marginLeft">5dp</item>
|
||||||
|
<item name="android:layout_marginRight">0dp</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<style name="default_theme" parent="Theme.Sherlock">
|
||||||
<item name="digitButtonStyle">@style/default_digit_button_style</item>
|
<item name="digitButtonStyle">@style/default_digit_button_style</item>
|
||||||
<item name="controlButtonStyle">@style/default_control_button_style</item>
|
<item name="controlButtonStyle">@style/default_control_button_style</item>
|
||||||
<item name="controlImageButtonStyle">@style/default_control_image_button_style</item>
|
<item name="controlImageButtonStyle">@style/default_control_image_button_style</item>
|
||||||
<item name="operationButtonStyle">@style/default_operation_button_style</item>
|
<item name="operationButtonStyle">@style/default_operation_button_style</item>
|
||||||
|
<item name="fragmentLayoutStyle">@style/default_fragment_layout_style</item>
|
||||||
|
<item name="secondPaneStyle">@style/default_second_pane_style</item>
|
||||||
|
<item name="fragmentTitleStyle">@style/default_fragment_title_style</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
@ -23,7 +23,7 @@
|
|||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="light_blue_theme">
|
<style name="light_blue_theme" parent="default_theme">
|
||||||
<item name="digitButtonStyle">@style/light_blue_digit_button_style</item>
|
<item name="digitButtonStyle">@style/light_blue_digit_button_style</item>
|
||||||
<item name="controlButtonStyle">@style/light_blue_control_button_style</item>
|
<item name="controlButtonStyle">@style/light_blue_control_button_style</item>
|
||||||
<item name="controlImageButtonStyle">@style/light_blue_control_image_button_style</item>
|
<item name="controlImageButtonStyle">@style/light_blue_control_image_button_style</item>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_blue_theme" parent="Theme.Sherlock">
|
<style name="metro_blue_theme" parent="default_theme">
|
||||||
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
||||||
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
||||||
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_green_theme">
|
<style name="metro_green_theme" parent="default_theme">
|
||||||
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
||||||
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
||||||
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="metro_purple_theme">
|
<style name="metro_purple_theme" parent="default_theme">
|
||||||
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
<item name="digitButtonStyle">@style/metro_digit_button_style</item>
|
||||||
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
<item name="controlButtonStyle">@style/metro_control_button_style</item>
|
||||||
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
<item name="controlImageButtonStyle">@style/metro_control_image_button_style</item>
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
<item name="android:padding">6dp</item>
|
<item name="android:padding">6dp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="violet_theme">
|
<style name="violet_theme" parent="default_theme">
|
||||||
<item name="digitButtonStyle">@style/violet_digit_button_style</item>
|
<item name="digitButtonStyle">@style/violet_digit_button_style</item>
|
||||||
<item name="controlButtonStyle">@style/violet_control_button_style</item>
|
<item name="controlButtonStyle">@style/violet_control_button_style</item>
|
||||||
<item name="controlImageButtonStyle">@style/violet_control_image_button_style</item>
|
<item name="controlImageButtonStyle">@style/violet_control_image_button_style</item>
|
||||||
|
@ -64,7 +64,7 @@ public class CalculatorActivity extends SherlockFragmentActivity implements Font
|
|||||||
|
|
||||||
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
final CalculatorPreferences.Gui.Layout layout = CalculatorPreferences.Gui.layout.getPreferenceNoError(preferences);
|
||||||
|
|
||||||
activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(layout.getLayoutId(), TAG);
|
activityHelper = CalculatorApplication.getInstance().createActivityHelper(layout.getLayoutId(), TAG);
|
||||||
activityHelper.logDebug("onCreate");
|
activityHelper.logDebug("onCreate");
|
||||||
activityHelper.onCreate(this, savedInstanceState);
|
activityHelper.onCreate(this, savedInstanceState);
|
||||||
|
|
||||||
|
@ -111,7 +111,12 @@ public class CalculatorApplication extends android.app.Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public CalculatorActivityHelper createCalculatorHistoryHelper(int layoutResId, @NotNull String logTag) {
|
public CalculatorActivityHelper createActivityHelper(int layoutResId, @NotNull String logTag) {
|
||||||
return new CalculatorActivityHelperImpl(layoutResId, logTag);
|
return new CalculatorActivityHelperImpl(layoutResId, logTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public CalculatorFragmentHelper createFragmentHelper() {
|
||||||
|
return new CalculatorFragmentHelperImpl();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 9/26/12
|
||||||
|
* Time: 10:14 PM
|
||||||
|
*/
|
||||||
|
public interface CalculatorFragmentHelper {
|
||||||
|
|
||||||
|
boolean isPane(@NotNull Fragment fragment);
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
package org.solovyev.android.calculator;
|
||||||
|
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: serso
|
||||||
|
* Date: 9/26/12
|
||||||
|
* Time: 10:14 PM
|
||||||
|
*/
|
||||||
|
public class CalculatorFragmentHelperImpl implements CalculatorFragmentHelper {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isPane(@NotNull Fragment fragment) {
|
||||||
|
return fragment.getActivity() instanceof CalculatorActivity;
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,7 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
import com.actionbarsherlock.app.SherlockListFragment;
|
import com.actionbarsherlock.app.SherlockListFragment;
|
||||||
import com.google.ads.AdView;
|
import com.google.ads.AdView;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@ -43,6 +44,14 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment implements CalculatorEventListener {
|
public abstract class AbstractCalculatorHistoryFragment extends SherlockListFragment implements CalculatorEventListener {
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* CONSTANTS
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static final String TAG = "CalculatorHistoryFragment";
|
private static final String TAG = "CalculatorHistoryFragment";
|
||||||
|
|
||||||
@ -61,6 +70,14 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
**********************************************************************
|
||||||
|
*
|
||||||
|
* FIELDS
|
||||||
|
*
|
||||||
|
**********************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private ArrayAdapter<CalculatorHistoryState> adapter;
|
private ArrayAdapter<CalculatorHistoryState> adapter;
|
||||||
@ -68,10 +85,15 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
|||||||
@Nullable
|
@Nullable
|
||||||
private AdView adView;
|
private AdView adView;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private CalculatorFragmentHelper fragmentHelper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper();
|
||||||
|
|
||||||
logDebug("onCreate");
|
logDebug("onCreate");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,6 +114,13 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
|||||||
|
|
||||||
logDebug("onViewCreated");
|
logDebug("onViewCreated");
|
||||||
|
|
||||||
|
final TextView fragmentTitle = (TextView) view.findViewById(R.id.fragmentTitle);
|
||||||
|
if (!fragmentHelper.isPane(this)) {
|
||||||
|
fragmentTitle.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
fragmentTitle.setText(this.getString(getFragmentTitleResId()).toUpperCase());
|
||||||
|
}
|
||||||
|
|
||||||
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList<CalculatorHistoryState>());
|
||||||
setListAdapter(adapter);
|
setListAdapter(adapter);
|
||||||
|
|
||||||
@ -143,7 +172,9 @@ public abstract class AbstractCalculatorHistoryFragment extends SherlockListFrag
|
|||||||
adView = AdsController.getInstance().inflateAd(this.getActivity(), (ViewGroup)view.findViewById(R.id.ad_parent_view), R.id.ad_parent_view);
|
adView = AdsController.getInstance().inflateAd(this.getActivity(), (ViewGroup)view.findViewById(R.id.ad_parent_view), R.id.ad_parent_view);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
protected abstract int getFragmentTitleResId();
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
logDebug("onDestroy");
|
logDebug("onDestroy");
|
||||||
|
|
||||||
|
@ -20,7 +20,12 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment {
|
public class CalculatorHistoryFragment extends AbstractCalculatorHistoryFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
protected int getFragmentTitleResId() {
|
||||||
|
return R.string.c_history;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected int getItemLayoutId() {
|
protected int getItemLayoutId() {
|
||||||
return R.layout.history;
|
return R.layout.history;
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import org.solovyev.android.calculator.*;
|
|||||||
public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
public class CalculatorHistoryFragmentActivity extends SherlockFragmentActivity implements CalculatorEventListener {
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createCalculatorHistoryHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
|
private final CalculatorActivityHelper activityHelper = CalculatorApplication.getInstance().createActivityHelper(R.layout.main_empty, CalculatorHistoryFragmentActivity.class.getSimpleName());
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
@ -20,7 +20,12 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class CalculatorSavedHistoryFragment extends AbstractCalculatorHistoryFragment {
|
public class CalculatorSavedHistoryFragment extends AbstractCalculatorHistoryFragment {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
protected int getFragmentTitleResId() {
|
||||||
|
return R.string.c_saved_history;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected int getItemLayoutId() {
|
protected int getItemLayoutId() {
|
||||||
return R.layout.saved_history;
|
return R.layout.saved_history;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user