Example usage for android.widget ImageView setBackgroundColor

List of usage examples for android.widget ImageView setBackgroundColor

Introduction

In this page you can find the example usage for android.widget ImageView setBackgroundColor.

Prototype

@RemotableViewMethod
public void setBackgroundColor(@ColorInt int color) 

Source Link

Document

Sets the background color for this view.

Usage

From source file:jahirfiquitiva.iconshowcase.activities.ShowcaseActivity.java

@SuppressWarnings("ResourceAsColor")
private void setupDrawer(final Toolbar toolbar, Bundle savedInstanceState) {

    //Initialize PrimaryDrawerItem
    PrimaryDrawerItem home, previews, walls, requests, apply, faqs, zooper, kustom, creditsItem, settingsItem,
            donationsItem;//from w  w w.  j  a v  a 2 s . co  m

    secondaryStart = primaryDrawerItems.length + 1; //marks the first identifier value that should be used

    DrawerBuilder drawerBuilder;

    if (themeMode) { //enabled theme mode, long press added
        drawerBuilder = new DrawerBuilder().withActivity(this).withToolbar(toolbar)
                .withFireOnInitialOnClick(true)
                .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

                    @Override
                    public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                        if (drawerItem != null) {
                            drawerItemClick(drawerItem.getIdentifier());
                        }
                        return false;
                    }
                }).withOnDrawerItemLongClickListener(new Drawer.OnDrawerItemLongClickListener() {

                    @Override
                    public boolean onItemLongClick(View view, int position, IDrawerItem drawerItem) {
                        if (drawerItem.getIdentifier() == iconsPickerIdentifier && mIsPremium) {
                            switchFragment(iconsPickerIdentifier, "Requests", context);
                            drawer.closeDrawer();
                        }
                        return false;
                    }
                });
    } else {
        drawerBuilder = new DrawerBuilder().withActivity(this).withToolbar(toolbar)
                .withFireOnInitialOnClick(true)
                .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

                    @Override
                    public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                        if (drawerItem != null) {
                            drawerItemClick(drawerItem.getIdentifier());
                        }
                        return false;
                    }
                });
    }

    for (int i = 0; i < primaryDrawerItems.length; i++) {
        switch (primaryDrawerItems[i]) {
        case "Main":
            home = new PrimaryDrawerItem().withName(thaHome)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_home)).withIconTintingEnabled(true)
                    .withIdentifier(i + 1);
            drawerBuilder.addDrawerItems(home);
            break;

        case "Previews":
            iconsPickerEnabled = true;
            iconsPickerIdentifier = i + 1;
            previews = new PrimaryDrawerItem().withName(thaPreviews)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_previews))
                    .withIconTintingEnabled(true).withIdentifier(iconsPickerIdentifier);
            drawerBuilder.addDrawerItems(previews);
            break;

        case "Wallpapers":
            wallsEnabled = true;
            wallsIdentifier = i + 1;
            walls = new PrimaryDrawerItem().withName(thaWalls)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_wallpapers))
                    .withIconTintingEnabled(true).withIdentifier(wallsIdentifier);
            drawerBuilder.addDrawerItems(walls);
            break;

        case "Requests":
            requests = new PrimaryDrawerItem().withName(thaRequest)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_request))
                    .withIconTintingEnabled(true).withIdentifier(i + 1);
            drawerBuilder.addDrawerItems(requests);
            break;

        case "Apply":
            applyIdentifier = i + 1;
            apply = new PrimaryDrawerItem().withName(thaApply)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_apply))
                    .withIconTintingEnabled(true).withIdentifier(applyIdentifier);
            drawerBuilder.addDrawerItems(apply);
            break;

        case "FAQs":
            faqs = new PrimaryDrawerItem().withName(thaFAQs)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_questions))
                    .withIconTintingEnabled(true).withIdentifier(i + 1);
            drawerBuilder.addDrawerItems(faqs);
            break;

        case "Zooper":
            WITH_ZOOPER_SECTION = true;
            zooper = new PrimaryDrawerItem().withName(thaZooper)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_zooper_kustom))
                    .withIconTintingEnabled(true).withIdentifier(i + 1);
            drawerBuilder.addDrawerItems(zooper);
            break;

        case "Kustom":
            kustom = new PrimaryDrawerItem().withName(thaKustom)
                    .withIcon(Utils.getVectorDrawable(context, R.drawable.ic_zooper_kustom))
                    .withIconTintingEnabled(true).withIdentifier(i + 1);
            drawerBuilder.addDrawerItems(kustom);
        }
    }

    drawerBuilder.addDrawerItems(new DividerDrawerItem()); //divider between primary and secondary

    for (int i = 0; i < secondaryDrawerItems.length; i++) {
        switch (secondaryDrawerItems[i]) {
        case "Credits":
            creditsItem = new SecondaryDrawerItem().withName(thaCredits).withIdentifier(i + secondaryStart);
            drawerBuilder.addDrawerItems(creditsItem);
            break;
        case "Settings":
            settingsItem = new SecondaryDrawerItem().withName(thaSettings).withIdentifier(i + secondaryStart);
            drawerBuilder.addDrawerItems(settingsItem);
            break;
        case "Donations":
            donationsItem = new SecondaryDrawerItem().withName(thaDonate).withIdentifier(i + secondaryStart);
            drawerBuilder.addDrawerItems(donationsItem);
            break;
        }
    }

    drawerBuilder.withSavedInstance(savedInstanceState);

    String headerAppName = "", headerAppVersion = "";

    boolean withDrawerTexts;

    if (ENABLE_DEV_OPTIONS) {
        withDrawerTexts = mPrefs.getDevDrawerTexts();
    } else {
        withDrawerTexts = getResources().getBoolean(R.bool.with_drawer_texts);
    }

    if (withDrawerTexts) {
        headerAppName = getResources().getString(R.string.app_long_name);
        headerAppVersion = "v " + Utils.getAppVersion(this);
    }

    switch (drawerHeaderStyle) {
    case 1:
        AccountHeader drawerHeader = new AccountHeaderBuilder().withActivity(this)
                .withHeaderBackground(
                        ThemeUtils.darkTheme
                                ? ThemeUtils.transparent ? R.drawable.drawer_header_clear
                                        : R.drawable.drawer_header_dark
                                : R.drawable.drawer_header_light)
                .withSelectionFirstLine(headerAppName).withSelectionSecondLine(headerAppVersion)
                .withProfileImagesClickable(false).withResetDrawerOnProfileListClick(false)
                .withSelectionListEnabled(false).withSelectionListEnabledForSingleProfile(false)
                .withSavedInstance(savedInstanceState).build();

        drawerBuilder.withAccountHeader(drawerHeader);
        break;
    case 2:
        drawerBuilder.withHeader(R.layout.mini_drawer_header);
        break;
    case 3:
        break;
    }

    drawer = drawerBuilder.build();

    if (drawerHeaderStyle == 2) {
        ImageView miniHeader = (ImageView) drawer.getHeader().findViewById(R.id.mini_drawer_header);
        miniHeader.getLayoutParams().height = UIUtils.getActionBarHeight(this)
                + UIUtils.getStatusBarHeight(this);
        TextView appVersion = (TextView) drawer.getHeader().findViewById(R.id.text_app_version);
        TextView appName = (TextView) drawer.getHeader().findViewById(R.id.text_app_name);

        boolean miniHeaderSolidColor;

        if (ENABLE_DEV_OPTIONS) {
            miniHeaderSolidColor = !(mPrefs.getDevMiniDrawerHeaderPicture());
        } else {
            miniHeaderSolidColor = context.getResources().getBoolean(R.bool.mini_header_solid_color);
        }

        if (miniHeaderSolidColor) {
            int backgroundColor = ThemeUtils.darkTheme
                    ? ContextCompat.getColor(context, R.color.dark_theme_primary)
                    : ContextCompat.getColor(context, R.color.light_theme_primary);
            miniHeader.setBackgroundColor(backgroundColor);
            int iconsColor = ThemeUtils.darkTheme ? ContextCompat.getColor(this, R.color.toolbar_text_dark)
                    : ContextCompat.getColor(this, R.color.toolbar_text_light);
            appVersion.setTextColor(iconsColor);
            appName.setTextColor(iconsColor);
        } else {
            miniHeader.setImageDrawable(ThemeUtils.darkTheme
                    ? ThemeUtils.transparent
                            ? ContextCompat.getDrawable(context, R.drawable.drawer_header_clear)
                            : ContextCompat.getDrawable(context, R.drawable.drawer_header_dark)
                    : ContextCompat.getDrawable(context, R.drawable.drawer_header_light));
            appVersion.setTextColor(ContextCompat.getColor(context, android.R.color.white));
            appName.setTextColor(ContextCompat.getColor(context, android.R.color.white));
        }
        appName.setText(headerAppName);
        appVersion.setText(headerAppVersion);
    }

}

