Chromium Code Reviews| Index: Application/src/main/java/org/chromium/customtabsclient/MainActivity.java |
| diff --git a/Application/src/main/java/org/chromium/customtabsclient/MainActivity.java b/Application/src/main/java/org/chromium/customtabsclient/MainActivity.java |
| index 3869244cee572333caeea51e034c1c504bc72027..6a60e7ae5f84cb66d166f6da14f61d8d99f888d3 100644 |
| --- a/Application/src/main/java/org/chromium/customtabsclient/MainActivity.java |
| +++ b/Application/src/main/java/org/chromium/customtabsclient/MainActivity.java |
| @@ -34,12 +34,16 @@ import android.support.customtabs.CustomTabsClient; |
| import android.support.customtabs.CustomTabsIntent; |
| import android.support.customtabs.CustomTabsServiceConnection; |
| import android.support.customtabs.CustomTabsSession; |
| +import android.support.customtabs.browseraction.BrowserActionCreator; |
| +import android.support.customtabs.browseraction.BrowserActionIntent; |
| +import android.support.customtabs.browseraction.BrowserActionItem; |
| import android.text.TextUtils; |
| import android.util.Log; |
| import android.util.Pair; |
| import android.view.LayoutInflater; |
| import android.view.View; |
| import android.view.View.OnClickListener; |
| +import android.view.View.OnLongClickListener; |
| import android.view.ViewGroup; |
| import android.widget.AdapterView; |
| import android.widget.ArrayAdapter; |
| @@ -58,9 +62,11 @@ import java.util.List; |
| /** |
| * Example client activity for using Chrome Custom Tabs. |
| */ |
| -public class MainActivity extends Activity implements OnClickListener, ServiceConnectionCallback { |
| +public class MainActivity extends Activity |
| + implements OnClickListener, ServiceConnectionCallback, OnLongClickListener { |
| private static final String TAG = "CustomTabsClientExample"; |
| private static final String TOOLBAR_COLOR = "#ef6c00"; |
| + private static final String URL_STRING = "https://www.example.com"; |
| private EditText mEditText; |
| private CustomTabsSession mCustomTabsSession; |
| @@ -72,6 +78,7 @@ public class MainActivity extends Activity implements OnClickListener, ServiceCo |
| private Button mMayLaunchButton; |
| private Button mLaunchButton; |
| private MediaPlayer mMediaPlayer; |
| + private TextView mUrlLinkText; |
| /** |
| * Once per second, asks the framework for the process importance, and logs any change. |
| @@ -117,12 +124,15 @@ public class MainActivity extends Activity implements OnClickListener, ServiceCo |
| mMayLaunchButton = (Button) findViewById(R.id.may_launch_button); |
| mLaunchButton = (Button) findViewById(R.id.launch_button); |
| Spinner spinner = (Spinner) findViewById(R.id.spinner); |
| + mUrlLinkText = (TextView) findViewById(R.id.url_link); |
|
Yusuf
2017/04/03 18:00:48
We will need another TextView above for an explana
ltian
2017/04/05 01:44:28
Done.
|
| mEditText.requestFocus(); |
| mConnectButton.setOnClickListener(this); |
| mWarmupButton.setOnClickListener(this); |
| mMayLaunchButton.setOnClickListener(this); |
| mLaunchButton.setOnClickListener(this); |
| mMediaPlayer = MediaPlayer.create(this, R.raw.amazing_grace); |
| + mUrlLinkText.setText(URL_STRING); |
| + mUrlLinkText.setOnLongClickListener(this); |
| Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.example.com")); |
| PackageManager pm = getPackageManager(); |
| @@ -295,4 +305,19 @@ public class MainActivity extends Activity implements OnClickListener, ServiceCo |
| mLaunchButton.setEnabled(false); |
| mClient = null; |
| } |
| + |
| + @Override |
| + public boolean onLongClick(View v) { |
| + Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic_share); |
| + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_STRING)); |
| + PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); |
| + BrowserActionItem item = new BrowserActionItem("Custom Item1", pendingIntent); |
| + BrowserActionItem item2 = new BrowserActionItem("Share", pendingIntent, icon); |
| + ArrayList<BrowserActionItem> items = new ArrayList<>(); |
| + items.add(item); |
| + items.add(item2); |
| + BrowserActionCreator.create(this, mUrlLinkText.getText().toString(), |
| + BrowserActionIntent.MEDIA_TYPE_IMAGE, items); |
| + return true; |
| + } |
| } |