Example usage for android.app Dialog Dialog

List of usage examples for android.app Dialog Dialog

Introduction

In this page you can find the example usage for android.app Dialog Dialog.

Prototype

public Dialog(@NonNull Context context) 

Source Link

Document

Creates a dialog window that uses the default dialog theme.

Usage

From source file:com.luke.lukef.lukeapp.popups.SubmissionPopup.java

public SubmissionPopup(MainActivity mainActivity) {
    this.mainActivity = mainActivity;
    this.dialog = new Dialog(mainActivity);
}

From source file:com.nextgis.ngm_clink_monitoring.dialogs.YesNoDialog.java

@NonNull
@Override// w  ww.java2 s  .co m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Idea from here
    // http://thanhcs.blogspot.ru/2014/10/android-custom-dialog-fragment.html
    Dialog dialog = new Dialog(getActivity());

    Window window = dialog.getWindow();
    window.requestFeature(Window.FEATURE_NO_TITLE);
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    dialog.setContentView(R.layout.dialog_yes_no);

    mIcon = (ImageView) dialog.findViewById(R.id.title_icon);
    mTitle = (TextView) dialog.findViewById(R.id.title_text);

    mDialogBodyScroll = (ScrollView) dialog.findViewById(R.id.dialog_body_scroll);
    mDialogBodyLayoutScrolled = (LinearLayout) dialog.findViewById(R.id.dialog_body_scrolled);
    mDialogBodyLayout = (LinearLayout) dialog.findViewById(R.id.dialog_body);

    mButtons = (TableLayout) dialog.findViewById(R.id.dialog_buttons_yn);
    mBtnPositive = (Button) dialog.findViewById(R.id.dialog_btn_positive_yn);
    mBtnNegative = (Button) dialog.findViewById(R.id.dialog_btn_negative_yn);

    if (null != mIconId) {
        mIcon.setVisibility(View.VISIBLE);
        mIcon.setImageResource(mIconId);
    }

    if (null != mTitleId) {
        mTitle.setText(mTitleId);
    }
    if (null != mTitleText) {
        mTitle.setText(mTitleText);
    }

    if (null != mMessageId) {
        setMessageView();
        mMessage.setText(mMessageId);
    }
    if (null != mMessageText) {
        setMessageView();
        mMessage.setText(mMessageText);
    }

    if (null != mView) {
        if (mAddScrollForView) {
            mDialogBodyScroll.setVisibility(View.VISIBLE);
            mDialogBodyLayoutScrolled.addView(mView);
        } else {
            mDialogBodyLayout.setVisibility(View.VISIBLE);
            mDialogBodyLayout.addView(mView);
        }
    }

    if (null != mPositiveTextId) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnPositive.setVisibility(View.VISIBLE);
        mBtnPositive.setText(mPositiveTextId);
    }
    if (null != mPositiveText) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnPositive.setVisibility(View.VISIBLE);
        mBtnPositive.setText(mPositiveText);
    }

    if (null != mNegativeTextId) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnNegative.setVisibility(View.VISIBLE);
        mBtnNegative.setText(mNegativeTextId);
    }
    if (null != mNegativeText) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnNegative.setVisibility(View.VISIBLE);
        mBtnNegative.setText(mNegativeText);
    }

    if (null != mOnPositiveClickedListener) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnPositive.setVisibility(View.VISIBLE);
        mBtnPositive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mOnPositiveClickedListener) {
                    mOnPositiveClickedListener.onPositiveClicked();
                }
                dismiss();
            }
        });
    }

    if (null != mOnNegativeClickedListener) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnNegative.setVisibility(View.VISIBLE);
        mBtnNegative.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mOnNegativeClickedListener) {
                    mOnNegativeClickedListener.onNegativeClicked();
                }
                dismiss();
            }
        });
    }

    return dialog;
}

