Track Share events to FirebaseAnalytics - firebase-analytics

I have a share function on the app that allows users to share app to others, but I want to track number of shares. The share item is on the action bar, not on the app dropdown menu.
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
//some other code here for items search item
//share menu item
MenuItem shareItem = menu.findItem(R.id.menu_item_share);
// Fetch and store ShareActionProvider
mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(shareItem);
String playStoreLink = Constants.PLAYSTORE_LINK + getPackageName();
String shareText = "Install app" + playStoreLink;
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setType("text/plain").setText(shareText).getIntent();
// Set the share Intent
mShareActionProvider.setShareIntent(shareIntent);
return true;
}
I have managed to implement tracking on other events by simply adding code in onClick() events but share event doesnt have onClick.
Code for tracking events example
Bundle param = new Bundle();
param.putString("call_data", "1");
mFirebaseAnalytics.logEvent("calls_made", param);

I've been strugling with the exact challenge, the quick answer is NO.
BUT, you can create your own share dialog in which you can detect on which app the user chose to share and then use analytics as desired:
Find the solution here
Another solution with ShareActionProvider

Related

How to Get Selected Item From LibGDX List?

I’ve tried a few different methods to get a selected item from a list (see code below), but everything I’ve tried only returns the first item in the list no matter which item was actually selected. Visually it appears to work because the correct item gets highlighted when it is clicked on.
As a general overview of what I’m trying to do, I have a folder that contains all of the saved preset files (json files), then I read the names of all the files into a list of strings, from this list a specific preset can be selected, and then I have a separate “load” textbutton that loads the item that was selected from the list. But as mentioned above, the correct item is not loaded from the list when the load button is clicked.
Here is my code:
public class PresetLoadMenu extends Menu {
private GUI gui;
private SaveManager saveManager;
private Table scrollPaneContainerTable;
private ScrollPane scrollPane;
private Table scrollTable;
private List<String> presetList;
private TextButton loadButton;
private FileHandle rootFolderHandle = Gdx.files.external(“presets/”);
public PresetLoadMenu(GUI gui){
this.gui = gui;
refreshList();
scrollTable = new Table();
scrollTable.add(presetList);
scrollPane = new ScrollPane(scrollTable);
scrollPaneContainerTable = new Table();
scrollPaneContainerTable.add(scrollPane).size(this.getWidth(), this.getHeight()*.2f);
add(scrollPaneContainerTable);
row();
loadButton = new TextButton("LOAD", gui.menuStyles.getMenuOkCancelButtonStyle());
loadButton.addCaptureListener(new ChangeListener(){
#Override
public void changed(ChangeEvent event, Actor actor){
// METHOD 1:
// System.out.println("SELECTED PRESET: " + presetList.getSelected());
// METHOD 2:
// System.out.println("SELECTED PRESET: " + presetList.getSelection().getLastSelected());
// METHOD 3:
// for (int i=0; i<presetList.getSelection().size(); i++){
// System.out.println("INDEX: " + i + " SELECTED PRESET: " + presetList.getSelection().toArray().get(i));
// }
}
});
add(loadButton).size(loadButton.getWidth(), loadButton.getHeight());
}
public void refreshList(){
FileHandle[] files = rootFolderHandle.list();
Array<String> namesArray = new Array<String>();
for(FileHandle file: files) {
namesArray.add(file.name());
}
presetList = new List<String>(gui.menuStyles.getListStyle());
presetList.setItems(namesArray);
}
}
The last method I tried using a for loop just to see if it would print out the other items that I clicked on, but it still printed the first item just one time and didn't detect that I had clicked on any of the other items.
On request I'm copying my last comment as an answer in order to close my question.
The problem was actually something else outside of the class that I posted, so presetList.getSelected() may work just fine now that I figured out what the problem was. But before I figured it out, I had swapped out the List for a ButtonGroup, which is actually better for me than using the List anyways so it worked out. The List has a built in listener that selects the item on touch down, so items would get selected when trying to scroll up or down. With a button I can have a listener just for the checked state, which is what I want.
Based on your answer, I solved it by creating a table of TextButton (buttonTable) , every of them initialize with an string:
final TextButton button = new TextButton("my string",skin);
and a listener:
button.addListener(new ClickListener() {
public void clicked (InputEvent event, float x, float y) {
button.getText()));
}
});
This buttonTable initialize a ScrollPane to allow vertical scrolling:
scrollPane = new ScrollPane(buttonsTable);
This scrollPane was added to table used to format my form:
mainTable.add(scrollPane);
This table was the actor added to the stage:
stage.addActor(mainTable);

