Skip to content

Commit

Permalink
Adding Splash-screen, first works for #5 and #3. Hopefully taking car…
Browse files Browse the repository at this point in the history
…e of #2
  • Loading branch information
pc-coholic committed Jul 18, 2017
1 parent 46bd93c commit 7ba2511
Show file tree
Hide file tree
Showing 11 changed files with 236 additions and 40 deletions.
84 changes: 51 additions & 33 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,15 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<application android:label="@string/app_name" android:icon="@mipmap/ic_launcher">
<application
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:name=".App">

<activity
android:name=".DPC"
android:label="@string/app_name">
android:name=".SplashActivity"
android:label="@string/app_name"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
Expand All @@ -30,34 +35,16 @@
</intent-filter>
</activity>

<receiver
android:name=".AdminReceiver"
android:label="@string/device_admin"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin" />
<activity
android:name=".DPC"
android:label="@string/app_name">
</activity>

<activity
android:name=".SetupActivity"
android:label="@string/app_name">
</activity>

<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
<receiver android:name=".BarcodeReceiver">
<intent-filter>
<action android:name="scan.rcv.message" />
</intent-filter>
</receiver>
<receiver android:name=".PowerConnectionReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</receiver>
<receiver android:name=".BatteryReceiver">
<intent-filter android:priority="900">
<action android:name="android.intent.action.BATTERY_CHANGED" />
</intent-filter>
</receiver>
<receiver android:name=".BootCompleteReceiver"
android:enabled="true"
android:exported="true"
Expand All @@ -66,13 +53,44 @@
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<!--<category android:name="android.intent.category.DEFAULT" />-->
</intent-filter>
</receiver>

<receiver
android:name=".AdminReceiver"
android:label="@string/device_admin"
android:permission="android.permission.BIND_DEVICE_ADMIN">
<meta-data
android:name="android.app.device_admin"
android:resource="@xml/device_admin" />

<intent-filter>
<action android:name="android.app.action.DEVICE_ADMIN_ENABLED" />
</intent-filter>
</receiver>
<!--
<receiver android:name=".BarcodeReceiver">
<intent-filter>
<action android:name="scan.rcv.message" />
</intent-filter>
</receiver>
<receiver android:name=".PowerConnectionReceiver">
<intent-filter>
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
</intent-filter>
</receiver>
<receiver android:name=".BatteryReceiver">
<intent-filter android:priority="900">
<action android:name="android.intent.action.BATTERY_CHANGED" />
</intent-filter>
</receiver>
-->
<!--
<service android:name=".StatusbarService"
android:enabled="true"
android:exported="true" />
android:exported="true">
</service>
-->
</application>

</manifest>
13 changes: 13 additions & 0 deletions res/drawable/background_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:drawable="@color/gray"/>

<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>

</layer-list>
6 changes: 4 additions & 2 deletions res/layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/main">
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:id="@+id/main"
tools:context=".SplashActivity">

<ImageView
android:id="@+id/batteryLevel"
Expand Down
29 changes: 29 additions & 0 deletions res/layout/setup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/setupErrorTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="setupErrorTitle"
android:textAlignment="center"
android:gravity="center"
android:textColor="@android:color/holo_red_dark"
android:textSize="18sp"
android:textStyle="bold" />

<TextView
android:id="@+id/setupErrorExpl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="setupErrorExpl" />

