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:cn.finalteam.galleryfinal.PhotoEditActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (GalleryFinal.getFunctionConfig() == null || GalleryFinal.getGalleryTheme() == null) {
        resultFailureDelayed(getString(R.string.please_reopen_gf), true);
    } else {/*w ww .  ja  va 2s .  c  om*/
        setContentView(R.layout.gf_activity_photo_edit);
        mDefaultDrawable = ContextCompat.getDrawable(this, R.drawable.ic_gf_default_photo);

        mSelectPhotoList = (ArrayList<PhotoInfo>) getIntent().getSerializableExtra(SELECT_MAP);
        mTakePhotoAction = this.getIntent().getBooleanExtra(TAKE_PHOTO_ACTION, false);
        mCropPhotoAction = this.getIntent().getBooleanExtra(CROP_PHOTO_ACTION, false);
        mEditPhotoAction = this.getIntent().getBooleanExtra(EDIT_PHOTO_ACTION, false);

        if (mSelectPhotoList == null) {
            mSelectPhotoList = new ArrayList<>();
        }
        mPhotoTempMap = new LinkedHashMap<>();
        mPhotoList = new ArrayList<>(mSelectPhotoList);

        mEditPhotoCacheFile = GalleryFinal.getCoreConfig().getEditPhotoCacheFolder();

        if (mPhotoList == null) {
            mPhotoList = new ArrayList<>();
        }

        for (PhotoInfo info : mPhotoList) {
            mPhotoTempMap.put(info.getPhotoId(), new PhotoTempModel(info.getPhotoPath()));
        }

        findViews();
        setListener();
        setTheme();

        mPhotoEditListAdapter = new PhotoEditListAdapter(this, mPhotoList, mScreenWidth);
        mLvGallery.setAdapter(mPhotoEditListAdapter);

        try {
            File nomediaFile = new File(mEditPhotoCacheFile, ".nomedia");
            if (!nomediaFile.exists()) {
                nomediaFile.createNewFile();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        if (GalleryFinal.getFunctionConfig().isCamera()) {
            mIvTakePhoto.setVisibility(View.VISIBLE);
        }

        if (GalleryFinal.getFunctionConfig().isCrop()) {
            mIvCrop.setVisibility(View.VISIBLE);
        }

        if (GalleryFinal.getFunctionConfig().isRotate()) {
            mIvRotate.setVisibility(View.VISIBLE);
        }

        if (!GalleryFinal.getFunctionConfig().isMutiSelect()) {
            mLlGallery.setVisibility(View.GONE);
        }

        //??
        CropEnum cropEnum = CropEnum.normal;
        if (GalleryFinal.getFunctionConfig().isCropSquare())
            cropEnum = CropEnum.square; //??
        if (GalleryFinal.getFunctionConfig().isCropCard())
            cropEnum = CropEnum.card; //???
        initCrop(mIvCropPhoto, cropEnum, GalleryFinal.getFunctionConfig().getCropWidth(),
                GalleryFinal.getFunctionConfig().getCropHeight());

        if (mPhotoList.size() > 0 && !mTakePhotoAction) {
            loadImage(mPhotoList.get(0));
        }

        if (mTakePhotoAction) {
            //
            takePhotoAction();
        }
        if (mCropPhotoAction) {
            mIvCrop.performClick();
            if (!GalleryFinal.getFunctionConfig().isRotate() && !GalleryFinal.getFunctionConfig().isCamera()) {
                mIvCrop.setVisibility(View.GONE);
            }
        } else {
            //??
            hasForceCrop();
        }

        if (GalleryFinal.getFunctionConfig().isEnablePreview()) {
            mIvPreView.setVisibility(View.VISIBLE);
        }
    }
}

From source file:cl.smartcities.isci.transportinspector.fragments.ReportMapFragment.java

@Override
public void currentIsOnBusStop(BusStop busStop) {
    currentIsOnBus = false;/*from  ww  w.j a  v  a2s .com*/
    Log.d(TAG, busStop.getId());
    this.stateMessage.changeMessage(this.getContext().getString(R.string.on_bus_stop_message),
            ContextCompat.getDrawable(getContext(), R.drawable.contexto_paradero), false);
}

From source file:com.appunite.appunitevideoplayer.PlayerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.player_activity);
    root = (ViewGroup) findViewById(R.id.root);
    root.setOnTouchListener(new OnTouchListener() {
        @Override/*from   w  ww.jav a  2s  .c o m*/
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                toggleControlsVisibility();
            } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                view.performClick();
            }
            return true;
        }
    });
    root.setOnKeyListener(new OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE
                    || keyCode == KeyEvent.KEYCODE_MENU) {
                return false;
            }
            return mediaController.dispatchKeyEvent(event);
        }
    });

    shutterView = findViewById(R.id.shutter);

    videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame);
    surfaceView = (SurfaceView) findViewById(R.id.surface_view);
    surfaceView.getHolder().addCallback(this);

    subtitleLayout = (SubtitleLayout) findViewById(R.id.subtitles);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back);
    toolbar.setTitle(getIntent().getStringExtra(TITLE_TEXT_EXTRA));
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    mediaController = new MediaController(this);
    mediaController.setAnchorView(root);
    controllerView = (ViewGroup) findViewById(R.id.controller_view);
    controllerView.addView(mediaController);
    CookieHandler currentHandler = CookieHandler.getDefault();
    if (currentHandler != defaultCookieManager) {
        CookieHandler.setDefault(defaultCookieManager);
    }

    audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this);
    audioCapabilitiesReceiver.register();

    progressBar = (ProgressBar) findViewById(R.id.progress_bar);

    playButton = (ImageView) findViewById(R.id.play_button_icon);
    final int playButtonIconDrawableId = getIntent().getIntExtra(PLAY_BUTTON_EXTRA, 0);
    if (playButtonIconDrawableId != 0) {
        playButton.setImageDrawable(ContextCompat.getDrawable(this, playButtonIconDrawableId));
        playButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                preparePlayer(true);
            }
        });
    }
}

