package androidx.constraintlayout.motion.widget; import android.content.Context; import android.util.Log; import android.util.Xml; import androidx.constraintlayout.widget.ConstraintAttribute; import androidx.constraintlayout.widget.ConstraintLayout; import java.io.IOException; import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Set; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; /* loaded from: classes.dex */ public class KeyFrames { private static final String TAG = "KeyFrames"; public static final int UNSET = -1; static HashMap> sKeyMakers; private HashMap> mFramesMap = new HashMap<>(); static { HashMap> hashMap = new HashMap<>(); sKeyMakers = hashMap; try { hashMap.put("KeyAttribute", KeyAttributes.class.getConstructor(new Class[0])); sKeyMakers.put("KeyPosition", KeyPosition.class.getConstructor(new Class[0])); sKeyMakers.put("KeyCycle", KeyCycle.class.getConstructor(new Class[0])); sKeyMakers.put("KeyTimeCycle", KeyTimeCycle.class.getConstructor(new Class[0])); sKeyMakers.put("KeyTrigger", KeyTrigger.class.getConstructor(new Class[0])); } catch (NoSuchMethodException e) { Log.e(TAG, "unable to load", e); } } private void addKey(Key key) { if (!this.mFramesMap.containsKey(Integer.valueOf(key.mTargetId))) { this.mFramesMap.put(Integer.valueOf(key.mTargetId), new ArrayList<>()); } this.mFramesMap.get(Integer.valueOf(key.mTargetId)).add(key); } public KeyFrames(Context context, XmlPullParser xmlPullParser) { Exception e; Key key; try { int eventType = xmlPullParser.getEventType(); Key key2 = null; while (eventType != 1) { if (eventType == 2) { String name = xmlPullParser.getName(); if (sKeyMakers.containsKey(name)) { try { key = sKeyMakers.get(name).newInstance(new Object[0]); } catch (Exception e2) { Key key3 = key2; e = e2; key = key3; } try { key.load(context, Xml.asAttributeSet(xmlPullParser)); addKey(key); } catch (Exception e3) { e = e3; Log.e(TAG, "unable to create ", e); key2 = key; eventType = xmlPullParser.next(); } key2 = key; } else if (name.equalsIgnoreCase("CustomAttribute") && key2 != null && key2.mCustomConstraints != null) { ConstraintAttribute.parse(context, xmlPullParser, key2.mCustomConstraints); } } else if (eventType == 3 && "KeyFrameSet".equals(xmlPullParser.getName())) { return; } eventType = xmlPullParser.next(); } } catch (IOException e4) { e4.printStackTrace(); } catch (XmlPullParserException e5) { e5.printStackTrace(); } } public void addFrames(MotionController motionController) { ArrayList arrayList = this.mFramesMap.get(Integer.valueOf(motionController.mId)); if (arrayList != null) { motionController.addKeys(arrayList); } ArrayList arrayList2 = this.mFramesMap.get(-1); if (arrayList2 != null) { Iterator it = arrayList2.iterator(); while (it.hasNext()) { Key next = it.next(); if (next.matches(((ConstraintLayout.LayoutParams) motionController.mView.getLayoutParams()).constraintTag)) { motionController.addKey(next); } } } } static String name(int i, Context context) { return context.getResources().getResourceEntryName(i); } public Set getKeys() { return this.mFramesMap.keySet(); } public ArrayList getKeyFramesForView(int i) { return this.mFramesMap.get(Integer.valueOf(i)); } }