From source file:com.ptapp.activity.SessionsFragment.java

@Override
public void bindCollectionItemView(Context context, View view, final int groupId, int indexInGroup,
        int dataIndex, Object tag) {
    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;//from   w ww  .  j a v  a 2 s.c  o m
    }

    Log.v(TAG, "test collection view cursor data: " + mCursor.getString(0) + ", " + mCursor.getString(1) + ", "
            + mCursor.getString(2) + ", " + mCursor.getString(3) + ", ");

    final String groupJid = mCursor.getString(SessionsQuery.GROUP_JID);
    final String classSubjectId = mCursor.getString(SessionsQuery.CLASS_SUBJECT_ID);

    if (classSubjectId == null) {
        return;
    }

    // first, read session info from cursor and put it in convenience variables
    final String courseTitle = mCursor.getString(SessionsQuery.GROUP_NAME);
    /*final String courseTitle = mCursor.getString(SessionsQuery.SUBJECT_TITLE);
    final String className = mCursor.getString(SessionsQuery.CLASS_TITLE)
        + "-" + mCursor.getString(SessionsQuery.SECTION_TITLE);*/
    /*final String educatorId = mCursor.getString(SessionsQuery.EDUCATOR_ID);
    final String classId = mCursor.getString(SessionsQuery.CLASS_ID);
            
    final String studentId = mCursor.getString(SessionsQuery.STUDENT_ID);*/
    /*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);*/
    int sessionColor = 0;
    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) : "";*/
    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);
    final View grpmsgView = (ImageView) view.findViewById(R.id.session_grp_msg);

    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_" + classSubjectId);

    // 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);
    int subjPath = R.drawable.nophotoavailable;
    //TODO:Temporary task to generate screenshots
    if (courseTitle != null) {
        if (courseTitle.contains("English")) {
            subjPath = R.drawable.logo_english;
        } else if (courseTitle.contains("Math")) {
            subjPath = R.drawable.logo_math;
        } else if (courseTitle.contains("Punjabi")) {
            subjPath = R.drawable.course_punjabi;
        } else if (courseTitle.contains("Hindi")) {
            subjPath = R.drawable.course_hindi;
        } else if (courseTitle.contains("German")) {
            subjPath = R.drawable.course_german;
        } else if (courseTitle.contains("Dutch")) {
            subjPath = R.drawable.course_dutch;
        } else if (courseTitle.contains("Science")) {
            subjPath = R.drawable.course_science;
        } else if (courseTitle.contains("French")) {
            subjPath = R.drawable.course_french;
        }
    }

    /*if (!TextUtils.isEmpty(photo)) {*/
    //mImageLoader.loadImage(photo, photoView, true /*crop*/);
    Picasso.with(context) //
            .load(subjPath) //
            .placeholder(CommonConstants.LOADING) //
            .error(CommonConstants.ERROR_IMAGE) //
            .fit() //
            .into(photoView);

    /*} else {
    // cleaning the (potentially) recycled photoView, in case this session has no photo:
    photoView.setImageDrawable(null);
    }*/

    // render title
    /*titleView.setText(courseTitle == null ? "?" : courseTitle);*/
    titleView.setText(courseTitle == null ? "?" : courseTitle);

    // 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);*/
        //subtitleView.setText(className == null ? "?" : className);
    } else if (shortSubtitleView != null) {
        //Dummy data
        /*shortSubtitleView.setText("25");*/
        shortSubtitleView.setText(mCursor.getString(SessionsQuery.MEMBER_COUNT));
        shortSubtitleView.setGravity(Gravity.RIGHT);
        /*shortSubtitleView.setText(UIUtils.formatSessionSubtitle(
            sessionStart, sessionEnd, roomName, mBuffer, context, true) + liveNowText);*/
        //shortSubtitleView.setText(className == null ? "?" : className);
    }

    // render category
    if (categoryView != null) {
        /*categoryView.setText(className == null ? "?" : className);*/
    }

    // 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 (!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(View.INVISIBLE);
        //liveNowBadge.setVisibility(happeningNow && hasLivestream ? View.VISIBLE : View.GONE);
    }

    // if this view is clicked, open the session details view
    final View finalPhotoView = photoView;
    final int studentGroupId = mCursor.getInt(SessionsQuery.GROUP_ID);

    sessionTargetView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mCallbacks.onSessionSelected(classSubjectId, courseTitle, groupJid, studentGroupId, finalPhotoView);
        }
    });

    // animate this card
    if (dataIndex > mMaxDataIndexAnimated) {
        mMaxDataIndexAnimated = dataIndex;
    }

    //if this view is clicked, open group messages chatting screen
    if (grpmsgView != null) {
        grpmsgView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.i(TAG, "grp msg image clicked, opening group messages screen");
                Intent intent = new Intent(getActivity(), EducatorGroupMsgActivity.class);
                startActivity(intent);
            }
        });
    }
}

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 ww  .  j a  va 2s . 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 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) {/*from  w ww .j a  v a  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);
    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  a  v  a  2  s.  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.saarang.samples.apps.iosched.ui.SessionsFragment.java

@Override
public void bindCollectionItemView(Context context, View view, int groupId, int indexInGroup, int dataIndex,
        Object tag) {//from  ww w  .j  a  va  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 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(com.saarang.samples.apps.iosched.R.color.default_session_color)
            : sessionColor;
    int darkSessionColor = 0;
    final String snippet = mIsSearchCursor ? mCursor.getString(SessionsQuery.SNIPPET) : null;
    final Spannable styledSnippet = mIsSearchCursor ? UIUtils.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(com.saarang.samples.apps.iosched.R.id.session_title);
    final TextView subtitleView = (TextView) view
            .findViewById(com.saarang.samples.apps.iosched.R.id.session_subtitle);
    final TextView shortSubtitleView = (TextView) view
            .findViewById(com.saarang.samples.apps.iosched.R.id.session_subtitle_short);
    final TextView snippetView = (TextView) view
            .findViewById(com.saarang.samples.apps.iosched.R.id.session_snippet);
    final TextView abstractView = (TextView) view
            .findViewById(com.saarang.samples.apps.iosched.R.id.session_abstract);
    final TextView categoryView = (TextView) view
            .findViewById(com.saarang.samples.apps.iosched.R.id.session_category);
    final View sessionTargetView = view.findViewById(com.saarang.samples.apps.iosched.R.id.session_target);

    if (sessionColor == 0) {
        // use default
        sessionColor = mDefaultSessionColor;
    }

    if (mNoTrackBranding) {
        sessionColor = getResources()
                .getColor(com.saarang.samples.apps.iosched.R.color.no_track_branding_session_color);
    }

    darkSessionColor = UIUtils.scaleSessionColorToDefaultBG(sessionColor);

    ImageView photoView = (ImageView) view
            .findViewById(com.saarang.samples.apps.iosched.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(
                        com.saarang.samples.apps.iosched.R.color.no_track_branding_session_tile_overlay),
                PorterDuff.Mode.SRC_ATOP) : UIUtils.makeSessionImageScrimColorFilter(darkSessionColor));
    } else {
        photoView = (ImageView) view.findViewById(com.saarang.samples.apps.iosched.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(" ");
        } 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("");
        }
    }

    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("");
    }

    // show or hide the "in my schedule" indicator
    view.findViewById(com.saarang.samples.apps.iosched.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(com.saarang.samples.apps.iosched.R.id.message_card_container_wide);
        final View abstractContainer = view
                .findViewById(com.saarang.samples.apps.iosched.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(com.saarang.samples.apps.iosched.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.colorchief.colorchief.MainActivity.java

public void hsvButtonClick(View view) {
    ImageView colourBlock22 = (ImageView) findViewById(R.id.colour22);
    ColorDrawable colourDrawable = (ColorDrawable) colourBlock22.getBackground();
    int setColour = colourDrawable.getColor();
    int newColour = 0;
    float hsvColour[] = new float[3];
    Color.colorToHSV(setColour, hsvColour);

    if (view.getId() == R.id.hueDownButton) {

        //Log.d(TAG, "Hue Down Button Clicked");

        hsvColour[0] = hsvColour[0] - H_ADJUST;
        if (hsvColour[0] < 0f)
            hsvColour[0] = 360f + hsvColour[0];

    }//from w  ww .  j  a v a 2  s. com
    if (view.getId() == R.id.hueUpButton) {
        //Log.d(TAG, "Hue Up Button Clicked");

        hsvColour[0] = hsvColour[0] + H_ADJUST;
        if (hsvColour[0] > 360f)
            hsvColour[0] = hsvColour[0] - 360f;

    }
    if (view.getId() == R.id.saturationDownButton) {
        //Log.d(TAG, "Saturation Down Button Clicked");

        hsvColour[1] = hsvColour[1] - S_ADJUST;
        //if (hsvColour[1] < 0f ) hsvColour[1] = 1f + hsvColour[1];
        if (hsvColour[1] < 0f)
            hsvColour[1] = 0f;

    }
    if (view.getId() == R.id.saturationUpButton) {
        //Log.d(TAG, "Saturation Up Button Clicked");

        hsvColour[1] = hsvColour[1] + S_ADJUST;
        //if (hsvColour[1] > 1f ) hsvColour[1] = hsvColour[1] - 1f;
        if (hsvColour[1] > 1f)
            hsvColour[1] = 1f;

    }
    if (view.getId() == R.id.lightnessDownButton) {
        //Log.d(TAG, "Lightness Down Button Clicked");

        hsvColour[2] = hsvColour[2] - V_ADJUST;
        //if (hsvColour[2] < 0f ) hsvColour[2] = 1f + hsvColour[2];
        if (hsvColour[2] < 0f)
            hsvColour[2] = 0f;

    }
    if (view.getId() == R.id.lightnessUpButton) {
        //Log.d(TAG, "Lightness Up Button Clicked");

        hsvColour[2] = hsvColour[2] + V_ADJUST;
        //if (hsvColour[2] > 1f ) hsvColour[2] = hsvColour[2] - 1f;
        if (hsvColour[2] > 1f)
            hsvColour[2] = 1f;
    }

    newColour = Color.HSVToColor(hsvColour);
    colourBlock22.setBackgroundColor(newColour);

}

From source file:org.telegram.ui.ChatActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (fragmentView == null) {
        fragmentView = inflater.inflate(R.layout.chat_layout, container, false);

        sizeNotifierRelativeLayout = (SizeNotifierRelativeLayout) fragmentView.findViewById(R.id.chat_layout);
        sizeNotifierRelativeLayout.delegate = this;
        contentView = sizeNotifierRelativeLayout;

        emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
        chatListView = (LayoutListView) fragmentView.findViewById(R.id.chat_list_view);
        chatListView.setAdapter(chatAdapter = new ChatAdapter(parentActivity));
        topPanel = fragmentView.findViewById(R.id.top_panel);
        topPlaneClose = (ImageView) fragmentView.findViewById(R.id.top_plane_close);
        topPanelText = (TextView) fragmentView.findViewById(R.id.top_panel_text);
        bottomOverlay = fragmentView.findViewById(R.id.bottom_overlay);
        bottomOverlayText = (TextView) fragmentView.findViewById(R.id.bottom_overlay_text);
        View bottomOverlayChat = fragmentView.findViewById(R.id.bottom_overlay_chat);
        progressView = fragmentView.findViewById(R.id.progressLayout);
        pagedownButton = fragmentView.findViewById(R.id.pagedown_button);
        audioSendButton = (ImageButton) fragmentView.findViewById(R.id.chat_audio_send_button);
        View progressViewInner = progressView.findViewById(R.id.progressLayoutInner);

        updateContactStatus();/*from   w  w  w  . j  a v  a 2s.c om*/

        ImageView backgroundImage = (ImageView) fragmentView.findViewById(R.id.background_image);

        SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig",
                Activity.MODE_PRIVATE);
        int selectedBackground = preferences.getInt("selectedBackground", 1000001);
        int selectedColor = preferences.getInt("selectedColor", 0);
        if (selectedColor != 0) {
            backgroundImage.setBackgroundColor(selectedColor);
            chatListView.setCacheColorHint(selectedColor);
        } else {
            chatListView.setCacheColorHint(0);
            if (selectedBackground == 1000001) {
                backgroundImage.setImageResource(R.drawable.background_hd);
            } else {
                File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg");
                if (toFile.exists()) {
                    if (ApplicationLoader.cachedWallpaper != null) {
                        backgroundImage.setImageBitmap(ApplicationLoader.cachedWallpaper);
                    } else {
                        backgroundImage.setImageURI(Uri.fromFile(toFile));
                        if (backgroundImage.getDrawable() instanceof BitmapDrawable) {
                            ApplicationLoader.cachedWallpaper = ((BitmapDrawable) backgroundImage.getDrawable())
                                    .getBitmap();
                        }
                    }
                    isCustomTheme = true;
                } else {
                    backgroundImage.setImageResource(R.drawable.background_hd);
                }
            }
        }

        if (currentEncryptedChat != null) {
            secretChatPlaceholder = contentView.findViewById(R.id.secret_placeholder);
            if (isCustomTheme) {
                secretChatPlaceholder.setBackgroundResource(R.drawable.system_black);
            } else {
                secretChatPlaceholder.setBackgroundResource(R.drawable.system_blue);
            }
            secretViewStatusTextView = (TextView) contentView.findViewById(R.id.invite_text);
            secretChatPlaceholder.setPadding(Utilities.dp(16), Utilities.dp(12), Utilities.dp(16),
                    Utilities.dp(12));

            View v = contentView.findViewById(R.id.secret_placeholder);
            v.setVisibility(View.VISIBLE);

            if (currentEncryptedChat.admin_id == UserConfig.clientUserId) {
                if (currentUser.first_name.length() > 0) {
                    secretViewStatusTextView
                            .setText(String.format(getStringEntry(R.string.EncryptedPlaceholderTitleOutgoing),
                                    currentUser.first_name));
                } else {
                    secretViewStatusTextView.setText(String.format(
                            getStringEntry(R.string.EncryptedPlaceholderTitleOutgoing), currentUser.last_name));
                }
            } else {
                if (currentUser.first_name.length() > 0) {
                    secretViewStatusTextView
                            .setText(String.format(getStringEntry(R.string.EncryptedPlaceholderTitleIncoming),
                                    currentUser.first_name));
                } else {
                    secretViewStatusTextView.setText(String.format(
                            getStringEntry(R.string.EncryptedPlaceholderTitleIncoming), currentUser.last_name));
                }
            }

            updateSecretStatus();
        }

        if (isCustomTheme) {
            progressViewInner.setBackgroundResource(R.drawable.system_loader2);
            emptyView.setBackgroundResource(R.drawable.system_black);
        } else {
            progressViewInner.setBackgroundResource(R.drawable.system_loader1);
            emptyView.setBackgroundResource(R.drawable.system_blue);
        }
        emptyView.setPadding(Utilities.dp(7), Utilities.dp(1), Utilities.dp(7), Utilities.dp(1));

        if (currentUser != null && currentUser.id == 333000) {
            emptyView.setText(R.string.GotAQuestion);
        }

        chatListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> adapter, View view, int position, long id) {
                if (mActionMode == null) {
                    createMenu(view, false);
                }
                return true;
            }
        });

        chatListView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView absListView, int i) {

            }

            @Override
            public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount,
                    int totalItemCount) {
                if (visibleItemCount > 0) {
                    if (firstVisibleItem <= 4) {
                        if (!endReached && !loading) {
                            if (messagesByDays.size() != 0) {
                                MessagesController.Instance.loadMessages(dialog_id, 0, 20, maxMessageId,
                                        !cacheEndReaced, minDate, classGuid, false, false);
                            } else {
                                MessagesController.Instance.loadMessages(dialog_id, 0, 20, 0, !cacheEndReaced,
                                        minDate, classGuid, false, false);
                            }
                            loading = true;
                        }
                    }
                    if (firstVisibleItem + visibleItemCount >= totalItemCount - 6) {
                        if (!unread_end_reached && !loadingForward) {
                            MessagesController.Instance.loadMessages(dialog_id, 0, 20, minMessageId, true,
                                    maxDate, classGuid, false, true);
                            loadingForward = true;
                        }
                    }
                    if (firstVisibleItem + visibleItemCount == totalItemCount && unread_end_reached) {
                        showPagedownButton(false, true);
                    }
                } else {
                    showPagedownButton(false, false);
                }
            }
        });

        messsageEditText = (EditText) fragmentView.findViewById(R.id.chat_text_edit);

        sendButton = (ImageButton) fragmentView.findViewById(R.id.chat_send_button);
        sendButton.setEnabled(false);
        sendButton.setVisibility(View.INVISIBLE);
        emojiButton = (ImageView) fragmentView.findViewById(R.id.chat_smile_button);

        if (loading && messages.isEmpty()) {
            progressView.setVisibility(View.VISIBLE);
            chatListView.setEmptyView(null);
        } else {
            progressView.setVisibility(View.GONE);
            if (currentEncryptedChat == null) {
                chatListView.setEmptyView(emptyView);
            } else {
                chatListView.setEmptyView(secretChatPlaceholder);
            }
        }

        emojiButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (emojiPopup == null) {
                    showEmojiPopup(true);
                } else {
                    showEmojiPopup(!emojiPopup.isShowing());
                }
            }
        });

        messsageEditText.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View view, int i, KeyEvent keyEvent) {
                if (i == 4 && !keyboardVisible && emojiPopup != null && emojiPopup.isShowing()) {
                    if (keyEvent.getAction() == 1) {
                        showEmojiPopup(false);
                    }
                    return true;
                } else if (i == KeyEvent.KEYCODE_ENTER && sendByEnter
                        && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    sendMessage();
                    return true;
                }
                return false;
            }
        });

        messsageEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                if (i == EditorInfo.IME_ACTION_SEND) {
                    sendMessage();
                    return true;
                } else if (sendByEnter) {
                    if (keyEvent != null && i == EditorInfo.IME_NULL
                            && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                        sendMessage();
                        return true;
                    }
                }
                return false;
            }
        });

        sendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sendMessage();
            }
        });

        audioSendButton.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
                    startRecording();
                } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                    stopRecording();
                }
                return false;
            }
        });

        pagedownButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (unread_end_reached || first_unread_id == 0) {
                    chatListView.setSelectionFromTop(messages.size() - 1,
                            -10000 - chatListView.getPaddingTop());
                } else {
                    messages.clear();
                    messagesByDays.clear();
                    messagesDict.clear();
                    progressView.setVisibility(View.VISIBLE);
                    chatListView.setEmptyView(null);
                    maxMessageId = Integer.MAX_VALUE;
                    minMessageId = Integer.MIN_VALUE;
                    maxDate = Integer.MIN_VALUE;
                    minDate = 0;
                    MessagesController.Instance.loadMessages(dialog_id, 0, 30, 0, true, 0, classGuid, true,
                            false);
                    loading = true;
                    chatAdapter.notifyDataSetChanged();
                }
            }
        });

        checkSendButton();

        messsageEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                String message = charSequence.toString().trim();
                message = message.replaceAll("\n\n+", "\n\n");
                message = message.replaceAll(" +", " ");
                sendButton.setEnabled(message.length() != 0);
                checkSendButton();

                if (message.length() != 0 && lastTypingTimeSend < System.currentTimeMillis() - 5000
                        && !ignoreTextChange) {
                    int currentTime = ConnectionsManager.Instance.getCurrentTime();
                    if (currentUser != null && currentUser.status != null
                            && currentUser.status.expires < currentTime
                            && currentUser.status.was_online < currentTime) {
                        return;
                    }
                    lastTypingTimeSend = System.currentTimeMillis();
                    MessagesController.Instance.sendTyping(dialog_id, classGuid);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {
                if (sendByEnter && editable.length() > 0 && editable.charAt(editable.length() - 1) == '\n') {
                    sendMessage();
                }
                int i = 0;
                ImageSpan[] arrayOfImageSpan = editable.getSpans(0, editable.length(), ImageSpan.class);
                int j = arrayOfImageSpan.length;
                while (true) {
                    if (i >= j) {
                        Emoji.replaceEmoji(editable);
                        return;
                    }
                    editable.removeSpan(arrayOfImageSpan[i]);
                    i++;
                }
            }
        });

        bottomOverlayChat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (currentChat != null) {
                    MessagesController.Instance.deleteDialog(-currentChat.id, 0, false);
                    finishFragment();
                }
            }
        });

        chatListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (mActionMode != null) {
                    processRowSelect(view);
                    return;
                }
                if (!spanClicked(chatListView, view, R.id.chat_message_text)) {
                    createMenu(view, true);
                }
            }
        });

        chatListView.setOnTouchListener(new OnSwipeTouchListener() {
            public void onSwipeRight() {
                try {
                    if (visibleDialog != null) {
                        visibleDialog.dismiss();
                        visibleDialog = null;
                    }
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
                finishFragment(true);
            }

            public void onSwipeLeft() {
                if (swipeOpening) {
                    return;
                }
                try {
                    if (visibleDialog != null) {
                        visibleDialog.dismiss();
                        visibleDialog = null;
                    }
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
                if (avatarImageView != null) {
                    swipeOpening = true;
                    avatarImageView.performClick();
                }
            }

            @Override
            public void onTouchUp(MotionEvent event) {
                mLastTouch.right = (int) event.getX();
                mLastTouch.bottom = (int) event.getY();
            }
        });

        emptyView.setOnTouchListener(new OnSwipeTouchListener() {
            public void onSwipeRight() {
                finishFragment(true);
            }

            public void onSwipeLeft() {
                if (swipeOpening) {
                    return;
                }
                if (avatarImageView != null) {
                    swipeOpening = true;
                    avatarImageView.performClick();
                }
            }
        });
        if (currentChat != null && (currentChat instanceof TLRPC.TL_chatForbidden || currentChat.left)) {
            bottomOverlayChat.setVisibility(View.VISIBLE);
        } else {
            bottomOverlayChat.setVisibility(View.GONE);
        }
    } else {
        ViewGroup parent = (ViewGroup) fragmentView.getParent();
        if (parent != null) {
            parent.removeView(fragmentView);
        }
    }
    return fragmentView;
}

