From 1cc255ba58fe854007f829435863118d60f4e29d Mon Sep 17 00:00:00 2001 From: mmk2410 Date: Tue, 31 Mar 2015 09:28:17 +0200 Subject: [PATCH] Finished writtenMorse List Fragment --- app/src/main/assets/codes.txt | 2 +- .../morseconverter/MyAdapter.java | 23 +++++++++++-------- .../writtenMorseListFragment.java | 21 +++++++++++++---- .../fragment_written_morse_list.xml | 14 +++++++++++ app/src/main/res/layout/codeview.xml | 12 +++++++++- 5 files changed, 55 insertions(+), 17 deletions(-) create mode 100644 app/src/main/res/layout-large-land/fragment_written_morse_list.xml diff --git a/app/src/main/assets/codes.txt b/app/src/main/assets/codes.txt index 668b445..f7a2e4a 100644 --- a/app/src/main/assets/codes.txt +++ b/app/src/main/assets/codes.txt @@ -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; \ No newline at end of file +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; diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/MyAdapter.java b/app/src/main/java/de/marcelkapfer/morseconverter/MyAdapter.java index dbe687c..f637714 100644 --- a/app/src/main/java/de/marcelkapfer/morseconverter/MyAdapter.java +++ b/app/src/main/java/de/marcelkapfer/morseconverter/MyAdapter.java @@ -10,23 +10,25 @@ import android.widget.TextView; * Created by mmk on 3/30/15. */ public class MyAdapter extends RecyclerView.Adapter { - 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 { // 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; } } diff --git a/app/src/main/java/de/marcelkapfer/morseconverter/writtenMorseListFragment.java b/app/src/main/java/de/marcelkapfer/morseconverter/writtenMorseListFragment.java index 972b9e0..1f5f927 100644 --- a/app/src/main/java/de/marcelkapfer/morseconverter/writtenMorseListFragment.java +++ b/app/src/main/java/de/marcelkapfer/morseconverter/writtenMorseListFragment.java @@ -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 dataset = new ArrayList<>(); + ArrayList letterset = new ArrayList<>(); + ArrayList 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()]); } } diff --git a/app/src/main/res/layout-large-land/fragment_written_morse_list.xml b/app/src/main/res/layout-large-land/fragment_written_morse_list.xml new file mode 100644 index 0000000..93f5b6c --- /dev/null +++ b/app/src/main/res/layout-large-land/fragment_written_morse_list.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/codeview.xml b/app/src/main/res/layout/codeview.xml index 353586e..2f01ead 100644 --- a/app/src/main/res/layout/codeview.xml +++ b/app/src/main/res/layout/codeview.xml @@ -1,12 +1,22 @@ + + + \ No newline at end of file