2015-04-06 20:58:35 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.pebble;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2015-04-20 20:49:14 +02:00
|
|
|
import android.content.BroadcastReceiver;
|
|
|
|
import android.content.Context;
|
2015-04-06 20:58:35 +02:00
|
|
|
import android.content.Intent;
|
2015-04-20 20:49:14 +02:00
|
|
|
import android.content.IntentFilter;
|
2015-04-06 20:58:35 +02:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.v4.app.NavUtils;
|
2015-04-20 20:49:14 +02:00
|
|
|
import android.support.v4.content.LocalBroadcastManager;
|
2015-04-06 20:58:35 +02:00
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.Button;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
2015-05-01 01:49:43 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.BluetoothCommunicationService;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.ControlCenter;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBDevice;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.GBDeviceApp;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
|
|
|
|
2015-04-06 20:58:35 +02:00
|
|
|
|
|
|
|
public class PebbleAppInstallerActivity extends Activity {
|
|
|
|
|
|
|
|
private final String TAG = this.getClass().getSimpleName();
|
|
|
|
|
|
|
|
TextView debugTextView;
|
|
|
|
Button installButton;
|
|
|
|
|
2015-04-20 20:49:14 +02:00
|
|
|
private PBWReader mPBWReader = null;
|
|
|
|
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
String action = intent.getAction();
|
|
|
|
if (action.equals(ControlCenter.ACTION_QUIT)) {
|
|
|
|
finish();
|
|
|
|
} else if (action.equals(GBDevice.ACTION_DEVICE_CHANGED)) {
|
|
|
|
GBDevice dev = intent.getParcelableExtra("device");
|
|
|
|
if (mPBWReader != null) {
|
|
|
|
if (mPBWReader.isFirmware()) {
|
|
|
|
String hwRevision = mPBWReader.getHWRevision();
|
|
|
|
if (hwRevision != null && hwRevision.equals(dev.getHardwareVersion()) && dev.isConnected()) {
|
|
|
|
installButton.setEnabled(true);
|
|
|
|
} else {
|
|
|
|
installButton.setEnabled(false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
installButton.setEnabled(dev.isConnected());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-04-06 20:58:35 +02:00
|
|
|
@Override
|
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
setContentView(R.layout.activity_appinstaller);
|
|
|
|
getActionBar().setDisplayHomeAsUpEnabled(true);
|
|
|
|
|
|
|
|
debugTextView = (TextView) findViewById(R.id.debugTextView);
|
|
|
|
installButton = (Button) findViewById(R.id.installButton);
|
2015-04-20 20:49:14 +02:00
|
|
|
IntentFilter filter = new IntentFilter();
|
|
|
|
filter.addAction(ControlCenter.ACTION_QUIT);
|
|
|
|
filter.addAction(GBDevice.ACTION_DEVICE_CHANGED);
|
|
|
|
LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filter);
|
2015-04-06 20:58:35 +02:00
|
|
|
|
|
|
|
final Uri uri = getIntent().getData();
|
2015-04-20 20:49:14 +02:00
|
|
|
mPBWReader = new PBWReader(uri, getApplicationContext());
|
|
|
|
GBDeviceApp app = mPBWReader.getGBDeviceApp();
|
2015-04-07 19:33:23 +02:00
|
|
|
|
2015-04-20 20:49:14 +02:00
|
|
|
if (mPBWReader.isFirmware()) {
|
2015-05-01 01:26:12 +02:00
|
|
|
debugTextView.setText(getString(R.string.firmware_install_warning, mPBWReader.getHWRevision()));
|
2015-04-17 12:23:19 +02:00
|
|
|
|
2015-04-20 20:49:14 +02:00
|
|
|
} else if (app != null) {
|
2015-05-01 01:26:12 +02:00
|
|
|
debugTextView.setText(getString(R.string.app_install_info, app.getName(), app.getVersion(), app.getCreator()));
|
2015-04-06 20:58:35 +02:00
|
|
|
}
|
2015-04-20 20:49:14 +02:00
|
|
|
|
|
|
|
installButton.setOnClickListener(new View.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(View v) {
|
|
|
|
Intent startIntent = new Intent(PebbleAppInstallerActivity.this, BluetoothCommunicationService.class);
|
|
|
|
startIntent.setAction(BluetoothCommunicationService.ACTION_INSTALL_PEBBLEAPP);
|
|
|
|
startIntent.putExtra("app_uri", uri.toString());
|
|
|
|
startService(startIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Intent versionInfoIntent = new Intent(this, BluetoothCommunicationService.class);
|
|
|
|
versionInfoIntent.setAction(BluetoothCommunicationService.ACTION_REQUEST_VERSIONINFO);
|
|
|
|
startService(versionInfoIntent);
|
2015-04-06 20:58:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case android.R.id.home:
|
|
|
|
NavUtils.navigateUpFromSameTask(this);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDestroy() {
|
2015-04-20 20:49:14 +02:00
|
|
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(mReceiver);
|
2015-04-06 20:58:35 +02:00
|
|
|
super.onDestroy();
|
|
|
|
}
|
|
|
|
}
|