Example usage for android.app Dialog setTitle

List of usage examples for android.app Dialog setTitle

Introduction

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

Prototype

public void setTitle(@StringRes int titleId) 

Source Link

Document

Set the title text for this dialog's window.

Usage

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

/**
 *
 */// w ww  . j  a  v  a 2  s  .c  o  m
private void createStream() {
    final android.app.Dialog dialog = new android.app.Dialog(getActivity());

    dialog.setContentView(R.layout.create_stream_dialog);

    dialog.setTitle(R.string.add_stream);

    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 unit = (EditText) dialog.findViewById(R.id.unit);
    final EditText symbol = (EditText) dialog.findViewById(R.id.symbol);
    final EditText callback = (EditText) dialog.findViewById(R.id.callback);
    final EditText latitude = (EditText) dialog.findViewById(R.id.latitude);
    final EditText longitude = (EditText) dialog.findViewById(R.id.longitude);

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

    callbackLayout.setVisibility(View.VISIBLE);
    actionButton.setText(getString(R.string.add_stream));

    actionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        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, "unit : " + unit.getText().toString());
            Log.d(TAG_NAME, "symbol : " + symbol.getText().toString());

            Stream newStream = new Stream();

            newStream.setName(name.getText().toString());
            newStream.setDescription(description.getText().toString());

            /**
             * Allocate new Location
             */
            Double[] location = null;

            String strLatitude = latitude.getText().toString();
            String strLongitude = longitude.getText().toString();

            try {
                if ((!"".equals(strLatitude)) && (!"".equals(strLongitude))) {
                    location = new Double[2];
                    location[0] = Double.parseDouble(strLatitude);
                    location[1] = Double.parseDouble(strLongitude);
                }
            } catch (NumberFormatException e) {
                Log.e(TAG_NAME, e.toString());
                location = null;
            }

            if (location != null) {
                newStream.setLocation(location);
            }
            /**************************************************************************/

            /**
             * Allocate new Unit & Symbol
             */
            Unit newUnit = null;
            String strUnit = unit.getText().toString();
            String strSymbol = symbol.getText().toString();

            if (!"".equals(strUnit)) {
                if (newUnit == null) {
                    newUnit = new Unit();
                }
                newUnit.setName(strUnit);
            }

            if (!"".equals(strSymbol)) {
                if (newUnit == null) {
                    newUnit = new Unit();
                }
                newUnit.setSymbol(strSymbol);
            }

            if (newUnit != null) {
                newStream.setUnit(newUnit);
            }

            /**
             * Allocate new Callback
             */
            Callback newCallback = null;
            String callbackUrl = callback.getText().toString();

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

            if (newCallback != null) {
                newStream.setCallback(newCallback);
            }

            /**************************************************************************/

            CreateStreamOperation createStreamOperation = new CreateStreamOperation(Model.instance.oapiKey,
                    Model.instance.key, Model.instance.currentDatasource, newStream, new OperationCallback() {
                        @Override
                        public void process(Object object, Exception exception) {
                            if (exception == null) {
                                getStreams();
                            } else {
                                Errors.displayError(getActivity(), exception);
                            }
                        }
                    });

            createStreamOperation.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:eu.trentorise.smartcampus.cm.fragments.groups.MyGroupsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.mygroups_add:
        Dialog dialog = new MyGroupsAddDialog(getActivity(), new DialogHandler<String>() {
            @Override//w w  w. ja  v a2s.  c o m
            public void handleSuccess(String result) {
                new SCAsyncTask<String, Void, Collection<Group>>(getActivity(),
                        new SaveGroupProcessor(getActivity())).execute(result);
            }
        }, null);
        dialog.setTitle(R.string.mygroups_add_title);
        dialog.show();
        return true;
    case R.id.mygroups_add_person:
        FragmentTransaction ft = getSherlockActivity().getSupportFragmentManager().beginTransaction();
        Fragment fragment = new CampusFragmentPeople();
        // Replacing old fragment with new one
        ft.replace(R.id.content_frame, fragment);
        fragment.setArguments(CampusFragmentPeople.prepareArgs(selected.getSocialId()));
        ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        ft.addToBackStack(null);
        ft.commit();

        return true;
    case R.id.mygroups_delete:
        new SCAsyncTask<Group, Void, Collection<Group>>(getActivity(), new DeleteGroupProcessor(getActivity()))
                .execute(selected);
        return true;
    case R.id.mygroups_rename:
        dialog = new MyGroupsAddDialog(getActivity(), new DialogHandler<String>() {
            @Override
            public void handleSuccess(String result) {
                new SCAsyncTask<String, Void, Collection<Group>>(getActivity(),
                        new SaveGroupProcessor(getActivity(), selected)).execute(result);
            }
        }, selected);
        dialog.setTitle(R.string.mygroups_rename_title);
        dialog.show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

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

