Back to project page inbox-android.
The source code is released under:
MIT License
If you think the Android project inbox-android 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.inboxapp.androidsdk.sample_application; //www . j av a2 s . c o m import android.app.Activity; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.app.ListFragment; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.Toast; import com.inboxapp.androidsdk.R; import com.inboxapp.androidsdk.apis.InboxAppClient; import com.inboxapp.androidsdk.apis.taskmanagement.InboxAppTaskCallback; import com.inboxapp.androidsdk.json_objects.collection_objects.ContactList; import com.inboxapp.androidsdk.json_objects.collection_objects.DraftList; import com.inboxapp.androidsdk.json_objects.collection_objects.FileList; import com.inboxapp.androidsdk.json_objects.collection_objects.MessageList; import com.inboxapp.androidsdk.json_objects.collection_objects.NameSpaceList; import com.inboxapp.androidsdk.json_objects.collection_objects.TagList; import com.inboxapp.androidsdk.json_objects.collection_objects.ThreadList; import com.inboxapp.androidsdk.json_objects.single_objects.*; import com.inboxapp.androidsdk.json_objects.single_objects.Thread; import com.inboxapp.androidsdk.json_objects.single_objects.base.InboxAppSingleObject; import com.inboxapp.androidsdk.json_objects.single_objects.body_objects.TagName; import java.util.ArrayList; import retrofit.Callback; import retrofit.RetrofitError; import retrofit.client.Response; /** * Created by sylvianguessan on 8/8/14. */ public class SampleDetailsActivity extends Activity { ProgressBar progressBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sample); progressBar = (ProgressBar) findViewById(R.id.progressBar); progressBar.setVisibility(View.VISIBLE); String categoryTitle = getIntent().getStringExtra(SampleMenuActivity.CATEGORY_TITLE); Bundle bundle = new Bundle(); bundle.putString(SampleMenuActivity.CATEGORY_TITLE, categoryTitle); FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); SampleDetailsListFragment llf = new SampleDetailsListFragment(); llf.setArguments(bundle); ft.replace(R.id.listFragment, llf); ft.commit(); } public static class SampleDetailsListFragment extends ListFragment { String[] mSubCategoryDetails; String mInputCategoryTitle; SampleArrayAdapter mAdapter; LayoutInflater mInflater; final Handler mHandler = new android.os.Handler(); @Override public void onListItemClick(ListView l, View v, int position, long id) { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mSubCategoryDetails = new String[]{}; mInputCategoryTitle = this.getArguments().getString(SampleMenuActivity.CATEGORY_TITLE); mInflater = inflater; mAdapter = new SampleArrayAdapter( mInflater.getContext(), mSubCategoryDetails, false, mInputCategoryTitle); setListAdapter(mAdapter); return super.onCreateView(inflater, container, savedInstanceState); } public void displayResult(ArrayList<? extends InboxAppSingleObject> arrList) { ((SampleDetailsActivity)(SampleDetailsListFragment.this.getActivity())).progressBar.setVisibility(View.GONE); if ((arrList != null) && (arrList.size() > 0)) { String[] dataDetails = new String[arrList.size()]; for (int i = 0; i < dataDetails.length; i++) { dataDetails[i] = arrList.get(i).memberTypesValue(); } mSubCategoryDetails = dataDetails; mAdapter = new SampleArrayAdapter( mInflater.getContext(), mSubCategoryDetails, false, mInputCategoryTitle); setListAdapter(mAdapter); Toast toast = Toast.makeText(SampleDetailsListFragment.this.getActivity(), "Success", Toast.LENGTH_SHORT); toast.show(); } else { Toast toast = Toast.makeText(SampleDetailsListFragment.this.getActivity(), "No Result", Toast.LENGTH_SHORT); toast.show(); } } public void stopSpinner() { ((SampleDetailsActivity)(SampleDetailsListFragment.this.getActivity())).progressBar.setVisibility(View.GONE); } public void showError(String error) { Toast toast = Toast.makeText(SampleDetailsListFragment.this.getActivity(), "No Result", Toast.LENGTH_SHORT); toast.show(); } @Override public void onResume() { super.onResume(); final InboxAppClient inboxAppClient = new InboxAppClient("", ""); if (mInputCategoryTitle.equals("Namespaces")) { ((SampleDetailsActivity)(SampleDetailsListFragment.this.getActivity())).progressBar.setVisibility(View.VISIBLE); inboxAppClient.getNamespacesWithCallback(new Callback<ArrayList<Namespace>>() { @Override public void success(ArrayList<Namespace> objectArrayList, Response response) { Log.w("Namespaces", "Success."); displayResult(objectArrayList); } @Override public void failure(RetrofitError retrofitError) { Log.w("Namespaces", "\nError Cause:"+retrofitError.getCause()+"\nError Message:"+retrofitError.getMessage()); stopSpinner(); showError(retrofitError.getMessage().toString()); }}); } else if (mInputCategoryTitle.equals("Tags")) { ((SampleDetailsActivity)(SampleDetailsListFragment.this.getActivity())).progressBar.setVisibility(View.VISIBLE); inboxAppClient.getTagsWithCallback("e64whckcmw4d463i41dhlhnya",new Callback<ArrayList<Tag>>() { @Override public void success(ArrayList<Tag> objectArrayList, Response response) { Log.w("Tags", "Success."); displayResult(objectArrayList); } @Override public void failure(RetrofitError retrofitError) { Log.w("Tags", "\nError Cause:" + retrofitError.getCause() + "\nError Message:" + retrofitError.getMessage()); stopSpinner(); showError(retrofitError.getMessage().toString()); }}); } else if (mInputCategoryTitle.equals("Threads")) { ((SampleDetailsActivity)(SampleDetailsListFragment.this.getActivity())).progressBar.setVisibility(View.VISIBLE); inboxAppClient.getThreadsWithCallback("e64whckcmw4d463i41dhlhnya", new Callback<ArrayList<Thread>>() { @Override public void success(ArrayList<Thread> objectArrayList, Response response) { Log.w("Threads", "Success."); displayResult(objectArrayList); //DEMO if (objectArrayList.size() > 0) { objectArrayList.get(29).markAsRead(inboxAppClient); } } @Override public void failure(RetrofitError retrofitError) { Log.w("Threads", "\nError Cause:" + retrofitError.getCause() + "\nError Message:" + retrofitError.getMessage()); stopSpinner(); showError(retrofitError.getMessage().toString()); } }); } else if (mInputCategoryTitle.equals("Messages")) { ((SampleDetailsActivity)(SampleDetailsListFragment.this.getActivity())).progressBar.setVisibility(View.VISIBLE); inboxAppClient.getMessagesWithCallback("e64whckcmw4d463i41dhlhnya", new Callback<ArrayList<Message>>() { @Override public void success(ArrayList<Message> objectArrayList, Response response) { Log.w("Messages", "Success."); displayResult(objectArrayList); } @Override public void failure(RetrofitError retrofitError) { Log.w("Messages", "\nError Cause:" + retrofitError.getCause() + "\nError Message:" + retrofitError.getMessage()); stopSpinner(); showError(retrofitError.getMessage().toString()); } }); } else if (mInputCategoryTitle.equals("Files")) { ((SampleDetailsActivity)(SampleDetailsListFragment.this.getActivity())).progressBar.setVisibility(View.VISIBLE); inboxAppClient.getFilesWithCallback("e64whckcmw4d463i41dhlhnya", new Callback<ArrayList<File>>() { @Override public void success(ArrayList<File> objectArrayList, Response response) { Log.w("Messages", "Success."); displayResult(objectArrayList); } @Override public void failure(RetrofitError retrofitError) { Log.w("Messages", "\nError Cause:" + retrofitError.getCause() + "\nError Message:" + retrofitError.getMessage()); stopSpinner(); showError(retrofitError.getMessage().toString()); } }); } else if (mInputCategoryTitle.equals("Contacts")) { ((SampleDetailsActivity)(SampleDetailsListFragment.this.getActivity())).progressBar.setVisibility(View.VISIBLE); inboxAppClient.getContactsWithCallback("e64whckcmw4d463i41dhlhnya", new Callback<ArrayList<Contact>>() { @Override public void success(ArrayList<Contact> objectArrayList, Response response) { Log.w("Contacts", "Success."); displayResult(objectArrayList); } @Override public void failure(RetrofitError retrofitError) { Log.w("Contacts", "\nError Cause:" + retrofitError.getCause() + "\nError Message:" + retrofitError.getMessage()); stopSpinner(); showError(retrofitError.getMessage().toString()); } }); } else if (mInputCategoryTitle.equals("Drafts")) { ((SampleDetailsActivity)(SampleDetailsListFragment.this.getActivity())).progressBar.setVisibility(View.VISIBLE); inboxAppClient.getDraftsWithCallback("e64whckcmw4d463i41dhlhnya", new Callback<ArrayList<Draft>>() { @Override public void success(ArrayList<Draft> objectArrayList, Response response) { Log.w("Drafts", "Success"); displayResult(objectArrayList); } @Override public void failure(RetrofitError retrofitError) { Log.w("Drafts", "\nError Cause:" + retrofitError.getCause() + "\nError Message:" + retrofitError.getMessage()); stopSpinner(); showError(retrofitError.getMessage().toString()); } }); } else if (mInputCategoryTitle.equals("Test")) { ((SampleDetailsActivity)(SampleDetailsListFragment.this.getActivity())).progressBar.setVisibility(View.GONE); //Demo //inboxAppClient.testQueueUpdateTag(); //inboxAppClient.testQueueCreateTags(); //inboxAppClient.testQueueCreateDraft(); //inboxAppClient.testQueueSendDraftID(); inboxAppClient.testQueueSendDraftBody(); //todo: } } @Override public void onActivityCreated (Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); getListView().setDivider(new ColorDrawable(Color.GRAY)); getListView().setDividerHeight(3); } } }