Example usage for android.app Dialog Dialog

List of usage examples for android.app Dialog Dialog

Introduction

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

Prototype

public Dialog(@NonNull Context context) 

Source Link

Document

Creates a dialog window that uses the default dialog theme.

Usage

From source file:com.zen.androidhtmleditor.AHEActivity.java

public void newFileFolder(int type) {

    final int fileType = type;

    ndialog = new Dialog(AHEActivity.this);
    ndialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    ndialog.setContentView(R.layout.newfilediag);

    ndialog.setCancelable(true);/*  w  w  w.jav a  2 s  .c  o m*/

    Button closeServer = (Button) ndialog.findViewById(R.id.closeServer);
    closeServer.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {

            ndialog.cancel();
        }
    });

    Button saveServer = (Button) ndialog.findViewById(R.id.saveServer);
    saveServer.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
            String currentServers = settings.getString("Accounts", "");
            int connectedTo = settings.getInt("connectedTo", -1);

            if (connectedTo != -1) {
                if (currentServers.equals("")) {
                } else {
                    Gson gson = new Gson();
                    SearchResponse response = gson.fromJson(currentServers, SearchResponse.class);
                    List<Result> results = response.data;
                    Result s = results.get(connectedTo);
                    if (s.serverName != "" && s.userName != "") {
                        new NewFileFolderTask(s.serverName, s.userName, s.passWord, fileType, folderPath,
                                s.sftp, s.port).execute();

                    }
                }
            }

        }
    });
    ndialog.show();
}

From source file:com.sentaroh.android.SMBExplorer.SMBExplorerMain.java

private void showFileListCache(final ArrayList<FileListCacheItem> fcl, final FileListAdapter fla,
        final ListView flv, final Spinner spinner) {
    // ??/*from   w ww .  java  2 s .c om*/
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.select_file_cache_dlg);
    //      final Button btnOk = 
    //            (Button) dialog.findViewById(R.id.select_file_cache_dlg_ok);
    final Button btnCancel = (Button) dialog.findViewById(R.id.select_file_cache_dlg_cancel);

    CommonDialog.setDlgBoxSizeCompact(dialog);

    ((TextView) dialog.findViewById(R.id.select_file_cache_dlg_title)).setText("Select file cache");

    ListView lv = (ListView) dialog.findViewById(R.id.select_file_cache_dlg_listview);

    final ArrayList<String> list = new ArrayList<String>();
    for (int i = 0; i < fcl.size(); i++) {
        list.add(fcl.get(i).directory);
    }
    Collections.sort(list, new Comparator<String>() {
        @Override
        public int compare(String lhs, String rhs) {
            return lhs.compareToIgnoreCase(rhs);
        }
    });
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(mContext, R.layout.simple_list_item_1o, list);
    lv.setAdapter(adapter);

    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String t_dir = list.get(position);
            FileListCacheItem dhi = getFileListCache(t_dir, fcl);
            if (dhi != null) {
                mIgnoreSpinnerSelection = true;
                int s_no = -1;
                for (int i = 0; i < spinner.getCount(); i++) {
                    if (spinner.getItemAtPosition(i).toString().equals(dhi.profile_name)) {
                        s_no = i;
                        break;
                    }
                }
                fla.setDataList(dhi.file_list);
                fla.notifyDataSetChanged();
                if (currentTabName.equals(SMBEXPLORER_TAB_LOCAL)) {
                    localBase = dhi.base;
                    if (dhi.base.equals(dhi.directory))
                        localDir = "";
                    else
                        localDir = dhi.directory.replace(localBase + "/", "");
                    replaceDirHist(localDirHist, dhi.directory_history);
                    setFilelistCurrDir(localFileListDirSpinner, localBase, localDir);
                    setFileListPathName(localFileListPathBtn, localFileListCache, localBase, localDir);
                    setEmptyFolderView();
                    localCurrFLI = dhi;
                    flv.setSelection(0);
                    for (int j = 0; j < localFileListView.getChildCount(); j++)
                        localFileListView.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);
                    localFileListReloadBtn.performClick();
                } else if (currentTabName.equals(SMBEXPLORER_TAB_REMOTE)) {
                    remoteBase = dhi.base;
                    if (dhi.base.equals(dhi.directory))
                        remoteDir = "";
                    else
                        remoteDir = dhi.directory.replace(remoteBase + "/", "");
                    replaceDirHist(remoteDirHist, dhi.directory_history);
                    setFilelistCurrDir(remoteFileListDirSpinner, remoteBase, remoteDir);
                    setFileListPathName(remoteFileListPathBtn, remoteFileListCache, remoteBase, remoteDir);
                    setEmptyFolderView();
                    remoteCurrFLI = dhi;
                    flv.setSelection(0);

                    //                  Log.v("","base="+remoteBase+", dir="+remoteDir+", histsz="+remoteDirHist.size());
                    for (int j = 0; j < remoteFileListView.getChildCount(); j++)
                        remoteFileListView.getChildAt(j).setBackgroundColor(Color.TRANSPARENT);
                    if (remoteDir.equals("")) {
                        remoteFileListTopBtn.setEnabled(false);
                        remoteFileListUpBtn.setEnabled(false);
                    } else {
                        remoteFileListTopBtn.setEnabled(true);
                        remoteFileListUpBtn.setEnabled(true);
                    }
                }

                if (s_no != -1)
                    spinner.setSelection(s_no);
                Handler hndl = new Handler();
                hndl.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mIgnoreSpinnerSelection = false;
                    }
                }, 100);
                dialog.dismiss();
            }
        }
    });

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

    dialog.show();

}

