■画面回転を固定にしたい場合
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
■画面回転の固定を解除したい場合
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Context context = getActivity().getApplicationContext(); Intent serviceIntent = new Intent(context, RpService.class);// サービスのクラスを指定 // サービス起動 context.startService(serviceIntent); // サービス停止 context.stopService(serviceIntent);
BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null) {
if (action.equals(Intent.ACTION_SCREEN_ON)) {
// 画面ON時の処理
}
}
}
};
public class RpService extends Service {
...
@Override
public void onCreate() {
super.onCreate();
// ブロードキャストリスナーの登録
// IntentFilterとして、画面オンを示すIntent.ACTION_SCREEN_ONを指定します
registerReceiver(mBroadcastReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON));
}
@Override
public void onDestroy() {
super.onDestroy();
// ブロードキャストリスナーの登録解除
unregisterReceiver(mBroadcastReceiver);
}
....
}
Context context = getApplicationContext();
LocalBroadcastManager.getInstance(context)
.sendBroadcast(new Intent(RpNoteIntent.ACTION_UPDATE_SERVICE));
BroadcastReceiver mLocalBroadcastManager = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null) {
if (action.equals(RpNoteIntent.ACTION_UPDATE_SERVICE)) {
// 設定の再読込処理
}
}
}
};
public class RpService extends Service {
...
@Override
public void onCreate() {
super.onCreate();
// ローカルブロードキャストリスナーの登録
LocalBroadcastManager.getInstance(getApplicationContext())
.registerReceiver(mLocalBroadcastReceiver, new IntentFilter(RpNoteIntent.ACTION_UPDATE_SERVICE));
}
@Override
public void onDestroy() {
super.onDestroy();
// ローカルブロードキャストリスナーの登録解除
LocalBroadcastManager.getInstance(getApplicationContext())
.unregisterReceiver(mLocalBroadcastReceiver);
}
....
}
public class TestDialog extends Dialog {
/* 〜〜〜 一部省略 〜〜〜*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// タイトルバーを非表示にする
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dlg_deadline);
// ダイアログの背景(境界線)を無くす(透明)
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
// ダイアログの大きさ最大にする(任意のサイズも指定可能)
getWindow().setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
}
/* 〜〜〜 一部省略 〜〜〜*/
}