Android Open Source - twawm2 Customize Actions Activity






From Project

Back to project page twawm2.

License

The source code is released under:

Copyright (c) 2014, afnf All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistr...

If you think the Android project twawm2 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.appspot.afnf4199ga.twawm.ctl;
/* w w w  .  j av  a 2s .  co m*/
import java.util.ArrayList;

import net.afnf.and.twawm2.R;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import com.appspot.afnf4199ga.twawm.Const;
import com.appspot.afnf4199ga.utils.Logger;
import com.appspot.afnf4199ga.utils.MyStringUtlis;

public class CustomizeActionsActivity extends ListActivity {

    private IconicAdapter adapter = null;
    private ArrayList<ListItem> array = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ctl_customize_actions_main);

        array = constructListItemArrayFromCustomizedData(
                getResources().getStringArray(R.array.entries_menu_widget_click_action_on_choose),
                Const.getPrefWidgetClickActionCustomizedData(this));

        adapter = new IconicAdapter();
        setListAdapter(adapter);

        CwacTouchListView tlv = (CwacTouchListView) getListView();
        tlv.setDropListener(onDrop);
        tlv.setRemoveListener(onRemove);
    }

    public void onSave(View view) {

        StringBuilder sb = new StringBuilder();
        int count = adapter.getCount();
        for (int i = 0; i < count; i++) {
            ListItem item = adapter.getItem(i);
            sb.append(item.value);
            sb.append(item.checked ? 1 : 0);
            sb.append(',');
        }
        Const.updatePrefWidgetClickActionCustomizedData(this, sb.toString());

        finish();
    }

    public void onCancel(View view) {
        finish();
    }

    public static ArrayList<ListItem> constructListItemArrayFromCustomizedData(String[] labels, String customizedData) {
        try {
            ArrayList<ListItem> array = new ArrayList<ListItem>();
            int len = labels.length;

            // ????
            if (MyStringUtlis.isEmpty(customizedData)) {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < len; i++) {
                    sb.append((char) ('a' + i));
                    sb.append("1,");
                }
                customizedData = sb.toString();
            }

            // customizedData??????
            String[] datas = customizedData.split(",");
            int datalen = datas.length;

            for (int i = 0; i < len; i++) {
                String data = "";

                // customizedData????????????????????
                if (datalen <= i) {
                    data = ((char) ('a' + i)) + "1";
                }
                else {
                    data = datas[i];
                }

                // ListItem?????
                char value = data.charAt(0);
                int index = value - 'a';
                boolean checked = data.charAt(1) == '1';
                ListItem item = new ListItem(value, labels[index], checked);
                array.add(item);
            }

            return array;
        }
        catch (Throwable e) {

            // ???????????????customizedData???????????????
            Logger.w("customizedData broken : " + customizedData, e);
            return constructListItemArrayFromCustomizedData(labels, null);
        }
    }

    private CwacTouchListView.DropListener onDrop = new CwacTouchListView.DropListener() {
        @Override
        public void drop(int from, int to) {
            ListItem item = adapter.getItem(from);
            adapter.remove(item);
            adapter.insert(item, to);
        }
    };

    private CwacTouchListView.RemoveListener onRemove = new CwacTouchListView.RemoveListener() {
        @Override
        public void remove(int which) {
            adapter.remove(adapter.getItem(which));
        }
    };

    class IconicAdapter extends ArrayAdapter<ListItem> {
        IconicAdapter() {
            super(CustomizeActionsActivity.this, R.layout.ctl_customize_actions_row, array);
        }

        public View getView(int position, View convertView, ViewGroup parent) {

            View row = convertView;
            if (row == null) {
                LayoutInflater inflater = getLayoutInflater();
                row = inflater.inflate(R.layout.ctl_customize_actions_row, parent, false);
            }

            TextView v = (TextView) row.findViewById(R.id.textView1);
            ListItem item = array.get(position);
            v.setText(item.label);

            CheckBox c = (CheckBox) row.findViewById(R.id.checkBox1);
            c.setOnCheckedChangeListener(new CheckBoxListener(item));
            c.setChecked(item.checked);

            return row;
        }
    }

    class CheckBoxListener implements CompoundButton.OnCheckedChangeListener {
        ListItem item;

        CheckBoxListener(ListItem item) {
            this.item = item;
        }

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            item.checked = isChecked;
        }
    }
}




Java Source Code List