"Events type" in java

My program contain two classes, one represent the main program and the other one is a gui implemented using swing,
I'm trying to create an "event type", meaning I want my main program to wait until the UserInterface (GUI) will indicate some event, like pressing a button, and I would like to sends some information when my button is pressed.
General Code for the main program (this is the relevant section)
// Open window GUI with the requested BID and wait for confirmation or denial
HumanIFWindow nextWindowGUI = new HumanIFWindow();
nextWindowGUI.setVisible(true);
// ----------------- //
// - Wait on event - //
// ----------------- //
// Here is where I want to wait for the gui Indication
return returnedBid;
Code for the GUI (Again only relevant part)
JButton btnAprove = new JButton("Aprove");
btnAprove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// ----------------- //
// - Trigger event - //
// ----------------- //
// Here is where I want to trigger the event
}});
Preferably I would like to use some library, is there's one that match my needs?
(Maybe BusEvent?)
Edit to specify the question (Thanks Kishan Sarsecha Gajjar)
I want the first class (the general one) to enter a wait statement, I know how to wait using:
while( someBoolean...)
Thread.sleep(...)
and I can change someBoolean with a handle in the GUI class, Like:
FisrtClass.someBoolean == False
But I want something nicer and neater, like a library that Implements the sleep statement. and there's no additional code needed. Is there something like that?
I've looked at Google-BusEvent library but I'm not sure if that's compatible
EDIT, adding JDialog
updated code: Main program:
Bid returnedBid = requestBid;
// Open window GUI with the requested BID and wait for confirmation
DialogHumanConfirmManual nextWindowGUI = new DialogHumanConfirmManual(requestBid);
// Wait on event
if ( (returnedBid = nextWindowGUI.getAnswer()) != null ){
System.out.println("Got Bid " + returnedBid.print());
}
GUI - Dialog:
public DialogHumanConfirmManual(Bid requestedBid){
currentBid = requestedBid;
currentBid.approvedHuman = false;
Dialog mainFrame = new Dialog(new Frame());
myPanel = new JPanel();
getContentPane().add(myPanel);
myPanel.add(new JLabel("Confirmation Dialog"));
yesButton = new JButton("Confirm");
yesButton.addActionListener(this);
myPanel.add(yesButton);
noButton = new JButton("No");
noButton.addActionListener(this);
myPanel.add(noButton);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if (yesButton == e.getSource()) {
currentBid.approvedHuman = true;
answeredBid = currentBid;
}
}
After opening the Dialog the if ( returnBid ) is called, which result in Null Pointer Exception later on in the code, So How can I delay the main program until the user can Confirm the request??
the other one is a gui implemented using swing,
Use a modal JDialog not a JFrame.
Once the dialog is made visible, the code after the setVisible(true) statement will NOT execute until the dialog is closed.
Read the section from the Swing tutorial on How to Make Dialogs for more information. The tutorial covers the JOptionPane class, but you can just use a JDialog, which is created exactly the same way a JFrame is. You can choose whether to use a JOptionPane or JDialog depending on your exact requirement.

how can i set the selectedIndex in a listPicker which i retrieve for isolatedStorageSettings in windows phone 8

