Example usage for android.content.res Resources getDrawable

List of usage examples for android.content.res Resources getDrawable

Introduction

In this page you can find the example usage for android.content.res Resources getDrawable.

Prototype

@Deprecated
public Drawable getDrawable(@DrawableRes int id) throws NotFoundException 

Source Link

Document

Return a drawable object associated with a particular resource ID.

Usage

From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java

public GlowPadView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Resources res = context.getResources();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlowPadView);
    mInnerRadius = a.getDimension(R.styleable.GlowPadView_innerRadius, mInnerRadius);
    mOuterRadius = a.getDimension(R.styleable.GlowPadView_outerRadius, mOuterRadius);
    mSnapMargin = a.getDimension(R.styleable.GlowPadView_snapMargin, mSnapMargin);
    mVibrationDuration = a.getInt(R.styleable.GlowPadView_vibrationDuration, mVibrationDuration);
    mFeedbackCount = a.getInt(R.styleable.GlowPadView_feedbackCount, mFeedbackCount);
    mAllowScaling = a.getBoolean(R.styleable.GlowPadView_allowScaling, false);
    TypedValue handle = a.peekValue(R.styleable.GlowPadView_handleDrawable);
    setHandleDrawable(handle != null ? handle.resourceId : R.drawable.ic_incall_audio_handle);
    mOuterRing = new TargetDrawable(res, getResourceId(a, R.styleable.GlowPadView_outerRingDrawable), 1);

    mAlwaysTrackFinger = a.getBoolean(R.styleable.GlowPadView_alwaysTrackFinger, false);

    int pointId = getResourceId(a, R.styleable.GlowPadView_pointDrawable);
    Drawable pointDrawable = pointId != 0 ? res.getDrawable(pointId) : null;
    mGlowRadius = a.getDimension(R.styleable.GlowPadView_glowRadius, 0.0f);

    TypedValue outValue = new TypedValue();

    // Read array of target drawables
    if (a.getValue(R.styleable.GlowPadView_targetDrawables, outValue)) {
        internalSetTargetResources(outValue.resourceId);
    }//w  ww .  j  ava 2 s.  c o m
    if (mTargetDrawables == null || mTargetDrawables.size() == 0) {
        throw new IllegalStateException("Must specify at least one target drawable");
    }

    // Read array of target descriptions
    if (a.getValue(R.styleable.GlowPadView_targetDescriptions, outValue)) {
        final int resourceId = outValue.resourceId;
        if (resourceId == 0) {
            throw new IllegalStateException("Must specify target descriptions");
        }
        setTargetDescriptionsResourceId(resourceId);
    }

    // Read array of direction descriptions
    if (a.getValue(R.styleable.GlowPadView_directionDescriptions, outValue)) {
        final int resourceId = outValue.resourceId;
        if (resourceId == 0) {
            throw new IllegalStateException("Must specify direction descriptions");
        }
        setDirectionDescriptionsResourceId(resourceId);
    }

    // Use gravity attribute from LinearLayout
    //a = context.obtainStyledAttributes(attrs, R.styleable.LinearLayout);
    mGravity = a.getInt(R.styleable.GlowPadView_android_gravity, Gravity.TOP);
    a.recycle();

    setVibrateEnabled(mVibrationDuration > 0);

    assignDefaultsIfNeeded();

    mPointCloud = new PointCloud(pointDrawable);
    mPointCloud.makePointCloud(mInnerRadius, mOuterRadius);
    mPointCloud.glowManager.setRadius(mGlowRadius);

    mExploreByTouchHelper = new GlowpadExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
}

From source file:com.wanikani.androidnotifier.ItemsFragment.java

/**
 * Creation of the fragment. We build up all the singletons, leaving the
 * bundle alone, because we set the retain instance flag to <code>true</code>.
 *    @param bundle the saved instance state
 *///from   ww  w. j av  a2 s .  com
