CircleIndicator を ViewPager の最下部に置く

github.com

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.makaroni.circleviewpagertest.MainActivity"
    >

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        />

    <me.relex.circleindicator.CircleIndicator
        android:id="@+id/indicator"
        android:layout_width="match_parent"
        android:layout_alignBottom="@+id/viewpager"
        android:layout_height="50sp"
        android:layout_marginBottom="50sp"
        app:ci_drawable="@drawable/circle"
        app:ci_height="10sp"
        app:ci_width="10sp"
        />

</RelativeLayout>

Unity Button OnClick処理

例はボタンを押したら残機を増やす処理

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class IncrementZankiController : MonoBehaviour {

    public Text text;
    public Image heart1;
    public Image heart2;
    public Image heart3;

    public void IncrementLife(){
        Sprite image = Resources.Load<Sprite> ("heart_full");
        int life = int.Parse (text.text);
        if (life == 0) {
            heart1.sprite = image;
            life++;
        } else if (life == 1) {
            heart2.sprite = image;
            life++;
        } else if (life == 2) {
            heart3.sprite = image;
            life++;
        }
        text.text = life.ToString ();
    }
}

ダイアログにEditView表示して、内容をクリップボードにコピー

@OnClick(R.id.btn)
    void buttonOnClick(View v) {
        //テキスト入力を受け付けるビューを作成します。
        final EditText editView = new EditText(MainActivity.this);
        editView.setText("hogehoge");
        new AlertDialog.Builder(MainActivity.this)
            .setIcon(android.R.drawable.ic_dialog_info)
            .setTitle("タイトル")
            .setView(editView)
            .setPositiveButton("コピー", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    CopyClipBoard(editView.getText().toString());
                }
            })
            .setNegativeButton("キャンセル", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                }
            })
            .show();
    }

    public void CopyClipBoard(String text) {
        SetClipData(text);
    }

    private void SetClipData(String allText) {
        try {
            ClipData.Item item = new ClipData.Item(allText);

            String[] mimeType = new String[1];
            mimeType[0] = ClipDescription.MIMETYPE_TEXT_URILIST;

            ClipData cd = new ClipData(new ClipDescription("text_data", mimeType), item);

            ClipboardManager cm = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
            cm.setPrimaryClip(cd);
        }
        catch(Exception e) {
            e.printStackTrace();
        }
    }

Android リストビュー

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ListView myListView = (ListView) findViewById(R.id.myListView);

        ArrayList<User> users = new ArrayList<>();

        int[] icons = {
            R.mipmap.ic_launcher,
            R.mipmap.ic_launcher,
            R.mipmap.ic_launcher,
        };

        String[] names = {
            "maroni1",
            "maroni2",
            "maroni3",
        };

        String[] locs = {
            "US",
            "UK",
            "JP",
        };

        for (int i = 0; i < icons.length; i++) {
            User user = new User();
            user.setIcon(BitmapFactory.decodeResource(
                getResources(),
                icons[i]
            ));
            user.setName(names[i]);
            user.setLocation(locs[i]);
            users.add(user);
        }

        UserAdapter adapter = new UserAdapter(this, 0, users);


//        for (int i = 0; i < 30; i++) {
//            items.add("item-" + i);
//        }
//
//        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
//            this,
//            R.layout.list_item,
//            items
//        );
//
        myListView.setEmptyView(findViewById(R.id.emptyView));
        myListView.setAdapter(adapter);

        myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(
                AdapterView<?> parent,
                View view,
                int position,
                long id
            ) {
                TextView name = (TextView)view.findViewById(R.id.name);
                Toast.makeText(
                    MainActivity.this,
                    Integer.toString(position) + ":" + name.getText().toString(),
                    Toast.LENGTH_SHORT
                ).show();
            }
        });
    }

    public class UserAdapter extends ArrayAdapter<User> {
        private LayoutInflater layoutInflater;

        public UserAdapter(Context context, int resource, ArrayList<User> users) {
            super(context, resource, users);
            this.layoutInflater = (LayoutInflater) context.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE
            );
        }

        @NonNull
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;

            if (convertView == null) {
                convertView = layoutInflater.inflate(
                    R.layout.list_item,
                    parent,
                    false
                );
                holder = new ViewHolder();
                holder.icon = (ImageView) convertView.findViewById(R.id.icon);
                holder.name = (TextView) convertView.findViewById(R.id.name);
                holder.location = (TextView) convertView.findViewById(R.id.loc);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            User user = (User) getItem(position);

            holder.icon.setImageBitmap(user.getIcon());
            holder.name.setText(user.getName());
            holder.location.setText(user.getLocation());

            return convertView;
        }
    }

    static class ViewHolder {
        ImageView icon;
        TextView name;
        TextView location;
    }

    public class User {
        private Bitmap icon;
        private String name;
        private String location;

        public Bitmap getIcon() {
            return icon;
        }

        public void setIcon(Bitmap icon) {
            this.icon = icon;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getLocation() {
            return location;
        }

        public void setLocation(String location) {
            this.location = location;
        }
    }
}

Keras で ORの学習

import numpy as np
import keras
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers import Dense

model = Sequential()
model.add(Dense(input_dim=2, activation='relu', units=1))

model.compile(loss='mean_squared_error', optimizer='sgd', metrics=['accuracy'])

# データセット
x_train = [
    [0, 0],
    [0, 1],
    [1, 0],
    [1, 1],
]
# 正解ラベル
y_train = [[0],[1],[1],[1]]

model.fit(x_train, y_train, nb_epoch=10, batch_size=1)
score = model.evaluate(x_train, y_train, verbose=0)
print("test-accuracy: {}".format(score[1]))

シンプルなmnist (python3.5 chainer)

import chainer
import chainer.functions as F
import chainer.links as L
from chainer import training
from chainer.training import extensions

class MnistModel(chainer.Chain):
    def __init__(self, out_units):
        super(MnistModel,self).__init__(
                l1 = L.Linear(None, 100),
                l2 = L.Linear(None, 100),
                l3 = L.Linear(None, out_units))

    def __call__(self,x):
         h = F.relu(self.l1(x))
         h = F.relu(self.l2(h))
         return self.l3(h)


model = L.Classifier(MnistModel(out_units=10))
optimizer = chainer.optimizers.Adam()
optimizer.setup(model)

train, test = chainer.datasets.get_mnist()
train_iter = chainer.iterators.SerialIterator(train, 100)
test_iter = chainer.iterators.SerialIterator(test, 100,repeat=False, shuffle=False)

updater = training.StandardUpdater(train_iter, optimizer, device=-1)
trainer = training.Trainer(updater, (100, 'epoch'), out="result")
trainer.extend(extensions.Evaluator(test_iter, model, device=-1))
trainer.extend(extensions.LogReport())
trainer.extend(extensions.PrintReport(['epoch', 'main/loss', 'validation/main/loss', 'main/accuracy', 'validation/main/accuracy']))
trainer.extend(extensions.ProgressBar())
if extensions.PlotReport.available():
    trainer.extend(
        extensions.PlotReport(['main/loss', 'validation/main/loss'], 'epoch', file_name='loss.png'))
    trainer.extend(
        extensions.PlotReport(
            ['main/accuracy', 'validation/main/accuracy'], 'epoch', file_name='accuracy.png'))
    
trainer.run()

SQL メモ

重複しているカラムを持つレコード抽出

select email from users group by email having count(email) <> 1;