Skip to content

Commit

Permalink
Add a Chrome custom tab to the app and a timer to time how long the u…
Browse files Browse the repository at this point in the history
…ser visits it. (#89)

* playing with chrome custom tabs

* Add a chrome custom tab, and a timer to times how long it was visited.
  • Loading branch information
jkwatson authored Jul 23, 2021
1 parent d69c2ec commit 24895b8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions sample-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {

implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.webkit:webkit:1.4.0'
implementation "androidx.browser:browser:1.3.0"
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.navigation:navigation-fragment:2.3.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package com.splunk.android.sample;

import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
Expand Down Expand Up @@ -52,13 +54,24 @@ public class SecondFragment extends Fragment {
private FragmentSecondBinding binding;
private Tracer sampleAppTracer;

private Span customChromeTabTimer;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
sampleAppTracer = SplunkRum.getInstance().getOpenTelemetry().getTracer("sampleAppTracer");
binding = FragmentSecondBinding.inflate(inflater, container, false);
return binding.getRoot();
}

@Override
public void onResume() {
super.onResume();
if (customChromeTabTimer != null) {
customChromeTabTimer.end();
customChromeTabTimer = null;
}
}

@Override
public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Expand All @@ -83,6 +96,18 @@ public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
binding.buttonToWebview.setOnClickListener(v ->
NavHostFragment.findNavController(SecondFragment.this)
.navigate(R.id.action_SecondFragment_to_webViewFragment));

binding.buttonToCustomTab.setOnClickListener(v -> {
String url = "https://ssidhu.o11ystore.com/";
customChromeTabTimer = SplunkRum.getInstance().startWorkflow("Visit to Chrome Custom Tab");
new CustomTabsIntent.Builder()
.setColorScheme(CustomTabsIntent.COLOR_SCHEME_DARK)
.setStartAnimations(getContext(), android.R.anim.slide_in_left, android.R.anim.slide_out_right)
.setExitAnimations(getContext(), android.R.anim.slide_out_right, android.R.anim.slide_in_left)
.build()
.launchUrl(this.getContext(), Uri.parse(url));
});

binding.buttonSpam.setOnClickListener(v -> toggleSpam());

binding.buttonFreeze.setOnClickListener(v -> {
Expand Down
7 changes: 7 additions & 0 deletions sample-app/src/main/res/layout/fragment_second.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
android:layout_marginTop="8dp"
android:text="@string/next" />

<Button
android:id="@+id/button_to_custom_tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/custom_tab" />

<Button
android:id="@+id/button_second"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions sample-app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
<string name="spam_status">Created %d spans</string>
<string name="freeze">Freeze!</string>
<string name="work_it">Work it!</string>
<string name="custom_tab">Chrome</string>
</resources>

0 comments on commit 24895b8

Please sign in to comment.