Example #1
1
    private boolean addUriShortcut(SQLiteDatabase db, ContentValues values, TypedArray a) {
      Resources r = mContext.getResources();

      final int iconResId = a.getResourceId(R.styleable.Favorite_icon, 0);
      final int titleResId = a.getResourceId(R.styleable.Favorite_title, 0);

      Intent intent;
      String uri = null;
      try {
        uri = a.getString(R.styleable.Favorite_uri);
        intent = Intent.parseUri(uri, 0);
      } catch (URISyntaxException e) {
        Log.w(TAG, "Shortcut has malformed uri: " + uri);
        return false; // Oh well
      }

      if (iconResId == 0 || titleResId == 0) {
        Log.w(TAG, "Shortcut is missing title or icon resource ID");
        return false;
      }

      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      values.put(Favorites.INTENT, intent.toUri(0));
      values.put(Favorites.TITLE, r.getString(titleResId));
      values.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_SHORTCUT);
      values.put(Favorites.SPANX, 1);
      values.put(Favorites.SPANY, 1);
      values.put(Favorites.ICON_TYPE, Favorites.ICON_TYPE_RESOURCE);
      values.put(Favorites.ICON_PACKAGE, mContext.getPackageName());
      values.put(Favorites.ICON_RESOURCE, r.getResourceName(iconResId));

      db.insert(TABLE_FAVORITES, null, values);

      return true;
    }
Example #2
0
  public FlyInMenu(Context context, AttributeSet attrs) {
    super(context, attrs);
    myContext = context;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FlyInMenu);
    duration = a.getInteger(R.styleable.FlyInMenu_animationDuration, 200);
    RuntimeException e = null;
    menuId = a.getResourceId(R.styleable.FlyInMenu_menu, 0);
    if (menuId == 0) {
      e =
          new IllegalArgumentException(
              a.getPositionDescription()
                  + ": The handle attribute is required and must refer to a valid child.");
    }
    rightLayoutId = a.getResourceId(R.styleable.FlyInMenu_content, 0);
    if (rightLayoutId == 0) {
      e =
          new IllegalArgumentException(
              a.getPositionDescription()
                  + ": The content attribute is required and must refer to a valid child.");
    }
    a.recycle();

    if (e != null) {
      throw e;
    }

    myHandler = new Handler();

    mState = State.READY;
  }
  private void initAttrs(AttributeSet attrs, int defStyle) {
    TypedArray a =
        getContext()
            .getTheme()
            .obtainStyledAttributes(attrs, R.styleable.ColorPreference, defStyle, defStyle);

    try {
      mItemLayoutId = a.getResourceId(R.styleable.ColorPreference_itemLayout, mItemLayoutId);
      mNumColumns = a.getInteger(R.styleable.ColorPreference_numColumns, mNumColumns);
      int choicesResId =
          a.getResourceId(R.styleable.ColorPreference_choices, R.array.default_color_choice_values);
      if (choicesResId > 0) {
        String[] choices = a.getResources().getStringArray(choicesResId);
        mColorChoices = new int[choices.length];
        for (int i = 0; i < choices.length; i++) {
          mColorChoices[i] = Color.parseColor(choices[i]);
        }
      }

    } finally {
      a.recycle();
    }

    setWidgetLayoutResource(mItemLayoutId);
  }
  public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    mDragHelper = ViewDragHelper.create(this, new ViewDragCallback());

    TypedArray a =
        context.obtainStyledAttributes(
            attrs, R.styleable.SwipeBackLayout, defStyle, R.style.SwipeBackLayout);

    int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1);
    if (edgeSize > 0) setEdgeSize(edgeSize);
    int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)];
    setEdgeTrackingEnabled(mode);

    int shadowLeft =
        a.getResourceId(R.styleable.SwipeBackLayout_shadow_left, R.drawable.shadow_left);
    int shadowRight =
        a.getResourceId(R.styleable.SwipeBackLayout_shadow_right, R.drawable.shadow_right);
    int shadowBottom =
        a.getResourceId(R.styleable.SwipeBackLayout_shadow_bottom, R.drawable.shadow_bottom);
    setShadow(shadowLeft, EDGE_LEFT);
    setShadow(shadowRight, EDGE_RIGHT);
    setShadow(shadowBottom, EDGE_BOTTOM);
    a.recycle();
    final float density = getResources().getDisplayMetrics().density;
    final float minVel = MIN_FLING_VELOCITY * density;
    mDragHelper.setMinVelocity(minVel);
    mDragHelper.setMaxVelocity(minVel * 2f);
  }
