Revision 7fe62d1f
Added by Leszek Koltunski almost 4 years ago
| src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.dialogs; |
| 21 | 21 |
|
| 22 |
import java.lang.ref.WeakReference; |
|
| 23 |
|
|
| 22 | 24 |
import android.app.Activity; |
| 23 | 25 |
import android.graphics.Bitmap; |
| 24 | 26 |
import android.graphics.Color; |
| ... | ... | |
| 36 | 38 |
import org.distorted.external.RubikUpdates; |
| 37 | 39 |
import org.distorted.objects.RubikObjectList; |
| 38 | 40 |
|
| 39 |
import java.io.IOException; |
|
| 40 |
import java.lang.ref.WeakReference; |
|
| 41 |
|
|
| 42 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 43 | 42 |
|
| 44 | 43 |
public class RubikDialogUpdateView implements RubikNetwork.Downloadee |
| ... | ... | |
| 48 | 47 |
private ProgressBar mBar; |
| 49 | 48 |
private Button mButton; |
| 50 | 49 |
private TextView mDescription; |
| 51 |
|
|
| 52 | 50 |
private WeakReference<Activity> mAct; |
| 51 |
private boolean mIconSaved; |
|
| 53 | 52 |
|
| 54 | 53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 55 | 54 |
|
| 56 | 55 |
public View createView(Activity act, RubikUpdates.UpdateInfo info, int fontSize, int padding, |
| 57 | 56 |
LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt ) |
| 58 | 57 |
{
|
| 58 |
mIconSaved=false; |
|
| 59 | 59 |
mAct = new WeakReference<>(act); |
| 60 | 60 |
mInfo = info; |
| 61 | 61 |
final RubikNetwork.Downloadee downloadee = this; |
| ... | ... | |
| 111 | 111 |
|
| 112 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 113 | 113 |
|
| 114 |
void setIcon(Bitmap icon) |
|
| 114 |
void setIcon(Bitmap icon, boolean downloaded)
|
|
| 115 | 115 |
{
|
| 116 | 116 |
mIcon.setImageBitmap(icon); |
| 117 |
|
|
| 118 |
if( downloaded ) |
|
| 119 |
{
|
|
| 120 |
String name = mInfo.mObjectShortName + ".png"; |
|
| 121 |
Activity act = mAct.get(); |
|
| 122 |
RubikFiles files = RubikFiles.getInstance(); |
|
| 123 |
mIconSaved = files.saveIcon(act,mInfo.mIcon, name); |
|
| 124 |
} |
|
| 117 | 125 |
} |
| 118 | 126 |
|
| 119 | 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 141 | 149 |
mDescription.setText(R.string.installing); |
| 142 | 150 |
|
| 143 | 151 |
RubikFiles files = RubikFiles.getInstance(); |
| 144 |
boolean iSuccess=true,oSuccess=true, eSuccess=true; |
|
| 145 |
|
|
| 146 |
if( mInfo.mIcon!=null ) |
|
| 147 |
{
|
|
| 148 |
String name = mInfo.mObjectShortName + ".png"; |
|
| 149 |
Activity act = mAct.get(); |
|
| 150 |
iSuccess = files.saveFile(act,mInfo.mIcon, name); |
|
| 151 |
} |
|
| 152 |
boolean oSuccess=true, eSuccess=true; |
|
| 152 | 153 |
|
| 153 | 154 |
if( mInfo.mObjectStream!=null ) |
| 154 | 155 |
{
|
| ... | ... | |
| 164 | 165 |
eSuccess = files.saveFile(act,mInfo.mExtrasStream, name); |
| 165 | 166 |
} |
| 166 | 167 |
|
| 167 |
if( iSuccess && oSuccess )
|
|
| 168 |
if( mIconSaved || oSuccess || eSuccess )
|
|
| 168 | 169 |
{
|
| 169 | 170 |
mBar.setProgress(75); |
| 170 | 171 |
mDescription.setText(R.string.configuring); |
| 171 |
RubikObjectList.addDownloadedObject(mInfo.mObjectShortName,iSuccess,oSuccess,eSuccess);
|
|
| 172 |
RubikObjectList.addDownloadedObject(mInfo.mObjectShortName,mIconSaved,oSuccess,eSuccess);
|
|
| 172 | 173 |
mBar.setProgress(100); |
| 173 | 174 |
mDescription.setText(R.string.success); |
| 174 | 175 |
|
| src/main/java/org/distorted/dialogs/RubikDialogUpdates.java | ||
|---|---|---|
| 186 | 186 |
} |
| 187 | 187 |
|
| 188 | 188 |
RubikNetwork network = RubikNetwork.getInstance(); |
| 189 |
network.downloadIcons(this); |
|
| 189 |
network.downloadIcons(act,this);
|
|
| 190 | 190 |
} |
| 191 | 191 |
else |
| 192 | 192 |
{
|
| ... | ... | |
| 224 | 224 |
|
| 225 | 225 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 226 | 226 |
|
| 227 |
public void iconDownloaded(int ordinal, Bitmap icon) |
|
| 227 |
public void iconDownloaded(int ordinal, Bitmap icon, boolean downloaded)
|
|
| 228 | 228 |
{
|
| 229 | 229 |
FragmentActivity act = getActivity(); |
| 230 | 230 |
|
| ... | ... | |
| 236 | 236 |
public void run() |
| 237 | 237 |
{
|
| 238 | 238 |
RubikDialogUpdateView view = mPanes.get(ordinal); |
| 239 |
if( view!=null ) view.setIcon(icon); |
|
| 239 |
if( view!=null ) view.setIcon(icon,downloaded);
|
|
| 240 | 240 |
} |
| 241 | 241 |
}); |
| 242 | 242 |
} |
| src/main/java/org/distorted/external/RubikFiles.java | ||
|---|---|---|
| 27 | 27 |
|
| 28 | 28 |
import android.content.Context; |
| 29 | 29 |
import android.graphics.Bitmap; |
| 30 |
import android.graphics.BitmapFactory; |
|
| 30 | 31 |
|
| 31 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 32 | 33 |
|
| ... | ... | |
| 51 | 52 |
return mThis; |
| 52 | 53 |
} |
| 53 | 54 |
|
| 55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 56 |
|
|
| 57 |
public Bitmap getIcon(Context context, String name) |
|
| 58 |
{
|
|
| 59 |
File file = new File(context.getFilesDir(), name); |
|
| 60 |
|
|
| 61 |
if( file.exists() ) |
|
| 62 |
{
|
|
| 63 |
String fname = context.getFilesDir().getAbsolutePath()+"/"+name; |
|
| 64 |
return BitmapFactory.decodeFile(fname); |
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
return null; |
|
| 68 |
} |
|
| 69 |
|
|
| 54 | 70 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 55 | 71 |
|
| 56 | 72 |
public boolean saveFile(Context context, InputStream stream, String name) |
| ... | ... | |
| 79 | 95 |
|
| 80 | 96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 81 | 97 |
|
| 82 |
public boolean saveFile(Context context, Bitmap bmp, String name)
|
|
| 98 |
public boolean saveIcon(Context context, Bitmap bmp, String name)
|
|
| 83 | 99 |
{
|
| 84 | 100 |
try |
| 85 | 101 |
{
|
| src/main/java/org/distorted/external/RubikNetwork.java | ||
|---|---|---|
| 29 | 29 |
import java.security.MessageDigest; |
| 30 | 30 |
import java.security.NoSuchAlgorithmException; |
| 31 | 31 |
|
| 32 |
import android.content.Context; |
|
| 32 | 33 |
import android.content.pm.PackageInfo; |
| 33 | 34 |
import android.content.pm.PackageManager; |
| 34 | 35 |
import android.graphics.Bitmap; |
| ... | ... | |
| 55 | 56 |
|
| 56 | 57 |
public interface IconReceiver |
| 57 | 58 |
{
|
| 58 |
void iconDownloaded(int ordinal, Bitmap bitmap); |
|
| 59 |
void iconDownloaded(int ordinal, Bitmap bitmap, boolean downloaded);
|
|
| 59 | 60 |
} |
| 60 | 61 |
|
| 61 | 62 |
public interface Updatee |
| ... | ... | |
| 693 | 694 |
|
| 694 | 695 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 695 | 696 |
|
| 696 |
private void iconThread(IconReceiver receiver) |
|
| 697 |
private void iconThread(Context context, IconReceiver receiver)
|
|
| 697 | 698 |
{
|
| 698 | 699 |
int numC = mUpdates.getCompletedNumber(); |
| 699 | 700 |
int numS = mUpdates.getStartedNumber(); |
| ... | ... | |
| 704 | 705 |
|
| 705 | 706 |
if( iconPresent!=0 ) |
| 706 | 707 |
{
|
| 707 |
Bitmap icon = mUpdates.getCompletedIcon(c); |
|
| 708 |
boolean downloaded = false; |
|
| 709 |
Bitmap icon = mUpdates.getCompletedIcon(context,c); |
|
| 708 | 710 |
|
| 709 | 711 |
if( icon==null ) |
| 710 | 712 |
{
|
| 711 | 713 |
String url = mUpdates.getCompletedURL(c); |
| 712 | 714 |
icon = downloadIcon(url); |
| 715 |
downloaded = true; |
|
| 713 | 716 |
} |
| 714 | 717 |
if( icon!=null ) |
| 715 | 718 |
{
|
| 716 | 719 |
mUpdates.setCompletedIcon(c,icon); |
| 717 |
receiver.iconDownloaded(c,icon); |
|
| 720 |
receiver.iconDownloaded(c,icon,downloaded);
|
|
| 718 | 721 |
} |
| 719 | 722 |
} |
| 720 | 723 |
} |
| ... | ... | |
| 725 | 728 |
|
| 726 | 729 |
if( iconPresent!=0 ) |
| 727 | 730 |
{
|
| 728 |
Bitmap icon = mUpdates.getStartedIcon(s); |
|
| 731 |
boolean downloaded = false; |
|
| 732 |
Bitmap icon = mUpdates.getStartedIcon(context,s); |
|
| 729 | 733 |
|
| 730 | 734 |
if( icon==null ) |
| 731 | 735 |
{
|
| 732 | 736 |
String url = mUpdates.getStartedURL(s); |
| 733 | 737 |
icon = downloadIcon(url); |
| 738 |
downloaded = true; |
|
| 734 | 739 |
} |
| 735 | 740 |
if( icon!=null ) |
| 736 | 741 |
{
|
| 737 | 742 |
mUpdates.setStartedIcon(s,icon); |
| 738 |
receiver.iconDownloaded(numC+s,icon); |
|
| 743 |
receiver.iconDownloaded(numC+s,icon,downloaded);
|
|
| 739 | 744 |
} |
| 740 | 745 |
} |
| 741 | 746 |
} |
| ... | ... | |
| 905 | 910 |
|
| 906 | 911 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 907 | 912 |
|
| 908 |
public void downloadIcons(final IconReceiver receiver) |
|
| 913 |
public void downloadIcons(final Context context, final IconReceiver receiver)
|
|
| 909 | 914 |
{
|
| 910 | 915 |
initializeStatics(); |
| 911 | 916 |
|
| ... | ... | |
| 913 | 918 |
{
|
| 914 | 919 |
public void run() |
| 915 | 920 |
{
|
| 916 |
iconThread(receiver); |
|
| 921 |
iconThread(context,receiver);
|
|
| 917 | 922 |
} |
| 918 | 923 |
}; |
| 919 | 924 |
|
| src/main/java/org/distorted/external/RubikUpdates.java | ||
|---|---|---|
| 21 | 21 |
|
| 22 | 22 |
import java.io.InputStream; |
| 23 | 23 |
import java.util.ArrayList; |
| 24 |
|
|
| 25 |
import android.content.Context; |
|
| 24 | 26 |
import android.graphics.Bitmap; |
| 25 | 27 |
import org.distorted.objects.RubikObjectList; |
| 26 | 28 |
|
| ... | ... | |
| 158 | 160 |
|
| 159 | 161 |
public void updateDone(String shortName) |
| 160 | 162 |
{
|
| 161 |
for( UpdateInfo info : mCompleted) |
|
| 163 |
for( UpdateInfo info : mCompleted )
|
|
| 162 | 164 |
{
|
| 163 | 165 |
if( info.mObjectShortName.equals(shortName) ) |
| 164 | 166 |
{
|
| ... | ... | |
| 198 | 200 |
|
| 199 | 201 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 200 | 202 |
|
| 201 |
public Bitmap getCompletedIcon(int ordinal) |
|
| 203 |
public Bitmap getCompletedIcon(Context context, int ordinal)
|
|
| 202 | 204 |
{
|
| 203 |
return mCompleted.get(ordinal).mIcon; |
|
| 205 |
UpdateInfo info = mCompleted.get(ordinal); |
|
| 206 |
Bitmap bmp = info.mIcon; |
|
| 207 |
if( bmp!=null ) return bmp; |
|
| 208 |
|
|
| 209 |
RubikFiles files = RubikFiles.getInstance(); |
|
| 210 |
bmp = files.getIcon(context,info.mObjectShortName+".png"); |
|
| 211 |
info.mIcon = bmp; |
|
| 212 |
return bmp; |
|
| 204 | 213 |
} |
| 205 | 214 |
|
| 206 | 215 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 207 | 216 |
|
| 208 |
public Bitmap getStartedIcon(int ordinal) |
|
| 217 |
public Bitmap getStartedIcon(Context context, int ordinal)
|
|
| 209 | 218 |
{
|
| 210 |
return mStarted.get(ordinal).mIcon; |
|
| 219 |
UpdateInfo info = mStarted.get(ordinal); |
|
| 220 |
Bitmap bmp = info.mIcon; |
|
| 221 |
if( bmp!=null ) return bmp; |
|
| 222 |
|
|
| 223 |
RubikFiles files = RubikFiles.getInstance(); |
|
| 224 |
bmp = files.getIcon(context,info.mObjectShortName+".png"); |
|
| 225 |
info.mIcon = bmp; |
|
| 226 |
return bmp; |
|
| 211 | 227 |
} |
| 212 | 228 |
|
| 213 | 229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/solvers/SolverMain.java | ||
|---|---|---|
| 125 | 125 |
} |
| 126 | 126 |
} |
| 127 | 127 |
|
| 128 |
if( cubit>19) return 4; |
|
| 128 |
if( cubit>19 ) return 4;
|
|
| 129 | 129 |
|
| 130 | 130 |
switch(face) |
| 131 | 131 |
{
|
Also available in: Unified diff
Download the icons only once and save to local storage.