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.inc.playground.playground.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
    // Create the adapter that will return a fragment for each of the three primary sections
    // of the app.
    mAppSectionsPagerAdapter = new AppSectionsPagerAdapter(getSupportFragmentManager());

    globalVariables = ((GlobalVariables) getApplication());
    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    setPlayGroundActionBar();//w  ww  . j a va  2  s  . co m
    //set actionBar color
    actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.primaryColor)));
    actionBar.setStackedBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.secondaryColor)));
    // Specify that the Home/Up button should not be enabled, since there is no hierarchical
    // parent.
    //actionBar.setHomeButtonEnabled(false);
    actionBar.setDisplayShowHomeEnabled(false);
    // Specify that we will be displaying tabs in the action bar.
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager, attaching the adapter and setting up a listener for when the
    // user swipes between sections.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mAppSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            // When swiping between different app sections, select the corresponding tab.
            // We can also use ActionBar.Tab#select() to do this if we have a reference to the
            // Tab.
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mAppSectionsPagerAdapter.getCount(); i++) {
        // Create a tab with text corresponding to the page title defined by the adapter.
        // Also specify this Activity object, which implements the TabListener interface, as the
        // listener for when this tab is selected.
        actionBar.addTab(actionBar.newTab().setTabListener(this));
    }
    actionBar.getTabAt(0).setIcon(R.drawable.pg_list_view);
    actionBar.getTabAt(1).setIcon(R.drawable.pg_map_view);
    actionBar.getTabAt(2).setIcon(R.drawable.pg_calendar_view);
    //NavigationDrawer handling (e.g the list from leftside):
    mTitle = mDrawerTitle = getTitle();
    mDrawerLayout = (DrawerLayout) findViewById(R.id.menu_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.pg_menu, /* nav drawer icon to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description */
            R.string.drawer_close /* "close drawer" description */
    ) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            getActionBar().setTitle(mTitle);
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            getActionBar().setTitle(mDrawerTitle);
        }
    };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);
    mDrawerLayout.closeDrawers();
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // all linear layout from slider menu

    /*Home button */
    LinearLayout ll_Home = (LinearLayout) findViewById(R.id.ll_home);
    ll_Home.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, MainActivity.class);
            startActivity(iv);
            finish();
        }
    });
    /*Login button */
    LinearLayout ll_Login = (LinearLayout) findViewById(R.id.ll_login);
    ll_Login.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            LinearLayout ll_Login = (LinearLayout) v;
            TextView loginTxt = (TextView) findViewById(R.id.login_txt);
            if (loginTxt.getText().equals("Login")) {
                Intent iv = new Intent(MainActivity.this, Login.class);
                startActivity(iv);
                finish();
            } else if (loginTxt.getText().equals("Logout")) {
                final Dialog alertDialog = new Dialog(MainActivity.this);
                alertDialog.setContentView(R.layout.logout_dilaog);
                alertDialog.setTitle("Logout");
                alertDialog.findViewById(R.id.ok_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {

                        SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE);
                        SharedPreferences.Editor editor = prefs.edit();
                        editor.clear();
                        editor.commit();
                        ImageView loginImg = (ImageView) findViewById(R.id.login_img);
                        TextView loginTxt = (TextView) findViewById(R.id.login_txt);
                        loginTxt.setText("Login");
                        loginImg.setImageResource(R.drawable.pg_action_lock_open);

                        globalVariables = ((GlobalVariables) getApplication());
                        globalVariables.SetCurrentUser(null);
                        globalVariables.SetUserPictureBitMap(null);
                        globalVariables.SetUsersList(null);
                        globalVariables.SetUsersImagesMap(null);

                        Util.clearCookies(getApplicationContext());

                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.findViewById(R.id.cancel_btn).setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent iv = new Intent(MainActivity.this, MainActivity.class);
                        startActivity(iv);
                        finish();
                    }
                });

                alertDialog.show(); //<-- See This!
            }

        }
    });

    /*Setting button*/
    LinearLayout ll_Setting = (LinearLayout) findViewById(R.id.ll_settings);
    ll_Setting.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this,
                    com.inc.playground.playground.upLeft3StripesButton.SettingsActivity.class);
            startActivity(iv);
            finish();
        }
    });

    /*My profile button*/
    LinearLayout ll_my_profile = (LinearLayout) findViewById(R.id.ll_my_profile);
    ll_my_profile.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // new changes
            globalVariables = ((GlobalVariables) getApplication());
            User currentUser = globalVariables.GetCurrentUser();
            if (currentUser == null) {
                Toast.makeText(MainActivity.this, "You are not logged in", Toast.LENGTH_LONG).show();
            } else {

                Intent iv = new Intent(MainActivity.this,
                        com.inc.playground.playground.upLeft3StripesButton.MyProfile.class);

                //for my profile
                iv.putExtra("name", currentUser.getName());
                iv.putExtra("createdNumOfEvents", currentUser.getCreatedNumOfEvents());
                //pass events
                iv.putExtra("events", currentUser.getEvents());
                iv.putExtra("events_wait4approval", currentUser.getEvents_wait4approval());
                iv.putExtra("events_decline", currentUser.getEvents_decline());

                iv.putExtra("photoUrl", currentUser.getPhotoUrl());
                startActivity(iv);
                //
            }
        }
    });

    LinearLayout ll_aboutUs = (LinearLayout) findViewById(R.id.ll_about);
    ll_aboutUs.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // new changes
            Intent iv = new Intent(MainActivity.this, AboutUs.class);
            startActivity(iv);
            finish();
        }
    });

}

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

