2 * Copyright (C) 2016 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5 * except in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the
10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11 * KIND, either express or implied. See the License for the specific language governing
12 * permissions and limitations under the License.
15 package com.android.egg.neko;
17 import android.content.Intent;
18 import android.service.quicksettings.Tile;
19 import android.service.quicksettings.TileService;
20 import android.util.Log;
22 import com.android.egg.neko.PrefState.PrefsListener;
23 import com.android.internal.logging.MetricsLogger;
25 public class NekoTile extends TileService implements PrefsListener {
27 private static final String TAG = "NekoTile";
29 private PrefState mPrefs;
32 public void onCreate() {
34 mPrefs = new PrefState(this);
38 public void onStartListening() {
39 super.onStartListening();
40 mPrefs.setListener(this);
45 public void onStopListening() {
46 super.onStopListening();
47 mPrefs.setListener(null);
51 public void onTileAdded() {
53 MetricsLogger.count(this, "egg_neko_tile_added", 1);
57 public void onTileRemoved() {
58 super.onTileRemoved();
59 MetricsLogger.count(this, "egg_neko_tile_removed", 1);
63 public void onPrefsChanged() {
67 private void updateState() {
68 Tile tile = getQsTile();
69 int foodState = mPrefs.getFoodState();
70 Food food = new Food(foodState);
71 tile.setIcon(food.getIcon(this));
72 tile.setLabel(food.getName(this));
73 tile.setState(foodState != 0 ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
78 public void onClick() {
79 if (mPrefs.getFoodState() != 0) {
80 // there's already food loaded, let's empty it
81 MetricsLogger.count(this, "egg_neko_empty_food", 1);
82 mPrefs.setFoodState(0);
83 NekoService.cancelJob(this);
85 // time to feed the cats
88 Log.d(TAG, "startActivityAndCollapse");
89 Intent intent = new Intent(this, NekoLockedActivity.class);
90 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
91 startActivityAndCollapse(intent);
93 unlockAndRun(new Runnable() {
106 private void showNekoDialog() {
107 Log.d(TAG, "showNekoDialog");
108 MetricsLogger.count(this, "egg_neko_select_food", 1);
109 showDialog(new NekoDialog(this));