@Override
public void onCreate(Bundle bundle) {
    Resources res;

    super.onCreate(bundle);

    setRetainInstance(true);

    fmap = new EnumMap<FilterType, Filter>(FilterType.class);
    fmap.put(FilterType.NONE, new NoFilter(this));
    fmap.put(FilterType.LEVEL, new LevelFilter(this));
    fmap.put(FilterType.CRITICAL, new CriticalFilter(this));
    fmap.put(FilterType.TOXIC, new ToxicFilter(this));
    fmap.put(FilterType.UNLOCKS, new UnlockFilter(this));

    filterType = FilterType.LEVEL;

    lcl = new LevelClickListener();

    mpl = new MenuPopupListener();
    rgl = new RadioGroupListener();

    res = getResources();
    srsht = new EnumMap<SRSLevel, Drawable>(SRSLevel.class);
    srsht.put(SRSLevel.APPRENTICE, res.getDrawable(R.drawable.apprentice));
    srsht.put(SRSLevel.GURU, res.getDrawable(R.drawable.guru));
    srsht.put(SRSLevel.MASTER, res.getDrawable(R.drawable.master));
    srsht.put(SRSLevel.ENLIGHTEN, res.getDrawable(R.drawable.enlighten));
    srsht.put(SRSLevel.BURNED, res.getDrawable(R.drawable.burned));

    normalColor = res.getColor(R.color.normal);
    importantColor = res.getColor(R.color.important);
    selectedColor = res.getColor(R.color.selected);
    unselectedColor = res.getColor(R.color.unselected);

    lad = new LevelListAdapter();
    iad = new ItemListAdapter(Item.SortByType.INSTANCE, ItemInfo.AVAILABLE);

    iss = new ItemSearchDialog.State();
}

From source file:com.androzic.Androzic.java

public void initializePlugins() {
    PackageManager packageManager = getPackageManager();
    List<ResolveInfo> plugins;
    Intent initializationIntent = new Intent("com.androzic.plugins.action.INITIALIZE");

    // enumerate initializable plugins
    plugins = packageManager.queryBroadcastReceivers(initializationIntent, 0);
    for (ResolveInfo plugin : plugins) {
        // send initialization broadcast, we send it directly instead of sending
        // one broadcast for all plugins to wake up stopped plugins:
        // http://developer.android.com/about/versions/android-3.1.html#launchcontrols
        Intent intent = new Intent();
        intent.setClassName(plugin.activityInfo.packageName, plugin.activityInfo.name);
        intent.setAction(initializationIntent.getAction());
        sendBroadcast(intent);//from   w  w  w. j  a  va  2s. com
    }

    // enumerate plugins with preferences
    plugins = packageManager.queryIntentActivities(new Intent("com.androzic.plugins.preferences"), 0);
    for (ResolveInfo plugin : plugins) {
        Intent intent = new Intent();
        intent.setClassName(plugin.activityInfo.packageName, plugin.activityInfo.name);
        pluginPreferences.put(plugin.activityInfo.loadLabel(packageManager).toString(), intent);
    }

    // enumerate plugins with views
    plugins = packageManager.queryIntentActivities(new Intent("com.androzic.plugins.view"), 0);
    for (ResolveInfo plugin : plugins) {
        // get menu icon
        Drawable icon = null;
        try {
            Resources resources = packageManager
                    .getResourcesForApplication(plugin.activityInfo.applicationInfo);
            int id = resources.getIdentifier("ic_menu_view", "drawable", plugin.activityInfo.packageName);
            if (id != 0)
                icon = resources.getDrawable(id);
        } catch (Resources.NotFoundException e) {
            e.printStackTrace();
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        Intent intent = new Intent();
        intent.setClassName(plugin.activityInfo.packageName, plugin.activityInfo.name);
        Pair<Drawable, Intent> pair = new Pair<>(icon, intent);
        pluginViews.put(plugin.activityInfo.loadLabel(packageManager).toString(), pair);
    }
}

From source file:com.marlonjones.voidlauncher.CellLayout.java

public CellLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
    // the user where a dragged item will land when dropped.
    setWillNotDraw(false);//from w w w .j a  v a  2 s.co m
    setClipToPadding(false);
    mLauncher = Launcher.getLauncher(context);

    DeviceProfile grid = mLauncher.getDeviceProfile();

    mCellWidth = mCellHeight = -1;
    mFixedCellWidth = mFixedCellHeight = -1;
    mWidthGap = mOriginalWidthGap = 0;
    mHeightGap = mOriginalHeightGap = 0;
    mMaxGap = Integer.MAX_VALUE;

    mCountX = grid.inv.numColumns;
    mCountY = grid.inv.numRows;
    mOccupied = new GridOccupancy(mCountX, mCountY);
    mTmpOccupied = new GridOccupancy(mCountX, mCountY);

    mPreviousReorderDirection[0] = INVALID_DIRECTION;
    mPreviousReorderDirection[1] = INVALID_DIRECTION;

    mFolderLeaveBehind.delegateCellX = -1;
    mFolderLeaveBehind.delegateCellY = -1;

    setAlwaysDrawnWithCacheEnabled(false);
    final Resources res = getResources();
    mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx;

    mBackground = (TransitionDrawable) res.getDrawable(
            FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND ? R.drawable.bg_screenpanel : R.drawable.bg_celllayout);
    mBackground.setCallback(this);
    mBackground.setAlpha((int) (mBackgroundAlpha * 255));

    mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx);

    // Initialize the data structures used for the drag visualization.
    mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out
    mDragCell[0] = mDragCell[1] = -1;
    for (int i = 0; i < mDragOutlines.length; i++) {
        mDragOutlines[i] = new Rect(-1, -1, -1, -1);
    }
    mDragOutlinePaint.setColor(getResources().getColor(R.color.outline_color));

    // When dragging things around the home screens, we show a green outline of
    // where the item will land. The outlines gradually fade out, leaving a trail
    // behind the drag path.
    // Set up all the animations that are used to implement this fading.
    final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime);
    final float fromAlphaValue = 0;
    final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha);

    Arrays.fill(mDragOutlineAlphas, fromAlphaValue);

    for (int i = 0; i < mDragOutlineAnims.length; i++) {
        final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue,
                toAlphaValue);
        anim.getAnimator().setInterpolator(mEaseOutInterpolator);
        final int thisIndex = i;
        anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                final Bitmap outline = (Bitmap) anim.getTag();

                // If an animation is started and then stopped very quickly, we can still
                // get spurious updates we've cleared the tag. Guard against this.
                if (outline == null) {
                    if (LOGD) {
                        Object val = animation.getAnimatedValue();
                        Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped());
                    }
                    // Try to prevent it from continuing to run
                    animation.cancel();
                } else {
                    mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
                    CellLayout.this.invalidate(mDragOutlines[thisIndex]);
                }
            }
        });
        // The animation holds a reference to the drag outline bitmap as long is it's
        // running. This way the bitmap can be GCed when the animations are complete.
        anim.getAnimator().addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) {
                    anim.setTag(null);
                }
            }
        });
        mDragOutlineAnims[i] = anim;
    }

    mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context);
    mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY);

    mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);

    mTouchFeedbackView = new ClickShadowView(context);
    addView(mTouchFeedbackView);
    addView(mShortcutsAndWidgets);
}

