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.klinker.android.twitter.activities.profile_viewer.ProfilePager.java

public void updateProfile() {
    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.change_profile_info_dialog);
    dialog.setTitle(getResources().getString(R.string.change_profile_info) + ":");

    final HoloEditText name = (HoloEditText) dialog.findViewById(R.id.name);
    final HoloEditText url = (HoloEditText) dialog.findViewById(R.id.url);
    final HoloEditText location = (HoloEditText) dialog.findViewById(R.id.location);
    final HoloEditText description = (HoloEditText) dialog.findViewById(R.id.description);

    name.setText(thisUser.getName());/*  w w  w. j a va2s  . c o  m*/

    try {
        url.setText(thisUser.getURLEntity().getDisplayURL());
    } catch (Exception e) {

    }

    location.setText(thisUser.getLocation());
    description.setText(thisUser.getDescription());

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

    Button change = (Button) dialog.findViewById(R.id.change);
    change.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean ok = true;
            String nameS = null;
            String urlS = null;
            String locationS = null;
            String descriptionS = null;

            if (name.getText().length() <= 20 && ok) {
                if (name.getText().length() > 0) {
                    nameS = name.getText().toString();
                    sharedPrefs.edit()
                            .putString("twitter_users_name_" + sharedPrefs.getInt("current_account", 1), nameS)
                            .commit();
                }
            } else {
                ok = false;
                Toast.makeText(context, getResources().getString(R.string.name_char_length), Toast.LENGTH_SHORT)
                        .show();
            }

            if (url.getText().length() <= 100 && ok) {
                if (url.getText().length() > 0) {
                    urlS = url.getText().toString();
                }
            } else {
                ok = false;
                Toast.makeText(context, getResources().getString(R.string.url_char_length), Toast.LENGTH_SHORT)
                        .show();
            }

            if (location.getText().length() <= 30 && ok) {
                if (location.getText().length() > 0) {
                    locationS = location.getText().toString();
                }
            } else {
                ok = false;
                Toast.makeText(context, getResources().getString(R.string.location_char_length),
                        Toast.LENGTH_SHORT).show();
            }

            if (description.getText().length() <= 160 && ok) {
                if (description.getText().length() > 0) {
                    descriptionS = description.getText().toString();
                }
            } else {
                ok = false;
                Toast.makeText(context, getResources().getString(R.string.description_char_length),
                        Toast.LENGTH_SHORT).show();
            }

            if (ok) {
                new UpdateInfo(nameS, urlS, locationS, descriptionS).execute();
                dialog.dismiss();
            }
        }
    });

    dialog.show();
}

From source file:com.android.cabapp.fragments.MyAccountFragment.java

void showDialog() {

    final Dialog dialog = new Dialog(mContext);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.device_id_dialog);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setCancelable(false);/*  w w w  .  j  a v a2  s  .c o m*/

    etDeviceName = (EditText) dialog.findViewById(R.id.etDeviceName);
    rlBtnSave = (RelativeLayout) dialog.findViewById(R.id.rlbtnSave);
    rlBtnCancel = (RelativeLayout) dialog.findViewById(R.id.rlbtnCancel);

    if (!Util.getPOSDeviceName(mContext).equals(""))
        etDeviceName.setText(Util.getPOSDeviceName(mContext));
    etDeviceName.setSelection(etDeviceName.getText().length());

    // dialog.setTitle("Please enter Serial number");
    rlBtnSave.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String szDeviceName = etDeviceName.getText().toString().trim();
            if (szDeviceName.isEmpty()) {
                Util.showToastMessage(mContext, "Field cannot be left empty!", Toast.LENGTH_LONG);
            } else if (szDeviceName.length() < 11) {
                Util.showToastMessage(mContext, "Serial number cannot be less than 10!", Toast.LENGTH_LONG);
            } else {
                Util.setPOSDeviceName(mContext, szDeviceName);
                tvDeviceID.setVisibility(View.VISIBLE);
                tvDeviceID.setText(Util.getPOSDeviceName(mContext));
                Util.hideSoftKeyBoard(mContext, rlBtnSave);
                dialog.dismiss();

            }

        }
    });

    rlBtnCancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Util.hideSoftKeyBoard(mContext, v);
            dialog.dismiss();
        }
    });
    dialog.show();

}

