1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.tv.settings; 18 19 /** 20 * Maps between an Action key and an Type/Behavior Enum pair. 21 */ 22 public class ActionKey<T extends Enum<T>, B extends Enum<B>> { 23 24 private final T mType; 25 private final String mTypeString; 26 private final B mBehavior; 27 private final String mBehaviorString; 28 ActionKey(T type, B behavior)29 public ActionKey(T type, B behavior) { 30 mType = type; 31 mTypeString = (mType != null) ? mType.name() : ""; 32 mBehavior = behavior; 33 mBehaviorString = (mBehavior != null) ? mBehavior.name() : ""; 34 } 35 ActionKey(Class<T> clazzT, Class<B> clazzB, String key)36 public ActionKey(Class<T> clazzT, Class<B> clazzB, String key) { 37 String[] typeAndBehavior = key.split(":"); 38 39 mTypeString = typeAndBehavior[0]; 40 if (typeAndBehavior.length > 1) { 41 mBehaviorString = typeAndBehavior[1]; 42 } else { 43 mBehaviorString = ""; 44 } 45 46 T type = null; 47 try { 48 type = T.valueOf(clazzT, mTypeString); 49 } catch (IllegalArgumentException iae) { 50 } 51 mType = type; 52 53 B behavior = null; 54 try { 55 behavior = B.valueOf(clazzB, mBehaviorString); 56 } catch (IllegalArgumentException iae) { 57 } 58 mBehavior = behavior; 59 } 60 getKey()61 public String getKey() { 62 return mTypeString + ":" + mBehaviorString; 63 } 64 getType()65 public T getType() { 66 return mType; 67 } 68 getTypeString()69 public String getTypeString() { 70 return mTypeString; 71 } 72 getBehavior()73 public B getBehavior() { 74 return mBehavior; 75 } 76 getBehaviorString()77 public String getBehaviorString() { 78 return mBehaviorString; 79 } 80 } 81