Search in sources :

Example 61 with RequestQueue

use of com.android.volley.RequestQueue in project ef-app_android by eurofurence.

the class ApiInvoker method initConnectionRequest.

private void initConnectionRequest(Cache cache, Network network) {
    mRequestQueue = new RequestQueue(cache, network);
    mRequestQueue.start();
}
Also used : RequestQueue(com.android.volley.RequestQueue)

Example 62 with RequestQueue

use of com.android.volley.RequestQueue in project ef-app_android by eurofurence.

the class ApiInvoker method initConnectionRequest.

private void initConnectionRequest(Cache cache, Network network, int threadPoolSize, ResponseDelivery delivery) {
    mRequestQueue = new RequestQueue(cache, network, threadPoolSize, delivery);
    mRequestQueue.start();
}
Also used : RequestQueue(com.android.volley.RequestQueue)

Example 63 with RequestQueue

use of com.android.volley.RequestQueue in project V2HOT by djyde.

the class ContentActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayShowHomeEnabled(false);
    }
    setContentView(R.layout.activity_content);
    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build();
    ImageLoader.getInstance().init(config);
    Intent intent = getIntent();
    String id = intent.getStringExtra("id");
    String content = intent.getStringExtra("content");
    String username = intent.getStringExtra("username");
    title = intent.getStringExtra("title");
    url = intent.getStringExtra("url");
    final RepliesAdapter repliesAdapter = new RepliesAdapter(this, username);
    ListView repliesView = (ListView) findViewById(R.id.replies);
    View headerView = getLayoutInflater().inflate(R.layout.topic_header, repliesView, false);
    ((TextView) headerView.findViewById(R.id.header_title)).setText(title);
    ((TextView) headerView.findViewById(R.id.header_content)).setText(content);
    ((TextView) headerView.findViewById(R.id.header_username)).setText(username);
    repliesView.addHeaderView(headerView);
    repliesView.setAdapter(repliesAdapter);
    RequestQueue queue = Volley.newRequestQueue(ContentActivity.this);
    // 获取回复
    queue.add(new GsonRequest<ReplyList>(Request.Method.GET, "https://www.v2ex.com/api/replies/show.json?topic_id=" + id, ReplyList.class, new Response.Listener<ReplyList>() {

        @Override
        public void onResponse(ReplyList response) {
            repliesAdapter.addAll(response);
            repliesAdapter.notifyDataSetChanged();
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(ContentActivity.this, "请检查网络", Toast.LENGTH_LONG).show();
        }
    }));
}
Also used : VolleyError(com.android.volley.VolleyError) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView) ListView(android.widget.ListView) RequestQueue(com.android.volley.RequestQueue) TextView(android.widget.TextView) ReplyList(com.v2ex.api.ReplyList) ImageLoaderConfiguration(com.nostra13.universalimageloader.core.ImageLoaderConfiguration) ActionBar(android.support.v7.app.ActionBar)

Example 64 with RequestQueue

use of com.android.volley.RequestQueue in project V2HOT by djyde.

the class TitleListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_title_list);
    final SwipeRefreshLayout swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.pull);
    final ArrayAdapter<Topic> topicsAdapter = new ArrayAdapter<Topic>(this, 0) {

        private final LayoutInflater inflater = LayoutInflater.from(getContext());

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.topic_item, parent, false);
            }
            TextView title = (TextView) convertView.findViewById(R.id.title);
            title.setText(getItem(position).title);
            return convertView;
        }
    };
    final ListView topicsView = (ListView) findViewById(R.id.topics);
    topicsView.setAdapter(topicsAdapter);
    topicsView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Topic topic = topicsAdapter.getItem(position);
            Intent intent = new Intent(TitleListActivity.this, ContentActivity.class);
            intent.putExtra("id", topic.id);
            intent.putExtra("title", topic.title);
            intent.putExtra("username", topic.member.username);
            intent.putExtra("url", topic.url);
            intent.putExtra("content", topic.content);
            startActivity(intent);
        }
    });
    // 创建volley请求队列
    final RequestQueue queue = Volley.newRequestQueue(this);
    // 根据API获取热议主题
    final GsonRequest<TopicList> request = new GsonRequest<TopicList>(Request.Method.GET, "https://www.v2ex.com/api/topics/hot.json", TopicList.class, new Response.Listener<TopicList>() {

        @Override
        public void onResponse(TopicList response) {
            topicsAdapter.clear();
            topicsAdapter.addAll(response);
            topicsAdapter.notifyDataSetChanged();
            swipeRefreshLayout.setRefreshing(false);
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(TitleListActivity.this, "请检查网络", Toast.LENGTH_LONG).show();
        }
    });
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            queue.add(request);
        }
    });
    queue.add(request);
    swipeRefreshLayout.setRefreshing(true);
}
Also used : GsonRequest(com.v2ex.api.GsonRequest) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) ListView(android.widget.ListView) RequestQueue(com.android.volley.RequestQueue) TopicList(com.v2ex.api.TopicList) TextView(android.widget.TextView) Topic(com.v2ex.api.Topic) VolleyError(com.android.volley.VolleyError) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Response(com.android.volley.Response) LayoutInflater(android.view.LayoutInflater) AdapterView(android.widget.AdapterView) ArrayAdapter(android.widget.ArrayAdapter)

