Search in sources :

Example 41 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class RentalsStyleFragment method createView.

@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_materail_style, null);
    setHeaderTitle(R.string.ptr_demo_rentals_style);
    final CubeImageView imageView = (CubeImageView) view.findViewById(R.id.material_style_image_view);
    final ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
    final PtrFrameLayout frame = (PtrFrameLayout) view.findViewById(R.id.material_style_ptr_frame);
    // header
    final RentalsSunHeaderView header = new RentalsSunHeaderView(getContext());
    header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
    header.setPadding(0, LocalDisplay.dp2px(15), 0, LocalDisplay.dp2px(10));
    header.setUp(frame);
    frame.setLoadingMinTime(1000);
    frame.setDurationToCloseHeader(1500);
    frame.setHeaderView(header);
    frame.addPtrUIHandler(header);
    // frame.setPullToRefresh(true);
    frame.postDelayed(new Runnable() {

        @Override
        public void run() {
            frame.autoRefresh(true);
        }
    }, 100);
    frame.setPtrHandler(new PtrHandler() {

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return true;
        }

        @Override
        public void onRefreshBegin(final PtrFrameLayout frame) {
            if (mImageHasLoaded) {
                long delay = 1500;
                frame.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        frame.refreshComplete();
                    }
                }, delay);
            } else {
                mStartLoadingTime = System.currentTimeMillis();
                imageView.loadImage(imageLoader, mUrl);
            }
        }
    });
    ImageLoadHandler imageLoadHandler = new ImageLoadHandler() {

        @Override
        public void onLoading(ImageTask imageTask, CubeImageView cubeImageView) {
        }

        @Override
        public void onLoadFinish(ImageTask imageTask, final CubeImageView cubeImageView, final BitmapDrawable bitmapDrawable) {
            mImageHasLoaded = true;
            long delay = 1500;
            frame.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (cubeImageView != null && bitmapDrawable != null) {
                        TransitionDrawable w1 = new TransitionDrawable(new Drawable[] { new ColorDrawable(Color.WHITE), (Drawable) bitmapDrawable });
                        imageView.setImageDrawable(w1);
                        w1.startTransition(200);
                    }
                    frame.refreshComplete();
                }
            }, delay);
        }

        @Override
        public void onLoadError(ImageTask imageTask, CubeImageView cubeImageView, int i) {
        }
    };
    imageLoader.setImageLoadHandler(imageLoadHandler);
    return view;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) PtrHandler(in.srain.cube.views.ptr.PtrHandler) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ImageLoadHandler(in.srain.cube.image.iface.ImageLoadHandler) BitmapDrawable(android.graphics.drawable.BitmapDrawable) CubeImageView(in.srain.cube.image.CubeImageView) RentalsSunHeaderView(in.srain.cube.views.ptr.demo.ui.header.RentalsSunHeaderView) View(android.view.View) ColorDrawable(android.graphics.drawable.ColorDrawable) CubeImageView(in.srain.cube.image.CubeImageView) ImageTask(in.srain.cube.image.ImageTask) ImageLoader(in.srain.cube.image.ImageLoader) RentalsSunHeaderView(in.srain.cube.views.ptr.demo.ui.header.RentalsSunHeaderView)

Example 42 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class MaterialStyleFragment method createView.

@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_materail_style, null);
    setHeaderTitle(R.string.ptr_demo_material_style);
    final CubeImageView imageView = (CubeImageView) view.findViewById(R.id.material_style_image_view);
    final ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
    mPtrFrameLayout = (PtrFrameLayout) view.findViewById(R.id.material_style_ptr_frame);
    // header
    final MaterialHeader header = new MaterialHeader(getContext());
    int[] colors = getResources().getIntArray(R.array.google_colors);
    header.setColorSchemeColors(colors);
    header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
    header.setPadding(0, LocalDisplay.dp2px(15), 0, LocalDisplay.dp2px(10));
    header.setPtrFrameLayout(mPtrFrameLayout);
    mPtrFrameLayout.setLoadingMinTime(1000);
    mPtrFrameLayout.setDurationToCloseHeader(1500);
    mPtrFrameLayout.setHeaderView(header);
    mPtrFrameLayout.addPtrUIHandler(header);
    mPtrFrameLayout.postDelayed(new Runnable() {

        @Override
        public void run() {
            mPtrFrameLayout.autoRefresh(false);
        }
    }, 100);
    mPtrFrameLayout.setPtrHandler(new PtrHandler() {

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return true;
        }

        @Override
        public void onRefreshBegin(final PtrFrameLayout frame) {
            if (mImageHasLoaded) {
                long delay = (long) (1000 + Math.random() * 2000);
                delay = Math.max(0, delay);
                delay = 0;
                frame.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        frame.refreshComplete();
                    }
                }, delay);
            } else {
                mStartLoadingTime = System.currentTimeMillis();
                imageView.loadImage(imageLoader, mUrl);
            }
        }
    });
    ImageLoadHandler imageLoadHandler = new ImageLoadHandler() {

        @Override
        public void onLoading(ImageTask imageTask, CubeImageView cubeImageView) {
        }

        @Override
        public void onLoadFinish(ImageTask imageTask, final CubeImageView cubeImageView, final BitmapDrawable bitmapDrawable) {
            mImageHasLoaded = true;
            long delay = Math.max(0, 1000 - (System.currentTimeMillis() - mStartLoadingTime));
            delay = 0;
            mPtrFrameLayout.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (cubeImageView != null && bitmapDrawable != null) {
                        TransitionDrawable w1 = new TransitionDrawable(new Drawable[] { new ColorDrawable(Color.WHITE), (Drawable) bitmapDrawable });
                        imageView.setImageDrawable(w1);
                        w1.startTransition(200);
                    }
                    mPtrFrameLayout.refreshComplete();
                }
            }, delay);
        }

        @Override
        public void onLoadError(ImageTask imageTask, CubeImageView cubeImageView, int i) {
        }
    };
    imageLoader.setImageLoadHandler(imageLoadHandler);
    return view;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) PtrHandler(in.srain.cube.views.ptr.PtrHandler) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ImageLoadHandler(in.srain.cube.image.iface.ImageLoadHandler) BitmapDrawable(android.graphics.drawable.BitmapDrawable) CubeImageView(in.srain.cube.image.CubeImageView) View(android.view.View) MaterialHeader(in.srain.cube.views.ptr.header.MaterialHeader) ColorDrawable(android.graphics.drawable.ColorDrawable) CubeImageView(in.srain.cube.image.CubeImageView) ImageTask(in.srain.cube.image.ImageTask) ImageLoader(in.srain.cube.image.ImageLoader)

