List of usage examples for android.support.v4.content ContextCompat getDrawable
public static final Drawable getDrawable(Context context, int i)
From source file:com.creationgroundmedia.nytimessearch.adapters.ArticlesAdapter.java
private Bitmap bitmapFromResource(int resId) { Drawable sendIcon = ContextCompat.getDrawable(mContext, resId); Bitmap bitmap = Bitmap.createBitmap(sendIcon.getIntrinsicWidth(), sendIcon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);/* ww w. j a v a 2 s . c o m*/ Canvas canvas = new Canvas(bitmap); sendIcon.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); sendIcon.draw(canvas); return bitmap; }
From source file:com.amaze.filemanager.activities.DbViewer.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Sp = PreferenceManager.getDefaultSharedPreferences(this); theme = Integer.parseInt(Sp.getString("theme", "0")); theme1 = theme == 2 ? PreferenceUtils.hourOfDay() : theme; if (theme1 == 1) { setTheme(R.style.appCompatDark); getWindow().getDecorView().setBackgroundColor(getResources().getColor(R.color.holo_dark_background)); }/*from w w w.j a v a 2 s . c o m*/ setContentView(R.layout.activity_db_viewer); toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); skin = PreferenceUtils.getPrimaryColorString(Sp); if (Build.VERSION.SDK_INT >= 21) { ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription("Amaze", ((BitmapDrawable) ContextCompat.getDrawable(this, R.mipmap.ic_launcher)).getBitmap(), Color.parseColor(skin)); ((Activity) this).setTaskDescription(taskDescription); } skinStatusBar = PreferenceUtils.getStatusColor(skin); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(skin))); getSupportActionBar().setDisplayHomeAsUpEnabled(true); rootMode = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("rootmode", false); int sdk = Build.VERSION.SDK_INT; if (sdk == 20 || sdk == 19) { SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintColor(Color.parseColor(skin)); FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.parentdb) .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))); } path = getIntent().getStringExtra("path"); pathFile = new File(path); listView = (ListView) findViewById(R.id.listView); load(pathFile); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); DbViewerFragment fragment = new DbViewerFragment(); Bundle bundle = new Bundle(); bundle.putString("table", arrayList.get(position)); fragment.setArguments(bundle); fragmentTransaction.add(R.id.content_frame, fragment); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); } }); }
From source file:com.doctoror.fuckoffmusicplayer.presentation.util.BindingAdapters.java
@BindingAdapter({ "srcRes", "tintAttr" }) public static void setSrcResTintedFromAttr(@NonNull final ImageView imageView, @DrawableRes final int res, @AttrRes final int tintAttr) { Drawable src = ContextCompat.getDrawable(imageView.getContext(), res); setSrcTintedFromAttr(imageView, src, tintAttr); }
From source file:com.finchuk.clock2.alarms.ui.BaseAlarmViewHolder.java
public BaseAlarmViewHolder(ViewGroup parent, @LayoutRes int layoutRes, OnListItemInteractionListener<Alarm> listener, AlarmController controller) { super(parent, layoutRes, listener); mAlarmController = controller;//from w w w. jav a2s. c o m // Because of VH binding, setting drawable resources on views would be bad for performance. // Instead, we create and cache the Drawables once. mDismissNowDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_dismiss_alarm_24dp); mCancelSnoozeDrawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_cancel_snooze); // TODO: This is bad! Use a Controller/Presenter instead... // or simply pass in an instance of FragmentManager to the ctor. AppCompatActivity act = (AppCompatActivity) getContext(); mFragmentManager = act.getSupportFragmentManager(); mAddLabelDialogController = new AddLabelDialogController(mFragmentManager, new AddLabelDialog.OnLabelSetListener() { @Override public void onLabelSet(String label) { final Alarm oldAlarm = getAlarm(); Alarm newAlarm = oldAlarm.toBuilder().label(label).build(); oldAlarm.copyMutableFieldsTo(newAlarm); persistUpdatedAlarm(newAlarm, false); } }); mTimePickerDialogController = new TimePickerDialogController(mFragmentManager, getContext(), new OnTimeSetListener() { @Override public void onTimeSet(ViewGroup viewGroup, int hourOfDay, int minute) { final Alarm oldAlarm = getAlarm(); // I don't think we need this; scheduling a new alarm that is considered // equal to a previous alarm will overwrite the previous alarm. // mAlarmController.cancelAlarm(oldAlarm, false); Alarm newAlarm = oldAlarm.toBuilder().hour(hourOfDay).minutes(minute).build(); oldAlarm.copyMutableFieldsTo(newAlarm); // ------------------------------------------- // TOneverDO: precede copyMutableFieldsTo() newAlarm.setEnabled(true); // Always enabled, esp. if oldAlarm is not enabled // ---------------------------------------------- persistUpdatedAlarm(newAlarm, true); } }); }
From source file:com.google.android.apps.santatracker.games.SplashActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); // Immersive mode (to hide nav). ImmersiveModeHelper.setImmersiveSticky(getWindow()); // Get Views//w w w . ja va 2 s.c om ImageView splashImageView = (ImageView) findViewById(R.id.splash_image); TextView splashTitleView = (TextView) findViewById(R.id.splash_title); // Set Image mSplashImage = ContextCompat.getDrawable(this, getIntent().getIntExtra(EXTRA_SPLASH_IMAGE_ID, -1)); if (mSplashImage != null) { splashImageView.setImageDrawable(mSplashImage); } // Set Title mSplashTitle = getString(getIntent().getIntExtra(EXTRA_SPLASH_TITLE_ID, -1)); splashTitleView.setText(mSplashTitle); // Make text "Lobster" font FontHelper.makeLobster(splashTitleView); // Start new activity in 1000ms final Class classToLaunch = (Class) getIntent().getSerializableExtra(EXTRA_GAME_CLASS); mHandler.postDelayed(new Runnable() { @Override public void run() { startActivity(new Intent(SplashActivity.this, classToLaunch)); finish(); } }, DELAY_MILLIS); }
From source file:com.finchuk.clock2.stopwatch.ui.StopwatchFragment.java
/** * This is called only when a new instance of this Fragment is being created, * especially if the user is navigating to this tab for the first time in * this app session.//ww w .j a v a 2 s .c o m */ @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); // TODO: Will these be kept alive after onDestroyView()? If not, we should move these to // onCreateView() or any other callback that is guaranteed to be called. mStartDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.ic_start_24dp); mPauseDrawable = ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_24dp); }
From source file:com.google.samples.apps.topeka.widget.AvatarView.java
@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);//from w w w .ja va 2 s. c o m } }
From source file:com.h6ah4i.android.example.advrecyclerview.demo_ds.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); // drag & drop manager mRecyclerViewDragDropManager = new RecyclerViewDragDropManager(); mRecyclerViewDragDropManager.setDraggingItemShadowDrawable( (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z3)); // swipe manager mRecyclerViewSwipeManager = new RecyclerViewSwipeManager(); //adapter/*w w w . j a va2 s . com*/ final MyDraggableSwipeableItemAdapter myItemAdapter = new MyDraggableSwipeableItemAdapter( getDataProvider()); myItemAdapter.setEventListener(new MyDraggableSwipeableItemAdapter.EventListener() { @Override public void onItemRemoved(int position) { ((DraggableSwipeableExampleActivity) getActivity()).onItemRemoved(position); } @Override public void onItemPinned(int position) { ((DraggableSwipeableExampleActivity) getActivity()).onItemPinned(position); } @Override public void onItemViewClicked(View v, boolean pinned) { onItemViewClick(v, pinned); } }); mAdapter = myItemAdapter; mWrappedAdapter = mRecyclerViewDragDropManager.createWrappedAdapter(myItemAdapter); // wrap for dragging mWrappedAdapter = mRecyclerViewSwipeManager.createWrappedAdapter(mWrappedAdapter); // 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); mRecyclerViewDragDropManager.attachRecyclerView(mRecyclerView); // for debugging // animator.setDebug(true); // animator.setMoveDuration(2000); // animator.setRemoveDuration(2000); // mRecyclerViewSwipeManager.setMoveToOutsideWindowAnimationDuration(2000); // mRecyclerViewSwipeManager.setReturnToDefaultPositionAnimationDuration(2000); }
From source file:com.fa.mastodon.fragment.ViewThreadFragment.java
@Nullable @Override/* w ww .ja v a 2s . c om*/ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_view_thread, container, false); Context context = getContext(); swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout); swipeRefreshLayout.setOnRefreshListener(this); recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); recyclerView.setHasFixedSize(true); LinearLayoutManager layoutManager = new LinearLayoutManager(context); recyclerView.setLayoutManager(layoutManager); DividerItemDecoration divider = new DividerItemDecoration(context, layoutManager.getOrientation()); Drawable drawable = ThemeUtils.getDrawable(context, R.attr.status_divider_drawable, R.drawable.status_divider_dark); divider.setDrawable(drawable); recyclerView.addItemDecoration(divider); recyclerView.addItemDecoration(new ConversationLineItemDecoration(context, ContextCompat.getDrawable(context, R.drawable.conversation_divider_dark))); adapter = new ThreadAdapter(this); recyclerView.setAdapter(adapter); mastodonApi = null; thisThreadsStatusId = null; return rootView; }
From source file:com.anysoftkeyboard.keyboards.views.CandidateView.java
/** * Construct a CandidateView for showing suggested words for completion. *///from w ww . j a v a2s. com public CandidateView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); mSelectionHighlight = ContextCompat.getDrawable(context, R.drawable.list_selector_background_pressed); mAddToDictionaryHint = context.getString(R.string.hint_add_to_dictionary); // themed final KeyboardTheme theme = KeyboardThemeFactory.getCurrentKeyboardTheme(context.getApplicationContext()); TypedArray a = theme.getPackageContext().obtainStyledAttributes(attrs, R.styleable.AnyKeyboardViewTheme, 0, theme.getThemeResId()); int colorNormal = ContextCompat.getColor(context, R.color.candidate_normal); int colorRecommended = ContextCompat.getColor(context, R.color.candidate_recommended); int colorOther = ContextCompat.getColor(context, R.color.candidate_other); float fontSizePixel = context.getResources().getDimensionPixelSize(R.dimen.candidate_font_height); try { colorNormal = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionNormalTextColor, colorNormal); colorRecommended = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionRecommendedTextColor, colorRecommended); colorOther = a.getColor(R.styleable.AnyKeyboardViewTheme_suggestionOthersTextColor, colorOther); mDivider = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionDividerImage); final Drawable stripImage = a.getDrawable(R.styleable.AnyKeyboardViewTheme_suggestionBackgroundImage); if (stripImage == null) setBackgroundColor(Color.BLACK); else setBackgroundDrawable(stripImage); fontSizePixel = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionTextSize, fontSizePixel); } catch (Exception e) { Logger.w(TAG, "Got an exception while reading theme data", e); } mHorizontalGap = a.getDimension(R.styleable.AnyKeyboardViewTheme_suggestionWordXGap, 20); a.recycle(); mColorNormal = colorNormal; mColorRecommended = colorRecommended; mColorOther = colorOther; if (mDivider == null) mDivider = ContextCompat.getDrawable(context, R.drawable.dark_suggestions_divider); // end of themed mPaint = new Paint(); mPaint.setColor(mColorNormal); mPaint.setAntiAlias(true); mPaint.setTextSize(fontSizePixel); mPaint.setStrokeWidth(0); mPaint.setTextAlign(Align.CENTER); mTextPaint = new TextPaint(mPaint); final int minTouchableWidth = context.getResources() .getDimensionPixelOffset(R.dimen.candidate_min_touchable_width); mGestureDetector = new GestureDetector(context, new CandidateStripGestureListener(minTouchableWidth)); setWillNotDraw(false); setHorizontalScrollBarEnabled(false); setVerticalScrollBarEnabled(false); scrollTo(0, getScrollY()); }