Example usage for android.support.v4.graphics.drawable DrawableCompat setTint

List of usage examples for android.support.v4.graphics.drawable DrawableCompat setTint

Introduction

In this page you can find the example usage for android.support.v4.graphics.drawable DrawableCompat setTint.

Prototype

public static void setTint(Drawable drawable, int i) 

Source Link

Usage

From source file:android_network.hetnet.vpn_service.AdapterRule.java

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    // Get rule/*from  w w w  .  ja v a 2 s .  c  om*/
    final Rule rule = listFiltered.get(position);

    // Handle expanding/collapsing
    holder.llApplication.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            rule.expanded = !rule.expanded;
            notifyItemChanged(position);
        }
    });

    // Show if non default rules
    holder.itemView.setBackgroundColor(rule.changed ? colorChanged : Color.TRANSPARENT);

    // Show expand/collapse indicator
    holder.ivExpander.setImageLevel(rule.expanded ? 1 : 0);

    // Show application icon
    if (rule.info.applicationInfo == null || rule.info.applicationInfo.icon == 0)
        Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(holder.ivIcon);
    else {
        Uri uri = Uri
                .parse("android.resource://" + rule.info.packageName + "/" + rule.info.applicationInfo.icon);
        Picasso.with(context).load(uri).resize(iconSize, iconSize).into(holder.ivIcon);
    }

    // Show application label
    holder.tvName.setText(rule.name);

    // Show application state
    int color = rule.system ? colorOff : colorText;
    if (!rule.internet || !rule.enabled)
        color = Color.argb(128, Color.red(color), Color.green(color), Color.blue(color));
    holder.tvName.setTextColor(color);

    // Show rule count
    new AsyncTask<Object, Object, Long>() {
        @Override
        protected void onPreExecute() {
            holder.tvHosts.setVisibility(View.GONE);
        }

        @Override
        protected Long doInBackground(Object... objects) {
            return DatabaseHelper.getInstance(context).getRuleCount(rule.info.applicationInfo.uid);
        }

        @Override
        protected void onPostExecute(Long rules) {
            if (rules > 0) {
                holder.tvHosts.setVisibility(View.VISIBLE);
                holder.tvHosts.setText(Long.toString(rules));
            }
        }
    }.execute();

    boolean screen_on = prefs.getBoolean("screen_on", true);

    // Wi-Fi settings
    holder.cbWifi.setEnabled(rule.apply);
    holder.cbWifi.setAlpha(wifiActive ? 1 : 0.5f);
    holder.cbWifi.setOnCheckedChangeListener(null);
    holder.cbWifi.setChecked(rule.wifi_blocked);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(CompoundButtonCompat.getButtonDrawable(holder.cbWifi));
        DrawableCompat.setTint(wrap, rule.apply ? (rule.wifi_blocked ? colorOff : colorOn) : colorGrayed);
    }
    holder.cbWifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            rule.wifi_blocked = isChecked;
            updateRule(rule, true, listAll);
        }
    });

    holder.ivScreenWifi.setEnabled(rule.apply);
    holder.ivScreenWifi.setAlpha(wifiActive ? 1 : 0.5f);
    holder.ivScreenWifi.setVisibility(rule.screen_wifi && rule.wifi_blocked ? View.VISIBLE : View.INVISIBLE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(holder.ivScreenWifi.getDrawable());
        DrawableCompat.setTint(wrap, rule.apply ? colorOn : colorGrayed);
    }

    // Mobile settings
    holder.cbOther.setEnabled(rule.apply);
    holder.cbOther.setAlpha(otherActive ? 1 : 0.5f);
    holder.cbOther.setOnCheckedChangeListener(null);
    holder.cbOther.setChecked(rule.other_blocked);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(CompoundButtonCompat.getButtonDrawable(holder.cbOther));
        DrawableCompat.setTint(wrap, rule.apply ? (rule.other_blocked ? colorOff : colorOn) : colorGrayed);
    }
    holder.cbOther.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            rule.other_blocked = isChecked;
            updateRule(rule, true, listAll);
        }
    });

    holder.ivScreenOther.setEnabled(rule.apply);
    holder.ivScreenOther.setAlpha(otherActive ? 1 : 0.5f);
    holder.ivScreenOther.setVisibility(rule.screen_other && rule.other_blocked ? View.VISIBLE : View.INVISIBLE);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(holder.ivScreenOther.getDrawable());
        DrawableCompat.setTint(wrap, rule.apply ? colorOn : colorGrayed);
    }

    holder.tvRoaming.setTextColor(rule.apply ? colorOff : colorGrayed);
    holder.tvRoaming.setAlpha(otherActive ? 1 : 0.5f);
    holder.tvRoaming.setVisibility(
            rule.roaming && (!rule.other_blocked || rule.screen_other) ? View.VISIBLE : View.INVISIBLE);

    // Expanded configuration section
    holder.llConfiguration.setVisibility(rule.expanded ? View.VISIBLE : View.GONE);

    // Show application details
    holder.tvUid
            .setText(rule.info.applicationInfo == null ? "?" : Integer.toString(rule.info.applicationInfo.uid));
    holder.tvPackage.setText(rule.info.packageName);
    holder.tvVersion.setText(rule.info.versionName + '/' + rule.info.versionCode);
    holder.tvDescription.setVisibility(rule.description == null ? View.GONE : View.VISIBLE);
    holder.tvDescription.setText(rule.description);

    // Show application state
    holder.tvInternet.setVisibility(rule.internet ? View.GONE : View.VISIBLE);
    holder.tvDisabled.setVisibility(rule.enabled ? View.GONE : View.VISIBLE);

    // Show traffic statistics
    holder.tvStatistics
            .setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? View.GONE : View.VISIBLE);
    holder.tvStatistics.setText(context.getString(R.string.msg_mbday, rule.upspeed, rule.downspeed));

    // Show related
    holder.btnRelated.setVisibility(rule.relateduids ? View.VISIBLE : View.GONE);
    holder.btnRelated.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent main = new Intent(context, MainActivity.class);
            main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(rule.info.applicationInfo.uid));
            context.startActivity(main);
        }
    });

    // Launch application settings
    holder.ibSettings.setVisibility(rule.settings == null ? View.GONE : View.VISIBLE);
    holder.ibSettings.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            context.startActivity(rule.settings);
        }
    });

    // Data saver
    holder.ibDatasaver.setVisibility(rule.datasaver == null ? View.GONE : View.VISIBLE);
    holder.ibDatasaver.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            context.startActivity(rule.datasaver);
        }
    });

    // Launch application
    holder.ibLaunch.setVisibility(rule.launch == null ? View.GONE : View.VISIBLE);
    holder.ibLaunch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            context.startActivity(rule.launch);
        }
    });

    // Apply
    holder.cbApply.setEnabled(rule.pkg);
    holder.cbApply.setOnCheckedChangeListener(null);
    holder.cbApply.setChecked(rule.apply);
    holder.cbApply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            rule.apply = isChecked;
            updateRule(rule, true, listAll);
        }
    });

    // Show Wi-Fi screen on condition
    holder.llScreenWifi.setVisibility(screen_on ? View.VISIBLE : View.GONE);
    holder.cbScreenWifi.setEnabled(rule.wifi_blocked && rule.apply);
    holder.cbScreenWifi.setOnCheckedChangeListener(null);
    holder.cbScreenWifi.setChecked(rule.screen_wifi);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(holder.ivWifiLegend.getDrawable());
        DrawableCompat.setTint(wrap, colorOn);
    }

    holder.cbScreenWifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            rule.screen_wifi = isChecked;
            updateRule(rule, true, listAll);
        }
    });

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable wrap = DrawableCompat.wrap(holder.ivOtherLegend.getDrawable());
        DrawableCompat.setTint(wrap, colorOn);
    }

    // Show mobile screen on condition
    holder.llScreenOther.setVisibility(screen_on ? View.VISIBLE : View.GONE);
    holder.cbScreenOther.setEnabled(rule.other_blocked && rule.apply);
    holder.cbScreenOther.setOnCheckedChangeListener(null);
    holder.cbScreenOther.setChecked(rule.screen_other);
    holder.cbScreenOther.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            rule.screen_other = isChecked;
            updateRule(rule, true, listAll);
        }
    });

    // Show roaming condition
    holder.cbRoaming.setEnabled((!rule.other_blocked || rule.screen_other) && rule.apply);
    holder.cbRoaming.setOnCheckedChangeListener(null);
    holder.cbRoaming.setChecked(rule.roaming);
    holder.cbRoaming.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        @TargetApi(Build.VERSION_CODES.M)
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            rule.roaming = isChecked;
            updateRule(rule, true, listAll);

            // Request permissions
            if (isChecked && !Util.hasPhoneStatePermission(context))
                context.requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE },
                        MainActivity.REQUEST_ROAMING);
        }
    });

    // Reset rule
    holder.btnClear.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Util.areYouSure(view.getContext(), R.string.msg_clear_rules, new Util.DoubtListener() {
                @Override
                public void onSure() {
                    holder.cbApply.setChecked(true);
                    holder.cbWifi.setChecked(rule.wifi_default);
                    holder.cbOther.setChecked(rule.other_default);
                    holder.cbScreenWifi.setChecked(rule.screen_wifi_default);
                    holder.cbScreenOther.setChecked(rule.screen_other_default);
                    holder.cbRoaming.setChecked(rule.roaming_default);
                }
            });
        }
    });

    // Live
    holder.ivLive.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            live = !live;
            TypedValue tv = new TypedValue();
            view.getContext().getTheme().resolveAttribute(live ? R.attr.iconPause : R.attr.iconPlay, tv, true);
            holder.ivLive.setImageResource(tv.resourceId);
            if (live)
                AdapterRule.this.notifyDataSetChanged();
        }
    });

    // Show logging is disabled
    boolean log_app = prefs.getBoolean("log_app", false);
    holder.tvNoLog.setVisibility(log_app ? View.GONE : View.VISIBLE);
    holder.tvNoLog.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            context.startActivity(new Intent(context, ActivitySettings.class));
        }
    });

    // Show filtering is disabled
    boolean filter = prefs.getBoolean("filter", false);
    holder.tvNoFilter.setVisibility(filter ? View.GONE : View.VISIBLE);
    holder.tvNoFilter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            context.startActivity(new Intent(context, ActivitySettings.class));
        }
    });

    // Show access rules
    if (rule.expanded) {
        // Access the database when expanded only
        final AdapterAccess badapter = new AdapterAccess(context,
                DatabaseHelper.getInstance(context).getAccess(rule.info.applicationInfo.uid));
        holder.lvAccess.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, final int bposition, long bid) {
                PackageManager pm = context.getPackageManager();
                Cursor cursor = (Cursor) badapter.getItem(bposition);
                final long id = cursor.getLong(cursor.getColumnIndex("ID"));
                final int version = cursor.getInt(cursor.getColumnIndex("version"));
                final int protocol = cursor.getInt(cursor.getColumnIndex("protocol"));
                final String daddr = cursor.getString(cursor.getColumnIndex("daddr"));
                final int dport = cursor.getInt(cursor.getColumnIndex("dport"));
                long time = cursor.getLong(cursor.getColumnIndex("time"));
                int block = cursor.getInt(cursor.getColumnIndex("block"));

                PopupMenu popup = new PopupMenu(context, context.findViewById(R.id.vwPopupAnchor));
                popup.inflate(R.menu.access);

                popup.getMenu().findItem(R.id.menu_host).setTitle(Util.getProtocolName(protocol, version, false)
                        + " " + daddr + (dport > 0 ? "/" + dport : ""));

                //                    markPro(popup.getMenu().findItem(R.id.menu_allow), ActivityPro.SKU_FILTER);
                //                    markPro(popup.getMenu().findItem(R.id.menu_block), ActivityPro.SKU_FILTER);

                // Whois
                final Intent lookupIP = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://www.tcpiputils.com/whois-lookup/" + daddr));
                if (pm.resolveActivity(lookupIP, 0) == null)
                    popup.getMenu().removeItem(R.id.menu_whois);
                else
                    popup.getMenu().findItem(R.id.menu_whois)
                            .setTitle(context.getString(R.string.title_log_whois, daddr));

                // Lookup port
                final Intent lookupPort = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://www.speedguide.net/port.php?port=" + dport));
                if (dport <= 0 || pm.resolveActivity(lookupPort, 0) == null)
                    popup.getMenu().removeItem(R.id.menu_port);
                else
                    popup.getMenu().findItem(R.id.menu_port)
                            .setTitle(context.getString(R.string.title_log_port, dport));

                popup.getMenu().findItem(R.id.menu_time)
                        .setTitle(SimpleDateFormat.getDateTimeInstance().format(time));

                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem menuItem) {
                        switch (menuItem.getItemId()) {
                        case R.id.menu_whois:
                            context.startActivity(lookupIP);
                            return true;

                        case R.id.menu_port:
                            context.startActivity(lookupPort);
                            return true;

                        case R.id.menu_allow:
                            if (true) {
                                DatabaseHelper.getInstance(context).setAccess(id, 0);
                                ServiceSinkhole.reload("allow host", context);
                            }
                            //                                        context.startActivity(new Intent(context, ActivityPro.class));
                            return true;

                        case R.id.menu_block:
                            if (true) {
                                DatabaseHelper.getInstance(context).setAccess(id, 1);
                                ServiceSinkhole.reload("block host", context);
                            }
                            //                                        context.startActivity(new Intent(context, ActivityPro.class));
                            return true;

                        case R.id.menu_reset:
                            DatabaseHelper.getInstance(context).setAccess(id, -1);
                            ServiceSinkhole.reload("reset host", context);
                            return true;
                        }
                        return false;
                    }
                });

                if (block == 0)
                    popup.getMenu().removeItem(R.id.menu_allow);
                else if (block == 1)
                    popup.getMenu().removeItem(R.id.menu_block);

                popup.show();
            }
        });

        holder.lvAccess.setAdapter(badapter);
    } else {
        holder.lvAccess.setAdapter(null);
        holder.lvAccess.setOnItemClickListener(null);
    }

    // Clear access log
    holder.btnClearAccess.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Util.areYouSure(view.getContext(), R.string.msg_reset_access, new Util.DoubtListener() {
                @Override
                public void onSure() {
                    DatabaseHelper.getInstance(context).clearAccess(rule.info.applicationInfo.uid, true);
                    if (!live)
                        notifyDataSetChanged();
                    if (rv != null)
                        rv.scrollToPosition(position);
                }
            });
        }
    });

    // Notify on access
    holder.cbNotify.setEnabled(prefs.getBoolean("notify_access", false) && rule.apply);
    holder.cbNotify.setOnCheckedChangeListener(null);
    holder.cbNotify.setChecked(rule.notify);
    holder.cbNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            rule.notify = isChecked;
            updateRule(rule, true, listAll);
        }
    });
}

