Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mannyamorim committed Sep 1, 2016
2 parents 43d1800 + f10258a commit 88afb87
Show file tree
Hide file tree
Showing 13 changed files with 457 additions and 93 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Metric Time

This android application provides a widget for your home screen that shows the current time in Metric Time (Decimal Time). You can read more about this time format here https://en.wikipedia.org/wiki/Decimal_time.
This android application provides a widget for your home screen that shows the current time in Metric Time (Decimal Time). You can read more about this time format here https://en.wikipedia.org/wiki/Decimal_time.

You can download the app from F-Droid. Please note F-Droid signs the APKs themselves using a different key than the one used to sign the releases on GitHub. If you switch between providers you will need to completely uninstall the app and then do a fresh install using the other provider.

[<img src="https://f-droid.org/badge/get-it-on.png" alt="Get it on F-Droid" height="80">](https://f-droid.org/app/com.mathi_amorim.emmanuel.metrictime)
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.mathi_amorim.emmanuel.metrictime"
minSdkVersion 19
targetSdkVersion 24
versionCode 3
versionName "0.0.3"
versionCode 4
versionName "0.1.1"
}
buildTypes {
release {
Expand Down
49 changes: 38 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<!--
<?xml version="1.0" encoding="utf-8"?><!--
MIT License
Copyright (c) 2016 Emmanuel Mathi-Amorim
Expand All @@ -23,10 +21,11 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mathi_amorim.emmanuel.metrictime">

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -35,18 +34,46 @@
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".MetricTimeWidgetProvider" android:label="@string/widget_name">

<receiver
android:name=".MetricTimeWidgetProvider"
android:label="@string/widget_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
<action android:name="com.mathi_amorim.emmanuel.metrictime.WIDGET_UPDATE"/>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
<action android:name="com.mathi_amorim.emmanuel.metrictime.WIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/metric_time_widget_info"/>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/metric_time_widget_info" />
</receiver>
<service android:name=".MetricTimeWidgetProvider$UpdateTimeService"/>

<service android:name=".UpdateTimeService" />

<receiver
android:name=".MetricTimeNotificationProvider"
android:directBootAware="true"
android:label="Metric Time Notification"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
</intent-filter>
</receiver>

<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"
android:parentActivityName=".MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="MainActivity" />
</activity>
</application>

</manifest>
31 changes: 31 additions & 0 deletions app/src/main/java/com/mathi_amorim/emmanuel/metrictime/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
MIT License
Copyright (c) 2016 Emmanuel Mathi-Amorim
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package com.mathi_amorim.emmanuel.metrictime;

import android.content.Context;

public final class Config {
public static boolean showNotification = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ of this software and associated documentation files (the "Software"), to deal

package com.mathi_amorim.emmanuel.metrictime;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void settingsClicked(View view) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
MIT License
Copyright (c) 2016 Emmanuel Mathi-Amorim
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package com.mathi_amorim.emmanuel.metrictime;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import android.util.Log;

public class MetricTimeNotificationProvider extends BroadcastReceiver {
@Override public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.intent.action.BOOT_COMPLETED") ||
intent.getAction().equals("android.intent.action.LOCKED_BOOT_COMPLETED")) {

context.startService(new Intent(context, UpdateTimeService.class));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,11 @@ of this software and associated documentation files (the "Software"), to deal

package com.mathi_amorim.emmanuel.metrictime;

import android.app.Service;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.widget.RemoteViews;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import android.util.Log;

public class MetricTimeWidgetProvider extends AppWidgetProvider {
@Override
Expand All @@ -51,8 +41,6 @@ public void onEnabled(Context context) {
@Override
public void onDisabled(Context context) {
super.onDisabled(context);

context.stopService(new Intent(context, UpdateTimeService.class));
}

@Override
Expand All @@ -61,67 +49,4 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a

context.startService(new Intent(context, UpdateTimeService.class));
}

public static final class UpdateTimeService extends Service {
static final String UPDATE_TIME = "com.mathi_amorim.emmanuel.metrictime.UPDATE_TIME";

private Calendar mCalendar;
private final static IntentFilter mIntentFilter = new IntentFilter();

static {
mIntentFilter.addAction(Intent.ACTION_TIME_TICK);
mIntentFilter.addAction(Intent.ACTION_TIME_CHANGED);
mIntentFilter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
}

@Override
public void onCreate() {
super.onCreate();

mCalendar = Calendar.getInstance();
registerReceiver(mTimeChangedReceiver, mIntentFilter);
}

@Override
public void onDestroy() {
super.onDestroy();

unregisterReceiver(mTimeChangedReceiver);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
super.onStartCommand(intent, flags, startId);

updateTime();

return START_STICKY;
}

@Override
public IBinder onBind(Intent intent) {
return null;
}

private final BroadcastReceiver mTimeChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateTime();
}
};

private void updateTime() {
mCalendar.setTimeInMillis(System.currentTimeMillis());

MetricTime time = MetricTimeConverter.currentMetricTime();
String currentTime = String.format("%1$01d:%2$02d", time.hours, time.minutes);

RemoteViews mRemoteViews = new RemoteViews(getPackageName(), R.layout.metric_time_widget);
mRemoteViews.setTextViewText(R.id.widget1label, currentTime);

ComponentName mComponentName = new ComponentName(this, MetricTimeWidgetProvider.class);
AppWidgetManager mAppWidgetManager = AppWidgetManager.getInstance(this);
mAppWidgetManager.updateAppWidget(mComponentName, mRemoteViews);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
MIT License
Copyright (c) 2016 Emmanuel Mathi-Amorim
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package com.mathi_amorim.emmanuel.metrictime;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;

public class SettingsActivity extends Activity implements SharedPreferences.OnSharedPreferenceChangeListener {
public static final String KEY_PREF_SHOW_NOTIFICATION = "pref_key_show_notification";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}

@Override
protected void onResume() {
super.onResume();
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
}

@Override
protected void onPause() {
super.onPause();
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this);
}

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(KEY_PREF_SHOW_NOTIFICATION)) {
Config.showNotification = sharedPreferences.getBoolean(SettingsActivity.KEY_PREF_SHOW_NOTIFICATION, true);
startService(new Intent(this, UpdateTimeService.class));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
MIT License
Copyright (c) 2016 Emmanuel Mathi-Amorim
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package com.mathi_amorim.emmanuel.metrictime;

import android.os.Bundle;
import android.preference.PreferenceFragment;

public class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
}
Loading

0 comments on commit 88afb87

Please sign in to comment.