Revision 0fd3ac1f
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/magic/RubikAbout.java | ||
|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // Copyright 2019 Leszek Koltunski // | |
| 3 | // // | |
| 4 | // This file is part of Magic Cube. // | |
| 5 | // // | |
| 6 | // Magic Cube is free software: you can redistribute it and/or modify // | |
| 7 | // it under the terms of the GNU General Public License as published by // | |
| 8 | // the Free Software Foundation, either version 2 of the License, or // | |
| 9 | // (at your option) any later version. // | |
| 10 | // // | |
| 11 | // Magic Cube is distributed in the hope that it will be useful, // | |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
| 14 | // GNU General Public License for more details. // | |
| 15 | // // | |
| 16 | // You should have received a copy of the GNU General Public License // | |
| 17 | // along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // | |
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 |  | |
| 20 | package org.distorted.magic; | |
| 21 |  | |
| 22 | import android.app.Dialog; | |
| 23 | import android.content.DialogInterface; | |
| 24 | import android.os.Bundle; | |
| 25 | import android.support.annotation.NonNull; | |
| 26 | import android.support.v4.app.FragmentActivity; | |
| 27 | import android.support.v7.app.AlertDialog; | |
| 28 | import android.support.v7.app.AppCompatDialogFragment; | |
| 29 | import android.view.LayoutInflater; | |
| 30 | import android.view.View; | |
| 31 |  | |
| 32 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 33 |  | |
| 34 | public class RubikAbout extends AppCompatDialogFragment | |
| 35 |   {
 | |
| 36 | @NonNull | |
| 37 | @Override | |
| 38 | public Dialog onCreateDialog(Bundle savedInstanceState) | |
| 39 |     {
 | |
| 40 | FragmentActivity act = getActivity(); | |
| 41 | AlertDialog.Builder builder = new AlertDialog.Builder(act); | |
| 42 |  | |
| 43 | builder.setTitle(R.string.app_version); | |
| 44 | builder.setIcon(R.drawable.button3); | |
| 45 | builder.setCancelable(false); | |
| 46 | builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() | |
| 47 |       {
 | |
| 48 | @Override | |
| 49 | public void onClick(DialogInterface dialog, int which) | |
| 50 |         {
 | |
| 51 |  | |
| 52 | } | |
| 53 | }); | |
| 54 |  | |
| 55 | LayoutInflater inflater = act.getLayoutInflater(); | |
| 56 | final View view = inflater.inflate(R.layout.about, null); | |
| 57 | builder.setView(view); | |
| 58 |  | |
| 59 | return builder.create(); | |
| 60 | } | |
| 61 | } | |
| src/main/java/org/distorted/magic/RubikActivity.java | ||
|---|---|---|
| 151 | 151 |  | 
| 152 | 152 | public void Settings(View v) | 
| 153 | 153 |       {
 | 
| 154 |       RubikSettings settings = new RubikSettings();
 | |
| 154 |       RubikDialogSettings settings = new RubikDialogSettings();
 | |
| 155 | 155 | settings.show(getSupportFragmentManager(), null); | 
| 156 | 156 | } | 
| 157 | 157 |  | 
| ... | ... | |
| 163 | 163 | Bundle bundle = new Bundle(); | 
| 164 | 164 |       bundle.putInt("tab", view.getRedButton());
 | 
| 165 | 165 |  | 
| 166 |       RubikScores scores = new RubikScores();
 | |
| 166 |       RubikDialogScores scores = new RubikDialogScores();
 | |
