Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 Google Inc. All Rights Reserved. | 1 // Copyright 2015 Google Inc. All Rights Reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 import android.media.MediaPlayer; | 27 import android.media.MediaPlayer; |
| 28 import android.net.Uri; | 28 import android.net.Uri; |
| 29 import android.os.Bundle; | 29 import android.os.Bundle; |
| 30 import android.os.Handler; | 30 import android.os.Handler; |
| 31 import android.os.Looper; | 31 import android.os.Looper; |
| 32 import android.support.customtabs.CustomTabsCallback; | 32 import android.support.customtabs.CustomTabsCallback; |
| 33 import android.support.customtabs.CustomTabsClient; | 33 import android.support.customtabs.CustomTabsClient; |
| 34 import android.support.customtabs.CustomTabsIntent; | 34 import android.support.customtabs.CustomTabsIntent; |
| 35 import android.support.customtabs.CustomTabsServiceConnection; | 35 import android.support.customtabs.CustomTabsServiceConnection; |
| 36 import android.support.customtabs.CustomTabsSession; | 36 import android.support.customtabs.CustomTabsSession; |
| 37 import android.support.customtabs.browseraction.BrowserActionCreator; | |
| 38 import android.support.customtabs.browseraction.BrowserActionIntent; | |
| 39 import android.support.customtabs.browseraction.BrowserActionItem; | |
| 37 import android.text.TextUtils; | 40 import android.text.TextUtils; |
| 38 import android.util.Log; | 41 import android.util.Log; |
| 39 import android.util.Pair; | 42 import android.util.Pair; |
| 40 import android.view.LayoutInflater; | 43 import android.view.LayoutInflater; |
| 41 import android.view.View; | 44 import android.view.View; |
| 42 import android.view.View.OnClickListener; | 45 import android.view.View.OnClickListener; |
| 46 import android.view.View.OnLongClickListener; | |
| 43 import android.view.ViewGroup; | 47 import android.view.ViewGroup; |
| 44 import android.widget.AdapterView; | 48 import android.widget.AdapterView; |
| 45 import android.widget.ArrayAdapter; | 49 import android.widget.ArrayAdapter; |
| 46 import android.widget.Button; | 50 import android.widget.Button; |
| 47 import android.widget.EditText; | 51 import android.widget.EditText; |
| 48 import android.widget.Spinner; | 52 import android.widget.Spinner; |
| 49 import android.widget.TextView; | 53 import android.widget.TextView; |
| 50 | 54 |
| 51 import org.chromium.customtabsclient.shared.CustomTabsHelper; | 55 import org.chromium.customtabsclient.shared.CustomTabsHelper; |
| 52 import org.chromium.customtabsclient.shared.ServiceConnection; | 56 import org.chromium.customtabsclient.shared.ServiceConnection; |
| 53 import org.chromium.customtabsclient.shared.ServiceConnectionCallback; | 57 import org.chromium.customtabsclient.shared.ServiceConnectionCallback; |
| 54 | 58 |
| 55 import java.util.ArrayList; | 59 import java.util.ArrayList; |
| 56 import java.util.List; | 60 import java.util.List; |
| 57 | 61 |
| 58 /** | 62 /** |
| 59 * Example client activity for using Chrome Custom Tabs. | 63 * Example client activity for using Chrome Custom Tabs. |
| 60 */ | 64 */ |
| 61 public class MainActivity extends Activity implements OnClickListener, ServiceCo nnectionCallback { | 65 public class MainActivity extends Activity |
| 66 implements OnClickListener, ServiceConnectionCallback, OnLongClickListen er { | |
| 62 private static final String TAG = "CustomTabsClientExample"; | 67 private static final String TAG = "CustomTabsClientExample"; |
| 63 private static final String TOOLBAR_COLOR = "#ef6c00"; | 68 private static final String TOOLBAR_COLOR = "#ef6c00"; |
| 69 private static final String URL_STRING = "https://www.example.com"; | |
| 64 | 70 |
| 65 private EditText mEditText; | 71 private EditText mEditText; |
| 66 private CustomTabsSession mCustomTabsSession; | 72 private CustomTabsSession mCustomTabsSession; |
| 67 private CustomTabsClient mClient; | 73 private CustomTabsClient mClient; |
| 68 private CustomTabsServiceConnection mConnection; | 74 private CustomTabsServiceConnection mConnection; |
| 69 private String mPackageNameToBind; | 75 private String mPackageNameToBind; |
| 70 private Button mConnectButton; | 76 private Button mConnectButton; |
| 71 private Button mWarmupButton; | 77 private Button mWarmupButton; |
| 72 private Button mMayLaunchButton; | 78 private Button mMayLaunchButton; |
| 73 private Button mLaunchButton; | 79 private Button mLaunchButton; |
| 74 private MediaPlayer mMediaPlayer; | 80 private MediaPlayer mMediaPlayer; |
| 81 private TextView mUrlLinkText; | |
| 75 | 82 |
| 76 /** | 83 /** |
| 77 * Once per second, asks the framework for the process importance, and logs any change. | 84 * Once per second, asks the framework for the process importance, and logs any change. |
| 78 */ | 85 */ |
| 79 private Runnable mLogImportance = new Runnable() { | 86 private Runnable mLogImportance = new Runnable() { |
| 80 private int mPreviousImportance = -1; | 87 private int mPreviousImportance = -1; |
| 81 private boolean mPreviousServiceInUse = false; | 88 private boolean mPreviousServiceInUse = false; |
| 82 private Handler mHandler = new Handler(Looper.getMainLooper()); | 89 private Handler mHandler = new Handler(Looper.getMainLooper()); |
| 83 | 90 |
| 84 @Override | 91 @Override |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 110 @Override | 117 @Override |
| 111 protected void onCreate(Bundle savedInstanceState) { | 118 protected void onCreate(Bundle savedInstanceState) { |
| 112 super.onCreate(savedInstanceState); | 119 super.onCreate(savedInstanceState); |
| 113 setContentView(R.layout.main); | 120 setContentView(R.layout.main); |
| 114 mEditText = (EditText) findViewById(R.id.edit); | 121 mEditText = (EditText) findViewById(R.id.edit); |
| 115 mConnectButton = (Button) findViewById(R.id.connect_button); | 122 mConnectButton = (Button) findViewById(R.id.connect_button); |
| 116 mWarmupButton = (Button) findViewById(R.id.warmup_button); | 123 mWarmupButton = (Button) findViewById(R.id.warmup_button); |
| 117 mMayLaunchButton = (Button) findViewById(R.id.may_launch_button); | 124 mMayLaunchButton = (Button) findViewById(R.id.may_launch_button); |
| 118 mLaunchButton = (Button) findViewById(R.id.launch_button); | 125 mLaunchButton = (Button) findViewById(R.id.launch_button); |
| 119 Spinner spinner = (Spinner) findViewById(R.id.spinner); | 126 Spinner spinner = (Spinner) findViewById(R.id.spinner); |
| 127 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.
| |
| 120 mEditText.requestFocus(); | 128 mEditText.requestFocus(); |
| 121 mConnectButton.setOnClickListener(this); | 129 mConnectButton.setOnClickListener(this); |
| 122 mWarmupButton.setOnClickListener(this); | 130 mWarmupButton.setOnClickListener(this); |
| 123 mMayLaunchButton.setOnClickListener(this); | 131 mMayLaunchButton.setOnClickListener(this); |
| 124 mLaunchButton.setOnClickListener(this); | 132 mLaunchButton.setOnClickListener(this); |
| 125 mMediaPlayer = MediaPlayer.create(this, R.raw.amazing_grace); | 133 mMediaPlayer = MediaPlayer.create(this, R.raw.amazing_grace); |
| 134 mUrlLinkText.setText(URL_STRING); | |
| 135 mUrlLinkText.setOnLongClickListener(this); | |
| 126 | 136 |
| 127 Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http:/ /www.example.com")); | 137 Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http:/ /www.example.com")); |
| 128 PackageManager pm = getPackageManager(); | 138 PackageManager pm = getPackageManager(); |
| 129 List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities( | 139 List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities( |
| 130 activityIntent, PackageManager.MATCH_ALL); | 140 activityIntent, PackageManager.MATCH_ALL); |
| 131 List<Pair<String, String>> packagesSupportingCustomTabs = new ArrayList< >(); | 141 List<Pair<String, String>> packagesSupportingCustomTabs = new ArrayList< >(); |
| 132 for (ResolveInfo info : resolvedActivityList) { | 142 for (ResolveInfo info : resolvedActivityList) { |
| 133 Intent serviceIntent = new Intent(); | 143 Intent serviceIntent = new Intent(); |
| 134 serviceIntent.setAction("android.support.customtabs.action.CustomTab sService"); | 144 serviceIntent.setAction("android.support.customtabs.action.CustomTab sService"); |
| 135 serviceIntent.setPackage(info.activityInfo.packageName); | 145 serviceIntent.setPackage(info.activityInfo.packageName); |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 } | 298 } |
| 289 | 299 |
| 290 @Override | 300 @Override |
| 291 public void onServiceDisconnected() { | 301 public void onServiceDisconnected() { |
| 292 mConnectButton.setEnabled(true); | 302 mConnectButton.setEnabled(true); |
| 293 mWarmupButton.setEnabled(false); | 303 mWarmupButton.setEnabled(false); |
| 294 mMayLaunchButton.setEnabled(false); | 304 mMayLaunchButton.setEnabled(false); |
| 295 mLaunchButton.setEnabled(false); | 305 mLaunchButton.setEnabled(false); |
| 296 mClient = null; | 306 mClient = null; |
| 297 } | 307 } |
| 308 | |
| 309 @Override | |
| 310 public boolean onLongClick(View v) { | |
| 311 Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic _share); | |
| 312 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_STRING)); | |
| 313 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0); | |
| 314 BrowserActionItem item = new BrowserActionItem("Custom Item1", pendingIn tent); | |
| 315 BrowserActionItem item2 = new BrowserActionItem("Share", pendingIntent, icon); | |
| 316 ArrayList<BrowserActionItem> items = new ArrayList<>(); | |
| 317 items.add(item); | |
| 318 items.add(item2); | |
| 319 BrowserActionCreator.create(this, mUrlLinkText.getText().toString(), | |
| 320 BrowserActionIntent.MEDIA_TYPE_IMAGE, items); | |
| 321 return true; | |
| 322 } | |
| 298 } | 323 } |
| OLD | NEW |