summaryrefslogtreecommitdiffstats
path: root/Ministro
diff options
context:
space:
mode:
authorBogDan Vatra <bog_dan_ro@yahoo.com>2011-05-18 13:37:29 +0800
committerBogDan Vatra <bog_dan_ro@yahoo.com>2011-05-18 13:39:29 +0800
commitb7f34e9f3d1992f9264c122495bfd97e529aec5e (patch)
tree640a234cb3a5cdf1a15e4ab9be9f7641f8648598 /Ministro
parent69d518d4ae9096d5ddbe2b767b5faab95c69b285 (diff)
Add Ministro configuration tool.
Diffstat (limited to 'Ministro')
-rw-r--r--Ministro/AndroidManifest.xml11
-rw-r--r--Ministro/res/values/strings.xml1
-rw-r--r--Ministro/src/eu/licentia/necessitas/ministro/MinistroActivity.java19
-rw-r--r--Ministro/src/eu/licentia/necessitas/ministro/MinistroConfigActivity.java91
-rw-r--r--Ministro/src/eu/licentia/necessitas/ministro/MinistroService.java26
5 files changed, 132 insertions, 16 deletions
diff --git a/Ministro/AndroidManifest.xml b/Ministro/AndroidManifest.xml
index aeeba91..f06bf99 100644
--- a/Ministro/AndroidManifest.xml
+++ b/Ministro/AndroidManifest.xml
@@ -8,8 +8,15 @@
android:label="@string/app_name"
android:configChanges="orientation|locale|fontScale|keyboard|keyboardHidden" >
<intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
+ <action android:name="android.intent.action.DEFAULT" />
+ <category android:name="android.intent.category.VIEW" />
+ </intent-filter>
+ </activity>
+ <activity android:name="MinistroConfigActivity"
+ android:label="@string/app_name">
+ <intent-filter>
+ <action android:name="eu.licentia.necessitas.ministro.MinistroConfigActivity" />
+ <category android:name="android.intent.category.VIEW" />
</intent-filter>
</activity>
<service android:name=".MinistroService">
diff --git a/Ministro/res/values/strings.xml b/Ministro/res/values/strings.xml
index 8debf7a..45435cf 100644
--- a/Ministro/res/values/strings.xml
+++ b/Ministro/res/values/strings.xml
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Ministro</string>
+ <string name="repositories_prompt">Choose a repository</string>
</resources>
diff --git a/Ministro/src/eu/licentia/necessitas/ministro/MinistroActivity.java b/Ministro/src/eu/licentia/necessitas/ministro/MinistroActivity.java
index 35923f5..8a0cd81 100644
--- a/Ministro/src/eu/licentia/necessitas/ministro/MinistroActivity.java
+++ b/Ministro/src/eu/licentia/necessitas/ministro/MinistroActivity.java
@@ -62,8 +62,7 @@ import android.os.IBinder;
public class MinistroActivity extends Activity {
public native static int nativeChmode(String filepath, int mode);
-
- private static final String DOMAIN_NAME="http://files.kde.org/necessitas";
+ private static final String DOMAIN_NAME="http://files.kde.org/necessitas/ministro/";
private String[] m_modules;
private int m_id=-1;
@@ -117,17 +116,17 @@ public class MinistroActivity extends Activity {
finish();
}
- private static URL getVersionUrl() throws MalformedURLException
+ private static URL getVersionUrl(Context c) throws MalformedURLException
{
- return new URL(DOMAIN_NAME+"/qt/android/"+android.os.Build.CPU_ABI+"/android-"+android.os.Build.VERSION.SDK_INT+"/versions.xml");
+ return new URL(DOMAIN_NAME+MinistroService.getRepository(c)+"/android/"+android.os.Build.CPU_ABI+"/android-"+android.os.Build.VERSION.SDK_INT+"/versions.xml");
}
- private static URL getLibsXmlUrl(double version) throws MalformedURLException
+ private static URL getLibsXmlUrl(Context c, double version) throws MalformedURLException
{
- return new URL(DOMAIN_NAME+"/qt/android/"+android.os.Build.CPU_ABI+"/android-"+android.os.Build.VERSION.SDK_INT+"/libs-"+version+".xml");
+ return new URL(DOMAIN_NAME+MinistroService.getRepository(c)+"/android/"+android.os.Build.CPU_ABI+"/android-"+android.os.Build.VERSION.SDK_INT+"/libs-"+version+".xml");
}
- public static double downloadVersionXmlFile(boolean checkOnly)
+ public static double downloadVersionXmlFile(Context c, boolean checkOnly)
{
try
{
@@ -135,7 +134,7 @@ public class MinistroActivity extends Activity {
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = null;
Element root = null;
- URLConnection connection = getVersionUrl().openConnection();
+ URLConnection connection = getVersionUrl(c).openConnection();
dom = builder.parse(connection.getInputStream());
root = dom.getDocumentElement();
root.normalize();
@@ -146,7 +145,7 @@ public class MinistroActivity extends Activity {
if (checkOnly)
return version;
- connection = getLibsXmlUrl(version).openConnection();
+ connection = getLibsXmlUrl(c, version).openConnection();
connection.setRequestProperty("Accept-Encoding", "gzip,deflate");
File file= new File(MinistroService.instance().getVersionXmlFile());
file.delete();
@@ -352,7 +351,7 @@ public class MinistroActivity extends Activity {
Element root = null;
if (update[0] || MinistroService.instance().getVersion()<0)
- version = downloadVersionXmlFile(false);
+ version = downloadVersionXmlFile(MinistroActivity.this, false);
else
version = MinistroService.instance().getVersion();
diff --git a/Ministro/src/eu/licentia/necessitas/ministro/MinistroConfigActivity.java b/Ministro/src/eu/licentia/necessitas/ministro/MinistroConfigActivity.java
new file mode 100644
index 0000000..294affc
--- /dev/null
+++ b/Ministro/src/eu/licentia/necessitas/ministro/MinistroConfigActivity.java
@@ -0,0 +1,91 @@
+/*
+ Copyright (c) 2011, BogDan Vatra <bog_dan_ro@yahoo.com>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package eu.licentia.necessitas.ministro;
+
+import android.app.Activity;
+import android.app.Notification;
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
+import android.widget.ArrayAdapter;
+import android.widget.Spinner;
+import android.widget.Toast;
+
+public class MinistroConfigActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ // TODO Auto-generated method stub
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.repoconfig);
+ Spinner s = (Spinner) findViewById(R.id.spinner);
+ ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
+ this, R.array.repositories, android.R.layout.simple_spinner_item);
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ s.setAdapter(adapter);
+ s.setSelection(adapter.getPosition(MinistroService.getRepository(this)));
+ s.setOnItemSelectedListener(new OnItemSelectedListener(){
+ @Override
+ public void onItemSelected(AdapterView<?> parent, View view, int pos,
+ long id) {
+ // TODO Auto-generated method stub
+ Toast.makeText(parent.getContext(), "Ministro will use " +
+ parent.getItemAtPosition(pos).toString()+" repository", Toast.LENGTH_LONG).show();
+ MinistroService.setRepository(MinistroConfigActivity.this, parent.getItemAtPosition(pos).toString());
+ }
+
+ @Override
+ public void onNothingSelected(AdapterView<?> arg0) {
+ // TODO Auto-generated method stub
+ }
+ });
+ }
+
+ @Override
+ protected void onDestroy() {
+ NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
+ int icon = R.drawable.icon;
+ CharSequence tickerText = "Ministro repository changed"; // ticker-text
+ long when = System.currentTimeMillis(); // notification time
+ Context context = getApplicationContext(); // application Context
+ CharSequence contentTitle = "Ministro update"; // expanded message title
+ CharSequence contentText = "Ministro repository changed tap to update."; // expanded message text
+
+ Intent notificationIntent = new Intent(this, MinistroActivity.class);
+ PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
+
+ // the next two lines initialize the Notification, using the configurations above
+ Notification notification = new Notification(icon, tickerText, when);
+ notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
+ notification.defaults |= Notification.DEFAULT_SOUND;
+ notification.defaults |= Notification.DEFAULT_VIBRATE;
+ notification.defaults |= Notification.DEFAULT_LIGHTS;
+ try{
+ nm.notify(1, notification);
+ }catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ super.onDestroy();
+ }
+} \ No newline at end of file
diff --git a/Ministro/src/eu/licentia/necessitas/ministro/MinistroService.java b/Ministro/src/eu/licentia/necessitas/ministro/MinistroService.java
index a2f1847..954fea6 100644
--- a/Ministro/src/eu/licentia/necessitas/ministro/MinistroService.java
+++ b/Ministro/src/eu/licentia/necessitas/ministro/MinistroService.java
@@ -42,6 +42,25 @@ import android.os.IBinder;
import android.os.RemoteException;
public class MinistroService extends Service {
+ private static final String MINISTRO_CHECK_UPDATES_KEY="LASTCHECK";
+ private static final String MINISTRO_REPOSITORY_KEY="REPOSITORY";
+ private static final String MINISTRO_DEFAULT_REPOSITORY="stable";
+
+ public static String getRepository(Context c)
+ {
+ SharedPreferences preferences=c.getSharedPreferences("Ministro", MODE_PRIVATE);
+ return preferences.getString(MINISTRO_REPOSITORY_KEY,MINISTRO_DEFAULT_REPOSITORY);
+ }
+
+ public static void setRepository(Context c, String value)
+ {
+ SharedPreferences preferences=c.getSharedPreferences("Ministro", MODE_PRIVATE);
+ SharedPreferences.Editor editor= preferences.edit();
+ editor.putString(MINISTRO_REPOSITORY_KEY,value);
+ editor.putLong(MINISTRO_CHECK_UPDATES_KEY,0);
+ editor.commit();
+ }
+
// used to check Ministro Service compatibility
private static final int MINISTRO_MIN_API_LEVEL=1;
private static final int MINISTRO_MAX_API_LEVEL=1;
@@ -83,10 +102,9 @@ public class MinistroService extends Service {
class CheckForUpdates extends AsyncTask<Void, Void, Void>
{
-
@Override
protected void onPreExecute() {
- if (m_version<MinistroActivity.downloadVersionXmlFile(true))
+ if (m_version<MinistroActivity.downloadVersionXmlFile(MinistroService.this, true))
{
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
@@ -230,12 +248,12 @@ public class MinistroService extends Service {
m_versionXmlFile = getFilesDir().getAbsolutePath()+"/version.xml";
m_qtLibsRootPath = getFilesDir().getAbsolutePath()+"/qt/";
SharedPreferences preferences=getSharedPreferences("Ministro", MODE_PRIVATE);
- long lastCheck = preferences.getLong("LASTCHECK",0);
+ long lastCheck = preferences.getLong(MINISTRO_CHECK_UPDATES_KEY,0);
if (System.currentTimeMillis()-lastCheck>24l*3600*100) // check once/day
{
refreshLibraries(true);
SharedPreferences.Editor editor= preferences.edit();
- editor.putLong("LASTCHECK",System.currentTimeMillis());
+ editor.putLong(MINISTRO_CHECK_UPDATES_KEY,System.currentTimeMillis());
editor.commit();
new CheckForUpdates().execute((Void[])null);
}