Example usage for android.graphics Bitmap recycle

List of usage examples for android.graphics Bitmap recycle

Introduction

In this page you can find the example usage for android.graphics Bitmap recycle.

Prototype

public void recycle() 

Source Link

Document

Free the native object associated with this bitmap, and clear the reference to the pixel data.

Usage

From source file:com.undatech.opaque.RemoteCanvas.java

public void disconnectAndCleanUp() {
    stayConnected = false;//from w  ww .  ja v a  2 s  .c  o  m

    if (keyboard != null) {
        // Tell the server to release any meta keys.
        keyboard.clearOnScreenMetaState();
        keyboard.keyEvent(0, new KeyEvent(KeyEvent.ACTION_UP, 0));
    }

    if (spicecomm != null)
        spicecomm.close();

    if (handler != null) {
        handler.removeCallbacksAndMessages(null);
    }

    if (clipboardMonitorTimer != null) {
        clipboardMonitorTimer.cancel();
        // Occasionally causes a NullPointerException
        //clipboardMonitorTimer.purge();
        clipboardMonitorTimer = null;
    }

    clipboardMonitor = null;
    clipboard = null;

    try {
        if (myDrawable != null && myDrawable.bitmap != null) {
            String location = settings.getFilename();
            FileOutputStream out = new FileOutputStream(getContext().getFilesDir() + "/" + location + ".png");
            Bitmap tmp = Bitmap.createScaledBitmap(myDrawable.bitmap, 360, 300, true);
            myDrawable.bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
            out.close();
            tmp.recycle();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    disposeDrawable();
}

From source file:cn.jmessage.android.uikit.pickerimage.view.BaseZoomableImageView.java

@SuppressLint("NewApi")
public void setImageBitmap(final Bitmap bitmap, final boolean fitScreen) {

    //???/*from  w  w  w  . j  a  va2s.  co m*/
    if (Build.VERSION.SDK_INT >= MIN_SDK_ENABLE_LAYER_TYPE_HARDWARE) {
        if (bitmap != null && (bitmap.getHeight() > SampleSizeUtil.getTextureSize()
                || bitmap.getWidth() > SampleSizeUtil.getTextureSize())) {
            setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        } else {
            setLayerType(View.LAYER_TYPE_HARDWARE, null);
        }
    }

    final int viewWidth = getWidth();
    if (viewWidth <= 0) {
        mOnLayoutRunnable = new Runnable() {
            public void run() {
                setImageBitmap(bitmap, fitScreen);
            }
        };
        return;
    }

    Bitmap oldBitmap = this.mBitmap;
    if (bitmap != null) {
        setBaseMatrix(bitmap, mBaseMatrix);
        this.mBitmap = bitmap;
    } else {
        mBaseMatrix.reset();
        this.mBitmap = bitmap;
    }
    if (oldBitmap != null && oldBitmap != mBitmap && !oldBitmap.isRecycled()) {
        oldBitmap.recycle();
    }

    mSuppMatrix.reset();
    setImageMatrix(getImageViewMatrix());
    mMaxZoom = maxZoom();

    // Set the image to fit the screen
    if (fitScreen) {
        zoomToScreen();
    }
}

From source file:com.irccloud.android.activity.UploadsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (ColorFormatter.file_uri_template != null)
        template = UriTemplate.fromTemplate(ColorFormatter.file_uri_template);
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                cloud, 0xFFF2F7FC));//from   w  w w  . ja  va 2  s .  com
        cloud.recycle();
    }

    if (Build.VERSION.SDK_INT >= 14) {
        try {
            java.io.File httpCacheDir = new java.io.File(getCacheDir(), "http");
            long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
            HttpResponseCache.install(httpCacheDir, httpCacheSize);
        } catch (IOException e) {
            Log.i("IRCCloud", "HTTP response cache installation failed:" + e);
        }
    }
    setContentView(R.layout.ignorelist);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));
        getSupportActionBar().setElevation(0);
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("cid")) {
        cid = savedInstanceState.getInt("cid");
        to = savedInstanceState.getString("to");
        msg = savedInstanceState.getString("msg");
        page = savedInstanceState.getInt("page");
        File[] files = (File[]) savedInstanceState.getSerializable("adapter");
        for (File f : files) {
            adapter.addFile(f);
        }
        adapter.notifyDataSetChanged();
    }

    footer = getLayoutInflater().inflate(R.layout.messageview_header, null);
    ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(adapter);
    listView.addFooterView(footer);
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (canLoadMore && firstVisibleItem + visibleItemCount > totalItemCount - 4) {
                canLoadMore = false;
                new FetchFilesTask().execute((Void) null);
            }
        }
    });
    listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            final File f = (File) adapter.getItem(i);

            AlertDialog.Builder builder = new AlertDialog.Builder(UploadsActivity.this);
            builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);
            final View v = getLayoutInflater().inflate(R.layout.dialog_upload, null);
            final EditText messageinput = (EditText) v.findViewById(R.id.message);
            messageinput.setText(msg);
            final ImageView thumbnail = (ImageView) v.findViewById(R.id.thumbnail);

            v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (messageinput.hasFocus()) {
                        v.post(new Runnable() {
                            @Override
                            public void run() {
                                v.scrollTo(0, v.getBottom());
                            }
                        });
                    }
                }
            });

            if (f.mime_type.startsWith("image/")) {
                try {
                    thumbnail.setImageBitmap(f.image);
                    thumbnail.setVisibility(View.VISIBLE);
                    thumbnail.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent i = new Intent(UploadsActivity.this, ImageViewerActivity.class);
                            i.setData(Uri.parse(f.url));
                            startActivity(i);
                        }
                    });
                    thumbnail.setClickable(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                thumbnail.setVisibility(View.GONE);
            }

            ((TextView) v.findViewById(R.id.filesize)).setText(f.metadata);
            v.findViewById(R.id.filename).setVisibility(View.GONE);
            v.findViewById(R.id.filename_heading).setVisibility(View.GONE);

            builder.setTitle("Send A File To " + to);
            builder.setView(v);
            builder.setPositiveButton("Send", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String message = messageinput.getText().toString();
                    if (message.length() > 0)
                        message += " ";
                    message += f.url;

                    dialog.dismiss();
                    if (getParent() == null) {
                        setResult(Activity.RESULT_OK);
                    } else {
                        getParent().setResult(Activity.RESULT_OK);
                    }
                    finish();

                    NetworkConnection.getInstance().say(cid, to, message);
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog d = builder.create();
            d.setOwnerActivity(UploadsActivity.this);
            d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
            d.show();
        }
    });
}

