Example usage for android.widget LinearLayout setBackgroundResource

List of usage examples for android.widget LinearLayout setBackgroundResource

Introduction

In this page you can find the example usage for android.widget LinearLayout setBackgroundResource.

Prototype

@RemotableViewMethod
public void setBackgroundResource(@DrawableRes int resid) 

Source Link

Document

Set the background to a given resource.

Usage

From source file:rosmi.acagild.alarmclock.ringing.ShareFragment.java

private static void drawStamp(Context context, Bitmap bitmap, String question) {
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(bitmap, 0, 0, null);

    float opacity = 0.7f;
    int horizontalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int verticalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int textSize = 16; // defined in SP
    int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16,
            context.getResources().getDisplayMetrics());

    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    layout.setBackgroundResource(R.drawable.rounded_corners);
    layout.getBackground().setAlpha((int) (opacity * 255));
    layout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);

    ImageView logo = new ImageView(context);
    logo.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.ic_launcher));
    layout.addView(logo);/*from   www.  j  a va2s .  co m*/

    TextView textView = new TextView(context);
    textView.setVisibility(View.VISIBLE);
    if (question != null) {
        textView.setText(question);
    } else {
        textView.setText("Mimicker");
    }
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
    textView.setPadding(horizontalPadding, 0, 0, 0);

    LinearLayout.LayoutParams centerInParent = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    centerInParent.gravity = Gravity.CENTER_VERTICAL;
    layout.addView(textView, centerInParent);

    layout.measure(canvas.getWidth(), height);
    layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

    canvas.translate(horizontalPadding, (float) (canvas.getHeight() * 0.8 - height));
    float scale = Math.min(1.0f, canvas.getWidth() / 1080f);
    canvas.scale(scale, scale);
    layout.draw(canvas);
}

From source file:com.microsoft.mimickeralarm.ringing.ShareFragment.java

private static void drawStamp(Context context, Bitmap bitmap, String question) {
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(bitmap, 0, 0, null);

    float opacity = 0.7f;
    int horizontalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int verticalPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 10,
            context.getResources().getDisplayMetrics());
    int textSize = 16; // defined in SP
    int height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16,
            context.getResources().getDisplayMetrics());

    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.HORIZONTAL);
    layout.setBackgroundResource(R.drawable.rounded_corners);
    layout.getBackground().setAlpha((int) (opacity * 255));
    layout.setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding);

    ImageView logo = new ImageView(context);
    logo.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.ic_launcher_no_bg));
    layout.addView(logo);//from  w  w w  . j a  v  a 2 s  .c  o m

    TextView textView = new TextView(context);
    textView.setVisibility(View.VISIBLE);
    if (question != null) {
        textView.setText(question);
    } else {
        textView.setText("Mimicker");
    }
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, textSize);
    textView.setPadding(horizontalPadding, 0, 0, 0);

    LinearLayout.LayoutParams centerInParent = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    centerInParent.gravity = Gravity.CENTER_VERTICAL;
    layout.addView(textView, centerInParent);

    layout.measure(canvas.getWidth(), height);
    layout.layout(0, 0, layout.getMeasuredWidth(), layout.getMeasuredHeight());

    canvas.translate(horizontalPadding, (float) (canvas.getHeight() * 0.8 - height));
    float scale = Math.min(1.0f, canvas.getWidth() / 1080f);
    canvas.scale(scale, scale);
    layout.draw(canvas);
}

From source file:com.kaedea.frontia.demo.DemoListFragment.java

