Skip to content

Commit

Permalink
target 28
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkaW committed Aug 18, 2018
1 parent c59d7c6 commit d8eb661
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 138 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
.DS_Store
/build
/captures
.idea/
.idea
signing.properties
48 changes: 24 additions & 24 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
compileSdkVersion 28

defaultConfig {
applicationId "rikka.smscodehelper"
minSdkVersion 15
targetSdkVersion 23
versionCode 10006
versionName "1.0.7"
targetSdkVersion 28
versionCode 10008
versionName "1.0.8"
}
signingConfigs {
sign
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
debug {
signingConfig signingConfigs.sign
}
release {
minifyEnabled false
signingConfig signingConfigs.sign
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.returnDefaultValues = true
}
}

applicationVariants.all { variant ->
variant.outputs.each { output ->
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
output.outputFile = file("${output.outputFile.parent}/smscodehelper" +
"-${variant.buildType.name.toLowerCase()}" +
"-${variant.versionName}" +
".apk")
}
}
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "sms-code-helper-${variant.versionCode}.apk"
}
}

apply from: rootProject.file('signing.gradle')

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// Unit testing dependencies
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
compile 'com.android.support:appcompat-v7:23.1.1'
}
implementation 'androidx.core:core:1.0.0-rc01'
}
21 changes: 13 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="rikka.smscodehelper">

<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS" />

<application
android:allowBackup="true"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".MainActivity"
android:excludeFromRecents="true"
android:label="@string/app_name"
android:theme="@style/Transparent"
android:excludeFromRecents="true">
android:theme="@style/AppTheme.Transparent">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<receiver android:name=".receiver.SMSBroadcastReceiver">
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED"/>
<receiver
android:name=".receiver.SMSBroadcastReceiver"
android:permission="android.permission.BROADCAST_SMS">
<intent-filter
android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
</application>
Expand Down
77 changes: 28 additions & 49 deletions app/src/main/java/rikka/smscodehelper/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,91 +1,70 @@
package rikka.smscodehelper;

import android.Manifest;
import android.content.DialogInterface;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class MainActivity extends AppCompatActivity {
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle);
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setOnCancelListener(dialog -> finish())
.setCancelable(false);

builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
finish();
}
});

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS) != PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
&& ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS) != PackageManager.PERMISSION_GRANTED) {
builder.setMessage(R.string.tip_m);
builder.setPositiveButton(R.string.get_permission, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
getPermission(Manifest.permission.RECEIVE_SMS);
}
});
builder.setPositiveButton(R.string.get_permission, (dialog, which) -> requestPermission());
builder.setNegativeButton(R.string.exit, (dialog, which) -> finish());
} else {
builder.setMessage(getString(R.string.tip));
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
hideLauncher();
finish();
}
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
hideFromLauncher();
finish();
});
}

AlertDialog alertDialog = builder.create();
alertDialog.setCanceledOnTouchOutside(false);
alertDialog.show();
builder.show();
}

private void getPermission(String permission) {
if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{permission}, 0);
private void requestPermission() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.RECEIVE_SMS}, 0);
}
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
switch (requestCode) {
case 0:
if (grantResults[0] != PackageManager.PERMISSION_GRANTED) {
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DialogStyle);
AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setTitle("OAQ");
builder.setMessage(R.string.permission_denied);
builder.setPositiveButton(R.string.exit, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
builder.create().show();
builder.setPositiveButton(R.string.exit, (dialog, which) -> finish());
builder.show();
} else {
hideFromLauncher();
finish();
hideLauncher();
}
break;
default:
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}

private void hideLauncher() {
PackageManager p = getApplicationContext().getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
private void hideFromLauncher() {
PackageManager pm = getApplicationContext().getPackageManager();
pm.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
}
}
8 changes: 0 additions & 8 deletions app/src/main/res/layout/activity_main.xml

This file was deleted.

15 changes: 8 additions & 7 deletions app/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<resources>>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme.Transparent" parent="AppTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
</resources>
</resources>
7 changes: 1 addition & 6 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<resources>
<string name="app_name">验证码复制器</string>

<string name="toast_format" formatted="false">%s 已被复制到剪贴板</string>

<string name="tip_m">在 Android 6.0 以上需要由用户授予权限,点击获取后,如果没有权限将弹出授权窗口。\n授权后应用将会从启动器隐藏。</string>
<string name="tip">点击确认后应用将会从启动器隐藏。</string>

<string name="get_permission">获取权限</string>
<string name="ok">确认</string>
<string name="get_permission">授予权限</string>
<string name="exit">退出</string>
<string name="permission_denied">被拒绝了..</string>

</resources>
5 changes: 2 additions & 3 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">驗證碼複製器</string>
<string name="toast_format">%s 已複製到剪貼簿</string>
<string name="exit">退出</string>
<string name="get_permission">取得權限</string>
<string name="ok">確定</string>
<string name="get_permission">授予權限</string>
<string name="permission_denied">被拒絕了..</string>
<string name="tip">點擊確定後App將會被隱藏</string>
<string name="tip_m">"Android 6.0以上需要由使用者授予權限,點擊授予後,如果沒有權限將跳出授權視窗。
授權後App將會被隱藏。"</string>
<string name="toast_format">%s 已複製到剪貼簿</string>
</resources>
7 changes: 1 addition & 6 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
<resources>
<string name="app_name">SmsCodeHelper</string>

<string name="toast_format" formatted="false">%s has been copied to clipboard.</string>

<string name="tip_m">After Android 6.0, permission should be authorized by user.\nApp will be hide from launcher if authorized.</string>
<string name="tip">App will be hide from launcher.</string>

<string name="get_permission">GET PERMISSION</string>
<string name="ok">OK</string>
<string name="get_permission">Grant permission</string>
<string name="exit">Exit</string>
<string name="permission_denied">Denied..</string>

</resources>
25 changes: 3 additions & 22 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme" parent="android:Theme.DeviceDefault"/>

<style name="Transparent" parent="AppTheme">
<item name="windowNoTitle">true</item>
<style name="AppTheme.Transparent" parent="AppTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowIsFloating">true</item>
</style>

<style name="DialogStyle" parent="Theme.AppCompat.Light.Dialog">
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
classpath 'com.android.tools.build:gradle:3.2.0-beta05'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -14,6 +15,7 @@ buildscript {

allprojects {
repositories {
google()
jcenter()
}
}
Expand Down
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# org.gradle.parallel=true
android.useAndroidX=true
android.enableJetifier=true
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Wed Oct 21 11:34:03 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
Loading

0 comments on commit d8eb661

Please sign in to comment.