List of usage examples for android.view View setBackgroundColor
@RemotableViewMethod public void setBackgroundColor(@ColorInt int color)
From source file:com.ns.developer.tagview.widget.TagCloudLinkView.java
/** * tag draw//from w w w . j a va 2 s . c om */ public void drawTags() { if (!mInitialized) { return; } // clear all tag removeAllViews(); // layout padding left & layout padding right float total = getPaddingLeft() + getPaddingRight(); // ???index int index = 1; // ? int pindex = index; // List Index int listIndex = 0; for (String item : mTags) { final int position = listIndex; final String tag = item; // inflate tag layout View tagLayout = (View) mInflater.inflate(R.layout.tag, null); tagLayout.setId(index); // tagLayout.setBackgroundColor(mTagLayoutColor); // tag text TextView tagView = (TextView) tagLayout.findViewById(R.id.tag_txt); tagView.setText(tag); tagView.setPadding(INNER_VIEW_PADDING, INNER_VIEW_PADDING, INNER_VIEW_PADDING, INNER_VIEW_PADDING); tagView.setTextColor(mTagTextColor); tagView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mSelectListener != null) { mSelectListener.onTagSelected(tag, position); } } }); // calculateof tag layout width float tagWidth = tagView.getPaint().measureText(tag) + INNER_VIEW_PADDING * 2; // tagView padding (left & right) // deletable text TextView deletableView = (TextView) tagLayout.findViewById(R.id.delete_txt); if (mIsDeletable) { deletableView.setVisibility(View.VISIBLE); deletableView.setText(DEFAULT_DELETABLE_STRING); deletableView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mDeleteListener != null) { String targetTag = tag; TagCloudLinkView.this.remove(position); mDeleteListener.onTagDeleted(targetTag, position); } } }); tagWidth += deletableView.getPaint().measureText(DEFAULT_DELETABLE_STRING) + INNER_VIEW_PADDING * 2; // deletableView Padding (left & right) } else { deletableView.setVisibility(View.GONE); } LayoutParams tagParams = new LayoutParams(HEIGHT_WC, HEIGHT_WC); tagParams.setMargins(0, 0, 0, 0); if (mWidth <= total + tagWidth + LAYOUT_WIDTH_OFFSET) { tagParams.addRule(RelativeLayout.BELOW, pindex); tagParams.topMargin = TAG_LAYOUT_TOP_MERGIN; // initialize total param (layout padding left & layout padding right) total = getPaddingLeft() + getPaddingRight(); pindex = index; } else { tagParams.addRule(RelativeLayout.ALIGN_TOP, pindex); tagParams.addRule(RelativeLayout.RIGHT_OF, index - 1); if (index > 1) { tagParams.leftMargin = TAG_LAYOUT_LEFT_MERGIN; total += TAG_LAYOUT_LEFT_MERGIN; } } total += tagWidth; addView(tagLayout, tagParams); index++; listIndex++; } LayoutParams tagParams = new LayoutParams(HEIGHT_WC, HEIGHT_WC); tagParams.setMargins(0, 0, 0, 0); if (isAutoCompleteMode || !mIsDeletable) { return; } int tagWidth = 50; //25dp if (mWidth <= total + tagWidth + LAYOUT_WIDTH_OFFSET) { tagParams.addRule(RelativeLayout.BELOW, pindex); tagParams.topMargin = TAG_LAYOUT_TOP_MERGIN; // initialize total param (layout padding left & layout padding right) total = getPaddingLeft() + getPaddingRight(); pindex = index; } else { tagParams.addRule(RelativeLayout.ALIGN_TOP, pindex); tagParams.addRule(RelativeLayout.RIGHT_OF, index - 1); if (index > 1) { tagParams.leftMargin = TAG_LAYOUT_LEFT_MERGIN; total += TAG_LAYOUT_LEFT_MERGIN; } } total += tagWidth; View tagLayout = (View) mInflater.inflate(R.layout.tag, null); addView(tagLayout, tagParams); tagLayout.findViewById(R.id.add_image_view).setVisibility(VISIBLE); tagLayout.findViewById(R.id.tag_txt).setVisibility(GONE); tagLayout.setClickable(true); tagLayout.setFocusable(true); tagLayout.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { if (mAddTagListener != null) { mAddTagListener.onAddTag(); } } }); int transparentColor = ContextCompat.getColor(getContext(), android.R.color.transparent); tagLayout.setBackgroundColor(transparentColor); }
From source file:com.amaze.filemanager.activities.MainActivity.java
void initialiseViews() { appBarLayout = (AppBarLayout) findViewById(R.id.lin); if (!ImageLoader.getInstance().isInited()) { ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this)); }/*from w w w . j av a2s. co m*/ displayImageOptions = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.amaze_header) .showImageForEmptyUri(R.drawable.amaze_header).showImageOnFail(R.drawable.amaze_header) .cacheInMemory(true).cacheOnDisk(true).considerExifParams(true).bitmapConfig(Bitmap.Config.RGB_565) .build(); buttonBarFrame = (FrameLayout) findViewById(R.id.buttonbarframe); buttonBarFrame.setBackgroundColor(Color.parseColor(skin)); drawerHeaderLayout = getLayoutInflater().inflate(R.layout.drawerheader, null); drawerHeaderParent = (RelativeLayout) drawerHeaderLayout.findViewById(R.id.drawer_header_parent); drawerHeaderView = (View) drawerHeaderLayout.findViewById(R.id.drawer_header); drawerHeaderView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent; if (Build.VERSION.SDK_INT < 19) { intent = new Intent(); intent.setAction(Intent.ACTION_GET_CONTENT); } else { intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); } intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(intent, image_selector_request_code); return false; } }); drawerProfilePic = (RoundedImageView) drawerHeaderLayout.findViewById(R.id.profile_pic); mGoogleName = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_name); mGoogleId = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_email); toolbar = (Toolbar) findViewById(R.id.action_bar); setSupportActionBar(toolbar); frameLayout = (FrameLayout) findViewById(R.id.content_frame); indicator_layout = findViewById(R.id.indicator_layout); mDrawerLinear = (ScrimInsetsRelativeLayout) findViewById(R.id.left_drawer); if (theme1 == 1) mDrawerLinear.setBackgroundColor(Color.parseColor("#303030")); else mDrawerLinear.setBackgroundColor(Color.WHITE); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setStatusBarBackgroundColor(Color.parseColor(skin)); mDrawerList = (ListView) findViewById(R.id.menu_drawer); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor(skin)); if (findViewById(R.id.tab_frame) != null) { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, mDrawerLinear); mDrawerLayout.setScrimColor(Color.TRANSPARENT); isDrawerLocked = true; } mDrawerList.addHeaderView(drawerHeaderLayout); getSupportActionBar().setDisplayShowTitleEnabled(false); View v = findViewById(R.id.fab_bg); if (theme1 == 1) v.setBackgroundColor(Color.parseColor("#a6ffffff")); v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { floatingActionButton.close(true); revealShow(view, false); } }); pathbar = (LinearLayout) findViewById(R.id.pathbar); buttons = (LinearLayout) findViewById(R.id.buttons); scroll = (HorizontalScrollView) findViewById(R.id.scroll); scroll1 = (HorizontalScrollView) findViewById(R.id.scroll1); scroll.setSmoothScrollingEnabled(true); scroll1.setSmoothScrollingEnabled(true); ImageView divider = (ImageView) findViewById(R.id.divider1); if (theme1 == 0) divider.setImageResource(R.color.divider); else divider.setImageResource(R.color.divider_dark); setDrawerHeaderBackground(); View settingsbutton = findViewById(R.id.settingsbutton); if (theme1 == 1) { settingsbutton.setBackgroundResource(R.drawable.safr_ripple_black); ((ImageView) settingsbutton.findViewById(R.id.settingicon)) .setImageResource(R.drawable.ic_settings_white_48dp); ((TextView) settingsbutton.findViewById(R.id.settingtext)) .setTextColor(getResources().getColor(android.R.color.white)); } settingsbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent in = new Intent(MainActivity.this, Preferences.class); finish(); final int enter_anim = android.R.anim.fade_in; final int exit_anim = android.R.anim.fade_out; Activity s = MainActivity.this; s.overridePendingTransition(exit_anim, enter_anim); s.finish(); s.overridePendingTransition(enter_anim, exit_anim); s.startActivity(in); } }); View appbutton = findViewById(R.id.appbutton); if (theme1 == 1) { appbutton.setBackgroundResource(R.drawable.safr_ripple_black); ((ImageView) appbutton.findViewById(R.id.appicon)).setImageResource(R.drawable.ic_doc_apk_white); ((TextView) appbutton.findViewById(R.id.apptext)) .setTextColor(getResources().getColor(android.R.color.white)); } appbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { android.support.v4.app.FragmentTransaction transaction2 = getSupportFragmentManager() .beginTransaction(); transaction2.replace(R.id.content_frame, new AppsList()); findViewById(R.id.lin).animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)) .start(); pending_fragmentTransaction = transaction2; if (!isDrawerLocked) mDrawerLayout.closeDrawer(mDrawerLinear); else onDrawerClosed(); select = -2; adapter.toggleChecked(false); } }); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(skin))); // status bar0 sdk = Build.VERSION.SDK_INT; if (sdk == 20 || sdk == 19) { SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintColor(Color.parseColor(skin)); FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.drawer_layout) .getLayoutParams(); SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); if (!isDrawerLocked) p.setMargins(0, config.getStatusBarHeight(), 0, 0); } else if (Build.VERSION.SDK_INT >= 21) { colourednavigation = Sp.getBoolean("colorednavigation", true); Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); if (isDrawerLocked) { window.setStatusBarColor((skinStatusBar)); } else window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); if (colourednavigation) window.setNavigationBarColor(skinStatusBar); } }
From source file:com.filemanager.free.activities.MainActivity.java
@SuppressLint("InflateParams") private void initialiseViews() { mCoordinatorLayout = (CoordinatorLayout) findViewById(R.id.main_frame); appBarLayout = (AppBarLayout) findViewById(R.id.lin); if (!ImageLoader.getInstance().isInited()) { ImageLoader.getInstance().init(ImageLoaderConfiguration.createDefault(this)); }/* ww w . j av a 2 s . co m*/ if (displayImageOptions != null) { displayImageOptions = new DisplayImageOptions.Builder().showImageOnLoading(R.drawable.amaze_header) .showImageForEmptyUri(R.drawable.amaze_header).showImageOnFail(R.drawable.amaze_header) .cacheInMemory(true).cacheOnDisk(true).considerExifParams(true) .bitmapConfig(Bitmap.Config.RGB_565).build(); } buttonBarFrame = (FrameLayout) findViewById(R.id.buttonbarframe); buttonBarFrame.setBackgroundColor(Color.parseColor(skin)); drawerHeaderLayout = getLayoutInflater().inflate(R.layout.drawerheader, null); drawerHeaderParent = (RelativeLayout) drawerHeaderLayout.findViewById(R.id.drawer_header_parent); drawerHeaderView = (View) drawerHeaderLayout.findViewById(R.id.drawer_header); drawerHeaderView.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Intent intent; if (Build.VERSION.SDK_INT < 19) { intent = new Intent(); intent.setAction(Intent.ACTION_GET_CONTENT); } else { intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); } intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("image/*"); startActivityForResult(intent, image_selector_request_code); return false; } }); drawerProfilePic = (RoundedImageView) drawerHeaderLayout.findViewById(R.id.profile_pic); mGoogleName = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_name); mGoogleId = (TextView) drawerHeaderLayout.findViewById(R.id.account_header_drawer_email); toolbar = (Toolbar) findViewById(R.id.action_bar); setSupportActionBar(toolbar); frameLayout = (FrameLayout) findViewById(R.id.content_frame); indicator_layout = findViewById(R.id.indicator_layout); mDrawerLinear = (ScrimInsetsRelativeLayout) findViewById(R.id.left_drawer); if (theme1 == 1) mDrawerLinear.setBackgroundColor(Color.parseColor("#303030")); else { assert mDrawerLinear != null; mDrawerLinear.setBackgroundColor(Color.WHITE); } mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerLayout.setStatusBarBackgroundColor(Color.parseColor(skin)); mDrawerList = (ListView) findViewById(R.id.menu_drawer); drawerHeaderView.setBackgroundResource(R.drawable.amaze_header); drawerHeaderParent.setBackgroundColor(Color.parseColor(skin)); if (findViewById(R.id.tab_frame) != null) { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN, mDrawerLinear); mDrawerLayout.setScrimColor(Color.TRANSPARENT); isDrawerLocked = true; } mDrawerList.addHeaderView(drawerHeaderLayout); if (getSupportActionBar() != null) { getSupportActionBar().setDisplayShowTitleEnabled(false); } View v = findViewById(R.id.fab_bg); if (theme1 == 1) { assert v != null; v.setBackgroundColor(Color.parseColor("#a6ffffff")); } assert v != null; v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { floatingActionButton.close(true); utils.revealShow(view, false); } }); pathbar = (LinearLayout) findViewById(R.id.pathbar); buttons = (LinearLayout) findViewById(R.id.buttons); scroll = (HorizontalScrollView) findViewById(R.id.scroll); scroll1 = (HorizontalScrollView) findViewById(R.id.scroll1); scroll.setSmoothScrollingEnabled(true); scroll1.setSmoothScrollingEnabled(true); ImageView divider = (ImageView) findViewById(R.id.divider1); if (theme1 == 0) { assert divider != null; divider.setImageResource(R.color.divider); } else { assert divider != null; divider.setImageResource(R.color.divider_dark); } setDrawerHeaderBackground(); View settingsbutton = findViewById(R.id.settingsbutton); if (theme1 == 1) { assert settingsbutton != null; settingsbutton.setBackgroundResource(R.drawable.safr_ripple_black); ((ImageView) settingsbutton.findViewById(R.id.settingicon)) .setImageResource(R.drawable.ic_settings_white_48dp); ((TextView) settingsbutton.findViewById(R.id.settingtext)) .setTextColor(ContextCompat.getColor(con, android.R.color.white)); } assert settingsbutton != null; settingsbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent in = new Intent(MainActivity.this, Preferences.class); finish(); final int enter_anim = android.R.anim.fade_in; final int exit_anim = android.R.anim.fade_out; Activity s = MainActivity.this; s.overridePendingTransition(exit_anim, enter_anim); s.finish(); s.overridePendingTransition(enter_anim, exit_anim); s.startActivity(in); } }); View appbutton = findViewById(R.id.appbutton); if (theme1 == 1) { assert appbutton != null; appbutton.setBackgroundResource(R.drawable.safr_ripple_black); ((ImageView) appbutton.findViewById(R.id.appicon)).setImageResource(R.drawable.ic_doc_apk_white); ((TextView) appbutton.findViewById(R.id.apptext)) .setTextColor(ContextCompat.getColor(con, android.R.color.white)); } assert appbutton != null; appbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { android.support.v4.app.FragmentTransaction transaction2 = getSupportFragmentManager() .beginTransaction(); transaction2.replace(R.id.content_frame, new AppsList()); findViewById(R.id.lin).animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)) .start(); pending_fragmentTransaction = transaction2; if (!isDrawerLocked) mDrawerLayout.closeDrawer(mDrawerLinear); else onDrawerClosed(); select = -2; adapter.toggleChecked(false); } }); getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.parseColor(skin))); // status bar0 sdk = Build.VERSION.SDK_INT; if (sdk == 20 || sdk == 19) { SystemBarTintManager tintManager = new SystemBarTintManager(this); tintManager.setStatusBarTintEnabled(true); tintManager.setStatusBarTintColor(Color.parseColor(skin)); FrameLayout.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) findViewById(R.id.drawer_layout) .getLayoutParams(); SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); if (!isDrawerLocked) p.setMargins(0, config.getStatusBarHeight(), 0, 0); } else if (Build.VERSION.SDK_INT >= 21) { colourednavigation = Sp.getBoolean("colorednavigation", true); Window window = getWindow(); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); //window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); if (isDrawerLocked) { window.setStatusBarColor((skinStatusBar)); } else window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); if (colourednavigation) window.setNavigationBarColor(skinStatusBar); } //admob mAdView = (View) findViewById(R.id.ads); }
From source file:io.intue.kamu.BestNearbyFragment.java
@Override public void bindCollectionItemView(Context context, View view, int groupId, int indexInGroup, int dataIndex, Object tag) {//from ww w. j a v 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; // } if (mresult == null) { return; } Venue result = mresult.get(dataIndex); final String sessionId = result.getId(); if (sessionId == null) { return; } // first, read session info from cursor and put it in convenience variables final String sessionTitle = result.getName(); //final String speakerNames = "SessionsQuery.SPEAKER_NAMES"; //final String sessionAbstract = "SessionsQuery.ABSTRACT"; //final long sessionStart = 44454544; //final long sessionEnd = 334343433; //final String roomName = "SessionsQuery.ROOM_NAME"; int sessionColor = 0; sessionColor = sessionColor == 0 ? getResources().getColor(R.color.transparent) : sessionColor; //final String snippet = "SessionsQuery.SNIPPET"; final Spannable styledSnippet = null; final boolean starred = false; //final String[] tags = "A,B,C".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 = false; final long now = UIUtils.getCurrentTime(context); final boolean happeningNow = false; // text that says "LIVE" if session is live, or empty if session is not live //final String liveNowText = ""; // 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 boxView = view.findViewById(R.id.info_box); final View sessionTargetView = view.findViewById(R.id.session_target); if (sessionColor == 0) { // use default sessionColor = getResources().getColor(R.color.transparent); } sessionColor = 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(UIUtils.setColorAlpha(sessionColor, UIUtils.SESSION_PHOTO_SCRIM_ALPHA)); } else { photoView = (ImageView) view.findViewById(R.id.session_photo); } ((BaseActivity) getActivity()).getLPreviewUtils().setViewName(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(sessionColor); } else { photoView.setBackgroundColor(sessionColor); } String photo = result.getPhotoUrl(); 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(result.getAddress()); } else if (shortSubtitleView != null) { shortSubtitleView.setText(result.getAddress()); } // 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()); // } // in expanded mode, the box background color follows the session color //if (useExpandedMode()) { boxView.setBackgroundColor(sessionColor); //} // 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 (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(sessionColor); } } // 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.mattfred.betterpickers.calendardatepicker.CalendarDatePickerDialogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(TAG, "onCreateView: "); if (getShowsDialog()) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); }/* w ww . ja v a 2s. c om*/ View view = inflater.inflate(R.layout.calendar_date_picker_dialog, null); mSelectedDateLayout = (LinearLayout) view.findViewById(R.id.day_picker_selected_date_layout); mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header); mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day); mMonthAndDayView.setOnClickListener(this); mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month); mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day); mYearView = (TextView) view.findViewById(R.id.date_picker_year); mYearView.setOnClickListener(this); int listPosition = -1; int listPositionOffset = 0; int currentView = MONTH_AND_DAY_VIEW; if (savedInstanceState != null) { mWeekStart = savedInstanceState.getInt(KEY_WEEK_START); mMinDate = new CalendarDay(savedInstanceState.getLong(KEY_DATE_START)); mMaxDate = new CalendarDay(savedInstanceState.getLong(KEY_DATE_END)); currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW); listPosition = savedInstanceState.getInt(KEY_LIST_POSITION); listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET); mStyleResId = savedInstanceState.getInt(KEY_THEME); mDisabledDays = savedInstanceState.getSparseParcelableArray(KEY_DISABLED_DAYS); } final Activity activity = getActivity(); mDayPickerView = new SimpleDayPickerView(activity, this); mYearPickerView = new YearPickerView(activity, this); Resources res = getResources(); TypedArray themeColors = getActivity().obtainStyledAttributes(mStyleResId, R.styleable.BetterPickersDialog); mDayPickerDescription = res.getString(R.string.day_picker_description); mSelectDay = res.getString(R.string.select_day); mYearPickerDescription = res.getString(R.string.year_picker_description); mSelectYear = res.getString(R.string.select_year); mSelectedColor = themeColors.getColor(R.styleable.BetterPickersDialog_bpAccentColor, R.color.bpBlue); mUnselectedColor = themeColors.getColor(R.styleable.BetterPickersDialog_bpMainTextColor, R.color.numbers_text_color); mAnimator = (AccessibleDateAnimator) view.findViewById(R.id.animator); mAnimator.addView(mDayPickerView); mAnimator.addView(mYearPickerView); mAnimator.setDateMillis(mCalendar.getTimeInMillis()); // TODO: Replace with animation decided upon by the design team. Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(ANIMATION_DURATION); mAnimator.setInAnimation(animation); // TODO: Replace with animation decided upon by the design team. Animation animation2 = new AlphaAnimation(1.0f, 0.0f); animation2.setDuration(ANIMATION_DURATION); mAnimator.setOutAnimation(animation2); Button doneButton = (Button) view.findViewById(R.id.done_button); doneButton.setTextColor(mSelectedColor); doneButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onOkClick(); } }); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); cancelButton.setTextColor(mSelectedColor); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); dismiss(); } }); updateDisplay(false); setCurrentView(currentView); if (listPosition != -1) { if (currentView == MONTH_AND_DAY_VIEW) { mDayPickerView.postSetSelection(listPosition); } else if (currentView == YEAR_VIEW) { mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset); } } mHapticFeedbackController = new HapticFeedbackController(activity); int mainColor1 = themeColors.getColor(R.styleable.BetterPickersDialog_bpMainColor1, R.color.bpWhite); int mainColor2 = themeColors.getColor(R.styleable.BetterPickersDialog_bpMainColor2, R.color.circle_background); int backgroundColor = themeColors.getColor(R.styleable.BetterPickersDialog_bpLineColor, R.color.bpWhite); mDayPickerView.setTheme(themeColors); mYearPickerView.setTheme(themeColors); mSelectedDateLayout.setBackgroundColor(mainColor1); mYearView.setBackgroundColor(mainColor1); mMonthAndDayView.setBackgroundColor(mainColor1); view.setBackgroundColor(mainColor2); if (mDayOfWeekView != null) { mDayOfWeekView.setBackgroundColor(backgroundColor); } mYearPickerView.setBackgroundColor(mainColor2); mDayPickerView.setBackgroundColor(mainColor2); return view; }
From source file:fr.paug.droidcon.ui.SessionsFragment.java
@Override public void bindCollectionItemView(Context context, View view, int groupId, int indexInGroup, int dataIndex, Object tag) {//from w ww .j a va 2s . 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); final String mainTag = mCursor.getString(SessionsQuery.MAIN_TAG); int sessionColor = mCursor.getInt(SessionsQuery.COLOR); sessionColor = sessionColor == 0 ? getResources().getColor(R.color.default_session_color) : sessionColor; 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 boxView = view.findViewById(R.id.info_box); final View sessionTargetView = view.findViewById(R.id.session_target); if (sessionColor == 0) { // use default sessionColor = mDefaultSessionColor; } sessionColor = 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(UIUtils.setColorAlpha(sessionColor, UIUtils.SESSION_PHOTO_SCRIM_ALPHA)); } else { photoView = (ImageView) view.findViewById(R.id.session_photo); } ((BaseActivity) getActivity()).getLPreviewUtils().setViewName(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(sessionColor); } else { photoView.setBackgroundColor(sessionColor); } 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); photoView.setImageResource(R.drawable.default_session_img); } // 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()); } // in expanded mode, the box background color follows the session color if (useExpandedMode()) { boxView.setBackgroundColor(sessionColor); } // show or hide the "in my schedule" indicator ImageView indicatorInSchedule = (ImageView) view.findViewById(R.id.indicator_in_schedule); indicatorInSchedule.setVisibility(starred ? View.VISIBLE : View.INVISIBLE); if (starred) { int resId = R.drawable.indicator_in_schedule; if (mainTag.equals(SessionDetailFragment.TOPIC_EVERYWHERE)) resId = R.drawable.indicator_in_schedule_red; else if (mainTag.equals(SessionDetailFragment.TOPIC_DEVELOPMENT)) resId = R.drawable.indicator_in_schedule_blue; else if (mainTag.equals(SessionDetailFragment.TOPIC_UI_UX)) resId = R.drawable.indicator_in_schedule_amber; else if (mainTag.equals(SessionDetailFragment.TOPIC_OTHER)) resId = R.drawable.indicator_in_schedule_indigo; indicatorInSchedule.setImageResource(resId); } // 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(sessionColor); } } // 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:cl.smartcities.isci.transportinspector.adapters.dialogAdapters.EventAdapter.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { final ViewHolder holder; if (convertView == null) { convertView = mInflater.inflate(R.layout.event_layout_row, parent, false); holder = new ViewHolder(); holder.event_icon = (ImageView) convertView.findViewById(R.id.event_icon); holder.description = (TextView) convertView.findViewById(R.id.description); holder.time = (TextView) convertView.findViewById(R.id.event_time); holder.yes_counter = (TextView) convertView.findViewById(R.id.yes_counter); holder.no_counter = (TextView) convertView.findViewById(R.id.no_counter); holder.yesIcon = (ImageButton) convertView.findViewById(R.id.yes_icon); holder.noIcon = (ImageButton) convertView.findViewById(R.id.no_icon); holder.true_text = (TextView) convertView.findViewById(R.id.true_text); holder.false_text = (TextView) convertView.findViewById(R.id.false_text); holder.ticket_font_green = (TextView) convertView.findViewById(R.id.ticket_font_green); holder.ticket_font_red = (TextView) convertView.findViewById(R.id.ticket_font_red); holder.confirm_button_layout = (RelativeLayout) convertView.findViewById(R.id.confirm_button_layout); holder.decline_button_layout = (RelativeLayout) convertView.findViewById(R.id.decline_button_layout); Typeface robotoRegular = Typeface.createFromAsset(this.getContext().getAssets(), this.context.getString(R.string.roboto_regular_font)); Typeface robotoBold = Typeface.createFromAsset(this.getContext().getAssets(), this.context.getString(R.string.roboto_bold_font)); Typeface iconFont = Typeface.createFromAsset(this.getContext().getAssets(), this.context.getString(R.string.icon_font)); holder.setHolderTypefaceRegular(robotoRegular); holder.setHolderTypefaceBold(robotoBold); holder.setHolderIconFont(iconFont); convertView.setTag(holder);// w ww . ja v a2 s . c om } else { holder = (ViewHolder) convertView.getTag(); } final Event event = this.events.get(position); //Descripcion del evento String description = this.events.get(position).getDescription(); holder.description.setText(description); //Time del evento String date = this.events.get(position).getTime(); holder.time.setText(date); //Confirmaciones del evento String confirms = this.events.get(position).getConfirms() + ""; holder.yes_counter.setText(confirms); //Negaciones del evento String declines = this.events.get(position).getDeclines() + ""; holder.no_counter.setText(declines); // Event icon int resDrawableId = this.events.get(position).getResDrawableId(); holder.event_icon.setImageResource(resDrawableId); //id del evento final String id = this.events.get(position).getId(); final EventRequest eventRequest; if (this.type.equals("Bus")) { eventRequest = new BusEventRequest(this.code, this.title, id); } else { eventRequest = new BusStopEventRequest(this.code, id); } holder.decline_button_layout.setVisibility(View.VISIBLE); holder.decline_button_layout.setVisibility(View.VISIBLE); if (getLastStateAccordingToPosition(position).equals(State.ONLY_CONFIRM)) { holder.decline_button_layout.setVisibility(View.GONE); } if (getLastStateAccordingToPosition(position).equals(State.ONLY_DECLINE)) { holder.confirm_button_layout.setVisibility(View.GONE); } //Listener de eventos holder.yesIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Map<String, String> attributes = new HashMap<>(); attributes.put("Event name", event.getName()); attributes.put("BusStop/Service Code", code); TranSappApplication.addFabricLog("Event confirmed", attributes); setCurrentState(position, State.ONLY_CONFIRM); confirmEvent(holder, eventRequest, event); holder.decline_button_layout.setVisibility(View.GONE); holder.ticket_font_green.setVisibility(View.VISIBLE); } }); holder.noIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Map<String, String> attributes = new HashMap<>(); attributes.put("Event name", event.getName()); attributes.put("BusStop/Service Code", code); TranSappApplication.addFabricLog("Event denied", attributes); setCurrentState(position, State.ONLY_DECLINE); denyEvent(holder, eventRequest, event); holder.confirm_button_layout.setVisibility(View.GONE); holder.ticket_font_red.setVisibility(View.VISIBLE); } }); /* save holder onStopListener convertView */ if (position % 2 == 0) { convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.even_row)); } else { convertView.setBackgroundColor(ContextCompat.getColor(context, R.color.odd_row)); } return convertView; }
From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java
protected void updateMessageDetail(final boolean isUpdate) { T.UI();/* w ww .j a v a 2s. c o m*/ // Set sender avatar ImageView avatarImage = (ImageView) findViewById(R.id.avatar); String sender = mCurrentMessage.sender; setAvatar(avatarImage, sender); // Set sender name TextView senderView = (TextView) findViewById(R.id.sender); final String senderName = mFriendsPlugin.getName(sender); senderView.setText(senderName == null ? sender : senderName); // Set timestamp TextView timestampView = (TextView) findViewById(R.id.timestamp); timestampView.setText(TimeUtils.getDayTimeStr(this, mCurrentMessage.timestamp * 1000)); // Set clickable region on top to go to friends detail final RelativeLayout messageHeader = (RelativeLayout) findViewById(R.id.message_header); messageHeader.setOnClickListener(getFriendDetailOnClickListener(mCurrentMessage.sender)); messageHeader.setVisibility(View.VISIBLE); // Set message TextView messageView = (TextView) findViewById(R.id.message); WebView web = (WebView) findViewById(R.id.webview); FrameLayout flay = (FrameLayout) findViewById(R.id.message_details); Resources resources = getResources(); flay.setBackgroundColor(resources.getColor(R.color.mc_background)); boolean showBranded = false; int darkSchemeTextColor = resources.getColor(android.R.color.primary_text_dark); int lightSchemeTextColor = resources.getColor(android.R.color.primary_text_light); senderView.setTextColor(lightSchemeTextColor); timestampView.setTextColor(lightSchemeTextColor); BrandingResult br = null; if (!TextUtils.isEmptyOrWhitespace(mCurrentMessage.branding)) { boolean brandingAvailable = false; try { brandingAvailable = mMessagingPlugin.getBrandingMgr().isBrandingAvailable(mCurrentMessage.branding); } catch (BrandingFailureException e1) { L.d(e1); } try { if (brandingAvailable) { br = mMessagingPlugin.getBrandingMgr().prepareBranding(mCurrentMessage); WebSettings settings = web.getSettings(); settings.setJavaScriptEnabled(false); settings.setBlockNetworkImage(false); web.loadUrl("file://" + br.file.getAbsolutePath()); web.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); if (br.color != null) { flay.setBackgroundColor(br.color); } if (!br.showHeader) { messageHeader.setVisibility(View.GONE); MarginLayoutParams mlp = (MarginLayoutParams) web.getLayoutParams(); mlp.setMargins(0, 0, 0, mlp.bottomMargin); } else if (br.scheme == ColorScheme.dark) { senderView.setTextColor(darkSchemeTextColor); timestampView.setTextColor(darkSchemeTextColor); } showBranded = true; } else { mMessagingPlugin.getBrandingMgr().queueGenericBranding(mCurrentMessage.branding); } } catch (BrandingFailureException e) { L.bug("Could not display message with branding: branding is available, but prepareBranding failed", e); } } if (showBranded) { web.setVisibility(View.VISIBLE); messageView.setVisibility(View.GONE); } else { web.setVisibility(View.GONE); messageView.setVisibility(View.VISIBLE); messageView.setText(mCurrentMessage.message); } // Add list of members who did not ack yet FlowLayout memberSummary = (FlowLayout) findViewById(R.id.member_summary); memberSummary.removeAllViews(); SortedSet<MemberStatusTO> memberSummarySet = new TreeSet<MemberStatusTO>(getMemberstatusComparator()); for (MemberStatusTO ms : mCurrentMessage.members) { if ((ms.status & MessagingPlugin.STATUS_ACKED) != MessagingPlugin.STATUS_ACKED && !ms.member.equals(mCurrentMessage.sender)) { memberSummarySet.add(ms); } } FlowLayout.LayoutParams flowLP = new FlowLayout.LayoutParams(2, 0); for (MemberStatusTO ms : memberSummarySet) { FrameLayout fl = new FrameLayout(this); fl.setLayoutParams(flowLP); memberSummary.addView(fl); fl.addView(createParticipantView(ms)); } memberSummary.setVisibility(memberSummarySet.size() < 2 ? View.GONE : View.VISIBLE); // Add members statuses final LinearLayout members = (LinearLayout) findViewById(R.id.members); members.removeAllViews(); final String myEmail = mService.getIdentityStore().getIdentity().getEmail(); boolean isMember = false; mSomebodyAnswered = false; for (MemberStatusTO ms : mCurrentMessage.members) { boolean showMember = true; View view = getLayoutInflater().inflate(R.layout.message_member_detail, null); // Set receiver avatar RelativeLayout rl = (RelativeLayout) view.findViewById(R.id.avatar); rl.addView(createParticipantView(ms)); // Set receiver name TextView receiverView = (TextView) view.findViewById(R.id.receiver); final String memberName = mFriendsPlugin.getName(ms.member); receiverView.setText(memberName == null ? sender : memberName); // Set received timestamp TextView receivedView = (TextView) view.findViewById(R.id.received_timestamp); if ((ms.status & MessagingPlugin.STATUS_RECEIVED) == MessagingPlugin.STATUS_RECEIVED) { final String humanTime = TimeUtils.getDayTimeStr(this, ms.received_timestamp * 1000); if (ms.member.equals(mCurrentMessage.sender)) receivedView.setText(getString(R.string.sent_at, humanTime)); else receivedView.setText(getString(R.string.received_at, humanTime)); } else { receivedView.setText(R.string.not_yet_received); } // Set replied timestamp TextView repliedView = (TextView) view.findViewById(R.id.acked_timestamp); if ((ms.status & MessagingPlugin.STATUS_ACKED) == MessagingPlugin.STATUS_ACKED) { mSomebodyAnswered = true; String acked_timestamp = TimeUtils.getDayTimeStr(this, ms.acked_timestamp * 1000); if (ms.button_id != null) { ButtonTO button = null; for (ButtonTO b : mCurrentMessage.buttons) { if (b.id.equals(ms.button_id)) { button = b; break; } } if (button == null) { repliedView.setText(getString(R.string.dismissed_at, acked_timestamp)); // Do not show sender as member if he hasn't clicked a // button showMember = !ms.member.equals(mCurrentMessage.sender); } else { repliedView.setText(getString(R.string.replied_at, button.caption, acked_timestamp)); } } else { if (ms.custom_reply == null) { // Do not show sender as member if he hasn't clicked a // button showMember = !ms.member.equals(mCurrentMessage.sender); repliedView.setText(getString(R.string.dismissed_at, acked_timestamp)); } else repliedView.setText(getString(R.string.replied_at, ms.custom_reply, acked_timestamp)); } } else { repliedView.setText(R.string.not_yet_replied); showMember = !ms.member.equals(mCurrentMessage.sender); } if (br != null && br.scheme == ColorScheme.dark) { receiverView.setTextColor(darkSchemeTextColor); receivedView.setTextColor(darkSchemeTextColor); repliedView.setTextColor(darkSchemeTextColor); } else { receiverView.setTextColor(lightSchemeTextColor); receivedView.setTextColor(lightSchemeTextColor); repliedView.setTextColor(lightSchemeTextColor); } if (showMember) members.addView(view); isMember |= ms.member.equals(myEmail); } boolean isLocked = (mCurrentMessage.flags & MessagingPlugin.FLAG_LOCKED) == MessagingPlugin.FLAG_LOCKED; boolean canEdit = isMember && !isLocked; // Add attachments LinearLayout attachmentLayout = (LinearLayout) findViewById(R.id.attachment_layout); attachmentLayout.removeAllViews(); if (mCurrentMessage.attachments.length > 0) { attachmentLayout.setVisibility(View.VISIBLE); for (final AttachmentTO attachment : mCurrentMessage.attachments) { View v = getLayoutInflater().inflate(R.layout.attachment_item, null); ImageView attachment_image = (ImageView) v.findViewById(R.id.attachment_image); if (AttachmentViewerActivity.CONTENT_TYPE_JPEG.equalsIgnoreCase(attachment.content_type) || AttachmentViewerActivity.CONTENT_TYPE_PNG.equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_img); } else if (AttachmentViewerActivity.CONTENT_TYPE_PDF.equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_pdf); } else if (AttachmentViewerActivity.CONTENT_TYPE_VIDEO_MP4 .equalsIgnoreCase(attachment.content_type)) { attachment_image.setImageResource(R.drawable.attachment_video); } else { attachment_image.setImageResource(R.drawable.attachment_unknown); L.d("attachment.content_type not known: " + attachment.content_type); } TextView attachment_text = (TextView) v.findViewById(R.id.attachment_text); attachment_text.setText(attachment.name); v.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { String downloadUrlHash = mMessagingPlugin .attachmentDownloadUrlHash(attachment.download_url); File attachmentsDir; try { attachmentsDir = mMessagingPlugin.attachmentsDir(mCurrentMessage.getThreadKey(), null); } catch (IOException e) { L.d("Unable to create attachment directory", e); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } boolean attachmentAvailable = mMessagingPlugin.attachmentExists(attachmentsDir, downloadUrlHash); if (!attachmentAvailable) { try { attachmentsDir = mMessagingPlugin.attachmentsDir(mCurrentMessage.getThreadKey(), mCurrentMessage.key); } catch (IOException e) { L.d("Unable to create attachment directory", e); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } attachmentAvailable = mMessagingPlugin.attachmentExists(attachmentsDir, downloadUrlHash); } if (!mService.getNetworkConnectivityManager().isConnected() && !attachmentAvailable) { AlertDialog.Builder builder = new AlertDialog.Builder( ServiceMessageDetailActivity.this); builder.setMessage(R.string.no_internet_connection_try_again); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); return; } if (IOUtils.shouldCheckExternalStorageAvailable()) { String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // Its all oke } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { if (!attachmentAvailable) { L.d("Unable to write to sd-card"); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } } else { L.d("Unable to read or write to sd-card"); UIUtils.showAlertDialog(ServiceMessageDetailActivity.this, "", R.string.unable_to_read_write_sd_card); return; } } L.d("attachment.content_type: " + attachment.content_type); L.d("attachment.download_url: " + attachment.download_url); L.d("attachment.name: " + attachment.name); L.d("attachment.size: " + attachment.size); if (AttachmentViewerActivity.supportsContentType(attachment.content_type)) { Intent i = new Intent(ServiceMessageDetailActivity.this, AttachmentViewerActivity.class); i.putExtra("thread_key", mCurrentMessage.getThreadKey()); i.putExtra("message", mCurrentMessage.key); i.putExtra("content_type", attachment.content_type); i.putExtra("download_url", attachment.download_url); i.putExtra("name", attachment.name); i.putExtra("download_url_hash", downloadUrlHash); startActivity(i); } else { AlertDialog.Builder builder = new AlertDialog.Builder( ServiceMessageDetailActivity.this); builder.setMessage(getString(R.string.attachment_can_not_be_displayed_in_your_version, getString(R.string.app_name))); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); } } }); attachmentLayout.addView(v); } } else { attachmentLayout.setVisibility(View.GONE); } LinearLayout widgetLayout = (LinearLayout) findViewById(R.id.widget_layout); if (mCurrentMessage.form == null) { widgetLayout.setVisibility(View.GONE); } else { widgetLayout.setVisibility(View.VISIBLE); widgetLayout.setEnabled(canEdit); displayWidget(widgetLayout, br); } // Add buttons TableLayout tableLayout = (TableLayout) findViewById(R.id.buttons); tableLayout.removeAllViews(); for (final ButtonTO button : mCurrentMessage.buttons) { addButton(senderName, myEmail, mSomebodyAnswered, canEdit, tableLayout, button); } if (mCurrentMessage.form == null && (mCurrentMessage.flags & MessagingPlugin.FLAG_ALLOW_DISMISS) == MessagingPlugin.FLAG_ALLOW_DISMISS) { ButtonTO button = new ButtonTO(); button.caption = "Roger that!"; addButton(senderName, myEmail, mSomebodyAnswered, canEdit, tableLayout, button); } if (mCurrentMessage.broadcast_type != null) { L.d("Show broadcast spam control"); final RelativeLayout broadcastSpamControl = (RelativeLayout) findViewById(R.id.broadcast_spam_control); View broadcastSpamControlBorder = findViewById(R.id.broadcast_spam_control_border); final View broadcastSpamControlDivider = findViewById(R.id.broadcast_spam_control_divider); final LinearLayout broadcastSpamControlTextContainer = (LinearLayout) findViewById( R.id.broadcast_spam_control_text_container); TextView broadcastSpamControlText = (TextView) findViewById(R.id.broadcast_spam_control_text); final LinearLayout broadcastSpamControlSettingsContainer = (LinearLayout) findViewById( R.id.broadcast_spam_control_settings_container); TextView broadcastSpamControlSettingsText = (TextView) findViewById( R.id.broadcast_spam_control_settings_text); TextView broadcastSpamControlIcon = (TextView) findViewById(R.id.broadcast_spam_control_icon); broadcastSpamControlIcon.setTypeface(mFontAwesomeTypeFace); broadcastSpamControlIcon.setText(R.string.fa_bell); final FriendBroadcastInfo fbi = mFriendsPlugin.getFriendBroadcastFlowForMfr(mCurrentMessage.sender); if (fbi == null) { L.bug("BroadcastData was null for: " + mCurrentMessage.sender); collapseDetails(DETAIL_SECTIONS); return; } broadcastSpamControl.setVisibility(View.VISIBLE); broadcastSpamControlSettingsContainer.setOnClickListener(new SafeViewOnClickListener() { @Override public void safeOnClick(View v) { L.d("goto broadcast settings"); PressMenuIconRequestTO request = new PressMenuIconRequestTO(); request.coords = fbi.coords; request.static_flow_hash = fbi.staticFlowHash; request.hashed_tag = fbi.hashedTag; request.generation = fbi.generation; request.service = mCurrentMessage.sender; mContext = "MENU_" + UUID.randomUUID().toString(); request.context = mContext; request.timestamp = System.currentTimeMillis() / 1000; showTransmitting(null); Map<String, Object> userInput = new HashMap<String, Object>(); userInput.put("request", request.toJSONMap()); userInput.put("func", "com.mobicage.api.services.pressMenuItem"); MessageFlowRun mfr = new MessageFlowRun(); mfr.staticFlowHash = fbi.staticFlowHash; try { JsMfr.executeMfr(mfr, userInput, mService, true); } catch (EmptyStaticFlowException ex) { completeTransmit(null); AlertDialog.Builder builder = new AlertDialog.Builder(ServiceMessageDetailActivity.this); builder.setMessage(ex.getMessage()); builder.setPositiveButton(R.string.rogerthat, null); AlertDialog dialog = builder.create(); dialog.show(); return; } } }); UIUtils.showHint(this, mService, HINT_BROADCAST, R.string.hint_broadcast, mCurrentMessage.broadcast_type, mFriendsPlugin.getName(mCurrentMessage.sender)); broadcastSpamControlText .setText(getString(R.string.broadcast_subscribed_to, mCurrentMessage.broadcast_type)); broadcastSpamControlSettingsText.setText(fbi.label); int ligthAlpha = 180; int darkAlpha = 70; int alpha = ligthAlpha; if (br != null && br.scheme == ColorScheme.dark) { broadcastSpamControlIcon.setTextColor(getResources().getColor(android.R.color.black)); broadcastSpamControlBorder.setBackgroundColor(darkSchemeTextColor); broadcastSpamControlDivider.setBackgroundColor(darkSchemeTextColor); activity.setBackgroundColor(darkSchemeTextColor); broadcastSpamControlText.setTextColor(lightSchemeTextColor); broadcastSpamControlSettingsText.setTextColor(lightSchemeTextColor); int alpacolor = Color.argb(darkAlpha, Color.red(lightSchemeTextColor), Color.green(lightSchemeTextColor), Color.blue(lightSchemeTextColor)); broadcastSpamControl.setBackgroundColor(alpacolor); alpha = darkAlpha; } else { broadcastSpamControlIcon.setTextColor(getResources().getColor(android.R.color.white)); broadcastSpamControlBorder.setBackgroundColor(lightSchemeTextColor); broadcastSpamControlDivider.setBackgroundColor(lightSchemeTextColor); activity.setBackgroundColor(lightSchemeTextColor); broadcastSpamControlText.setTextColor(darkSchemeTextColor); broadcastSpamControlSettingsText.setTextColor(darkSchemeTextColor); int alpacolor = Color.argb(darkAlpha, Color.red(darkSchemeTextColor), Color.green(darkSchemeTextColor), Color.blue(darkSchemeTextColor)); broadcastSpamControl.setBackgroundColor(alpacolor); } if (br != null && br.color != null) { int alphaColor = Color.argb(alpha, Color.red(br.color), Color.green(br.color), Color.blue(br.color)); broadcastSpamControl.setBackgroundColor(alphaColor); } mService.postOnUIHandler(new SafeRunnable() { @Override protected void safeRun() throws Exception { int maxHeight = broadcastSpamControl.getHeight(); broadcastSpamControlDivider.getLayoutParams().height = maxHeight; broadcastSpamControlDivider.requestLayout(); broadcastSpamControlSettingsContainer.getLayoutParams().height = maxHeight; broadcastSpamControlSettingsContainer.requestLayout(); broadcastSpamControlTextContainer.getLayoutParams().height = maxHeight; broadcastSpamControlTextContainer.requestLayout(); int broadcastSpamControlWidth = broadcastSpamControl.getWidth(); android.view.ViewGroup.LayoutParams lp = broadcastSpamControlSettingsContainer .getLayoutParams(); lp.width = broadcastSpamControlWidth / 4; broadcastSpamControlSettingsContainer.setLayoutParams(lp); } }); } if (!isUpdate) collapseDetails(DETAIL_SECTIONS); }
From source file:com.leavjenn.smoothdaterangepicker.date.SmoothDateRangePickerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Log.d(TAG, "onCreateView: "); getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); View view = inflater.inflate(R.layout.sdrp_dialog, container); mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header); mDayOfWeekViewEnd = (TextView) view.findViewById(R.id.date_picker_header_end); mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day); mMonthAndDayViewEnd = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day_end); mMonthAndDayView.setOnClickListener(this); mMonthAndDayViewEnd.setOnClickListener(this); mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month); mSelectedMonthTextViewEnd = (TextView) view.findViewById(R.id.date_picker_month_end); mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day); mSelectedDayTextViewEnd = (TextView) view.findViewById(R.id.date_picker_day_end); mYearView = (TextView) view.findViewById(R.id.date_picker_year); mYearViewEnd = (TextView) view.findViewById(R.id.date_picker_year_end); mYearView.setOnClickListener(this); mYearViewEnd.setOnClickListener(this); mDurationView = (LinearLayout) view.findViewById(R.id.date_picker_duration_layout); mDurationView.setOnClickListener(this); mDurationTextView = (TextView) view.findViewById(R.id.date_picker_duration_days); mDurationEditText = (EditText) view.findViewById(R.id.date_picker_duration_days_et); // disable soft keyboard popup when edittext is selected mDurationEditText.setRawInputType(InputType.TYPE_CLASS_TEXT); mDurationEditText.setTextIsSelectable(true); mDurationDayTextView = (TextView) view.findViewById(R.id.tv_duration_day); mDurationArrow = (TextView) view.findViewById(R.id.arrow_start); mDurationArrow.setOnClickListener(this); mDurationArrowEnd = (TextView) view.findViewById(R.id.arrow_end); mDurationArrowEnd.setOnClickListener(this); viewList = new ArrayList<>(); viewList.add(MONTH_AND_DAY_VIEW, mMonthAndDayView); viewList.add(YEAR_VIEW, mYearView);//from w ww.j av a 2s . c o m viewList.add(MONTH_AND_DAY_VIEW_END, mMonthAndDayViewEnd); viewList.add(YEAR_VIEW_END, mYearViewEnd); viewList.add(DURATION_VIEW, mDurationView); int listPosition = -1; int listPositionOffset = 0; int listPositionEnd = -1; int listPositionOffsetEnd = 0; int currentView = MONTH_AND_DAY_VIEW; if (savedInstanceState != null) { mWeekStart = savedInstanceState.getInt(KEY_WEEK_START); mMinYear = savedInstanceState.getInt(KEY_YEAR_START); mMaxYear = savedInstanceState.getInt(KEY_YEAR_END); currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW); listPosition = savedInstanceState.getInt(KEY_LIST_POSITION); listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET); listPositionEnd = savedInstanceState.getInt(KEY_LIST_POSITION_END); listPositionOffsetEnd = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET_END); mMinDate = (Calendar) savedInstanceState.getSerializable(KEY_MIN_DATE); mMaxDate = (Calendar) savedInstanceState.getSerializable(KEY_MAX_DATE); mMinSelectableDate = (Calendar) savedInstanceState.getSerializable(KEY_MIN_DATE_SELECTABLE); highlightedDays = (Calendar[]) savedInstanceState.getSerializable(KEY_HIGHLIGHTED_DAYS); selectableDays = (Calendar[]) savedInstanceState.getSerializable(KEY_SELECTABLE_DAYS); mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK); mAccentColor = savedInstanceState.getInt(KEY_ACCENT); mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE); mDismissOnPause = savedInstanceState.getBoolean(KEY_DISMISS); } final Activity activity = getActivity(); mDayPickerView = new SimpleDayPickerView(activity, this); mYearPickerView = new YearPickerView(activity, this); mDayPickerViewEnd = new SimpleDayPickerView(activity, this); mYearPickerViewEnd = new YearPickerView(activity, this); mNumberPadView = new NumberPadView(activity, this); Resources res = getResources(); mDayPickerDescription = res.getString(R.string.mdtp_day_picker_description); mSelectDay = res.getString(R.string.mdtp_select_day); mYearPickerDescription = res.getString(R.string.mdtp_year_picker_description); mSelectYear = res.getString(R.string.mdtp_select_year); int bgColorResource = mThemeDark ? R.color.mdtp_date_picker_view_animator_dark_theme : R.color.mdtp_date_picker_view_animator; view.setBackgroundColor(activity.getResources().getColor(bgColorResource)); if (mThemeDark) { view.findViewById(R.id.hyphen).setBackgroundColor( activity.getResources().getColor(R.color.date_picker_selector_unselected_dark_theme)); Utils.setMultiTextColorList(activity.getResources().getColorStateList(R.color.sdrp_selector_dark), mDayOfWeekView, mDayOfWeekViewEnd, mSelectedMonthTextView, mSelectedMonthTextViewEnd, mSelectedDayTextView, mSelectedDayTextViewEnd, mYearView, mYearViewEnd, mDurationTextView, mDurationDayTextView, mDurationArrow, mDurationArrowEnd, mDurationEditText, (TextView) view.findViewById(R.id.tv_duration)); } mAnimator = (AccessibleDateAnimator) view.findViewById(R.id.animator); mAnimator.addView(mDayPickerView); mAnimator.addView(mYearPickerView); mAnimator.addView(mDayPickerViewEnd); mAnimator.addView(mYearPickerViewEnd); mAnimator.addView(mNumberPadView); mAnimator.setDateMillis(mCalendar.getTimeInMillis()); Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(ANIMATION_DURATION); mAnimator.setInAnimation(animation); Animation animation2 = new AlphaAnimation(1.0f, 0.0f); animation2.setDuration(ANIMATION_DURATION); mAnimator.setOutAnimation(animation2); Button okButton = (Button) view.findViewById(R.id.ok); okButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (mCallBack != null) { mCallBack.onDateRangeSet(SmoothDateRangePickerFragment.this, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH), mCalendarEnd.get(Calendar.YEAR), mCalendarEnd.get(Calendar.MONTH), mCalendarEnd.get(Calendar.DAY_OF_MONTH)); } dismiss(); } }); okButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium")); Button cancelButton = (Button) view.findViewById(R.id.cancel); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (getDialog() != null) getDialog().cancel(); } }); cancelButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium")); cancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE); //If an accent color has not been set manually, try and get it from the context if (mAccentColor == -1) { int accentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity()); if (accentColor != -1) { mAccentColor = accentColor; } } if (mAccentColor != -1) { if (mDayOfWeekView != null) mDayOfWeekView.setBackgroundColor(mAccentColor); if (mDayOfWeekViewEnd != null) mDayOfWeekViewEnd.setBackgroundColor(mAccentColor); view.findViewById(R.id.layout_container).setBackgroundColor(mAccentColor); view.findViewById(R.id.day_picker_selected_date_layout).setBackgroundColor(mAccentColor); view.findViewById(R.id.day_picker_selected_date_layout_end).setBackgroundColor(mAccentColor); mDurationView.setBackgroundColor(mAccentColor); mDurationEditText.setHighlightColor(Utils.darkenColor(mAccentColor)); mDurationEditText.getBackground().setColorFilter(Utils.darkenColor(mAccentColor), PorterDuff.Mode.SRC_ATOP); okButton.setTextColor(mAccentColor); cancelButton.setTextColor(mAccentColor); mYearPickerView.setAccentColor(mAccentColor); mDayPickerView.setAccentColor(mAccentColor); mYearPickerViewEnd.setAccentColor(mAccentColor); mDayPickerViewEnd.setAccentColor(mAccentColor); } updateDisplay(false); setCurrentView(currentView); if (listPosition != -1) { if (currentView == MONTH_AND_DAY_VIEW) { mDayPickerView.postSetSelection(listPosition); } else if (currentView == YEAR_VIEW) { mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset); } } if (listPositionEnd != -1) { if (currentView == MONTH_AND_DAY_VIEW_END) { mDayPickerViewEnd.postSetSelection(listPositionEnd); } else if (currentView == YEAR_VIEW_END) { mYearPickerViewEnd.postSetSelectionFromTop(listPositionEnd, listPositionOffsetEnd); } } mHapticFeedbackController = new HapticFeedbackController(activity); return view; }
From source file:io.github.a1inani.sphygmo.activity.CardActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_card); toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/*from www .j a v a 2 s. c om*/ try { String lastReading = getLastReadingDate(); Log.d("Test: ", lastReading); TextView date = (TextView) findViewById(R.id.date); date.setText(lastReading); } catch (Exception e) { } updateTable(); drawGraph(); Button viewAll = (Button) findViewById(R.id.read_more); viewAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(CardActivity.this, ViewActivity.class); startActivity(intent); } }); final FloatingActionButton myFab = (FloatingActionButton) this.findViewById(R.id.fab); if (myFab != null) { myFab.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(CardActivity.this); builder.setTitle("Add Reading"); // Get the layout inflater LayoutInflater inflater = CardActivity.this.getLayoutInflater(); final View dialoglayout = inflater.inflate(R.layout.activity_dialog, null); builder.setView(dialoglayout); builder.setPositiveButton("Save", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); builder.setPositiveButton(R.string.save_btn, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); builder.setNegativeButton(R.string.cancel_btn, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); final AlertDialog alert = builder.create(); alert.show(); Button nbutton = alert.getButton(DialogInterface.BUTTON_NEGATIVE); nbutton.setTextColor(Color.parseColor("#882D61")); Button pbutton = alert.getButton(DialogInterface.BUTTON_POSITIVE); pbutton.setTextColor(Color.parseColor("#882D61")); pbutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String systolic = ((EditText) dialoglayout.findViewById(R.id.systolic)).getText() .toString(); String diastolic = ((EditText) dialoglayout.findViewById(R.id.diastolic)).getText() .toString(); String pulse = ((EditText) dialoglayout.findViewById(R.id.pulse)).getText().toString(); if (!systolic.isEmpty() && !diastolic.isEmpty() && !pulse.isEmpty()) { Reading reading = new Reading(Integer.parseInt(systolic), Integer.parseInt(diastolic), Integer.parseInt(pulse)); db.addReading(reading); sys.add(new Entry(Float.parseFloat(systolic), sys.size())); dia.add(new Entry(Float.parseFloat(diastolic), dia.size())); LineDataSet set1 = new LineDataSet(sys, "Systolic"); set1.setAxisDependency(YAxis.AxisDependency.LEFT); set1.setColor(Color.RED); set1.setCircleColor(Color.RED); LineDataSet set2 = new LineDataSet(dia, "Diastolic"); set2.setAxisDependency(YAxis.AxisDependency.LEFT); ArrayList<ILineDataSet> dataSets = new ArrayList<>(); dataSets.add(set1); dataSets.add(set2); ArrayList<String> xVals = new ArrayList<>(); int count = set1.getEntryCount(); for (int i = 0; i < count; i++) { xVals.add(""); } LineData data = new LineData(xVals, dataSets); updateTable(); try { String lastReading = getLastReadingDate(); Log.d("Test: ", lastReading); TextView date = (TextView) findViewById(R.id.date); date.setText(lastReading); } catch (Exception e) { } LineChart lc = (LineChart) findViewById(R.id.chart); lc.setData(data); lc.notifyDataSetChanged(); lc.animateXY(2000, 2000); alert.dismiss(); } else { Snackbar snack = Snackbar.make(findViewById(R.id.coordinatorLayout), "Ensure all the fields are filled.", Snackbar.LENGTH_LONG); View view = snack.getView(); TextView tv = (TextView) view .findViewById(android.support.design.R.id.snackbar_text); tv.setTextColor(Color.WHITE); view.setBackgroundColor( ContextCompat.getColor(CardActivity.this, R.color.colorPrimary)); snack.show(); } } }); } }); } }