Example usage for android.os Bundle getSerializable

List of usage examples for android.os Bundle getSerializable

Introduction

In this page you can find the example usage for android.os Bundle getSerializable.

Prototype

@Override
@Nullable
public Serializable getSerializable(@Nullable String key) 

Source Link

Document

Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key or a null value is explicitly associated with the key.

Usage

From source file:com.styleme.floating.toolbox.pro.widget.colorpicker.dashclockpicker.ColorPickerDialogDash.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
    View rootView = layoutInflater.inflate(R.layout.dash_dialog_colors, null);

    if (getArguments() != null) {
        mTitleResId = getArguments().getInt(KEY_TITLE_ID);
        mNumColumns = getArguments().getInt(KEY_COLUMNS);
    }/* www  . j a  v  a2 s  . co m*/

    if (savedInstanceState != null) {
        mColorChoices = savedInstanceState.getIntArray(KEY_COLORS);
        mSelectedColor = (Integer) savedInstanceState.getSerializable(KEY_SELECTED_COLOR);
        tryBindLists();
    }

    mColorGrid = (GridView) rootView.findViewById(R.id.color_grid);

    mColorGrid.setNumColumns(mNumColumns);

    mColorGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> listView, View view, int position, long itemId) {
            //Added
            //Toast.makeText(getActivity(), "Selected color="+mAdapter.getItem(position), Toast.LENGTH_LONG).show();
            if (mListener != null)
                mListener.onColorSelected(mAdapter.getItem(position));
            dismiss();
        }
    });

    tryBindLists();

    if (AppHelper.isDarkTheme(getContext())) {
        return new AlertDialog.Builder(getActivity(), R.style.CustomDialogTheme).setView(rootView)
                .setTitle(mTitleResId) //Added
                .create();
    } else {
        return new AlertDialog.Builder(getActivity()).setView(rootView).setTitle(mTitleResId) //Added
                .create();
    }

}

From source file:cn.finalteam.galleryfinal.PhotoEditActivity.java

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    mSelectPhotoList = (ArrayList<PhotoInfo>) savedInstanceState.getSerializable("selectPhotoMap");
    mEditPhotoCacheFile = (File) savedInstanceState.getSerializable("editPhotoCacheFile");
    mPhotoTempMap = new LinkedHashMap<>(
            (HashMap<Integer, PhotoTempModel>) savedInstanceState.getSerializable("photoTempMap"));

    mSelectIndex = savedInstanceState.getInt("selectIndex");
    mCropState = savedInstanceState.getBoolean("cropState");
    mRotating = savedInstanceState.getBoolean("rotating");

    mTakePhotoAction = savedInstanceState.getBoolean("takePhotoAction");
    mCropPhotoAction = savedInstanceState.getBoolean("cropPhotoAction");
    mEditPhotoAction = savedInstanceState.getBoolean("editPhotoAction");
}

From source file:com.prasanna.android.stacknetwork.QuestionActivity.java

@SuppressWarnings("unchecked")
@Override//from  www .  j  a  v  a 2s. co m
public void onReceiveResult(int resultCode, Bundle resultData) {
    switch (resultCode) {
    case QuestionDetailsIntentService.RESULT_CODE_Q_CACHED:
        setProgressBarIndeterminateVisibility(false);
    case QuestionDetailsIntentService.RESULT_CODE_Q:
        question = (Question) resultData.getSerializable(StringConstants.QUESTION);
        displayQuestion();
        if (question.answerCount > 0 && (question.answers == null || question.answers.isEmpty()))
            startServiceForAnswers();
        else
            setProgressBarIndeterminateVisibility(false);
        break;
    case QuestionDetailsIntentService.RESULT_CODE_Q_BODY:
        questionFragment.displayBody(resultData.getString(StringConstants.BODY));
        if (question.answerCount == 0)
            setProgressBarIndeterminateVisibility(false);
        break;
    case QuestionDetailsIntentService.RESULT_CODE_Q_COMMENTS:
        question.comments = (ArrayList<Comment>) resultData.getSerializable(StringConstants.COMMENTS);
        questionFragment.setComments(question.comments);
        break;
    case QuestionDetailsIntentService.RESULT_CODE_ANSWERS:
        serviceRunningForAnswers = false;
        setProgressBarIndeterminateVisibility(false);
        displayAnswers((ArrayList<Answer>) resultData.getSerializable(StringConstants.ANSWERS), true);
        break;
    case WriteIntentService.ACTION_ADD_COMMENT:
        dismissPostCommentFragmentIfVisible(true);
        addMyCommentToPost(resultData);
        break;
    case QuestionDetailsIntentService.RESULT_CODE_FAVORITE_SUCCESS:
        serviceRunningForFavorite = false;
        question.favorited = true;
        setupFavoriteActionBarIcon();
        break;
    case QuestionDetailsIntentService.RESULT_CODE_FAVORITE_UNDO_SUCCESS:
        serviceRunningForFavorite = false;
        question.favorited = false;
        setupFavoriteActionBarIcon();
        break;
    case QuestionDetailsIntentService.ERROR:
        if (serviceRunningForAnswers)
            serviceRunningForAnswers = false;
        if (serviceRunningForFavorite)
            serviceRunningForFavorite = false;
        handleError(resultData);
        break;
    default:
        break;
    }
}

