Finished writtenMorse List Fragment

This commit is contained in:
mmk2410 2015-03-31 09:28:17 +02:00
parent 0e6b5e610b
commit 1cc255ba58
5 changed files with 55 additions and 17 deletions

View file

@ -1 +1 @@
A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z;0;1;2;3;4;5;6;7;8;9;
A:01;B:1000;C:1010;D:100;E:0;F:0010;G:110;H:0000;I:00;J:0111;K:101;L:0100;M:11;N:10;O:111;P:0110;Q:1101;R:010;S:000;T:1;U:001;V:0001;W:011;X:1001;Y:1011;Z:1100;0:11111;1:01111;2:00111;3:00011;4:00001;5:00000;6:10000;7:11000;8:11100;9:11110;Ö:1110;Ü:0011;CH:1111;.:010101;,:110011;?:001100;-:100001;_:001101;(:10110;):101101;':011110;=:10001;+:01010;/:10010;@:011010;BEGIN:10101;BREAK:10001;END:01010;SOS:000111000;ERROR:00000000;

View file

@ -10,23 +10,25 @@ import android.widget.TextView;
* Created by mmk on 3/30/15.
*/
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private String[] mDataset;
private String[] mLetter;
private String[] mCode;
private static String mType = "LETTER";
public static class ViewHolder extends RecyclerView.ViewHolder {
// each data item is just a string in this case
public TextView mTextView;
public TextView mLetterView;
public TextView mCodeView;
public ViewHolder(View v) {
super(v);
mTextView = (TextView) v.findViewById(R.id.codefield);
mLetterView = (TextView) v.findViewById(R.id.letterfield);
mCodeView = (TextView) v.findViewById(R.id.codefield);
}
public TextView getTextView() {
return mTextView;
}
}
public MyAdapter(String[] myDataset) {
mDataset = myDataset;
public MyAdapter(String[] myLetter, String[] myCode) {
mLetter = myLetter;
mCode = myCode;
}
@Override
@ -42,12 +44,13 @@ public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
// Replace the contents of a view (invoked by the layout manager)
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.mTextView.setText(mDataset[position]);
holder.mLetterView.setText(mLetter[position]);
holder.mCodeView.setText(mCode[position]);
}
@Override
public int getItemCount() {
return mDataset.length;
return mCode.length;
}
}

View file

@ -14,6 +14,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class writtenMorseListFragment extends Fragment {
@ -21,7 +22,8 @@ public class writtenMorseListFragment extends Fragment {
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
private String[] myDataset;
private String[] myLetter;
private String[] myCode;
private static final String TAG = "RecyclerViewFragment";
@Override
@ -38,13 +40,14 @@ public class writtenMorseListFragment extends Fragment {
mLayoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(mLayoutManager);
getDataset();
mAdapter = new MyAdapter(myDataset);
mAdapter = new MyAdapter(myLetter, myCode);
mRecyclerView.setAdapter(mAdapter);
return rootView;
}
private void getDataset(){
ArrayList<String> dataset = new ArrayList<>();
ArrayList<String> letterset = new ArrayList<>();
ArrayList<String> codeset = new ArrayList<>();
String datastring = "";
AssetManager astmgr = getActivity().getAssets();
try {
@ -64,10 +67,18 @@ public class writtenMorseListFragment extends Fragment {
for(int c = 0; datastring.length() > 1; c++){
int pos = datastring.indexOf(";");
dataset.add(datastring.substring(0, pos));
String datasubstring = datastring.substring(0, pos);
int subpos = datasubstring.indexOf(":");
letterset.add(datasubstring.substring(0, subpos));
codeset.add(datasubstring.substring(subpos + 1, pos));
datastring = datastring.substring(pos + 1);
myDataset = dataset.toArray(new String[dataset.size()]);
}
letterset.add(":");
letterset.add(";");
codeset.add("111000");
codeset.add("101010");
myLetter = letterset.toArray(new String[letterset.size()]);
myCode = codeset.toArray(new String[letterset.size()]);
}
}

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingRight="150dp"
android:paddingLeft="150dp">
<android.support.v7.widget.RecyclerView
android:id="@+id/wm_recycler"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

View file

@ -1,12 +1,22 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:padding="5dp"
android:paddingRight="32dp"
android:paddingLeft="32dp"
android:layout_height="64dp">
<TextView
android:id="@+id/letterfield"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/hello_world"
android:gravity="center_vertical"/>
<TextView
android:id="@+id/codefield"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="@string/hello_world"
android:layout_gravity="right"
android:gravity="center_vertical"/>
</FrameLayout>