@Override
protected Dialog onCreateDialog(int id) {
    final Dialog dialog;
    switch (id) {

    case R.id.DIALOG_EDIT_CORE: //fallthrough
    case R.id.DIALOG_ADD_CORE:
        dialog = new Dialog(this);
        dialog.setContentView(R.layout.dialog_add_core);
        dialog.setTitle("Add new core");

        OnClickListener buttonListener = new OnClickListener() {

            @Override/*from w  ww .  j  av a2  s.co  m*/
            public void onClick(View v) {
                EditText nameField = (EditText) dialog.findViewById(R.id.dialog_name_field);
                EditText addressField = (EditText) dialog.findViewById(R.id.dialog_address_field);
                EditText portField = (EditText) dialog.findViewById(R.id.dialog_port_field);
                CheckBox sslBox = (CheckBox) dialog.findViewById(R.id.dialog_usessl_checkbox);
                if (v.getId() == R.id.cancel_button) {
                    nameField.setText("");
                    addressField.setText("");
                    portField.setText("");
                    sslBox.setChecked(false);
                    dialog.dismiss();

                } else if (v.getId() == R.id.save_button && !nameField.getText().toString().equals("")
                        && !addressField.getText().toString().equals("")
                        && !portField.getText().toString().equals("")) {
                    String name = nameField.getText().toString().trim();
                    String address = addressField.getText().toString().trim();
                    int port = Integer.parseInt(portField.getText().toString().trim());
                    boolean useSSL = sslBox.isChecked();

                    //TODO: Ken: mabye add some better check on what state the dialog is used for, edit/add. Atleast use a string from the resources so its the same if you change it.
                    if ((String) dialog.getWindow().getAttributes().getTitle() == "Add new core") {
                        dbHelper.addCore(name, address, port, useSSL);
                    } else if ((String) dialog.getWindow().getAttributes().getTitle() == "Edit core") {
                        dbHelper.updateCore(core.getSelectedItemId(), name, address, port, useSSL);
                    }
                    LoginActivity.this.updateCoreSpinner();
                    nameField.setText("");
                    addressField.setText("");
                    portField.setText("");
                    sslBox.setChecked(false);
                    dialog.dismiss();
                    if ((String) dialog.getWindow().getAttributes().getTitle() == "Add new core") {
                        Toast.makeText(LoginActivity.this, "Added core", Toast.LENGTH_LONG).show();
                    } else if ((String) dialog.getWindow().getAttributes().getTitle() == "Edit core") {
                        Toast.makeText(LoginActivity.this, "Edited core", Toast.LENGTH_LONG).show();
                    }
                }

            }
        };
        dialog.findViewById(R.id.cancel_button).setOnClickListener(buttonListener);
        dialog.findViewById(R.id.save_button).setOnClickListener(buttonListener);
        break;

    case R.id.DIALOG_NEW_CERTIFICATE:
        AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
        final SharedPreferences certPrefs = getSharedPreferences("CertificateStorage", Context.MODE_PRIVATE);
        builder.setMessage("Received a new certificate, do you trust it?\n" + hashedCert).setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        certPrefs.edit().putString("certificate", hashedCert).commit();
                        onConnect.onClick(null);
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
        dialog = builder.create();
        break;

    default:
        dialog = null;
        break;
    }
    return dialog;
}

From source file:com.andrewshu.android.reddit.submit.SubmitLinkActivity.java

@Override
protected void onPrepareDialog(int id, Dialog dialog) {
    super.onPrepareDialog(id, dialog);

    switch (id) {
    case Constants.DIALOG_LOGIN:
        if (mSettings.getUsername() != null) {
            final TextView loginUsernameInput = (TextView) dialog.findViewById(R.id.login_username_input);
            loginUsernameInput.setText(mSettings.getUsername());
        }/* w w  w  . j  a va 2  s.com*/
        final TextView loginPasswordInput = (TextView) dialog.findViewById(R.id.login_password_input);
        loginPasswordInput.setText("");
        break;

    default:
        break;
    }
}

