Example usage for android.app Dialog findViewById

List of usage examples for android.app Dialog findViewById

Introduction

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

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID or null if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via #show() or #create() ).

Usage

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Change the order of the favorite rows.
 * /*from  ww  w .  ja  v  a 2  s . c o  m*/
 * @param context
 */
public static void displayChangeRowOrder(final Launcher context) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.row_list);

    final ListView listView = (ListView) dialog.findViewById(R.id.rowList);
    ArrayList<RowInfo> persistedRows = RowsTable.getRows(context);
    final ArrayList<RowInfo> rows = new ArrayList<RowInfo>();
    // Add in reverse order to match favorite rows order
    for (RowInfo rowInfo : persistedRows) {
        rows.add(0, rowInfo);
    }
    final RowAdapter rowAdapter = new RowAdapter(context, rows);
    listView.setAdapter(rowAdapter);
    listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            RowInfo rowInfo = (RowInfo) parent.getAdapter().getItem(position);
            if (rowInfo.isSelected()) {
                rowInfo.setSelected(false);

                // Persist the new row order
                try {
                    int counter = 0;
                    for (int i = rowAdapter.getCount() - 1; i >= 0; i--) {
                        RowInfo currentRowInfo = (RowInfo) parent.getAdapter().getItem(i);
                        RowsTable.updateRow(context, currentRowInfo.getId(), currentRowInfo.getTitle(), counter,
                                currentRowInfo.getType());
                        counter++;
                    }
                } catch (Exception e) {
                    Log.e(LOG_TAG, "displayChangeRowOrder", e);
                }
                Analytics.logEvent(Analytics.CHANGE_ROW_ORDER);
            } else {
                rowInfo.setSelected(true);
            }
            rowAdapter.notifyDataSetChanged();
        }

    });
    listView.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // Swap the selected item in the list
            int selectedRowIndex = -1;
            for (int i = 0; i < rows.size(); i++) {
                RowInfo rowInfo = rows.get(i);
                if (rowInfo.isSelected()) {
                    selectedRowIndex = i;
                    break;
                }
            }
            if (selectedRowIndex != -1) {
                try {
                    Collections.swap(rows, position, selectedRowIndex);
                    rowAdapter.notifyDataSetChanged();
                } catch (Exception e) {
                    Log.e(LOG_TAG, "displayChangeRowOrder", e);
                }
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

    });
    listView.setDrawingCacheEnabled(true);
    listView.setOnKeyListener(onKeyListener);
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
            context.reloadAllGalleries();
        }

    });
    Button okButton = (Button) dialog.findViewById(R.id.okButton);
    okButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            context.showCover(false);
            dialog.dismiss();
            context.reloadAllGalleries();
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_CHANGE_ROW_ORDER);
}

From source file:com.example.android.indoornavigation.activities.MainActivity.java

public void createCustomDialog() {

    // custom dialog
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.navigation_dialog);

    Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
    // if button is clicked, close the custom dialog
    dialogButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from   ww w .ja  v  a 2  s.  c  om*/
        public void onClick(View v) {
            dialog.dismiss();

            mMyWebView = (MyWebView) findViewById(R.id.map);
            mMyWebView.setDrawPath(1);
            mMyWebView.draw(new Canvas());

            selectItem(0);
        }
    });

    dialog.show();
}

From source file:com.pericstudio.drawit.activities.DashboardMainActivity.java

/**
 * Sets up the toolbar and the FAB.//  w  w  w .j a va  2s.com
 */