From source file:com.pukulab.puku0x.gscalendar.CalendarActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    // ??// w  w  w  .  j  a  v a  2s .co m
    case DetailActivity.REQUEST_DETAIL:
        // ???
        if (resultCode == RESULT_OK) {
            if (data != null) {
                // ??
                Bundle bundle = data.getExtras();
                Schedule newSchedule = (Schedule) bundle.getSerializable(EditActivity.ARGS_NEW_SCHEDULE);

                // ????????
                if (!newSchedule.equals(mLastSchedule)) {
                    // ???
                    new DisplaySchedulesTask(CalendarActivity.this, mDisplayedUser, mDisplayedDate)
                            .execute(mStartDate, mEndDate);
                }
            }
        }
        break;

    // ??
    case EditActivity.REQUEST_ADD_SCHEDULE:
        if (resultCode == RESULT_OK) {
            if (data != null) {
                // ??
                Bundle bundle = data.getExtras();
                Schedule newSchedule = (Schedule) bundle.getSerializable(EditActivity.ARGS_NEW_SCHEDULE);
                if (newSchedule != null) {

                }

                // ???
                new DisplaySchedulesTask(CalendarActivity.this, mDisplayedUser, mDisplayedDate)
                        .execute(mStartDate, mEndDate);
            }
        }
    default:
        break;
    }
}