From source file:com.example.search.car.pools.welcome.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.welcome);/*from  ww  w. j  a  va 2s  .c  o m*/

    Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
        frag_id = bundle.getInt("frag_id");
    }
    tf = Typeface.createFromAsset(welcome.this.getAssets(), "AvenirLTStd_Book.otf");
    // for notification
    // nReceiver = new NotificationReceiver();
    // IntentFilter filter = new IntentFilter();
    // filter.addAction("com.kpbird.nlsexample.NOTIFICATION_LISTENER_EXAMPLE");
    // registerReceiver(nReceiver, filter);

    task = getSharedPreferences("user", MODE_PRIVATE);
    SharedPreferences sharedpreferences = this.getPreferences(0);
    Editor editor = sharedpreferences.edit();
    editor.putString("username", userid);

    editor.commit();
    initMenu();

    // mTitle = mDrawerTitle = "Search Carpool";
    mPlanetTitles = getResources().getStringArray(R.array.menu_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (RelativeLayout) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer
    // opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    // mDrawerList.setAdapter(new ArrayAdapter<String>(this,
    // R.layout.drawer_list_item, mPlanetTitles));
    mDrawerList.setOnClickListener(this);

    // enable ActionBar app icon to behave as action to toggle nav drawer

    // getActionBar().setTitle("");
    // getActionBar().setDisplayHomeAsUpEnabled(true);
    // getActionBar().setHomeButtonEnabled(true);
    // getActionBar().setBackgroundDrawable(new
    // ColorDrawable(Color.parseColor("#0087ca")));
    // Drawable d = ContextCompat.getDrawable(welcome.this,
    // R.drawable.logooo);
    // getActionBar().setIcon(d);

    // custom navigation bar
    getActionBar().setDisplayShowHomeEnabled(false);
    getActionBar().setDisplayShowTitleEnabled(false);
    LayoutInflater mInflater = LayoutInflater.from(this);
    View mCustomView = mInflater.inflate(R.layout.layout_navigation, null);

    ib_back = (ImageButton) mCustomView.findViewById(R.id.ib_navigation_back);
    ib_handle = (ImageButton) mCustomView.findViewById(R.id.ib_navigation_handle);
    ib_logo = (ImageButton) mCustomView.findViewById(R.id.ib_navigation_logo);
    ib_search = (ImageButton) mCustomView.findViewById(R.id.ib_navigation_search);
    ib_menu = (ImageButton) mCustomView.findViewById(R.id.ib_navigation_menu);

    l_back = (LinearLayout) mCustomView.findViewById(R.id.l_navigation_back);
    l_handle = (LinearLayout) mCustomView.findViewById(R.id.l_navigation_handle);
    l_logo = (LinearLayout) mCustomView.findViewById(R.id.l_navigation_logo);
    l_nav_search = (LinearLayout) mCustomView.findViewById(R.id.l_navigation_search);
    l_menu = (LinearLayout) mCustomView.findViewById(R.id.l_navigation_menu);

    d1 = ContextCompat.getDrawable(welcome.this, R.drawable.touch_ripple_back_color);
    d2 = ContextCompat.getDrawable(welcome.this, R.drawable.touch_blue_back_color);
    l_back.setBackground(d2);
    l_handle.setBackground(d2);
    l_logo.setBackground(d2);
    l_nav_search.setBackground(d2);
    l_menu.setBackground(d2);

    ib_back.setOnClickListener(this);
    ib_handle.setOnClickListener(this);
    ib_logo.setOnClickListener(this);
    ib_search.setOnClickListener(this);
    ib_menu.setOnClickListener(this);
    l_back.setOnClickListener(this);
    l_handle.setOnClickListener(this);
    l_logo.setOnClickListener(this);
    l_nav_search.setOnClickListener(this);
    l_menu.setOnClickListener(this);

    // l_handle.setOnTouchListener(new OnTouchListener() {
    //
    // @Override
    // public boolean onTouch(View v, MotionEvent event) {
    // // TODO Auto-generated method stub
    // if (event.getAction() == MotionEvent.ACTION_DOWN){
    // v.setBackgroundResource(R.drawable.touch_ripple_back_color);
    // } else if (event.getAction() == MotionEvent.ACTION_UP){
    // v.setBackgroundResource(R.drawable.touch_blue_back_color);
    // }
    // return true;
    // }
    // });
    // ib_handle.setOnTouchListener(new OnTouchListener() {
    //
    // @Override
    // public boolean onTouch(View v, MotionEvent event) {
    // // TODO Auto-generated method stub
    // final int DELAY = 200;
    // ColorDrawable f = new ColorDrawable(Color.parseColor("#0087ca"));
    // ColorDrawable f1 = new ColorDrawable(Color.parseColor("#3398ca"));
    // Drawable d1 =
    // ContextCompat.getDrawable(welcome.this,R.drawable.touch_ripple_back_color);
    // Drawable d2 =
    // ContextCompat.getDrawable(welcome.this,R.drawable.touch_blue_back_color);
    // AnimationDrawable a = new AnimationDrawable();
    // a.addFrame(f1, DELAY);
    // a.addFrame(f, DELAY);
    // a.setOneShot(true);
    // l_handle.setBackground(a);
    // a.start();
    // if (mDrawerLayout.isDrawerOpen(GravityCompat.START) &&
    // event.getAction() == MotionEvent.ACTION_UP) {
    // mDrawerLayout.closeDrawer(mDrawerList);
    // } else {
    // mDrawerLayout.openDrawer(mDrawerList);
    // }
    //
    // return true;
    // }
    // });

    SVG svg_back = SVGParser.getSVGFromResource(getResources(), R.raw.actionbar_back);
    SVG svg_handle = SVGParser.getSVGFromResource(getResources(), R.raw.actionbar_menu);
    SVG svg_logo = SVGParser.getSVGFromResource(getResources(), R.raw.logo_splash);
    SVG svg_search = SVGParser.getSVGFromResource(getResources(), R.raw.actionbar_search);
    SVG svg_menu = SVGParser.getSVGFromResource(getResources(), R.raw.actionbar_triple_dot);

    ib_back.setImageDrawable(svg_back.createPictureDrawable());
    ib_handle.setImageDrawable(svg_handle.createPictureDrawable());
    ib_logo.setImageDrawable(svg_logo.createPictureDrawable());
    ib_search.setImageDrawable(svg_search.createPictureDrawable());
    ib_menu.setImageDrawable(svg_menu.createPictureDrawable());

    // int colorFrom = Color.parseColor("#0087ca");
    // int colorTo = Color.parseColor("#3398ca");
    // ValueAnimator colorAnimation = ValueAnimator.ofObject(new
    // ArgbEvaluator(), colorFrom,colorTo);
    // colorAnimation.addUpdateListener(new AnimatorUpdateListener() {
    //
    // @Override
    // public void onAnimationUpdate(ValueAnimator animator) {
    // // TODO Auto-generated method stub
    // l_handle.setBackgroundColor((Integer) animator.getAnimatedValue());
    // }
    // });

    //      l_handle.setOnClickListener(new OnClickListener() {
    //
    //         @Override
    //         public void onClick(View v) {
    //            // TODO Auto-generated method stub
    //            
    //         }
    //      });

    l_back.setVisibility(View.GONE);
    // popup = new PopupMenu(welcome.this, ib_menu);
    //      l_menu.setOnClickListener(new OnClickListener() {
    //
    //         @Override
    //         public void onClick(View v) {
    //            // TODO Auto-generated method stub
    //            
    //         }
    //      });
    //      l_search.setOnClickListener(new OnClickListener() {
    //
    //         @Override
    //         public void onClick(View v) {
    //            // TODO Auto-generated method stub
    //            
    //         }
    //      });

    getActionBar().setCustomView(mCustomView);
    getActionBar().setDisplayShowCustomEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
            mDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawerxx, /*
                                    * nav drawer image to replace 'Up'
                                    * caret
                                    */
            R.string.drawer_open, /*
                                  * "open drawer" description for
                                  * accessibility
                                  */
            R.string.drawer_close /*
                                  * "close drawer" description for
                                  * accessibility
                                  */
    ) {
        public void onDrawerClosed(View view) {
            // getActionBar().setTitle("Search Carpool");
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            // getActionBar().setTitle("Search Carpool");
            invalidateOptionsMenu(); // creates call to
            // onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(frag_id);
    }

}

