Search in sources :

Example 1 with ContextCompat.getDrawable

use of android.support.v4.content.ContextCompat.getDrawable in project Rashr by DsLNeXuS.

the class BackupRestoreFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_backup_restore, container, false);
    mActivity = (RashrActivity) getActivity();
    mContext = root.getContext();
    mPager = (ViewPager) root.findViewById(R.id.vpBackupRestore);
    mAdapter = new BackupRestorePagerAdapter(getChildFragmentManager());
    mPager.setAdapter(mAdapter);
    SlidingTabLayout slidingTabLayout = (SlidingTabLayout) root.findViewById(R.id.stlBackupRestore);
    slidingTabLayout.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {

        @Override
        public int getIndicatorColor(int position) {
            TypedValue typedValue = new TypedValue();
            Resources.Theme theme = mContext.getTheme();
            theme.resolveAttribute(R.attr.colorAccent, typedValue, true);
            return typedValue.data;
        }

        @Override
        public int getDividerColor(int position) {
            return 0;
        }
    });
    slidingTabLayout.setViewPager(mPager);
    final FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.fabCreateBackup);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean isRecovery = mPager.getCurrentItem() == 0;
            createBackup(isRecovery);
        }
    });
    fab.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.ic_add_white));
    slidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            if (position == 0) {
                if (RashrApp.DEVICE.isRecoveryDD() || RashrApp.DEVICE.isRecoveryMTD()) {
                    fab.setVisibility(View.VISIBLE);
                } else {
                    fab.setVisibility(View.INVISIBLE);
                }
            } else {
                if (RashrApp.DEVICE.isKernelDD() || RashrApp.DEVICE.isKernelMTD()) {
                    fab.setVisibility(View.VISIBLE);
                } else {
                    fab.setVisibility(View.INVISIBLE);
                }
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    mAdapter.getRecoveryBackupFragment().getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!(RashrApp.DEVICE.isRecoveryDD() || RashrApp.DEVICE.isRecoveryMTD())) {
                Toast.makeText(mContext, R.string.op_not_supported, Toast.LENGTH_SHORT).show();
            } else {
                showPopup(view);
            }
        }
    });
    mAdapter.getKernelBackupFragment().getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!(RashrApp.DEVICE.isKernelDD() || RashrApp.DEVICE.isKernelMTD())) {
                Toast.makeText(mContext, R.string.op_not_supported, Toast.LENGTH_SHORT).show();
            } else {
                showPopup(view);
            }
        }
    });
    return root;
}
Also used : SlidingTabLayout(de.mkrtchyan.recoverytools.view.SlidingTabLayout) View(android.view.View) AdapterView(android.widget.AdapterView) AppCompatTextView(android.support.v7.widget.AppCompatTextView) ListView(android.widget.ListView) ViewPager(android.support.v4.view.ViewPager) FloatingActionButton(android.support.design.widget.FloatingActionButton) AdapterView(android.widget.AdapterView) TypedValue(android.util.TypedValue)

Example 2 with ContextCompat.getDrawable

use of android.support.v4.content.ContextCompat.getDrawable in project android-topeka by googlesamples.

the class AvatarView method onDraw.

@Override
protected void onDraw(@NonNull Canvas canvas) {
    super.onDraw(canvas);
    if (mChecked) {
        Drawable border = ContextCompat.getDrawable(getContext(), R.drawable.selector_avatar);
        border.setBounds(0, 0, getWidth(), getHeight());
        border.draw(canvas);
    }
}
Also used : BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) RoundedBitmapDrawable(android.support.v4.graphics.drawable.RoundedBitmapDrawable)

Example 3 with ContextCompat.getDrawable

use of android.support.v4.content.ContextCompat.getDrawable in project android-UniversalMusicPlayer by googlesamples.