From source file:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java

public void setArrowTintColor(int resolvedColor) {
    if (arrowDrawable != null && !isArrowHidden) {
        DrawableCompat.setTint(arrowDrawable, resolvedColor);
    }//from w w  w .j ava  2s .c  om
}

From source file:org.gateshipone.malp.application.listviewitems.FileListItem.java

/**
 * Extracts the information from a MPDTrack.
 * @param track Track to show the view for.
 * @param context Context used for String extraction
 */// ww  w  . jav a 2 s.  c om
public void setTrack(MPDTrack track, Context context) {
    if (track != null) {
        String trackNumber;

        if (track.getAlbumDiscCount() > 0) {
            trackNumber = String.valueOf(track.getDiscNumber()) + '-' + String.valueOf(track.getTrackNumber());
        } else {
            trackNumber = String.valueOf(track.getTrackNumber());
        }

        /* Extract the information from the track */
        mNumberView.setText(trackNumber);

        int trackLength = track.getLength();
        if (trackLength > 0) {
            // Get the preformatted duration of the track.
            mDurationView.setText(FormatHelper.formatTracktimeFromS(track.getLength()));
            mDurationView.setVisibility(VISIBLE);
        } else {
            mDurationView.setVisibility(GONE);
        }
        // Get track title
        String trackTitle = track.getTrackTitle();

        // If no trackname is available (e.g. streaming URLs) show path
        if (null == trackTitle || trackTitle.isEmpty()) {
            trackTitle = FormatHelper.getFilenameFromPath(track.getPath());
        }
        mTitleView.setText(trackTitle);

        // additional information (artist + album)
        String trackInformation;

        String trackAlbum = track.getTrackAlbum();

        // Check which information is available and set the separator accordingly.
        if (!track.getTrackArtist().isEmpty() && !track.getTrackAlbum().isEmpty()) {
            trackInformation = track.getTrackArtist()
                    + context.getResources().getString(R.string.track_item_separator) + trackAlbum;
        } else if (track.getTrackArtist().isEmpty() && !track.getTrackAlbum().isEmpty()) {
            trackInformation = trackAlbum;
        } else if (track.getTrackAlbum().isEmpty() && !track.getTrackArtist().isEmpty()) {
            trackInformation = track.getTrackArtist();
        } else {
            trackInformation = track.getPath();
        }

        mAdditionalInfoView.setText(trackInformation);
        mSeparator.setVisibility(VISIBLE);
        mAdditionalInfoView.setVisibility(VISIBLE);
        mNumberView.setVisibility(VISIBLE);
    } else {
        /* Show loading text */
        mSeparator.setVisibility(GONE);
        mTitleView.setText(getResources().getText(R.string.track_item_loading));
        mNumberView.setVisibility(GONE);
        mDurationView.setVisibility(GONE);
        mAdditionalInfoView.setVisibility(GONE);
    }

    if (mShowIcon) {
        Drawable icon = context.getDrawable(R.drawable.ic_file_48dp);

        if (icon != null) {
            // get tint color
            int tintColor = ThemeUtils.getThemeColor(context, android.R.attr.textColor);
            // tint the icon
            DrawableCompat.setTint(icon, tintColor);
        }
        mItemIcon.setImageDrawable(icon);
    }

}

