Android Open Source - unbounce-android Wakelocks 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;
// w ww. jav  a  2 s.com
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
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.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 WakelocksAdapter extends BaseAdapter {

    //Track whether we're sorting by count or duration.
    private int mSortBy = SortWakeLocks.SORT_COUNT;

    public WakelocksAdapter(Context context, ArrayList<BaseStats> wakelockStatList) {
        super(context, R.layout.fragment_wakelocks_listitem, wakelockStatList, "wakelock");
    }


    private static class WakelockViewHolder {
        TextView name;
        TextView wakeTime;
        TextView wakeCount;
    }

    @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
                WakelockStats wakelock = (WakelockStats)getItem(position);

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

                    LayoutInflater inflater = LayoutInflater.from(getContext());
                    convertView = inflater.inflate(R.layout.fragment_wakelocks_listitem, parent, false);
                    viewHolder.name = (TextView) convertView.findViewById(R.id.textviewWakelockName);
                    viewHolder.wakeTime = (TextView) convertView.findViewById(R.id.textviewWakelockTime);
                    viewHolder.wakeCount = (TextView) convertView.findViewById(R.id.textViewWakelockCount);

                    convertView.setTag(viewHolder);
                }
                else {
                    viewHolder = (WakelockViewHolder) convertView.getTag();
                }

                // Populate the data into the template view using the data object
                viewHolder.name.setText(wakelock.getName());
                viewHolder.name.setSelected(true);

                viewHolder.wakeTime.setText(String.valueOf(wakelock.getDurationAllowedFormatted()));
                viewHolder.wakeCount.setText(String.valueOf(wakelock.getAllowedCount()));

                //Size the count box width to at least the height.
                viewHolder.wakeCount.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                int height = viewHolder.wakeCount.getMeasuredHeight();
                int width = viewHolder.wakeCount.getMeasuredWidth();
                if (height > width) {
                    viewHolder.wakeCount.setLayoutParams(new LinearLayout.LayoutParams(height, height));
                }
                else {
                    viewHolder.wakeCount.setLayoutParams(new LinearLayout.LayoutParams(width, width));
                }
                float[] hsv = getBackColorFromSpectrum(wakelock);
                viewHolder.wakeCount.setBackgroundColor(Color.HSVToColor(hsv));

                hsv = getForeColorFromBack(hsv);
                viewHolder.wakeCount.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.getWakelockListComparator(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