@SuppressWarnings("ResourceType")
public static View getItemViewLayout(Context context) {
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER_VERTICAL);
    int[] attrs = new int[] { R.attr.selectableItemBackground };
    TypedArray typedArray = context.obtainStyledAttributes(attrs);
    int backgroundResource = typedArray.getResourceId(0, 0);
    linearLayout.setBackgroundResource(backgroundResource);
    typedArray.recycle();/*  w  w  w  .ja v a 2s  .  c  o m*/
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    linearLayout.setLayoutParams(layoutParams);
    // Title
    TextView tvTitle = new TextView(context);
    tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16f);
    tvTitle.setMaxLines(1);
    tvTitle.setTextColor(Color.parseColor("#212121"));
    tvTitle.setId(ID_TITLE);
    layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(Utils.dpToPx(context, 20f), Utils.dpToPx(context, 10f), Utils.dpToPx(context, 20f),
            0);
    linearLayout.addView(tvTitle, layoutParams);
    // Sub Title
    TextView tvSubTitle = new TextView(context);
    tvSubTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14f);
    tvSubTitle.setMaxLines(2);
    tvSubTitle.setTextColor(Color.parseColor("#757575"));
    tvSubTitle.setId(ID_SUBTITLE);
    layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(Utils.dpToPx(context, 20f), 0, Utils.dpToPx(context, 20f),
            Utils.dpToPx(context, 10f));
    linearLayout.addView(tvSubTitle, layoutParams);
    return linearLayout;
}

From source file:org.tomahawk.tomahawk_android.dialogs.RedirectConfigDialog.java

/**
 * Called when this {@link android.support.v4.app.DialogFragment} is being created
 *///  w w w  .  j  a  v  a2 s  .com
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getArguments() != null && getArguments().containsKey(TomahawkFragment.PREFERENCEID)) {
        String id = getArguments().getString(TomahawkFragment.PREFERENCEID);
        mScriptResolver = (ScriptResolver) PipeLine.get().getResolver(id);
        mAuthenticatorUtils = AuthenticatorManager.get().getAuthenticatorUtils(id);
    }

    TextView headerTextView = (TextView) addScrollingViewToFrame(R.layout.config_textview);
    headerTextView.setText(mScriptResolver.getDescription());

    int buttonBackgroundResId;
    int buttonTextColor;
    View.OnClickListener onClickListener;
    switch (mScriptResolver.getId()) {
    case TomahawkApp.PLUGINNAME_RDIO:
        buttonBackgroundResId = R.drawable.selectable_background_tomahawk_rectangle_gray;
        buttonTextColor = getResources().getColor(R.color.primary_textcolor);
        onClickListener = new RedirectButtonListener(TomahawkApp.PLUGINNAME_RDIO);
        break;
    case TomahawkApp.PLUGINNAME_SPOTIFY:
        buttonBackgroundResId = R.drawable.selectable_background_tomahawk_rectangle_gray;
        buttonTextColor = getResources().getColor(R.color.primary_textcolor);
        onClickListener = new RedirectButtonListener(TomahawkApp.PLUGINNAME_SPOTIFY);
        break;
    default:
        buttonBackgroundResId = R.drawable.selectable_background_deezer_button;
        buttonTextColor = getResources().getColor(R.color.primary_textcolor_inverted);
        onClickListener = new RedirectButtonListener(TomahawkApp.PLUGINNAME_DEEZER);
        break;
    }

    View buttonLayout = addScrollingViewToFrame(R.layout.config_redirect_button);
    LinearLayout button = ((LinearLayout) buttonLayout.findViewById(R.id.config_redirect_button));
    button.setBackgroundResource(buttonBackgroundResId);
    ImageView buttonImage = (ImageView) buttonLayout.findViewById(R.id.config_redirect_button_image);
    mScriptResolver.loadIcon(buttonImage, false);
    mRedirectButtonTextView = (TextView) button.findViewById(R.id.config_redirect_button_text);
    mRedirectButtonTextView.setTextColor(buttonTextColor);
    mRedirectButtonTextView.setText(mAuthenticatorUtils.isLoggedIn()
            ? getString(R.string.resolver_config_redirect_button_text_log_out_of)
            : getString(R.string.resolver_config_redirect_button_text_log_into));
    button.setOnClickListener(onClickListener);
    setDialogTitle(mScriptResolver.getName());
    hideNegativeButton();
    setStatus(mScriptResolver);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(getDialogView());
    return builder.create();
}

From source file:org.tomahawk.tomahawk_android.dialogs.ResolverRedirectConfigDialog.java