From source file:io.mapsquare.osmcontributor.utils.core.ArpiInitializer.java

/**
 * Pre-compute the different PoiTypes bitmaps icons for the ArpiGL fragment and view.
 *///from   w w  w.  ja v a 2 s. com
public void precomputeArpiBitmaps() {
    try {
        if (!ArpiGlInstaller.getInstance(application.getApplicationContext()).isInstalled()) {
            ArpiGlInstaller.getInstance(application.getApplicationContext()).install();

            Map<Long, PoiType> poiTypes = poiManager.loadPoiTypes();

            for (Map.Entry<Long, PoiType> entry : poiTypes.entrySet()) {
                Integer id = bitmapHandler.getIconDrawableId(entry.getValue());
                if (id != null && id > 0) {
                    Drawable d = application.getApplicationContext().getResources().getDrawableForDensity(id,
                            DisplayMetrics.DENSITY_XXHIGH);
                    int width = d.getIntrinsicWidth();
                    int height = d.getIntrinsicHeight();
                    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
                    Canvas c = new Canvas(bitmap);
                    d.setBounds(0, 0, width, height);
                    d.draw(c);

                    File dest = new File(application.getApplicationContext().getFilesDir(),
                            ArpiGlInstaller.INSTALLATION_DIR + "/" + ArpiGlInstaller.TEXTURE_ICONS_SUBDIR + "/"
                                    + entry.getValue().getIcon() + ".png");
                    dest.getParentFile().mkdirs();

                    if (dest.exists()) {
                        dest.delete();
                    }
                    dest.createNewFile();
                    OutputStream stream = new FileOutputStream(dest);
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                    stream.close();
                    bitmap.recycle();
                }
            }
        }
    } catch (IOException | JSONException e) {
        Timber.e("Error while initializing ArpiGl library: {}", e.getMessage());
    }
}

