Initial open source release

This commit is contained in:
Trevor Slocum 2015-10-13 18:09:33 -07:00
commit 43d5d6d9e8
869 changed files with 24998 additions and 0 deletions

42
.gitignore vendored Normal file
View file

@ -0,0 +1,42 @@
build/
captures/
*/captures/
# built application files
*.apk
*.ap_
*.bar
*.wrn
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Eclipse project files
.classpath
.project
# Android Studio
.idea/
.gradle
/*/local.properties
/*/out
/*/*/build
*/build
/*/*/production
*.iml
*.iws
*.ipr
*~
*.swp

1
MeditationAssistant/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1 @@
{"project_info":{"project_id":"api-project-163346957857","project_number":"163346957857","name":"Meditation Assistant Free"},"client":[{"client_info":{"client_id":"android:sh.ftp.rocketninelabs.meditationassistant","client_type":1,"android_client_info":{"package_name":"sh.ftp.rocketninelabs.meditationassistant"}},"oauth_client":[{"client_id":"163346957857.apps.googleusercontent.com","client_type":1,"android_info":{"package_name":"sh.ftp.rocketninelabs.meditationassistant","certificate_hash":"f5f29854d4bac9d7ccf5d98a8a4b88f3beca47ff"}}],"services":{"analytics_service":{"status":2,"analytics_property":{"tracking_id":"UA-71983-51"}},"cloud_messaging_service":{"status":1,"apns_config":[]},"appinvite_service":{"status":2,"other_platform_oauth_client":[]},"google_signin_service":{"status":2},"ads_service":{"status":1}}}],"ARTIFACT_VERSION":"1"}

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<ignore path="build/**" />
</lint>

View file

@ -0,0 +1,216 @@
-verbose
# Begin optimizeproguard-optimize.txt:
-optimizations !code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 25
-allowaccessmodification
-dontpreverify
-dontwarn android.webkit.**
-keep class com.google.android.gms.analytics.**
-keep class com.google.analytics.tracking.**
-dontwarn com.google.android.gms.analytics.**
-dontwarn com.google.analytics.tracking.**
-dontwarn com.google.android.gms.**
-keep class android.support.** { *; }
-keep interface android.support.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keep class com.actionbarsherlock.** {*;}
-keep class org.holoeverywhere.** {*;}
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
public static final *** NULL;
}
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
@com.google.android.gms.common.annotation.KeepName *;
}
-keepnames class * implements android.os.Parcelable {
public static final ** CREATOR;
}
-keepclassmembers class * extends com.actionbarsherlock.ActionBarSherlock {
<init>(android.app.Activity, int);
}
# Keep line numbers to alleviate debugging stack traces
# -renamesourcefileattribute SourceFile
-keepattributes SourceFile,LineNumberTable
# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-keepattributes *Annotation*
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
native <methods>;
}
# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}
# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class **.R$* {
public static <fields>;
}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version. We know about them, and they are safe.
-dontwarn android.support.**
# End optimize
-keepattributes JavascriptInterface
-overloadaggressively
-allowaccessmodification
-keep public class sh.ftp.rocketninelabs.meditationassistant.JavascriptCallback
-keep public class * implements sh.ftp.rocketninelabs.meditationassistant.JavascriptCallback
-keepclassmembers class * implements sh.ftp.rocketninelabs.meditationassistant.JavascriptCallback {
<methods>;
}
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class com.actionbarsherlock.** { *; }
-keep interface com.actionbarsherlock.** { *; }
-keep public class com.crittercism.**
-keepclassmembers public class com.crittercism.* { *; }
# HoloEverywhere
-keep,allowshrinking,allowoptimization public class * extends ListView
-keep,allowoptimization class org.holoeverywhere.** {
public *;
protected *;
}
-keepclasseswithmembernames class org.holoeverywhere.internal.** {
public *;
protected *;
}
-keepclasseswithmembernames class org.holoeverywhere.internal.AlertController
-keep public class org.holoeverywhere.internal.AlertController.RecycleListView { *; }
-keep,allowshrinking,allowoptimization class org.holoeverywhere.** { *; }
-keep,allowshrinking,allowoptimization interface org.holoeverywhere.** { *; }
-keep,allowshrinking,allowoptimization public class * extends android.app.Application
-keep,allowshrinking,allowoptimization public class * extends android.app.Service
-keep,allowshrinking,allowoptimization public class * extends android.content.BroadcastReceiver
-keep,allowshrinking,allowoptimization public class * extends android.content.ContentProvider
-keep,allowshrinking,allowoptimization public class * extends android.app.backup.BackupAgentHelper
-keep,allowshrinking,allowoptimization public class * extends android.preference.Preference
-keep,allowshrinking,allowoptimization public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep,allowshrinking,allowoptimization class * { <methods>; }
-keepclasseswithmembernames,allowshrinking class * {
native <methods>;
}
-keepclasseswithmembers,allowshrinking class * {
public <init>(android.content.Context,android.util.AttributeSet);
public <init>(android.content.Context,android.util.AttributeSet,int);
}
-keepclassmembers class * {
public <init>(android.content.Context,android.util.AttributeSet);
public <init>(android.content.Context,android.util.AttributeSet,int);
}
# Google API Client
-keepattributes Signature,RuntimeVisibleAnnotations,AnnotationDefault
-keepclassmembers class * {
@com.google.api.client.util.Key <fields>;
}
# Needed by google-http-client-android when linking against an older platform version
-dontwarn com.google.api.client.extensions.android.**
# Needed by google-api-client-android when linking against an older platform version
-dontwarn com.google.api.client.googleapis.extensions.android.**
# End Google API Client

