Skip to content

Add new activity in sample app using Java #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 17 additions & 9 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
compileSdkVersion 30
defaultConfig {
applicationId "it.sephiroth.android.library.demo"
minSdkVersion 23
targetSdkVersion 28
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -20,17 +20,25 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
kotlinOptions {
jvmTarget = '1.6' // Java 7 not supported by kotlinOptions jvmTarget
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':library')

implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.1.0-alpha03'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'androidx.core:core-ktx:1.6.0-beta02'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.material:material:1.3.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="it.sephiroth.android.library.demo"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="it.sephiroth.android.library.demo">

<application
android:allowBackup="true"
Expand All @@ -9,6 +9,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity2"></activity>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package it.sephiroth.android.library.demo

import android.content.Intent
import android.os.Bundle
import android.widget.CheckBox
import androidx.appcompat.app.AppCompatActivity
Expand Down Expand Up @@ -27,6 +28,10 @@ class MainActivity : AppCompatActivity() {
listenToUpdates = true
}
}
buttonToJava.setOnClickListener{
val intent = Intent (this, MainActivity2::class.java)
startActivity(intent)
}

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package it.sephiroth.android.library.demo;


/**
* Thanks so much to om Yohanes
* for helped me to use this library
*/

import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import androidx.appcompat.app.AppCompatActivity;

import it.sephiroth.android.library.checkbox3state.CheckBox3;

public class MainActivity2 extends AppCompatActivity {

private CheckBox3 checkBox1;
private boolean listenToUpdates = true;
private CheckBox[] checkBoxesArray;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
checkBox1 = findViewById(R.id.checkBox1);
checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (listenToUpdates) {
listenToUpdates = false;
if (!isChecked) {
for (CheckBox it : checkBoxesArray) {
it.setChecked(false);
}
} else if (isChecked) {
for (CheckBox it : checkBoxesArray) {
it.setChecked(true);
}
}
checkBox1.setText(isChecked ? "Select None": "Select All");
checkBox1.setCycle(R.array.sephiroth_checkbox3_cycleCheckedUncheckedOnly);
listenToUpdates = true;
}
}
});
}

@Override
public void onContentChanged() {
super.onContentChanged();
checkBoxesArray = new CheckBox[] {findViewById(R.id.checkBox2), findViewById(R.id.checkBox3), findViewById(R.id.checkBox4)};

for (CheckBox it : checkBoxesArray) {
it.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

if (listenToUpdates) {
listenToUpdates = false;
int checkSize = 0;
for (CheckBox checkBox : checkBoxesArray) {
if (checkBox.isChecked()) {
checkSize++;
}
}

if (checkSize == checkBoxesArray.length) {
checkBox1.setCycle(R.array.sephiroth_checkbox3_cycleCheckedUncheckedOnly);
checkBox1.setChecked(true, false);
checkBox1.setText("Select None");
} else if (checkSize == 0) {
checkBox1.setCycle(R.array.sephiroth_checkbox3_cycleCheckedUncheckedOnly);
checkBox1.setChecked(false, false);
checkBox1.setText("Select All");
} else {
checkBox1.setCycle(R.array.sephiroth_checkbox3_cycleAll);
checkBox1.setChecked(false,true);
checkBox1.setText("Select All");
}
listenToUpdates = true;
}
}
});
}

}
}
9 changes: 9 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,13 @@
app:layout_constraintStart_toStartOf="@+id/checkBox3"
app:layout_constraintTop_toBottomOf="@+id/checkBox3" />

<androidx.appcompat.widget.AppCompatButton
android:id="@+id/buttonToJava"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="@id/checkBox1"
android:text="Sample in Java Code"
app:layout_constraintTop_toBottomOf="@id/checkBox4"
android:textColor="@android:color/black"/>

</androidx.constraintlayout.widget.ConstraintLayout>
66 changes: 66 additions & 0 deletions app/src/main/res/layout/activity_main2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity2">

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="Let's pretend this is a multi-selection option. Just select any of the checkbox preferences to see the behavior of the tri state checkbox below."
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<it.sephiroth.android.library.checkbox3state.CheckBox3
android:id="@+id/checkBox1"
style="@style/Sephiroth.Widget.Checkbox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:checked="false"
android:enabled="true"
android:text="Select All"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView1"
app:sephiroth_checkbox3_checkableCycle="@array/sephiroth_checkbox3_cycleCheckedUncheckedOnly"
app:sephiroth_checkbox3_indeterminate="false" />

<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:checked="false"
android:enabled="true"
android:text="Single Option 1"
app:layout_constraintStart_toStartOf="@+id/checkBox1"
app:layout_constraintTop_toBottomOf="@+id/checkBox1" />

<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Option 2"
app:layout_constraintStart_toStartOf="@+id/checkBox2"
app:layout_constraintTop_toBottomOf="@+id/checkBox2" />

<CheckBox
android:id="@+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Another Option"
app:layout_constraintStart_toStartOf="@+id/checkBox3"
app:layout_constraintTop_toBottomOf="@+id/checkBox3" />


</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.11'
ext.kotlin_version = '1.5.0'
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0-alpha10'
classpath 'com.android.tools.build:gradle:4.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1-milestone-1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-all.zip
3 changes: 3 additions & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ android {
includeAndroidResources = true
}
}
kotlinOptions {
jvmTarget = '1.6' // Java 7 not supported by kotlinOptions jvmTarget
}

}

Expand Down