add neko metrics
Bug: 29878060 Change-Id: I0b1c7fdcb6bd065c3f31147894cca90f110f0213
This commit is contained in:
@@ -28,6 +28,7 @@ import java.util.Random;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import com.android.egg.R;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
|
||||
public class Cat extends Drawable {
|
||||
public static final long[] PURR = {0, 40, 20, 40, 20, 40, 20, 40, 20, 40, 20, 40};
|
||||
@@ -37,6 +38,8 @@ public class Cat extends Drawable {
|
||||
private long mSeed;
|
||||
private String mName;
|
||||
private int mBodyColor;
|
||||
private int mFootType;
|
||||
private boolean mBowTie;
|
||||
|
||||
private synchronized Random notSoRandom(long seed) {
|
||||
if (mNotSoRandom == null) {
|
||||
@@ -66,6 +69,15 @@ public class Cat extends Drawable {
|
||||
return a[i+1];
|
||||
}
|
||||
|
||||
public static final int getColorIndex(int q, int[] a) {
|
||||
for(int i = 1; i < a.length; i+=2) {
|
||||
if (a[i] == q) {
|
||||
return i/2;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static final int[] P_BODY_COLORS = {
|
||||
180, 0xFF212121, // black
|
||||
180, 0xFFFFFFFF, // white
|
||||
@@ -155,14 +167,19 @@ public class Cat extends Drawable {
|
||||
tint(0xFF000000, D.mouth, D.nose);
|
||||
}
|
||||
|
||||
mFootType = 0;
|
||||
if (nsr.nextFloat() < 0.25f) {
|
||||
mFootType = 4;
|
||||
tint(0xFFFFFFFF, D.foot1, D.foot2, D.foot3, D.foot4);
|
||||
} else {
|
||||
if (nsr.nextFloat() < 0.25f) {
|
||||
mFootType = 2;
|
||||
tint(0xFFFFFFFF, D.foot1, D.foot2);
|
||||
} else if (nsr.nextFloat() < 0.25f) {
|
||||
mFootType = 3; // maybe -2 would be better? meh.
|
||||
tint(0xFFFFFFFF, D.foot3, D.foot4);
|
||||
} else if (nsr.nextFloat() < 0.1f) {
|
||||
mFootType = 1;
|
||||
tint(0xFFFFFFFF, (Drawable) choose(nsr, D.foot1, D.foot2, D.foot3, D.foot4));
|
||||
}
|
||||
}
|
||||
@@ -175,7 +192,8 @@ public class Cat extends Drawable {
|
||||
|
||||
final int collarColor = chooseP(nsr, P_COLLAR_COLORS);
|
||||
tint(collarColor, D.collar);
|
||||
tint((nsr.nextFloat() < 0.1f) ? collarColor : 0, D.bowtie);
|
||||
mBowTie = nsr.nextFloat() < 0.1f;
|
||||
tint(mBowTie ? collarColor : 0, D.bowtie);
|
||||
}
|
||||
|
||||
public static Cat create(Context context) {
|
||||
@@ -290,6 +308,26 @@ public class Cat extends Drawable {
|
||||
return mBodyColor;
|
||||
}
|
||||
|
||||
public void logAdd(Context context) {
|
||||
logCatAction(context, "egg_neko_add");
|
||||
}
|
||||
|
||||
public void logRemove(Context context) {
|
||||
logCatAction(context, "egg_neko_remove");
|
||||
}
|
||||
|
||||
public void logShare(Context context) {
|
||||
logCatAction(context, "egg_neko_share");
|
||||
}
|
||||
|
||||
private void logCatAction(Context context, String prefix) {
|
||||
MetricsLogger.count(context, prefix, 1);
|
||||
MetricsLogger.histogram(context, prefix +"_color",
|
||||
getColorIndex(mBodyColor, P_BODY_COLORS));
|
||||
MetricsLogger.histogram(context, prefix + "_bowtie", mBowTie ? 1 : 0);
|
||||
MetricsLogger.histogram(context, prefix + "_feet", mFootType);
|
||||
}
|
||||
|
||||
public static class CatParts {
|
||||
public Drawable leftEar;
|
||||
public Drawable rightEar;
|
||||
|
||||
@@ -20,6 +20,8 @@ import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
|
||||
public class NekoActivationActivity extends Activity {
|
||||
private void toastUp(String s) {
|
||||
Toast toast = Toast.makeText(this, s, Toast.LENGTH_SHORT);
|
||||
@@ -39,6 +41,7 @@ public class NekoActivationActivity extends Activity {
|
||||
}
|
||||
pm.setComponentEnabledSetting(cn, PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP);
|
||||
MetricsLogger.histogram(this, "egg_neko_enable", 0);
|
||||
toastUp("\uD83D\uDEAB");
|
||||
} else {
|
||||
if (NekoLand.DEBUG) {
|
||||
@@ -46,6 +49,7 @@ public class NekoActivationActivity extends Activity {
|
||||
}
|
||||
pm.setComponentEnabledSetting(cn, PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
|
||||
PackageManager.DONT_KILL_APP);
|
||||
MetricsLogger.histogram(this, "egg_neko_enable", 1);
|
||||
toastUp("\uD83D\uDC31");
|
||||
}
|
||||
finish();
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.android.egg.R;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -51,6 +52,7 @@ public class NekoDialog extends Dialog {
|
||||
if (currentState == 0 && food.getType() != 0) {
|
||||
NekoService.registerJob(getContext(), food.getInterval(getContext()));
|
||||
}
|
||||
MetricsLogger.histogram(getContext(), "egg_neko_offered_food", food.getType());
|
||||
prefs.setFoodState(food.getType());
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.android.egg.R;
|
||||
import com.android.egg.neko.PrefState.PrefsListener;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -79,7 +80,8 @@ public class NekoLand extends Activity implements PrefsListener {
|
||||
mAdapter = new CatAdapter();
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
|
||||
updateCats();
|
||||
int numCats = updateCats();
|
||||
MetricsLogger.histogram(this, "egg_neko_visit_gallery", numCats);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,7 +90,7 @@ public class NekoLand extends Activity implements PrefsListener {
|
||||
mPrefs.setListener(null);
|
||||
}
|
||||
|
||||
private void updateCats() {
|
||||
private int updateCats() {
|
||||
Cat[] cats;
|
||||
if (CAT_GEN) {
|
||||
cats = new Cat[50];
|
||||
@@ -99,6 +101,7 @@ public class NekoLand extends Activity implements PrefsListener {
|
||||
cats = mPrefs.getCats().toArray(new Cat[0]);
|
||||
}
|
||||
mAdapter.setCats(cats);
|
||||
return cats.length;
|
||||
}
|
||||
|
||||
private void onCatClick(Cat cat) {
|
||||
@@ -115,11 +118,12 @@ public class NekoLand extends Activity implements PrefsListener {
|
||||
}
|
||||
|
||||
private void onCatRemove(Cat cat) {
|
||||
cat.logRemove(this);
|
||||
mPrefs.removeCat(cat);
|
||||
}
|
||||
|
||||
private void showNameDialog(final Cat cat) {
|
||||
Context context = new ContextThemeWrapper(this,
|
||||
final Context context = new ContextThemeWrapper(this,
|
||||
android.R.style.Theme_Material_Light_Dialog_NoActionBar);
|
||||
// TODO: Move to XML, add correct margins.
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.edit_text, null);
|
||||
@@ -134,6 +138,7 @@ public class NekoLand extends Activity implements PrefsListener {
|
||||
.setPositiveButton(android.R.string.ok, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
MetricsLogger.count(context, "egg_neko_rename_cat", 1);
|
||||
cat.setName(text.getText().toString().trim());
|
||||
mPrefs.addCat(cat);
|
||||
}
|
||||
@@ -244,6 +249,7 @@ public class NekoLand extends Activity implements PrefsListener {
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, cat.getName());
|
||||
intent.setType("image/png");
|
||||
startActivity(Intent.createChooser(intent, null));
|
||||
cat.logShare(this);
|
||||
} catch (IOException e) {
|
||||
Log.e("NekoLand", "save: error: " + e);
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ public class NekoService extends JobService {
|
||||
if (cats.size() == 0 || rng.nextFloat() <= new_cat_prob) {
|
||||
cat = Cat.create(this);
|
||||
prefs.addCat(cat);
|
||||
cat.logAdd(this);
|
||||
Log.v(TAG, "A new cat is here: " + cat.getName());
|
||||
} else {
|
||||
cat = cats.get(rng.nextInt(cats.size()));
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.service.quicksettings.TileService;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.egg.neko.PrefState.PrefsListener;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
|
||||
public class NekoTile extends TileService implements PrefsListener {
|
||||
|
||||
@@ -46,6 +47,18 @@ public class NekoTile extends TileService implements PrefsListener {
|
||||
mPrefs.setListener(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTileAdded() {
|
||||
super.onTileAdded();
|
||||
MetricsLogger.count(this, "egg_neko_tile_added", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTileRemoved() {
|
||||
super.onTileRemoved();
|
||||
MetricsLogger.count(this, "egg_neko_tile_removed", 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrefsChanged() {
|
||||
updateState();
|
||||
@@ -65,6 +78,7 @@ public class NekoTile extends TileService implements PrefsListener {
|
||||
public void onClick() {
|
||||
if (mPrefs.getFoodState() != 0) {
|
||||
// there's already food loaded, let's empty it
|
||||
MetricsLogger.count(this, "egg_neko_empty_food", 1);
|
||||
mPrefs.setFoodState(0);
|
||||
NekoService.cancelJob(this);
|
||||
} else {
|
||||
@@ -91,6 +105,7 @@ public class NekoTile extends TileService implements PrefsListener {
|
||||
|
||||
private void showNekoDialog() {
|
||||
Log.d(TAG, "showNekoDialog");
|
||||
MetricsLogger.count(this, "egg_neko_select_food", 1);
|
||||
showDialog(new NekoDialog(this));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user