Removed localrepo classes that were used before "swap".
All of the relevant code from them has been ported across to swap, and they are no longer needed as a reference for how to implement app swapping.
This commit is contained in:
parent
ec44c1efe5
commit
52c4554877
@ -1,11 +0,0 @@
|
|||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<fragment
|
|
||||||
android:id="@+id/fragment_app_list"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="fill_parent"
|
|
||||||
class="org.fdroid.fdroid.views.fragments.SelectLocalAppsFragment" />
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
@ -1,338 +0,0 @@
|
|||||||
package org.fdroid.fdroid.views;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.app.ProgressDialog;
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.nfc.NdefMessage;
|
|
||||||
import android.nfc.NdefRecord;
|
|
||||||
import android.nfc.NfcAdapter;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
|
||||||
import android.support.v7.app.ActionBarActivity;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.CheckBox;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
|
||||||
import org.fdroid.fdroid.PreferencesActivity;
|
|
||||||
import org.fdroid.fdroid.QrGenAsyncTask;
|
|
||||||
import org.fdroid.fdroid.R;
|
|
||||||
import org.fdroid.fdroid.Utils;
|
|
||||||
import org.fdroid.fdroid.localrepo.LocalRepoManager;
|
|
||||||
import org.fdroid.fdroid.localrepo.LocalRepoService;
|
|
||||||
import org.fdroid.fdroid.net.WifiStateChangeService;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Timer;
|
|
||||||
import java.util.TimerTask;
|
|
||||||
|
|
||||||
public class LocalRepoActivity extends ActionBarActivity {
|
|
||||||
|
|
||||||
private static final String TAG = "LocalRepoActivity";
|
|
||||||
private ProgressDialog repoProgress;
|
|
||||||
|
|
||||||
private WifiManager wifiManager;
|
|
||||||
private Button enableWifiButton;
|
|
||||||
private CheckBox repoSwitch;
|
|
||||||
|
|
||||||
private Timer stopTimer;
|
|
||||||
|
|
||||||
private final int SET_IP_ADDRESS = 7345;
|
|
||||||
private final int UPDATE_REPO = 7346;
|
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
((FDroidApp) getApplication()).applyTheme(this);
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.local_repo_activity);
|
|
||||||
|
|
||||||
enableWifiButton = (Button) findViewById(R.id.enable_wifi);
|
|
||||||
repoSwitch = (CheckBox) findViewById(R.id.repoSwitch);
|
|
||||||
wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
resetNetworkInfo();
|
|
||||||
setRepoSwitchChecked(FDroidApp.isLocalRepoServiceRunning());
|
|
||||||
|
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(onWifiChange,
|
|
||||||
new IntentFilter(WifiStateChangeService.BROADCAST));
|
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(onLocalRepoChange,
|
|
||||||
new IntentFilter(LocalRepoService.STATE));
|
|
||||||
// if no local repo exists, create one with only FDroid in it
|
|
||||||
if (!LocalRepoManager.get(this).xmlIndex.exists())
|
|
||||||
new UpdateAsyncTask(this, new String[] {
|
|
||||||
getPackageName(),
|
|
||||||
}).execute();
|
|
||||||
|
|
||||||
// start repo by default
|
|
||||||
FDroidApp.startLocalRepoService(LocalRepoActivity.this);
|
|
||||||
// reset the timer if viewing this Activity again
|
|
||||||
if (stopTimer != null)
|
|
||||||
stopTimer.cancel();
|
|
||||||
// automatically turn off after 15 minutes
|
|
||||||
stopTimer = new Timer();
|
|
||||||
stopTimer.schedule(new TimerTask() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
FDroidApp.stopLocalRepoService(LocalRepoActivity.this);
|
|
||||||
}
|
|
||||||
}, 900000); // 15 minutes
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(onWifiChange);
|
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(onLocalRepoChange);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final BroadcastReceiver onWifiChange = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent i) {
|
|
||||||
resetNetworkInfo();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private final BroadcastReceiver onLocalRepoChange = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent i) {
|
|
||||||
String state = i.getStringExtra(LocalRepoService.STATE);
|
|
||||||
if (state != null && state.equals(LocalRepoService.STARTED))
|
|
||||||
setRepoSwitchChecked(true);
|
|
||||||
else
|
|
||||||
setRepoSwitchChecked(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void resetNetworkInfo() {
|
|
||||||
int wifiState = wifiManager.getWifiState();
|
|
||||||
if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
|
|
||||||
setUIFromWifi();
|
|
||||||
wireRepoSwitchToWebServer();
|
|
||||||
repoSwitch.setVisibility(View.VISIBLE);
|
|
||||||
enableWifiButton.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
repoSwitch.setChecked(false);
|
|
||||||
repoSwitch.setVisibility(View.GONE);
|
|
||||||
enableWifiButton.setVisibility(View.VISIBLE);
|
|
||||||
enableWifiButton.setText(R.string.enable_wifi);
|
|
||||||
enableWifiButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
enableWifiButton.setText(R.string.enabling_wifi);
|
|
||||||
wifiManager.setWifiEnabled(true);
|
|
||||||
/*
|
|
||||||
* Once the wifi is connected to a network, then
|
|
||||||
* WifiStateChangeReceiver will receive notice, and kick off
|
|
||||||
* the process of getting the info about the wifi
|
|
||||||
* connection.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
MenuInflater inflater = getMenuInflater();
|
|
||||||
inflater.inflate(R.menu.local_repo_activity, menu);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case R.id.menu_setup_repo:
|
|
||||||
startActivityForResult(new Intent(this, SelectLocalAppsActivity.class), UPDATE_REPO);
|
|
||||||
return true;
|
|
||||||
case R.id.menu_send_fdroid_via_wifi:
|
|
||||||
startActivity(new Intent(this, QrWizardWifiNetworkActivity.class));
|
|
||||||
return true;
|
|
||||||
case R.id.menu_settings:
|
|
||||||
startActivityForResult(new Intent(this, PreferencesActivity.class), SET_IP_ADDRESS);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
if (resultCode != RESULT_OK)
|
|
||||||
return;
|
|
||||||
if (requestCode == SET_IP_ADDRESS) {
|
|
||||||
setUIFromWifi();
|
|
||||||
} else if (requestCode == UPDATE_REPO) {
|
|
||||||
setUIFromWifi();
|
|
||||||
new UpdateAsyncTask(this, FDroidApp.selectedApps.toArray(new String[FDroidApp.selectedApps.size()]))
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Dialog onCreateDialog(int id) {
|
|
||||||
switch (id) {
|
|
||||||
case 0:
|
|
||||||
repoProgress = new ProgressDialog(this);
|
|
||||||
repoProgress.setMessage("Scanning Apps. Please wait...");
|
|
||||||
repoProgress.setIndeterminate(false);
|
|
||||||
repoProgress.setMax(100);
|
|
||||||
repoProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
|
||||||
repoProgress.setCancelable(false);
|
|
||||||
repoProgress.show();
|
|
||||||
return repoProgress;
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void wireRepoSwitchToWebServer() {
|
|
||||||
repoSwitch.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
setRepoSwitchChecked(repoSwitch.isChecked());
|
|
||||||
if (repoSwitch.isChecked()) {
|
|
||||||
FDroidApp.startLocalRepoService(LocalRepoActivity.this);
|
|
||||||
} else {
|
|
||||||
FDroidApp.stopLocalRepoService(LocalRepoActivity.this);
|
|
||||||
stopTimer.cancel(); // disable automatic stop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setRepoSwitchChecked(boolean checked) {
|
|
||||||
repoSwitch.setChecked(checked);
|
|
||||||
if (checked) {
|
|
||||||
repoSwitch.setText(R.string.local_repo_running);
|
|
||||||
} else {
|
|
||||||
repoSwitch.setText(R.string.touch_to_turn_on_local_repo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(14)
|
|
||||||
private void setUIFromWifi() {
|
|
||||||
if (TextUtils.isEmpty(FDroidApp.repo.address))
|
|
||||||
return;
|
|
||||||
// the fingerprint is not useful on the button label
|
|
||||||
String buttonLabel = FDroidApp.repo.address.replaceAll("\\?.*$", "");
|
|
||||||
TextView sharingUriTextView = (TextView) findViewById(R.id.sharing_uri);
|
|
||||||
sharingUriTextView.setText(buttonLabel);
|
|
||||||
/*
|
|
||||||
* Set URL to UPPER for compact QR Code, FDroid will translate it back.
|
|
||||||
* Remove the SSID from the query string since SSIDs are case-sensitive.
|
|
||||||
* Instead the receiver will have to rely on the BSSID to find the right
|
|
||||||
* wifi AP to join. Lots of QR Scanners are buggy and do not respect
|
|
||||||
* custom URI schemes, so we have to use http:// or https:// :-(
|
|
||||||
*/
|
|
||||||
final String qrUriString = Utils.getSharingUri(FDroidApp.repo).toString()
|
|
||||||
.replaceFirst("fdroidrepo", "http")
|
|
||||||
.replaceAll("ssid=[^?]*", "")
|
|
||||||
.toUpperCase(Locale.ENGLISH);
|
|
||||||
if (Build.VERSION.SDK_INT >= 8) // zxing requires >= 8
|
|
||||||
new QrGenAsyncTask(this, R.id.repoQrCode).execute(qrUriString);
|
|
||||||
|
|
||||||
TextView wifiNetworkNameTextView = (TextView) findViewById(R.id.wifi_network);
|
|
||||||
wifiNetworkNameTextView.setText(FDroidApp.ssid);
|
|
||||||
|
|
||||||
TextView fingerprintTextView = (TextView) findViewById(R.id.fingerprint);
|
|
||||||
if (FDroidApp.repo.fingerprint != null) {
|
|
||||||
fingerprintTextView.setVisibility(View.VISIBLE);
|
|
||||||
fingerprintTextView.setText(FDroidApp.repo.fingerprint);
|
|
||||||
} else {
|
|
||||||
fingerprintTextView.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// the required NFC API was added in 4.0 aka Ice Cream Sandwich
|
|
||||||
if (Build.VERSION.SDK_INT >= 14) {
|
|
||||||
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
|
|
||||||
if (nfcAdapter == null)
|
|
||||||
return;
|
|
||||||
nfcAdapter.setNdefPushMessage(new NdefMessage(new NdefRecord[] {
|
|
||||||
NdefRecord.createUri(Utils.getSharingUri(FDroidApp.repo)),
|
|
||||||
}), this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class UpdateAsyncTask extends AsyncTask<Void, String, Void> {
|
|
||||||
private static final String TAG = "LocalRepoActivity.UpdateAsyncTask";
|
|
||||||
private final ProgressDialog progressDialog;
|
|
||||||
private final String[] selectedApps;
|
|
||||||
private final Uri sharingUri;
|
|
||||||
|
|
||||||
public UpdateAsyncTask(Context c, String[] apps) {
|
|
||||||
selectedApps = apps;
|
|
||||||
progressDialog = new ProgressDialog(c);
|
|
||||||
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
|
||||||
progressDialog.setTitle(R.string.updating);
|
|
||||||
sharingUri = Utils.getSharingUri(FDroidApp.repo);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPreExecute() {
|
|
||||||
progressDialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... params) {
|
|
||||||
try {
|
|
||||||
final LocalRepoManager lrm = LocalRepoManager.get(LocalRepoActivity.this);
|
|
||||||
publishProgress(getString(R.string.deleting_repo));
|
|
||||||
lrm.deleteRepo();
|
|
||||||
for (String app : selectedApps) {
|
|
||||||
publishProgress(String.format(getString(R.string.adding_apks_format), app));
|
|
||||||
lrm.addApp(getApplicationContext(), app);
|
|
||||||
}
|
|
||||||
lrm.writeIndexPage(sharingUri.toString());
|
|
||||||
publishProgress(getString(R.string.writing_index_jar));
|
|
||||||
lrm.writeIndexJar();
|
|
||||||
publishProgress(getString(R.string.linking_apks));
|
|
||||||
lrm.copyApksToRepo();
|
|
||||||
publishProgress(getString(R.string.copying_icons));
|
|
||||||
// run the icon copy without progress, its not a blocker
|
|
||||||
new AsyncTask<Void, Void, Void>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Void doInBackground(Void... params) {
|
|
||||||
lrm.copyIconsToRepo();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}.execute();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onProgressUpdate(String... progress) {
|
|
||||||
super.onProgressUpdate(progress);
|
|
||||||
progressDialog.setMessage(progress[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Void result) {
|
|
||||||
progressDialog.dismiss();
|
|
||||||
Toast.makeText(getBaseContext(), R.string.updated_local_repo, Toast.LENGTH_SHORT)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,83 +0,0 @@
|
|||||||
package org.fdroid.fdroid.views;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
|
||||||
import android.support.v7.app.ActionBarActivity;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
|
||||||
import org.fdroid.fdroid.Preferences;
|
|
||||||
import org.fdroid.fdroid.QrGenAsyncTask;
|
|
||||||
import org.fdroid.fdroid.R;
|
|
||||||
import org.fdroid.fdroid.net.WifiStateChangeService;
|
|
||||||
|
|
||||||
public class QrWizardDownloadActivity extends ActionBarActivity {
|
|
||||||
|
|
||||||
private static final String TAG = "QrWizardDownloadActivity";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
((FDroidApp) getApplication()).applyTheme(this);
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.qr_wizard_activity);
|
|
||||||
TextView instructions = (TextView) findViewById(R.id.qrWizardInstructions);
|
|
||||||
instructions.setText(R.string.qr_wizard_download_instructions);
|
|
||||||
Button next = (Button) findViewById(R.id.qrNextButton);
|
|
||||||
next.setOnClickListener(new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
setResult(RESULT_OK);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
resetNetworkInfo();
|
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(onWifiChange,
|
|
||||||
new IntentFilter(WifiStateChangeService.BROADCAST));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(onWifiChange);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final BroadcastReceiver onWifiChange = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent i) {
|
|
||||||
Log.i(TAG, "onWifiChange.onReceive()");
|
|
||||||
resetNetworkInfo();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void resetNetworkInfo() {
|
|
||||||
String qrString = "";
|
|
||||||
if (Preferences.get().isLocalRepoHttpsEnabled())
|
|
||||||
qrString += "https";
|
|
||||||
else
|
|
||||||
qrString += "http";
|
|
||||||
qrString += "://" + FDroidApp.ipAddressString;
|
|
||||||
qrString += ":" + FDroidApp.port;
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= 8) // zxing requires >= 8
|
|
||||||
new QrGenAsyncTask(this, R.id.qrWizardImage).execute(qrString);
|
|
||||||
Log.i(TAG, "qr: " + qrString);
|
|
||||||
|
|
||||||
TextView wifiNetworkName = (TextView) findViewById(R.id.qrWifiNetworkName);
|
|
||||||
wifiNetworkName.setText(qrString.replaceFirst("http://", ""));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,111 +0,0 @@
|
|||||||
package org.fdroid.fdroid.views;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.IntentFilter;
|
|
||||||
import android.net.wifi.WifiInfo;
|
|
||||||
import android.net.wifi.WifiManager;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.v4.content.LocalBroadcastManager;
|
|
||||||
import android.support.v7.app.ActionBarActivity;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.View.OnClickListener;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
|
||||||
import org.fdroid.fdroid.QrGenAsyncTask;
|
|
||||||
import org.fdroid.fdroid.R;
|
|
||||||
import org.fdroid.fdroid.net.WifiStateChangeService;
|
|
||||||
|
|
||||||
public class QrWizardWifiNetworkActivity extends ActionBarActivity {
|
|
||||||
private static final String TAG = "QrWizardWifiNetworkActivity";
|
|
||||||
|
|
||||||
private WifiManager wifiManager;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
((FDroidApp) getApplication()).applyTheme(this);
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
|
|
||||||
wifiManager.setWifiEnabled(true);
|
|
||||||
FDroidApp.startLocalRepoService(this);
|
|
||||||
|
|
||||||
setContentView(R.layout.qr_wizard_activity);
|
|
||||||
TextView instructions = (TextView) findViewById(R.id.qrWizardInstructions);
|
|
||||||
instructions.setText(R.string.qr_wizard_wifi_network_instructions);
|
|
||||||
Button next = (Button) findViewById(R.id.qrNextButton);
|
|
||||||
next.setOnClickListener(new OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Intent intent = new Intent(getBaseContext(), QrWizardDownloadActivity.class);
|
|
||||||
startActivityForResult(intent, 0);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
resetNetworkInfo();
|
|
||||||
LocalBroadcastManager.getInstance(this).registerReceiver(onWifiChange,
|
|
||||||
new IntentFilter(WifiStateChangeService.BROADCAST));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(onWifiChange);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final BroadcastReceiver onWifiChange = new BroadcastReceiver() {
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent i) {
|
|
||||||
Log.i(TAG, "onWifiChange.onReceive()");
|
|
||||||
resetNetworkInfo();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void resetNetworkInfo() {
|
|
||||||
int wifiState = wifiManager.getWifiState();
|
|
||||||
if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
|
|
||||||
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
|
|
||||||
// http://zxing.appspot.com/generator/
|
|
||||||
// WIFI:S:openwireless.org;; // no pw
|
|
||||||
// WIFI:S:openwireless.org;T:WPA;;
|
|
||||||
// WIFI:S:openwireless.org;T:WEP;;
|
|
||||||
// WIFI:S:openwireless.org;H:true;; // hidden
|
|
||||||
// WIFI:S:openwireless.org;T:WPA;H:true;; // all
|
|
||||||
String qrString = "WIFI:S:";
|
|
||||||
qrString += wifiInfo.getSSID();
|
|
||||||
// TODO get encryption state (none, WEP, WPA)
|
|
||||||
/*
|
|
||||||
* WifiConfiguration wc = null; for (WifiConfiguration i :
|
|
||||||
* wifiManager.getConfiguredNetworks()) { if (i.status ==
|
|
||||||
* WifiConfiguration.Status.CURRENT) { wc = i; break; } } if (wc !=
|
|
||||||
* null)
|
|
||||||
*/
|
|
||||||
if (wifiInfo.getHiddenSSID())
|
|
||||||
qrString += ";H:true";
|
|
||||||
qrString += ";;";
|
|
||||||
if (Build.VERSION.SDK_INT >= 8) // zxing requires >= 8
|
|
||||||
new QrGenAsyncTask(this, R.id.qrWizardImage).execute(qrString);
|
|
||||||
|
|
||||||
TextView wifiNetworkName = (TextView) findViewById(R.id.qrWifiNetworkName);
|
|
||||||
wifiNetworkName.setText(wifiInfo.getSSID());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
// this wizard is done, clear this Activity from the history
|
|
||||||
if (resultCode == RESULT_OK)
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,93 +0,0 @@
|
|||||||
package org.fdroid.fdroid.views;
|
|
||||||
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.v4.view.MenuItemCompat;
|
|
||||||
import android.support.v7.app.ActionBarActivity;
|
|
||||||
import android.support.v7.view.ActionMode;
|
|
||||||
import android.support.v7.widget.SearchView;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
|
||||||
import org.fdroid.fdroid.PreferencesActivity;
|
|
||||||
import org.fdroid.fdroid.R;
|
|
||||||
import org.fdroid.fdroid.views.fragments.SelectLocalAppsFragment;
|
|
||||||
|
|
||||||
public class SelectLocalAppsActivity extends ActionBarActivity {
|
|
||||||
|
|
||||||
private static final String TAG = "SelectLocalAppsActivity";
|
|
||||||
private SelectLocalAppsFragment selectLocalAppsFragment = null;
|
|
||||||
private SearchView searchView;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
((FDroidApp) getApplication()).applyTheme(this);
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.select_local_apps_activity);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
if (selectLocalAppsFragment == null)
|
|
||||||
selectLocalAppsFragment = (SelectLocalAppsFragment) getSupportFragmentManager()
|
|
||||||
.findFragmentById(R.id.fragment_app_list);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
getMenuInflater().inflate(R.menu.select_local_apps_activity, menu);
|
|
||||||
searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
|
|
||||||
searchView.setOnQueryTextListener(selectLocalAppsFragment);
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case android.R.id.home:
|
|
||||||
setResult(RESULT_CANCELED);
|
|
||||||
finish();
|
|
||||||
return true;
|
|
||||||
case R.id.action_settings:
|
|
||||||
startActivity(new Intent(this, PreferencesActivity.class));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.onOptionsItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
||||||
MenuInflater inflater = mode.getMenuInflater();
|
|
||||||
inflater.inflate(R.menu.select_local_apps_action_mode, menu);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
||||||
return false; // Return false if nothing is done
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onActionItemClicked(final ActionMode mode, MenuItem item) {
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case R.id.action_update_repo:
|
|
||||||
setResult(RESULT_OK);
|
|
||||||
finish();
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
|
||||||
setResult(RESULT_CANCELED);
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,211 +0,0 @@
|
|||||||
/*
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.fdroid.fdroid.views.fragments;
|
|
||||||
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.support.v4.app.ListFragment;
|
|
||||||
import android.support.v4.app.LoaderManager;
|
|
||||||
import android.support.v4.content.CursorLoader;
|
|
||||||
import android.support.v4.content.Loader;
|
|
||||||
import android.support.v4.widget.SimpleCursorAdapter;
|
|
||||||
import android.support.v4.widget.SimpleCursorAdapter.ViewBinder;
|
|
||||||
import android.support.v7.view.ActionMode;
|
|
||||||
import android.support.v7.widget.SearchView.OnQueryTextListener;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
|
||||||
import org.fdroid.fdroid.R;
|
|
||||||
import org.fdroid.fdroid.data.InstalledAppProvider;
|
|
||||||
import org.fdroid.fdroid.data.InstalledAppProvider.DataColumns;
|
|
||||||
import org.fdroid.fdroid.localrepo.LocalRepoManager;
|
|
||||||
import org.fdroid.fdroid.views.SelectLocalAppsActivity;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class SelectLocalAppsFragment extends ListFragment
|
|
||||||
implements LoaderManager.LoaderCallbacks<Cursor>, OnQueryTextListener {
|
|
||||||
|
|
||||||
private PackageManager packageManager;
|
|
||||||
private Drawable defaultAppIcon;
|
|
||||||
private SelectLocalAppsActivity selectLocalAppsActivity;
|
|
||||||
private ActionMode mActionMode = null;
|
|
||||||
private String mCurrentFilterString;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
|
|
||||||
setEmptyText(getString(R.string.no_applications_found));
|
|
||||||
|
|
||||||
packageManager = getActivity().getPackageManager();
|
|
||||||
defaultAppIcon = getActivity().getResources()
|
|
||||||
.getDrawable(android.R.drawable.sym_def_app_icon);
|
|
||||||
|
|
||||||
selectLocalAppsActivity = (SelectLocalAppsActivity) getActivity();
|
|
||||||
ListView listView = getListView();
|
|
||||||
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
|
||||||
SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(),
|
|
||||||
R.layout.select_local_apps_list_item,
|
|
||||||
null,
|
|
||||||
new String[] {
|
|
||||||
InstalledAppProvider.DataColumns.APPLICATION_LABEL,
|
|
||||||
InstalledAppProvider.DataColumns.APP_ID,
|
|
||||||
},
|
|
||||||
new int[] {
|
|
||||||
R.id.application_label,
|
|
||||||
R.id.package_name,
|
|
||||||
},
|
|
||||||
0);
|
|
||||||
adapter.setViewBinder(new ViewBinder() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
|
|
||||||
if (columnIndex == cursor.getColumnIndex(InstalledAppProvider.DataColumns.APP_ID)) {
|
|
||||||
String packageName = cursor.getString(columnIndex);
|
|
||||||
TextView textView = (TextView) view.findViewById(R.id.package_name);
|
|
||||||
textView.setText(packageName);
|
|
||||||
LinearLayout ll = (LinearLayout) view.getParent().getParent();
|
|
||||||
ImageView iconView = (ImageView) ll.getChildAt(0);
|
|
||||||
Drawable icon;
|
|
||||||
try {
|
|
||||||
icon = packageManager.getApplicationIcon(packageName);
|
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
|
||||||
icon = defaultAppIcon;
|
|
||||||
}
|
|
||||||
iconView.setImageDrawable(icon);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
setListAdapter(adapter);
|
|
||||||
setListShown(false); // start out with a progress indicator
|
|
||||||
|
|
||||||
// either reconnect with an existing loader or start a new one
|
|
||||||
getLoaderManager().initLoader(0, null, this);
|
|
||||||
|
|
||||||
// build list of existing apps from what is on the file system
|
|
||||||
if (FDroidApp.selectedApps == null) {
|
|
||||||
Set<String> selectedApps = new HashSet<>();
|
|
||||||
for (String filename : LocalRepoManager.get(selectLocalAppsActivity).repoDir.list()) {
|
|
||||||
if (filename.matches(".*\\.apk")) {
|
|
||||||
String packageName = filename.substring(0, filename.indexOf("_"));
|
|
||||||
selectedApps.add(packageName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FDroidApp.selectedApps = selectedApps;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onListItemClick(ListView l, View v, int position, long id) {
|
|
||||||
if (mActionMode == null)
|
|
||||||
mActionMode = selectLocalAppsActivity
|
|
||||||
.startSupportActionMode(selectLocalAppsActivity.mActionModeCallback);
|
|
||||||
Cursor c = (Cursor) getListAdapter().getItem(position);
|
|
||||||
String packageName = c.getString(c.getColumnIndex(DataColumns.APP_ID));
|
|
||||||
if (FDroidApp.selectedApps.contains(packageName)) {
|
|
||||||
FDroidApp.selectedApps.remove(packageName);
|
|
||||||
} else {
|
|
||||||
FDroidApp.selectedApps.add(packageName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CursorLoader onCreateLoader(int id, Bundle args) {
|
|
||||||
Uri baseUri;
|
|
||||||
if (TextUtils.isEmpty(mCurrentFilterString)) {
|
|
||||||
baseUri = InstalledAppProvider.getContentUri();
|
|
||||||
} else {
|
|
||||||
baseUri = InstalledAppProvider.getSearchUri(mCurrentFilterString);
|
|
||||||
}
|
|
||||||
return new CursorLoader(
|
|
||||||
this.getActivity(),
|
|
||||||
baseUri,
|
|
||||||
InstalledAppProvider.DataColumns.ALL,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
InstalledAppProvider.DataColumns.APPLICATION_LABEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
|
||||||
SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter();
|
|
||||||
adapter.swapCursor(cursor);
|
|
||||||
|
|
||||||
ListView listView = getListView();
|
|
||||||
int count = listView.getCount();
|
|
||||||
String fdroid = loader.getContext().getPackageName();
|
|
||||||
for (int i = 0; i < count; i++) {
|
|
||||||
Cursor c = ((Cursor) listView.getItemAtPosition(i));
|
|
||||||
String packageName = c.getString(c.getColumnIndex(DataColumns.APP_ID));
|
|
||||||
if (TextUtils.equals(packageName, fdroid)) {
|
|
||||||
listView.setItemChecked(i, true); // always include FDroid
|
|
||||||
} else {
|
|
||||||
for (String selected : FDroidApp.selectedApps) {
|
|
||||||
if (TextUtils.equals(packageName, selected)) {
|
|
||||||
listView.setItemChecked(i, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isResumed()) {
|
|
||||||
setListShown(true);
|
|
||||||
} else {
|
|
||||||
setListShownNoAnimation(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoaderReset(Loader<Cursor> loader) {
|
|
||||||
SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter();
|
|
||||||
adapter.swapCursor(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextChange(String newText) {
|
|
||||||
String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
|
|
||||||
if (mCurrentFilterString == null && newFilter == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (mCurrentFilterString != null && mCurrentFilterString.equals(newFilter)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
mCurrentFilterString = newFilter;
|
|
||||||
getLoaderManager().restartLoader(0, null, this);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextSubmit(String query) {
|
|
||||||
// this is not needed since we respond to every change in text
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCurrentFilterString() {
|
|
||||||
return mCurrentFilterString;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user