List of usage examples for android.graphics.drawable StateListDrawable addState
public void addState(int[] stateSet, Drawable drawable)
From source file:com.androguide.apkreator.MainActivity.java
private StateListDrawable getColouredTouchFeedback() { StateListDrawable states = new StateListDrawable(); states.addState(new int[] { android.R.attr.state_pressed }, new ColorDrawable(Color.parseColor(getPluginColor()))); states.addState(new int[] { android.R.attr.state_focused }, new ColorDrawable(Color.parseColor(getPluginColor()))); states.addState(new int[] {}, getResources().getDrawable(android.R.color.transparent)); return states; }
From source file:com.lambdasoup.quickfit.ui.WorkoutListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Timber.d("onCreate before inflate"); setContentView(R.layout.activity_workout_list); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* ww w .j av a2s . co m*/ //noinspection ConstantConditions toolbar.setTitle(getTitle()); fabAnimationDuration = getResources().getInteger(R.integer.fab_animation_duration); fab = (FloatingActionButton) findViewById(R.id.fab); //noinspection ConstantConditions fab.setOnClickListener(view -> addNewWorkout()); // need to set statelistdrawable referencing vector drawables programmatically, because // support library vector drawable support in 23.3.0 does not allow vector drawable // references in xml statelistdrawables if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { VectorDrawableCompat drawableAdd = VectorDrawableCompat.create(getResources(), R.drawable.ic_add_white_fat_24dp, getTheme()); VectorDrawableCompat drawableExpandLess = VectorDrawableCompat.create(getResources(), R.drawable.ic_expand_less_white_fat_24dp, getTheme()); StateListDrawable stateListDrawable = new StateListDrawable(); stateListDrawable.addState(new int[] { android.R.attr.state_activated }, drawableExpandLess); stateListDrawable.addState(new int[] {}, drawableAdd); fab.setImageDrawable(stateListDrawable); } fabBackgroundToActivated = BackgroundTintListAnimator.create(this, fab, R.color.colorAccent, R.color.colorPrimaryMediumLight, fabAnimationDuration); fabBackgroundToNotActivated = BackgroundTintListAnimator.create(this, fab, R.color.colorPrimaryMediumLight, R.color.colorAccent, fabAnimationDuration); masterDetailView = (MasterDetailLayout) findViewById(R.id.two_panes); if (masterDetailView != null) { // The detail container view will be present only in the // large-screen layouts (res/values-w900dp). // If this view is present, then the // activity should be in two-pane mode. isTwoPane = true; fabAddSchedule = findViewById(R.id.fab_add_schedule); //noinspection ConstantConditions fabAddSchedule.setOnClickListener(view -> addNewSchedule()); fabAddWorkout = findViewById(R.id.fab_add_workout); //noinspection ConstantConditions fabAddWorkout.setOnClickListener(view -> addNewWorkout()); setMiniFabOffsets(); masterDetailView.setAfterCollapse(() -> { CoordinatorLayout.LayoutParams fabLayoutParams = (CoordinatorLayout.LayoutParams) fab .getLayoutParams(); fabLayoutParams.setAnchorId(View.NO_ID); fabLayoutParams.gravity = Gravity.BOTTOM | Gravity.END; fab.setLayoutParams(fabLayoutParams); Fragment schedulesFragment = getSupportFragmentManager().findFragmentById(R.id.schedules_container); getSupportFragmentManager().beginTransaction().remove(schedulesFragment).commit(); }); } workoutsRecyclerView = (EmptyRecyclerView) findViewById(R.id.workout_list); workoutsAdapter = new WorkoutItemRecyclerViewAdapter(this, isTwoPane); workoutsAdapter.setOnWorkoutInteractionListener(this); workoutsRecyclerView.setAdapter(workoutsAdapter); workoutsRecyclerView.addItemDecoration(new DividerItemDecoration(this, false)); readIntentExtras(); if (savedInstanceState != null) { idToSelect = savedInstanceState.getLong(KEY_SHOW_WORKOUT_ID, NO_ID); if (idToSelect == NO_ID) { idToSelect = savedInstanceState.getLong(KEY_SELECTED_ITEM_ID, NO_ID); } } else { idToSelect = FIRST_ITEM_IF_EXISTS; } getLoaderManager().initLoader(0, null, this); Timber.d("onCreate finished"); }
From source file:com.esri.android.ecologicalmarineunitexplorer.watercolumn.WaterColumnFragment.java
private StateListDrawable buildStateList(int emuName) { StateListDrawable stateListDrawable = new StateListDrawable(); GradientDrawable defaultShape = new GradientDrawable(); int color = Color.parseColor(EmuHelper.getColorForEMUCluster(getContext(), emuName)); defaultShape.setColor(color);//w w w . java 2s . c o m GradientDrawable selectedPressShape = new GradientDrawable(); selectedPressShape.setColor(color); selectedPressShape.setStroke(5, Color.parseColor("#f4f442")); stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, selectedPressShape); stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selectedPressShape); stateListDrawable.addState(new int[] { android.R.attr.state_enabled }, defaultShape); return stateListDrawable; }
From source file:org.androidwhite.icons.ui.MainActivity.java
private void setupNavDrawer() { assert mNavView != null; assert mDrawer != null; mNavView.getMenu().clear();/*from ww w . ja v a 2s . c o m*/ for (PagesBuilder.Page page : mPages) page.addToMenu(mNavView.getMenu()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getWindow().setStatusBarColor(Color.TRANSPARENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mDrawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { //TODO: Check if NavigationView needs bottom padding WindowInsets drawerLayoutInsets = insets.replaceSystemWindowInsets( insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), 0); mDrawerModeTopInset = drawerLayoutInsets.getSystemWindowInsetTop(); ((DrawerLayout) v).setChildInsets(drawerLayoutInsets, drawerLayoutInsets.getSystemWindowInsetTop() > 0); return insets; } }); } assert getSupportActionBar() != null; getSupportActionBar().setDisplayHomeAsUpEnabled(true); Drawable menuIcon = ContextCompat.getDrawable(this, R.drawable.ic_action_menu); menuIcon = TintUtils.createTintedDrawable(menuIcon, DialogUtils.resolveColor(this, R.attr.tab_icon_color)); getSupportActionBar().setHomeAsUpIndicator(menuIcon); mDrawer.addDrawerListener( new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.drawer_open, R.string.drawer_close)); mDrawer.setStatusBarBackgroundColor(DialogUtils.resolveColor(this, R.attr.colorPrimaryDark)); mNavView.setNavigationItemSelectedListener(this); final ColorDrawable navBg = (ColorDrawable) mNavView.getBackground(); final int selectedIconText = DialogUtils.resolveColor(this, R.attr.colorAccent); int iconColor; int titleColor; int selectedBg; if (TintUtils.isColorLight(navBg.getColor())) { iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_light); titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_light); selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_light); } else { iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_dark); titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_dark); selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_dark); } final ColorStateList iconSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked } }, new int[] { iconColor, selectedIconText }); final ColorStateList textSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked } }, new int[] { titleColor, selectedIconText }); mNavView.setItemTextColor(textSl); mNavView.setItemIconTintList(iconSl); StateListDrawable bgDrawable = new StateListDrawable(); bgDrawable.addState(new int[] { android.R.attr.state_checked }, new ColorDrawable(selectedBg)); mNavView.setItemBackground(bgDrawable); mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { dispatchFragmentUpdateTitle(false); invalidateNavViewSelection(position); } }); mToolbar.setContentInsetsRelative(getResources().getDimensionPixelSize(R.dimen.second_keyline), 0); }
From source file:com.afollestad.polar.ui.MainActivity.java
private void setupNavDrawer() { assert mNavView != null; assert mDrawer != null; mNavView.getMenu().clear();//from www . j a v a 2 s. c o m for (PagesBuilder.Page page : mPages) page.addToMenu(mNavView.getMenu()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getWindow().setStatusBarColor(Color.TRANSPARENT); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mDrawer.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) { //TODO: Check if NavigationView needs bottom padding WindowInsets drawerLayoutInsets = insets.replaceSystemWindowInsets( insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), 0); mDrawerModeTopInset = drawerLayoutInsets.getSystemWindowInsetTop(); ((DrawerLayout) v).setChildInsets(drawerLayoutInsets, drawerLayoutInsets.getSystemWindowInsetTop() > 0); return insets; } }); } assert getSupportActionBar() != null; getSupportActionBar().setDisplayHomeAsUpEnabled(true); Drawable menuIcon = VC.get(R.drawable.ic_action_menu); menuIcon = TintUtils.createTintedDrawable(menuIcon, DialogUtils.resolveColor(this, R.attr.tab_icon_color)); getSupportActionBar().setHomeAsUpIndicator(menuIcon); mDrawer.addDrawerListener( new ActionBarDrawerToggle(this, mDrawer, mToolbar, R.string.drawer_open, R.string.drawer_close)); mDrawer.setStatusBarBackgroundColor(DialogUtils.resolveColor(this, R.attr.colorPrimaryDark)); mNavView.setNavigationItemSelectedListener(this); final ColorDrawable navBg = (ColorDrawable) mNavView.getBackground(); final int selectedIconText = DialogUtils.resolveColor(this, R.attr.colorAccent); int iconColor; int titleColor; int selectedBg; if (TintUtils.isColorLight(navBg.getColor())) { iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_light); titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_light); selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_light); } else { iconColor = ContextCompat.getColor(this, R.color.navigationview_normalicon_dark); titleColor = ContextCompat.getColor(this, R.color.navigationview_normaltext_dark); selectedBg = ContextCompat.getColor(this, R.color.navigationview_selectedbg_dark); } final ColorStateList iconSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked } }, new int[] { iconColor, selectedIconText }); final ColorStateList textSl = new ColorStateList(new int[][] { new int[] { -android.R.attr.state_checked }, new int[] { android.R.attr.state_checked } }, new int[] { titleColor, selectedIconText }); mNavView.setItemTextColor(textSl); mNavView.setItemIconTintList(iconSl); StateListDrawable bgDrawable = new StateListDrawable(); bgDrawable.addState(new int[] { android.R.attr.state_checked }, new ColorDrawable(selectedBg)); mNavView.setItemBackground(bgDrawable); mPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { dispatchFragmentUpdateTitle(false); invalidateNavViewSelection(position); } }); mToolbar.setContentInsetsRelative(getResources().getDimensionPixelSize(R.dimen.second_keyline), 0); }
From source file:com.moki.touch.fragments.views.WebContent.java
private StateListDrawable createButtonStateList(int pressedState, int nonPressedState) { StateListDrawable stateList = new StateListDrawable(); stateList.addState(new int[] { android.R.attr.state_pressed }, context.getResources().getDrawable(pressedState)); stateList.addState(new int[] { -android.R.attr.state_pressed }, context.getResources().getDrawable(nonPressedState)); return stateList; }
From source file:git.egatuts.nxtremotecontroller.activity.ControllerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setActiveTheme(super.getPreferenceTheme()); super.setContentView(R.layout.controller_layout); toolbar = (Toolbar) this.findViewById(R.id.toolbar); super.setSupportToolbar(); toolbar.setNavigationOnClickListener(new View.OnClickListener() { @Override/*from ww w . j av a 2 s . c om*/ public void onClick(View v) { ControllerActivity.this.onBackPressed(); } }); /* * We get the device from the extra data of the intent. */ this.device = this.getIntent().getParcelableExtra("device"); /* * We create the final variables we will use in the listeners, etc. */ final ControllerActivity self = this; final GlobalUtils utils = this.getGlobalUtils(); /* * We create the AlertDialog.Builder we will show to ask the user to reconnect with the device. */ this.builder = utils .createAlertDialog(utils.getStringResource(R.string.connecting_reconnect_title), utils.format(R.string.connecting_reconnect_message, this.device.getName())) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { self.finish(); } }).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { self.resume(); } }); /* * Now we define the progress dialog we will show while we are connecting with the device. * When the progress dialog has been cancelled it means the connection process has been cancelled. * But on dismiss we have to check if the connection failed or it succeed. */ this.progressDialog = this.getLongProgressDialog(); this.progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { self.aborted = true; utils.showToast(R.string.connecting_aborted); self.connector.closeConnectThread(); self.finish(); } }); /* * Now we declare the handler that will handle (so obviously) the messages * sent by the threads that are in the background connecting with the device. */ this.handler = new Handler() { @Override public void handleMessage(Message msg) { if ((self.connector.getConnectThread() == null || self.aborted) && self.connector.getConnectedThread() == null) { return; } int category = msg.what; int state; int error; if (category == NXTConnector.WHAT_CHANGE_STATE) { progressDialog.show(); state = msg.arg1; error = msg.arg2; if (NXTConnector.isPreparingConnection(state)) { progressDialog.setText(R.string.connecting_preparing_connection); } else if (NXTConnector.isCreatingSocket(state)) { progressDialog.setText(R.string.connecting_creating_socket); } else if (NXTConnector.isConnecting(state)) { progressDialog.setText(R.string.connecting_connecting); } else if (NXTConnector.isConnected(state)) { progressDialog.dismiss(); utils.showToast(R.string.connecting_connected, device.getName()); self.connected(); } } else if (category == NXTConnector.WHAT_ERROR_ENCOUNTERED) { progressDialog.dismiss(); self.connector.closeAllThreads(); error = msg.arg1; state = msg.arg2; boolean notReconnect = false; if (NXTConnector.connectionClosed(state, error)) { utils.showToast(R.string.connecting_connection_closed); notReconnect = true; ControllerActivity.this.finish(); } else if (NXTConnector.connectionLost(state, error)) { utils.showToast(R.string.connecting_connection_lost); if (!self.connector.getBluetoothUtils().isEnabled()) { notReconnect = true; ControllerActivity.this.finish(); } } else if (NXTConnector.connectionSocketFailed(state, error)) { utils.showToast(R.string.connecting_socket_error); } else if (NXTConnector.connectionRequestFailed(state, error)) { utils.showToast(R.string.connecting_request_failed); } else if (NXTConnector.connectionUnexpectedFailed(state, error)) { utils.showToast(R.string.connecting_unexpected_error); } if (!notReconnect) { self.builder.show(); } } } }; /* * Now we create the connector with the device and the handler * which we will use to connect and send messages to the robot. */ this.connector = new NXTConnector(this, this.device, this.handler); /* * We set the title with the device name. */ String title = utils.getStringResource(R.string.controller_window_title); this.setTitle(title + this.device.getName()); /* * We set the colors we will use with the drawables used in the tabs. */ final int underlineColor = utils.getAttribute(R.attr.toolbar_color); final int backgroundColor = utils.getAttribute(R.attr.toolbar_background); final int lightBackgroundColor = GlobalUtils.mixColors(backgroundColor, 0x55FFFFFF); /* * Now we create the drawables used in all the states of the tabs and then we assign * them to a StateListDrawable to add it to the tabs. */ ShapeDrawable.ShaderFactory tabSelectedFactory = new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { return new LinearGradient(0, 0, /* Origin of the background (top left corner) */ 0, height, /* End of the background (bottom left corner) */ new int[] { backgroundColor, backgroundColor, /* The first gradient doesn't change color so it's like a rectangle shape */ underlineColor, underlineColor /* The same for the second one */ }, new float[] { 0, 51f / 55f, /* The first background covers 51dp out of 55dp */ 51f / 55f, 1 /* And the second one takes the rest of the space */ }, Shader.TileMode.REPEAT /* The repeat mode doesn't mind but this would look prettier in case of error */ ); } }; PaintDrawable tabSel = new PaintDrawable(); tabSel.setShape(new RectShape()); tabSel.setShaderFactory(tabSelectedFactory); ShapeDrawable.ShaderFactory tabSelectedAndPressedFactory = new ShapeDrawable.ShaderFactory() { @Override public Shader resize(int width, int height) { return new LinearGradient(0, 0, /* Origin of the background (top left corner) */ 0, height, /* End of the background (bottom left corner) */ new int[] { lightBackgroundColor, lightBackgroundColor, /* The first gradient doesn't change color so it's like a rectangle shape */ underlineColor, underlineColor /* The same for the second one */ }, new float[] { 0, 51f / 55f, /* The first background covers 51dp out of 55dp */ 51f / 55f, 1 /* And the second one takes the rest of the space */ }, Shader.TileMode.REPEAT /* The repeat mode doesn't mind but this would look prettier in case of error */ ); } }; PaintDrawable tabSelAndPress = new PaintDrawable(); tabSelAndPress.setShape(new RectShape()); tabSelAndPress.setShaderFactory(tabSelectedAndPressedFactory); /* * Now we create the states lists for the drawables and the colors. */ StateListDrawable drawableList = new StateListDrawable(); drawableList.addState(new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed }, new ColorDrawable(lightBackgroundColor)); drawableList.addState(new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed, android.R.attr.state_focused }, new ColorDrawable(lightBackgroundColor)); drawableList.addState(new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed }, tabSel); drawableList.addState(new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed, -android.R.attr.state_focused }, tabSel); drawableList.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_pressed }, tabSelAndPress); drawableList.addState(new int[] { android.R.attr.state_selected, android.R.attr.state_pressed, android.R.attr.state_focused }, tabSelAndPress); drawableList.addState(new int[] {}, new ColorDrawable(backgroundColor)); int darkColor = utils.getAttribute(R.attr.toolbar_color); int lightColor = Color.argb(0xAA, Color.red(darkColor), Color.green(darkColor), Color.blue(darkColor)); int[][] states = new int[][] { new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed }, new int[] { -android.R.attr.state_selected, android.R.attr.state_pressed, android.R.attr.state_focused }, new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed }, new int[] { android.R.attr.state_selected, -android.R.attr.state_pressed, -android.R.attr.state_focused }, new int[] { android.R.attr.state_selected, android.R.attr.state_pressed }, new int[] { android.R.attr.state_selected, android.R.attr.state_pressed, android.R.attr.state_focused }, new int[] { -android.R.attr.state_selected, -android.R.attr.state_pressed, -android.R.attr.state_focused }, new int[] {} }; int[] colors = new int[] { lightColor, /* Text color when pressed and not selected */ lightColor, /* Text color when pressed (with focused fallback) */ darkColor, /* Text color when selected and not pressed */ darkColor, /* Text color when selected and not pressed (with focused fallback) */ darkColor, /* Text color when selected and pressed */ darkColor, /* Text color when selected and pressed (with focused fallback) */ lightColor, /* Normal color when not pressed, selected or focused */ lightColor /* Default text color */ }; ColorStateList colorList = new ColorStateList(states, colors); /* * We assign the drawable and the list to the activity instance to be accessible everywhere. */ this.tabSelected = tabSel; this.tabSelectedAndPressed = tabSelAndPress; this.tabDrawableList = drawableList; this.tabColorList = colorList; /* * Now we setup the tab host and add the tabs to the view. */ this.tabHost = (FragmentTabHost) this.findViewById(R.id.tabhost); this.tabHost.setup(this, super.fragmentManager, R.id.tabcontent); this.tabHost.getTabWidget().setDividerDrawable(null); this.addTab(this.createTabView(R.layout.controller_tab, R.string.controller_tab_local_title), R.string.controller_tab_local_spec, LocalControllerFragment.class); this.addTab(this.createTabView(R.layout.controller_tab, R.string.controller_tab_online_title), R.string.controller_tab_online_spec, OnlineControllerFragment.class); }
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;/* ww w . j a va2 s .c o m*/ }
From source file:de.mrapp.android.view.FloatingActionButton.java
/** * Creates and returns a state list drawable, which can be used as the floating action button * background and adapts the background color depending on the button's current state. * * @return The drawable, which has been created, as an instance of the class {@link Drawable} */// ww w .j av a 2 s .c o m private Drawable createStateListBackgroundDrawable() { StateListDrawable drawable = new StateListDrawable(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { drawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed }, createPressedBackgroundDrawable()); } drawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_activated }, createActivatedBackgroundDrawable()); drawable.addState(new int[] { android.R.attr.state_enabled }, createBackgroundDrawable(getColor())); drawable.addState(new int[] {}, createDisabledBackgroundDrawable()); return drawable; }
From source file:com.mappn.gfan.ui.HomeTabActivity.java
private void drawUpdateCount(Activity context, Resources res, ImageView view, boolean flag) { DisplayMetrics dm = new DisplayMetrics(); context.getWindowManager().getDefaultDisplay().getMetrics(dm); Bitmap cornerRes = BitmapFactory.decodeResource(res, R.drawable.notify_update); Bitmap appBitmapNormal = BitmapFactory.decodeResource(res, R.drawable.main_tab_app_unselect); Bitmap appBitmapPressed = BitmapFactory.decodeResource(res, R.drawable.main_tab_app_select); StateListDrawable stateDrawable = new StateListDrawable(); int stateSelected = android.R.attr.state_selected; if (flag) {//from w w w . j a va 2s.c o m Bitmap cornerBitmap = drawText(dm, res, cornerRes, mSession.getUpgradeNumber()); Bitmap newBitmapNormal = drawBitmap(dm, appBitmapNormal, cornerBitmap); Bitmap newBitmapPressed = drawBitmap(dm, appBitmapPressed, cornerBitmap); stateDrawable.addState(new int[] { -stateSelected }, new BitmapDrawable(res, newBitmapNormal)); stateDrawable.addState(new int[] { stateSelected }, new BitmapDrawable(res, newBitmapPressed)); view.setImageDrawable(stateDrawable); } else { view.setImageResource(R.drawable.main_tab_app_manager_selector); } }