Example usage for android.support.v4.content ContextCompat getDrawable

List of usage examples for android.support.v4.content ContextCompat getDrawable

Introduction

In this page you can find the example usage for android.support.v4.content ContextCompat getDrawable.

Prototype

public static final Drawable getDrawable(Context context, int i) 

Source Link

Usage

From source file:com.h6ah4i.android.example.advrecyclerview.demo_e_add_remove.AddRemoveExpandableExampleFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    //noinspection ConstantConditions
    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mLayoutManager = new LinearLayoutManager(getContext());

    final Parcelable eimSavedState = (savedInstanceState != null)
            ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER)
            : null;/* w  w  w.  j a  va2s  .  c  om*/
    mRecyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(eimSavedState);
    mRecyclerViewExpandableItemManager.setOnGroupExpandListener(this);
    mRecyclerViewExpandableItemManager.setOnGroupCollapseListener(this);

    //adapter
    final AddRemoveExpandableExampleAdapter myItemAdapter = new AddRemoveExpandableExampleAdapter(
            mRecyclerViewExpandableItemManager, getDataProvider());

    mAdapter = myItemAdapter;

    mWrappedAdapter = mRecyclerViewExpandableItemManager.createWrappedAdapter(myItemAdapter); // wrap for expanding

    final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();

    // Change animations are enabled by default since support-v7-recyclerview v22.
    // Need to disable them when using animation indicator.
    animator.setSupportsChangeAnimations(false);

    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter
    mRecyclerView.setItemAnimator(animator);
    mRecyclerView.setHasFixedSize(false);

    // additional decorations
    //noinspection StatementWithEmptyBody
    if (supportsViewElevation()) {
        // Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required.
    } else {
        mRecyclerView.addItemDecoration(new ItemShadowDecorator(
                (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1)));
    }
    mRecyclerView.addItemDecoration(new SimpleListDividerDecorator(
            ContextCompat.getDrawable(getContext(), R.drawable.list_divider_h), true));

    mRecyclerViewExpandableItemManager.attachRecyclerView(mRecyclerView);
}

From source file:com.hippo.preference.DialogPreference.java

/**
 * Sets the icon (resource ID) of the dialog. This will be shown on
 * subsequent dialogs./*from w w w . ja va 2  s  .c o  m*/
 *
 * @param dialogIconRes The icon, as a resource ID.
 */
public void setDialogIcon(@DrawableRes int dialogIconRes) {
    mDialogIcon = ContextCompat.getDrawable(getContext(), dialogIconRes);
}

From source file:agricultural.nxt.agriculturalsupervision.Activity.company.CompanyActivity.java

