Android Open Source - okulus Rounded Rectangles Fragment






From Project

Back to project page okulus.

License

The source code is released under:

Apache License

If you think the Android project okulus 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

package com.vinaysshenoy.okulusdemo.fragments;
//from  ww  w . j  ava  2 s  .  com
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.vinaysshenoy.okulus.OkulusImageView;
import com.vinaysshenoy.okulusdemo.R;
import com.vinaysshenoy.okulusdemo.utils.RawBitmapManager;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by vinay.shenoy on 24/07/14.
 */
public class RoundedRectanglesFragment extends Fragment {

    private static final int[] ITEMS = new int[]{
            R.raw.img_1,
            R.raw.img_2,
            R.raw.img_3,
            R.raw.img_4,
            R.raw.img_5,
            R.raw.img_6
    };

    private OkulusImageView mImageView1;
    private OkulusImageView mImageView2;
    private OkulusImageView mImageView3;
    private OkulusImageView mImageView4;
    private OkulusImageView mImageView5;
    private OkulusImageView mImageView6;


    private ExecutorService mPool;
    private Handler mHandler = new Handler(Looper.getMainLooper());

    private boolean mPaused;

    @Override
    public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) {

        mPool = Executors.newSingleThreadExecutor();
        final View content = inflater.inflate(R.layout.fragment_rounded_rectangles, container, false);

        mImageView1 = (OkulusImageView) content.findViewById(R.id.image_1);
        mImageView2 = (OkulusImageView) content.findViewById(R.id.image_2);
        mImageView3 = (OkulusImageView) content.findViewById(R.id.image_3);
        mImageView4 = (OkulusImageView) content.findViewById(R.id.image_4);
        mImageView5 = (OkulusImageView) content.findViewById(R.id.image_5);
        mImageView6 = (OkulusImageView) content.findViewById(R.id.image_6);


        //loadBitmaps();

        return content;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        Drawable drawable = new ColorDrawable(Color.RED);
        mImageView1.setImageDrawable(drawable);
        Uri uri = Uri.parse("android.resource://com.vinaysshenoy.okulusdemo/" + R.drawable.img_for_uri);
        mImageView2.setImageURI(uri);

        mImageView3.setImageResource(R.drawable.img_res);
        loadBitmaps();
    }

    private void loadBitmaps() {

        mPool.submit(new LoadBitmapRunnable(mImageView4, R.raw.img_4, 256, 128));
        mPool.submit(new LoadBitmapRunnable(mImageView5, R.raw.img_5, 128, 256));
        mPool.submit(new LoadBitmapRunnable(mImageView6, R.raw.img_6, 256, 128));

    }

    @Override
    public void onPause() {
        super.onPause();
        mPool.shutdownNow();
        mPaused = true;
    }

    @Override
    public void onResume() {
        super.onResume();
        mPaused = false;
    }

    private class LoadBitmapRunnable implements Runnable {

        private int mResourceId;
        private int mTargetWidth, mTargetHeight;
        private OkulusImageView mImageView;

        public LoadBitmapRunnable(OkulusImageView imageView, int resourceId, int targetWidth, int targetheight) {

            mImageView = imageView;
            mResourceId = resourceId;
            mTargetWidth = targetWidth;
            mTargetHeight = targetheight;
        }

        @Override
        public void run() {

            final Bitmap bitmap = RawBitmapManager.INSTANCE.getBitmap(
                    mImageView.getContext(),
                    mResourceId,
                    mTargetWidth,
                    mTargetHeight);

            if (!mPaused && bitmap != null) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        mImageView.setImageBitmap(bitmap);
                    }
                });
            }
        }
    }
}




Java Source Code List

com.android.volley.AuthFailureError.java
com.android.volley.CacheDispatcher.java
com.android.volley.Cache.java
com.android.volley.DefaultRetryPolicy.java
com.android.volley.ExecutorDelivery.java
com.android.volley.NetworkDispatcher.java
com.android.volley.NetworkError.java
com.android.volley.NetworkResponse.java
com.android.volley.Network.java
com.android.volley.NoConnectionError.java
com.android.volley.ParseError.java
com.android.volley.RequestQueue.java
com.android.volley.Request.java
com.android.volley.ResponseDelivery.java
com.android.volley.Response.java
com.android.volley.RetryPolicy.java
com.android.volley.ServerError.java
com.android.volley.TimeoutError.java
com.android.volley.VolleyError.java
com.android.volley.VolleyLog.java
com.android.volley.toolbox.AndroidAuthenticator.java
com.android.volley.toolbox.Authenticator.java
com.android.volley.toolbox.BasicNetwork.java
com.android.volley.toolbox.ByteArrayPool.java
com.android.volley.toolbox.ClearCacheRequest.java
com.android.volley.toolbox.DiskBasedCache.java
com.android.volley.toolbox.HttpClientStack.java
com.android.volley.toolbox.HttpHeaderParser.java
com.android.volley.toolbox.HttpStack.java
com.android.volley.toolbox.HurlStack.java
com.android.volley.toolbox.ImageLoader.java
com.android.volley.toolbox.ImageRequest.java
com.android.volley.toolbox.JsonArrayRequest.java
com.android.volley.toolbox.JsonObjectRequest.java
com.android.volley.toolbox.JsonRequest.java
com.android.volley.toolbox.NetworkImageView.java
com.android.volley.toolbox.NoCache.java
com.android.volley.toolbox.PoolingByteArrayOutputStream.java
com.android.volley.toolbox.RequestFuture.java
com.android.volley.toolbox.StringRequest.java
com.android.volley.toolbox.Volley.java
com.vinaysshenoy.okulus.OkulusDrawable.java
com.vinaysshenoy.okulus.OkulusImageView.java
com.vinaysshenoy.okulusdemo.DemoApplication.java
com.vinaysshenoy.okulusdemo.MainActivity.java
com.vinaysshenoy.okulusdemo.fragments.NetworkFragment.java
com.vinaysshenoy.okulusdemo.fragments.RoundedRectanglesFragment.java
com.vinaysshenoy.okulusdemo.utils.RawBitmapManager.java