com.appspot.afnf4199ga.twawm.BluetoothHelper.java
com.appspot.afnf4199ga.twawm.Const.java
com.appspot.afnf4199ga.twawm.Const.java
com.appspot.afnf4199ga.twawm.HostnameListTest.java
com.appspot.afnf4199ga.twawm.HostnameList.java
com.appspot.afnf4199ga.twawm.IconSelectorTest.java
com.appspot.afnf4199ga.twawm.IconSelector.java
com.appspot.afnf4199ga.twawm.OnlineChecker.java
com.appspot.afnf4199ga.twawm.StateMachineTest.java
com.appspot.afnf4199ga.twawm.StateMachine.java
com.appspot.afnf4199ga.twawm.TwawmUtils.java
com.appspot.afnf4199ga.twawm.app.BackgroundServiceTest.java
com.appspot.afnf4199ga.twawm.app.BackgroundService.java
com.appspot.afnf4199ga.twawm.app.DefaultWidgetProvider.java
com.appspot.afnf4199ga.twawm.app.InfoActivity.java
com.appspot.afnf4199ga.twawm.app.InitialConfigurationWizardActivity.java
com.appspot.afnf4199ga.twawm.app.LogSendActivity.java
com.appspot.afnf4199ga.twawm.app.MainActivity.java
com.appspot.afnf4199ga.twawm.app.MainApp.java
com.appspot.afnf4199ga.twawm.app.MyPreferenceActivity.java
com.appspot.afnf4199ga.twawm.app.NetworkSwitcher.java
com.appspot.afnf4199ga.twawm.app.StaticIntentListener.java
com.appspot.afnf4199ga.twawm.app.UIAct.java
com.appspot.afnf4199ga.twawm.ctl.CustomizeActionsActivityTest.java
com.appspot.afnf4199ga.twawm.ctl.CustomizeActionsActivity.java
com.appspot.afnf4199ga.twawm.ctl.CwacTouchListView.java
com.appspot.afnf4199ga.twawm.ctl.ListItem.java
com.appspot.afnf4199ga.twawm.router.EcoModeControlTest.java
com.appspot.afnf4199ga.twawm.router.EcoModeControl.java
com.appspot.afnf4199ga.twawm.router.InetLookupWrappter.java
com.appspot.afnf4199ga.twawm.router.InetLookupWrappter.java
com.appspot.afnf4199ga.twawm.router.MyHttpClientTest.java
com.appspot.afnf4199ga.twawm.router.MyHttpClient.java
com.appspot.afnf4199ga.twawm.router.MyHttpClient.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttpTest.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttp.java
com.appspot.afnf4199ga.twawm.router.RouterControlByHttp.java
com.appspot.afnf4199ga.twawm.router.RouterControl.java
com.appspot.afnf4199ga.twawm.router.RouterControl.java
com.appspot.afnf4199ga.twawm.router.RouterInfo.java
com.appspot.afnf4199ga.twawm.router.RouterInfo.java
com.appspot.afnf4199ga.utils.AndroidUtilsTest.java
com.appspot.afnf4199ga.utils.AndroidUtils.java
com.appspot.afnf4199ga.utils.AndroidUtils.java
com.appspot.afnf4199ga.utils.Logger.java
com.appspot.afnf4199ga.utils.Logger.java
com.appspot.afnf4199ga.utils.MyStringUtlisTest.java
com.appspot.afnf4199ga.utils.MyStringUtlis.java
com.appspot.afnf4199ga.utils.MyStringUtlis.java
com.appspot.afnf4199ga.utils.MyTestUtils.java
com.appspot.afnf4199ga.utils.MyUncaughtExceptionHandler.java
com.appspot.afnf4199ga.utils.MyUncaughtExceptionHandler.java
com.appspot.afnf4199ga.wmgraph.app.FetchThread.java
com.appspot.afnf4199ga.wmgraph.app.InetLookupThread.java
com.appspot.afnf4199ga.wmgraph.app.InfoActivity.java
com.appspot.afnf4199ga.wmgraph.app.MainActivity.java
com.appspot.afnf4199ga.wmgraph.app.MyPreferenceActivity.java
com.appspot.afnf4199ga.wmgraph.app.UIAct.java
net.afnf.and.twawm2.DexmakerInstrumentationTestCase.java
net.afnf.and.twawm2.MyInstrumentationTestRunner.java