Search in sources :

Example 6 with ListHolder

use of com.orhanobut.dialogplus.ListHolder in project dialogplus by orhanobut.

the class ListHolderTest method testHeader.

@Test
public void testHeader() {
    ListHolder holder = getListHolder();
    assertThat(holder.getHeader()).isNull();
    View header = new LinearLayout(context);
    holder.addHeader(header);
    assertThat(holder.getHeader()).isEqualTo(header);
}
Also used : View(android.view.View) ListView(android.widget.ListView) ListHolder(com.orhanobut.dialogplus.ListHolder) LinearLayout(android.widget.LinearLayout) Test(org.junit.Test)

Example 7 with ListHolder

use of com.orhanobut.dialogplus.ListHolder in project dialogplus by orhanobut.

the class ListHolderTest method testViewInflation.

@Test
public void testViewInflation() {
    ListHolder holder = new ListHolder();
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    View view = holder.getView(layoutInflater, new LinearLayout(context));
    assertThat(view).isNotNull();
    assertThat(holder.getInflatedView().getId()).isEqualTo(R.id.dialogplus_list);
    ListView listView = (ListView) holder.getInflatedView();
    assertThat(listView.getOnItemClickListener()).isInstanceOf(ListHolder.class);
}
Also used : ListView(android.widget.ListView) LayoutInflater(android.view.LayoutInflater) View(android.view.View) ListView(android.widget.ListView) ListHolder(com.orhanobut.dialogplus.ListHolder) LinearLayout(android.widget.LinearLayout) Test(org.junit.Test)

Example 8 with ListHolder

use of com.orhanobut.dialogplus.ListHolder in project dialogplus by orhanobut.

the class ListHolderTest method getListHolder.

private ListHolder getListHolder() {
    ListHolder holder = new ListHolder();
    LayoutInflater layoutInflater = LayoutInflater.from(context);
    holder.getView(layoutInflater, new LinearLayout(context));
    return holder;
}
Also used : LayoutInflater(android.view.LayoutInflater) ListHolder(com.orhanobut.dialogplus.ListHolder) LinearLayout(android.widget.LinearLayout)

Example 9 with ListHolder

use of com.orhanobut.dialogplus.ListHolder in project dialogplus by orhanobut.

the class ListHolderTest method doNotCountHeaderForPositionCalculation.

@Test
public void doNotCountHeaderForPositionCalculation() {
    ListHolder holder = getListHolder();
    holder.addHeader(new View(context));
    ListView listView = (ListView) holder.getInflatedView();
    //with adapter set
    ArrayAdapter<String> adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, new String[] { "test" });
    holder.setAdapter(adapter);
    //set listener
    holder.setOnItemClickListener(new OnHolderListener() {

        @Override
        public void onItemClick(Object item, View view, int position) {
            assertThat(String.valueOf(item)).isEqualTo("test");
            assertThat(position).isEqualTo(0);
            assertThat(view).isNull();
        }
    });
    listView.performItemClick(null, 1, 0);
}
Also used : OnHolderListener(com.orhanobut.dialogplus.OnHolderListener) ListView(android.widget.ListView) View(android.view.View) ListView(android.widget.ListView) ListHolder(com.orhanobut.dialogplus.ListHolder) ArrayAdapter(android.widget.ArrayAdapter) Test(org.junit.Test)

Example 10 with ListHolder

use of com.orhanobut.dialogplus.ListHolder in project dialogplus by orhanobut.

the class MainActivity method showDialog.