From source file:com.luyaozhou.recognizethisforglass.ViewFinder.java

private void processPictureWhenReady(final String picturePath) {
    final File pictureFile = new File(picturePath);
    //Map<String, String > result = new HashMap<String,String>();

    if (pictureFile.exists()) {
        // The picture is ready; process it.
        Bitmap imageBitmap = null;
        try {/*w ww . j  a  v  a  2s .c o  m*/
            //               Bundle extras = data.getExtras();
            //               imageBitmap = (Bitmap) extras.get("data");
            FileInputStream fis = new FileInputStream(picturePath); //get the bitmap from file
            imageBitmap = (Bitmap) BitmapFactory.decodeStream(fis);

            if (imageBitmap != null) {
                Bitmap lScaledBitmap = Bitmap.createScaledBitmap(imageBitmap, 1600, 1200, false);
                if (lScaledBitmap != null) {
                    imageBitmap.recycle();
                    imageBitmap = null;

                    ByteArrayOutputStream lImageBytes = new ByteArrayOutputStream();
                    lScaledBitmap.compress(Bitmap.CompressFormat.JPEG, 30, lImageBytes);
                    lScaledBitmap.recycle();
                    lScaledBitmap = null;

                    byte[] lImageByteArray = lImageBytes.toByteArray();

                    HashMap<String, String> lValuePairs = new HashMap<String, String>();
                    lValuePairs.put("base64Image", Base64.encodeToString(lImageByteArray, Base64.DEFAULT));
                    lValuePairs.put("compressionLevel", "30");
                    lValuePairs.put("documentIdentifier", "DRIVER_LICENSE_CA");
                    lValuePairs.put("documentHints", "");
                    lValuePairs.put("dataReturnLevel", "15");
                    lValuePairs.put("returnImageType", "1");
                    lValuePairs.put("rotateImage", "0");
                    lValuePairs.put("data1", "");
                    lValuePairs.put("data2", "");
                    lValuePairs.put("data3", "");
                    lValuePairs.put("data4", "");
                    lValuePairs.put("data5", "");
                    lValuePairs.put("userName", "zbroyan@miteksystems.com");
                    lValuePairs.put("password", "google1");
                    lValuePairs.put("phoneKey", "1");
                    lValuePairs.put("orgName", "MobileImagingOrg");

                    String lSoapMsg = formatSOAPMessage("InsertPhoneTransaction", lValuePairs);

                    DefaultHttpClient mHttpClient = new DefaultHttpClient();
                    //                        mHttpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.R)
                    HttpPost mHttpPost = new HttpPost();

                    mHttpPost.setHeader("User-Agent", "UCSD Team");
                    mHttpPost.setHeader("Content-typURIe", "text/xml;charset=UTF-8");
                    //mHttpPost.setURI(URI.create("https://mi1.miteksystems.com/mobileimaging/ImagingPhoneService.asmx?op=InsertPhoneTransaction"));
                    mHttpPost.setURI(
                            URI.create("https://mi1.miteksystems.com/mobileimaging/ImagingPhoneService.asmx"));

                    StringEntity se = new StringEntity(lSoapMsg, HTTP.UTF_8);
                    se.setContentType("text/xml; charset=UTF-8");
                    mHttpPost.setEntity(se);
                    HttpResponse mResponse = mHttpClient.execute(mHttpPost, new BasicHttpContext());

                    String responseString = new BasicResponseHandler().handleResponse(mResponse);
                    parseXML(responseString);

                    //Todo: this is test code. Need to be implemented
                    //result = parseXML(testStr);
                    Log.i("test", "test:" + " " + responseString);
                    Log.i("test", "test: " + " " + map.size());

                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        // this part will be relocated in order to let the the server process picture
        if (map.size() == 0) {
            Intent display = new Intent(getApplicationContext(), DisplayInfoFailed.class);
            display.putExtra("result", (java.io.Serializable) iQAMsg);
            startActivity(display);
        } else {
            Intent display = new Intent(getApplicationContext(), DisplayInfo.class);
            display.putExtra("result", (java.io.Serializable) map);
            startActivity(display);

        }
    } else {
        // The file does not exist yet. Before starting the file observer, you
        // can update your UI to let the user know that the application is
        // waiting for the picture (for example, by displaying the thumbnail
        // image and a progress indicator).

        final File parentDirectory = pictureFile.getParentFile();
        FileObserver observer = new FileObserver(parentDirectory.getPath(),
                FileObserver.CLOSE_WRITE | FileObserver.MOVED_TO) {
            // Protect against additional pending events after CLOSE_WRITE
            // or MOVED_TO is handled.
            private boolean isFileWritten;

            @Override
            public void onEvent(int event, final String path) {
                if (!isFileWritten) {
                    // For safety, make sure that the file that was created in
                    // the directory is actually the one that we're expecting.
                    File affectedFile = new File(parentDirectory, path);
                    isFileWritten = affectedFile.equals(pictureFile);

                    if (isFileWritten) {
                        stopWatching();
                        // Now that the file is ready, recursively call
                        // processPictureWhenReady again (on the UI thread).
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                new LongOperation().execute(picturePath);
                            }
                        });
                    }
                }
            }
        };
        observer.startWatching();

    }

}

