protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.hackathon); CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapse_toolbar); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); register_button = (Button) findViewById(R.id.hackathon_register_button); loadToast = new LoadToast(EventRegisterActivity.this); loadToast.setText("LOADING"); loadToast.setTranslationY((int) Utils.convertDpToPixel(20, EventRegisterActivity.this)); text = (TextView) findViewById(R.id.description); error_image = (ImageView) findViewById(R.id.error_image); error_image.setVisibility(View.GONE); final int newColor = getResources().getColor(R.color.new_color); error_image.setColorFilter(newColor, PorterDuff.Mode.SRC_ATOP); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ImageView logo_image = (ImageView) findViewById(R.id.bgheader); logo_image.setTransitionName(getString(R.string.transition_name)); } String toshow = ""; getRegisteredEventRequest(); // for getting array of registered events register_button.setVisibility(View.GONE); if (savedInstanceState != null) { toshow = (String) savedInstanceState.getString(KEY_STRING); event = (EventClass) savedInstanceState.getSerializable(KEY_EVENT); current_event_registered = (Boolean) savedInstanceState.getSerializable(KEY_SHOW_BUTTON); if (current_event_registered == true) { register_button.setText("Unregister"); } else { register_button.setText("Register"); } if (toshow.contains("Details about event is currently unavailable.")) { register_button.setVisibility(View.GONE); error_image.setVisibility(View.VISIBLE); } else { register_button.setVisibility(View.VISIBLE); } } else { toshow += "Please wait...\n\n\n"; event = (EventClass) getIntent().getSerializableExtra("eventPassed"); register_button.setVisibility(View.GONE); loadToast.show(); getRequest(); } collapsingToolbarLayout.setTitle(event.getName()); text.setText(toshow); register_button.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { getRegistrationRequest(event); loadToast.show(); } }); }
private void getRequest() { loadToast = new LoadToast(Profile.this); loadToast.setText("LOADING"); loadToast.setTranslationY((int) Utils.convertDpToPixel(70, Profile.this)); loadToast.show(); final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest( getURL(), new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { Log.d("RESPONSE-PROFILE", response.toString()); try { loadToast.success(); JSONObject data = response.getJSONObject("data"); String status = response.getString("status"); if (status.equals("User Profile Info")) { String email = data.getString("email"); String name = data.getString("name"); int silver_coins = Integer.parseInt(data.getString("silver_coins")); int gold_coins = Integer.parseInt(data.getString("gold_coins")); user = new User(); user.setEmail(email); user.setName(name); user.setGoldCoins(gold_coins); user.setSilverCoins(silver_coins); email_textview.setText(email); name_textview.setText(name); silverCoins_textview.setText(Integer.toString(silver_coins)); goldCoins_textview.setText(Integer.toString(gold_coins)); String roll = null; if (data.has("rollno")) { if (!data.isNull("rollno")) { roll = data.getString("rollno"); username_textview.setText(roll); user.setRoll(roll); } else { username_textview.setVisibility(View.GONE); } } } } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { loadToast.error(); } }) { @Override public Map<String, String> getHeaders() throws AuthFailureError { Map<String, String> map = new HashMap<>(); map.put("Authorization", "bearer " + new PersonalData(Profile.this).getToken()); return map; } }; jsonObjectRequest.setRetryPolicy( new DefaultRetryPolicy(10000, 5, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); MySingleton.getInstance(MyApplication.getAppContext()).addToRequestQueue(jsonObjectRequest); }