Хочу сделать local vpn на sketchware, но мешает actionBarActivity
Импортировал все res, подправил manifest и изменил немного импорт в активити сурс
package xyz.hexene.localvpn;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.VpnService;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.appcompat.app.ActionBar;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class LocalVPN extends ActionBarActivity
{
private static final int VPN_REQUEST_CODE = 0x0F;
private boolean waitingForVPNStart;
private BroadcastReceiver vpnStateReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
if (LocalVPNService.BROADCAST_VPN_STATE.equals(intent.getAction()))
{
if (intent.getBooleanExtra("running", false))
waitingForVPNStart = false;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_local_vpn);
final Button vpnButton = (Button)findViewById(R.id.vpn);
vpnButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
startVPN();
}
});
waitingForVPNStart = false;
LocalBroadcastManager.getInstance(this).registerReceiver(vpnStateReceiver,
new IntentFilter(LocalVPNService.BROADCAST_VPN_STATE));
}
private void startVPN()
{
Intent vpnIntent = VpnService.prepare(this);
if (vpnIntent != null)
startActivityForResult(vpnIntent, VPN_REQUEST_CODE);
else
onActivityResult(VPN_REQUEST_CODE, RESULT_OK, null);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == VPN_REQUEST_CODE && resultCode == RESULT_OK)
{
waitingForVPNStart = true;
startService(new Intent(this, LocalVPNService.class));
enableButton(false);
}
}
@Override
protected void onResume() {
super.onResume();
enableButton(!waitingForVPNStart && !LocalVPNService.isRunning());
}
private void enableButton(boolean enable)
{
final Button vpnButton = (Button) findViewById(R.id.vpn);
if (enable)
{
vpnButton.setEnabled(true);
vpnButton.setText(R.string.start_vpn);
}
else
{
vpnButton.setEnabled(false);
vpnButton.setText(R.string.stop_vpn);
}
}
}