MainActivity.java
4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.upc.pbe.upcnews;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
//Finestra incial i activity principal del programa
public class MainActivity extends Activity implements OnClickListener {
private final static String TAG = "Main";
private static String html;
private ImageView alerta;
private ImageButton buttonDescarrega;
private TextView URLText, alertaText;
@Override
public void onCreate(Bundle savedInstanceState){
//Creem el layout
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
Log.d(TAG, "onCreated");
//Especifiquem la ruta de descarrega
File tempFolder = new File(((UpcApp)getApplication()).getLocalPath());
if(tempFolder.mkdirs()) {
Log.d(TAG,"Directori " + tempFolder.toString() + " creat");
}
//Creem els botons i text
URLText = (TextView) findViewById(R.id.textViewUrl);
buttonDescarrega = (ImageButton) findViewById(R.id.button);
buttonDescarrega.setOnClickListener(this);
updateURL();
//Mostrem el missatge d'alerta si Vitamio no esta instalat
if(!io.vov.vitamio.LibsChecker.checkVitamioLibs(this)){
/*
* NO SEMBLA QUE FUNCIONI (AIXO COMPROVA LA LLIBRERIA, NO LA APP)
* PROBAR CLASE ANDROID PACKAGEMANAGER PER OBTENIR LLISTA D'APPS INSTALADES
*/
alerta = (ImageView) findViewById(R.id.imageViewAlerta);
alerta.setVisibility(View.VISIBLE);
alertaText = (TextView) findViewById(R.id.textViewAlerta);
alertaText.setVisibility(View.VISIBLE);
}
/* TESTING ANDROID DOWNLOADMANAGER NATIU
*
*
*
*
String pfile = "sample_ep_128k-00001.ts";
DownloadManager.Request request = new DownloadManager.Request(Uri.parse("http://revistes.upc.es/~imanol/PBE/"+pfile));
request.setDescription("SetDescprition");
request.setTitle("SetTitle");
request.setDestinationInExternalPublicDir(Environment.getExternalStorageDirectory().toString(), "sample_ep_128k-00001.ts");
DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(request);
*/
}
public void onClick(View v) {
//Al polsar el boto s'inicia la descarrega
Log.d(TAG, "onClicked");
this.descarregar();
if(!html.equals("EMPTY")) {
((UpcApp) getApplication()).setDesc(html);
startActivity(new Intent(this, Directoris.class));
}
}
public void descarregar() {
//Descarrega del document HTML de la URL especificada
//Si hi ha errors, els mostrem en Toasts
Descarrega d = new Descarrega();
html="EMPTY";
try {
html = (String) d.doInBackground(((UpcApp)getApplication()).getUrl());
}
catch(MalformedURLException e) {
Toast.makeText(this, "URL invalida", Toast.LENGTH_LONG).show();
}
catch(IOException e) {
Toast.makeText(this, "No s'ha pogut trobar la URL", Toast.LENGTH_LONG).show();
}
}
public void onResume() {
super.onResume();
updateURL();
}
public void updateURL() {
URLText.setText(((UpcApp)getApplication()).getUrl());
}
public boolean onCreateOptionsMenu(Menu menu) {
//Determina el funcionament al apretar la tecla d'opcions
getMenuInflater().inflate(R.menu.menu, menu);
Log.d(TAG, "Menu");
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
//Determina el funcionament al clickar en el menu d'opcions
switch (item.getItemId()) {
case R.id.itemprefs:
startActivity(new Intent(this, Prefs.class));
Log.d(TAG, "Preferencies");
return true;
case R.id.itemhelp:
startActivity(new Intent(this, Help.class));
Log.d(TAG, "Help");
return true;
default:
return false;
}
}
/*
* COSAS POR HACER
* (RELEASE-CRITICAL) Lentitud descarga -- Todos (este miercoles)
* (SEVERE) Crash preferences (Me sigue saliendo O.o)
* (NORMAL) Poner la defaultURL al server de PBE
* (WISHLIST) Descarga en segundo plano (Mejora dificil)
* (WISHLIST) Añadir gif Imanol bailando (Easter eggs? vais en serio? XDDDDDDDDDDDD)
* Borrar esta puta mierda
*/
}