From source file:com.customprogrammingsolutions.MediaStreamer.MainActivity.java

private void setUpTabs() {
    Resources res = getResources();
    tabHost = (TabHost) findViewById(R.id.tabhost);
    tabHost.setup();//from   w  w  w . ja  va2 s.co m

    recentsAdapter = new SimpleCursorAdapter(this, R.layout.recent_item_layout, null,
            new String[] { RecentsDBHelper.KEY_URL }, new int[] { R.id.recent_url }, 0);
    favoritesAdapter = new SimpleCursorAdapter(this, R.layout.favorite_item_layout, null,
            new String[] { FavoritesDBHelper.KEY_URL, FavoritesDBHelper.KEY_NAME, FavoritesDBHelper.KEY_ROWID },
            new int[] { R.id.favorite_url, R.id.favorite_name, R.id.favorite_row_id }, 0);
    recents = (ListView) findViewById(R.id.recents_tab);
    recents.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    favorites = (ListView) findViewById(R.id.favorites_tab);
    favorites.setLayoutParams(
            new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    recents.setAdapter(recentsAdapter);
    favorites.setAdapter(favoritesAdapter);

    recents.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            TextView tv = (TextView) view.findViewById(R.id.recent_url);
            String url = tv.getText().toString();
            urlBar.setText(url);

            if (isPlayDrawable) {
                mediaStateButton.performClick();
            } else {
                mediaStateButton.performClick();
                mediaStateButton.performClick();
            }
        }

    });

    favorites.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            TextView tv = (TextView) view.findViewById(R.id.favorite_url);
            String url = tv.getText().toString();
            urlBar.setText(url);

            if (isPlayDrawable) {
                mediaStateButton.performClick();
            } else {
                mediaStateButton.performClick();
                mediaStateButton.performClick();
            }
        }

    });

    getSupportLoaderManager().initLoader(0, null, this);
    getSupportLoaderManager().initLoader(1, null, this);

    TabHost.TabSpec spec; // Resusable TabSpec for each tab
    spec = tabHost.newTabSpec("recents").setIndicator("Recents", res.getDrawable(R.drawable.ic_action_search))
            .setContent(R.id.recents_tab);
    tabHost.addTab(spec);
    spec = tabHost.newTabSpec("favorites")
            .setIndicator("Favorites", res.getDrawable(R.drawable.ic_action_search))
            .setContent(R.id.favorites_tab);
    tabHost.addTab(spec);
}

