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 ProgressRequestBody extends RequestBody { | |
private File mFile; | |
private String mPath; | |
private UploadCallbacks mListener; | |
private static final int DEFAULT_BUFFER_SIZE = 2048; | |
public interface UploadCallbacks { | |
void onProgressUpdate(int percentage); | |
void onError(); |
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
class IOHelper { | |
public byte[] readBytes(InputStream inputStream) throws IOException { | |
// this dynamically extends to take the bytes you read | |
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); | |
// this is storage overwritten on each iteration with bytes | |
int bufferSize = 1024; | |
byte[] buffer = new byte[bufferSize]; | |
// we need to know how may bytes were read to write them to the byteBuffer |
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
/** | |
* Convert the dps to pixels, based on density scale | |
* @param dp value expressed in dps | |
* @return value expressed in pixels | |
*/ | |
public int dpToPixel(int dp) { | |
// Get the screen's density scale | |
float scale = getResources().getDisplayMetrics().density; | |
// Add 0.5f to round the figure up to the nearest whole number | |
return (int) (dp * scale + 0.5f); |
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
/** | |
* Created by weiyi.li on 4/7/16. | |
* This activity includes {@link AlbumFragment} and {@link ThumbnailFragment}. | |
*/ | |
public class TwoFragmentsActivity extends BasicOperationActivity { | |
private boolean mShowingThumbnail = true; | |
@Dvr.DvrFolder private int mFolderType = Dvr.DVR_FOLDER_LOOPED_VIDEOS; | |
private FragmentManager mFm; | |
private AlbumFragment mAlbumFragment; | |
private ThumbnailFragment mThumbnailFragment; |
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
/** | |
* Created by weiyi on 2/23/16. | |
* http://li2.me/2016/08/make-a-reusable-ui-in-android-app-development.html | |
*/ | |
public class SingleFragmentActivtiy extends BasicActivity { | |
@Override | |
protected String getActionBarTitle() { | |
return "Single Fragment Activity"; | |
} |
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
/** | |
* Created by weiyi.li on 2/19/16. | |
* http://li2.me/2016/08/make-a-reusable-ui-in-android-app-development.html | |
*/ | |
public abstract class BasicOperationActivity extends BasicActivity { | |
private ToggleButton mOperationBtn1; | |
private ToggleButton mOperationBtn2; | |
/** Override this method to inflate bottom toolbar layout. */ | |
@Override |
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
/** | |
* Created by weiyi.li on 2/19/16 | |
* li2.me/2016/08/make-a-reusable-ui-in-android-app-development.html | |
*/ | |
public abstract class BasicActivity extends AppCompatActivity { | |
protected TextView mActionTitleView; | |
protected TextView mActionBackBtn; | |
protected Button mActionCloseBtn; | |
protected Fragment mContentFragment; |
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"?> | |
<android.support.design.widget.AppBarLayout | |
xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:id="@+id/topActionbarLayout" | |
android:layout_height="wrap_content" | |
android:layout_width="match_parent" | |
android:elevation="@dimen/elevation_header"> | |
<android.support.v7.widget.Toolbar |
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" | |
android:fitsSystemWindows="true"> | |
<include | |
layout="@layout/toolbar_actionbar" |
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
// https://stackoverflow.com/a/38847374/2722270 | |
public abstract class BasicServiceActivity extends AppCompatActivity { | |
protected DvrService mDvrService; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_basic); | |
attachService(); |