зеркало из https://github.com/mozilla/Jisort.git
Коммит
56ff763427
|
@ -0,0 +1,129 @@
|
|||
package com.mozilla.hackathon.kiboko;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by secretrobotron on 7/2/16.
|
||||
*/
|
||||
|
||||
public class Analytics {
|
||||
|
||||
private static final String ANALYTICS_FILENAME = "jisort_analytics.txt";
|
||||
private static final long TIME_BETWEEN_SAVES= 5000;
|
||||
|
||||
private class AnalyticsItem {
|
||||
String mName;
|
||||
String mData = null;
|
||||
Date mTime;
|
||||
|
||||
public AnalyticsItem(String name) {
|
||||
mName = name;
|
||||
mTime = new Date(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public AnalyticsItem(String name, String data) {
|
||||
mName = name;
|
||||
mData = data;
|
||||
mTime = new Date(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String output = "[" + mTime.toString() + "] " + mName;
|
||||
if (mData != null) {
|
||||
output += " -> (" + mData.toString() + ")";
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
protected static Analytics sAnalytics = null;
|
||||
|
||||
private List<AnalyticsItem> mItems;
|
||||
|
||||
private long mLastSaveTime = 0;
|
||||
|
||||
private Analytics() {
|
||||
mItems = new ArrayList<AnalyticsItem>();
|
||||
|
||||
// Prevent from saving right away.
|
||||
mLastSaveTime = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private void flushItems() {
|
||||
save(true);
|
||||
}
|
||||
|
||||
private void save() {
|
||||
save(false);
|
||||
}
|
||||
|
||||
private void save(boolean flush) {
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
if (!flush && now - mLastSaveTime < TIME_BETWEEN_SAVES) {
|
||||
return;
|
||||
}
|
||||
|
||||
mLastSaveTime = now;
|
||||
|
||||
String output = "";
|
||||
|
||||
// this should run every once in a while to save to perm memory
|
||||
for (AnalyticsItem item : mItems) {
|
||||
output += item.toString() + "\n";
|
||||
}
|
||||
|
||||
// Replace this with save to disk functionality
|
||||
FileOutputStream outputStream;
|
||||
|
||||
try {
|
||||
outputStream = App.getContext().openFileOutput(ANALYTICS_FILENAME, Context.MODE_PRIVATE | Context.MODE_APPEND);
|
||||
|
||||
outputStream.write(output.getBytes());
|
||||
outputStream.close();
|
||||
mItems.clear();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Don't just consume a whole bunch of memory if something is going wrong.
|
||||
if (mItems.size() > 100) {
|
||||
mItems.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addItem(String name, String data) {
|
||||
mItems.add(new AnalyticsItem(name, data));
|
||||
save();
|
||||
}
|
||||
|
||||
public void addItem(String name) {
|
||||
mItems.add(new AnalyticsItem(name));
|
||||
save();
|
||||
}
|
||||
|
||||
public static Analytics get() {
|
||||
// Generate one if it doesn't exist yet.
|
||||
if (sAnalytics == null) {
|
||||
sAnalytics = new Analytics();
|
||||
}
|
||||
return sAnalytics;
|
||||
}
|
||||
|
||||
public static void flush() {
|
||||
Analytics.get().flushItems();
|
||||
}
|
||||
|
||||
public static void add(String name, String data) {
|
||||
Analytics.get().addItem(name, data);
|
||||
}
|
||||
|
||||
public static void add(String name) {
|
||||
Analytics.get().addItem(name);
|
||||
}
|
||||
}
|
|
@ -22,6 +22,8 @@ import com.mozilla.hackathon.kiboko.widgets.MessageCardView;
|
|||
import com.squareup.otto.Bus;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import com.mozilla.hackathon.kiboko.Analytics;
|
||||
|
||||
public class DashboardActivity extends DSOActivity {
|
||||
public static boolean active = false;
|
||||
public static FragmentActivity mDashboard;
|
||||
|
@ -35,11 +37,13 @@ public class DashboardActivity extends DSOActivity {
|
|||
dashboard_summary = (LinearLayout) findViewById(R.id.dashboard_summary);
|
||||
mDashboard = DashboardActivity.this;
|
||||
bus.post(new NetworkStateChanged(false) );
|
||||
Analytics.add("Dashboard", "create");
|
||||
}
|
||||
|
||||
public void findIconsClicked(View view){
|
||||
Intent dashboardIntent = new Intent(this, FindIconsActivity.class);
|
||||
startActivity(dashboardIntent);
|
||||
Analytics.add("Dashboard::FindIcons", "click");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -63,6 +67,8 @@ public class DashboardActivity extends DSOActivity {
|
|||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
active = false;
|
||||
Analytics.add("Dashboard", "destroy");
|
||||
Analytics.flush();
|
||||
}
|
||||
|
||||
// method that will be called when the device posts an event NetworkStateChanged
|
||||
|
@ -87,9 +93,11 @@ public class DashboardActivity extends DSOActivity {
|
|||
dashboard_summary.removeView(wifiCard);
|
||||
|
||||
if(tag.equals("cancel")){
|
||||
Analytics.add("Dashboard::NetworkEvent", "dismiss");
|
||||
return;
|
||||
}
|
||||
|
||||
Analytics.add("Dashboard::NetworkEvent", "learn more");
|
||||
Intent dashboardIntent = new Intent(DashboardActivity.this, TutorialSlideActivity.class);
|
||||
dashboardIntent.putExtra("header","Wifi ni noma!");
|
||||
dashboardIntent.putExtra("topic","wifi");
|
||||
|
@ -122,9 +130,11 @@ public class DashboardActivity extends DSOActivity {
|
|||
dashboard_summary.removeView(wifiCard);
|
||||
|
||||
if(tag.equals("cancel")){
|
||||
Analytics.add("Dashboard::LowStorageEvent", "dismiss");
|
||||
return;
|
||||
}
|
||||
|
||||
Analytics.add("Dashboard::LowStorageEvent", "learn more");
|
||||
Intent dashboardIntent = new Intent(DashboardActivity.this, TutorialSlideActivity.class);
|
||||
dashboardIntent.putExtra("header","Freeing up Memory!");
|
||||
dashboardIntent.putExtra("topic","storage");
|
||||
|
@ -156,9 +166,11 @@ public class DashboardActivity extends DSOActivity {
|
|||
dashboard_summary.removeView(batteryCard);
|
||||
|
||||
if(tag.equals("cancel")){
|
||||
Analytics.add("Dashboard::BatteryEvent", "dismiss");
|
||||
return;
|
||||
}
|
||||
|
||||
Analytics.add("Dashboard::BatteryEvent", "learn more");
|
||||
Intent dashboardIntent = new Intent(DashboardActivity.this, TutorialSlideActivity.class);
|
||||
dashboardIntent.putExtra("title","Phone battery");
|
||||
dashboardIntent.putExtra("topic","battery");
|
||||
|
@ -189,9 +201,11 @@ public class DashboardActivity extends DSOActivity {
|
|||
dashboard_summary.removeView(batteryCard);
|
||||
|
||||
if(tag.equals("cancel")){
|
||||
Analytics.add("Dashboard::AirplaneModeEvent", "dismiss");
|
||||
return;
|
||||
}
|
||||
|
||||
Analytics.add("Dashboard::AirplaneModeEvent", "learn more");
|
||||
Intent dashboardIntent = new Intent(DashboardActivity.this, TutorialSlideActivity.class);
|
||||
dashboardIntent.putExtra("title","Airplane Mode");
|
||||
dashboardIntent.putExtra("topic","airplane_mode");
|
||||
|
@ -223,9 +237,11 @@ public class DashboardActivity extends DSOActivity {
|
|||
dashboard_summary.removeView(locationCard);
|
||||
|
||||
if(tag.equals("cancel")){
|
||||
Analytics.add("Dashboard::LocationEvent", "dismiss");
|
||||
return;
|
||||
}
|
||||
|
||||
Analytics.add("Dashboard::AirplaneModeEvent", "learn more");
|
||||
Intent dashboardIntent = new Intent(DashboardActivity.this, TutorialSlideActivity.class);
|
||||
dashboardIntent.putExtra("title","Using location services.");
|
||||
dashboardIntent.putExtra("topic","location");
|
||||
|
|
|
@ -11,6 +11,7 @@ import android.widget.Filterable;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mozilla.hackathon.kiboko.Analytics;
|
||||
import com.mozilla.hackathon.kiboko.R;
|
||||
import com.mozilla.hackathon.kiboko.activities.FindIconsActivity;
|
||||
import com.mozilla.hackathon.kiboko.activities.TutorialSlideActivity;
|
||||
|
@ -94,6 +95,7 @@ public class TopicsAdapter extends BaseAdapter implements Filterable {
|
|||
viewItem.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Analytics.add("TopicsAdapter::Clicked", topic.getTag());
|
||||
if(topic.getTag().equals("icons")){
|
||||
Intent topicIntent = new Intent(context, FindIconsActivity.class);
|
||||
// topicIntent.putExtra("topic", topic.getName());
|
||||
|
|
|
@ -16,6 +16,7 @@ import android.view.ViewGroup;
|
|||
import android.widget.CompoundButton;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.mozilla.hackathon.kiboko.Analytics;
|
||||
import com.mozilla.hackathon.kiboko.R;
|
||||
import com.mozilla.hackathon.kiboko.adapters.TopicsAdapter;
|
||||
import com.mozilla.hackathon.kiboko.models.Topic;
|
||||
|
@ -98,7 +99,9 @@ public class TopicsFragment extends ListFragment implements CompoundButton.OnChe
|
|||
case R.id.toggleSwitch:
|
||||
if(!isChecked){
|
||||
getContext().stopService(new Intent(getContext(), ChatHeadService.class));
|
||||
Analytics.add("TopicsFragment::FABSwitch", "off");
|
||||
}else{
|
||||
Analytics.add("TopicsFragment::FABSwitch", "on");
|
||||
if(!isServiceRunning()){
|
||||
if(Utils.canDrawOverlays(getContext()))
|
||||
startOverlayService();
|
||||
|
|
|
@ -19,6 +19,7 @@ import android.view.View.OnTouchListener;
|
|||
import android.view.WindowManager;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
import com.mozilla.hackathon.kiboko.Analytics;
|
||||
import com.mozilla.hackathon.kiboko.R;
|
||||
import com.mozilla.hackathon.kiboko.activities.DashboardActivity;
|
||||
import com.mozilla.hackathon.kiboko.events.BatteryStateChanged;
|
||||
|
@ -366,6 +367,7 @@ public class ChatHeadService extends Service {
|
|||
* Open application
|
||||
*/
|
||||
private void openAppClicked() {
|
||||
Analytics.add("ChatHeadService::Clicked");
|
||||
switchToNormalHead();
|
||||
Intent dashboardIntent = new Intent(this, DashboardActivity.class);
|
||||
dashboardIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
|
Загрузка…
Ссылка в новой задаче