use of com.android.volley.Response in project aplicativo by InCasa.
the class FragmentServidor method testeServer.
public void testeServer(String ipServer) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, "http://" + ipServer + "/backend/teste", null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
Toast.makeText(getActivity(), "Servidor: OK", Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getActivity(), "Erro no servidor", Toast.LENGTH_SHORT).show();
}
});
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(getActivity().getApplicationContext());
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.Response 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.Response in project aplicativo by InCasa.
the class AdminActivity method getUserInfo.
public void getUserInfo(JSONObject json, String URLUSERINFO) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLUSERINFO, json, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
Context context = getApplicationContext();
CharSequence text = "Usuário: Sucesso !";
int duration = Toast.LENGTH_SHORT;
User user = User.getInstancia();
try {
user.setNome(response.getString("nome"));
user.setId(response.getString("id"));
} catch (JSONException e) {
e.printStackTrace();
}
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Usuário: Falha !";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.Response in project aplicativo by InCasa.
the class AlarmeActivity method getPresenca.
public void getPresenca(String URLPRESENCA) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLPRESENCA, null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
String presenca = "";
try {
TextView txtPresenca = (TextView) findViewById(R.id.txtPresenca);
presenca = response.getString("valor");
if (presenca.equals("null")) {
ativo = false;
} else {
if (presenca.equals("1")) {
ativo = true;
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
Context context = getApplicationContext();
CharSequence text = "Erro na requisição";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
use of com.android.volley.Response in project aplicativo by InCasa.
the class HomeActivity method getRele2.
public void getRele2(String URLGETRELE2) {
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, URLGETRELE2, null, new Response.Listener<JSONObject>() {
// Em caso de sucesso
@Override
public void onResponse(JSONObject response) {
try {
Rele2.setIdRele(response.getInt("id"));
Rele2.setNome(response.getString("nome"));
Rele2.setDescricao(response.getString("descricao"));
Rele2.setPorta(response.getInt("porta"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
// Em caso de erro
@Override
public void onErrorResponse(VolleyError error) {
}
}) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> headers = new HashMap<String, String>();
// add headers <key,value>
User user = User.getInstancia();
String auth = new String(Base64.encode((user.getLogin() + ":" + user.getSenha()).getBytes(), Base64.DEFAULT));
headers.put("Authorization ", " Basic " + auth);
return headers;
}
};
// fila de requisições
RequestQueue fila = Volley.newRequestQueue(this);
// Adiciona a requisição á fila de requisições
fila.add(req);
}
Aggregations