Example #5
0
  private void setMyFlag(int position) {
    // Save country to preferences
    this.myCountry = position;
    SharedPreferences.Editor editor = mSharedPreferences.edit();
    editor.putInt(MY_COUNTRY, myCountry);
    editor.apply();

    ImageView imageView = (ImageView) findViewById(R.id.myflag);
    imageView.setImageResource(flags.getResourceId(position, 0));

    ImageView imageView2 = (ImageView) findViewById(R.id.flag);

    //		mView.setImageResource(flags.getResourceId(myCountry, 0));
    //		mView.setRotation(90);
    // Bypass because setRotation in not available before API level 11
    Bitmap bmp = BitmapFactory.decodeResource(getResources(), flags.getResourceId(myCountry, 0));
    // Getting width & height of the given image.
    int w = bmp.getWidth();
    int h = bmp.getHeight();
    // Setting post rotate to 90
    Matrix mtx = new Matrix();
    mtx.postRotate(90);
    // Rotating Bitmap
    Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
    BitmapDrawable bmd = new BitmapDrawable(rotatedBMP);
    imageView2.setImageDrawable(bmd);

    TextView mTextView = (TextView) findViewById(R.id.mycountry);
    mTextView.setText(countries[position]);

    TextView mTextView1 = (TextView) findViewById(R.id.comment);
    mTextView1.setText(R.string.flag_set);
  }
  public AnotherCustomView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // See attrs.xml
    TypedArray typedArray =
        context.obtainStyledAttributes(attrs, R.styleable.AnotherCustomView, defStyle, 0);

    int leftViewId = typedArray.getResourceId(R.styleable.AnotherCustomView_left_view, 0);
    int mainViewId = typedArray.getResourceId(R.styleable.AnotherCustomView_main_view, 0);
    int rightViewId = typedArray.getResourceId(R.styleable.AnotherCustomView_right_view, 0);
    float leftViewPadding =
        typedArray.getDimension(R.styleable.AnotherCustomView_left_view_padding, 20.0f);
    float rightViewPadding =
        typedArray.getDimension(R.styleable.AnotherCustomView_right_view_padding, 20.0f);

    mLeftViewId = leftViewId;
    mMainViewId = mainViewId;
    mRightViewId = rightViewId;

    mLeftViewRightPadding = leftViewPadding;
    mRightViewLeftPadding = rightViewPadding;

    typedArray.recycle();

    setAlwaysDrawnWithCacheEnabled(true);
  }
    public AdapterViewAnimator(
            Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);

        final TypedArray a = context.obtainStyledAttributes(attrs,
                com.android.internal.R.styleable.AdapterViewAnimator, defStyleAttr, defStyleRes);
        int resource = a.getResourceId(
                com.android.internal.R.styleable.AdapterViewAnimator_inAnimation, 0);
        if (resource > 0) {
            setInAnimation(context, resource);
        } else {
            setInAnimation(getDefaultInAnimation());
        }

        resource = a.getResourceId(com.android.internal.R.styleable.AdapterViewAnimator_outAnimation, 0);
        if (resource > 0) {
            setOutAnimation(context, resource);
        } else {
            setOutAnimation(getDefaultOutAnimation());
        }

        boolean flag = a.getBoolean(
                com.android.internal.R.styleable.AdapterViewAnimator_animateFirstView, true);
        setAnimateFirstView(flag);

        mLoopViews = a.getBoolean(
                com.android.internal.R.styleable.AdapterViewAnimator_loopViews, false);

        a.recycle();

        initViewAnimator();
    }
  private void init(AttributeSet attrs) {
    inflate(getContext(), R.layout.searchbar, this);

    TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.MaterialSearchBar);
    iconRightResId = array.getResourceId(R.styleable.MaterialSearchBar_iconRight, -1);
    iconLefttResId = array.getResourceId(R.styleable.MaterialSearchBar_iconLeft, -1);
    hint = array.getString(R.styleable.MaterialSearchBar_hint);
    maxSuggestionCount = array.getInt(R.styleable.MaterialSearchBar_maxSuggestionsCount, 3);
    speechMode = array.getBoolean(R.styleable.MaterialSearchBar_speechMode, false);

    destiny = getResources().getDisplayMetrics().density;
    adapter = new SuggestionsAdapter(LayoutInflater.from(getContext()));
    adapter.setOnClickListener(this);
    adapter.maxSuggestionsCount = maxSuggestionCount;
    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.mt_recycler);
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

    array.recycle();

    searchIcon = (ImageView) findViewById(R.id.mt_search);
    arrowIcon = (ImageView) findViewById(R.id.mt_arrow);
    searchEdit = (EditText) findViewById(R.id.mt_editText);
    inputContainer = (LinearLayout) findViewById(R.id.inputContainer);
    findViewById(R.id.mt_clear).setOnClickListener(this);

    arrowIcon.setOnClickListener(this);
    searchEdit.setOnFocusChangeListener(this);
    setOnClickListener(this);
    searchEdit.setOnEditorActionListener(this);
    if (speechMode) searchIcon.setOnClickListener(this);

    setupIcons();
  }
  public VDVideoSoundSeekButton(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
    mContext = context;
    // 支持自定义背景
    TypedArray typedArr =
        context.obtainStyledAttributes(attrs, new int[] {android.R.attr.background});

    mResID = R.drawable.play_ctrl_volume;
    if (typedArr != null) {
      mResID = typedArr.getResourceId(0, -1);
      if (mResID == -1) {
        mResID = R.drawable.play_ctrl_volume;
      }
      typedArr.recycle();
    }
    setBackgroundResource(mResID);

    // 指定相应的音量控制容器类
    typedArr = context.obtainStyledAttributes(attrs, R.styleable.VDVideoSoundSeekButton);
    mSilentResID = R.drawable.ad_silent_selcetor;
    if (typedArr != null) {
      for (int i = 0; i < typedArr.getIndexCount(); i++) {
        if (typedArr.getIndex(i) == R.styleable.VDVideoSoundSeekButton_soundSeekContainer) {
          mContainerID = typedArr.getResourceId(i, -1);
        } else if (typedArr.getIndex(i) == R.styleable.VDVideoSoundSeekButton_soundSeekSilent) {
          // 自定义背景的时候,换静音按钮
          mSilentResID = typedArr.getResourceId(i, -1);
        }
      }
      typedArr.recycle();
    }

    registerListeners();
  }
