Search in sources :

Example 1 with OnCancelListener

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

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.activity_toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setTitle(getString(R.string.app_name));
    radioGroup = (RadioGroup) findViewById(R.id.radio_group);
    headerCheckBox = (CheckBox) findViewById(R.id.header_check_box);
    footerCheckBox = (CheckBox) findViewById(R.id.footer_check_box);
    expandedCheckBox = (CheckBox) findViewById(R.id.expanded_check_box);
    findViewById(R.id.button_bottom).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showDialog(radioGroup.getCheckedRadioButtonId(), Gravity.BOTTOM, headerCheckBox.isChecked(), footerCheckBox.isChecked(), expandedCheckBox.isChecked());
        }
    });
    findViewById(R.id.button_center).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showDialog(radioGroup.getCheckedRadioButtonId(), Gravity.CENTER, headerCheckBox.isChecked(), footerCheckBox.isChecked(), expandedCheckBox.isChecked());
        }
    });
    findViewById(R.id.button_top).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showDialog(radioGroup.getCheckedRadioButtonId(), Gravity.TOP, headerCheckBox.isChecked(), footerCheckBox.isChecked(), expandedCheckBox.isChecked());
        }
    });
    View contentView = getLayoutInflater().inflate(R.layout.content2, null);
    DialogPlus dialogPlus = DialogPlus.newDialog(this).setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, new String[] { "asdfa" })).setCancelable(true).setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogPlus dialog) {
        }
    }).setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogPlus dialog) {
        }
    }).setOnBackPressListener(new OnBackPressListener() {

        @Override
        public void onBackPressed(DialogPlus dialogPlus) {
        }
    }).create();
    dialogPlus.show();
}
Also used : DialogPlus(com.orhanobut.dialogplus.DialogPlus) OnDismissListener(com.orhanobut.dialogplus.OnDismissListener) TextView(android.widget.TextView) View(android.view.View) OnBackPressListener(com.orhanobut.dialogplus.OnBackPressListener) ActionBar(android.support.v7.app.ActionBar) ArrayAdapter(android.widget.ArrayAdapter) Toolbar(android.support.v7.widget.Toolbar) OnCancelListener(com.orhanobut.dialogplus.OnCancelListener)

Example 2 with OnCancelListener

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

the class DialogPlusBuilderTest method testSetOnCancelListener.

@Test
public void testSetOnCancelListener() {
    DialogPlusBuilder builder = DialogPlus.newDialog(context);
    assertThat(builder.getOnCancelListener()).isNull();
    OnCancelListener listener = new OnCancelListener() {

        @Override
        public void onCancel(DialogPlus dialog) {
        }
    };
    builder.setOnCancelListener(listener);
    assertThat(builder.getOnCancelListener()).isNotNull();
    assertThat(builder.getOnCancelListener()).isEqualTo(listener);
}
Also used : DialogPlus(com.orhanobut.dialogplus.DialogPlus) DialogPlusBuilder(com.orhanobut.dialogplus.DialogPlusBuilder) OnCancelListener(com.orhanobut.dialogplus.OnCancelListener) Test(org.junit.Test)

Example 3 with OnCancelListener

use of com.orhanobut.dialogplus.OnCancelListener 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

DialogPlus (com.orhanobut.dialogplus.DialogPlus)3 OnCancelListener (com.orhanobut.dialogplus.OnCancelListener)3 View (android.view.View)2 TextView (android.widget.TextView)2 OnDismissListener (com.orhanobut.dialogplus.OnDismissListener)2 ActionBar (android.support.v7.app.ActionBar)1 Toolbar (android.support.v7.widget.Toolbar)1 ArrayAdapter (android.widget.ArrayAdapter)1 DialogPlusBuilder (com.orhanobut.dialogplus.DialogPlusBuilder)1 GridHolder (com.orhanobut.dialogplus.GridHolder)1 Holder (com.orhanobut.dialogplus.Holder)1 ListHolder (com.orhanobut.dialogplus.ListHolder)1 OnBackPressListener (com.orhanobut.dialogplus.OnBackPressListener)1 OnClickListener (com.orhanobut.dialogplus.OnClickListener)1 OnItemClickListener (com.orhanobut.dialogplus.OnItemClickListener)1 ViewHolder (com.orhanobut.dialogplus.ViewHolder)1 Test (org.junit.Test)1