Example usage for android.os StrictMode setVmPolicy

List of usage examples for android.os StrictMode setVmPolicy

Introduction

In this page you can find the example usage for android.os StrictMode setVmPolicy.

Prototype

public static void setVmPolicy(final VmPolicy policy) 

Source Link

Document

Sets the policy for what actions in the VM process (on any thread) should be detected, as well as the penalty if such actions occur.

Usage

From source file:com.fbbackup.FriendAlbumList.java

@SuppressLint("NewApi")
@Override//from  w  w w  . j a v  a 2 s . co m
public void onCreate(Bundle savedInstanceState) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        StrictMode.setThreadPolicy(
                new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or
                        // .detectAll()
                        // for
                        // all
                        // detectable
                        // problems
                        .penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());

    }

    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);

    extStorageDirectory = Environment.getExternalStorageDirectory().toString();

    Log.w("fbtest", extStorageDirectory);

    mImageThumbSize = getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size);
    mImageThumbSpacing = getResources().getDimensionPixelSize(R.dimen.image_thumbnail_spacing);

    facebook = new Facebook("134348190059034");

    albumArray = getArguments().getStringArray("albumArray");

    albumCoverArray = getArguments().getStringArray("albumCoverArray");

    albumCoverUrlArray = getArguments().getStringArray("albumCoverUrlArray");

    albumNameArray = getArguments().getStringArray("albumNameArray");

    albumPhotoAccountArray = getArguments().getStringArray("albumPhotoAccountArray");

    token = getArguments().getString("token");

    name = getArguments().getString("userName");

    Log.w("fbtest", "first token:" + token);

    mAdapter = new ImageAdapter(getActivity());

    imageLoader = new ImageLoader(getActivity());

    getAlbumCoverUrl();

    ImageCacheParams cacheParams = new ImageCacheParams(getActivity(), IMAGE_CACHE_DIR);

    cacheParams.setMemCacheSizePercent(0.25f); // Set memory cache to 25% of
    // app memory

    // The ImageFetcher takes care of loading images into our ImageView
    // children asynchronously
    mImageFetcher = new ImageFetcher(getActivity(), mImageThumbSize);
    mImageFetcher.setLoadingImage(R.drawable.ic_launcher);
    mImageFetcher.addImageCache(getActivity().getSupportFragmentManager(), cacheParams);

    MyFriendFragmentActivity.controlPanelHandler.sendEmptyMessage(MyFriendFragmentActivity.HIDE_CONTROL_PANEL);
}

From source file:com.sythealth.fitness.util.Utils.java