public static void putArcDeal(final Context ctx) {

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.arcdeal_dialog);
    dialog.setTitle(R.string.ArcDealDialogTitle);

    datetxt = (EditText) dialog.findViewById(R.id.expdateedit);
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date dat1 = new Date();
    datetxt.setText(sdf.format(dat1));//w w w  . j  ava  2s . c om
    mYear = dat1.getYear() + 1900;
    mMonth = dat1.getMonth();
    mDay = dat1.getDate();
    final Date dat = new GregorianCalendar(mYear, mMonth, mDay).getTime();

    datetxt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.i(TAG, "Show DatePickerDialog");
            DatePickerDialog dpd = new DatePickerDialog(ctx, mDateSetListener, mYear, mMonth, mDay);
            dpd.show();
        }
    });

    TextView itext = (TextView) dialog.findViewById(R.id.instrtext);
    itext.setText(Common.arcfilter);

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

            dialog.dismiss();
        }

    });

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

            Double price = new Double(0);
            Long qval = new Long(0);
            final EditText pricetxt = (EditText) dialog.findViewById(R.id.priceedit);
            final EditText quanttxt = (EditText) dialog.findViewById(R.id.quantedit);

            try {

                price = Double.valueOf(pricetxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
                return;
            }
            try {

                qval = Long.valueOf(quanttxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
                return;
            }

            //            if (dat.compareTo(new GregorianCalendar(mYear, mMonth, mDay)
            //            .getTime()) > 0) {
            //
            //               Toast.makeText(ctx, R.string.CorrectDate,
            //               Toast.LENGTH_SHORT).show();
            //
            //            return;
            //            }

            long maxkey = 0;
            Iterator<String> itr2 = arcdealMap.keySet().iterator();
            while (itr2.hasNext()) {
                String key1 = itr2.next();
                long k = Long.parseLong(key1);
                if (k > maxkey)
                    maxkey = k;
            }

            Deal adeal = new Deal();
            Iterator<String> itr1 = instrMap.keySet().iterator();
            while (itr1.hasNext()) {
                String key1 = itr1.next();
                Instrument in = instrMap.get(key1);
                if (in.symbol.equals(Common.arcfilter)) {

                    adeal.instrId = Long.valueOf(in.id);
                    break;
                }
            }

            final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.radio0);

            adeal.price = price;
            adeal.qty = qval;
            adeal.dtime = new GregorianCalendar(mYear, mMonth, mDay).getTimeInMillis();
            adeal.direct = bu0.isChecked() ? Long.valueOf(0) : Long.valueOf(1);
            Collection<String> lacc = Common.getAccountList();
            adeal.account = (lacc == null) ? "" : lacc.iterator().next();
            arcdealMap.put(String.valueOf(maxkey + 1), adeal);
            Common.saveArcDeals();
            Common.arcActivity.refresh();
            dialog.dismiss();
        }
    });

    dialog.show();

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.FILL_PARENT;
    dialog.getWindow().setAttributes(lp);

}

From source file:com.fitme.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.options, menu);
    MenuItem mi = menu.findItem(R.id.menu_spinner_active_program);
    final TextView tv = (TextView) mi.getActionView();
    ActiveProgramDAO apd = new ActiveProgramDAO(MainActivity.this);
    activeProgram = apd.getActiveProgramName();
    tv.setText(activeProgram);//from  w  w  w. ja v  a2 s . c om

    tv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            final Dialog dialog = new Dialog(MainActivity.this);
            dialog.setTitle(getText(R.string.title_select_prog_dialog));
            View programView = getLayoutInflater().inflate(R.layout.programs_list, null);
            ExpandableListView elv = (ExpandableListView) programView.findViewById(R.id.list_programs);
            final ProgramListAdapter pda = new ProgramListAdapter(MainActivity.this);
            elv.setAdapter(pda);
            // Setting listener for Add Program button
            Button addProgram = (Button) programView.findViewById(R.id.button_add_program);
            addProgram.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    onAddProgramRequested(pda);
                }
            });
            elv.setGroupIndicator(null);
            elv.setOnGroupClickListener(null);
            elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition,
                        int childPosition, long l) {
                    pda.setProgramSelected(groupPosition, childPosition);
                    onNewProgramSelected(pda.getSelectedProgramName());
                    // Refresh trainings section list
                    TrainingsSectionFragment tsf = (TrainingsSectionFragment) mAppSectionsPagerAdapter
                            .getItem(AppSectionsPagerAdapter.SECTION_TRAININGS);
                    tsf.onNewProgramSelected();
                    dialog.dismiss();
                    return false;
                }
            });
            dialog.setContentView(programView);
            dialog.show();
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT);
        }
    });

    return true;
}