From source file:com.android.mylauncher3.CellLayout.java

public CellLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
    // the user where a dragged item will land when dropped.
    setWillNotDraw(false);/*  w w w  .jav a  2s  .  c o  m*/
    setClipToPadding(false);
    mLauncher = (Launcher) context;

    DeviceProfile grid = mLauncher.getDeviceProfile();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);

    mCellWidth = mCellHeight = -1;
    mFixedCellWidth = mFixedCellHeight = -1;
    mWidthGap = mOriginalWidthGap = 0;
    mHeightGap = mOriginalHeightGap = 0;
    mMaxGap = Integer.MAX_VALUE;
    mCountX = (int) grid.inv.numColumns;
    mCountY = (int) grid.inv.numRows;
    mOccupied = new boolean[mCountX][mCountY];
    mTmpOccupied = new boolean[mCountX][mCountY];
    mPreviousReorderDirection[0] = INVALID_DIRECTION;
    mPreviousReorderDirection[1] = INVALID_DIRECTION;

    a.recycle();

    setAlwaysDrawnWithCacheEnabled(false);

    final Resources res = getResources();
    mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx;

    mBackground = (TransitionDrawable) res.getDrawable(R.drawable.bg_screenpanel);
    mBackground.setCallback(this);
    mBackground.setAlpha((int) (mBackgroundAlpha * 255));

    mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx);

    // Initialize the data structures used for the drag visualization.
    mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out
    mDragCell[0] = mDragCell[1] = -1;
    for (int i = 0; i < mDragOutlines.length; i++) {
        mDragOutlines[i] = new Rect(-1, -1, -1, -1);
    }

    // When dragging things around the home screens, we show a green outline of
    // where the item will land. The outlines gradually fade out, leaving a trail
    // behind the drag path.
    // Set up all the animations that are used to implement this fading.
    final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime);
    final float fromAlphaValue = 0;
    final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha);

    Arrays.fill(mDragOutlineAlphas, fromAlphaValue);

    for (int i = 0; i < mDragOutlineAnims.length; i++) {
        final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue,
                toAlphaValue);
        anim.getAnimator().setInterpolator(mEaseOutInterpolator);
        final int thisIndex = i;
        anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                final Bitmap outline = (Bitmap) anim.getTag();

                // If an animation is started and then stopped very quickly, we can still
                // get spurious updates we've cleared the tag. Guard against this.
                if (outline == null) {
                    @SuppressWarnings("all") // suppress dead code warning
                    final boolean debug = false;
                    if (debug) {
                        Object val = animation.getAnimatedValue();
                        Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped());
                    }
                    // Try to prevent it from continuing to run
                    animation.cancel();
                } else {
                    mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
                    CellLayout.this.invalidate(mDragOutlines[thisIndex]);
                }
            }
        });
        // The animation holds a reference to the drag outline bitmap as long is it's
        // running. This way the bitmap can be GCed when the animations are complete.
        anim.getAnimator().addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) {
                    anim.setTag(null);
                }
            }
        });
        mDragOutlineAnims[i] = anim;
    }

    mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context);
    mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY);

    mStylusEventHelper = new StylusEventHelper(this);

    mTouchFeedbackView = new ClickShadowView(context);
    addView(mTouchFeedbackView);
    addView(mShortcutsAndWidgets);
}

From source file:com.android.zlauncher.CellLayout.java

public CellLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
    // the user where a dragged item will land when dropped.
    setWillNotDraw(false);/*w w w .ja  v  a 2  s. c  om*/
    setClipToPadding(false);
    mLauncher = (Launcher) context;

    DeviceProfile grid = mLauncher.getDeviceProfile();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);

    mCellWidth = mCellHeight = -1;
    mFixedCellWidth = mFixedCellHeight = -1;
    mWidthGap = mOriginalWidthGap = 0;
    mHeightGap = mOriginalHeightGap = 0;
    mMaxGap = Integer.MAX_VALUE;
    mCountX = (int) grid.inv.numColumns;
    mCountY = (int) grid.inv.numRows;
    mOccupied = new boolean[mCountX][mCountY];
    mTmpOccupied = new boolean[mCountX][mCountY];
    mPreviousReorderDirection[0] = INVALID_DIRECTION;
    mPreviousReorderDirection[1] = INVALID_DIRECTION;

    a.recycle();

    setAlwaysDrawnWithCacheEnabled(false);

    final Resources res = getResources();
    mHotseatScale = (float) grid.hotseatIconSizePx / grid.iconSizePx;

    mBackground = (TransitionDrawable) res.getDrawable(R.drawable.bg_screenpanel);
    mBackground.setCallback(this);
    mBackground.setAlpha((int) (mBackgroundAlpha * 255));

    mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx);

    // Initialize the data structures used for the drag visualization.
    mEaseOutInterpolator = new DecelerateInterpolator(2.5f); // Quint ease out
    mDragCell[0] = mDragCell[1] = -1;
    for (int i = 0; i < mDragOutlines.length; i++) {
        mDragOutlines[i] = new Rect(-1, -1, -1, -1);
    }

    // When dragging things around the home screens, we show a green outline of
    // where the item will land. The outlines gradually fade out, leaving a trail
    // behind the drag path.
    // Set up all the animations that are used to implement this fading.
    final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime);
    final float fromAlphaValue = 0;
    final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha);

    Arrays.fill(mDragOutlineAlphas, fromAlphaValue);

    for (int i = 0; i < mDragOutlineAnims.length; i++) {
        final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue,
                toAlphaValue);
        anim.getAnimator().setInterpolator(mEaseOutInterpolator);
        final int thisIndex = i;
        anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                final Bitmap outline = (Bitmap) anim.getTag();

                // If an animation is started and then stopped very quickly, we can still
                // get spurious updates we've cleared the tag. Guard against this.
                if (outline == null) {
                    @SuppressWarnings("all") // suppress dead code warning
                    final boolean debug = false;
                    if (debug) {
                        Object val = animation.getAnimatedValue();
                        Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped());
                    }
                    // Try to prevent it from continuing to run
                    animation.cancel();
                } else {
                    mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
                    CellLayout.this.invalidate(mDragOutlines[thisIndex]);
                }
            }
        });
        // The animation holds a reference to the drag outline bitmap as long is it's
        // running. This way the bitmap can be GCed when the animations are complete.
        anim.getAnimator().addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) {
                    anim.setTag(null);
                }
            }
        });
        mDragOutlineAnims[i] = anim;
    }

    mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context);
    mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY);

    mStylusEventHelper = new StylusEventHelper(this);

    /*       mTouchFeedbackView = new ClickShadowView(context);
           addView(mTouchFeedbackView);*/
    addView(mShortcutsAndWidgets);
}