@TargetApi(11)
public static void enableStrictMode() {
    if (Utils.hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll()
                .penaltyLog();/*w w w  .ja  v a2s . com*/
        StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog();

        if (Utils.hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
            // vmPolicyBuilder
            // .setClassInstanceLimit(DailyArtWorkActivity.class, 1)
            // .setClassInstanceLimit(ImageDetailActivity.class, 1);
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}

From source file:org.fdroid.fdroid.FDroidApp.java

@TargetApi(9)
@Override/* w  w w.  j av a2s. c  o m*/
public void onCreate() {
    super.onCreate();
    if (Build.VERSION.SDK_INT >= 9 && BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
    }
    updateLanguage();
    ACRA.init(this);

    // Needs to be setup before anything else tries to access it.
    // Perhaps the constructor is a better place, but then again,
    // it is more deterministic as to when this gets called...
    Preferences.setup(this);
    curTheme = Preferences.get().getTheme();

    // Apply the Google PRNG fixes to properly seed SecureRandom
    PRNGFixes.apply();

    // Check that the installed app cache hasn't gotten out of sync somehow.
    // e.g. if we crashed/ran out of battery half way through responding
    // to a package installed intent. It doesn't really matter where
    // we put this in the bootstrap process, because it runs on a different
    // thread, which will be delayed by some seconds to avoid an error where
    // the database is locked due to the database updater.
    InstalledAppCacheUpdater.updateInBackground(getApplicationContext());

    // make sure the current proxy stuff is configured
    Preferences.get().configureProxy();

    // If the user changes the preference to do with filtering rooted apps,
    // it is easier to just notify a change in the app provider,
    // so that the newly updated list will correctly filter relevant apps.
    Preferences.get().registerAppsRequiringRootChangeListener(new Preferences.ChangeListener() {
        @Override
        public void onPreferenceChange() {
            getContentResolver().notifyChange(AppProvider.getContentUri(), null);
        }
    });

    // This is added so that the bluetooth:// scheme we use for URLs the BluetoothDownloader
    // understands is not treated as invalid by the java.net.URL class. The actual Handler does
    // nothing, but its presence is enough.
    URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
        @Override
        public URLStreamHandler createURLStreamHandler(String protocol) {
            return TextUtils.equals(protocol, "bluetooth") ? new Handler() : null;
        }
    });

    final Context context = this;
    Preferences.get().registerUnstableUpdatesChangeListener(new Preferences.ChangeListener() {
        @Override
        public void onPreferenceChange() {
            AppProvider.Helper.calcDetailsFromIndex(context);
        }
    });

    // Clear cached apk files. We used to just remove them after they'd
    // been installed, but this causes problems for proprietary gapps
    // users since the introduction of verification (on pre-4.2 Android),
    // because the install intent says it's finished when it hasn't.
    if (!Preferences.get().shouldCacheApks()) {
        Utils.deleteFiles(Utils.getApkCacheDir(this), null, ".apk");
    }

    // Index files which downloaded, but were not removed (e.g. due to F-Droid being force
    // closed during processing of the file, before getting a chance to delete). This may
    // include both "index-*-downloaded" and "index-*-extracted.xml" files. The first is from
    // either signed or unsigned repos, and the later is from signed repos.
    Utils.deleteFiles(getCacheDir(), "index-", null);

    // As above, but for legacy F-Droid clients that downloaded under a different name, and
    // extracted to the files directory rather than the cache directory.
    // TODO: This can be removed in a a few months or a year (e.g. 2016) because people will
    // have upgraded their clients, this code will have executed, and they will not have any
    // left over files any more. Even if they do hold off upgrading until this code is removed,
    // the only side effect is that they will have a few more MiB of storage taken up on their
    // device until they uninstall and re-install F-Droid.
    Utils.deleteFiles(getCacheDir(), "dl-", null);
    Utils.deleteFiles(getFilesDir(), "index-", null);

    UpdateService.schedule(getApplicationContext());
    bluetoothAdapter = getBluetoothAdapter();

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
            .imageDownloader(new IconDownloader(getApplicationContext()))
            .diskCache(new LimitedAgeDiskCache(
                    new File(StorageUtils.getCacheDirectory(getApplicationContext(), true), "icons"), null,
                    new FileNameGenerator() {
                        @Override
                        public String generate(String imageUri) {
                            return imageUri.substring(imageUri.lastIndexOf('/') + 1);
                        }
                    },
                    // 30 days in secs: 30*24*60*60 = 2592000
                    2592000))
            .threadPoolSize(4).threadPriority(Thread.NORM_PRIORITY - 2) // Default is NORM_PRIORITY - 1
            .build();
    ImageLoader.getInstance().init(config);

    // TODO reintroduce PinningTrustManager and MemorizingTrustManager

    // initialized the local repo information
    FDroidApp.initWifiSettings();
    startService(new Intent(this, WifiStateChangeService.class));
    // if the HTTPS pref changes, then update all affected things
    Preferences.get().registerLocalRepoHttpsListeners(new ChangeListener() {
        @Override
        public void onPreferenceChange() {
            startService(new Intent(FDroidApp.this, WifiStateChangeService.class));
        }
    });

    configureTor(Preferences.get().isTorEnabled());
}

From source file:com.jtechme.apphub.FDroidApp.java

