Android Open Source - unbounce-android Alarms Adapter






From Project

Back to project page unbounce-android.

License

The source code is released under:

MIT License

If you think the Android project unbounce-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ryansteckler.nlpunbounce.adapters;
/*  www. ja  va2  s .  c  o  m*/
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ryansteckler.nlpunbounce.R;
import com.ryansteckler.nlpunbounce.helpers.SortWakeLocks;
import com.ryansteckler.nlpunbounce.helpers.ThemeHelper;
import com.ryansteckler.nlpunbounce.models.AlarmStats;
import com.ryansteckler.nlpunbounce.models.BaseStats;
import com.ryansteckler.nlpunbounce.models.EventLookup;
import com.ryansteckler.nlpunbounce.models.WakelockStats;


import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created by rsteckler on 9/7/14.
 */
public class AlarmsAdapter extends BaseAdapter {

    private int mSortBy = SortWakeLocks.SORT_COUNT;

    public AlarmsAdapter(Context context, ArrayList<BaseStats> alarmStatList) {
        super(context, R.layout.fragment_alarms_listitem, alarmStatList, "alarm");
    }


    private static class AlarmViewHolder {
        TextView name;
        TextView alarmCount;
    }



    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        int itemType = this.getItemViewType(position);
        switch (itemType) {
            case ITEM_TYPE:
                // Get the data item for this position
                AlarmStats alarm = (AlarmStats)getItem(position);

                // Check if an existing view is being reused, otherwise inflate the view
                AlarmViewHolder alarmViewHolder; // view lookup cache stored in tag
                if (convertView == null) {
                    alarmViewHolder = new AlarmViewHolder();

                    LayoutInflater inflater = LayoutInflater.from(getContext());
                    convertView = inflater.inflate(R.layout.fragment_alarms_listitem, parent, false);
                    alarmViewHolder.name = (TextView) convertView.findViewById(R.id.textviewAlarmName);
                    alarmViewHolder.alarmCount = (TextView) convertView.findViewById(R.id.textViewAlarmCount);

                    convertView.setTag(alarmViewHolder);
                }
                else {
                   alarmViewHolder = (AlarmViewHolder) convertView.getTag();
                }

                // Populate the data into the template view using the data object
                alarmViewHolder.name.setText(alarm.getName());
                alarmViewHolder.alarmCount.setText(String.valueOf(alarm.getAllowedCount()));

                alarmViewHolder.name.setSelected(true);

                //Size the count box width to at least the height.
                alarmViewHolder.alarmCount.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                int height = alarmViewHolder.alarmCount.getMeasuredHeight();
                int width = alarmViewHolder.alarmCount.getMeasuredWidth();
                if (height > width) {
                    alarmViewHolder.alarmCount.setLayoutParams(new LinearLayout.LayoutParams(height, height));
                }
                else {
                    alarmViewHolder.alarmCount.setLayoutParams(new LinearLayout.LayoutParams(width, width));
                }

                //Set the background color along the reg-green spectrum based on the severity of the count.
                float correctedStat = alarm.getAllowedCount() - mLowCount;
                float point = 120 - ((correctedStat / mScale) * 120); //this gives us a 1-120 hue number.

                float[] hsv = getBackColorFromSpectrum(alarm);
                alarmViewHolder.alarmCount.setBackgroundColor(Color.HSVToColor(hsv));

                hsv = getForeColorFromBack(hsv);
                alarmViewHolder.alarmCount.setTextColor(Color.HSVToColor(hsv));

                break;

            case CATEGORY_TYPE:
                convertView = getCategoryView(position, convertView, parent);
                break;

        }


        return convertView;
    }



    public void sort(int sortBy, boolean categorize) {
        mSortBy = sortBy;
        sort(SortWakeLocks.getBaseListComparator(mSortBy, categorize,this.getContext()));
        addCategories(mBackingList);
    }

    public void sort(int sortBy) {
        sort(sortBy, true);
    }


}




Java Source Code List

com.example.rsteckler.myapplication.ApplicationTest.java
com.ryansteckler.inappbilling.Base64DecoderException.java
com.ryansteckler.inappbilling.Base64.java
com.ryansteckler.inappbilling.IabException.java
com.ryansteckler.inappbilling.IabHelper.java
com.ryansteckler.inappbilling.IabResult.java
com.ryansteckler.inappbilling.Inventory.java
com.ryansteckler.inappbilling.Purchase.java
com.ryansteckler.inappbilling.Security.java
com.ryansteckler.inappbilling.SkuDetails.java
com.ryansteckler.nlpunbounce.ActivityReceiver.java
com.ryansteckler.nlpunbounce.AlarmDetailFragment.java
com.ryansteckler.nlpunbounce.AlarmsFragment.java
com.ryansteckler.nlpunbounce.BaseDetailFragment.java
com.ryansteckler.nlpunbounce.ExpandingLayout.java
com.ryansteckler.nlpunbounce.HomeFragment.java
com.ryansteckler.nlpunbounce.MaterialSettingsActivity.java
com.ryansteckler.nlpunbounce.NavigationDrawerFragment.java
com.ryansteckler.nlpunbounce.ServiceDetailFragment.java
com.ryansteckler.nlpunbounce.ServicesFragment.java
com.ryansteckler.nlpunbounce.SettingsActivity.java
com.ryansteckler.nlpunbounce.WakelockDetailFragment.java
com.ryansteckler.nlpunbounce.WakelocksFragment.java
com.ryansteckler.nlpunbounce.XposedReceiver.java
com.ryansteckler.nlpunbounce.adapters.AlarmsAdapter.java
com.ryansteckler.nlpunbounce.adapters.BaseAdapter.java
com.ryansteckler.nlpunbounce.adapters.ServicesAdapter.java
com.ryansteckler.nlpunbounce.adapters.WakelocksAdapter.java
com.ryansteckler.nlpunbounce.helpers.DownloadHelper.java
com.ryansteckler.nlpunbounce.helpers.LocaleHelper.java
com.ryansteckler.nlpunbounce.helpers.LogHelper.java
com.ryansteckler.nlpunbounce.helpers.NetworkHelper.java
com.ryansteckler.nlpunbounce.helpers.RootHelper.java
com.ryansteckler.nlpunbounce.helpers.SettingsHelper.java
com.ryansteckler.nlpunbounce.helpers.SortWakeLocks.java
com.ryansteckler.nlpunbounce.helpers.ThemeHelper.java
com.ryansteckler.nlpunbounce.helpers.UidNameResolver.java
com.ryansteckler.nlpunbounce.hooks.Wakelocks.java
com.ryansteckler.nlpunbounce.models.AlarmStats.java
com.ryansteckler.nlpunbounce.models.BaseStatsWrapper.java
com.ryansteckler.nlpunbounce.models.BaseStats.java
com.ryansteckler.nlpunbounce.models.EventLookup.java
com.ryansteckler.nlpunbounce.models.InterimEvent.java
com.ryansteckler.nlpunbounce.models.ServiceStats.java
com.ryansteckler.nlpunbounce.models.UnbounceStatsCollection.java
com.ryansteckler.nlpunbounce.models.WakelockStats.java
com.ryansteckler.nlpunbounce.tasker.TaskerActivity.java
com.ryansteckler.nlpunbounce.tasker.TaskerReceiver.java
com.ryansteckler.nlpunbounce.tasker.TaskerWhichFragment.java