From source file:dk.kk.ibikecphlib.map.MapActivity.java

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, "onActivityResult, requestCode " + requestCode + " resultCode " + resultCode);

    if (requestCode == LeftMenu.LAUNCH_LOGIN) {
        Log.d(TAG, "Got back from the user login");
        /*//from  w ww  .j a va2  s . co m
        Log.d("JC", "Got back from LAUNCH_LOGIN");
        if (!OverviewMapHandler.isWatchingAddress) {
        this.mapView.changeState(IBCMapView.MapViewState.DEFAULT);
        }
        leftMenu.populateMenu();
        */
    } else if (resultCode == ProfileActivity.RESULT_USER_DELETED) {
        Log.d(TAG, "Got back from deleting the user");
        AlertDialog dialog;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(IBikeApplication.getString("account_deleted"));
        builder.setPositiveButton(IBikeApplication.getString("close"), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        dialog = builder.create();
        dialog.show();
    } else if (requestCode == REQUEST_SEARCH_ADDRESS && resultCode == RESULT_OK) {
        Log.d(TAG, "Got back from address search, with an OK result");
        // Change state right away
        DestinationPreviewState state = this.changeState(DestinationPreviewState.class);
        // What address was selected?
        final Bundle extras = data.getExtras();
        Address address = (Address) extras.getSerializable("addressObject");

        if (address != null) {
            if (address.getSource() == Address.Source.FAVORITE) {
                address.setHouseNumber("");
            }
            state.setDestination(address);
        } else {
            throw new RuntimeException("Expected an address");
        }
    } else if (requestCode == REQUEST_SEARCH_ADDRESS && resultCode == RESULT_CANCELED) {
        Log.d(TAG, "Got back from address search were the user canceled!");
        // throw new UnsupportedOperationException("Canceling the search address has not been implemented.");
    } else if (requestCode == REQUEST_CHANGE_SOURCE_ADDRESS
            && resultCode == SearchAutocompleteActivity.RESULT_AUTOTOCMPLETE_SET) {
        Log.d(TAG, "Got back from setting the source");
        if (state instanceof RouteSelectionState) {
            final Bundle extras = data.getExtras();
            Address address = (Address) extras.getSerializable("addressObject");
            if (address != null) {
                ((RouteSelectionState) state).setSource(address);
            } else {
                throw new RuntimeException("Expected an address");
            }
        }
    } else if (requestCode == REQUEST_CHANGE_DESTINATION_ADDRESS
            && resultCode == SearchAutocompleteActivity.RESULT_AUTOTOCMPLETE_SET) {
        Log.d(TAG, "Got back from setting the destination");
        if (state instanceof RouteSelectionState) {
            final Bundle extras = data.getExtras();
            Address address = (Address) extras.getSerializable("addressObject");
            if (address != null) {
                ((RouteSelectionState) state).setDestination(address);
            } else {
                throw new RuntimeException("Expected an address");
            }
        }
    } else if (requestCode == LeftMenu.LAUNCH_FAVORITE) {
        Log.d(TAG, "Got back from the favorite screen.");
        // We got a favorite to navigate to
        if (resultCode == RESULT_OK) {
            // TODO: Re-implement launching of favorites
            // throw new UnsupportedOperationException("Launching favorites not yet implemented using MapStates");
            FavoriteListItem fd = data.getExtras().getParcelable("ROUTE_TO");
            Address address = fd.getAddress();
            RouteSelectionState state = changeState(RouteSelectionState.class);
            state.setDestination(address);
            // mapView.showRoute(fd);
            //mapView.showAddressFromFavorite(a);
            // Close the LeftMenu
            drawerLayout.closeDrawer(Gravity.LEFT);
        }
    } else if (requestCode == LeftMenu.LAUNCH_TRACKING) {
        Log.d(TAG, "Got back from the tracking screen.");
    } else if (requestCode == LeftMenu.LAUNCH_ABOUT) {
        Log.d(TAG, "Got back from the about screen.");
    }
}

From source file:com.example.skode6.scanenvy.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);// w  w w .ja v  a 2s .c  o  m
    if (savedInstanceState != null) {
        try {
            ArrayList myArrayList = (ArrayList) getLastNonConfigurationInstance();
        } catch (NullPointerException e) {
            List<Product> values = new ArrayList<Product>();
            for (int i = 0; i < productList.size(); i++) {
                values.add((Product) savedInstanceState.getSerializable("product" + i));
            }
            if (values != null) {
                lv = (RecyclerView) findViewById(R.id.list);
                lv.setHasFixedSize(false);
                LinearLayoutManager llm = new LinearLayoutManager(this);
                lv.setLayoutManager(llm);
                adapter = new ProductAdapter(this, values);
                lv.setAdapter(adapter);
            }
        }
    } else {
        productList = run.getProductList();
        setListView();
    }
    setToolBar();
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    dialog = enterDialog(edit = new EditText(this));
    edit = new EditText(this);
    fabToolbar = ((FabToolbar) findViewById(R.id.fab_toolbar));
    findViewById(R.id.scan_code).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            fabToolbar.hide();
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