From source file:com.hacktx.android.activities.EventDetailActivity.java

private void setupCards() {
    final CardView rateEventCard = (CardView) findViewById(R.id.rateEventCard);

    View.OnClickListener feedbackOnClickListener = new View.OnClickListener() {
        @Override/* ww  w  .  j ava2 s  .co  m*/
        public void onClick(View v) {
            if (!UserStateStore.getFeedbackSubmitted(EventDetailActivity.this, event.getId())) {
                final Dialog dialog = new Dialog(EventDetailActivity.this);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.dialog_feedback);
                WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
                params.width = WindowManager.LayoutParams.MATCH_PARENT;
                dialog.getWindow().setAttributes(params);
                dialog.show();

                final RatingBar ratingBar = (RatingBar) dialog.findViewById(R.id.feedbackDialogRatingBar);
                dialog.findViewById(R.id.feedbackDialogCancel).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        mMetricsManager.logEvent(R.string.analytics_event_feedback_cancel, null);
                        dialog.dismiss();
                    }
                });
                dialog.findViewById(R.id.feedbackDialogSubmit).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        HackTxService hackTxService = HackTxClient.getInstance().getApiService();
                        hackTxService.sendFeedback(event.getId(), (int) ratingBar.getRating(),
                                new Callback<EventFeedback>() {
                                    @Override
                                    public void success(EventFeedback feedback, Response response) {
                                        mMetricsManager.logEvent(R.string.analytics_event_feedback_submit,
                                                null);
                                        UserStateStore.setFeedbackSubmitted(EventDetailActivity.this,
                                                event.getId(), true);
                                        findViewById(R.id.rateEventCard).setVisibility(View.GONE);
                                        dialog.dismiss();
                                        Snackbar.make(findViewById(android.R.id.content),
                                                R.string.event_feedback_submitted, Snackbar.LENGTH_SHORT)
                                                .show();
                                    }

                                    @Override
                                    public void failure(RetrofitError error) {
                                        Log.e("EventDetailActivity",
                                                "Error when submitting feedback: " + error.getMessage());
                                        dialog.dismiss();
                                        Snackbar.make(findViewById(android.R.id.content),
                                                R.string.event_feedback_failed, Snackbar.LENGTH_SHORT).show();
                                    }
                                });
                    }
                });
            } else {
                mMetricsManager.logEvent(R.string.analytics_event_feedback_already_submitted, null);
                Snackbar.make(findViewById(android.R.id.content), R.string.event_feedback_already_submitted,
                        Snackbar.LENGTH_SHORT).show();
            }
        }
    };

    if (shouldShowFeedbackCard()) {
        findViewById(R.id.rateEventCardOk).setOnClickListener(feedbackOnClickListener);

        findViewById(R.id.rateEventCardNoThanks).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMetricsManager.logEvent(R.string.analytics_event_feedback_no_thanks, null);
                UserStateStore.setFeedbackIgnored(EventDetailActivity.this, event.getId(), true);
                rateEventCard.setVisibility(View.GONE);
            }
        });
    } else {
        findViewById(R.id.rateEventCard).setVisibility(View.GONE);
    }

    if (!mConfigManager.getValue(ConfigParam.EVENT_FEEDBACK)) {
        findViewById(R.id.rateEventCard).setVisibility(View.GONE);
    }
}

From source file:com.example.alyshia.customsimplelauncher.MainActivity.java

void inflateDialog(int type) {
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("PASSWORD");

    LayoutInflater inflater = LayoutInflater.from(this);
    final View view = inflater.inflate(R.layout.dialoglayout, null);
    EditText edittext = (EditText) view.findViewById(R.id.pswEditText);

    alert.setView(R.layout.dialoglayout);
    if (type == TYPE_EXIT) {
        alert.setPositiveButton("Enter", new DialogInterface.OnClickListener() {
            @Override/*w  w  w. j  a v a2s . c o  m*/
            public void onClick(DialogInterface dialog, int which) {
                Dialog d = (Dialog) dialog;
                EditText et = (EditText) d.findViewById(R.id.pswEditText);
                Log.d(TAG, "TEXT is " + et.getText().toString());
                if (et.getText().toString().equals("")) {
                    dialog.dismiss();
                    Toast.makeText(MainActivity.this, "wrong password", Toast.LENGTH_SHORT).show();
                } else if (et.getText().toString().equals(getPW())) {
                    setkioskReceiver();
                    if (km == null) {
                        km = KioskMode.getInstance(getApplicationContext());
                    }
                    if (km.isKioskModeEnabled()) {
                        Log.d(TAG, "Kioskmode being disabled bc it is enabled");
                        km.disableKioskMode();
                    }
                }

            }
        });
    } else if (type == TYPE_ADMIN) {
        alert.setPositiveButton("Enter", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                Dialog d = (Dialog) dialog;
                EditText et = (EditText) d.findViewById(R.id.pswEditText);
                Log.d(TAG, "TEXT is " + et.getText().toString());
                if (et.getText().toString().equals("")) {
                    dialog.dismiss();
                } else if (et.getText().toString().equals(getPW())) {
                    Intent intent = new Intent(MainActivity.this, AdminActivity.class);
                    startActivity(intent);
                }

            }
        });
    }

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    alert.setCancelable(true);
    AlertDialog cdialog = alert.create();
    cdialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    cdialog.show();

}