From source file:com.medisa.myspacecal.MainActivity.java

@Override
public void onSideNavigationItemClick(int itemId) {
    switch (itemId) {
    case R.id.side_navigation_menu_calendario:
        range = 0;/*  w  w w. ja v a2 s  . c o  m*/
        Intent i = new Intent(this, MainActivity.class);
        startActivity(i);
        break;
    case R.id.side_navigation_menu_date_range:
        // custom dialog
        final Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.custom_range_date);
        dialog.setTitle("Data range");

        // set the custom dialog components - text, image and button
        final DatePicker dpStart = (DatePicker) dialog.findViewById(R.id.dpStart);
        final DatePicker dpEnd = (DatePicker) dialog.findViewById(R.id.dpEnd);
        Button btnSalva = (Button) dialog.findViewById(R.id.btnSalva);
        final CheckBox cbIntegralBox = (CheckBox) dialog.findViewById(R.id.cbIntegral);
        // if button is clicked, close the custom dialog
        btnSalva.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dateStart = Funzioni.addZero(dpStart.getDayOfMonth(), 2) + "-"
                        + Funzioni.addZero(dpStart.getMonth() + 1, 2) + "-" + dpStart.getYear();
                dateEnd = Funzioni.addZero(dpEnd.getDayOfMonth(), 2) + "-"
                        + Funzioni.addZero(dpEnd.getMonth() + 1, 2) + "-" + dpEnd.getYear();
                Log.e(dateStart, dateEnd);
                if (cbIntegralBox.isChecked()) {
                    //#########################JSON
                    AsyncHttpClient client = new AsyncHttpClient();
                    client.get("http://199.180.196.10/json/integral?startdate=" + dateStart + "&enddate="
                            + dateEnd, new AsyncHttpResponseHandler() {
                                @Override
                                public void onSuccess(String response) {
                                    Log.e("SCARICATO", response + "");
                                    JSONArray jObject;
                                    satellitiIntegral = new ArrayList<SatelliteIntegral>();
                                    try {
                                        jObject = new JSONArray(response);
                                        for (int i = 0; i < jObject.length(); i++) {
                                            JSONArray menuObject = jObject.getJSONArray(i);
                                            String dataStart = menuObject.getString(0);
                                            String dataEnd = menuObject.getString(1);
                                            String raj2000 = menuObject.getString(2);
                                            String decj2000 = menuObject.getString(3);
                                            String target = menuObject.getString(4);
                                            Log.e("", dataStart + " " + dataEnd + " " + raj2000 + " " + decj2000
                                                    + " " + target);
                                            satellitiIntegral.add(new SatelliteIntegral(dataStart, dataEnd,
                                                    raj2000, decj2000, target));
                                        }
                                        adapter = new GridCellAdapter(getApplicationContext(),
                                                R.id.day_gridcell, month, year);
                                        adapter.notifyDataSetChanged();
                                        calendarView.setAdapter(adapter);

                                    } catch (JSONException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                }
                            });
                }

                dialog.dismiss();
                //###############################################
                //                   Intent mioIntent= new Intent(ctx, MainActivity.class);
                //                   startActivity(mioIntent);
            }

        });
        dialog.show();
        break;
    //            case R.id.side_navigation_menu_item3:
    //                invokeActivity(getString(R.string.title3), R.drawable.ic_android3);
    //                break;
    //
    //            case R.id.side_navigation_menu_item4:
    //                invokeActivity(getString(R.string.title4), R.drawable.ic_android4);
    //                break;
    //
    //            case R.id.side_navigation_menu_item5:
    //                invokeActivity(getString(R.string.title5), R.drawable.ic_android5);
    //                break;

    default:
        return;
    }
}