/**
 * Called when this {@link android.support.v4.app.DialogFragment} is being created
 *//*from   w  w w . ja  v a  2 s.  c  om*/
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (getArguments() != null && getArguments().containsKey(TomahawkFragment.PREFERENCEID)) {
        String id = getArguments().getString(TomahawkFragment.PREFERENCEID);
        mScriptResolver = (ScriptResolver) PipeLine.get().getResolver(id);
    }

    TextView headerTextView = (TextView) addScrollingViewToFrame(R.layout.config_textview);
    headerTextView.setText(mScriptResolver.getDescription());

    int buttonBackgroundResId = R.drawable.selectable_background_tomahawk_rectangle_gray;
    int buttonTextColor = getResources().getColor(R.color.primary_textcolor);
    View.OnClickListener onClickListener = new RedirectButtonListener();

    View buttonLayout = addScrollingViewToFrame(R.layout.config_redirect_button);
    LinearLayout button = ((LinearLayout) buttonLayout.findViewById(R.id.config_redirect_button));
    button.setBackgroundResource(buttonBackgroundResId);
    ImageView buttonImage = (ImageView) buttonLayout.findViewById(R.id.config_redirect_button_image);
    mScriptResolver.loadIcon(buttonImage, false);
    mRedirectButtonTextView = (TextView) button.findViewById(R.id.config_redirect_button_text);
    mRedirectButtonTextView.setTextColor(buttonTextColor);

    if (isPluginInstalled()) {
        mRedirectButtonTextView.setText(mScriptResolver.isEnabled()
                ? getString(R.string.resolver_config_redirect_button_text_log_out_of)
                : getString(R.string.resolver_config_redirect_button_text_log_into));
    } else {
        mRedirectButtonTextView
                .setText(getString(R.string.resolver_config_redirect_button_text_download_plugin));
    }

    button.setOnClickListener(onClickListener);
    setDialogTitle(mScriptResolver.getName());
    hideNegativeButton();
    setStatus(mScriptResolver);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(getDialogView());
    return builder.create();
}

From source file:com.fibrobook.viewpager.custom.CardFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    LayoutParams params = new LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT,
            android.view.ViewGroup.LayoutParams.MATCH_PARENT);

    FrameLayout fl = new FrameLayout(getActivity());
    fl.setLayoutParams(params);/*  w  w  w.j a v a 2  s . c  om*/

    final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8,
            getResources().getDisplayMetrics());

    LinearLayout l = new LinearLayout(getActivity());
    params.setMargins(margin, margin, margin, margin);
    l.setLayoutParams(params);
    l.setGravity(Gravity.CENTER);
    l.setBackgroundResource(R.drawable.background_card);

    switch (position) {

    case 0:
        symphtomsView(l);
        break;

    case 1:
        dayView(l);
        break;

    }

    fl.addView(l);
    return fl;
}

From source file:com.ehret.mixit.fragment.SessionDetailFragment.java

private void addSpeakerInfo(Talk conference) {
    //On vide les lments
    sessionPersonList.removeAllViews();/*from   w w  w . java 2 s.  c om*/

    List<Member> speakers = new ArrayList<>();
    for (Speaker member : conference.getSpeakers()) {
        Member membre = MembreFacade.getInstance().getMembre(getActivity(), TypeFile.speaker.name(),
                member.getIdMember());

        if (membre != null) {
            speakers.add(membre);
        }
    }

    //On affiche les liens que si on a recuperer des choses
    if (!speakers.isEmpty()) {
        //On utilisait auparavant une liste pour afficher ces lments dans la page mais cette liste
        //empche d'avoir un ScrollView englobant pour toute la page. Nous utilisons donc un tableau

        //On ajoute un table layout
        TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
        TableLayout tableLayout = new TableLayout(getActivity().getBaseContext());
        tableLayout.setLayoutParams(tableParams);

        if (mInflater != null) {
            for (final Member membre : speakers) {
                LinearLayout row = (LinearLayout) mInflater.inflate(R.layout.item_person, tableLayout, false);
                row.setBackgroundResource(R.drawable.row_transparent_background);

                //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
                TextView userName = (TextView) row.findViewById(R.id.person_user_name);
                TextView descriptif = (TextView) row.findViewById(R.id.person_shortdesciptif);
                TextView level = (TextView) row.findViewById(R.id.person_level);
                ImageView profileImage = (ImageView) row.findViewById(R.id.person_user_image);

                userName.setText(membre.getCompleteName());

                if (membre.getShortDescription() != null) {
                    descriptif.setText(membre.getShortDescription().trim());
                }

                //Recuperation de l'mage liee au profil
                Bitmap image = FileUtils.getImageProfile(getActivity(), membre);
                if (image == null) {
                    profileImage.setImageDrawable(getResources().getDrawable(R.drawable.person_image_empty));
                } else {
                    //On regarde dans les images embarquees
                    profileImage.setImageBitmap(image);
                }

                row.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((HomeActivity) getActivity()).changeCurrentFragment(PeopleDetailFragment
                                .newInstance(TypeFile.speaker.toString(), membre.getLogin(), 7),
                                TypeFile.speaker.toString());
                    }
                });

                tableLayout.addView(row);
            }
        }
        sessionPersonList.addView(tableLayout);
    }
}

