Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: Application/src/main/java/org/chromium/customtabsclient/MainActivity.java

Issue 2787723002: [Android] Add public API for Browser Action in support library (Closed)
Patch Set: Update for the new comments from Yusuf. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Application/src/main/res/layout/main.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.browseractions.BrowserActionsIntent;
38 import android.support.customtabs.browseractions.BrowserActionItem;
37 import android.text.TextUtils; 39 import android.text.TextUtils;
38 import android.util.Log; 40 import android.util.Log;
39 import android.util.Pair; 41 import android.util.Pair;
40 import android.view.LayoutInflater; 42 import android.view.LayoutInflater;
41 import android.view.View; 43 import android.view.View;
42 import android.view.View.OnClickListener; 44 import android.view.View.OnClickListener;
45 import android.view.View.OnLongClickListener;
43 import android.view.ViewGroup; 46 import android.view.ViewGroup;
44 import android.widget.AdapterView; 47 import android.widget.AdapterView;
45 import android.widget.ArrayAdapter; 48 import android.widget.ArrayAdapter;
46 import android.widget.Button; 49 import android.widget.Button;
47 import android.widget.EditText; 50 import android.widget.EditText;
48 import android.widget.Spinner; 51 import android.widget.Spinner;
49 import android.widget.TextView; 52 import android.widget.TextView;
50 53
51 import org.chromium.customtabsclient.shared.CustomTabsHelper; 54 import org.chromium.customtabsclient.shared.CustomTabsHelper;
52 import org.chromium.customtabsclient.shared.ServiceConnection; 55 import org.chromium.customtabsclient.shared.ServiceConnection;
53 import org.chromium.customtabsclient.shared.ServiceConnectionCallback; 56 import org.chromium.customtabsclient.shared.ServiceConnectionCallback;
54 57
55 import java.util.ArrayList; 58 import java.util.ArrayList;
56 import java.util.List; 59 import java.util.List;
57 60
58 /** 61 /**
59 * Example client activity for using Chrome Custom Tabs. 62 * Example client activity for using Chrome Custom Tabs.
60 */ 63 */
61 public class MainActivity extends Activity implements OnClickListener, ServiceCo nnectionCallback { 64 public class MainActivity extends Activity
65 implements OnClickListener, ServiceConnectionCallback, OnLongClickListen er {
62 private static final String TAG = "CustomTabsClientExample"; 66 private static final String TAG = "CustomTabsClientExample";
63 private static final String TOOLBAR_COLOR = "#ef6c00"; 67 private static final String TOOLBAR_COLOR = "#ef6c00";
68 private static final String URL_STRING = "https://www.google.com";
64 69
65 private EditText mEditText; 70 private EditText mEditText;
66 private CustomTabsSession mCustomTabsSession; 71 private CustomTabsSession mCustomTabsSession;
67 private CustomTabsClient mClient; 72 private CustomTabsClient mClient;
68 private CustomTabsServiceConnection mConnection; 73 private CustomTabsServiceConnection mConnection;
69 private String mPackageNameToBind; 74 private String mPackageNameToBind;
70 private Button mConnectButton; 75 private Button mConnectButton;
71 private Button mWarmupButton; 76 private Button mWarmupButton;
72 private Button mMayLaunchButton; 77 private Button mMayLaunchButton;
73 private Button mLaunchButton; 78 private Button mLaunchButton;
74 private MediaPlayer mMediaPlayer; 79 private MediaPlayer mMediaPlayer;
80 private TextView mUrlLinkText;
75 81
76 /** 82 /**
77 * Once per second, asks the framework for the process importance, and logs any change. 83 * Once per second, asks the framework for the process importance, and logs any change.
78 */ 84 */
79 private Runnable mLogImportance = new Runnable() { 85 private Runnable mLogImportance = new Runnable() {
80 private int mPreviousImportance = -1; 86 private int mPreviousImportance = -1;
81 private boolean mPreviousServiceInUse = false; 87 private boolean mPreviousServiceInUse = false;
82 private Handler mHandler = new Handler(Looper.getMainLooper()); 88 private Handler mHandler = new Handler(Looper.getMainLooper());
83 89
84 @Override 90 @Override
(...skipping 25 matching lines...) Expand all
110 @Override 116 @Override
111 protected void onCreate(Bundle savedInstanceState) { 117 protected void onCreate(Bundle savedInstanceState) {
112 super.onCreate(savedInstanceState); 118 super.onCreate(savedInstanceState);
113 setContentView(R.layout.main); 119 setContentView(R.layout.main);
114 mEditText = (EditText) findViewById(R.id.edit); 120 mEditText = (EditText) findViewById(R.id.edit);
115 mConnectButton = (Button) findViewById(R.id.connect_button); 121 mConnectButton = (Button) findViewById(R.id.connect_button);
116 mWarmupButton = (Button) findViewById(R.id.warmup_button); 122 mWarmupButton = (Button) findViewById(R.id.warmup_button);
117 mMayLaunchButton = (Button) findViewById(R.id.may_launch_button); 123 mMayLaunchButton = (Button) findViewById(R.id.may_launch_button);
118 mLaunchButton = (Button) findViewById(R.id.launch_button); 124 mLaunchButton = (Button) findViewById(R.id.launch_button);
119 Spinner spinner = (Spinner) findViewById(R.id.spinner); 125 Spinner spinner = (Spinner) findViewById(R.id.spinner);
126 mUrlLinkText = (TextView) findViewById(R.id.url_link);
120 mEditText.requestFocus(); 127 mEditText.requestFocus();
121 mConnectButton.setOnClickListener(this); 128 mConnectButton.setOnClickListener(this);
122 mWarmupButton.setOnClickListener(this); 129 mWarmupButton.setOnClickListener(this);
123 mMayLaunchButton.setOnClickListener(this); 130 mMayLaunchButton.setOnClickListener(this);
124 mLaunchButton.setOnClickListener(this); 131 mLaunchButton.setOnClickListener(this);
125 mMediaPlayer = MediaPlayer.create(this, R.raw.amazing_grace); 132 mMediaPlayer = MediaPlayer.create(this, R.raw.amazing_grace);
133 mUrlLinkText.setText(URL_STRING);
134 mUrlLinkText.setOnLongClickListener(this);
126 135
127 Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http:/ /www.example.com")); 136 Intent activityIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http:/ /www.example.com"));
128 PackageManager pm = getPackageManager(); 137 PackageManager pm = getPackageManager();
129 List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities( 138 List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(
130 activityIntent, PackageManager.MATCH_ALL); 139 activityIntent, PackageManager.MATCH_ALL);
131 List<Pair<String, String>> packagesSupportingCustomTabs = new ArrayList< >(); 140 List<Pair<String, String>> packagesSupportingCustomTabs = new ArrayList< >();
132 for (ResolveInfo info : resolvedActivityList) { 141 for (ResolveInfo info : resolvedActivityList) {
133 Intent serviceIntent = new Intent(); 142 Intent serviceIntent = new Intent();
134 serviceIntent.setAction("android.support.customtabs.action.CustomTab sService"); 143 serviceIntent.setAction("android.support.customtabs.action.CustomTab sService");
135 serviceIntent.setPackage(info.activityInfo.packageName); 144 serviceIntent.setPackage(info.activityInfo.packageName);
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 } 297 }
289 298
290 @Override 299 @Override
291 public void onServiceDisconnected() { 300 public void onServiceDisconnected() {
292 mConnectButton.setEnabled(true); 301 mConnectButton.setEnabled(true);
293 mWarmupButton.setEnabled(false); 302 mWarmupButton.setEnabled(false);
294 mMayLaunchButton.setEnabled(false); 303 mMayLaunchButton.setEnabled(false);
295 mLaunchButton.setEnabled(false); 304 mLaunchButton.setEnabled(false);
296 mClient = null; 305 mClient = null;
297 } 306 }
307
308 @Override
309 public boolean onLongClick(View v) {
310 Bitmap icon = BitmapFactory.decodeResource(getResources(), R.drawable.ic _launcher);
311 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(URL_STRING));
312 PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
313 BrowserActionItem item =
314 new BrowserActionItem("Open the link (without icon)", pendingInt ent);
315 BrowserActionItem item2 =
316 new BrowserActionItem("Open the link (with icon)", pendingIntent , icon);
317 ArrayList<BrowserActionItem> items = new ArrayList<>();
318 items.add(item);
319 items.add(item2);
320 BrowserActionsIntent.openBrowserAction(this, Uri.parse(mUrlLinkText.getT ext().toString()),
321 BrowserActionsIntent.URL_TYPE_IMAGE, items);
322 return true;
323 }
298 } 324 }
OLDNEW
« no previous file with comments | « no previous file | Application/src/main/res/layout/main.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698