From source file:com.jaredrummler.materialspinner.MaterialSpinner.java

/**
 * Set the tint color for the dropdown arrow
 *
 * @param color// w w  w  .j a v  a 2s  .co m
 *     the color value
 */
public void setArrowColor(@ColorInt int color) {
    arrowColor = color;
    if (arrowDrawable != null) {
        DrawableCompat.setTint(arrowDrawable, arrowColor);
    }
}

From source file:org.onebusaway.android.ui.ArrivalsListAdapterStyleB.java

@Override
protected void initView(final View view, CombinedArrivalInfoStyleB combinedArrivalInfoStyleB) {
    final ArrivalInfo stopInfo = combinedArrivalInfoStyleB.getArrivalInfoList().get(0);
    final ObaArrivalInfo arrivalInfo = stopInfo.getInfo();
    final Context context = getContext();

    LayoutInflater inflater = LayoutInflater.from(context);

    TextView routeName = (TextView) view.findViewById(R.id.routeName);
    TextView destination = (TextView) view.findViewById(R.id.routeDestination);

    // TableLayout that we will fill with TableRows of arrival times
    TableLayout arrivalTimesLayout = (TableLayout) view.findViewById(R.id.arrivalTimeLayout);
    arrivalTimesLayout.removeAllViews();

    Resources r = view.getResources();

    ImageButton starBtn = (ImageButton) view.findViewById(R.id.route_star);
    starBtn.setColorFilter(r.getColor(R.color.theme_primary));

    ImageButton mapImageBtn = (ImageButton) view.findViewById(R.id.mapImageBtn);
    mapImageBtn.setColorFilter(r.getColor(R.color.theme_primary));

    ImageButton routeMoreInfo = (ImageButton) view.findViewById(R.id.route_more_info);
    routeMoreInfo.setColorFilter(r.getColor(R.color.switch_thumb_normal_material_dark));

    starBtn.setImageResource(/*from w  ww.  ja v  a2s  .c om*/
            stopInfo.isRouteAndHeadsignFavorite() ? R.drawable.focus_star_on : R.drawable.focus_star_off);

    starBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Show dialog for setting route favorite
            RouteFavoriteDialogFragment dialog = new RouteFavoriteDialogFragment.Builder(
                    stopInfo.getInfo().getRouteId(), stopInfo.getInfo().getHeadsign())
                            .setRouteShortName(stopInfo.getInfo().getShortName())
                            .setRouteLongName(stopInfo.getInfo().getRouteLongName())
                            .setStopId(stopInfo.getInfo().getStopId())
                            .setFavorite(!stopInfo.isRouteAndHeadsignFavorite()).build();

            dialog.setCallback(new RouteFavoriteDialogFragment.Callback() {
                @Override
                public void onSelectionComplete(boolean savedFavorite) {
                    if (savedFavorite) {
                        mFragment.refreshLocal();
                    }
                }
            });
            dialog.show(mFragment.getFragmentManager(), RouteFavoriteDialogFragment.TAG);
        }
    });

    // Setup map
    mapImageBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFragment.showRouteOnMap(stopInfo);
        }
    });

    // Setup more
    routeMoreInfo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFragment.showListItemMenu(view, stopInfo);
        }
    });

    routeName.setText(arrivalInfo.getShortName());
    destination.setText(MyTextUtils.toTitleCase(arrivalInfo.getHeadsign()));

    // Loop through the arrival times and create the TableRows that contains the data
    for (int i = 0; i < combinedArrivalInfoStyleB.getArrivalInfoList().size(); i++) {
        final ArrivalInfo arrivalRow = combinedArrivalInfoStyleB.getArrivalInfoList().get(i);
        final ObaArrivalInfo tempArrivalInfo = arrivalRow.getInfo();
        long scheduledTime = tempArrivalInfo.getScheduledArrivalTime();

        // Create a new row to be added
        final TableRow tr = (TableRow) inflater.inflate(R.layout.arrivals_list_tr_template_style_b, null);

        // Layout and views to inflate from XML templates
        RelativeLayout layout;
        TextView scheduleView, estimatedView, statusView;
        View divider;

        if (i == 0) {
            // Use larger styled layout/view for next arrival time
            layout = (RelativeLayout) inflater.inflate(R.layout.arrivals_list_rl_template_style_b_large, null);
            scheduleView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_schedule_large, null);
            estimatedView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_estimated_large, null);
            statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_large,
                    null);
        } else {
            // Use smaller styled layout/view for further out times
            layout = (RelativeLayout) inflater.inflate(R.layout.arrivals_list_rl_template_style_b_small, null);
            scheduleView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_schedule_small, null);
            estimatedView = (TextView) inflater
                    .inflate(R.layout.arrivals_list_tv_template_style_b_estimated_small, null);
            statusView = (TextView) inflater.inflate(R.layout.arrivals_list_tv_template_style_b_status_small,
                    null);
        }

        // Set arrival times and status in views
        scheduleView.setText(DateUtils.formatDateTime(context, scheduledTime,
                DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NO_NOON | DateUtils.FORMAT_NO_MIDNIGHT));
        if (arrivalRow.getPredicted()) {
            long eta = arrivalRow.getEta();
            if (eta == 0) {
                estimatedView.setText(R.string.stop_info_eta_now);
            } else {
                estimatedView.setText(eta + " min");
            }
        } else {
            estimatedView.setText(R.string.stop_info_eta_unknown);
        }
        statusView.setText(arrivalRow.getStatusText());
        int colorCode = arrivalRow.getColor();
        statusView.setBackgroundResource(R.drawable.round_corners_style_b_status);
        GradientDrawable d = (GradientDrawable) statusView.getBackground();
        d.setColor(context.getResources().getColor(colorCode));

        int alpha;
        if (i == 0) {
            // Set next arrival
            alpha = (int) (1.0f * 255); // X percent transparency
        } else {
            // Set smaller rows
            alpha = (int) (.35f * 255); // X percent transparency
        }
        d.setAlpha(alpha);

        // Set padding on status view
        int pSides = UIUtils.dpToPixels(context, 5);
        int pTopBottom = UIUtils.dpToPixels(context, 2);
        statusView.setPadding(pSides, pTopBottom, pSides, pTopBottom);

        // Add TextViews to layout
        layout.addView(scheduleView);
        layout.addView(statusView);
        layout.addView(estimatedView);

        // Make sure the TextViews align left/center/right of parent relative layout
        RelativeLayout.LayoutParams params1 = (RelativeLayout.LayoutParams) scheduleView.getLayoutParams();
        params1.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        params1.addRule(RelativeLayout.CENTER_VERTICAL);
        scheduleView.setLayoutParams(params1);

        RelativeLayout.LayoutParams params2 = (RelativeLayout.LayoutParams) statusView.getLayoutParams();
        params2.addRule(RelativeLayout.CENTER_IN_PARENT);
        // Give status view a little extra margin
        int p = UIUtils.dpToPixels(context, 3);
        params2.setMargins(p, p, p, p);
        statusView.setLayoutParams(params2);

        RelativeLayout.LayoutParams params3 = (RelativeLayout.LayoutParams) estimatedView.getLayoutParams();
        params3.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        params3.addRule(RelativeLayout.CENTER_VERTICAL);
        estimatedView.setLayoutParams(params3);

        // Add layout to TableRow
        tr.addView(layout);

        // Add the divider, if its not the first row
        if (i != 0) {
            int dividerHeight = UIUtils.dpToPixels(context, 1);
            divider = inflater.inflate(R.layout.arrivals_list_divider_template_style_b, null);
            divider.setLayoutParams(
                    new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, dividerHeight));
            arrivalTimesLayout.addView(divider);
        }

        // Add click listener
        tr.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mFragment.showListItemMenu(tr, arrivalRow);
            }
        });

        // Add TableRow to container layout
        arrivalTimesLayout.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                TableLayout.LayoutParams.MATCH_PARENT));
    }

    // Show or hide reminder for this trip
    ContentValues values = null;
    if (mTripsForStop != null) {
        values = mTripsForStop.getValues(arrivalInfo.getTripId());
    }
    if (values != null) {
        String reminderName = values.getAsString(ObaContract.Trips.NAME);

        TextView reminder = (TextView) view.findViewById(R.id.reminder);
        if (reminderName.length() == 0) {
            reminderName = context.getString(R.string.trip_info_noname);
        }
        reminder.setText(reminderName);
        Drawable d = reminder.getCompoundDrawables()[0];
        d = DrawableCompat.wrap(d);
        DrawableCompat.setTint(d.mutate(), view.getResources().getColor(R.color.theme_primary));
        reminder.setCompoundDrawables(d, null, null, null);
        reminder.setVisibility(View.VISIBLE);
    } else {
        // Explicitly set reminder to invisible because we might be reusing
        // this view.
        View reminder = view.findViewById(R.id.reminder);
        reminder.setVisibility(View.GONE);
    }
}