From source file:fm.krui.kruifm.ScheduleFragment.java

/**
 * Adds a show to the schedule./*from www. j a v  a 2s. c  o  m*/
 * @param title Title of show to display
 * @param description Description of show to display
 * @param startTime Start time of show in minutes from midnight
 * @param endTime End time of show in minutes from midnight
 * @param category Format of this show, required to correctly color the event.
 *
 * Valid settings for category include:
 *                 1 - Regular Rotation
 *                 2 - Music Speciality
 *                 3 - Sports
 *                 4 - News/Talk
 *                 5 - Specials
 */
private void addShow(String title, String description, int startTime, int endTime, int category) {

    /* Build the LinearLayout to function as the container for this show. Since the size of the container is to represent
    the length of the show, its height must be proportional (1dp = 1 minute) to the length. Determine length by finding the difference
    between the start and end times. */

    // Fix for corner case of shows ending at midnight.
    if (endTime == 0) {
        endTime = 1440;
    }
    int difference = endTime - startTime;

    /* Define the margins of this show. All shows must not overlap the displayed times, which are 50dp in width.
    Add 5 more (to the right and left) to see the schedule lines for clarity. Push the show down to align with the appropriate time marker using the top margin value set to the
    difference (in minutes) between midnight and the start of the show. */

    Log.v(TAG, "Configuring " + title);
    //Log.v(TAG, "Start time: " + startTime + " End time: " + endTime);
    //Log.v(TAG, "Setting parameters for " + title);
    RelativeLayout.LayoutParams rrLayoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, dpToPixels(difference));
    rrLayoutParams.leftMargin = dpToPixels(55);
    //Log.v(TAG, "Left margin: " + rrLayoutParams.leftMargin);
    rrLayoutParams.topMargin = dpToPixels(startTime);
    //Log.v(TAG, "Top margin: " + rrLayoutParams.topMargin);
    rrLayoutParams.rightMargin = dpToPixels(5);
    //Log.v(TAG, "Right margin: " + rrLayoutParams.rightMargin);

    /* Build LinearLayout and apply parameters */
    LinearLayout eventLL = new LinearLayout(getActivity());
    eventLL.setOrientation(LinearLayout.VERTICAL);
    eventLL.setPadding(dpToPixels(5), dpToPixels(2), dpToPixels(5), dpToPixels(5));

    // Get background for this event
    eventLL.setBackgroundResource(getEventBackground(category));

    /* Add title of event to LinearLayout */
    TextView titleTV = new TextView(getActivity());

    // Title of a show should be bolded
    titleTV.setText(title);
    titleTV.setTypeface(null, Typeface.BOLD);
    titleTV.setPadding(dpToPixels(5), 0, dpToPixels(5), 0);
    eventLL.addView(titleTV);

    /* Determine length of event to see if we have room to attach a description (if one was passed) */
    int length = endTime - startTime;

    /* Attach a description with a size that depends on the event length (longer events can hold more description text). */
    if (description != null) {
        TextView descriptionTV = new TextView(getActivity());
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        descriptionTV.setText(description);

        // ~hour long shows can display 1 line of description
        if (difference >= 30 && difference <= 60) {
            descriptionTV.setMaxLines(1);
        }

        // 1:30 long shows can display 2 lines of description
        else if (difference >= 60 && difference <= 90) {
            descriptionTV.setMaxLines(2);
        }

        // 2:00 long shows can display 4 lines of description
        else if (difference >= 120) {
            descriptionTV.setMaxLines(4);
        }

        descriptionTV.setEllipsize(TextUtils.TruncateAt.END);
        descriptionTV.setPadding(dpToPixels(5), dpToPixels(5), dpToPixels(5), dpToPixels(5));
        eventLL.addView(descriptionTV);
    }

    /* Add this view to the schedule UI */
    RelativeLayout rl = (RelativeLayout) rootView.findViewById(R.id.schedule_container_relativelayout);
    rl.addView(eventLL, rrLayoutParams);
}