Example #10
0
  private void updateStyle(TypedArray styled, boolean invalidate) {
    int backgroundColor =
        styled.getColor(R.styleable.ShowcaseView_sv_backgroundColor, Color.argb(128, 80, 80, 80));
    int showcaseColor = styled.getColor(R.styleable.ShowcaseView_sv_showcaseColor, HOLO_BLUE);
    String buttonText = styled.getString(R.styleable.ShowcaseView_sv_buttonText);
    if (TextUtils.isEmpty(buttonText)) {
      buttonText = getResources().getString(android.R.string.ok);
    }
    boolean tintButton = styled.getBoolean(R.styleable.ShowcaseView_sv_tintButtonColor, true);

    int titleTextAppearance =
        styled.getResourceId(
            R.styleable.ShowcaseView_sv_titleTextAppearance,
            R.style.TextAppearance_ShowcaseView_Title);
    int detailTextAppearance =
        styled.getResourceId(
            R.styleable.ShowcaseView_sv_detailTextAppearance,
            R.style.TextAppearance_ShowcaseView_Detail);

    styled.recycle();

    showcaseDrawer.setShowcaseColour(showcaseColor);
    showcaseDrawer.setBackgroundColour(backgroundColor);
    tintButton(showcaseColor, tintButton);
    mEndButton.setText(buttonText);
    textDrawer.setTitleStyling(titleTextAppearance);
    textDrawer.setDetailStyling(detailTextAppearance);
    hasAlteredText = true;

    if (invalidate) {
      invalidate();
    }
  }
Example #11
0
    /** Called when the parser is pointing to an item tag. */
    public void readItem(AttributeSet attrs) {
      TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.SherlockMenuItem);

      // Inherit attributes from the group as default value
      itemId = a.getResourceId(R.styleable.SherlockMenuItem_android_id, defaultItemId);
      final int category =
          a.getInt(R.styleable.SherlockMenuItem_android_menuCategory, groupCategory);
      final int order = a.getInt(R.styleable.SherlockMenuItem_android_orderInCategory, groupOrder);
      itemCategoryOrder = (category & Menu.CATEGORY_MASK) | (order & Menu.USER_MASK);
      itemTitle = a.getText(R.styleable.SherlockMenuItem_android_title);
      itemTitleCondensed = a.getText(R.styleable.SherlockMenuItem_android_titleCondensed);
      itemIconResId = a.getResourceId(R.styleable.SherlockMenuItem_android_icon, 0);
      itemAlphabeticShortcut =
          getShortcut(a.getString(R.styleable.SherlockMenuItem_android_alphabeticShortcut));
      itemNumericShortcut =
          getShortcut(a.getString(R.styleable.SherlockMenuItem_android_numericShortcut));
      if (a.hasValue(R.styleable.SherlockMenuItem_android_checkable)) {
        // Item has attribute checkable, use it
        itemCheckable = a.getBoolean(R.styleable.SherlockMenuItem_android_checkable, false) ? 1 : 0;
      } else {
        // Item does not have attribute, use the group's (group can have one more state
        // for checkable that represents the exclusive checkable)
        itemCheckable = groupCheckable;
      }

      itemChecked = a.getBoolean(R.styleable.SherlockMenuItem_android_checked, defaultItemChecked);
      itemVisible = a.getBoolean(R.styleable.SherlockMenuItem_android_visible, groupVisible);
      itemEnabled = a.getBoolean(R.styleable.SherlockMenuItem_android_enabled, groupEnabled);

      TypedValue value = new TypedValue();
      a.getValue(R.styleable.SherlockMenuItem_android_showAsAction, value);
      itemShowAsAction = value.type == TypedValue.TYPE_INT_HEX ? value.data : -1;

      itemListenerMethodName = a.getString(R.styleable.SherlockMenuItem_android_onClick);
      itemActionViewLayout = a.getResourceId(R.styleable.SherlockMenuItem_android_actionLayout, 0);
      itemActionViewClassName = a.getString(R.styleable.SherlockMenuItem_android_actionViewClass);
      itemActionProviderClassName =
          a.getString(R.styleable.SherlockMenuItem_android_actionProviderClass);

      final boolean hasActionProvider = itemActionProviderClassName != null;
      if (hasActionProvider && itemActionViewLayout == 0 && itemActionViewClassName == null) {
        itemActionProvider =
            newInstance(
                itemActionProviderClassName,
                ACTION_PROVIDER_CONSTRUCTOR_SIGNATURE,
                mActionProviderConstructorArguments);
      } else {
        if (hasActionProvider) {
          Log.w(
              LOG_TAG,
              "Ignoring attribute 'actionProviderClass'." + " Action view already specified.");
        }
        itemActionProvider = null;
      }

      a.recycle();

      itemAdded = false;
    }