From source file:org.gateshipone.odyssey.viewitems.ListViewItem.java

/**
 * Extracts the information from a file model.
 *
 * @param context The current context.//ww  w .  j av  a  2s.  c  om
 * @param file    The current file model.
 */
public void setFile(final Context context, final FileModel file) {
    // title
    String title = file.getName();

    // get icon for filetype
    Drawable icon;
    if (file.isDirectory()) {
        // choose directory icon
        icon = context.getDrawable(R.drawable.ic_folder_48dp);
    } else {
        // choose file icon
        icon = context.getDrawable(R.drawable.ic_file_48dp);
    }

    if (icon != null) {
        // get tint color
        int tintColor = ThemeUtils.getThemeColor(context, R.attr.odyssey_color_text_background_secondary);
        // tint the icon
        DrawableCompat.setTint(icon, tintColor);
    }

    // last modified
    String lastModifiedDateString = FormatHelper.formatTimeStampToString(context, file.getLastModified());

    setTitle(title);
    setSubtitle(lastModifiedDateString);

    setIcon(icon);
}

From source file:com.layer.messenger.makemoji.MakeMojiAtlasComposer.java

private void addAttachmentMenuItem(AttachmentSender sender) {
    LayoutInflater inflater = LayoutInflater.from(getContext());
    LinearLayout menuLayout = (LinearLayout) mAttachmentMenu.getContentView();

    View menuItem = inflater.inflate(com.layer.atlas.R.layout.atlas_message_composer_attachment_menu_item,
            menuLayout, false);/*from   w w  w. j  av  a  2 s  .c om*/
    ((TextView) menuItem.findViewById(com.layer.atlas.R.id.title)).setText(sender.getTitle());
    menuItem.setTag(sender);
    menuItem.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            mAttachmentMenu.dismiss();
            ((AttachmentSender) v.getTag()).requestSend();
        }
    });
    if (sender.getIcon() != null) {
        ImageView iconView = ((ImageView) menuItem.findViewById(com.layer.atlas.R.id.icon));
        iconView.setImageResource(sender.getIcon());
        iconView.setVisibility(VISIBLE);
        Drawable d = DrawableCompat.wrap(iconView.getDrawable());
        DrawableCompat.setTint(d, getResources().getColor(com.layer.atlas.R.color.atlas_icon_enabled));
    }
    menuLayout.addView(menuItem);
}