Example 43 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project cube-sdk by liaohuqiu.

the class DefaultImageLoadHandler method onLoadFinish.

@Override
public void onLoadFinish(ImageTask imageTask, CubeImageView imageView, BitmapDrawable drawable) {
    if (imageView == null) {
        return;
    }
    Drawable d = drawable;
    if (drawable != null) {
        if (mResizeImageViewAfterLoad) {
            int w = drawable.getBitmap().getWidth();
            int h = drawable.getBitmap().getHeight();
            if (w > 0 && h > 0) {
                ViewGroup.LayoutParams lyp = imageView.getLayoutParams();
                if (lyp != null) {
                    lyp.width = w;
                    lyp.height = h;
                    imageView.setLayoutParams(lyp);
                }
            }
        }
        // RoundedDrawable will not recycle automatically when API level is lower than 11
        if ((mDisplayTag & DISPLAY_ROUNDED) == DISPLAY_ROUNDED && Version.hasHoneycomb()) {
            d = new RoundedDrawable(drawable.getBitmap(), mCornerRadius);
        }
        if ((mDisplayTag & DISPLAY_FADE_IN) == DISPLAY_FADE_IN) {
            int loadingColor = android.R.color.transparent;
            if (mLoadingColor != -1 && (mDisplayTag & DISPLAY_ROUNDED) != DISPLAY_ROUNDED) {
                loadingColor = mLoadingColor;
            }
            final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(loadingColor), d });
            imageView.setImageDrawable(td);
            td.startTransition(200);
        } else {
            if (DEBUG) {
                Drawable oldDrawable = imageView.getDrawable();
                int w = 0, h = 0;
                if (oldDrawable != null) {
                    w = oldDrawable.getIntrinsicWidth();
                    h = oldDrawable.getIntrinsicHeight();
                }
                CLog.d(LOG_TAG, MSG_LOAD_FINISH, imageTask, imageView, w, h, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            }
            imageView.setImageDrawable(drawable);
        }
    }
}
Also used : RoundedDrawable(in.srain.cube.image.drawable.RoundedDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) ViewGroup(android.view.ViewGroup) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) RoundedDrawable(in.srain.cube.image.drawable.RoundedDrawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable)

Example 44 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project ARChon-Packager by bpear96.

the class activityInstalled method SelectedAPK.

public void SelectedAPK() throws IOException {
    //If user selects apk manually. Run this.
    String APKFilePath = g.getAPKPath();
    PackageManager pm = getPackageManager();
    PackageInfo pi = pm.getPackageArchiveInfo(APKFilePath, 0);
    // tell package info where app is located.
    pi.applicationInfo.sourceDir = APKFilePath;
    pi.applicationInfo.publicSourceDir = APKFilePath;
    String PackageName = pi.packageName;
    String AppName = (String) pi.applicationInfo.loadLabel(pm);
    g.setSelectedAppName(AppName);
    g.setPackageName(PackageName);
    Drawable icon = pi.applicationInfo.loadIcon(pm);
    Bitmap bmpIcon = ((BitmapDrawable) icon).getBitmap();
    //Make folders on phones storage
    setupFolders();
    // Extract icon
    String extStorageDirectory = Environment.getExternalStorageDirectory().toString() + "/ChromeAPKS/" + AppName + File.separator;
    OutputStream outStream = null;
    File file = new File(extStorageDirectory, "icon.png");
    try {
        outStream = new FileOutputStream(file);
        bmpIcon.compress(Bitmap.CompressFormat.PNG, 100, outStream);
        outStream.flush();
        outStream.close();
    } catch (Exception e) {
        Toast.makeText(activityInstalled.this, "Error: App Icon was not extracted.", Toast.LENGTH_LONG).show();
    }
    //Copy APK from selected source to ChromeAPKS location
    File apksource = new File(APKFilePath);
    File apkdst = new File(Environment.getExternalStorageDirectory().toString() + File.separator + "ChromeAPKS/" + AppName + "/vendor/chromium/crx/" + PackageName + ".apk");
    copy(apksource, apkdst);
    // End dialog activity to return to app wizard.
    finish();
//TODO: Cleanup leftover directories (Unzipped app directory, pulled app directory are not needed.)
}
Also used : Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) PackageInfo(android.content.pm.PackageInfo) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 45 with BitmapDrawable

