List of usage examples for android.app Dialog setContentView
public void setContentView(@NonNull View view)
From source file:org.opendatakit.tables.activities.TableDisplayActivity.java
private void showDialogOder() { int i, j = 0, n; int k = 0;//from w w w .j av a 2 s .c o m final List<String[]> tile = readCsv(context); for (n = 0; n < tile.size(); n++) { if ("sort".equals(tile.get(n)[0])) { j++; } } String[] name = new String[j]; final ViewFragmentType fage = this.mCurrentFragmentType; final Dialog dialog = new Dialog(context); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); View layout = inflater.inflate(R.layout.dialog_sapxep, null); dialog.addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); dialog.setContentView(R.layout.dialog_sapxep); final ListView lv = (ListView) dialog.findViewById(R.id.list_oder); TextView title = (TextView) dialog.findViewById(R.id.title); title.setText("Sp xp theo"); for (i = 0; i < tile.size(); i++) { if ("sort".equals(tile.get(i)[0])) { name[k] = tile.get(i)[1].toString(); k++; } } List<Model> list = new ArrayList<Model>(); for (String elementKey : name) { list.add(new Model(elementKey)); } if (oder_position >= 0) { Model m = new Model(name[oder_position], true); list.set(oder_position, m); } adapter = new Adapter(this, list); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Model model = (Model) (lv.getItemAtPosition(position)); String selectedFromList = model.getName(); for (int n = 0; n < tile.size(); n++) { if (selectedFromList.equals(tile.get(n)[1])) { String oder_key = tile.get(n)[2].toString(); Intent intent = getIntent(); intent.putExtra("oder", oder_key); intent.putExtra("oder_position", String.valueOf(position)); intent.putExtra("all", "0"); switch (fage) { case SPREADSHEET: intent.putExtra("page", "SPREADSHEET"); break; case LIST: intent.putExtra("page", "LIST"); break; case MAP: intent.putExtra("page", "MAP"); break; case DETAIL: intent.putExtra("page", "DETAIL"); break; default: break; } finish(); startActivity(intent); } } } }); dialog.show(); }
From source file:org.opendatakit.tables.activities.TableDisplayActivity.java
private void showDialogTimkiem() { int i, j = 0, n; int k = 0;/*from www .ja va2s . c om*/ final List<String[]> tile = readCsv(context); final ViewFragmentType fage = this.mCurrentFragmentType; for (n = 0; n < tile.size(); n++) { if ("filter".equals(tile.get(n)[0])) { j++; } } String[] name = new String[j]; final Dialog dialog = new Dialog(context); LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); View layout = inflater.inflate(R.layout.dialog_sapxep, null); dialog.addContentView(layout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); dialog.setContentView(R.layout.dialog_sapxep); final ListView lv = (ListView) dialog.findViewById(R.id.list_oder); TextView title = (TextView) dialog.findViewById(R.id.title); title.setText("L?c theo trng thi"); for (i = 0; i < tile.size(); i++) { if ("filter".equals(tile.get(i)[0])) { name[k] = tile.get(i)[1].toString(); k++; } } List<Model> list = new ArrayList<Model>(); for (String elementKey : name) { list.add(new Model(elementKey)); } if (position_check >= 0) { Model m = new Model(name[position_check], true); list.set(position_check, m); } adapter = new Adapter(this, list); lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { RadioButton checkbox = (RadioButton) view.getTag(R.id.radioBT); checkbox.setChecked(true); Model model = (Model) (lv.getItemAtPosition(position)); String selectedFromList = model.getName(); for (int n = 0; n < tile.size(); n++) { if (selectedFromList.equals(tile.get(n)[1])) { String mj = tile.get(n)[2].toString(); Intent intent = getIntent(); StringBuilder s = new StringBuilder(); s.append(mj); intent.putExtra("timkiem", s.toString()); intent.putExtra("vitri", String.valueOf(position)); intent.putExtra("all", "0"); switch (fage) { case SPREADSHEET: intent.putExtra("page", "SPREADSHEET"); break; case LIST: intent.putExtra("page", "LIST"); break; case MAP: intent.putExtra("page", "MAP"); break; case DETAIL: intent.putExtra("page", "DETAIL"); break; default: break; } finish(); startActivity(intent); } } } }); dialog.show(); }
From source file:org.connectbot.ConsoleActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); TerminalView view = adapter.getCurrentTerminalView(); final boolean activeTerminal = view != null; boolean sessionOpen = false; boolean disconnected = false; boolean canForwardPorts = false; if (activeTerminal) { TerminalBridge bridge = view.bridge; sessionOpen = bridge.isSessionOpen(); disconnected = bridge.isDisconnected(); canForwardPorts = bridge.canFowardPorts(); }//w w w .j a v a2 s . c om menu.setQwertyMode(true); disconnect = menu.add(R.string.list_host_disconnect); if (hardKeyboard) disconnect.setAlphabeticShortcut('w'); if (!sessionOpen && disconnected) disconnect.setTitle(R.string.console_menu_close); disconnect.setEnabled(activeTerminal); disconnect.setIcon(android.R.drawable.ic_menu_close_clear_cancel); disconnect.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // disconnect or close the currently visible session TerminalView terminalView = adapter.getCurrentTerminalView(); TerminalBridge bridge = terminalView.bridge; bridge.dispatchDisconnect(true); return true; } }); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { copy = menu.add(R.string.console_menu_copy); if (hardKeyboard) copy.setAlphabeticShortcut('c'); MenuItemCompat.setShowAsAction(copy, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); copy.setIcon(R.drawable.ic_action_copy); copy.setEnabled(activeTerminal); copy.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { adapter.getCurrentTerminalView().startPreHoneycombCopyMode(); Toast.makeText(ConsoleActivity.this, getString(R.string.console_copy_start), Toast.LENGTH_LONG) .show(); return true; } }); } paste = menu.add(R.string.console_menu_paste); if (hardKeyboard) paste.setAlphabeticShortcut('v'); MenuItemCompat.setShowAsAction(paste, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); paste.setIcon(R.drawable.ic_action_paste); paste.setEnabled(activeTerminal); paste.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { pasteIntoTerminal(); return true; } }); portForward = menu.add(R.string.console_menu_portforwards); if (hardKeyboard) portForward.setAlphabeticShortcut('f'); portForward.setIcon(android.R.drawable.ic_menu_manage); portForward.setEnabled(sessionOpen && canForwardPorts); portForward.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { TerminalView terminalView = adapter.getCurrentTerminalView(); TerminalBridge bridge = terminalView.bridge; Intent intent = new Intent(ConsoleActivity.this, PortForwardListActivity.class); intent.putExtra(Intent.EXTRA_TITLE, bridge.host.getId()); ConsoleActivity.this.startActivityForResult(intent, REQUEST_EDIT); return true; } }); urlscan = menu.add(R.string.console_menu_urlscan); if (hardKeyboard) urlscan.setAlphabeticShortcut('u'); urlscan.setIcon(android.R.drawable.ic_menu_search); urlscan.setEnabled(activeTerminal); urlscan.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { final TerminalView terminalView = adapter.getCurrentTerminalView(); List<String> urls = terminalView.bridge.scanForURLs(); Dialog urlDialog = new Dialog(ConsoleActivity.this); urlDialog.setTitle(R.string.console_menu_urlscan); ListView urlListView = new ListView(ConsoleActivity.this); URLItemListener urlListener = new URLItemListener(ConsoleActivity.this); urlListView.setOnItemClickListener(urlListener); urlListView.setAdapter( new ArrayAdapter<String>(ConsoleActivity.this, android.R.layout.simple_list_item_1, urls)); urlDialog.setContentView(urlListView); urlDialog.show(); return true; } }); resize = menu.add(R.string.console_menu_resize); if (hardKeyboard) resize.setAlphabeticShortcut('s'); resize.setIcon(android.R.drawable.ic_menu_crop); resize.setEnabled(sessionOpen); resize.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { final TerminalView terminalView = adapter.getCurrentTerminalView(); @SuppressLint("InflateParams") // Dialogs do not have a parent view. final View resizeView = inflater.inflate(R.layout.dia_resize, null, false); new android.support.v7.app.AlertDialog.Builder(ConsoleActivity.this, R.style.AlertDialogTheme) .setView(resizeView) .setPositiveButton(R.string.button_resize, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { int width, height; try { width = Integer.parseInt( ((EditText) resizeView.findViewById(R.id.width)).getText().toString()); height = Integer.parseInt( ((EditText) resizeView.findViewById(R.id.height)).getText().toString()); } catch (NumberFormatException nfe) { // TODO change this to a real dialog where we can // make the input boxes turn red to indicate an error. return; } terminalView.forceSize(width, height); } }).setNegativeButton(android.R.string.cancel, null).create().show(); return true; } }); return true; }
From source file:co.taqat.call.LinphoneActivity.java
public Dialog displayDialog(String text) { Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.colorC)); d.setAlpha(200);//from w w w. j a va2 s . co m dialog.setContentView(R.layout.dialog); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); dialog.getWindow().setBackgroundDrawable(d); TextView customText = (TextView) dialog.findViewById(R.id.customText); customText.setText(text); return dialog; }
From source file:org.thoughtland.xlocation.ActivityApp.java
private void optionLegend() { // Show help//from ww w. j a v a 2s. co m Dialog dialog = new Dialog(ActivityApp.this); dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON); dialog.setTitle(R.string.menu_legend); dialog.setContentView(R.layout.legend); dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, getThemed(R.attr.icon_launcher)); ((ImageView) dialog.findViewById(R.id.imgHelpHalf)).setImageBitmap(getHalfCheckBox()); ((ImageView) dialog.findViewById(R.id.imgHelpOnDemand)).setImageBitmap(getOnDemandCheckBox()); for (View child : Util.getViewsByTag((ViewGroup) dialog.findViewById(android.R.id.content), "main")) child.setVisibility(View.GONE); ((LinearLayout) dialog.findViewById(R.id.llUnsafe)) .setVisibility(PrivacyManager.cVersion3 ? View.VISIBLE : View.GONE); dialog.setCancelable(true); dialog.show(); }
From source file:co.taqat.call.LinphoneActivity.java
public Dialog displayWrongPasswordDialog(final String username, final String realm, final String domain) { final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.colorC)); d.setAlpha(200);//from w ww . ja va 2 s .c om dialog.setContentView(R.layout.input_dialog); dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); dialog.getWindow().setBackgroundDrawable(d); TextView customText = (TextView) dialog.findViewById(R.id.customText); customText.setText(getString(R.string.error_bad_credentials)); Button retry = (Button) dialog.findViewById(R.id.retry); Button cancel = (Button) dialog.findViewById(R.id.cancel); retry.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { String newPassword = ((EditText) dialog.findViewById(R.id.password)).getText().toString(); LinphoneAuthInfo authInfo = LinphoneCoreFactory.instance().createAuthInfo(username, null, newPassword, null, realm, domain); LinphoneManager.getLc().addAuthInfo(authInfo); LinphoneManager.getLc().refreshRegisters(); dialog.dismiss(); } }); cancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { dialog.dismiss(); } }); return dialog; }
From source file:com.haibison.android.anhuu.utils.ui.history.HistoryFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (BuildConfig.DEBUG) Log.d(CLASSNAME, "onCreateDialog()"); Dialog dialog = new Dialog(getActivity(), UI.resolveAttribute(getActivity(), R.attr.anhuu_f5be488d_theme_dialog)) { @Override/*from ww w. j a v a 2s.co m*/ public boolean onCreateOptionsMenu(Menu menu) { getActivity().getMenuInflater().inflate(R.menu.anhuu_f5be488d_viewgroup_history, menu); return super.onCreateOptionsMenu(menu); }// onCreateOptionsMenu() @Override public boolean onPrepareOptionsMenu(Menu menu) { menu.findItem(R.id.anhuu_f5be488d_menuitem_clear) .setEnabled(mHistoryCursorAdapter != null && mHistoryCursorAdapter.getGroupCount() > 0); return true; }// onPrepareOptionsMenu() @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { if (BuildConfig.DEBUG) Log.d(CLASSNAME, "onMenuItemSelected() in Dialog"); UI.showSoftKeyboard(mSearchView, false); if (item.getItemId() == R.id.anhuu_f5be488d_menuitem_clear) doConfirmClearHistory(); return true; }// onMenuItemSelected() }; dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(true); dialog.setContentView(initContentView(dialog.getLayoutInflater(), null)); dialog.setOnKeyListener(mDialogOnKeyListener); UI.adjustDialogSizeForLargeScreens(dialog); return dialog; }
From source file:foam.jellyfish.StarwispBuilder.java
public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) { try {/*from ww w . j a va2s. c om*/ 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()); } }
From source file:com.sentaroh.android.TaskAutomation.Config.ProfileMaintenanceActionProfile.java
final static private void editDataArrayListItem(final GlobalParameters mGlblParms, final String edit_data, final int pos) { final Dialog dialog = new Dialog(mGlblParms.context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // dialog.getWindow().setSoftInputMode( // WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); dialog.setContentView(R.layout.data_array_item_edit_dlg); // final TextView dlg_msg = (TextView) dialog.findViewById(R.id.data_array_item_edit_dlg_msg); final TextView dlg_title = (TextView) dialog.findViewById(R.id.data_array_item_edit_dlg_title); dlg_title.setText("Edit data"); final EditText dlg_value = (EditText) dialog.findViewById(R.id.data_array_item_edit_dlg_value); final Button dlg_apply = (Button) dialog.findViewById(R.id.data_array_item_edit_dlg_apply); final Button dlg_cancel = (Button) dialog.findViewById(R.id.data_array_item_edit_dlg_cancel); // CommonDialog.setDlgBoxSizeCompact(dialog); dlg_value.setText(edit_data);/*from w w w . j ava 2 s .co m*/ // CANCEL? dlg_cancel.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { mGlblParms.actionCompareDataAdapter.getItem(pos).while_edit = false; mGlblParms.actionCompareDataAdapter.notifyDataSetChanged(); dialog.dismiss(); } }); // Apply? dlg_apply.setOnClickListener(new View.OnClickListener() { final public void onClick(View v) { mGlblParms.actionCompareDataAdapter.getItem(pos).while_edit = false; mGlblParms.actionCompareDataAdapter.getItem(pos).data_value = dlg_value.getText().toString(); mGlblParms.actionCompareDataAdapter.notifyDataSetChanged(); dialog.dismiss(); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { dlg_cancel.performClick(); } }); // dialog.setCancelable(false); dialog.show(); }
From source file:foam.mongoose.StarwispBuilder.java
public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) { try {/*from w w w. ja v a2 s . 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 (token.equals("play-sound")) { String name = arr.getString(3); if (name.equals("ping")) { MediaPlayer mp = MediaPlayer.create(ctx, R.raw.ping); mp.start(); } if (name.equals("active")) { MediaPlayer mp = MediaPlayer.create(ctx, R.raw.active); mp.start(); } } if (token.equals("vibrate")) { Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(arr.getInt(3)); } 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("gps-start")) { final String name = arr.getString(3); if (m_LocationManager == null) { m_LocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE); m_GPS = new DorisLocationListener(m_LocationManager); } m_GPS.Start((StarwispActivity) ctx, name, this); 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")) { 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; } /////////////////////////////////////////////////////////// // problem associating the id number if (id == 0) 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")) { LinearLayout horiz = (LinearLayout) vv; if (token.equals("grid-buttons")) { 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")) { 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)); } if (token.equals("request-focus")) { v.requestFocus(); InputMethodManager imm = (InputMethodManager) ctx .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT); } 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()); } }