<Button
android:id="@+id/setupAction"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="setupAction"
android:visibility="invisible"/>
</LinearLayout>
4 changes: 4 additions & 0 deletions res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="gray">#444440</color>
</resources>
12 changes: 12 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,16 @@
<string name="pref_DPC_default_unlock_barcode">4002590140964</string>
<string name="pref_DPC_kiosk_package">Name of package that should run in Kiosk Mode</string>
<string name="pref_DPC_default_kiosk_package">eu.pretix.pretixdroid</string>
<string name="setup_not_device_owner">pretixDPC is not the device owner!</string>
<string name="setup_not_device_owner_expl">In order to function correctly, pretixDPC needs to be the device owner.\nThis can only be done by provisioning the device when there has been no account added to the device yet.\n\nThe most reliable way is to provision the device with the help an NFC-tag or by bumping it to another NFC-enabled phone.\n\nIf no NFC-tag or device is at hand, the same can be achieved by executing the following command through adb:\nadb shell dpm set-device-owner de.pccoholic.pretix.dpc/.AdminReceiver</string>
<string name="setup_not_device_admin">pretixDPC is not the device administrator!</string>
<string name="setup_not_device_admin_expl">In order to function correctly, pretixDPC needs to be the device administrator.\nNormally, this should have automatically been done during provisioning of pretixDPC as a device owner. However it can also be done manually by accessing the System Settings and finding the \"Device Adminstrators\"-settings in the Security-tab.</string>
<string name="setup_not_provisioned">pretixDPC is not provisioned!</string>
<string name="setup_not_provisioned_expl">This device has not been provisioned yet or the saved settings have been corrupted. Please scan a provisioning barcode now.</string>
<string name="setup_no_kioskapp">Kiosk application missing!</string>
<string name="setup_no_kioskapp_expl">The application that pretixDPC is supposed to guard is not installed yet.\n\nPress the button below to install the application.</string>
<string name="setup_no_kioskapp_button">Install now</string>
<string name="setup_everything_fine">Everything is fine!</string>
<string name="setup_everything_fine_expl">Why you are seeing this screen is thus beyond our understanding.\n\nPerhaps try restarting the app and/or device and see if the problem persists.</string>
<string name="setup_everything_fine_button">Exit the application</string>
</resources>
12 changes: 12 additions & 0 deletions res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>

<style name="SplashTheme" parent="android:Theme.Holo.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>

</resources>
16 changes: 16 additions & 0 deletions src/de/pccoholic/pretix/dpc/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.pccoholic.pretix.dpc;

import android.app.Application;
import android.os.SystemClock;

import java.util.concurrent.TimeUnit;

public class App extends Application {
@Override
public void onCreate() {
super.onCreate();

// Don't do this! This is just so cold launches take some time
SystemClock.sleep(TimeUnit.SECONDS.toMillis(3));
}
}
6 changes: 1 addition & 5 deletions src/de/pccoholic/pretix/dpc/BootCompleteReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
public class BootCompleteReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
Intent i = new Intent(context, DPC.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
// Nothing to do here, Application gets called first automagically.
}
}
68 changes: 68 additions & 0 deletions src/de/pccoholic/pretix/dpc/SetupActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package de.pccoholic.pretix.dpc;

import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class SetupActivity extends Activity {
private DevicePolicyManager dpm;
private ComponentName deviceAdmin;
private SharedPreferences prefs;

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

setContentView(R.layout.setup);

dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
deviceAdmin = new ComponentName(this, AdminReceiver.class);
prefs = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE);

TextView title = findViewById(R.id.setupErrorTitle);
TextView expl = findViewById(R.id.setupErrorExpl);
Button actionButton = findViewById(R.id.setupAction);

if (!dpm.isDeviceOwnerApp(getPackageName())) {
title.setText(R.string.setup_not_device_owner);
expl.setText(R.string.setup_not_device_owner_expl);
} else if (!dpm.isAdminActive(deviceAdmin)) {
title.setText(R.string.setup_not_device_admin);
expl.setText(R.string.setup_not_device_admin_expl);
} else if (!prefs.getBoolean("isProvisioned", false)) {
title.setText(R.string.setup_not_provisioned);
expl.setText(R.string.setup_not_provisioned_expl);
} else if (true == false) {
// ToDo: Check if Kiosk-App is installed
title.setText(R.string.setup_no_kioskapp);
expl.setText(R.string.setup_no_kioskapp_expl);
actionButton.setText(R.string.setup_no_kioskapp_button);
actionButton.setVisibility(View.VISIBLE);

actionButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// ToDo: Trigger the installation of the Kiosk-App
}
});
} else {
title.setText(R.string.setup_everything_fine);
expl.setText(R.string.setup_everything_fine_expl);
actionButton.setText(R.string.setup_everything_fine_button);
actionButton.setVisibility(View.VISIBLE);

actionButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finishAndRemoveTask();
}
});
}


}
}
26 changes: 26 additions & 0 deletions src/de/pccoholic/pretix/dpc/SplashActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.pccoholic.pretix.dpc;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;


public class SplashActivity extends Activity {
boolean isProvisioned = false;

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

Class<?> intentToLaunch = DPC.class;

if (isProvisioned != true) {
intentToLaunch = SetupActivity.class;
}

Intent intent = new Intent(this, intentToLaunch);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME);
startActivity(intent);
finish();
}
}

0 comments on commit 7ba2511

Please sign in to comment.