@TargetApi(9)
@Override//ww  w. ja v a 2s. co m
public void onCreate() {
    if (Build.VERSION.SDK_INT >= 9 && BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
    }
    updateLanguage();
    super.onCreate();
    ACRA.init(this);

    // Needs to be setup before anything else tries to access it.
    // Perhaps the constructor is a better place, but then again,
    // it is more deterministic as to when this gets called...
    Preferences.setup(this);

    // Apply the Google PRNG fixes to properly seed SecureRandom
    PRNGFixes.apply();

    // Check that the installed app cache hasn't gotten out of sync somehow.
    // e.g. if we crashed/ran out of battery half way through responding
    // to a package installed intent. It doesn't really matter where
    // we put this in the bootstrap process, because it runs on a different
    // thread, which will be delayed by some seconds to avoid an error where
    // the database is locked due to the database updater.
    InstalledAppCacheUpdater.updateInBackground(getApplicationContext());

    // If the user changes the preference to do with filtering rooted apps,
    // it is easier to just notify a change in the app provider,
    // so that the newly updated list will correctly filter relevant apps.
    Preferences.get().registerAppsRequiringRootChangeListener(new Preferences.ChangeListener() {
        @Override
        public void onPreferenceChange() {
            getContentResolver().notifyChange(AppProvider.getContentUri(), null);
        }
    });

    // This is added so that the bluetooth:// scheme we use for URLs the BluetoothDownloader
    // understands is not treated as invalid by the java.net.URL class. The actual Handler does
    // nothing, but its presence is enough.
    URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() {
        @Override
        public URLStreamHandler createURLStreamHandler(String protocol) {
            return TextUtils.equals(protocol, "bluetooth") ? new Handler() : null;
        }
    });

    final Context context = this;
    Preferences.get().registerUnstableUpdatesChangeListener(new Preferences.ChangeListener() {
        @Override
        public void onPreferenceChange() {
            AppProvider.Helper.calcDetailsFromIndex(context);
        }
    });

    // Clear cached apk files. We used to just remove them after they'd
    // been installed, but this causes problems for proprietary gapps
    // users since the introduction of verification (on pre-4.2 Android),
    // because the install intent says it's finished when it hasn't.
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    curTheme = Theme.valueOf(prefs.getString(Preferences.PREF_THEME, Preferences.DEFAULT_THEME));
    Utils.deleteFiles(Utils.getApkDownloadDir(this), null, ".apk");
    if (!Preferences.get().shouldCacheApks()) {
        Utils.deleteFiles(Utils.getApkCacheDir(this), null, ".apk");
    }

    // Index files which downloaded, but were not removed (e.g. due to F-Droid being force
    // closed during processing of the file, before getting a chance to delete). This may
    // include both "index-*-downloaded" and "index-*-extracted.xml" files. The first is from
    // either signed or unsigned repos, and the later is from signed repos.
    Utils.deleteFiles(getCacheDir(), "index-", null);

    // As above, but for legacy F-Droid clients that downloaded under a different name, and
    // extracted to the files directory rather than the cache directory.
    // TODO: This can be removed in a a few months or a year (e.g. 2016) because people will
    // have upgraded their clients, this code will have executed, and they will not have any
    // left over files any more. Even if they do hold off upgrading until this code is removed,
    // the only side effect is that they will have a few more MiB of storage taken up on their
    // device until they uninstall and re-install F-Droid.
    Utils.deleteFiles(getCacheDir(), "dl-", null);
    Utils.deleteFiles(getFilesDir(), "index-", null);

    UpdateService.schedule(getApplicationContext());
    bluetoothAdapter = getBluetoothAdapter();

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
            .imageDownloader(new IconDownloader(getApplicationContext()))
            .diskCache(new LimitedAgeDiskCache(
                    new File(StorageUtils.getCacheDirectory(getApplicationContext(), true), "icons"), null,
                    new FileNameGenerator() {
                        @Override
                        public String generate(String imageUri) {
                            return imageUri.substring(imageUri.lastIndexOf('/') + 1);
                        }
                    },
                    // 30 days in secs: 30*24*60*60 = 2592000
                    2592000))
            .threadPoolSize(4).threadPriority(Thread.NORM_PRIORITY - 2) // Default is NORM_PRIORITY - 1
            .build();
    ImageLoader.getInstance().init(config);

    // TODO reintroduce PinningTrustManager and MemorizingTrustManager

    // initialized the local repo information
    FDroidApp.initWifiSettings();
    startService(new Intent(this, WifiStateChangeService.class));
    // if the HTTPS pref changes, then update all affected things
    Preferences.get().registerLocalRepoHttpsListeners(new ChangeListener() {
        @Override
        public void onPreferenceChange() {
            startService(new Intent(FDroidApp.this, WifiStateChangeService.class));
        }
    });
}