View file

@ -0,0 +1,187 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
package="sh.ftp.rocketninelabs.meditationassistant"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="22"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application
android:name="sh.ftp.rocketninelabs.meditationassistant.MeditationAssistant"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/appName"
android:theme="@style/MeditationDarkTheme">
<!-- Comment both when releasing full -->
<meta-data
android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAIqq_HCa56eFzfQpNSwYUIIytAyO6bh4fFUFUcYA"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<!-- DON'T COMMENT BELOW -->
<meta-data
android:name="com.google.android.gms.analytics.globalConfigResource"
android:resource="@xml/analytics"/>
<!-- Services -->
<service android:name="sh.ftp.rocketninelabs.meditationassistant.MeditationService"></service>
<!-- Receivers -->
<receiver
android:name="sh.ftp.rocketninelabs.meditationassistant.DailyNotification"
android:exported="true">
<intent-filter>
<action android:name="sh.ftp.rocketninelabs.meditationassistant.DAILY_NOTIFICATION"></action>
<action android:name="sh.ftp.rocketninelabs.meditationassistant.DAILY_NOTIFICATION_UPDATED"></action>
<action android:name="android.intent.action.EXTERNAL_APPLICATIONS_AVAILABLE"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.PACKAGE_REPLACED"/>
<data
android:path="sh.ftp.rocketninelabs.meditationassistant"
android:scheme="package"/>
</intent-filter>
</receiver>
<!-- Register AnalyticsReceiver and AnalyticsService to support background dispatching on non-Google Play devices -->
<receiver
android:name="com.google.android.gms.analytics.AnalyticsReceiver"
android:enabled="true"
tools:ignore="ExportedReceiver">
<intent-filter>
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH"/>
</intent-filter>
</receiver>
<service
android:name="com.google.android.gms.analytics.AnalyticsService"
android:enabled="true"
android:exported="false"/>
<!-- Register Wear data layer service -->
<service android:name=".WearListenerService">
<intent-filter>
<action android:name="com.google.android.gms.wearable.BIND_LISTENER"/>
</intent-filter>
</service>
<!-- Widgets -->
<!--
<receiver
android:name="sh.ftp.rocketninelabs.meditationassistant.MeditationProvider1"
android:label="@string/widget1x1" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_1" />
</receiver>
<receiver
android:name="sh.ftp.rocketninelabs.meditationassistant.MeditationProvider2"
android:label="@string/widget2x1" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_2" />
</receiver>
<receiver
android:name="sh.ftp.rocketninelabs.meditationassistant.MeditationProvider3"
android:label="@string/widget3x1" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/widget_3" />
</receiver>
-->
<!-- Activities -->
<activity
android:name="sh.ftp.rocketninelabs.meditationassistant.MainActivity"
android:configChanges="keyboard|keyboardHidden|screenSize|orientation"
android:label="@string/appNameShort"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="sh.ftp.rocketninelabs.meditationassistant.ALARM"></action>
</intent-filter>
</activity>
<activity
android:name="sh.ftp.rocketninelabs.meditationassistant.SettingsActivity"
android:configChanges="keyboard|keyboardHidden|screenSize|orientation"
android:label="@string/settings"
android:launchMode="singleTop"
android:parentActivityName="sh.ftp.rocketninelabs.meditationassistant.MainActivity"
tools:ignore="UnusedAttribute">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="sh.ftp.rocketninelabs.meditationassistant.MainActivity"/>
</activity>
<activity
android:name="sh.ftp.rocketninelabs.meditationassistant.MediNETActivity"
android:configChanges="keyboard|keyboardHidden|screenSize|orientation"
android:label=""
android:launchMode="singleTop">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="sh.ftp.rocketninelabs.meditationassistant.MainActivity"/>
</activity>
<activity
android:name="sh.ftp.rocketninelabs.meditationassistant.CompleteActivity"
android:configChanges="keyboard|keyboardHidden|screenSize|orientation"
android:label="@string/sessioncomplete">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="sh.ftp.rocketninelabs.meditationassistant.MainActivity"/>
</activity>
<activity
android:name="sh.ftp.rocketninelabs.meditationassistant.AboutActivity"
android:configChanges="keyboard|keyboardHidden|screenSize|orientation"
android:label="@string/about">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="sh.ftp.rocketninelabs.meditationassistant.MainActivity"/>
</activity>
<activity
android:name="sh.ftp.rocketninelabs.meditationassistant.ProgressActivity"
android:configChanges="keyboard|keyboardHidden|screenSize|orientation"
android:label="@string/progress">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="sh.ftp.rocketninelabs.meditationassistant.MainActivity"/>
</activity>
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent"/>
</application>
</manifest>