private void setUpToolbar() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
            R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        TextView tvName;
        TextView tvDes;

        @Override
        public void onClick(View view) {
            final Dialog testDialog = new Dialog(DashboardMainActivity.this);
            testDialog.setTitle("TEST TITLE!");
            testDialog.setContentView(R.layout.dialog_test);

            tvName = (TextView) testDialog.findViewById(R.id.et_dialog_name);
            tvDes = (TextView) testDialog.findViewById(R.id.et_dialog_desciption);

            Button button = (Button) testDialog.findViewById(R.id.dialog_button);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    final String tvNameContent = tvName.getText().toString().trim();
                    final String tvDesContent = tvDes.getText().toString().trim();

                    final Drawing drawing = new Drawing(tvNameContent, tvDesContent);

                    drawing.save(getApplicationContext(), new Response.Listener<ObjectModificationResponse>() {
                        @Override
                        public void onResponse(ObjectModificationResponse modificationResponse) {
                            //code
                            List<String> idList = modificationResponse.getCreatedObjectIds();
                            final String drawingID = idList.get(0);

                            LocallySavableCMObject.searchObjects(getApplicationContext(),
                                    SearchQuery.filter("ownerID").equal(MyApplication.userID).searchQuery(),
                                    new Response.Listener<CMObjectResponse>() {
                                        @Override
                                        public void onResponse(CMObjectResponse response) {
                                            List<CMObject> userObject = response.getObjects();
                                            UserObjectIDs ids = (UserObjectIDs) userObject.get(0);
                                            ids.addInProgress(drawingID);
                                            MyApplication.setUserDataObject(ids);

                                            ids.save();

                                            T.showShortDebug(getApplicationContext(), "Refresh for update");

                                            testDialog.dismiss();

                                        }
                                    });

                        }
                    }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError volleyError) {
                            //code
                        }
                    });

                }
            });
            testDialog.show();
        }
    });
}

From source file:com.orange.datavenue.StreamListFragment.java

/**
 *
 *//*from   www  .  j av  a2 s . c o m*/
private void deleteStream() {
    final android.app.Dialog dialog = new android.app.Dialog(getActivity());

    dialog.setContentView(R.layout.delete_dialog);
    dialog.setTitle(R.string.delete);

    TextView info = (TextView) dialog.findViewById(R.id.info_label);
    info.setText(String.format(getString(R.string.delete_stream), Model.instance.currentStream.getId()));

    Button deleteButton = (Button) dialog.findViewById(R.id.delete_button);

    deleteButton.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View view) {
            Log.d(TAG_NAME, "datasource : " + Model.instance.currentDatasource.getId());
            Log.d(TAG_NAME, "stream : " + Model.instance.currentStream.getId());

            DeleteStreamOperation deleteStreamOperation = new DeleteStreamOperation(Model.instance.oapiKey,
                    Model.instance.key, Model.instance.currentDatasource, Model.instance.currentStream,
                    new OperationCallback() {
                        @Override
                        public void process(Object object, Exception exception) {
                            if (exception == null) {
                                getStreams(); // reload
                            } else {
                                Errors.displayError(getActivity(), exception);
                            }
                        }
                    });

            deleteStreamOperation.execute("");

            dialog.dismiss();
        }

    });

    Button cancelDeleteButton = (Button) dialog.findViewById(R.id.cancel_button);
    cancelDeleteButton.setOnClickListener(new Button.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            dialog.dismiss();
        }
    });

    dialog.setCancelable(false);
    dialog.show();
}

From source file:com.example.android.navigationdrawer.QRCode.java

public void onQR(View v) {
    switch (v.getId()) {
    case R.id.button1:
        String qrInputText = MidiFile.readString;

        //Find screen size
        WindowManager manager = (WindowManager) getSystemService(WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        Point point = new Point();
        display.getSize(point);/*from  w  w w  .  j a  v  a 2 s.  c o  m*/
        int width = point.x;
        int height = point.y;
        int smallerDimension = width < height ? width : height;
        smallerDimension = smallerDimension * 3 / 4;
        //Encode with a QR Code image
        QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrInputText, null, Contents.Type.TEXT,
                BarcodeFormat.QR_CODE.toString(), smallerDimension);
        try {
            Bitmap bitmap = qrCodeEncoder.encodeAsBitmap();
            ImageView myImage = (ImageView) findViewById(R.id.imageView1);
            myImage.setImageBitmap(bitmap);

            // Get screen size
            Display display1 = this.getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display1.getSize(size);
            int screenWidth = size.x;
            int screenHeight = size.y;

            // Get target image size
            Bitmap bitmap1 = qrCodeEncoder.encodeAsBitmap();
            int bitmapHeight = bitmap1.getHeight();
            int bitmapWidth = bitmap1.getWidth();

            // Scale the image down to fit perfectly into the screen
            // The value (250 in this case) must be adjusted for phone/tables displays
            while (bitmapHeight > (screenHeight - 250) || bitmapWidth > (screenWidth - 250)) {
                bitmapHeight = bitmapHeight / 2;
                bitmapWidth = bitmapWidth / 2;
            }

            // Create resized bitmap image
            BitmapDrawable resizedBitmap = new BitmapDrawable(this.getResources(),
                    Bitmap.createScaledBitmap(bitmap, bitmapWidth, bitmapHeight, false));

            // Create dialog
            Dialog dialog = new Dialog(this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.thumbnail);

            ImageView image = (ImageView) dialog.findViewById(R.id.imageview);

            // !!! Do here setBackground() instead of setImageDrawable() !!! //
            image.setBackground(resizedBitmap);

            // Without this line there is a very small border around the image (1px)
            // In my opinion it looks much better without it, so the choice is up to you.
            dialog.getWindow().setBackgroundDrawable(null);
            dialog.show();

        } catch (WriterException e) {
            e.printStackTrace();
        }
        break;
    }
}