From source file:net.wespot.pim.view.InqImageDetailFragment.java

public static void enableStrictMode(InqImageDetailFragment context) {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().penaltyLog().build());
}

From source file:com.justone.android.main.MainActivity.java

@SuppressWarnings("deprecation")
@Override// w  w w.  ja  v  a 2s. c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    currentContext = this;
    //listviewview
    this.viewMap = new HashMap<String, ListViewAdapter>();
    //
    this.asynImageLoader = JustOne.getAsynImageLoader();
    this.dataOp = JustOne.getDataOp();

    //
    this.res = getResources(); // Resource object to get Drawables  

    // 
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());

    justOne = (JustOne) getApplication();
    justOne.pushActivity(this);
    // view
    LayoutInflater inflater = LayoutInflater.from(this);
    //details_page_setitem = inflater.inflate(R.layout.one_details_page_setitem, null);
    main_item = inflater.inflate(R.layout.activity_main, null);
    bind_item = inflater.inflate(R.layout.one_details_page_binditem, null);
    about_one = inflater.inflate(R.layout.about_one, null);
    //microblog = inflater.inflate(R.layout.one_details_page_microblog, null);

    feedback = inflater.inflate(R.layout.feedback, null);

    setContentView(main_item);

    initData();

    // view
    mListView = (ListView) findViewById(R.id.tab2);
    //ArrayList<ArrayList<String>> list_data = loadData("list",data);
    listAdapter = new ListViewAdapter(this, mList, mGist, R.id.scrollview, R.layout.list_item);

    mListView.setAdapter(listAdapter);

    /*
    mListView1 = (ListView) findViewById(R.id.tab1);
            
    //ArrayList<ArrayList<String>> collect_data = loadData("collect",data);
    collectAdapter = new ListViewAdapter(this,mList,
    mGist, R.id.collectScrollview,
    R.layout.collect_item);
            
    mListView1.setAdapter(collectAdapter);
    */
    homeListView = (ListView) findViewById(R.id.homeTab);
    homeAdapter = new ListViewAdapter(this, mList, mGist, R.id.homeScrollView, R.layout.home_item);

    homeListView.setAdapter(homeAdapter);

    qaListView = (ListView) findViewById(R.id.QAtab);

    //ArrayList<ArrayList<String>> QA_data = loadData("QA",data);
    QAAdapter = new ListViewAdapter(this, mList, mGist, R.id.qaScrollView, R.layout.qa_item);

    qaListView.setAdapter(QAAdapter);

    //detailView = (ListView) findViewById(R.id.tab3);

    //ArrayList<ArrayList<String>> detail_data = loadData("detail",data);
    //detailAdapter = new ListViewAdapter(this,
    //      mList, mGist,
    //      R.id.detailScrollView, R.layout.detail_item);

    //detailView.setAdapter(detailAdapter);

    /*//loading list view 
    loadingView = (ListView) findViewById(R.id.loading_view);
            
    //ArrayList<ArrayList<String>> detail_data = loadData("detail",data);
    loadingAdapter = new ListViewAdapter(this,
    mList, mGist,
    R.id.loadingScrollView, R.layout.one_welcome_ad);
            
    loadingView.setAdapter(loadingAdapter);
            
    */

    tabs = (TabHost) findViewById(R.id.tabhost);
    tabWidget = (TabWidget) findViewById(android.R.id.tabs);
    int width = 100;
    int height = 100;
    tabs.setup();
    tabs.addTab(tabs.newTabSpec("home tab").setIndicator("", this.res.getDrawable(R.drawable.home_tab_selector))
            .setContent(R.id.homeTab));
    tabs.addTab(tabs.newTabSpec("list tab").setIndicator("", this.res.getDrawable(R.drawable.one_tab_selector))
            .setContent(R.id.tab2));
    tabs.addTab(tabs.newTabSpec("QA Tab").setIndicator("", this.res.getDrawable(R.drawable.qa_tab_selector))
            .setContent(R.id.QAtab));

    /*
    tabs.addTab(tabs.newTabSpec("second tab").setIndicator("", null)
    .setContent(R.id.tab1));*/
    //tabs.addTab(tabs.newTabSpec("second tab").setIndicator("",this.res.getDrawable(R.drawable.more_tab_selector))
    //      .setContent(R.id.tab3));

    tabs.setCurrentTab(0);
    for (int i = 0; i < tabWidget.getChildCount(); i++) {
        /**
         * fill_parent
         */
        tabWidget.getChildAt(i).getLayoutParams().height = height;
        tabWidget.getChildAt(i).getLayoutParams().width = width;

        /**
         * tab
         */
        final TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title);
        tv.setTextColor(this.getResources().getColorStateList(android.R.color.white));
        tv.setTextSize(15);
        tv.setGravity(Gravity.TOP);
    }
    mActivityName = getString(R.string.activity_c_label);
    mStatusTracker.setStatus(mActivityName, getString(R.string.on_create));
    Utils.printStatus(mStatusView, mStatusAllView);
    detector = new GestureDetector(this);
    viewMap.put("home", this.homeAdapter);

    //
    View returnBackToIndex = main_item.findViewById(R.id.returnBackToIndex_layout);
    returnBackToIndex.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            MainActivity.this.finish();
            // TODO Auto-generated method stub

        }
    });

    userFirstTips();

}