From source file:com.example.pyrkesa.frag.User_Fragment.java

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

    setRetainInstance(true);// www . jav  a  2s  .  c  o  m
    rootView = inflater.inflate(R.layout.user_fragment, container, false);
    userList = (ListView) rootView.findViewById(R.id.lt_user);

    // custom dialog
    final Dialog dialog = new Dialog(rootView.getContext());
    d = dialog;
    userIcons = getResources().obtainTypedArray(R.array.userIcons);// load icons from
    userIcons1 = getResources().obtainTypedArray(R.array.userIcons1);

    userItems = new ArrayList<UserItem>();
    adapter = new UserAdapter(getActivity(), userItems, getActivity());
    userList.setAdapter(adapter);
    ImageButton addButton = (ImageButton) rootView.findViewById(R.id.add);
    addButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ModelFactory model = (ModelFactory) ModelFactory.getContext();
            if (model.user.type == 1) {

                dialog.setContentView(R.layout.adduser_dialog);
                dialog.setTitle("Ajouter un utilisateur ");
                dialogTypes = getResources().getStringArray(R.array.user_type_dialog); // load
                Button dialogButtonOk = (Button) dialog.findViewById(R.id.button_ok);
                Button dialogButtonCancel = (Button) dialog.findViewById(R.id.button_cancel);
                final EditText Newlogin = (EditText) dialog.findViewById(R.id.dialogLogin);
                final EditText NewPW = (EditText) dialog.findViewById(R.id.dialogPW);
                final Spinner NewType = (Spinner) dialog.findViewById(R.id.dialogType);

                ArrayList<String> types = new ArrayList<String>();

                for (String t : dialogTypes) {
                    types.add(t);
                }

                NewType.setAdapter(new ArrayAdapter<String>(rootView.getContext(),
                        android.R.layout.simple_spinner_dropdown_item, types));
                dialogButtonCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                    }
                });
                dialogButtonOk.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        ArrayList<String> temp = new ArrayList<String>();
                        String login = Newlogin.getText().toString();
                        String password = NewPW.getText().toString();
                        String type = NewType.getSelectedItem().toString();

                        if (login.equalsIgnoreCase("") && password.equalsIgnoreCase("") && type != null) {
                            new AlertDialog.Builder(v.getContext()).setTitle("Attention")
                                    .setMessage("Veuillez remplir toutes les informations.").show();

                        } else {
                            temp.add(login);
                            temp.add(password);

                            if (type.equalsIgnoreCase("admin")) {
                                temp.add("1");
                            } else if (type.equalsIgnoreCase("utilisateur")) {
                                temp.add("0");
                            } else {
                                temp.add("0");
                            }

                        }

                        new addUser().execute(temp);
                    }
                });
                dialog.show();

            } else {
                new AlertDialog.Builder(v.getContext()).setTitle("Attention")
                        .setMessage("Opration interdite : Droits d'administration requis.").show();
            }

        }
    });
    // adding user items

    new LoadAllUser().execute();

    return rootView;

}

From source file:co.uk.alt236.restclient4android.fragments.FragmentHeaders.java

private void URLPreviewDialog(final int headerIndex, final boolean newHeader) {

    headerDialog = new Dialog(getActivity());
    headerDialog.setContentView(R.layout.dialog_add_header);

    final EditText editHeaderName = (EditText) headerDialog.findViewById(R.id.editHeaderName);
    final EditText editHeaderValue = (EditText) headerDialog.findViewById(R.id.editHeaderValue);

    Button cancel = (Button) headerDialog.findViewById(R.id.btnCancel);
    Button save = (Button) headerDialog.findViewById(R.id.btnSave);
    Button delete = (Button) headerDialog.findViewById(R.id.btnDelete);

    if (newHeader) {
        delete.setVisibility(View.GONE);
        headerDialog.setTitle("New header");
    } else {/*from   w ww.j  a v a 2  s .  c om*/
        headerDialog.setTitle("Edit header");
        Pair<String, String> header = RestClient4AndroidApplication.getRequest().getRequestHeaders()
                .get(headerIndex);

        editHeaderName.setText(header.first);
        editHeaderValue.setText(header.second);
    }

    save.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            boolean res = saveHeader(headerIndex, editHeaderName.getText().toString(),
                    editHeaderValue.getText().toString());
            if (res) {
                headerDialog.dismiss();
            }
        }
    });

    cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            headerDialog.dismiss();
        }
    });

    delete.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            RestClient4AndroidApplication.getRequest().getRequestHeaders().remove(headerIndex);
            mAdapter.notifyDataSetChanged();
            Log.d(TAG, "^ HEADERS: " + mAdapter.getCount());
            headerDialog.dismiss();
        }
    });

    headerDialog.show();
}