From source file:com.cellobject.oikos.FormActivity.java

private void initializeSettingsAndInfoButtons() {
    preferencesBtn = (ImageButton) findViewById(R.id.preferences_btn);
    preferencesBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(final View view) {
            final Intent intent = new Intent(FormActivity.this, OikosPreferenceActivity.class);
            startActivity(intent);//from  w  w  w  .  j a v  a2 s  .c o  m
        }
    });
    infoBtn = (ImageButton) findViewById(R.id.info_btn);
    infoBtn.setOnClickListener(new View.OnClickListener() {
        public void onClick(final View view) {
            final Dialog dialog = new Dialog(FormActivity.this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setContentView(R.layout.info);
            final Button button = (Button) dialog.findViewById(R.id.aboutOk);
            button.setOnClickListener(new OnClickListener() {
                public void onClick(final View v) {
                    dialog.dismiss();
                }
            });
            dialog.show();
        }
    });
}

From source file:org.tigase.mobile.chat.ChatHistoryFragment.java

private void showMessageDetails(final long id) {
    Cursor cc = null;/*from w ww .ja v  a2  s .c o  m*/
    final java.text.DateFormat df = DateFormat.getDateFormat(getActivity());
    final java.text.DateFormat tf = DateFormat.getTimeFormat(getActivity());

    try {
        cc = getChatEntry(id);

        Dialog alertDialog = new Dialog(getActivity());
        alertDialog.setContentView(R.layout.chat_item_details_dialog);
        alertDialog.setCancelable(true);
        alertDialog.setCanceledOnTouchOutside(true);
        alertDialog.setTitle("Message details");

        TextView msgDetSender = (TextView) alertDialog.findViewById(R.id.msgDetSender);
        msgDetSender.setText(cc.getString(cc.getColumnIndex(ChatTableMetaData.FIELD_JID)));

        Date timestamp = new Date(cc.getLong(cc.getColumnIndex(ChatTableMetaData.FIELD_TIMESTAMP)));
        TextView msgDetReceived = (TextView) alertDialog.findViewById(R.id.msgDetReceived);
        msgDetReceived.setText(df.format(timestamp) + " " + tf.format(timestamp));

        final int state = cc.getInt(cc.getColumnIndex(ChatTableMetaData.FIELD_STATE));
        TextView msgDetState = (TextView) alertDialog.findViewById(R.id.msgDetState);
        switch (state) {
        case ChatTableMetaData.STATE_INCOMING:
            msgDetState.setText("Received");
            break;
        case ChatTableMetaData.STATE_OUT_SENT:
            msgDetState.setText("Sent");
            break;
        case ChatTableMetaData.STATE_OUT_NOT_SENT:
            msgDetState.setText("Not sent");
            break;
        default:
            msgDetState.setText("?");
            break;
        }

        alertDialog.show();
    } finally {
        if (cc != null && !cc.isClosed())
            cc.close();
    }
}

From source file:com.vkassin.mtrade.Common.java

