mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 18:59:06 +01:00
Make test data creation configurable.
This commit is contained in:
@@ -352,6 +352,16 @@
|
||||
/>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="org.briarproject.briar.android.test.TestDataActivity"
|
||||
android:label="Create test data"
|
||||
android:parentActivityName="org.briarproject.briar.android.settings.SettingsActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="org.briarproject.briar.android.settings.SettingsActivity"
|
||||
/>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="org.briarproject.briar.android.panic.PanicPreferencesActivity"
|
||||
android:label="@string/panic_setting"
|
||||
|
||||
@@ -70,6 +70,7 @@ import org.briarproject.briar.android.sharing.ShareForumFragment;
|
||||
import org.briarproject.briar.android.sharing.ShareForumMessageFragment;
|
||||
import org.briarproject.briar.android.sharing.SharingModule;
|
||||
import org.briarproject.briar.android.splash.SplashScreenActivity;
|
||||
import org.briarproject.briar.android.test.TestDataActivity;
|
||||
|
||||
import dagger.Component;
|
||||
|
||||
@@ -147,6 +148,8 @@ public interface ActivityComponent {
|
||||
|
||||
void inject(SettingsActivity activity);
|
||||
|
||||
void inject(TestDataActivity activity);
|
||||
|
||||
void inject(ChangePasswordActivity activity);
|
||||
|
||||
void inject(IntroductionActivity activity);
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.util.UserFeedback;
|
||||
import org.briarproject.briar.api.test.TestDataCreator;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -105,8 +104,6 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
|
||||
@Inject
|
||||
AndroidExecutor androidExecutor;
|
||||
@Inject
|
||||
TestDataCreator testDataCreator;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
@@ -153,14 +150,7 @@ public class SettingsFragment extends PreferenceFragmentCompat
|
||||
});
|
||||
|
||||
Preference testData = findPreference("pref_key_test_data");
|
||||
if (IS_DEBUG_BUILD) {
|
||||
testData.setOnPreferenceClickListener(preference -> {
|
||||
LOG.info("Creating test data");
|
||||
testDataCreator.createTestData();
|
||||
getActivity().finish();
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
if (!IS_DEBUG_BUILD) {
|
||||
testData.setVisible(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package org.briarproject.briar.android.test;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.SeekBar.OnSeekBarChangeListener;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
import org.briarproject.briar.android.navdrawer.NavDrawerActivity;
|
||||
import org.briarproject.briar.api.test.TestDataCreator;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class TestDataActivity extends BriarActivity {
|
||||
|
||||
@Inject
|
||||
TestDataCreator testDataCreator;
|
||||
|
||||
private TextView[] textviews = new TextView[5];
|
||||
private SeekBar[] seekbars = new SeekBar[5];
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_test_data);
|
||||
textviews[0] = findViewById(R.id.textViewContactsSb);
|
||||
textviews[1] = findViewById(R.id.textViewMessagesSb);
|
||||
textviews[2] = findViewById(R.id.TextViewBlogPostsSb);
|
||||
textviews[3] = findViewById(R.id.TextViewForumsSb);
|
||||
textviews[4] = findViewById(R.id.TextViewForumMessagesSb);
|
||||
seekbars[0] = findViewById(R.id.seekBarContacts);
|
||||
seekbars[1] = findViewById(R.id.seekBarMessages);
|
||||
seekbars[2] = findViewById(R.id.seekBarBlogPosts);
|
||||
seekbars[3] = findViewById(R.id.seekBarForums);
|
||||
seekbars[4] = findViewById(R.id.seekBarForumMessages);
|
||||
|
||||
for (int i = 0; i < 5; i++) {
|
||||
final TextView textView = textviews[i];
|
||||
seekbars[i].setOnSeekBarChangeListener(
|
||||
new OnSeekBarChangeListener() {
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekBar,
|
||||
int progress,
|
||||
boolean fromUser) {
|
||||
textView.setText("" + progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
findViewById(R.id.buttonCreateTestData).setOnClickListener(
|
||||
v -> {
|
||||
createTestData();
|
||||
});
|
||||
}
|
||||
|
||||
private void createTestData() {
|
||||
testDataCreator.createTestData(seekbars[0].getProgress(),
|
||||
seekbars[1].getProgress(), seekbars[2].getProgress(),
|
||||
seekbars[3].getProgress(), seekbars[4].getProgress());
|
||||
Intent intent = new Intent(this, NavDrawerActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectActivity(ActivityComponent component) {
|
||||
component.inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
onBackPressed();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
170
briar-android/src/main/res/layout/activity_test_data.xml
Normal file
170
briar-android/src/main/res/layout/activity_test_data.xml
Normal file
@@ -0,0 +1,170 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:padding="8dp">
|
||||
|
||||
<android.support.constraint.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewContacts"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Number of contacts"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBarContacts"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="50"
|
||||
android:progress="20"
|
||||
app:layout_constraintEnd_toStartOf="@+id/textViewContactsSb"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewContacts"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewContactsSb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="2"
|
||||
android:text="20"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/seekBarContacts"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewMessages"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Number of messages per contact"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/seekBarContacts"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBarMessages"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="50"
|
||||
android:paddingTop="5dp"
|
||||
android:progress="15"
|
||||
app:layout_constraintEnd_toStartOf="@+id/textViewMessagesSb"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewMessages"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewMessagesSb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="2"
|
||||
android:text="20"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/seekBarMessages"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewBlogPosts"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Number of blog posts"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/seekBarMessages"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBarBlogPosts"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="50"
|
||||
android:paddingTop="5dp"
|
||||
android:progress="30"
|
||||
app:layout_constraintEnd_toStartOf="@+id/TextViewBlogPostsSb"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewBlogPosts"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TextViewBlogPostsSb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="2"
|
||||
android:text="20"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/seekBarBlogPosts"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewForums"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Number of forums"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/seekBarBlogPosts"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBarForums"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="10"
|
||||
android:paddingTop="5dp"
|
||||
android:progress="3"
|
||||
app:layout_constraintEnd_toStartOf="@+id/TextViewForumsSb"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewForums"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TextViewForumsSb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="2"
|
||||
android:text="20"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/seekBarForums"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textViewForumMessages"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Number of forum messages"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/seekBarForums"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/seekBarForumMessages"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:max="50"
|
||||
android:paddingTop="5dp"
|
||||
android:progress="30"
|
||||
app:layout_constraintEnd_toStartOf="@+id/TextViewForumMessagesSb"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textViewForumMessages"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/TextViewForumMessagesSb"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="2"
|
||||
android:text="20"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/seekBarForumMessages"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonCreateTestData"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="10dp"
|
||||
android:text="Create test data"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/seekBarForumMessages"/>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
</ScrollView>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
@@ -124,6 +124,11 @@
|
||||
|
||||
<Preference
|
||||
android:key="pref_key_test_data"
|
||||
android:title="Create Test Data"/>
|
||||
android:title="Create Test Data">
|
||||
|
||||
</PreferenceScreen>
|
||||
<intent
|
||||
android:targetClass="org.briarproject.briar.android.test.TestDataActivity"
|
||||
android:targetPackage="@string/app_package"/>
|
||||
</Preference>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
Reference in New Issue
Block a user