From source file:com.idt.ontomedia.geoconsum.BaseActivity.java

private Dialog setDialogWithCheck(int _id) {
    final Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.dialog_with_check);

    TextView textViewInfo = (TextView) dialog.findViewById(R.id.text_layout);
    CheckBox checkBox = (CheckBox) dialog.findViewById(R.id.checkBox1);

    switch (_id) {
    case DIALOG_ABOUT_ID: {
        dialog.setTitle(getResources().getString(R.string.dialog_title_about) + " "
                + getResources().getString(R.string.app_name));
        dialog.setCancelable(true);/*from   w  w w . j av a  2s . c  o m*/

        checkBox.setVisibility(View.GONE);

        ImageView imageViewBanner = (ImageView) dialog.findViewById(R.id.imageViewBanner);
        imageViewBanner.setImageDrawable(getResources().getDrawable(R.drawable.logo_idt));
        imageViewBanner.setVisibility(View.VISIBLE);

        textViewInfo.setText(R.string.dialog_text_about);
    }
    case DIALOG_WARNING_ID: {
        dialog.setTitle(getResources().getString(R.string.dialog_title_warning));
        dialog.setCancelable(false);

        textViewInfo.setText(R.string.dialog_text_warning);

        checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton _buttonView, boolean _isChecked) {
                SharedPreferences sharedPreferences = PreferenceManager
                        .getDefaultSharedPreferences(getBaseContext());
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putBoolean(DialogPreferenceActivity.PREF_DIALOG_CHECK, _isChecked);
                editor.commit();
            }
        });
    }
    }

    Button acceptButton = (Button) dialog.findViewById(R.id.button1);
    acceptButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.cancel();
        }

    });

    return dialog;
}

From source file:com.adithya321.sharesanalysis.fragments.PurchaseShareFragment.java

