This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface RowType { | |
| int BUTTON_ROW_TYPE = 0; | |
| int IMAGE_ROW_TYPE = 1; | |
| int TEXT_ROW_TYPE = 2; | |
| int getItemViewType(); | |
| void onBindViewHolder(RecyclerView.ViewHolder viewHolder); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Override | |
| public int getItemViewType() { | |
| return RowType.TEXT_ROW_TYPE; | |
| } | |
| @Override | |
| public void onBindViewHolder(RecyclerView.ViewHolder viewHolder) { | |
| ViewHolderFactory.TextViewHolder textViewHolder = (ViewHolderFactory.TextViewHolder) viewHolder; | |
| textViewHolder.headerTextView.setText(header); | |
| textViewHolder.textView1.setText(text); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MultipleTypesAdapter extends RecyclerView.Adapter { | |
| private List<RowType> dataSet; | |
| public MultipleTypesAdapter(List<RowType> dataSet) { | |
| this.dataSet = dataSet; | |
| } | |
| @Override | |
| public int getItemViewType(int position) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Object lock = new Object(); | |
| synchronized (lock) { | |
| new Thread(new Runnable() { | |
| @Override | |
| void run() { | |
| lock.wait(); | |
| System.out.println("Thread1"); | |
| } | |
| }).start(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // lock jest obiektem na którym synchronizują się dwa wątki żeby wzajemnie sobie nie przeszkadzać | |
| // i mieć pewność, że wszystko przebiega tak jak powinno (tzn. że najpierw jest wait() a dopiero potem notify()) | |
| // synchronized(lock) można używać na blokach kodu. Używaj ich wewnątrz metody run(). | |
| // wait() i notify() oddziałują na wątki Thread1 i Thread2 ale wywoływane są na lock'u | |
| // bez wait() i notify() poniższy program wydrukowałby Thread1 a potem Thread2 (bo Thread2 ma sleep(2000)) | |
| // jednak z wait() i notify() i po synchronizacji Thread1 czeka na notify() od Thread2 więc najpierw wydrukuje się Thread2 | |
| // a potem Thread1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <RelativeLayout 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"> | |
| <TextureView | |
| android:id="@+id/texture_view" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA}, CAMERA_REQUEST_CODE); | |
| cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); | |
| cameraFacing = CameraCharacteristics.LENS_FACING_BACK; | |
| surfaceTextureListener = new TextureView.SurfaceTextureListener() { | |
| @Override | |
| public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) { | |
| setUpCamera(); | |
| openCamera(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void setUpCamera() { | |
| try { | |
| for (String cameraId : cameraManager.getCameraIdList()) { | |
| CameraCharacteristics cameraCharacteristics = | |
| cameraManager.getCameraCharacteristics(cameraId); | |
| if (cameraCharacteristics.get(CameraCharacteristics.LENS_FACING) == | |
| cameraFacing) { | |
| StreamConfigurationMap streamConfigurationMap = cameraCharacteristics.get( | |
| CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); | |
| previewSize = streamConfigurationMap.getOutputSizes(SurfaceTexture.class)[0]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void openCamera() { | |
| try { | |
| if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA) | |
| == PackageManager.PERMISSION_GRANTED) { | |
| cameraManager.openCamera(cameraId, stateCallback, backgroundHandler); | |
| } | |
| } catch (CameraAccessException e) { | |
| e.printStackTrace(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private void openBackgroundThread() { | |
| backgroundThread = new HandlerThread("camera_background_thread"); | |
| backgroundThread.start(); | |
| backgroundHandler = new Handler(backgroundThread.getLooper()); | |
| } |