List of usage examples for android.widget ImageView ImageView
public ImageView(Context context)
From source file:foam.opensauces.StarwispBuilder.java
public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) { try {//from w w w . j av a 2 s .c om String type = arr.getString(0); //Log.i("starwisp","building started "+type); if (type.equals("build-fragment")) { String name = arr.getString(1); int ID = arr.getInt(2); Fragment fragment = ActivityManager.GetFragment(name); LinearLayout inner = new LinearLayout(ctx); inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); inner.setId(ID); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(ID, fragment); fragmentTransaction.commit(); parent.addView(inner); return; } if (type.equals("linear-layout")) { LinearLayout v = new LinearLayout(ctx); v.setId(arr.getInt(1)); v.setOrientation(BuildOrientation(arr.getString(2))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); //v.setPadding(2,2,2,2); JSONArray col = arr.getJSONArray(4); v.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2))); parent.addView(v); JSONArray children = arr.getJSONArray(5); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("draggable")) { final LinearLayout v = new LinearLayout(ctx); final int id = arr.getInt(1); v.setPadding(20, 20, 20, 20); v.setId(id); v.setOrientation(BuildOrientation(arr.getString(2))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); v.setClickable(true); v.setFocusable(true); JSONArray col = arr.getJSONArray(4); v.setBackgroundResource(R.drawable.draggable); GradientDrawable drawable = (GradientDrawable) v.getBackground(); final int colour = Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)); drawable.setColor(colour); parent.addView(v); JSONArray children = arr.getJSONArray(5); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } // Sets a long click listener for the ImageView using an anonymous listener object that // implements the OnLongClickListener interface /* v.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View vv) { if (id!=99) { ClipData dragData = ClipData.newPlainText("simple text", ""+id); View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v); Log.i("starwisp","start drag id "+vv.getId()); v.startDrag(dragData, myShadow, null, 0); v.setVisibility(View.GONE); return true; } return false; } }); */ // Sets a long click listener for the ImageView using an anonymous listener object that // implements the OnLongClickListener interface v.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View vv, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN && id != 99) { // ClipData dragData = ClipData.newPlainText("simple text", ""+id); ClipData dragData = new ClipData( new ClipDescription(null, new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN }), new ClipData.Item("" + id)); View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v); Log.i("starwisp", "start drag id " + vv.getId()); v.startDrag(dragData, myShadow, null, 0); v.setVisibility(View.GONE); return true; } return false; } }); v.setOnDragListener(new View.OnDragListener() { public boolean onDrag(View vv, DragEvent event) { final int action = event.getAction(); switch (action) { case DragEvent.ACTION_DRAG_STARTED: if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { // returns true to indicate that the View can accept the dragged data. return true; } else { // Returns false. During the current drag and drop operation, this View will // not receive events again until ACTION_DRAG_ENDED is sent. return false; } case DragEvent.ACTION_DRAG_ENTERED: { return true; } case DragEvent.ACTION_DRAG_LOCATION: return true; case DragEvent.ACTION_DRAG_EXITED: { return true; } case DragEvent.ACTION_DROP: { ClipData.Item item = event.getClipData().getItemAt(0); String dragData = item.getText().toString(); Log.i("starwisp", "Dragged view is " + dragData); int otherid = Integer.parseInt(dragData); View otherw = ctx.findViewById(otherid); Log.i("starwisp", "removing from parent " + ((View) otherw.getParent()).getId()); // check we are not adding to ourself if (id != otherid) { ((ViewManager) otherw.getParent()).removeView(otherw); Log.i("starwisp", "adding to " + id); v.addView(otherw); } otherw.setVisibility(View.VISIBLE); return true; } case DragEvent.ACTION_DRAG_ENDED: { if (event.getResult()) { } else { } ; return true; } // An unknown action type was received. default: Log.e("starwisp", "Unknown action type received by OnDragListener."); break; } ; return true; } }); return; } if (type.equals("frame-layout")) { FrameLayout v = new FrameLayout(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } /* if (type.equals("grid-layout")) { GridLayout v = new GridLayout(ctx); v.setId(arr.getInt(1)); v.setRowCount(arr.getInt(2)); //v.setColumnCount(arr.getInt(2)); v.setOrientation(BuildOrientation(arr.getString(3))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); parent.addView(v); JSONArray children = arr.getJSONArray(5); for (int i=0; i<children.length(); i++) { Build(ctx,ctxname,new JSONArray(children.getString(i)), v); } return; } */ if (type.equals("scroll-view")) { HorizontalScrollView v = new HorizontalScrollView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("scroll-view-vert")) { ScrollView v = new ScrollView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("view-pager")) { ViewPager v = new ViewPager(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); v.setOffscreenPageLimit(3); 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; } }); parent.addView(v); return; } if (type.equals("space")) { // Space v = new Space(ctx); (class not found runtime error??) TextView v = new TextView(ctx); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); } if (type.equals("image-view")) { ImageView v = new ImageView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); String image = arr.getString(2); if (image.startsWith("/")) { Bitmap bitmap = BitmapFactory.decodeFile(image); v.setImageBitmap(bitmap); } else { int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName()); v.setImageResource(id); } parent.addView(v); } if (type.equals("text-view")) { TextView v = new TextView(ctx); v.setId(arr.getInt(1)); v.setText(Html.fromHtml(arr.getString(2))); v.setTextSize(arr.getInt(3)); v.setMovementMethod(LinkMovementMethod.getInstance()); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setClickable(false); v.setEnabled(false); v.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View vv, MotionEvent event) { return false; } }); if (arr.length() > 5) { if (arr.getString(5).equals("left")) { v.setGravity(Gravity.LEFT); } else { if (arr.getString(5).equals("fill")) { v.setGravity(Gravity.FILL); } else { v.setGravity(Gravity.CENTER); } } } else { v.setGravity(Gravity.LEFT); } v.setTypeface(((StarwispActivity) ctx).m_Typeface); parent.addView(v); } if (type.equals("debug-text-view")) { TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null); // v.setBackgroundResource(R.color.black); v.setId(arr.getInt(1)); // v.setText(Html.fromHtml(arr.getString(2))); // v.setTextColor(R.color.white); // v.setTextSize(arr.getInt(3)); // v.setMovementMethod(LinkMovementMethod.getInstance()); // v.setMaxLines(10); // v.setVerticalScrollBarEnabled(true); // v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); //v.setMovementMethod(new ScrollingMovementMethod()); /* if (arr.length()>5) { if (arr.getString(5).equals("left")) { v.setGravity(Gravity.LEFT); } else { if (arr.getString(5).equals("fill")) { v.setGravity(Gravity.FILL); } else { v.setGravity(Gravity.CENTER); } } } else { v.setGravity(Gravity.LEFT); } v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/ parent.addView(v); } if (type.equals("web-view")) { WebView v = new WebView(ctx); v.setId(arr.getInt(1)); v.setVerticalScrollBarEnabled(false); v.loadData(arr.getString(2), "text/html", "utf-8"); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); parent.addView(v); } if (type.equals("edit-text")) { final EditText v = new EditText(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); String inputtype = arr.getString(4); if (inputtype.equals("text")) { //v.setInputType(InputType.TYPE_CLASS_TEXT); } else if (inputtype.equals("numeric")) { v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL); } else if (inputtype.equals("email")) { v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS); } v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(5); //v.setSingleLine(true); v.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\""); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); parent.addView(v); } if (type.equals("button")) { Button v = new Button(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(5); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Callback(ctx, ctxname, v.getId()); } }); parent.addView(v); } if (type.equals("toggle-button")) { ToggleButton v = new ToggleButton(ctx); if (arr.getString(5).equals("fancy")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null); } if (arr.getString(5).equals("yes")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null); } if (arr.getString(5).equals("maybe")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null); } if (arr.getString(5).equals("no")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null); } v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(6); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, v.getId(), arg); } }); parent.addView(v); } if (type.equals("seek-bar")) { SeekBar v = new SeekBar(ctx); v.setId(arr.getInt(1)); v.setMax(arr.getInt(2)); v.setProgress(arr.getInt(2) / 2); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); final String fn = arr.getString(4); v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar v, int a, boolean s) { CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a)); } public void onStartTrackingTouch(SeekBar v) { } public void onStopTrackingTouch(SeekBar v) { } }); parent.addView(v); } if (type.equals("spinner")) { Spinner v = new Spinner(ctx); final int wid = arr.getInt(1); v.setId(wid); final JSONArray items = arr.getJSONArray(2); v.setLayoutParams(BuildLayoutParams(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, R.layout.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; } }; spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout); v.setAdapter(spinnerArrayAdapter); 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) { } }); parent.addView(v); } if (type.equals("canvas")) { StarwispCanvas v = new StarwispCanvas(ctx); final int wid = arr.getInt(1); v.setId(wid); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); v.SetDrawList(arr.getJSONArray(3)); parent.addView(v); } if (type.equals("camera-preview")) { PictureTaker pt = new PictureTaker(); CameraPreview v = new CameraPreview(ctx, pt); final int wid = arr.getInt(1); v.setId(wid); // LinearLayout.LayoutParams lp = // new LinearLayout.LayoutParams(minWidth, minHeight, 1); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); // v.setLayoutParams(lp); parent.addView(v); } if (type.equals("button-grid")) { LinearLayout horiz = new LinearLayout(ctx); final int id = arr.getInt(1); final String buttontype = arr.getString(2); horiz.setId(id); horiz.setOrientation(LinearLayout.HORIZONTAL); parent.addView(horiz); int height = arr.getInt(3); int textsize = arr.getInt(4); LinearLayout.LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5)); JSONArray buttons = arr.getJSONArray(6); 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 = arr.getString(6); 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 = arr.getString(6); 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); } } } } catch (JSONException e) { Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString()); } //Log.i("starwisp","building ended"); }
From source file:com.roger.lineselectionwebview.LSWebView.java
/** * ?//from w w w. j a v a2s. c o m */ private void drawImage() { int size = rectList.size(); Rect endRect = rectList.get(size - 1); Rect realEndRect = endRect; // ?left???,,? if (size > 2) { Rect endPreRect = rectList.get(size - 2); if (endRect.left == endPreRect.left) { if (endRect.width() > endPreRect.width()) { realEndRect = endPreRect; } else { realEndRect = endRect; } } } Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.del); ImageView imageView = new ImageView(mContext); imageView.setImageBitmap(bitmap); imageView.setScaleType(ScaleType.CENTER); imageView.setTag(selectContext); MyAbsoluteLayout.LayoutParams lp = new MyAbsoluteLayout.LayoutParams( MyAbsoluteLayout.LayoutParams.WRAP_CONTENT, MyAbsoluteLayout.LayoutParams.WRAP_CONTENT, realEndRect.right, realEndRect.bottom); imageView.setLayoutParams(lp); imageView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { String tag = (String) v.getTag(); lineView.remove(tag); myLayout.removeView(v); if (onTextSelectListener != null) { onTextSelectListener.cancle(tag.split(SELECT_SPLIT)[0]); } } }); myLayout.addView(imageView, lp); }
From source file:com.near.chimerarevo.fragments.PostFragment.java
private void addGallery(final String[] imgUrls) { numGalleries++;//from w w w .j a v a2 s .co m if (!PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("load_imgs_pref", true) || numGalleries > Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString("gallery_num_pref", "20"))) return; HorizontalScrollView hsv = new HorizontalScrollView(getActivity()); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); params.gravity = Gravity.CENTER_HORIZONTAL; params.setMargins(10, 10, 10, 0); hsv.setLayoutParams(params); LinearLayout container = new LinearLayout(getActivity()); container.setOrientation(LinearLayout.HORIZONTAL); for (int i = 0; i < imgUrls.length; i++) { final ImageView img = new ImageView(getActivity()); LayoutParams imgPar = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); if (i == 0) imgPar.setMargins(5, 10, 0, 10); else imgPar.setMargins(10, 10, 0, 10); img.setLayoutParams(imgPar); img.setScaleType(ImageView.ScaleType.CENTER_INSIDE); container.addView(img); final DisplayImageOptions options = new DisplayImageOptions.Builder().cacheOnDisk(false) .cacheInMemory(true).showImageOnLoading(R.drawable.empty_cr).bitmapConfig(Bitmap.Config.RGB_565) .imageScaleType(ImageScaleType.EXACTLY).delayBeforeLoading(200).build(); ImageLoader.getInstance().displayImage(imgUrls[i], img, options); final int k = i; img.setClickable(true); img.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.img_dialog_layout); ImageLoader.getInstance().displayImage(imgUrls[k].split("\\?resize=")[0], ((TouchImageView) dialog.findViewById(R.id.dialog_image)), options); dialog.setCancelable(true); dialog.show(); } }); } hsv.addView(container); lay.addView(hsv); }
From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java
private ImageView generateImageView(final int imageButton, final int visible) { ImageView iv = new ImageView(mActivity); iv.setVisibility(visible);//from w w w.j a v a2 s .c o m final int imageResourse = getImageResourceForKey(imageButton); if (imageResourse != 0) iv.setImageResource(imageResourse); iv.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { processOnClickListenerForKey(imageButton); } }); if (IMAGE_BUTTON_TEXT == imageButton) { iv.setColorFilter(UIUtils.imageColorFilter(ContextCompat.getColor(mActivity, R.color.mc_divider_gray))); } iv.setPadding(_5_DP_IN_PX, _5_DP_IN_PX, _5_DP_IN_PX, _5_DP_IN_PX); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(_30_DP_IN_PX, _30_DP_IN_PX, 1.0f); iv.setLayoutParams(lp); return iv; }
From source file:com.retroteam.studio.retrostudio.MeasureEditor.java
/** * Draw the grid./* w w w .j av a2 s.c o m*/ */ private void drawGrid() { //draw the grid based on project info thisMeasure = theproject.track(trackNum).measure(measureNum); TableLayout notedraw = (TableLayout) findViewById(R.id.notedraw); int notedrawlen = notedraw.getChildCount(); //get note scale final float dscale = getApplicationContext().getResources().getDisplayMetrics().density; int notewidth = (int) (144 * dscale + 0.5f); int noteheight = (int) (75 * dscale + 0.5f); for (int x = 0; x < notedrawlen; x++) { TableRow noterow = (TableRow) notedraw.getChildAt(x); List<List<Integer>> rangelist = numNotesFromGuiSnap(); for (int i = 0; i < rangelist.size(); i++) { ImageView note = new ImageView(getApplicationContext()); note.setLayoutParams(new TableRow.LayoutParams(notewidth, noteheight)); note.setTag(R.id.TAG_ROW, x); note.setTag(R.id.TAG_COLUMN, i); note.setTag(R.id.TAG_NOTE, notesdisplay[x]); note.setTag(R.id.TAG_GUISNAPRANGE, rangelist.get(i)); note.setImageResource(R.drawable.measure_outline); if (filledNotesFromIntent.size() > 0) { for (int z = 0; z < filledNotesFromIntent.size(); z++) { if ((filledNotesFromIntent.get(z)[0] == x) && (filledNotesFromIntent.get(z)[1] == i)) { note.setImageResource(R.drawable.note_filled); } } } note.setBackgroundColor(getResources().getColor(R.color.note_rest)); note.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { paintNote(v); } }); noterow.addView(note); } } }
From source file:com.google.android.apps.iosched.ui.SessionDetailFragment.java
private void updateLinksTab(Cursor cursor) { ViewGroup container = (ViewGroup) mRootView.findViewById(R.id.links_container); // Remove all views but the 'empty' view int childCount = container.getChildCount(); if (childCount > 1) { container.removeViews(1, childCount - 1); }//from ww w . ja va 2 s.c o m LayoutInflater inflater = getLayoutInflater(null); boolean hasLinks = false; for (int i = 0; i < SessionsQuery.LINKS_INDICES.length; i++) { final String url = cursor.getString(SessionsQuery.LINKS_INDICES[i]); if (!TextUtils.isEmpty(url)) { hasLinks = true; ViewGroup linkContainer = (ViewGroup) inflater.inflate(R.layout.list_item_session_link, container, false); ((TextView) linkContainer.findViewById(R.id.link_text)).setText(SessionsQuery.LINKS_TITLES[i]); final int linkTitleIndex = i; linkContainer.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { fireLinkEvent(SessionsQuery.LINKS_TITLES[linkTitleIndex]); Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(intent); } }); container.addView(linkContainer); // Create separator View separatorView = new ImageView(getActivity()); separatorView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); separatorView.setBackgroundResource(android.R.drawable.divider_horizontal_bright); container.addView(separatorView); } } container.findViewById(R.id.empty_links).setVisibility(hasLinks ? View.GONE : View.VISIBLE); }
From source file:com.near.chimerarevo.fragments.PostFragment.java
private void addYoutubeVideo(String url) { final String yturl; if (url.contains("embed")) { String temp = url.split("embed/")[1]; if (url.contains("feature")) { temp = temp.split("feature=")[0]; yturl = temp.substring(0, temp.length() - 1); } else//from w w w .j a v a 2s .c o m yturl = temp; } else if (url.contains("youtu.be")) { yturl = url.split("youtu.be/")[1]; } else return; final RelativeLayout rl = new RelativeLayout(getActivity()); YouTubeThumbnailView yt = new YouTubeThumbnailView(getActivity()); ImageView icon = new ImageView(getActivity()); try { yt.setTag(yturl); yt.initialize(Constants.YOUTUBE_API_TOKEN, new OnInitializedListener() { @Override public void onInitializationFailure(YouTubeThumbnailView thumbView, YouTubeInitializationResult error) { rl.setVisibility(View.GONE); } @Override public void onInitializationSuccess(YouTubeThumbnailView thumbView, YouTubeThumbnailLoader thumbLoader) { thumbLoader.setVideo(yturl); } }); } catch (Exception e) { e.printStackTrace(); } RelativeLayout.LayoutParams obj_params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); obj_params.addRule(RelativeLayout.CENTER_HORIZONTAL); obj_params.addRule(RelativeLayout.CENTER_VERTICAL); yt.setLayoutParams(obj_params); icon.setImageResource(R.drawable.yt_play_button); icon.setLayoutParams(obj_params); RelativeLayout.LayoutParams rl_params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); rl_params.setMargins(0, 10, 0, 0); rl.setLayoutParams(rl_params); rl.setGravity(Gravity.CENTER_HORIZONTAL); rl.setClickable(true); rl.addView(yt); rl.addView(icon); rl.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(getActivity(), YoutubeActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i.putExtra(Constants.KEY_VIDEO_URL, yturl); startActivity(i); } }); lay.addView(rl); }
From source file:com.umeng.comm.ui.adapters.viewholders.FeedItemViewHolder.java
/** * feed icon</br>/*from w ww. j av a2 s .c o m*/ */ protected void setTypeIcon() { Drawable drawable = null; if (mFeedItem.type == FeedItem.ANNOUNCEMENT_FEED) { drawable = ColorQueque.getDrawable("umeng_comm_discuss_announce"); mFeedTypeImgView.setVisibility(View.VISIBLE); mFeedTypeImgView.setImageDrawable(drawable); } else { mFeedTypeImgView.setVisibility(View.INVISIBLE); } mfeedTypeContainer.removeAllViews(); if (mFeedItem.isTop == FeedItem.TOP_FEED) { ImageView img = new ImageView(mContext); img.setImageDrawable(ColorQueque.getDrawable("umeng_comm_weibo_ding")); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); mfeedTypeContainer.addView(img, lp); } if (mFeedItem.tag == 1) { ImageView img = new ImageView(mContext); img.setImageDrawable(ColorQueque.getDrawable("umeng_comm_weibo_jing")); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); if (mFeedItem.isTop == FeedItem.TOP_FEED) { lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); } mfeedTypeContainer.addView(img, lp); } }
From source file:com.rainmakerlabs.bleepsample.BleepService.java
public void imgShow(Bitmap bitmap, String strImgMsg) { MainActivity.adlib.put(strImgMsg, bitmap); Log.d("Portal", "Added an image. Size is now " + MainActivity.adlib.size()); Log.i("Portal", "Image added for key " + strImgMsg); if (MainActivity.myGallery == null) return;/*from w ww.j ava 2 s . com*/ if (MainActivity.gal_size < MainActivity.adlib.size()) { //new image has been added and the layout is initialized LinearLayout superLL = (LinearLayout) MainActivity.myGallery.getParent().getParent(); if (MainActivity.gal_size < 1) { ImageView imgSplash = (ImageView) superLL.findViewById(R.id.imgSplash); imgSplash.setVisibility(View.INVISIBLE); } LinearLayout layout = new LinearLayout(getApplicationContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); layout.setGravity(Gravity.CENTER); ImageView imageview = new ImageView(getApplicationContext()); imageview.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1000)); imageview.setScaleType(ImageView.ScaleType.CENTER_CROP); imageview.setImageBitmap(bitmap); //Add a button to go with it Button btnBuy = new Button(getApplicationContext()); LinearLayout.LayoutParams btnParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); btnParams.setMargins(-10, -10, -10, -10); btnBuy.setLayoutParams(btnParams); btnBuy.setText("Buy Now (" + strImgMsg + ")"); btnBuy.setBackgroundColor(MainActivity.getDominantColor(bitmap)); btnBuy.setTextColor(Color.WHITE); btnBuy.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { Intent newActivity = new Intent(getApplicationContext(), WebActivity.class); newActivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); newActivity.putExtra("URL", "https://portal-battlehack.herokuapp.com/"); startActivity(newActivity); } }); layout.addView(imageview); layout.addView(btnBuy); MainActivity.myGallery.addView(layout); MainActivity.gal_size++; } }
From source file:foam.starwisp.StarwispBuilder.java
public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) { if (StarwispLinearLayout.m_DisplayMetrics == null) { StarwispLinearLayout.m_DisplayMetrics = ctx.getResources().getDisplayMetrics(); }// w ww . j a va 2s . co m try { String type = arr.getString(0); //Log.i("starwisp","building started "+type); if (type.equals("build-fragment")) { String name = arr.getString(1); int ID = arr.getInt(2); Fragment fragment = ActivityManager.GetFragment(name); LinearLayout inner = new LinearLayout(ctx); inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); inner.setId(ID); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(ID, fragment); fragmentTransaction.commit(); parent.addView(inner); return; } if (type.equals("map")) { int ID = arr.getInt(1); LinearLayout inner = new LinearLayout(ctx); inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); inner.setId(ID); Fragment mapfrag = SupportMapFragment.newInstance(); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(ID, mapfrag); fragmentTransaction.commit(); parent.addView(inner); return; } if (type.equals("drawmap")) { final LinearLayout inner = new LinearLayout(ctx); inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); DrawableMap dm = new DrawableMap(); dm.init(arr.getInt(1), inner, (StarwispActivity) ctx, this, arr.getString(3)); parent.addView(inner); m_DMaps.put(arr.getInt(1), dm); return; } if (type.equals("linear-layout")) { StarwispLinearLayout.Build(this, ctx, ctxname, arr, parent); return; } if (type.equals("relative-layout")) { StarwispRelativeLayout.Build(this, ctx, ctxname, arr, parent); return; } if (type.equals("draggable")) { final LinearLayout v = new LinearLayout(ctx); final int id = arr.getInt(1); final String behaviour_type = arr.getString(5); v.setPadding(20, 20, 20, 10); v.setId(id); v.setOrientation(StarwispLinearLayout.BuildOrientation(arr.getString(2))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); v.setClickable(true); v.setFocusable(true); JSONArray col = arr.getJSONArray(4); v.setBackgroundResource(R.drawable.draggable); GradientDrawable drawable = (GradientDrawable) v.getBackground(); final int colour = Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)); drawable.setColor(colour); /*LayerDrawable bgDrawable = (LayerDrawable)v.getBackground(); GradientDrawable bgShape = (GradientDrawable)bgDrawable.findDrawableByLayerId(R.id.draggableshape); bgShape.setColor(colour);*/ /*v.getBackground().setColorFilter(colour, PorterDuff.Mode.MULTIPLY);*/ parent.addView(v); JSONArray children = arr.getJSONArray(6); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } // Sets a long click listener for the ImageView using an anonymous listener object that // implements the OnLongClickListener interface if (!behaviour_type.equals("drop-only") && !behaviour_type.equals("drop-only-consume")) { v.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View vv) { if (id != 99) { ClipData dragData = new ClipData( new ClipDescription("" + id, new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN }), new ClipData.Item("" + id)); View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v); Log.i("starwisp", "start drag id " + vv.getId() + " " + v); v.startDrag(dragData, myShadow, v, 0); v.setVisibility(View.GONE); return true; } return false; } }); } if (!behaviour_type.equals("drag-only")) { // ye gads - needed as drag/drop doesn't deal with nested targets final StarwispBuilder that = this; v.setOnDragListener(new View.OnDragListener() { public boolean onDrag(View vv, DragEvent event) { //Log.i("starwisp","on drag event happened"); final int action = event.getAction(); switch (action) { case DragEvent.ACTION_DRAG_STARTED: //Log.i("starwisp","Drag started"+v ); if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { // returns true to indicate that the View can accept the dragged data. return true; } else { // Returns false. During the current drag and drop operation, this View will // not receive events again until ACTION_DRAG_ENDED is sent. return false; } case DragEvent.ACTION_DRAG_ENTERED: { if (that.m_LastDragHighlighted != null) { that.m_LastDragHighlighted.getBackground().setColorFilter(null); } v.getBackground().setColorFilter(0x77777777, PorterDuff.Mode.MULTIPLY); that.m_LastDragHighlighted = v; //Log.i("starwisp","Drag entered"+v ); return true; } case DragEvent.ACTION_DRAG_LOCATION: { //View dragee = (View)event.getLocalState(); //dragee.setVisibility(View.VISIBLE); //Log.i("starwisp","Drag location"+v ); return true; } case DragEvent.ACTION_DRAG_EXITED: { //Log.i("starwisp","Drag exited "+v ); v.getBackground().setColorFilter(null); return true; } case DragEvent.ACTION_DROP: { v.getBackground().setColorFilter(null); //Log.i("starwisp","Drag dropped "+v ); View otherw = (View) event.getLocalState(); //Log.i("starwisp","removing from parent "+((View)otherw.getParent()).getId()); // check we are not adding to ourself if (id != otherw.getId()) { ((ViewManager) otherw.getParent()).removeView(otherw); //Log.i("starwisp","adding to " + id); if (!behaviour_type.equals("drop-only-consume")) { v.addView(otherw); } } otherw.setVisibility(View.VISIBLE); return true; } case DragEvent.ACTION_DRAG_ENDED: { //Log.i("starwisp","Drag ended "+v ); v.getBackground().setColorFilter(null); View dragee = (View) event.getLocalState(); dragee.setVisibility(View.VISIBLE); if (event.getResult()) { //Log.i("starwisp","sucess " ); } else { //Log.i("starwisp","fail " ); } ; return true; } // An unknown action type was received. default: //Log.e("starwisp","Unknown action type received by OnDragListener."); break; } ; return true; } }); return; } } if (type.equals("frame-layout")) { FrameLayout v = new FrameLayout(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } /* if (type.equals("grid-layout")) { GridLayout v = new GridLayout(ctx); v.setId(arr.getInt(1)); v.setRowCount(arr.getInt(2)); //v.setColumnCount(arr.getInt(2)); v.setOrientation(BuildOrientation(arr.getString(3))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); parent.addView(v); JSONArray children = arr.getJSONArray(5); for (int i=0; i<children.length(); i++) { Build(ctx,ctxname,new JSONArray(children.getString(i)), v); } return; } */ if (type.equals("scroll-view")) { HorizontalScrollView v = new HorizontalScrollView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("scroll-view-vert")) { ScrollView v = new ScrollView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("view-pager")) { ViewPager v = new ViewPager(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); v.setOffscreenPageLimit(3); 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 fragment data " + e.toString()); } return null; } }); parent.addView(v); return; } if (type.equals("space")) { // Space v = new Space(ctx); (class not found runtime error??) TextView v = new TextView(ctx); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); } if (type.equals("image-view")) { ImageView v = new ImageView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); v.setAdjustViewBounds(true); String image = arr.getString(2); if (image.startsWith("/")) { Bitmap b = BitmapCache.Load(image); if (b != null) { v.setImageBitmap(b); } } else { int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName()); v.setImageResource(id); } parent.addView(v); } if (type.equals("image-button")) { ImageButton v = new ImageButton(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); String image = arr.getString(2); if (image.startsWith("/")) { v.setImageBitmap(BitmapCache.Load(image)); } else { int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName()); v.setImageResource(id); } final String fn = arr.getString(4); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Callback(ctx, ctxname, v.getId()); } }); v.setAdjustViewBounds(true); v.setScaleType(ImageView.ScaleType.CENTER_INSIDE); parent.addView(v); } if (type.equals("text-view")) { TextView v = new TextView(ctx); v.setId(arr.getInt(1)); v.setText(Html.fromHtml(arr.getString(2)), BufferType.SPANNABLE); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setLinkTextColor(0xff00aa00); // uncomment all this to get hyperlinks to work in text... // should make this an option of course //v.setClickable(true); // make links //v.setMovementMethod(LinkMovementMethod.getInstance()); //v.setEnabled(true); // go to browser /*v.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View vv, MotionEvent event) { return false; } };*/ if (arr.length() > 5) { if (arr.getString(5).equals("left")) { v.setGravity(Gravity.LEFT); } else { if (arr.getString(5).equals("fill")) { v.setGravity(Gravity.FILL); } else { v.setGravity(Gravity.CENTER); } } } else { v.setGravity(Gravity.CENTER); } v.setTypeface(((StarwispActivity) ctx).m_Typeface); parent.addView(v); } if (type.equals("debug-text-view")) { TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null); // v.setBackgroundResource(R.color.black); v.setId(arr.getInt(1)); // v.setText(Html.fromHtml(arr.getString(2))); // v.setTextColor(R.color.white); // v.setTextSize(arr.getInt(3)); // v.setMovementMethod(LinkMovementMethod.getInstance()); // v.setMaxLines(10); // v.setVerticalScrollBarEnabled(true); // v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); //v.setMovementMethod(new ScrollingMovementMethod()); /* if (arr.length()>5) { if (arr.getString(5).equals("left")) { v.setGravity(Gravity.LEFT); } else { if (arr.getString(5).equals("fill")) { v.setGravity(Gravity.FILL); } else { v.setGravity(Gravity.CENTER); } } } else { v.setGravity(Gravity.LEFT); } v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/ parent.addView(v); } if (type.equals("web-view")) { WebView v = new WebView(ctx); v.setId(arr.getInt(1)); v.setVerticalScrollBarEnabled(false); v.loadData(arr.getString(2), "text/html", "utf-8"); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); parent.addView(v); } if (type.equals("edit-text")) { final EditText v = new EditText(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setGravity(Gravity.LEFT | Gravity.TOP); String inputtype = arr.getString(4); if (inputtype.equals("text")) { //v.setInputType(InputType.TYPE_CLASS_TEXT); } else if (inputtype.equals("numeric")) { v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED); } else if (inputtype.equals("email")) { v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS); } v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(5); //v.setSingleLine(true); v.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\""); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); parent.addView(v); } if (type.equals("button")) { Button v = new Button(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(5); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Callback(ctx, ctxname, v.getId()); } }); parent.addView(v); } if (type.equals("colour-button")) { Button v = new Button(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); JSONArray col = arr.getJSONArray(6); v.getBackground().setColorFilter( Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)), PorterDuff.Mode.MULTIPLY); final String fn = arr.getString(5); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Callback(ctx, ctxname, v.getId()); } }); parent.addView(v); } if (type.equals("toggle-button")) { ToggleButton v = new ToggleButton(ctx); if (arr.getString(5).equals("fancy")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null); } if (arr.getString(5).equals("yes")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null); } if (arr.getString(5).equals("maybe")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null); } if (arr.getString(5).equals("no")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null); } v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(6); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, v.getId(), arg); } }); parent.addView(v); } if (type.equals("seek-bar")) { SeekBar v = new SeekBar(ctx); v.setId(arr.getInt(1)); v.setMax(arr.getInt(2)); v.setProgress(arr.getInt(2) / 2); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); final String fn = arr.getString(4); v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar v, int a, boolean s) { CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a)); } public void onStartTrackingTouch(SeekBar v) { } public void onStopTrackingTouch(SeekBar v) { } }); parent.addView(v); } if (type.equals("spinner")) { Spinner v = new Spinner(ctx); final int wid = arr.getInt(1); v.setId(wid); final JSONArray items = arr.getJSONArray(2); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); v.setMinimumWidth(100); // stops tiny buttons 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, R.layout.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; } }; spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout); v.setAdapter(spinnerArrayAdapter); v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> a, View v, int pos, long id) { CallbackArgs(ctx, ctxname, wid, "" + pos); } public void onNothingSelected(AdapterView<?> v) { } }); parent.addView(v); } if (type.equals("nomadic")) { final int wid = arr.getInt(1); NomadicSurfaceView v = new NomadicSurfaceView(ctx, wid); v.setId(wid); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); Log.e("starwisp", "built the thing"); parent.addView(v); Log.e("starwisp", "addit to the view"); } if (type.equals("canvas")) { StarwispCanvas v = new StarwispCanvas(ctx); final int wid = arr.getInt(1); v.setId(wid); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); v.SetDrawList(arr.getJSONArray(3)); parent.addView(v); } if (type.equals("camera-preview")) { PictureTaker pt = new PictureTaker(); CameraPreview v = new CameraPreview(ctx, pt); final int wid = arr.getInt(1); v.setId(wid); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); Log.i("starwisp", "in camera-preview..."); List<List<String>> info = v.mPictureTaker.GetInfo(); // can't find a way to do this via a callback yet String arg = "'("; for (List<String> e : info) { arg += "(" + e.get(0) + " " + e.get(1) + ")"; //Log.i("starwisp","converting prop "+arg); } arg += ")"; m_Scheme.eval("(set! camera-properties " + arg + ")"); } if (type.equals("button-grid")) { LinearLayout horiz = new LinearLayout(ctx); final int id = arr.getInt(1); final String buttontype = arr.getString(2); horiz.setId(id); horiz.setOrientation(LinearLayout.HORIZONTAL); parent.addView(horiz); int height = arr.getInt(3); int textsize = arr.getInt(4); LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5)); JSONArray buttons = arr.getJSONArray(6); 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 = arr.getString(6); 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 = arr.getString(6); 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); } } } } catch (JSONException e) { Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString()); } //Log.i("starwisp","building ended"); }