Skip to content

Commit

Permalink
Android Studio file structure
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed Mar 15, 2015
1 parent 11d6bbd commit 1ff3c1c
Show file tree
Hide file tree
Showing 190 changed files with 1,124 additions and 1,036 deletions.
93 changes: 93 additions & 0 deletions app/app.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="uHabits" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
<option name="GRADLE_PROJECT_PATH" value=":app" />
</configuration>
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-22.0.0" level="project" />
<orderEntry type="library" exported="" name="ActiveAndroid" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.0.0" level="project" />
</component>
</module>

24 changes: 24 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 22
buildToolsVersion "21.1.2"

defaultConfig {
applicationId "org.isoron.uhabits"
minSdkVersion 21
targetSdkVersion 22
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

dependencies {
compile 'com.android.support:support-v4:22.0.0'
compile files('libs/ActiveAndroid.jar')
}
File renamed without changes.
3 changes: 3 additions & 0 deletions app/lint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<lint>
</lint>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.android.colorpicker.ColorPickerSwatch.OnColorSelectedListener;

/**
* A dialog which takes in as input an array of colors and creates a palette allowing the user to
* A dialog which takes in as input an array of palette and creates a palette allowing the user to
* select a specific color swatch, which invokes a listener.
*/
public class ColorPickerDialog extends DialogFragment implements OnColorSelectedListener {
Expand All @@ -41,7 +41,7 @@ public class ColorPickerDialog extends DialogFragment implements OnColorSelected
protected AlertDialog mAlertDialog;

protected static final String KEY_TITLE_ID = "title_id";
protected static final String KEY_COLORS = "colors";
protected static final String KEY_COLORS = "palette";
protected static final String KEY_SELECTED_COLOR = "selected_color";
protected static final String KEY_COLUMNS = "columns";
protected static final String KEY_SIZE = "size";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void drawPalette(int[] colors, int selectedColor) {
int rowElements = 0;
int rowNumber = 0;

// Fills the table with swatches based on the array of colors.
// Fills the table with swatches based on the array of palette.
TableRow row = createTableRow();
for (int color : colors) {
tableElements++;
Expand Down Expand Up @@ -135,8 +135,8 @@ private static void addSwatchToRow(TableRow row, View swatch, int rowNumber) {
}

/**
* Add a content description to the specified swatch view. Because the colors get added in a
* snaking form, every other row will need to compensate for the fact that the colors are added
* Add a content description to the specified swatch view. Because the palette get added in a
* snaking form, every other row will need to compensate for the fact that the palette are added
* in an opposite direction from their left->right/top->bottom order, which is how the system
* will arrange them for accessibility purposes.
*/
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public void onClick(View v) {

// Set the theme at the end so that the initialize()s above don't counteract the theme.
mTimePicker.setTheme(getActivity().getApplicationContext(), mThemeDark);
// Prepare some colors to use.
// Prepare some palette to use.
int white = res.getColor(R.color.white);
int circleBackground = res.getColor(R.color.circle_background);
int line = res.getColor(R.color.line_background);
Expand All @@ -345,7 +345,7 @@ public void onClick(View v) {
ColorStateList darkDoneTextColor = res.getColorStateList(R.color.done_text_color_dark);
int darkDoneBackground = R.drawable.done_background_color_dark;

// Set the colors for each view based on the theme.
// Set the palette for each view based on the theme.
view.findViewById(R.id.time_display_background).setBackgroundColor(mThemeDark? darkGray : white);
view.findViewById(R.id.time_display).setBackgroundColor(mThemeDark? darkGray : white);
((TextView) view.findViewById(R.id.separator)).setTextColor(mThemeDark? white : timeDisplay);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package org.isoron.helpers;

import android.graphics.Color;

public class ColorHelper
{
public static int mixColors(int color1, int color2, float amount)
public static final int[] palette = { Color.parseColor("#900000"),
Color.parseColor("#c54100"), Color.parseColor("#c0ab00"),
Color.parseColor("#8db600"), Color.parseColor("#117209"),
Color.parseColor("#06965b"), Color.parseColor("#069a95"),
Color.parseColor("#114896"), Color.parseColor("#501394"),
Color.parseColor("#872086"), Color.parseColor("#c31764"),
Color.parseColor("#000000"), Color.parseColor("#aaaaaa") };

public static int mixColors(int color1, int color2, float amount)
{
final byte ALPHA_CHANNEL = 24;
final byte RED_CHANNEL = 16;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
185 changes: 185 additions & 0 deletions app/src/main/java/org/isoron/uhabits/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package org.isoron.uhabits;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import org.isoron.helpers.Command;
import org.isoron.uhabits.dialogs.ListHabitsFragment;
import org.isoron.uhabits.models.Habit;

import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;

public class MainActivity extends Activity
{
private static int MAX_UNDO_LEVEL = 15;
private ListHabitsFragment listHabitsFragment;
private LinkedList<Command> undoList;
private LinkedList<Command> redoList;

private Toast toast;

public static void createReminderAlarms(Context context)
{
for (Habit habit : Habit.getHabitsWithReminder())
createReminderAlarm(context, habit, null);
}

public static void createReminderAlarm(Context context, Habit habit, Long reminderTime)
{
Uri uri = Uri.parse("content://org.isoron.uhabits/habit/" + habit.getId());

if (reminderTime == null)
{
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, habit.reminder_hour);
calendar.set(Calendar.MINUTE, habit.reminder_min);
calendar.set(Calendar.SECOND, 0);

reminderTime = calendar.getTimeInMillis();

if (System.currentTimeMillis() > reminderTime)
{
reminderTime += AlarmManager.INTERVAL_DAY;
}
}

Intent alarmIntent = new Intent(context, ReminderAlarmReceiver.class);
alarmIntent.setAction(ReminderAlarmReceiver.ACTION_REMIND);
alarmIntent.setData(uri);

PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
((int) (habit.getId() % Integer.MAX_VALUE)) + 1,
alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);

AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (Build.VERSION.SDK_INT >= 19)
{
manager.setExact(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);
} else
{
manager.set(AlarmManager.RTC_WAKEUP, reminderTime, pendingIntent);
}

Log.d("Alarm", String.format("Setting alarm (%s): %s", DateFormat.getDateTimeInstance()
.format(new Date(reminderTime)), habit.name));
}

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

getActionBar().setElevation(5);

setContentView(R.layout.list_habits_activity);

listHabitsFragment = (ListHabitsFragment) getFragmentManager().findFragmentById(
R.id.fragment1);

Log.d("MainActivity", "Creating activity");

undoList = new LinkedList<>();
redoList = new LinkedList<>();

createReminderAlarms(MainActivity.this);
}

@Override
protected void onStart()
{
super.onStart();
listHabitsFragment.notifyDataSetChanged();
Log.d("MainActivity", "Starting activity");
}

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.main_activity, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
int id = item.getItemId();
if (id == R.id.action_settings)
{
return true;
}
return super.onOptionsItemSelected(item);
}

public void executeCommand(Command command, boolean datasetChanged)
{
executeCommand(command, datasetChanged, true);
}

public void executeCommand(Command command, boolean datasetChanged, boolean clearRedoStack)
{
undoList.push(command);
if (undoList.size() > MAX_UNDO_LEVEL)
undoList.removeLast();
if (clearRedoStack)
redoList.clear();
command.execute();

showToast(command.getExecuteStringId());
if (datasetChanged)
{
listHabitsFragment.notifyDataSetChanged();
}
}

public void undo()
{
if (undoList.isEmpty())
{
showToast(R.string.toast_nothing_to_undo);
return;
}

Command last = undoList.pop();
redoList.push(last);
last.undo();
showToast(last.getUndoStringId());

listHabitsFragment.notifyDataSetChanged();
}

public void redo()
{
if (redoList.isEmpty())
{
showToast(R.string.toast_nothing_to_redo);
return;
}
Command last = redoList.pop();
executeCommand(last, true, false);
}

private void showToast(Integer stringId)
{
if (stringId == null)
return;
if (toast == null)
toast = Toast.makeText(this, stringId, Toast.LENGTH_SHORT);
else
toast.setText(stringId);
toast.show();
}
}
Loading

0 comments on commit 1ff3c1c

Please sign in to comment.