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();
}
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();
}
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();
}
}));
}
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);
}
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);
}
Aggregations