OSDN Git Service

Refactor backup / restore logic to implement multi-threading
[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.content.BroadcastReceiver;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.content.IntentFilter;
22 import android.os.Bundle;
23 import androidx.localbroadcastmanager.content.LocalBroadcastManager;
24
25 import com.farmerbb.taskbar.BuildConfig;
26 import com.farmerbb.taskbar.util.U;
27
28 public class ImportSettingsActivity extends AbstractProgressActivity {
29
30     boolean broadcastSent = false;
31
32     private BroadcastReceiver settingsReceivedReceiver = new BroadcastReceiver() {
33         @Override
34         public void onReceive(Context context, Intent intent) {
35             U.restartApp(ImportSettingsActivity.this, true);
36         }
37     };
38
39     @Override
40     protected void onCreate(Bundle savedInstanceState) {
41         super.onCreate(savedInstanceState);
42
43         LocalBroadcastManager.getInstance(this).registerReceiver(settingsReceivedReceiver, new IntentFilter("com.farmerbb.taskbar.IMPORT_FINISHED"));
44
45         if(!broadcastSent) {
46             Intent intent = new Intent("com.farmerbb.taskbar.RECEIVE_SETTINGS");
47             intent.setPackage(BuildConfig.BASE_APPLICATION_ID);
48             sendBroadcast(intent);
49
50             broadcastSent = true;
51         }
52     }
53
54     @Override
55     protected void onDestroy() {
56         super.onDestroy();
57
58         LocalBroadcastManager.getInstance(this).unregisterReceiver(settingsReceivedReceiver);
59     }
60 }