From source file:com.amazonaws.cognito.sync.demo.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_activity);

    Log.i(TAG, "onCreate");

    /**/*from   w w  w  .  j a  v a2  s  . c  o  m*/
     * Initialize Facebook SDK
     */
    FacebookSdk.sdkInitialize(getApplicationContext());
    callbackManager = CallbackManager.Factory.create();

    //Twitter
    if (mOauthConsumer == null) {
        mOauthProvider = new DefaultOAuthProvider("https://api.twitter.com/oauth/request_token",
                "https://api.twitter.com/oauth/access_token", "https://api.twitter.com/oauth/authorize");
        mOauthConsumer = new DefaultOAuthConsumer(getString(R.string.twitter_consumer_key),
                getString(R.string.twitter_consumer_secret));
    }
    retrieveTwitterCredentials(getIntent());

    //If access token is already here, set fb session
    final AccessToken fbAccessToken = AccessToken.getCurrentAccessToken();
    if (fbAccessToken != null) {
        setFacebookSession(fbAccessToken);
        btnLoginFacebook.setVisibility(View.GONE);
    }

    /**
     * Initializes the sync client. This must be call before you can use it.
     */
    CognitoSyncClientManager.init(this);

    btnLoginFacebook = (Button) findViewById(R.id.btnLoginFacebook);
    btnLoginFacebook.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // start Facebook Login
            LoginManager.getInstance().logInWithReadPermissions(MainActivity.this,
                    Arrays.asList("public_profile"));
            LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
                @Override
                public void onSuccess(LoginResult loginResult) {
                    btnLoginFacebook.setVisibility(View.GONE);
                    new GetFbName(loginResult).execute();
                    setFacebookSession(loginResult.getAccessToken());
                }

                @Override
                public void onCancel() {
                    Toast.makeText(MainActivity.this, "Facebook login cancelled", Toast.LENGTH_LONG).show();
                }

                @Override
                public void onError(FacebookException error) {
                    Toast.makeText(MainActivity.this, "Error in Facebook login " + error.getMessage(),
                            Toast.LENGTH_LONG).show();
                }
            });
        }
    });
    btnLoginFacebook.setEnabled(getString(R.string.facebook_app_id) != "facebook_app_id");

    try {
        mAuthManager = new AmazonAuthorizationManager(this, Bundle.EMPTY);
    } catch (IllegalArgumentException e) {
        Log.d(TAG, "Login with Amazon isn't configured correctly. " + "Thus it's disabled in this demo.");
    }
    btnLoginLWA = (Button) findViewById(R.id.btnLoginLWA);
    btnLoginLWA.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mAuthManager.authorize(APP_SCOPES, Bundle.EMPTY, new AuthorizeListener());
        }
    });
    btnLoginLWA.setEnabled(mAuthManager != null);

    Button btnWipedata = (Button) findViewById(R.id.btnWipedata);
    btnWipedata.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(MainActivity.this).setTitle("Wipe data?")
                    .setMessage("This will log off your current session and wipe all user data. "
                            + "Any data not synchronized will be lost.")
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // clear login status
                            if (fbAccessToken != null) {
                                LoginManager.getInstance().logOut();
                            }
                            btnLoginFacebook.setVisibility(View.VISIBLE);
                            if (mAuthManager != null) {
                                mAuthManager.clearAuthorizationState(null);
                            }
                            btnLoginLWA.setVisibility(View.VISIBLE);
                            // wipe data
                            CognitoSyncClientManager.getInstance().wipeData();

                            // Wipe shared preferences
                            AmazonSharedPreferencesWrapper
                                    .wipe(PreferenceManager.getDefaultSharedPreferences(MainActivity.this));
                        }

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

    findViewById(R.id.btnListDatasets).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, ListDatasetsActivity.class);
            startActivity(intent);
        }
    });

    btnLoginDevAuth = (Button) findViewById(R.id.btnLoginDevAuth);
    if ((CognitoSyncClientManager.credentialsProvider
            .getIdentityProvider()) instanceof DeveloperAuthenticationProvider) {
        btnLoginDevAuth.setEnabled(true);
        Log.w(TAG, "Developer authentication feature configured correctly. ");
    } else {
        btnLoginDevAuth.setEnabled(false);
        Log.w(TAG, "Developer authentication feature configured incorrectly. "
                + "Thus it's disabled in this demo.");
    }
    btnLoginDevAuth.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // username and password dialog
            final Dialog login = new Dialog(MainActivity.this);
            login.setContentView(R.layout.login_dialog);
            login.setTitle("Sample developer login");
            final TextView txtUsername = (TextView) login.findViewById(R.id.txtUsername);
            txtUsername.setHint("Username");
            final TextView txtPassword = (TextView) login.findViewById(R.id.txtPassword);
            txtPassword.setHint("Password");
            Button btnLogin = (Button) login.findViewById(R.id.btnLogin);
            Button btnCancel = (Button) login.findViewById(R.id.btnCancel);

            btnCancel.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    login.dismiss();
                }
            });

            btnLogin.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Validate the username and password
                    if (txtUsername.getText().toString().isEmpty()
                            || txtPassword.getText().toString().isEmpty()) {
                        new AlertDialog.Builder(MainActivity.this).setTitle("Login error")
                                .setMessage("Username or password cannot be empty!!").show();
                    } else {
                        // Clear the existing credentials
                        CognitoSyncClientManager.credentialsProvider.clearCredentials();
                        // Initiate user authentication against the
                        // developer backend in this case the sample Cognito
                        // developer authentication application.
                        ((DeveloperAuthenticationProvider) CognitoSyncClientManager.credentialsProvider
                                .getIdentityProvider()).login(txtUsername.getText().toString(),
                                        txtPassword.getText().toString(), MainActivity.this);
                    }
                    login.dismiss();
                }
            });
            login.show();
        }
    });

    /**
     * Button that leaves the app and launches the Twitter site to get an authorization.
     * If the user grants permissions to our app, it will be redirected to us again through
     * a callback.
     */
    Button btnLoginTwitter = (Button) findViewById(R.id.btnLoginTwitter);
    btnLoginTwitter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        String callbackUrl = "callback://" + getString(R.string.twitter_callback_url);
                        String authUrl = mOauthProvider.retrieveRequestToken(mOauthConsumer, callbackUrl);
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl));
                        startActivity(intent);
                    } catch (Exception e) {
                        Log.w("oauth fail", e);
                    }
                }
            }).start();
        }
    });
    btnLoginTwitter.setEnabled(getString(R.string.twitter_consumer_secret) != "twitter_consumer_secret");

}