Example #12
0
 private void mapGUI(TypedArray attributes) {
   int dragViewId =
       attributes.getResourceId(R.styleable.draggable_view_top_view_id, R.id.drag_view);
   int secondViewId =
       attributes.getResourceId(R.styleable.draggable_view_bottom_view_id, R.id.second_view);
   dragView = findViewById(dragViewId);
   secondView = findViewById(secondViewId);
 }
Example #13
0
  public DropDownMenu(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    setOrientation(VERTICAL);

    // 为DropDownMenu添加自定义属性
    int menuBackgroundColor = 0xffffffff;
    int underlineColor = 0xffcccccc;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DropDownMenu);
    underlineColor = a.getColor(R.styleable.DropDownMenu_ddunderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.DropDownMenu_dddividerColor, dividerColor);
    textSelectedColor = a.getColor(R.styleable.DropDownMenu_ddtextSelectedColor, textSelectedColor);
    textUnselectedColor =
        a.getColor(R.styleable.DropDownMenu_ddtextUnselectedColor, textUnselectedColor);
    menuBackgroundColor =
        a.getColor(R.styleable.DropDownMenu_ddmenuBackgroundColor, menuBackgroundColor);
    maskColor = a.getColor(R.styleable.DropDownMenu_ddmaskColor, maskColor);
    menuTextSize = a.getDimensionPixelSize(R.styleable.DropDownMenu_ddmenuTextSize, menuTextSize);
    menuSelectedIcon =
        a.getResourceId(R.styleable.DropDownMenu_ddmenuSelectedIcon, menuSelectedIcon);
    menuUnselectedIcon =
        a.getResourceId(R.styleable.DropDownMenu_ddmenuUnselectedIcon, menuUnselectedIcon);
    stickyTag = a.getString(R.styleable.DropDownMenu_ddmenuTag);
    a.recycle();

    //        setTag(stickyTag);
    // 初始化tabMenuView并添加到tabMenuView
    tabMenuView = new LinearLayout(context);

    if (!TextUtils.isEmpty(stickyTag)) {
      tabMenuView.setTag(stickyTag);
    }
    LayoutParams params =
        new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    tabMenuView.setOrientation(HORIZONTAL);
    tabMenuView.setBackgroundColor(menuBackgroundColor);
    tabMenuView.setLayoutParams(params);
    addView(tabMenuView, 0);

    // 为tabMenuView添加下划线
    View underLine = new View(getContext());
    underLine.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpTpPx(1.0f)));
    underLine.setBackgroundColor(underlineColor);
    addView(underLine, 1);

    // 初始化containerView并将其添加到DropDownMenu
    containerView = new FrameLayout(context);
    //        containerView.setTag(stickyTag);
    FrameLayout.LayoutParams params1 =
        new FrameLayout.LayoutParams(
            FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
    //        params1.height = 1000;
    containerView.setLayoutParams(params1);
    //        containerView.setBackgroundDrawable(new ColorDrawable(Color.RED));

    addView(containerView, 2);
  }
  @Override
  public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs)
      throws XmlPullParserException, IOException {
    super.inflate(r, parser, attrs);

    int type;

    final int innerDepth = parser.getDepth() + 1;
    int depth;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
        && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
      if (type != XmlPullParser.START_TAG) {
        continue;
      }

      if (depth > innerDepth || !parser.getName().equals("item")) {
        continue;
      }

      TypedArray a = r.obtainAttributes(attrs, com.android.internal.R.styleable.LayerDrawableItem);

      int left =
          a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_left, 0);
      int top =
          a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_top, 0);
      int right =
          a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_right, 0);
      int bottom =
          a.getDimensionPixelOffset(com.android.internal.R.styleable.LayerDrawableItem_bottom, 0);
      int drawableRes =
          a.getResourceId(com.android.internal.R.styleable.LayerDrawableItem_drawable, 0);
      int id = a.getResourceId(com.android.internal.R.styleable.LayerDrawableItem_id, View.NO_ID);

      a.recycle();

      Drawable dr;
      if (drawableRes != 0) {
        dr = r.getDrawable(drawableRes);
      } else {
        while ((type = parser.next()) == XmlPullParser.TEXT) {}
        if (type != XmlPullParser.START_TAG) {
          throw new XmlPullParserException(
              parser.getPositionDescription()
                  + ": <item> tag requires a 'drawable' attribute or "
                  + "child tag defining a drawable");
        }
        dr = Drawable.createFromXmlInner(r, parser, attrs);
      }

      addLayer(dr, id, left, top, right, bottom);
    }

    ensurePadding();
    onStateChange(getState());
  }
  @Override
  public boolean init(final Context context, final AttributeSet attrs) {
    if (!super.init(context, attrs)) {
      return false;
    }

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AwesomePreference);

    int filePath = -1, filePathList = -1, fileValue = -1;
    if (a != null) {
      filePath = a.getResourceId(R.styleable.AwesomePreference_filePath, -1);
      filePathList = a.getResourceId(R.styleable.AwesomePreference_filePathList, -1);
      fileValue = a.getResourceId(R.styleable.AwesomePreference_fileValue, -1);
      mStartup = a.getBoolean(R.styleable.AwesomePreference_startup, mStartup);
      mMultiFile = a.getBoolean(R.styleable.AwesomePreference_multifile, mMultiFile);
      mValueChecked = a.getString(R.styleable.AwesomePreference_valueChecked);
      mValueNotChecked = a.getString(R.styleable.AwesomePreference_valueNotChecked);
      a.recycle();
    }

    final Resources res = context.getResources();
    if (filePath != -1) {
      mPath = Utils.checkPath(res.getString(filePath));
      mPaths = null;
    } else if (filePathList != -1) {
      mPaths = res.getStringArray(filePathList);
      mPath = Utils.checkPaths(mPaths);
      if (mPath.isEmpty() || !mMultiFile) {
        mPaths = null;
      }
    } else {
      mPath = "";
      mPaths = null;
    }

    if (!TextUtils.isEmpty(mPath) && filePathList != -1 && fileValue != -1) {
      final int index = Arrays.asList(res.getStringArray(filePathList)).indexOf(mPath);
      final String[] values = res.getStringArray(fileValue)[index].split(";");
      mValueChecked = values[0];
      mValueNotChecked = values[1];
      Logger.d(
          this, "mValueChecked -> %s\nmValueNotChecked -> %s", mValueChecked, mValueNotChecked);
    }

    if (TextUtils.isEmpty(mValueChecked)) {
      mValueChecked = "1";
    }
    if (TextUtils.isEmpty(mValueNotChecked)) {
      mValueNotChecked = "0";
    }

    handleSelf(true);

    return true;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    Resources res = getResources();
    TypedArray ta = res.obtainTypedArray(R.array.movies);
    int n = ta.length();

    for (int i = 0; i < n; i++) {
      TypedArray movieData = res.obtainTypedArray(ta.getResourceId(i, 0));
      Movie movie =
          new Movie(
              movieData.getString(0),
              movieData.getString(1),
              movieData.getString(2),
              movieData.getResourceId(4, 0),
              movieData.getResourceId(3, 0));
      mMovieList.add(movie);
      movieData.recycle();
    }

    ta.recycle();

    View v = inflater.inflate(R.layout.fragment_master, container, false);
    GridView gridview = (GridView) v.findViewById(R.id.gridview);
    gridview.setAdapter(new GridAdapter(v.getContext(), mMovieList));

    gridview.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            // Create new fragment and bundle
            DetailFragment newFragment = new DetailFragment();
            Bundle bundle = new Bundle();
            Movie movie = mMovieList.get(position);
            if (movie != null) {
              bundle.putSerializable(FRAGMENT_BUNDLE_KEY, movie);
              newFragment.setArguments(bundle);
            } else {
              Log.e("Movie", "Is null");
            }

            // Set transaction.
            android.support.v4.app.FragmentTransaction transaction =
                getFragmentManager().beginTransaction();
            transaction.replace(R.id.fragment_container, newFragment);
            transaction.addToBackStack(null);

            // Commit the transaction
            transaction.commit();
          }
        });
    return v;
  }
  @SuppressWarnings("deprecation")
  protected void init(Context context, AttributeSet attributes, int defStyleAttr) {
    EditText reference = new EditText(getContext());

    setOrientation(VERTICAL);
    setPadding(
        reference.getLeft() + reference.getCompoundPaddingLeft(),
        0,
        reference.getRight() + reference.getCompoundPaddingRight(),
        0);

    hint =
        (TextView)
            LayoutInflater.from(context).inflate(R.layout.floating_label_layout_hint, this, false);

    error =
        (TextView)
            LayoutInflater.from(context).inflate(R.layout.floating_label_layout_error, this, false);

    TypedArray array =
        context.obtainStyledAttributes(
            attributes,
            R.styleable.TextInputLayout,
            defStyleAttr,
            R.style.Widget_Design_TextInputLayout);

    hint.setText(array.getString(R.styleable.TextInputLayout_android_hint));

    if (array.hasValue(R.styleable.TextInputLayout_android_textColorHint)) {
      hint.setTextColor(array.getColorStateList(R.styleable.TextInputLayout_android_textColorHint));
    }

    if (array.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, -1) != -1) {
      setHintTextAppearance(array.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, 0));
    }

    final int errorAppearance =
        array.getResourceId(R.styleable.TextInputLayout_errorTextAppearance, 0);

    try {
      error.setTextAppearance(getContext(), errorAppearance);
    } catch (Exception exception) {
      // Probably caused by our theme not extending from Theme.Design*. Instead
      // we manually set something appropriate
      error.setTextAppearance(getContext(), R.style.TextAppearance_AppCompat_Caption);
      error.setTextColor(
          ContextCompat.getColor(getContext(), R.color.design_textinput_error_color_light));
    }

    error.setVisibility(
        array.getBoolean(R.styleable.TextInputLayout_errorEnabled, false) ? VISIBLE : GONE);

    array.recycle();
  }
 private void readAttribute(Context context, AttributeSet attrs) {
   TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BaseFrameLayout);
   try {
     mLoadingLayoutId = a.getResourceId(R.styleable.BaseFrameLayout_loadingLayout, 0);
     mDataLayoutId = a.getResourceId(R.styleable.BaseFrameLayout_dataLayout, 0);
     mEmptyLayoutId = a.getResourceId(R.styleable.BaseFrameLayout_emptyLayout, 0);
     mErrorLayoutId = a.getResourceId(R.styleable.BaseFrameLayout_errorLayout, 0);
   } finally {
     a.recycle();
   }
 }
