OSDN Git Service

Merge pull request #4 from farmerbb/master
[android-x86/packages-apps-Taskbar.git] / app / src / main / java / com / farmerbb / taskbar / activity / ImportSettingsActivity.java
1 /* Copyright 2016 Braden Farmer
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 package com.farmerbb.taskbar.activity;
17
18 import android.app.Activity;
19 import android.content.BroadcastReceiver;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.IntentFilter;
23 import android.os.Bundle;
24 import android.support.v4.content.LocalBroadcastManager;
25
26 import com.farmerbb.taskbar.MainActivity;
27 import com.farmerbb.taskbar.R;
28
29 public class ImportSettingsActivity extends Activity {
30
31     boolean broadcastSent = false;
32
33     private BroadcastReceiver settingsReceivedReceiver = new BroadcastReceiver() {
34         @Override
35         public void onReceive(Context context, Intent intent) {
36             Intent restartIntent = new Intent(ImportSettingsActivity.this, MainActivity.class);
37             restartIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
38             startActivity(restartIntent);
39             overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
40
41             System.exit(0);
42         }
43     };
44
45     @Override
46     protected void onCreate(Bundle savedInstanceState) {
47         super.onCreate(savedInstanceState);
48         setContentView(R.layout.import_settings);
49         setFinishOnTouchOutside(false);
50
51         LocalBroadcastManager.getInstance(this).registerReceiver(settingsReceivedReceiver, new IntentFilter("com.farmerbb.taskbar.IMPORT_FINISHED"));
52
53         if(!broadcastSent) {
54             sendBroadcast(new Intent("com.farmerbb.taskbar.RECEIVE_SETTINGS"));
55             broadcastSent = true;
56         }
57     }
58
59     @Override
60     protected void onDestroy() {
61         super.onDestroy();
62
63         LocalBroadcastManager.getInstance(this).unregisterReceiver(settingsReceivedReceiver);
64     }
65
66     // Disable back button
67     @Override
68     public void onBackPressed() {}
69 }