pedrovgs / DraggablePanel

Android library used to create an awesome Android UI based on a draggable element similar to the last YouTube graphic component.
Apache License 2.0
2.99k stars 607 forks source link

Cannot display DraggableView #90

Open hieubeta118 opened 8 years ago

hieubeta118 commented 8 years ago

Hi everyone,

I'm meeting this problem. I can't display my layout Item inside DraggableView. This is my FragmentHomePage. When I click the SegmentGroup button then DraggableView will show up. But I dont know why my layout didnt show anything ` public class Fragment_HomePage extends BaseFragment { /* * Home Page Fragment declare / private RecyclerView recyclerView; private SegmentedGroup segmentedGroup; private ArrayList listNewsTopicArrayList; private ListTopicAdapter topicAdapter; private Stack backStack; private AutoHighlightImageView btnMenu; private boolean animating;

public LinearLayout main_content;
public static final String TAG_TIN_TUC_URL = "new_url";
public static final String TAG_VIDEO_URL = "video_url";
public static final String TAG_ARRAY_CATEGORIES = "categories";
public static final String TAG_TOP_MENU = "top_menu";
public static final String TAG_MAIN_PAGE = "url";
public static final String TAG_CATEGORY_URL = "catUrl";
public static final String TAG_TITLE = "title";
public static final String TIM_KIEM_URL = "http://m.vtv.vn/app/tim-kiem.htm";
public static final int CLEAR_RECYCLERVIEW_SELECTION = -1;

/**
 * TV Fragment Declare
 *
 */
private RecyclerView recyclerViewChannel;
private ArrayList<ListLiveVideoModel> listLiveVideoArrayList;
private ListLiveTvAdapter channelAdapter;
private FullscreenVideoLayout videoLayout;
private ViewPager viewPager;
private PagerLichAdapter pagerAdapter;
private PagerSlidingTabStrip pagerSlidingTabStrip;
private static final String TAG = "TV";
String channelName;
private DraggableView draggableView;

public static Fragment_HomePage newInstance() {
    Fragment_HomePage fragment_homePage = new Fragment_HomePage();
    return fragment_homePage;
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    return inflater.inflate(R.layout.fragment_homepage, container, false);
}

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    if (backStack == null) {
        backStack = new Stack<Fragment>();
    }
    draggableView = (DraggableView) view.findViewById(R.id.draggable_view_TV);
    hookDraggableListener();
    initDraggableView();
    /**
     * Fragment Home Page
     */
    //Menu drawer init
    initMenuDrawer(view);
    //init Recyclerview
    initRecyclerview(view);
    loadData();
    initSegmentGroup(view);
    /**
     * Fragment TV
     */
    loadDataTV();
    intiRecyclerViewTV(view);
    initLichChieuPager(view);
    videoLayout = (FullscreenVideoLayout)
            view.findViewById(R.id.videoView);
    videoLayout.setActivity(getActivity());

}

private void initDraggableView(){
    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            draggableView.setVisibility(View.GONE);
            draggableView.setClickToMaximizeEnabled(true);
            draggableView.setClickToMinimizeEnabled(true);
            draggableView.closeToRight();
        }
    }, 10);
}
private void initRecyclerview(View view) {
    //main content for fragments
    main_content = (LinearLayout) view.findViewById(R.id.main_content);
    listNewsTopicArrayList = new ArrayList<>();
    topicAdapter = new ListTopicAdapter(getActivity(), listNewsTopicArrayList);
    //recyclerView setup
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview_tab);
    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.setHasFixedSize(true);
    //devider between each item
    recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(),
            DividerItemDecoration.HORIZONTAL_LIST));
    recyclerView.setAdapter(topicAdapter);
    /**
     * click recyclerView item to display fragments below
     */
    recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(),
            new RecyclerItemClickListener.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    segmentedGroup.clearCheck();
                    topicAdapter.setSelecteditem(position);
                    final ListNewsTopic listNewsTopic = listNewsTopicArrayList.get(position);
                    Fragment newFragment = new FragmentWebView();

                    Bundle args = new Bundle();
                    args.putString("cateUrl", listNewsTopic.getCategoryUrl());
                    newFragment.setArguments(args);
                    replaceAllFragment(newFragment);
                }
            }));

}

private void initSegmentGroup(View view) {
    RadioButton radioButton = (RadioButton) view.findViewById(R.id.btn_trangchu);
    radioButton.setChecked(true);
    pushFragment(Fragment_TrangChu.newInStance());

    /**
     * Top Menu segment init
     */
    segmentedGroup = (SegmentedGroup) view.findViewById(R.id.segmented);
    segmentedGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            topicAdapter.setSelecteditem(CLEAR_RECYCLERVIEW_SELECTION);
            switch (checkedId) {
                case R.id.btn_trangchu:
                    replaceAllFragment(Fragment_TrangChu.newInStance());
                    return;
                case R.id.btn_tintuc:
                    replaceAllFragment(Fragment_TinTuc.newInStance());
                    return;
                case R.id.btn_video:
                    //onClick To show DraggableView
                    draggableView.setVisibility(View.VISIBLE);
                    draggableView.maximize();
                    return;
                default:
            }
        }
    });
}

private void initMenuDrawer(View view) {
    View customView = View.inflate(getActivity(), R.layout.menu_drawer_layout, null);
    final Drawer result = new DrawerBuilder()
            .withActivity(getActivity())
            .withCustomView(customView)
            .build();
    btnMenu = (AutoHighlightImageView) view.findViewById(R.id.btn_menu);
    btnMenu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            result.openDrawer();
            result.getDrawerLayout();
        }
    });
    RelativeLayout relativeLayout_search = (RelativeLayout) customView.findViewById(R.id.menu_search);
    relativeLayout_search.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            result.closeDrawer();
            segmentedGroup.clearCheck();
            Fragment newFragment = new FragmentWebView();

            Bundle args = new Bundle();
            args.putString("cateUrl", TIM_KIEM_URL);
            newFragment.setArguments(args);
            replaceAllFragment(newFragment);
        }
    });
    RelativeLayout relativeLayout_Offline = (RelativeLayout) customView.findViewById(R.id.menu_offline);
    relativeLayout_Offline.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            result.closeDrawer();
            ((HomeActivity) getActivity()).pushFragment(Fragment_Offline.newInstance());
        }
    });
    RelativeLayout relativeLayout_Font = (RelativeLayout) customView.findViewById(R.id.menu_options);
    relativeLayout_Font.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            result.closeDrawer();
            ((HomeActivity) getActivity()).pushFragment(Fragment_FontSetting.newInstance());
        }
    });

}

private void loadData() {
    listNewsTopicArrayList.clear();
    topicAdapter.notifyDataSetChanged();
    ServiceManager.getInstance().getSourceLink(new Callback<JsonObject>() {
        @Override
        public void success(JsonObject jsonObject, Response response) {
            try {
                JSONObject responseObject = new JSONObject(jsonObject.toString());
                JSONArray results = responseObject.getJSONArray(TAG_ARRAY_CATEGORIES);
                Log.i("getResults", String.valueOf(results));
                for (int i = 0; i < results.length(); i++) {
                    final ListNewsTopic newsTopicItem = new ListNewsTopic();
                    JSONObject topicObject = results.getJSONObject(i);
                    newsTopicItem.setCateTitle(topicObject.optString(TAG_TITLE));
                    newsTopicItem.setCategoryUrl(topicObject.optString(TAG_CATEGORY_URL));
                    Log.i("getCateUrl", topicObject.optString(TAG_CATEGORY_URL));
                    listNewsTopicArrayList.add(newsTopicItem);
                }
            } catch (JSONException e) {
                e.getMessage();
                e.printStackTrace();
            } finally {
                topicAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void failure(RetrofitError error) {
            Log.i("getError", String.valueOf(error));
        }
    });
}

public void pushFragment(Fragment fragment) {
    pushFragment(fragment, true);
}

public void replaceTopFragment(Fragment fragment) {
    if (backStack.isEmpty()) {
        pushFragment(fragment);
        return;
    }
    Fragment currentFragment = backStack.pop();
    if (currentFragment instanceof BaseFragment) {
        ((BaseFragment) currentFragment).recycle();
    }
    backStack.add(fragment);
    animating = true;
    getActivity().getSupportFragmentManager()
            .beginTransaction()
            .setCustomAnimations(R.anim.back_slide_in,
                    R.anim.back_slide_out)
            .remove(currentFragment)
            .add(R.id.main_content, fragment, fragment.getClass().getName()).commit();
    getChildFragmentManager().executePendingTransactions();
    animating = false;
}

public void pushFragment(Fragment fragment, boolean animate) {
    Fragment currentFragment = backStack.isEmpty() ? null : backStack
            .peek();
    backStack.push(fragment);
    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
    animating = true;
    if (animate) {
        ft.setCustomAnimations(R.anim.slide_in, R.anim.slide_out);
    }
    if (currentFragment != null) {
        ft.remove(currentFragment);
    }
    ft.add(R.id.main_content, fragment, fragment.getClass().getName()).commitAllowingStateLoss();
    getChildFragmentManager().executePendingTransactions();
    animating = false;
}

public void popFragment() {
    popFragment(true);
}

/**
 * Pops a single fragment from backstack.
 *
 * @param animate
 */
public void popFragment(boolean animate) {
    popFragment(animate, 1);
}

public void popFragment(boolean animate, int depth) {
    if (depth < 1) {
        return;
    }
    if (backStack.size() < 2) {
        getActivity().finish();
        return;
    }
    hideKeyboard();
    Fragment currentFragment = backStack.peek();
    while (depth >= 1) {
        Fragment next = backStack.pop();
        if (next instanceof BaseFragment) {
            ((BaseFragment) next).recycle();
        }
        depth--;
        if (backStack.size() < 2) {
            break;
        }
    }
    Fragment fragment = backStack.peek();
    animating = true;
    FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
    if (animate) {
        ft.setCustomAnimations(R.anim.back_slide_in, R.anim.back_slide_out);
    }
    if (currentFragment != null) {
        ft.remove(currentFragment);
        if (currentFragment instanceof BaseFragment) {
            ((BaseFragment) currentFragment).recycle();
        }
    }
    ft.add(R.id.main_content, fragment, fragment.getClass().getName()).commitAllowingStateLoss();
    getChildFragmentManager().executePendingTransactions();
    animating = false;
}

public void replaceAllFragment(Fragment fragment) {
    if (backStack.isEmpty()) {
        pushFragment(fragment);
        return;
    }
    Fragment currentFragment = backStack.pop();
    if (currentFragment instanceof BaseFragment) {
        ((BaseFragment) currentFragment).recycle();
    }
    backStack.removeAllElements();
    backStack.add(fragment);
    animating = true;
    getActivity().getSupportFragmentManager()
            .beginTransaction()
            .setCustomAnimations(R.anim.back_slide_in,
                    R.anim.back_slide_out)
            .remove(currentFragment)
            .add(R.id.main_content, fragment, fragment.getClass().getName()).commit();
    getChildFragmentManager().executePendingTransactions();
    animating = false;
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

}
/**
 * ------------------------------------Fragment TV--------------------------
 */
private void intiRecyclerViewTV(View view){
    listLiveVideoArrayList = new ArrayList<>();
    channelAdapter = new ListLiveTvAdapter(getActivity(), listLiveVideoArrayList);

    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
    recyclerViewChannel = (RecyclerView) view.findViewById(R.id.toolbarVideo);
    linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recyclerViewChannel.setLayoutManager(linearLayoutManager);
    recyclerViewChannel.setHasFixedSize(true);
    recyclerViewChannel.setAdapter(channelAdapter);
    recyclerViewChannel.addOnItemTouchListener(new RecyclerItemClickListener(getActivity(),
            new RecyclerItemClickListener.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    channelAdapter.setSelectedItem(position);
                    final ListLiveVideoModel listLiveVideoModel =
                            listLiveVideoArrayList.get(position);
                    videoLayout.reset();

// channelName = listLiveVideoModel.getNameChannel().toLowerCase(); AppPreferences.INSTANCE.setChannelName(listLiveVideoModel.getNameChannel()); notifyViewPagerDataSetChanged(); initVideoStreaming(listLiveVideoModel.getLinkFile()); } })); } private void initVideoStreaming(String urlStream){ try{ Uri videoUri = Uri.parse(urlStream); videoLayout.setVideoURI(videoUri); videoLayout.requestFocus(); videoLayout.start();

    }catch (IOException e){
        e.printStackTrace();
        e.getMessage();
    }
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}
private void initLichChieuPager(View view){
    viewPager = (ViewPager) view.findViewById(R.id.content_channel);
    pagerAdapter = new PagerLichAdapter(getActivity(), getChildFragmentManager());
    pagerSlidingTabStrip = (PagerSlidingTabStrip) view.findViewById(R.id.tab_lich_phat);
    viewPager.setAdapter(pagerAdapter);
    pagerSlidingTabStrip.setViewPager(viewPager);
    pagerSlidingTabStrip.setOnTabReselectedListener(new PagerSlidingTabStrip.OnTabReselectedListener() {
        @Override
        public void onTabReselected(int position) {
            channelAdapter.setSelectedItem(-1);
        }
    });
}
private void notifyViewPagerDataSetChanged() {
    Log.d(TAG, "\nnotifyDataSetChanged()");
    pagerAdapter.notifyDataSetChanged();
}
private void loadDataTV(){

// listLiveVideoArrayList.clear(); // channelAdapter.notifyDataSetChanged(); ServiceManager.getInstance().getListLiveVideoItem(new Callback() { @Override public void success(JsonArray jsonElements, Response response) { try { JSONArray responseArray = new JSONArray(jsonElements.toString()); Log.i("getArray", String.valueOf(responseArray)); for (int i = 0; i < responseArray.length(); i++) { final ListLiveVideoModel liveVideoItem = new ListLiveVideoModel(); JSONObject channelObject = responseArray.getJSONObject(i); listLiveVideoArrayList.add(ParseListLiveVideo .parse(channelObject, liveVideoItem));

                }
            } catch (JSONException e) {
                e.printStackTrace();
                e.getMessage();
            } finally {
                channelAdapter.notifyDataSetChanged();
            }
        }

        @Override
        public void failure(RetrofitError error) {
            Log.i("getErrorParse", error.getMessage());
        }
    });
}
private void hookDraggableListener() {
    // TODO Auto-generated method stub
    draggableView.setDraggableListener(new DraggableListener() {
        @Override
        public void onMaximized() {
            Log.i("Draggable", "Max");
        }

        @Override
        public void onMinimized() {
            Log.i("Draggable", "Min");
        }

        @Override
        public void onClosedToLeft() {
            Log.i("Draggable", "Left");
        }

        @Override
        public void onClosedToRight() {
            Log.i("Draggable", "Right");

        }
    });
}

} This is my xml file <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/layout_homepage" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">

<RelativeLayout
    android:id="@+id/navigation_bar"
    android:layout_width="match_parent"
    android:layout_height="44dp"
    android:background="@color/colorPrimary"
    android:orientation="vertical">

    <RelativeLayout
        android:id="@+id/relative_menu_icon"
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

        <vccorp.project.cnnd.vtvnews.main.view.AutoHighlightImageView
            android:id="@+id/btn_menu"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:paddingBottom="5dp"
            android:paddingLeft="5dp"
            android:paddingTop="5dp"
            android:src="@drawable/ic_menu_setting" />
    </RelativeLayout>

    <info.hoang8f.android.segmented.SegmentedGroup xmlns:segmentedgroup="http://schemas.android.com/apk/res-auto"
        android:id="@+id/segmented"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="horizontal"
        segmentedgroup:sc_border_width="1dp"
        segmentedgroup:sc_checked_text_color="@color/colorPrimary"
        segmentedgroup:sc_corner_radius="7dp"
        segmentedgroup:sc_tint_color="#fff">

        <RadioButton
            android:id="@+id/btn_trangchu"
            style="@style/RadioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tv_main_page_toolbar"
            android:textColor="@color/white" />

        <RadioButton
            android:id="@+id/btn_tintuc"
            style="@style/RadioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tv_news_toolbar"
            android:textColor="@color/white" />

        <RadioButton
            android:id="@+id/btn_video"
            style="@style/RadioButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tv_tv_video_toolbar"
            android:textColor="@color/white" />

    </info.hoang8f.android.segmented.SegmentedGroup>

    <ImageView
        android:id="@+id/imv_notify_news"
        android:layout_width="28dp"
        android:layout_height="28dp"
        android:layout_centerVertical="true"
        android:layout_gravity="center"
        android:layout_marginRight="7dp"
        android:layout_toLeftOf="@+id/anchor"
        android:background="@drawable/ic_planet" />

    <RelativeLayout
        android:id="@+id/rel_notify_circle"
        android:layout_width="25dp"
        android:layout_height="25dp"
        android:layout_toLeftOf="@+id/anchor">

        <ImageView
            android:id="@+id/imv_notify_circle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/ic_round_notify" />

        <TextView
            android:id="@+id/tev_notify_circle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:text="5"
            android:textColor="@color/white"
            android:textSize="14dp" />
    </RelativeLayout>

    <View
        android:id="@+id/anchor"
        android:layout_width="1dp"
        android:layout_height="match_parent"
        android:layout_alignParentRight="true" />

</RelativeLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview_tab"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_below="@id/navigation_bar"
    android:background="@color/tab_bg" />

<LinearLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/recyclerview_tab"
    android:background="@color/white"
    android:orientation="vertical" />

<com.github.pedrovgs.DraggableView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:draggable_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/draggable_view_TV"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    draggable_view:bottom_view_id="@+id/linearPager"
    draggable_view:enable_minimized_horizontal_alpha_effect="true"
    draggable_view:top_view_height="200dp"
    android:visibility="gone"
    android:background="@drawable/border"
    draggable_view:top_view_id="@+id/frameLayout_videoView"
    draggable_view:top_view_margin_bottom="50dp"
    draggable_view:top_view_margin_right="10dp"
    draggable_view:top_view_resize="true"
    draggable_view:top_view_x_scale_factor="2.3"
    draggable_view:top_view_y_scale_factor="2.3">

    <include
        android:id="@+id/activity_video_layout"
        layout="@layout/activity_video"/>

</com.github.pedrovgs.DraggableView>

`

vnzlogin commented 8 years ago

Try: edit below line in DraggableView draggable_view:top_view_id="@+id/frameLayout_videoView" to draggable_view:top_view_id="@+id/activity_video_layout"