From source file:com.sentaroh.android.SMBSync2.ActivityMain.java

@SuppressLint("InflateParams")
private void aboutSMBSync() {
    final Dialog dialog = new Dialog(this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.about_dialog);

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.about_dialog_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.about_dialog_title);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);
    title.setText(getString(R.string.msgs_dlg_title_about) + "(Ver " + packageVersionName + ")");

    // get our tabHost from the xml
    final TabHost tab_host = (TabHost) dialog.findViewById(R.id.about_tab_host);
    tab_host.setup();/*ww  w.j ava 2 s  .  c om*/

    final TabWidget tab_widget = (TabWidget) dialog.findViewById(android.R.id.tabs);

    if (Build.VERSION.SDK_INT >= 11) {
        tab_widget.setStripEnabled(false);
        tab_widget.setShowDividers(LinearLayout.SHOW_DIVIDER_NONE);
    }

    CustomTabContentView tabViewProf = new CustomTabContentView(this,
            getString(R.string.msgs_about_dlg_func_btn));
    tab_host.addTab(tab_host.newTabSpec("func").setIndicator(tabViewProf).setContent(android.R.id.tabcontent));

    CustomTabContentView tabViewHist = new CustomTabContentView(this,
            getString(R.string.msgs_about_dlg_change_btn));
    tab_host.addTab(
            tab_host.newTabSpec("change").setIndicator(tabViewHist).setContent(android.R.id.tabcontent));

    LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    LinearLayout ll_func = (LinearLayout) vi.inflate(R.layout.about_dialog_func, null);
    LinearLayout ll_change = (LinearLayout) vi.inflate(R.layout.about_dialog_change, null);

    final WebView func_view = (WebView) ll_func.findViewById(R.id.about_dialog_function);
    func_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_func_desc));
    func_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    func_view.getSettings().setBuiltInZoomControls(true);

    final WebView change_view = (WebView) ll_change.findViewById(R.id.about_dialog_change_history);
    change_view.loadUrl("file:///android_asset/" + getString(R.string.msgs_dlg_title_about_change_desc));
    change_view.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    change_view.getSettings().setBuiltInZoomControls(true);

    final CustomViewPagerAdapter mAboutViewPagerAdapter = new CustomViewPagerAdapter(this,
            new WebView[] { func_view, change_view });
    final CustomViewPager mAboutViewPager = (CustomViewPager) dialog.findViewById(R.id.about_view_pager);
    //       mMainViewPager.setBackgroundColor(mThemeColorList.window_color_background);
    mAboutViewPager.setAdapter(mAboutViewPagerAdapter);
    mAboutViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            //             util.addDebugMsg(2,"I","onPageSelected entered, pos="+position);
            tab_widget.setCurrentTab(position);
            tab_host.setCurrentTab(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            //             util.addDebugMsg(2,"I","onPageScrollStateChanged entered, state="+state);
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            //             util.addDebugMsg(2,"I","onPageScrolled entered, pos="+position);
        }
    });

    tab_host.setOnTabChangedListener(new OnTabChangeListener() {
        @Override
        public void onTabChanged(String tabId) {
            util.addDebugMsg(2, "I", "onTabchanged entered. tab=" + tabId);
            mAboutViewPager.setCurrentItem(tab_host.getCurrentTab());
        }
    });

    final Button btnOk = (Button) dialog.findViewById(R.id.about_dialog_btn_ok);

    CommonDialog.setDlgBoxSizeLimit(dialog, true);

    // OK?
    btnOk.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btnOk.performClick();
        }
    });

    dialog.show();
}