From source file:com.mercandalli.android.apps.files.file.image.FileImageActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_file_picture);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.my_toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);//  ww  w  . ja  v a2 s .c  o m
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(true);
        }
    }

    // Translucent notification bar
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

    // Get views
    mProgressBar = (ProgressBar) this.findViewById(R.id.progressBar);
    mCircle = (ImageButton) this.findViewById(R.id.circle);
    mTitleTextView = (TextView) this.findViewById(R.id.title);
    mProgressTextView = (TextView) this.findViewById(R.id.progress_tv);

    mProgressBar.setProgress(0);

    Bundle extras = getIntent().getExtras();
    if (extras == null) {
        Log.e("" + getClass().getName(), "extras == null");
        finish();
        overridePendingTransition(R.anim.right_in, R.anim.right_out);
        return;
    } else {
        mId = extras.getInt("ID");
        mTitle = extras.getString("TITLE");
        mUrl = extras.getString("URL_FILE");
        online = extras.getBoolean("CLOUD");
        sizeFile = extras.getLong("SIZE_FILE");
        date_creation = (Date) extras.getSerializable("DATE_FILE");

        if (mTitle != null) {
            mTitleTextView.setText(mTitle);
        }

        if (ImageUtils.isImage(this, this.mId)) {
            mBitmap = ImageUtils.loadImage(this, this.mId);
            ((ImageView) this.findViewById(R.id.tab_icon)).setImageBitmap(mBitmap);
            int bgColor = ColorUtils.getMutedColor(mBitmap);
            if (bgColor != 0) {
                mTitleTextView.setBackgroundColor(bgColor);
                mTitleTextView.setTextColor(ColorUtils.colorText(bgColor));
                RippleDrawable cir = ImageUtils.getPressedColorRippleDrawable(bgColor,
                        ColorUtils.getDarkMutedColor(mBitmap));
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    mCircle.setBackground(cir);
                }
            }
            mProgressBar.setVisibility(View.GONE);
            mProgressTextView.setVisibility(View.GONE);
        } else if (this.mId != 0) {
            mProgressBar.setVisibility(View.VISIBLE);
            mProgressTextView.setVisibility(View.VISIBLE);
            (new TaskGetDownloadImage(this, mUrl, mId, sizeFile, -1, new IBitmapListener() {
                @Override
                public void execute(Bitmap bitmap) {
                    ((ImageView) findViewById(R.id.tab_icon)).setImageBitmap(bitmap);
                    int bgColor = ColorUtils.getMutedColor(bitmap);
                    if (bgColor != 0) {
                        mTitleTextView.setBackgroundColor(bgColor);
                        mTitleTextView.setTextColor(ColorUtils.colorText(bgColor));
                        RippleDrawable cir = ImageUtils.getPressedColorRippleDrawable(bgColor,
                                ColorUtils.getDarkMutedColor(bitmap));
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                            mCircle.setBackground(cir);
                        }
                    }
                    mProgressBar.setVisibility(View.GONE);
                    mProgressTextView.setVisibility(View.GONE);
                }
            }, new ILongListener() {
                @Override
                public void execute(long text) {
                    mProgressBar.setProgress((int) text);
                    mProgressTextView.setText(text + "%");
                }
            })).execute();
        }
    }

    mCircle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent picIntent = new Intent();
            picIntent.setAction(Intent.ACTION_VIEW);
            picIntent.setDataAndType(Uri.parse("file://"
                    + (new File(FileImageActivity.this.getFilesDir() + "/file_" + mId)).getAbsolutePath()),
                    "image/*");
            FileImageActivity.this.startActivity(picIntent);
        }
    });
}

