[Gradle] Allow dialer to be compiled as a library

This CL adds a new build-library.gradle file for AOSP dialer.
This allows the dialer to be built as a library that can be
included from GoogleDialer.

Switching to a library project meant making two other changes:
  - changed all switch statements that used resources to if statements.
    This was required because resource IDs are not final in library
    projects.
  - changed InCalUI code to import com.android.dialer.R instead of
    com.android.incallui.R. See http://b.android.com/82743 for more info
    on why this is required.

src-N isn't supported yet. Also, this isn't the ideal project layout.
In the future we should consider switching to the following layout:
  - dialer/incallui/ <- incall UI as an independent library project
  - dialer/dialerlib/ <- dialer code as an independent library project
  - dialer/app <- skelent app that builds a standalone dialer AOSP app

Bug: 26676586
Change-Id: I07fbee4d33cc683539e4f8b3953c93f1427af9d7
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 72753be..d507483 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -620,35 +620,30 @@
 
     @Override
     public void onClick(View view) {
-        switch (view.getId()) {
-            case R.id.floating_action_button:
-                if (mListsFragment.getCurrentTabIndex()
-                        == ListsFragment.TAB_INDEX_ALL_CONTACTS && !mInRegularSearch) {
-                    DialerUtils.startActivityWithErrorToast(
-                            this,
-                            IntentUtil.getNewContactIntent(),
-                            R.string.add_contact_not_available);
-                } else if (!mIsDialpadShown) {
-                    mInCallDialpadUp = false;
-                    showDialpadFragment(true);
-                }
-                break;
-            case R.id.voice_search_button:
-                try {
-                    startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
-                            ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
-                } catch (ActivityNotFoundException e) {
-                    Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
-                            Toast.LENGTH_SHORT).show();
-                }
-                break;
-            case R.id.dialtacts_options_menu_button:
-                mOverflowMenu.show();
-                break;
-            default: {
-                Log.wtf(TAG, "Unexpected onClick event from " + view);
-                break;
+        int resId = view.getId();
+        if (resId == R.id.floating_action_button) {
+            if (mListsFragment.getCurrentTabIndex()
+                    == ListsFragment.TAB_INDEX_ALL_CONTACTS && !mInRegularSearch) {
+                DialerUtils.startActivityWithErrorToast(
+                        this,
+                        IntentUtil.getNewContactIntent(),
+                        R.string.add_contact_not_available);
+            } else if (!mIsDialpadShown) {
+                mInCallDialpadUp = false;
+                showDialpadFragment(true);
             }
+        } else if (resId == R.id.voice_search_button) {
+            try {
+                startActivityForResult(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH),
+                        ACTIVITY_REQUEST_CODE_VOICE_SEARCH);
+            } catch (ActivityNotFoundException e) {
+                Toast.makeText(DialtactsActivity.this, R.string.voice_search_not_available,
+                        Toast.LENGTH_SHORT).show();
+            }
+        } else if (resId == R.id.dialtacts_options_menu_button) {
+            mOverflowMenu.show();
+        } else {
+            Log.wtf(TAG, "Unexpected onClick event from " + view);
         }
     }
 
@@ -658,41 +653,37 @@
             return true;
         }
 
-        switch (item.getItemId()) {
-            case R.id.menu_history:
-                // Use explicit CallLogActivity intent instead of ACTION_VIEW +
-                // CONTENT_TYPE, so that we always open our call log from our dialer
-                final Intent intent = new Intent(this, CallLogActivity.class);
-                startActivity(intent);
-                break;
-            case R.id.menu_add_contact:
-                DialerUtils.startActivityWithErrorToast(
-                        this,
-                        IntentUtil.getNewContactIntent(),
-                        R.string.add_contact_not_available);
-                break;
-            case R.id.menu_import_export:
-                // We hard-code the "contactsAreAvailable" argument because doing it properly would
-                // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
-                // now in Dialtacts for (potential) performance reasons. Compare with how it is
-                // done in {@link PeopleActivity}.
-                if (mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) {
-                    ImportExportDialogFragment.show(getFragmentManager(), true,
-                            DialtactsActivity.class, ImportExportDialogFragment.EXPORT_MODE_FAVORITES);
-                } else {
-                    ImportExportDialogFragment.show(getFragmentManager(), true,
-                            DialtactsActivity.class, ImportExportDialogFragment.EXPORT_MODE_DEFAULT);
-                }
-                Logger.logScreenView(ScreenEvent.IMPORT_EXPORT_CONTACTS, this);
-                return true;
-            case R.id.menu_clear_frequents:
-                ClearFrequentsDialog.show(getFragmentManager());
-                Logger.logScreenView(ScreenEvent.CLEAR_FREQUENTS, this);
-                return true;
-            case R.id.menu_call_settings:
-                handleMenuSettings();
-                Logger.logScreenView(ScreenEvent.SETTINGS, this);
-                return true;
+        int resId = item.getItemId();
+        if (resId == R.id.menu_history) {// Use explicit CallLogActivity intent instead of ACTION_VIEW +
+            // CONTENT_TYPE, so that we always open our call log from our dialer
+            final Intent intent = new Intent(this, CallLogActivity.class);
+            startActivity(intent);
+        } else if (resId == R.id.menu_add_contact) {
+            DialerUtils.startActivityWithErrorToast(
+                    this,
+                    IntentUtil.getNewContactIntent(),
+                    R.string.add_contact_not_available);
+        } else if (resId == R.id.menu_import_export) {// We hard-code the "contactsAreAvailable" argument because doing it properly would
+            // involve querying a {@link ProviderStatusLoader}, which we don't want to do right
+            // now in Dialtacts for (potential) performance reasons. Compare with how it is
+            // done in {@link PeopleActivity}.
+            if (mListsFragment.getCurrentTabIndex() == ListsFragment.TAB_INDEX_SPEED_DIAL) {
+                ImportExportDialogFragment.show(getFragmentManager(), true,
+                        DialtactsActivity.class, ImportExportDialogFragment.EXPORT_MODE_FAVORITES);
+            } else {
+                ImportExportDialogFragment.show(getFragmentManager(), true,
+                        DialtactsActivity.class, ImportExportDialogFragment.EXPORT_MODE_DEFAULT);
+            }
+            Logger.logScreenView(ScreenEvent.IMPORT_EXPORT_CONTACTS, this);
+            return true;
+        } else if (resId == R.id.menu_clear_frequents) {
+            ClearFrequentsDialog.show(getFragmentManager());
+            Logger.logScreenView(ScreenEvent.CLEAR_FREQUENTS, this);
+            return true;
+        } else if (resId == R.id.menu_call_settings) {
+            handleMenuSettings();
+            Logger.logScreenView(ScreenEvent.SETTINGS, this);
+            return true;
         }
         return false;
     }