Example #19
0
 public ViewStubCompat(Context context, AttributeSet attrs, int defStyle) {
   super(context, attrs, defStyle);
   this.mLayoutResource = 0;
   TypedArray a =
       context.obtainStyledAttributes(attrs, C0170R.styleable.ViewStubCompat, defStyle, 0);
   this.mInflatedId = a.getResourceId(C0170R.styleable.ViewStubCompat_android_inflatedId, -1);
   this.mLayoutResource = a.getResourceId(C0170R.styleable.ViewStubCompat_android_layout, 0);
   setId(a.getResourceId(C0170R.styleable.ViewStubCompat_android_id, -1));
   a.recycle();
   setVisibility(8);
   setWillNotDraw(true);
 }
  private void init(final Context context, AttributeSet attrs) {
    final View rootView = View.inflate(context, R.layout.view_expandable, this);
    headerLayout = (FrameLayout) rootView.findViewById(R.id.view_expandable_headerlayout);
    final TypedArray typedArray =
        context.obtainStyledAttributes(attrs, R.styleable.ExpandableLayout);
    final int headerID = typedArray.getResourceId(R.styleable.ExpandableLayout_el_headerLayout, -1);
    final int contentID =
        typedArray.getResourceId(R.styleable.ExpandableLayout_el_contentLayout, -1);
    contentLayout = (FrameLayout) rootView.findViewById(R.id.view_expandable_contentLayout);

    if (headerID == -1 || contentID == -1)
      throw new IllegalArgumentException("HeaderLayout and ContentLayout cannot be null!");

    if (isInEditMode()) return;

    duration =
        typedArray.getInt(
            R.styleable.ExpandableLayout_el_duration,
            getContext().getResources().getInteger(android.R.integer.config_shortAnimTime));
    final View headerView = View.inflate(context, headerID, null);
    headerView.setLayoutParams(
        new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    headerLayout.addView(headerView);
    final View contentView = View.inflate(context, contentID, null);
    contentView.setLayoutParams(
        new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    contentLayout.addView(contentView);
    contentLayout.setVisibility(GONE);
    headerLayout.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            if (!isAnimationRunning) {
              if (contentLayout.getVisibility() == VISIBLE) collapse(contentLayout);
              else expand(contentLayout);

              isAnimationRunning = true;
              new Handler()
                  .postDelayed(
                      new Runnable() {
                        @Override
                        public void run() {
                          isAnimationRunning = false;
                        }
                      },
                      duration);
            }
          }
        });

    typedArray.recycle();
  }