@Override
protected void initView() {
    application = MyApplication.getInstance();
    toolBar.setTitle("?");
    toolBar.setLeftButtonIcon(ContextCompat.getDrawable(this, R.mipmap.icon_arrow_02));
    toolBar.setLeftButtonOnClickLinster(v -> finish());
    mBaiduMap = mapview.getMap();/* ww w  .  j a  va 2  s  .c o m*/
    MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f);
    mBaiduMap.setMapStatus(msu);
    mBaiduMap.setOnMapTouchListener(this);
    //?
    mBaiduMap.setOnMapClickListener(new BaiduMap.OnMapClickListener() {
        @Override
        public void onMapClick(LatLng latLng) {
            //??
            double latitude = latLng.latitude;
            double longitude = latLng.longitude;
            Log.i(TAG, "latitude=" + latitude + "," + "longitude=" + longitude);
            vcgpsx.setText(longitude + "");
            fgpsy.setText(latitude + "");
            //
            mBaiduMap.clear();
            // Maker??
            LatLng point = new LatLng(latitude, longitude);
            // MarkerOptionMarker
            MarkerOptions options = new MarkerOptions().position(point).icon(bitmap);
            // Marker
            mBaiduMap.addOverlay(options);
            //??
            GeoCoder geoCoder = GeoCoder.newInstance();
            //???????
            ReverseGeoCodeOption op = new ReverseGeoCodeOption();
            op.location(point);
            //?????(?->??)
            geoCoder.reverseGeoCode(op);
            geoCoder.setOnGetGeoCodeResultListener(new OnGetGeoCoderResultListener() {
                @Override
                public void onGetGeoCodeResult(GeoCodeResult geoCodeResult) {

                }

                @Override
                public void onGetReverseGeoCodeResult(ReverseGeoCodeResult reverseGeoCodeResult) {
                    String ss = reverseGeoCodeResult.getAddress();
                    vcaddress.setText(reverseGeoCodeResult.getAddress());
                }
            });
        }

        @Override
        public boolean onMapPoiClick(MapPoi mapPoi) {
            return false;
        }
    });

    url = Constants.COMPANY_MANAGER;

    OkhttpHelper.Get(url, new OkhttpHelper.GetCallBack() {
        @Override
        public void onSuccess(String response, int tag) {
            if (null != response) {
                Company company = new Gson().fromJson(response, Company.class);
                CompanyId = company.getData().getId();
                areaname.setText(company.getData().getArea().getName());
                areaname.setKeyListener(null);
                vcorgname.setText(company.getData().getVcorgname());
                vcorgname.setKeyListener(null);
                ikind.setKeyListener(null);
                String type = company.getData().getIkind();
                if ("0".equalsIgnoreCase(type)) {
                    ikind.setText("?");
                } else if ("1".equalsIgnoreCase(type)) {
                    ikind.setText("?");
                } else if ("2".equalsIgnoreCase(type)) {
                    ikind.setText("??");
                }
                List<String> onwntype = company.getData().getOwnerscopeTypes();
                for (int i = 0; i < onwntype.size(); i++) {
                    if (onwntype.get(i).equalsIgnoreCase("0")) {
                        seed.setChecked(true);
                        seed.setClickable(false);
                    } else if (onwntype.get(i).equalsIgnoreCase("1")) {
                        pesticide.setChecked(true);
                        pesticide.setClickable(false);
                    } else if (onwntype.get(i).equalsIgnoreCase("2")) {
                        fertilizer.setChecked(true);
                        fertilizer.setClickable(false);
                    }
                }
                vccorporation.setText(company.getData().getVccorporation());
                vccorporation.setKeyListener(null);
                vcidnumber.setText(company.getData().getVcidnumber());
                vcphone.setText(company.getData().getVcphone());
                vcemail.setText(company.getData().getVcemail());
                mGpsX = Double.parseDouble(company.getData().getVcgpsx());
                mGpsY = Double.parseDouble(company.getData().getFgpsy());
                vcaddress.setText(company.getData().getVcaddress());
                vcgpsx.setText(company.getData().getVcgpsx());
                fgpsy.setText(company.getData().getFgpsy());
                if (!TextUtils.isEmpty(company.getData().getVcgpsx())
                        & !TextUtils.isEmpty(company.getData().getFgpsy())) {
                    getMapByLatLng();
                }
                //?
                vcbizlicense.setText(company.getData().getVcbizlicense());
                vcbizlicense.setKeyListener(null);
                cbizlicedate.setText(company.getData().getVcbizlicedate());
                //??
                vcproductlicense.setText(company.getData().getVcproductlicense());
                vcproductlicense.setKeyListener(null);
                dtprodlicendate.setText(company.getData().getDtprodlicendate());
                String status = company.getData().getIcheckstatus();
                if ("-2".equalsIgnoreCase(status)) {
                    icheckstatus.setText("??");
                } else if ("-1".equalsIgnoreCase(status)) {
                    icheckstatus.setText("");
                } else if ("0".equalsIgnoreCase(status)) {
                    icheckstatus.setText("");
                } else if ("1".equalsIgnoreCase(status)) {
                    icheckstatus.setText("");
                }
                vccheckerName.setText(company.getData().getVccheckerName());
                tcheckdate.setText(company.getData().getDtcheckdate());
                Glide.with(CompanyActivity.this).load(Constants.IMG_HEAD + company.getData().getVcbizlicepic())
                        .crossFade().into(img1);
                Glide.with(CompanyActivity.this)
                        .load(Constants.IMG_HEAD + company.getData().getVcprodlicenpic()).crossFade()
                        .into(img2);
            }
        }

        @Override
        public void onFailed(String error, int tag) {

        }
    }, 1);

    //

    //        recycler_view.init(this,MultiPickResultView.ACTION_ONLY_SHOW,imgpath);
    //        recycler_view2.init(this,MultiPickResultView.ACTION_ONLY_SHOW,imgpath2);

}

From source file:com.google.blockly.android.ui.TrashCanView.java

/**
 * Assigns a drawable resource id for the hovered state, when a block has been dragged above
 * this view. Usually, this is a open trashcan.
 *
 * @param drawableRes Drawable resource id for the hovered
 */// ww  w .j  av a  2 s  . c o m
