Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Commit

Permalink
## breaking changes:
Browse files Browse the repository at this point in the history
remove KillerManager.init();
throw Exception from doAction() methods
Empty Dialog Builder removed, Context is obligatory
show() method throws Exceptions

Enhancement:
* check is the device supported or not
* DialogBuilder onUnSpportedDevice handler.
* DialogBuilder onNoActionAvailable
* Ability to customize Dialog Builder, or material dialog
  • Loading branch information
tabebqena committed Feb 17, 2020
1 parent 1142cc5 commit b4dcfb1
Show file tree
Hide file tree
Showing 7 changed files with 330 additions and 97 deletions.
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
compileSdkVersion 28
defaultConfig {
applicationId "com.thelittlefireman.appkillermanager_exemple"
minSdkVersion 15
targetSdkVersion 27
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -21,7 +22,7 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class InstructionsActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
KillerManager.init(this);
setContentView(R.layout.activity_instructions);
ButterKnife.bind(this);

Expand All @@ -60,7 +59,7 @@ public void onStart() {
public void onSuccess(@NonNull ResponseWrapper responseWrapper) {
Instructions instructions = new Instructions(responseWrapper);
if ( ! instructions.isHasException()){
//LogUtils.i(TAG,instructions.getName() + instructions.getUser_solution());
LogUtils.i(TAG,instructions.getName() + instructions.getUser_solution());
//Do your stuff here
}
}
Expand Down Expand Up @@ -109,7 +108,14 @@ public void onClick(View v) {

public void startDialog(KillerManager.Actions actions) {

new DialogKillerManagerBuilder().setContext(this).setAction(actions).show();
try {
new DialogKillerManagerBuilder(this)
.setAction(actions).show();
} catch (DialogKillerManagerBuilder.UnAvailableActionException e) {
e.printStackTrace();
} catch (DialogKillerManagerBuilder.UnSupportedDeviceException e) {
e.printStackTrace();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.AppCompatCheckBox;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.thelittlefireman.appkillermanager.managers.KillerManager;
import com.thelittlefireman.appkillermanager.ui.DialogKillerManagerBuilder;
import com.thelittlefireman.appkillermanager.utils.LogUtils;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends Activity {
@BindView(R.id.device_name)
TextView deviceName;
@BindView(R.id.is_device_supported)
TextView isDeviceSupported;
@BindView(R.id.powerSavingManagerButton)
Button powerSavingManagerButton;
@BindView(R.id.autoStartManagerButton)
Expand All @@ -27,39 +38,55 @@ public class MainActivity extends Activity {
@BindView(R.id.goToInstructonsActivityButton)
Button goToInstructonsActivityButton;

KillerManager.Actions currentAction = null;

@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
KillerManager.init(this);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
powerSavingManagerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentAction = KillerManager.Actions.ACTION_POWERSAVING;
if (mAppCompatCheckBoxByDialog.isChecked()) {
startDialog(KillerManager.Actions.ACTION_POWERSAVING);
startDialog(currentAction);
} else {
KillerManager.doActionPowerSaving(MainActivity.this);
try {
KillerManager.doActionPowerSaving(MainActivity.this);
} catch (KillerManager.NoActionFoundException e) {
e.printStackTrace();
}
}
}
});
autoStartManagerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentAction = KillerManager.Actions.ACTION_AUTOSTART;
if (mAppCompatCheckBoxByDialog.isChecked()) {
startDialog(KillerManager.Actions.ACTION_AUTOSTART);
startDialog(currentAction);
} else {
KillerManager.doActionAutoStart(MainActivity.this);
try {
KillerManager.doActionAutoStart(MainActivity.this);
} catch (KillerManager.NoActionFoundException e) {
e.printStackTrace();
}
}
}
});
notificationManagerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
currentAction = KillerManager.Actions.ACTION_NOTIFICATIONS;
if (mAppCompatCheckBoxByDialog.isChecked()) {
startDialog(KillerManager.Actions.ACTION_NOTIFICATIONS);
startDialog(currentAction);
} else {
KillerManager.doActionNotification(MainActivity.this);
try {
KillerManager.doActionNotification(MainActivity.this);
} catch (KillerManager.NoActionFoundException e) {
e.printStackTrace();
}
}
}
});
Expand All @@ -72,11 +99,40 @@ public void onClick(View v) {
self.startActivity(intent);
}
});

deviceName.setText( "Device name: " .concat(KillerManager.getDevice().getDeviceManufacturer().toString()) );
isDeviceSupported.setText( "Is supported: ".concat(String.valueOf( KillerManager.isDeviceSupported()) ) );

}

public void startDialog(KillerManager.Actions actions) {

new DialogKillerManagerBuilder().setContext(this).setAction(actions).show();
try {
new DialogKillerManagerBuilder(this).setAction(actions).show();

} catch (DialogKillerManagerBuilder.UnAvailableActionException e) {
e.printStackTrace();
} catch (DialogKillerManagerBuilder.UnSupportedDeviceException e) {
e.printStackTrace();
}

}

@Override
public void onResume() {

super.onResume();
if (currentAction == KillerManager.Actions.ACTION_AUTOSTART){
// may show dalog to ask the user about the result of action
// and store the result in preference
}else if (currentAction == KillerManager.Actions.ACTION_NOTIFICATIONS){

}else if (currentAction == KillerManager.Actions.ACTION_POWERSAVING){

}
// dont forget to nullify current action
currentAction = null;
}


}
39 changes: 27 additions & 12 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,54 @@
android:layout_height="match_parent"
tools:context=".MainActivity">


<TextView
android:id="@+id/device_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:gravity="center"
android:layout_margin="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.117"
tools:layout_editor_absoluteX="0dp" />

<TextView
android:id="@+id/is_device_supported"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_margin="10dp"
app:layout_constraintTop_toBottomOf="@id/device_name"
android:gravity="center"
app:layout_constraintVertical_bias="0.07"
tools:layout_editor_absoluteX="0dp" />

<Button
android:id="@+id/powerSavingManagerButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="68dp"
android:layout_marginBottom="8dp"
android:text="PowerSaving Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintTop_toBottomOf="@id/is_device_supported"
tools:layout_editor_absoluteX="0dp" />

<Button
android:id="@+id/autoStartManagerButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:layout_marginBottom="8dp"
android:text="AutoStart Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintTop_toBottomOf="@id/powerSavingManagerButton"
tools:layout_editor_absoluteX="0dp" />

<Button
android:id="@+id/notificationManagerButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="300dp"
android:layout_marginBottom="8dp"
android:text="Notification Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/autoStartManagerButton"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="0dp" />

Expand Down
9 changes: 5 additions & 4 deletions appkillermanager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ apply plugin: 'com.android.library'
apply plugin: "com.github.ben-manes.versions"

android {
compileSdkVersion 27
compileSdkVersion 28

defaultConfig {
minSdkVersion 15
targetSdkVersion 27
targetSdkVersion 28
versionCode rootProject.ext.libVersionCode
versionName rootProject.ext.libVersionName

Expand All @@ -32,8 +32,9 @@ dependencies {
implementation 'com.android.support:support-annotations:27.1.1'

// UI
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'

implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'

Expand Down
Loading

0 comments on commit b4dcfb1

Please sign in to comment.