Skip to content

Commit

Permalink
before merging with Pur3v1l
Browse files Browse the repository at this point in the history
  • Loading branch information
spirosbond committed Aug 8, 2013
1 parent 2c91741 commit ab919d0
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 23 deletions.
Binary file modified .gradle/1.6/taskArtifacts/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/1.6/taskArtifacts/fileSnapshots.bin
Binary file not shown.
Binary file modified .gradle/1.6/taskArtifacts/taskArtifacts.bin
Binary file not shown.
13 changes: 12 additions & 1 deletion AppSpecificOrientation/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,31 @@
android:minSdkVersion="7"
android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>


<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.spydiko.appspecificorientation.MainActivity"
android:label="@string/app_name" >
android:label="@string/app_name"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

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

<service
android:name=".OrientationService"
android:enabled="true"
android:permission="SAIL_SERVICE_PERMISSION"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,23 +1,60 @@
package com.spydiko.appspecificorientation;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.ToggleButton;

public class MainActivity extends Activity implements View.OnClickListener {

private static final String TAG = MainActivity.class.getSimpleName();
private ToggleButton serviceButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreated");
setContentView(R.layout.activity_main);
serviceButton = (ToggleButton) findViewById(R.id.serviceButton);
serviceButton.setOnClickListener(this);
if(OrientationService.isRunning()) serviceButton.setChecked(true);
// startService(new Intent(this, OrientationService.class));
}

public class MainActivity extends Activity {
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.d(TAG, "onConfigurationChanged");
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.d(TAG, "onRestoredInstanceState");
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public void onClick(View view) {
ToggleButton button = (ToggleButton) view;
switch (button.getId()) {
case R.id.serviceButton:
if (button.isChecked()) {
startService(new Intent(this, OrientationService.class));
}
if (!button.isChecked()) {
stopService(new Intent(this, OrientationService.class));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package com.spydiko.appspecificorientation;

import android.app.ActivityManager;
import android.app.Service;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.IBinder;
import android.provider.Settings;
import android.util.Log;

/**
* Created by spiros on 8/7/13.
*/
public class OrientationService extends Service {


private static final String TAG = OrientationService.class.getSimpleName();
private static boolean running;
// private OrientationEventListener orientationEventListener;
private ActivityManager activityManager;
private String foregroundApp;
private int defaultState;
private int newState;

public static boolean isRunning() {
return running;
}

public static void setRunning(boolean running) {
OrientationService.running = running;
}
// private AppSpecificOrientation appSpecificOrientation;

@Override
public void onCreate() {
super.onCreate();
Log.d(TAG, "onCreated");
running = true;
try {
defaultState = Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION);
if (defaultState == 1) newState = 0;
else newState = 1;
} catch (Settings.SettingNotFoundException e) {
Log.d(TAG, "Couldn't find ACCELEROMETER_ROTATION settings");
}

Log.d(TAG, "Default state: " + defaultState);
Log.d(TAG, "New state: " + newState);


new AppMonitoring().execute();
// orientationEventListener = new OrientationEventListener(getApplicationContext()) {
// @Override
// public void onOrientationChanged(int i) {
// Log.d(TAG, "orientation changed to: " + i + " degrees");
//
// activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
// get the info from the currently running task
// try {
// foregroundApp = activityManager.getRunningTasks(1).get(0).topActivity.getClassName();
// } catch (NullPointerException e) {
// Log.d(TAG, "No foreground app??? Da Fuck???");
// }
//
// if (appSpecificOrientation.isChecked(foregroundApp)) {
//
// Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, newState);
//
//
// } else {
// Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, defaultState);
// }
// previousForegroundApp = foregroundApp;
// }
// };
// orientationEventListener.enable();
}

@Override
public void onDestroy() {
super.onDestroy();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);

}

@Override
public IBinder onBind(Intent intent) {
return null;
}

public class AppMonitoring extends AsyncTask<String, Integer, String> {


@Override
protected String doInBackground(String... strings) {
while (running) {
activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
// get the info from the currently running task
try {
foregroundApp = activityManager.getRunningTasks(1).get(0).topActivity.getClassName();
Log.d(TAG, "Foreground app: " + foregroundApp);
} catch (NullPointerException e) {
Log.d(TAG, "No foreground app??? Da Fuck???");
}

// if (appSpecificOrientation.isChecked(foregroundApp)) {
if (foregroundApp.contains("com.android.gallery3d.app")) {

Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, newState);
Log.d(TAG, "rotation " + newState);


} else {
Settings.System.putInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, defaultState);
Log.d(TAG, "rotation " + defaultState);

}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}

}
return "end";
}
}


}
24 changes: 16 additions & 8 deletions AppSpecificOrientation/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical">

<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/serviceButton"
android:textOn="@string/serviceOn"
android:textOff="@string/serviceOff"/>

<ListView
android:layout_width="fill_parent"
Expand Down
2 changes: 2 additions & 0 deletions AppSpecificOrientation/src/main/res/layout/app_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="@dimen/activity_horizontal_margin"

>

</CheckBox>
Expand Down
2 changes: 2 additions & 0 deletions AppSpecificOrientation/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
<string name="app_name">App Specific Orientation</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="serviceOn">Service Running</string>
<string name="serviceOff">Start Service</string>

</resources>

0 comments on commit ab919d0

Please sign in to comment.