the class FullScreenPlayerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_player);
    initializeToolbar();
    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 = MediaControllerCompat.getMediaController(FullScreenPlayerActivity.this).getTransportControls();
            controls.skipToNext();
        }
    });
    mSkipPrev.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            MediaControllerCompat.TransportControls controls = MediaControllerCompat.getMediaController(FullScreenPlayerActivity.this).getTransportControls();
            controls.skipToPrevious();
        }
    });
    mPlayPause.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PlaybackStateCompat state = MediaControllerCompat.getMediaController(FullScreenPlayerActivity.this).getPlaybackState();
            if (state != null) {
                MediaControllerCompat.TransportControls controls = MediaControllerCompat.getMediaController(FullScreenPlayerActivity.this).getTransportControls();
                switch(state.getState()) {
                    // fall through
                    case PlaybackStateCompat.STATE_PLAYING:
                    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) {
            MediaControllerCompat.getMediaController(FullScreenPlayerActivity.this).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);
}
Also used : PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) MediaBrowserCompat(android.support.v4.media.MediaBrowserCompat) SeekBar(android.widget.SeekBar) ComponentName(android.content.ComponentName) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 4 with ContextCompat.getDrawable

use of android.support.v4.content.ContextCompat.getDrawable in project android-UniversalMusicPlayer by googlesamples.

the class PlaybackControlsFragment method onPlaybackStateChanged.

private void onPlaybackStateChanged(PlaybackStateCompat state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (getActivity() == null) {
        LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null," + "this should not happen if the callback was properly unregistered. Ignoring.");
        return;
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch(state.getState()) {
        case PlaybackStateCompat.STATE_PAUSED:
        case PlaybackStateCompat.STATE_STOPPED:
            enablePlay = true;
            break;
        case PlaybackStateCompat.STATE_ERROR:
            LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage());
            Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
            break;
    }
    if (enablePlay) {
        mPlayPause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_36dp));
    } else {
        mPlayPause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_black_36dp));
    }
    MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
    String extraInfo = null;
    if (controller != null && controller.getExtras() != null) {
        String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            extraInfo = getResources().getString(R.string.casting_to_device, castName);
        }
    }
    setExtraInfo(extraInfo);
}
Also used : MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat)

Example 5 with ContextCompat.getDrawable

use of android.support.v4.content.ContextCompat.getDrawable in project MTweaks-KernelAdiutorMOD by morogoku.

the class NavigationActivity method appendFragments.

