Back to project page PodioPuzzle.
The source code is released under:
Apache License
If you think the Android project PodioPuzzle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.podio.podiopuzzle.ui; //from w ww.ja v a 2 s . c o m import android.app.Activity; import android.os.Bundle; /** * Created by goman on 10/29/2014. */ import android.content.Intent; import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.ExpandableListView; import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.podio.podiopuzzle.R; import com.podio.podiopuzzle.model.Organization; import com.podio.podiopuzzle.services.Podio; import com.podio.podiopuzzle.util.Utility; import java.util.List; import retrofit.Callback; import retrofit.RetrofitError; /** * Created by goman on 10/29/2014. */ public class OrganizationActivity extends Activity { private ExpandableListView mExpandableListView; private OrganizationExpandAdapter mAdapter; private ProgressBar pbLoading; private TextView tvNotification; private Boolean enableMenu = true; private List<Organization> mListOrg = null; public static final String STATE_DATA = "state_data"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(!Podio.getInstance(this).isLogin()){ Intent i = new Intent(this, LoginActivity.class); startActivity(i); finish(); } else{ setContentView(R.layout.activity_organization); pbLoading = (ProgressBar) findViewById(R.id.pb_loading); tvNotification = (TextView) findViewById(R.id.text_notification); mExpandableListView = (ExpandableListView) findViewById(R.id.expand_list_organization); mAdapter = new OrganizationExpandAdapter(getApplicationContext(), mExpandableListView); mExpandableListView.setAdapter(mAdapter); mExpandableListView.setGroupIndicator(null); mExpandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { return true; } }); //To restore from instance state if (savedInstanceState != null){ String json = savedInstanceState.getString(STATE_DATA); if (json != null){ try { mListOrg = new Gson().fromJson(json, new TypeToken<List<Organization>>() {}.getType()); mAdapter.setData(mListOrg); }catch (Exception e){ } } } if (mListOrg == null) { loadData(); } } } public void loadData(){ stateLoading(); Podio.getInstance(this).getOrganization(callback); } public void stateLoading(){ enableMenu = false; invalidateOptionsMenu(); pbLoading.setVisibility(View.VISIBLE); tvNotification.setVisibility(View.VISIBLE); mExpandableListView.setVisibility(View.GONE); tvNotification.setText(R.string.text_progress); } public void stateFailure(){ enableMenu = true; invalidateOptionsMenu(); pbLoading.setVisibility(View.GONE); tvNotification.setVisibility(View.VISIBLE); mExpandableListView.setVisibility(View.GONE); tvNotification.setText(R.string.text_failed); } public void stateEmpty(){ enableMenu = true; invalidateOptionsMenu(); pbLoading.setVisibility(View.GONE); tvNotification.setVisibility(View.VISIBLE); mExpandableListView.setVisibility(View.GONE); tvNotification.setText(R.string.text_empty); } public void stateSuccess(){ enableMenu = true; invalidateOptionsMenu(); pbLoading.setVisibility(View.GONE); tvNotification.setVisibility(View.GONE); mExpandableListView.setVisibility(View.VISIBLE); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.login, menu); menu.getItem(0).setEnabled(enableMenu); return super.onCreateOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()){ case R.id.action_settings: loadData(); break; } return super.onOptionsItemSelected(item); } @Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putString(STATE_DATA, new Gson().toJson(mListOrg)); } private Callback<List<Organization>> callback = new Callback<List<Organization>>() { @Override public void success(List<Organization> organizations, retrofit.client.Response response) { if (Utility.isListNullOrEmpty(organizations)){ stateEmpty(); } else{ OrganizationActivity.this.mListOrg = organizations; mAdapter.setData(organizations); stateSuccess(); } } @Override public void failure(RetrofitError error) { if (error.getResponse().getStatus() == 401){ //if the request is unauthorized Podio.getInstance(OrganizationActivity.this).reset(); Toast.makeText(OrganizationActivity.this, "Token Expired!", Toast.LENGTH_SHORT).show(); Intent i = new Intent(OrganizationActivity.this, LoginActivity.class); startActivity(i); finish(); } else{ stateFailure(); } } }; }