Added progress bar on list items while moving certificate.

This commit is contained in:
Felix Ableitner 2014-07-24 18:32:07 +02:00
parent 1238d2ca61
commit 73d6e1de7c
4 changed files with 40 additions and 7 deletions

View file

@ -58,6 +58,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />

View file

@ -8,6 +8,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.List;
@ -37,16 +38,25 @@ public class CertificateAdapter extends ArrayAdapter<Certificate> implements
convertView = inflater.inflate(R.layout.certificate_list_item, parent, false);
}
TextView title = (TextView) convertView.findViewById(R.id.title);
Button button = (Button) convertView.findViewById(R.id.button);
ProgressBar loading = (ProgressBar) convertView.findViewById(R.id.loading);
TextView summary = (TextView) convertView.findViewById(R.id.summary);
button.setVisibility(View.VISIBLE);
loading.setVisibility(View.INVISIBLE);
final Certificate cert = getItem(position);
// NOTE: This should be called asynchronously.
Pair<String, String> desc = CertificateManager.getDescription(cert);
TextView title = (TextView) convertView.findViewById(R.id.title);
title.setText(desc.first);
TextView summary = (TextView) convertView.findViewById(R.id.summary);
summary.setText(desc.second);
Button button = (Button) convertView.findViewById(R.id.button);
int colorRes;
if (cert.isSystemCertificate()) {
int colorRes = android.R.color.primary_text_light;
if (mCertificateManager.isMovingCertificate(cert)) {
button.setVisibility(View.INVISIBLE);
loading.setVisibility(View.VISIBLE);
}
else if (cert.isSystemCertificate()) {
button.setText(R.string.delete);
button.setOnClickListener(new View.OnClickListener() {
@Override

View file

@ -13,6 +13,7 @@ import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import eu.chainfire.libsuperuser.Shell;
@ -40,6 +41,11 @@ public class CertificateManager {
ReadWrite
}
/**
* Contains all certificates that are currently being moved from user to system storage.
*/
private LinkedList<Certificate> mCurrentlyMoving = new LinkedList<Certificate>();
private OnCertificateChangedListener mOnCertificateChangedListener;
public void setOnCertificateChangedListener(OnCertificateChangedListener listener) {
@ -68,6 +74,10 @@ public class CertificateManager {
* @return The updated certificate (located in system storage).
*/
public Certificate moveCertificateToSystem(Certificate certificate) {
mCurrentlyMoving.add(certificate);
if (mOnCertificateChangedListener != null) {
mOnCertificateChangedListener.onCertificateChanged();
}
remountSystem(Mode.ReadWrite);
// NOTE: Using mv gives error: "failed on *file* - Cross-device link".
run("cp " + USER_CERTIFICATES_DIR + "/" + certificate.getFile().getName() +
@ -75,6 +85,7 @@ public class CertificateManager {
run("chmod 644 " + SYSTEM_CERTIFICATES_DIR + "/" + certificate.getFile().getName());
remountSystem(Mode.ReadOnly);
deleteCertificate(certificate);
mCurrentlyMoving.remove(certificate);
Certificate newCert = new Certificate(certificate.getFile().getName(), true);
if (mOnCertificateChangedListener != null) {
mOnCertificateChangedListener.onCertificateChanged();
@ -171,4 +182,8 @@ public class CertificateManager {
return new Pair<String, String>(primary, secondary);
}
public boolean isMovingCertificate(Certificate cert) {
return mCurrentlyMoving.contains(cert);
}
}

View file

@ -13,7 +13,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dip"
android:textAppearance="?android:attr/textAppearanceListItem"/>
android:textAppearance="?android:attr/textAppearanceListItem" />
<Button
android:id="@+id/button"
@ -21,7 +21,14 @@
android:layout_height="wrap_content"
android:layout_alignTop="@id/title"
android:layout_alignParentRight="true"
style="?android:attr/buttonStyleSmall"/>
style="?android:attr/buttonStyleSmall" />
<ProgressBar
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/title"
android:layout_alignParentRight="true" />
<TextView
android:id="@+id/summary"