From source file:com.enstage.wibmo.sdk.inapp.InAppInitActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.v(TAG, "OnCreate");
    activity = this;

    Bundle extras = getIntent().getExtras();
    if (extras != null) {

        w2faInitRequest = (W2faInitRequest) extras.getSerializable("W2faInitRequest");
        wPayInitRequest = (WPayInitRequest) extras.getSerializable("WPayInitRequest");

        //reset//w  ww .j  av  a 2s .  com
        w2faInitResponse = null;
        wPayInitResponse = null;

        if (w2faInitRequest != null || wPayInitRequest != null) {
            qrMsg = "InApp payment";
        } else {
            Log.e(TAG, "W2faInitRequest and wPayInitRequest was null!");
            sendAbort(WibmoSDK.RES_CODE_FAILURE_SYSTEM_ABORT,
                    "sdk init - W2faInitRequest and wPayInitRequest was null!");
            return;
        }
    }

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setProgressBarIndeterminateVisibility(false);

    LayoutInflater inflator = getLayoutInflater();
    view = inflator.inflate(R.layout.activity_inapp_init, null, false);
    view.startAnimation(AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left));
    setContentView(view);

    TextView text = (TextView) findViewById(R.id.text);
    text.setText(qrMsg);

    mainView = (View) findViewById(R.id.main_view);

    final Activity activity = this;

    Button abortButton = (Button) findViewById(R.id.abort_button);
    abortButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            cancelIAP();
            sendAbort();
        }
    });

    if (WibmoSDK.IS_PHONE_STATE_PERMISSION_REQ) {
        if (WibmoSDKPermissionUtil.checkSelfPermission(activity,
                Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
            Log.w(TAG, "Permission not granted! READ_PHONE_STATE");

            WibmoSDKPermissionUtil.showRequestPermissionRationalel(activity,
                    getString(R.string.wibmosdk_phone_state_permission_rationale), new Runnable() {
                        @Override
                        public void run() {
                            ActivityCompat.requestPermissions(activity,
                                    new String[] { Manifest.permission.READ_PHONE_STATE },
                                    WibmoSDKPermissionUtil.REQUEST_CODE_ASK_PERMISSION_PHONE_STATE);
                        }
                    }, new Runnable() {
                        @Override
                        public void run() {
                            WibmoSDKPermissionUtil.showPermissionMissingUI(activity,
                                    getString(R.string.wibmosdk_phone_state_permission_missing_msg));
                            sendAbort(WibmoSDK.RES_CODE_FAILURE_SYSTEM_ABORT,
                                    "sdk init - no permission ph state");
                        }
                    });

            return;//we need this so can;t go on
        }
    }

    doIAPStuff();
}

From source file:com.halzhang.android.apps.startupnews.ui.tablet.DiscussFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHasOptionsMenu(true);/*www  .  j  a v  a  2s .c o m*/
    View view = inflater.inflate(R.layout.fragment_discuss, null);
    mListView = (ListView) view.findViewById(android.R.id.list);
    mListView.setOnItemClickListener(this);
    mSnDiscuss = new SNDiscuss();
    Bundle args = getArguments();
    SNNew snNew = null;
    if (args != null && args.containsKey(DiscussActivity.ARG_DISCUSS_URL)) {
        mDiscussURL = args.getString(DiscussActivity.ARG_DISCUSS_URL);
    } else {
        throw new IllegalArgumentException("Discuss URL is required!");
    }
    if (args.containsKey(DiscussActivity.ARG_SNNEW)) {
        snNew = (SNNew) args.getSerializable(DiscussActivity.ARG_SNNEW);
        mSnDiscuss.setSnNew(snNew);
    }
    mAdapter = new DiscussCommentAdapter();
    View headerView = inflater.inflate(R.layout.discuss_header_view, null);
    mTitle = (TextView) headerView.findViewById(R.id.discuss_news_title);
    mSubTitle = (TextView) headerView.findViewById(R.id.discuss_news_subtitle);
    mText = (TextView) headerView.findViewById(R.id.discuss_text);

    mSendBtn = (ImageButton) view.findViewById(R.id.discuss_comment_send_btn);
    mSendBtn.setEnabled(false);
    mSendBtn.setOnClickListener(mSendBtnClickListener);
    mCommentEdit = (EditText) view.findViewById(R.id.discuss_comment_edit);
    mCommentEdit.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            mSendBtn.setEnabled(s.length() > 0);
        }
    });
    mListView.addHeaderView(headerView);
    mListView.setAdapter(mAdapter);
    wrapHeaderView(snNew);
    loadData();
    return view;
}

From source file:com.antew.redditinpictures.library.service.RESTService.java