I am developing a windows phone 8 app in which i have to use listPicker control. I need to save the selectedIndex from selected item in listPicker, in isolatedStorageSettings to be able to use it when the app opens. I want the saved index to be the selected index in my listPicker when the apps runs again. I have tried to do this with the onnavigatedto and onnavigatedfrom methods in the page in which i have the control. The problem is when i change se selected item and return back from full mode, the selected item does not change. I had searched this problem heare again and i didn't found the solution yet. How can i solve it?
Sorry for my English
I followed this settings_sample for the general setup by modifying the ListBox example. I ran into several problems trying to use a ListPicker with isolated storage like this.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff769510(v=vs.105).aspx
I removed the databindings for the ListPicker, set the SelectedIndex after initializing, and stored the SelectedIndex in isolated storage on SelectionChanged after the first occurrence of loading the page. It's a roundabout solution, but my searches came up empty.
public List<string> daysOfWeek = new List<string>() { "Sunday", "Monday", "etc" };
public int listPickerCounter = 0;
public Settings()
{
InitializeComponent();
BuildLocalizedApplicationBar();
// Fill listPicker with string items
this.listPicker.ItemsSource = daysOfWeek;
// Set SelectedIndex = IsolatedStorage Variable
if (IsolatedStorageSettings.ApplicationSettings.Contains("ListPickerSetting"))
{
this.listPicker.SelectedIndex = (int)IsolatedStorageSettings.ApplicationSettings["ListPickerSetting"];
}
}
On SelectionChanged update the isolated storage after the first occurrence of loading page.
private void listPicker_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (listPickerCounter > 0 && IsolatedStorageSettings.ApplicationSettings.Contains("ListPickerSetting"))
{
IsolatedStorageSettings.ApplicationSettings["ListPickerSetting"] = (int)this.listPicker.SelectedIndex;
}
listPickerCounter++;
}
Edit: forgot to add another reference that really helped understand isolated storage.
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj714090(v=vs.105).aspx

Posting from AS3 to Twitter

I've got a main menu and a game which loads as a separate swf from that menu. So far when the player enters their name at the start on the main menu I can get this name to post to Twitter. Also when the player completes the game I get post their time onto Twitter.
The problem is that I want to take the name posted from the main menu and dispatch it and only when the player completed the game post their time and name to Twitter.
Code in main menu to dispatch name:
[CODE]
var NameTextField:TextField = new TextField();
var MyFormat:TextFormat = new TextFormat();
addChild(NameTextField);
SubmitButton.addEventListener(MouseEvent.CLICK, SubmitClicked);
function SubmitClicked(e:MouseEvent)
{
dispatchEvent(new Event(NameTextField.text, true));
trace (NameTextField.text);
NameTextField.selectable = false;
}
[/CODE]
Code in game to receive name and post time to twitter.
[CODE]
navigateToURL(new URLRequest('http://twitter.com/home?status='+encodeURIComponent(+NameTextField.text+" completed Game"+' in a time of '+HourText.text+':'+MinuteText.text+':'+SecondText.text+'')),'_blank');
[/CODE]
In order to post to twitter you need to be authenticated.
I suggest you use an existing api like Tweetr by swfjunkie_com or Twitter-ActionScript-API by Denis Borisenko
Check this post for a sample code and for more details
http://www.redcodelabs.com/2012/02/actionscript3-twitter-api/
I assume you have twitter authentication already taken care of..
So when user enters the name on main menu you can save the name into save global variable in javascript like
var name = "some name";
and call ExternalInterface from as3 when user is done playing
like
ExternalInterface.call('getName'..
in js you should have a function like
function getName() { return name; }

how to display a video from a JList?

I am currently doing an application using Swing and i am stuck at a certain point. In my function, i have to link videos from a JList. The problem is i am not sure how to link the videos from the JList. I am using an OpenBrowser class to link the video to the internet. I did consider using JButton but i would have to hardcode it and that would be ugly. Is there any other alternatives to do this? I am in desperate need and would be eternally grateful to whoever that can help me.
Safa :)
If you don't want to open a browser with the video using a selection listener, you can consider the idea of launching it with a double click on a JList entry.
sample code
String[] items = {"i1", "i2", "i3", "i4"};
JList list = new JList(items);
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
JList list = (JList)evt.getSource();
if (evt.getClickCount() == 2) { //check if it is a Double-click
int index = list.locationToIndex(evt.getPoint());
// do whatever you want with the entry at that index
}
}
});
Desktp classes to browse some site (sample code):
if (desktop.isSupported(Desktop.Action.BROWSE)) {
URI uri = new URI("http://www.google.com");
desktop.browse(uri);
}
The desktop.browse() call will open your favourite browser with the given URL.