Example #21
0
 private SliderMenuAdapter(Context context) {
   context = sThemes.context(context);
   mLayoutInflater = LayoutInflater.from(context);
   TypedArray a = context.obtainStyledAttributes(R.styleable.SliderMenu);
   mDefaultTextAppearance =
       a.getResourceId(
           R.styleable.SliderMenu_textAppearanceSliderItem, R.style.Holo_TextAppearance_Medium);
   mDefaultTextAppearanceInverse =
       a.getResourceId(
           R.styleable.SliderMenu_textAppearanceSliderItemInverse,
           R.style.Holo_TextAppearance_Medium_Inverse);
   a.recycle();
 }
  /**
   * Does all the functions of the constructor for RangeBar. Called by both RangeBar constructors in
   * lieu of copying the code for each constructor.
   *
   * @param context Context from the constructor.
   * @param attrs AttributeSet from the constructor.
   * @return none
   */
  private void rangeBarInit(Context context, AttributeSet attrs) {
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.RangeBar, 0, 0);

    try {

      // Sets the values of the user-defined attributes based on the XML
      // attributes.
      final Integer tickCount = ta.getInteger(R.styleable.RangeBar_tickCount, DEFAULT_TICK_COUNT);

      if (isValidTickCount(tickCount)) {

        // Similar functions performed above in setTickCount; make sure
        // you know how they interact
        mTickCount = tickCount;
        mLeftIndex = 0;
        mRightIndex = mTickCount - 1;

        if (mListener != null) {
          mListener.onIndexChangeListener(this, mLeftIndex, mRightIndex);
        }

      } else {

        Log.e(TAG, "tickCount less than 2; invalid tickCount. XML input ignored.");
      }

      mTickHeightDP = ta.getDimension(R.styleable.RangeBar_tickHeight, DEFAULT_TICK_HEIGHT_DP);
      mBarWeight = ta.getDimension(R.styleable.RangeBar_barWeight, DEFAULT_BAR_WEIGHT_PX);
      mBarColor = ta.getColor(R.styleable.RangeBar_barColor, DEFAULT_BAR_COLOR);
      mConnectingLineWeight =
          ta.getDimension(
              R.styleable.RangeBar_connectingLineWeight, DEFAULT_CONNECTING_LINE_WEIGHT_PX);
      mConnectingLineColor =
          ta.getColor(R.styleable.RangeBar_connectingLineColor, DEFAULT_CONNECTING_LINE_COLOR);
      mThumbRadiusDP = ta.getDimension(R.styleable.RangeBar_thumbRadius, DEFAULT_THUMB_RADIUS_DP);
      mThumbImageNormal =
          ta.getResourceId(R.styleable.RangeBar_thumbImageNormal, DEFAULT_THUMB_IMAGE_NORMAL);
      mThumbImagePressed =
          ta.getResourceId(R.styleable.RangeBar_thumbImagePressed, DEFAULT_THUMB_IMAGE_PRESSED);
      mThumbColorNormal =
          ta.getColor(R.styleable.RangeBar_thumbColorNormal, DEFAULT_THUMB_COLOR_NORMAL);
      mThumbColorPressed =
          ta.getColor(R.styleable.RangeBar_thumbColorPressed, DEFAULT_THUMB_COLOR_PRESSED);

    } finally {

      ta.recycle();
    }
  }
 public HeaderDrawerLayout(Context context, AttributeSet attrs, int defStyleAttr) {
   super(context, attrs, defStyleAttr);
   final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HeaderDrawerLayout);
   final int headerLayoutId = a.getResourceId(R.styleable.HeaderDrawerLayout_hdl_headerLayout, 0);
   final int contentLayoutId =
       a.getResourceId(R.styleable.HeaderDrawerLayout_hdl_contentLayout, 0);
   addView(
       mContainer = new InternalContainer(this, context, headerLayoutId, contentLayoutId),
       LayoutParams.MATCH_PARENT,
       LayoutParams.WRAP_CONTENT);
   a.recycle();
   mDragHelper = ViewDragHelper.create(this, mDragCallback = new DragCallback(this));
   mGestureDetector = new GestureDetector(context, new GestureListener(this));
   mScroller = ScrollerCompat.create(context);
 }