Example 65 with RequestQueue

use of com.android.volley.RequestQueue in project J2ME-Loader by nikita36078.

the class AppCenterSender method send.

@Override
public void send(@NonNull Context context, @NonNull final CrashReportData report) {
    final String log = (String) report.get(AppCenterCollector.APPCENTER_LOG);
    if (log == null || log.isEmpty()) {
        return;
    }
    // Force TLSv1.2 for Android 4.1-4.4
    boolean forceTls12 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP;
    HurlStack hurlStack = new HurlStack(null, forceTls12 ? new TLSSocketFactory(context) : null);
    RequestQueue queue = Volley.newRequestQueue(context, hurlStack);
    StringRequest postRequest = new StringRequest(Request.Method.POST, BASE_URL, response -> Log.d(TAG, "send success: " + response), error -> {
        Log.e(TAG, "Response error", error);
        String logFile = Config.getEmulatorDir() + "/crash.txt";
        try (FileOutputStream fos = new FileOutputStream(logFile)) {
            String logcat = report.getString(ReportField.LOGCAT);
            if (logcat != null) {
                fos.write(logcat.getBytes());
            }
            String stack = report.getString(ReportField.STACK_TRACE);
            if (stack != null) {
                fos.write("\n====================Error==================\n".getBytes());
                fos.write(stack.getBytes());
            }
            JSONObject o = (JSONObject) report.get(ReportField.CUSTOM_DATA.name());
            if (o != null) {
                Object od = o.opt(Constants.KEY_APPCENTER_ATTACHMENT);
                if (od != null) {
                    String customData = (String) od;
                    fos.write("\n==========application=info=============\n".getBytes());
                    fos.write(customData.getBytes());
                }
            }
            fos.close();
            Toast.makeText(context, "Can't send report! Saved to file:\n" + logFile, Toast.LENGTH_LONG).show();
        } catch (IOException e) {
            e.printStackTrace();
            Toast.makeText(context, "Can't send report!", Toast.LENGTH_LONG).show();
        }
    }) {

        @Override
        public Map<String, String> getHeaders() {
            Map<String, String> params = new HashMap<>();
            params.put("Content-Type", "application/json");
            params.put("App-Secret", FORM_KEY);
            params.put("Install-ID", report.getString(ReportField.INSTALLATION_ID));
            return params;
        }

        @Override
        public byte[] getBody() {
            return log.getBytes();
        }
    };
    postRequest.setShouldCache(false);
    queue.add(postRequest);
}
Also used : HurlStack(com.android.volley.toolbox.HurlStack) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) RequestQueue(com.android.volley.RequestQueue) StringRequest(com.android.volley.toolbox.StringRequest) FileOutputStream(java.io.FileOutputStream) JSONObject(org.json.JSONObject) IOException(java.io.IOException)

Aggregations

RequestQueue (com.android.volley.RequestQueue)119 Response (com.android.volley.Response)101 VolleyError (com.android.volley.VolleyError)95 JSONObject (org.json.JSONObject)83 HashMap (java.util.HashMap)71 JsonObjectRequest (com.android.volley.toolbox.JsonObjectRequest)59 User (model.User)50 JSONException (org.json.JSONException)50 StringRequest (com.android.volley.toolbox.StringRequest)29 Context (android.content.Context)22 Toast (android.widget.Toast)20 TextView (android.widget.TextView)14 Intent (android.content.Intent)10 DefaultRetryPolicy (com.android.volley.DefaultRetryPolicy)10 Network (com.android.volley.Network)10 NetworkResponse (com.android.volley.NetworkResponse)10 File (java.io.File)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 ExecutionException (java.util.concurrent.ExecutionException)9 TimeoutException (java.util.concurrent.TimeoutException)9