From source file:org.gateshipone.malp.application.listviewitems.FileListItem.java

/**
 * Extracts the information from a MPDDirectory
 * @param directory Directory to show the view for.
 * @param context Context used for image extraction
 *///from   w w w . jav  a  2s. c o m
public void setDirectory(MPDDirectory directory, Context context) {
    mTitleView.setText(directory.getSectionTitle());
    mAdditionalInfoView.setText(directory.getLastModified());

    if (mShowIcon) {
        Drawable icon = context.getDrawable(R.drawable.ic_folder_48dp);

        if (icon != null) {
            // get tint color
            int tintColor = ThemeUtils.getThemeColor(context, android.R.attr.textColor);
            // tint the icon
            DrawableCompat.setTint(icon, tintColor);
        }
        mItemIcon.setImageDrawable(icon);
    }
}

From source file:org.rebo.app.route.RouteSearch.java

public synchronized ExtendedMarkerItem putMarkerItem(ExtendedMarkerItem item, GHPoint p, int index,
        int titleResId, int markerResId, int iconResId, Integer colorResId) {

    if (item != null)
        mItineraryMarkers.removeItem(item);

    Drawable drawable = ContextCompat.getDrawable(activity, markerResId);
    if (colorResId != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable.mutate(), ContextCompat.getColor(activity, colorResId));
    }/*from  www  .j  av a2 s. c  o  m*/
    Bitmap bitmap = AndroidGraphics.drawableToBitmap(drawable);
    MarkerSymbol marker = new MarkerSymbol(bitmap, 0.5f, 1);

    ExtendedMarkerItem overlayItem = new ExtendedMarkerItem(App.res.getString(titleResId), "",
            convertGHPointToGeoPoint(p));

    overlayItem.setMarker(marker);

    if (iconResId != -1) {
        overlayItem.setImage(ContextCompat.getDrawable(activity, iconResId));
    }

    overlayItem.setRelatedObject(index);

    mItineraryMarkers.addItem(overlayItem);

    App.map.updateMap(true);

    //Start geocoding task to update the description of the marker with its address:
    new GeocodingTask().execute(overlayItem);

    return overlayItem;
}