From source file:net.margaritov.preference.colorpicker.dialog.ColorPickerDialogFragment.java

@NonNull
@Override/* w  w w .j a  v a 2 s. c  o m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {

    if (getActivity() != null) {
        final Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_DeviceDefault_Light_Dialog);
        dialog.getWindow().setFormat(PixelFormat.RGBA_8888);

        dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        dialog.setContentView(R.layout.view_color_picker_dialog);

        colorPicker = (ColorPickerView) dialog.findViewById(R.id.color_picker_view);
        oldColor = (ColorPanelView) dialog.findViewById(R.id.color_panel_old);
        newColor = (ColorPanelView) dialog.findViewById(R.id.color_panel_new);
        ((LinearLayout) oldColor.getParent()).setPadding(Math.round(colorPicker.getDrawingOffset()), 0,
                Math.round(colorPicker.getDrawingOffset()), 0);
        colorPicker.setOnColorChangedListener(this);
        oldColor.setColor(initialColor);
        if (savedInstanceState == null) {
            colorPicker.setColor(initialColor, true);
        }

        buttonNegative = (Button) dialog.findViewById(R.id.dialog_button_negative);
        buttonPositive = (Button) dialog.findViewById(R.id.dialog_button_positive);

        buttonNegative.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onDialogButtonClickedListener != null) {
                    onDialogButtonClickedListener.onNegativeButtonClicked(ColorPickerDialogFragment.this);
                }
                dismiss();
            }
        });
        buttonPositive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onDialogButtonClickedListener != null) {
                    onDialogButtonClickedListener.onPositiveButtonClicked(ColorPickerDialogFragment.this);
                }
                dismiss();
            }
        });
        return dialog;
    } else {
        return super.onCreateDialog(savedInstanceState);
    }
}

From source file:com.iskrembilen.quasseldroid.gui.LoginActivity.java

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    switch (id) {
    case R.id.DIALOG_ADD_CORE:
        dialog.setTitle("Add new core");
        break;/*from  ww  w  . ja v a 2  s.  c o  m*/
    case R.id.DIALOG_EDIT_CORE:
        dialog.setTitle("Edit core");
        Bundle res = dbHelper.getCore(core.getSelectedItemId());
        ((EditText) dialog.findViewById(R.id.dialog_name_field))
                .setText(res.getString(QuasselDbHelper.KEY_NAME));
        ((EditText) dialog.findViewById(R.id.dialog_address_field))
                .setText(res.getString(QuasselDbHelper.KEY_ADDRESS));
        ((EditText) dialog.findViewById(R.id.dialog_port_field))
                .setText(Integer.toString(res.getInt(QuasselDbHelper.KEY_PORT)));
        ((CheckBox) dialog.findViewById(R.id.dialog_usessl_checkbox))
                .setChecked(res.getBoolean(QuasselDbHelper.KEY_SSL));
        break;
    }

    super.onPrepareDialog(id, dialog);
}

From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceTaskProfile.java

