-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
2c91741
commit ab919d0
Showing
9 changed files
with
217 additions
and
23 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
65 changes: 51 additions & 14 deletions
65
AppSpecificOrientation/src/main/java/com/spydiko/appspecificorientation/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 |
---|---|---|
@@ -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)); | ||
} | ||
} | ||
} | ||
} |
134 changes: 134 additions & 0 deletions
134
...cificOrientation/src/main/java/com/spydiko/appspecificorientation/OrientationService.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,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
24
AppSpecificOrientation/src/main/res/layout/activity_main.xml
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
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
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