Revision 7aff6aa7
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java | ||
|---|---|---|
| 41 | 41 |
|
| 42 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 43 | 43 |
|
| 44 |
public void receive(final int[][][] country, final String[][][] name, final String[][][] time)
|
|
| 44 |
public void receive(final String[][][] country, final String[][][] name, final String[][][] time)
|
|
| 45 | 45 |
{
|
| 46 | 46 |
prepareView(); |
| 47 | 47 |
|
| ... | ... | |
| 74 | 74 |
}); |
| 75 | 75 |
try |
| 76 | 76 |
{
|
| 77 |
Thread.sleep(200);
|
|
| 77 |
Thread.sleep(150);
|
|
| 78 | 78 |
} |
| 79 | 79 |
catch( InterruptedException ie) |
| 80 | 80 |
{
|
| ... | ... | |
| 84 | 84 |
|
| 85 | 85 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 86 | 86 |
|
| 87 |
private void addPage(final RubikDialogScoresView view, final int[][] country, final String[][] name, final String[][] time)
|
|
| 87 |
private void addPage(final RubikDialogScoresView view, final String[][] country, final String[][] name, final String[][] time)
|
|
| 88 | 88 |
{
|
| 89 | 89 |
for(int i=0; i<RubikStatePlay.MAX_SCRAMBLE; i++) |
| 90 | 90 |
{
|
| ... | ... | |
| 101 | 101 |
|
| 102 | 102 |
try |
| 103 | 103 |
{
|
| 104 |
Thread.sleep(60);
|
|
| 104 |
Thread.sleep(50);
|
|
| 105 | 105 |
} |
| 106 | 106 |
catch( InterruptedException ie) |
| 107 | 107 |
{
|
| ... | ... | |
| 162 | 162 |
if( allCreated ) |
| 163 | 163 |
{
|
| 164 | 164 |
RubikScoresDownloader downloader = new RubikScoresDownloader(); |
| 165 |
downloader.download(this, mAct.getResources(), mAct.getPackageName());
|
|
| 165 |
downloader.download(this); |
|
| 166 | 166 |
} |
| 167 | 167 |
|
| 168 | 168 |
return mViews[position]; |
| src/main/java/org/distorted/dialog/RubikDialogScoresView.java | ||
|---|---|---|
| 20 | 20 |
package org.distorted.dialog; |
| 21 | 21 |
|
| 22 | 22 |
import android.content.Context; |
| 23 |
import android.content.res.Resources; |
|
| 23 | 24 |
import android.support.v4.app.FragmentActivity; |
| 24 | 25 |
import android.util.AttributeSet; |
| 25 | 26 |
import android.view.View; |
| ... | ... | |
| 63 | 64 |
|
| 64 | 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 65 | 66 |
|
| 66 |
void exception(final String exce)
|
|
| 67 |
LinearLayout createSection(FragmentActivity act, int scramble, final String[] country, final String[] name, final String[] time)
|
|
| 67 | 68 |
{
|
| 68 |
TextView text = findViewById(R.id.downloading_text); |
|
| 69 |
text.setText(exce); |
|
| 69 |
LinearLayout level = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null); |
|
| 70 |
TextView text = level.findViewById(R.id.scoresScrambleTitle); |
|
| 71 |
text.setText(act.getString(R.string.sc_placeholder,(scramble+1))); |
|
| 72 |
|
|
| 73 |
Resources res = act.getResources(); |
|
| 74 |
String packageName = act.getPackageName(); |
|
| 75 |
|
|
| 76 |
for(int j = 0; j< RubikScoresDownloader.MAX_PLACES; j++) |
|
| 77 |
{
|
|
| 78 |
if( name[j] != null ) |
|
| 79 |
{
|
|
| 80 |
View row = inflate(act, R.layout.dialog_scores_scramble_row, null); |
|
| 81 |
|
|
| 82 |
ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry); |
|
| 83 |
TextView textName = row.findViewById(R.id.scoresScrambleRowName); |
|
| 84 |
TextView textTime = row.findViewById(R.id.scoresScrambleRowTime); |
|
| 85 |
|
|
| 86 |
int resID = res.getIdentifier( country[j], "drawable", packageName); |
|
| 87 |
|
|
| 88 |
imgCoun.setImageResource(resID!=0 ? resID : R.drawable.unk); |
|
| 89 |
textName.setText(name[j]); |
|
| 90 |
textTime.setText(time[j]); |
|
| 91 |
|
|
| 92 |
level.addView(row); |
|
| 93 |
} |
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
return level; |
|
| 70 | 97 |
} |
| 71 | 98 |
|
| 72 | 99 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 100 |
// needs to run on UI thread |
|
| 73 | 101 |
|
| 74 | 102 |
void prepareView(FragmentActivity act) |
| 75 | 103 |
{
|
| ... | ... | |
| 81 | 109 |
} |
| 82 | 110 |
|
| 83 | 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 112 |
// needs to run on UI thread |
|
| 84 | 113 |
|
| 85 | 114 |
void addSection(LinearLayout section) |
| 86 | 115 |
{
|
| ... | ... | |
| 88 | 117 |
} |
| 89 | 118 |
|
| 90 | 119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 120 |
// needs to run on UI thread |
|
| 91 | 121 |
|
| 92 |
LinearLayout createSection(FragmentActivity act, int scramble, final int[] country, final String[] name, final String[] time)
|
|
| 122 |
void exception(final String exce)
|
|
| 93 | 123 |
{
|
| 94 |
LinearLayout level = (LinearLayout)inflate(act, R.layout.dialog_scores_scramble_title, null); |
|
| 95 |
TextView text = level.findViewById(R.id.scoresScrambleTitle); |
|
| 96 |
text.setText(act.getString(R.string.sc_placeholder,(scramble+1))); |
|
| 97 |
|
|
| 98 |
for(int j = 0; j< RubikScoresDownloader.MAX_PLACES; j++) |
|
| 99 |
{
|
|
| 100 |
if( name[j] != null ) |
|
| 101 |
{
|
|
| 102 |
View row = inflate(act, R.layout.dialog_scores_scramble_row, null); |
|
| 103 |
|
|
| 104 |
ImageView imgCoun = row.findViewById(R.id.scoresScrambleRowCountry); |
|
| 105 |
TextView textName = row.findViewById(R.id.scoresScrambleRowName); |
|
| 106 |
TextView textTime = row.findViewById(R.id.scoresScrambleRowTime); |
|
| 107 |
|
|
| 108 |
imgCoun.setImageResource(country[j]); |
|
| 109 |
textName.setText(name[j]); |
|
| 110 |
textTime.setText(time[j]); |
|
| 111 |
|
|
| 112 |
level.addView(row); |
|
| 113 |
} |
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
return level; |
|
| 124 |
TextView text = findViewById(R.id.downloading_text); |
|
| 125 |
text.setText(exce); |
|
| 117 | 126 |
} |
| 118 | 127 |
} |
| src/main/java/org/distorted/network/RubikScoresDownloader.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.network; |
| 21 | 21 |
|
| 22 |
import android.content.res.Resources; |
|
| 23 |
|
|
| 24 | 22 |
import java.io.InputStream; |
| 25 | 23 |
import java.net.HttpURLConnection; |
| 26 | 24 |
import java.net.URL; |
| 27 | 25 |
import java.net.UnknownHostException; |
| 28 | 26 |
|
| 29 | 27 |
import org.distorted.magic.R; |
| 30 |
import org.distorted.object.RubikObject; |
|
| 31 |
import org.distorted.uistate.RubikStatePlay; |
|
| 28 |
|
|
| 29 |
import static org.distorted.object.RubikObject.LENGTH; |
|
| 30 |
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE; |
|
| 32 | 31 |
|
| 33 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 34 | 33 |
|
| ... | ... | |
| 36 | 35 |
{
|
| 37 | 36 |
public interface Receiver |
| 38 | 37 |
{
|
| 39 |
void receive(int[][][] country, String[][][] name, String[][][] time);
|
|
| 38 |
void receive(String[][][] country, String[][][] name, String[][][] time);
|
|
| 40 | 39 |
void exception(String exception); |
| 41 | 40 |
} |
| 42 | 41 |
|
| ... | ... | |
| 86 | 85 |
private static boolean mRunning = false; |
| 87 | 86 |
private static int mMode = IDLE; |
| 88 | 87 |
private static Receiver mReceiver; |
| 89 |
private static Resources mResources; |
|
| 90 |
private static String mPackageName; |
|
| 91 | 88 |
|
| 92 | 89 |
private static String mScores = ""; |
| 93 |
private static int[][][] mCountry = new int [RubikObject.LENGTH][RubikStatePlay.MAX_SCRAMBLE][MAX_PLACES];
|
|
| 94 |
private static String[][][] mName = new String[RubikObject.LENGTH][RubikStatePlay.MAX_SCRAMBLE][MAX_PLACES];
|
|
| 95 |
private static String[][][] mTime = new String[RubikObject.LENGTH][RubikStatePlay.MAX_SCRAMBLE][MAX_PLACES];
|
|
| 90 |
private static String[][][] mCountry = new String[LENGTH][MAX_SCRAMBLE][MAX_PLACES];
|
|
| 91 |
private static String[][][] mName = new String[LENGTH][MAX_SCRAMBLE][MAX_PLACES];
|
|
| 92 |
private static String[][][] mTime = new String[LENGTH][MAX_SCRAMBLE][MAX_PLACES];
|
|
| 96 | 93 |
|
| 97 | 94 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 98 | 95 |
|
| ... | ... | |
| 124 | 121 |
{
|
| 125 | 122 |
int size = Integer.valueOf( row.substring(0,s1) ); |
| 126 | 123 |
|
| 127 |
if( size>=0 && size< RubikObject.LENGTH )
|
|
| 124 |
if( size>=0 && size<LENGTH ) |
|
| 128 | 125 |
{
|
| 129 | 126 |
int level = Integer.valueOf( row.substring(s1+1,s2) ); |
| 130 | 127 |
int place = Integer.valueOf( row.substring(s2+1,s3) ); |
| ... | ... | |
| 133 | 130 |
String country = row.substring(s5+1, s6); |
| 134 | 131 |
String realTime= String.valueOf(time/10.0f); |
| 135 | 132 |
|
| 136 |
if(level>=0 && level<RubikStatePlay.MAX_SCRAMBLE && place>=0 && place<MAX_PLACES)
|
|
| 133 |
if(level>=0 && level<MAX_SCRAMBLE && place>=0 && place<MAX_PLACES) |
|
| 137 | 134 |
{
|
| 138 |
int resID = mResources.getIdentifier( country, "drawable", mPackageName); |
|
| 139 |
mCountry[size][level][place] = resID!=0 ? resID: R.drawable.unk; |
|
| 140 |
mName[size][level][place] = name; |
|
| 141 |
mTime[size][level][place] = realTime; |
|
| 135 |
mCountry[size][level][place] = country; |
|
| 136 |
mName [size][level][place] = name; |
|
| 137 |
mTime [size][level][place] = realTime; |
|
| 142 | 138 |
} |
| 143 | 139 |
} |
| 144 | 140 |
} |
| ... | ... | |
| 185 | 181 |
|
| 186 | 182 |
private boolean doDownload() |
| 187 | 183 |
{
|
| 188 |
String veri = "distored"; |
|
| 189 |
String name = URLencode(veri); |
|
| 184 |
// TODO |
|
| 190 | 185 |
int numRuns = 1; |
| 186 |
String veri = "distored"; |
|
| 187 |
// END |
|
| 191 | 188 |
String version = R.string.app_version+"d"; |
| 192 |
String message=URL+"/download.cgi?n="+name+"&r="+numRuns+"&e="+version; |
|
| 189 |
|
|
| 190 |
String message=URL+"/download.cgi?n="+URLencode(veri)+"&r="+numRuns+"&e="+version; |
|
| 193 | 191 |
|
| 194 | 192 |
try |
| 195 | 193 |
{
|
| ... | ... | |
| 285 | 283 |
|
| 286 | 284 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 287 | 285 |
|
| 288 |
public void download(Receiver receiver, Resources resources, String packageName)
|
|
| 286 |
public void download(Receiver receiver) |
|
| 289 | 287 |
{
|
| 290 | 288 |
mReceiver = receiver; |
| 291 |
mResources= resources; |
|
| 292 |
mPackageName = packageName; |
|
| 293 | 289 |
mMode = DOWNLOAD; |
| 294 |
|
|
| 295 | 290 |
Thread networkThrd = new Thread(this); |
| 296 | 291 |
networkThrd.start(); |
| 297 | 292 |
} |
Also available in: Unified diff
Improvement for Downloader. Remove as much knowledge from it as possible.