From source file:com.ehret.mixit.fragment.PeopleDetailFragment.java

private void addPeopleSession(Member membre) {
    //On recupere aussi la liste des sessions de l'utilisateur
    List<Talk> conferences = ConferenceFacade.getInstance().getSessionMembre(membre, getActivity());

    //On vide les lments
    sessionLayout.removeAllViews();/*from   w w  w . jav  a  2s .co  m*/

    //On affiche les liens que si on a recuperer des choses
    if (conferences != null && !conferences.isEmpty()) {
        //On ajoute un table layout
        TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
        TableLayout tableLayout = new TableLayout(getActivity().getBaseContext());
        tableLayout.setLayoutParams(tableParams);

        if (mInflater != null) {

            for (final Talk conf : conferences) {
                LinearLayout row = (LinearLayout) mInflater.inflate(R.layout.item_talk, tableLayout, false);
                row.setBackgroundResource(R.drawable.row_transparent_background);
                //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
                TextView horaire = (TextView) row.findViewById(R.id.talk_horaire);
                TextView talkImageText = (TextView) row.findViewById(R.id.talkImageText);
                TextView talkSalle = (TextView) row.findViewById(R.id.talk_salle);
                ImageView imageFavorite = (ImageView) row.findViewById(R.id.talk_image_favorite);
                ImageView langImage = (ImageView) row.findViewById(R.id.talk_image_language);

                ((TextView) row.findViewById(R.id.talk_name)).setText(conf.getTitle());
                ((TextView) row.findViewById(R.id.talk_shortdesciptif)).setText(conf.getSummary().trim());

                SimpleDateFormat sdf = new SimpleDateFormat("EEE");
                if (conf.getStart() != null && conf.getEnd() != null) {
                    horaire.setText(String.format(getResources().getString(R.string.periode),
                            sdf.format(conf.getStart()),
                            DateFormat.getTimeInstance(DateFormat.SHORT).format(conf.getStart()),
                            DateFormat.getTimeInstance(DateFormat.SHORT).format(conf.getEnd())));
                } else {
                    horaire.setText(getResources().getString(R.string.pasdate));

                }
                if (conf.getLang() != null && "ENGLISH".equals(conf.getLang())) {
                    langImage.setImageDrawable(getResources().getDrawable(R.drawable.en));
                } else {
                    langImage.setImageDrawable(getResources().getDrawable(R.drawable.fr));
                }
                Salle salle = Salle.INCONNU;
                if (conf instanceof Talk && Salle.INCONNU != Salle.getSalle(conf.getRoom())) {
                    salle = Salle.getSalle(conf.getRoom());
                }
                talkSalle.setText(String.format(getResources().getString(R.string.Salle), salle.getNom()));
                talkSalle.setBackgroundColor(getResources().getColor(salle.getColor()));

                if (conf instanceof Talk) {
                    if ("Workshop".equals(((Talk) conf).getFormat())) {
                        talkImageText.setText("Atelier");
                    } else {
                        talkImageText.setText("Talk");
                    }
                } else {
                    talkImageText.setText("L.Talk");
                }

                row.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        TypeFile typeFile;
                        int page = 6;
                        if (conf instanceof Talk) {
                            if ("Workshop".equals(((Talk) conf).getFormat())) {
                                typeFile = TypeFile.workshops;
                                page = 4;
                            } else {
                                typeFile = TypeFile.talks;
                                page = 3;
                            }
                        } else {
                            typeFile = TypeFile.lightningtalks;
                        }
                        ((HomeActivity) getActivity()).changeCurrentFragment(SessionDetailFragment.newInstance(
                                typeFile.toString(), conf.getIdSession(), page), typeFile.toString());
                    }
                });

                //On regarde si la conf fait partie des favoris
                SharedPreferences settings = getActivity().getSharedPreferences(UIUtils.PREFS_FAVORITES_NAME,
                        0);
                boolean trouve = false;
                for (String key : settings.getAll().keySet()) {
                    if (key.equals(String.valueOf(conf.getIdSession()))) {
                        trouve = true;
                        imageFavorite.setImageDrawable(
                                getActivity().getResources().getDrawable(R.drawable.ic_action_important));
                        break;
                    }
                }
                if (!trouve) {
                    imageFavorite.setImageDrawable(
                            getActivity().getResources().getDrawable(R.drawable.ic_action_not_important));
                }
                tableLayout.addView(row);
            }
        }
        sessionLayout.addView(tableLayout);
    } else {
        titleSessions.getLayoutParams().height = 0;
    }
}