From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java

public void renameProfile(final SyncTaskItem pli, final NotifyEvent p_ntfy) {

    // ??/*  w  w w  .j a v a  2 s. co m*/
    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.single_item_input_dlg);

    LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.single_item_input_dlg_view);
    ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color);

    final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.single_item_input_title_view);
    final TextView title = (TextView) dialog.findViewById(R.id.single_item_input_title);
    title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color);
    title.setTextColor(mGp.themeColorList.text_color_dialog_title);

    //      final TextView dlg_msg = (TextView) dialog.findViewById(R.id.single_item_input_msg);
    final TextView dlg_cmp = (TextView) dialog.findViewById(R.id.single_item_input_name);
    final Button btn_ok = (Button) dialog.findViewById(R.id.single_item_input_ok_btn);
    final Button btn_cancel = (Button) dialog.findViewById(R.id.single_item_input_cancel_btn);
    final EditText etInput = (EditText) dialog.findViewById(R.id.single_item_input_dir);

    title.setText(mContext.getString(R.string.msgs_rename_profile));

    dlg_cmp.setVisibility(TextView.GONE);
    CommonDialog.setDlgBoxSizeCompact(dialog);
    etInput.setText(pli.getSyncTaskName());
    btn_ok.setEnabled(false);
    etInput.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable arg0) {
            if (!arg0.toString().equals(pli.getSyncTaskName()))
                btn_ok.setEnabled(true);
            else
                btn_ok.setEnabled(false);
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }

        @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
        }
    });

    //OK button
    btn_ok.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
            String new_name = etInput.getText().toString();

            pli.setSyncTaskName(new_name);

            mGp.syncTaskAdapter.sort();
            mGp.syncTaskAdapter.notifyDataSetChanged();

            saveSyncTaskListToFile(mGp, mContext, util, false, "", "", mGp.syncTaskAdapter.getArrayList(),
                    false);

            SyncTaskUtility.setAllSyncTaskToUnchecked(true, mGp.syncTaskAdapter);

            p_ntfy.notifyToListener(true, null);
        }
    });
    // CANCEL?
    btn_cancel.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    // Cancel?
    dialog.setOnCancelListener(new Dialog.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface arg0) {
            btn_cancel.performClick();
        }
    });
    //      dialog.setCancelable(false);
    //      dialog.setOnKeyListener(new DialogOnKeyListener(context));
    dialog.show();

}

From source file:org.csp.everyaware.offline.Map.java

