Android Open Source - Reader Circle Transform






From Project

Back to project page Reader.

License

The source code is released under:

GNU General Public License

If you think the Android project Reader 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 2014 Julian Shen/*from  w ww  . jav  a 2  s  .  co m*/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.carlrice.reader.utils;


import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;

import com.squareup.picasso.Transformation;

public class CircleTransform implements Transformation {
    @Override
    public Bitmap transform(Bitmap source) {
        int size = Math.min(source.getWidth(), source.getHeight());

        Bitmap circleBitmap;
        try {
            circleBitmap = Bitmap.createBitmap(size, size, source.getConfig());
        } catch (Exception ignored) {
            return source;
        }

        int x = (source.getWidth() - size) / 2;
        int y = (source.getHeight() - size) / 2;
        Bitmap squaredBitmap = Bitmap.createBitmap(source, x, y, size, size);
        if (squaredBitmap != source) {
            source.recycle();
        }

        Canvas canvas = new Canvas(circleBitmap);
        Paint paint = new Paint();
        BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP);
        paint.setShader(shader);
        paint.setAntiAlias(true);

        float r = size / 2f;
        canvas.drawCircle(r, r, r, paint);

        squaredBitmap.recycle();
        return circleBitmap;
    }

    @Override
    public String key() {
        return "circle";
    }
}




Java Source Code List

com.carlrice.reader.Application.java
com.carlrice.reader.Constants.java
com.carlrice.reader.activity.AboutActivity.java
com.carlrice.reader.activity.AddGoogleNewsActivity.java
com.carlrice.reader.activity.BaseActivity.java
com.carlrice.reader.activity.EditFeedActivity.java
com.carlrice.reader.activity.EditFeedsListActivity.java
com.carlrice.reader.activity.EntryActivity.java
com.carlrice.reader.activity.GeneralPrefsActivity.java
com.carlrice.reader.activity.HomeActivity.java
com.carlrice.reader.adapter.CursorLoaderExpandableListAdapter.java
com.carlrice.reader.adapter.DrawerAdapter.java
com.carlrice.reader.adapter.EntriesCursorAdapter.java
com.carlrice.reader.adapter.FeedsCursorAdapter.java
com.carlrice.reader.adapter.FiltersCursorAdapter.java
com.carlrice.reader.fragment.EditFeedsListFragment.java
com.carlrice.reader.fragment.EntriesListFragment.java
com.carlrice.reader.fragment.EntryFragment.java
com.carlrice.reader.fragment.GeneralPrefsFragment.java
com.carlrice.reader.fragment.SwipeRefreshFragment.java
com.carlrice.reader.fragment.SwipeRefreshListFragment.java
com.carlrice.reader.loader.BaseLoader.java
com.carlrice.reader.parser.OPML.java
com.carlrice.reader.parser.RssAtomParser.java
com.carlrice.reader.provider.DatabaseHelper.java
com.carlrice.reader.provider.FeedDataContentProvider.java
com.carlrice.reader.provider.FeedData.java
com.carlrice.reader.receiver.BootCompletedBroadcastReceiver.java
com.carlrice.reader.receiver.ConnectionChangeReceiver.java
com.carlrice.reader.service.FetcherService.java
com.carlrice.reader.service.RefreshService.java
com.carlrice.reader.utils.ArticleTextExtractor.java
com.carlrice.reader.utils.CircleTransform.java
com.carlrice.reader.utils.FileUtils.java
com.carlrice.reader.utils.HtmlUtils.java
com.carlrice.reader.utils.NetworkUtils.java
com.carlrice.reader.utils.PrefUtils.java
com.carlrice.reader.utils.StringUtils.java
com.carlrice.reader.utils.ThrottledContentObserver.java
com.carlrice.reader.utils.UiUtils.java
com.carlrice.reader.view.AutoSummaryListPreference.java
com.carlrice.reader.view.BakedBezierInterpolator.java
com.carlrice.reader.view.DragNDropExpandableListView.java
com.carlrice.reader.view.DragNDropListener.java
com.carlrice.reader.view.EntryView.java
com.carlrice.reader.view.SwipeProgressBar.java
com.carlrice.reader.view.SwipeRefreshLayout.java
com.carlrice.reader.widget.ColorPickerDialogPreference.java
com.carlrice.reader.widget.TickerWidgetProvider.java
com.carlrice.reader.widget.TickerWidgetService.java
com.carlrice.reader.widget.WidgetConfigActivity.java
com.carlrice.reader.widget.WidgetConfigFragment.java
com.carlrice.reader.widget.WidgetProvider.java
com.carlrice.reader.widget.WidgetService.java