| 167 | 167 | scores.setArguments(bundle); | 
| 168 | 168 | scores.show(getSupportFragmentManager(), null); | 
| 169 | 169 | } | 
| ... | ... | |
| 172 | 172 |  | 
| 173 | 173 | public void About(View v) | 
| 174 | 174 |       {
 | 
| 175 |       RubikAbout about = new RubikAbout();
 | |
| 175 |       RubikDialogAbout about = new RubikDialogAbout();
 | |
| 176 | 176 | about.show(getSupportFragmentManager(), null); | 
| 177 | 177 | } | 
| 178 | 178 |  | 
| src/main/java/org/distorted/magic/RubikDialogAbout.java | ||
|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // Copyright 2019 Leszek Koltunski // | |
| 3 | // // | |
| 4 | // This file is part of Magic Cube. // | |
| 5 | // // | |
| 6 | // Magic Cube is free software: you can redistribute it and/or modify // | |
| 7 | // it under the terms of the GNU General Public License as published by // | |
| 8 | // the Free Software Foundation, either version 2 of the License, or // | |
| 9 | // (at your option) any later version. // | |
| 10 | // // | |
| 11 | // Magic Cube is distributed in the hope that it will be useful, // | |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
| 14 | // GNU General Public License for more details. // | |
| 15 | // // | |
| 16 | // You should have received a copy of the GNU General Public License // | |
| 17 | // along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // | |
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 |  | |
| 20 | package org.distorted.magic; | |
| 21 |  | |
| 22 | import android.app.Dialog; | |
| 23 | import android.content.DialogInterface; | |
| 24 | import android.os.Bundle; | |
| 25 | import android.support.annotation.NonNull; | |
| 26 | import android.support.v4.app.FragmentActivity; | |
| 27 | import android.support.v7.app.AlertDialog; | |
| 28 | import android.support.v7.app.AppCompatDialogFragment; | |
| 29 | import android.view.LayoutInflater; | |
| 30 | import android.view.View; | |
| 31 | import android.widget.TextView; | |
| 32 |  | |
| 33 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 34 |  | |
| 35 | public class RubikDialogAbout extends AppCompatDialogFragment | |
| 36 |   {
 | |
| 37 | @NonNull | |
| 38 | @Override | |
| 39 | public Dialog onCreateDialog(Bundle savedInstanceState) | |
| 40 |     {
 | |
| 41 | FragmentActivity act = getActivity(); | |
| 42 | LayoutInflater inflater = act.getLayoutInflater(); | |
| 43 | AlertDialog.Builder builder = new AlertDialog.Builder(act); | |
| 44 |  | |
| 45 | TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); | |
| 46 | tv.setText(R.string.about_title); | |
| 47 | builder.setCustomTitle(tv); | |
| 48 |  | |
| 49 | builder.setCancelable(true); | |
| 50 | builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() | |
| 51 |       {
 | |
| 52 | @Override | |
| 53 | public void onClick(DialogInterface dialog, int which) | |
| 54 |         {
 | |
| 55 |  | |
| 56 | } | |
| 57 | }); | |
| 58 |  | |
| 59 | final View view = inflater.inflate(R.layout.dialog_about, null); | |
| 60 | TextView text = view.findViewById(R.id.about_version); | |
| 61 | text.setText(R.string.app_version); | |
| 62 | builder.setView(view); | |
| 63 |  | |
| 64 | return builder.create(); | |
| 65 | } | |
| 66 | } | |
| src/main/java/org/distorted/magic/RubikDialogMain.java | ||
|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // Copyright 2019 Leszek Koltunski // | |
| 3 | // // | |
| 4 | // This file is part of Magic Cube. // | |
| 5 | // // | |
| 6 | // Magic Cube is free software: you can redistribute it and/or modify // | |
| 7 | // it under the terms of the GNU General Public License as published by // | |
| 8 | // the Free Software Foundation, either version 2 of the License, or // | |
| 9 | // (at your option) any later version. // | |
| 10 | // // | |
| 11 | // Magic Cube is distributed in the hope that it will be useful, // | |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
| 14 | // GNU General Public License for more details. // | |
| 15 | // // | |
| 16 | // You should have received a copy of the GNU General Public License // | |
| 17 | // along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // | |
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 |  | |
| 20 | package org.distorted.magic; | |
| 21 |  | |
| 22 | import android.app.Dialog; | |
| 23 | import android.content.DialogInterface; | |
| 24 | import android.os.Bundle; | |
| 25 | import android.support.annotation.NonNull; | |
| 26 | import android.support.v4.app.FragmentActivity; | |
| 27 | import android.support.v7.app.AlertDialog; | |
| 28 | import android.support.v7.app.AppCompatDialogFragment; | |
| 29 | import android.view.LayoutInflater; | |
| 30 | import android.view.View; | |
| 31 |  | |
| 32 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 33 |  | |
| 34 | public class RubikDialogMain extends AppCompatDialogFragment | |
| 35 |   {
 | |
| 36 | @NonNull | |
| 37 | @Override | |
| 38 | public Dialog onCreateDialog(Bundle savedInstanceState) | |
| 39 |     {
 | |
| 40 | FragmentActivity act = getActivity(); | |
| 41 | AlertDialog.Builder builder = new AlertDialog.Builder(act); | |
| 42 |  | |
| 43 | builder.setTitle(R.string.app_version); | |
| 44 | builder.setIcon(R.drawable.button3); | |
| 45 | builder.setCancelable(false); | |
| 46 | builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() | |
| 47 |       {
 | |
| 48 | @Override | |
| 49 | public void onClick(DialogInterface dialog, int which) | |
| 50 |         {
 | |
| 51 |  | |
| 52 | } | |
| 53 | }); | |
| 54 |  | |
| 55 | LayoutInflater inflater = act.getLayoutInflater(); | |
| 56 | final View view = inflater.inflate(R.layout.dialog_about, null); | |
| 57 | builder.setView(view); | |
| 58 |  | |
| 59 | return builder.create(); | |
| 60 | } | |
| 61 | } | |
| src/main/java/org/distorted/magic/RubikDialogScores.java | ||
|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // Copyright 2019 Leszek Koltunski // | |
| 3 | // // | |
| 4 | // This file is part of Magic Cube. // | |
| 5 | // // | |
| 6 | // Magic Cube is free software: you can redistribute it and/or modify // | |
| 7 | // it under the terms of the GNU General Public License as published by // | |
| 8 | // the Free Software Foundation, either version 2 of the License, or // | |
| 9 | // (at your option) any later version. // | |
| 10 | // // | |
| 11 | // Magic Cube is distributed in the hope that it will be useful, // | |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
| 14 | // GNU General Public License for more details. // | |
| 15 | // // | |
| 16 | // You should have received a copy of the GNU General Public License // | |
| 17 | // along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // | |
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 |  | |
| 20 | package org.distorted.magic; | |
| 21 |  | |
| 22 | import android.app.Dialog; | |
| 23 | import android.content.DialogInterface; | |
| 24 | import android.os.Bundle; | |
| 25 | import android.support.annotation.NonNull; | |
| 26 | import android.support.v4.app.FragmentActivity; | |
| 27 | import android.support.v4.view.ViewPager; | |
| 28 | import android.support.v7.app.AlertDialog; | |
| 29 | import android.support.v7.app.AppCompatDialogFragment; | |
| 30 | import android.support.design.widget.TabLayout; | |
| 31 | import android.view.LayoutInflater; | |
| 32 | import android.view.View; | |
| 33 | import android.widget.ImageView; | |
| 34 | import android.widget.TextView; | |
| 35 |  | |
| 36 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 37 |  | |
| 38 | public class RubikDialogScores extends AppCompatDialogFragment | |
| 39 |   {
 | |
| 40 | RubikDialogScoresPagerAdapter mPagerAdapter; | |
| 41 |  | |
| 42 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 43 |  | |
| 44 | @NonNull | |
| 45 | @Override | |
| 46 | public Dialog onCreateDialog(Bundle savedInstanceState) | |
| 47 |     {
 | |
| 48 | FragmentActivity act = getActivity(); | |
| 49 | AlertDialog.Builder builder = new AlertDialog.Builder(act); | |
| 50 |  | |
| 51 | LayoutInflater layoutInflater = act.getLayoutInflater(); | |
| 52 | TextView tv = (TextView) layoutInflater.inflate(R.layout.dialog_title, null); | |
| 53 | tv.setText(R.string.scores_title); | |
| 54 | builder.setCustomTitle(tv); | |
| 55 |  | |
| 56 | builder.setCancelable(true); | |
| 57 | builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() | |
| 58 |       {
 | |
| 59 | @Override | |
| 60 | public void onClick(DialogInterface dialog, int which) | |
| 61 |         {
 | |
| 62 |  | |
| 63 | } | |
| 64 | }); | |
| 65 |  | |
| 66 | Bundle args = getArguments(); | |
| 67 | int curTab; | |
| 68 |  | |
| 69 | try | |
| 70 |       {
 | |
| 71 |       curTab = args.getInt("tab");
 | |
| 72 | } | |
| 73 | catch(Exception e) | |
| 74 |       {
 | |
| 75 | curTab = 0; | |
| 76 | } | |
| 77 |  | |
| 78 | LayoutInflater inflater = act.getLayoutInflater(); | |
| 79 | final View view = inflater.inflate(R.layout.dialog_scores, null); | |
| 80 | builder.setView(view); | |
| 81 |  | |
| 82 | ViewPager viewPager = view.findViewById(R.id.viewpager); | |
| 83 | TabLayout tabLayout = view.findViewById(R.id.sliding_tabs); | |
| 84 | mPagerAdapter = new RubikDialogScoresPagerAdapter(act,viewPager); | |
| 85 | tabLayout.setupWithViewPager(viewPager); | |
| 86 |  | |
| 87 | viewPager.setCurrentItem(curTab); | |
| 88 |  | |
| 89 | for (int i = 0; i< RubikSize.LENGTH; i++) | |
| 90 |       {
 | |
| 91 | ImageView imageView = new ImageView(act); | |
| 92 | imageView.setImageResource(RubikSize.getSize(i).getIconID()); | |
| 93 | TabLayout.Tab tab = tabLayout.getTabAt(i); | |
| 94 | if(tab!=null) tab.setCustomView(imageView); | |
| 95 | } | |
| 96 |  | |
| 97 | return builder.create(); | |
| 98 | } | |
| 99 | } | |
| src/main/java/org/distorted/magic/RubikDialogScoresPagerAdapter.java | ||
|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // Copyright 2020 Leszek Koltunski // | |
| 3 | // // | |
| 4 | // This file is part of Magic Cube. // | |
| 5 | // // | |
| 6 | // Magic Cube is free software: you can redistribute it and/or modify // | |
| 7 | // it under the terms of the GNU General Public License as published by // | |
| 8 | // the Free Software Foundation, either version 2 of the License, or // | |
| 9 | // (at your option) any later version. // | |
| 10 | // // | |
| 11 | // Magic Cube is distributed in the hope that it will be useful, // | |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
| 14 | // GNU General Public License for more details. // | |
| 15 | // // | |
| 16 | // You should have received a copy of the GNU General Public License // | |
| 17 | // along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // | |
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 |  | |
| 20 | package org.distorted.magic; | |
| 21 |  | |
| 22 | import android.support.annotation.NonNull; | |
| 23 | import android.support.v4.app.FragmentActivity; | |
| 24 | import android.support.v4.view.PagerAdapter; | |
| 25 | import android.support.v4.view.ViewPager; | |
| 26 | import android.view.View; | |
| 27 | import android.view.ViewGroup; | |
| 28 |  | |
| 29 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 30 |  | |
| 31 | class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresDownloader.Receiver | |
| 32 |   {
 | |
| 33 | private FragmentActivity mAct; | |
| 34 | private RubikDialogScoresView[] mViews; | |
| 35 | private ViewPager mViewPager; | |
| 36 |  | |
| 37 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 38 |  | |
| 39 | public void receive(final int[][][] country, final String[][][] name, final String[][][] time) | |
| 40 |     {
 | |
| 41 | prepareView(); | |
| 42 |  | |
| 43 | int c = mViewPager.getCurrentItem(); | |
| 44 |  | |
| 45 | addPage(mViews[c],country[c],name[c],time[c]); | |
| 46 |  | |
| 47 | for(int i=0; i<RubikSize.LENGTH; i++) | |
| 48 |       {
 | |
| 49 | if( i==c ) continue; | |
| 50 |  | |
| 51 | addPage(mViews[i],country[i],name[i],time[i]); | |
| 52 | } | |
| 53 | } | |
| 54 |  | |
| 55 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 56 |  | |
| 57 | private void prepareView() | |
| 58 |     {
 | |
| 59 | mAct.runOnUiThread(new Runnable() | |
| 60 |       {
 | |
| 61 | @Override | |
| 62 | public void run() | |
| 63 |         {
 | |
| 64 | for(int i=0; i<RubikSize.LENGTH; i++) | |
| 65 |           {
 | |
| 66 | mViews[i].prepareView(mAct); | |
| 67 | } | |
| 68 | } | |
| 69 | }); | |
| 70 | try | |
| 71 |       {
 | |
| 72 | Thread.sleep(200); | |
| 73 | } | |
| 74 | catch( InterruptedException ie) | |
| 75 |       {
 | |
| 76 |  | |
| 77 | } | |
| 78 | } | |
| 79 |  | |
| 80 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 81 |  | |
| 82 | private void addPage(final RubikDialogScoresView view, final int[][] country, final String[][] name, final String[][] time) | |
| 83 |     {
 | |
| 84 | for(int section=0; section<RubikActivity.MAX_SCRAMBLE; section++) | |
| 85 |       {
 | |
| 86 | final int sec = section; | |
| 87 | final int[] c = country[section]; | |
| 88 | final String[] n = name[section]; | |
| 89 | final String[] t = time[section]; | |
| 90 |  | |
| 91 | mAct.runOnUiThread(new Runnable() | |
| 92 |         {
 | |
| 93 | @Override | |
| 94 | public void run() | |
| 95 |           {
 | |
| 96 | view.addSection(mAct, sec, c, n, t); | |
| 97 | } | |
| 98 | }); | |
| 99 |  | |
| 100 | try | |
| 101 |         {
 | |
| 102 | Thread.sleep(60); | |
| 103 | } | |
| 104 | catch( InterruptedException ie) | |
| 105 |         {
 | |
| 106 |  | |
| 107 | } | |
| 108 | } | |
| 109 | } | |
| 110 |  | |
| 111 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 112 |  | |
| 113 | public void exception(final String exce) | |
| 114 |     {
 | |
| 115 | mAct.runOnUiThread(new Runnable() | |
| 116 |       {
 | |
| 117 | @Override | |
| 118 | public void run() | |
| 119 |         {
 | |
| 120 | for(int i=0; i<RubikSize.LENGTH; i++) | |
| 121 |           {
 | |
| 122 | mViews[i].exception(exce); | |
| 123 | } | |
| 124 | } | |
| 125 | }); | |
| 126 | } | |
| 127 |  | |
| 128 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 129 |  | |
| 130 | RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager) | |
| 131 |     {
 | |
| 132 | mAct = act; | |
| 133 | mViews = new RubikDialogScoresView[RubikSize.LENGTH]; | |
| 134 | mViewPager = viewPager; | |
| 135 |  | |
| 136 | viewPager.setAdapter(this); | |
| 137 | viewPager.setOffscreenPageLimit( RubikSize.LENGTH-1 ); | |
| 138 | } | |
| 139 |  | |
| 140 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 141 |  | |
| 142 | @Override | |
| 143 | @NonNull | |
| 144 | public Object instantiateItem(@NonNull ViewGroup collection, int position) | |
| 145 |     {
 | |
| 146 | mViews[position] = new RubikDialogScoresView(mAct); | |
| 147 | collection.addView(mViews[position]); | |
| 148 |  | |
| 149 | boolean allCreated = true; | |
| 150 |  | |
| 151 | for(int i=0; i<RubikSize.LENGTH; i++) | |
| 152 |       {
 | |
| 153 | if( mViews[i]==null ) | |
| 154 |         {
 | |
| 155 | allCreated = false; | |
| 156 | break; | |
| 157 | } | |
| 158 | } | |
| 159 |  | |
| 160 | if( allCreated ) | |
| 161 |       {
 | |
| 162 | RubikScoresDownloader downloader = new RubikScoresDownloader(); | |
| 163 | downloader.download(this, mAct.getResources(), mAct.getPackageName()); | |
| 164 | } | |
| 165 |  | |
| 166 | return mViews[position]; | |
| 167 | } | |
| 168 |  | |
| 169 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 170 |  | |
| 171 | @Override | |
| 172 | public void destroyItem(ViewGroup collection, int position, @NonNull Object view) | |
| 173 |     {
 | |
| 174 | collection.removeView((View) view); | |
| 175 | } | |
| 176 |  | |
| 177 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 178 |  | |
| 179 | @Override | |
| 180 | public int getCount() | |
| 181 |     {
 | |
| 182 | return RubikSize.LENGTH; | |
| 183 | } | |
| 184 |  | |
| 185 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 186 |  | |
| 187 | @Override | |
| 188 | public boolean isViewFromObject(@NonNull View view, @NonNull Object object) | |
| 189 |     {
 | |
| 190 | return view == object; | |
| 191 | } | |
| 192 | } | |
| src/main/java/org/distorted/magic/RubikDialogScoresView.java | ||
|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // Copyright 2020 Leszek Koltunski // | |
| 3 | // // | |
| 4 | // This file is part of Magic Cube. // | |
| 5 | // // | |
| 6 | // Magic Cube is free software: you can redistribute it and/or modify // | |
| 7 | // it under the terms of the GNU General Public License as published by // | |
| 8 | // the Free Software Foundation, either version 2 of the License, or // | |
| 9 | // (at your option) any later version. // | |
| 10 | // // | |
| 11 | // Magic Cube is distributed in the hope that it will be useful, // | |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
| 14 | // GNU General Public License for more details. // | |
| 15 | // // | |
| 16 | // You should have received a copy of the GNU General Public License // | |
| 17 | // along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // | |
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 |  | |
| 20 | package org.distorted.magic; | |
| 21 |  | |
| 22 | import android.content.Context; | |
| 23 | import android.support.v4.app.FragmentActivity; | |
| 24 | import android.util.AttributeSet; | |
| 25 | import android.view.View; | |
| 26 | import android.widget.FrameLayout; | |
| 27 | import android.widget.ImageView; | |
| 28 | import android.widget.LinearLayout; | |
| 29 | import android.widget.TextView; | |
| 30 |  | |
| 31 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 32 |  | |
| 33 | public class RubikDialogScoresView extends FrameLayout | |
| 34 |   {
 | |
| 35 | LinearLayout mLayout; | |
| 36 |  | |
| 37 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 38 |  | |
| 39 | public RubikDialogScoresView(Context context, AttributeSet attrs, int defStyle) | |
| 40 |     {
 | |
| 41 | super(context, attrs, defStyle); | |
| 42 | } | |
| 43 |  | |
| 44 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 45 |  | |
| 46 | public RubikDialogScoresView(Context context, AttributeSet attrs) | |
| 47 |     {
 | |
| 48 | super(context, attrs); | |
| 49 | } | |
| 50 |  | |
| 51 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 52 |  | |
| 53 | public RubikDialogScoresView(Context context) | |
| 54 |     {
 | |
| 55 | super(context); | |
| 56 |  | |
| 57 | View view = inflate(context, R.layout.dialog_scores_downloading, null); | |
| 58 | addView(view); | |
| 59 | } | |
| 60 |  | |
| 61 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 62 |  | |
| 63 | void exception(final String exce) | |
| 64 |     {
 | |
| 65 | TextView text = findViewById(R.id.downloading_text); | |
| 66 | text.setText(exce); | |
| 67 | } | |
| 68 |  | |
| 69 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 70 |  | |
| 71 | void prepareView(FragmentActivity act) | |
| 72 |     {
 | |
| 73 | removeAllViews(); | |
| 74 |  | |
| 75 | View tab = inflate(act, R.layout.dialog_scores_tab, null); | |
| 76 | mLayout = tab.findViewById(R.id.tabLayout); | |
| 77 | addView(tab); | |
| 78 | } | |
| 79 |  | |
| 80 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 81 |  | |
| 82 | void addSection(FragmentActivity act, int scramble, final int[] country, final String[] name, final String[] time) | |
| 83 |     {
 | |
| 84 | LinearLayout level = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null); | |
| 85 | TextView text = level.findViewById(R.id.scoresScrambleTitle); | |
| 86 | text.setText(act.getString(R.string.sc_placeholder,(scramble+1))); | |
| 87 |  | |
| 88 | for(int j=0; j<RubikScoresDownloader.MAX_PLACES; j++) | |
| 89 |       {
 | |
| 90 | if( name[j] != null ) | |
| 91 |         {
 | |
| 92 | View row = inflate(act, R.layout.dialog_scores_scramble_row, null); | |
| 93 |  | |
| 94 | ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry); | |
| 95 | TextView textName = row.findViewById(R.id.scoresScrambleRowName); | |
| 96 | TextView textTime = row.findViewById(R.id.scoresScrambleRowTime); | |
| 97 |  | |
| 98 | imgCoun.setImageResource(country[j]); | |
| 99 | textName.setText(name[j]); | |
| 100 | textTime.setText(time[j]); | |
| 101 |  | |
| 102 | level.addView(row); | |
| 103 | } | |
| 104 | } | |
| 105 |  | |
| 106 | mLayout.addView(level); | |
| 107 | } | |
| 108 | } | |
| src/main/java/org/distorted/magic/RubikDialogSettings.java | ||
|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // Copyright 2019 Leszek Koltunski // | |
| 3 | // // | |
| 4 | // This file is part of Magic Cube. // | |
| 5 | // // | |
| 6 | // Magic Cube is free software: you can redistribute it and/or modify // | |
| 7 | // it under the terms of the GNU General Public License as published by // | |
| 8 | // the Free Software Foundation, either version 2 of the License, or // | |
| 9 | // (at your option) any later version. // | |
| 10 | // // | |
| 11 | // Magic Cube is distributed in the hope that it will be useful, // | |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
| 14 | // GNU General Public License for more details. // | |
| 15 | // // | |
| 16 | // You should have received a copy of the GNU General Public License // | |
| 17 | // along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // | |
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 |  | |
| 20 | package org.distorted.magic; | |
| 21 |  | |
| 22 | import android.app.Dialog; | |
| 23 | import android.content.DialogInterface; | |
| 24 | import android.os.Bundle; | |
| 25 | import android.support.annotation.NonNull; | |
| 26 | import android.support.v4.app.FragmentActivity; | |
| 27 | import android.support.v4.content.ContextCompat; | |
| 28 | import android.support.v7.app.AlertDialog; | |
| 29 | import android.support.v7.app.AppCompatDialogFragment; | |
| 30 | import android.util.DisplayMetrics; | |
| 31 | import android.view.Gravity; | |
| 32 | import android.view.LayoutInflater; | |
| 33 | import android.view.View; | |
| 34 | import android.widget.AdapterView; | |
| 35 | import android.widget.ArrayAdapter; | |
| 36 | import android.widget.LinearLayout; | |
| 37 | import android.widget.SeekBar; | |
| 38 | import android.widget.Spinner; | |
| 39 | import android.widget.TextView; | |
| 40 |  | |
| 41 | import org.distorted.effect.BaseEffect; | |
| 42 |  | |
| 43 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 44 |  | |
| 45 | public class RubikDialogSettings extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener | |
| 46 |   {
 | |
| 47 | private TextView[] mDurationText; | |
| 48 |  | |
| 49 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 50 |  | |
| 51 | private void addSettingsSection(FragmentActivity act, LinearLayout layout, int index) | |
| 52 |     {
 | |
| 53 | BaseEffect.Type beType = BaseEffect.Type.getType(index); | |
| 54 | DisplayMetrics metrics = act.getResources().getDisplayMetrics(); | |
| 55 | float scale = metrics.density; | |
| 56 |  | |
| 57 | int textH=32; | |
| 58 | int layoH=36; | |
| 59 | int margH=10; | |
| 60 | /* | |
| 61 | if( metrics.widthPixels > metrics.heightPixels ) | |
| 62 |       {
 | |
| 63 | textH = 18; | |
| 64 | layoH = 25; | |
| 65 | margH = 5; | |
| 66 | } | |
| 67 | else | |
| 68 |       {
 | |
| 69 | textH = 32; | |
| 70 | layoH = 36; | |
| 71 | margH = 10; | |
| 72 | } | |
| 73 | */ | |
| 74 | ///// OUTER LAYOUT /////////////////////////////////////////////////////////////////// | |
| 75 |  | |
| 76 | int margin = (int)(scale*margH + 0.5f); | |
| 77 | int color = ContextCompat.getColor(act, R.color.grey); | |
| 78 | LinearLayout outerLayout = new LinearLayout(act); | |
| 79 | LinearLayout.LayoutParams outerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 0.5f); | |
| 80 | outerLayoutParams.topMargin = margin; | |
| 81 | outerLayoutParams.bottomMargin = 0; | |
| 82 | outerLayoutParams.leftMargin = margin; | |
| 83 | outerLayoutParams.rightMargin = margin; | |
| 84 |  | |
| 85 | outerLayout.setLayoutParams(outerLayoutParams); | |
| 86 | outerLayout.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); | |
| 87 | outerLayout.setBackgroundColor(color); | |
| 88 | outerLayout.setOrientation(LinearLayout.VERTICAL); | |
| 89 | layout.addView(outerLayout); | |
| 90 |  | |
| 91 | ///// TEXT /////////////////////////////////////////////////////////////////////////// | |
| 92 |  | |
| 93 | int layoutHeight = (int)(scale*textH + 0.5f); | |
| 94 | int padding = (int)(scale*10 + 0.5f); | |
| 95 |  | |
| 96 | LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,layoutHeight); | |
| 97 |  | |
| 98 | TextView textView = new TextView(act); | |
| 99 | textView.setText(beType.getText()); | |
| 100 | textView.setLayoutParams(textParams); | |
| 101 | textView.setGravity(Gravity.CENTER); | |
| 102 | textView.setPadding(padding,0,padding,0); | |
| 103 | textView.setTextAppearance(android.R.style.TextAppearance_Small); | |
| 104 | outerLayout.addView(textView); | |
| 105 |  | |
| 106 | ///// INNER LAYOUT1 ////////////////////////////////////////////////////////////////// | |
| 107 |  | |
| 108 | int innerLayout1Height = (int)(scale*layoH + 0.5f); | |
| 109 | LinearLayout innerLayout1 = new LinearLayout(act); | |
| 110 | LinearLayout.LayoutParams innerLayout1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout1Height); | |
| 111 |  | |
| 112 | innerLayout1.setLayoutParams(innerLayout1Params); | |
| 113 | innerLayout1.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); | |
| 114 | innerLayout1.setOrientation(LinearLayout.HORIZONTAL); | |
| 115 | outerLayout.addView(innerLayout1); | |
| 116 |  | |
| 117 | ///// STUFF INSIDE INNER LAYOUT1 ///////////////////////////////////////////////////// | |
| 118 |  | |
| 119 | int text1Padding = (int)(scale*5 + 0.5f); | |
| 120 | LinearLayout.LayoutParams text1LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); | |
| 121 |  | |
| 122 | TextView text1View = new TextView(act); | |
| 123 | text1View.setText(R.string.duration); | |
| 124 | text1View.setLayoutParams(text1LayoutParams); | |
| 125 | text1View.setGravity(Gravity.START|Gravity.CENTER); | |
| 126 | text1View.setPadding(text1Padding,0,text1Padding,0); | |
| 127 | text1View.setTextAppearance(android.R.style.TextAppearance_Small); | |
| 128 | innerLayout1.addView(text1View); | |
| 129 | ////////////////////////////////////////////////////////////////// | |
| 130 | int text2Padding = (int)(scale*5 + 0.5f); | |
| 131 | LinearLayout.LayoutParams text2LayoutParams = new LinearLayout.LayoutParams(0,layoutHeight,0.2f); | |
| 132 |  | |
| 133 | mDurationText[index] = new TextView(act); | |
| 134 | mDurationText[index].setLayoutParams(text2LayoutParams); | |
| 135 | mDurationText[index].setGravity(Gravity.END|Gravity.CENTER); | |
| 136 | mDurationText[index].setPadding(text2Padding,0,text2Padding,0); | |
| 137 | mDurationText[index].setTextAppearance(android.R.style.TextAppearance_Small); | |
| 138 | innerLayout1.addView(mDurationText[index]); | |
| 139 | ////////////////////////////////////////////////////////////////// | |
| 140 | int seekPadding = (int)(scale*10 + 0.5f); | |
| 141 | LinearLayout.LayoutParams seekLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); | |
| 142 |  | |
| 143 | SeekBar seekBar = new SeekBar(act); | |
| 144 | seekBar.setLayoutParams(seekLayoutParams); | |
| 145 | seekBar.setPadding(seekPadding,0,seekPadding,0); | |
| 146 | seekBar.setId(index); | |
| 147 | innerLayout1.addView(seekBar); | |
| 148 |  | |
| 149 | seekBar.setOnSeekBarChangeListener(this); | |
| 150 | seekBar.setProgress(beType.getCurrentPos()); | |
| 151 |  | |
| 152 | ///// INNER LAYOUT2 ////////////////////////////////////////////////////////////////// | |
| 153 |  | |
| 154 | int innerLayout2Height = (int)(scale*layoH + 0.5f); | |
| 155 | LinearLayout innerLayout2 = new LinearLayout(act); | |
| 156 | LinearLayout.LayoutParams innerLayout2Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout2Height); | |
| 157 |  | |
| 158 | innerLayout2.setLayoutParams(innerLayout2Params); | |
| 159 | innerLayout2.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); | |
| 160 | innerLayout2.setOrientation(LinearLayout.HORIZONTAL); | |
| 161 | outerLayout.addView(innerLayout2); | |
| 162 |  | |
| 163 | ///// STUFF INSIDE INNER LAYOUT2 ///////////////////////////////////////////////////// | |
| 164 |  | |
| 165 | int text3Padding = (int)(scale*5 + 0.5f); | |
| 166 | LinearLayout.LayoutParams text3LayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.4f); | |
| 167 |  | |
| 168 | TextView text3View = new TextView(act); | |
| 169 | text3View.setText(R.string.type); | |
| 170 | text3View.setLayoutParams(text3LayoutParams); | |
| 171 | text3View.setGravity(Gravity.START|Gravity.CENTER); | |
| 172 | text3View.setPadding(text3Padding,0,text3Padding,0); | |
| 173 | text3View.setTextAppearance(android.R.style.TextAppearance_Small); | |
| 174 | innerLayout2.addView(text3View); | |
| 175 | ////////////////////////////////////////////////////////////////// | |
| 176 | int spinnerPadding = (int)(scale*10 + 0.5f); | |
| 177 | LinearLayout.LayoutParams spinnerLayoutParams = new LinearLayout.LayoutParams(0,LinearLayout.LayoutParams.MATCH_PARENT,0.6f); | |
| 178 |  | |
| 179 | Spinner spinner = new Spinner(act); | |
| 180 | spinner.setLayoutParams(spinnerLayoutParams); | |
| 181 | spinner.setPadding(spinnerPadding,0,spinnerPadding,0); | |
| 182 | spinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); | |
| 183 | spinner.setId(index+BaseEffect.Type.LENGTH); | |
| 184 | innerLayout2.addView(spinner); | |
| 185 |  | |
| 186 | spinner.setOnItemSelectedListener(this); | |
| 187 | String[] appear = BaseEffect.Type.getType(index).getNames(); | |
| 188 |  | |
| 189 | ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, appear); | |
| 190 | adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); | |
| 191 | spinner.setAdapter(adapterType); | |
| 192 | spinner.setSelection(beType.getCurrentType()); | |
| 193 | } | |
| 194 |  | |
| 195 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 196 | // PUBLIC API | |
| 197 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 198 |  | |
| 199 | public RubikDialogSettings() | |
| 200 |     {
 | |
| 201 | mDurationText = new TextView[BaseEffect.Type.LENGTH]; | |
| 202 | } | |
| 203 |  | |
| 204 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 205 |  | |
| 206 | @NonNull | |
| 207 | @Override | |
| 208 | public Dialog onCreateDialog(Bundle savedInstanceState) | |
| 209 |     {
 | |
| 210 | FragmentActivity act = getActivity(); | |
| 211 | LayoutInflater inflater = act.getLayoutInflater(); | |
| 212 | AlertDialog.Builder builder = new AlertDialog.Builder(act); | |
| 213 | TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null); | |
| 214 | tv.setText(R.string.settings_title); | |
| 215 | builder.setCustomTitle(tv); | |
| 216 |  | |
| 217 | builder.setCancelable(true); | |
| 218 | builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() | |
| 219 |       {
 | |
| 220 | @Override | |
| 221 | public void onClick(DialogInterface dialog, int which) | |
| 222 |         {
 | |
| 223 |  | |
| 224 | } | |
| 225 | }); | |
| 226 |  | |
| 227 | final View view = inflater.inflate(R.layout.dialog_settings, null); | |
| 228 | builder.setView(view); | |
| 229 |  | |
| 230 | LinearLayout linearLayout = view.findViewById(R.id.settingsLayout); | |
| 231 |  | |
| 232 | if( linearLayout!=null ) | |
| 233 |       {
 | |
| 234 | for (int i=0; i< BaseEffect.Type.LENGTH; i++) | |
| 235 |         {
 | |
| 236 | addSettingsSection(act,linearLayout,i); | |
| 237 | } | |
| 238 | } | |
| 239 | else | |
| 240 |       {
 | |
| 241 |       android.util.Log.e("dialog_settings", "linearLayout NULL!");
 | |
| 242 | } | |
| 243 |  | |
| 244 | return builder.create(); | |
| 245 | } | |
| 246 |  | |
| 247 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 248 |  | |
| 249 | public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) | |
| 250 |     {
 | |
| 251 | int parentID = parent.getId(); | |
| 252 | int len = BaseEffect.Type.LENGTH; | |
| 253 |  | |
| 254 | if( parentID>=len && parentID< 2*len) // ith spinner's ID is equal to i+LENGTH (see createSettingSection) | |
| 255 |       {
 | |
| 256 | BaseEffect.Type.getType(parentID-len).setCurrentType(pos); | |
| 257 | } | |
| 258 | } | |
| 259 |  | |
| 260 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 261 |  | |
| 262 | public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) | |
| 263 |     {
 | |
| 264 | int barID = bar.getId(); | |
| 265 |  | |
| 266 | if( barID>=0 && barID< BaseEffect.Type.LENGTH) // ith seekbar's ID is equal to i (see createSettingSection) | |
| 267 |       {
 | |
| 268 | BaseEffect.Type.getType(barID).setCurrentPos(progress); | |
| 269 | int ms = BaseEffect.Type.translatePos(progress); | |
| 270 | mDurationText[barID].setText(getString(R.string.ms_placeholder,ms)); | |
| 271 | } | |
| 272 | } | |
| 273 |  | |
| 274 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 275 |  | |
| 276 |   public void onNothingSelected(AdapterView<?> parent) { }
 | |