From source file:com.bamobile.fdtks.util.Tools.java

public static Bitmap resizeBitmap(Bitmap bitmap, int width, int height) {
    int scaledWidth = bitmap.getWidth();
    int scaledHeight = bitmap.getHeight();

    if (scaledWidth < scaledHeight) {
        float scale = width / (float) scaledWidth;

        scaledWidth = width;/*from   w w w.  ja  v  a2s . c om*/
        scaledHeight = (int) Math.ceil(scaledHeight * scale);
        if (scaledHeight < height) {
            scale = height / (float) scaledHeight;

            scaledHeight = height;
            scaledWidth = (int) Math.ceil(scaledWidth * scale);
        }
    } else {
        float scale = height / (float) scaledHeight;

        scaledHeight = height;
        scaledWidth = (int) Math.ceil(scaledWidth * scale);

        if (scaledWidth < width) {
            scale = width / (float) scaledWidth;

            scaledWidth = width;
            scaledHeight = (int) Math.ceil(scaledHeight * scale);
        }
    }

    Bitmap bmp = Bitmap.createScaledBitmap(bitmap, scaledWidth, scaledHeight, false);

    bitmap.recycle();
    bitmap = null;

    return bmp;
}

From source file:com.letsdoitworld.wastemapper.utils.ImageDownloader.java

public Bitmap rezise(Bitmap bitmapOrg) {

    int width = bitmapOrg.getWidth();
    int height = bitmapOrg.getHeight();
    int newWidth = 320;
    int newHeight = 240;
    // calculate the scale
    float scaleWidth = ((float) newWidth) / width;
    float scaleHeight = ((float) newHeight) / height;
    // create a matrix for the manipulation
    Matrix matrix = new Matrix();
    // resize the bit map
    matrix.postScale(scaleWidth, scaleHeight);
    Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true);
    // make a Drawable from Bitmap to allow to set the BitMap

    bitmapOrg.recycle();

    return resizedBitmap;
}