From source file:com.google.android.apps.gutenberg.ScannerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scanner);
    // Resources//from   w  ww. j  a v  a  2 s . c o m
    final Resources resources = getResources();
    mColorTabSelected = resources.getColor(R.color.tab_selected);
    mColorTabUnselected = resources.getColor(R.color.tab_unselected);
    mColorTabIndicator = resources.getColor(R.color.primary_dark);
    mToolbarElevation = resources.getDimensionPixelSize(R.dimen.toolbar_elevation);
    GutenbergApplication app = GutenbergApplication.from(this);
    mImageLoader = new ImageLoader(app.getRequestQueue(), app.getBitmapCache());
    // Set up the Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Set up the Fragments
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().replace(R.id.scanner, ScannerFragment.newInstance())
                .replace(R.id.event_selector, EventSelectionFragment.newInstance()).commit();
    }
    // Set up the ViewPager
    mPanelLayout = (RecyclerViewSlidingUpPanelLayout) findViewById(R.id.layout);
    mTabLayout = (TabLayout) findViewById(R.id.tabs);
    mTabLayout.getViewTreeObserver().addOnGlobalLayoutListener(mTabLayoutListener);
    mViewPager = (DrawerViewPager) findViewById(R.id.pager);
    mAdapter = new ScannerPagerAdapter(getSupportFragmentManager(), this);
    mViewPager.setAdapter(mAdapter);
    mTabLayout.addTabsFromPagerAdapter(mAdapter);
    int tabCount = mAdapter.getCount();
    mTabs = new AppCompatTextView[tabCount];
    LayoutInflater inflater = LayoutInflater.from(this);
    for (int i = 0; i < tabCount; i++) {
        mTabs[i] = (AppCompatTextView) inflater.inflate(R.layout.tab, mTabLayout, false);
        mTabs[i].setText(mAdapter.getPageTitle(i));
        mTabLayout.getTabAt(i).setCustomView(mTabs[i]);
    }
    mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            mViewPager.setCurrentItem(tab.getPosition(), true);
            mTabs[tab.getPosition()].setTextColor(mColorTabSelected);
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            mTabs[tab.getPosition()].setTextColor(mColorTabUnselected);
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    mPanelLayout.setPanelSlideListener(mPanelSlideListener);
    mViewPager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            VIEW_PAGER_PAGE_MARGIN, resources.getDisplayMetrics()));
    mViewPager.setPageMarginDrawable(resources.getDrawable(R.drawable.page_margin));
    final ViewPager.OnPageChangeListener onPageChangeListener = mTabLayout.createOnPageChangeListener();
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            onPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
        }

        @Override
        public void onPageSelected(int position) {
            onPageChangeListener.onPageSelected(position);
            mPanelLayout.setRecyclerView(mAdapter.getItem(position).getRecyclerView());
        }
    });
    mAdapter.getItem(mViewPager.getCurrentItem())
            .setOnRecyclerViewReadyListener(new RecyclerViewFragment.OnRecyclerViewReadyListener() {
                @Override
                public void onRecyclerViewReady(RecyclerView rv) {
                    mPanelLayout.setRecyclerView(rv);
                }
            });
    mViewPager.setOnClickListenerWhenClosed(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
        }
    });
}

From source file:com.android.leanlauncher.CellLayout.java

public CellLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mDragEnforcer = new DropTarget.DragEnforcer(context);

    // A ViewGroup usually does not draw, but CellLayout needs to draw a rectangle to show
    // the user where a dragged item will land when dropped.
    setWillNotDraw(false);/*  w  w w .  j a  v  a 2  s  .co m*/
    setClipToPadding(false);
    mLauncher = (Launcher) context;

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CellLayout, defStyle, 0);

    mCellWidth = mCellHeight = -1;
    mFixedCellWidth = mFixedCellHeight = -1;
    mWidthGap = mOriginalWidthGap = 0;
    mHeightGap = mOriginalHeightGap = 0;
    mMaxGap = Integer.MAX_VALUE;
    mCountX = (int) grid.numColumns;
    mCountY = (int) grid.numRows;
    mOccupied = new boolean[mCountX][mCountY];
    mTmpOccupied = new boolean[mCountX][mCountY];
    mPreviousReorderDirection[0] = INVALID_DIRECTION;
    mPreviousReorderDirection[1] = INVALID_DIRECTION;

    a.recycle();

    setAlwaysDrawnWithCacheEnabled(false);

    final Resources res = getResources();

    mNormalBackground = res.getDrawable(R.drawable.screenpanel);
    mActiveGlowBackground = res.getDrawable(R.drawable.screenpanel_hover);

    mOverScrollLeft = res.getDrawable(R.drawable.overscroll_glow_left);
    mOverScrollRight = res.getDrawable(R.drawable.overscroll_glow_right);
    mForegroundPadding = res.getDimensionPixelSize(R.dimen.workspace_overscroll_drawable_padding);

    mReorderPreviewAnimationMagnitude = (REORDER_PREVIEW_MAGNITUDE * grid.iconSizePx);

    mNormalBackground.setFilterBitmap(true);
    mActiveGlowBackground.setFilterBitmap(true);

    // Initialize the data structures used for the drag visualization.
    TimeInterpolator easeOutInterpolator = new DecelerateInterpolator(2.5f);
    mDragCell[0] = mDragCell[1] = -1;
    for (int i = 0; i < mDragOutlines.length; i++) {
        mDragOutlines[i] = new Rect(-1, -1, -1, -1);
    }

    // When dragging things around the home screens, we show a green outline of
    // where the item will land. The outlines gradually fade out, leaving a trail
    // behind the drag path.
    // Set up all the animations that are used to implement this fading.
    final int duration = res.getInteger(R.integer.config_dragOutlineFadeTime);
    final float fromAlphaValue = 0;
    final float toAlphaValue = (float) res.getInteger(R.integer.config_dragOutlineMaxAlpha);

    Arrays.fill(mDragOutlineAlphas, fromAlphaValue);

    for (int i = 0; i < mDragOutlineAnims.length; i++) {
        final InterruptibleInOutAnimator anim = new InterruptibleInOutAnimator(this, duration, fromAlphaValue,
                toAlphaValue);
        anim.getAnimator().setInterpolator(easeOutInterpolator);
        final int thisIndex = i;
        anim.getAnimator().addUpdateListener(new AnimatorUpdateListener() {
            public void onAnimationUpdate(ValueAnimator animation) {
                final Bitmap outline = (Bitmap) anim.getTag();

                // If an animation is started and then stopped very quickly, we can still
                // get spurious updates we've cleared the tag. Guard against this.
                if (outline == null) {
                    @SuppressWarnings("all") // suppress dead code warning
                    final boolean debug = false;
                    if (debug) {
                        Object val = animation.getAnimatedValue();
                        Log.d(TAG, "anim " + thisIndex + " update: " + val + ", isStopped " + anim.isStopped());
                    }
                    // Try to prevent it from continuing to run
                    animation.cancel();
                } else {
                    mDragOutlineAlphas[thisIndex] = (Float) animation.getAnimatedValue();
                    CellLayout.this.invalidate(mDragOutlines[thisIndex]);
                }
            }
        });
        // The animation holds a reference to the drag outline bitmap as long is it's
        // running. This way the bitmap can be GCed when the animations are complete.
        anim.getAnimator().addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if ((Float) ((ValueAnimator) animation).getAnimatedValue() == 0f) {
                    anim.setTag(null);
                }
            }
        });
        mDragOutlineAnims[i] = anim;
    }

    mBackgroundRect = new Rect();
    mForegroundRect = new Rect();

    mShortcutsAndWidgets = new ShortcutAndWidgetContainer(context);
    mShortcutsAndWidgets.setCellDimensions(mCellWidth, mCellHeight, mWidthGap, mHeightGap, mCountX, mCountY);

    mTouchFeedbackView = new FastBitmapView(context);
    // Make the feedback view large enough to hold the blur bitmap.
    addView(mTouchFeedbackView, (int) (grid.cellWidthPx * 1.2), (int) (grid.cellHeightPx * 1.2));
    addView(mShortcutsAndWidgets);
}

From source file:com.tct.mail.browse.ConversationItemView.java

