kopia lustrzana https://github.com/olgamiller/SSTVEncoder2
Added ProgressBar for sending
rodzic
bd949f044b
commit
acaceef5b7
|
@ -31,10 +31,12 @@ import om.sstvencoder.Output.OutputFactory;
|
|||
class Encoder {
|
||||
private final Thread mThread;
|
||||
private final List<IMode> mQueue;
|
||||
private final ProgressBarWrapper mProgressBar;
|
||||
private boolean mQuit, mStop;
|
||||
private Class<?> mModeClass;
|
||||
|
||||
Encoder() {
|
||||
Encoder(ProgressBarWrapper progressBar) {
|
||||
mProgressBar = progressBar;
|
||||
mQueue = new LinkedList<>();
|
||||
mQuit = false;
|
||||
mStop = false;
|
||||
|
@ -59,14 +61,18 @@ class Encoder {
|
|||
mode = mQueue.remove(0);
|
||||
}
|
||||
mode.init();
|
||||
mProgressBar.begin(mode.getProcessCount());
|
||||
|
||||
while (mode.process()) {
|
||||
mProgressBar.step();
|
||||
|
||||
synchronized (this) {
|
||||
if (mQuit || mStop)
|
||||
break;
|
||||
}
|
||||
}
|
||||
mode.finish(mStop);
|
||||
mProgressBar.end();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -39,6 +39,7 @@ import android.system.OsConstants;
|
|||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SubMenu;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -64,7 +65,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
mCropView = (CropView) findViewById(R.id.cropView);
|
||||
mEncoder = new Encoder();
|
||||
mEncoder = new Encoder(new ProgressBarWrapper((ProgressBar) findViewById(R.id.progressBar)));
|
||||
IModeInfo mode = mEncoder.getModeInfo();
|
||||
mCropView.setModeSize(mode.getModeSize());
|
||||
setTitle(mode.getModeName());
|
||||
|
|
|
@ -18,6 +18,8 @@ package om.sstvencoder.ModeInterfaces;
|
|||
public interface IMode {
|
||||
void init();
|
||||
|
||||
int getProcessCount();
|
||||
|
||||
boolean process();
|
||||
|
||||
void finish(boolean cancel);
|
||||
|
|
|
@ -34,6 +34,7 @@ abstract class Mode implements IMode {
|
|||
mBitmap = bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
mRunningIntegral = 0.0;
|
||||
mLine = 0;
|
||||
|
@ -41,6 +42,12 @@ abstract class Mode implements IMode {
|
|||
writeCalibrationHeader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProcessCount() {
|
||||
return mBitmap.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process() {
|
||||
if (mLine >= mBitmap.getHeight())
|
||||
return false;
|
||||
|
@ -51,6 +58,7 @@ abstract class Mode implements IMode {
|
|||
}
|
||||
|
||||
// Note that also Bitmap will be recycled here
|
||||
@Override
|
||||
public void finish(boolean cancel) {
|
||||
mOutput.finish(cancel);
|
||||
destroyBitmap();
|
||||
|
|
|
@ -51,6 +51,11 @@ abstract class PD extends Mode {
|
|||
return mBitmap.getHeight() / 2 * lineSamples;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProcessCount() {
|
||||
return mBitmap.getHeight() / 2;
|
||||
}
|
||||
|
||||
protected void writeEncodedLine() {
|
||||
addSyncPulse();
|
||||
addPorch();
|
||||
|
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
Copyright 2017 Olga Miller <olga.rgb@gmail.com>
|
||||
|
||||
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 om.sstvencoder;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
class ProgressBarWrapper {
|
||||
private final ProgressBar mProgressBar;
|
||||
private final Handler mHandler;
|
||||
private final int mSteps;
|
||||
private int mLastStep;
|
||||
private int mPosition, mMaxPosition;
|
||||
|
||||
ProgressBarWrapper(ProgressBar progressBar) {
|
||||
mProgressBar = progressBar;
|
||||
mProgressBar.setVisibility(View.INVISIBLE);
|
||||
mHandler = new Handler();
|
||||
mSteps = 10;
|
||||
}
|
||||
|
||||
private void startProgressBar(final int max) {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mProgressBar.setMax(max);
|
||||
mProgressBar.setProgress(0);
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void stepProgressBar(final int state) {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mProgressBar.setProgress(state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void endProgressBar() {
|
||||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mProgressBar.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void begin(int max) {
|
||||
mLastStep = 0;
|
||||
mPosition = 0;
|
||||
mMaxPosition = max;
|
||||
startProgressBar(mSteps);
|
||||
}
|
||||
|
||||
void step() {
|
||||
++mPosition;
|
||||
int newStep = (mSteps * mPosition + mMaxPosition / 2) / mMaxPosition;
|
||||
if (newStep != mLastStep) {
|
||||
stepProgressBar(newStep);
|
||||
mLastStep = newStep;
|
||||
}
|
||||
}
|
||||
|
||||
void end() {
|
||||
endProgressBar();
|
||||
}
|
||||
}
|
|
@ -17,4 +17,11 @@
|
|||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentTop="true"/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
Ładowanie…
Reference in New Issue