List of usage examples for android.graphics.drawable GradientDrawable setColor
public void setColor(@Nullable ColorStateList colorStateList)
From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java
private GradientDrawable makeThumbDrawable(int color, int thumbWidth, int thumbHeight, float radius, int padding) { GradientDrawable thumbDrawable = new GradientDrawable(); if (padding > 0) { thumbDrawable.setStroke(padding, Color.TRANSPARENT);//make a transparent stroke ,just like padding }// w w w . ja v a2 s . com thumbDrawable.setCornerRadius(radius); thumbDrawable.setSize(thumbWidth, thumbHeight); thumbDrawable.setColor(color); return thumbDrawable; }
From source file:com.htc.dotdesign.ToolBoxService.java
private void updateBrushColor() { Resources resources = getResources(); ImageView button = null;/* w w w . j av a 2 s . c o m*/ GradientDrawable drawable = null; View extendView = null; if (mCurrFun == FunType.Fun_Palette) { extendView = mPalette; } else { extendView = mEraser; } if (extendView != null) { button = (ImageView) extendView.findViewById(R.id.btn_1x1); if (button != null) { //drawable = (GradientDrawable) button.getBackground(); drawable = (GradientDrawable) button.getDrawable(); if (mCurrBrushSize == BrushSize.Size_1x1) { drawable.setColor(resources.getColor(R.color.brush_size_enable_color)); } else if (mCurrBrushSize == BrushSize.Size_2x2) { drawable.setColor(resources.getColor(R.color.brush_size_disable_color)); } } button = (ImageView) extendView.findViewById(R.id.btn_2x2); if (button != null) { //drawable = (GradientDrawable) button.getBackground(); drawable = (GradientDrawable) button.getDrawable(); if (mCurrBrushSize == BrushSize.Size_1x1) { drawable.setColor(resources.getColor(R.color.brush_size_disable_color)); } else if (mCurrBrushSize == BrushSize.Size_2x2) { drawable.setColor(resources.getColor(R.color.brush_size_enable_color)); } } } }
From source file:foam.opensauces.StarwispBuilder.java
public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) { try {/* w w w. j a va 2 s .c o m*/ 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:de.mrapp.android.preference.activity.PreferenceActivity.java
/** * Sets the background color of the toolbar, which is used to show the title of the currently * selected preference header on devices with a large screen. * * @param color//from w w w . j a va 2 s.co m * The background color, which should be set, as an {@link Integer} value * @return True, if the background has been set, false otherwise */ public final boolean setBreadCrumbBackgroundColor(@ColorInt final int color) { if (getBreadCrumbToolbar() != null) { breadCrumbBackgroundColor = color; GradientDrawable background = (GradientDrawable) ContextCompat.getDrawable(this, R.drawable.breadcrumb_background); background.setColor(color); ViewUtil.setBackground(getBreadCrumbToolbar(), background); return true; } return false; }
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(); }/*from w w w . j a v a 2 s. 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"); }
From source file:cw.kop.autobackground.sources.SourceListFragment.java
@Override public void onClick(final View v) { switch (v.getId()) { case R.id.set_button: setWallpaper();/*from w w w . ja va 2s . c o m*/ break; case R.id.floating_button_icon: final GradientDrawable circleDrawable = (GradientDrawable) getResources() .getDrawable(R.drawable.floating_button_circle); final float scale = (float) ((Math.hypot(addButtonBackground.getX(), addButtonBackground.getY()) + addButtonBackground.getWidth()) / addButtonBackground.getWidth() * 2); Animation animation = new Animation() { private boolean needsFragment = true; private float pivot; @Override public void initialize(int width, int height, int parentWidth, int parentHeight) { super.initialize(width, height, parentWidth, parentHeight); pivot = resolveSize(RELATIVE_TO_SELF, 0.5f, width, parentWidth); } @Override protected void applyTransformation(float interpolatedTime, Transformation t) { if (needsFragment && interpolatedTime >= 1) { needsFragment = false; showSourceAddFragment(); } else { float scaleFactor = 1.0f + ((scale - 1.0f) * interpolatedTime); t.getMatrix().setScale(scaleFactor, scaleFactor, pivot, pivot); } } @Override public boolean willChangeBounds() { return true; } }; animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE)); addButtonBackground.setImageDrawable(circleDrawable); } @Override public void onAnimationEnd(Animation animation) { handler.postDelayed(new Runnable() { @Override public void run() { if (needsButtonReset) { addButton.setOnClickListener(SourceListFragment.this); addButtonBackground.setScaleX(1.0f); addButtonBackground.setScaleY(1.0f); addButtonBackground.clearAnimation(); circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE)); addButtonBackground.setImageDrawable(circleDrawable); addButton.setVisibility(View.VISIBLE); } } }, 100); } @Override public void onAnimationRepeat(Animation animation) { } }); ValueAnimator buttonColorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), getResources().getColor(R.color.ACCENT_OPAQUE), getResources().getColor(AppSettings.getBackgroundColorResource())); buttonColorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { circleDrawable.setColor((Integer) animation.getAnimatedValue()); addButtonBackground.setImageDrawable(circleDrawable); } }); DecelerateInterpolator decelerateInterpolator = new DecelerateInterpolator(); animation.setDuration(ADD_ANIMATION_TIME); buttonColorAnimation.setDuration((long) (ADD_ANIMATION_TIME * 0.9)); buttonColorAnimation.setInterpolator(decelerateInterpolator); animation.setInterpolator(decelerateInterpolator); // Post a delayed Runnable to ensure reset even if animation is interrupted handler.postDelayed(new Runnable() { @Override public void run() { if (needsButtonReset) { addButtonBackground.setScaleX(1.0f); addButtonBackground.setScaleY(1.0f); addButtonBackground.clearAnimation(); circleDrawable.setColor(getResources().getColor(R.color.ACCENT_OPAQUE)); addButtonBackground.setImageDrawable(circleDrawable); addButton.setVisibility(View.VISIBLE); needsButtonReset = false; } } }, (long) (ADD_ANIMATION_TIME * 1.1f)); needsButtonReset = true; addButton.setVisibility(View.GONE); buttonColorAnimation.start(); addButtonBackground.startAnimation(animation); break; default: } }
From source file:com.bilibili.magicasakura.utils.GradientDrawableUtils.java
@Override protected Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { GradientDrawable gradientDrawable = new GradientDrawable(); inflateGradientRootElement(context, attrs, gradientDrawable); int type;//w w w. ja v a 2 s . com final int innerDepth = parser.getDepth() + 1; int depth; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) { if (type != XmlPullParser.START_TAG) { continue; } if (depth > innerDepth) { continue; } String name = parser.getName(); if (name.equals("size")) { final int width = getAttrDimensionPixelSize(context, attrs, android.R.attr.width); final int height = getAttrDimensionPixelSize(context, attrs, android.R.attr.height); gradientDrawable.setSize(width, height); } else if (name.equals("gradient") && Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { final float centerX = getAttrFloatOrFraction(context, attrs, android.R.attr.centerX, 0.5f, 1.0f, 1.0f); final float centerY = getAttrFloatOrFraction(context, attrs, android.R.attr.centerY, 0.5f, 1.0f, 1.0f); gradientDrawable.setGradientCenter(centerX, centerY); final boolean useLevel = getAttrBoolean(context, attrs, android.R.attr.useLevel, false); gradientDrawable.setUseLevel(useLevel); final int gradientType = getAttrInt(context, attrs, android.R.attr.type, 0); gradientDrawable.setGradientType(gradientType); final int startColor = getAttrColor(context, attrs, android.R.attr.startColor, Color.TRANSPARENT); final int centerColor = getAttrColor(context, attrs, android.R.attr.centerColor, Color.TRANSPARENT); final int endColor = getAttrColor(context, attrs, android.R.attr.endColor, Color.TRANSPARENT); if (!getAttrHasValue(context, attrs, android.R.attr.centerColor)) { gradientDrawable.setColors(new int[] { startColor, endColor }); } else { gradientDrawable.setColors(new int[] { startColor, centerColor, endColor }); setStGradientPositions(gradientDrawable.getConstantState(), 0.0f, centerX != 0.5f ? centerX : centerY, 1f); } if (gradientType == GradientDrawable.LINEAR_GRADIENT) { int angle = (int) getAttrFloat(context, attrs, android.R.attr.angle, 0.0f); angle %= 360; if (angle % 45 != 0) { throw new XmlPullParserException( "<gradient> tag requires" + "'angle' attribute to " + "be a multiple of 45"); } setStGradientAngle(gradientDrawable.getConstantState(), angle); switch (angle) { case 0: gradientDrawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT); break; case 45: gradientDrawable.setOrientation(GradientDrawable.Orientation.BL_TR); break; case 90: gradientDrawable.setOrientation(GradientDrawable.Orientation.BOTTOM_TOP); break; case 135: gradientDrawable.setOrientation(GradientDrawable.Orientation.BR_TL); break; case 180: gradientDrawable.setOrientation(GradientDrawable.Orientation.RIGHT_LEFT); break; case 225: gradientDrawable.setOrientation(GradientDrawable.Orientation.TR_BL); break; case 270: gradientDrawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM); break; case 315: gradientDrawable.setOrientation(GradientDrawable.Orientation.TL_BR); break; } } else { setGradientRadius(context, attrs, gradientDrawable, gradientType); } } else if (name.equals("solid")) { int color = getAttrColor(context, attrs, android.R.attr.color, Color.TRANSPARENT); gradientDrawable .setColor(getAlphaColor(color, getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f))); } else if (name.equals("stroke")) { final float alphaMod = getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f); final int strokeColor = getAttrColor(context, attrs, android.R.attr.color, Color.TRANSPARENT); final int strokeWidth = getAttrDimensionPixelSize(context, attrs, android.R.attr.width); final float dashWidth = getAttrDimension(context, attrs, android.R.attr.dashWidth); if (dashWidth != 0.0f) { final float dashGap = getAttrDimension(context, attrs, android.R.attr.dashGap); gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod), dashWidth, dashGap); } else { gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod)); } } else if (name.equals("corners")) { final int radius = getAttrDimensionPixelSize(context, attrs, android.R.attr.radius); gradientDrawable.setCornerRadius(radius); final int topLeftRadius = getAttrDimensionPixelSize(context, attrs, android.R.attr.topLeftRadius, radius); final int topRightRadius = getAttrDimensionPixelSize(context, attrs, android.R.attr.topRightRadius, radius); final int bottomLeftRadius = getAttrDimensionPixelSize(context, attrs, android.R.attr.bottomLeftRadius, radius); final int bottomRightRadius = getAttrDimensionPixelSize(context, attrs, android.R.attr.bottomRightRadius, radius); if (topLeftRadius != radius || topRightRadius != radius || bottomLeftRadius != radius || bottomRightRadius != radius) { // The corner radii are specified in clockwise order (see Path.addRoundRect()) gradientDrawable.setCornerRadii( new float[] { topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius }); } } else if (name.equals("padding")) { final int paddingLeft = getAttrDimensionPixelOffset(context, attrs, android.R.attr.left); final int paddingTop = getAttrDimensionPixelOffset(context, attrs, android.R.attr.top); final int paddingRight = getAttrDimensionPixelOffset(context, attrs, android.R.attr.right); final int paddingBottom = getAttrDimensionPixelOffset(context, attrs, android.R.attr.bottom); if (paddingLeft != 0 || paddingTop != 0 || paddingRight != 0 || paddingBottom != 0) { final Rect pad = new Rect(); pad.set(paddingLeft, paddingTop, paddingRight, paddingBottom); try { if (sPaddingField == null) { sPaddingField = GradientDrawable.class.getDeclaredField("mPadding"); sPaddingField.setAccessible(true); } sPaddingField.set(gradientDrawable, pad); if (sStPaddingField == null) { sStPaddingField = Class .forName("android.graphics.drawable.GradientDrawable$GradientState") .getDeclaredField("mPadding"); sStPaddingField.setAccessible(true); } sStPaddingField.set(gradientDrawable.getConstantState(), pad); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } else { Log.w("drawable", "Bad element under <shape>: " + name); } } return gradientDrawable; }
From source file:com.bilibili.magicasakura.utils.GradientDrawableInflateImpl.java
@Override public Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { GradientDrawable gradientDrawable = new GradientDrawable(); inflateGradientRootElement(context, attrs, gradientDrawable); int type;// ww w . j ava 2 s.c o m final int innerDepth = parser.getDepth() + 1; int depth; while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) { if (type != XmlPullParser.START_TAG) { continue; } if (depth > innerDepth) { continue; } String name = parser.getName(); if (name.equals("size")) { final int width = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.width); final int height = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.height); gradientDrawable.setSize(width, height); } else if (name.equals("gradient") && Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { final float centerX = getAttrFloatOrFraction(context, attrs, android.R.attr.centerX, 0.5f, 1.0f, 1.0f); final float centerY = getAttrFloatOrFraction(context, attrs, android.R.attr.centerY, 0.5f, 1.0f, 1.0f); gradientDrawable.setGradientCenter(centerX, centerY); final boolean useLevel = DrawableUtils.getAttrBoolean(context, attrs, android.R.attr.useLevel, false); gradientDrawable.setUseLevel(useLevel); final int gradientType = DrawableUtils.getAttrInt(context, attrs, android.R.attr.type, 0); gradientDrawable.setGradientType(gradientType); final int startColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.startColor, Color.TRANSPARENT); final int centerColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.centerColor, Color.TRANSPARENT); final int endColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.endColor, Color.TRANSPARENT); if (!DrawableUtils.getAttrHasValue(context, attrs, android.R.attr.centerColor)) { gradientDrawable.setColors(new int[] { startColor, endColor }); } else { gradientDrawable.setColors(new int[] { startColor, centerColor, endColor }); setStGradientPositions(gradientDrawable.getConstantState(), 0.0f, centerX != 0.5f ? centerX : centerY, 1f); } if (gradientType == GradientDrawable.LINEAR_GRADIENT) { int angle = (int) DrawableUtils.getAttrFloat(context, attrs, android.R.attr.angle, 0.0f); angle %= 360; if (angle % 45 != 0) { throw new XmlPullParserException( "<gradient> tag requires" + "'angle' attribute to " + "be a multiple of 45"); } setStGradientAngle(gradientDrawable.getConstantState(), angle); switch (angle) { case 0: gradientDrawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT); break; case 45: gradientDrawable.setOrientation(GradientDrawable.Orientation.BL_TR); break; case 90: gradientDrawable.setOrientation(GradientDrawable.Orientation.BOTTOM_TOP); break; case 135: gradientDrawable.setOrientation(GradientDrawable.Orientation.BR_TL); break; case 180: gradientDrawable.setOrientation(GradientDrawable.Orientation.RIGHT_LEFT); break; case 225: gradientDrawable.setOrientation(GradientDrawable.Orientation.TR_BL); break; case 270: gradientDrawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM); break; case 315: gradientDrawable.setOrientation(GradientDrawable.Orientation.TL_BR); break; } } else { setGradientRadius(context, attrs, gradientDrawable, gradientType); } } else if (name.equals("solid")) { int color = DrawableUtils.getAttrColor(context, attrs, android.R.attr.color, Color.TRANSPARENT); gradientDrawable.setColor(getAlphaColor(color, DrawableUtils.getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f))); } else if (name.equals("stroke")) { final float alphaMod = DrawableUtils.getAttrFloat(context, attrs, android.R.attr.alpha, 1.0f); final int strokeColor = DrawableUtils.getAttrColor(context, attrs, android.R.attr.color, Color.TRANSPARENT); final int strokeWidth = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.width); final float dashWidth = DrawableUtils.getAttrDimension(context, attrs, android.R.attr.dashWidth); if (dashWidth != 0.0f) { final float dashGap = DrawableUtils.getAttrDimension(context, attrs, android.R.attr.dashGap); gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod), dashWidth, dashGap); } else { gradientDrawable.setStroke(strokeWidth, getAlphaColor(strokeColor, alphaMod)); } } else if (name.equals("corners")) { final int radius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.radius); gradientDrawable.setCornerRadius(radius); final int topLeftRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.topLeftRadius, radius); final int topRightRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.topRightRadius, radius); final int bottomLeftRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.bottomLeftRadius, radius); final int bottomRightRadius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.bottomRightRadius, radius); if (topLeftRadius != radius || topRightRadius != radius || bottomLeftRadius != radius || bottomRightRadius != radius) { // The corner radii are specified in clockwise order (see Path.addRoundRect()) gradientDrawable.setCornerRadii( new float[] { topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, bottomRightRadius, bottomRightRadius, bottomLeftRadius, bottomLeftRadius }); } } else if (name.equals("padding")) { final int paddingLeft = DrawableUtils.getAttrDimensionPixelOffset(context, attrs, android.R.attr.left); final int paddingTop = DrawableUtils.getAttrDimensionPixelOffset(context, attrs, android.R.attr.top); final int paddingRight = DrawableUtils.getAttrDimensionPixelOffset(context, attrs, android.R.attr.right); final int paddingBottom = DrawableUtils.getAttrDimensionPixelOffset(context, attrs, android.R.attr.bottom); if (paddingLeft != 0 || paddingTop != 0 || paddingRight != 0 || paddingBottom != 0) { final Rect pad = new Rect(); pad.set(paddingLeft, paddingTop, paddingRight, paddingBottom); try { if (sPaddingField == null) { sPaddingField = GradientDrawable.class.getDeclaredField("mPadding"); sPaddingField.setAccessible(true); } sPaddingField.set(gradientDrawable, pad); if (sStPaddingField == null) { sStPaddingField = Class .forName("android.graphics.drawable.GradientDrawable$GradientState") .getDeclaredField("mPadding"); sStPaddingField.setAccessible(true); } sStPaddingField.set(gradientDrawable.getConstantState(), pad); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } } } else { Log.w("drawable", "Bad element under <shape>: " + name); } } return gradientDrawable; }
From source file:me.ububble.speakall.fragment.ConversationChatFragment.java
public void showMensajeLocation(int position, Context context, final Message message, View rowView, TextView icnMessageArrow) {// w ww .j av a2s . c o m final TextView prevMessages = (TextView) rowView.findViewById(R.id.showprev_messages); TextView messageTime = (TextView) rowView.findViewById(R.id.message_time); final TextView icnMesajeTempo = (TextView) rowView.findViewById(R.id.icn_message_tempo); final View icnMensajeTempoDivider = (View) rowView.findViewById(R.id.icn_message_tempo_divider); final TextView icnMesajeCopy = (TextView) rowView.findViewById(R.id.icn_message_copy); final TextView icnMesajeBack = (TextView) rowView.findViewById(R.id.icn_message_back); final ImageView messageContent = (ImageView) rowView.findViewById(R.id.message_content); TextView messageStatus = (TextView) rowView.findViewById(R.id.message_status); final LinearLayout messageMenu = (LinearLayout) rowView.findViewById(R.id.messages_menu_layout); final LinearLayout mensajeLayout = (LinearLayout) rowView.findViewById(R.id.mensaje_layout); TextView messageDate = (TextView) rowView.findViewById(R.id.message_date); TextView messageLocationText = (TextView) rowView.findViewById(R.id.message_location_text); TextView messageLocationIcon = (TextView) rowView.findViewById(R.id.message_location_icon); TFCache.apply(context, messageTime, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, icnMesajeTempo, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeCopy, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeBack, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, messageLocationIcon, TFCache.TF_SPEAKALL); TFCache.apply(context, messageDate, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, messageLocationText, TFCache.TF_WHITNEY_MEDIUM); if (position == 0) { if (mensajesTotal > mensajesOffset) { prevMessages.setVisibility(View.VISIBLE); prevMessages.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { prevMessages.setVisibility(View.GONE); if (mensajesTotal - mensajesOffset >= 10) { mensajesLimit = 10; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } else { mensajesLimit = mensajesTotal - mensajesOffset; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } } }); } } double latitud = 0; double longitud = 0; try { JSONObject locationData = new JSONObject(message.mensaje); messageLocationText.setText(locationData.getString("direccion")); latitud = Double.parseDouble(locationData.getString("latitud")); longitud = Double.parseDouble(locationData.getString("longitud")); } catch (JSONException e) { e.printStackTrace(); } DateFormat dateDay = new SimpleDateFormat("d"); DateFormat dateDayText = new SimpleDateFormat("EEEE"); DateFormat dateMonth = new SimpleDateFormat("MMMM"); DateFormat dateYear = new SimpleDateFormat("yyyy"); DateFormat timeFormat = new SimpleDateFormat("h:mm a"); Calendar fechamsj = Calendar.getInstance(); fechamsj.setTimeInMillis(message.emitedAt); String time = timeFormat.format(fechamsj.getTime()); String dayMessage = dateDay.format(fechamsj.getTime()); String monthMessage = dateMonth.format(fechamsj.getTime()); String yearMessage = dateYear.format(fechamsj.getTime()); String dayMessageText = dateDayText.format(fechamsj.getTime()); char[] caracteres = dayMessageText.toCharArray(); caracteres[0] = Character.toUpperCase(caracteres[0]); dayMessageText = new String(caracteres); Calendar fechaActual = Calendar.getInstance(); String dayActual = dateDay.format(fechaActual.getTime()); String monthActual = dateMonth.format(fechaActual.getTime()); String yearActual = dateYear.format(fechaActual.getTime()); String fechaMostrar = ""; if (dayMessage.equals(dayActual) && monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { fechaMostrar = getString(R.string.messages_today); } else if (monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { int days = Integer.parseInt(dayActual) - Integer.parseInt(dayMessage); if (days < 7) { switch (days) { case 1: fechaMostrar = getString(R.string.messages_yesterday); break; default: fechaMostrar = dayMessageText; break; } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } messageDate.setText(fechaMostrar); if (position != -1) { if (itemAnterior != null) { if (!fechaMostrar.equals(fechaAnterior)) { itemAnterior.findViewById(R.id.message_date).setVisibility(View.VISIBLE); } else { itemAnterior.findViewById(R.id.message_date).setVisibility(View.GONE); } } itemAnterior = rowView; fechaAnterior = fechaMostrar; } else { View v = messagesList.getChildAt(messagesList.getChildCount() - 1); if (v != null) { TextView tv = (TextView) v.findViewById(R.id.message_date); if (tv.getText().toString().equals(fechaMostrar)) { messageDate.setVisibility(View.GONE); } else { messageDate.setVisibility(View.VISIBLE); } } } messageTime.setText(time); if (message.emisor.equals(u.id)) { if (message.status != -1) { rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(30); Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (mensaje.status != 4) { icnMesajeTempo.setVisibility(View.VISIBLE); icnMensajeTempoDivider.setVisibility(View.VISIBLE); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeTempo, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeTempo, "translationX", 150, 0), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } else { icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } return false; } }); } if (message.status == 1) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setTextColor(getResources().getColor(R.color.speak_all_ligh_gray)); messageStatus.setText(Finder.STRING.ICN_MSJ_SENDING.toString()); ValueAnimator colorAnim = ObjectAnimator.ofFloat(messageStatus, "alpha", 1, 0); colorAnim.setRepeatCount(ValueAnimator.INFINITE); colorAnim.setRepeatMode(ValueAnimator.REVERSE); colorAnim.setDuration(1000).start(); animaciones.put(message.mensajeId, colorAnim); JSONObject data = new JSONObject(); try { data.put("message_id", message.mensajeId); data.put("source", message.emisor); data.put("source_email", message.emisorEmail); data.put("target_email", message.receptorEmail); data.put("target", message.receptor); data.put("message", message.mensaje); data.put("source_lang", message.emisorLang); data.put("delay", message.delay); data.put("type", message.tipo); } catch (JSONException e) { Log.w("--->", e.toString()); e.printStackTrace(); } if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { message.status = 1; SpeakSocket.mSocket.emit("message", data); } else { message.status = -1; } } if (message.status == -1) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_ERROR.toString()); } if (message.status == 3) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_CLOSED.toString()); } if (message.status == 2) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_SEND.toString()); } if (message.status == 4) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_OPENED.toString()); icnMensajeTempoDivider.setVisibility(View.GONE); icnMesajeTempo.setVisibility(View.GONE); } else { icnMensajeTempoDivider.setVisibility(View.INVISIBLE); icnMesajeTempo.setVisibility(View.INVISIBLE); } } else { mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getFriendBalloon(activity)); if (message.tipo == Integer.parseInt(getString(R.string.MSG_TYPE_BROADCAST_PHOTO))) { messageStatus.setTextSize(15); messageStatus.setText(Finder.STRING.ICN_BROADCAST_FILL.toString()); } //messageContent.setText(message.mensajeTrad); icnMesajeTempo.setVisibility(View.GONE); rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(20); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", -100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", -150, 0)); set.setDuration(200).start(); return false; } }); } icnMesajeTempo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { JSONObject notifyMessage = new JSONObject(); try { Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (mensaje.status != 4) { notifyMessage.put("type", mensaje.tipo); notifyMessage.put("message_id", mensaje.mensajeId); notifyMessage.put("source", mensaje.receptor); notifyMessage.put("status", 5); SpeakSocket.mSocket.emit("message-status", notifyMessage); } new Delete().from(Message.class).where("mensajeId = ?", mensaje.mensajeId).execute(); Message message = null; if (mensaje.emisor.equals(u.id)) { message = new Select().from(Message.class) .where("emisor = ? or receptor = ?", mensaje.receptor, mensaje.receptor) .orderBy("emitedAt DESC").executeSingle(); } else { message = new Select().from(Message.class) .where("emisor = ? or receptor = ?", mensaje.emisor, mensaje.emisor) .orderBy("emitedAt DESC").executeSingle(); } if (message != null) { Chats chat = null; if (mensaje.emisor.equals(u.id)) { chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.receptor) .executeSingle(); } else { chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.emisor) .executeSingle(); } if (chat != null) { chat.mensajeId = message.mensajeId; chat.lastStatus = message.status; chat.emitedAt = message.emitedAt; chat.lang = message.emisorLang; chat.notRead = 0; if (chat.idContacto.equals(message.emisor)) chat.lastMessage = message.mensajeTrad; else chat.lastMessage = message.mensaje; chat.save(); } } else { if (mensaje.emisor.equals(u.id)) { new Delete().from(Chats.class).where("idContacto = ?", mensaje.receptor).execute(); } else { new Delete().from(Chats.class).where("idContacto = ?", mensaje.emisor).execute(); } } View delete = messagesList.findViewWithTag(mensaje.mensajeId); if (delete != null) messagesList.removeView(delete); messageSelected = null; ((MainActivity) activity).setOnBackPressedListener(null); } catch (JSONException e) { e.printStackTrace(); } } } ); icnMesajeCopy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { /*ClipData clip = ClipData.newPlainText("text", messageContent.getText().toString()); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(clip); Toast.makeText(activity, "Copiado", Toast.LENGTH_SHORT).show();*/ } } ); icnMesajeBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (message.emisor.equals(u.id)) { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensaje)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } else { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensajeTrad)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } } } ); final double finalLatitud = latitud; final double finalLongitud = longitud; rowView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); if (!messageSelected.equals(message.mensajeId)) { vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } else { if (mensaje.status != -1) { dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:" + finalLatitud + "," + finalLongitud)); i.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(i); } } if (mensaje.status == -1) { JSONObject data = new JSONObject(); try { data.put("message_id", mensaje.mensajeId); data.put("source", mensaje.emisor); data.put("source_email", mensaje.emisorEmail); data.put("target_email", mensaje.receptorEmail); data.put("target", mensaje.receptor); data.put("message", message.mensaje); data.put("source_lang", mensaje.emisorLang); data.put("delay", mensaje.delay); data.put("type", mensaje.tipo); } catch (JSONException e) { Log.w("--->", e.toString()); e.printStackTrace(); } if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { mensaje.status = 1; SpeakSocket.mSocket.emit("message", data); } else { mensaje.status = -1; } changeStatus(mensaje.mensajeId, mensaje.status); } } } ); }
From source file:me.ububble.speakall.fragment.ConversationChatFragment.java
public void showMensajeContact(int position, final Context context, final Message message, View rowView, TextView icnMessageArrow) {/*from w w w .ja v a 2s .c o m*/ final TextView prevMessages = (TextView) rowView.findViewById(R.id.showprev_messages); TextView messageTime = (TextView) rowView.findViewById(R.id.message_time); final TextView icnMesajeTempo = (TextView) rowView.findViewById(R.id.icn_message_tempo); final View icnMensajeTempoDivider = (View) rowView.findViewById(R.id.icn_message_tempo_divider); final TextView icnMesajeCopy = (TextView) rowView.findViewById(R.id.icn_message_copy); final TextView icnMesajeBack = (TextView) rowView.findViewById(R.id.icn_message_back); TextView messageStatus = (TextView) rowView.findViewById(R.id.message_status); final LinearLayout messageMenu = (LinearLayout) rowView.findViewById(R.id.messages_menu_layout); final LinearLayout mensajeLayout = (LinearLayout) rowView.findViewById(R.id.mensaje_layout); TextView messageDate = (TextView) rowView.findViewById(R.id.message_date); TextView contactPhoto = (TextView) rowView.findViewById(R.id.contact_photo); TextView contactName = (TextView) rowView.findViewById(R.id.contact_name); final TextView contactPhone = (TextView) rowView.findViewById(R.id.contact_phone); TFCache.apply(context, messageTime, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, icnMesajeTempo, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeCopy, TFCache.TF_SPEAKALL); TFCache.apply(context, icnMesajeBack, TFCache.TF_SPEAKALL); TFCache.apply(context, messageStatus, TFCache.TF_SPEAKALL); TFCache.apply(context, contactPhoto, TFCache.TF_SPEAKALL); TFCache.apply(context, prevMessages, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, messageDate, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, contactName, TFCache.TF_WHITNEY_MEDIUM); TFCache.apply(context, contactPhone, TFCache.TF_WHITNEY_MEDIUM); try { JSONObject contactData = new JSONObject(message.mensaje); contactName.setText(contactData.getString("nombre")); contactPhone.setText(Html.fromHtml("<u>" + contactData.getString("telefono") + "</u>")); if (contactPhone.length() > 0) { contactPhone.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dontClose = true; ((MainActivity) activity).dontClose = true; hideKeyBoard(); Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + contactPhone.getText().toString())); context.startActivity(intent); } }); } } catch (JSONException e) { e.printStackTrace(); } if (position == 0) { if (mensajesTotal > mensajesOffset) { prevMessages.setVisibility(View.VISIBLE); prevMessages.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { prevMessages.setVisibility(View.GONE); if (mensajesTotal - mensajesOffset >= 10) { mensajesLimit = 10; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } else { mensajesLimit = mensajesTotal - mensajesOffset; mensajesOffset += mensajesLimit; showPreviousMessages(mensajesOffset); } } }); } } DateFormat dateDay = new SimpleDateFormat("d"); DateFormat dateDayText = new SimpleDateFormat("EEEE"); DateFormat dateMonth = new SimpleDateFormat("MMMM"); DateFormat dateYear = new SimpleDateFormat("yyyy"); DateFormat timeFormat = new SimpleDateFormat("h:mm a"); Calendar fechamsj = Calendar.getInstance(); fechamsj.setTimeInMillis(message.emitedAt); String time = timeFormat.format(fechamsj.getTime()); String dayMessage = dateDay.format(fechamsj.getTime()); String monthMessage = dateMonth.format(fechamsj.getTime()); String yearMessage = dateYear.format(fechamsj.getTime()); String dayMessageText = dateDayText.format(fechamsj.getTime()); char[] caracteres = dayMessageText.toCharArray(); caracteres[0] = Character.toUpperCase(caracteres[0]); dayMessageText = new String(caracteres); Calendar fechaActual = Calendar.getInstance(); String dayActual = dateDay.format(fechaActual.getTime()); String monthActual = dateMonth.format(fechaActual.getTime()); String yearActual = dateYear.format(fechaActual.getTime()); String fechaMostrar = ""; if (dayMessage.equals(dayActual) && monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { fechaMostrar = getString(R.string.messages_today); } else if (monthMessage.equals(monthActual) && yearMessage.equals(yearActual)) { int days = Integer.parseInt(dayActual) - Integer.parseInt(dayMessage); if (days < 7) { switch (days) { case 1: fechaMostrar = getString(R.string.messages_yesterday); break; default: fechaMostrar = dayMessageText; break; } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } } else { fechaMostrar = (dayMessage + " " + monthMessage + " " + yearMessage).toUpperCase(); } messageDate.setText(fechaMostrar); if (position != -1) { if (itemAnterior != null) { if (!fechaMostrar.equals(fechaAnterior)) { itemAnterior.findViewById(R.id.message_date).setVisibility(View.VISIBLE); } else { itemAnterior.findViewById(R.id.message_date).setVisibility(View.GONE); } } itemAnterior = rowView; fechaAnterior = fechaMostrar; } else { View v = messagesList.getChildAt(messagesList.getChildCount() - 1); if (v != null) { TextView tv = (TextView) v.findViewById(R.id.message_date); if (tv.getText().toString().equals(fechaMostrar)) { messageDate.setVisibility(View.GONE); } else { messageDate.setVisibility(View.VISIBLE); } } } messageTime.setText(time); if (message.emisor.equals(u.id)) { if (message.status != -1) { rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(30); Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (mensaje.status != 4) { icnMesajeTempo.setVisibility(View.VISIBLE); icnMensajeTempoDivider.setVisibility(View.VISIBLE); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeTempo, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeTempo, "translationX", 150, 0), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } else { icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", 100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", 50, 0)); set.setDuration(200).start(); } return false; } }); } if (message.status == 1) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setTextColor(getResources().getColor(R.color.speak_all_ligh_gray)); messageStatus.setText(Finder.STRING.ICN_MSJ_SENDING.toString()); ValueAnimator colorAnim = ObjectAnimator.ofFloat(messageStatus, "alpha", 1, 0); colorAnim.setRepeatCount(ValueAnimator.INFINITE); colorAnim.setRepeatMode(ValueAnimator.REVERSE); colorAnim.setDuration(1000).start(); animaciones.put(message.mensajeId, colorAnim); JSONObject data = new JSONObject(); try { data.put("message_id", message.mensajeId); data.put("source", message.emisor); data.put("source_email", message.emisorEmail); data.put("target_email", message.receptorEmail); data.put("target", message.receptor); data.put("message", message.mensaje); data.put("delay", message.delay); data.put("translation_required", message.translation); data.put("target_lang", message.receptorLang); data.put("type", message.tipo); } catch (JSONException e) { e.printStackTrace(); } if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { message.status = 1; SpeakSocket.mSocket.emit("message", data); } else { message.status = -1; } } if (message.status == -1) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_ERROR.toString()); } if (message.status == 3) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_CLOSED.toString()); } if (message.status == 2) { messageStatus.setTextSize(16); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_SEND.toString()); } if (message.status == 4) { messageStatus.setTextSize(11); mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getBackgroundColor(activity)); icnMessageArrow.setTextColor(BalloonFragment.getBackgroundColor(activity)); messageStatus.setText(Finder.STRING.ICN_MSJ_OPENED.toString()); icnMensajeTempoDivider.setVisibility(View.GONE); icnMesajeTempo.setVisibility(View.GONE); } else { icnMensajeTempoDivider.setVisibility(View.INVISIBLE); icnMesajeTempo.setVisibility(View.INVISIBLE); } icnMesajeTempo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { JSONObject notifyMessage = new JSONObject(); try { Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (mensaje.status != 4) { notifyMessage.put("type", mensaje.tipo); notifyMessage.put("message_id", mensaje.mensajeId); notifyMessage.put("source", mensaje.receptor); notifyMessage.put("target", mensaje.emisor); notifyMessage.put("status", 5); SpeakSocket.mSocket.emit("message-status", notifyMessage); } new Delete().from(Message.class).where("mensajeId = ?", mensaje.mensajeId).execute(); Message message = null; if (mensaje.emisor.equals(u.id)) { message = new Select().from(Message.class) .where("emisor = ? or receptor = ?", mensaje.receptor, mensaje.receptor) .orderBy("emitedAt DESC").executeSingle(); } else { message = new Select().from(Message.class) .where("emisor = ? or receptor = ?", mensaje.emisor, mensaje.emisor) .orderBy("emitedAt DESC").executeSingle(); } if (message != null) { Chats chat = null; if (mensaje.emisor.equals(u.id)) { chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.receptor) .executeSingle(); } else { chat = new Select().from(Chats.class).where("idContacto = ?", mensaje.emisor) .executeSingle(); } if (chat != null) { chat.mensajeId = message.mensajeId; chat.lastStatus = message.status; chat.emitedAt = message.emitedAt; chat.lang = message.emisorLang; chat.notRead = 0; if (chat.idContacto.equals(message.emisor)) chat.lastMessage = message.mensajeTrad; else chat.lastMessage = message.mensaje; chat.save(); } } else { if (mensaje.emisor.equals(u.id)) { new Delete().from(Chats.class).where("idContacto = ?", mensaje.receptor).execute(); } else { new Delete().from(Chats.class).where("idContacto = ?", mensaje.emisor).execute(); } } View delete = messagesList.findViewWithTag(mensaje.mensajeId); if (delete != null) messagesList.removeView(delete); messageSelected = null; ((MainActivity) activity).setOnBackPressedListener(null); } catch (JSONException e) { e.printStackTrace(); } } }); } else { mensajeLayout.setBackgroundResource(R.drawable.message_out_background); GradientDrawable drawable = (GradientDrawable) mensajeLayout.getBackground(); drawable.setCornerRadius(radius); drawable.setColor(BalloonFragment.getFriendBalloon(activity)); if (message.tipo == Integer.parseInt(getString(R.string.MSG_TYPE_BROADCAST_TEXT))) { messageStatus.setTextSize(15); messageStatus.setText(Finder.STRING.ICN_BROADCAST_FILL.toString()); } rowView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { if (messageSelected != null) { longclick = true; View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } else { messageSelected = message.mensajeId; ((MainActivity) activity).setOnBackPressedListener(new BackPressedListener(activity) { @Override public void doBack() { View vista = messagesList.findViewWithTag(messageSelected); vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } }); } Vibrator x = (Vibrator) activity.getApplicationContext() .getSystemService(Context.VIBRATOR_SERVICE); x.vibrate(20); icnMesajeTempo.setVisibility(View.GONE); icnMensajeTempoDivider.setVisibility(View.GONE); icnMesajeCopy.setVisibility(View.VISIBLE); icnMesajeBack.setVisibility(View.VISIBLE); messageMenu.setVisibility(View.VISIBLE); AnimatorSet set = new AnimatorSet(); set.playTogether(ObjectAnimator.ofFloat(icnMesajeCopy, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeBack, "alpha", 0, 1), ObjectAnimator.ofFloat(messageMenu, "alpha", 0, 1), ObjectAnimator.ofFloat(icnMesajeCopy, "translationX", -100, 0), ObjectAnimator.ofFloat(icnMesajeBack, "translationX", -150, 0)); set.setDuration(200).start(); longclick = true; return false; } }); icnMesajeTempo.setOnClickListener(new View.OnClickListener() { boolean translation = true; @Override public void onClick(View v) { translation = !translation; if (translation) { icnMesajeTempo.setTextColor(getResources().getColor(R.color.speak_all_red)); } else { icnMesajeTempo.setTextColor(getResources().getColor(R.color.speak_all_white)); } } }); } /*icnMesajeCopy.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ClipData clip = ClipData.newPlainText("text", messageContent.getText().toString()); ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE); clipboard.setPrimaryClip(clip); Toast.makeText(activity, "Copiado", Toast.LENGTH_SHORT).show(); } });*/ icnMesajeBack.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (message.emisor.equals(u.id)) { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensaje)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } else { getFragmentManager().beginTransaction() .replace(R.id.container2, ForwarForFragment.newInstance(message.mensajeTrad)) .addToBackStack(null).commit(); ((MainActivity) activity).setOnBackPressedListener(null); } } }); rowView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (messageSelected != null) { View vista = messagesList.findViewWithTag(messageSelected); if (!messageSelected.equals(message.mensajeId)) { longclick = true; vista.findViewById(messageMenu.getId()).setVisibility(View.INVISIBLE); ((MainActivity) activity).setOnBackPressedListener(null); messageSelected = null; } } Message mensaje = new Select().from(Message.class).where("mensajeId = ?", message.mensajeId) .executeSingle(); if (mensaje.status == -1) { String message = mensaje.mensaje; JSONObject data = new JSONObject(); try { data.put("message_id", mensaje.mensajeId); data.put("source", mensaje.emisor); data.put("source_email", mensaje.emisorEmail); data.put("target_email", mensaje.receptorEmail); data.put("target", mensaje.receptor); data.put("message", mensaje.mensaje); data.put("delay", mensaje.delay); data.put("type", mensaje.tipo); } catch (JSONException e) { e.printStackTrace(); } if (SpeakSocket.mSocket != null) if (SpeakSocket.mSocket.connected()) { mensaje.status = 1; SpeakSocket.mSocket.emit("message", data); } else { mensaje.status = -1; } mensaje.save(); changeStatus(mensaje.mensajeId, mensaje.status); } if (!mensaje.emisor.equals(u.id)) { if (!longclick) { showDialogAddContact(mensaje.mensaje); } longclick = false; } } }); }