From source file:com.hellofyc.base.app.AppSupportDelegate.java

@Override
public Drawable getDrawable(@DrawableRes int id) {
    return ContextCompat.getDrawable(mActivity, id);
}

From source file:android.support.design.internal.BottomNavigationItemView.java

public void setItemBackground(int background) {
    Drawable backgroundDrawable = background == 0 ? null : ContextCompat.getDrawable(getContext(), background);
    ViewCompat.setBackground(this, backgroundDrawable);
}

From source file:com.cerema.cloud2.ui.activity.FileDisplayActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log_OC.v(TAG, "onCreate() start");

    super.onCreate(savedInstanceState); // this calls onAccountChanged() when ownCloud Account
                                        // is valid

    /// grant that FileObserverService is watching favorite files
    if (savedInstanceState == null) {
        Intent initObserversIntent = FileObserverService.makeInitIntent(this);
        startService(initObserversIntent);
    }//w w w  . ja va  2s . com

    /// Load of saved instance state
    if (savedInstanceState != null) {
        mWaitingToPreview = (OCFile) savedInstanceState
                .getParcelable(FileDisplayActivity.KEY_WAITING_TO_PREVIEW);
        mSyncInProgress = savedInstanceState.getBoolean(KEY_SYNC_IN_PROGRESS);
        mWaitingToSend = (OCFile) savedInstanceState.getParcelable(FileDisplayActivity.KEY_WAITING_TO_SEND);
    } else {
        mWaitingToPreview = null;
        mSyncInProgress = false;
        mWaitingToSend = null;
    }

    /// USER INTERFACE

    // Inflate and set the layout view
    setContentView(R.layout.files);

    // Navigation Drawer
    initDrawer();

    mProgressBar = (ProgressBar) findViewById(R.id.progressBar);
    mProgressBar.setIndeterminateDrawable(
            ContextCompat.getDrawable(this, R.drawable.actionbar_progress_indeterminate_horizontal));

    mDualPane = getResources().getBoolean(R.bool.large_land_layout);
    mLeftFragmentContainer = findViewById(R.id.left_fragment_container);
    mRightFragmentContainer = findViewById(R.id.right_fragment_container);

    // Action bar setup
    getSupportActionBar().setHomeButtonEnabled(true); // mandatory since Android ICS,
                                                      // according to the official
                                                      // documentation

    // enable ActionBar app icon to behave as action to toggle nav drawer
    //getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    Log_OC.v(TAG, "onCreate() end");
}