From source file:com.commonsdroid.fragmentdialog.AlertFragmentDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    setCancelable(isCancelable);/*from ww w.  j  a v  a  2 s  .  com*/
    if (TextUtils.isEmpty(positiveText)) {
        positiveText = "OK";
        Log.d("CHECK", "" + com.commonsdroid.fragmentdialog.R.string.ok);
    }

    if (TextUtils.isEmpty(negativeText)) {
        negativeText = "Cancel";
    }
    switch (type) {
    case DIALOG_TYPE_OK:
        /*show dialog with positive button*/
        return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
                .setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onPositiveButtonClick(identifier);

                    }
                }).create();
    case DIALOG_TYPE_YES_NO:
        /*show dialog with positive and negative button*/
        return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
                .setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onPositiveButtonClick(identifier);

                    }
                }).setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onNegativeButtonClick(identifier);

                    }
                }).create();
    case DATE_DIALOG:
        /*show date picker dialog*/
        return new DatePickerDialog(getActivity(), AlertFragmentDialog.this, sYear, sMonth, sDate);
    case TIME_DIALOG:
        /*show time picker dialog*/
        return new TimePickerDialog(getActivity(), AlertFragmentDialog.this, sHour, sMinute, true);
    case SIMPLE_LIST_DIALOG:
        /**
         * show simple list dialog
         */
        return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_item).create();
    case SINGLE_CHOICE_LIST_DIALOG:
        /*show single choice list dialog*/
        return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_singlechoice).create();
    case MULTI_CHOICE_LIST_DIALOG:
        /*show multichoice list dialog*/
        Dialog multipleChoice = new Dialog(getActivity());
        multipleChoice.setContentView(R.layout.list_multichoice);
        multipleChoice.setTitle(title);
        ListView listView = (ListView) multipleChoice.findViewById(R.id.lstMultichoiceList);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // Manage selected items here

                CheckedTextView textView = (CheckedTextView) view;
                if (textView.isChecked()) {

                } else {

                }
                Log.e("CHECK", "clicked pos : " + position + " checked : " + textView.isChecked());
            }
        });

        final ArrayAdapter<String> arraySingleChoiceAdapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.select_dialog_multichoice, dialogList);

        listView.setAdapter(arraySingleChoiceAdapter);
        multipleChoice.show();
        /*multipleChoice.setNegativeButton(R.string.cancel,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
        multipleChoice.setPositiveButton(R.string.cancel, new OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
              dismiss();      
              sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
           }
        });*/
        /* multipleChoice.setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {
                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (alSelectedItem.size() != 0) {
                        sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
                    }
                }
            });*/
        //         multipleChoice.create();

        //         singleChoiceListDialog.setCancelable(false);

        /* multipleChoice.setMultiChoiceItems(items, null,
            new DialogInterface.OnMultiChoiceClickListener() {
             @Override
                public void onClick(DialogInterface dialog, int which,
                        boolean isChecked) {
                    if (isChecked) {
                        alSelectedItem.add(items[which]);
                    } else {
                        alSelectedItem.remove(items[which]);
                    }
                }
            });
           multipleChoice.setNegativeButton(R.string.cancel,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
           multipleChoice.setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {
                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (alSelectedItem.size() != 0) {
                        sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
                    }
                }
            });*/
        return multipleChoice;//.create();

    }
    return null;
}