From source file:org.cm.podd.report.activity.GroupReportTypeActivity.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    dataSource = new ReportTypeDataSource(this);
    reportDataSource = new ReportDataSource(this);
    reportQueueDataSource = new ReportQueueDataSource(this);

    Typeface typeface = StyleUtil.getDefaultTypeface(getAssets(), Typeface.NORMAL);
    setContentView(R.layout.activity_group_report_type);
    testCheckbox = findViewById(R.id.test_checkbox);
    testCheckbox.setTypeface(typeface);/*from w  ww  .  jav a 2  s  .co  m*/

    final LinearLayout testLayout = findViewById(R.id.test_section);
    testCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b) {
                testLayout.setBackgroundResource(R.color.report_test_indicator);
                compoundButton.setBackgroundResource(R.color.report_test_indicator);
            } else {
                testLayout.setBackgroundResource(R.color.white);
                compoundButton.setBackgroundResource(R.color.white);
            }
        }
    });

    Toolbar topBar = findViewById(R.id.toolbar_top);
    setSupportActionBar(topBar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    listView = findViewById(R.id.report_type_list_view);

    DisplayMetrics metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int width = metrics.widthPixels;
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        listView.setIndicatorBounds(width - GetPixelFromDips(100), width - GetPixelFromDips(10));
    } else {
        listView.setIndicatorBoundsRelative(width - GetPixelFromDips(100), width - GetPixelFromDips(10));
    }

    adapter = new GroupReportTypeAdapter(this, dataSource.getAllWithNoFollowAction());
    listView.setAdapter(adapter);
    listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView expandableListView, View view, int groupIndex,
                int childIndex, long id) {
            ReportType item = (ReportType) adapter.getChild(groupIndex, childIndex);
            Log.d(TAG, String.format("select report type = %d", item.getId()));
            Intent intent = ReportActivity.newReportIntent(GroupReportTypeActivity.this, item.getId(),
                    testCheckbox.isChecked());
            startActivity(intent);
            return true;
        }
    });
    listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView expandableListView, View view, int groupPosition,
                long id) {
            Log.d(TAG, "group " + groupPosition);
            if (groupPosition == 0) {
                long reportId = reportDataSource.createPositiveReport();

                // after save positive report, submit to queue right away
                reportQueueDataSource.addDataQueue(reportId);
                broadcastReportSubmission();

                finish();
                return true;
            }
            return false;
        }
    });

    progress = new ProgressDialog(this);
    progress.setTitle(getString(R.string.update_report_type));
    registerReceiver(mSyncReceiver, new IntentFilter(SyncReportTypeService.SYNC));

}