View file

@ -0,0 +1,157 @@
package sh.ftp.rocketninelabs.meditationassistant;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.appinvite.AppInviteInvitation;
public class AboutActivity extends Activity {
public String license = "";
private MeditationAssistant ma = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(getMeditationAssistant().getMATheme());
getActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_about);
TextView txtAboutAppName = (TextView) findViewById(R.id.txtAboutAppName);
TextView txtAboutAppVersion = (TextView) findViewById(R.id.txtAboutAppVersion);
if (getPackageName().equals(
"sh.ftp.rocketninelabs.meditationassistant")) {
txtAboutAppName.setText(getString(R.string.appName));
} else {
txtAboutAppName.setText(getString(R.string.appNameShort));
}
PackageInfo pInfo;
try {
pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
txtAboutAppVersion.setText(String.format(getString(R.string.version), pInfo.versionName));
} catch (PackageManager.NameNotFoundException e) {
txtAboutAppVersion.setVisibility(View.GONE);
e.printStackTrace();
}
LinearLayout layAbout = (LinearLayout) findViewById(R.id.layAbout);
layAbout.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
ImageView charis = (ImageView) findViewById(R.id.charis);
charis.setVisibility(View.VISIBLE);
charis.startAnimation(AnimationUtils.loadAnimation(
getApplicationContext(), R.anim.spin));
return true;
}
});
if (getMeditationAssistant().sendUsageReports()) {
getMeditationAssistant().getTracker(MeditationAssistant.TrackerName.APP_TRACKER);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.about, menu);
if (getMeditationAssistant().getIsBB() || !MeditationAssistant.getMarketName().equals("google")) {
MenuItem share = menu.findItem(R.id.action_share_app);
share.setVisible(false);
invalidateOptionsMenu();
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int i = item.getItemId();
if (i == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
} else if (i == R.id.action_share_app) {
Intent intent = new AppInviteInvitation.IntentBuilder(getString(R.string.appNameShort))
.setMessage(getString(R.string.invitationBlurb))
.build();
startActivityForResult(intent, 1337);
} else if (i == R.id.action_rate) {
getMeditationAssistant().askToRateApp();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onStart() {
super.onStart();
if (getMeditationAssistant().sendUsageReports()) {
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
}
@Override
protected void onStop() {
super.onStop();
if (getMeditationAssistant().sendUsageReports()) {
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
}
public void sendMeEmail(View view) {
Log.d("MeditationAssistant", "Open about");
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_EMAIL,
new String[]{"tslocum@gmail.com"});
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(
getPackageName(), 0);
intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.appNameShort) + " "
+ pInfo.versionName);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.appNameShort));
}
intent.putExtra(android.content.Intent.EXTRA_TEXT, "");
startActivity(Intent.createChooser(intent, getString(R.string.sendEmail)));
}
public void openHowToMeditate(View view) {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://medinet.ftp.sh/howtomeditate")).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
public void openTranslate(View view) {
startActivity(new Intent(
Intent.ACTION_VIEW,
Uri.parse("http://medinet.ftp.sh/translate")).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
public MeditationAssistant getMeditationAssistant() {
if (ma == null) {
ma = (MeditationAssistant) this.getApplication();
}
return ma;
}
}

View file

@ -0,0 +1,304 @@
package sh.ftp.rocketninelabs.meditationassistant;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TextView;
import java.util.Calendar;
import java.util.Locale;
public class CalendarFragment extends Fragment {
GridView gridCalendar = null;
TextView txtCurrentMonth = null;
TextView txtCurrentYear = null;
MonthAdapter monthadapter = null;
Calendar mCalendar = null;
ImageButton nextMonth = null;
private MeditationAssistant ma = null;
SharedPreferences.OnSharedPreferenceChangeListener sharedPrefslistener = new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
if (key.equals("sessionsupdate")) {
Log.d("MeditationAssistant", "Got sessions update, refreshing CalendarFragment");
refreshMonthDisplay();
}
}
};
public MeditationAssistant getMeditationAssistant() {
if (ma == null) {
ma = (MeditationAssistant) getActivity().getApplication();
}
return ma;
}
private MonthAdapter getMonthAdapter() {
final DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay()
.getMetrics(metrics);
updatecurrentDate();
return new MonthAdapter(getActivity(), mCalendar.get(Calendar.MONTH),
mCalendar.get(Calendar.YEAR), metrics, (ProgressActivity) getActivity(), getMeditationAssistant());
}
public void refreshMonthDisplay() {
gridCalendar.setAdapter(getMonthAdapter());
}
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getMeditationAssistant().getPrefs().registerOnSharedPreferenceChangeListener(sharedPrefslistener);
int color_primary = getResources().getColor(getMeditationAssistant().getMATextColor(true));
int color_primary_disabled = getResources().getColor(getMeditationAssistant().getMATextColor(false));
/* Getting resource not found errors here */
try {
color_primary = getResources().getColor(
getMeditationAssistant()
.getTheme()
.obtainStyledAttributes(
getMeditationAssistant().getMATheme(),
new int[]{android.R.attr.textColorPrimary})
.getResourceId(0, 0)
);
color_primary_disabled = getResources()
.getColor(
getMeditationAssistant()
.getTheme()
.obtainStyledAttributes(
getMeditationAssistant()
.getMATheme(),
new int[]{android.R.attr.textColorPrimaryDisableOnly}
)
.getResourceId(0, 0)
);
} catch (Exception e) {
Log.d("MeditationAssistant", "Unable to get color resources in CalendarFragment:");
e.printStackTrace();
}
txtCurrentMonth = new TextView(getActivity());
txtCurrentYear = new TextView(getActivity());
mCalendar = Calendar.getInstance();
txtCurrentMonth.setTextSize(22);
txtCurrentYear.setTextSize(12);
txtCurrentMonth.setTextColor(color_primary);
txtCurrentMonth
.setTextColor(color_primary_disabled);
txtCurrentMonth.setSingleLine(true);
txtCurrentMonth.setEllipsize(TextUtils.TruncateAt.END);
txtCurrentYear.setSingleLine(true);
txtCurrentYear.setEllipsize(TextUtils.TruncateAt.END);
gridCalendar = new GridView(getActivity());
gridCalendar.setNumColumns(7);
gridCalendar.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
gridCalendar.setVerticalSpacing(2);
gridCalendar.setHorizontalSpacing(2);
gridCalendar.setAdapter(getMonthAdapter());
}
@SuppressWarnings("deprecation")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Context ctx = getActivity().getApplicationContext();
LinearLayout lcontainer = new LinearLayout(ctx);
lcontainer.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
lcontainer.setOrientation(LinearLayout.VERTICAL);
LinearLayout lmain = new LinearLayout(ctx);
lmain.setOrientation(LinearLayout.VERTICAL);
lmain.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
lmain.setWeightSum(0.5f);
LinearLayout lhoriz = new LinearLayout(ctx);
lhoriz.setOrientation(LinearLayout.HORIZONTAL);
lhoriz.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
lmain.addView(gridCalendar);
ImageButton prevMonth = new ImageButton(getActivity());
prevMonth.setImageDrawable(getResources().getDrawable(
getMeditationAssistant()
.getTheme()
.obtainStyledAttributes(
getMeditationAssistant().getMATheme(),
new int[]{R.attr.actionIconPreviousItem})
.getResourceId(0, 0)
));
nextMonth = new ImageButton(getActivity());
nextMonth.setImageDrawable(getResources().getDrawable(
getMeditationAssistant()
.getTheme()
.obtainStyledAttributes(
getMeditationAssistant().getMATheme(),
new int[]{R.attr.actionIconNextItem})
.getResourceId(0, 0)
));
/*TableLayout.LayoutParams monthbuttonslp = new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1f);*/
TableLayout.LayoutParams monthbuttonslp = new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1f);
monthbuttonslp.setMargins(0, MeditationAssistant.dpToPixels(7, ctx), 0,
MeditationAssistant.dpToPixels(7, ctx));
prevMonth.setLayoutParams(monthbuttonslp);
nextMonth.setLayoutParams(monthbuttonslp);
prevMonth.setBackgroundColor(getActivity().getResources().getColor(
android.R.color.transparent));
nextMonth.setBackgroundColor(getActivity().getResources().getColor(
android.R.color.transparent));
prevMonth.setBackgroundResource(getMeditationAssistant()
.getTheme()
.obtainStyledAttributes(
getMeditationAssistant().getMATheme(),
new int[]{android.R.attr.selectableItemBackground})
.getResourceId(0, 0));
nextMonth.setBackgroundResource(getMeditationAssistant()
.getTheme()
.obtainStyledAttributes(
getMeditationAssistant().getMATheme(),
new int[]{android.R.attr.selectableItemBackground})
.getResourceId(0, 0));
prevMonth.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mCalendar.add(Calendar.MONTH, -1);
gridCalendar.setAdapter(getMonthAdapter());
updateMonthScroll();
}
});
nextMonth.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mCalendar.add(Calendar.MONTH, 1);
gridCalendar.setAdapter(getMonthAdapter());
updateMonthScroll();
}
});
LinearLayout ldate = new LinearLayout(ctx);
ldate.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams lp_horiz = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1f);
prevMonth.setLayoutParams(lp_horiz);
ldate.setLayoutParams(lp_horiz);
nextMonth.setLayoutParams(lp_horiz);
ldate.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL);
txtCurrentMonth.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL);
txtCurrentYear.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL);
ldate.addView(txtCurrentMonth);
ldate.addView(txtCurrentYear);
lhoriz.setMinimumHeight(MeditationAssistant.dpToPixels(48, ctx));
lhoriz.addView(prevMonth);
lhoriz.addView(ldate);
lhoriz.addView(nextMonth);
LinearLayout lbottom = new LinearLayout(ctx);
lmain.setOrientation(LinearLayout.VERTICAL);
lbottom.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
lbottom.setWeightSum(0.5f);
lbottom.setMinimumHeight(MeditationAssistant.dpToPixels(48, ctx));
lbottom.addView(lhoriz);
lmain.setGravity(Gravity.BOTTOM);
View divBottom = new View(ctx);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT,
MeditationAssistant.dpToPixels(1, ctx));
lp.setMargins(MeditationAssistant.dpToPixels(7, ctx), 0,
MeditationAssistant.dpToPixels(7, ctx), 0);
divBottom.setLayoutParams(lp);
divBottom.setPadding(7, 0, 7, 0);
divBottom.setBackgroundDrawable(getResources().getDrawable(
getMeditationAssistant()
.getTheme()
.obtainStyledAttributes(
getMeditationAssistant().getMATheme(),
new int[]{android.R.attr.listDividerAlertDialog})
.getResourceId(0, 0)
));
lcontainer.addView(lbottom);
lcontainer.addView(divBottom);
lcontainer.addView(lmain);
updateMonthScroll();
return lcontainer;
}
public void updatecurrentDate() {
txtCurrentMonth.setText(String.format(Locale.getDefault(), "%tB", mCalendar));
txtCurrentYear.setText(String.format(Locale.getDefault(), "%tY", mCalendar));
}
private void updateMonthScroll() {
Calendar nowCalendar = Calendar.getInstance();
if (mCalendar.get(Calendar.MONTH) == nowCalendar.get(Calendar.MONTH)
&& mCalendar.get(Calendar.YEAR) == nowCalendar
.get(Calendar.YEAR)) {
nextMonth.setClickable(false);
nextMonth.setVisibility(View.INVISIBLE);
} else {
nextMonth.setClickable(true);
nextMonth.setVisibility(View.VISIBLE);
}
}
@Override
public void onPause() {
getMeditationAssistant().getPrefs().unregisterOnSharedPreferenceChangeListener(sharedPrefslistener);
super.onPause();
}
@Override
public void onResume() {
getMeditationAssistant().getPrefs().registerOnSharedPreferenceChangeListener(sharedPrefslistener);
super.onResume();
}
}

