diff --git a/briar-android/res/layout/activity_plain.xml b/briar-android/res/layout/activity_plain.xml new file mode 100644 index 0000000000000000000000000000000000000000..93af4f94bfe12cd8778550e5c24f56c76ab629df --- /dev/null +++ b/briar-android/res/layout/activity_plain.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + + <android.support.v7.widget.Toolbar + android:id="@+id/toolbar" + style="@style/BriarToolbar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:background="?attr/colorPrimary" + android:minHeight="?attr/actionBarSize" + /> + + <FrameLayout + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <FrameLayout + android:id="@+id/content_fragment" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@color/window_background"/> + + </FrameLayout> + +</LinearLayout> \ No newline at end of file diff --git a/briar-android/res/layout/fragment_keyagreement_qr.xml b/briar-android/res/layout/fragment_keyagreement_qr.xml index 993045ef9b3b78d10dc2193a86e9c18cad8a8024..ec308624b2710b09b5b2f67e7cbb56acdbd8e703 100644 --- a/briar-android/res/layout/fragment_keyagreement_qr.xml +++ b/briar-android/res/layout/fragment_keyagreement_qr.xml @@ -11,9 +11,11 @@ android:layout_height="match_parent"/> <LinearLayout + android:id="@+id/camera_overlay" android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="vertical"> + android:orientation="vertical" + android:weightSum="2"> <FrameLayout android:layout_width="match_parent" @@ -64,4 +66,30 @@ android:scaleType="fitCenter"/> </RelativeLayout> </LinearLayout> + + <RelativeLayout + android:id="@+id/container_progress" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@android:color/white" + android:visibility="invisible"> + + <ProgressBar + android:id="@+id/progress_bar" + style="?android:attr/progressBarStyleLarge" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_centerInParent="true"/> + + <TextView + android:id="@+id/title_progress_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_below="@id/progress_bar" + android:gravity="center" + android:paddingTop="@dimen/margin_large" + tools:text="progress bar title" + /> + </RelativeLayout> + </FrameLayout> diff --git a/briar-android/src/org/briarproject/android/NavDrawerActivity.java b/briar-android/src/org/briarproject/android/NavDrawerActivity.java index 3aa248716fd10976f549aa827e8fe2475c2f37af..a7af5d0d062edb19ce994264f51f33208504bf54 100644 --- a/briar-android/src/org/briarproject/android/NavDrawerActivity.java +++ b/briar-android/src/org/briarproject/android/NavDrawerActivity.java @@ -235,7 +235,6 @@ public class NavDrawerActivity extends BriarFragmentActivity implements super.signOut(); } - @Override public void showLoadingScreen(boolean isBlocking, int stringId) { if (isBlocking) { // Disable navigation drawer slide to open @@ -245,7 +244,6 @@ public class NavDrawerActivity extends BriarFragmentActivity implements progressViewGroup.setVisibility(View.VISIBLE); } - @Override public void hideLoadingScreen() { drawerLayout.setDrawerLockMode(LOCK_MODE_UNLOCKED); progressViewGroup.setVisibility(INVISIBLE); diff --git a/briar-android/src/org/briarproject/android/blogs/BlogActivity.java b/briar-android/src/org/briarproject/android/blogs/BlogActivity.java index bb7a5cc8d3ec4f6f3f86ba492e8606591aaa0fe0..1b35bc5ced54153325ef84a420fdd238e410f53e 100644 --- a/briar-android/src/org/briarproject/android/blogs/BlogActivity.java +++ b/briar-android/src/org/briarproject/android/blogs/BlogActivity.java @@ -13,9 +13,6 @@ import org.briarproject.api.sync.GroupId; import javax.inject.Inject; -import static android.view.View.INVISIBLE; -import static android.view.View.VISIBLE; - public class BlogActivity extends BriarActivity implements OnBlogPostClickListener, BaseFragmentListener { @@ -72,16 +69,6 @@ public class BlogActivity extends BriarActivity implements .commit(); } - @Override - public void showLoadingScreen(boolean isBlocking, int stringId) { - progressBar.setVisibility(VISIBLE); - } - - @Override - public void hideLoadingScreen() { - progressBar.setVisibility(INVISIBLE); - } - @Override public void onFragmentCreated(String tag) { } diff --git a/briar-android/src/org/briarproject/android/blogs/ReblogActivity.java b/briar-android/src/org/briarproject/android/blogs/ReblogActivity.java index 6b4afb89bac8121f8dfac031bc6c60b783cf2512..4489f5c730f20e4302e31f22fa692a4d1c734865 100644 --- a/briar-android/src/org/briarproject/android/blogs/ReblogActivity.java +++ b/briar-android/src/org/briarproject/android/blogs/ReblogActivity.java @@ -64,16 +64,6 @@ public class ReblogActivity extends BriarActivity implements component.inject(this); } - @Override - public void showLoadingScreen(boolean isBlocking, int stringId) { - // this is handled by the fragment - } - - @Override - public void hideLoadingScreen() { - // this is handled by the fragment - } - @Override public void onFragmentCreated(String tag) { diff --git a/briar-android/src/org/briarproject/android/fragment/BaseFragment.java b/briar-android/src/org/briarproject/android/fragment/BaseFragment.java index 82d8f8ebc635df03feaaa59b4227e0c830bee8ab..7c1e072acc7effc6e94dbec16de11950c480fffb 100644 --- a/briar-android/src/org/briarproject/android/fragment/BaseFragment.java +++ b/briar-android/src/org/briarproject/android/fragment/BaseFragment.java @@ -48,12 +48,6 @@ public abstract class BaseFragment extends Fragment { public interface BaseFragmentListener extends DestroyableActivity { - @UiThread - void showLoadingScreen(boolean isBlocking, int stringId); - - @UiThread - void hideLoadingScreen(); - void runOnDbThread(Runnable runnable); @UiThread diff --git a/briar-android/src/org/briarproject/android/introduction/IntroductionActivity.java b/briar-android/src/org/briarproject/android/introduction/IntroductionActivity.java index 3c14628ebf55a535190f26736029abf327573676..8c4e6465243c87fabdb56a27fab183485025dfdd 100644 --- a/briar-android/src/org/briarproject/android/introduction/IntroductionActivity.java +++ b/briar-android/src/org/briarproject/android/introduction/IntroductionActivity.java @@ -48,16 +48,6 @@ public class IntroductionActivity extends BriarActivity implements component.inject(this); } - @Override - public void showLoadingScreen(boolean isBlocking, int stringId) { - // this is handled by the recycler view in ContactChooserFragment - } - - @Override - public void hideLoadingScreen() { - // this is handled by the recycler view in ContactChooserFragment - } - @Override public void onFragmentCreated(String tag) { diff --git a/briar-android/src/org/briarproject/android/keyagreement/KeyAgreementActivity.java b/briar-android/src/org/briarproject/android/keyagreement/KeyAgreementActivity.java index 431f0f59169e2a01d959c23f25de35d068df2ed1..a9c7fb4b6b69251b6b1ebe61b5afd76b32915e7c 100644 --- a/briar-android/src/org/briarproject/android/keyagreement/KeyAgreementActivity.java +++ b/briar-android/src/org/briarproject/android/keyagreement/KeyAgreementActivity.java @@ -3,8 +3,6 @@ package org.briarproject.android.keyagreement; import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.view.MenuItem; -import android.view.View; -import android.widget.TextView; import android.widget.Toast; import org.briarproject.R; @@ -45,8 +43,6 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements protected EventBus eventBus; private Toolbar toolbar; - private View progressContainer; - private TextView progressTitle; // Fields that are accessed from background threads must be volatile @Inject @@ -63,11 +59,9 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements @Override public void onCreate(Bundle state) { super.onCreate(state); - setContentView(R.layout.activity_with_loading); + setContentView(R.layout.activity_plain); toolbar = (Toolbar) findViewById(R.id.toolbar); - progressContainer = findViewById(R.id.container_progress); - progressTitle = (TextView) findViewById(R.id.title_progress_bar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); @@ -120,17 +114,6 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements } } - @Override - public void showLoadingScreen(boolean isBlocking, int stringId) { - progressTitle.setText(stringId); - progressContainer.setVisibility(View.VISIBLE); - } - - @Override - public void hideLoadingScreen() { - progressContainer.setVisibility(View.INVISIBLE); - } - @Override public void showNextScreen() { showStep(STEP_QR); @@ -148,7 +131,6 @@ public class KeyAgreementActivity extends BriarFragmentActivity implements runOnUiThread(new Runnable() { @Override public void run() { - showLoadingScreen(false, R.string.exchanging_contact_details); startContactExchange(result); } }); diff --git a/briar-android/src/org/briarproject/android/keyagreement/ShowQrCodeFragment.java b/briar-android/src/org/briarproject/android/keyagreement/ShowQrCodeFragment.java index e3426388bc1961cceaf4808ff10f243387c14c01..c53200bec967051e20fb95dc28d99bb1acdbcdda 100644 --- a/briar-android/src/org/briarproject/android/keyagreement/ShowQrCodeFragment.java +++ b/briar-android/src/org/briarproject/android/keyagreement/ShowQrCodeFragment.java @@ -7,14 +7,18 @@ import android.content.Intent; import android.content.IntentFilter; import android.graphics.Bitmap; import android.hardware.Camera; +import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.annotation.UiThread; import android.util.Base64; +import android.util.DisplayMetrics; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.AlphaAnimation; import android.widget.ImageView; +import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; @@ -30,6 +34,7 @@ import org.briarproject.android.view.CameraView; import org.briarproject.api.event.Event; import org.briarproject.api.event.KeyAgreementAbortedEvent; import org.briarproject.api.event.KeyAgreementFailedEvent; +import org.briarproject.api.event.KeyAgreementFinishedEvent; import org.briarproject.api.event.KeyAgreementListeningEvent; import org.briarproject.api.event.KeyAgreementStartedEvent; import org.briarproject.api.event.KeyAgreementWaitingEvent; @@ -74,9 +79,13 @@ public class ShowQrCodeFragment extends BaseEventFragment protected Executor ioExecutor; private CameraView cameraView; + private ViewGroup cameraOverlay; private View statusView; private TextView status; private ImageView qrCode; + private ProgressBar mainProgressBar; + private TextView mainProgressTitle; + private ViewGroup mainProgressContainer; private BluetoothStateReceiver receiver; private QrCodeDecoder decoder; @@ -117,9 +126,15 @@ public class ShowQrCodeFragment extends BaseEventFragment super.onViewCreated(view, savedInstanceState); cameraView = (CameraView) view.findViewById(R.id.camera_view); + cameraOverlay = (ViewGroup) view.findViewById(R.id.camera_overlay); statusView = view.findViewById(R.id.status_container); status = (TextView) view.findViewById(R.id.connect_status); qrCode = (ImageView) view.findViewById(R.id.qr_code); + mainProgressBar = (ProgressBar) view.findViewById(R.id.progress_bar); + mainProgressTitle = + (TextView) view.findViewById(R.id.title_progress_bar); + mainProgressContainer = + (ViewGroup) view.findViewById(R.id.container_progress); } @Override @@ -262,23 +277,54 @@ public class ShowQrCodeFragment extends BaseEventFragment } else if (e instanceof KeyAgreementAbortedEvent) { KeyAgreementAbortedEvent event = (KeyAgreementAbortedEvent) e; keyAgreementAborted(event.didRemoteAbort()); + } else if (e instanceof KeyAgreementFinishedEvent) { + listener.runOnUiThread(new Runnable() { + @Override + public void run() { + mainProgressContainer.setVisibility(VISIBLE); + mainProgressTitle.setText(R.string.exchanging_contact_details); + } + }); } } + @UiThread + private void generateBitmapQR(final Payload payload) { + // Get narrowest screen dimension + Context context = getContext(); + if (context == null) return; + final DisplayMetrics dm = context.getResources().getDisplayMetrics(); + new AsyncTask<Void, Void, Bitmap>() { + + @Override + protected Bitmap doInBackground(Void... params) { + String input = + Base64.encodeToString(payloadEncoder.encode(payload), + 0); + Bitmap bitmap = + QrCodeUtils.createQrCode(dm, input); + return bitmap; + } + + @Override + protected void onPostExecute(Bitmap bitmap) { + if (bitmap != null && !isDetached()) { + qrCode.setImageBitmap(bitmap); + // Simple fade-in animation + AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f); + anim.setDuration(200); + qrCode.startAnimation(anim); + } + } + }.execute(); + } + private void setQrCode(final Payload localPayload) { + listener.runOnUiThread(new Runnable() { @Override public void run() { - String input = Base64.encodeToString( - payloadEncoder.encode(localPayload), 0); - Bitmap bitmap = - QrCodeUtils.createQrCode((Context) listener, input); - if (bitmap == null) return; - qrCode.setImageBitmap(bitmap); - // Simple fade-in animation - AlphaAnimation anim = new AlphaAnimation(0.0f, 1.0f); - anim.setDuration(200); - qrCode.startAnimation(anim); + generateBitmapQR(localPayload); } }); } @@ -308,8 +354,8 @@ public class ShowQrCodeFragment extends BaseEventFragment listener.runOnUiThread(new Runnable() { @Override public void run() { - listener.showLoadingScreen(false, - R.string.authenticating_with_device); + mainProgressContainer.setVisibility(VISIBLE); + mainProgressTitle.setText(R.string.authenticating_with_device); } }); } @@ -319,7 +365,8 @@ public class ShowQrCodeFragment extends BaseEventFragment @Override public void run() { reset(); - listener.hideLoadingScreen(); + mainProgressContainer.setVisibility(INVISIBLE); + mainProgressTitle.setText(""); // TODO show abort somewhere persistent? Toast.makeText(getActivity(), remoteAborted ? R.string.connection_aborted_remote : diff --git a/briar-android/src/org/briarproject/android/sharing/ShareActivity.java b/briar-android/src/org/briarproject/android/sharing/ShareActivity.java index a5e59ce8953759e54ede4dff2a15f7fbc2f6d11c..d79a7ed2eee4ae5141a8020c45f211e6a1eee627 100644 --- a/briar-android/src/org/briarproject/android/sharing/ShareActivity.java +++ b/briar-android/src/org/briarproject/android/sharing/ShareActivity.java @@ -89,16 +89,6 @@ public abstract class ShareActivity extends BriarActivity implements return contacts; } - @Override - public void showLoadingScreen(boolean isBlocking, int stringId) { - // this is handled by the recycler view in ContactSelectorFragment - } - - @Override - public void hideLoadingScreen() { - // this is handled by the recycler view in ContactSelectorFragment - } - @Override public void onFragmentCreated(String tag) { diff --git a/briar-android/src/org/briarproject/android/util/QrCodeUtils.java b/briar-android/src/org/briarproject/android/util/QrCodeUtils.java index 16d0172a23693f0559f65173b26def39376ac290..57a092eeb242f67f3f8f219fa892732512c43f3f 100644 --- a/briar-android/src/org/briarproject/android/util/QrCodeUtils.java +++ b/briar-android/src/org/briarproject/android/util/QrCodeUtils.java @@ -1,6 +1,5 @@ package org.briarproject.android.util; -import android.content.Context; import android.graphics.Bitmap; import android.util.DisplayMetrics; @@ -24,9 +23,7 @@ public class QrCodeUtils { Logger.getLogger(QrCodeUtils.class.getName()); @Nullable - public static Bitmap createQrCode(Context context, String input) { - // Get narrowest screen dimension - DisplayMetrics dm = context.getResources().getDisplayMetrics(); + public static Bitmap createQrCode(DisplayMetrics dm, String input) { int smallestDimen = Math.min(dm.widthPixels, dm.heightPixels); try { // Generate QR code