JLChen
2021-01-04 ed86fe7ed952bb2151aac8841134246bbde152c9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*
 * Copyright (c) 2010-2019 Belledonne Communications SARL.
 *
 * This file is part of linphone-android
 * (see https://www.linphone.org).
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.linphone.activities;
 
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.core.content.ContextCompat;
import org.linphone.LinphoneManager;
import org.linphone.R;
import org.linphone.core.Core;
import org.linphone.core.CoreListenerStub;
import org.linphone.settings.LinphonePreferences;
 
public class AboutActivity extends MainActivity {
    private CoreListenerStub mListener;
    private ProgressDialog mProgress;
    private boolean mUploadInProgress;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
 
        mOnBackPressGoHome = false;
        mAlwaysHideTabBar = true;
 
        // Uses the fragment container layout to inflate the about view instead of using a fragment
        View aboutView = LayoutInflater.from(this).inflate(R.layout.about, null, false);
        LinearLayout fragmentContainer = findViewById(R.id.fragmentContainer);
        LinearLayout.LayoutParams params =
                new LinearLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        fragmentContainer.addView(aboutView, params);
 
        if (isTablet()) {
            findViewById(R.id.fragmentContainer2).setVisibility(View.GONE);
        }
 
        TextView aboutVersion = findViewById(R.id.about_android_version);
        TextView aboutLiblinphoneVersion = findViewById(R.id.about_liblinphone_sdk_version);
        aboutLiblinphoneVersion.setText(
                String.format(
                        getString(R.string.about_liblinphone_sdk_version),
                        getString(R.string.linphone_sdk_version)
                                + " ("
                                + getString(R.string.linphone_sdk_branch)
                                + ")"));
        // We can't access a library's BuildConfig, so we have to set it as a resource
        aboutVersion.setText(
                String.format(
                        getString(R.string.about_version),
                        org.linphone.BuildConfig.VERSION_NAME
                                + " ("
                                + org.linphone.BuildConfig.BUILD_TYPE
                                + ")"));
 
        TextView privacyPolicy = findViewById(R.id.privacy_policy_link);
        privacyPolicy.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent browserIntent =
                                new Intent(
                                        Intent.ACTION_VIEW,
                                        Uri.parse(getString(R.string.about_privacy_policy_link)));
                        startActivity(browserIntent);
                    }
                });
 
        TextView license = findViewById(R.id.about_text);
        license.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent browserIntent =
                                new Intent(
                                        Intent.ACTION_VIEW,
                                        Uri.parse(getString(R.string.about_license_link)));
                        startActivity(browserIntent);
                    }
                });
 
        Button sendLogs = findViewById(R.id.send_log);
        sendLogs.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Core core = LinphoneManager.getCore();
                        if (core != null) {
                            core.uploadLogCollection();
                        }
                    }
                });
        sendLogs.setVisibility(
                LinphonePreferences.instance().isDebugEnabled() ? View.VISIBLE : View.GONE);
 
        Button resetLogs = findViewById(R.id.reset_log);
        resetLogs.setOnClickListener(
                new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Core core = LinphoneManager.getCore();
                        if (core != null) {
                            core.resetLogCollection();
                        }
                    }
                });
        resetLogs.setVisibility(
                LinphonePreferences.instance().isDebugEnabled() ? View.VISIBLE : View.GONE);
 
        mListener =
                new CoreListenerStub() {
                    @Override
                    public void onLogCollectionUploadProgressIndication(
                            Core core, int offset, int total) {}
 
                    @Override
                    public void onLogCollectionUploadStateChanged(
                            Core core, Core.LogCollectionUploadState state, String info) {
                        if (state == Core.LogCollectionUploadState.InProgress) {
                            displayUploadLogsInProgress();
                        } else if (state == Core.LogCollectionUploadState.Delivered
                                || state == Core.LogCollectionUploadState.NotDelivered) {
                            mUploadInProgress = false;
                            if (mProgress != null) mProgress.dismiss();
                        }
                    }
                };
    }
 
    @Override
    public void onResume() {
        super.onResume();
 
        showTopBarWithTitle(getString(R.string.about));
        if (getResources().getBoolean(R.bool.hide_bottom_bar_on_second_level_views)) {
            hideTabBar();
        }
 
        Core core = LinphoneManager.getCore();
        if (core != null) {
            core.addListener(mListener);
        }
    }
 
    @Override
    public void onPause() {
        Core core = LinphoneManager.getCore();
        if (core != null) {
            core.removeListener(mListener);
        }
 
        super.onPause();
    }
 
    @Override
    protected void onDestroy() {
        mListener = null;
        mProgress = null;
 
        super.onDestroy();
    }
 
    private void displayUploadLogsInProgress() {
        if (mUploadInProgress) {
            return;
        }
        mUploadInProgress = true;
 
        mProgress = ProgressDialog.show(this, null, null);
        Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.light_grey_color));
        d.setAlpha(200);
        mProgress
                .getWindow()
                .setLayout(
                        WindowManager.LayoutParams.MATCH_PARENT,
                        WindowManager.LayoutParams.MATCH_PARENT);
        mProgress.getWindow().setBackgroundDrawable(d);
        mProgress.setContentView(R.layout.wait_layout);
        mProgress.show();
    }
}