public void setOnHoverIcon(int drawableRes) {
    setOnHoverIcon(ContextCompat.getDrawable(getContext(), drawableRes));
}

From source file:com.bachhuberdesign.deckbuildergwent.util.FabTransform.java

@Override
public Animator createAnimator(final ViewGroup sceneRoot, final TransitionValues startValues,
        final TransitionValues endValues) {
    if (startValues == null || endValues == null)
        return null;

    final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
    final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);

    final boolean fromFab = endBounds.width() > startBounds.width();
    final View view = endValues.view;
    final Rect dialogBounds = fromFab ? endBounds : startBounds;
    final Interpolator fastOutSlowInInterpolator = AnimUtils.getFastOutSlowInInterpolator();
    final long duration = getDuration();
    final long halfDuration = duration / 2;
    final long twoThirdsDuration = duration * 2 / 3;

    if (!fromFab) {
        // Force measure / layout the dialog back to it's original bounds
        view.measure(makeMeasureSpec(startBounds.width(), View.MeasureSpec.EXACTLY),
                makeMeasureSpec(startBounds.height(), View.MeasureSpec.EXACTLY));
        view.layout(startBounds.left, startBounds.top, startBounds.right, startBounds.bottom);
    }/*from   ww  w . j a v  a  2s.  c  o m*/

    final int translationX = startBounds.centerX() - endBounds.centerX();
    final int translationY = startBounds.centerY() - endBounds.centerY();
    if (fromFab) {
        view.setTranslationX(translationX);
        view.setTranslationY(translationY);
    }

    // Add a color overlay to fake appearance of the FAB
    final ColorDrawable fabColor = new ColorDrawable(color);
    fabColor.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
    if (!fromFab)
        fabColor.setAlpha(0);
    view.getOverlay().add(fabColor);

    // Add an icon overlay again to fake the appearance of the FAB
    final Drawable fabIcon = ContextCompat.getDrawable(sceneRoot.getContext(), icon).mutate();
    final int iconLeft = (dialogBounds.width() - fabIcon.getIntrinsicWidth()) / 2;
    final int iconTop = (dialogBounds.height() - fabIcon.getIntrinsicHeight()) / 2;
    fabIcon.setBounds(iconLeft, iconTop, iconLeft + fabIcon.getIntrinsicWidth(),
            iconTop + fabIcon.getIntrinsicHeight());
    if (!fromFab)
        fabIcon.setAlpha(0);
    view.getOverlay().add(fabIcon);

    // Since the view that's being transition to always seems to be on the top (z-order), we have
    // to make a copy of the "from" view and put it in the "to" view's overlay, then fade it out.
    // There has to be another way to do this, right?
    Drawable dialogView = null;
    if (!fromFab) {
        startValues.view.setDrawingCacheEnabled(true);
        startValues.view.buildDrawingCache();
        Bitmap viewBitmap = startValues.view.getDrawingCache();
        dialogView = new BitmapDrawable(view.getResources(), viewBitmap);
        dialogView.setBounds(0, 0, dialogBounds.width(), dialogBounds.height());
        view.getOverlay().add(dialogView);
    }

    // Circular clip from/to the FAB size
    final Animator circularReveal;
    if (fromFab) {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, startBounds.width() / 2,
                (float) Math.hypot(endBounds.width() / 2, endBounds.height() / 2));
        circularReveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator());
    } else {
        circularReveal = ViewAnimationUtils.createCircularReveal(view, view.getWidth() / 2,
                view.getHeight() / 2, (float) Math.hypot(startBounds.width() / 2, startBounds.height() / 2),
                endBounds.width() / 2);
        circularReveal.setInterpolator(AnimUtils.getLinearOutSlowInInterpolator());

        // Persist the end clip i.e. stay at FAB size after the reveal has run
        circularReveal.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                final ViewOutlineProvider fabOutlineProvider = view.getOutlineProvider();

                view.setOutlineProvider(new ViewOutlineProvider() {
                    boolean hasRun = false;

                    @Override
                    public void getOutline(final View view, Outline outline) {
                        final int left = (view.getWidth() - endBounds.width()) / 2;
                        final int top = (view.getHeight() - endBounds.height()) / 2;

                        outline.setOval(left, top, left + endBounds.width(), top + endBounds.height());

                        if (!hasRun) {
                            hasRun = true;
                            view.setClipToOutline(true);

                            // We have to remove this as soon as it's laid out so we can get the shadow back
                            view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
                                @Override
                                public boolean onPreDraw() {
                                    if (view.getWidth() == endBounds.width()
                                            && view.getHeight() == endBounds.height()) {
                                        view.setOutlineProvider(fabOutlineProvider);
                                        view.setClipToOutline(false);
                                        view.getViewTreeObserver().removeOnPreDrawListener(this);
                                        return true;
                                    }

                                    return true;
                                }
                            });
                        }
                    }
                });
            }
        });
    }
    circularReveal.setDuration(duration);

    // Translate to end position along an arc
    final Animator translate = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, View.TRANSLATION_Y,
            fromFab ? getPathMotion().getPath(translationX, translationY, 0, 0)
                    : getPathMotion().getPath(0, 0, -translationX, -translationY));
    translate.setDuration(duration);
    translate.setInterpolator(fastOutSlowInInterpolator);

    // Fade contents of non-FAB view in/out
    List<Animator> fadeContents = null;
    if (view instanceof ViewGroup) {
        final ViewGroup vg = ((ViewGroup) view);
        fadeContents = new ArrayList<>(vg.getChildCount());
        for (int i = vg.getChildCount() - 1; i >= 0; i--) {
            final View child = vg.getChildAt(i);
            final Animator fade = ObjectAnimator.ofFloat(child, View.ALPHA, fromFab ? 1f : 0f);
            if (fromFab) {
                child.setAlpha(0f);
            }
            fade.setDuration(twoThirdsDuration);
            fade.setInterpolator(fastOutSlowInInterpolator);
            fadeContents.add(fade);
        }
    }

    // Fade in/out the fab color & icon overlays
    final Animator colorFade = ObjectAnimator.ofInt(fabColor, "alpha", fromFab ? 0 : 255);
    final Animator iconFade = ObjectAnimator.ofInt(fabIcon, "alpha", fromFab ? 0 : 255);
    if (!fromFab) {
        colorFade.setStartDelay(halfDuration);
        iconFade.setStartDelay(halfDuration);
    }
    colorFade.setDuration(halfDuration);
    iconFade.setDuration(halfDuration);
    colorFade.setInterpolator(fastOutSlowInInterpolator);
    iconFade.setInterpolator(fastOutSlowInInterpolator);

    // Run all animations together
    final AnimatorSet transition = new AnimatorSet();
    transition.playTogether(circularReveal, translate, colorFade, iconFade);
    transition.playTogether(fadeContents);
    if (dialogView != null) {
        final Animator dialogViewFade = ObjectAnimator.ofInt(dialogView, "alpha", 0)
                .setDuration(twoThirdsDuration);
        dialogViewFade.setInterpolator(fastOutSlowInInterpolator);
        transition.playTogether(dialogViewFade);
    }
    transition.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            // Clean up
            view.getOverlay().clear();

            if (!fromFab) {
                view.setTranslationX(0);
                view.setTranslationY(0);
                view.setTranslationZ(0);

                view.measure(makeMeasureSpec(endBounds.width(), View.MeasureSpec.EXACTLY),
                        makeMeasureSpec(endBounds.height(), View.MeasureSpec.EXACTLY));
                view.layout(endBounds.left, endBounds.top, endBounds.right, endBounds.bottom);
            }

        }
    });
    return new AnimUtils.NoPauseAnimator(transition);
}

