-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Sample) Add floating menus for phone, email and map addresses
- Loading branch information
Showing
9 changed files
with
250 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
sample/src/main/java/me/saket/bettermovementmethod/sample/EmailFloatingMenu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package me.saket.bettermovementmethod.sample; | ||
|
||
import android.content.ClipData; | ||
import android.content.ClipboardManager; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
public class EmailFloatingMenu extends BaseFloatingMenu { | ||
|
||
public static void show(Context context, View anchorView, String emailAddress) { | ||
new EmailFloatingMenu(context, anchorView, emailAddress).show(); | ||
} | ||
|
||
private EmailFloatingMenu(Context context, View anchorView, String phoneAddress) { | ||
super(context, anchorView, phoneAddress); | ||
} | ||
|
||
@Override | ||
protected int getMenuLayout() { | ||
return R.layout.floating_menu_email; | ||
} | ||
|
||
@Override | ||
protected void handleMenuClick(int menuItemId) { | ||
switch (menuItemId) { | ||
case R.id.btn_email: | ||
onEmailAddressClick(); | ||
break; | ||
|
||
case R.id.btn_copy: | ||
onCopyAddressClick(); | ||
break; | ||
} | ||
} | ||
|
||
private void onEmailAddressClick() { | ||
Intent dialIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse(getURL())); | ||
getContext().startActivity(dialIntent); | ||
} | ||
|
||
private void onCopyAddressClick() { | ||
final ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); | ||
final ClipData clip = ClipData.newPlainText(getContext().getPackageName(), getURL()); | ||
clipboard.setPrimaryClip(clip); | ||
Toast.makeText(getContext(), "Copied to clipboard", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
sample/src/main/java/me/saket/bettermovementmethod/sample/FloatingMenuPhone.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package me.saket.bettermovementmethod.sample; | ||
|
||
import android.content.ClipData; | ||
import android.content.ClipboardManager; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.provider.ContactsContract; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
public class FloatingMenuPhone extends BaseFloatingMenu { | ||
|
||
public static void show(Context context, View anchorView, String phoneAddress) { | ||
new FloatingMenuPhone(context, anchorView, phoneAddress).show(); | ||
} | ||
|
||
private FloatingMenuPhone(Context context, View anchorView, String phoneAddress) { | ||
super(context, anchorView, phoneAddress); | ||
} | ||
|
||
@Override | ||
protected int getMenuLayout() { | ||
return R.layout.floating_menu_phone_number; | ||
} | ||
|
||
@Override | ||
protected void handleMenuClick(int menuItemId) { | ||
switch (menuItemId) { | ||
case R.id.btn_call: | ||
onCallAddressClick(); | ||
break; | ||
|
||
case R.id.btn_compose_sms: | ||
onComposeNewSmsClick(); | ||
break; | ||
|
||
case R.id.btn_copy: | ||
onCopyAddressClick(); | ||
break; | ||
|
||
case R.id.btn_save: | ||
onAddToContactsClick(); | ||
break; | ||
} | ||
} | ||
|
||
private void onCallAddressClick() { | ||
Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse(getURL())).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | ||
getContext().startActivity(dialIntent); | ||
} | ||
|
||
private void onComposeNewSmsClick() { | ||
Intent smsIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + getURL())); | ||
getContext().startActivity(smsIntent); | ||
} | ||
|
||
private void onCopyAddressClick() { | ||
final ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); | ||
final ClipData clip = ClipData.newPlainText(getContext().getPackageName(), getURL()); | ||
clipboard.setPrimaryClip(clip); | ||
Toast.makeText(getContext(), "Copied to clipboard", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
private void onAddToContactsClick() { | ||
final Intent addContactIntent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT); | ||
addContactIntent.putExtra("finishActivityOnSaveCompleted", true); | ||
addContactIntent.setData(Uri.fromParts("tel", getURL(), null)); | ||
addContactIntent.putExtra(ContactsContract.Intents.EXTRA_FORCE_CREATE, true); | ||
getContext().startActivity(addContactIntent); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
sample/src/main/java/me/saket/bettermovementmethod/sample/MapFloatingMenu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package me.saket.bettermovementmethod.sample; | ||
|
||
import android.content.Context; | ||
import android.view.View; | ||
import android.widget.Toast; | ||
|
||
public class MapFloatingMenu extends BaseFloatingMenu { | ||
|
||
public static void show(Context context, View anchorView, String mapAddress) { | ||
new MapFloatingMenu(context, anchorView, mapAddress).show(); | ||
} | ||
|
||
private MapFloatingMenu(Context context, View anchorView, String phoneAddress) { | ||
super(context, anchorView, phoneAddress); | ||
} | ||
|
||
@Override | ||
protected int getMenuLayout() { | ||
return R.layout.floating_menu_map; | ||
} | ||
|
||
@Override | ||
protected void handleMenuClick(int menuItemId) { | ||
Toast.makeText(getContext(), "Just kidding", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
tools:ignore="HardcodedText"> | ||
|
||
<Button | ||
android:id="@+id/btn_email" | ||
style="@style/Button.FloatingMenu" | ||
android:text="Email" /> | ||
|
||
<Button | ||
android:id="@+id/btn_copy" | ||
style="@style/Button.FloatingMenu" | ||
android:text="Copy" /> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
tools:ignore="HardcodedText"> | ||
|
||
<Button | ||
android:id="@+id/btn_navigate" | ||
style="@style/Button.FloatingMenu" | ||
android:text="Navigate" /> | ||
|
||
<Button | ||
android:id="@+id/btn_open" | ||
style="@style/Button.FloatingMenu" | ||
android:text="Open" /> | ||
</LinearLayout> |
File renamed without changes.