Skip to content

Instantly share code, notes, and snippets.

View rosuH's full-sized avatar
👻
Wubba lubba dub dub

rosuH

👻
Wubba lubba dub dub
View GitHub Profile
@rosuH
rosuH / SearchView.java
Last active April 4, 2018 03:18
SearchView Template
...
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.fragment_photo_gallery, menu);
MenuItem searchItem = menu.findItem(R.id.menu_item_search);
final SearchView searchView = (SearchView)searchItem.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@rosuH
rosuH / NetworkUtil.java
Created April 4, 2018 07:25
Judge whether the network is available.
private boolean isNetworkAvailableAndConnected() {
ConnectivityManager cm = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
boolean isNetworkAvailable = cm.getActiveNetworkInfo() != null;
boolean isNetworkConnected = isNetworkAvailable && cm.getActiveNetworkInfo().isConnected();
return isNetworkConnected;
}
@rosuH
rosuH / SingleFragmentActivity.java
Created April 18, 2018 13:15
A common super class to create activity that hosting a fragment.
public abstract class SingleFragmentActivity extends AppCompatActivity {
protected abstract Fragment createFragment();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fragment);
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragment_container);
if (fragment == null) {
fragment = createFragment();
@rosuH
rosuH / color.xml
Last active April 23, 2018 15:50
[Android WEB Color xml] This xml file list all WEB color. #Android #Color #XML
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="White">#FFFFFF</color>
<color name="Ivory">#FFFFF0</color>
<color name="LightYellow">#FFFFE0</color>
<color name="Yellow">#FFFF00</color>
<color name="Snow">#FFFAFA</color>
<color name="FloralWhite">#FFFAF0</color>
<color name="LemonChiffon">#FFFACD</color>
<color name="Cornsilk">#FFF8DC</color>
@rosuH
rosuH / java.gitignore
Created May 10, 2018 04:59
Java Git ignore file
# Built application files
*.apk
*.ap_
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
@rosuH
rosuH / getUserDirectory.java
Last active September 4, 2018 11:39
[getUserDirectory] Java Get User Directory #java #cross-platform
File file = new File(System.getProperty("user.home") + "/Downloads/" + "1.jpg");
@rosuH
rosuH / transparency.xml
Created September 5, 2018 03:08
[Hex transparency] #color #xml #transparency
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C
@rosuH
rosuH / glide.java
Last active September 6, 2018 13:32
[View RoundedCorners] #java #Android #view #Glide
// with Glide
Glide.with(context)
.load(url)
.apply(new RequestOptions().transforms(new CenterCrop(), new RoundedCorners(radius)))
.into(imageView);
// with Drawable xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
@rosuH
rosuH / RequestPermission.java
Created September 10, 2018 08:54
[Request Permission at runing time] #permission #Android
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) !=
PackageManager.PERMISSION_GRANTED){
Log.i(TAG, "onCreate: 准备申请权限");
@rosuH
rosuH / crash.log
Created September 30, 2018 02:21
Vivaldi crash log
Process: Vivaldi [1994]
Path: /Applications/Vivaldi.app/Contents/MacOS/Vivaldi
Identifier: com.vivaldi.Vivaldi
Version: 2.0.1309.29 (2.0.1309.29)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Vivaldi [1994]
User ID: 502
Date/Time: 2018-09-30 09:57:48.491 +0800