@Nullable
@Override/*w  ww  .j  av a  2s.  co  m*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_purchase, container, false);

    databaseHandler = new DatabaseHandler(getContext());
    sharePurchasesRecyclerView = (RecyclerView) root.findViewById(R.id.share_purchases_recycler_view);
    emptyTV = (TextView) root.findViewById(R.id.empty);
    arrow = (ImageView) root.findViewById(R.id.arrow);
    setRecyclerViewAdapter();

    FloatingActionButton addPurchaseFab = (FloatingActionButton) root.findViewById(R.id.add_purchase_fab);
    addPurchaseFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(getContext());
            dialog.setTitle("Add Share Purchase");
            dialog.setContentView(R.layout.dialog_add_share_purchase);
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT);
            dialog.show();

            final AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name);
            List<String> nseList = ShareUtils.getNseList(getContext());
            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getContext(),
                    android.R.layout.simple_dropdown_item_1line, nseList);
            name.setAdapter(arrayAdapter);

            final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner);
            ArrayList<String> shares = new ArrayList<>();
            for (Share share : sharesList) {
                shares.add(share.getName());
            }
            ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(),
                    android.R.layout.simple_spinner_item, shares);
            spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(spinnerAdapter);

            final RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new);
            RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing);
            if (shares.size() == 0)
                existingRB.setVisibility(View.GONE);
            (newRB).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    name.setVisibility(View.VISIBLE);
                    spinner.setVisibility(View.GONE);
                }
            });

            (existingRB).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    name.setVisibility(View.GONE);
                    spinner.setVisibility(View.VISIBLE);
                }
            });

            Calendar calendar = Calendar.getInstance();
            year_start = calendar.get(Calendar.YEAR);
            month_start = calendar.get(Calendar.MONTH) + 1;
            day_start = calendar.get(Calendar.DAY_OF_MONTH);
            final Button selectDate = (Button) dialog.findViewById(R.id.select_date);
            selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/")
                    .append(year_start));
            selectDate.setOnClickListener(this);

            Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn);
            addPurchaseBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Share share = new Share();
                    share.setId(databaseHandler.getNextKey("share"));
                    share.setPurchases(new RealmList<Purchase>());
                    Purchase purchase = new Purchase();
                    purchase.setId(databaseHandler.getNextKey("purchase"));

                    if (newRB.isChecked()) {
                        String sName = name.getText().toString().trim();
                        if (sName.equals("")) {
                            Toast.makeText(getActivity(), "Invalid Name", Toast.LENGTH_SHORT).show();
                            return;
                        } else {
                            share.setName(sName);
                            purchase.setName(sName);
                        }
                    }

                    String stringStartDate = year_start + " " + month_start + " " + day_start;
                    DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH);
                    try {
                        Date date = format.parse(stringStartDate);
                        share.setDateOfInitialPurchase(date);
                        purchase.setDate(date);
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares);
                    try {
                        purchase.setQuantity(Integer.parseInt(quantity.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText price = (EditText) dialog.findViewById(R.id.buying_price);
                    try {
                        purchase.setPrice(Double.parseDouble(price.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    purchase.setType("buy");
                    if (newRB.isChecked()) {
                        if (!databaseHandler.addShare(share, purchase)) {
                            Toast.makeText(getActivity(), "Share Already Exists", Toast.LENGTH_SHORT).show();
                            return;
                        }
                    } else {
                        purchase.setName(spinner.getSelectedItem().toString());
                        databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase);
                    }
                    setRecyclerViewAdapter();
                    dialog.dismiss();
                }
            });
        }
    });

    return root;
}

From source file:com.mimp.fragment.institucion.PlanTrabajoPage.java

public void btnAgregar() {
    final Dialog dialog = new Dialog(this.getActivity());
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    //dialog.setCancelable(false);
    dialog.setContentView(R.layout.dialog_plan_trabajo);

    TextView lblResponsable = (TextView) dialog.findViewById(R.id.lblResponsable);
    lblResponsable.setTextSize(TypedValue.COMPLEX_UNIT_DIP, lblResponsable.getTextSize() + SizeText);

    TextView lblDResponsable = (TextView) dialog.findViewById(R.id.lblDResponsable);
    lblDResponsable.setTextSize(TypedValue.COMPLEX_UNIT_DIP, lblDResponsable.getTextSize() + SizeText);

    TextView lblObejtivo = (TextView) dialog.findViewById(R.id.lblObejtivo);
    lblObejtivo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, lblObejtivo.getTextSize() + SizeText);

    TextView lblMeta = (TextView) dialog.findViewById(R.id.lblMeta);
    lblMeta.setTextSize(TypedValue.COMPLEX_UNIT_DIP, lblMeta.getTextSize() + SizeText);

    TextView lblActividad = (TextView) dialog.findViewById(R.id.lblActividad);
    lblActividad.setTextSize(TypedValue.COMPLEX_UNIT_DIP, lblActividad.getTextSize() + SizeText);

    TextView lblCronograma = (TextView) dialog.findViewById(R.id.lblCronograma);
    lblCronograma.setTextSize(TypedValue.COMPLEX_UNIT_DIP, lblCronograma.getTextSize() + SizeText);

    final EditText txtObejtivo = (EditText) dialog.findViewById(R.id.txtObejtivo);
    txtObejtivo.setTextSize(TypedValue.COMPLEX_UNIT_DIP, txtObejtivo.getTextSize() + SizeText);
    txtObejtivo.setText("");

    final EditText txtActividad = (EditText) dialog.findViewById(R.id.txtActividad);
    txtActividad.setTextSize(TypedValue.COMPLEX_UNIT_DIP, txtActividad.getTextSize() + SizeText);
    txtActividad.setText("");

    final EditText txtCronograma = (EditText) dialog.findViewById(R.id.txtCronograma);
    txtCronograma.setTextSize(TypedValue.COMPLEX_UNIT_DIP, txtCronograma.getTextSize() + SizeText);
    txtCronograma.setText("");

    final EditText txtMeta = (EditText) dialog.findViewById(R.id.txtMeta);
    txtMeta.setTextSize(TypedValue.COMPLEX_UNIT_DIP, txtMeta.getTextSize() + SizeText);
    txtMeta.setText("");

    final EditText txtResponsable = (EditText) dialog.findViewById(R.id.txtResponsable);
    txtResponsable.setTextSize(TypedValue.COMPLEX_UNIT_DIP, txtResponsable.getTextSize() + SizeText);
    txtResponsable.setText("");

    Button btnAgregar = (Button) dialog.findViewById(R.id.btnAgregar);
    btnAgregar.setOnClickListener(new View.OnClickListener() {
        @Override// w  ww. jav a 2 s. c  om
        public void onClick(View v) {
            clsPlanTrabajo entidad = new clsPlanTrabajo();
            entidad.setActividad(txtActividad.getText().toString());
            entidad.setCronograma(txtCronograma.getText().toString());
            entidad.setMeta(txtMeta.getText().toString());
            entidad.setObejtivo(txtObejtivo.getText().toString());
            entidad.setResponsable(txtResponsable.getText().toString());
            list.add(entidad);
            getListaPlanTrabajo();
            dialog.dismiss();
        }
    });
    dialog.show();

}

From source file:com.nbplus.vbroadlauncher.fragment.LoadIoTDevicesDialogFragmentStatus.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Dialog dialog = new Dialog(
            getActivity()/*new ContextThemeWrapper(getActivity(), R.style.FullScreenDialog)*/);

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    setRetainInstance(true);/*from  w w w  .j  a va  2 s.  c o m*/
    originalOrientation = getActivity().getRequestedOrientation();
    getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    // fullscreen without statusbar
    dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    dialog.setCancelable(false);
    this.setCancelable(false);

    // disable back key
    dialog.setOnKeyListener(this);

    // set content view
    View v = getActivity().getLayoutInflater().inflate(R.layout.fragment_iot_devices, null, false);
    dialog.setContentView(v);

    // grid view
    mGridView = (GridView) v.findViewById(R.id.iot_devices_grid);
    mGridView.setEmptyView(v.findViewById(android.R.id.empty));

    // set button control
    mCloseButton = (ImageButton) v.findViewById(R.id.btn_close);
    mCloseButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.d(TAG, "onClick btnClose..");
            ((BaseActivity) getActivity()).dismissProgressDialog();
            Intent sendIntent = new Intent();
            sendIntent.setAction(Constants.ACTION_IOT_DEVICE_LIST);
            sendIntent.putExtra(Constants.EXTRA_IOT_DEVICE_CANCELED, true);
            LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(sendIntent);

            dismiss();
        }
    });

    mRefreshButton = (Button) v.findViewById(R.id.btn_refresh);
    mRefreshButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.d(TAG, "onClick btnRefresh..");
            ((BaseActivity) getActivity()).showProgressDialog();

            IoTInterface.getInstance().getDevicesList(DeviceTypes.ALL, LoadIoTDevicesDialogFragmentStatus.this,
                    true);
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    ((BaseActivity) getActivity()).dismissProgressDialog();
                }
            }, 6000);
        }
    });

    mSendButton = (Button) v.findViewById(R.id.btn_send);
    mSendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.d(TAG, "onClick btnSend..");
            ((BaseActivity) getActivity()).dismissProgressDialog();
            showSyncAlertDialog();
        }
    });

    mGridView.setOnItemClickListener(this);

    return dialog;
}