View file

@ -0,0 +1,421 @@
package sh.ftp.rocketninelabs.meditationassistant;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.analytics.GoogleAnalytics;
public class CompleteActivity extends Activity {
private AdView av = null;
private MediaPlayer mMediaPlayer;
private MeditationAssistant ma;
private Handler handler = new Handler();
private Runnable runnable = new Runnable() {
@Override
public void run() {
handler.removeCallbacks(this);
if (getMeditationAssistant().getMediNET().result.equals("posted")) {
getMeditationAssistant()
.shortToast(getString(R.string.sessionPosted));
finish();
} else if (getMeditationAssistant().getMediNET().result
.equals("alreadyposted")) {
getMeditationAssistant().longToast(getString(R.string.sessionAlreadyPosted));
} else if (getMeditationAssistant().getMediNET().status
.equals("failure")
&& getMeditationAssistant().getMediNET().result
.equals("corrupt")) {
getMeditationAssistant()
.longToast(
getString(R.string.sessionNotPosted));
} else {
handler.postDelayed(this, 2000);
}
}
};
private Runnable clearWakeLock = new Runnable() {
public void run() {
handler.removeCallbacks(clearWakeLock);
WakeLocker.release();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(getMeditationAssistant().getMATheme());
setContentView(R.layout.activity_complete);
getMeditationAssistant().hideNotification(); // Called twice because it seems to help
long timestamp = System.currentTimeMillis() / 1000;
if (getMeditationAssistant().getTimeStartMeditate() == 0
|| (timestamp - getMeditationAssistant().getTimeStartMeditate()) <= 0) {
// Reset timestamps for current session
getMeditationAssistant().setTimeStartMeditate(0);
getMeditationAssistant().setTimeToStopMeditate(0);
finish();
return;
}
setTheme(getMeditationAssistant().getMATheme());
/*if (getMeditationAssistant().getMATheme() != R.style.MADark) {
getWindow().setBackgroundDrawable(
getResources().getDrawable(
android.R.drawable.screen_background_light));
}*/
setContentView(R.layout.activity_complete);
getWindow().setWindowAnimations(0);
getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
);
Boolean manual = false;
if (getIntent().hasExtra("manual")) {
if (getIntent().getBooleanExtra("manual", false)) {
manual = true;
}
}
getMeditationAssistant().unsetNotificationControl();
getMeditationAssistant().hideNotification(); // Called twice because it seems to help
if (getPackageName().equals("sh.ftp.rocketninelabs.meditationassistant")) {
Log.d("MeditationAssistant", "Fetching ad");
av = (AdView) findViewById(R.id.adViewSessionComplete);
av.setVisibility(View.VISIBLE);
com.google.android.gms.ads.AdRequest adRequest = new com.google.android.gms.ads.AdRequest.Builder()
.addTestDevice(com.google.android.gms.ads.AdRequest.DEVICE_ID_EMULATOR)
.build();
av.loadAd(adRequest);
}
EditText editSessionMessage = (EditText) findViewById(R.id.editSessionMessage);
if (editSessionMessage.getText().toString().equals("")
&& getMeditationAssistant().getPrefs().getBoolean("pref_remembermessage", false)) {
editSessionMessage.setText(getMeditationAssistant().getPrefs().getString("lastmessage", ""));
}
editSessionMessage
.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
EditText editSessionMessage = (EditText) findViewById(R.id.editSessionMessage);
TextView editSessionMessageInfo = (TextView) findViewById(R.id.editSessionMessageInfo);
if (hasFocus) {
editSessionMessageInfo.setText(String
.valueOf(editSessionMessage.getText()
.length())
+ " / 160");
editSessionMessageInfo.setVisibility(View.VISIBLE);
} else {
editSessionMessageInfo.setVisibility(View.GONE);
}
}
});
editSessionMessage.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
TextView editSessionMessageInfo = (TextView) findViewById(R.id.editSessionMessageInfo);
editSessionMessageInfo.setText(String.valueOf(s.length())
+ " / 160");
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
if (getMeditationAssistant()
.getTimeStartMeditate() == 0) {
/* Getting null pointers on getTimeStartMeditate() */
Log.d("MeditationAssistant", "getTimeStartMeditate() was 0! Exiting AlarmReceiverActivity...");
finish();
return;
}
// Meditation Session
getMeditationAssistant().getMediNET().resetSession();
getMeditationAssistant().getMediNET().session.started = getMeditationAssistant()
.getTimeStartMeditate();
if (getMeditationAssistant().getTimerMode().equals("endat")) {
Log.d("MeditationAssistant", String.valueOf(Math.min(timestamp, getMeditationAssistant().getTimeToStopMeditate())) + " - "
+ String.valueOf(getMeditationAssistant().getTimeStartMeditate()) + " - " + String.valueOf(getMeditationAssistant().pausetime));
getMeditationAssistant().getMediNET().session.length = Math.min(timestamp, getMeditationAssistant().getTimeToStopMeditate())
- getMeditationAssistant().getTimeStartMeditate() - getMeditationAssistant().pausetime;
} else {
Log.d("MeditationAssistant", String.valueOf(timestamp) + " - "
+ String.valueOf(getMeditationAssistant().getTimeStartMeditate()) + " - " + String.valueOf(getMeditationAssistant().pausetime));
getMeditationAssistant().getMediNET().session.length = timestamp
- getMeditationAssistant().getTimeStartMeditate() - getMeditationAssistant().pausetime;
}
getMeditationAssistant().getMediNET().session.length += 7; // Add seven seconds to account for slow wake-ups
getMeditationAssistant().getMediNET().session.completed = timestamp;
// Reset timestamps for current session
getMeditationAssistant().setTimeStartMeditate(0);
getMeditationAssistant().setTimeToStopMeditate(0);
Log.d("MeditationAssistant",
"Session length: "
+ String.valueOf(getMeditationAssistant().getMediNET().session.length)
);
if (getMeditationAssistant().getMediNET().session.length > 0) {
TextView txtDuration = (TextView) findViewById(R.id.txtDuration);
txtDuration.setText(MediNET
.durationToTimerString(getMeditationAssistant()
.getMediNET().session.length, false));
String text_size = getMeditationAssistant().getPrefs().getString("pref_text_size", "normal");
if (text_size.equals("tiny")) {
txtDuration.setTextSize(85);
} else if (text_size.equals("small")) {
txtDuration.setTextSize(115);
} else if (text_size.equals("large")) {
txtDuration.setTextSize(175);
} else if (text_size.equals("extralarge")) {
txtDuration.setTextSize(200);
} else { // Normal
txtDuration.setTextSize(153);
}
if (!manual
&& !getMeditationAssistant().getPrefs().getString("pref_meditation_sound_finish", "")
.equals("none")) {
mMediaPlayer = null;
if (getMeditationAssistant().getPrefs().getString("pref_meditation_sound_finish", "").equals(
"custom")) {
String soundpath = getMeditationAssistant().getPrefs().getString(
"pref_meditation_sound_finish_custom", "");
if (!soundpath.equals("")) {
try {
mMediaPlayer = MediaPlayer.create(this,
Uri.parse(soundpath));
} catch (Exception e) {
e.printStackTrace();
}
}
} else {
mMediaPlayer = MediaPlayer.create(this, MeditationSounds
.getMeditationSound(getMeditationAssistant().getPrefs().getString(
"pref_meditation_sound_finish", "")));
}
if (mMediaPlayer != null) {
mMediaPlayer
.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
WakeLocker.release();
mp.release();
}
});
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer
.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(
MediaPlayer mp) {
mp.start();
}
});
//mMediaPlayer.prepareAsync();
} else {
handler.postDelayed(clearWakeLock, 5000);
}
}
}
if (getMeditationAssistant().sendUsageReports()) {
getMeditationAssistant().getTracker(MeditationAssistant.TrackerName.APP_TRACKER);
}
if (!manual) {
getMeditationAssistant().vibrateDevice();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.complete, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
if (item.getItemId() == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void askDismiss() {
new AlertDialog.Builder(this)
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(getString(R.string.askDiscardText))
.setPositiveButton(getString(R.string.discard),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
finish();
}
}
).setNegativeButton(getString(R.string.cancel), null)
.show();
}
public void dismiss(View view) {
if (getMeditationAssistant().getPrefs().getBoolean("pref_askdismiss", true)) {
askDismiss();
} else {
finish();
}
}
public MeditationAssistant getMeditationAssistant() {
if (ma == null) {
ma = (MeditationAssistant) this.getApplication();
}
return ma;
}
private String getSessionMessage() {
EditText editSessionMessage = (EditText) findViewById(R.id.editSessionMessage);
return editSessionMessage.getText().toString().trim();
}
@Override
public void onBackPressed() {
if (getMeditationAssistant().getPrefs().getBoolean("pref_askdismiss", true)) {
askDismiss();
} else {
super.onBackPressed();
}
}
@Override
public void onDestroy() {
if (av != null) {
av.destroy();
}
if (mMediaPlayer != null) {
try {
mMediaPlayer.release();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
WakeLocker.release();
} catch (Exception e) {
e.printStackTrace();
}
handler.removeCallbacks(runnable);
super.onDestroy();
}
@Override
public void onPause() {
if (av != null) {
av.pause();
}
super.onPause();
}
@Override
public void onResume() {
super.onResume();
if (av != null) {
av.resume();
}
}
@Override
public void onStart() {
super.onStart();
if (getMeditationAssistant().sendUsageReports()) {
GoogleAnalytics.getInstance(this).reportActivityStart(this);
}
}
@Override
protected void onStop() {
super.onStop();
if (getMeditationAssistant().sendUsageReports()) {
GoogleAnalytics.getInstance(this).reportActivityStop(this);
}
}
public void postMediNET(View view) {
if (getMeditationAssistant().getMediNETKey() == "") {
getMeditationAssistant().showSignInDialog(this);
return;
}
saveLastMessage();
getMeditationAssistant().shortToast(getString(R.string.sessionPosting));
getMeditationAssistant().getMediNET().session.message = getSessionMessage();
getMeditationAssistant().getMediNET().postSession();
handler.removeCallbacks(runnable);
handler.postDelayed(runnable, 5);
}
private void saveLastMessage() {
SharedPreferences.Editor editor = getMeditationAssistant().getPrefs().edit();
editor.putString("lastmessage", getSessionMessage());
editor.apply();
}
public void saveMediNET(View view) {
saveLastMessage();
getMeditationAssistant().getMediNET().session.message = getSessionMessage();
getMeditationAssistant().getMediNET().saveSession(false, false);
getMeditationAssistant().shortToast(getString(R.string.sessionSaved));
finish();
}
}