From source file:com.klinker.android.twitter.ui.profile_viewer.ProfilePager.java

public void updateProfile() {
    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.change_profile_info_dialog);
    dialog.setTitle(getResources().getString(R.string.change_profile_info) + ":");

    final HoloEditText name = (HoloEditText) dialog.findViewById(R.id.name);
    final HoloEditText url = (HoloEditText) dialog.findViewById(R.id.url);
    final HoloEditText location = (HoloEditText) dialog.findViewById(R.id.location);
    final HoloEditText description = (HoloEditText) dialog.findViewById(R.id.description);

    Button cancel = (Button) dialog.findViewById(R.id.cancel);
    cancel.setOnClickListener(new View.OnClickListener() {
        @Override//from www  . j a v a  2 s . c o m
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    Button change = (Button) dialog.findViewById(R.id.change);
    change.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean ok = true;
            String nameS = null;
            String urlS = null;
            String locationS = null;
            String descriptionS = null;

            if (name.getText().length() <= 20 && ok) {
                if (name.getText().length() > 0) {
                    nameS = name.getText().toString();
                    sharedPrefs.edit()
                            .putString("twitter_users_name_" + sharedPrefs.getInt("current_account", 1), nameS)
                            .commit();
                }
            } else {
                ok = false;
                Toast.makeText(context, getResources().getString(R.string.name_char_length), Toast.LENGTH_SHORT)
                        .show();
            }

            if (url.getText().length() <= 100 && ok) {
                if (url.getText().length() > 0) {
                    urlS = url.getText().toString();
                }
            } else {
                ok = false;
                Toast.makeText(context, getResources().getString(R.string.url_char_length), Toast.LENGTH_SHORT)
                        .show();
            }

            if (location.getText().length() <= 30 && ok) {
                if (location.getText().length() > 0) {
                    locationS = location.getText().toString();
                }
            } else {
                ok = false;
                Toast.makeText(context, getResources().getString(R.string.location_char_length),
                        Toast.LENGTH_SHORT).show();
            }

            if (description.getText().length() <= 160 && ok) {
                if (description.getText().length() > 0) {
                    descriptionS = description.getText().toString();
                }
            } else {
                ok = false;
                Toast.makeText(context, getResources().getString(R.string.description_char_length),
                        Toast.LENGTH_SHORT).show();
            }

            if (ok) {
                new UpdateInfo(nameS, urlS, locationS, descriptionS).execute();
                dialog.dismiss();
            }
        }
    });

    dialog.show();
}

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

void onLanguageButtonLongClick(final Context context) {
    final Dialog dialog = new Dialog(context);
    dialog.setContentView(R.layout.select_dictionary_dialog);
    dialog.setTitle(R.string.selectDictionary);

    final List<DictionaryInfo> installedDicts = application.getDictionariesOnDevice(null);

    ListView listView = (ListView) dialog.findViewById(android.R.id.list);
    final Button button = new Button(listView.getContext());
    final String name = getString(R.string.dictionaryManager);
    button.setText(name);/*from   w  ww .j  a va  2  s  .  com*/
    final IntentLauncher intentLauncher = new IntentLauncher(listView.getContext(),
            DictionaryManagerActivity.getLaunchIntent(getApplicationContext())) {
        @Override
        protected void onGo() {
            dialog.dismiss();
            DictionaryActivity.this.finish();
        }
    };
    button.setOnClickListener(intentLauncher);
    listView.addHeaderView(button);

    listView.setAdapter(new BaseAdapter() {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            final DictionaryInfo dictionaryInfo = getItem(position);

            final LinearLayout result = new LinearLayout(parent.getContext());

            for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) {
                final IndexInfo indexInfo = dictionaryInfo.indexInfos.get(i);
                final View button = application.createButton(parent.getContext(), dictionaryInfo, indexInfo);
                final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(),
                        getLaunchIntent(getApplicationContext(),
                                application.getPath(dictionaryInfo.uncompressedFilename), indexInfo.shortName,
                                searchView.getQuery().toString())) {
                    @Override
                    protected void onGo() {
                        dialog.dismiss();
                        DictionaryActivity.this.finish();
                    }
                };
                button.setOnClickListener(intentLauncher);
                if (i == indexIndex && dictFile != null
                        && dictFile.getName().equals(dictionaryInfo.uncompressedFilename)) {
                    button.setPressed(true);
                }
                result.addView(button);
            }

            final TextView nameView = new TextView(parent.getContext());
            final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename);
            nameView.setText(name);
            final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            layoutParams.width = 0;
            layoutParams.weight = 1.0f;
            nameView.setLayoutParams(layoutParams);
            nameView.setGravity(Gravity.CENTER_VERTICAL);
            result.addView(nameView);
            return result;
        }

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

        @Override
        public DictionaryInfo getItem(int position) {
            return installedDicts.get(position);
        }

        @Override
        public int getCount() {
            return installedDicts.size();
        }
    });
    dialog.show();
}

