From: Marius Gavrilescu Date: Thu, 13 Jun 2013 14:34:40 +0000 (+0300) Subject: Clean up X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=dfc674f65f8335d6e00490a1a5350dc31beea944;p=unical.git Clean up --- diff --git a/.pmd b/.pmd index 9794d09..6a82507 100644 --- a/.pmd +++ b/.pmd @@ -4,500 +4,472 @@ .ruleset - AvoidDecimalLiteralsInBigDecimalConstructor - Basic Rules + AbstractClassWithoutAbstractMethod + Design Rules - AvoidMultipleUnaryOperators - Basic Rules + AbstractClassWithoutAnyMethod + Design Rules - AvoidThreadGroup - Basic Rules + AbstractNaming + Naming Rules - AvoidUsingHardCodedIP - Basic Rules + AccessorClassGeneration + Design Rules - AvoidUsingOctalValues - Basic Rules + AddEmptyString + Optimization Rules - BigIntegerInstantiation - Basic Rules + AppendCharacterWithChar + String and StringBuffer Rules - BooleanInstantiation - Basic Rules + ArrayIsStoredDirectly + Security Code Guidelines - BrokenNullCheck - Basic Rules + AssignmentInOperand + Controversial Rules - CheckResultSet - Basic Rules + AssignmentToNonFinalStatic + Design Rules - ClassCastExceptionWithToArray - Basic Rules + AtLeastOneConstructor + Controversial Rules - CollapsibleIfStatements - Basic Rules + AvoidAccessibilityAlteration + Controversial Rules - DoubleCheckedLocking - Basic Rules + AvoidArrayLoops + Optimization Rules - EmptyCatchBlock - Basic Rules + AvoidAssertAsIdentifier + Migration Rules - EmptyFinallyBlock - Basic Rules + AvoidCallingFinalize + Finalizer Rules - EmptyIfStmt - Basic Rules + AvoidCatchingNPE + Strict Exception Rules - EmptyInitializer - Basic Rules + AvoidCatchingThrowable + Strict Exception Rules - EmptyStatementNotInLoop - Basic Rules + AvoidConstantsInterface + Design Rules - EmptyStaticInitializer + AvoidDecimalLiteralsInBigDecimalConstructor Basic Rules - EmptySwitchStatements - Basic Rules + AvoidDeeplyNestedIfStmts + Design Rules - EmptySynchronizedBlock - Basic Rules + AvoidDollarSigns + Naming Rules - EmptyTryBlock - Basic Rules + AvoidDuplicateLiterals + String and StringBuffer Rules - EmptyWhileStmt - Basic Rules + AvoidEnumAsIdentifier + Migration Rules - ForLoopShouldBeWhileLoop - Basic Rules + AvoidFieldNameMatchingMethodName + Naming Rules - JumbledIncrementer - Basic Rules + AvoidFieldNameMatchingTypeName + Naming Rules - MisplacedNullCheck - Basic Rules + AvoidFinalLocalVariable + Controversial Rules - OverrideBothEqualsAndHashcode - Basic Rules + AvoidInstanceofChecksInCatchClause + Design Rules - ReturnFromFinallyBlock + AvoidMultipleUnaryOperators Basic Rules - UnconditionalIfStatement - Basic Rules + AvoidPrintStackTrace + Java Logging Rules - UnnecessaryConversionTemporary - Basic Rules + AvoidProtectedFieldInFinalClass + Design Rules - UnnecessaryFinalModifier - Basic Rules + AvoidReassigningParameters + Design Rules - UnnecessaryReturn - Basic Rules + AvoidRethrowingException + Strict Exception Rules - UnusedNullCheckInEquals - Basic Rules + AvoidStringBufferField + String and StringBuffer Rules - UselessOperationOnImmutable - Basic Rules + AvoidSynchronizedAtMethodLevel + Design Rules - UselessOverridingMethod + AvoidThreadGroup Basic Rules - CloneThrowsCloneNotSupportedException - Clone Implementation Rules - - - ProperCloneImplementation - Clone Implementation Rules - - - CyclomaticComplexity - Code Size Rules - - - ExcessiveClassLength - Code Size Rules - - - ExcessiveMethodLength - Code Size Rules - - - ExcessiveParameterList - Code Size Rules - - - ExcessivePublicCount - Code Size Rules - - - NcssConstructorCount - Code Size Rules + AvoidThrowingNewInstanceOfSameException + Strict Exception Rules - NcssMethodCount - Code Size Rules + AvoidThrowingNullPointerException + Strict Exception Rules - NcssTypeCount - Code Size Rules + AvoidThrowingRawExceptionTypes + Strict Exception Rules - TooManyFields - Code Size Rules + AvoidUsingHardCodedIP + Basic Rules - TooManyMethods - Code Size Rules + AvoidUsingNativeCode + Controversial Rules - AssignmentInOperand - Controversial Rules + AvoidUsingOctalValues + Basic Rules - AtLeastOneConstructor + AvoidUsingShortType Controversial Rules - AvoidAccessibilityAlteration + AvoidUsingVolatile Controversial Rules - AvoidFinalLocalVariable - Controversial Rules + BadComparison + Design Rules - AvoidUsingNativeCode - Controversial Rules + BigIntegerInstantiation + Basic Rules - AvoidUsingShortType - Controversial Rules + BooleanGetMethodName + Naming Rules - AvoidUsingVolatile - Controversial Rules + BooleanInstantiation + Basic Rules BooleanInversion Controversial Rules - CallSuperInConstructor - Controversial Rules + BrokenNullCheck + Basic Rules - DefaultPackage - Controversial Rules + ByteInstantiation + Migration Rules - DoNotCallGarbageCollectionExplicitly + CallSuperInConstructor Controversial Rules - DontImportSun - Controversial Rules + CheckResultSet + Basic Rules - NullAssignment - Controversial Rules + ClassCastExceptionWithToArray + Basic Rules - SuspiciousOctalEscape - Controversial Rules + ClassNamingConventions + Naming Rules - UnnecessaryConstructor - Controversial Rules + ClassWithOnlyPrivateConstructorsShouldBeFinal + Design Rules - UnnecessaryParentheses - Controversial Rules + CloneMethodMustImplementCloneable + Type Resolution Rules - UnusedModifier - Controversial Rules + CloneThrowsCloneNotSupportedException + Clone Implementation Rules - CouplingBetweenObjects - Coupling Rules + CloseResource + Design Rules - ExcessiveImports - Coupling Rules + CollapsibleIfStatements + Basic Rules - AbstractClassWithoutAbstractMethod + CompareObjectsWithEquals Design Rules - AbstractClassWithoutAnyMethod + ConfusingTernary Design Rules - AccessorClassGeneration - Design Rules + ConsecutiveLiteralAppends + String and StringBuffer Rules - AssignmentToNonFinalStatic + ConstructorCallsOverridableMethod Design Rules - AvoidConstantsInterface - Design Rules + CouplingBetweenObjects + Coupling Rules - AvoidDeeplyNestedIfStmts + DefaultLabelNotLastInSwitchStmt Design Rules - AvoidInstanceofChecksInCatchClause - Design Rules + DefaultPackage + Controversial Rules - AvoidProtectedFieldInFinalClass - Design Rules + DoNotCallGarbageCollectionExplicitly + Controversial Rules - AvoidReassigningParameters - Design Rules + DoNotCallSystemExit + J2EE Rules - AvoidSynchronizedAtMethodLevel - Design Rules + DoNotExtendJavaLangError + Strict Exception Rules - BadComparison - Design Rules + DoNotThrowExceptionInFinally + Strict Exception Rules - ClassWithOnlyPrivateConstructorsShouldBeFinal - Design Rules + DoNotUseThreads + J2EE Rules - CloseResource - Design Rules + DontImportJavaLang + Import Statement Rules - CompareObjectsWithEquals - Design Rules + DontImportSun + Controversial Rules - ConfusingTernary - Design Rules + DoubleCheckedLocking + Basic Rules - ConstructorCallsOverridableMethod - Design Rules + DuplicateImports + Import Statement Rules - DefaultLabelNotLastInSwitchStmt - Design Rules + EmptyCatchBlock + Basic Rules - EmptyMethodInAbstractClassShouldBeAbstract - Design Rules + EmptyFinalizer + Finalizer Rules - EqualsNull - Design Rules + EmptyFinallyBlock + Basic Rules - FinalFieldCouldBeStatic - Design Rules + EmptyIfStmt + Basic Rules - IdempotentOperations - Design Rules + EmptyInitializer + Basic Rules - ImmutableField + EmptyMethodInAbstractClassShouldBeAbstract Design Rules - InstantiationToGetClass - Design Rules + EmptyStatementNotInLoop + Basic Rules - MissingBreakInSwitch - Design Rules + EmptyStaticInitializer + Basic Rules - MissingStaticMethodInNonInstantiatableClass - Design Rules + EmptySwitchStatements + Basic Rules - NonCaseLabelInSwitchStatement - Design Rules + EmptySynchronizedBlock + Basic Rules - NonStaticInitializer - Design Rules + EmptyTryBlock + Basic Rules - NonThreadSafeSingleton - Design Rules + EmptyWhileStmt + Basic Rules - OptimizableToArrayCall + EqualsNull Design Rules - PositionLiteralsFirstInComparisons - Design Rules + ExceptionAsFlowControl + Strict Exception Rules - PreserveStackTrace - Design Rules + ExcessiveClassLength + Code Size Rules - ReturnEmptyArrayRatherThanNull - Design Rules + ExcessiveImports + Coupling Rules - SimpleDateFormatNeedsLocale - Design Rules + ExcessiveMethodLength + Code Size Rules - SimplifyBooleanExpressions - Design Rules + ExcessiveParameterList + Code Size Rules - SimplifyBooleanReturns - Design Rules + ExcessivePublicCount + Code Size Rules - SimplifyConditional + FinalFieldCouldBeStatic Design Rules - SingularField - Design Rules + FinalizeDoesNotCallSuperFinalize + Finalizer Rules - SwitchDensity - Design Rules + FinalizeOnlyCallsSuperFinalize + Finalizer Rules - SwitchStmtsShouldHaveDefault - Design Rules + FinalizeOverloaded + Finalizer Rules - UncommentedEmptyConstructor - Design Rules + FinalizeShouldBeProtected + Finalizer Rules - UncommentedEmptyMethod - Design Rules + ForLoopShouldBeWhileLoop + Basic Rules - UnnecessaryLocalBeforeReturn + IdempotentOperations Design Rules - UnsynchronizedStaticDateFormatter + ImmutableField Design Rules - UseCollectionIsEmpty - Design Rules + ImportFromSamePackage + Import Statement Rules - UseLocaleWithCaseConversions - Design Rules + InefficientEmptyStringCheck + String and StringBuffer Rules - UseNotifyAllInsteadOfNotify - Design Rules + InefficientStringBuffering + String and StringBuffer Rules - UseSingleton + InstantiationToGetClass Design Rules - AvoidCallingFinalize - Finalizer Rules + InsufficientStringBufferDeclaration + String and StringBuffer Rules - EmptyFinalizer - Finalizer Rules + IntegerInstantiation + Migration Rules - FinalizeDoesNotCallSuperFinalize - Finalizer Rules + JumbledIncrementer + Basic Rules - FinalizeOnlyCallsSuperFinalize - Finalizer Rules + JUnit4SuitesShouldUseSuiteAnnotation + Migration Rules - FinalizeOverloaded - Finalizer Rules + JUnit4TestShouldUseAfterAnnotation + Migration Rules - FinalizeShouldBeProtected - Finalizer Rules + JUnit4TestShouldUseBeforeAnnotation + Migration Rules - DontImportJavaLang - Import Statement Rules + JUnit4TestShouldUseTestAnnotation + Migration Rules - DuplicateImports - Import Statement Rules + JUnitAssertionsShouldIncludeMessage + JUnit Rules - ImportFromSamePackage - Import Statement Rules + JUnitSpelling + JUnit Rules - TooManyStaticImports - Import Statement Rules + JUnitStaticSuite + JUnit Rules - DoNotCallSystemExit - J2EE Rules + JUnitTestsShouldIncludeAssert + JUnit Rules - DoNotUseThreads - J2EE Rules + JUnitUseExpected + Migration Rules LocalHomeNamingConvention @@ -508,132 +480,132 @@ J2EE Rules - MDBAndSessionBeanNamingConvention - J2EE Rules + LocalVariableCouldBeFinal + Optimization Rules - RemoteInterfaceNamingConvention - J2EE Rules + LoggerIsNotStaticFinal + Java Logging Rules - RemoteSessionInterfaceNamingConvention - J2EE Rules + LongInstantiation + Migration Rules - StaticEJBFieldShouldBeFinal - J2EE Rules + LooseCoupling + Type Resolution Rules - UseProperClassLoader + MDBAndSessionBeanNamingConvention J2EE Rules - ProperLogger - Jakarta Commons Logging Rules + MethodArgumentCouldBeFinal + Optimization Rules - UseCorrectExceptionLogging - Jakarta Commons Logging Rules + MethodNamingConventions + Naming Rules - AvoidPrintStackTrace - Java Logging Rules + MethodReturnsInternalArray + Security Code Guidelines - LoggerIsNotStaticFinal - Java Logging Rules + MethodWithSameNameAsEnclosingClass + Naming Rules - MoreThanOneLogger - Java Logging Rules + MisleadingVariableName + Naming Rules - SystemPrintln - Java Logging Rules + MisplacedNullCheck + Basic Rules - MissingSerialVersionUID - JavaBean Rules + MissingBreakInSwitch + Design Rules - JUnitAssertionsShouldIncludeMessage - JUnit Rules + MissingSerialVersionUID + JavaBean Rules - JUnitSpelling - JUnit Rules + MissingStaticMethodInNonInstantiatableClass + Design Rules - JUnitStaticSuite - JUnit Rules + MoreThanOneLogger + Java Logging Rules - JUnitTestsShouldIncludeAssert - JUnit Rules + NcssConstructorCount + Code Size Rules - SimplifyBooleanAssertion - JUnit Rules + NcssMethodCount + Code Size Rules - TestClassWithoutTestCases - JUnit Rules + NcssTypeCount + Code Size Rules - UnnecessaryBooleanAssertion - JUnit Rules + NonCaseLabelInSwitchStatement + Design Rules - UseAssertEqualsInsteadOfAssertTrue - JUnit Rules + NonStaticInitializer + Design Rules - UseAssertNullInsteadOfAssertTrue - JUnit Rules + NonThreadSafeSingleton + Design Rules - UseAssertSameInsteadOfAssertTrue - JUnit Rules + NoPackage + Naming Rules - AvoidAssertAsIdentifier - Migration Rules + NullAssignment + Controversial Rules - AvoidEnumAsIdentifier - Migration Rules + OptimizableToArrayCall + Design Rules - ByteInstantiation - Migration Rules + OverrideBothEqualsAndHashcode + Basic Rules - IntegerInstantiation - Migration Rules + PackageCase + Naming Rules - JUnit4SuitesShouldUseSuiteAnnotation - Migration Rules + PositionLiteralsFirstInComparisons + Design Rules - JUnit4TestShouldUseAfterAnnotation - Migration Rules + PreserveStackTrace + Design Rules - JUnit4TestShouldUseBeforeAnnotation - Migration Rules + ProperCloneImplementation + Clone Implementation Rules - JUnit4TestShouldUseTestAnnotation - Migration Rules + ProperLogger + Jakarta Commons Logging Rules - JUnitUseExpected - Migration Rules + RemoteInterfaceNamingConvention + J2EE Rules - LongInstantiation - Migration Rules + RemoteSessionInterfaceNamingConvention + J2EE Rules ReplaceEnumerationWithIterator @@ -647,57 +619,69 @@ ReplaceVectorWithList Migration Rules + + ReturnEmptyArrayRatherThanNull + Design Rules + + + ReturnFromFinallyBlock + Basic Rules + ShortInstantiation Migration Rules - AbstractNaming + ShortMethodName Naming Rules - AvoidDollarSigns - Naming Rules + SignatureDeclareThrowsException + Type Resolution Rules - AvoidFieldNameMatchingMethodName - Naming Rules + SimpleDateFormatNeedsLocale + Design Rules - AvoidFieldNameMatchingTypeName - Naming Rules + SimplifyBooleanAssertion + JUnit Rules - BooleanGetMethodName - Naming Rules + SimplifyBooleanExpressions + Design Rules - ClassNamingConventions - Naming Rules + SimplifyBooleanReturns + Design Rules - MethodNamingConventions - Naming Rules + SimplifyConditional + Design Rules - MethodWithSameNameAsEnclosingClass - Naming Rules + SimplifyStartsWith + Optimization Rules - MisleadingVariableName - Naming Rules + SingularField + Design Rules - NoPackage - Naming Rules + StaticEJBFieldShouldBeFinal + J2EE Rules - PackageCase - Naming Rules + StringBufferInstantiationWithChar + String and StringBuffer Rules - ShortMethodName - Naming Rules + StringInstantiation + String and StringBuffer Rules + + + StringToString + String and StringBuffer Rules SuspiciousConstantFieldName @@ -712,132 +696,144 @@ Naming Rules - VariableNamingConventions - Naming Rules + SuspiciousOctalEscape + Controversial Rules - AddEmptyString - Optimization Rules + SwitchDensity + Design Rules - AvoidArrayLoops - Optimization Rules + SwitchStmtsShouldHaveDefault + Design Rules - LocalVariableCouldBeFinal - Optimization Rules + SystemPrintln + Java Logging Rules - MethodArgumentCouldBeFinal - Optimization Rules + TestClassWithoutTestCases + JUnit Rules - SimplifyStartsWith - Optimization Rules + TooManyFields + Code Size Rules - UnnecessaryWrapperObjectCreation - Optimization Rules + TooManyMethods + Code Size Rules - UseArrayListInsteadOfVector - Optimization Rules + TooManyStaticImports + Import Statement Rules - UseArraysAsList - Optimization Rules + UncommentedEmptyConstructor + Design Rules - UseStringBufferForStringAppends - Optimization Rules + UncommentedEmptyMethod + Design Rules - ArrayIsStoredDirectly - Security Code Guidelines + UnconditionalIfStatement + Basic Rules - MethodReturnsInternalArray - Security Code Guidelines + UnnecessaryBooleanAssertion + JUnit Rules - AvoidCatchingNPE - Strict Exception Rules + UnnecessaryCaseChange + String and StringBuffer Rules - AvoidCatchingThrowable - Strict Exception Rules + UnnecessaryConstructor + Controversial Rules - AvoidRethrowingException - Strict Exception Rules + UnnecessaryConversionTemporary + Basic Rules - AvoidThrowingNewInstanceOfSameException - Strict Exception Rules + UnnecessaryFinalModifier + Basic Rules - AvoidThrowingNullPointerException - Strict Exception Rules + UnnecessaryLocalBeforeReturn + Design Rules - AvoidThrowingRawExceptionTypes - Strict Exception Rules + UnnecessaryParentheses + Controversial Rules - DoNotExtendJavaLangError - Strict Exception Rules + UnnecessaryReturn + Basic Rules - DoNotThrowExceptionInFinally - Strict Exception Rules + UnnecessaryWrapperObjectCreation + Optimization Rules - ExceptionAsFlowControl - Strict Exception Rules + UnsynchronizedStaticDateFormatter + Design Rules - AppendCharacterWithChar - String and StringBuffer Rules + UnusedFormalParameter + Unused Code Rules - AvoidDuplicateLiterals - String and StringBuffer Rules + UnusedImports + Type Resolution Rules - AvoidStringBufferField - String and StringBuffer Rules + UnusedLocalVariable + Unused Code Rules - ConsecutiveLiteralAppends - String and StringBuffer Rules + UnusedModifier + Controversial Rules - InefficientEmptyStringCheck - String and StringBuffer Rules + UnusedNullCheckInEquals + Basic Rules - InefficientStringBuffering - String and StringBuffer Rules + UnusedPrivateField + Unused Code Rules - InsufficientStringBufferDeclaration - String and StringBuffer Rules + UnusedPrivateMethod + Unused Code Rules - StringBufferInstantiationWithChar - String and StringBuffer Rules + UseArrayListInsteadOfVector + Optimization Rules - StringInstantiation - String and StringBuffer Rules + UseArraysAsList + Optimization Rules - StringToString - String and StringBuffer Rules + UseAssertEqualsInsteadOfAssertTrue + JUnit Rules - UnnecessaryCaseChange - String and StringBuffer Rules + UseAssertNullInsteadOfAssertTrue + JUnit Rules + + + UseAssertSameInsteadOfAssertTrue + JUnit Rules + + + UseCollectionIsEmpty + Design Rules + + + UseCorrectExceptionLogging + Jakarta Commons Logging Rules UseEqualsToCompareStrings @@ -848,44 +844,44 @@ String and StringBuffer Rules - UselessStringValueOf - String and StringBuffer Rules + UselessOperationOnImmutable + Basic Rules - UseStringBufferLength - String and StringBuffer Rules + UselessOverridingMethod + Basic Rules - CloneMethodMustImplementCloneable - Type Resolution Rules + UselessStringValueOf + String and StringBuffer Rules - LooseCoupling - Type Resolution Rules + UseLocaleWithCaseConversions + Design Rules - SignatureDeclareThrowsException - Type Resolution Rules + UseNotifyAllInsteadOfNotify + Design Rules - UnusedImports - Type Resolution Rules + UseProperClassLoader + J2EE Rules - UnusedFormalParameter - Unused Code Rules + UseSingleton + Design Rules - UnusedLocalVariable - Unused Code Rules + UseStringBufferForStringAppends + Optimization Rules - UnusedPrivateField - Unused Code Rules + UseStringBufferLength + String and StringBuffer Rules - UnusedPrivateMethod - Unused Code Rules + VariableNamingConventions + Naming Rules false diff --git a/src/ro/ieval/unical/AddEventActivity.java b/src/ro/ieval/unical/AddEventActivity.java index 17c86d4..9219640 100644 --- a/src/ro/ieval/unical/AddEventActivity.java +++ b/src/ro/ieval/unical/AddEventActivity.java @@ -90,9 +90,9 @@ public final class AddEventActivity extends Activity implements OnDateSetListene @Override public void onDateSet(final DatePicker picker, final int year, final int monthOfYear, final int dayOfMonth) { final Calendar calendar=new GregorianCalendar(year, monthOfYear, dayOfMonth); - dateTimeTextView.setText(String.format("%4d-%02d-%02d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); + dateTimeTextView.setText(Utils.formatDate(year, monthOfYear, dayOfMonth)); calendar.add(Calendar.DAY_OF_MONTH, 1); if(dateTimeTextView.getId() == R.id.date_start) - ((TextView)findViewById(R.id.date_end)).setText(String.format("%4d-%2d-%2d", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); + ((TextView)findViewById(R.id.date_end)).setText(Utils.formatDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH))); } } diff --git a/src/ro/ieval/unical/TrivialFragment.java b/src/ro/ieval/unical/TrivialFragment.java index 55e5da1..23086ab 100644 --- a/src/ro/ieval/unical/TrivialFragment.java +++ b/src/ro/ieval/unical/TrivialFragment.java @@ -2,68 +2,74 @@ package ro.ieval.unical; import android.app.Fragment; import android.os.Bundle; -import android.text.InputType; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import android.widget.AdapterView.OnItemSelectedListener; import android.widget.CompoundButton; -import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Spinner; import android.widget.Switch; -import android.widget.CompoundButton.OnCheckedChangeListener; public final class TrivialFragment extends Fragment { + private static class OnItemSelectedListener implements android.widget.AdapterView.OnItemSelectedListener{ + final View repeatCount; + public OnItemSelectedListener(final View repeatCount) { + this.repeatCount=repeatCount; + } + + @Override + public void onItemSelected(final AdapterView whatever, final View ignored, final int pos, final long id) { + switch(pos){ + case 0: + repeatCount.setVisibility(View.GONE); + break; + case 1: + repeatCount.setVisibility(View.GONE); + break; + case 2: + repeatCount.setVisibility(View.VISIBLE); + break; + default: + } + } + + @Override public void onNothingSelected(final AdapterView arg0) { /* do nothing */ } + } + + private static class OnCheckedChangeListener implements android.widget.CompoundButton.OnCheckedChangeListener{ + private final LinearLayout layout; + private final View root; + public OnCheckedChangeListener(final LinearLayout layout, final View root){ + this.layout=layout; + this.root=root; + } + + @Override + public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { + if(isChecked) { + Utils.setEnabledRecursively(layout, true); + final Spinner repeatType = (Spinner) root.findViewById(R.id.repeat_type); + repeatType.setOnItemSelectedListener(new OnItemSelectedListener(root.findViewById(R.id.repeat_count))); + }else { + Utils.setEnabledRecursively(layout, false); + } + } + } + public static final String ARGUMENT_LAYOUT="layout"; @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final View view=inflater.inflate(getArguments().getInt(ARGUMENT_LAYOUT), container, false); - final LinearLayout ll = (LinearLayout) view.findViewById(R.id.repeat_layout); + final LinearLayout layout = (LinearLayout) view.findViewById(R.id.repeat_layout); - if(ll != null){ + if(layout != null){ final Switch repeatSwitch = (Switch) view.findViewById(R.id.repeat_switch); - Utils.setEnabledRecursively(ll, false); + Utils.setEnabledRecursively(layout, false); - repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener() { - @Override - public void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked) { - if(isChecked) { - Utils.setEnabledRecursively(ll, true); - Spinner repeatType = (Spinner) view.findViewById(R.id.repeat_type); - final EditText repeatCount = (EditText) view.findViewById(R.id.repeat_count); - - repeatType.setOnItemSelectedListener(new OnItemSelectedListener() { - - @Override - public void onItemSelected(AdapterView arg0, - View arg1, int arg2, long arg3) { - if(arg2==1) { - //TODO adauga un date picker - //TODO sterge repeatCount - repeatCount.setVisibility(EditText.GONE); - }else if(arg2==2) { - repeatCount.setVisibility(EditText.VISIBLE); - }else { - //TODO sterge repeatCount - repeatCount.setVisibility(EditText.GONE); - } - - } - - @Override - public void onNothingSelected(AdapterView arg0) { - - } - }); - }else { - Utils.setEnabledRecursively(ll, false); - } - } - }); + repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout, view)); } return view; } diff --git a/src/ro/ieval/unical/Utils.java b/src/ro/ieval/unical/Utils.java index 74fa1a2..703c8dd 100644 --- a/src/ro/ieval/unical/Utils.java +++ b/src/ro/ieval/unical/Utils.java @@ -1,9 +1,13 @@ package ro.ieval.unical; +import java.util.Locale; + import android.view.View; import android.view.ViewGroup; final class Utils { + private Utils(){ /* do nothing */ } + public static void setEnabledRecursively(final View view, final boolean enabled){ view.setEnabled(enabled); if(view instanceof ViewGroup){ @@ -12,4 +16,8 @@ final class Utils { setEnabledRecursively(group.getChildAt(i), enabled); } } + + public static String formatDate(final int year, final int month, final int day){ + return String.format(Locale.ENGLISH, "%4d-%02d-%02d", year, month, day); + } }