1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 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 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 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. 13 */ 14 15 package com.android.egg.neko; 16 17 import android.app.Activity; 18 import android.content.ComponentName; 19 import android.content.pm.PackageManager; 20 import android.util.Log; 21 import android.widget.Toast; 22 23 import com.android.internal.logging.MetricsLogger; 24 25 public class NekoActivationActivity extends Activity { 26 private void toastUp(String s) { 27 Toast toast = Toast.makeText(this, s, Toast.LENGTH_SHORT); 28 toast.getView().setBackgroundDrawable(null); 29 toast.show(); 30 } 31 32 @Override 33 public void onStart() { 34 super.onStart(); 35 36 final PackageManager pm = getPackageManager(); 37 final ComponentName cn = new ComponentName(this, NekoTile.class); 38 if (pm.getComponentEnabledSetting(cn) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) { 39 if (NekoLand.DEBUG) { 40 Log.v("Neko", "Disabling tile."); 41 } 42 pm.setComponentEnabledSetting(cn, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, 43 PackageManager.DONT_KILL_APP); 44 MetricsLogger.histogram(this, "egg_neko_enable", 0); 45 toastUp("\uD83D\uDEAB"); 46 } else { 47 if (NekoLand.DEBUG) { 48 Log.v("Neko", "Enabling tile."); 49 } 50 pm.setComponentEnabledSetting(cn, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, 51 PackageManager.DONT_KILL_APP); 52 MetricsLogger.histogram(this, "egg_neko_enable", 1); 53 toastUp("\uD83D\uDC31"); 54 } 55 finish(); 56 } 57 } 58