From source file:com.ryan.ryanreader.fragments.ImageViewFragment.java

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

    final Context context = inflater.getContext();

    final LoadingView loadingView = new LoadingView(context, R.string.download_loading, true, false);

    final LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(loadingView);//from w  w  w. ja v  a2s .  com

    CacheManager.getInstance(context)
            .makeRequest(new CacheRequest(url, RedditAccountManager.getAnon(), null,
                    Constants.Priority.IMAGE_VIEW, 0, CacheRequest.DownloadType.IF_NECESSARY,
                    Constants.FileType.IMAGE, false, false, false, context) {

                private void setContentView(View v) {
                    layout.removeAllViews();
                    layout.addView(v);
                    v.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
                    v.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
                }

                @Override
                protected void onCallbackException(Throwable t) {
                    BugReportActivity.handleGlobalError(context.getApplicationContext(),
                            new RRError(null, null, t));
                }

                @Override
                protected void onDownloadNecessary() {
                    loadingView.setIndeterminate(R.string.download_waiting);
                }

                @Override
                protected void onDownloadStarted() {
                    loadingView.setIndeterminate(R.string.download_downloading);
                }

                @Override
                protected void onFailure(final RequestFailureType type, Throwable t, StatusLine status,
                        final String readableMessage) {

                    loadingView.setDone(R.string.download_failed);
                    final RRError error = General.getGeneralErrorForFailure(context, type, t, status);

                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        public void run() {
                            // TODO handle properly
                            layout.addView(new ErrorView(getSupportActivity(), error));
                        }
                    });
                }

                @Override
                protected void onProgress(long bytesRead, long totalBytes) {
                    loadingView.setProgress(R.string.download_downloading,
                            (float) ((double) bytesRead / (double) totalBytes));
                }

                @Override
                protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp,
                        UUID session, boolean fromCache, final String mimetype) {

                    if (mimetype == null || !Constants.Mime.isImage(mimetype)) {
                        revertToWeb();
                        return;
                    }

                    if (Constants.Mime.isImageGif(mimetype)) {

                        try {

                            gifThread = new GifDecoderThread(cacheFile.getInputStream(),
                                    new GifDecoderThread.OnGifLoadedListener() {

                                        public void onGifLoaded() {
                                            new Handler(Looper.getMainLooper()).post(new Runnable() {
                                                public void run() {
                                                    imageView = new ImageView(context);
                                                    imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
                                                    setContentView(imageView);
                                                    gifThread.setView(imageView);

                                                    imageView.setOnClickListener(new View.OnClickListener() {
                                                        public void onClick(View v) {
                                                            getSupportActivity().finish();
                                                        }
                                                    });
                                                }
                                            });
                                        }

                                        public void onOutOfMemory() {
                                            General.quickToast(context, R.string.imageview_oom);
                                            revertToWeb();
                                        }

                                        public void onGifInvalid() {
                                            General.quickToast(context, R.string.imageview_invalid_gif);
                                            revertToWeb();
                                        }
                                    });

                            gifThread.start();

                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }

                    } else {

                        final Bitmap finalResult;

                        try {

                            final int maxTextureSize = 2048;
                            final Bitmap imageOrig = BitmapFactory.decodeStream(cacheFile.getInputStream());

                            if (imageOrig == null) {
                                General.quickToast(context,
                                        "Couldn't load the image. Trying internal browser.");
                                revertToWeb();
                                return;
                            }

                            final int maxDim = Math.max(imageOrig.getWidth(), imageOrig.getHeight());

                            if (maxDim > maxTextureSize) {

                                imageOrig.recycle();

                                final double scaleFactorPowerOfTwo = Math
                                        .log((double) maxDim / (double) maxTextureSize) / Math.log(2);
                                final int scaleFactor = (int) Math
                                        .round(Math.pow(2, Math.ceil(scaleFactorPowerOfTwo)));

                                final BitmapFactory.Options options = new BitmapFactory.Options();
                                options.inSampleSize = scaleFactor;
                                finalResult = BitmapFactory.decodeStream(cacheFile.getInputStream(), null,
                                        options);
                            } else {
                                finalResult = imageOrig;
                            }

                        } catch (IOException e) {
                            throw new RuntimeException(e);

                        } catch (OutOfMemoryError e) {
                            General.quickToast(context, "Out of memory. Trying internal browser.");
                            revertToWeb();
                            return;
                        }

                        new Handler(Looper.getMainLooper()).post(new Runnable() {
                            public void run() {
                                imageView = new GestureImageView(context);
                                imageView.setImageBitmap(finalResult);
                                imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                                setContentView(imageView);

                                imageView.setOnClickListener(new View.OnClickListener() {
                                    public void onClick(View v) {
                                        getSupportActivity().finish();
                                    }
                                });
                            }
                        });
                    }
                }
            });

    final RedditPost src_post = getArguments().getParcelable("post");
    final RedditPreparedPost post = src_post == null ? null
            : new RedditPreparedPost(context, CacheManager.getInstance(context), 0, src_post, -1, false,
                    new RedditSubreddit("/r/" + src_post.subreddit, src_post.subreddit, false), false, false,
                    false, RedditAccountManager.getInstance(context).getDefaultAccount());

    final FrameLayout outerFrame = new FrameLayout(context);
    outerFrame.addView(layout);

    if (post != null) {

        final SideToolbarOverlay toolbarOverlay = new SideToolbarOverlay(context);

        final BezelSwipeOverlay bezelOverlay = new BezelSwipeOverlay(context,
                new BezelSwipeOverlay.BezelSwipeListener() {

                    public boolean onSwipe(BezelSwipeOverlay.SwipeEdge edge) {

                        toolbarOverlay.setContents(
                                post.generateToolbar(context, ImageViewFragment.this, toolbarOverlay));
                        toolbarOverlay.show(edge == BezelSwipeOverlay.SwipeEdge.LEFT
                                ? SideToolbarOverlay.SideToolbarPosition.LEFT
                                : SideToolbarOverlay.SideToolbarPosition.RIGHT);
                        return true;
                    }

                    public boolean onTap() {

                        if (toolbarOverlay.isShown()) {
                            toolbarOverlay.hide();
                            return true;
                        }

                        return false;
                    }
                });

        outerFrame.addView(bezelOverlay);
        outerFrame.addView(toolbarOverlay);

        bezelOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        bezelOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

        toolbarOverlay.getLayoutParams().width = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;
        toolbarOverlay.getLayoutParams().height = android.widget.FrameLayout.LayoutParams.MATCH_PARENT;

    }

    return outerFrame;
}