View file

@ -0,0 +1,123 @@
package sh.ftp.rocketninelabs.meditationassistant;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
//import org.apache.commons.codec.binary.Base64;
public class Crypt {
private IvParameterSpec ivspec;
private SecretKeySpec keyspec;
private Cipher cipher;
public Crypt() {
ivspec = new IvParameterSpec("fzsznzsjh2asdr7e".getBytes());
keyspec = new SecretKeySpec("jqx82h4ad6fzb4dk".getBytes(), "AES");
try {
cipher = Cipher.getInstance("AES/CBC/NoPadding");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchPaddingException e) {
e.printStackTrace();
}
}
public static String bytesToHex(byte[] data) {
if (data == null) {
return null;
}
int len = data.length;
String str = "";
for (int i = 0; i < len; i++) {
if ((data[i] & 0xFF) < 16)
str = str + "0" + java.lang.Integer.toHexString(data[i] & 0xFF);
else
str = str + java.lang.Integer.toHexString(data[i] & 0xFF);
}
return str;
}
public static byte[] hexToBytes(String str) {
if (str == null) {
return null;
} else if (str.length() < 2) {
return null;
} else {
int len = str.length() / 2;
byte[] buffer = new byte[len];
for (int i = 0; i < len; i++) {
buffer[i] = (byte) Integer.parseInt(
str.substring(i * 2, i * 2 + 2), 16);
}
return buffer;
}
}
private static String padString(String source) {
char paddingChar = ' ';
int size = 16;
int x = source.length() % size;
int padLength = size - x;
for (int i = 0; i < padLength; i++) {
source += paddingChar;
}
return source;
}
public byte[] decrypt(String code) throws Exception {
if (code == null || code.length() == 0)
throw new Exception("Empty string");
byte[] decrypted = null;
try {