From source file:de.mkrtchyan.recoverytools.RecoveryTools.java

private void showFlashRecoveryDialog() {
    final Dialog FlashRecoveryDialog = new Dialog(mContext);
    LayoutInflater inflater = getLayoutInflater();
    FlashRecoveryDialog.setTitle(R.string.flash_options);
    try {//  w w w.  j  a  va2 s .c o m
        final ScrollView RecoveryLayout = (ScrollView) inflater.inflate(R.layout.recovery_dialog, null);
        LinearLayout layout = (LinearLayout) RecoveryLayout.getChildAt(0);

        FlashRecoveryDialog.setContentView(RecoveryLayout);
        if (!mDevice.isCwmSupported()) {
            layout.removeView(FlashRecoveryDialog.findViewById(R.id.bCWM));
        }
        if (!mDevice.isTwrpSupported()) {
            layout.removeView(FlashRecoveryDialog.findViewById(R.id.bTWRP));
        }
        if (!mDevice.isPhilzSupported()) {
            layout.removeView(FlashRecoveryDialog.findViewById(R.id.bPHILZ));
        }

        FlashRecoveryDialog.show();
    } catch (NullPointerException e) {
        Notifyer.showExceptionToast(mContext, TAG, e);
    }
}

From source file:app.clirnet.com.clirnetapp.activity.LoginActivity.java

private void showCreatePatientAlertDialog() {

    final Dialog dialog = new Dialog(this);

    dialog.setContentView(R.layout.no_inetrnet_login_dialog);

    dialog.setTitle(/*from w  w  w .ja v a  2  s . com*/
            "Your security credentials have expired. Please login with an active internet connection to refresh.");
    //  dialog.setCancelable(false);

    Button dialogButtonCancel = (Button) dialog.findViewById(R.id.customDialogCancel);
    Button dialogButtonOk = (Button) dialog.findViewById(R.id.customDialogOk);
    // Click cancel to dismiss android custom dialog box
    dialogButtonCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            dialog.dismiss();

        }
    });

    // Your android custom dialog ok action
    // Action for custom dialog ok button click
    dialogButtonOk.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);

            dialog.dismiss();

        }
    });

    dialog.show();

}

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

/**
 * Display dialog to the user for the Spotlight web apps:
 * https://www.google.com/tv/spotlight-gallery.html Allow the user to add a
 * web app to an existing row or a new row.
 * /*from  w  w w .j ava2 s. co m*/
 * @param context
 */