| 277 |   public void onStartTrackingTouch(SeekBar bar) { }
 | |
| 278 |   public void onStopTrackingTouch(SeekBar bar)  { }
 | |
| 279 | } | |
| src/main/java/org/distorted/magic/RubikRenderer.java | ||
|---|---|---|
| 38 | 38 |  | 
| 39 | 39 | public class RubikRenderer implements GLSurfaceView.Renderer, EffectListener | 
| 40 | 40 | {
 | 
| 41 |     public static final float CAMERA_DISTANCE   = 0.6f;  // 0.6 of the length of max(scrHeight,scrWidth)
 | |
| 41 |     static final float CAMERA_DISTANCE = 0.6f;  // 0.6 of the length of min(scrHeight,scrWidth)
 | |
| 42 | 42 | public static final int TEXTURE_SIZE = 600; | 
| 43 | 43 |  | 
| 44 | 44 | private RubikSurfaceView mView; | 
| ... | ... | |
| 238 | 238 |  | 
| 239 | 239 | if( solved && !mIsSolved ) | 
| 240 | 240 |          {
 | 
| 241 |          mCanDrag        = false;
 | |
| 241 |          mCanDrag        = true;
 | |
| 242 | 242 | mCanRotate = false; | 
| 243 | 243 | mCanUI = false; | 
| 244 | 244 | doEffectNow( BaseEffect.Type.WIN ); | 
| src/main/java/org/distorted/magic/RubikScores.java | ||
|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // Copyright 2019 Leszek Koltunski // | |
| 3 | // // | |
| 4 | // This file is part of Magic Cube. // | |
| 5 | // // | |
| 6 | // Magic Cube is free software: you can redistribute it and/or modify // | |
| 7 | // it under the terms of the GNU General Public License as published by // | |
| 8 | // the Free Software Foundation, either version 2 of the License, or // | |
| 9 | // (at your option) any later version. // | |
| 10 | // // | |
| 11 | // Magic Cube is distributed in the hope that it will be useful, // | |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
| 14 | // GNU General Public License for more details. // | |
| 15 | // // | |
| 16 | // You should have received a copy of the GNU General Public License // | |
| 17 | // along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // | |
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 |  | |
| 20 | package org.distorted.magic; | |
| 21 |  | |
| 22 | import android.app.Dialog; | |
| 23 | import android.content.DialogInterface; | |
| 24 | import android.os.Bundle; | |
| 25 | import android.support.annotation.NonNull; | |
| 26 | import android.support.v4.app.FragmentActivity; | |
| 27 | import android.support.v4.view.ViewPager; | |
| 28 | import android.support.v7.app.AlertDialog; | |
| 29 | import android.support.v7.app.AppCompatDialogFragment; | |
| 30 | import android.support.design.widget.TabLayout; | |
| 31 | import android.view.LayoutInflater; | |
| 32 | import android.view.View; | |
| 33 | import android.widget.ImageView; | |
| 34 | import android.widget.TextView; | |
| 35 |  | |
| 36 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 37 |  | |
| 38 | public class RubikScores extends AppCompatDialogFragment | |
| 39 |   {
 | |
| 40 | RubikScoresPagerAdapter mPagerAdapter; | |
| 41 |  | |
| 42 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 43 |  | |
| 44 | @NonNull | |
| 45 | @Override | |
| 46 | public Dialog onCreateDialog(Bundle savedInstanceState) | |
| 47 |     {
 | |
| 48 | FragmentActivity act = getActivity(); | |
| 49 | AlertDialog.Builder builder = new AlertDialog.Builder(act); | |
| 50 |  | |
| 51 | LayoutInflater layoutInflater = act.getLayoutInflater(); | |
| 52 | TextView tv = (TextView) layoutInflater.inflate(R.layout.scores_title, null); | |
| 53 | tv.setText(R.string.scores_title); | |
| 54 | builder.setCustomTitle(tv); | |
| 55 |  | |
| 56 | builder.setCancelable(true); | |
| 57 | builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() | |
| 58 |       {
 | |
| 59 | @Override | |
| 60 | public void onClick(DialogInterface dialog, int which) | |
| 61 |         {
 | |
| 62 |  | |
| 63 | } | |
| 64 | }); | |
| 65 |  | |
| 66 | Bundle args = getArguments(); | |
| 67 | int curTab; | |
| 68 |  | |
| 69 | try | |
| 70 |       {
 | |
| 71 |       curTab = args.getInt("tab");
 | |
| 72 | } | |
| 73 | catch(Exception e) | |
| 74 |       {
 | |
| 75 | curTab = 0; | |
| 76 | } | |
| 77 |  | |
| 78 | LayoutInflater inflater = act.getLayoutInflater(); | |
| 79 | final View view = inflater.inflate(R.layout.scores, null); | |
| 80 | builder.setView(view); | |
| 81 |  | |
| 82 | ViewPager viewPager = view.findViewById(R.id.viewpager); | |
| 83 | TabLayout tabLayout = view.findViewById(R.id.sliding_tabs); | |
| 84 | mPagerAdapter = new RubikScoresPagerAdapter(act,viewPager); | |
| 85 | tabLayout.setupWithViewPager(viewPager); | |
| 86 |  | |
| 87 | viewPager.setCurrentItem(curTab); | |
| 88 |  | |
| 89 | for (int i = 0; i< RubikSize.LENGTH; i++) | |
| 90 |       {
 | |
| 91 | ImageView imageView = new ImageView(act); | |
| 92 | imageView.setImageResource(RubikSize.getSize(i).getIconID()); | |
| 93 | TabLayout.Tab tab = tabLayout.getTabAt(i); | |
| 94 | if(tab!=null) tab.setCustomView(imageView); | |
| 95 | } | |
| 96 |  | |
| 97 | return builder.create(); | |
| 98 | } | |
| 99 | } | |
| src/main/java/org/distorted/magic/RubikScoresPagerAdapter.java | ||
|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // Copyright 2020 Leszek Koltunski // | |
| 3 | // // | |
| 4 | // This file is part of Magic Cube. // | |
| 5 | // // | |
| 6 | // Magic Cube is free software: you can redistribute it and/or modify // | |
| 7 | // it under the terms of the GNU General Public License as published by // | |
| 8 | // the Free Software Foundation, either version 2 of the License, or // | |
| 9 | // (at your option) any later version. // | |
| 10 | // // | |
| 11 | // Magic Cube is distributed in the hope that it will be useful, // | |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
| 14 | // GNU General Public License for more details. // | |
| 15 | // // | |
| 16 | // You should have received a copy of the GNU General Public License // | |
| 17 | // along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // | |
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 |  | |
| 20 | package org.distorted.magic; | |
| 21 |  | |
| 22 | import android.support.annotation.NonNull; | |
| 23 | import android.support.v4.app.FragmentActivity; | |
| 24 | import android.support.v4.view.PagerAdapter; | |
| 25 | import android.support.v4.view.ViewPager; | |
| 26 | import android.view.View; | |
| 27 | import android.view.ViewGroup; | |
| 28 |  | |
| 29 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 30 |  | |
| 31 | class RubikScoresPagerAdapter extends PagerAdapter implements RubikScoresDownloader.Receiver | |
| 32 |   {
 | |
| 33 | private FragmentActivity mAct; | |
| 34 | private RubikScoresView[] mViews; | |
| 35 | private ViewPager mViewPager; | |
| 36 |  | |
| 37 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 38 |  | |
| 39 | public void receive(final int[][][] country, final String[][][] name, final String[][][] time) | |
| 40 |     {
 | |
| 41 | prepareView(); | |
| 42 |  | |
| 43 | int c = mViewPager.getCurrentItem(); | |
| 44 |  | |
| 45 | addPage(mViews[c],country[c],name[c],time[c]); | |
| 46 |  | |
| 47 | for(int i=0; i<RubikSize.LENGTH; i++) | |
| 48 |       {
 | |
| 49 | if( i==c ) continue; | |
| 50 |  | |
| 51 | addPage(mViews[i],country[i],name[i],time[i]); | |
| 52 | } | |
| 53 | } | |
| 54 |  | |
| 55 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 56 |  | |
| 57 | private void prepareView() | |
| 58 |     {
 | |
| 59 | mAct.runOnUiThread(new Runnable() | |
| 60 |       {
 | |
| 61 | @Override | |
| 62 | public void run() | |
| 63 |         {
 | |
| 64 | for(int i=0; i<RubikSize.LENGTH; i++) | |
| 65 |           {
 | |
| 66 | mViews[i].prepareView(mAct); | |
| 67 | } | |
| 68 | } | |
| 69 | }); | |
| 70 | try | |
| 71 |       {
 | |
| 72 | Thread.sleep(200); | |
| 73 | } | |
| 74 | catch( InterruptedException ie) | |
| 75 |       {
 | |
| 76 |  | |
| 77 | } | |
| 78 | } | |
| 79 |  | |
| 80 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 81 |  | |
| 82 | private void addPage(final RubikScoresView view, final int[][] country, final String[][] name, final String[][] time) | |
| 83 |     {
 | |
| 84 | for(int section=0; section<RubikActivity.MAX_SCRAMBLE; section++) | |
| 85 |       {
 | |
| 86 | final int sec = section; | |
| 87 | final int[] c = country[section]; | |
| 88 | final String[] n = name[section]; | |
| 89 | final String[] t = time[section]; | |
| 90 |  | |
| 91 | mAct.runOnUiThread(new Runnable() | |
| 92 |         {
 | |
| 93 | @Override | |
| 94 | public void run() | |
| 95 |           {
 | |
| 96 | view.addSection(mAct, sec, c, n, t); | |
| 97 | } | |
| 98 | }); | |
| 99 |  | |
| 100 | try | |
| 101 |         {
 | |
| 102 | Thread.sleep(60); | |
| 103 | } | |
| 104 | catch( InterruptedException ie) | |
| 105 |         {
 | |
| 106 |  | |
| 107 | } | |
| 108 | } | |
| 109 | } | |
| 110 |  | |
| 111 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 112 |  | |
| 113 | public void exception(final String exce) | |
| 114 |     {
 | |
| 115 | mAct.runOnUiThread(new Runnable() | |
| 116 |       {
 | |
| 117 | @Override | |
| 118 | public void run() | |
| 119 |         {
 | |
| 120 | for(int i=0; i<RubikSize.LENGTH; i++) | |
| 121 |           {
 | |
| 122 | mViews[i].exception(exce); | |
| 123 | } | |
| 124 | } | |
| 125 | }); | |
| 126 | } | |
| 127 |  | |
| 128 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 129 |  | |
| 130 | RubikScoresPagerAdapter(FragmentActivity act, ViewPager viewPager) | |
| 131 |     {
 | |
| 132 | mAct = act; | |
| 133 | mViews = new RubikScoresView[RubikSize.LENGTH]; | |
| 134 | mViewPager = viewPager; | |
| 135 |  | |
| 136 | viewPager.setAdapter(this); | |
| 137 | viewPager.setOffscreenPageLimit( RubikSize.LENGTH-1 ); | |
| 138 | } | |
| 139 |  | |
| 140 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 141 |  | |
| 142 | @Override | |
| 143 | @NonNull | |
| 144 | public Object instantiateItem(@NonNull ViewGroup collection, int position) | |
| 145 |     {
 | |
| 146 | mViews[position] = new RubikScoresView(mAct); | |
| 147 | collection.addView(mViews[position]); | |
| 148 |  | |
| 149 | boolean allCreated = true; | |
| 150 |  | |
| 151 | for(int i=0; i<RubikSize.LENGTH; i++) | |
| 152 |       {
 | |
| 153 | if( mViews[i]==null ) | |
| 154 |         {
 | |
| 155 | allCreated = false; | |
| 156 | break; | |
| 157 | } | |
| 158 | } | |
| 159 |  | |
| 160 | if( allCreated ) | |
| 161 |       {
 | |
| 162 | RubikScoresDownloader downloader = new RubikScoresDownloader(); | |
| 163 | downloader.download(this, mAct.getResources(), mAct.getPackageName()); | |
| 164 | } | |
| 165 |  | |
| 166 | return mViews[position]; | |
| 167 | } | |
| 168 |  | |
| 169 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 170 |  | |
| 171 | @Override | |
| 172 | public void destroyItem(ViewGroup collection, int position, @NonNull Object view) | |
| 173 |     {
 | |
| 174 | collection.removeView((View) view); | |
| 175 | } | |
| 176 |  | |
| 177 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 178 |  | |
| 179 | @Override | |
| 180 | public int getCount() | |
| 181 |     {
 | |
| 182 | return RubikSize.LENGTH; | |
| 183 | } | |
| 184 |  | |
| 185 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 186 |  | |
| 187 | @Override | |
| 188 | public boolean isViewFromObject(@NonNull View view, @NonNull Object object) | |
| 189 |     {
 | |
| 190 | return view == object; | |
| 191 | } | |
| 192 | } | |
| src/main/java/org/distorted/magic/RubikScoresView.java | ||
|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // Copyright 2020 Leszek Koltunski // | |
| 3 | // // | |
| 4 | // This file is part of Magic Cube. // | |
| 5 | // // | |
| 6 | // Magic Cube is free software: you can redistribute it and/or modify // | |
| 7 | // it under the terms of the GNU General Public License as published by // | |
| 8 | // the Free Software Foundation, either version 2 of the License, or // | |
| 9 | // (at your option) any later version. // | |
| 10 | // // | |
| 11 | // Magic Cube is distributed in the hope that it will be useful, // | |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
| 14 | // GNU General Public License for more details. // | |
| 15 | // // | |
| 16 | // You should have received a copy of the GNU General Public License // | |
| 17 | // along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // | |
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 |  | |
| 20 | package org.distorted.magic; | |
| 21 |  | |
| 22 | import android.content.Context; | |
| 23 | import android.support.v4.app.FragmentActivity; | |
| 24 | import android.util.AttributeSet; | |
| 25 | import android.view.View; | |
| 26 | import android.widget.FrameLayout; | |
| 27 | import android.widget.ImageView; | |
| 28 | import android.widget.LinearLayout; | |
| 29 | import android.widget.TextView; | |
| 30 |  | |
| 31 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 32 |  | |
| 33 | public class RubikScoresView extends FrameLayout | |
| 34 |   {
 | |
| 35 | LinearLayout mLayout; | |
| 36 |  | |
| 37 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 38 |  | |
| 39 | public RubikScoresView(Context context, AttributeSet attrs, int defStyle) | |
| 40 |     {
 | |
| 41 | super(context, attrs, defStyle); | |
| 42 | } | |
| 43 |  | |
| 44 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 45 |  | |
| 46 | public RubikScoresView(Context context, AttributeSet attrs) | |
| 47 |     {
 | |
| 48 | super(context, attrs); | |
| 49 | } | |
| 50 |  | |
| 51 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 52 |  | |
| 53 | public RubikScoresView(Context context) | |
| 54 |     {
 | |
| 55 | super(context); | |
| 56 |  | |
| 57 | View view = inflate(context, R.layout.scores_downloading, null); | |
| 58 | addView(view); | |
| 59 | } | |
| 60 |  | |
| 61 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 62 |  | |
| 63 | void exception(final String exce) | |
| 64 |     {
 | |
| 65 | TextView text = findViewById(R.id.downloading_text); | |
| 66 | text.setText(exce); | |
| 67 | } | |
| 68 |  | |
| 69 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 70 |  | |
| 71 | void prepareView(FragmentActivity act) | |
| 72 |     {
 | |
| 73 | removeAllViews(); | |
| 74 |  | |
| 75 | View tab = inflate(act, R.layout.scores_tab, null); | |
| 76 | mLayout = tab.findViewById(R.id.tabLayout); | |
| 77 | addView(tab); | |
| 78 | } | |
| 79 |  | |
| 80 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 81 |  | |
| 82 | void addSection(FragmentActivity act, int scramble, final int[] country, final String[] name, final String[] time) | |
| 83 |     {
 | |
| 84 | LinearLayout level = (LinearLayout)inflate(act, R.layout.scores_scramble_title, null); | |
| 85 | TextView text = level.findViewById(R.id.scoresScrambleTitle); | |
| 86 | text.setText(act.getString(R.string.sc_placeholder,(scramble+1))); | |
| 87 |  | |
| 88 | for(int j=0; j<RubikScoresDownloader.MAX_PLACES; j++) | |
| 89 |       {
 | |
| 90 | if( name[j] != null ) | |
| 91 |         {
 | |
| 92 | View row = inflate(act, R.layout.scores_scramble_row, null); | |
| 93 |  | |
| 94 | ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry); | |
| 95 | TextView textName = row.findViewById(R.id.scoresScrambleRowName); | |
| 96 | TextView textTime = row.findViewById(R.id.scoresScrambleRowTime); | |
| 97 |  | |
| 98 | imgCoun.setImageResource(country[j]); | |
| 99 | textName.setText(name[j]); | |
| 100 | textTime.setText(time[j]); | |
| 101 |  | |
| 102 | level.addView(row); | |
| 103 | } | |
| 104 | } | |
| 105 |  | |
| 106 | mLayout.addView(level); | |
| 107 | } | |
| 108 | } | |
| src/main/java/org/distorted/magic/RubikSettings.java | ||
|---|---|---|
| 1 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 2 | // Copyright 2019 Leszek Koltunski // | |
| 3 | // // | |
| 4 | // This file is part of Magic Cube. // | |
| 5 | // // | |
| 6 | // Magic Cube is free software: you can redistribute it and/or modify // | |
| 7 | // it under the terms of the GNU General Public License as published by // | |
| 8 | // the Free Software Foundation, either version 2 of the License, or // | |
| 9 | // (at your option) any later version. // | |
| 10 | // // | |
| 11 | // Magic Cube is distributed in the hope that it will be useful, // | |
| 12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // | |
| 13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // | |
| 14 | // GNU General Public License for more details. // | |
| 15 | // // | |
| 16 | // You should have received a copy of the GNU General Public License // | |
| 17 | // along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. // | |
| 18 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 19 |  | |
| 20 | package org.distorted.magic; | |
| 21 |  | |
| 22 | import android.app.Dialog; | |
| 23 | import android.content.DialogInterface; | |
| 24 | import android.os.Bundle; | |
| 25 | import android.support.annotation.NonNull; | |
| 26 | import android.support.v4.app.FragmentActivity; | |
| 27 | import android.support.v4.content.ContextCompat; | |
| 28 | import android.support.v7.app.AlertDialog; | |
| 29 | import android.support.v7.app.AppCompatDialogFragment; | |
| 30 | import android.util.DisplayMetrics; | |
| 31 | import android.view.Gravity; | |
| 32 | import android.view.LayoutInflater; | |
| 33 | import android.view.View; | |
| 34 | import android.widget.AdapterView; | |
| 35 | import android.widget.ArrayAdapter; | |
| 36 | import android.widget.LinearLayout; | |
| 37 | import android.widget.SeekBar; | |
| 38 | import android.widget.Spinner; | |
| 39 | import android.widget.TextView; | |
| 40 |  | |
| 41 | import org.distorted.effect.BaseEffect; | |
| 42 |  | |
| 43 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 44 |  | |
| 45 | public class RubikSettings extends AppCompatDialogFragment implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener | |
| 46 |   {
 | |
| 47 | private TextView[] mDurationText; | |
| 48 |  | |
| 49 | /////////////////////////////////////////////////////////////////////////////////////////////////// | |
| 50 |  | |
| 51 | private void createSettingsSection(FragmentActivity act, LinearLayout layout, int index) | |
| 52 |     {
 | |
| 53 | BaseEffect.Type beType = BaseEffect.Type.getType(index); | |
| 54 | DisplayMetrics metrics = act.getResources().getDisplayMetrics(); | |
| 55 | float scale = metrics.density; | |
| 56 |  | |
| 57 | int textH; | |
| 58 | int layoH; | |
| 59 |  | |
| 60 | if( metrics.widthPixels > metrics.heightPixels ) | |
| 61 |       {
 | |
| 62 | textH = 20; | |
| 63 | layoH = 26; | |
| 64 | } | |
| 65 | else | |
| 66 |       {
 | |
| 67 | textH = 32; | |
| 68 | layoH = 36; | |
| 69 | } | |
| 70 |  | |
| 71 | ///// OUTER LAYOUT /////////////////////////////////////////////////////////////////// | |
| 72 |  | |
| 73 | int margin = (int)(scale*10 + 0.5f); | |
| 74 | int color = ContextCompat.getColor(act, R.color.grey); | |
| 75 | LinearLayout outerLayout = new LinearLayout(act); | |
| 76 | LinearLayout.LayoutParams outerLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT, 0.5f); | |
| 77 | outerLayoutParams.topMargin = margin; | |
| 78 | outerLayoutParams.bottomMargin = 0; | |
| 79 | outerLayoutParams.leftMargin = margin; | |
| 80 | outerLayoutParams.rightMargin = margin; | |
| 81 |  | |
| 82 | outerLayout.setLayoutParams(outerLayoutParams); | |
| 83 | outerLayout.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); | |
| 84 | outerLayout.setBackgroundColor(color); | |
| 85 | outerLayout.setOrientation(LinearLayout.VERTICAL); | |
| 86 | layout.addView(outerLayout); | |
| 87 |  | |
| 88 | ///// TEXT /////////////////////////////////////////////////////////////////////////// | |
| 89 |  | |
| 90 | int layoutHeight = (int)(scale*textH + 0.5f); | |
| 91 | int padding = (int)(scale*10 + 0.5f); | |
| 92 |  | |
| 93 | LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,layoutHeight); | |
| 94 |  | |
| 95 | TextView textView = new TextView(act); | |
| 96 | textView.setText(beType.getText()); | |
| 97 | textView.setLayoutParams(textParams); | |
| 98 | textView.setGravity(Gravity.CENTER); | |
| 99 | textView.setPadding(padding,0,padding,0); | |
| 100 | textView.setTextAppearance(android.R.style.TextAppearance_Small); | |
| 101 | outerLayout.addView(textView); | |
| 102 |  | |
| 103 | ///// INNER LAYOUT1 ////////////////////////////////////////////////////////////////// | |
| 104 |  | |
| 105 | int innerLayout1Height = (int)(scale*layoH + 0.5f); | |
| 106 | LinearLayout innerLayout1 = new LinearLayout(act); | |
| 107 | LinearLayout.LayoutParams innerLayout1Params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,innerLayout1Height); | |
| 108 |  | |
| 109 | innerLayout1.setLayoutParams(innerLayout1Params); | |
| 110 | innerLayout1.setGravity(Gravity.CENTER|Gravity.FILL_HORIZONTAL); | |
| 111 | innerLayout1.setOrientation(LinearLayout.HORIZONTAL); | |
Also available in: Unified diff
Making the Dialogs more consistent.