FAB for variables and functions view

This commit is contained in:
serso 2015-01-28 12:04:37 +01:00
parent c151b6573d
commit 77e1570088
12 changed files with 103 additions and 173 deletions

View File

@ -26,25 +26,21 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
import android.text.ClipboardManager;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.view.Menu; import android.text.ClipboardManager;
import android.view.MenuInflater; import android.view.View;
import android.view.MenuItem; import android.widget.ListView;
import com.melnykov.fab.FloatingActionButton;
import jscl.math.function.Function; import jscl.math.function.Function;
import jscl.math.function.IFunction; import jscl.math.function.IFunction;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.function.FunctionEditDialogFragment; import org.solovyev.android.calculator.function.FunctionEditDialogFragment;
import org.solovyev.android.menu.AMenuItem; import org.solovyev.android.menu.AMenuItem;
import org.solovyev.android.menu.LabeledMenuItem; import org.solovyev.android.menu.LabeledMenuItem;
import org.solovyev.common.text.Strings; import org.solovyev.common.text.Strings;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -70,7 +66,7 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
if (bundle != null) { if (bundle != null) {
final Parcelable parcelable = bundle.getParcelable(CREATE_FUNCTION_EXTRA); final Parcelable parcelable = bundle.getParcelable(CREATE_FUNCTION_EXTRA);
if (parcelable instanceof FunctionEditDialogFragment.Input) { if (parcelable instanceof FunctionEditDialogFragment.Input) {
FunctionEditDialogFragment.showDialog((FunctionEditDialogFragment.Input) parcelable, this.getActivity().getSupportFragmentManager()); FunctionEditDialogFragment.showDialog((FunctionEditDialogFragment.Input) parcelable, getFragmentManager());
// in order to stop intent for other tabs // in order to stop intent for other tabs
bundle.remove(CREATE_FUNCTION_EXTRA); bundle.remove(CREATE_FUNCTION_EXTRA);
@ -81,6 +77,22 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
} }
@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
final ListView lv = getListView();
final FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.fab);
fab.setVisibility(View.VISIBLE);
fab.attachToListView(lv);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FunctionEditDialogFragment.showDialog(FunctionEditDialogFragment.Input.newInstance(), getFragmentManager());
}
});
}
@Override @Override
protected AMenuItem<Function> getOnClickAction() { protected AMenuItem<Function> getOnClickAction() {
return LongClickMenuItem.use; return LongClickMenuItem.use;
@ -201,36 +213,6 @@ public class CalculatorFunctionsFragment extends AbstractMathEntityListFragment<
} }
} }
/*
**********************************************************************
*
* MENU
*
**********************************************************************
*/
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.functions_menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean result;
switch (item.getItemId()) {
case R.id.menu_functions_add_function:
FunctionEditDialogFragment.showDialog(FunctionEditDialogFragment.Input.newInstance(), this.getActivity().getSupportFragmentManager());
result = true;
break;
default:
result = super.onOptionsItemSelected(item);
}
return result;
}
/* /*
********************************************************************** **********************************************************************
* *

View File

@ -24,11 +24,10 @@ package org.solovyev.android.calculator.math.edit;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.view.Menu; import android.view.View;
import android.view.MenuInflater; import android.widget.ListView;
import android.view.MenuItem; import com.melnykov.fab.FloatingActionButton;
import jscl.math.function.IConstant; import jscl.math.function.IConstant;
import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.math.MathType; import org.solovyev.android.calculator.math.MathType;
@ -65,7 +64,7 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
if (bundle != null) { if (bundle != null) {
final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING); final String varValue = bundle.getString(CREATE_VAR_EXTRA_STRING);
if (!Strings.isEmpty(varValue)) { if (!Strings.isEmpty(varValue)) {
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), this.getActivity().getSupportFragmentManager()); VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newFromValue(varValue), getFragmentManager());
// in order to stop intent for other tabs // in order to stop intent for other tabs
bundle.remove(CREATE_VAR_EXTRA_STRING); bundle.remove(CREATE_VAR_EXTRA_STRING);
@ -75,6 +74,22 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
setHasOptionsMenu(true); setHasOptionsMenu(true);
} }
@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
super.onViewCreated(root, savedInstanceState);
final ListView lv = getListView();
final FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.fab);
fab.setVisibility(View.VISIBLE);
fab.attachToListView(lv);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newInstance(), getFragmentManager());
}
});
}
@Override @Override
protected AMenuItem<IConstant> getOnClickAction() { protected AMenuItem<IConstant> getOnClickAction() {
return LongClickMenuItem.use; return LongClickMenuItem.use;
@ -144,35 +159,6 @@ public class CalculatorVarsFragment extends AbstractMathEntityListFragment<ICons
} }
} }
/*
**********************************************************************
*
* MENU
*
**********************************************************************
*/
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.vars_menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
boolean result;
switch (item.getItemId()) {
case R.id.menu_vars_add_var:
VarEditDialogFragment.showDialog(VarEditDialogFragment.Input.newInstance(), this.getActivity().getSupportFragmentManager());
result = true;
break;
default:
result = super.onOptionsItemSelected(item);
}
return result;
}
@Override @Override
public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) { public void onCalculatorEvent(@Nonnull CalculatorEventData calculatorEventData, @Nonnull CalculatorEventType calculatorEventType, @Nullable Object data) {
super.onCalculatorEvent(calculatorEventData, calculatorEventType, data); super.onCalculatorEvent(calculatorEventData, calculatorEventType, data);

Binary file not shown.

After

Width:  |  Height:  |  Size: 250 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 B

View File

@ -22,18 +22,18 @@
~ Site: http://se.solovyev.org ~ Site: http://se.solovyev.org
--> -->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:fab="http://schemas.android.com/apk/res-auto"
a:id="@+id/main_fragment_layout" a:id="@+id/main_fragment_layout"
style="?cpp_fragment_layout_style" style="?cpp_fragment_layout_style"
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">
<TextView <TextView
a:id="@+id/fragment_title" a:id="@+id/fragment_title"
a:layout_height="wrap_content" style="?cpp_fragment_title_style"
a:layout_width="match_parent" a:layout_width="match_parent"
style="?cpp_fragment_title_style" /> a:layout_height="wrap_content" />
<include layout="@layout/ad" /> <include layout="@layout/ad" />
@ -45,13 +45,7 @@
<com.melnykov.fab.FloatingActionButton <com.melnykov.fab.FloatingActionButton
a:id="@+id/fab" a:id="@+id/fab"
a:layout_width="wrap_content" style="@style/Fab"
a:layout_height="wrap_content" a:src="@drawable/ic_delete_white_36dp" />
a:layout_gravity="bottom|right"
a:layout_margin="16dp"
a:src="@drawable/ic_delete_white_36dp"
fab:fab_colorNormal="@color/cpp_metro_button"
fab:fab_colorPressed="@color/cpp_metro_button"
fab:fab_colorRipple="?attr/colorControlHighlight" />
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>

View File

@ -22,20 +22,31 @@
~ Site: http://se.solovyev.org ~ Site: http://se.solovyev.org
--> -->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout
a:id="@+id/main_fragment_layout" a:id="@+id/main_fragment_layout"
style="?cpp_fragment_layout_style" style="?cpp_fragment_layout_style"
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">
<TextView <TextView
a:id="@+id/fragment_title" a:id="@+id/fragment_title"
a:layout_height="wrap_content" style="?cpp_fragment_title_style"
a:layout_width="match_parent" a:layout_width="match_parent"
style="?cpp_fragment_title_style"/> a:layout_height="wrap_content" />
<include layout="@layout/ad"/> <include layout="@layout/ad" />
<ListView style="@style/ListView"/> <FrameLayout
a:layout_width="match_parent"
a:layout_height="match_parent">
<ListView style="@style/ListView" />
<com.melnykov.fab.FloatingActionButton
a:id="@+id/fab"
style="@style/Fab"
a:src="@drawable/ic_add_white_36dp"
a:visibility="gone" />
</FrameLayout>
</LinearLayout> </LinearLayout>

View File

@ -22,20 +22,31 @@
~ Site: http://se.solovyev.org ~ Site: http://se.solovyev.org
--> -->
<LinearLayout xmlns:a="http://schemas.android.com/apk/res/android" <LinearLayout
a:id="@+id/main_fragment_layout" a:id="@+id/main_fragment_layout"
style="?cpp_fragment_layout_style" style="?cpp_fragment_layout_style"
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">
<TextView <TextView
a:id="@+id/fragment_title" a:id="@+id/fragment_title"
a:layout_height="wrap_content" style="?cpp_fragment_title_style"
a:layout_width="match_parent" a:layout_width="match_parent"
style="?cpp_fragment_title_style"/> a:layout_height="wrap_content" />
<include layout="@layout/ad"/> <include layout="@layout/ad" />
<ListView style="@style/ListView"/> <FrameLayout
a:layout_width="match_parent"
a:layout_height="match_parent">
<ListView style="@style/ListView" />
<com.melnykov.fab.FloatingActionButton
a:id="@+id/fab"
style="@style/Fab"
a:src="@drawable/ic_add_white_36dp" />
</FrameLayout>
</LinearLayout> </LinearLayout>

View File

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2013 serso aka se.solovyev
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Contact details
~
~ Email: se.solovyev@gmail.com
~ Site: http://se.solovyev.org
-->
<menu xmlns:a="http://schemas.android.com/apk/res/android">
<item
a:id="@+id/menu_functions_add_function"
a:title="@string/c_add"
a:icon="@drawable/ab_plus"
a:showAsAction="always"/>
</menu>

View File

@ -1,32 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2013 serso aka se.solovyev
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Contact details
~
~ Email: se.solovyev@gmail.com
~ Site: http://se.solovyev.org
-->
<menu xmlns:a="http://schemas.android.com/apk/res/android">
<item
a:id="@+id/menu_vars_add_var"
a:title="@string/c_add"
a:icon="@drawable/ab_plus"
a:showAsAction="always"/>
</menu>

View File

@ -58,6 +58,16 @@
<item name="android:gravity">center_vertical|left</item> <item name="android:gravity">center_vertical|left</item>
</style> </style>
<style name="Fab">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">bottom|end</item>
<item name="android:layout_margin">16dp</item>
<item name="fab_colorNormal">@color/cpp_metro_button</item>
<item name="fab_colorPressed">@color/cpp_metro_button</item>
<item name="fab_colorRipple">?attr/colorControlHighlight</item>
</style>
<style name="ListView"> <style name="ListView">
<item name="android:id">@android:id/list</item> <item name="android:id">@android:id/list</item>
<item name="android:dividerHeight">1px</item> <item name="android:dividerHeight">1px</item>