Revision 806329e3
Added by Leszek Koltunski over 3 years ago
| src/main/java/org/distorted/dialogs/RubikDialogUpdateView.java | ||
|---|---|---|
| 34 | 34 |
import org.distorted.main.R; |
| 35 | 35 |
import org.distorted.external.RubikNetwork; |
| 36 | 36 |
import org.distorted.external.RubikUpdates; |
| 37 |
import org.distorted.objects.RubikObjectList; |
|
| 38 |
|
|
| 39 |
import java.io.IOException; |
|
| 40 |
import java.lang.ref.WeakReference; |
|
| 37 | 41 |
|
| 38 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 39 | 43 |
|
| ... | ... | |
| 45 | 49 |
private Button mButton; |
| 46 | 50 |
private TextView mDescription; |
| 47 | 51 |
|
| 52 |
private WeakReference<Activity> mAct; |
|
| 53 |
|
|
| 48 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 49 | 55 |
|
| 50 | 56 |
public View createView(Activity act, RubikUpdates.UpdateInfo info, int fontSize, int padding, |
| 51 | 57 |
LinearLayout.LayoutParams pView, LinearLayout.LayoutParams pText, LinearLayout.LayoutParams pButt ) |
| 52 | 58 |
{
|
| 59 |
mAct = new WeakReference<>(act); |
|
| 53 | 60 |
mInfo = info; |
| 54 | 61 |
final RubikNetwork.Downloadee downloadee = this; |
| 55 | 62 |
View view = act.getLayoutInflater().inflate(R.layout.dialog_updates_pane, null); |
| ... | ... | |
| 134 | 141 |
mDescription.setText(R.string.installing); |
| 135 | 142 |
|
| 136 | 143 |
RubikFiles files = RubikFiles.getInstance(); |
| 137 |
boolean oSuccess=true, eSuccess=true; |
|
| 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 |
} |
|
| 138 | 152 |
|
| 139 | 153 |
if( mInfo.mObjectStream!=null ) |
| 140 | 154 |
{
|
| 141 | 155 |
String name = mInfo.mObjectShortName + "_object.json"; |
| 142 |
oSuccess = files.saveFile(mInfo.mObjectStream, name); |
|
| 156 |
Activity act = mAct.get(); |
|
| 157 |
oSuccess = files.saveFile(act,mInfo.mObjectStream, name); |
|
| 143 | 158 |
} |
| 144 | 159 |
|
| 145 | 160 |
if( mInfo.mExtrasStream!=null ) |
| 146 | 161 |
{
|
| 147 | 162 |
String name = mInfo.mObjectShortName + "_extras.json"; |
| 148 |
eSuccess = files.saveFile(mInfo.mExtrasStream, name); |
|
| 163 |
Activity act = mAct.get(); |
|
| 164 |
eSuccess = files.saveFile(act,mInfo.mExtrasStream, name); |
|
| 149 | 165 |
} |
| 150 | 166 |
|
| 151 |
if( oSuccess ) |
|
| 167 |
if( iSuccess && oSuccess )
|
|
| 152 | 168 |
{
|
| 153 | 169 |
mBar.setProgress(75); |
| 154 | 170 |
mDescription.setText(R.string.configuring); |
| 171 |
RubikObjectList.addDownloadedObject(mInfo.mObjectShortName,iSuccess,oSuccess,eSuccess); |
|
| 172 |
mBar.setProgress(100); |
|
| 173 |
mDescription.setText(R.string.success); |
|
| 174 |
|
|
| 175 |
RubikNetwork network = RubikNetwork.getInstance(); |
|
| 176 |
network.updateDone(mInfo.mObjectShortName); |
|
| 155 | 177 |
} |
| 156 | 178 |
else |
| 157 | 179 |
{
|
| src/main/java/org/distorted/external/RubikFiles.java | ||
|---|---|---|
| 19 | 19 |
|
| 20 | 20 |
package org.distorted.external; |
| 21 | 21 |
|
| 22 |
import java.io.File; |
|
| 23 |
import java.io.FileOutputStream; |
|
| 24 |
import java.io.IOException; |
|
| 22 | 25 |
import java.io.InputStream; |
| 26 |
import java.io.OutputStream; |
|
| 27 |
|
|
| 28 |
import android.content.Context; |
|
| 29 |
import android.graphics.Bitmap; |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 | 32 |
|
| 24 | 33 |
public class RubikFiles |
| 25 | 34 |
{
|
| ... | ... | |
| 44 | 53 |
|
| 45 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 46 | 55 |
|
| 47 |
public boolean saveFile(InputStream stream, String name) |
|
| 56 |
public boolean saveFile(Context context, InputStream stream, String name)
|
|
| 48 | 57 |
{
|
| 49 |
return false; |
|
| 58 |
try |
|
| 59 |
{
|
|
| 60 |
File file = new File(context.getFilesDir(), name); |
|
| 61 |
OutputStream outStream = new FileOutputStream(file); |
|
| 62 |
|
|
| 63 |
byte[] buffer = new byte[8*1024]; |
|
| 64 |
int bytesRead; |
|
| 65 |
while ((bytesRead = stream.read(buffer)) != -1) |
|
| 66 |
{
|
|
| 67 |
outStream.write(buffer, 0, bytesRead); |
|
| 68 |
} |
|
| 69 |
outStream.close(); |
|
| 70 |
|
|
| 71 |
return true; |
|
| 72 |
} |
|
| 73 |
catch(IOException ioe) |
|
| 74 |
{
|
|
| 75 |
android.util.Log.e("D", "Exception trying to save "+name+" : "+ioe.getMessage() );
|
|
| 76 |
return false; |
|
| 77 |
} |
|
| 78 |
} |
|
| 79 |
|
|
| 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 81 |
|
|
| 82 |
public boolean saveFile(Context context, Bitmap bmp, String name) |
|
| 83 |
{
|
|
| 84 |
try |
|
| 85 |
{
|
|
| 86 |
File file = new File(context.getFilesDir(), name); |
|
| 87 |
OutputStream outStream = new FileOutputStream(file); |
|
| 88 |
bmp.compress(Bitmap.CompressFormat.PNG, 100, outStream); |
|
| 89 |
outStream.close(); |
|
| 90 |
|
|
| 91 |
return true; |
|
| 92 |
} |
|
| 93 |
catch(IOException ioe) |
|
| 94 |
{
|
|
| 95 |
android.util.Log.e("D", "Exception trying to save "+name+" : "+ioe.getMessage() );
|
|
| 96 |
return false; |
|
| 97 |
} |
|
| 50 | 98 |
} |
| 51 | 99 |
} |
| src/main/java/org/distorted/external/RubikNetwork.java | ||
|---|---|---|
| 753 | 753 |
HttpURLConnection conn = (HttpURLConnection) connectURL.openConnection(); |
| 754 | 754 |
conn.setDoInput(true); |
| 755 | 755 |
conn.connect(); |
| 756 |
InputStream stream = conn.getInputStream(); |
|
| 757 |
conn.disconnect(); |
|
| 758 |
return stream; |
|
| 756 |
return conn.getInputStream(); |
|
| 759 | 757 |
} |
| 760 | 758 |
catch (IOException e) |
| 761 | 759 |
{
|
| ... | ... | |
| 773 | 771 |
if(info.mUpdateExtras) info.mExtrasStream = downloadJSON(info.mObjectShortName+"_extras.json"); |
| 774 | 772 |
|
| 775 | 773 |
downloadee.jsonDownloaded(); |
| 774 |
|
|
| 775 |
try |
|
| 776 |
{
|
|
| 777 |
if( info.mObjectStream!=null ) info.mObjectStream.close(); |
|
| 778 |
} |
|
| 779 |
catch(IOException ioe) |
|
| 780 |
{
|
|
| 781 |
android.util.Log.e("D", "failed to close object input stream");
|
|
| 782 |
} |
|
| 783 |
|
|
| 784 |
try |
|
| 785 |
{
|
|
| 786 |
if( info.mExtrasStream!=null ) info.mExtrasStream.close(); |
|
| 787 |
} |
|
| 788 |
catch(IOException ioe) |
|
| 789 |
{
|
|
| 790 |
android.util.Log.e("D", "failed to close extras input stream");
|
|
| 791 |
} |
|
| 776 | 792 |
} |
| 777 | 793 |
|
| 778 | 794 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/objects/RubikObjectList.java | ||
|---|---|---|
| 121 | 121 |
return type.getNumScramble(); |
| 122 | 122 |
} |
| 123 | 123 |
|
| 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 125 |
|
|
| 126 |
public static void addDownloadedObject(String shortName, boolean icon, boolean object, boolean extras) |
|
| 127 |
{
|
|
| 128 |
|
|
| 129 |
} |
|
| 130 |
|
|
| 124 | 131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 125 | 132 |
|
| 126 | 133 |
public static void setMeshState(int ordinal, int state) |
| src/main/res/values-de/strings.xml | ||
|---|---|---|
| 34 | 34 |
<string name="configuring">Konfigurieren…</string> |
| 35 | 35 |
<string name="saveError">Fehler beim Speichern der Datei</string> |
| 36 | 36 |
<string name="networkError">Netzwerkfehler</string> |
| 37 |
<string name="success">Erfolg</string> |
|
| 37 | 38 |
<string name="view">Sehen</string> |
| 38 | 39 |
<string name="level_full">Volles Scramble</string> |
| 39 | 40 |
|
| src/main/res/values-es/strings.xml | ||
|---|---|---|
| 34 | 34 |
<string name="configuring">Configurando…</string> |
| 35 | 35 |
<string name="saveError">Error al guardar el archivo</string> |
| 36 | 36 |
<string name="networkError">Error de red</string> |
| 37 |
<string name="success">Éxito</string> |
|
| 37 | 38 |
<string name="view">Ver</string> |
| 38 | 39 |
<string name="level_full">Revuelto Completo</string> |
| 39 | 40 |
|
| src/main/res/values-fr/strings.xml | ||
|---|---|---|
| 34 | 34 |
<string name="configuring">Configuration…</string> |
| 35 | 35 |
<string name="saveError">Échec de l\'enregistrement du fichier</string> |
| 36 | 36 |
<string name="networkError">Erreur réseau</string> |
| 37 |
<string name="success">Succès</string> |
|
| 37 | 38 |
<string name="view">Regarder</string> |
| 38 | 39 |
<string name="level_full">Brouillage Complet</string> |
| 39 | 40 |
|
| src/main/res/values-ja/strings.xml | ||
|---|---|---|
| 34 | 34 |
<string name="configuring">構成…</string> |
| 35 | 35 |
<string name="saveError">ファイルの保存に失敗しました</string> |
| 36 | 36 |
<string name="networkError">ネットワークエラー</string> |
| 37 |
<string name="success">成功</string> |
|
| 37 | 38 |
<string name="view">見る</string> |
| 38 | 39 |
<string name="level_full">フルスクランブル</string> |
| 39 | 40 |
|
| src/main/res/values-ko/strings.xml | ||
|---|---|---|
| 34 | 34 |
<string name="configuring">구성…</string> |
| 35 | 35 |
<string name="saveError">파일 저장 실패</string> |
| 36 | 36 |
<string name="networkError">네트워크 오류</string> |
| 37 |
<string name="success">성공</string> |
|
| 37 | 38 |
<string name="view">보다</string> |
| 38 | 39 |
<string name="level_full">풀 스크램블</string> |
| 39 | 40 |
|
| src/main/res/values-pl/strings.xml | ||
|---|---|---|
| 34 | 34 |
<string name="configuring">Konfigurowanie…</string> |
| 35 | 35 |
<string name="saveError">Błąd zapisu pliku</string> |
| 36 | 36 |
<string name="networkError">Błąd sieci</string> |
| 37 |
<string name="success">Sukces</string> |
|
| 37 | 38 |
<string name="view">Zobacz</string> |
| 38 | 39 |
<string name="level_full">Pełne Pomieszanie</string> |
| 39 | 40 |
|
| src/main/res/values-ru/strings.xml | ||
|---|---|---|
| 34 | 34 |
<string name="configuring">Настройка…</string> |
| 35 | 35 |
<string name="saveError">Не удалось сохранить файл</string> |
| 36 | 36 |
<string name="networkError">Ошибка сети</string> |
| 37 |
<string name="success">Успех</string> |
|
| 37 | 38 |
<string name="view">Смотри</string> |
| 38 | 39 |
<string name="level_full">Полная Схватка</string> |
| 39 | 40 |
|
| src/main/res/values-zh-rCN/strings.xml | ||
|---|---|---|
| 34 | 34 |
<string name="configuring">配置…</string> |
| 35 | 35 |
<string name="saveError">保存文件失败</string> |
| 36 | 36 |
<string name="networkError">網絡錯誤</string> |
| 37 |
<string name="success">成功</string> |
|
| 37 | 38 |
<string name="view">看</string> |
| 38 | 39 |
<string name="level_full">级满</string> |
| 39 | 40 |
|
| src/main/res/values-zh-rTW/strings.xml | ||
|---|---|---|
| 34 | 34 |
<string name="configuring">配置…</string> |
| 35 | 35 |
<string name="saveError">保存文件失敗</string> |
| 36 | 36 |
<string name="networkError">網絡錯誤</string> |
| 37 |
<string name="success">成功</string> |
|
| 37 | 38 |
<string name="view">看</string> |
| 38 | 39 |
<string name="level_full">級滿</string> |
| 39 | 40 |
|
| src/main/res/values/strings.xml | ||
|---|---|---|
| 35 | 35 |
<string name="configuring">Configuring…</string> |
| 36 | 36 |
<string name="saveError">Failed to save file</string> |
| 37 | 37 |
<string name="networkError">Network Error</string> |
| 38 |
<string name="success">Success</string> |
|
| 38 | 39 |
<string name="view">View</string> |
| 39 | 40 |
<string name="level_full">Full Scramble</string> |
| 40 | 41 |
|
Also available in: Unified diff
Support for saving the downloaded JSONs in local data storage.