Example #24
0
  public FocusImageView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.focusview_show);
    mHandler = new Handler();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FocusImageView);
    mFocusImg = a.getResourceId(R.styleable.FocusImageView_focus_focusing_id, NO_ID);
    mFocusSucceedImg = a.getResourceId(R.styleable.FocusImageView_focus_success_id, NO_ID);
    mFocusFailedImg = a.getResourceId(R.styleable.FocusImageView_focus_fail_id, NO_ID);
    a.recycle();

    // 聚焦图片不能为空
    if (mFocusImg == NO_ID || mFocusSucceedImg == NO_ID || mFocusFailedImg == NO_ID)
      throw new RuntimeException("Animation is null");
  }
Example #25
0
  public ExtendedListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    super.setOnScrollListener(this);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ExtendedListView);
    final int scrollBarPanelLayoutId =
        a.getResourceId(R.styleable.ExtendedListView_scrollBarPanel, -1);
    final int scrollBarPanelInAnimation =
        a.getResourceId(
            R.styleable.ExtendedListView_scrollBarPanelInAnimation, R.anim.scroll_bar_panel_in);
    final int scrollBarPanelOutAnimation =
        a.getResourceId(
            R.styleable.ExtendedListView_scrollBarPanelOutAnimation, R.anim.scroll_bar_panel_out);
    a.recycle();

    if (scrollBarPanelLayoutId != -1) {
      setScrollBarPanel(scrollBarPanelLayoutId);
    }

    final int scrollBarPanelFadeDuration = ViewConfiguration.getScrollBarFadeDuration();

    if (scrollBarPanelInAnimation > 0) {
      inAnimation = AnimationUtils.loadAnimation(getContext(), scrollBarPanelInAnimation);
    }

    if (scrollBarPanelOutAnimation > 0) {
      outAnimation = AnimationUtils.loadAnimation(getContext(), scrollBarPanelOutAnimation);
      outAnimation.setDuration(scrollBarPanelFadeDuration);

      outAnimation.setAnimationListener(
          new AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {}

            @Override
            public void onAnimationRepeat(Animation animation) {}

            @Override
            public void onAnimationEnd(Animation animation) {
              if (scrollBarPanel != null) {
                scrollBarPanel.setVisibility(View.GONE);
              }
            }
          });
    }
  }
 public FloatingMenuLayout(Context context, AttributeSet attrs, int defStyleAttr) {
   super(context, attrs, defStyleAttr);
   TypedArray attr =
       context.obtainStyledAttributes(attrs, R.styleable.CustomFloatingActionMenu, 0, 0);
   mLabelStyle = attr.getResourceId(R.styleable.CustomFloatingActionMenu_menu_label_style, 0);
   attr.recycle();
 }