public static void login(final Context ctx) {

    // ctx = Common.app_ctx;
    Common.connected = false;/*ww w. j  av  a  2 s. c o m*/

    if (inLogin)
        return;

    inLogin = true;

    if (Common.mainActivity != null)
        Common.mainActivity.handler.sendMessage(
                Message.obtain(Common.mainActivity.handler, Common.mainActivity.DISMISS_PROGRESS_DIALOG));

    // while(true) {

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.login_dialog);
    dialog.setTitle(R.string.LoginDialogTitle);
    dialog.setCancelable(false);

    final EditText nametxt = (EditText) dialog.findViewById(R.id.loginnameedit);
    final EditText passtxt = (EditText) dialog.findViewById(R.id.passwordedit);
    final EditText passtxt1 = (EditText) dialog.findViewById(R.id.passwordedit1);
    final EditText passtxt2 = (EditText) dialog.findViewById(R.id.passwordedit2);
    final EditText mailtxt = (EditText) dialog.findViewById(R.id.emailedit2);

    String nam = myaccount.get("name");
    Common.oldName = nam;

    if (nam != null) {

        nametxt.setText(nam);
        passtxt.requestFocus();
    }

    Button customDialog_Register = (Button) dialog.findViewById(R.id.goregister);
    customDialog_Register.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.setTitle(R.string.LoginDialogTitle1);
            final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
            layreg.setVisibility(View.VISIBLE);
            final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
            laylog.setVisibility(View.GONE);
        }

    });

    Button customDialog_Register1 = (Button) dialog.findViewById(R.id.goregister1);
    customDialog_Register1.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            if (mailtxt.getText().length() < 1) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectEmail, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();

                return;
            }

            if (passtxt1.getText().length() < 1) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
                return;
            }

            if (!passtxt2.getText().toString().equals(passtxt1.getText().toString())) {

                Toast toast = Toast.makeText(mainActivity, R.string.CorrectPassword1, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();
                return;
            }

            try {

                Socket sock = new Socket(ip_addr, port_register);

                JSONObject msg = new JSONObject();
                msg.put("objType", Common.MSG_REGISTER);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("user", mailtxt.getText().toString());
                msg.put("passwd", passtxt1.getText().toString());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("sign", sign(mailtxt.getText().toString(), passtxt1.getText().toString()));

                byte[] array = msg.toString().getBytes();
                ByteBuffer buff = ByteBuffer.allocate(array.length + 4);
                buff.putInt(array.length);
                buff.put(array);
                sock.getOutputStream().write(buff.array());

                ByteBuffer buff1 = ByteBuffer.allocate(4);
                buff1.put(readMsg(sock.getInputStream(), 4));
                buff1.position(0);
                int pkgSize = buff1.getInt();
                // Log.i(TAG, "size = "+pkgSize);
                String s = new String(readMsg(sock.getInputStream(), pkgSize));

                sock.close();

                JSONObject jo = new JSONObject(s);

                Log.i(TAG, "register answer = " + jo);

                int t = jo.getInt("status");
                switch (t) {

                case 1:
                    Toast toast = Toast.makeText(mainActivity, R.string.RegisterStatus1, Toast.LENGTH_LONG);
                    toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast.show();

                    dialog.setTitle(R.string.LoginDialogTitle);
                    final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
                    layreg.setVisibility(View.GONE);
                    final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
                    laylog.setVisibility(View.VISIBLE);

                    nametxt.setText(mailtxt.getText());
                    break;

                case -2:
                    Toast toast1 = Toast.makeText(mainActivity, R.string.RegisterStatus3, Toast.LENGTH_LONG);
                    toast1.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast1.show();
                    break;

                default:
                    Toast toast2 = Toast.makeText(mainActivity, R.string.RegisterStatus2, Toast.LENGTH_LONG);
                    toast2.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                    toast2.show();
                    break;

                }

            } catch (Exception e) {

                e.printStackTrace();
                Log.e(TAG, "Error in registration process!!", e);

                Toast toast = Toast.makeText(mainActivity, R.string.ConnectError, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 0);
                toast.show();

            }

        }

    });

    Button customDialog_CancelReg = (Button) dialog.findViewById(R.id.cancelreg);
    customDialog_CancelReg.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.setTitle(R.string.LoginDialogTitle);
            final LinearLayout layreg = (LinearLayout) dialog.findViewById(R.id.reglayout354);
            layreg.setVisibility(View.GONE);
            final LinearLayout laylog = (LinearLayout) dialog.findViewById(R.id.loginlayout543);
            laylog.setVisibility(View.VISIBLE);

        }

    });

    Button customDialog_Dismiss = (Button) dialog.findViewById(R.id.gologin);
    customDialog_Dismiss.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.lradio0);
            Common.isSSL = bu0.isChecked();

            inLogin = false;

            JSONObject msg = new JSONObject();
            try {

                msg.put("objType", Common.LOGOUT);
                msg.put("time", Calendar.getInstance().getTimeInMillis());
                msg.put("version", Common.PROTOCOL_VERSION);
                msg.put("status", 1);
                mainActivity.writeJSONMsg(msg);
            } catch (Exception e) {
                e.printStackTrace();
                Log.e(TAG, "Error! Cannot create JSON logout object", e);
            }

            myaccount.put("name", nametxt.getText().toString());
            myaccount.put("password", passtxt.getText().toString());

            Log.i(TAG,
                    "myaccount username: " + myaccount.get("name") + " password: " + myaccount.get("password"));

            dialog.dismiss();
            mainActivity.stop();
            // saveAccountDetails();
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            loginFromDialog = true;
            //            mainActivity.refresh();

            Common.keypassword(ctx);
        }

    });

    dialog.show();
    // Common.confChanged = false;
    // }//while(true);

}