private void insertAnnDialog(final ExtendedLatLng annLatLng) {
    final Dialog insertDialog = new Dialog(Map.this);
    insertDialog.setContentView(R.layout.insert_dialog);
    insertDialog.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    insertDialog.setTitle(R.string.annotation_insertion);
    insertDialog.setCancelable(false);/*from   w  w  w.j  a v a 2 s  .  c  om*/

    //get reference to send button
    final Button sendButton = (Button) insertDialog.findViewById(R.id.send_button);
    sendButton.setEnabled(false); //active only if there's text

    //get reference to cancel/close window button
    final Button cancelButton = (Button) insertDialog.findViewById(R.id.cancel_button);
    cancelButton.setEnabled(true); //active all time
    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            insertDialog.dismiss();
        }
    });

    //get reference to edittext in which user writes annotation
    final EditText editText = (EditText) insertDialog.findViewById(R.id.annotation_editText);
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //if modified text length is more than 0, activate send button
            if (s.length() > 0)
                sendButton.setEnabled(true);
            else
                sendButton.setEnabled(false);
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });

    //get checkbox references
    CheckBox facebookChBox = (CheckBox) insertDialog.findViewById(R.id.facebook_checkBox);
    CheckBox twitterChBox = (CheckBox) insertDialog.findViewById(R.id.twitter_checkBox);

    //activate check boxes depends from log in facebook/twitter
    boolean[] logs = new boolean[2];
    logs[0] = Utils.getValidFbSession(getApplicationContext());
    logs[1] = Utils.getValidTwSession(getApplicationContext());

    facebookChBox.setEnabled(logs[0]);
    twitterChBox.setEnabled(logs[1]);

    //checked on check boxes
    final boolean[] checkeds = Utils.getShareCheckedOn(getApplicationContext());
    if (checkeds[0] == true)
        facebookChBox.setChecked(true);
    else
        facebookChBox.setChecked(false);
    if (checkeds[1] == true)
        twitterChBox.setChecked(true);
    else
        twitterChBox.setChecked(false);

    facebookChBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton arg0, boolean checked) {
            Utils.setShareCheckedOn(checked, checkeds[1], getApplicationContext());
            checkeds[0] = checked;
        }
    });

    twitterChBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton arg0, boolean checked) {
            Utils.setShareCheckedOn(checkeds[0], checked, getApplicationContext());
            checkeds[1] = checked;
        }
    });

    //send annotation to server and on facebook/twitter if user is logged on 
    sendButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            //1 - read inserted annotation
            String annotation = editText.getText().toString();

            //2 - update record on db with annotation and save recordId            
            double recordId = annLatLng.mRecordId;

            int result = mDbManager.updateRecordAnnotation(recordId, annotation);

            if (result == 1)
                Toast.makeText(getApplicationContext(), "Updated record", Toast.LENGTH_LONG).show();
            else
                Toast.makeText(getApplicationContext(), "Error!", Toast.LENGTH_LONG).show();

            boolean[] checks = Utils.getShareCheckedOn(getApplicationContext());

            //3 - share on facebook is user wants and internet is active now
            if (checks[0] == true) {
                Record annotatedRecord = mDbManager.loadRecordById(recordId);
                try {
                    FacebookManager fb = FacebookManager.getInstance(null, null);
                    if (fb != null)
                        fb.postMessageOnWall(annotatedRecord);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            //4 - share on twitter is user wants and internet is active now
            if (checks[1] == true) {
                Record annotatedRecord = mDbManager.loadRecordById(recordId);

                try {
                    TwitterManager twManager = TwitterManager.getInstance(null);
                    twManager.postMessage(annotatedRecord);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            //5 - show marker for annotated record
            Record annotatedRecord = mDbManager.loadRecordById(recordId);

            String userAnn = annotatedRecord.mUserData1;

            if (!userAnn.equals("") && (annotatedRecord.mValues[0] != 0)) {
                BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.annotation_marker);
                Marker marker = mGoogleMap.addMarker(new MarkerOptions()
                        .position(new LatLng(annotatedRecord.mValues[0], annotatedRecord.mValues[1]))
                        .title("BC: " + String.valueOf(annotatedRecord.mBcMobile) + " "
                                + getResources().getString(R.string.micrograms))
                        .snippet("Annotation: " + userAnn).icon(icon).anchor(0f, 1f));
            }

            insertDialog.dismiss();
        }
    });

    insertDialog.show();
}

