List of usage examples for android.graphics.drawable Drawable setColorFilter
public void setColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode)
From source file:com.apptentive.android.sdk.ApptentiveViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle bundle = FragmentFactory.addDisplayModeToFragmentBundle(getIntent().getExtras()); boolean isInteractionModal = bundle.getBoolean(Constants.FragmentConfigKeys.MODAL); ApptentiveBaseFragment newFragment = null; if (savedInstanceState != null) { // retrieve the retained fragment after orientation change using saved tag String savedFragmentTag = savedInstanceState.getString(FRAGMENT_TAG); newFragment = (ApptentiveBaseFragment) getSupportFragmentManager().findFragmentByTag(savedFragmentTag); /* Since we always store tags of fragments in the ViewPager upon orientation change, * failure of retrieval indicate internal error */// w w w .j a v a 2s. c o m if (newFragment == null) { finish(); return; } } try { fragmentType = bundle.getInt(Constants.FragmentConfigKeys.TYPE, Constants.FragmentTypes.UNKNOWN); if (fragmentType != Constants.FragmentTypes.UNKNOWN) { if (fragmentType == Constants.FragmentTypes.INTERACTION || fragmentType == Constants.FragmentTypes.MESSAGE_CENTER_ERROR || fragmentType == Constants.FragmentTypes.ABOUT) { bundle.putInt("toolbarLayoutId", R.id.apptentive_toolbar); if (newFragment == null) { newFragment = FragmentFactory.createFragmentInstance(bundle); isInteractionModal = newFragment.isShownAsModalDialog(); } if (newFragment != null) { applyApptentiveTheme(isInteractionModal); newFragment.setOnTransitionListener(this); } } if (newFragment == null) { if (fragmentType == Constants.FragmentTypes.ENGAGE_INTERNAL_EVENT) { String eventName = getIntent().getStringExtra(Constants.FragmentConfigKeys.EXTRA); if (eventName != null) { EngagementModule.engageInternal(this, eventName); } } finish(); return; } } } catch (Exception e) { ApptentiveLog.e("Error creating ApptentiveViewActivity.", e); MetricModule.sendError(e, null, null); } setContentView(R.layout.apptentive_viewactivity); toolbar = (Toolbar) findViewById(R.id.apptentive_toolbar); setSupportActionBar(toolbar); /* Add top padding by the amount of Status Bar height to avoid toolbar being covered when * status bar is translucent */ toolbar.setPadding(0, getToolbarHeightAdjustment(!isInteractionModal), 0, 0); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); int navIconResId = newFragment.getToolbarNavigationIconResourceId(getTheme()); // Check if fragment may show an alternative navigation icon if (navIconResId != 0) { /* In order for the alternative icon has the same color used by toolbar icon, * need to apply the same color in toolbar theme * By default colorControlNormal has same value as textColorPrimary defined in toolbar theme overlay */ final Drawable alternateUpArrow = ResourcesCompat.getDrawable(getResources(), navIconResId, getTheme()); int colorControlNormal = Util.getThemeColor( ApptentiveInternal.getInstance().getApptentiveToolbarTheme(), R.attr.colorControlNormal); alternateUpArrow.setColorFilter(colorControlNormal, PorterDuff.Mode.SRC_ATOP); actionBar.setHomeAsUpIndicator(alternateUpArrow); } } //current_tab = extra.getInt(SELECTED_TAB_EXTRA_KEY, 0); current_tab = 0; addFragmentToAdapter(newFragment, newFragment.getTitle()); // Get the ViewPager and set it's PagerAdapter so that it can display items viewPager = (ViewPager) findViewById(R.id.apptentive_vp); viewPager.setAdapter(viewPager_Adapter); ViewPager.OnPageChangeListener pageChangeListener = new ViewPager.OnPageChangeListener() { Boolean first = true; @Override public void onPageSelected(int position) { final ApptentiveBaseFragment currentFragment = (ApptentiveBaseFragment) viewPager_Adapter .getItem(viewPager.getCurrentItem()); // Set the Activity title for TalkBack support final String title = currentFragment.getTitle(); if (currentFragment != null && currentFragment.getActivity() != null) { currentFragment.getActivity().setTitle(title); } if (!currentFragment.isShownAsModalDialog()) { toolbar.post(new Runnable() { @Override public void run() { toolbar.setVisibility(View.VISIBLE); toolbar.setTitle(title); } }); } else { toolbar.setVisibility(View.GONE); } current_tab = position; } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (first && positionOffset == 0 && positionOffsetPixels == 0) { onPageSelected(current_tab); first = false; } } @Override public void onPageScrollStateChanged(int pos) { // TODO Auto-generated method stub } }; viewPager.addOnPageChangeListener(pageChangeListener); // Needed to prevent the window from being panned up when the keyboard is opened. getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); }
From source file:com.example.sam.savemeapp.StatisticsFragment.java
/** * Sets up the initial legend with the contained categories shown * in the pie chart and bullet points with the corresponding colors. *//*from w w w .jav a 2 s . c o m*/ public void setUpPiechart() { pieChart.getDescription().setEnabled(false); Legend pieL = pieChart.getLegend(); Log.d("stats", Float.toString(pieL.getEntries().length)); startLegend = pieL; LegendEntry[] legends = pieL.getEntries(); pieL.setEnabled(false); mLegend.removeAllViews(); //The default legend consist of TextViews and ImageViews which contains a bullet point. //The legends are contained inside of a horizontal LinearLayout which is contained in a vertical LinearLayout. for (int t = 0; t < legends.length - 1; t++) { LegendEntry x = legends[t]; LinearLayout hLayout = new LinearLayout(getContext()); hLayout.setLayoutParams(params); TextView tv = new TextView(getContext()); tv.setText(x.label); tv.setTextColor(x.formColor); tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textViewParams.setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin)); tv.setLayoutParams(textViewParams); ImageView iv = new ImageView(getContext()); Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend); dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC); iv.setImageDrawable(dot); iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); hLayout.addView(iv); hLayout.addView(tv); mLegend.addView(hLayout); } designPiechart(); pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { private int color; @Override public void onValueSelected(Entry e, Highlight h) { //it creates new legends with the information of the subcategories when a // category in the pi chart is clicked ArrayList<LegendEntry> list = new ArrayList<>(); mLegend.removeAllViews(); if (e.getData().equals(Color.parseColor("#00a0ae"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Food & Beverage")) { color = x.formColor; } } list.add(new LegendEntry("Food & Beverage: " + u.categories.get("Food & Beverage").get("Food & Beverage") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Restaurant & Caf: " + u.categories.get("Food & Beverage").get("Restaurant & Caf") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Supermarket: " + u.categories.get("Food & Beverage").get("Supermarket") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); //This category legends consist of the main category in this case "Food & Beverage" in the top of the legend //and the sub categories bellow. The name is also shown together with the amount spend in that category. for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#be3127"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Transportation")) { color = x.formColor; } } list.add(new LegendEntry("Transportation: " + u.categories.get("Transportation").get("Transportation") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Public transport: " + u.categories.get("Transportation").get("Public transport") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Taxi & Uber: " + u.categories.get("Transportation").get("Taxi & Uber") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Petrol: " + u.categories.get("Transportation").get("Petrol") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Maintenance: " + u.categories.get("Transportation").get("Maintenance") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#7dc725"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Shopping")) { color = x.formColor; } } list.add(new LegendEntry( "Shopping: " + u.categories.get("Shopping").get("Shopping") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Clothing: " + u.categories.get("Shopping").get("Clothing") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Electronics: " + u.categories.get("Shopping").get("Electronics") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Books: " + u.categories.get("Shopping").get("Books") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Gifts: " + u.categories.get("Shopping").get("Gifts") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Other: " + u.categories.get("Shopping").get("Other") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#e88300"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Entertainment")) { color = x.formColor; } } list.add(new LegendEntry( "Entertainment: " + u.categories.get("Entertainment").get("Entertainment") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Going out: " + u.categories.get("Entertainment").get("Going out") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Sports: " + u.categories.get("Entertainment").get("Sports") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#dc006d"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Health")) { color = x.formColor; } } list.add(new LegendEntry("Health: " + u.categories.get("Health").get("Health") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Doctor: " + u.categories.get("Health").get("Doctor") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Pharmacy: " + u.categories.get("Health").get("Pharmacy") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } else if (e.getData().equals(Color.parseColor("#1562a4"))) { for (LegendEntry x : startLegend.getEntries()) { if (x.label.equals("Bills")) { color = x.formColor; } } list.add(new LegendEntry("Bills: " + u.categories.get("Bills").get("Bills") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Water: " + u.categories.get("Bills").get("Water") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry( "Electricity: " + u.categories.get("Bills").get("Electricity") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Gas: " + u.categories.get("Bills").get("Gas") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Rent: " + u.categories.get("Bills").get("Rent") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Phone: " + u.categories.get("Bills").get("Phone") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add( new LegendEntry("Insurance: " + u.categories.get("Bills").get("Insurance") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("TV: " + u.categories.get("Bills").get("TV") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); list.add(new LegendEntry("Internet: " + u.categories.get("Bills").get("Internet") + u.currency, Legend.LegendForm.SQUARE, 7f, 7f, null, color)); mLegend.removeAllViews(); for (LegendEntry x : list) { TextView tv = new TextView(getContext()); if (x.equals(list.get(0))) { tv.setTypeface(fontBlack); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); } else { tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_text_size)); } tv.setText(x.label); tv.setTextColor(color); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); mLegend.addView(tv); } } } @Override public void onNothingSelected() { //Sets up the default legend when nothing is selected pieChart = (PieChart) v.findViewById(R.id.piechart); pieChart.setUsePercentValues(true); LegendEntry[] legends = startLegend.getEntries(); startLegend.setEnabled(false); mLegend.removeAllViews(); for (LegendEntry x : legends) { LinearLayout hLayout = new LinearLayout(getContext()); hLayout.setLayoutParams(params); TextView tv = new TextView(getContext()); tv.setText(x.label); tv.setTextColor(x.formColor); tv.setTypeface(fontLight); tv.setTextSize(TypedValue.COMPLEX_UNIT_SP, getResources().getDimension(R.dimen.statistics_main_text_size)); tv.setTextAlignment(View.TEXT_ALIGNMENT_TEXT_START); LinearLayoutCompat.LayoutParams textViewParams = new LinearLayoutCompat.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); textViewParams .setMarginStart((int) getResources().getDimension(R.dimen.statistics_text_margin)); tv.setLayoutParams(textViewParams); ImageView iv = new ImageView(getContext()); Drawable dot = ContextCompat.getDrawable(getContext(), R.drawable.circle_legend); dot.setColorFilter(x.formColor, PorterDuff.Mode.SRC); iv.setImageDrawable(dot); iv.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); hLayout.addView(iv); hLayout.addView(tv); mLegend.addView(hLayout); } } }); }
From source file:com.terracom.mumbleclient.app.QRPushToTalkActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem disconnectButton = menu.findItem(R.id.action_disconnect); try {//from w w w. j a v a 2 s . c o m disconnectButton.setVisible(mService != null && mService.isConnected()); } catch (RemoteException e) { e.printStackTrace(); } // Color the action bar icons to the primary text color of the theme. int foregroundColor = getSupportActionBar().getThemedContext() .obtainStyledAttributes(new int[] { android.R.attr.textColor }).getColor(0, -1); for (int x = 0; x < menu.size(); x++) { MenuItem item = menu.getItem(x); if (item.getIcon() != null) { Drawable icon = item.getIcon().mutate(); // Mutate the icon so that the color filter is exclusive to the action bar icon.setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY); } } return super.onPrepareOptionsMenu(menu); }
From source file:com.bitants.wally.fragments.SearchFragment.java
private void colorizeColorTag(int backgroundColor, int primaryColor, int secondaryColor, String hexColor) { Drawable colorTagCardBackground = getResources().getDrawable(R.drawable.chip_background); colorTagCardBackground.setColorFilter(backgroundColor, PorterDuff.Mode.MULTIPLY); colorTagCard.setBackgroundDrawable(colorTagCardBackground); colorTagClearButton.getDrawable().setColorFilter(secondaryColor, PorterDuff.Mode.MULTIPLY); colorTagTextView.setTextColor(primaryColor); colorTagTextView.setText("#" + hexColor); }
From source file:com.mk4droid.IMC_Activities.FActivity_TabHost.java
private LinearLayout ActivateColorize(LinearLayout ll, String text, Drawable dr) { // text//from w w w . j a v a2s .co m TextView v = (TextView) ll.findViewWithTag("tv"); v.setText(text); v.setTextSize(10); v.setTextColor(Color.BLACK); //v.setTextColor(Color.WHITE); v.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL); //dr.setColorFilter(0xFF888888, android.graphics.PorterDuff.Mode.MULTIPLY); dr.setColorFilter(resources.getColor(R.color.orange), android.graphics.PorterDuff.Mode.SRC_ATOP); v.setCompoundDrawablesWithIntrinsicBounds(null, dr, null, null); v.setPadding(0, 5, 0, 2); v.setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_tabs_focused)); // hbar View hbar = ll.findViewWithTag("hbar"); //hbar.setBackgroundColor(resources.getColor(R.color.orange)); hbar.setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_orange)); return ll; }
From source file:com.teitsmch.hearthmaker.MainActivity.java
@Override public void onDialogComplete(int type, int deckId, String deckName) { String className = dialogClasses[type]; if (deckName.trim().isEmpty()) { SharedPreferences preferences = getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); deckName = ""; int count = preferences.getInt(className, 0); count++;/* w w w .j a va 2s . c om*/ deckName = String.format("%s %d", className, count); editor.putInt(className, count); editor.apply(); } currentDeckClass = className; setNavigationMenuItem(deckId, deckName); onNavigationItemSelected(mDrawerList.getMenu().findItem(deckId)); //set class icon switch (className) { case "Warrior": getNavigationView().getMenu().findItem(deckId).setIcon(R.drawable.warrior_icon); break; case "Druid": getNavigationView().getMenu().findItem(deckId).setIcon(R.drawable.druid_icon); break; case "Hunter": getNavigationView().getMenu().findItem(deckId).setIcon(R.drawable.hunter_icon); break; case "Mage": getNavigationView().getMenu().findItem(deckId).setIcon(R.drawable.mage_icon); break; case "Paladin": getNavigationView().getMenu().findItem(deckId).setIcon(R.drawable.paladin_icon); break; case "Priest": getNavigationView().getMenu().findItem(deckId).setIcon(R.drawable.priest_icon); break; case "Rogue": getNavigationView().getMenu().findItem(deckId).setIcon(R.drawable.rogue_icon); break; case "Shaman": getNavigationView().getMenu().findItem(deckId).setIcon(R.drawable.shaman_icon); break; case "Warlock": getNavigationView().getMenu().findItem(deckId).setIcon(R.drawable.warlock_icon); break; default: break; } Drawable drawable = getNavigationView().getMenu().findItem(deckId).getIcon(); drawable.mutate(); drawable.setColorFilter(0, PorterDuff.Mode.SRC_ATOP); }
From source file:com.morlunk.mumbleclient.app.PlumbleActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem disconnectButton = menu.findItem(R.id.action_disconnect); disconnectButton.setVisible(mService != null && mService.isSynchronized()); // Color the action bar icons to the primary text color of the theme. int foregroundColor = getSupportActionBar().getThemedContext() .obtainStyledAttributes(new int[] { android.R.attr.textColor }).getColor(0, -1); for (int x = 0; x < menu.size(); x++) { MenuItem item = menu.getItem(x); if (item.getIcon() != null) { Drawable icon = item.getIcon().mutate(); // Mutate the icon so that the color filter is exclusive to the action bar icon.setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY); }//from w w w . ja v a 2 s. c o m } return super.onPrepareOptionsMenu(menu); }
From source file:com.terracom.mumbleclient.app.QRPushToTalkActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { mSettings = Settings.getInstance(this); setTheme(mSettings.getTheme());/* w w w. ja v a 2 s . co m*/ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setStayAwake(mSettings.shouldStayAwake()); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); preferences.registerOnSharedPreferenceChangeListener(this); mDatabase = new QRPushToTalkSQLiteDatabase(this); // TODO add support for cloud storage mDatabase.open(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerList.setOnItemClickListener(this); mDrawerAdapter = new DrawerAdapter(this, this); mDrawerList.setAdapter(mDrawerAdapter); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerClosed(View drawerView) { supportInvalidateOptionsMenu(); } @Override public void onDrawerOpened(View drawerView) { supportInvalidateOptionsMenu(); } }; mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); // Tint logo to theme int iconColor = getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorPrimaryInverse }) .getColor(0, -1); Drawable logo = getResources().getDrawable(R.drawable.ic_home); logo.setColorFilter(iconColor, PorterDuff.Mode.MULTIPLY); getSupportActionBar().setLogo(logo); mConnectingDialog = new ProgressDialog(this); mConnectingDialog.setIndeterminate(true); mConnectingDialog.setCancelable(true); mConnectingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { try { mService.disconnect(); Toast.makeText(QRPushToTalkActivity.this, R.string.cancelled, Toast.LENGTH_SHORT).show(); } catch (RemoteException e) { e.printStackTrace(); } } }); AlertDialog.Builder dadb = new AlertDialog.Builder(this); dadb.setMessage(R.string.disconnectSure); dadb.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { if (mService != null && mService.isConnected()) mService.disconnect(); loadDrawerFragment(DrawerAdapter.ITEM_FAVOURITES); } catch (RemoteException e) { e.printStackTrace(); } } }); dadb.setNegativeButton(android.R.string.cancel, null); mDisconnectPromptBuilder = dadb; if (savedInstanceState == null) { if (getIntent() != null && getIntent().hasExtra(EXTRA_DRAWER_FRAGMENT)) { loadDrawerFragment(getIntent().getIntExtra(EXTRA_DRAWER_FRAGMENT, DrawerAdapter.ITEM_FAVOURITES)); } else { loadDrawerFragment(DrawerAdapter.ITEM_FAVOURITES); } } // If we're given a Mumble URL to show, open up a server edit fragment. if (getIntent() != null && Intent.ACTION_VIEW.equals(getIntent().getAction())) { String url = getIntent().getDataString(); try { Server server = MumbleURLParser.parseURL(url); // Open a dialog prompting the user to add the Mumble server. Bundle args = new Bundle(); args.putBoolean("save", false); args.putParcelable("server", server); ServerEditFragment fragment = (ServerEditFragment) ServerEditFragment.instantiate(this, ServerEditFragment.class.getName(), args); fragment.show(getSupportFragmentManager(), "url_edit"); } catch (MalformedURLException e) { Toast.makeText(this, getString(R.string.mumble_url_parse_failed), Toast.LENGTH_LONG).show(); e.printStackTrace(); } } if (mSettings.isFirstRun()) showSetupWizard(); }
From source file:com.fa.imaged.activity.DetailActivityV2.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.detail_like: if (detailImageLoaderv2.user_has_liked) { HeartPostTask liker = new HeartPostTask(detailImageLoaderv2, false, 0); liker.execute();//from ww w .jav a 2s .c om try { detailImageLoaderv2 = liker.get(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (!detailImageLoaderv2.user_has_liked) { Drawable myIcon = getResources().getDrawable(R.drawable.ic_like); myIcon.setColorFilter(0, PorterDuff.Mode.SRC_ATOP); detailLikeStatus.setImageDrawable(myIcon); } detailLikeCounts.setText(String.valueOf(detailImageLoaderv2.liker_count)); } else { animatePhotoLike(); HeartPostTask liker = new HeartPostTask(detailImageLoaderv2, true, 0); liker.execute(); try { detailImageLoaderv2 = liker.get(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (detailImageLoaderv2.user_has_liked) { Drawable myIcon = getResources().getDrawable(R.drawable.ic_like); myIcon.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP); detailLikeStatus.setImageDrawable(myIcon); } detailLikeCounts.setText(String.valueOf(detailImageLoaderv2.liker_count)); } break; case R.id.detail_likeCounts: Intent i = new Intent(getBaseContext(), LikersActivity.class); i.putExtra("media_id", detailImageLoaderv2.id); i.putExtra("title", "Likers " + "(" + detailImageLoaderv2.liker_count + ")"); startActivity(i); break; case R.id.detail_share: Intent shareIntent = new Intent(); Uri uri = null; // Create share intent as described above if (!detailImageLoaderv2.video) { Drawable mDrawable = detailImageV2.getDrawable(); Bitmap mBitmap = ((BitmapDrawable) mDrawable).getBitmap(); String path = Images.Media.insertImage(getContentResolver(), mBitmap, detailImageLoaderv2.full_name, detailImageLoaderv2.caption); uri = Uri.parse(path); } else { } shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.putExtra(Intent.EXTRA_TEXT, detailImageLoaderv2.caption + getResources().getString(R.string.share_postby) + detailImageLoaderv2.username); startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.share_to))); break; case R.id.detail_user_pic: viewProfile(this, detailImageLoaderv2); } }
From source file:com.kd.filmstrip.DetailActivityV2.java
@Override public void onClick(View v) { switch (v.getId()) { case R.id.detail_like: if (detailImageLoaderv2.user_has_liked) { HeartPostTask liker = new HeartPostTask(detailImageLoaderv2, false, 0); liker.execute();//from w ww . ja v a 2s .com try { detailImageLoaderv2 = liker.get(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (!detailImageLoaderv2.user_has_liked) { Drawable myIcon = getResources().getDrawable(R.drawable.ic_like); myIcon.setColorFilter(0, PorterDuff.Mode.SRC_ATOP); detailLikeStatus.setImageDrawable(myIcon); } detailLikeCounts.setText(String.valueOf(detailImageLoaderv2.liker_count)); } else { animatePhotoLike(); HeartPostTask liker = new HeartPostTask(detailImageLoaderv2, true, 0); liker.execute(); try { detailImageLoaderv2 = liker.get(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (detailImageLoaderv2.user_has_liked) { Drawable myIcon = getResources().getDrawable(R.drawable.ic_like); myIcon.setColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP); detailLikeStatus.setImageDrawable(myIcon); } detailLikeCounts.setText(String.valueOf(detailImageLoaderv2.liker_count)); } break; case R.id.detail_likeCounts: Intent i = new Intent(getBaseContext(), LikersActivity.class); i.putExtra("media_id", detailImageLoaderv2.id); i.putExtra("title", "Likers " + "(" + detailImageLoaderv2.liker_count + ")"); startActivity(i); break; case R.id.detail_share: Intent shareIntent = new Intent(); Uri uri = null; // Create share intent as described above if (!detailImageLoaderv2.video) { Drawable mDrawable = detailImageV2.getDrawable(); Bitmap mBitmap = ((BitmapDrawable) mDrawable).getBitmap(); String path = Images.Media.insertImage(getContentResolver(), mBitmap, detailImageLoaderv2.full_name, detailImageLoaderv2.caption); uri = Uri.parse(path); } else { } shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.putExtra(Intent.EXTRA_TEXT, detailImageLoaderv2.caption + " Posted by @" + detailImageLoaderv2.username); startActivity(Intent.createChooser(shareIntent, "Share To")); break; case R.id.detail_user_pic: viewProfile(this, detailImageLoaderv2); } }