From source file:info.bartowski.easteregg.MLand.java

public void reset() {
    L("reset");//from w ww .jav a  2  s . com
    final Drawable sky = new GradientDrawable(GradientDrawable.Orientation.BOTTOM_TOP, SKIES[mTimeOfDay]);
    sky.setDither(true);
    setBackground(sky);

    mFlipped = frand() > 0.5f;
    setScaleX(mFlipped ? -1 : 1);

    int i = getChildCount();
    while (i-- > 0) {
        final View v = getChildAt(i);
        if (v instanceof GameView) {
            removeViewAt(i);
        }
    }

    mObstaclesInPlay.clear();
    mCurrentPipeId = 0;

    mWidth = getWidth();
    mHeight = getHeight();

    boolean showingSun = (mTimeOfDay == DAY || mTimeOfDay == SUNSET) && frand() > 0.25;
    if (showingSun) {
        final Star sun = new Star(getContext());
        sun.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.sun));
        final int w = getResources().getDimensionPixelSize(R.dimen.mland_sun_size);
        sun.setTranslationX(frand(w, mWidth - w));
        if (mTimeOfDay == DAY) {
            sun.setTranslationY(frand(w, (mHeight * 0.66f)));
            DrawableCompat.setTint(sun.getBackground(), 0);
        } else {
            sun.setTranslationY(frand(mHeight * 0.66f, mHeight - w));
            DrawableCompat.setTintMode(sun.getBackground(), PorterDuff.Mode.SRC_ATOP);
            DrawableCompat.setTint(sun.getBackground(), 0xC0FF8000);

        }
        addView(sun, new LayoutParams(w, w));
    }
    if (!showingSun) {
        final boolean dark = mTimeOfDay == NIGHT || mTimeOfDay == TWILIGHT;
        final float ff = frand();
        if ((dark && ff < 0.75f) || ff < 0.5f) {
            final Star moon = new Star(getContext());
            moon.setBackground(Utility.getCompatDrawable(getContext(), R.drawable.moon));
            moon.getBackground().setAlpha(dark ? 255 : 128);
            moon.setScaleX(frand() > 0.5 ? -1 : 1);
            moon.setRotation(moon.getScaleX() * frand(5, 30));
            final int w = getResources().getDimensionPixelSize(R.dimen.mland_sun_size);
            moon.setTranslationX(frand(w, mWidth - w));
            moon.setTranslationY(frand(w, mHeight - w));
            addView(moon, new LayoutParams(w, w));
        }
    }

    final int mh = mHeight / 6;
    final boolean cloudless = frand() < 0.25;
    final int N = 20;
    for (i = 0; i < N; i++) {
        final float r1 = frand();
        final Scenery s;
        if (HAVE_STARS && r1 < 0.3 && mTimeOfDay != DAY) {
            s = new Star(getContext());
        } else if (r1 < 0.6 && !cloudless) {
            s = new Cloud(getContext());
        } else {
            switch (mScene) {
            case SCENE_ZRH:
                s = new Mountain(getContext());
                break;
            case SCENE_TX:
                s = new Cactus(getContext());
                break;
            case SCENE_CITY:
            default:
                s = new Building(getContext());
                break;
            }
            s.z = (float) i / N;
            // no more shadows for these things
            //s.setTranslationZ(PARAMS.SCENERY_Z * (1+s.z));
            s.v = 0.85f * s.z; // buildings move proportional to their distance
            if (mScene == SCENE_CITY) {
                s.setBackgroundColor(Color.GRAY);
                s.h = irand(PARAMS.BUILDING_HEIGHT_MIN, mh);
            }
            final int c = (int) (255f * s.z);
            final Drawable bg = s.getBackground();
            if (bg != null)
                bg.setColorFilter(Color.rgb(c, c, c), PorterDuff.Mode.MULTIPLY);
        }
        final LayoutParams lp = new LayoutParams(s.w, s.h);
        if (s instanceof Building) {
            lp.gravity = Gravity.BOTTOM;
        } else {
            lp.gravity = Gravity.TOP;
            final float r = frand();
            if (s instanceof Star) {
                lp.topMargin = (int) (r * r * mHeight);
            } else {
                lp.topMargin = (int) (1 - r * r * mHeight / 2) + mHeight / 2;
            }
        }

        addView(s, lp);
        s.setTranslationX(frand(-lp.width, mWidth + lp.width));
    }

    for (Player p : mPlayers) {
        addView(p); // put it back!
        p.reset();
    }

    realignPlayers();

    if (mAnim != null) {
        mAnim.cancel();
    }
    mAnim = new TimeAnimator();
    mAnim.setTimeListener(new TimeAnimator.TimeListener() {
        @Override
        public void onTimeUpdate(TimeAnimator timeAnimator, long t, long dt) {
            step(t, dt);
        }
    });
}