private void showDialog(int holderId, int gravity, boolean showHeader, boolean showFooter, boolean expanded) {
    boolean isGrid;
    Holder holder;
    switch(holderId) {
        case R.id.basic_holder_radio_button:
            holder = new ViewHolder(R.layout.content);
            isGrid = false;
            break;
        case R.id.list_holder_radio_button:
            holder = new ListHolder();
            isGrid = false;
            break;
        default:
            holder = new GridHolder(3);
            isGrid = true;
    }
    OnClickListener clickListener = new OnClickListener() {

        @Override
        public void onClick(DialogPlus dialog, View view) {
        //        switch (view.getId()) {
        //          case R.id.header_container:
        //            Toast.makeText(MainActivity.this, "Header clicked", Toast.LENGTH_LONG).show();
        //            break;
        //          case R.id.like_it_button:
        //            Toast.makeText(MainActivity.this, "We're glad that you like it", Toast.LENGTH_LONG).show();
        //            break;
        //          case R.id.love_it_button:
        //            Toast.makeText(MainActivity.this, "We're glad that you love it", Toast.LENGTH_LONG).show();
        //            break;
        //          case R.id.footer_confirm_button:
        //            Toast.makeText(MainActivity.this, "Confirm button clicked", Toast.LENGTH_LONG).show();
        //            break;
        //          case R.id.footer_close_button:
        //            Toast.makeText(MainActivity.this, "Close button clicked", Toast.LENGTH_LONG).show();
        //            break;
        //        }
        //        dialog.dismiss();
        }
    };
    OnItemClickListener itemClickListener = new OnItemClickListener() {

        @Override
        public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
            TextView textView = (TextView) view.findViewById(R.id.text_view);
            String clickedAppName = textView.getText().toString();
        //        dialog.dismiss();
        //        Toast.makeText(MainActivity.this, clickedAppName + " clicked", Toast.LENGTH_LONG).show();
        }
    };
    OnDismissListener dismissListener = new OnDismissListener() {

        @Override
        public void onDismiss(DialogPlus dialog) {
        //        Toast.makeText(MainActivity.this, "dismiss listener invoked!", Toast.LENGTH_SHORT).show();
        }
    };
    OnCancelListener cancelListener = new OnCancelListener() {

        @Override
        public void onCancel(DialogPlus dialog) {
        //        Toast.makeText(MainActivity.this, "cancel listener invoked!", Toast.LENGTH_SHORT).show();
        }
    };
    SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, isGrid);
    if (showHeader && showFooter) {
        showCompleteDialog(holder, gravity, adapter, clickListener, itemClickListener, dismissListener, cancelListener, expanded);
        return;
    }
    if (showHeader && !showFooter) {
        showNoFooterDialog(holder, gravity, adapter, clickListener, itemClickListener, dismissListener, cancelListener, expanded);
        return;
    }
    if (!showHeader && showFooter) {
        showNoHeaderDialog(holder, gravity, adapter, clickListener, itemClickListener, dismissListener, cancelListener, expanded);
        return;
    }
    showOnlyContentDialog(holder, gravity, adapter, itemClickListener, dismissListener, cancelListener, expanded);
}
Also used : DialogPlus(com.orhanobut.dialogplus.DialogPlus) OnItemClickListener(com.orhanobut.dialogplus.OnItemClickListener) Holder(com.orhanobut.dialogplus.Holder) ViewHolder(com.orhanobut.dialogplus.ViewHolder) GridHolder(com.orhanobut.dialogplus.GridHolder) ListHolder(com.orhanobut.dialogplus.ListHolder) OnDismissListener(com.orhanobut.dialogplus.OnDismissListener) TextView(android.widget.TextView) View(android.view.View) ListHolder(com.orhanobut.dialogplus.ListHolder) ViewHolder(com.orhanobut.dialogplus.ViewHolder) OnClickListener(com.orhanobut.dialogplus.OnClickListener) TextView(android.widget.TextView) GridHolder(com.orhanobut.dialogplus.GridHolder) OnCancelListener(com.orhanobut.dialogplus.OnCancelListener)

Aggregations

ListHolder (com.orhanobut.dialogplus.ListHolder)10 Test (org.junit.Test)8 ListView (android.widget.ListView)7 View (android.view.View)6 LinearLayout (android.widget.LinearLayout)5 ArrayAdapter (android.widget.ArrayAdapter)3 LayoutInflater (android.view.LayoutInflater)2 GridHolder (com.orhanobut.dialogplus.GridHolder)2 OnHolderListener (com.orhanobut.dialogplus.OnHolderListener)2 ViewHolder (com.orhanobut.dialogplus.ViewHolder)2 TextView (android.widget.TextView)1 DialogPlus (com.orhanobut.dialogplus.DialogPlus)1 DialogPlusBuilder (com.orhanobut.dialogplus.DialogPlusBuilder)1 Holder (com.orhanobut.dialogplus.Holder)1 OnCancelListener (com.orhanobut.dialogplus.OnCancelListener)1 OnClickListener (com.orhanobut.dialogplus.OnClickListener)1 OnDismissListener (com.orhanobut.dialogplus.OnDismissListener)1 OnItemClickListener (com.orhanobut.dialogplus.OnItemClickListener)1