From source file:com.hplasplas.cam_capture.activitys.CamCapture.java

private void setVmPolicyIfNeed() {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        StrictMode.setVmPolicy(builder.build());
    }/*from  ww w  .  j  ava  2 s . co m*/
}

From source file:org.opensilk.music.MusicApp.java

protected void enableStrictMode() {
    if (DEBUG) {//from   ww  w  .java  2s  . c o m
        final StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder()
                .detectAll().penaltyLog().penaltyFlashScreen();
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());

        final StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog().setClassInstanceLimit(MediaCastManager.class, 1)
                .setClassInstanceLimit(BitmapDiskLruCache.class, 1)
                .setClassInstanceLimit(ArtworkLruCache.class, 1)
                .setClassInstanceLimit(LauncherActivity.class, 1)
                .setClassInstanceLimit(ArtworkRequestManagerImpl.class, 1);
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}

From source file:com.rnd.snapsplit.view.OcrCaptureFragment.java

/**
 * Initializes the UI and creates the detector pipeline.
 *//*  ww  w .  ja va 2s.  c  o  m*/
//    @Override
//    public void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//
//        if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
//            Toast.makeText(getContext(), "pic saved", Toast.LENGTH_LONG).show();
//            Log.d("CameraDemo", "Pic saved");
//        }
//    }

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

    final View view = inflater.inflate(R.layout.view_ocr_capture, container, false);
    final Activity activity = getActivity();
    final Context context = getContext();

    ((Toolbar) activity.findViewById(R.id.tool_bar_hamburger))
            .setBackgroundColor(ContextCompat.getColor(context, android.R.color.transparent));
    final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
            + "/picFolder/";
    File newdir = new File(dir);
    newdir.mkdirs();

    mPreview = (CameraSourcePreview) view.findViewById(R.id.preview);
    mGraphicOverlay = (GraphicOverlay<OcrGraphic>) view.findViewById(R.id.graphicOverlay);

    StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
    StrictMode.setVmPolicy(builder.build());

    // Set good defaults for capturing text.
    boolean autoFocus = true;
    boolean useFlash = false;

    //        createNewThread();
    //        t.start();

    final ImageView upArrow = (ImageView) view.findViewById(R.id.arrow_up);
    upArrow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (rotationAngle == 0) { // arrow up
                //mCameraSource.takePicture(null, mPicture);
                //mGraphicOverlay.clear();
                //                    mGraphicOverlay.clear();
                //                    mGraphicOverlay.amountItem = null;
                onPause();
                //shouldContinue = false;
                //mCamera.takePicture(null, null, mPicture);

                File pictureFile = getOutputMediaFile();
                if (pictureFile == null) {
                    return;
                }
                try {
                    FileOutputStream fos = new FileOutputStream(pictureFile);
                    Bitmap receiptBitmap = byteStreamToBitmap(mCameraSource.mostRecentBitmap);
                    receiptBitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos);
                    picPath = pictureFile.getAbsolutePath();
                    //fos.write(mCameraSource.mostRecentBitmap);
                    fos.close();
                } catch (FileNotFoundException e) {

                } catch (IOException e) {
                }

                upArrow.animate().rotation(180).setDuration(500).start();

                TextView amount = (TextView) view.findViewById(R.id.text_amount_value);
                if (mGraphicOverlay.amountItem == null) {
                    amount.setText("0.00");
                } else {
                    amount.setText(String.format("%.2f", mGraphicOverlay.amountItemAfterFormat));
                }
                TextView desc = (TextView) view.findViewById(R.id.text_name_value);
                desc.setText(mGraphicOverlay.description);

                RelativeLayout box = (RelativeLayout) view.findViewById(R.id.recognition_box);
                box.setVisibility(View.VISIBLE);
                Animation slide_up = AnimationUtils.loadAnimation(activity.getApplicationContext(),
                        R.anim.slide_up);

                box.startAnimation(slide_up);
                rotationAngle = 180;

            } else {
                //                    t.interrupt();
                //                    t = null;
                RelativeLayout box = (RelativeLayout) view.findViewById(R.id.recognition_box);
                Animation slide_down = AnimationUtils.loadAnimation(activity.getApplicationContext(),
                        R.anim.slide_down);

                upArrow.animate().rotation(0).setDuration(500).start();

                box.startAnimation(slide_down);
                box.setVisibility(View.INVISIBLE);
                //shouldContinue = true;
                mGraphicOverlay.amountItem = null;
                mGraphicOverlay.amountItemAfterFormat = 0f;
                mGraphicOverlay.description = "";
                onResume();
                //                    createNewThread();
                //                    t.start();
                rotationAngle = 0;
            }
        }
    });

    ImageView addButton = (ImageView) view.findViewById(R.id.add_icon);
    addButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // takePicture();
            EditText description = (EditText) view.findViewById(R.id.text_name_value);
            EditText amount = (EditText) view.findViewById(R.id.text_amount_value);
            float floatAmount = Float.parseFloat(amount.getText().toString());
            Summary t = new Summary(description.getText().toString(), floatAmount);

            Bundle bundle = new Bundle();
            bundle.putSerializable("splitTransaction", t);

            //                 ByteArrayOutputStream stream = new ByteArrayOutputStream();
            //                 mCameraSource.mostRecentBitmap.compress(Bitmap.CompressFormat.PNG, 80, stream);
            //                 byte[] byteArray = stream.toByteArray();
            //Bitmap receiptBitmap = byteStreamToBitmap(mCameraSource.mostRecentBitmap);
            //bundle.putParcelable("receiptPicture",receiptBitmap);
            bundle.putString("receiptPicture", picPath);

            FriendsSelectionFragment fragment = new FriendsSelectionFragment();
            fragment.setArguments(bundle);

            ((Toolbar) activity.findViewById(R.id.tool_bar_hamburger)).setVisibility(View.INVISIBLE);
            getActivity().getSupportFragmentManager().beginTransaction()
                    .add(R.id.fragment_holder, fragment, "FriendsSelectionFragment").addToBackStack(null)
                    .commit();
        }
    });

    // Check for the camera permission before accessing the camera.  If the
    // permission is not granted yet, request permission.
    int rc = ActivityCompat.checkSelfPermission(context, Manifest.permission.CAMERA);
    if (rc == PackageManager.PERMISSION_GRANTED) {
        createCameraSource(autoFocus, useFlash);
    } else {
        requestCameraPermission();
    }

    gestureDetector = new GestureDetector(context, new CaptureGestureListener());
    scaleGestureDetector = new ScaleGestureDetector(context, new ScaleListener());

    //        Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom",
    //                Snackbar.LENGTH_LONG)
    //                .show();

    // Set up the Text To Speech engine.
    TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(final int status) {
            if (status == TextToSpeech.SUCCESS) {
                Log.d("OnInitListener", "Text to speech engine started successfully.");
                tts.setLanguage(Locale.US);
            } else {
                Log.d("OnInitListener", "Error starting the text to speech engine.");
            }
        }
    };
    tts = new TextToSpeech(activity.getApplicationContext(), listener);

    return view;
}