final static private void setEditTaskActionListener(final GlobalParameters mGlblParms, final Dialog dialog,
        final AdapterProfileList pfla, ListView pflv, final String curr_grp,
        final ArrayList<TaskActionEditListItem> adapter_act_list) {
    final Spinner spinnerActionProfile = (Spinner) dialog.findViewById(R.id.edit_profile_task_user_actionlist);
    CustomSpinnerAdapter adapterActionProfile = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterActionProfile.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerActionProfile(mGlblParms, dialog, pfla, pflv, spinnerActionProfile,
            adapterActionProfile);//from  www. ja v a 2 s . c o m
    if (adapterActionProfile.getCount() == 0)
        spinnerActionProfile.setEnabled(false);

    final Spinner spinnerBuiltinPrimitiveAction = (Spinner) dialog
            .findViewById(R.id.edit_profile_task_builtin_primitive_actionlist);
    CustomSpinnerAdapter adapterBuiltinPrimitiveAction = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterBuiltinPrimitiveAction.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerBuiltinPrimitiveAction(mGlblParms, dialog, spinnerBuiltinPrimitiveAction,
            adapterBuiltinPrimitiveAction);
    if (adapterBuiltinPrimitiveAction.getCount() == 0)
        spinnerBuiltinPrimitiveAction.setEnabled(false);

    final Spinner spinnerBuiltinConditionalAction = (Spinner) dialog
            .findViewById(R.id.edit_profile_task_builtin_conditional_actionlist);
    CustomSpinnerAdapter adapterBuiltinConditionalAction = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterBuiltinConditionalAction.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerBuiltinConditionalAction(mGlblParms, dialog, spinnerBuiltinConditionalAction,
            adapterBuiltinConditionalAction);
    if (adapterBuiltinConditionalAction.getCount() == 0)
        spinnerBuiltinConditionalAction.setEnabled(false);

    final Spinner spinnerBuiltinCancelAction = (Spinner) dialog
            .findViewById(R.id.edit_profile_task_builtin_cancel_actionlist);
    CustomSpinnerAdapter adapterBuiltinCancelAction = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterBuiltinCancelAction.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerBuiltinCancelAction(mGlblParms, dialog, spinnerBuiltinCancelAction,
            adapterBuiltinCancelAction);
    if (adapterBuiltinCancelAction.getCount() == 0)
        spinnerBuiltinCancelAction.setEnabled(false);

    final Spinner spinnerBuiltinBlockAction = (Spinner) dialog
            .findViewById(R.id.edit_profile_task_builtin_block_actionlist);
    CustomSpinnerAdapter adapterBuiltinBlockAction = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterBuiltinBlockAction.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerBuiltinBlockAction(mGlblParms, dialog, spinnerBuiltinBlockAction,
            adapterBuiltinBlockAction);
    if (adapterBuiltinBlockAction.getCount() == 0)
        spinnerBuiltinBlockAction.setEnabled(false);

    final ListView lv_act_list = (ListView) dialog.findViewById(android.R.id.list);
    mGlblParms.taskActionListAdapter = new AdapterTaskActionEditList(mGlblParms.context,
            R.layout.task_action_list_item, adapter_act_list);
    lv_act_list.setAdapter(mGlblParms.taskActionListAdapter);
    lv_act_list.setEnabled(true);
    lv_act_list.setSelected(true);

    lv_act_list.setOnItemClickListener(new OnItemClickListener() {
        @Override
        final public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {
            if (!mGlblParms.taskActionListAdapter.getItem(position).action.startsWith(BUILTIN_PREFIX)
                    && !curr_grp.equals(QUICK_TASK_GROUP_NAME)) {
                for (int i = 0; i < pfla.getDataListCount(); i++) {
                    if (pfla.getDataListItem(i).getProfileType().equals(PROFILE_TYPE_ACTION)
                            && pfla.getDataListItem(i).getProfileGroup().equals(curr_grp)
                            && pfla.getDataListItem(i).getProfileName()
                                    .equals(mGlblParms.taskActionListAdapter.getItem(position).action)) {
                        NotifyEvent ntfy = new NotifyEvent(mGlblParms.context);
                        ntfy.setListener(new NotifyEventListener() {
                            @Override
                            public void positiveResponse(Context c, Object[] o) {
                                updateTaskActionEditListDescription(mGlblParms, dialog, pfla, curr_grp,
                                        adapter_act_list);
                                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                            }

                            @Override
                            public void negativeResponse(Context c, Object[] o) {
                            }
                        });
                        ProfileMaintenanceActionProfile pmap = ProfileMaintenanceActionProfile.newInstance();
                        pmap.showDialog(mGlblParms.frgamentMgr, pmap, "EDIT", curr_grp,
                                pfla.getDataListItem(i));
                        pmap.setNotifyEvent(ntfy);
                        break;
                    }
                }
            }
        }
    });

    lv_act_list.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        final public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            createTaskActionListContextMenu(mGlblParms, dialog, curr_grp, arg2, pfla);
            return false;
        }
    });

    // Add user action?
    spinnerActionProfile.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (arg2 != 0) {
                TaskActionEditListItem taeli = new TaskActionEditListItem();
                taeli.action = (String) spinnerActionProfile.getSelectedItem();
                mGlblParms.taskActionListAdapter.add(taeli);
                updateTaskActionEditListDescription(mGlblParms, dialog, pfla, curr_grp, adapter_act_list);
                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                lv_act_list.setSelection(mGlblParms.taskActionListAdapter.getCount() - 1);
                arg0.setSelection(0);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    // Add builtin action primitive?
    spinnerBuiltinPrimitiveAction.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (arg2 != 0) {
                TaskActionEditListItem taeli = new TaskActionEditListItem();
                taeli.action = (String) spinnerBuiltinPrimitiveAction.getSelectedItem();
                mGlblParms.taskActionListAdapter.add(taeli);
                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                lv_act_list.setSelection(mGlblParms.taskActionListAdapter.getCount() - 1);
                arg0.setSelection(0);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }

    });

    // Add builtin action conditional?
    spinnerBuiltinConditionalAction.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (arg2 != 0) {
                TaskActionEditListItem taeli = new TaskActionEditListItem();
                taeli.action = (String) spinnerBuiltinConditionalAction.getSelectedItem();
                mGlblParms.taskActionListAdapter.add(taeli);
                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                lv_act_list.setSelection(mGlblParms.taskActionListAdapter.getCount() - 1);
                arg0.setSelection(0);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    // Add builtin action cancel?
    spinnerBuiltinCancelAction.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (arg2 != 0) {
                TaskActionEditListItem taeli = new TaskActionEditListItem();
                taeli.action = (String) spinnerBuiltinCancelAction.getSelectedItem();
                mGlblParms.taskActionListAdapter.add(taeli);
                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                lv_act_list.setSelection(mGlblParms.taskActionListAdapter.getCount() - 1);
                arg0.setSelection(0);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    // Add builtin action block?
    spinnerBuiltinBlockAction.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            if (arg2 != 0) {
                TaskActionEditListItem taeli = new TaskActionEditListItem();
                taeli.action = (String) spinnerBuiltinBlockAction.getSelectedItem();
                mGlblParms.taskActionListAdapter.add(taeli);
                mGlblParms.taskActionListAdapter.notifyDataSetChanged();
                lv_act_list.setSelection(mGlblParms.taskActionListAdapter.getCount() - 1);
                arg0.setSelection(0);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    final Spinner spinnerSelectAction = (Spinner) dialog.findViewById(R.id.edit_profile_task_select_action);
    CustomSpinnerAdapter adapterSelectAction = new CustomSpinnerAdapter(mGlblParms.context,
            R.layout.custom_simple_spinner_item);
    adapterSelectAction.setTextColor(Color.BLACK);
    ProfileMaintenance.setSpinnerSelectAction(mGlblParms, dialog, spinnerSelectAction, adapterSelectAction);
    spinnerSelectAction.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        final public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            spinnerActionProfile.setVisibility(Spinner.GONE);
            spinnerBuiltinPrimitiveAction.setVisibility(Spinner.GONE);
            spinnerBuiltinConditionalAction.setVisibility(Spinner.GONE);
            spinnerBuiltinCancelAction.setVisibility(Spinner.GONE);
            spinnerBuiltinBlockAction.setVisibility(Spinner.GONE);
            String act = (String) spinnerSelectAction.getSelectedItem();
            if (act.equals(mGlblParms.context.getString(R.string.msgs_edit_profile_action_select_user))) {
                spinnerActionProfile.setVisibility(Spinner.VISIBLE);
            } else if (act
                    .equals(mGlblParms.context.getString(R.string.msgs_edit_profile_action_select_primitive))) {
                spinnerBuiltinPrimitiveAction.setVisibility(Spinner.VISIBLE);
            } else if (act.equals(
                    mGlblParms.context.getString(R.string.msgs_edit_profile_action_select_conditional))) {
                spinnerBuiltinConditionalAction.setVisibility(Spinner.VISIBLE);
            } else if (act
                    .equals(mGlblParms.context.getString(R.string.msgs_edit_profile_action_select_cancel))) {
                spinnerBuiltinCancelAction.setVisibility(Spinner.VISIBLE);
            } else if (act
                    .equals(mGlblParms.context.getString(R.string.msgs_edit_profile_action_select_block))) {
                spinnerBuiltinBlockAction.setVisibility(Spinner.VISIBLE);
            }
        }

        @Override
        final public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

}

From source file:com.orange.datavenue.DatasourceListFragment.java

private void createDatasource() {
    final android.app.Dialog dialog = new android.app.Dialog(getActivity());

    dialog.setContentView(R.layout.create_datasource_dialog);

    dialog.setTitle(R.string.add_datasource);

    final LinearLayout callbackLayout = (LinearLayout) dialog.findViewById(R.id.callback_layout);
    final EditText name = (EditText) dialog.findViewById(R.id.name);
    final EditText description = (EditText) dialog.findViewById(R.id.description);
    final EditText serial = (EditText) dialog.findViewById(R.id.serial);
    final EditText callback = (EditText) dialog.findViewById(R.id.callback);
    final CheckBox status = (CheckBox) dialog.findViewById(R.id.status);

    status.setChecked(true); // by default status is activated

    Button actionButton = (Button) dialog.findViewById(R.id.add_button);

    actionButton.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w w w .ja v a  2 s  .c om*/
        public void onClick(View view) {
            Log.d(TAG_NAME, "name : " + name.getText().toString());
            Log.d(TAG_NAME, "description : " + description.getText().toString());
            Log.d(TAG_NAME, "serial : " + serial.getText().toString());
            Log.d(TAG_NAME, "status : " + status.isChecked());

            Datasource newDatasource = new Datasource();

            newDatasource.setName(name.getText().toString());
            newDatasource.setDescription(description.getText().toString());
            newDatasource.setSerial(serial.getText().toString());

            String callbackUrl = callback.getText().toString();

            if ("".equals(callbackUrl)) {
                newDatasource.setCallback(null);
            } else {
                try {
                    URL url = new URL(callbackUrl);
                    Callback newCallback = new Callback();
                    newCallback.setUrl(url.toString());
                    newCallback.setStatus("activated");
                    newCallback.setName("Callback");
                    newCallback.setDescription("application callback");
                    newDatasource.setCallback(newCallback);
                } catch (MalformedURLException e) {
                    Log.e(TAG_NAME, e.toString());
                    newDatasource.setCallback(null);
                    callback.setText("");
                }
            }

            if (status.isChecked()) {
                newDatasource.setStatus("activated");
            } else {
                newDatasource.setStatus("deactivated");
            }

            CreateDatasourceOperation createDatasourceOperation = new CreateDatasourceOperation(
                    Model.instance.oapiKey, Model.instance.key, newDatasource, new OperationCallback() {
                        @Override
                        public void process(Object object, Exception exception) {
                            if (exception == null) {
                                getDatasources();
                            } else {
                                Errors.displayError(getActivity(), exception);
                            }
                        }
                    });

            createDatasourceOperation.execute("");

            dialog.dismiss();
        }
    });

    Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });

    dialog.setCancelable(false);
    dialog.show();
}

From source file:com.minerva.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    checkAndRequestPermissions();//from  ww w  .ja v a2s  .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();
}