List of usage examples for android.support.v4.content ContextCompat getDrawable
public static final Drawable getDrawable(Context context, int i)
From source file:com.example.android.todolist.AddTaskActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_add_task); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); toolbar = (Toolbar) findViewById(R.id.archive_toolbar); add_btn = (FloatingActionButton) findViewById(R.id.addButton); delete_btn = (FloatingActionButton) findViewById(R.id.fab_delete); picked_color = (FloatingActionButton) findViewById(R.id.pick_color); formated_time = (TextView) findViewById(R.id.pickedTime); edt_title = (EditText) findViewById(R.id.editTextTaskDescription); edt_description = (EditText) findViewById(R.id.TaskDescription); choosenTime = (TextView) findViewById(R.id.pickedTime); contentValues = new ContentValues(); delete_btn.setVisibility(View.INVISIBLE); Intent intent = getIntent();//w w w .j av a2 s . c om mCurrentUri = intent.getData(); isFromArchive = intent.getBooleanExtra("FROM_ARCHIVE", false); // /tasks/1 // /tasks if (mCurrentUri == null) { // add a new task setTitle("add task"); // Toast.makeText(AddTaskActivity.this, "" + mCurrentUri, Toast.LENGTH_LONG).show(); add_btn.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_send)); } else if (isFromArchive) { // add task from archive add_btn.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_send)); getSupportLoaderManager().initLoader(1, null, this); // archive } else { setTitle("update task"); // update task add_btn.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_done_black_24dp)); delete_btn.setVisibility(View.VISIBLE); int row = Integer.valueOf(mCurrentUri.getLastPathSegment()); String match = TaskContract.TaskEntry.CONTENT_URI.getPath() + "/" + row; if (mCurrentUri.getPath().equals(match)) { isTaskUri = true; getSupportLoaderManager().initLoader(0, null, this); } /* else { getSupportLoaderManager().initLoader(1, null, this); }*/ } picked_color.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new SpectrumDialog.Builder(AddTaskActivity.this).setColors(R.array.color_array) // .setSelectedColorRes(R.color.md_blue_500) .setDismissOnColorSelected(false) // .setOutlineWidth(2) .setOnColorSelectedListener(new SpectrumDialog.OnColorSelectedListener() { @Override public void onColorSelected(boolean positiveResult, @ColorInt int color) { if (positiveResult) { isColorPicked = true; color_posiotion = color; // Toast.makeText(getApplicationContext(), "" + color, Toast.LENGTH_LONG).show(); // Toast.makeText(AddTaskActivity.this, "Color selected: #" + Integer.toHexString(color).toUpperCase(), Toast.LENGTH_SHORT).show(); } else { Toast.makeText(AddTaskActivity.this, "No color selected", Toast.LENGTH_SHORT) .show(); } } }).build().show(getSupportFragmentManager(), "hi"); } }); fabTime = (FloatingActionButton) findViewById(R.id.time_picked); fabTime.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Calendar now = Calendar.getInstance(); DatePickerDialog dpd = DatePickerDialog.newInstance(AddTaskActivity.this, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)); dpd.show(getFragmentManager(), "Datepickerdialog"); dpd.setVersion(DatePickerDialog.Version.VERSION_1); dpd.setThemeDark(false); } }); add_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCurrentUri == null || isFromArchive) { onClickAddTask(); } else { updateTask(); } } }); delete_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // notify app widget to be updated sendBroadcast(new Intent("ACTION_DATA_UPDATED")); String stringId = Integer.toString(id); Uri uri = TaskContract.TaskEntry.CONTENT_URI; uri = uri.buildUpon().appendPath(stringId).build(); getContentResolver().delete(uri, null, null); finish(); } }); }
From source file:com.amazon.android.tv.tenfoot.ui.fragments.FullContentBrowseFragment.java
private void setupUIElements() { // Set custom badge drawable and title here but note that when badge is set title does // not show so we have setTitle commented out. setBadgeDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.company_logo)); //setTitle(getString(R.string.browse_title)); setHeadersState(HEADERS_ENABLED);/*from w w w . j ava 2 s.c om*/ setHeadersTransitionOnBackEnabled(true); // Set headers and rows background color setBrandColor(getResources().getColor(R.color.browse_headers_bar)); setDefaultBackground(R.drawable.default_background); mBackgroundManager .setDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.browse_background_no_preview)); // Disables the scaling of rows when Headers bar is in open state. enableRowScaling(false); // Set search icon color setSearchAffordanceColor(getResources().getColor(R.color.search_orb)); // Here is where a header presenter can be set to customize the look // of the headers list. setHeaderPresenterSelector(new PresenterSelector() { @Override public Presenter getPresenter(Object o) { return new RowHeaderPresenter(); } }); }
From source file:br.com.mauker.materialseekbar.PinView.java
/** * The view is created empty with a default constructor. Use init to set all the initial * variables for the pin/*from w w w. ja v a2 s .c o m*/ * * @param ctx Context * @param y The y coordinate to raw the pin (i.e. the bar location) * @param pinRadiusDP the initial size of the pin * @param pinColor the color of the pin * @param textColor the color of the value text in the pin * @param circleRadius the radius of the selector circle * @param minFont the minimum font size for the pin text * @param maxFont the maximum font size for the pin text * @param pinsAreTemporary whether to show the pin initially or just the circle */ public void init(Context ctx, float y, float pinRadiusDP, int pinColor, int textColor, float circleRadius, int circleColor, float minFont, float maxFont, boolean pinsAreTemporary) { Resources res = ctx.getResources(); mPin = ContextCompat.getDrawable(ctx, R.drawable.rotate); mDensity = getResources().getDisplayMetrics().density; mMinPinFont = minFont / mDensity; mMaxPinFont = maxFont / mDensity; mIsTemporary = pinsAreTemporary; mPinPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, res.getDisplayMetrics()); mCircleRadiusPx = circleRadius; mTextYPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8f, res.getDisplayMetrics()); // If one of the attributes are set, but the others aren't, set the // attributes to default if (pinRadiusDP == -1) { mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_THUMB_RADIUS_DP, res.getDisplayMetrics()); } else { mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pinRadiusDP, res.getDisplayMetrics()); } //Set text size in px from dp int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 5, res.getDisplayMetrics()); // Creates the paint and sets the Paint values mTextPaint = new Paint(); mTextPaint.setColor(textColor); mTextPaint.setAntiAlias(true); mTextPaint.setTextSize(textSize); // Creates the paint and sets the Paint values mCirclePaint = new Paint(); mCirclePaint.setColor(circleColor); mCirclePaint.setAntiAlias(true); //Color filter for the selection pin mPinFilter = new LightingColorFilter(pinColor, pinColor); // Sets the minimum touchable area, but allows it to expand based on // image size int targetRadius = (int) Math.max(MINIMUM_TARGET_RADIUS_DP, mPinRadiusPx); mTargetRadiusPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, targetRadius, res.getDisplayMetrics()); mY = y; }
From source file:com.agenmate.lollipop.addedit.AddEditActivity.java
@SuppressLint("NewApi") public void setBarColor(int color, boolean isWhiteText) { appBar.setBackgroundColor(ContextCompat.getColor(this, colorBarIds[color])); String title = taskId == null ? "New Task" : "Edit Task"; toolbar.setTitleTextColor(isWhiteText ? Color.WHITE : Color.BLACK); toolbar.setTitle(title);//from w w w.ja v a 2 s. c o m final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_material); upArrow.setColorFilter(isWhiteText ? Color.WHITE : Color.BLACK, PorterDuff.Mode.SRC_ATOP); getSupportActionBar().setHomeAsUpIndicator(upArrow); setStatusBarColor(color); if (menu != null) { for (int i = 0; i < menu.size(); i++) { Drawable drawable = menu.getItem(i).getIcon(); if (drawable != null) { drawable.mutate(); drawable.setColorFilter(isWhiteText ? Color.WHITE : Color.BLACK, PorterDuff.Mode.SRC_ATOP); } } } }
From source file:com.fairphone.fplauncher3.oobe.animation.MenuTutorialAnimationView.java
private void init() { WindowManager windowMananger = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE); mDisplayMetrics = new DisplayMetrics(); windowMananger.getDefaultDisplay().getMetrics(mDisplayMetrics); SCREEN_HEIGHT = mDisplayMetrics.heightPixels; SCREEN_WIDTH = mDisplayMetrics.widthPixels; if (getBackground() == null) { setBackgroundColor(0x00000000);/* ww w . j a v a2 s. co m*/ } spritePaint = new Paint(); spritePaint.setColor(0xffffffff); spriteRoot = new KWSprite(); spriteArrow = new KWSprite(); spriteHand = new KWSprite(); spriteHandShadow = new KWSprite(); spriteMenu = new KWSprite(); spriteAppIcon = new KWSprite(); spriteAppIconSelected = new KWSprite(); spriteArrow.drawable = ContextCompat.getDrawable(getContext(), R.drawable.arrow_gradient_oobe); spriteArrow.applySizeFromDrawable(); spriteHand.drawable = ContextCompat.getDrawable(getContext(), R.drawable.icn_hand_oobe); spriteHand.applySizeFromDrawable(); spriteHandShadow.drawable = ContextCompat.getDrawable(getContext(), R.drawable.oobe_hand_shadow); spriteHandShadow.applySizeFromDrawable(); spriteMenu.drawable = ContextCompat.getDrawable(getContext(), R.drawable.oobe_menu); spriteMenu.applySizeFromDrawable(); spriteAppIcon.drawable = ContextCompat.getDrawable(getContext(), R.drawable.icn_circle_oobe); spriteAppIcon.applySizeFromDrawable(); spriteAppIconSelected.drawable = ContextCompat.getDrawable(getContext(), R.drawable.icn_circle_glow_oobe); spriteAppIconSelected.applySizeFromDrawable(); spriteRoot.addChild(spriteArrow); spriteRoot.addChild(spriteHand); //spriteRoot.addChild(spriteHandShadow); spriteRoot.addChild(spriteMenu); spriteMenu.addChild(spriteAppIcon); //spriteMenu.addChild(spriteAppIconSelected); spriteRoot.alpha = 0; spriteAppIconSelected.alpha = 0; // Animation setup animationManager = new KWAnimationManager(); animationGroupSwipe = new KWAnimationGroup(animationManager); animationGroupSelectApp = new KWAnimationGroup(animationManager); mHandStopPointXinDP = SCREEN_WIDTH - DynamicGrid.pxFromDp(100, mDisplayMetrics); mArrowStopPointXinDP = SCREEN_WIDTH - DynamicGrid.pxFromDp(120, mDisplayMetrics); setupSwipeAnimation(); setupAppOpenAnimation(); }
From source file:com.justplay1.shoppist.features.goods.GoodsFragment.java
protected void initRecyclerView(View view, Bundle savedInstanceState) { super.initRecyclerView(view, savedInstanceState); final Parcelable eimSavedState = (savedInstanceState != null) ? savedInstanceState.getParcelable(SAVED_STATE_EXPANDABLE_ITEM_MANAGER) : null;//w w w .ja v a 2s .c om recyclerViewExpandableItemManager = new RecyclerViewExpandableItemManager(eimSavedState); wrappedAdapter = recyclerViewExpandableItemManager.createWrappedAdapter(adapter); // wrap for expanding final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator(); animator.setSupportsChangeAnimations(false); recyclerView.setAdapter(wrappedAdapter); // requires *wrapped* adapter recyclerView.setItemAnimator(animator); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { recyclerView.addItemDecoration(new ItemShadowDecorator( (NinePatchDrawable) ContextCompat.getDrawable(getContext(), R.drawable.material_shadow_z1))); } recyclerViewExpandableItemManager.attachRecyclerView(recyclerView); }
From source file:airfree.xprojets.airfree.PinView.java
/** * The view is created empty with a default constructor. Use init to set all the initial * variables for the pin//from w ww .j a v a 2s. c o m * * @param ctx Context * @param y The y coordinate to raw the pin (i.e. the bar location) * @param pinRadiusDP the initial size of the pin * @param pinColor the color of the pin * @param textColor the color of the value text in the pin * @param circleRadius the radius of the selector circle * @param minFont the minimum font size for the pin text * @param maxFont the maximum font size for the pin text * @param pinsAreTemporary whether to show the pin initially or just the circle */ public void init(Context ctx, float y, float pinRadiusDP, int pinColor, int textColor, float circleRadius, int circleColor, float minFont, float maxFont, boolean pinsAreTemporary) { mRes = ctx.getResources(); mPin = ContextCompat.getDrawable(ctx, R.drawable.rotate); mDensity = getResources().getDisplayMetrics().density; mMinPinFont = minFont / mDensity; mMaxPinFont = maxFont / mDensity; mPinsAreTemporary = pinsAreTemporary; mPinPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 15, mRes.getDisplayMetrics()); mCircleRadiusPx = circleRadius; mTextYPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 3.5f, mRes.getDisplayMetrics()); // If one of the attributes are set, but the others aren't, set the // attributes to default if (pinRadiusDP == -1) { mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_THUMB_RADIUS_DP, mRes.getDisplayMetrics()); } else { mPinRadiusPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, pinRadiusDP, mRes.getDisplayMetrics()); } //Set text size in px from dp int textSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 15, mRes.getDisplayMetrics()); // Creates the paint and sets the Paint values mTextPaint = new Paint(); mTextPaint.setColor(textColor); mTextPaint.setAntiAlias(true); mTextPaint.setTextSize(textSize); // Creates the paint and sets the Paint values mCirclePaint = new Paint(); mCirclePaint.setColor(circleColor); mCirclePaint.setAntiAlias(true); //Color filter for the selection pin mPinFilter = new LightingColorFilter(pinColor, pinColor); // Sets the minimum touchable area, but allows it to expand based on // image size int targetRadius = (int) Math.max(MINIMUM_TARGET_RADIUS_DP, mPinRadiusPx); mTargetRadiusPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, targetRadius, mRes.getDisplayMetrics()); mY = y; }
From source file:com.dgmltn.ranger.internal.PinView.java
/** * The view is created empty with a default constructor. Use init to set all the initial * variables for the pin/*from ww w .j av a2s . com*/ * * @param position The position of this point in its parent's view * @param pinRadiusDP the initial size of the pin * @param pinColor the color of the pin * @param textColor the color of the value text in the pin * @param circleRadius the radius of the selector circle * @param circleColor the color of the selector circle */ public void init(PointF position, float pinRadiusDP, int pinColor, int textColor, float circleRadius, int circleColor, float minFont, float maxFont) { mPin = ContextCompat.getDrawable(getContext(), R.drawable.rotate); mPosition = position; mDensity = getResources().getDisplayMetrics().density; mMinPinFont = minFont / mDensity; mMaxPinFont = maxFont / mDensity; mPinPadding = (int) (15f * mDensity); mCircleRadiusPx = circleRadius; mTextYPadding = (int) (3.5f * mDensity); mPinRadiusPx = (int) ((pinRadiusDP == -1 ? DEFAULT_THUMB_RADIUS_DP : pinRadiusDP) * mDensity); // Creates the paint and sets the Paint values mTextPaint = new TextPaint(); mTextPaint.setTypeface(Typeface.MONOSPACE); mTextPaint.setColor(textColor); mTextPaint.setAntiAlias(true); mTextPaint.setTextSize(15f * mDensity); // Creates the paint and sets the Paint values mCirclePaint = new Paint(); mCirclePaint.setColor(circleColor); mCirclePaint.setAntiAlias(true); // Color filter for the selection pin mPinFilter = new LightingColorFilter(pinColor, pinColor); // Sets the minimum touchable area, but allows it to expand based on image size mTargetRadiusPx = Math.max(MINIMUM_TARGET_RADIUS_DP * mDensity, mPinRadiusPx); }
From source file:cl.smartcities.isci.transportinspector.adapters.dialogAdapters.BusSelectionAdapter.java
private void setUpNormalRow(final ViewHolder holder, final int position) { final String service = this.serviceList.get(position); final ArrayList<Bus> sameServiceBusList = this.busMap.get(service); final Drawable busImage = ContextCompat.getDrawable(this.getContext(), sameServiceBusList.get(0).getBusIcon()); holder.optionsLayout = holder.platesLayout; holder.busImage.setVisibility(View.VISIBLE); holder.busRoute.setVisibility(View.VISIBLE); holder.dropDownButton.setVisibility(View.VISIBLE); holder.busRoute.setText(service);/* ww w .ja v a 2s .c om*/ holder.busImage.setImageDrawable(busImage); /* case: only one bus of this service is coming */ if (sameServiceBusList.size() == 1) { holder.dropDownButton.setVisibility(View.GONE); holder.busRoute.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Bus bus = sameServiceBusList.get(0); bus.addPassenger(); Log.d("Notification dialog", "Added me to the passenger number"); listener.onPositiveClick(bus); } }); } else { /* case: two buses of this service are coming */ String plate1 = sameServiceBusList.get(0).getFormattedPlate(); String plate2 = sameServiceBusList.get(1).getFormattedPlate(); holder.licensePlate1.setText(plate1); holder.licencePlate2.setText(plate2); setUpBusOptionsLayout(holder, position); /* set every option to send its own plate */ holder.licensePlate1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Add 1 to the passenger number Bus bus = sameServiceBusList.get(0); bus.addPassenger(); Log.d("Notification dialog", "Added me to the passenger number"); listener.onPositiveClick(bus); } }); holder.licencePlate2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Add 1 to the passenger number Bus bus = sameServiceBusList.get(1); bus.addPassenger(); Log.d("Notification dialog", "Added me to the passenger number"); listener.onPositiveClick(bus); } }); /* if the plate is not known raise false alarm */ holder.doNotKnow.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { listener.onPositiveClick(new Bus(sameServiceBusList.get(0).getService(), "")); } }); } }
From source file:com.example.android.AudioArchive.ui.FullScreenPlayerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_full_player); initializeToolbar();/*from w ww . j ava 2 s .co 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); 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(); break; case PlaybackStateCompat.STATE_PAUSED: case PlaybackStateCompat.STATE_STOPPED: controls.play(); break; default: LogHelper.d(TAG, "onClick with state ", state.getState()); } } } }); ; // 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); }