From source file:com.minerva.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    checkAndRequestPermissions();//from w ww. j a  v a 2s  . c o  m

    LOG_TAG = MainActivity.this.getClass().getSimpleName();

    Log.i(LOG_TAG, "Creating application Main Activity...");

    // *** Setting up the Toolbar ***
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // *** Handling navigation buttons and clicks ***
    BottomNavigationView bottomNavigationVew = (BottomNavigationView) findViewById(R.id.navigation);
    bottomNavigationVew
            .setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.action_camera:
                        Log.i(LOG_TAG, "Accessing Camera Activity...");
                        Intent cameraIntent = new Intent(MainActivity.this, CameraActivity.class);
                        startActivity(cameraIntent);
                        break;
                    case R.id.action_gallery:
                        Log.i(LOG_TAG, "Accessing Gallery Activity...");
                        Intent galleryIntent = new Intent(MainActivity.this, GalleryActivity.class);
                        startActivity(galleryIntent);
                        break;
                    case R.id.action_home:
                        break;
                    }

                    return false;
                }
            });

    // *** Handling first time use ***

    SharedPreferences settings = getSharedPreferences(PREFS_NAME1, 0);

    //if (settings.getBoolean("my_first_time1", false)) {
    //the app is being launched for first time, do something

    // *** First time task ***
    final Dialog alertDialog = new Dialog(this);
    alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    alertDialog.setContentView(R.layout.navigation);
    alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    alertDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT);

    alertDialog.show();

    Button gotIt = (Button) alertDialog.findViewById(R.id.gotIt);
    gotIt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            alertDialog.dismiss();
        }
    });
    // record the fact that the app has been started at least once
    //  settings.edit().putBoolean("my_first_time", false).commit();
}

