Android Open Source - RSSReader Delete Drop Zone View






From Project

Back to project page RSSReader.

License

The source code is released under:

?????? ????? ?????? ?????? ?????????? ????????? 1.?????? ???????? ??????? ??????? ????? ?????? ????? ?????????...

If you think the Android project RSSReader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Copyright 2012/*from w w  w  . j  a v a2  s  .  c  o m*/
 *
 * Nicolas Desjardins
 * https://github.com/mrKlar
 *
 * Facilite solutions
 * http://www.facilitesolutions.com/
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package ca.laplanete.mobile.pageddragdropgrid;

import com.example.draggridview.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.LightingColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.view.View;

public class DeleteDropZoneView extends View {

  private Paint textPaintStraight;
  private Paint textPaintRed;
  private Paint bitmapPaint;
  private Paint bitmapPaintRed;
  private boolean straight = true;

  private Bitmap trash;
  private Rect bounds;

  public DeleteDropZoneView(Context context) {
    super(context);

    bounds = new Rect();

    textPaintStraight = createTextPaint();
    textPaintStraight.setColor(Color.WHITE);

    textPaintRed = createTextPaint();
    textPaintRed.setColor(Color.RED);

    bitmapPaint = createBaseBitmapPaint();

    bitmapPaintRed = createBaseBitmapPaint();
    ColorFilter filter = new LightingColorFilter(Color.RED, 1);
    bitmapPaintRed.setColorFilter(filter);

    setBackgroundColor(Color.BLACK);
    getBackground().setAlpha(200);
  }

  private Paint createTextPaint() {
    Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setStyle(Style.FILL);
    textPaint.setTextAlign(Paint.Align.CENTER);
    textPaint.setTypeface(Typeface.DEFAULT_BOLD);
    return textPaint;
  }

  private Paint createBaseBitmapPaint() {
    Paint bitmapPaint = new Paint();
    bitmapPaint.setAntiAlias(true);
    bitmapPaint.setFilterBitmap(true);
    bitmapPaint.setDither(true);
    return bitmapPaint;
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    int measuredHeight = getMeasuredHeight();
    int measuredWidth = getMeasuredWidth();
    String removeString = getResources()
        .getString(R.string.action_settings);

    initTrashIcon();

    textPaintStraight.getTextBounds(removeString, 0, 6, bounds);

    int proportion = 3 * measuredHeight / 4;
    if (straight) {
      textPaintStraight.setTextSize(proportion);
      canvas.drawText(removeString,
          (measuredWidth / 2) + (trash.getWidth() / 2) + 5,
          measuredHeight - ((measuredHeight - bounds.height()) / 2),
          textPaintStraight);
      canvas.drawBitmap(trash, (measuredWidth / 2) - (bounds.width() / 2)
          - (trash.getWidth() / 2) - 10, 0, bitmapPaint);
    } else {
      textPaintRed.setTextSize(proportion);
      canvas.drawText(removeString,
          (measuredWidth / 2) + (trash.getWidth() / 2) + 5,
          measuredHeight - ((measuredHeight - bounds.height()) / 2),
          textPaintRed);
      canvas.drawBitmap(trash, (measuredWidth / 2) - (bounds.width() / 2)
          - (trash.getWidth() / 2) - 10, 0, bitmapPaintRed);
    }
  }

  private void initTrashIcon() {
    if (trash == null) {
      trash = getImage(R.drawable.circuit, getMeasuredHeight(),
          getMeasuredHeight());
      
    }
  }

  public void highlight() {
    straight = false;
    invalidate();
  }

  public void smother() {
    straight = true;
    invalidate();
  }

  private Bitmap getImage(int id, int width, int height) {
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), id);
    Bitmap img = Bitmap.createScaledBitmap(bmp, width, height, true);
    if (bmp != null && !isInEditMode()) {
      bmp.recycle();
    }
    invalidate();
    return img;
  }

}




Java Source Code List

ca.laplanete.mobile.example.ExampleActivity.java
ca.laplanete.mobile.example.ExamplePagedDragDropGridAdapter.java
ca.laplanete.mobile.example.Item.java
ca.laplanete.mobile.example.Page.java
ca.laplanete.mobile.pageddragdropgrid.DeleteDropZoneView.java
ca.laplanete.mobile.pageddragdropgrid.DragDropGrid.java
ca.laplanete.mobile.pageddragdropgrid.ItemsSource.java
ca.laplanete.mobile.pageddragdropgrid.OnPageChangedListener.java
ca.laplanete.mobile.pageddragdropgrid.PagedContainer.java
ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGridAdapter.java
ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGrid.java
net.uyghurdev.avaroid.rssreader.About.java
net.uyghurdev.avaroid.rssreader.AddFeedActivity.java
net.uyghurdev.avaroid.rssreader.Configs.java
net.uyghurdev.avaroid.rssreader.ContentActivity.java
net.uyghurdev.avaroid.rssreader.CustomAlertDialog.java
net.uyghurdev.avaroid.rssreader.EditFeedActivity.java
net.uyghurdev.avaroid.rssreader.ImageLoader.java
net.uyghurdev.avaroid.rssreader.ItemAdapter.java
net.uyghurdev.avaroid.rssreader.ItemListActivity.java
net.uyghurdev.avaroid.rssreader.Item.java
net.uyghurdev.avaroid.rssreader.LItem.java
net.uyghurdev.avaroid.rssreader.RSSReaderActivity.java
net.uyghurdev.avaroid.rssreader.SettingsActivity.java
net.uyghurdev.avaroid.rssreader.SplashActivity.java
net.uyghurdev.avaroid.rssreader.SuggestedFeedsActivity.java
net.uyghurdev.avaroid.rssreader.data.DataHelper_.java
net.uyghurdev.avaroid.rssreader.data.FeedData.java
net.uyghurdev.avaroid.rssreader.data.OpenHelper.java
net.uyghurdev.avaroid.rssreader.operator.FeedParser.java
net.uyghurdev.avaroid.rssreader.operator.Feed.java
net.uyghurdev.avaroid.rssreader.operator.FeedsAdapter.java
net.uyghurdev.avaroid.rssreader.operator.JSONManager.java
net.uyghurdev.avaroid.rssreader.operator.NetworkOperator.java
net.uyghurdev.avaroid.rssreader.service.AlarmReceiver.java
net.uyghurdev.avaroid.rssreader.service.UpdateService.java
net.uyghurdev.avaroid.rssreader.tools.FileCache.java
net.uyghurdev.avaroid.rssreader.tools.Helper.java
net.uyghurdev.avaroid.rssreader.tools.MemoryCache.java
net.uyghurdev.avaroid.rssreader.tools.UIManager.java
net.uyghurdev.avaroid.rssreader.tools.Utils.java