From source file:com.filemanager.free.activities.TextReader.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Sp = PreferenceManager.getDefaultSharedPreferences(this);

    if (theme1 == 1) {
        getWindow().getDecorView().setBackgroundColor(ContextCompat.getColor(c, R.color.holo_dark_background));
    }// w ww  .  j  av a  2s  . com
    setContentView(R.layout.search);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    skin = PreferenceUtils.getPrimaryColorString(Sp);
    findViewById(R.id.lin).setBackgroundColor(Color.parseColor(skin));
    if (Build.VERSION.SDK_INT >= 21) {
        ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("File Manager",
                ((BitmapDrawable) ContextCompat.getDrawable(c, R.mipmap.ic_launcher)).getBitmap(),
                Color.parseColor(skin));
        ((Activity) this).setTaskDescription(taskDescription);
    }
    int skinStatusBar = PreferenceUtils.getStatusColor(skin);
    assert (getSupportActionBar()) != null;
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(skin)));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    if (Build.VERSION.SDK_INT == 20 || Build.VERSION.SDK_INT == 19) {
        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintColor(Color.parseColor(skin));
        FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.texteditor)
                .getLayoutParams();
        SystemBarTintManager.SystemBarConfig config = tintManager.getConfig();
        p.setMargins(0, config.getStatusBarHeight(), 0, 0);
    } else if (Build.VERSION.SDK_INT >= 21) {
        boolean colourednavigation = Sp.getBoolean("colorednavigation", true);
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor((PreferenceUtils.getStatusColor(skin)));
        if (colourednavigation)
            window.setNavigationBarColor((PreferenceUtils.getStatusColor(skin)));

    }
    mInput = (EditText) findViewById(R.id.fname);
    scrollView = (ScrollView) findViewById(R.id.editscroll);

    try {
        if (getIntent().getData() != null) {
            uri = getIntent().getData();

            mFile = new File(getIntent().getData().getPath());
        } else
            mFile = new File(getIntent().getStringExtra("path"));
    } catch (Exception e) {
        mFile = null;
    }
    String fileName = null;
    try {
        if (uri.getScheme().equals("file")) {
            fileName = uri.getLastPathSegment();
        } else {
            Cursor cursor = null;
            try {
                cursor = getContentResolver().query(uri,
                        new String[] { MediaStore.Images.ImageColumns.DISPLAY_NAME }, null, null, null);

                if (cursor != null && cursor.moveToFirst()) {
                    fileName = cursor
                            .getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME));
                }
            } finally {

                if (cursor != null) {
                    cursor.close();
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (fileName == null || fileName.trim().length() == 0)
        fileName = f.getName();
    getSupportActionBar().setTitle(fileName);
    mInput.addTextChangedListener(this);
    try {
        if (theme1 == 1)
            mInput.setBackgroundColor(ContextCompat.getColor(c, R.color.holo_dark_background));
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    } catch (Exception ignored) {

    }
    if (savedInstanceState != null) {
        mOriginal = savedInstanceState.getString(KEY_ORIGINAL_TEXT);
        int index = savedInstanceState.getInt(KEY_INDEX);
        mInput.setText(savedInstanceState.getString(KEY_MODIFIED_TEXT));
        mInput.setScrollY(index);
    } else {
        load(mFile);
    }
}

From source file:com.example.chu.googleplaylibrary.ui.FullScreenPlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_player);
    initializeToolbar();/*from  w  w  w.j a v  a 2s.  c o  m*/
    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("");
    }

    mBackgroundImage = (ImageView) findViewById(R.id.background_image);
    mPauseDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_pause_white_48dp);
    mPlayDrawable = ContextCompat.getDrawable(this, R.drawable.uamp_ic_play_arrow_white_48dp);
    mPlayPause = (ImageView) findViewById(R.id.play_pause);
    mSkipNext = (ImageView) findViewById(R.id.next);
    mSkipPrev = (ImageView) findViewById(R.id.prev);
    mStart = (TextView) findViewById(R.id.startText);
    mEnd = (TextView) findViewById(R.id.endText);
    mSeekbar = (SeekBar) findViewById(R.id.seekBar1);
    mLine1 = (TextView) findViewById(R.id.line1);
    mLine2 = (TextView) findViewById(R.id.line2);
    mLine3 = (TextView) findViewById(R.id.line3);
    mLoading = (ProgressBar) findViewById(R.id.progressBar1);
    mControllers = findViewById(R.id.controllers);

    mSkipNext.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToNext();
        }
    });

    mSkipPrev.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = getSupportMediaController()
                    .getTransportControls();
            controls.skipToPrevious();
        }
    });

    mPlayPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PlaybackStateCompat state = getSupportMediaController().getPlaybackState();
            if (state != null) {
                MediaControllerCompat.TransportControls controls = getSupportMediaController()
                        .getTransportControls();
                switch (state.getState()) {
                case PlaybackStateCompat.STATE_PLAYING: // fall through
                case PlaybackStateCompat.STATE_BUFFERING:
                    controls.pause();
                    stopSeekbarUpdate();
                    break;
                case PlaybackStateCompat.STATE_PAUSED:
                case PlaybackStateCompat.STATE_STOPPED:
                    controls.play();
                    scheduleSeekbarUpdate();
                    break;
                default:
                    LogHelper.d(TAG, "onClick with state ", state.getState());
                }
            }
        }
    });

    mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mStart.setText(DateUtils.formatElapsedTime(progress / 1000));
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            stopSeekbarUpdate();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            getSupportMediaController().getTransportControls().seekTo(seekBar.getProgress());
            scheduleSeekbarUpdate();
        }
    });

    // Only update from the intent if we are not recreating from a config change:
    if (savedInstanceState == null) {
        //updateFromParams(getIntent());
    }

    mMediaBrowser = new MediaBrowserCompat(this, new ComponentName(this, MusicService.class),
            mConnectionCallback, null);
}