use of android.graphics.drawable.BitmapDrawable in project ARChon-Packager by bpear96.

the class activityInstalled method pullAPk.

public void pullAPk() {
    //Pull APK from selected installed app. Uses PackageInfo and PackageManager.
    List<PackageInfo> PackList = getPackageManager().getInstalledPackages(0);
    PackageInfo PackInfo = PackList.get(SelectedAppId);
    if ((PackInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
        File org = new File(PackInfo.applicationInfo.publicSourceDir);
        String PackageNamePull = PackInfo.applicationInfo.packageName;
        g.setPackageName(PackageNamePull);
        //Setup directories.
        setupFolders();
        //Extract app icon to use with chrome.
        PackageManager pm = getPackageManager();
        Drawable icon = PackInfo.applicationInfo.loadIcon(pm);
        Bitmap bmpIcon = ((BitmapDrawable) icon).getBitmap();
        String extStorageDirectory = Environment.getExternalStorageDirectory().toString() + "/ChromeAPKS/" + SelectedAppName + File.separator;
        OutputStream outStream = null;
        File file = new File(extStorageDirectory, "icon.png");
        try {
            outStream = new FileOutputStream(file);
            bmpIcon.compress(Bitmap.CompressFormat.PNG, 100, outStream);
            outStream.flush();
            outStream.close();
        } catch (Exception e) {
            Toast.makeText(activityInstalled.this, "Error: APK not pulled.", Toast.LENGTH_LONG).show();
        }
        try {
            String file_name = PackInfo.applicationInfo.loadLabel(getPackageManager()).toString();
            Log.d("file_name--", " " + file_name);
            PackageName = PackInfo.applicationInfo.packageName;
            // make directory for pulled apks
            File apk = new File(Environment.getExternalStorageDirectory().toString() + "/ChromeAPKS/Pulled");
            apk.mkdirs();
            // Set pulled apk to its proper name
            apk = new File(apk.getPath() + "/" + file_name + ".apk");
            // Move APK
            apk.createNewFile();
            InputStream in = new FileInputStream(org);
            OutputStream out = new FileOutputStream(apk);
            byte[] buf = new byte[1024];
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
            System.out.println("File copied.");
        } catch (FileNotFoundException ex) {
            System.out.println(ex.getMessage() + " in the specified directory.");
        } catch (IOException e) {
            System.out.println(e.getMessage());
        }
        g.setAPKPath(Environment.getExternalStorageDirectory() + "/ChromeAPKS/Pulled/" + SelectedAppName + ".apk");
        File apksource = new File(Environment.getExternalStorageDirectory() + "/ChromeAPKS/Pulled/" + SelectedAppName + ".apk");
        File apkdst = new File(Environment.getExternalStorageDirectory().toString() + File.separator + "ChromeAPKS/" + SelectedAppName + "/vendor/chromium/crx/" + PackageName + ".apk");
        try {
            copy(apksource, apkdst);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    //Finish activity dialog to return to main wizard.
    finish();
}
Also used : PackageInfo(android.content.pm.PackageInfo) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) FileNotFoundException(java.io.FileNotFoundException) BitmapDrawable(android.graphics.drawable.BitmapDrawable) IOException(java.io.IOException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) FileInputStream(java.io.FileInputStream) Bitmap(android.graphics.Bitmap) PackageManager(android.content.pm.PackageManager) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

BitmapDrawable (android.graphics.drawable.BitmapDrawable)640 Bitmap (android.graphics.Bitmap)426 Drawable (android.graphics.drawable.Drawable)187 Canvas (android.graphics.Canvas)182 Paint (android.graphics.Paint)110 Rect (android.graphics.Rect)77 View (android.view.View)77 ImageView (android.widget.ImageView)63 ColorDrawable (android.graphics.drawable.ColorDrawable)59 TextView (android.widget.TextView)51 IOException (java.io.IOException)40 Resources (android.content.res.Resources)35 LayerDrawable (android.graphics.drawable.LayerDrawable)33 AnimationDrawable (android.graphics.drawable.AnimationDrawable)30 File (java.io.File)27 Test (org.junit.Test)24 Matrix (android.graphics.Matrix)23 Intent (android.content.Intent)22 StateListDrawable (android.graphics.drawable.StateListDrawable)22 InputStream (java.io.InputStream)22