From source file:com.irccloud.android.activity.PreferencesActivity.java

@SuppressWarnings("deprecation")
@Override/*from   w  w  w.j  av a2 s .c  o  m*/
public void onCreate(Bundle icicle) {
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    super.onCreate(icicle);
    getDelegate().installViewFactory();
    getDelegate().onCreate(icicle);
    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                cloud, 0xFFF2F7FC));
        cloud.recycle();
    }
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.actionbar_prefs);

    Toolbar toolbar = (Toolbar) findViewById(R.id.actionbar);
    toolbar.setTitle(getTitle());
    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    toolbar.setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));

    if (Build.VERSION.SDK_INT >= 21)
        toolbar.setElevation(0);

    conn = NetworkConnection.getInstance();
    addPreferencesFromResource(R.xml.preferences_account);
    addPreferencesFromResource(R.xml.preferences_display);
    addPreferencesFromResource(R.xml.preferences_device);
    addPreferencesFromResource(R.xml.preferences_photos);
    addPreferencesFromResource(R.xml.preferences_notifications);
    addPreferencesFromResource(R.xml.preferences_dashclock);
    findPreference("dashclock_showmsgs").setOnPreferenceChangeListener(dashclocktoggle);
    try {
        int pebbleVersion = getPackageManager().getPackageInfo("com.getpebble.android", 0).versionCode;
        if (pebbleVersion < 553)
            addPreferencesFromResource(R.xml.preferences_pebble);
    } catch (Exception e) {
    }
    boolean foundSony = false;
    try {
        getPackageManager().getPackageInfo("com.sonyericsson.extras.liveware", 0);
        addPreferencesFromResource(R.xml.preferences_sony);
        foundSony = true;
    } catch (Exception e) {
    }
    if (!foundSony) {
        try {
            getPackageManager().getPackageInfo("com.sonyericsson.extras.smartwatch", 0);
            addPreferencesFromResource(R.xml.preferences_sony);
            foundSony = true;
        } catch (Exception e) {
        }
    }
    if (!foundSony) {
        try {
            getPackageManager().getPackageInfo("com.sonyericsson.extras.liveview", 0);
            addPreferencesFromResource(R.xml.preferences_sony);
            foundSony = true;
        } catch (Exception e) {
        }
    }
    if (foundSony)
        findPreference("notify_sony").setOnPreferenceChangeListener(sonytoggle);
    if (BuildConfig.DEBUG)
        addPreferencesFromResource(R.xml.preferences_debug);
    addPreferencesFromResource(R.xml.preferences_about);
    findPreference("name").setOnPreferenceChangeListener(settingstoggle);

    findPreference("autoaway").setOnPreferenceChangeListener(settingstoggle);
    findPreference("time-24hr").setOnPreferenceChangeListener(prefstoggle);
    findPreference("time-seconds").setOnPreferenceChangeListener(prefstoggle);
    findPreference("mode-showsymbol").setOnPreferenceChangeListener(prefstoggle);
    findPreference("pastebin-disableprompt").setOnPreferenceChangeListener(prefstoggle);
    if (findPreference("emoji-disableconvert") != null) {
        findPreference("emoji-disableconvert").setOnPreferenceChangeListener(prefstoggle);
        findPreference("emoji-disableconvert").setSummary(":thumbsup:  \uD83D\uDC4D");
    }
    findPreference("nick-colors").setOnPreferenceChangeListener(prefstoggle);
    findPreference("faq").setOnPreferenceClickListener(urlClick);
    findPreference("feedback").setOnPreferenceClickListener(urlClick);
    findPreference("licenses").setOnPreferenceClickListener(licensesClick);
    findPreference("imageviewer").setOnPreferenceChangeListener(imageviewertoggle);
    findPreference("imgur_account_username").setOnPreferenceClickListener(imgurClick);
    //findPreference("subscriptions").setOnPreferenceClickListener(urlClick);
    //findPreference("changes").setOnPreferenceClickListener(urlClick);
    findPreference("notify_type").setOnPreferenceChangeListener(notificationstoggle);
    findPreference("notify_led_color").setOnPreferenceChangeListener(ledtoggle);
    findPreference("photo_size").setOnPreferenceChangeListener(photosizetoggle);

    imgurPreference = findPreference("imgur_account_username");
    if (NetworkConnection.getInstance().uploadsAvailable()) {
        if (!PreferenceManager.getDefaultSharedPreferences(this).getString("image_service", "IRCCloud")
                .equals("imgur")) {
            PreferenceCategory c = (PreferenceCategory) findPreference("photos");
            c.removePreference(imgurPreference);
        }
        findPreference("image_service").setOnPreferenceChangeListener(imageservicetoggle);
    } else {
        PreferenceCategory c = (PreferenceCategory) findPreference("photos");
        c.removePreference(findPreference("image_service"));
    }

    try {
        final String version = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
        findPreference("version").setSummary(version);
        findPreference("version").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
            @Override
            public boolean onPreferenceClick(Preference preference) {
                if (Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
                    android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                            CLIPBOARD_SERVICE);
                    clipboard.setText(version);
                } else {
                    @SuppressLint("ServiceCast")
                    android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                            CLIPBOARD_SERVICE);
                    android.content.ClipData clip = android.content.ClipData.newPlainText("IRCCloud Version",
                            version);
                    clipboard.setPrimaryClip(clip);
                }
                Toast.makeText(PreferencesActivity.this, "Version number copied to clipboard",
                        Toast.LENGTH_SHORT).show();
                return false;
            }
        });
    } catch (NameNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.xgf.inspection.qrcode.google.zxing.client.CaptureActivity.java

private void clearBitmap() {
    for (Bitmap bitmap : mBitmapList) {
        bitmap.recycle();
    }
    mBitmapList.clear();
}