1. Share intent to gather analytics files and make them shareable.
2. "Easter egg" to share analytics files by clicking 10 times in Wi-Fi icon and then long-pressing.
This commit is contained in:
secretrobotron 2016-07-18 12:13:07 -04:00
Родитель 0a34f5ae86
Коммит ee40ac5f94
2 изменённых файлов: 59 добавлений и 5 удалений

Просмотреть файл

@ -1,6 +1,8 @@
package com.mozilla.hackathon.kiboko;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.util.Log;
@ -20,11 +22,40 @@ import java.util.List;
public class Analytics {
private static final String ANALYTICS_FILENAME = "jisort_analytics.txt";
private static final String ANALYTICS_ARCHIVE_FILENAME = "jisort_analytics.1.txt";
private static final String ANALYTICS_FILENAME = ".jisort_analytics.txt";
private static final String ANALYTICS_ARCHIVE_FILENAME = ".jisort_analytics.1.txt";
private static final long TIME_BETWEEN_SAVES= 5000;
private static final long FILE_SIZE_LIMIT = 100000; //bytes
public static void shareAnalytics() {
Analytics.get().share();
}
private void share () {
File currentFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), ANALYTICS_FILENAME);
File oldFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), ANALYTICS_ARCHIVE_FILENAME);
ArrayList<Uri> files = new ArrayList<Uri>();
if (currentFile.exists()) {
files.add(Uri.fromFile(currentFile));
}
if (oldFile.exists()) {
files.add(Uri.fromFile(oldFile));
}
if (files.size() > 0) {
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_SEND_MULTIPLE);
intent.putExtra(Intent.EXTRA_SUBJECT, "Jisort Analytics Files");
intent.setType("text/plain");
intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, files);
App.getContext().startActivity(intent);
}
}
private class AnalyticsItem {
String mName;
String mData = null;
@ -77,8 +108,8 @@ public class Analytics {
}
private void copyOldAnalytics() throws IOException {
InputStream in = new FileInputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), ANALYTICS_FILENAME));
OutputStream out = new FileOutputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), ANALYTICS_ARCHIVE_FILENAME));
InputStream in = new FileInputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), ANALYTICS_FILENAME));
OutputStream out = new FileOutputStream(new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), ANALYTICS_ARCHIVE_FILENAME));
// Transfer bytes from in to out
byte[] buf = new byte[1024];
@ -115,7 +146,7 @@ public class Analytics {
if (isExternalStorageWritable()) {
try {
File outputFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS), ANALYTICS_FILENAME);
File outputFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), ANALYTICS_FILENAME);
if (!outputFile.exists()) {
outputFile.createNewFile();
}

Просмотреть файл

@ -29,6 +29,9 @@ public class IconsAdapter extends BaseAdapter implements Filterable {
private Filter topicFilter;
private List<IconTopic> origTopicList;
private int analyticsStartClicks = 0;
private final int ANALYTICS_CLICKS = 10;
public IconsAdapter(Context ctx, List<IconTopic> topics) {
this.topics = topics;
this.context = ctx;
@ -87,6 +90,19 @@ public class IconsAdapter extends BaseAdapter implements Filterable {
final IconTopic topic = topics.get(position);
holder.img.setImageResource(topic.getImage());
viewItem.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (analyticsStartClicks > ANALYTICS_CLICKS) {
Analytics.shareAnalytics();
return true;
}
else {
return false;
}
}
});
viewItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -101,6 +117,13 @@ public class IconsAdapter extends BaseAdapter implements Filterable {
.contentView(R.layout.tooltip_dso, R.id.tv_text)
.build();
if (topic.getTag().equals("wifi")) {
++analyticsStartClicks;
}
else {
analyticsStartClicks = 0;
}
TextView text = tooltip.findViewById(R.id.tv_title);
text.setText(topic.getTitle());