From source file:fr.cph.chicago.activity.MainActivity.java

private void displayUpdatePanel() {
    try {//from  w ww .  ja v  a  2s .c om
        String versionName = this.getPackageManager().getPackageInfo(this.getPackageName(), 0).versionName;
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
        String versionNamePreferences = sharedPref.getString("version.name", null);
        if (versionNamePreferences == null || !versionNamePreferences.equals(versionName)) {
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString("version.name", versionName);
            editor.commit();

            final Dialog dialog = new Dialog(this);
            dialog.setContentView(R.layout.update);
            dialog.setTitle("Update");

            InputStreamReader is = new InputStreamReader(
                    ChicagoTracker.getAppContext().getAssets().open("update.txt"));
            BufferedReader br = new BufferedReader(is);
            String read = br.readLine();
            StringBuilder sb = new StringBuilder();
            while (read != null) {
                sb.append(read + "\n");
                read = br.readLine();
            }

            TextView text = (TextView) dialog.findViewById(R.id.updateText);
            text.setText(sb.toString());

            Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
            dialogButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                }
            });

            Display display = getWindowManager().getDefaultDisplay();
            Point size = new Point();
            display.getSize(size);
            int width = size.x;
            int newWidth = width - (width * 20 / 100);
            int height = size.y;
            int newHeight = height - (height * 20 / 100);

            dialog.getWindow().setLayout(newWidth, newHeight);

            dialog.show();
        }

    } catch (NameNotFoundException e) {
        Log.w(TAG, e.getMessage(), e);
    } catch (IOException e) {
        Log.w(TAG, e.getMessage(), e);
    }
}

From source file:com.z3r0byte.magistify.DashboardActivity.java

private void relogin() {
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.fragment_login);
    dialog.setTitle(R.string.msg_relogin);

    Button button = (Button) dialog.findViewById(R.id.button_login);
    button.setOnClickListener(new View.OnClickListener() {
        @Override// ww  w. j a v a2 s.  co m
        public void onClick(View view) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    Looper.prepare();
                    EditText usertxt = (EditText) dialog.findViewById(R.id.edit_text_username);
                    EditText passwordtxt = (EditText) dialog.findViewById(R.id.edit_text_password);

                    String username = usertxt.getText().toString();
                    String password = passwordtxt.getText().toString();

                    School school = new Gson().fromJson(configUtil.getString("School"), School.class);
                    try {
                        Magister magister = Magister.login(school, username, password);
                    } catch (final IOException | NullPointerException e) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(DashboardActivity.this, R.string.err_no_connection,
                                        Toast.LENGTH_SHORT).show();
                            }
                        });
                        return;
                    } catch (ParseException e) {
                        e.printStackTrace();
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(DashboardActivity.this, R.string.err_unknown, Toast.LENGTH_SHORT)
                                        .show();
                            }
                        });
                        return;
                    } catch (InvalidParameterException e) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(DashboardActivity.this, R.string.err_wrong_username_or_password,
                                        Toast.LENGTH_SHORT).show();
                            }
                        });
                        return;
                    }
                    Log.d(TAG, "onClick: login succeeded!");
                    User user = new User(username, password, false);
                    configUtil.setString("User", new Gson().toJson(user));
                    configUtil.setInteger("failed_auth", 0);
                    GlobalAccount.USER = user;
                    dialog.dismiss();
                }
            }).start();

        }
    });

    dialog.show();
}

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

public static void login(final Context ctx) {

    // ctx = Common.app_ctx;
    Common.connected = false;/* w  w  w.  jav a2 s  . c  om*/

    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);

}