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

Commit

Permalink
v0.0.1; add button for stopping service; add bug fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Jerry Chen <jerryc05@qq.com>
  • Loading branch information
Jerry Chen committed Jul 14, 2019
1 parent 11767b3 commit 304f0cd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 22 deletions.
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLE_REQUESTED" />
<action android:name="android.app.action.DEVICE_ADMIN_DISABLED" />
<action android:name="android.app.action.ACTION_PASSWORD_FAILED"/>
<action android:name="android.app.action.ACTION_PASSWORD_SUCCEEDED"/>
</intent-filter>
</receiver>
</application>
Expand Down
27 changes: 18 additions & 9 deletions app/src/main/java/jerryc05/unlockme/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import jerryc05.unlockme.helpers.URLConnectionBuilder;
import jerryc05.unlockme.helpers.UserInterface;
import jerryc05.unlockme.helpers.camera.CameraBaseAPIClass;
import jerryc05.unlockme.services.ForegroundIntentService;

import static jerryc05.unlockme.helpers.camera.CameraBaseAPIClass.SP_KEY_PREFER_CAMERA_API_2;

Expand All @@ -49,9 +50,11 @@ protected void onCreate(Bundle savedInstanceState) {

applicationContext = getApplicationContext();
findViewById(R.id.activity_main_button_front)
.setOnClickListener(MainActivity.this);
.setOnClickListener(this);
findViewById(R.id.activity_main_button_back)
.setOnClickListener(MainActivity.this);
.setOnClickListener(this);
findViewById(R.id.activity_main_button_stopService)
.setOnClickListener(this);

final CheckBox forceAPI1 =
findViewById(R.id.activity_main_api1CheckBox);
Expand Down Expand Up @@ -113,13 +116,19 @@ public void onRequestPermissionsResult(int requestCode,

@Override
public void onClick(View view) {
threadPoolExecutor.execute(new Runnable() {
@Override
public void run() {
CameraBaseAPIClass.getImageFromDefaultCamera(MainActivity.this,
view.getId() == R.id.activity_main_button_front);
}
});
final int id = view.getId();

if (id == R.id.activity_main_button_stopService)
stopService(new Intent(
this, ForegroundIntentService.class));
else
threadPoolExecutor.execute(new Runnable() {
@Override
public void run() {
CameraBaseAPIClass.getImageFromDefaultCamera(MainActivity.this,
view.getId() == R.id.activity_main_button_front);
}
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public class MyDeviceAdminReceiver extends DeviceAdminReceiver {

@Override
public void onPasswordFailed(Context context, Intent intent, UserHandle user) {
super.onPasswordFailed(context, intent, user);

super.onPasswordFailed(context, intent);
if (BuildConfig.DEBUG)
Log.d(TAG, "onPasswordFailed: ");

Expand All @@ -31,14 +30,6 @@ public void onPasswordFailed(Context context, Intent intent, UserHandle user) {
context.startService(mIntent);
else
context.startForegroundService(mIntent);

// MainActivity.threadPoolExecutor.execute(new Runnable() {
// @Override
// public void run() {
// final MainActivity activity = MainActivity.weakMainActivity.get();
// CameraBaseAPIClass.getImageFromDefaultCamera(activity, true);
// }
// });
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void onCreate() {
final String title = "Background Service";
final Notification.Builder builder =
new Notification.Builder(this)
.setContentTitle("UnlockMe " + title)
.setContentTitle(title)
.setSmallIcon(
R.drawable.ic_launcher_smartphone_lock_foreground);
startForeground(-1, UserInterface.setNotificationChannel(builder,
Expand Down
12 changes: 10 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Take Photo on front camera!" />
android:text="Take Photo on Front Camera!" />

<Button
android:id="@+id/activity_main_button_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/activity_main_button_front"
android:layout_centerHorizontal="true"
android:text="Take Photo on back camera!" />
android:text="Take Photo on Back Camera!" />

<CheckBox
android:id="@+id/activity_main_api1CheckBox"
Expand All @@ -27,4 +27,12 @@
android:layout_below="@+id/activity_main_button_back"
android:layout_centerHorizontal="true"
android:text="Force Camera1 API?" />

<Button
android:id="@+id/activity_main_button_stopService"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/activity_main_api1CheckBox"
android:layout_centerHorizontal="true"
android:text="Stop Background Service!" />
</RelativeLayout>

0 comments on commit 304f0cd

Please sign in to comment.