private void appendFragments(boolean setShortcuts) {
    sActualFragments.clear();
    Menu menu = mNavigationView.getMenu();
    menu.clear();
    SubMenu lastSubMenu = null;
    for (NavigationFragment navigationFragment : sFragments) {
        Fragment fragment = navigationFragment.mFragment;
        int id = navigationFragment.mId;
        Drawable drawable = ContextCompat.getDrawable(this, Utils.DONATED && Prefs.getBoolean("section_icons", true, this) && navigationFragment.mDrawable != 0 ? navigationFragment.mDrawable : R.drawable.ic_blank);
        if (fragment == null) {
            lastSubMenu = menu.addSubMenu(id);
            sActualFragments.put(id, null);
        } else if (Prefs.getBoolean(fragment.getClass().getSimpleName() + "_enabled", true, this)) {
            MenuItem menuItem = lastSubMenu == null ? menu.add(0, id, 0, id) : lastSubMenu.add(0, id, 0, id);
            menuItem.setIcon(drawable);
            menuItem.setCheckable(true);
            if (mSelection != 0) {
                mNavigationView.setCheckedItem(mSelection);
            }
            sActualFragments.put(id, fragment);
        }
    }
    if (setShortcuts) {
        setShortcuts();
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) SubMenu(android.view.SubMenu) MenuItem(android.view.MenuItem) SubMenu(android.view.SubMenu) Menu(android.view.Menu) LMKFragment(com.moro.mtweaks.fragments.kernel.LMKFragment) BackupFragment(com.moro.mtweaks.fragments.tools.BackupFragment) BuildpropFragment(com.moro.mtweaks.fragments.tools.BuildpropFragment) RecyclerViewFragment(com.moro.mtweaks.fragments.RecyclerViewFragment) Fragment(android.support.v4.app.Fragment) ThermalFragment(com.moro.mtweaks.fragments.kernel.ThermalFragment) EntropyFragment(com.moro.mtweaks.fragments.kernel.EntropyFragment) OverallFragment(com.moro.mtweaks.fragments.statistics.OverallFragment) CPUVoltageCl0Fragment(com.moro.mtweaks.fragments.kernel.CPUVoltageCl0Fragment) ScreenFragment(com.moro.mtweaks.fragments.kernel.ScreenFragment) LEDFragment(com.moro.mtweaks.fragments.kernel.LEDFragment) CPUFragment(com.moro.mtweaks.fragments.kernel.CPUFragment) DeviceFragment(com.moro.mtweaks.fragments.statistics.DeviceFragment) MemoryFragment(com.moro.mtweaks.fragments.statistics.MemoryFragment) AboutFragment(com.moro.mtweaks.fragments.other.AboutFragment) InitdFragment(com.moro.mtweaks.fragments.tools.InitdFragment) RecoveryFragment(com.moro.mtweaks.fragments.tools.RecoveryFragment) WakelockFragment(com.moro.mtweaks.fragments.kernel.WakelockFragment) CPUVoltageCl1Fragment(com.moro.mtweaks.fragments.kernel.CPUVoltageCl1Fragment) SoundFragment(com.moro.mtweaks.fragments.kernel.SoundFragment) IOFragment(com.moro.mtweaks.fragments.kernel.IOFragment) DvfsFragment(com.moro.mtweaks.fragments.kernel.DvfsFragment) SpectrumFragment(com.moro.mtweaks.fragments.kernel.SpectrumFragment) MiscFragment(com.moro.mtweaks.fragments.kernel.MiscFragment) SettingsFragment(com.moro.mtweaks.fragments.other.SettingsFragment) CustomControlsFragment(com.moro.mtweaks.fragments.tools.customcontrols.CustomControlsFragment) BoefflaWakelockFragment(com.moro.mtweaks.fragments.kernel.BoefflaWakelockFragment) ContributorsFragment(com.moro.mtweaks.fragments.other.ContributorsFragment) ProfileFragment(com.moro.mtweaks.fragments.tools.ProfileFragment) GPUFragment(com.moro.mtweaks.fragments.kernel.GPUFragment) VMFragment(com.moro.mtweaks.fragments.kernel.VMFragment) DownloadsFragment(com.moro.mtweaks.fragments.tools.downloads.DownloadsFragment) DonationFragment(com.moro.mtweaks.fragments.other.DonationFragment) BaseFragment(com.moro.mtweaks.fragments.BaseFragment) KSMFragment(com.moro.mtweaks.fragments.kernel.KSMFragment) BatteryFragment(com.moro.mtweaks.fragments.kernel.BatteryFragment) InputsFragment(com.moro.mtweaks.fragments.statistics.InputsFragment) HmpFragment(com.moro.mtweaks.fragments.kernel.HmpFragment) OnBootFragment(com.moro.mtweaks.fragments.tools.OnBootFragment) CPUHotplugFragment(com.moro.mtweaks.fragments.kernel.CPUHotplugFragment)

Aggregations

View (android.view.View)13 ImageView (android.widget.ImageView)10 Drawable (android.graphics.drawable.Drawable)9 TextView (android.widget.TextView)6 Bundle (android.os.Bundle)5 ContextCompat (android.support.v4.content.ContextCompat)5 ViewPager (android.support.v4.view.ViewPager)5 ViewGroup (android.view.ViewGroup)5 Context (android.content.Context)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 Color (android.graphics.Color)3 Handler (android.os.Handler)3 NonNull (android.support.annotation.NonNull)3 Fragment (android.support.v4.app.Fragment)3 RoundedBitmapDrawable (android.support.v4.graphics.drawable.RoundedBitmapDrawable)3 RecyclerView (android.support.v7.widget.RecyclerView)3 TypedValue (android.util.TypedValue)3 LayoutInflater (android.view.LayoutInflater)3 FrameLayout (android.widget.FrameLayout)3