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;
24 public class NekoTile extends TileService implements PrefsListener {
26 private static final String TAG = "NekoTile";
28 private PrefState mPrefs;
31 public void onCreate() {
33 mPrefs = new PrefState(this);
37 public void onStartListening() {
38 super.onStartListening();
39 mPrefs.setListener(this);
44 public void onStopListening() {
45 super.onStopListening();
46 mPrefs.setListener(null);
50 public void onPrefsChanged() {
54 private void updateState() {
55 Tile tile = getQsTile();
56 int foodState = mPrefs.getFoodState();
57 Food food = new Food(foodState);
58 tile.setIcon(food.getIcon(this));
59 tile.setLabel(food.getName(this));
60 tile.setState(foodState != 0 ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
65 public void onClick() {
66 if (mPrefs.getFoodState() != 0) {
67 // there's already food loaded, let's empty it
68 mPrefs.setFoodState(0);
69 NekoService.cancelJob(this);
71 // time to feed the cats
74 Log.d(TAG, "startActivityAndCollapse");
75 Intent intent = new Intent(this, NekoLockedActivity.class);
76 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
77 startActivityAndCollapse(intent);
79 unlockAndRun(new Runnable() {
92 private void showNekoDialog() {
93 Log.d(TAG, "showNekoDialog");
94 showDialog(new NekoDialog(this));