List of usage examples for android.graphics.drawable BitmapDrawable setGravity
public void setGravity(int gravity)
From source file:org.smssecure.smssecure.preferences.ColorPreference.java
private static void setColorViewValue(View view, int color, boolean selected) { if (view instanceof ImageView) { ImageView imageView = (ImageView) view; Resources res = imageView.getContext().getResources(); Drawable currentDrawable = imageView.getDrawable(); GradientDrawable colorChoiceDrawable; if (currentDrawable instanceof GradientDrawable) { // Reuse drawable colorChoiceDrawable = (GradientDrawable) currentDrawable; } else {//from w w w . j a v a 2s. c om colorChoiceDrawable = new GradientDrawable(); colorChoiceDrawable.setShape(GradientDrawable.OVAL); } // Set stroke to dark version of color // int darkenedColor = Color.rgb( // Color.red(color) * 192 / 256, // Color.green(color) * 192 / 256, // Color.blue(color) * 192 / 256); colorChoiceDrawable.setColor(color); // colorChoiceDrawable.setStroke((int) TypedValue.applyDimension( // TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics()), darkenedColor); Drawable drawable = colorChoiceDrawable; if (selected) { BitmapDrawable checkmark = (BitmapDrawable) res.getDrawable(R.drawable.check); checkmark.setGravity(Gravity.CENTER); drawable = new LayerDrawable(new Drawable[] { colorChoiceDrawable, checkmark }); } imageView.setImageDrawable(drawable); } else if (view instanceof TextView) { ((TextView) view).setTextColor(color); } }
From source file:com.tingtingapps.securesms.preferences.ColorPreference.java
private static void setColorViewValue(View view, int color, boolean selected) { if (view instanceof ImageView) { ImageView imageView = (ImageView) view; Resources res = imageView.getContext().getResources(); Drawable currentDrawable = imageView.getDrawable(); GradientDrawable colorChoiceDrawable; if (currentDrawable instanceof GradientDrawable) { // Reuse drawable colorChoiceDrawable = (GradientDrawable) currentDrawable; } else {/* w ww . j a v a2 s. c o m*/ colorChoiceDrawable = new GradientDrawable(); colorChoiceDrawable.setShape(GradientDrawable.OVAL); } // Set stroke to dark version of color // int darkenedColor = Color.rgb( // Color.red(color) * 192 / 256, // Color.green(color) * 192 / 256, // Color.blue(color) * 192 / 256); colorChoiceDrawable.setColor(color); // colorChoiceDrawable.setStroke((int) TypedValue.applyDimension( // TypedValue.COMPLEX_UNIT_DIP, 2, res.getDisplayMetrics()), darkenedColor); Drawable drawable = colorChoiceDrawable; if (selected) { BitmapDrawable checkmark = (BitmapDrawable) res .getDrawable(com.tingtingapps.securesms.R.drawable.check); checkmark.setGravity(Gravity.CENTER); drawable = new LayerDrawable(new Drawable[] { colorChoiceDrawable, checkmark }); } imageView.setImageDrawable(drawable); } else if (view instanceof TextView) { ((TextView) view).setTextColor(color); } }
From source file:com.github.jobs.ui.fragment.JobDetailsFragment.java
private void setLogoBackground() { if (mJob.getCompanyLogo() == null) { return;//from www .j a va 2 s. c om } CallbackBitmapObserver rawBitmapObserver = new CallbackBitmapObserver( new CallbackBitmapObserver.BitmapCallback() { @Override public boolean stillNeedsUrl(String uri) { return true; } @Override public void receiveBitmap(String uri, Bitmap bitmap) { if (bitmap == null) { return; } BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap); bitmapDrawable.setAlpha(50); bitmapDrawable.setGravity(Gravity.CENTER); mBackground.setImageDrawable(bitmapDrawable); } }, mJob.getCompanyLogo(), new Handler()); BitmapHelper.getInstance().registerBitmapObserver(getActivity(), rawBitmapObserver); }
From source file:com.mycelium.wallet.activity.modern.ModernMain.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); _mbwManager = MbwManager.getInstance(this); mViewPager = new ViewPager(this); mViewPager.setId(R.id.pager);/* ww w .ja va 2s. c o m*/ setContentView(mViewPager); ActionBar bar = getSupportActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayOptions(1, ActionBar.DISPLAY_SHOW_TITLE); // Load the theme-background (usually happens in styles.xml) but use a lower // pixel format, this saves around 10MB of allocated memory // persist the loaded Bitmap in the context of mbw-manager and reuse it every time this activity gets created try { BitmapDrawable background = (BitmapDrawable) _mbwManager.getBackgroundObjectsCache() .get("mainBackground", new Callable<BitmapDrawable>() { @Override public BitmapDrawable call() throws Exception { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.RGB_565; Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.background_witherrors_dimmed, options); BitmapDrawable drawable = new BitmapDrawable(getResources(), background); drawable.setGravity(Gravity.CENTER); return drawable; } }); getWindow().setBackgroundDrawable(background); } catch (ExecutionException ignore) { } mTabsAdapter = new TabsAdapter(this, mViewPager, _mbwManager); mAccountsTab = bar.newTab(); mTabsAdapter.addTab(mAccountsTab.setText(getString(R.string.tab_accounts)), AccountsFragment.class, null); mBalanceTab = bar.newTab(); mTabsAdapter.addTab(mBalanceTab.setText(getString(R.string.tab_balance)), BalanceMasterFragment.class, null); mTabsAdapter.addTab(bar.newTab().setText(getString(R.string.tab_transactions)), TransactionHistoryFragment.class, null); final Bundle addressBookConfig = new Bundle(); addressBookConfig.putBoolean(AddressBookFragment.SELECT_ONLY, false); mTabsAdapter.addTab(bar.newTab().setText(getString(R.string.tab_addresses)), AddressBookFragment.class, addressBookConfig); bar.selectTab(mBalanceTab); _toaster = new Toaster(this); ChangeLog cl = new DarkThemeChangeLog(this); if (cl.isFirstRun() && cl.getChangeLog(false).size() > 0 && !cl.isFirstRunEver()) { cl.getLogDialog().show(); } checkTorState(); if (savedInstanceState != null) { _lastSync = savedInstanceState.getLong(LAST_SYNC, 0); _isAppStart = savedInstanceState.getBoolean(APP_START, true); } if (_isAppStart) { _mbwManager.getVersionManager().showFeatureWarningIfNeeded(this, Feature.APP_START); checkGapBug(); _isAppStart = false; } }
From source file:com.mobicage.rogerthat.plugins.friends.ServiceActionMenuActivity.java
private void populateScreen(final ServiceMenu menu) { menuBrandingHash = menu.branding;/* w ww. java 2s. c o m*/ final FriendsPlugin friendsPlugin = mService.getPlugin(FriendsPlugin.class); final MessagingPlugin messagingPlugin = mService.getPlugin(MessagingPlugin.class); final FriendStore store = friendsPlugin.getStore(); List<Cell> usedCells = new ArrayList<Cell>(); if (page == 0) { addAboutHandler(usedCells, menu.aboutLabel); addHistoryHandler(usedCells, store, menu.messagesLabel); addCallHandler(menu, usedCells, menu.callLabel); if (CloudConstants.isYSAAA()) { addScanHandler(menu, usedCells, null); } else { addShareHandler(menu, usedCells, menu.shareLabel); } } boolean[] rows = new boolean[] { false, false, false }; if (page == 0) rows[0] = true; for (final ServiceMenuItem item : menu.itemList) { rows[(int) item.coords[1]] = true; final Cell cell = cells[(int) item.coords[0]][(int) item.coords[1]]; View.OnClickListener onClickListener = new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { pressMenuItem(menu, messagingPlugin, store, item); } }; ((View) cell.icon.getParent()).setOnClickListener(onClickListener); cell.icon.setImageBitmap(BitmapFactory.decodeByteArray(item.icon, 0, item.icon.length)); cell.icon.setVisibility(View.VISIBLE); cell.label.setText(item.label); cell.label.setVisibility(View.VISIBLE); usedCells.add(cell); } for (int i = 2; i >= 0; i--) { if (rows[i]) break; tableRows[i].setVisibility(View.GONE); } boolean showBranded = false; boolean useDarkScheme = false; Integer menuItemColor = null; if (menu.branding != null) { try { BrandingMgr brandingMgr = messagingPlugin.getBrandingMgr(); Friend friend = store.getExistingFriend(email); if (brandingMgr.isBrandingAvailable(menu.branding)) { BrandingResult br = brandingMgr.prepareBranding(menu.branding, friend, false); WebSettings settings = branding.getSettings(); settings.setJavaScriptEnabled(false); settings.setBlockNetworkImage(false); branding.setVisibility(View.VISIBLE); branding.setVerticalScrollBarEnabled(false); final int displayWidth = UIUtils.getDisplayWidth(this); final int calculatedHeight = BrandingMgr.calculateHeight(br, displayWidth); final long start = System.currentTimeMillis(); branding.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() { @Override public boolean onPreDraw() { int height = branding.getMeasuredHeight(); if (height > calculatedHeight * 90 / 100 || System.currentTimeMillis() - start > 3000) { if (calculatedHeight > 0) { setBrandingHeight(height); } else { mService.postDelayedOnUIHandler(new SafeRunnable() { @Override protected void safeRun() throws Exception { setBrandingHeight(branding.getMeasuredHeight()); } }, 100); } branding.getViewTreeObserver().removeOnPreDrawListener(this); } return false; } }); branding.loadUrl("file://" + br.file.getAbsolutePath()); if (br.color != null) { branding.setBackgroundColor(br.color); activity.setBackgroundColor(br.color); } if (br.scheme == ColorScheme.dark) { for (Cell cell : usedCells) { cell.label.setTextColor(darkSchemeTextColor); cell.label.setShadowLayer(2, 1, 1, Color.BLACK); } useDarkScheme = true; } menuItemColor = br.menuItemColor; final ImageView watermarkView = (ImageView) findViewById(R.id.watermark); if (br.watermark != null) { BitmapDrawable watermark = new BitmapDrawable(getResources(), BitmapFactory.decodeFile(br.watermark.getAbsolutePath())); watermark.setGravity(Gravity.BOTTOM | Gravity.RIGHT); watermarkView.setImageDrawable(watermark); final LayoutParams layoutParams = watermarkView.getLayoutParams(); layoutParams.width = layoutParams.height = displayWidth; } else { watermarkView.setImageDrawable(null); } showBranded = true; } else { friend.actionMenu = menu; friend.actionMenu.items = menu.itemList.toArray(new ServiceMenuItemTO[] {}); brandingMgr.queue(friend); } } catch (BrandingFailureException e) { L.bug("Could not display service action menu with branding.", e); } } if (!showBranded) { setNavigationBarVisible(AppConstants.SHOW_NAV_HEADER); setNavigationBarTitle(menu.name); title.setVisibility(View.GONE); title.setText(menu.name); } for (final Cell cell : usedCells) { final View p = (View) cell.icon.getParent(); final Drawable d = getResources().getDrawable( useDarkScheme ? R.drawable.mc_smi_background_light : R.drawable.mc_smi_background_dark); p.setBackgroundDrawable(d); } if (menuItemColor == null) menuItemColor = Color.parseColor("#646464"); for (Cell cell : new Cell[] { cells[0][0], cells[1][0], cells[2][0], cells[3][0] }) cell.faIcon.setTextColor(menuItemColor); if (menu.maxPage > 0) { for (int i = 0; i <= menu.maxPage; i++) { ImageView bolleke = (ImageView) getLayoutInflater().inflate(R.layout.page, pages, false); if (page == i) { if (useDarkScheme) { bolleke.setImageResource(R.drawable.current_page_dark); } else { bolleke.setImageResource(R.drawable.current_page_light); } } else { if (useDarkScheme) { bolleke.setImageResource(R.drawable.other_page_dark); } else { bolleke.setImageResource(R.drawable.other_page_light); } } pages.addView(bolleke); } pages.setVisibility(View.VISIBLE); } final int leftPage = page - 1; final int rightPage = page + 1; final String service = email; Slider instance = new Slider(this, this, page == menu.maxPage ? null : new Slider.Swiper() { @Override public Intent onSwipe() { return new Intent(ServiceActionMenuActivity.this, ServiceActionMenuActivity.class) .putExtra(SERVICE_EMAIL, service).putExtra(MENU_PAGE, rightPage); } }, page == 0 ? null : new Slider.Swiper() { @Override public Intent onSwipe() { return new Intent(ServiceActionMenuActivity.this, ServiceActionMenuActivity.class) .putExtra(SERVICE_EMAIL, service).putExtra(MENU_PAGE, leftPage); } }); mGestureScanner = new GestureDetector(this, instance); }
From source file:org.brandroid.openmanager.activities.OpenExplorer.java
private void changePath(OpenPath path, Boolean addToStack, Boolean force) { try {//from w w w . j av a 2 s . c o m //if(mLastPath != null && !mLastPath.equals(path) && mLastPath instanceof OpenNetworkPath) // ((OpenNetworkPath)mLastPath).disconnect(); } catch (Exception e) { Logger.LogError("Couldn't disconnect while changing paths.", e); } toggleBookmarks(false); if (path == null) path = mLastPath; if (path == null) return; if (mLastPath == null && getDirContentFragment(false) != null) mLastPath = getDirContentFragment(false).getPath(); if (!(mLastPath instanceof OpenFile) || !(path instanceof OpenFile)) force = true; onClipboardUpdate(); //if(!BEFORE_HONEYCOMB) force = true; //if(!force) //if(!addToStack && path.getPath().equals("/")) return; //if(mLastPath.getPath().equalsIgnoreCase(path.getPath())) return; int newView = getSetting(path, "view", 0); if (!CAN_DO_CAROUSEL && newView == VIEW_CAROUSEL) { setSetting(path, "view", VIEW_LIST); newView = VIEW_LIST; } //boolean isNew = !mLastPath.equals(path); int oldView = getSetting(mLastPath, "view", 0); if (path instanceof OpenNetworkPath) { if (mLogViewEnabled) showLogFrag(mLogFragment, false); } else setViewVisibility(false, false, R.id.frag_log); final ImageView icon = (ImageView) findViewById(R.id.title_icon); if (icon != null) ThumbnailCreator.setThumbnail(icon, path, 96, 96, new OnUpdateImageListener() { public void updateImage(Bitmap b) { BitmapDrawable d = new BitmapDrawable(getResources(), b); d.setGravity(Gravity.CENTER); icon.setImageDrawable(d); } }); //mFileManager.setShowHiddenFiles(getSetting(path, "hide", false)); //setViewMode(newView); //if(!BEFORE_HONEYCOMB && Build.VERSION.SDK_INT < 14 && newView == VIEW_CAROUSEL) { //setViewVisibility(true, false, R.id.content_pager_frame); //setViewVisibility(false, false, R.id.content_frag); List<OpenPath> familyTree = path.getAncestors(false); if (addToStack) { int bsCount = fragmentManager.getBackStackEntryCount(); String last = null; if (bsCount > 0) { BackStackEntry entry = fragmentManager.getBackStackEntryAt(bsCount - 1); last = entry.getBreadCrumbTitle() != null ? entry.getBreadCrumbTitle().toString() : ""; Logger.LogVerbose("Changing " + last + " to " + path.getPath() + "? " + (last.equalsIgnoreCase(path.getPath()) ? "No" : "Yes")); } else Logger.LogVerbose("First changePath to " + path.getPath()); if (mStateReady && (last == null || !last.equalsIgnoreCase(path.getPath()))) { fragmentManager.beginTransaction().setBreadCrumbTitle(path.getPath()).addToBackStack("path") .commitAllowingStateLoss(); } } final OpenFragment cf = (CAN_DO_CAROUSEL && newView == VIEW_CAROUSEL) ? new CarouselFragment(path) : ContentFragment.getInstance(path, newView, getSupportFragmentManager()); if (force || addToStack || path.requiresThread()) { int common = 0; boolean removed = false; for (int i = mViewPagerAdapter.getCount() - 1; i >= 0; i--) { OpenFragment f = mViewPagerAdapter.getItem(i); if (f == null || !(f instanceof ContentFragment)) continue; if (!familyTree.contains(((ContentFragment) f).getPath())) { mViewPagerAdapter.remove(i); removed = true; } else common++; } if (force) { mViewPagerAdapter.remove(cf); mViewPagerAdapter.add(cf); removed = true; //notifyPager(); } //mViewPagerAdapter.notifyDataSetChanged(); //mViewPagerAdapter.removeOfType(ContentFragment.class); //mViewPagerAdapter = new ArrayPagerAdapter(fragmentManager); int iNonContentPages = mViewPagerAdapter.getCount() - common; if (common < 0) mViewPagerAdapter.add(cf); else mViewPagerAdapter.add(common, cf); OpenPath tmp = path.getParent(); while (tmp != null) { Logger.LogDebug("Adding Parent: " + tmp.getPath()); try { if (common > 0) if (tmp.getPath() .equals(((ContentFragment) mViewPagerAdapter.getItem(common - 1)).getPath())) break; } catch (Exception e) { Logger.LogError("I don't trust this!", e); } try { mViewPagerAdapter.add(common, ContentFragment.getInstance(tmp, getSetting(tmp, "view", newView), getSupportFragmentManager())); } catch (Exception e) { Logger.LogError("Downloads?", e); } tmp = tmp.getParent(); } //Logger.LogVerbose("All Titles: [" + getPagerTitles() + "] Paths: [" + getFragmentPaths(mViewPagerAdapter.getFragments()) + "]"); //mViewPagerAdapter = newAdapter; //mViewPagerAdapter.getCount() - iNonContentPages - 1; setViewPageAdapter(mViewPagerAdapter, true); // TODO: I really want to set this to false, as it will speed up the app considerably //mViewPagerAdapter.notifyDataSetChanged(); //index -= iNonContentPages; //int index = mViewPagerAdapter.getLastPositionOfType(ContentFragment.class); int index = mViewPagerAdapter.getItemPosition(cf); setCurrentItem(index, addToStack); //if(cf instanceof ContentFragment) ((ContentFragment)cf).refreshData(null, false); //updatePagerTitle(index); } else { OpenPath commonBase = null; for (int i = mViewPagerAdapter.getCount() - 1; i >= 0; i--) { if (!(mViewPagerAdapter.getItem(i) instanceof ContentFragment)) continue; ContentFragment c = (ContentFragment) mViewPagerAdapter.getItem(i); if (path.getPath().startsWith(c.getPath().getPath())) continue; commonBase = ((ContentFragment) mViewPagerAdapter.remove(i)).getPath(); } int depth = 0; if (commonBase != null) depth = commonBase.getDepth() - 1; OpenPath tmp = path; while (tmp != null && (commonBase == null || !tmp.equals(commonBase))) { mViewPagerAdapter.add(depth, ContentFragment.getInstance(path, getSetting(path, "view", newView), getSupportFragmentManager())); tmp = tmp.getParent(); if (tmp == null) break; } setViewPageAdapter(mViewPagerAdapter, true); //mViewPager.setAdapter(mViewPagerAdapter); setCurrentItem(path.getDepth() - 1, false); //getDirContentFragment(false).refreshData(null, false); } //} //refreshContent(); if (!BEFORE_HONEYCOMB) invalidateOptionsMenu(); /*if(content instanceof ContentFragment) ((ContentFragment)content).setSettings( SortType.DATE_DESC, getSetting(path, "thumbs", true), getSetting(path, "hide", true) );*/ if (path instanceof OpenFile && !path.requiresThread()) new PeekAtGrandKidsTask().execute((OpenFile) path); //ft.replace(R.id.content_frag, content); //ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); Logger.LogDebug("Setting path to " + path.getPath()); mLastPath = path; }