Skip to content

Commit

Permalink
Merge branch 'repitch-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelhubert committed Jan 17, 2018
2 parents c957a3d + 23091a8 commit c4114c2
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 40 deletions.
Expand Up @@ -58,6 +58,7 @@ public class AHBottomNavigation extends FrameLayout {
// Title state
public enum TitleState {
SHOW_WHEN_ACTIVE,
SHOW_WHEN_ACTIVE_FORCE,
ALWAYS_SHOW,
ALWAYS_HIDE
}
Expand Down Expand Up @@ -278,6 +279,7 @@ private void createItems() {
addView(linearLayoutContainer, layoutParams);

if (titleState != TitleState.ALWAYS_HIDE &&
titleState != TitleState.SHOW_WHEN_ACTIVE_FORCE &&
(items.size() == MIN_ITEMS || titleState == TitleState.ALWAYS_SHOW)) {
createClassicItems(linearLayoutContainer);
} else {
Expand Down
Expand Up @@ -63,9 +63,9 @@ private void initUI() {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}

bottomNavigation = (AHBottomNavigation) findViewById(R.id.bottom_navigation);
viewPager = (AHBottomNavigationViewPager) findViewById(R.id.view_pager);
floatingActionButton = (FloatingActionButton) findViewById(R.id.floating_action_button);
bottomNavigation = findViewById(R.id.bottom_navigation);
viewPager = findViewById(R.id.view_pager);
floatingActionButton = findViewById(R.id.floating_action_button);

if (useMenuResource) {
tabColors = getApplicationContext().getResources().getIntArray(R.array.tab_colors);
Expand Down Expand Up @@ -287,11 +287,10 @@ public void updateSelectedBackgroundVisibility(boolean isVisible) {
}

/**
* Show or hide selected item background
* Set title state for bottomNavigation
*/
public void setForceTitleHide(boolean forceTitleHide) {
AHBottomNavigation.TitleState state = forceTitleHide ? AHBottomNavigation.TitleState.ALWAYS_HIDE : AHBottomNavigation.TitleState.ALWAYS_SHOW;
bottomNavigation.setTitleState(state);
public void setTitleState(AHBottomNavigation.TitleState titleState) {
bottomNavigation.setTitleState(titleState);
}

/**
Expand Down
Expand Up @@ -13,20 +13,26 @@
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.Spinner;

import com.aurelhubert.ahbottomnavigation.AHBottomNavigation;

import java.util.ArrayList;
import java.util.List;

/**
*
*/
public class DemoFragment extends Fragment {

private FrameLayout fragmentContainer;
private RecyclerView recyclerView;
private RecyclerView.LayoutManager layoutManager;

/**
* Create a new instance of the fragment
*/
Expand All @@ -37,7 +43,7 @@ public static DemoFragment newInstance(int index) {
fragment.setArguments(b);
return fragment;
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Expand All @@ -51,28 +57,28 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
return view;
}
}

/**
* Init demo settings
*/
private void initDemoSettings(View view) {

final DemoActivity demoActivity = (DemoActivity) getActivity();
final SwitchCompat switchColored = (SwitchCompat) view.findViewById(R.id.fragment_demo_switch_colored);
final SwitchCompat switchFiveItems = (SwitchCompat) view.findViewById(R.id.fragment_demo_switch_five_items);
final SwitchCompat showHideBottomNavigation = (SwitchCompat) view.findViewById(R.id.fragment_demo_show_hide);
final SwitchCompat showSelectedBackground = (SwitchCompat) view.findViewById(R.id.fragment_demo_selected_background);
final SwitchCompat switchForceTitleHide = (SwitchCompat) view.findViewById(R.id.fragment_demo_force_title_hide);
final SwitchCompat switchTranslucentNavigation = (SwitchCompat) view.findViewById(R.id.fragment_demo_translucent_navigation);

final SwitchCompat switchColored = view.findViewById(R.id.fragment_demo_switch_colored);
final SwitchCompat switchFiveItems = view.findViewById(R.id.fragment_demo_switch_five_items);
final SwitchCompat showHideBottomNavigation = view.findViewById(R.id.fragment_demo_show_hide);
final SwitchCompat showSelectedBackground = view.findViewById(R.id.fragment_demo_selected_background);
final Spinner spinnerTitleState = view.findViewById(R.id.fragment_demo_title_state);
final SwitchCompat switchTranslucentNavigation = view.findViewById(R.id.fragment_demo_translucent_navigation);
switchColored.setChecked(demoActivity.isBottomNavigationColored());
switchFiveItems.setChecked(demoActivity.getBottomNavigationNbItems() == 5);
switchTranslucentNavigation.setChecked(getActivity()
.getSharedPreferences("shared", Context.MODE_PRIVATE)
.getBoolean("translucentNavigation", false));
switchTranslucentNavigation.setVisibility(
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? View.VISIBLE : View.GONE);

switchTranslucentNavigation.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Expand Down Expand Up @@ -108,34 +114,47 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
demoActivity.updateSelectedBackgroundVisibility(isChecked);
}
});
switchForceTitleHide.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
final List<String> titleStates = new ArrayList<>();
for (AHBottomNavigation.TitleState titleState : AHBottomNavigation.TitleState.values()) {
titleStates.add(titleState.toString());
}
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, titleStates);
spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerTitleState.setAdapter(spinnerAdapter);
spinnerTitleState.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
demoActivity.setForceTitleHide(isChecked);
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
AHBottomNavigation.TitleState titleState = AHBottomNavigation.TitleState.valueOf(titleStates.get(position));
demoActivity.setTitleState(titleState);
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// do nothing
}
});
}

/**
* Init the fragment
*/
private void initDemoList(View view) {

fragmentContainer = (FrameLayout) view.findViewById(R.id.fragment_container);
recyclerView = (RecyclerView) view.findViewById(R.id.fragment_demo_recycler_view);
fragmentContainer = view.findViewById(R.id.fragment_container);
recyclerView = view.findViewById(R.id.fragment_demo_recycler_view);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);

ArrayList<String> itemsData = new ArrayList<>();
for (int i = 0; i < 50; i++) {
itemsData.add("Fragment " + getArguments().getInt("index", -1) + " / Item " + i);
}

DemoAdapter adapter = new DemoAdapter(itemsData);
recyclerView.setAdapter(adapter);
}

/**
* Refresh
*/
Expand All @@ -144,7 +163,7 @@ public void refresh() {
recyclerView.smoothScrollToPosition(0);
}
}

/**
* Called when a fragment will be displayed
*/
Expand All @@ -155,7 +174,7 @@ public void willBeDisplayed() {
fragmentContainer.startAnimation(fadeIn);
}
}

/**
* Called when a fragment will be hidden
*/
Expand Down
24 changes: 16 additions & 8 deletions demo/src/main/res/layout/fragment_demo_settings.xml
Expand Up @@ -2,7 +2,6 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin">

Expand All @@ -28,16 +27,25 @@
android:checked="false"
android:text="Show selected background" />

<android.support.v7.widget.SwitchCompat
android:id="@+id/fragment_demo_force_title_hide"
style="@style/setting"
android:checked="false"
android:text="Force title hide" />

<android.support.v7.widget.SwitchCompat
android:id="@+id/fragment_demo_translucent_navigation"
style="@style/setting"
android:checked="false"
android:text="Enable translucent navigation" />

</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="12dp"
android:text="Title State:" />

<Spinner
android:id="@+id/fragment_demo_title_state"
style="@style/setting"
android:paddingLeft="12dp"
android:paddingRight="12dp" />

</LinearLayout>

0 comments on commit c4114c2

Please sign in to comment.