List of usage examples for android.view View setBackgroundColor
@RemotableViewMethod public void setBackgroundColor(@ColorInt int color)
From source file:de.baumann.hhsmoodle.data_schedule.Schedule_Fragment.java
private void setScheduleList() { final int line = sharedPref.getInt("getLine", 1); //display data final int layoutstyle = R.layout.list_item_schedule; int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.att_notes, R.id.textView_create_notes }; String[] column = new String[] { "schedule_title", "schedule_content", "schedule_attachment", "schedule_creation" }; final Cursor row = db.fetchAllData(); adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) { @Override//w ww. j av a 2 s. c om public View getView(final int position, View convertView, ViewGroup parent) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content")); final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon")); final String schedule_attachment = row2 .getString(row2.getColumnIndexOrThrow("schedule_attachment")); final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation")); final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id")); View v = super.getView(position, convertView, parent); ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes); if (position == line) { v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.colorAccent_trans)); } else { v.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.color_trans)); } if (schedule_title.equals(getActivity().getString(R.string.schedule_weekend)) || schedule_title.equals(getActivity().getString(R.string.schedule_def_title))) { sharedPref.edit().putString("hour_" + schedule_id, "false").apply(); } else { sharedPref.edit().putString("hour_" + schedule_id, "true").apply(); } Subjects_helper.switchIcon(getActivity(), schedule_icon, "schedule_color", iv_icon); iv_icon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString(R.string.subjects_color_red), R.drawable.circle_red), new helper_main.Item(getString(R.string.subjects_color_pink), R.drawable.circle_pink), new helper_main.Item(getString(R.string.subjects_color_purple), R.drawable.circle_purple), new helper_main.Item(getString(R.string.subjects_color_blue), R.drawable.circle_blue), new helper_main.Item(getString(R.string.subjects_color_teal), R.drawable.circle_teal), new helper_main.Item(getString(R.string.subjects_color_green), R.drawable.circle_green), new helper_main.Item(getString(R.string.subjects_color_lime), R.drawable.circle_lime), new helper_main.Item(getString(R.string.subjects_color_yellow), R.drawable.circle_yellow), new helper_main.Item(getString(R.string.subjects_color_orange), R.drawable.circle_orange), new helper_main.Item(getString(R.string.subjects_color_brown), R.drawable.circle_brown), new helper_main.Item(getString(R.string.subjects_color_grey), R.drawable.circle_grey), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v.findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { if (item == 0) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "1", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 1) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "2", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 2) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "3", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 3) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "4", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 4) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "5", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 5) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "6", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 6) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "7", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 7) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "8", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 8) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "9", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 9) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "10", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } else if (item == 10) { db.update(Integer.parseInt(_id), schedule_title, schedule_content, "11", schedule_attachment, schedule_creation, schedule_id); setScheduleList(); } } }).show(); } }); return v; } }; //display data by filter final String note_search = sharedPref.getString("filter_scheduleBY", "schedule_title"); sharedPref.edit().putString("filter_scheduleBY", "schedule_title").apply(); filter.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s.toString()); } }); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return db.fetchDataByFilter(constraint.toString(), note_search); } }); lv.setAdapter(adapter); //onClick function lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final CharSequence[] options = { getString(R.string.schedule_todo), getString(R.string.schedule_notes) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.schedule_todo))) { sharedPref.edit().putString("filter_todo_subject", schedule_title).apply(); new Handler().postDelayed(new Runnable() { public void run() { helper_main.switchToActivity(getActivity(), Popup_todo.class, false); } }, 200); } if (options[item].equals(getString(R.string.schedule_notes))) { sharedPref.edit().putString("filter_note_subject", schedule_title).apply(); new Handler().postDelayed(new Runnable() { public void run() { helper_main.switchToActivity(getActivity(), Popup_note.class, false); } }, 200); } } }).show(); } }); lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Cursor row2 = (Cursor) lv.getItemAtPosition(position); final String _id = row2.getString(row2.getColumnIndexOrThrow("_id")); final String schedule_title = row2.getString(row2.getColumnIndexOrThrow("schedule_title")); final String schedule_content = row2.getString(row2.getColumnIndexOrThrow("schedule_content")); final String schedule_icon = row2.getString(row2.getColumnIndexOrThrow("schedule_icon")); final String schedule_attachment = row2 .getString(row2.getColumnIndexOrThrow("schedule_attachment")); final String schedule_creation = row2.getString(row2.getColumnIndexOrThrow("schedule_creation")); final String schedule_id = row2.getString(row2.getColumnIndexOrThrow("schedule_id")); final CharSequence[] options = { getString(R.string.number_edit_entry), getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_menu), getString(R.string.bookmark_createNote), getString(R.string.count_create), getString(R.string.bookmark_createEvent) }; new AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @SuppressWarnings("ConstantConditions") @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals(getString(R.string.number_edit_entry))) { final CharSequence[] options = { getString(R.string.schedule_fromSubjectList), getString(R.string.todo_from_new) }; new AlertDialog.Builder(getActivity()).setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }).setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item] .equals(getString(R.string.schedule_fromSubjectList))) { sharedPref.edit().putString("edit_yes", "true") .putInt("scroll", Integer.parseInt(schedule_id)) .putString("handleSubjectCreation", schedule_creation) .putString("handleSubject_id", schedule_id) .putString("handle_id", _id).apply(); helper_main.switchToActivity(getActivity(), Popup_subjects.class, false); } if (options[item].equals(getString(R.string.todo_from_new))) { LayoutInflater inflater = getActivity().getLayoutInflater(); final ViewGroup nullParent = null; View dialogView = inflater .inflate(R.layout.dialog_edit_subject, nullParent); final EditText titleInput = (EditText) dialogView .findViewById(R.id.subject_title_); titleInput.setSelection(titleInput.getText().length()); titleInput.setText(schedule_title); final EditText teacherInput = (EditText) dialogView .findViewById(R.id.subject_teacher); teacherInput.setText(schedule_content); final EditText roomInput = (EditText) dialogView .findViewById(R.id.subject_room); roomInput.setText(schedule_attachment); helper_main.showKeyboard(getActivity(), titleInput); final ImageButton be = (ImageButton) dialogView .findViewById(R.id.imageButtonPri); assert be != null; Subjects_helper.switchIcon(getActivity(), schedule_icon, "schedule_color", be); be.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { final helper_main.Item[] items = { new helper_main.Item(getString( R.string.subjects_color_red), R.drawable.circle_red), new helper_main.Item(getString( R.string.subjects_color_pink), R.drawable.circle_pink), new helper_main.Item(getString( R.string.subjects_color_purple), R.drawable.circle_purple), new helper_main.Item(getString( R.string.subjects_color_blue), R.drawable.circle_blue), new helper_main.Item(getString( R.string.subjects_color_teal), R.drawable.circle_teal), new helper_main.Item(getString( R.string.subjects_color_green), R.drawable.circle_green), new helper_main.Item(getString( R.string.subjects_color_lime), R.drawable.circle_lime), new helper_main.Item(getString( R.string.subjects_color_yellow), R.drawable.circle_yellow), new helper_main.Item(getString( R.string.subjects_color_orange), R.drawable.circle_orange), new helper_main.Item(getString( R.string.subjects_color_brown), R.drawable.circle_brown), new helper_main.Item(getString( R.string.subjects_color_grey), R.drawable.circle_grey), }; ListAdapter adapter = new ArrayAdapter<helper_main.Item>( getActivity(), android.R.layout.select_dialog_item, android.R.id.text1, items) { @NonNull public View getView(int position, View convertView, @NonNull ViewGroup parent) { //Use super class to create the View View v = super.getView(position, convertView, parent); TextView tv = (TextView) v .findViewById(android.R.id.text1); tv.setTextSize(18); tv.setCompoundDrawablesWithIntrinsicBounds( items[position].icon, 0, 0, 0); //Add margin between image and text (support various screen densities) int dp5 = (int) (24 * getActivity().getResources() .getDisplayMetrics().density + 0.5f); tv.setCompoundDrawablePadding(dp5); return v; } }; new android.app.AlertDialog.Builder(getActivity()) .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int whichButton) { dialog.cancel(); } }) .setAdapter(adapter, new DialogInterface.OnClickListener() { public void onClick( DialogInterface dialog, int item) { if (item == 0) { be.setImageResource( R.drawable.circle_red); sharedPref.edit() .putString( "schedule_color", "1") .apply(); } else if (item == 1) { be.setImageResource( R.drawable.circle_pink); sharedPref.edit() .putString( "schedule_color", "2") .apply(); } else if (item == 2) { be.setImageResource( R.drawable.circle_purple); sharedPref.edit() .putString( "schedule_color", "3") .apply(); } else if (item == 3) { be.setImageResource( R.drawable.circle_blue); sharedPref.edit() .putString( "schedule_color", "4") .apply(); } else if (item == 4) { be.setImageResource( R.drawable.circle_teal); sharedPref.edit() .putString( "schedule_color", "5") .apply(); } else if (item == 5) { be.setImageResource( R.drawable.circle_green); sharedPref.edit() .putString( "schedule_color", "6") .apply(); } else if (item == 6) { be.setImageResource( R.drawable.circle_lime); sharedPref.edit() .putString( "schedule_color", "7") .apply(); } else if (item == 7) { be.setImageResource( R.drawable.circle_yellow); sharedPref.edit() .putString( "schedule_color", "8") .apply(); } else if (item == 8) { be.setImageResource( R.drawable.circle_orange); sharedPref.edit() .putString( "schedule_color", "9") .apply(); } else if (item == 9) { be.setImageResource( R.drawable.circle_brown); sharedPref.edit() .putString( "schedule_color", "10") .apply(); } else if (item == 10) { be.setImageResource( R.drawable.circle_grey); sharedPref.edit() .putString( "schedule_color", "11") .apply(); } } }) .show(); } }); android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder( getActivity()); builder.setTitle(R.string.subjects_edit); builder.setView(dialogView); builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String inputTitle = titleInput.getText() .toString().trim(); String inputTeacher = teacherInput.getText() .toString().trim(); String inputRoom = roomInput.getText() .toString().trim(); db.update(Integer.parseInt(_id), inputTitle, inputTeacher, sharedPref.getString( "schedule_color", ""), inputRoom, schedule_creation, schedule_id); dialog.dismiss(); setScheduleList(); lv.setSelection( Integer.parseInt(schedule_id) - 1); Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show(); } }); builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); final android.support.v7.app.AlertDialog dialog2 = builder .create(); dialog2.show(); } } }).show(); } if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) { Snackbar snackbar = Snackbar .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG) .setAction(R.string.toast_yes, new View.OnClickListener() { @Override public void onClick(View view) { db.update(Integer.parseInt(_id), getString(R.string.schedule_def_teacher), getString(R.string.schedule_def_teacher), "11", getString(R.string.schedule_def_teacher), schedule_creation, schedule_id); setScheduleList(); lv.setSelection(Integer.parseInt(schedule_id) - 1); } }); snackbar.show(); } if (options[item].equals(getString(R.string.todo_menu))) { Todo_helper.newTodo(getActivity(), schedule_title, schedule_content, getActivity().getString(R.string.note_content)); } if (options[item].equals(getString(R.string.count_create))) { Count_helper.newCount(getActivity(), schedule_title, schedule_content, getActivity().getString(R.string.note_content), false); } if (options[item].equals(getString(R.string.bookmark_createEvent))) { helper_main.createCalendarEvent(getActivity(), schedule_title, schedule_content); } if (options[item].equals(getString(R.string.bookmark_createNote))) { Notes_helper.newNote(getActivity(), schedule_title, schedule_content, "", "", "", ""); } } }).show(); return true; } }); scrollToNow(); }
From source file:com.philliphsu.bottomsheetpickers.time.numberpad.NumberPadTimePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); mInputField = (TextView) view.findViewById(R.id.input_time); mNumpad = (NumberPadTimePicker) view.findViewById(R.id.number_grid); final FloatingActionButton fab = (FloatingActionButton) mNumpad.findViewById(R.id.fab); fab.setOnClickListener(new View.OnClickListener() { @Override//from w w w . j a va 2 s . co m public void onClick(View v) { if (!mNumpad.checkTimeValid()) return; onTimeSet(mNumpad, mNumpad.getHour(), mNumpad.getMinute()); } }); if (!mThemeSetAtRuntime) { mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark); } mNumpad.setOnInputChangeListener(this); mNumpad.insertDigits(mInputtedDigits); // TOneverDO: before mNumpad.setOnInputChangeListener(this); mNumpad.setAmPmState(mAmPmState); // Prepare colors int accentColor = Utils.getThemeAccentColor(getContext()); int lightGray = ContextCompat.getColor(getContext(), R.color.light_gray); int darkGray = ContextCompat.getColor(getContext(), R.color.dark_gray); int white = ContextCompat.getColor(getContext(), android.R.color.white); // Set background color of entire view view.setBackgroundColor(mThemeDark ? darkGray : white); TextView inputTime = (TextView) view.findViewById(R.id.input_time); inputTime.setBackgroundColor(mThemeDark ? lightGray : accentColor); inputTime.setTextColor(ContextCompat.getColor(getContext(), android.R.color.white)); mNumpad.setTheme(getContext()/*DO NOT GIVE THE APPLICATION CONTEXT, OR ELSE THE NUMPAD CAN'T GET THE CORRECT ACCENT COLOR*/, mThemeDark); return view; }
From source file:de.mkrtchyan.recoverytools.FlashFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_rashr, container, false); /** Check if device uses unified builds */ if (Common.getBooleanPref(mContext, Constants.PREF_NAME, Constants.PREF_KEY_SHOW_UNIFIED) && mDevice.isUnified() && (!mDevice.isStockRecoverySupported() || !mDevice.isCwmRecoverySupported() || !mDevice.isTwrpRecoverySupported() || !mDevice.isPhilzRecoverySupported())) { showUnifiedBuildsDialog();/*from www. ja v a2 s .co m*/ } optimizeLayout(root); root.setBackgroundColor(RashrActivity.isDark ? getResources().getColor(R.color.background_material_dark) : getResources().getColor(R.color.background_material_light)); if (Common.getBooleanPref(mContext, Constants.PREF_NAME, Constants.PREF_KEY_CHECK_UPDATES) && RashrActivity.FirstSession) { catchUpdates(true); RashrActivity.FirstSession = false; } return root; }
From source file:com.ncode.android.apps.schedo.ui.EventsFragment.java
@Override public void bindCollectionItemView(Context context, View view, int groupId, int indexInGroup, int dataIndex, Object tag) {// w w w. j av a 2 s. c om if (mCursor == null || !mCursor.moveToPosition(dataIndex)) { LOGW(TAG, "Can't bind collection view item, dataIndex=" + dataIndex + (mCursor == null ? ": cursor is null" : ": bad data index.")); return; } final String eventId = mCursor.getString(EventsQuery.EVENT_ID); if (eventId == null) { return; } // first, read event info from cursor and put it in convenience variables final String eventTitle = mCursor.getString(EventsQuery.TITLE); final String speakerNames = mCursor.getString(EventsQuery.SPEAKER_NAMES); final String eventAbstract = mCursor.getString(EventsQuery.ABSTRACT); final String[] eventDays = mCursor.getString(EventsQuery.EVENT_DAYS).split(","); final long eventStart = Long.valueOf(eventDays[0]).longValue(); final long eventEnd = Long.valueOf(eventDays[eventDays.length / 2]).longValue(); //final String roomName = mCursor.getString(EventsQuery.ROOM_NAME); int eventColor = mCursor.getInt(EventsQuery.COLOR); eventColor = eventColor == 0 ? getResources().getColor(R.color.default_event_color) : eventColor; int darkEventColor = 0; final String snippet = mIsSearchCursor ? mCursor.getString(EventsQuery.SNIPPET) : null; final Spannable styledSnippet = mIsSearchCursor ? buildStyledSnippet(snippet) : null; final boolean starred = mCursor.getInt(EventsQuery.IN_MY_SCHEDULE) != 0; final String[] tags = mCursor.getString(EventsQuery.TAGS).split(","); // now let's compute a few pieces of information from the data, which we will use // later to decide what to render where final boolean hasLivestream = !TextUtils.isEmpty(mCursor.getString(EventsQuery.LIVESTREAM_URL)); final long now = UIUtils.getCurrentTime(context); final boolean happeningNow = now >= eventStart && now <= eventEnd; // text that says "LIVE" if event is live, or empty if event is not live final String liveNowText = hasLivestream ? " " + UIUtils.getLiveBadgeText(context, eventStart, eventEnd) : ""; // get reference to all the views in the layout we will need final TextView titleView = (TextView) view.findViewById(R.id.session_title); final TextView subtitleView = (TextView) view.findViewById(R.id.session_subtitle); final TextView shortSubtitleView = (TextView) view.findViewById(R.id.session_subtitle_short); final TextView snippetView = (TextView) view.findViewById(R.id.session_snippet); final TextView abstractView = (TextView) view.findViewById(R.id.session_abstract); final TextView categoryView = (TextView) view.findViewById(R.id.session_category); final View eventTargetView = view.findViewById(R.id.session_target); if (eventColor == 0) { // use default eventColor = mDefaultEventColor; } if (mNoTrackBranding) { eventColor = getResources().getColor(R.color.no_track_branding_session_color); } darkEventColor = UIUtils.scaleSessionColorToDefaultBG(eventColor); ImageView photoView = (ImageView) view.findViewById(R.id.session_photo_colored); if (photoView != null) { if (!mPreloader.isDimensSet()) { final ImageView finalPhotoView = photoView; photoView.post(new Runnable() { @Override public void run() { mPreloader.setDimens(finalPhotoView.getWidth(), finalPhotoView.getHeight()); } }); } // colored photoView .setColorFilter(mNoTrackBranding ? new PorterDuffColorFilter( getResources().getColor(R.color.no_track_branding_session_tile_overlay), PorterDuff.Mode.SRC_ATOP) : UIUtils.makeSessionImageScrimColorFilter(darkEventColor)); } else { photoView = (ImageView) view.findViewById(R.id.session_photo); } ViewCompat.setTransitionName(photoView, "photo_" + eventId); // when we load a photo, it will fade in from transparent so the // background of the container must be the event color to avoid a white flash ViewParent parent = photoView.getParent(); if (parent != null && parent instanceof View) { ((View) parent).setBackgroundColor(darkEventColor); } else { photoView.setBackgroundColor(darkEventColor); } String photo = mCursor.getString(EventsQuery.PHOTO_URL); if (!TextUtils.isEmpty(photo)) { mImageLoader.loadImage(photo, photoView, true /*crop*/); } else { // cleaning the (potentially) recycled photoView, in case this event has no photo: photoView.setImageDrawable(null); } // render title titleView.setText(eventTitle == null ? "?" : eventTitle); // render subtitle into either the subtitle view, or the short subtitle view, as available if (subtitleView != null) { subtitleView.setText(UIUtils.formatEventSubtitle(eventStart, eventEnd, mBuffer, context) + liveNowText); } else if (shortSubtitleView != null) { shortSubtitleView.setText( UIUtils.formatEventSubtitle(eventStart, eventEnd, mBuffer, context, true) + liveNowText); } // render category if (categoryView != null) { TagMetadata.Tag groupTag = mTagMetadata.getGroupTag(tags, Config.Tags.EVENT_GROUPING_TAG_CATEGORY); if (groupTag != null && !Config.Tags.EVENTS.equals(groupTag.getId())) { categoryView.setText(groupTag.getName()); categoryView.setVisibility(View.VISIBLE); } else { categoryView.setVisibility(View.GONE); } } // if a snippet view is available, render the event snippet there. if (snippetView != null) { if (mIsSearchCursor) { // render the search snippet into the snippet view snippetView.setText(styledSnippet); } else { // render speaker names and abstracts into the snippet view mBuffer.setLength(0); if (!TextUtils.isEmpty(speakerNames)) { mBuffer.append(speakerNames).append(". "); } if (!TextUtils.isEmpty(eventAbstract)) { mBuffer.append(eventAbstract); } snippetView.setText(mBuffer.toString()); } } if (abstractView != null && !mIsSearchCursor) { // render speaker names and abstracts into the abstract view mBuffer.setLength(0); if (!TextUtils.isEmpty(speakerNames)) { mBuffer.append(speakerNames).append("\n\n"); } if (!TextUtils.isEmpty(eventAbstract)) { mBuffer.append(eventAbstract); } abstractView.setText(mBuffer.toString()); } // show or hide the "in my schedule" indicator view.findViewById(R.id.indicator_in_schedule).setVisibility(starred ? View.VISIBLE : View.INVISIBLE); // if we are in condensed mode and this card is the hero card (big card at the top // of the screen), set up the message card if necessary. if (!useExpandedMode() && groupId == HERO_GROUP_ID) { // this is the hero view, so we might want to show a message card final boolean cardShown = setupMessageCard(view); // if this is the wide hero layout, show or hide the card or the event abstract // view, as appropriate (they are mutually exclusive). final View cardContainer = view.findViewById(R.id.message_card_container_wide); final View abstractContainer = view.findViewById(R.id.session_abstract); if (cardContainer != null && abstractContainer != null) { cardContainer.setVisibility(cardShown ? View.VISIBLE : View.GONE); abstractContainer.setVisibility(cardShown ? View.GONE : View.VISIBLE); abstractContainer.setBackgroundColor(darkEventColor); } } // if this event is live right now, display the "LIVE NOW" icon on top of it View liveNowBadge = view.findViewById(R.id.live_now_badge); if (liveNowBadge != null) { liveNowBadge.setVisibility(happeningNow && hasLivestream ? View.VISIBLE : View.GONE); } // if this view is clicked, open the event details view final View finalPhotoView = photoView; eventTargetView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCallbacks.onEventSelected(eventId, finalPhotoView); } }); // animate this card if (dataIndex > mMaxDataIndexAnimated) { mMaxDataIndexAnimated = dataIndex; } }
From source file:com.google.samples.apps.iosched.ui.SessionsFragment.java
@Override public void bindCollectionItemView(Context context, View view, int groupId, int indexInGroup, int dataIndex, Object tag) {/*w w w . j a v a 2 s .com*/ if (mCursor == null || !mCursor.moveToPosition(dataIndex)) { LOGW(TAG, "Can't bind collection view item, dataIndex=" + dataIndex + (mCursor == null ? ": cursor is null" : ": bad data index.")); return; } final String sessionId = mCursor.getString(SessionsQuery.SESSION_ID); if (sessionId == null) { return; } // first, read session info from cursor and put it in convenience variables final String sessionTitle = mCursor.getString(SessionsQuery.TITLE); final String speakerNames = mCursor.getString(SessionsQuery.SPEAKER_NAMES); final String sessionAbstract = mCursor.getString(SessionsQuery.ABSTRACT); final long sessionStart = mCursor.getLong(SessionsQuery.SESSION_START); final long sessionEnd = mCursor.getLong(SessionsQuery.SESSION_END); final String roomName = mCursor.getString(SessionsQuery.ROOM_NAME); int sessionColor = mCursor.getInt(SessionsQuery.COLOR); sessionColor = sessionColor == 0 ? getResources().getColor(R.color.default_session_color) : sessionColor; int darkSessionColor = 0; final String snippet = mIsSearchCursor ? mCursor.getString(SessionsQuery.SNIPPET) : null; final Spannable styledSnippet = mIsSearchCursor ? buildStyledSnippet(snippet) : null; final boolean starred = mCursor.getInt(SessionsQuery.IN_MY_SCHEDULE) != 0; final String[] tags = mCursor.getString(SessionsQuery.TAGS).split(","); // now let's compute a few pieces of information from the data, which we will use // later to decide what to render where final boolean hasLivestream = !TextUtils.isEmpty(mCursor.getString(SessionsQuery.LIVESTREAM_URL)); final long now = UIUtils.getCurrentTime(context); final boolean happeningNow = now >= sessionStart && now <= sessionEnd; // text that says "LIVE" if session is live, or empty if session is not live final String liveNowText = hasLivestream ? " " + UIUtils.getLiveBadgeText(context, sessionStart, sessionEnd) : ""; // get reference to all the views in the layout we will need final TextView titleView = (TextView) view.findViewById(R.id.session_title); final TextView subtitleView = (TextView) view.findViewById(R.id.session_subtitle); final TextView shortSubtitleView = (TextView) view.findViewById(R.id.session_subtitle_short); final TextView snippetView = (TextView) view.findViewById(R.id.session_snippet); final TextView abstractView = (TextView) view.findViewById(R.id.session_abstract); final TextView categoryView = (TextView) view.findViewById(R.id.session_category); final View sessionTargetView = view.findViewById(R.id.session_target); if (sessionColor == 0) { // use default sessionColor = mDefaultSessionColor; } if (mNoTrackBranding) { sessionColor = getResources().getColor(R.color.no_track_branding_session_color); } darkSessionColor = UIUtils.scaleSessionColorToDefaultBG(sessionColor); ImageView photoView = (ImageView) view.findViewById(R.id.session_photo_colored); if (photoView != null) { if (!mPreloader.isDimensSet()) { final ImageView finalPhotoView = photoView; photoView.post(new Runnable() { @Override public void run() { mPreloader.setDimens(finalPhotoView.getWidth(), finalPhotoView.getHeight()); } }); } // colored photoView .setColorFilter(mNoTrackBranding ? new PorterDuffColorFilter( getResources().getColor(R.color.no_track_branding_session_tile_overlay), PorterDuff.Mode.SRC_ATOP) : UIUtils.makeSessionImageScrimColorFilter(darkSessionColor)); } else { photoView = (ImageView) view.findViewById(R.id.session_photo); } ViewCompat.setTransitionName(photoView, "photo_" + sessionId); // when we load a photo, it will fade in from transparent so the // background of the container must be the session color to avoid a white flash ViewParent parent = photoView.getParent(); if (parent != null && parent instanceof View) { ((View) parent).setBackgroundColor(darkSessionColor); } else { photoView.setBackgroundColor(darkSessionColor); } String photo = mCursor.getString(SessionsQuery.PHOTO_URL); if (!TextUtils.isEmpty(photo)) { mImageLoader.loadImage(photo, photoView, true /*crop*/); } else { // cleaning the (potentially) recycled photoView, in case this session has no photo: photoView.setImageDrawable(null); } // render title titleView.setText(sessionTitle == null ? "?" : sessionTitle); // render subtitle into either the subtitle view, or the short subtitle view, as available if (subtitleView != null) { subtitleView.setText(UIUtils.formatSessionSubtitle(sessionStart, sessionEnd, roomName, mBuffer, context) + liveNowText); } else if (shortSubtitleView != null) { shortSubtitleView.setText( UIUtils.formatSessionSubtitle(sessionStart, sessionEnd, roomName, mBuffer, context, true) + liveNowText); } // render category if (categoryView != null) { TagMetadata.Tag groupTag = mTagMetadata.getSessionGroupTag(tags); if (groupTag != null && !Config.Tags.SESSIONS.equals(groupTag.getId())) { categoryView.setText(groupTag.getName()); categoryView.setVisibility(View.VISIBLE); } else { categoryView.setVisibility(View.GONE); } } // if a snippet view is available, render the session snippet there. if (snippetView != null) { if (mIsSearchCursor) { // render the search snippet into the snippet view snippetView.setText(styledSnippet); } else { // render speaker names and abstracts into the snippet view mBuffer.setLength(0); if (!TextUtils.isEmpty(speakerNames)) { mBuffer.append(speakerNames).append(". "); } if (!TextUtils.isEmpty(sessionAbstract)) { mBuffer.append(sessionAbstract); } snippetView.setText(mBuffer.toString()); } } if (abstractView != null && !mIsSearchCursor) { // render speaker names and abstracts into the abstract view mBuffer.setLength(0); if (!TextUtils.isEmpty(speakerNames)) { mBuffer.append(speakerNames).append("\n\n"); } if (!TextUtils.isEmpty(sessionAbstract)) { mBuffer.append(sessionAbstract); } abstractView.setText(mBuffer.toString()); } // show or hide the "in my schedule" indicator view.findViewById(R.id.indicator_in_schedule).setVisibility(starred ? View.VISIBLE : View.INVISIBLE); // if we are in condensed mode and this card is the hero card (big card at the top // of the screen), set up the message card if necessary. if (!useExpandedMode() && groupId == HERO_GROUP_ID) { // this is the hero view, so we might want to show a message card final boolean cardShown = setupMessageCard(view); // if this is the wide hero layout, show or hide the card or the session abstract // view, as appropriate (they are mutually exclusive). final View cardContainer = view.findViewById(R.id.message_card_container_wide); final View abstractContainer = view.findViewById(R.id.session_abstract); if (cardContainer != null && abstractContainer != null) { cardContainer.setVisibility(cardShown ? View.VISIBLE : View.GONE); abstractContainer.setVisibility(cardShown ? View.GONE : View.VISIBLE); abstractContainer.setBackgroundColor(darkSessionColor); } } // if this session is live right now, display the "LIVE NOW" icon on top of it View liveNowBadge = view.findViewById(R.id.live_now_badge); if (liveNowBadge != null) { liveNowBadge.setVisibility(happeningNow && hasLivestream ? View.VISIBLE : View.GONE); } // if this view is clicked, open the session details view final View finalPhotoView = photoView; sessionTargetView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCallbacks.onSessionSelected(sessionId, finalPhotoView); } }); // animate this card if (dataIndex > mMaxDataIndexAnimated) { mMaxDataIndexAnimated = dataIndex; } }
From source file:com.ncode.android.apps.schedo.ui.SessionsFragment.java
@Override public void bindCollectionItemView(Context context, View view, int groupId, int indexInGroup, int dataIndex, Object tag) {//from w w w .j av a2s . c o m if (mCursor == null || !mCursor.moveToPosition(dataIndex)) { LOGW(TAG, "Can't bind collection view item, dataIndex=" + dataIndex + (mCursor == null ? ": cursor is null" : ": bad data index.")); return; } final String sessionId = mCursor.getString(SessionsQuery.SESSION_ID); if (sessionId == null) { return; } // first, read session info from cursor and put it in convenience variables final String sessionTitle = mCursor.getString(SessionsQuery.TITLE); final String speakerNames = mCursor.getString(SessionsQuery.SPEAKER_NAMES); final String sessionAbstract = mCursor.getString(SessionsQuery.ABSTRACT); final long sessionStart = mCursor.getLong(SessionsQuery.SESSION_START); final long sessionEnd = mCursor.getLong(SessionsQuery.SESSION_END); final String roomName = mCursor.getString(SessionsQuery.ROOM_NAME); int sessionColor = mCursor.getInt(SessionsQuery.COLOR); sessionColor = sessionColor == 0 ? getResources().getColor(R.color.default_session_color) : sessionColor; int darkSessionColor = 0; final String snippet = mIsSearchCursor ? mCursor.getString(SessionsQuery.SNIPPET) : null; final Spannable styledSnippet = mIsSearchCursor ? buildStyledSnippet(snippet) : null; final boolean starred = mCursor.getInt(SessionsQuery.IN_MY_SCHEDULE) != 0; final String[] tags = mCursor.getString(SessionsQuery.TAGS).split(","); // now let's compute a few pieces of information from the data, which we will use // later to decide what to render where final boolean hasLivestream = !TextUtils.isEmpty(mCursor.getString(SessionsQuery.LIVESTREAM_URL)); final long now = UIUtils.getCurrentTime(context); final boolean happeningNow = now >= sessionStart && now <= sessionEnd; // text that says "LIVE" if session is live, or empty if session is not live final String liveNowText = hasLivestream ? " " + UIUtils.getLiveBadgeText(context, sessionStart, sessionEnd) : ""; // get reference to all the views in the layout we will need final TextView titleView = (TextView) view.findViewById(R.id.session_title); final TextView subtitleView = (TextView) view.findViewById(R.id.session_subtitle); final TextView shortSubtitleView = (TextView) view.findViewById(R.id.session_subtitle_short); final TextView snippetView = (TextView) view.findViewById(R.id.session_snippet); final TextView abstractView = (TextView) view.findViewById(R.id.session_abstract); final TextView categoryView = (TextView) view.findViewById(R.id.session_category); final View sessionTargetView = view.findViewById(R.id.session_target); if (sessionColor == 0) { // use default sessionColor = mDefaultSessionColor; } if (mNoTrackBranding) { sessionColor = getResources().getColor(R.color.no_track_branding_session_color); } darkSessionColor = UIUtils.scaleSessionColorToDefaultBG(sessionColor); ImageView photoView = (ImageView) view.findViewById(R.id.session_photo_colored); if (photoView != null) { if (!mPreloader.isDimensSet()) { final ImageView finalPhotoView = photoView; photoView.post(new Runnable() { @Override public void run() { mPreloader.setDimens(finalPhotoView.getWidth(), finalPhotoView.getHeight()); } }); } // colored photoView .setColorFilter(mNoTrackBranding ? new PorterDuffColorFilter( getResources().getColor(R.color.no_track_branding_session_tile_overlay), PorterDuff.Mode.SRC_ATOP) : UIUtils.makeSessionImageScrimColorFilter(darkSessionColor)); } else { photoView = (ImageView) view.findViewById(R.id.session_photo); } ViewCompat.setTransitionName(photoView, "photo_" + sessionId); // when we load a photo, it will fade in from transparent so the // background of the container must be the session color to avoid a white flash ViewParent parent = photoView.getParent(); if (parent != null && parent instanceof View) { ((View) parent).setBackgroundColor(darkSessionColor); } else { photoView.setBackgroundColor(darkSessionColor); } String photo = mCursor.getString(SessionsQuery.PHOTO_URL); if (!TextUtils.isEmpty(photo)) { mImageLoader.loadImage(photo, photoView, true /*crop*/); } else { // cleaning the (potentially) recycled photoView, in case this session has no photo: photoView.setImageDrawable(null); } // render title titleView.setText(sessionTitle == null ? "?" : sessionTitle); // render subtitle into either the subtitle view, or the short subtitle view, as available if (subtitleView != null) { subtitleView.setText(UIUtils.formatSessionSubtitle(sessionStart, sessionEnd, roomName, mBuffer, context) + liveNowText); } else if (shortSubtitleView != null) { shortSubtitleView.setText( UIUtils.formatSessionSubtitle(sessionStart, sessionEnd, roomName, mBuffer, context, true) + liveNowText); } // render category if (categoryView != null) { TagMetadata.Tag groupTag = mTagMetadata.getGroupTag(tags, Config.Tags.SESSION_GROUPING_TAG_CATEGORY); if (groupTag != null && !Config.Tags.SESSIONS.equals(groupTag.getId())) { categoryView.setText(groupTag.getName()); categoryView.setVisibility(View.VISIBLE); } else { categoryView.setVisibility(View.GONE); } } // if a snippet view is available, render the session snippet there. if (snippetView != null) { if (mIsSearchCursor) { // render the search snippet into the snippet view snippetView.setText(styledSnippet); } else { // render speaker names and abstracts into the snippet view mBuffer.setLength(0); if (!TextUtils.isEmpty(speakerNames)) { mBuffer.append(speakerNames).append(". "); } if (!TextUtils.isEmpty(sessionAbstract)) { mBuffer.append(sessionAbstract); } snippetView.setText(mBuffer.toString()); } } if (abstractView != null && !mIsSearchCursor) { // render speaker names and abstracts into the abstract view mBuffer.setLength(0); if (!TextUtils.isEmpty(speakerNames)) { mBuffer.append(speakerNames).append("\n\n"); } if (!TextUtils.isEmpty(sessionAbstract)) { mBuffer.append(sessionAbstract); } abstractView.setText(mBuffer.toString()); } // show or hide the "in my schedule" indicator view.findViewById(R.id.indicator_in_schedule).setVisibility(starred ? View.VISIBLE : View.INVISIBLE); // if we are in condensed mode and this card is the hero card (big card at the top // of the screen), set up the message card if necessary. if (!useExpandedMode() && groupId == HERO_GROUP_ID) { // this is the hero view, so we might want to show a message card final boolean cardShown = setupMessageCard(view); // if this is the wide hero layout, show or hide the card or the session abstract // view, as appropriate (they are mutually exclusive). final View cardContainer = view.findViewById(R.id.message_card_container_wide); final View abstractContainer = view.findViewById(R.id.session_abstract); if (cardContainer != null && abstractContainer != null) { cardContainer.setVisibility(cardShown ? View.VISIBLE : View.GONE); abstractContainer.setVisibility(cardShown ? View.GONE : View.VISIBLE); abstractContainer.setBackgroundColor(darkSessionColor); } } // if this session is live right now, display the "LIVE NOW" icon on top of it View liveNowBadge = view.findViewById(R.id.live_now_badge); if (liveNowBadge != null) { liveNowBadge.setVisibility(happeningNow && hasLivestream ? View.VISIBLE : View.GONE); } // if this view is clicked, open the session details view final View finalPhotoView = photoView; sessionTargetView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCallbacks.onSessionSelected(sessionId, finalPhotoView); } }); // animate this card if (dataIndex > mMaxDataIndexAnimated) { mMaxDataIndexAnimated = dataIndex; } }
From source file:com.github.vgoliveira.panificadora.MainActivity.java
@Override public boolean onTouch(View view, MotionEvent motionEvent) { byte[] value; value = new byte[] { NO_OPERATION, NOT_PRESSED, NOT_PRESSED, NOT_PRESSED, NOT_PRESSED, NOT_PRESSED, NOT_PRESSED, NOT_PRESSED };// w ww . ja v a2 s . com if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { value[OPERATION] = COMMAND; switch (view.getId()) { case R.id.button_time_more: value[TIME_MORE] = PRESSED; break; case R.id.button_time_less: value[TIME_LESS] = PRESSED; break; case R.id.button_dough_qnt: value[DOUGH_QNT] = PRESSED; break; case R.id.button_options: value[OPTIONS] = PRESSED; break; case R.id.button_color: value[COLOR] = PRESSED; break; case R.id.button_init_stop: value[INIT_STOP] = PRESSED; break; } mService.writeRXCharacteristic(value); view.setBackgroundColor(0xFFFDFBB3); } if (motionEvent.getAction() == MotionEvent.ACTION_UP) { value[OPERATION] = COMMAND; switch (view.getId()) { case R.id.button_time_more: value[TIME_MORE] = NOT_PRESSED; break; case R.id.button_time_less: value[TIME_LESS] = NOT_PRESSED; break; case R.id.button_dough_qnt: value[DOUGH_QNT] = NOT_PRESSED; break; case R.id.button_options: value[OPTIONS] = NOT_PRESSED; break; case R.id.button_color: value[COLOR] = NOT_PRESSED; break; case R.id.button_init_stop: value[INIT_STOP] = NOT_PRESSED; break; } mService.writeRXCharacteristic(value); view.setBackgroundColor(0xFFCAC7C7); } return true; }
From source file:lewa.support.v7.internal.widget.ActionBarContextView.java
public void initForMode(final ActionMode mode) { ///LEWA BEGIN mActionMode = mode;//from www. ja va 2s.co m if (mClose == null) { LayoutInflater inflater = LayoutInflater.from(getContext()); mClose = inflater.inflate(R.layout.action_mode_close_item, this, false); addView(mClose); } else if (mClose.getParent() == null) { addView(mClose); } View closeButton = mClose.findViewById(R.id.action_mode_close_button); closeButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { mode.finish(); } }); closeButton.setBackgroundColor(0); closeButton.setOnTouchListener(new InjectorTouchListener()); closeButton.setPadding(closeButton.getPaddingLeft(), mStatusbarHeight, closeButton.getPaddingRight(), closeButton.getPaddingBottom()); final MenuBuilder menu = (MenuBuilder) mode.getMenu(); if (mActionMenuPresenter != null) { mActionMenuPresenter.dismissPopupMenus(); } ///LEWA BEGIN mSplitActionBar = true; if (mSplitActionBar) { mActionMenuPresenter = new LewaActionMenuPresenter(getContext()); // Set action mode for change style of action mode. ((LewaActionMenuPresenter) mActionMenuPresenter).setActionMode(true); } else { mActionMenuPresenter = new ActionMenuPresenter(getContext()); } ///LEWA END mActionMenuPresenter.setReserveOverflow(true); final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); if (!mSplitActionBar) { menu.addMenuPresenter(mActionMenuPresenter, mPopupContext); mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); mMenuView.setBackgroundDrawable(null); addView(mMenuView, layoutParams); } else { // Allow full screen width in split mode. mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true); // No limit to the item count; use whatever will fit. mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE); // Span the whole width layoutParams.width = LayoutParams.MATCH_PARENT; layoutParams.height = mContentHeight; ///LEWA BEGIN int actionbarHeight = ActionBarPolicy.get(getContext()).getTabContainerHeight(); layoutParams.height = actionbarHeight; ///LEWA END menu.addMenuPresenter(mActionMenuPresenter, mPopupContext); // create menu view in by menu presenter mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); mMenuView.setBackgroundDrawable(mSplitBackground); // LEWA ADD START // Add menu bar into action mode. addActionModeOptionMenu(this, menu, layoutParams); if (true) { } else { mSplitView.addView(mMenuView, layoutParams); } // LEWA ADD END } mAnimateInOnLayout = true; }
From source file:com.ezeeideas.wordjam.BaseGameActivity.java
private void honorTheme() { //honor theme for common elements LinearLayout mainLayout = (LinearLayout) findViewById(R.id.game_main_layout); mainLayout.setBackgroundColor(Themes.getColorFor(Themes.COLOR_BACKGROUND)); View ruleHeader = (View) findViewById(R.id.rule_header); ruleHeader.setBackgroundColor(Themes.getColorFor(Themes.COLOR_LINE_HEADING)); View ruleFooter = (View) findViewById(R.id.rule_footer); ruleFooter.setBackgroundColor(Themes.getColorFor(Themes.COLOR_LINE_HEADING)); View ruleFooter2 = (View) findViewById(R.id.rule_footer2); if (ruleFooter2 != null) { ruleFooter2.setBackgroundColor(Themes.getColorFor(Themes.COLOR_LINE_HEADING)); }//w w w.ja v a2 s .co m //honor theme for game specfic elements doHonorTheme(); }
From source file:edu.stanford.mobisocial.dungbeetle.model.DbObject.java
/** * @param v the view to bind/*from w w w . j a v a 2s.c o m*/ * @param context standard activity context * @param c the cursor source for the object in the db object table. * Must include _id in the projection. * * @param allowInteractions controls whether the bound view is * allowed to intercept touch events and do its own processing. */ public static void bindView(View v, final Context context, Cursor cursor, boolean allowInteractions) { TextView nameText = (TextView) v.findViewById(R.id.name_text); ViewGroup frame = (ViewGroup) v.findViewById(R.id.object_content); frame.removeAllViews(); // make sure we have all the columns we need Long objId = cursor.getLong(cursor.getColumnIndexOrThrow(DbObj.COL_ID)); String[] projection = null; String selection = DbObj.COL_ID + " = ?"; String[] selectionArgs = new String[] { Long.toString(objId) }; String sortOrder = null; Cursor c = context.getContentResolver().query(DbObj.OBJ_URI, projection, selection, selectionArgs, sortOrder); if (!c.moveToFirst()) { Log.w(TAG, "could not find obj " + objId); c.close(); return; } DbObj obj = App.instance().getMusubi().objForCursor(c); if (obj == null) { nameText.setText("Failed to access database."); Log.e("DbObject", "cursor was null for bindView of DbObject"); return; } DbUser sender = obj.getSender(); Long timestamp = c.getLong(c.getColumnIndexOrThrow(DbObj.COL_TIMESTAMP)); Long hash = obj.getHash(); short deleted = c.getShort(c.getColumnIndexOrThrow(DELETED)); String feedName = obj.getFeedName(); String type = obj.getType(); Date date = new Date(timestamp); c.close(); c = null; if (sender == null) { nameText.setText("Message from unknown contact."); return; } nameText.setText(sender.getName()); final ImageView icon = (ImageView) v.findViewById(R.id.icon); if (sViewProfileAction == null) { sViewProfileAction = new OnClickViewProfile((Activity) context); } icon.setTag(sender.getLocalId()); if (allowInteractions) { icon.setOnClickListener(sViewProfileAction); v.setTag(objId); } icon.setImageBitmap(sender.getPicture()); if (deleted == 1) { v.setBackgroundColor(sDeletedColor); } else { v.setBackgroundColor(Color.TRANSPARENT); } TextView timeText = (TextView) v.findViewById(R.id.time_text); timeText.setText(RelativeDate.getRelativeDate(date)); frame.setTag(objId); // TODO: error prone! This is database id frame.setTag(R.id.object_entry, cursor.getPosition()); // this is cursor id FeedRenderer renderer = DbObjects.getFeedRenderer(type); if (renderer != null) { renderer.render(context, frame, obj, allowInteractions); } if (!allowInteractions) { v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE); v.findViewById(R.id.obj_attachments).setVisibility(View.GONE); } else { if (!MusubiBaseActivity.isDeveloperModeEnabled(context)) { v.findViewById(R.id.obj_attachments_icon).setVisibility(View.GONE); v.findViewById(R.id.obj_attachments).setVisibility(View.GONE); } else { ImageView attachmentCountButton = (ImageView) v.findViewById(R.id.obj_attachments_icon); TextView attachmentCountText = (TextView) v.findViewById(R.id.obj_attachments); attachmentCountButton.setVisibility(View.VISIBLE); if (hash == 0) { attachmentCountButton.setVisibility(View.GONE); } else { //int color = DbObject.colorFor(hash); boolean selfPost = false; DBHelper helper = new DBHelper(context); try { Cursor attachments = obj.getSubfeed().query("type=?", new String[] { LikeObj.TYPE }); try { attachmentCountText.setText("+" + attachments.getCount()); if (attachments.moveToFirst()) { while (!attachments.isAfterLast()) { if (attachments.getInt(attachments.getColumnIndex(CONTACT_ID)) == -666) { selfPost = true; break; } attachments.moveToNext(); } } } finally { attachments.close(); } } finally { helper.close(); } if (selfPost) { attachmentCountButton.setImageResource(R.drawable.ic_menu_love_red); } else { attachmentCountButton.setImageResource(R.drawable.ic_menu_love); } attachmentCountText.setTag(R.id.object_entry, hash); attachmentCountText.setTag(R.id.feed_label, Feed.uriForName(feedName)); attachmentCountText.setOnClickListener(LikeListener.getInstance(context)); } } } }