From source file:com.android.launcher3.Launcher.java

/**
 * Finds all the views we need and configure them properly.
 *//*w w  w  .  j  ava  2s.c o  m*/
private void setupViews() {
    mLauncherView = findViewById(R.id.launcher);
    mDragLayer = (DragLayer) findViewById(R.id.drag_layer);
    mFocusHandler = mDragLayer.getFocusIndicatorHelper();
    mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace);
    mQsbContainer = mDragLayer.findViewById(
            mDeviceProfile.isVerticalBarLayout() ? R.id.workspace_blocked_row : R.id.qsb_container);
    mWorkspace.initParentViews(mDragLayer);

    mLauncherView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);

    // Setup the drag layer
    mDragLayer.setup(this, mDragController, mAllAppsController);

    // Setup the hotseat
    mHotseat = (Hotseat) findViewById(R.id.hotseat);
    if (mHotseat != null) {
        mHotseat.setOnLongClickListener(this);
    }

    // Setup the overview panel
    setupOverviewPanel();

    setuphome();

    // Setup the workspace
    mWorkspace.setHapticFeedbackEnabled(false);
    mWorkspace.setOnLongClickListener(this);
    mWorkspace.setup(mDragController);
    // Until the workspace is bound, ensure that we keep the wallpaper offset locked to the
    // default state, otherwise we will update to the wrong offsets in RTL
    mWorkspace.lockWallpaperToDefaultPage();
    mDragController.addDragListener(mWorkspace);

    // Get the search/delete/uninstall bar
    mDropTargetBar = (DropTargetBar) mDragLayer.findViewById(R.id.drop_target_bar);

    // Setup Apps and Widgets
    mAppsView = (AllAppsContainerView) findViewById(R.id.apps_view);
    mWidgetsView = (WidgetsContainerView) findViewById(R.id.widgets_view);
    if (mLauncherCallbacks != null && mLauncherCallbacks.getAllAppsSearchBarController() != null) {
        mAppsView.setSearchBarController(mLauncherCallbacks.getAllAppsSearchBarController());
    } else {
        mAppsView.setSearchBarController(new DefaultAppSearchController());
    }

    // Setup the drag controller (drop targets have to be added in reverse order in priority)
    mDragController.setDragScoller(mWorkspace);
    mDragController.setScrollView(mDragLayer);
    mDragController.setMoveTarget(mWorkspace);
    mDragController.addDropTarget(mWorkspace);
    mDropTargetBar.setup(mDragController);

    if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP) {
        mAllAppsController.setupViews(mAppsView, mHotseat, mWorkspace);
    }

    if (TestingUtils.MEMORY_DUMP_ENABLED) {
        TestingUtils.addWeightWatcher(this);
    }

    FrameLayout gBar = (FrameLayout) findViewById(R.id.g_bar);

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
        FrameLayout.LayoutParams gBarLayout = (FrameLayout.LayoutParams) gBar.getLayoutParams();
        gBarLayout.width = Utils.getScreenXDimension(this) - Utils.getScreenXDimension(this) / 6;
        gBar.setLayoutParams(gBarLayout);
    } else {
        FrameLayout.LayoutParams gBarLayout = (FrameLayout.LayoutParams) gBar.getLayoutParams();
        gBarLayout.width = Utils.getScreenYDimension(this) - Utils.getScreenYDimension(this) / 12;
        gBar.setLayoutParams(gBarLayout);
    }

    gBar.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            startSearch("", false, null, true);
        }
    });

    ImageView gSearch = (ImageView) findViewById(R.id.g_search);
    gSearch.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            startSearch("", false, null, true);
        }
    });

    FrameLayout.LayoutParams gSearchLayout = (FrameLayout.LayoutParams) gSearch.getLayoutParams();
    gSearchLayout.leftMargin = 30;
    gSearch.setLayoutParams(gSearchLayout);

    ImageView gSearchMic = (ImageView) findViewById(R.id.g_search_mic);
    if (IS_ALLOW_MIC) {
        gSearchMic.setVisibility(View.VISIBLE);
        gSearchMic.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                startActivityForResult(intent, RECOGNIZER_REQ_CODE);
            }
        });
    } else {
        gSearchMic.setVisibility(View.GONE);
    }

    FrameLayout.LayoutParams gSearchMicLayout = (FrameLayout.LayoutParams) gSearchMic.getLayoutParams();
    gSearchMicLayout.rightMargin = 30;
    gSearchMic.setLayoutParams(gSearchMicLayout);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        if (Utilities.isAllowNightModePrefEnabled(getApplicationContext())) {
            gBar.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.shape_night));
            gSearch.setImageDrawable(
                    ContextCompat.getDrawable(getApplicationContext(), R.drawable.g_icon_night));
            gSearch.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.night_color));
            gSearchMic
                    .setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.mic_night));
            gSearchMic.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.night_color));
        } else {
            gBar.setBackground(ContextCompat.getDrawable(getApplicationContext(), R.drawable.shape));
            gSearch.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.g_icon));
            gSearch.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.white));
            gSearchMic.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.mic));
            gSearchMic
                    .setBackgroundColor(ContextCompat.getColor(getApplicationContext(), android.R.color.white));
        }
    }

    if (!Utilities.isAllowPersisentSearchBarPrefEnabled(getApplicationContext())) {
        gBar.setVisibility(View.GONE);
        gSearch.setVisibility(View.GONE);
        gSearchMic.setVisibility(View.GONE);
    } else {
        gBar.setVisibility(View.VISIBLE);
        gSearch.setVisibility(View.VISIBLE);
        if (IS_ALLOW_MIC) {
            gSearchMic.setVisibility(View.VISIBLE);
        } else {
            gSearchMic.setVisibility(View.GONE);
        }
    }

}