@Override
protected void onHandleIntent(Intent intent) {
    Uri action = intent.getData();//ww w  . j a  va2s  .  c om
    Bundle extras = intent.getExtras();

    if (extras == null || action == null) {
        Ln.e("You did not pass extras or data with the Intent.");
        return;
    }

    // We default to GET if no verb was specified.
    int verb = extras.getInt(EXTRA_HTTP_VERB, GET);
    RequestCode requestCode = (RequestCode) extras.getSerializable(EXTRA_REQUEST_CODE);
    Bundle params = extras.getParcelable(EXTRA_PARAMS);
    String cookie = extras.getString(EXTRA_COOKIE);
    String userAgent = extras.getString(EXTRA_USER_AGENT);

    // Items in this bundle are simply passed on in onRequestComplete
    Bundle passThrough = extras.getBundle(EXTRA_PASS_THROUGH);

    HttpEntity responseEntity = null;
    Intent result = new Intent(Constants.Broadcast.BROADCAST_HTTP_FINISHED);
    result.putExtra(EXTRA_PASS_THROUGH, passThrough);
    Bundle resultData = new Bundle();

    try {
        // Here we define our base request object which we will
        // send to our REST service via HttpClient.
        HttpRequestBase request = null;

        // Let's build our request based on the HTTP verb we were
        // given.
        switch (verb) {
        case GET: {
            request = new HttpGet();
            attachUriWithQuery(request, action, params);
        }
            break;

        case DELETE: {
            request = new HttpDelete();
            attachUriWithQuery(request, action, params);
        }
            break;

        case POST: {
            request = new HttpPost();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary. Note: some REST APIs
            // require you to POST JSON. This is easy to do, simply use
            // postRequest.setHeader('Content-Type', 'application/json')
            // and StringEntity instead. Same thing for the PUT case
            // below.
            HttpPost postRequest = (HttpPost) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                postRequest.setEntity(formEntity);
            }
        }
            break;

        case PUT: {
            request = new HttpPut();
            request.setURI(new URI(action.toString()));

            // Attach form entity if necessary.
            HttpPut putRequest = (HttpPut) request;

            if (params != null) {
                UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(paramsToList(params));
                putRequest.setEntity(formEntity);
            }
        }
            break;
        }

        if (request != null) {
            DefaultHttpClient client = new DefaultHttpClient();

            // GZip requests
            // antew on 3/12/2014 - Disabling GZIP for now, need to figure this CloseGuard error:
            // 03-12 21:02:09.248    9674-9683/com.antew.redditinpictures.pro E/StrictMode A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
            //         java.lang.Throwable: Explicit termination method 'end' not called
            // at dalvik.system.CloseGuard.open(CloseGuard.java:184)
            // at java.util.zip.Inflater.<init>(Inflater.java:82)
            // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
            // at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
            // at com.antew.redditinpictures.library.service.RESTService$GzipDecompressingEntity.getContent(RESTService.java:346)
            client.addRequestInterceptor(getGzipRequestInterceptor());
            client.addResponseInterceptor(getGzipResponseInterceptor());

            if (cookie != null) {
                request.addHeader("Cookie", cookie);
            }

            if (userAgent != null) {
                request.addHeader("User-Agent", Constants.Reddit.USER_AGENT);
            }

            // Let's send some useful debug information so we can monitor things
            // in LogCat.
            Ln.d("Executing request: %s %s ", verbToString(verb), action.toString());

            // Finally, we send our request using HTTP. This is the synchronous
            // long operation that we need to run on this thread.
            HttpResponse response = client.execute(request);

            responseEntity = response.getEntity();
            StatusLine responseStatus = response.getStatusLine();
            int statusCode = responseStatus != null ? responseStatus.getStatusCode() : 0;

            if (responseEntity != null) {
                resultData.putString(REST_RESULT, EntityUtils.toString(responseEntity));
                resultData.putSerializable(EXTRA_REQUEST_CODE, requestCode);
                resultData.putInt(EXTRA_STATUS_CODE, statusCode);
                result.putExtra(EXTRA_BUNDLE, resultData);

                onRequestComplete(result);
            } else {
                onRequestFailed(result, statusCode);
            }
        }
    } catch (URISyntaxException e) {
        Ln.e(e, "URI syntax was incorrect. %s %s ", verbToString(verb), action.toString());
        onRequestFailed(result, 0);
    } catch (UnsupportedEncodingException e) {
        Ln.e(e, "A UrlEncodedFormEntity was created with an unsupported encoding.");
        onRequestFailed(result, 0);
    } catch (ClientProtocolException e) {
        Ln.e(e, "There was a problem when sending the request.");
        onRequestFailed(result, 0);
    } catch (IOException e) {
        Ln.e(e, "There was a problem when sending the request.");
        onRequestFailed(result, 0);
    } finally {
        if (responseEntity != null) {
            try {
                responseEntity.consumeContent();
            } catch (IOException ignored) {
            }
        }
    }
}