From source file:course1778.mobileapp.safeMedicare.Main.FamMemFrag.java

public void onClick(DialogInterface di, int whichButton) {
    // get strings from edittext boxes, then insert them into database
    ContentValues values = new ContentValues(DatabaseHelper.CONTENT_VALUE_COUNT);
    ContentValues drugInteractionValues = new ContentValues(4);
    Dialog dlg = (Dialog) di;
    EditText title = (EditText) dlg.findViewById(R.id.title);
    TimePicker tp = (TimePicker) dlg.findViewById(R.id.timePicker);
    Spinner mySpinner = (Spinner) dlg.findViewById(R.id.spinner);
    String fre = mySpinner.getSelectedItem().toString();
    EditText dosage = (EditText) dlg.findViewById(R.id.dosage);
    EditText instruction = (EditText) dlg.findViewById(R.id.instruction);
    RadioGroup radioButtonGroup = (RadioGroup) dlg.findViewById(R.id.radioGroup);
    int radioButtonID = radioButtonGroup.getCheckedRadioButtonId();
    View radioButton = radioButtonGroup.findViewById(radioButtonID);
    int shape = radioButtonGroup.indexOfChild(radioButton) / 2;
    int Fre;/*ww  w .  j a  v  a 2 s. c o m*/
    //int day = 0;
    int monday = 0, tuesday = 0, wednesday = 0, thursday = 0, friday = 0, saturday = 0, sunday = 0;

    // clear array list
    drug_interaction_list.clear();
    curr_drug_interaction_list.clear();

    // loop through database
    crsInteractions.moveToPosition(-1);
    while (crsInteractions.moveToNext()) {
        // drug names
        drugName = crsInteractions.getString(crsInteractions.getColumnIndex(DatabaseHelper.SHEET_1_DRUG_NAMES));

        // corresponding interacted drugs/foods
        interactionName = crsInteractions
                .getString(crsInteractions.getColumnIndex(DatabaseHelper.SHEET_1_DRUG_INTERACTIONS));

        // interaction result
        interactionResult = crsInteractions
                .getString(crsInteractions.getColumnIndex(DatabaseHelper.SHEET_1_INTERACTION_RESULT));

        // medication name entered by user
        medNameFieldTxt = textView.getText().toString();

        // check if newly entered medication name matches current drug name
        if (drugName.equals(medNameFieldTxt)) {
            /**if found, check if the corresponding interaction
             * drug in the list of all added drugs by user
             */
            if (db.isNameExitOnDB(interactionName)) {
                // interaction found
                Log.d("myinteraction", "Found Interaction");

                String interaction_result = medNameFieldTxt + "/" + interactionName + "\n";

                // only insert new drug interactions if they have not yet exist
                if (!dbInteraction.isDrugInteractionExist(medNameFieldTxt, interactionName)) {
                    // insert the drug interaction into our new dynamic drug interaction db
                    drugInteractionValues.put(DatabaseInteractionHelper.USR_NAME,
                            ParseUser.getCurrentUser().getUsername());
                    drugInteractionValues.put(DatabaseInteractionHelper.DRUG_NAME, medNameFieldTxt);
                    drugInteractionValues.put(DatabaseInteractionHelper.DRUG_INTERACTION, interactionName);
                    drugInteractionValues.put(DatabaseInteractionHelper.DRUG_INTERACTION_SHOW,
                            DatabaseInteractionHelper.DRUG_INTERACTION_SHOW_TRUE);

                    dbInteraction.getWritableDatabase().insert(DatabaseInteractionHelper.TABLE,
                            DatabaseInteractionHelper.DRUG_NAME, drugInteractionValues);
                }

                drug_interaction_list.add(interaction_result);
                curr_drug_interaction_list.add(interactionName);
            }
        }
    }

    Log.d("mydatabase3", DatabaseUtils.dumpCursorToString(dbInteraction.getCursor()));

    // display all iteractions in pop window if there is any
    String interaction_results = "\n";
    for (int i = 0; i < curr_drug_interaction_list.size(); i++) {
        String interaction = medNameFieldTxt + " & " + curr_drug_interaction_list.get(i) + "\n\n";
        interaction_results = interaction_results.concat(interaction);
    }

    if (drug_interaction_list.size() != 0) {
        // inflate a dialog to display the drug interactions warning
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View resultView = inflater.inflate(R.layout.drug_interaction_result, null);
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

        builder.setTitle(R.string.drug_interaction_result_title).setView(resultView)
                // go to drug interaction list button
                .setNegativeButton(R.string.drug_interaction_list, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        // drug interaction page
                        DrugInteractions drugInterac = new DrugInteractions();
                        FragmentTransaction transaction;
                        transaction = getFragmentManager().beginTransaction();
                        transaction.replace(R.id.fragmentContainer, drugInterac);
                        transaction.addToBackStack(null);
                        // Commit the transaction
                        transaction.commit();
                    }
                })

                // ok button
                .setPositiveButton(R.string.dismiss, null).show();

        TextView interactionResultView = (TextView) resultView.findViewById(R.id.resultView);

        // add warning message into the pop up window
        interaction_results = interaction_results.concat(getString(R.string.interaction_warning));

        // display on pop up window
        interactionResultView.setText(interaction_results);
    }

    // write the list of drug interactions into file
    Helpers.writeToFile(getContext(), drug_interaction_list, "drug_interaction_list");

    Log.d("mydatabase", DatabaseUtils.dumpCursorToString(db.getCursor()));

    if (fre == "Ten Times a Day") {
        Fre = 10;
    } else if (fre == "Twice a Day") {
        Fre = 2;
    } else if (fre == "Three Times a Day") {
        Fre = 3;
    } else if (fre == "Four Times a Day") {
        Fre = 4;
    } else if (fre == "Five Times a Day") {
        Fre = 5;
    } else if (fre == "Six Times a Day") {
        Fre = 6;
    } else if (fre == "Seven Times a Day") {
        Fre = 7;
    } else if (fre == "Eight Times a Day") {
        Fre = 8;
    } else if (fre == "Nine Times a Day") {
        Fre = 9;
    } else {
        Fre = 1;
    }

    if (((CheckBox) dlg.findViewById(R.id.MonCheck)).isChecked()) {
        monday = monday + 1;
    }
    if (((CheckBox) dlg.findViewById(R.id.TueCheck)).isChecked()) {
        tuesday = tuesday + 1;
    }
    if (((CheckBox) dlg.findViewById(R.id.WedCheck)).isChecked()) {
        wednesday = wednesday + 1;
    }
    if (((CheckBox) dlg.findViewById(R.id.ThuCheck)).isChecked()) {
        thursday = thursday + 1;
    }
    if (((CheckBox) dlg.findViewById(R.id.FriCheck)).isChecked()) {
        friday = friday + 1;
    }
    if (((CheckBox) dlg.findViewById(R.id.SatCheck)).isChecked()) {
        saturday = saturday + 1;
    }
    if (((CheckBox) dlg.findViewById(R.id.SunCheck)).isChecked()) {
        sunday = sunday + 1;
    }

    // clear focus before retrieving the min and hr
    tp.clearFocus();

    int tpMinute = tp.getCurrentMinute();
    int tpHour = tp.getCurrentHour();
    // an order number to order the list view items
    int orderNum = tpHour * 60 + tpMinute;
    tp.setIs24HourView(true);

    String titleStr = title.getText().toString();
    String timeHStr = Helpers.StringFormatter(tpHour, "00");
    String timeMStr = Helpers.StringFormatter(tpMinute, "00");
    String dosageStr = dosage.getText().toString();
    String instructionStr = instruction.getText().toString();

    Log.d("mytime", Integer.toString(tpHour));
    Log.d("mytime", Integer.toString(tpMinute));

    values.put(DatabaseHelper.USRNAME, ParseUser.getCurrentUser().getUsername());
    values.put(DatabaseHelper.TITLE, titleStr);
    values.put(DatabaseHelper.TIME_H, timeHStr);
    values.put(DatabaseHelper.TIME_M, timeMStr);
    values.put(DatabaseHelper.FREQUENCY, Fre);
    //values.put(DatabaseHelper.DAY, day);

    values.put(DatabaseHelper.MONDAY, monday);
    values.put(DatabaseHelper.TUESDAY, tuesday);
    values.put(DatabaseHelper.WEDNESDAY, wednesday);
    values.put(DatabaseHelper.THURSDAY, thursday);
    values.put(DatabaseHelper.FRIDAY, friday);
    values.put(DatabaseHelper.SATURDAY, saturday);
    values.put(DatabaseHelper.SUNDAY, sunday);

    values.put(DatabaseHelper.DOSAGE, dosageStr);
    values.put(DatabaseHelper.INSTRUCTION, instructionStr);
    values.put(DatabaseHelper.SHAPE, shape);
    values.put(DatabaseHelper.ORDER_NUM, orderNum);

    Bundle bundle = new Bundle();
    // add extras here..
    bundle.putString(DatabaseHelper.TITLE, title.getText().toString());
    bundle.putString(DatabaseHelper.TIME_H, timeHStr);
    bundle.putString(DatabaseHelper.TIME_M, timeMStr);
    bundle.putInt(DatabaseHelper.FREQUENCY, Fre);
    //bundle.putInt(DatabaseHelper.DAY, day);

    bundle.putInt(DatabaseHelper.MONDAY, monday);
    bundle.putInt(DatabaseHelper.TUESDAY, tuesday);
    bundle.putInt(DatabaseHelper.WEDNESDAY, wednesday);
    bundle.putInt(DatabaseHelper.THURSDAY, thursday);
    bundle.putInt(DatabaseHelper.FRIDAY, friday);
    bundle.putInt(DatabaseHelper.SATURDAY, saturday);
    bundle.putInt(DatabaseHelper.SUNDAY, sunday);

    bundle.putString(DatabaseHelper.DOSAGE, dosageStr);
    bundle.putString(DatabaseHelper.INSTRUCTION, instructionStr);
    bundle.putInt(DatabaseHelper.SHAPE, shape);
    bundle.putInt(DatabaseHelper.ORDER_NUM, orderNum);
    //Alarm alarm = new Alarm(getActivity().getApplicationContext(), bundle);

    // get unique notifyId for each alarm
    int length = title.length();
    for (int i = 0; i < length; i++) {
        notifyId = (int) titleStr.charAt(i) + notifyId;
    }
    notifyId = Integer.parseInt(timeHStr + timeMStr);

    // saving it into parse.com
    ParseObject parseObject = new ParseObject(Helpers.PARSE_OBJECT);
    parseObject.put(DatabaseHelper.USRNAME, ParseUser.getCurrentUser().getUsername());
    parseObject.put(DatabaseHelper.TITLE, titleStr);
    parseObject.put(DatabaseHelper.TIME_H, timeHStr);
    parseObject.put(DatabaseHelper.TIME_M, timeMStr);
    parseObject.put(DatabaseHelper.FREQUENCY, Fre);
    //parseObject.put(DatabaseHelper.DAY, day);

    parseObject.put(DatabaseHelper.MONDAY, monday);
    parseObject.put(DatabaseHelper.TUESDAY, tuesday);
    parseObject.put(DatabaseHelper.WEDNESDAY, wednesday);
    parseObject.put(DatabaseHelper.THURSDAY, thursday);
    parseObject.put(DatabaseHelper.FRIDAY, friday);
    parseObject.put(DatabaseHelper.SATURDAY, saturday);
    parseObject.put(DatabaseHelper.SUNDAY, sunday);

    parseObject.put(DatabaseHelper.DOSAGE, dosageStr);
    parseObject.put(DatabaseHelper.INSTRUCTION, instructionStr);
    parseObject.put(DatabaseHelper.SHAPE, shape);
    parseObject.put(DatabaseHelper.NOFITY_ID, notifyId);
    parseObject.put(DatabaseHelper.ORDER_NUM, orderNum);
    parseObject.saveInBackground();

    task = new InsertTask().execute(values);
}

