Project

General

Profile

« Previous | Next » 

Revision 86cbdab1

Added by Leszek Koltunski about 4 years ago

Minor tweaks to the 'Prev' buton in Solving state;
Relax requirements in the Manifest - now only 'android.hardware.faketouch' supporting device is required, i.e. something that supports basic point-click-drag-unclick. No need for full 'android.hardware.touchscreen' thing with its multitouch silliness.

View differences:

build.gradle
5 5

  
6 6
    defaultConfig {
7 7
        applicationId "org.distorted.magic"
8
        minSdkVersion 25
8
        minSdkVersion 21
9 9
        targetSdkVersion 27
10 10
        versionCode 1
11 11
        versionName "1.0"
src/main/AndroidManifest.xml
2 2
    package="org.distorted.main">
3 3

  
4 4
    <uses-feature android:glEsVersion="0x00030001" android:required="true" />
5
    <uses-feature android:name="android.hardware.faketouch" android:required="true" />
6
    <uses-feature android:name="android.hardware.touchscreen" android:required="false" />
7

  
5 8
    <uses-permission android:name="android.permission.INTERNET" />
6 9

  
7 10
    <application
src/main/java/org/distorted/scores/RubikScoresDownloader.java
28 28
import java.net.HttpURLConnection;
29 29
import java.net.URL;
30 30
import java.net.UnknownHostException;
31
import java.security.MessageDigest;
32
import java.security.NoSuchAlgorithmException;
31 33

  
32 34
import static org.distorted.objects.RubikObjectList.MAX_LEVEL;
33 35

  
......
98 100
  private static RubikScoresDownloader mThis;
99 101

  
100 102
///////////////////////////////////////////////////////////////////////////////////////////////////
101
// TODO
102 103

  
103
  private static int computeHash(String name, String veri, String country, String lvllist,
104
                                 String objlist, String timelist, int runnings)
104
  private static String computeHash(String stringToHash, byte[] salt)
105 105
    {
106
    int length, hash = 0;
107

  
108
    length = name.length();
109
    for(int i=0; i<length; i++) hash += i*name.charAt(i);
110
    length = veri.length();
111
    for(int i=0; i<length; i++) hash += i*veri.charAt(i);
112
    length = country.length();
113
    for(int i=0; i<length; i++) hash += i*country.charAt(i);
114
    length = lvllist.length();
115
    for(int i=0; i<length; i++) hash += i*lvllist.charAt(i);
116
    length = objlist.length();
117
    for(int i=0; i<length; i++) hash += i*objlist.charAt(i);
118
    length = timelist.length();
119
    for(int i=0; i<length; i++) hash += i*timelist.charAt(i);
120

  
121
    hash *= runnings;
122
    hash %= 541;
123

  
124
    return hash<0 ? -hash: hash;
106
    String generatedPassword;
107

  
108
    try
109
      {
110
      MessageDigest md = MessageDigest.getInstance("MD5");
111
      md.update(salt);
112
      byte[] bytes = md.digest(stringToHash.getBytes());
113
      StringBuilder sb = new StringBuilder();
114

  
115
      for (byte aByte : bytes)
116
        {
117
        sb.append(Integer.toString((aByte & 0xff) + 0x100, 16).substring(1));
118
        }
119

  
120
      generatedPassword = sb.toString();
121
      }
122
    catch (NoSuchAlgorithmException e)
123
      {
124
      return "NoSuchAlgorithm";
125
      }
126

  
127
    return generatedPassword;
125 128
    }
126 129

  
127 130
///////////////////////////////////////////////////////////////////////////////////////////////////
......
330 333
    String lvllist = scores.getUnsubmittedLevellist();
331 334
    String timlist = scores.getUnsubmittedTimelist();
332 335
    String country = scores.getCountry();
333
    int hash = computeHash(name,veri,country,lvllist,objlist,timlist,numRuns);
336
    long epoch = System.currentTimeMillis();
337
    String salt = "cuboid";
334 338

  
335
    String url="https://distorted.org/magic/cgi-bin/submit.cgi";
336
    url += "?n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&i="+deviceID+"&e="+mVersion+"d";
337
    url += "&o="+objlist+"&l="+lvllist+"&t="+timlist+"&c="+country+"&h="+hash;
338
    url += "&oo="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_LEVEL+"&lo="+MAX_PLACES;
339
    String url1="https://distorted.org/magic/cgi-bin/submit.cgi";
340
    String url2 = "n="+name+"&v="+veri+"&r="+numRuns+"&p="+numPlay+"&i="+deviceID+"&e="+mVersion+"d";
341
    url2 += "&o="+objlist+"&l="+lvllist+"&t="+timlist+"&c="+country+"&f="+epoch;
342
    url2 += "&oo="+RubikObjectList.getObjectList()+"&min=0&max="+MAX_LEVEL+"&lo="+MAX_PLACES;
343
    url2 += "&h="+computeHash( url2, salt.getBytes() );
339 344

  
340
    return url;
345
    return url1 + "?" + url2;
341 346
    }
342 347

  
343 348
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/states/RubikStateSolving.java
142 142
    mPrevButton.setLayoutParams(params);
143 143
    mPrevButton.setPadding(padding,0,padding,0);
144 144
    mPrevButton.setImageResource(R.drawable.left);
145
    mPrevButton.setEnabled(false);
145
    mPrevButton.setVisibility(View.INVISIBLE);
146 146

  
147 147
    mPrevButton.setOnClickListener( new View.OnClickListener()
148 148
      {
......
180 180

  
181 181
          if( numMoves==1 )
182 182
            {
183
            mPrevButton.setEnabled(false);
183
            mPrevButton.setVisibility(View.INVISIBLE);
184 184
            }
185 185
          }
186 186
        else
......
203 203

  
204 204
    if( mMoves.size()==1 )
205 205
      {
206
      mPrevButton.setEnabled(true);
206
      mPrevButton.setVisibility(View.VISIBLE);
207 207
      }
208 208
    }
209 209

  
......
263 263
          {
264 264
          mTime.setText(R.string.solved);
265 265
          mBack.setClickable(false);
266
          mPrevButton.setVisibility(View.INVISIBLE);
266 267
          }
267 268
        });
268 269

  

Also available in: Unified diff