From source file:cl.gisred.android.InspActivity.java

private void abrirBusqMedidores() {

    lstBusqMedidores.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from w  ww. j a v  a2  s. c  o  m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SpiBusqueda = 0;
            callQuery(datosBusqMed[position].getNis(), getValueByEmp("CLIENTES_XY_006.nis"),
                    LyCLIENTES.getUrl().concat("/0"));
            if (LyCLIENTES.getLayers() != null && LyCLIENTES.getLayers().length > 0)
                iBusqScale = LyCLIENTES.getLayers()[0].getLayerServiceInfo().getMinScale();
            dialogBusq.dismiss();
        }
    });

    dialogBusq = new Dialog(this);
    dialogBusq.setTitle("Lista Bsqueda");
    dialogBusq.addContentView(lstBusqMedidores, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    dialogBusq.show();
}

From source file:com.updetector.MainActivity.java

/**
* Handle Setting click/*from  w w  w  .  j  a va 2 s.c  om*/
*/
private void handleSettings() {
    final Dialog dialog = new Dialog(this);
    dialog.setTitle(R.string.menu_item_settings);
    dialog.setContentView(R.layout.settings);

    final SharedPreferences mPrefs = getSharedPreferences(Constants.SHARED_PREFERENCES, Context.MODE_PRIVATE);
    final Editor editor = mPrefs.edit();

    final ToggleButton logOnButton = (ToggleButton) dialog.findViewById(R.id.log_on);
    logOnButton.setChecked(mPrefs.getBoolean(Constants.LOGGING_ON, false));

    final Button btDeviceSelectButton = (Button) dialog.findViewById(R.id.bt_device_button);
    btDeviceSelectButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (mBluetoothAdapter.isEnabled()) {
                selectBluetoothDevice();
            } else {
                Toast.makeText(getApplicationContext(), "Please enable your Bluetooth first.",
                        Toast.LENGTH_SHORT).show();
            }

        }
    });

    final Button applyButton = (Button) dialog.findViewById(R.id.apply_button);
    final Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button);
    applyButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            if (logOnButton.isChecked())
                editor.putBoolean(Constants.LOGGING_ON, true);
            else
                editor.putBoolean(Constants.LOGGING_ON, false);
            editor.commit();
            dialog.cancel();
        }
    });

    cancelButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            dialog.cancel();
        }
    });
    dialog.show();
}

From source file:cl.gisred.android.InspActivity.java

