-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c2fa96f
Showing
47 changed files
with
1,306 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 29 | ||
buildToolsVersion "29.0.2" | ||
defaultConfig { | ||
applicationId "com.example.custombars" | ||
minSdkVersion 21 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'androidx.appcompat:appcompat:1.1.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.1' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' | ||
compile project(path: ':customizebars') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
27 changes: 27 additions & 0 deletions
27
app/src/androidTest/java/com/example/custombars/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.example.custombars; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry; | ||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | ||
|
||
assertEquals("com.example.custombars", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.custombars"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name="com.example.customizebars.ColorPicker"> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
112 changes: 112 additions & 0 deletions
112
app/src/main/java/com/example/custombars/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.example.custombars; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import android.content.Intent; | ||
import android.content.SharedPreferences; | ||
import android.graphics.drawable.ColorDrawable; | ||
import android.hardware.SensorListener; | ||
import android.hardware.SensorManager; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.Window; | ||
import android.view.WindowManager; | ||
import android.widget.LinearLayout; | ||
import android.widget.TextView; | ||
import android.widget.Toast; | ||
|
||
import com.example.customizebars.ColorPicker; | ||
|
||
public class MainActivity extends AppCompatActivity implements SensorListener { | ||
|
||
private LinearLayout ll; | ||
private SensorManager sensorMgr; | ||
private final int SHAKE_THRESHOLD = 500; | ||
long lastUpdate = 0; | ||
float last_x = 0; | ||
float last_y = 0; | ||
float last_z = 0; | ||
private final String PREFERENCE_FILE_KEY = "Colorpreferences"; | ||
private SharedPreferences.Editor editor; | ||
private SharedPreferences sharedPref; | ||
private String descriptionStatusBar = "StatusBar"; | ||
private String descriptionActionBar = "ActionBar"; | ||
private String descriptionBackground = "Background"; | ||
private int statusbar; | ||
private int actionbar; | ||
private int background; | ||
private int defaultStatusbar = 0; | ||
private int defaultActionbar = 0; | ||
private int defaultbackground = 0; | ||
private String myActivityName; | ||
public int helper = 0; | ||
|
||
private TextView textv; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE); | ||
sharedPref = getSharedPreferences(PREFERENCE_FILE_KEY, this.MODE_PRIVATE); | ||
editor = sharedPref.edit(); | ||
statusbar = sharedPref.getInt(descriptionStatusBar, defaultStatusbar); | ||
actionbar = sharedPref.getInt(descriptionActionBar, defaultActionbar); | ||
background = sharedPref.getInt(descriptionBackground, defaultbackground); | ||
ll = findViewById(R.id.testb); | ||
textv = findViewById(R.id.textme); | ||
String s = this.getClass().getName(); | ||
myActivityName = s; | ||
textv.setText(s); | ||
|
||
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(actionbar)); | ||
ll.setBackgroundColor(background); | ||
Window window = getWindow(); | ||
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); | ||
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); | ||
window.setStatusBarColor(statusbar); | ||
|
||
sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE); | ||
sensorMgr.registerListener((SensorListener) this, | ||
SensorManager.SENSOR_ACCELEROMETER, | ||
SensorManager.SENSOR_DELAY_GAME); | ||
|
||
} | ||
|
||
@Override | ||
public void onSensorChanged(int sensor, float[] values) { | ||
if (sensor == SensorManager.SENSOR_ACCELEROMETER && helper<1) { | ||
long curTime = System.currentTimeMillis(); | ||
// only allow one update every 100ms. | ||
if ((curTime - lastUpdate) > 500) { | ||
long diffTime = (curTime - lastUpdate); | ||
lastUpdate = curTime; | ||
|
||
float x = values[SensorManager.DATA_X]; | ||
float y = values[SensorManager.DATA_Y]; | ||
float z = values[SensorManager.DATA_Z]; | ||
|
||
float speed = Math.abs(x+y+z - last_x - last_y - last_z) / diffTime * 10000; | ||
|
||
if (speed > SHAKE_THRESHOLD) { | ||
Log.d("sensor", "shake detected w/ speed: " + speed); | ||
Toast.makeText(this, "shake detected w/ speed: " + speed, Toast.LENGTH_SHORT).show(); | ||
Intent intent = new Intent(MainActivity.this, ColorPicker.class); | ||
intent.putExtra("NextActivity", myActivityName); | ||
startActivity(intent); | ||
finish(); | ||
helper++; | ||
} | ||
last_x = x; | ||
last_y = y; | ||
last_z = z; | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onAccuracyChanged(int i, int i1) { | ||
|
||
} | ||
} |
Oops, something went wrong.