From source file:com.barak.pix.PostViewHolder.java

public void setLikeStatus(LikeStatus status, Context context) {
    mLikeIcon.setImageDrawable(ContextCompat.getDrawable(context,
            status == LikeStatus.LIKED ? R.drawable.heart_full : R.drawable.heart_empty));
}

From source file:com.h6ah4i.android.example.advrecyclerview.demo_us.RecyclerListViewFragment.java

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    //noinspection ConstantConditions
    mRecyclerView = (RecyclerView) getView().findViewById(R.id.recycler_view);
    mLayoutManager = new LinearLayoutManager(getContext());

    // touch guard manager  (this class is required to suppress scrolling while swipe-dismiss animation is running)
    mRecyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
    mRecyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
    mRecyclerViewTouchActionGuardManager.setEnabled(true);

    // swipe manager
    mRecyclerViewSwipeManager = new RecyclerViewSwipeManager();

    //adapter// w w  w .  j av  a2 s  . c  om
    final MyUnderSwipeableItemAdapter myItemAdapter = new MyUnderSwipeableItemAdapter(getDataProvider());
    myItemAdapter.setEventListener(new MyUnderSwipeableItemAdapter.EventListener() {
        @Override
        public void onItemPinned(int position) {
            ((UnderSwipeableExampleActivity) getActivity()).onItemPinned(position);
        }

        @Override
        public void onItemViewClicked(View v) {
            handleOnItemViewClicked(v);
        }

        @Override
        public void onUnderSwipeableViewButtonClicked(View v) {
            handleOnUnderSwipeableViewButtonClicked(v);
        }
    });

    mAdapter = myItemAdapter;

    mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(myItemAdapter); // wrap for swiping

    final GeneralItemAnimator animator = new SwipeDismissItemAnimator();

    // Change animations are enabled by default since support-v7-recyclerview v22.
    // Disable the change animation in order to make turning back animation of swiped item works properly.
    animator.setSupportsChangeAnimations(false);

    mRecyclerView.setLayoutManager(mLayoutManager);
    mRecyclerView.setAdapter(mWrappedAdapter); // requires *wrapped* adapter
    mRecyclerView.setItemAnimator(animator);

    // additional decorations
    //noinspection StatementWithEmptyBody
    if (supportsViewElevation()) {
        // Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required.
    } else {
        mRecyclerView.addItemDecoration(new ItemShadowDecorator(
                (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1)));
    }
    mRecyclerView.addItemDecoration(new SimpleListDividerDecorator(
            ContextCompat.getDrawable(getContext(), R.drawable.list_divider_h), true));

    // NOTE:
    // The initialization order is very important! This order determines the priority of touch event handling.
    //
    // priority: TouchActionGuard > Swipe > DragAndDrop
    mRecyclerViewTouchActionGuardManager.attachRecyclerView(mRecyclerView);
    mRecyclerViewSwipeManager.attachRecyclerView(mRecyclerView);

    // for debugging
    //        animator.setDebug(true);
    //        animator.setMoveDuration(2000);
    //        mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000);
    //        mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000);
}

From source file:ca.hoogit.garagepi.Controls.DoorView.java

protected void setupViews() {
    mToggleContainer.setBackgroundColor(mDoorValue ? mOpenedColor : mClosedColor);

    mNameTextView/*w ww . j  a  v a2s.c  o  m*/
            .setText(mDoorName.isEmpty() ? mContext.getString(R.string.door_view_default_name) : mDoorName);

    int drawableId = mDoorValue ? R.drawable.ic_arrow_downward_black_24dp
            : R.drawable.ic_arrow_upward_black_24dp;
    mArrowImageView.setImageDrawable(ContextCompat.getDrawable(mContext, drawableId));

    int stringId = mDoorValue ? R.string.door_view_status_close : R.string.door_view_status_open;
    mStatusTextView.setText(mContext.getString(stringId));
}