public static void displayAddSpotlight(final Launcher context) {
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(R.layout.add_apps_grid);

    final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName);
    final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio);
    currentRadioButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // hide the row name edit field if the current row radio button
            // is selected
            nameEditText.setVisibility(View.GONE);
        }

    });
    final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio);
    newRadioButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // show the row name edit field if the new radio button is
            // selected
            nameEditText.setVisibility(View.VISIBLE);
            nameEditText.requestFocus();
        }

    });
    final GridView gridView = (GridView) dialog.findViewById(R.id.grid);
    final ArrayList<SpotlightInfo> spotlights = SpotlightTable.getAllSpotlights(context);
    gridView.setAdapter(new AllSpotlightAdapter(context, spotlights));
    gridView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // if the new row radio button is selected, the user must enter
            // a name for the new row
            String name = nameEditText.getText().toString().trim();
            if (newRadioButton.isChecked() && name.length() == 0) {
                nameEditText.requestFocus();
                displayAlert(context, context.getString(R.string.dialog_new_row_name_alert));
                return;
            }
            ItemInfo itemInfo = (ItemInfo) parent.getAdapter().getItem(position);
            boolean currentRow = !newRadioButton.isChecked();
            context.addItem(itemInfo, currentRow ? null : name);
            context.showCover(false);
            dialog.dismiss();
            if (currentRow) {
                Analytics.logEvent(Analytics.ADD_SPOTLIGHT_WEB_APP);
            } else {
                Analytics.logEvent(Analytics.ADD_SPOTLIGHT_WEB_APP_WITH_ROW);
            }
        }

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

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

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

From source file:org.ros.android.app_chooser.ExchangeActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case INSTALL_DIALOG:
        dialog = new Dialog(this);
        dialog.setContentView(R.layout.install_dialog);
        dialog.setTitle("Installation Messages");
        dialog_text = (TextView) dialog.findViewById(R.id.dialog_textview);
        dialog_text.setText("Installing...");
        button = (Button) dialog.findViewById(R.id.ok_button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override//from  ww w .  ja v  a  2  s . c  om
            public void onClick(View v) {
                removeDialog(INSTALL_DIALOG);
            }
        });
        button.setVisibility(View.GONE);
        break;
    default:
        dialog = null;
    }
    return dialog;
}

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

/****************** OTTIENE RIFERIMENTO AI BOTTONI *********************************/

public void getButtonRefs() {
    mZoomControls = (LinearLayout) findViewById(R.id.zoomLinearLayout);
    mZoomControls.setVisibility(View.GONE);

    mTrackLengthBtn = (Button) findViewById(R.id.trackLengthBtn);
    mFollowCamBtn = (Button) findViewById(R.id.followCameraBtn);
    mZoomOutBtn = (Button) findViewById(R.id.zoomOutBtn);
    mZoomInBtn = (Button) findViewById(R.id.zoomInBtn);
    mInsertAnnBtn = (Button) findViewById(R.id.insertAnnBtn);
    mShareBtn = (Button) findViewById(R.id.shareBtn);

    mTrackLengthBtn.setVisibility(View.GONE);
    mInsertAnnBtn.setVisibility(View.GONE);

    mZoomOutBtn.setOnClickListener(new OnClickListener() {
        @Override/* w  w  w  . j a  v  a 2  s.  c  o  m*/
        public void onClick(View arg0) {
            // Zoom out
            try {
                mGoogleMap.moveCamera(CameraUpdateFactory.zoomBy(-1f));
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
            //read and save actual zoom level
            mZoom = mGoogleMap.getCameraPosition().zoom;
        }
    });

    mZoomInBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // Zoom in
            try {
                mGoogleMap.moveCamera(CameraUpdateFactory.zoomBy(1f));
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
            //read and save actual zoom level
            mZoom = mGoogleMap.getCameraPosition().zoom;
        }
    });

    mShareBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            mFacebookManager = FacebookManager.getInstance(Map.this, mFacebookHandler);
            mTwitterManager = TwitterManager.getInstance(Map.this);

            final Dialog dialog = new Dialog(Map.this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.share_dialog);
            //dialog.setTitle("Activate login on...");

            getShareButtonsRef(dialog);

            dialog.show();
        }
    });

    mFollowCamBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            //mCameraTrackOn = !mCameraTrackOn;
            setCameraTracking();

            if (mCameraTrackOn) {
                try {
                    if (Utils.lastPhoneLocation != null)
                        mGoogleMap.animateCamera(
                                CameraUpdateFactory.newLatLng(new LatLng(Utils.lastPhoneLocation.getLatitude(),
                                        Utils.lastPhoneLocation.getLongitude())));
                    else if (Utils.lastNetworkLocation != null)
                        mGoogleMap.animateCamera(CameraUpdateFactory
                                .newLatLng(new LatLng(Utils.lastNetworkLocation.getLatitude(),
                                        Utils.lastNetworkLocation.getLongitude())));
                } catch (NullPointerException e) {
                    e.printStackTrace();
                }
            }
        }
    });

    mShareBtn.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            Toast toast = Toast.makeText(getApplicationContext(),
                    getResources().getString(R.string.share_btn_text), Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, 250); //250 from top on a 480x800 screen
            toast.show();
            return false;
        }
    });

    //status icons references
    mGpsStatus = (ImageView) findViewById(R.id.gpsStatusIv);
    mInterUplStatus = (ImageView) findViewById(R.id.interUplStatusIv);

    //gps status icon initialization
    mGpsStatus.setBackgroundResource(R.drawable.gps_off);

    //read network type index on which upload data is allowed: 0 - only wifi; 1 - both wifi and mobile
    int networkTypeIndex = Utils.getUploadNetworkTypeIndex(getApplicationContext());

    //1 - is internet connection available? 
    boolean[] connectivity = Utils.haveNetworkConnection(getApplicationContext());

    //if user wants to upload only on wifi networks, connectivity[0] (network connectivity) must be true
    if (networkTypeIndex == 0) {
        if (connectivity[0])
            mConnectivityOn = true;
        else
            mConnectivityOn = false;
    } else //if user wants to upload both on wifi/mobile networks
        mConnectivityOn = connectivity[0] || connectivity[1];

    //network status icon initialization
    if (mConnectivityOn) {
        mInterUplStatus.setBackgroundResource(R.drawable.internet_on);
        Utils.uploadOn = Constants.INTERNET_ON_INT;
    } else {
        mInterUplStatus.setBackgroundResource(R.drawable.internet_off);
        Utils.uploadOn = Constants.INTERNET_OFF_INT;
    }

    //button to get from server black carbon levels around user
    mGetBcLevelsBtn = (Button) findViewById(R.id.getBcLevelsBtn);
    mGetBcLevelsBtn.setVisibility(View.VISIBLE);
    mGetBcLevelsBtn.setOnClickListener(mGetBcLevelsOnClickListener);

    //bcLayout.addView(mGetBcLevelsBtn);
    mSpectrum = (LinearLayout) findViewById(R.id.spectrumLinearLayout);
    mSpectrum.setVisibility(View.VISIBLE);
}