private void abrirBusqEquipos() {

    lstBusqEquipos.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/* ww w.j  a  va  2 s  .c o  m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            ArcGISDynamicMapServiceLayer oDLEquipo = (datosBusqEquipo[position].getTipo().equals("POINT"))
                    ? LyEQUIPOSPTO
                    : LyEQUIPOSLINEA;
            int iNumCapa = (datosBusqEquipo[position].getTipo().equals("POINT")) ? 3 : 0;

            callQuery(datosBusqEquipo[position].getIdEquipo(), getValueByEmp("id_equipo"),
                    oDLEquipo.getUrl().concat("/" + iNumCapa));
            if (oDLEquipo.getLayers() != null && oDLEquipo.getLayers().length > iNumCapa)
                iBusqScale = oDLEquipo.getLayers()[iNumCapa].getLayerServiceInfo().getMinScale();
            dialogBusq.dismiss();
        }
    });

    dialogBusq = new Dialog(this);
    dialogBusq.setTitle("Lista Bsqueda");
    dialogBusq.addContentView(lstBusqEquipos, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    dialogBusq.show();
}

From source file:de.ub0r.android.websms.WebSMS.java

/**
 * Create a Emoticons {@link Dialog}.//w w w . j av  a 2  s  .c o m
 *
 * @return Emoticons {@link Dialog}
 */
private Dialog createEmoticonsDialog() {
    final Dialog d = new Dialog(this);
    d.setTitle(R.string.emo_);
    d.setContentView(R.layout.emo);
    d.setCancelable(true);
    final String[] emoticons = this.getResources().getStringArray(R.array.emoticons);
    final GridView gridview = (GridView) d.findViewById(R.id.gridview);
    gridview.setAdapter(new BaseAdapter() {
        // references to our images
        // keep order and count synced with string-array!
        private Integer[] mThumbIds = { R.drawable.emo_im_angel, R.drawable.emo_im_cool,
                R.drawable.emo_im_crying, R.drawable.emo_im_foot_in_mouth, R.drawable.emo_im_happy,
                R.drawable.emo_im_kissing, R.drawable.emo_im_laughing, R.drawable.emo_im_lips_are_sealed,
                R.drawable.emo_im_money_mouth, R.drawable.emo_im_sad, R.drawable.emo_im_surprised,
                R.drawable.emo_im_tongue_sticking_out, R.drawable.emo_im_undecided, R.drawable.emo_im_winking,
                R.drawable.emo_im_wtf, R.drawable.emo_im_yelling };

        @Override
        public long getItemId(final int position) {
            return 0;
        }

        @Override
        public Object getItem(final int position) {
            return null;
        }

        @Override
        public int getCount() {
            return this.mThumbIds.length;
        }

        @Override
        public View getView(final int position, final View convertView, final ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) { // if it's not recycled,
                // initialize some attributes
                imageView = new ImageView(WebSMS.this);
                imageView.setLayoutParams(new GridView.LayoutParams(EMOTICONS_SIZE, EMOTICONS_SIZE));
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setPadding(EMOTICONS_PADDING, EMOTICONS_PADDING, EMOTICONS_PADDING,
                        EMOTICONS_PADDING);
            } else {
                imageView = (ImageView) convertView;
            }

            imageView.setImageResource(this.mThumbIds[position]);
            return imageView;
        }
    });
    gridview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(final AdapterView<?> adapter, final View v, final int id, final long arg3) {
            EditText et = WebSMS.this.etText;
            final String e = emoticons[id];
            int i = et.getSelectionStart();
            int j = et.getSelectionEnd();
            if (i > j) {
                int x = i;
                i = j;
                j = x;
            }
            String t = et.getText().toString();
            et.setText(t.substring(0, i) + e + t.substring(j));
            et.setSelection(i + e.length());
            d.dismiss();
            et.requestFocus();
        }
    });
    return d;
}

From source file:com.hughes.android.dictionary.DictionaryActivity.java

void onSearchTextChange(final String text) {
    if ("thadolina".equals(text)) {
        final Dialog dialog = new Dialog(getListView().getContext());
        dialog.setContentView(R.layout.thadolina_dialog);
        dialog.setTitle("Ti amo, amore mio!");
        final ImageView imageView = (ImageView) dialog.findViewById(R.id.thadolina_image);
        imageView.setOnClickListener(new OnClickListener() {
            @Override//w  w w .  ja v a  2  s  .c o m
            public void onClick(View v) {
                final Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("https://sites.google.com/site/cfoxroxvday/vday2012"));
                startActivity(intent);
            }
        });
        dialog.show();
    }
    if (dictRaf == null) {
        Log.d(LOG, "searchText changed during shutdown, doing nothing.");
        return;
    }

    // if (!searchView.hasFocus()) {
    // Log.d(LOG, "searchText changed without focus, doing nothing.");
    // return;
    // }
    Log.d(LOG, "onSearchTextChange: " + text);
    if (currentSearchOperation != null) {
        Log.d(LOG, "Interrupting currentSearchOperation.");
        currentSearchOperation.interrupted.set(true);
    }
    currentSearchOperation = new SearchOperation(text, index);
    searchExecutor.execute(currentSearchOperation);
}