List of usage examples for android.graphics.drawable ColorDrawable ColorDrawable
public ColorDrawable(@ColorInt int color)
From source file:com.bt.heliniumstudentapp.GradesFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle savedInstanceState) { mainContext = (AppCompatActivity) getActivity(); gradesLayout = inflater.inflate(R.layout.fragment_grades, viewGroup, false); boolean pass = true; if (gradesHtml == null) { termFocus = Integer.parseInt( PreferenceManager.getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1")); yearFocus = 0;//from ww w.j av a2 s .c o m if (Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("pref_general_class", "0")) == 0) { try { //TODO Improve maxYear = Integer.parseInt(((TextView) mainContext.findViewById(R.id.tv_class_hd)).getText() .toString().replaceAll("\\D+", "")); } catch (NumberFormatException e) { pass = false; MainActivity.drawerNV.getMenu().findItem(R.id.i_schedule_md).setChecked(true); MainActivity.FM.beginTransaction() .replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE").commit(); final AlertDialog.Builder classDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, MainActivity.themeDialog)); classDialogBuilder.setTitle(R.string.error); classDialogBuilder.setMessage(R.string.error_class); classDialogBuilder.setCancelable(false); classDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mainContext.startActivity(new Intent(mainContext, SettingsActivity.class)); } }); classDialogBuilder.setNegativeButton(android.R.string.cancel, null); final AlertDialog classDialog = classDialogBuilder.create(); classDialog.setCanceledOnTouchOutside(false); classDialog.show(); classDialog.getButton(AlertDialog.BUTTON_POSITIVE) .setTextColor(ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor)); classDialog.getButton(AlertDialog.BUTTON_NEGATIVE) .setTextColor(ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor)); } } else { maxYear = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("pref_general_class", "1")); } } if (pass) { MainActivity.setToolbarTitle(mainContext, getString(R.string.grades), null); gradesELV = (ExpandableListView) gradesLayout.findViewById(R.id.lv_course_fg); final boolean online = MainActivity.isOnline(); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null) == null) { //TODO Simpler if (online) { getGrades(termFocus, HeliniumStudentApp.df_date().format(new Date()), HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_INIT_IN); } else { //TODO Display empty GradesFragment with retry option Toast.makeText(mainContext, getString(R.string.database_no), Toast.LENGTH_SHORT).show(); MainActivity.drawerNV.getMenu().findItem(R.id.i_schedule_md).setChecked(true); MainActivity.FM.beginTransaction() .replace(R.id.fl_container_am, new ScheduleFragment(), "SCHEDULE").commit(); } } else if (online && gradesHtml == null && PreferenceManager.getDefaultSharedPreferences(mainContext) .getBoolean("pref_grades_init", true)) { getGrades(termFocus, HeliniumStudentApp.df_date().format(new Date()), HeliniumStudentApp.DIREC_CURRENT, HeliniumStudentApp.ACTION_INIT_IN); } else { if (gradesHtml == null) gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null); if (online) parseData(HeliniumStudentApp.ACTION_ONLINE); else parseData(HeliniumStudentApp.ACTION_OFFLINE); } ((SwipeRefreshLayout) gradesLayout).setColorSchemeResources(MainActivity.accentSecondaryColor, MainActivity.accentPrimaryColor, MainActivity.primaryColor); ((SwipeRefreshLayout) gradesLayout).setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { refresh(); } }); gradesELV.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() { int previousPosition = -1; @Override public void onGroupExpand(int position) { if (position != previousPosition) gradesELV.collapseGroup(previousPosition); previousPosition = position; } }); gradesELV.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { //Just a little easter egg int clickCount = 1; @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int position, long id) { if (clickCount >= 80) { Toast.makeText(mainContext, "Is this what you wanted?", Toast.LENGTH_SHORT).show(); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://youtu.be/dQw4w9WgXcQ"))); } else { switch (clickCount) { case 2: Toast.makeText(mainContext, "Good for you!", Toast.LENGTH_SHORT).show(); break; case 10: Toast.makeText(mainContext, "You're really proud of that, aren't you?", Toast.LENGTH_SHORT).show(); break; case 20: Toast.makeText(mainContext, "It's really not that big of a deal...", Toast.LENGTH_SHORT) .show(); break; case 40: Toast.makeText(mainContext, "You can stop now.", Toast.LENGTH_SHORT).show(); break; case 50: Toast.makeText(mainContext, "Please...", Toast.LENGTH_SHORT).show(); case 60: Toast.makeText(mainContext, "F* OFF!", Toast.LENGTH_SHORT).show(); break; } } clickCount++; return false; } }); MainActivity.prevIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (MainActivity.isOnline()) { if (termFocus != 1) { termFocus--; getGrades(termFocus, HeliniumStudentApp.df_grades(yearFocus), HeliniumStudentApp.DIREC_BACK, HeliniumStudentApp.ACTION_REFRESH_IN); } else { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_ONLINE); } } else { final int databaseFocus = Integer.parseInt(PreferenceManager .getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1")); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null) != null && yearFocus == 0 && termFocus > databaseFocus) { yearFocus = 0; termFocus = databaseFocus; gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("html_grades", null); parseData(HeliniumStudentApp.ACTION_OFFLINE); } else { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_OFFLINE); } } } }); MainActivity.historyIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (MainActivity.isOnline()) { if (maxYear != 1) { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_ONLINE); final AlertDialog.Builder gradesDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(mainContext, MainActivity.themeDialog)); final View gradesLayout = View.inflate(mainContext, R.layout.dialog_grades, null); gradesDialogBuilder.setTitle(getString(R.string.year, maxYear)); final NumberPicker yearNP = (NumberPicker) gradesLayout.findViewById(R.id.np_year_dg); gradesDialogBuilder.setView(gradesLayout); //TODO Listen for year change. gradesDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (MainActivity.isOnline()) { final int oldValue = yearFocus; yearFocus = yearNP.getValue() - maxYear; getGrades(termFocus, HeliniumStudentApp.df_grades(yearFocus), oldValue + HeliniumStudentApp.FOCUS_YEAR, HeliniumStudentApp.ACTION_REFRESH_IN); } else { Toast.makeText(mainContext, getString(R.string.error_conn_no), Toast.LENGTH_SHORT).show(); } } }); yearNP.setMinValue(1); yearNP.setMaxValue(maxYear); yearNP.setValue(maxYear); java.lang.reflect.Field[] pickerFields = NumberPicker.class.getDeclaredFields(); for (java.lang.reflect.Field pf : pickerFields) { if (pf.getName().equals("mSelectionDivider")) { pf.setAccessible(true); try { pf.set(yearNP, new ColorDrawable(ContextCompat.getColor(mainContext, MainActivity.accentPrimaryColor))); } catch (IllegalArgumentException | IllegalAccessException ignored) { } break; /*} else if(pf.getName().equals("mSelectorWheelPaint")) { pf.setAccessible(true); try { ((Paint) pf.get(yearNP)) .setColor(getColor(MainActivity.themePrimaryTextColor)); } catch (IllegalArgumentException | IllegalAccessException ignored) {}*/ //FIXME Doesn't work... yet } else if (pf.getName().equals("mInputText")) { pf.setAccessible(true); try { ((EditText) pf.get(yearNP)).setTextColor(ContextCompat.getColor(mainContext, MainActivity.themePrimaryTextColor)); } catch (IllegalArgumentException | IllegalAccessException ignored) { } } } yearNP.invalidate(); gradesDialogBuilder.setNegativeButton(android.R.string.cancel, null); AlertDialog gradesDialog = gradesDialogBuilder.create(); gradesDialog.setCanceledOnTouchOutside(true); gradesDialog.show(); gradesDialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor( ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor)); gradesDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor( ContextCompat.getColor(mainContext, MainActivity.accentSecondaryColor)); } } else { final int databaseFocus = Integer.parseInt(PreferenceManager .getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1")); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null) != null && yearFocus != 0 || termFocus != databaseFocus) { yearFocus = 0; termFocus = databaseFocus; gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("html_grades", null); parseData(HeliniumStudentApp.ACTION_OFFLINE); } else { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_OFFLINE); } } } }); MainActivity.nextIV.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (MainActivity.isOnline()) { if (termFocus != 4) { termFocus++; getGrades(termFocus, HeliniumStudentApp.df_grades(yearFocus), HeliniumStudentApp.DIREC_NEXT, HeliniumStudentApp.ACTION_REFRESH_IN); } else { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_ONLINE); } } else { final int databaseFocus = Integer.parseInt(PreferenceManager .getDefaultSharedPreferences(mainContext).getString("pref_grades_term", "1")); if (PreferenceManager.getDefaultSharedPreferences(mainContext).getString("html_grades", null) != null && yearFocus == 0 && termFocus < databaseFocus) { yearFocus = 0; termFocus = databaseFocus; gradesHtml = PreferenceManager.getDefaultSharedPreferences(mainContext) .getString("html_grades", null); parseData(HeliniumStudentApp.ACTION_OFFLINE); } else { MainActivity.setUI(HeliniumStudentApp.VIEW_GRADES, HeliniumStudentApp.ACTION_OFFLINE); } } } }); } return gradesLayout; }
From source file:com.itheima.googlemarket.PagerSlidingTabStrip.java
/** * Tab/* w w w. j a va 2 s. co m*/ * @param pressedColor ?tab8?16??0x66FF0000 * @param normalColor ?tab8?16??0x66FF0000 */ public void setTabBackground(int pressedColor, int normalColor) { tabBackgroundPressed = new ColorDrawable(pressedColor); tabBackgroundNormal = new ColorDrawable(normalColor); updateTabStyles(); }
From source file:com.android.displayingbitmaps.util.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView.//from w ww .j av a2 s . c o m * * @param imageView * @param drawable */ protected void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable }); // Set background to loading bitmap //imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:aierjun.com.aierjunlibrary.widget.tablayout.PagerSlidingTabStrip.java
public StateListDrawable createColorStateListDrawable(@ColorInt int normal, @ColorInt int checked) { StateListDrawable bg = new StateListDrawable(); Drawable normalDrawable = new ColorDrawable(normal); Drawable pressedDrawable = new ColorDrawable(checked); Drawable focusedDrawable = new ColorDrawable(checked); // View.PRESSED_ENABLED_STATE_SET bg.addState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled }, pressedDrawable); // View.ENABLED_FOCUSED_STATE_SET bg.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_focused }, focusedDrawable); // View.ENABLED_STATE_SET bg.addState(new int[] { android.R.attr.state_enabled }, normalDrawable); // View.FOCUSED_STATE_SET bg.addState(new int[] { android.R.attr.state_focused }, focusedDrawable); // View.EMPTY_STATE_SET bg.addState(new int[] {}, normalDrawable); return bg;/*www.j a v a 2 s . c o m*/ }
From source file:com.mediatek.galleryfeature.stereo.segment.background.StereoBackgroundActivity.java
private void loadXML() { setContentView(R.layout.m_stereo_background_activity); mActionBar = getActionBar();/* w w w . j a v a 2 s . c o m*/ mActionBar.setBackgroundDrawable(new ColorDrawable(ACTIONBAR_BACKGROUND_COLOR)); mActionBar.setSubtitle(null); mActionBar.setCustomView(R.layout.m_stereo_actionbar); mSaveButton = mActionBar.getCustomView(); View clickableRegion = mSaveButton.findViewById(R.id.stereo_segment_save); clickableRegion.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { saveSynthedImage(); } }); setActionBarDisplayOptions(mActionBar, true, true); mImageShowBackground = (ImageShow) findViewById(R.id.imageShowBackground); mButtonCollapse = findViewById(R.id.collapse); mBackgroundThumbnailList = findViewById(R.id.main_panel_container); mBackgroundStrip = findViewById(R.id.mainPanel); mButtonCollapse.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mIsBottomStripIn) { ((ImageView) (mButtonCollapse)).setImageBitmap(mBitmapExpand); ObjectAnimator animator = ObjectAnimator.ofFloat(mBackgroundStrip, "translationY", mBackgroundThumbnailList.getHeight()); animator.setDuration(THUMBNAIL_TRACK_ANIMATION_DURATION).start(); mIsBottomStripIn = false; } else { ((ImageView) (mButtonCollapse)).setImageBitmap(mBitmapCollapse); ObjectAnimator animator = ObjectAnimator.ofFloat(mBackgroundStrip, "translationY", 0); animator.setDuration(THUMBNAIL_TRACK_ANIMATION_DURATION).start(); mIsBottomStripIn = true; } } }); }
From source file:com.intuit.qboecoui.feeds.util.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView.// w w w . j av a 2 s .c o m * * @param imageView * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable }); // Set background to loading bitmap //imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.andreaszeiser.bob.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set * on the ImageView./*from w ww . ja v a 2 s . c o m*/ * * @param imageView * @param bitmap */ private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { // Use TransitionDrawable to fade in final TransitionDrawable td = new TransitionDrawable(new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); // noinspection deprecation imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageBitmap(bitmap); } }
From source file:com.granita.tasks.ViewTaskFragment.java
@SuppressLint("NewApi") private void updateColor(float percentage) { if (getActivity() instanceof TaskListActivity) { return;/*from w ww . j a v a 2 s. c om*/ } float[] hsv = new float[3]; Color.colorToHSV(mListColor, hsv); if (VERSION.SDK_INT >= 11 && mColorBar != null) { percentage = Math.max(0, Math.min(Float.isNaN(percentage) ? 0 : percentage, 1)); percentage = (float) Math.pow(percentage, 1.5); int newColor = darkenColor2(mListColor); hsv[2] *= (0.5 + 0.25 * percentage); ActionBar actionBar = ((ActionBarActivity) getActivity()).getSupportActionBar(); actionBar.setBackgroundDrawable( new ColorDrawable((newColor & 0x00ffffff) | ((int) (percentage * 255) << 24))); // this is a workaround to ensure the new color is applied on all devices, some devices show a transparent ActionBar if we don't do that. actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowTitleEnabled(false); mColorBar.setBackgroundColor(mListColor); if (VERSION.SDK_INT >= 21) { Window window = getActivity().getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(newColor | 0xff000000); } } if (mActionButton != null) { // adjust color of action button if (hsv[0] > 70 && hsv[0] < 170 && hsv[2] < 0.62) { mActionButton.setBackgroundResource(R.drawable.bg_actionbutton_light); } else { mActionButton.setBackgroundResource(R.drawable.bg_actionbutton); } } }
From source file:com.image.cache.util.ImageWorker.java
/** * Called when the processing is complete and the final drawable should be * set on the ImageView./*www .ja va 2 s . co m*/ * * @param imageView * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), drawable }); // Set background to loading bitmap imageView.setImageDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
From source file:com.github.shareme.gwsmaterialdrawer.library.DrawerView.java
private void updateProfile() { Log.d(TAG, "updateProfile()"); if (mProfileAdapter.getCount() > 0 && isInViewHierarchy) { final DrawerProfile currentProfile = mProfileAdapter.getItem(0); if (mProfileAdapter.getCount() > 2) { /* More than two profiles. Should show a little badge. */ textViewProfileAvatarCount.setText("+" + (mProfileAdapter.getCount() - 1)); textViewProfileAvatarCount.setOnClickListener(new OnClickListener() { @Override//from w w w . ja v a2s .c o m public void onClick(View v) { openProfileList(); } }); if (currentProfile.getBackground() instanceof BitmapDrawable) { new Palette.Builder(((BitmapDrawable) currentProfile.getBackground()).getBitmap()) .resizeBitmapSize(500).generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { Palette.Swatch vibrantSwatch = palette.getVibrantSwatch(); if (vibrantSwatch != null) { textViewProfileAvatarCount.setTextColor(vibrantSwatch.getTitleTextColor()); textViewProfileAvatarCount.getBackground() .setColorFilter(vibrantSwatch.getRgb(), PorterDuff.Mode.SRC_IN); } } }); } imageViewProfileAvatarSecondary.setVisibility(INVISIBLE); textViewProfileAvatarCount.setVisibility(VISIBLE); imageViewOpenProfileListIcon.setVisibility(VISIBLE); } else if (mProfileAdapter.getCount() == 2) { /* Two profiles. Should show the second profile avatar. */ final DrawerProfile secondProfile = mProfileAdapter.getItem(1); if (secondProfile.hasAvatar()) { imageViewProfileAvatarSecondary.setImageDrawable(secondProfile.getAvatar()); imageViewProfileAvatarSecondary.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { selectProfile(secondProfile); } }); imageViewProfileAvatarSecondary.setVisibility(VISIBLE); } else { imageViewProfileAvatarSecondary.setVisibility(INVISIBLE); } textViewProfileAvatarCount.setVisibility(GONE); imageViewOpenProfileListIcon.setVisibility(VISIBLE); closeProfileList(); } else { imageViewProfileAvatarSecondary.setVisibility(INVISIBLE); textViewProfileAvatarCount.setVisibility(GONE); imageViewOpenProfileListIcon.setVisibility(GONE); } if (currentProfile.getAvatar() != null) { imageViewProfileAvatar.setImageDrawable(currentProfile.getAvatar()); } if (currentProfile.getName() != null && !currentProfile.getName().equals("")) { textViewProfileName.setText(currentProfile.getName()); } if (currentProfile.getBackground() != null) { imageViewProfileBackground.setImageDrawable(currentProfile.getBackground()); } else { imageViewProfileBackground .setImageDrawable(new ColorDrawable(getResources().getColor(android.R.color.transparent))); } if (currentProfile.getDescription() != null && !currentProfile.getDescription().equals("")) { textViewProfileDescription.setVisibility(VISIBLE); textViewProfileDescription.setText(currentProfile.getDescription()); } else { textViewProfileDescription.setVisibility(GONE); } if (currentProfile.hasOnProfileClickListener()) { frameLayoutProfile.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { currentProfile.getOnProfileClickListener().onClick(currentProfile, currentProfile.getId()); } }); frameLayoutProfile.setEnabled(true); } else { if (hasOnProfileClickListener()) { frameLayoutProfile.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getOnProfileClickListener().onClick(currentProfile, currentProfile.getId()); } }); frameLayoutProfile.setEnabled(true); } else { frameLayoutProfile.setEnabled(false); } } updateProfileTheme(); } else { closeProfileList(); } }