From source file:foam.jellyfish.StarwispBuilder.java

public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) {
    try {/*w  w  w  .j  a  v  a2s . co m*/

        String type = arr.getString(0);
        final Integer id = arr.getInt(1);
        String token = arr.getString(2);

        Log.i("starwisp", "Update: " + type + " " + id + " " + token);

        // non widget commands
        if (token.equals("toast")) {
            Toast msg = Toast.makeText(ctx.getBaseContext(), arr.getString(3), Toast.LENGTH_SHORT);
            msg.show();
            return;
        }

        if (type.equals("replace-fragment")) {
            int ID = arr.getInt(1);
            String name = arr.getString(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            FragmentTransaction ft = ctx.getSupportFragmentManager().beginTransaction();

            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

            //ft.setCustomAnimations(
            //    R.animator.card_flip_right_in, R.animator.card_flip_right_out,
            //    R.animator.card_flip_left_in, R.animator.card_flip_left_out);
            ft.replace(ID, fragment);
            //ft.addToBackStack(null);
            ft.commit();
            return;
        }

        if (token.equals("dialog-fragment")) {
            FragmentManager fm = ctx.getSupportFragmentManager();
            final int ID = arr.getInt(3);
            final JSONArray lp = arr.getJSONArray(4);
            final String name = arr.getString(5);

            final Dialog dialog = new Dialog(ctx);
            dialog.setTitle("Title...");

            LinearLayout inner = new LinearLayout(ctx);
            inner.setId(ID);
            inner.setLayoutParams(BuildLayoutParams(lp));

            dialog.setContentView(inner);

            //                Fragment fragment = ActivityManager.GetFragment(name);
            //                FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            //                fragmentTransaction.add(ID,fragment);
            //                fragmentTransaction.commit();

            dialog.show();

            /*                DialogFragment df = new DialogFragment() {
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                     Bundle savedInstanceState) {
                LinearLayout inner = new LinearLayout(ctx);
                inner.setId(ID);
                inner.setLayoutParams(BuildLayoutParams(lp));
                    
                return inner;
            }
                    
            @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                Dialog ret = super.onCreateDialog(savedInstanceState);
                Log.i("starwisp","MAKINGDAMNFRAGMENT");
                    
                Fragment fragment = ActivityManager.GetFragment(name);
                FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
                fragmentTransaction.add(1,fragment);
                fragmentTransaction.commit();
                return ret;
            }
                            };
                            df.show(ctx.getFragmentManager(), "foo");
            */
        }

        if (token.equals("time-picker-dialog")) {

            final Calendar c = Calendar.getInstance();
            int hour = c.get(Calendar.HOUR_OF_DAY);
            int minute = c.get(Calendar.MINUTE);

            // Create a new instance of TimePickerDialog and return it
            TimePickerDialog d = new TimePickerDialog(ctx, null, hour, minute, true);
            d.show();
            return;
        }
        ;

        if (token.equals("make-directory")) {
            File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(3));
            file.mkdirs();
            return;
        }

        if (token.equals("list-files")) {
            final String name = arr.getString(3);
            File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(5));
            // todo, should probably call callback with empty list
            if (file != null) {
                File list[] = file.listFiles();

                if (list != null) {
                    String code = "(";
                    for (int i = 0; i < list.length; i++) {
                        code += " \"" + list[i].getName() + "\"";
                    }
                    code += ")";

                    DialogCallback(ctx, ctxname, name, code);
                }
            }
            return;
        }

        if (token.equals("delayed")) {
            final String name = arr.getString(3);
            final int d = arr.getInt(5);
            Runnable timerThread = new Runnable() {
                public void run() {
                    DialogCallback(ctx, ctxname, name, "");
                }
            };
            m_Handler.removeCallbacksAndMessages(null);
            m_Handler.postDelayed(timerThread, d);
            return;
        }

        if (token.equals("network-connect")) {
            if (m_NetworkManager.state == NetworkManager.State.IDLE) {
                final String name = arr.getString(3);
                final String ssid = arr.getString(5);
                m_NetworkManager.Start(ssid, (StarwispActivity) ctx, name, this);
            }
            return;
        }

        if (token.equals("http-request")) {
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http request");
                final String name = arr.getString(3);
                final String url = arr.getString(5);
                m_NetworkManager.StartRequestThread(url, "normal", name);
            }
            return;
        }

        if (token.equals("http-download")) {
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http dl request");
                final String filename = arr.getString(4);
                final String url = arr.getString(5);
                m_NetworkManager.StartRequestThread(url, "download", filename);
            }
            return;
        }

        if (token.equals("send-mail")) {
            final String to[] = new String[1];
            to[0] = arr.getString(3);
            final String subject = arr.getString(4);
            final String body = arr.getString(5);

            JSONArray attach = arr.getJSONArray(6);
            ArrayList<String> paths = new ArrayList<String>();
            for (int a = 0; a < attach.length(); a++) {
                Log.i("starwisp", attach.getString(a));
                paths.add(attach.getString(a));
            }

            email(ctx, to[0], "", subject, body, paths);
        }

        if (token.equals("date-picker-dialog")) {
            final Calendar c = Calendar.getInstance();
            int day = c.get(Calendar.DAY_OF_MONTH);
            int month = c.get(Calendar.MONTH);
            int year = c.get(Calendar.YEAR);

            final String name = arr.getString(3);

            // Create a new instance of TimePickerDialog and return it
            DatePickerDialog d = new DatePickerDialog(ctx, new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker view, int year, int month, int day) {
                    DialogCallback(ctx, ctxname, name, day + " " + month + " " + year);
                }
            }, year, month, day);
            d.show();
            return;
        }
        ;

        if (token.equals("alert-dialog")) {

            final String name = arr.getString(3);
            final String msg = arr.getString(5);

            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int result = 0;
                    if (which == DialogInterface.BUTTON_POSITIVE)
                        result = 1;
                    DialogCallback(ctx, ctxname, name, "" + result);
                }
            };

            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
            builder.setMessage(msg).setPositiveButton("Yes", dialogClickListener)
                    .setNegativeButton("No", dialogClickListener).show();

            return;
        }

        if (token.equals("start-activity")) {
            ActivityManager.StartActivity(ctx, arr.getString(3), arr.getInt(4), arr.getString(5));
            return;
        }

        if (token.equals("start-activity-goto")) {
            ActivityManager.StartActivityGoto(ctx, arr.getString(3), arr.getString(4));
            return;
        }

        if (token.equals("finish-activity")) {
            ctx.setResult(arr.getInt(3));
            ctx.finish();
            return;
        }

        ///////////////////////////////////////////////////////////

        // now try and find the widget
        View vv = ctx.findViewById(id);
        if (vv == null) {
            Log.i("starwisp", "Can't find widget : " + id);
            return;
        }

        // tokens that work on everything
        if (token.equals("hide")) {
            vv.setVisibility(View.GONE);
            return;
        }

        if (token.equals("show")) {
            vv.setVisibility(View.VISIBLE);
            return;
        }

        // tokens that work on everything
        if (token.equals("set-enabled")) {
            vv.setEnabled(arr.getInt(3) == 1);
            return;
        }

        // special cases
        if (type.equals("linear-layout")) {
            LinearLayout v = (LinearLayout) vv;
            if (token.equals("contents")) {
                v.removeAllViews();
                JSONArray children = arr.getJSONArray(3);
                for (int i = 0; i < children.length(); i++) {
                    Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
                }
            }
        }

        if (type.equals("button-grid")) {
            Log.i("starwisp", "button-grid update");
            LinearLayout horiz = (LinearLayout) vv;
            if (token.equals("grid-buttons")) {
                Log.i("starwisp", "button-grid contents");
                horiz.removeAllViews();

                JSONArray params = arr.getJSONArray(3);
                String buttontype = params.getString(0);
                int height = params.getInt(1);
                int textsize = params.getInt(2);
                LinearLayout.LayoutParams lp = BuildLayoutParams(params.getJSONArray(3));
                final JSONArray buttons = params.getJSONArray(4);
                final int count = buttons.length();
                int vertcount = 0;
                LinearLayout vert = null;

                for (int i = 0; i < count; i++) {
                    JSONArray button = buttons.getJSONArray(i);

                    if (vertcount == 0) {
                        vert = new LinearLayout(ctx);
                        vert.setId(0);
                        vert.setOrientation(LinearLayout.VERTICAL);
                        horiz.addView(vert);
                    }
                    vertcount = (vertcount + 1) % height;

                    if (buttontype.equals("button")) {
                        Button b = new Button(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                            }
                        });
                        vert.addView(b);
                    } else if (buttontype.equals("toggle")) {
                        ToggleButton b = new ToggleButton(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                String arg = "#f";
                                if (((ToggleButton) v).isChecked())
                                    arg = "#t";
                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                            }
                        });
                        vert.addView(b);
                    } else if (buttontype.equals("single")) {
                        ToggleButton b = new ToggleButton(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                try {
                                    for (int i = 0; i < count; i++) {
                                        JSONArray button = buttons.getJSONArray(i);
                                        int bid = button.getInt(0);
                                        if (bid != v.getId()) {
                                            ToggleButton tb = (ToggleButton) ctx.findViewById(bid);
                                            tb.setChecked(false);
                                        }
                                    }
                                } catch (JSONException e) {
                                    Log.e("starwisp", "Error parsing data " + e.toString());
                                }

                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                            }
                        });
                        vert.addView(b);
                    }

                }
            }
        }

        /*
                    if (type.equals("grid-layout")) {
        GridLayout v = (GridLayout)vv;
        if (token.equals("contents")) {
            v.removeAllViews();
            JSONArray children = arr.getJSONArray(3);
            for (int i=0; i<children.length(); i++) {
                Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
            }
        }
                    }
        */
        if (type.equals("view-pager")) {
            ViewPager v = (ViewPager) vv;
            if (token.equals("switch")) {
                v.setCurrentItem(arr.getInt(3));
            }
            if (token.equals("pages")) {
                final JSONArray items = arr.getJSONArray(3);
                v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {
                    @Override
                    public int getCount() {
                        return items.length();
                    }

                    @Override
                    public Fragment getItem(int position) {
                        try {
                            String fragname = items.getString(position);
                            return ActivityManager.GetFragment(fragname);
                        } catch (JSONException e) {
                            Log.e("starwisp", "Error parsing data " + e.toString());
                        }
                        return null;
                    }
                });
            }
        }

        if (type.equals("image-view")) {
            ImageView v = (ImageView) vv;
            if (token.equals("image")) {
                int iid = ctx.getResources().getIdentifier(arr.getString(3), "drawable", ctx.getPackageName());
                v.setImageResource(iid);
            }
            if (token.equals("external-image")) {
                Bitmap bitmap = BitmapFactory.decodeFile(arr.getString(3));
                v.setImageBitmap(bitmap);
            }
            return;
        }

        if (type.equals("text-view") || type.equals("debug-text-view")) {
            Log.i("starwisp", "text-view...");
            TextView v = (TextView) vv;
            if (token.equals("text")) {
                if (type.equals("debug-text-view")) {
                    //v.setMovementMethod(new ScrollingMovementMethod());
                }
                v.setText(arr.getString(3));
            }
            return;
        }

        if (type.equals("edit-text")) {
            EditText v = (EditText) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
            }
            return;
        }

        if (type.equals("button")) {
            Button v = (Button) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
            }

            if (token.equals("listener")) {
                final String fn = arr.getString(3);
                v.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        m_Scheme.eval("(" + fn + ")");
                    }
                });
            }
            return;
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = (ToggleButton) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
                return;
            }

            if (token.equals("checked")) {
                if (arr.getInt(3) == 0)
                    v.setChecked(false);
                else
                    v.setChecked(true);
                return;
            }

            if (token.equals("listener")) {
                final String fn = arr.getString(3);
                v.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        m_Scheme.eval("(" + fn + ")");
                    }
                });
            }
            return;
        }

        /*
                    if (type.equals("canvas")) {
        StarwispCanvas v = (StarwispCanvas)vv;
        if (token.equals("drawlist")) {
            v.SetDrawList(arr.getJSONArray(3));
        }
        return;
                    }
                
                    if (type.equals("camera-preview")) {
        final CameraPreview v = (CameraPreview)vv;
                
        if (token.equals("take-picture")) {
            final String path = ((StarwispActivity)ctx).m_AppDir+arr.getString(3);
                
            v.TakePicture(
                new PictureCallback() {
                    public void onPictureTaken(byte[] data, Camera camera) {
                        String datetime = getDateTime();
                        String filename = path+datetime + ".jpg";
                        SaveData(filename,data);
                        v.Shutdown();
                        ctx.finish();
                    }
                });
        }
                
        if (token.equals("shutdown")) {
            v.Shutdown();
        }
                
        return;
                    }
        */
        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            if (token.equals("max")) {
                // android seekbar bug workaround
                int p = v.getProgress();
                v.setMax(0);
                v.setProgress(0);
                v.setMax(arr.getInt(3));
                v.setProgress(1000);

                // not working.... :(
            }
        }

        if (type.equals("spinner")) {
            Spinner v = (Spinner) vv;

            if (token.equals("selection")) {
                v.setSelection(arr.getInt(3));
            }

            if (token.equals("array")) {
                final JSONArray items = arr.getJSONArray(3);
                ArrayList<String> spinnerArray = new ArrayList<String>();

                for (int i = 0; i < items.length(); i++) {
                    spinnerArray.add(items.getString(i));
                }

                ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx,
                        android.R.layout.simple_spinner_item, spinnerArray) {
                    public View getView(int position, View convertView, ViewGroup parent) {
                        View v = super.getView(position, convertView, parent);
                        ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                        return v;
                    }
                };

                v.setAdapter(spinnerArrayAdapter);

                final int wid = id;
                // need to update for new values
                v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                        try {
                            CallbackArgs(ctx, ctxname, wid, "\"" + items.getString(pos) + "\"");
                        } catch (JSONException e) {
                            Log.e("starwisp", "Error parsing data " + e.toString());
                        }
                    }

                    public void onNothingSelected(AdapterView<?> v) {
                    }
                });

            }
            return;
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing data " + e.toString());
    }
}