From source file:com.adithya321.sharesanalysis.fragments.SharePurchaseFragment.java

@Nullable
@Override/*from   w w  w.  j  ava 2  s.com*/
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_purchase, container, false);

    databaseHandler = new DatabaseHandler(getContext());
    sharePurchasesRecyclerView = (RecyclerView) root.findViewById(R.id.share_purchases_recycler_view);
    emptyTV = (TextView) root.findViewById(R.id.empty);
    arrow = (ImageView) root.findViewById(R.id.arrow);
    setRecyclerViewAdapter();

    FloatingActionButton addPurchaseFab = (FloatingActionButton) root.findViewById(R.id.add_purchase_fab);
    addPurchaseFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(getContext());
            dialog.setTitle("Add Share Purchase");
            dialog.setContentView(R.layout.dialog_add_share_purchase);
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT);
            dialog.show();

            final AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name);
            List<String> nseList = ShareUtils.getNseList(getContext());
            FilterWithSpaceAdapter<String> arrayAdapter = new FilterWithSpaceAdapter<>(getContext(),
                    android.R.layout.simple_dropdown_item_1line, nseList);
            name.setThreshold(1);
            name.setAdapter(arrayAdapter);

            final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner);

            ArrayList<String> shares = new ArrayList<>();
            for (Share share : sharesList) {
                shares.add(share.getName());
            }
            ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(),
                    android.R.layout.simple_spinner_item, shares);
            spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(spinnerAdapter);

            final RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new);
            RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing);
            if (shares.size() == 0)
                existingRB.setVisibility(View.GONE);
            (newRB).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    name.setVisibility(View.VISIBLE);
                    spinner.setVisibility(View.GONE);
                }
            });

            (existingRB).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    name.setVisibility(View.GONE);
                    spinner.setVisibility(View.VISIBLE);
                }
            });

            Calendar calendar = Calendar.getInstance();
            year_start = calendar.get(Calendar.YEAR);
            month_start = calendar.get(Calendar.MONTH) + 1;
            day_start = calendar.get(Calendar.DAY_OF_MONTH);
            final Button selectDate = (Button) dialog.findViewById(R.id.select_date);
            selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/")
                    .append(year_start));
            selectDate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Dialog dialog = new DatePickerDialog(getActivity(), onDateSetListener, year_start,
                            month_start - 1, day_start);
                    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            selectDate.setText(new StringBuilder().append(day_start).append("/")
                                    .append(month_start).append("/").append(year_start));
                        }
                    });
                    dialog.show();
                }
            });

            Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn);
            addPurchaseBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Share share = new Share();
                    share.setId(databaseHandler.getNextKey("share"));
                    share.setPurchases(new RealmList<Purchase>());
                    Purchase purchase = new Purchase();
                    purchase.setId(databaseHandler.getNextKey("purchase"));

                    if (newRB.isChecked()) {
                        String sName = name.getText().toString().trim();
                        if (sName.equals("")) {
                            Toast.makeText(getActivity(), "Invalid Name", Toast.LENGTH_SHORT).show();
                            return;
                        } else {
                            share.setName(sName);
                            purchase.setName(sName);
                        }
                    }

                    String stringStartDate = year_start + " " + month_start + " " + day_start;
                    DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH);
                    try {
                        Date date = format.parse(stringStartDate);
                        share.setDateOfInitialPurchase(date);
                        purchase.setDate(date);
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares);
                    try {
                        purchase.setQuantity(Integer.parseInt(quantity.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText price = (EditText) dialog.findViewById(R.id.buying_price);
                    try {
                        purchase.setPrice(Double.parseDouble(price.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    purchase.setType("buy");
                    if (newRB.isChecked()) {
                        if (!databaseHandler.addShare(share, purchase)) {
                            Toast.makeText(getActivity(), "Share Already Exists", Toast.LENGTH_SHORT).show();
                            return;
                        }
                    } else {
                        purchase.setName(spinner.getSelectedItem().toString());
                        databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase);
                    }
                    setRecyclerViewAdapter();
                    dialog.dismiss();
                }
            });
        }
    });

    return root;
}