From source file:com.amaze.carbonfilemanager.ui.icons.IconHolder.java

private Bitmap getAppDrawable(String path) throws OutOfMemoryError {
    Bitmap bitsat;//from w  ww.  ja va  2s .co m
    try {
        PackageManager pm = mContext.getPackageManager();
        PackageInfo pi = pm.getPackageArchiveInfo(path, 0);
        // // the secret are these two lines....
        pi.applicationInfo.sourceDir = path;
        pi.applicationInfo.publicSourceDir = path;
        // //
        Drawable d = pi.applicationInfo.loadIcon(pm);

        Bitmap d1 = null;
        d1 = ((BitmapDrawable) d).getBitmap();
        bitsat = d1;
    } catch (Exception e) {
        Drawable apk = ContextCompat.getDrawable(mContext, R.drawable.ic_doc_apk_grid);
        Bitmap apk1 = ((BitmapDrawable) apk).getBitmap();
        bitsat = apk1;
    }
    return bitsat;
}

From source file:com.amaze.filemanager.utils.Futils.java

public void setTint(CheckBox box, int color) {
    if (Build.VERSION.SDK_INT >= 21)
        return;//from   www . j a v  a  2s .  c o  m
    ColorStateList sl = new ColorStateList(
            new int[][] { new int[] { -android.R.attr.state_checked },
                    new int[] { android.R.attr.state_checked } },
            new int[] { Color.parseColor("#666666"), color });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        box.setButtonTintList(sl);
    } else {
        Drawable drawable = DrawableCompat
                .wrap(ContextCompat.getDrawable(box.getContext(), R.drawable.abc_btn_check_material));
        DrawableCompat.setTintList(drawable, sl);
        box.setButtonDrawable(drawable);
    }
}

From source file:com.finchuk.clock2.timepickers.Utils.java

/**
 * Returns a tinted drawable from the given drawable resource and color resource.
 *///  w w  w.j  a v a2  s .  co m
public static Drawable getTintedDrawable(@NonNull Context context, @DrawableRes int drawableRes,
        @ColorInt int colorInt) {
    Drawable d = DrawableCompat.wrap(ContextCompat.getDrawable(context, drawableRes).mutate());
    DrawableCompat.setTint(d, colorInt);
    return d;
}