private static synchronized void getItemViewResources(Context context) {
    if (sConfigurationChangedReceiver == null) {
        sConfigurationChangedReceiver = new BroadcastReceiver() {
            @Override/* www .j a  v  a  2 s  . co  m*/
            public void onReceive(Context context, Intent intent) {
                STAR_OFF = null;
                //[BUGFIX]-Mod-BEGIN by TCTNB.caixia.chen,01/07/2015,PR 893304
                getItemViewResources(context.getApplicationContext());
                //[BUGFIX]-Mod-END by TCTNB.caixia.chen
            }
        };
        context.registerReceiver(sConfigurationChangedReceiver,
                new IntentFilter(Intent.ACTION_CONFIGURATION_CHANGED));
    }
    if (STAR_OFF == null) {
        final Resources res = context.getResources();
        // Initialize static bitmaps.
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 MOD-S
        // star off will not show in list item.
        //STAR_OFF = BitmapFactory.decodeResource(res, R.drawable.ic_star_outline_20dp);
        STAR_OFF = BitmapFactory.decodeResource(res, R.drawable.ic_importance_normal);
        //TS: junwei-xu 2015-09-02 EMAIL BUGFIX-546917 MOD-S
        STAR_ON = BitmapFactory.decodeResource(res, R.drawable.ic_star_20dp);
        ATTACHMENT = BitmapFactory.decodeResource(res, R.drawable.ic_attach_file_20dp);
        ONLY_TO_ME = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_double);
        TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_single);
        IMPORTANT_ONLY_TO_ME = BitmapFactory.decodeResource(res,
                R.drawable.ic_email_caret_double_important_unread);
        IMPORTANT_TO_ME_AND_OTHERS = BitmapFactory.decodeResource(res,
                R.drawable.ic_email_caret_single_important_unread);
        IMPORTANT = BitmapFactory.decodeResource(res, R.drawable.ic_email_caret_none_important_unread);
        STATE_REPLIED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_reply_holo_light);
        STATE_FORWARDED = BitmapFactory.decodeResource(res, R.drawable.ic_badge_forward_holo_light);
        STATE_REPLIED_AND_FORWARDED = BitmapFactory.decodeResource(res,
                R.drawable.ic_badge_reply_forward_holo_light);
        STATE_CALENDAR_INVITE = BitmapFactory.decodeResource(res, R.drawable.ic_badge_invite_holo_light);
        VISIBLE_CONVERSATION_HIGHLIGHT = res.getDrawable(R.drawable.visible_conversation_highlight);
        RIGHT_EDGE_TABLET = res.getDrawable(R.drawable.list_edge_tablet);
        //[FEATURE]-Add-BEGIN by TSCD.chao zhang,04/17/2014,FR 631895(porting from FR514398)
        sHighPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_high_priority);
        sLowPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_low_priority);
        sNormalPriorityIcon = BitmapFactory.decodeResource(res, R.drawable.ic_importance_normal);
        //[FEATURE]-Add-END by TSCD.chao zhang

        // Initialize colors.
        sActivatedTextSpan = CharacterStyle
                .wrap(new ForegroundColorSpan(res.getColor(R.color.senders_text_color)));
        sSendersTextColor = res.getColor(R.color.senders_text_color);
        sSubjectTextUnreadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceUnreadStyle);
        sSubjectTextReadSpan = new TextAppearanceSpan(context, R.style.SubjectAppearanceReadStyle);

        sBadgeTextSpan = new TextAppearanceSpan(context, R.style.BadgeTextStyle);
        sBadgeBackgroundSpan = new BackgroundColorSpan(res.getColor(R.color.badge_background_color));
        sDateTextColorRead = res.getColor(R.color.date_text_color_read);
        sDateTextColorUnread = res.getColor(R.color.date_text_color_unread);
        sStarTouchSlop = res.getDimensionPixelSize(R.dimen.star_touch_slop);
        sSenderImageTouchSlop = res.getDimensionPixelSize(R.dimen.sender_image_touch_slop);
        sShrinkAnimationDuration = res.getInteger(R.integer.shrink_animation_duration);
        sSlideAnimationDuration = res.getInteger(R.integer.slide_animation_duration);
        // Initialize static color.
        sSendersSplitToken = res.getString(R.string.senders_split_token);
        sElidedPaddingToken = res.getString(R.string.elided_padding_token);
        sScrollSlop = res.getInteger(R.integer.swipeScrollSlop);
        sFoldersStartPadding = res.getDimensionPixelOffset(R.dimen.folders_start_padding);
        sFoldersInnerPadding = res.getDimensionPixelOffset(R.dimen.folder_cell_content_padding);
        sFoldersMaxCount = res.getInteger(R.integer.conversation_list_max_folder_count);
        sFoldersOverflowGradientPadding = res.getDimensionPixelOffset(R.dimen.folders_gradient_padding);
        sCabAnimationDuration = res.getInteger(R.integer.conv_item_view_cab_anim_duration);
        sBadgePaddingExtraWidth = res.getDimensionPixelSize(R.dimen.badge_padding_extra_width);
        sBadgeRoundedCornerRadius = res.getDimensionPixelSize(R.dimen.badge_rounded_corner_radius);
        sFolderRoundedCornerRadius = res.getDimensionPixelOffset(R.dimen.folder_rounded_corner_radius);
        sDividerColor = res.getColor(R.color.conversation_list_divider_color);
        sDividerInset = res.getDimensionPixelSize(R.dimen.conv_list_divider_inset);
        sDividerHeight = res.getDimensionPixelSize(R.dimen.divider_height);
    }
}