Example #27
0
  private void init(AttributeSet attrs, int defStyle) {
    if (isInEditMode()) return;
    TypedArray a =
        getContext()
            .getTheme()
            .obtainStyledAttributes(attrs, R.styleable.SVGImageView, defStyle, 0);
    try {
      int resourceId = a.getResourceId(R.styleable.SVGImageView_svg, -1);
      if (resourceId != -1) {
        setImageResource(resourceId);
        return;
      }

      String url = a.getString(R.styleable.SVGImageView_svg);
      if (url != null) {
        Uri uri = Uri.parse(url);
        if (internalSetImageURI(uri, false)) return;

        // Last chance, try loading it as an asset filename
        setImageAsset(url);
      }

    } finally {
      a.recycle();
    }
  }
  /**
   * Tries to pull the Font Path from the Text Appearance.
   *
   * @param context Activity Context
   * @param attrs View Attributes
   * @param attributeId if -1 returns null.
   * @return returns null if attribute is not defined or if no TextAppearance is found.
   */
  static String pullFontPathFromTextAppearance(
      final Context context, AttributeSet attrs, int attributeId) {
    if (attributeId == -1 || attrs == null) {
      return null;
    }

    int textAppearanceId = -1;
    final TypedArray typedArrayAttr =
        context.obtainStyledAttributes(attrs, new int[] {android.R.attr.textAppearance});
    if (typedArrayAttr != null) {
      try {
        textAppearanceId = typedArrayAttr.getResourceId(0, -1);
      } catch (Exception ignored) {
        // Failed for some reason
        return null;
      } finally {
        typedArrayAttr.recycle();
      }
    }

    final TypedArray textAppearanceAttrs =
        context.obtainStyledAttributes(textAppearanceId, new int[] {attributeId});
    if (textAppearanceAttrs != null) {
      try {
        return textAppearanceAttrs.getString(0);
      } catch (Exception ignore) {
        // Failed for some reason.
        return null;
      } finally {
        textAppearanceAttrs.recycle();
      }
    }
    return null;
  }
  private static int preloadDrawables(VMRuntime runtime, TypedArray ar) {
    int N = ar.length();
    for (int i = 0; i < N; i++) {
      if (Debug.getGlobalAllocSize() > PRELOAD_GC_THRESHOLD) {

        Log.i(TAG, " GC at " + Debug.getGlobalAllocSize());

        System.gc();
        runtime.runFinalizationSync();
        Debug.resetGlobalAllocSize();
      }
      int id = ar.getResourceId(i, 0);
      if (false) {
        Log.v(TAG, "Preloading resource #" + Integer.toHexString(id));
      }
      if (id != 0) {
        Drawable dr = mResources.getDrawable(id);
        if ((dr.getChangingConfigurations() & ~ActivityInfo.CONFIG_FONT_SCALE) != 0) {
          Log.w(
              TAG,
              "Preloaded drawable resource #0x"
                  + Integer.toHexString(id)
                  + " ("
                  + ar.getString(i)
                  + ") that varies with configuration!!");
        }
      }
    }
    return N;
  }
  /**
   * Last but not least, try to pull the Font Path from the Theme, which is defined.
   *
   * @param context Activity Context
   * @param styleAttrId Theme style id
   * @param subStyleAttrId the sub style from the theme to look up after the first style
   * @param attributeId if -1 returns null.
   * @return null if no theme or attribute defined.
   */
  static String pullFontPathFromTheme(
      Context context, int styleAttrId, int subStyleAttrId, int attributeId) {
    if (styleAttrId == -1 || attributeId == -1) return null;

    final Resources.Theme theme = context.getTheme();
    final TypedValue value = new TypedValue();

    theme.resolveAttribute(styleAttrId, value, true);
    int subStyleResId = -1;
    final TypedArray parentTypedArray =
        theme.obtainStyledAttributes(value.resourceId, new int[] {subStyleAttrId});
    try {
      subStyleResId = parentTypedArray.getResourceId(0, -1);
    } catch (Exception ignore) {
      // Failed for some reason.
      return null;
    } finally {
      parentTypedArray.recycle();
    }

    if (subStyleResId == -1) return null;
    final TypedArray subTypedArray =
        context.obtainStyledAttributes(subStyleResId, new int[] {attributeId});
    if (subTypedArray != null) {
      try {
        return subTypedArray.getString(0);
      } catch (Exception ignore) {
        // Failed for some reason.
        return null;
      } finally {
        subTypedArray.recycle();
      }
    }
    return null;
  }