From d23f92585705942c70e3e4308f800ffe5f416ca9 Mon Sep 17 00:00:00 2001 From: "Hoa V. DINH" Date: Sat, 10 Jan 2015 14:11:27 -0800 Subject: Added example for Android --- example/android/AndroidExample/.gitignore | 6 + example/android/AndroidExample/AndroidExample.iml | 21 +++ example/android/AndroidExample/app/.gitignore | 1 + example/android/AndroidExample/app/app.iml | 91 ++++++++++ example/android/AndroidExample/app/build.gradle | 35 ++++ .../android/AndroidExample/app/proguard-rules.pro | 17 ++ .../app/src/main/AndroidManifest.xml | 49 ++++++ .../libmailcore/androidexample/MessageAdapter.java | 18 ++ .../androidexample/MessageViewDetailActivity.java | 70 ++++++++ .../androidexample/MessageViewDetailFragment.java | 84 +++++++++ .../androidexample/MessageViewListActivity.java | 87 ++++++++++ .../androidexample/MessageViewListFragment.java | 191 +++++++++++++++++++++ .../androidexample/MessagesSyncManager.java | 34 ++++ .../app/src/main/res/drawable-hdpi/ic_launcher.png | Bin 0 -> 9397 bytes .../app/src/main/res/drawable-mdpi/ic_launcher.png | Bin 0 -> 5237 bytes .../src/main/res/drawable-xhdpi/ic_launcher.png | Bin 0 -> 14383 bytes .../src/main/res/drawable-xxhdpi/ic_launcher.png | Bin 0 -> 19388 bytes .../layout-sw600dp/activity_messageview_list.xml | 23 +++ .../res/layout/activity_messageview_detail.xml | 5 + .../main/res/layout/activity_messageview_list.xml | 7 + .../res/layout/fragment_messageview_detail.xml | 5 + .../app/src/main/res/values-v21/styles.xml | 5 + .../app/src/main/res/values/dimens.xml | 5 + .../app/src/main/res/values/strings.xml | 8 + .../src/main/res/values/strings_activity_login.xml | 15 ++ .../app/src/main/res/values/styles.xml | 8 + example/android/AndroidExample/build.gradle | 19 ++ example/android/AndroidExample/gradle.properties | 18 ++ .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 49896 bytes .../gradle/wrapper/gradle-wrapper.properties | 6 + example/android/AndroidExample/gradlew | 164 ++++++++++++++++++ example/android/AndroidExample/gradlew.bat | 90 ++++++++++ example/android/AndroidExample/settings.gradle | 1 + 33 files changed, 1083 insertions(+) create mode 100644 example/android/AndroidExample/.gitignore create mode 100644 example/android/AndroidExample/AndroidExample.iml create mode 100644 example/android/AndroidExample/app/.gitignore create mode 100644 example/android/AndroidExample/app/app.iml create mode 100644 example/android/AndroidExample/app/build.gradle create mode 100644 example/android/AndroidExample/app/proguard-rules.pro create mode 100644 example/android/AndroidExample/app/src/main/AndroidManifest.xml create mode 100644 example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageAdapter.java create mode 100644 example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewDetailActivity.java create mode 100644 example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewDetailFragment.java create mode 100644 example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewListActivity.java create mode 100644 example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewListFragment.java create mode 100644 example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessagesSyncManager.java create mode 100644 example/android/AndroidExample/app/src/main/res/drawable-hdpi/ic_launcher.png create mode 100644 example/android/AndroidExample/app/src/main/res/drawable-mdpi/ic_launcher.png create mode 100644 example/android/AndroidExample/app/src/main/res/drawable-xhdpi/ic_launcher.png create mode 100644 example/android/AndroidExample/app/src/main/res/drawable-xxhdpi/ic_launcher.png create mode 100644 example/android/AndroidExample/app/src/main/res/layout-sw600dp/activity_messageview_list.xml create mode 100644 example/android/AndroidExample/app/src/main/res/layout/activity_messageview_detail.xml create mode 100644 example/android/AndroidExample/app/src/main/res/layout/activity_messageview_list.xml create mode 100644 example/android/AndroidExample/app/src/main/res/layout/fragment_messageview_detail.xml create mode 100644 example/android/AndroidExample/app/src/main/res/values-v21/styles.xml create mode 100644 example/android/AndroidExample/app/src/main/res/values/dimens.xml create mode 100644 example/android/AndroidExample/app/src/main/res/values/strings.xml create mode 100644 example/android/AndroidExample/app/src/main/res/values/strings_activity_login.xml create mode 100644 example/android/AndroidExample/app/src/main/res/values/styles.xml create mode 100644 example/android/AndroidExample/build.gradle create mode 100644 example/android/AndroidExample/gradle.properties create mode 100644 example/android/AndroidExample/gradle/wrapper/gradle-wrapper.jar create mode 100644 example/android/AndroidExample/gradle/wrapper/gradle-wrapper.properties create mode 100755 example/android/AndroidExample/gradlew create mode 100644 example/android/AndroidExample/gradlew.bat create mode 100644 example/android/AndroidExample/settings.gradle (limited to 'example') diff --git a/example/android/AndroidExample/.gitignore b/example/android/AndroidExample/.gitignore new file mode 100644 index 00000000..afbdab33 --- /dev/null +++ b/example/android/AndroidExample/.gitignore @@ -0,0 +1,6 @@ +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build diff --git a/example/android/AndroidExample/AndroidExample.iml b/example/android/AndroidExample/AndroidExample.iml new file mode 100644 index 00000000..2a022014 --- /dev/null +++ b/example/android/AndroidExample/AndroidExample.iml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/example/android/AndroidExample/app/.gitignore b/example/android/AndroidExample/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/example/android/AndroidExample/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/example/android/AndroidExample/app/app.iml b/example/android/AndroidExample/app/app.iml new file mode 100644 index 00000000..cdd2cdf5 --- /dev/null +++ b/example/android/AndroidExample/app/app.iml @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/android/AndroidExample/app/build.gradle b/example/android/AndroidExample/app/build.gradle new file mode 100644 index 00000000..54a946ef --- /dev/null +++ b/example/android/AndroidExample/app/build.gradle @@ -0,0 +1,35 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 21 + buildToolsVersion "21.1.1" + + defaultConfig { + applicationId "com.libmailcore.androidexample" + minSdkVersion 21 + targetSdkVersion 21 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +repositories { + flatDir { + dirs 'libs' + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + compile fileTree(dir: 'libs', include: ['*.jar']) + compile(name: 'mailcore2-android-1', ext: 'aar') + compile 'com.android.support:support-v4:21.0.2' + compile 'com.google.android.gms:play-services:6.5.87' + compile 'com.android.support:appcompat-v7:21.0.2' +} diff --git a/example/android/AndroidExample/app/proguard-rules.pro b/example/android/AndroidExample/app/proguard-rules.pro new file mode 100644 index 00000000..3c2c65b2 --- /dev/null +++ b/example/android/AndroidExample/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/hoa/Android/android-sdk-macosx/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/example/android/AndroidExample/app/src/main/AndroidManifest.xml b/example/android/AndroidExample/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..58481ab8 --- /dev/null +++ b/example/android/AndroidExample/app/src/main/AndroidManifest.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageAdapter.java b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageAdapter.java new file mode 100644 index 00000000..86781ce6 --- /dev/null +++ b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageAdapter.java @@ -0,0 +1,18 @@ +package com.libmailcore.androidexample; + +import com.libmailcore.IMAPMessage; + +/** + * Created by hoa on 1/9/15. + */ +public class MessageAdapter { + IMAPMessage message; + + public MessageAdapter(IMAPMessage msg) { + message = msg; + } + + public String toString() { + return message.header().from().displayName() + " " + message.header().extractedSubject(); + } +} diff --git a/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewDetailActivity.java b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewDetailActivity.java new file mode 100644 index 00000000..e12f71b1 --- /dev/null +++ b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewDetailActivity.java @@ -0,0 +1,70 @@ +package com.libmailcore.androidexample; + +import android.content.Intent; +import android.os.Bundle; +import android.app.Activity; + +import android.view.MenuItem; + + +/** + * An activity representing a single MessageView detail screen. This + * activity is only used on handset devices. On tablet-size devices, + * item details are presented side-by-side with a list of items + * in a {@link MessageViewListActivity}. + *

+ * This activity is mostly just a 'shell' activity containing nothing + * more than a {@link MessageViewDetailFragment}. + */ +public class MessageViewDetailActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_messageview_detail); + + // Show the Up button in the action bar. + getActionBar().setDisplayHomeAsUpEnabled(true); + + // savedInstanceState is non-null when there is fragment state + // saved from previous configurations of this activity + // (e.g. when rotating the screen from portrait to landscape). + // In this case, the fragment will automatically be re-added + // to its container so we don't need to manually add it. + // For more information, see the Fragments API guide at: + // + // http://developer.android.com/guide/components/fragments.html + // + if (savedInstanceState == null) { + // Create the detail fragment and add it to the activity + // using a fragment transaction. + /* + Bundle arguments = new Bundle(); + arguments.putString(MessageViewDetailFragment.ARG_ITEM_ID, + getIntent().getStringExtra(MessageViewDetailFragment.ARG_ITEM_ID)); + */ + + MessageViewDetailFragment fragment = new MessageViewDetailFragment(); + //fragment.setArguments(arguments); + getFragmentManager().beginTransaction() + .add(R.id.messageview_detail_container, fragment) + .commit(); + } + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + if (id == android.R.id.home) { + // This ID represents the Home or Up button. In the case of this + // activity, the Up button is shown. For + // more details, see the Navigation pattern on Android Design: + // + // http://developer.android.com/design/patterns/navigation.html#up-vs-back + // + navigateUpTo(new Intent(this, MessageViewListActivity.class)); + return true; + } + return super.onOptionsItemSelected(item); + } +} diff --git a/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewDetailFragment.java b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewDetailFragment.java new file mode 100644 index 00000000..4fd80282 --- /dev/null +++ b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewDetailFragment.java @@ -0,0 +1,84 @@ +package com.libmailcore.androidexample; + +import android.os.Bundle; +import android.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.webkit.WebView; +import android.util.Log; + + +import com.libmailcore.MailException; +import com.libmailcore.OperationCallback; +import com.libmailcore.IMAPMessage; +import com.libmailcore.IMAPMessageRenderingOperation; + +/** + * A fragment representing a single MessageView detail screen. + * This fragment is either contained in a {@link MessageViewListActivity} + * in two-pane mode (on tablets) or a {@link MessageViewDetailActivity} + * on handsets. + */ +public class MessageViewDetailFragment extends Fragment implements OperationCallback { + /** + * The fragment argument representing the item ID that this fragment + * represents. + */ + public static final String ARG_ITEM_ID = "item_id"; + + /** + * The dummy content this fragment is presenting. + */ + //private DummyContent.DummyItem mItem; + private IMAPMessage message; + + /** + * Mandatory empty constructor for the fragment manager to instantiate the + * fragment (e.g. upon screen orientation changes). + */ + public MessageViewDetailFragment() { + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + /* + if (getArguments().containsKey(ARG_ITEM_ID)) { + // Load the dummy content specified by the fragment + // arguments. In a real-world scenario, use a Loader + // to load content from a content provider. + mItem = DummyContent.ITEM_MAP.get(getArguments().getString(ARG_ITEM_ID)); + } + */ + message = MessagesSyncManager.singleton().currentMessage; + } + + private IMAPMessageRenderingOperation renderingOp; + private WebView webView; + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_messageview_detail, container, false); + webView = (WebView) rootView.findViewById(R.id.messageview_detail); + + if (message != null) { + Log.d("detail", "message: " + message); + renderingOp = MessagesSyncManager.singleton().session.htmlRenderingOperation(message, "INBOX"); + renderingOp.start(this); + } + + return rootView; + } + + public void succeeded() { + String html = renderingOp.result(); + webView.loadData(html, "text/html", "utf-8"); + } + + public void failed(MailException exception) { + + } +} diff --git a/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewListActivity.java b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewListActivity.java new file mode 100644 index 00000000..e0115a69 --- /dev/null +++ b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewListActivity.java @@ -0,0 +1,87 @@ +package com.libmailcore.androidexample; + +import android.content.Intent; +import android.os.Bundle; +import android.app.Activity; +import com.libmailcore.IMAPSession; +import com.libmailcore.MailException; +import com.libmailcore.OperationCallback; +import com.libmailcore.IMAPMessage; + +/** + * An activity representing a list of MessagesViews. This activity + * has different presentations for handset and tablet-size devices. On + * handsets, the activity presents a list of items, which when touched, + * lead to a {@link MessageViewDetailActivity} representing + * item details. On tablets, the activity presents the list of items and + * item details side-by-side using two vertical panes. + *

+ * The activity makes heavy use of fragments. The list of items is a + * {@link MessageViewListFragment} and the item details + * (if present) is a {@link MessageViewDetailFragment}. + *

+ * This activity also implements the required + * {@link MessageViewListFragment.Callbacks} interface + * to listen for item selections. + */ +public class MessageViewListActivity extends Activity + implements MessageViewListFragment.Callbacks { + + /** + * Whether or not the activity is in two-pane mode, i.e. running on a tablet + * device. + */ + private boolean mTwoPane; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_messageview_list); + + if (findViewById(R.id.messageview_detail_container) != null) { + // The detail container view will be present only in the + // large-screen layouts (res/values-large and + // res/values-sw600dp). If this view is present, then the + // activity should be in two-pane mode. + mTwoPane = true; + + // In two-pane mode, list items should be given the + // 'activated' state when touched. + ((MessageViewListFragment) getFragmentManager() + .findFragmentById(R.id.messageview_list)) + .setActivateOnItemClick(true); + } + + // TODO: If exposing deep links into your app, handle intents here. + } + + /** + * Callback method from {@link MessageViewListFragment.Callbacks} + * indicating that the item with the given ID was selected. + */ + @Override + public void onItemSelected(IMAPMessage msg) { + if (mTwoPane) { + // In two-pane mode, show the detail view in this activity by + // adding or replacing the detail fragment using a + // fragment transaction. + MessagesSyncManager.singleton().currentMessage = msg; + + //Bundle arguments = new Bundle(); + //arguments.putString(MessageViewDetailFragment.ARG_ITEM_ID, msg); + MessageViewDetailFragment fragment = new MessageViewDetailFragment(); + //fragment.setArguments(arguments); + getFragmentManager().beginTransaction() + .replace(R.id.messageview_detail_container, fragment) + .commit(); + + } else { + // In single-pane mode, simply start the detail activity + // for the selected item ID. + MessagesSyncManager.singleton().currentMessage = msg; + Intent detailIntent = new Intent(this, MessageViewDetailActivity.class); + //detailIntent.putExtra(MessageViewDetailFragment.ARG_ITEM_ID, id); + startActivity(detailIntent); + } + } +} diff --git a/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewListFragment.java b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewListFragment.java new file mode 100644 index 00000000..b39c51ac --- /dev/null +++ b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessageViewListFragment.java @@ -0,0 +1,191 @@ +package com.libmailcore.androidexample; + +import android.app.Activity; +import android.os.Bundle; +import android.app.ListFragment; +import android.view.View; +import android.widget.ArrayAdapter; +import android.widget.ListView; +import android.util.Log; + +import java.util.ArrayList; + +import com.libmailcore.IMAPFetchMessagesOperation; +import com.libmailcore.IMAPMessage; +import com.libmailcore.MailException; +import com.libmailcore.OperationCallback; +//import com.libmailcore.androidexample.dummy.DummyContent; +import com.libmailcore.IndexSet; +import com.libmailcore.IMAPMessagesRequestKind; +import com.libmailcore.Range; + +/** + * A list fragment representing a list of MessagesViews. This fragment + * also supports tablet devices by allowing list items to be given an + * 'activated' state upon selection. This helps indicate which item is + * currently being viewed in a {@link MessageViewDetailFragment}. + *

+ * Activities containing this fragment MUST implement the {@link Callbacks} + * interface. + */ +public class MessageViewListFragment extends ListFragment implements OperationCallback { + + /** + * The serialization (saved instance state) Bundle key representing the + * activated item position. Only used on tablets. + */ + private static final String STATE_ACTIVATED_POSITION = "activated_position"; + + /** + * The fragment's current callback object, which is notified of list item + * clicks. + */ + private Callbacks mCallbacks = sDummyCallbacks; + + /** + * The current activated item position. Only used on tablets. + */ + private int mActivatedPosition = ListView.INVALID_POSITION; + + /** + * A callback interface that all activities containing this fragment must + * implement. This mechanism allows activities to be notified of item + * selections. + */ + public interface Callbacks { + /** + * Callback for when an item has been selected. + */ + public void onItemSelected(IMAPMessage msg); + } + + /** + * A dummy implementation of the {@link Callbacks} interface that does + * nothing. Used only when this fragment is not attached to an activity. + */ + private static Callbacks sDummyCallbacks = new Callbacks() { + @Override + public void onItemSelected(IMAPMessage msg) { + } + }; + + /** + * Mandatory empty constructor for the fragment manager to instantiate the + * fragment (e.g. upon screen orientation changes). + */ + public MessageViewListFragment() { + } + + private IMAPFetchMessagesOperation fetchMessagesOp; + private ArrayAdapter adapter; + private java.util.List messages; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + fetchMessagesOp = MessagesSyncManager.singleton().session.fetchMessagesByNumberOperation("INBOX", IMAPMessagesRequestKind.IMAPMessagesRequestKindHeaders | IMAPMessagesRequestKind.IMAPMessagesRequestKindStructure, IndexSet.indexSetWithRange(new Range(1, Range.RangeMax))); + fetchMessagesOp.start(this); + } + + @Override + public void onViewCreated(View view, Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + // Restore the previously serialized activated item position. + if (savedInstanceState != null + && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) { + setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION)); + } + } + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + + // Activities containing this fragment must implement its callbacks. + if (!(activity instanceof Callbacks)) { + throw new IllegalStateException("Activity must implement fragment's callbacks."); + } + + mCallbacks = (Callbacks) activity; + } + + @Override + public void onDetach() { + super.onDetach(); + + // Reset the active callbacks interface to the dummy implementation. + mCallbacks = sDummyCallbacks; + } + + @Override + public void onListItemClick(ListView listView, View view, int position, long id) { + super.onListItemClick(listView, view, position, id); + + // Notify the active callbacks interface (the activity, if the + // fragment is attached to one) that an item has been selected. +// mCallbacks.onItemSelected(DummyContent.ITEMS.get(position).id); + Log.d("msglist", "row clicked: " + id); + mCallbacks.onItemSelected(messages.get((int) id)); + } + + @Override + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + if (mActivatedPosition != ListView.INVALID_POSITION) { + // Serialize and persist the activated item position. + outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition); + } + } + + /** + * Turns on activate-on-click mode. When this mode is on, list items will be + * given the 'activated' state when touched. + */ + public void setActivateOnItemClick(boolean activateOnItemClick) { + // When setting CHOICE_MODE_SINGLE, ListView will automatically + // give items the 'activated' state when touched. + getListView().setChoiceMode(activateOnItemClick + ? ListView.CHOICE_MODE_SINGLE + : ListView.CHOICE_MODE_NONE); + } + + private void setActivatedPosition(int position) { + if (position == ListView.INVALID_POSITION) { + getListView().setItemChecked(mActivatedPosition, false); + } else { + getListView().setItemChecked(position, true); + } + + mActivatedPosition = position; + } + + public void succeeded() { + messages = fetchMessagesOp.messages(); + updateResult(); + } + + public void failed(MailException exception) { + + } + + private void updateResult() { + + Log.d("msglist", "update result"); + ArrayList array = new ArrayList(); + for(IMAPMessage msg : messages) { + MessageAdapter msgAdapter = new MessageAdapter(msg); + array.add(msgAdapter); + } + adapter = new ArrayAdapter( + getActivity(), + android.R.layout.simple_list_item_activated_1, + android.R.id.text1, + array); + + // TODO: replace with a real list adapter. + setListAdapter(adapter); + + } +} diff --git a/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessagesSyncManager.java b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessagesSyncManager.java new file mode 100644 index 00000000..3c25e2bf --- /dev/null +++ b/example/android/AndroidExample/app/src/main/java/com/libmailcore/androidexample/MessagesSyncManager.java @@ -0,0 +1,34 @@ +package com.libmailcore.androidexample; + +import com.libmailcore.ConnectionType; +import com.libmailcore.IMAPFetchMessagesOperation; +import com.libmailcore.IMAPSession; +import com.libmailcore.IMAPMessage; + +/** + * Created by hoa on 1/8/15. + */ +public class MessagesSyncManager { + public IMAPSession session; + public IMAPMessage currentMessage; + + static private MessagesSyncManager theSingleton; + + public static MessagesSyncManager singleton() { + if (theSingleton == null) { + theSingleton = new MessagesSyncManager(); + } + return theSingleton; + } + + private MessagesSyncManager() { + session = new IMAPSession(); + session.setUsername("login@gmail.com"); + session.setPassword("password"); + session.setHostname("imap.gmail.com"); + session.setPort(993); + session.setConnectionType(ConnectionType.ConnectionTypeTLS); + } + + +} diff --git a/example/android/AndroidExample/app/src/main/res/drawable-hdpi/ic_launcher.png b/example/android/AndroidExample/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 00000000..96a442e5 Binary files /dev/null and b/example/android/AndroidExample/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/example/android/AndroidExample/app/src/main/res/drawable-mdpi/ic_launcher.png b/example/android/AndroidExample/app/src/main/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 00000000..359047df Binary files /dev/null and b/example/android/AndroidExample/app/src/main/res/drawable-mdpi/ic_launcher.png differ diff --git a/example/android/AndroidExample/app/src/main/res/drawable-xhdpi/ic_launcher.png b/example/android/AndroidExample/app/src/main/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 00000000..71c6d760 Binary files /dev/null and b/example/android/AndroidExample/app/src/main/res/drawable-xhdpi/ic_launcher.png differ diff --git a/example/android/AndroidExample/app/src/main/res/drawable-xxhdpi/ic_launcher.png b/example/android/AndroidExample/app/src/main/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 00000000..4df18946 Binary files /dev/null and b/example/android/AndroidExample/app/src/main/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/example/android/AndroidExample/app/src/main/res/layout-sw600dp/activity_messageview_list.xml b/example/android/AndroidExample/app/src/main/res/layout-sw600dp/activity_messageview_list.xml new file mode 100644 index 00000000..9b211bda --- /dev/null +++ b/example/android/AndroidExample/app/src/main/res/layout-sw600dp/activity_messageview_list.xml @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/example/android/AndroidExample/app/src/main/res/layout/activity_messageview_detail.xml b/example/android/AndroidExample/app/src/main/res/layout/activity_messageview_detail.xml new file mode 100644 index 00000000..fa100d0b --- /dev/null +++ b/example/android/AndroidExample/app/src/main/res/layout/activity_messageview_detail.xml @@ -0,0 +1,5 @@ + diff --git a/example/android/AndroidExample/app/src/main/res/layout/activity_messageview_list.xml b/example/android/AndroidExample/app/src/main/res/layout/activity_messageview_list.xml new file mode 100644 index 00000000..039f69b1 --- /dev/null +++ b/example/android/AndroidExample/app/src/main/res/layout/activity_messageview_list.xml @@ -0,0 +1,7 @@ + diff --git a/example/android/AndroidExample/app/src/main/res/layout/fragment_messageview_detail.xml b/example/android/AndroidExample/app/src/main/res/layout/fragment_messageview_detail.xml new file mode 100644 index 00000000..d1ecbf75 --- /dev/null +++ b/example/android/AndroidExample/app/src/main/res/layout/fragment_messageview_detail.xml @@ -0,0 +1,5 @@ + diff --git a/example/android/AndroidExample/app/src/main/res/values-v21/styles.xml b/example/android/AndroidExample/app/src/main/res/values-v21/styles.xml new file mode 100644 index 00000000..dba3c417 --- /dev/null +++ b/example/android/AndroidExample/app/src/main/res/values-v21/styles.xml @@ -0,0 +1,5 @@ + + + + diff --git a/example/android/AndroidExample/app/src/main/res/values/dimens.xml b/example/android/AndroidExample/app/src/main/res/values/dimens.xml new file mode 100644 index 00000000..47c82246 --- /dev/null +++ b/example/android/AndroidExample/app/src/main/res/values/dimens.xml @@ -0,0 +1,5 @@ + + + 16dp + 16dp + diff --git a/example/android/AndroidExample/app/src/main/res/values/strings.xml b/example/android/AndroidExample/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..986a9ee4 --- /dev/null +++ b/example/android/AndroidExample/app/src/main/res/values/strings.xml @@ -0,0 +1,8 @@ + + + + AndroidExample + MessagesViews + MessageView Detail + + diff --git a/example/android/AndroidExample/app/src/main/res/values/strings_activity_login.xml b/example/android/AndroidExample/app/src/main/res/values/strings_activity_login.xml new file mode 100644 index 00000000..9f1a810f --- /dev/null +++ b/example/android/AndroidExample/app/src/main/res/values/strings_activity_login.xml @@ -0,0 +1,15 @@ + + Sign in + + + Email + Password (optional) + Sign in or register + Sign in + Switch Google+ account + Disconnect from Google+ + This email address is invalid + This password is too short + This password is incorrect + This field is required + diff --git a/example/android/AndroidExample/app/src/main/res/values/styles.xml b/example/android/AndroidExample/app/src/main/res/values/styles.xml new file mode 100644 index 00000000..ff6c9d2c --- /dev/null +++ b/example/android/AndroidExample/app/src/main/res/values/styles.xml @@ -0,0 +1,8 @@ + + + + + + diff --git a/example/android/AndroidExample/build.gradle b/example/android/AndroidExample/build.gradle new file mode 100644 index 00000000..6356aabd --- /dev/null +++ b/example/android/AndroidExample/build.gradle @@ -0,0 +1,19 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + repositories { + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.0.0' + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + jcenter() + } +} diff --git a/example/android/AndroidExample/gradle.properties b/example/android/AndroidExample/gradle.properties new file mode 100644 index 00000000..1d3591c8 --- /dev/null +++ b/example/android/AndroidExample/gradle.properties @@ -0,0 +1,18 @@ +# Project-wide Gradle settings. + +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. + +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html + +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +# Default value: -Xmx10248m -XX:MaxPermSize=256m +# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 + +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true \ No newline at end of file diff --git a/example/android/AndroidExample/gradle/wrapper/gradle-wrapper.jar b/example/android/AndroidExample/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 00000000..8c0fb64a Binary files /dev/null and b/example/android/AndroidExample/gradle/wrapper/gradle-wrapper.jar differ diff --git a/example/android/AndroidExample/gradle/wrapper/gradle-wrapper.properties b/example/android/AndroidExample/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 00000000..0c71e760 --- /dev/null +++ b/example/android/AndroidExample/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Apr 10 15:27:10 PDT 2013 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip diff --git a/example/android/AndroidExample/gradlew b/example/android/AndroidExample/gradlew new file mode 100755 index 00000000..91a7e269 --- /dev/null +++ b/example/android/AndroidExample/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/example/android/AndroidExample/gradlew.bat b/example/android/AndroidExample/gradlew.bat new file mode 100644 index 00000000..aec99730 --- /dev/null +++ b/example/android/AndroidExample/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/example/android/AndroidExample/settings.gradle b/example/android/AndroidExample/settings.gradle new file mode 100644 index 00000000..e7b4def4 --- /dev/null +++ b/example/android/AndroidExample/settings.gradle @@ -0,0 +1 @@ +include ':app' -- cgit v1.2.3