Android Open Source - WarDroid News List View Adapter






From Project

Back to project page WarDroid.

License

The source code is released under:

MIT License

If you think the Android project WarDroid 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.deathsnacks.wardroid.adapters;
// ww  w . ja va2s . co m
import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.deathsnacks.wardroid.R;

import java.util.List;

/**
 * Created by Admin on 25/01/14.
 */
public class NewsListViewAdapter extends BaseAdapter {
    private Activity mActivity;
    private List<String> mLines;
    private LayoutInflater mInflater;

    public NewsListViewAdapter(Activity act, List<String> data) {
        mActivity = act;
        mLines = data;
        mInflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public String getOriginalValues() {
        return TextUtils.join("\n", mLines);
    }

    public int getCount() {
        return mLines.size();
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;
        if (view == null)
            view = mInflater.inflate(R.layout.list_item_news, null);
        TextView text = (TextView) view.findViewById(R.id.news_text);
        TextView duration = (TextView) view.findViewById(R.id.news_duration);
        TextView url = (TextView) view.findViewById(R.id.news_url);

        String line = mLines.get(position);
        String[] parts = line.split("\\|");
        if (parts.length != 4) {
            View dedView = new View(mActivity);
            dedView.setVisibility(View.GONE);
            return dedView;
        }
        text.setText(parts[3]);
        int activation = Integer.parseInt(parts[2]);
        long now = (long) (System.currentTimeMillis() / 1000);
        long diff = now - activation;
        long days = (long) Math.floor(diff / 86400);
        long hours = (long) Math.floor(diff / 3600) % 24;
        long minutes = (diff / 60 % 60);
        long used = minutes;
        String usedstr = "m";
        if (hours >= 1) {
            used = hours;
            usedstr = "h";
        }
        if (days >= 1) {
            used = days;
            usedstr = "d";
        }
        duration.setText(String.format("[%d%s]", used, usedstr));
        url.setText(parts[1]);
        return view;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
}




Java Source Code List

afzkl.development.colorpickerview.dialog.ColorPickerDialog.java
afzkl.development.colorpickerview.drawable.AlphaPatternDrawable.java
afzkl.development.colorpickerview.preference.ColorPickerPreference.java
afzkl.development.colorpickerview.view.ColorPanelView.java
afzkl.development.colorpickerview.view.ColorPickerView.java
android.support.v4.preference.PreferenceFragment.java
android.support.v4.preference.PreferenceManagerCompat.java
com.deathsnacks.wardroid.Constants.java
com.deathsnacks.wardroid.activities.CustomFilterActivity.java
com.deathsnacks.wardroid.activities.MainActivity.java
com.deathsnacks.wardroid.activities.SettingsActivity.java
com.deathsnacks.wardroid.adapters.AlertsListViewAdapter.java
com.deathsnacks.wardroid.adapters.BadlandsListViewAdapter.java
com.deathsnacks.wardroid.adapters.InvasionListViewAdapter.java
com.deathsnacks.wardroid.adapters.NewsListViewAdapter.java
com.deathsnacks.wardroid.adapters.SeparatedListAdapter.java
com.deathsnacks.wardroid.fragments.AlertsFragment.java
com.deathsnacks.wardroid.fragments.BadlandDialogFragment.java
com.deathsnacks.wardroid.fragments.BadlandsFragment.java
com.deathsnacks.wardroid.fragments.InvasionFragment.java
com.deathsnacks.wardroid.fragments.NewsFragment.java
com.deathsnacks.wardroid.fragments.SettingsFragment.java
com.deathsnacks.wardroid.gson.alert.Activation.java
com.deathsnacks.wardroid.gson.alert.Alert.java
com.deathsnacks.wardroid.gson.alert.CountedItem.java
com.deathsnacks.wardroid.gson.alert.Expiry.java
com.deathsnacks.wardroid.gson.alert.MissionInfo.java
com.deathsnacks.wardroid.gson.alert.MissionReward.java
com.deathsnacks.wardroid.gson.alert._id.java
com.deathsnacks.wardroid.gson.badlands.AttId.java
com.deathsnacks.wardroid.gson.badlands.AttackerInfo.java
com.deathsnacks.wardroid.gson.badlands.BadlandNode.java
com.deathsnacks.wardroid.gson.badlands.ConflictExpiration.java
com.deathsnacks.wardroid.gson.badlands.CountedItem.java
com.deathsnacks.wardroid.gson.badlands.DefId.java
com.deathsnacks.wardroid.gson.badlands.DefenderInfo.java
com.deathsnacks.wardroid.gson.badlands.DeploymentActivationTime.java
com.deathsnacks.wardroid.gson.badlands.End.java
com.deathsnacks.wardroid.gson.badlands.History.java
com.deathsnacks.wardroid.gson.badlands.Id.java
com.deathsnacks.wardroid.gson.badlands.LastHealTime.java
com.deathsnacks.wardroid.gson.badlands.MissionInfo.java
com.deathsnacks.wardroid.gson.badlands.MissionRewardExtra.java
com.deathsnacks.wardroid.gson.badlands.MissionReward.java
com.deathsnacks.wardroid.gson.badlands.Start.java
com.deathsnacks.wardroid.gson.badlands.TaxChangeAllowedTime.java
com.deathsnacks.wardroid.gson.badlands.WinId.java
com.deathsnacks.wardroid.gson.badlands._id.java
com.deathsnacks.wardroid.services.GcmBroadcastReceiver.java
com.deathsnacks.wardroid.services.NotificationsUpdateReceiver.java
com.deathsnacks.wardroid.services.PollingAlarmReceiver.java
com.deathsnacks.wardroid.services.UpdateReceiver.java
com.deathsnacks.wardroid.utils.GlobalApplication.java
com.deathsnacks.wardroid.utils.Http.java
com.deathsnacks.wardroid.utils.Names.java
com.deathsnacks.wardroid.utils.Platform.java
com.deathsnacks.wardroid.utils.PreferenceActivityCallbacks.java
com.deathsnacks.wardroid.utils.PreferenceUtils.java
com.deathsnacks.wardroid.utils.UnifiedPreferenceUtils.java
com.deathsnacks.wardroid.utils.Utils.java
com.deathsnacks.wardroid.utils.gcmclasses.Alert.java
com.deathsnacks.wardroid.utils.gcmclasses.Invasion.java
com.deathsnacks.wardroid.utils.httpclasses.Alert.java
com.deathsnacks.wardroid.utils.httpclasses.InvasionMini.java
com.deathsnacks.wardroid.utils.httpclasses.Invasion.java
com.deathsnacks.wardroid.utils.httpclasses.News.java
com.deathsnacks.wardroid.utils.httpclasses.Sale.java
com.deathsnacks.wardroid.utils.preferences.IntEditTextPreference.java
com.deathsnacks.wardroid.utils.preferences.MultiSelectListPreference.java