List of usage examples for android.view View setBackgroundResource
@RemotableViewMethod public void setBackgroundResource(@DrawableRes int resid)
From source file:com.ichi2.anki2.CardBrowser.java
@Override protected void onCreate(Bundle savedInstanceState) { Themes.applyTheme(this); super.onCreate(savedInstanceState); View mainView = getLayoutInflater().inflate(R.layout.card_browser, null); setContentView(mainView);/*from www .j a v a 2 s . co m*/ Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER); mCol = AnkiDroidApp.getCol(); if (mCol == null) { reloadCollection(savedInstanceState); return; } mDeckNames = new HashMap<String, String>(); for (long did : mCol.getDecks().allIds()) { mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did)); } registerExternalStorageListener(); Intent i = getIntent(); mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false); mBackground = Themes.getCardBrowserBackground(); SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO); String sflCustomFont = preferences.getString("browserEditorFont", ""); mPrefFixArabic = preferences.getBoolean("fixArabicText", false); Resources res = getResources(); mOrderByFields = res.getStringArray(R.array.card_browser_order_labels); try { mOrder = CARD_ORDER_NONE; String colOrder = mCol.getConf().getString("sortType"); for (int c = 0; c < fSortTypes.length; ++c) { if (fSortTypes[c].equals(colOrder)) { mOrder = c; break; } } if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) { mOrder = 0; } mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false); // default to descending for non-text fields if (fSortTypes[mOrder].equals("noteFld")) { mOrderAsc = !mOrderAsc; } } catch (JSONException e) { throw new RuntimeException(e); } mCards = new ArrayList<HashMap<String, String>>(); mCardsListView = (ListView) findViewById(R.id.card_browser_list); mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item, new String[] { "sfld", "deck", "flags" }, new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont); mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object arg1, String text) { if (view.getId() == R.id.card_item) { int which = BACKGROUND_NORMAL; if (text.equals("1")) { which = BACKGROUND_SUSPENDED; } else if (text.equals("2")) { which = BACKGROUND_MARKED; } else if (text.equals("3")) { which = BACKGROUND_MARKED_SUSPENDED; } view.setBackgroundResource(mBackground[which]); return true; } else if (view.getId() == R.id.card_deck && text.length() > 0) { view.setVisibility(View.VISIBLE); } return false; } }); mCardsListView.setAdapter(mCardsAdapter); mCardsListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent editCard = new Intent(CardBrowser.this, CardEditor.class); editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT); mPositionInCardsList = position; long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id")); sCardBrowserCard = mCol.getCard(cardId); startActivityForResult(editCard, EDIT_CARD); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT); } } }); registerForContextMenu(mCardsListView); mSearchEditText = (EditText) findViewById(R.id.card_browser_search); mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { onSearch(); return true; } return false; } }); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button); mSearchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSearch(); } }); mSearchTerms = ""; if (mWholeCollection) { mRestrictOnDeck = ""; setTitle(res.getString(R.string.card_browser_all_decks)); } else { try { String deckName = mCol.getDecks().current().getString("name"); mRestrictOnDeck = "deck:'" + deckName + "' "; setTitle(deckName); } catch (JSONException e) { throw new RuntimeException(e); } } mSelectedTags = new HashSet<String>(); if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) { searchCards(); } }
From source file:com.hichinaschool.flashcards.anki.CardBrowser.java
@Override protected void onCreate(Bundle savedInstanceState) { Themes.applyTheme(this); super.onCreate(savedInstanceState); View mainView = getLayoutInflater().inflate(R.layout.card_browser, null); setContentView(mainView);/* w w w. j a v a 2 s . co m*/ Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER); mCol = AnkiDroidApp.getCol(); if (mCol == null) { reloadCollection(savedInstanceState); return; } mDeckNames = new HashMap<String, String>(); for (long did : mCol.getDecks().allIds()) { mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did)); } registerExternalStorageListener(); Intent i = getIntent(); mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false); mBackground = Themes.getCardBrowserBackground(); SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO); String sflCustomFont = preferences.getString("browserEditorFont", ""); mPrefFixArabic = preferences.getBoolean("fixArabicText", false); Resources res = getResources(); mOrderByFields = res.getStringArray(R.array.card_browser_order_labels); try { mOrder = CARD_ORDER_NONE; String colOrder = mCol.getConf().getString("sortType"); for (int c = 0; c < fSortTypes.length; ++c) { if (fSortTypes[c].equals(colOrder)) { mOrder = c; break; } } if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) { mOrder = 0; } mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false); // default to descending for non-text fields if (fSortTypes[mOrder].equals("noteFld")) { mOrderAsc = !mOrderAsc; } } catch (JSONException e) { throw new RuntimeException(e); } mCards = new ArrayList<HashMap<String, String>>(); mCardsListView = (ListView) findViewById(R.id.card_browser_list); mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item, new String[] { "sfld", "deck", "flags" }, new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont); mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object arg1, String text) { if (view.getId() == R.id.card_item) { int which = BACKGROUND_NORMAL; if (text.equals("1")) { which = BACKGROUND_SUSPENDED; } else if (text.equals("2")) { which = BACKGROUND_MARKED; } else if (text.equals("3")) { which = BACKGROUND_MARKED_SUSPENDED; } view.setBackgroundResource(mBackground[which]); return true; } else if (view.getId() == R.id.card_deck && text.length() > 0) { view.setVisibility(View.VISIBLE); } return false; } }); mCardsListView.setAdapter(mCardsAdapter); mCardsListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mPositionInCardsList = position; long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id")); sCardBrowserCard = mCol.getCard(cardId); Intent editCard = new Intent(CardBrowser.this, CardEditor.class); editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT); editCard.putExtra(CardEditor.EXTRA_CARD_ID, sCardBrowserCard.getId()); startActivityForResult(editCard, EDIT_CARD); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT); } } }); registerForContextMenu(mCardsListView); mSearchEditText = (EditText) findViewById(R.id.card_browser_search); mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { onSearch(); return true; } return false; } }); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button); mSearchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSearch(); } }); mSearchTerms = ""; if (mWholeCollection) { mRestrictOnDeck = ""; setTitle(res.getString(R.string.card_browser_all_decks)); } else { try { String deckName = mCol.getDecks().current().getString("name"); mRestrictOnDeck = "deck:'" + deckName + "' "; setTitle(deckName); } catch (JSONException e) { throw new RuntimeException(e); } } mSelectedTags = new HashSet<String>(); if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) { searchCards(); } }
From source file:com.nkahoang.screenstandby.Main.java
@SuppressLint("NewApi") @Override//from ww w . j a v a 2 s . com public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); if (!prefs.getBoolean("wizardRun", false)) { Intent i = new Intent(this, com.nkahoang.screenstandby.AutoSettingWizard.class); this.startActivity(i); this.finish(); } animFlippingWholePage = (ObjectAnimator) AnimatorInflater.loadAnimator(Main.this, R.animator.flipping_whole_page); animFlippingRight = (ObjectAnimator) AnimatorInflater.loadAnimator(Main.this, R.animator.flipping_right); animFlippingLeft = (ObjectAnimator) AnimatorInflater.loadAnimator(Main.this, R.animator.flipping_left); animFlippingBack = (ObjectAnimator) AnimatorInflater.loadAnimator(Main.this, R.animator.flipping_back); animFlippingBackFromLeft = (ObjectAnimator) AnimatorInflater.loadAnimator(Main.this, R.animator.flipping_back_from_left); animZoomingOut = (AnimatorSet) AnimatorInflater.loadAnimator(Main.this, R.animator.zoomout); animZoomingIn = (AnimatorSet) AnimatorInflater.loadAnimator(Main.this, R.animator.zoomin); Thread.setDefaultUncaughtExceptionHandler(new ExceptionHandler(this)); setContentView(useMetro ? R.layout.activity_main : R.layout.activity_main_alt); View rootView = this.findViewById(R.id.rootView); animFlippingWholePage.setTarget(rootView); if (!useMetro) animFlippingWholePage.setDuration(0); if (android.os.Build.VERSION.SDK_INT >= 11) { rootView.setPivotX(0); rootView.setPivotY(0); } AnimatorProxy.wrap(rootView).setPivotX(0); AnimatorProxy.wrap(rootView).setPivotY(0); mPager = (ViewPager) findViewById(R.id.mainpager); mPagerAdapter = new MainPagerAdapter(this.getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); final TextView txtTitle = ((TextView) this.findViewById(R.id.txtTitle)); txtTitle.setTypeface(useMetro ? typefaceLight : typeface); final Button txtTitleNext = ((Button) this.findViewById(R.id.txtTitleNex)); txtTitleNext.setTypeface(typefaceLight); txtTitleNext.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mPager.getCurrentItem() < (NUM_PAGES - 1)) { mPager.setCurrentItem(mPager.getCurrentItem() + 1); } } }); final View indicator1 = Main.this.findViewById(R.id.indicator1); final View indicator2 = Main.this.findViewById(R.id.indicator2); final View indicator3 = Main.this.findViewById(R.id.indicator3); mPager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageScrollStateChanged(int arg0) { // TODO Auto-generated method stub } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // TODO Auto-generated method stub } @Override public void onPageSelected(int arg0) { txtTitle.setText(mPagerAdapter.getPageTitle(arg0)); txtTitleNext.setText(mPagerAdapter.getPageTitle(arg0 + 1)); int selected = useMetro ? R.drawable.circleindicator_selected : R.drawable.barindicator_selected; int normal = useMetro ? R.drawable.circleindicator : R.drawable.barindicator; indicator1.setBackgroundResource(arg0 == 0 ? selected : normal); indicator2.setBackgroundResource(arg0 == 1 ? selected : normal); indicator3.setBackgroundResource(arg0 == 2 ? selected : normal); } }); if (!useMetro) { ((ImageButton) this.findViewById(R.id.btnBackToMain)).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mPager.setCurrentItem(0); } }); } ImageButton btnOverflows = (ImageButton) this.findViewById(R.id.btnOverflows); btnOverflows.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Main.this.openOptionsMenu(); } }); ImageButton btnSettings = (ImageButton) this.findViewById(R.id.btnSettings); btnSettings.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { openSettings(); } }); ImageButton btnVideoClip = (ImageButton) this.findViewById(R.id.btnVidClip); btnVideoClip.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { openVideoClip(); } }); ImageButton btnTroubleshooting = (ImageButton) this.findViewById(R.id.btntroubleshooting); btnTroubleshooting.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { animFlippingWholePage.start(); animFlippingWholePage.removeAllListeners(); animFlippingWholePage.addListener(new AnimatorListener() { @Override public void onAnimationCancel(Animator arg0) { } @Override public void onAnimationEnd(Animator arg0) { Intent intent = new Intent(Main.this, TroubleshootingActivity.class); startActivity(intent); animFlippingWholePage.reverse(); } @Override public void onAnimationRepeat(Animator arg0) { } @Override public void onAnimationStart(Animator arg0) { } }); } }); /* if (!ChangeLogHandler.IsChangeLogRead(this)) { ChangeLogHandler.ShowChangelog(this); } */ //warning(); }
From source file:com.nit.vicky.CardBrowser.java
@Override protected void onCreate(Bundle savedInstanceState) { Themes.applyTheme(this); super.onCreate(savedInstanceState); View mainView = getLayoutInflater().inflate(R.layout.card_browser, null); setContentView(mainView);/*w w w. java 2 s .com*/ Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER); mCol = AnkiDroidApp.getCol(); if (mCol == null) { reloadCollection(savedInstanceState); return; } mDeckNames = new HashMap<String, String>(); for (long did : mCol.getDecks().allIds()) { mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did)); } registerExternalStorageListener(); Intent i = getIntent(); mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false); mBackground = Themes.getCardBrowserBackground(); SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext()); int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO); String sflCustomFont = preferences.getString("browserEditorFont", ""); mPrefFixArabic = preferences.getBoolean("fixArabicText", false); Resources res = getResources(); mOrderByFields = res.getStringArray(R.array.card_browser_order_labels); try { mOrder = CARD_ORDER_NONE; String colOrder = mCol.getConf().getString("sortType"); for (int c = 0; c < fSortTypes.length; ++c) { if (fSortTypes[c].equals(colOrder)) { mOrder = c; break; } } if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) { mOrder = 0; } mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false); // default to descending for non-text fields if (fSortTypes[mOrder].equals("noteFld")) { mOrderAsc = !mOrderAsc; } } catch (JSONException e) { throw new RuntimeException(e); } mCards = new ArrayList<HashMap<String, String>>(); mCardsListView = (ListView) findViewById(R.id.card_browser_list); mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item, new String[] { "word", "sfld", "deck", "flags" }, new int[] { R.id.card_word, R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont); mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object arg1, String text) { if (view.getId() == R.id.card_item) { int which = BACKGROUND_NORMAL; if (text.equals("1")) { which = BACKGROUND_SUSPENDED; } else if (text.equals("2")) { which = BACKGROUND_MARKED; } else if (text.equals("3")) { which = BACKGROUND_MARKED_SUSPENDED; } view.setBackgroundResource(mBackground[which]); return true; } else if (view.getId() == R.id.card_deck && text.length() > 0) { view.setVisibility(View.VISIBLE); } return false; } }); //mCardsListView.setAdapter(mCardsAdapter); mCardsListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { mPositionInCardsList = position; long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id")); sCardBrowserCard = mCol.getCard(cardId); Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class); //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT); editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId()); startActivityForResult(editCard, EDIT_CARD); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT); } } }); registerForContextMenu(mCardsListView); mCardsGridView = (StaggeredGridView) findViewById(R.id.card_browser_gridview); mCardsGridView.setAdapter(mGridAdapter); mCardsGridView.setOnItemClickListener(new StaggeredGridView.OnItemClickListener() { @Override public void onItemClick(StaggeredGridView parent, View view, int position, long id) { mPositionInCardsList = position; long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id")); sCardBrowserCard = mCol.getCard(cardId); Intent editCard = new Intent(CardBrowser.this, MultimediaCardEditorActivity.class); //editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT); editCard.putExtra(MultimediaCardEditorActivity.EXTRA_CARD_ID, sCardBrowserCard.getId()); startActivityForResult(editCard, EDIT_CARD); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT); } String imgURL = getImgURL(sCardBrowserCard); Toast.makeText(CardBrowser.this, imgURL, Toast.LENGTH_LONG).show(); } }); mSearchEditText = (EditText) findViewById(R.id.card_browser_search); mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { onSearch(); return true; } return false; } }); getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button); mSearchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onSearch(); } }); mSearchTerms = ""; if (mWholeCollection) { mRestrictOnDeck = ""; setTitle(res.getString(R.string.card_browser_all_decks)); } else { try { String deckName = mCol.getDecks().current().getString("name"); mRestrictOnDeck = "deck:'" + deckName + "' "; setTitle(deckName); } catch (JSONException e) { throw new RuntimeException(e); } } mSelectedTags = new HashSet<String>(); if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) { searchCards(); } }
From source file:com.android.mail.ui.ConversationListFragment.java
/** * Used with SwipeableListView to change conv_list backgrounds to work around shadow elevation * issues causing and overdraw problems due to static backgrounds. * * @param view/*from w w w . ja v a 2 s. c om*/ * @param scrollState */ @Override public void onScrollStateChanged(final AbsListView view, final int scrollState) { mListView.onScrollStateChanged(view, scrollState); final View rootView = getView(); // It seems that the list view is reading the scroll state, but the onCreateView has not // yet finished and the root view is null, so check that if (rootView != null) { // If not scrolling, assign default background - white for tablet, transparent for phone if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { rootView.setBackgroundColor(mDefaultListBackgroundColor); // Otherwise, list is scrolling, so remove background (corresponds to 0 input) } else { rootView.setBackgroundResource(0); } } }
From source file:com.android.mail.browse.ConversationItemView.java
@SuppressWarnings("deprecation") @Override// w ww.j av a 2 s .c o m public void setTranslationX(float translationX) { super.setTranslationX(translationX); // When a list item is being swiped or animated, ensure that the hosting view has a // background color set. We only enable the background during the X-translation effect to // reduce overdraw during normal list scrolling. final View parent = (View) getParent(); if (parent == null) { LogUtils.w(LOG_TAG, "CIV.setTranslationX null ConversationItemView parent x=%s", translationX); } if (parent instanceof SwipeableConversationItemView) { if (translationX != 0f) { parent.setBackgroundResource(R.color.swiped_bg_color); } else { parent.setBackgroundDrawable(null); } } }
From source file:no.digipost.android.gui.MainContentActivity.java
private void setDrawerListeners() { drawerList.setOnItemClickListener(new ListView.OnItemClickListener() { @Override/*w w w . ja va 2 s . c o m*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (account != null && position == (numberOfFolders + ApplicationConstants.numberOfStaticFolders)) { showCreateEditDialog(position, false); } else if (editDrawerMode) { showCreateEditDialog(position, true); } else { selectItem(position); } } }); drawerList.setOnItemLongClickListener(new ListView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { editDrawerMode = !editDrawerMode; if (editDrawerMode) { drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN); } else { drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); } updateUI(false); return true; } }); drawerList.setOnItemDragNDropListener(new DragNDropListView.OnItemDragNDropListener() { @Override public void onItemDrag(DragNDropListView parent, View view, int position, long id) { view.setBackgroundResource(R.drawable.main_drawer_hover); } @Override public void onItemDrop(DragNDropListView parent, View view, int startPosition, int endPosition, long id) { moveFolderFrom(startPosition, endPosition); } }); }
From source file:com.xabber.android.ui.adapter.ChatMessageAdapter.java
private void setUpMessageBalloonBackground(View messageBalloon, ColorStateList darkColorStateList, int lightBackgroundId) { if (SettingsManager.interfaceTheme() == SettingsManager.InterfaceTheme.dark) { final Drawable originalBackgroundDrawable = messageBalloon.getBackground(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { originalBackgroundDrawable.setTintList(darkColorStateList); } else {/*from w w w .j a v a2 s .c o m*/ Drawable wrapDrawable = DrawableCompat.wrap(originalBackgroundDrawable); DrawableCompat.setTintList(wrapDrawable, darkColorStateList); int pL = messageBalloon.getPaddingLeft(); int pT = messageBalloon.getPaddingTop(); int pR = messageBalloon.getPaddingRight(); int pB = messageBalloon.getPaddingBottom(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { messageBalloon.setBackground(wrapDrawable); } else { messageBalloon.setBackgroundDrawable(wrapDrawable); } messageBalloon.setPadding(pL, pT, pR, pB); } } else { int pL = messageBalloon.getPaddingLeft(); int pT = messageBalloon.getPaddingTop(); int pR = messageBalloon.getPaddingRight(); int pB = messageBalloon.getPaddingBottom(); messageBalloon.setBackgroundResource(lightBackgroundId); messageBalloon.getBackground().setLevel(AccountManager.getInstance().getColorLevel(account)); messageBalloon.setPadding(pL, pT, pR, pB); } }
From source file:com.openerp.addons.messages.Message.java
public void setupListView(List<OEListViewRows> message_list) { // Destroying pre-loaded instance and going to create new one lstview = null;/*ww w. java 2s . c o m*/ // Fetching required messages for listview by filtering of requrement if (list != null && list.size() <= 0) { list = message_list;// getMessages(message_list); } else { rootView.findViewById(R.id.messageSyncWaiter).setVisibility(View.GONE); rootView.findViewById(R.id.txvMessageAllReadMessage).setVisibility(View.GONE); } // Handling List View controls and keys String[] from = new String[] { "subject|type", "body", "starred", "author_id|email_from", "date", "model|type" }; int[] to = new int[] { R.id.txvMessageSubject, R.id.txvMessageBody, R.id.imgMessageStarred, R.id.txvMessageFrom, R.id.txvMessageDate, R.id.txvMessageTag }; // Creating instance for listAdapter listAdapter = new OEListViewAdapter(scope.context(), R.layout.message_listview_items, list, from, to, db, true, new int[] { R.drawable.message_listview_bg_toread_selector, R.drawable.message_listview_bg_tonotread_selector }, "to_read"); // Telling adapter to clean HTML text for key value listAdapter.cleanHtmlToTextOn("body"); listAdapter.cleanDate("date", scope.User().getTimezone()); // Setting callback handler for boolean field value change. listAdapter.setBooleanEventOperation("starred", R.drawable.ic_action_starred, R.drawable.ic_action_unstarred, updateStarred); listAdapter.addViewListener(new OEListViewOnCreateListener() { @Override public View listViewOnCreateListener(int position, View row_view, OEListViewRows row_data) { String model_name = row_data.getRow_data().get("model").toString(); String model = model_name; String res_id = row_data.getRow_data().get("res_id").toString(); if (model_name.equals("false")) { model_name = capitalizeString(row_data.getRow_data().get("type").toString()); } else { String[] model_parts = TextUtils.split(model_name, "\\."); HashSet unique_parts = new HashSet(Arrays.asList(model_parts)); model_name = capitalizeString(TextUtils.join(" ", unique_parts.toArray())); } TextView msgTag = (TextView) row_view.findViewById(R.id.txvMessageTag); int tag_color = 0; if (message_model_colors.containsKey(model_name)) { tag_color = message_model_colors.get(model_name); } else { tag_color = Color.parseColor(tag_colors[tag_color_count]); message_model_colors.put(model_name, tag_color); tag_color_count++; if (tag_color_count > tag_colors.length) { tag_color_count = 0; } } if (model.equals("mail.group")) { if (UserGroups.group_names.containsKey("group_" + res_id)) { model_name = UserGroups.group_names.get("group_" + res_id); tag_color = UserGroups.menu_color.get("group_" + res_id); } } msgTag.setBackgroundColor(tag_color); msgTag.setText(model_name); TextView txvSubject = (TextView) row_view.findViewById(R.id.txvMessageSubject); TextView txvAuthor = (TextView) row_view.findViewById(R.id.txvMessageFrom); if (row_data.getRow_data().get("to_read").toString().equals("false")) { txvSubject.setTypeface(null, Typeface.NORMAL); txvSubject.setTextColor(Color.BLACK); txvAuthor.setTypeface(null, Typeface.NORMAL); txvAuthor.setTextColor(Color.BLACK); } else { txvSubject.setTypeface(null, Typeface.BOLD); txvSubject.setTextColor(Color.parseColor("#414141")); txvAuthor.setTypeface(null, Typeface.BOLD); txvAuthor.setTextColor(Color.parseColor("#414141")); } return row_view; } }); // Creating instance for listview control lstview = (ListView) rootView.findViewById(R.id.lstMessages); // Providing adapter to listview scope.context().runOnUiThread(new Runnable() { @Override public void run() { lstview.setAdapter(listAdapter); } }); // Setting listview choice mode to multiple model lstview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); // Seeting item long click listern to activate action mode. lstview.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View view, int index, long arg3) { // TODO Auto-generated method stub OEListViewRows data = (OEListViewRows) lstview.getAdapter().getItem(index); Toast.makeText(scope.context(), data.getRow_id() + " id clicked", Toast.LENGTH_LONG).show(); view.setSelected(true); if (mActionMode != null) { return false; } // Start the CAB using the ActionMode.Callback defined above mActionMode = scope.context().startActionMode(mActionModeCallback); selectedCounter++; view.setBackgroundResource(R.drawable.listitem_pressed); // lstview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); return true; } }); // Setting multi choice selection listener lstview.setMultiChoiceModeListener(new MultiChoiceModeListener() { HashMap<Integer, Boolean> selectedList = new HashMap<Integer, Boolean>(); @Override public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) { // Here you can do something when items are // selected/de-selected, // such as update the title in the CAB selectedList.put(position, checked); if (checked) { selectedCounter++; } else { selectedCounter--; } if (selectedCounter != 0) { mode.setTitle(selectedCounter + ""); } } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { // Respond to clicks on the actions in the CAB HashMap<Integer, Integer> msg_pos = new HashMap<Integer, Integer>(); OEDialog dialog = null; switch (item.getItemId()) { case R.id.menu_message_mark_unread_selected: Log.e("menu_message_context", "Mark as Unread"); for (int pos : selectedList.keySet()) { msg_pos.put(list.get(pos).getRow_id(), pos); } readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, false); readunreadoperation.execute((Void) null); mode.finish(); return true; case R.id.menu_message_mark_read_selected: Log.e("menu_message_context", "Mark as Read"); for (int pos : selectedList.keySet()) { msg_pos.put(list.get(pos).getRow_id(), pos); } readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, true); readunreadoperation.execute((Void) null); mode.finish(); return true; case R.id.menu_message_more_move_to_archive_selected: Log.e("menu_message_context", "Archive"); for (int pos : selectedList.keySet()) { msg_pos.put(list.get(pos).getRow_id(), pos); } readunreadoperation = new PerformReadUnreadArchiveOperation(msg_pos, false); readunreadoperation.execute((Void) null); mode.finish(); return true; case R.id.menu_message_more_add_star_selected: for (int pos : selectedList.keySet()) { msg_pos.put(list.get(pos).getRow_id(), pos); } markasTodoTask = new PerformOperation(msg_pos, true); markasTodoTask.execute((Void) null); mode.finish(); return true; case R.id.menu_message_more_remove_star_selected: for (int pos : selectedList.keySet()) { msg_pos.put(list.get(pos).getRow_id(), pos); } markasTodoTask = new PerformOperation(msg_pos, false); markasTodoTask.execute((Void) null); mode.finish(); return true; default: return false; } } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate the menu for the CAB MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.menu_fragment_message_context, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { // Here you can make any necessary updates to the activity when // the CAB is removed. By default, selected items are // deselected/unchecked. /* * Perform Operation on Selected Ids. * * row_ids are list of selected message Ids. */ selectedList.clear(); selectedCounter = 0; lstview.clearChoices(); } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { // Here you can perform updates to the CAB due to // an invalidate() request return false; } }); lstview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int index, long id) { // TODO Auto-generated method stub MessageDetail messageDetail = new MessageDetail(); Bundle bundle = new Bundle(); bundle.putInt("message_id", list.get(index).getRow_id()); bundle.putInt("position", index); messageDetail.setArguments(bundle); scope.context().fragmentHandler.setBackStack(true, null); scope.context().fragmentHandler.replaceFragmnet(messageDetail); if (!type.equals("archive")) { list.remove(index); } listAdapter.refresh(list); } }); // Getting Pull To Refresh Attacher from Main Activity mPullToRefreshAttacher = scope.context().getPullToRefreshAttacher(); // Set the Refreshable View to be the ListView and the refresh listener // to be this. if (mPullToRefreshAttacher != null & lstview != null) { mPullToRefreshAttacher.setRefreshableView(lstview, this); } }
From source file:com.groksolutions.grok.mobile.annotation.AnnotationListFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); _adapter = new ArrayAdapter<CharSequence>(getActivity(), R.layout.annotation_item, R.id.txt_annotation_message) { @Override//from w w w .j a v a 2s .c om public View getView(int position, View convertView, ViewGroup parent) { View view = super.getView(position, convertView, parent); if (_annotations != null && !_annotations.isEmpty()) { Pair<Annotation, Boolean> pair = _annotations.get(position); Annotation annotation = pair.first; Boolean showDate = pair.second; if (annotation != null) { // Update Annotation footer TextView footerTxt = (TextView) view.findViewById(R.id.txt_annotation_footer); footerTxt.setText(formatAnnotationFooter(annotation, showDate)); // Show or Hide "delete" button if the annotation was created using the // current device. The user can only delete annotations he creates View deleteBtn = view.findViewById(R.id.btn_annotation_delete); if (HTMITApplication.getDeviceId().equals(annotation.getDevice())) { deleteBtn.setVisibility(View.VISIBLE); } else { deleteBtn.setVisibility(View.GONE); } View listItemFrame = view.findViewById(R.id.layout_list_item); TextView dateTxt = (TextView) view.findViewById(R.id.txt_annotation_date); View addBtn = view.findViewById(R.id.btn_annotation_add); // Only show the "+" button on the last annotation for the specific time. if (_annotations.size() == 1) { // If we only have one annotation then show "+" button addBtn.setVisibility(View.VISIBLE); } else if (position < _annotations.size() - 1) { Annotation next = _annotations.get(position + 1).first; if (next.getTimestamp() != annotation.getTimestamp()) { // Last annotation for time. Show "add" button addBtn.setVisibility(View.VISIBLE); } else { // Only show "add" button for the last annotation at specific time addBtn.setVisibility(View.GONE); } } else { // Last annotation. Show "add" button addBtn.setVisibility(View.VISIBLE); } // Only show the annotation date before the first annotation for the specific time. if (_annotations.size() == 1) { // If we only have one annotation then show annotation date dateTxt.setText(_dateTimeFormat.format(new Date(annotation.getTimestamp()))); dateTxt.setVisibility(View.VISIBLE); listItemFrame.setBackgroundResource(R.drawable.annotation_background_first_item); } else if (position == 0) { // First annotation in List. Show annotation date dateTxt.setText(_dateTimeFormat.format(new Date(annotation.getTimestamp()))); dateTxt.setVisibility(View.VISIBLE); listItemFrame.setBackgroundResource(R.drawable.annotation_background_first_item); } else { Annotation prev = _annotations.get(position - 1).first; if (prev.getTimestamp() != annotation.getTimestamp()) { dateTxt.setText(_dateTimeFormat.format(new Date(annotation.getTimestamp()))); dateTxt.setVisibility(View.VISIBLE); listItemFrame.setBackgroundResource(R.drawable.annotation_background_first_item); } else { dateTxt.setVisibility(View.GONE); listItemFrame.setBackgroundResource(R.drawable.annotation_background); } } } } return view; } }; setListAdapter(_adapter); }