From source file:com.openerp.addons.idea.product.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case R.id.Dash_Board:

        Dash_Board detail = new Dash_Board();
        FragmentListener frag = (FragmentListener) getActivity();
        frag.startDetailFragment(detail);

        return true;

    case R.id.Search_product:

        final Dialog dialog = new Dialog(getActivity());
        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
        dialog.setContentView(R.layout.product_search_custom_dialog);
        //   dialog.setTitle("Product Search");
        dialog.setOnCancelListener(new OnCancelListener() {

            @Override/*from   www.jav  a  2 s .  c o  m*/
            public void onCancel(DialogInterface dialog) {

                dialog.dismiss();
            }
        });

        AutoCompleteTextView autotext = (AutoCompleteTextView) dialog
                .findViewById(R.id.autoCompleteTextView_product_search);
        final ArrayAdapter adapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1,
                OEHelper.datatemplate);
        TextView txv = (TextView) dialog.findViewById(R.id.textView1);
        Typeface font = Typeface.createFromAsset(getActivity().getAssets(), "fonts/Georgia.ttf");
        autotext.setTypeface(font, Typeface.BOLD);
        autotext.setAdapter(adapter);
        txv.setTypeface(font, Typeface.BOLD);
        autotext.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

                String name = adapter.getItem(arg2).toString();
                callmethod_for_position_productdetail(OEHelper.datatemplate.indexOf(name));
                dialog.dismiss();
            }
        });

        dialog.show();
        return true;
    }
    return true;
}