Revision b88cdd91
Added by Leszek Koltunski over 3 years ago
| src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java | ||
|---|---|---|
| 20 | 20 |
package org.distorted.dialogs; |
| 21 | 21 |
|
| 22 | 22 |
import android.app.Activity; |
| 23 |
import android.graphics.Bitmap; |
|
| 23 | 24 |
import android.util.TypedValue; |
| 24 | 25 |
import android.view.View; |
| 25 | 26 |
import android.widget.Button; |
| ... | ... | |
| 37 | 38 |
|
| 38 | 39 |
public class RubikDialogUpdateView |
| 39 | 40 |
{
|
| 40 |
public RubikDialogUpdateView() |
|
| 41 |
{
|
|
| 42 |
|
|
| 43 |
} |
|
| 41 |
private ImageView mIcon; |
|
| 44 | 42 |
|
| 45 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 46 | 44 |
|
| ... | ... | |
| 54 | 52 |
TextView description = view.findViewById(R.id.updates_pane_description); |
| 55 | 53 |
description.setText(info.mDescription); |
| 56 | 54 |
|
| 57 |
ImageView image = view.findViewById(R.id.updates_pane_image);
|
|
| 58 |
image.setBackgroundResource(R.drawable.unknown_icon);
|
|
| 55 |
mIcon = view.findViewById(R.id.updates_pane_image);
|
|
| 56 |
mIcon.setImageResource(R.drawable.unknown_icon);
|
|
| 59 | 57 |
|
| 60 |
image.setLayoutParams(pImage);
|
|
| 58 |
mIcon.setLayoutParams(pImage);
|
|
| 61 | 59 |
view.setLayoutParams(pView); |
| 62 | 60 |
|
| 63 | 61 |
title.setTextSize(TypedValue.COMPLEX_UNIT_PX, fontSize); |
| ... | ... | |
| 95 | 93 |
|
| 96 | 94 |
return view; |
| 97 | 95 |
} |
| 96 |
|
|
| 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 98 |
|
|
| 99 |
void setIcon(Bitmap icon) |
|
| 100 |
{
|
|
| 101 |
mIcon.setImageBitmap(icon); |
|
| 102 |
} |
|
| 98 | 103 |
} |
| src/main/java/org/distorted/dialogs/RubikDialogUpdates.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.dialogs; |
| 21 | 21 |
|
| 22 |
import java.util.ArrayList; |
|
| 23 |
|
|
| 22 | 24 |
import android.app.Dialog; |
| 23 | 25 |
import android.content.DialogInterface; |
| 26 |
import android.graphics.Bitmap; |
|
| 24 | 27 |
import android.os.Bundle; |
| 25 | 28 |
import android.util.DisplayMetrics; |
| 26 | 29 |
import android.util.TypedValue; |
| ... | ... | |
| 49 | 52 |
private LinearLayout mLayout; |
| 50 | 53 |
private int mMargin, mSize, mFontSize, mPadding; |
| 51 | 54 |
|
| 55 |
private ArrayList<RubikDialogUpdateView> mPanes; |
|
| 56 |
|
|
| 52 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 53 | 58 |
|
| 54 | 59 |
private View createView(FragmentActivity act, LayoutInflater inflater, float size, int minH) |
| ... | ... | |
| 72 | 77 |
@Override |
| 73 | 78 |
public Dialog onCreateDialog(Bundle savedInstanceState) |
| 74 | 79 |
{
|
| 80 |
if( mPanes==null ) mPanes = new ArrayList<>(); |
|
| 81 |
|
|
| 75 | 82 |
FragmentActivity act = getActivity(); |
| 76 | 83 |
LayoutInflater inflater = act.getLayoutInflater(); |
| 77 | 84 |
AlertDialog.Builder builder = new AlertDialog.Builder(act); |
| ... | ... | |
| 166 | 173 |
RubikDialogUpdateView rubikView = new RubikDialogUpdateView(); |
| 167 | 174 |
View pane = rubikView.createView(act,info,mFontSize,mPadding,pI,pV,pT,pB); |
| 168 | 175 |
mLayout.addView(pane); |
| 176 |
mPanes.add(rubikView); |
|
| 169 | 177 |
} |
| 170 | 178 |
|
| 171 | 179 |
int numS = updates.getStartedNumber(); |
| ... | ... | |
| 176 | 184 |
RubikDialogUpdateView rubikView = new RubikDialogUpdateView(); |
| 177 | 185 |
View pane = rubikView.createView(act,info,mFontSize,mPadding,pI,pV,pT,pB); |
| 178 | 186 |
mLayout.addView(pane); |
| 187 |
mPanes.add(rubikView); |
|
| 179 | 188 |
} |
| 180 | 189 |
|
| 181 | 190 |
RubikNetwork network = RubikNetwork.getInstance(); |
| ... | ... | |
| 216 | 225 |
|
| 217 | 226 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 218 | 227 |
|
| 219 |
public void iconDownloaded() |
|
| 228 |
public void iconDownloaded(int ordinal, Bitmap icon)
|
|
| 220 | 229 |
{
|
| 230 |
FragmentActivity act = getActivity(); |
|
| 221 | 231 |
|
| 232 |
if( act!=null ) |
|
| 233 |
{
|
|
| 234 |
act.runOnUiThread(new Runnable() |
|
| 235 |
{
|
|
| 236 |
@Override |
|
| 237 |
public void run() |
|
| 238 |
{
|
|
| 239 |
RubikDialogUpdateView view = mPanes.get(ordinal); |
|
| 240 |
if( view!=null ) view.setIcon(icon); |
|
| 241 |
} |
|
| 242 |
}); |
|
| 243 |
} |
|
| 222 | 244 |
} |
| 223 | 245 |
|
| 224 | 246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/network/RubikNetwork.java | ||
|---|---|---|
| 20 | 20 |
package org.distorted.network; |
| 21 | 21 |
|
| 22 | 22 |
import java.io.BufferedReader; |
| 23 |
import java.io.IOException; |
|
| 23 | 24 |
import java.io.InputStream; |
| 24 | 25 |
import java.io.InputStreamReader; |
| 25 | 26 |
import java.net.HttpURLConnection; |
| ... | ... | |
| 30 | 31 |
|
| 31 | 32 |
import android.content.pm.PackageInfo; |
| 32 | 33 |
import android.content.pm.PackageManager; |
| 34 |
import android.graphics.Bitmap; |
|
| 35 |
import android.graphics.BitmapFactory; |
|
| 33 | 36 |
|
| 34 | 37 |
import androidx.fragment.app.FragmentActivity; |
| 35 | 38 |
|
| ... | ... | |
| 52 | 55 |
|
| 53 | 56 |
public interface Updatee |
| 54 | 57 |
{
|
| 55 |
void iconDownloaded(); |
|
| 58 |
void iconDownloaded(int ordinal, Bitmap bitmap);
|
|
| 56 | 59 |
void receiveUpdate(RubikUpdates update); |
| 57 | 60 |
void errorUpdate(); |
| 58 | 61 |
} |
| ... | ... | |
| 655 | 658 |
} |
| 656 | 659 |
} |
| 657 | 660 |
|
| 661 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 662 |
|
|
| 663 |
private Bitmap downloadIcon(String url) |
|
| 664 |
{
|
|
| 665 |
try |
|
| 666 |
{
|
|
| 667 |
java.net.URL connectURL = new URL(url); |
|
| 668 |
HttpURLConnection conn = (HttpURLConnection) connectURL.openConnection(); |
|
| 669 |
conn.setDoInput(true); |
|
| 670 |
conn.connect(); |
|
| 671 |
InputStream input = conn.getInputStream(); |
|
| 672 |
return BitmapFactory.decodeStream(input); |
|
| 673 |
} |
|
| 674 |
catch (IOException e) |
|
| 675 |
{
|
|
| 676 |
android.util.Log.e("D", "Failed to download "+url);
|
|
| 677 |
android.util.Log.e("D", e.getMessage() );
|
|
| 678 |
return null; |
|
| 679 |
} |
|
| 680 |
} |
|
| 681 |
|
|
| 682 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 683 |
|
|
| 684 |
private void iconThread() |
|
| 685 |
{
|
|
| 686 |
int numC = mUpdates.getCompletedNumber(); |
|
| 687 |
int numS = mUpdates.getStartedNumber(); |
|
| 688 |
|
|
| 689 |
for(int c=0; c<numC; c++) |
|
| 690 |
{
|
|
| 691 |
Bitmap icon = mUpdates.getCompletedIcon(c); |
|
| 692 |
|
|
| 693 |
if( icon==null ) |
|
| 694 |
{
|
|
| 695 |
String url = mUpdates.getCompletedURL(c); |
|
| 696 |
icon = downloadIcon(url); |
|
| 697 |
} |
|
| 698 |
if( icon!=null ) |
|
| 699 |
{
|
|
| 700 |
mUpdates.setCompletedIcon(c,icon); |
|
| 701 |
mUpdatee.iconDownloaded(c,icon); |
|
| 702 |
} |
|
| 703 |
} |
|
| 704 |
|
|
| 705 |
for(int s=0; s<numS; s++) |
|
| 706 |
{
|
|
| 707 |
Bitmap icon = mUpdates.getStartedIcon(s); |
|
| 708 |
|
|
| 709 |
if( icon==null ) |
|
| 710 |
{
|
|
| 711 |
String url = mUpdates.getStartedURL(s); |
|
| 712 |
icon = downloadIcon(url); |
|
| 713 |
} |
|
| 714 |
if( icon!=null ) |
|
| 715 |
{
|
|
| 716 |
mUpdates.setStartedIcon(s,icon); |
|
| 717 |
mUpdatee.iconDownloaded(numC+s,icon); |
|
| 718 |
} |
|
| 719 |
} |
|
| 720 |
} |
|
| 721 |
|
|
| 658 | 722 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 659 | 723 |
|
| 660 | 724 |
private RubikNetwork() |
| ... | ... | |
| 778 | 842 |
|
| 779 | 843 |
public void downloadIcons(Updatee updatee) |
| 780 | 844 |
{
|
| 845 |
initializeStatics(); |
|
| 846 |
mUpdatee = updatee; |
|
| 847 |
|
|
| 848 |
Thread thread = new Thread() |
|
| 849 |
{
|
|
| 850 |
public void run() |
|
| 851 |
{
|
|
| 852 |
iconThread(); |
|
| 853 |
} |
|
| 854 |
}; |
|
| 781 | 855 |
|
| 856 |
thread.start(); |
|
| 782 | 857 |
} |
| 783 | 858 |
|
| 784 | 859 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/network/RubikUpdates.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.network; |
| 21 | 21 |
|
| 22 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
| 23 |
|
|
| 22 |
import java.util.ArrayList;
|
|
| 23 |
import android.graphics.Bitmap; |
|
| 24 | 24 |
import org.distorted.objects.RubikObjectList; |
| 25 | 25 |
|
| 26 |
import java.util.ArrayList;
|
|
| 26 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
| 27 | 27 |
|
| 28 | 28 |
public class RubikUpdates |
| 29 | 29 |
{
|
| ... | ... | |
| 37 | 37 |
public final int mPercent; |
| 38 | 38 |
public final boolean mUpdateObject; |
| 39 | 39 |
public final boolean mUpdateExtras; |
| 40 |
public Bitmap mIcon; |
|
| 40 | 41 |
|
| 41 | 42 |
public UpdateInfo(String shortName, String longName, String description, int objectMinor, |
| 42 | 43 |
int extrasMinor, int percent, boolean updateO, boolean updateE) |
| ... | ... | |
| 49 | 50 |
mPercent = percent; |
| 50 | 51 |
mUpdateObject = updateO; |
| 51 | 52 |
mUpdateExtras = updateE; |
| 53 |
|
|
| 54 |
mIcon = null; |
|
| 52 | 55 |
} |
| 53 | 56 |
} |
| 54 | 57 |
|
| ... | ... | |
| 133 | 136 |
if( numLines>=1 ) |
| 134 | 137 |
{
|
| 135 | 138 |
mUrl = lines[0]; |
| 139 |
if( !mUrl.endsWith("/") ) mUrl += "/";
|
|
| 140 |
|
|
| 136 | 141 |
for(int line=1; line<numLines; line++) |
| 137 | 142 |
{
|
| 138 | 143 |
String[] elements = lines[line].split(",");
|
| ... | ... | |
| 183 | 188 |
return mStarted.size(); |
| 184 | 189 |
} |
| 185 | 190 |
|
| 191 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 192 |
|
|
| 193 |
public Bitmap getCompletedIcon(int ordinal) |
|
| 194 |
{
|
|
| 195 |
return mCompleted.get(ordinal).mIcon; |
|
| 196 |
} |
|
| 197 |
|
|
| 198 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 199 |
|
|
| 200 |
public Bitmap getStartedIcon(int ordinal) |
|
| 201 |
{
|
|
| 202 |
return mStarted.get(ordinal).mIcon; |
|
| 203 |
} |
|
| 204 |
|
|
| 205 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 206 |
|
|
| 207 |
public String getCompletedURL(int ordinal) |
|
| 208 |
{
|
|
| 209 |
UpdateInfo info = mCompleted.get(ordinal); |
|
| 210 |
return info!=null ? mUrl + info.mObjectShortName + ".png" : null; |
|
| 211 |
} |
|
| 212 |
|
|
| 213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 214 |
|
|
| 215 |
public String getStartedURL(int ordinal) |
|
| 216 |
{
|
|
| 217 |
UpdateInfo info = mStarted.get(ordinal); |
|
| 218 |
return info!=null ? mUrl + info.mObjectShortName + ".png" : null; |
|
| 219 |
} |
|
| 220 |
|
|
| 221 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 222 |
|
|
| 223 |
public void setCompletedIcon(int ordinal, Bitmap icon) |
|
| 224 |
{
|
|
| 225 |
UpdateInfo info = mCompleted.get(ordinal); |
|
| 226 |
info.mIcon = icon; |
|
| 227 |
} |
|
| 228 |
|
|
| 229 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 230 |
|
|
| 231 |
public void setStartedIcon(int ordinal, Bitmap icon) |
|
| 232 |
{
|
|
| 233 |
UpdateInfo info = mStarted.get(ordinal); |
|
| 234 |
info.mIcon = icon; |
|
| 235 |
} |
|
| 236 |
|
|
| 186 | 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 187 | 238 |
|
| 188 | 239 |
public void showDebug() |
| src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
|---|---|---|
| 25 | 25 |
import android.content.Context; |
| 26 | 26 |
import android.content.SharedPreferences; |
| 27 | 27 |
import android.content.res.Resources; |
| 28 |
import android.graphics.Bitmap; |
|
| 28 | 29 |
import android.graphics.drawable.BitmapDrawable; |
| 29 | 30 |
import android.os.Build; |
| 30 | 31 |
import android.os.Bundle; |
| ... | ... | |
| 747 | 748 |
|
| 748 | 749 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 749 | 750 |
|
| 750 |
public void iconDownloaded() |
|
| 751 |
public void iconDownloaded(int ordinal, Bitmap bitmap)
|
|
| 751 | 752 |
{
|
| 752 | 753 |
// empty |
| 753 | 754 |
} |
Also available in: Unified diff
Download Update icons.