<commit_before>/**
 * Copyright 2015 Red Hat, Inc., and individual contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.feedhenry.helloworld;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.feedhenry.helloworld_android.R;
import com.feedhenry.sdk.FH;
import com.feedhenry.sdk.FHActCallback;
import com.feedhenry.sdk.FHResponse;
import com.feedhenry.sdk.api.FHCloudRequest;
import com.feedhenry.sdk.exceptions.FHNotReadyException;

import org.json.fh.JSONObject;

public class HelloFragment extends Fragment {

    private static final String TAG = InitFragment.class.getName();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = View.inflate(getActivity(), R.layout.hello_fragment, null);

        final TextView mResponse = (TextView) view.findViewById(R.id.cloud_response);
        final EditText mName = (EditText) view.findViewById(R.id.name);
        Button mCloudButton = (Button) view.findViewById(R.id.button);
        mCloudButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                mResponse.setText("");
                mCloudButton.setEnabled(false);
                cloudCall(v, mName.getText().toString(), mResponse);
                mName.setText("");
            }
        });

        return view;
    }

    private void cloudCall(final View button, final String name, final TextView response) {
        try {
            JSONObject params = new JSONObject("{hello: '" + name + "'}");

            FHCloudRequest request = FH.buildCloudRequest("hello", "POST", null, params);
            request.executeAsync(new FHActCallback() {
                @Override<commit_msg>FH-3862 fixed improper JSON creation<commit_after>/**
 * Copyright 2015 Red Hat, Inc., and individual contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.feedhenry.helloworld;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.feedhenry.helloworld_android.R;
import com.feedhenry.sdk.FH;
import com.feedhenry.sdk.FHActCallback;
import com.feedhenry.sdk.FHResponse;
import com.feedhenry.sdk.api.FHCloudRequest;
import com.feedhenry.sdk.exceptions.FHNotReadyException;
import org.json.fh.JSONObject;

public class HelloFragment extends Fragment {

    private static final String TAG = InitFragment.class.getName();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final View view = View.inflate(getActivity(), R.layout.hello_fragment, null);

        final TextView mResponse = (TextView) view.findViewById(R.id.cloud_response);
        final EditText mName = (EditText) view.findViewById(R.id.name);
        Button mCloudButton = (Button) view.findViewById(R.id.button);
        mCloudButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                mResponse.setText("");
                mCloudButton.setEnabled(false);
                cloudCall(v, mName.getText().toString(), mResponse);
                mName.setText("");
            }
        });

        return view;
    }

    private void cloudCall(final View button, final String name, final TextView response) {
        try {
            JSONObject params = new JSONObject();
            params.put("hello", name);  // { 'hello': $name }

            FHCloudRequest request = FH.buildCloudRequest("hello", "POST", null, params);
            request.executeAsync(new FHActCallback() {
                @Override
{'fraction_non_alphanumeric': 0.09559968847352025, 'fraction_numerical': 0.004283489096573208, 'mean_word_length': 3.316806722689076, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3434286', 'n_tokens_mistral': 1411, 'n_tokens_neox': 1332, 'n_words': 412}